Skip to main content

Type Definitions

declare namespace midas {
interface MinigameAPI {
showMenu(options?: MenuShowOptions): Promise<ShowResult>;
hideMenu(options?: MenuHideOptions): void;
showPayment(options: PaymentShowOptions): Promise<PaymentResult>;
hidePayment(): void;
hideAll(): void;
login(options: LoginOptions): Promise<LoginResult>;
getLoginStatus(): boolean;
logout(): void;
getProductsData(params: ProductsParams): Promise<ProductsResult>;
on(event: string, callback: Function): void;
off(event: string, callback?: Function): void;
getModule(module: 'menu' | 'payment' | 'login'): any;
setErrorHandler(handler: (error: MinigameError) => void): void;
}

interface MenuShowOptions {
gradually?: boolean;
}

interface MenuHideOptions {
gradually?: boolean;
}

interface PaymentShowOptions {
params: PaymentParams;
extra?: PaymentExtra;
}

interface ShowResult {
res: string;
size?: {
width?: string;
height?: string;
};
}

interface LoginOptions {
success?: (result: LoginResult) => void;
fail?: (error: LoginError) => void;
}

interface LoginError {
code: number;
message: string;
error: string;
}

interface LoginResult {
code: number;
message: string;
data: {
jwtToken: string;
expiresIn: number;
refreshToken: string;
};
}

interface PaymentResult {
order_no: string; // Order number
openid: string; // User ID
order_no_hash: string; // Order hash
}

interface PaymentError extends Error {
code: string;
type: 'failed' | 'hide' | 'queryChannelsFailed';
data?: any;
timestamp: number;
}

interface ProductsParams {
game_openid: string;
role_id: string;
server_id?: string;
}

interface ProductItem {
product_id: string; // Unique identification of the item within Midasbuy
game_product_id: string; // Unique identification of the item within game
quantity: number; // Game coins or items amount (combined with product_type)
product_type: 'currency' | 'item'; // Product type: currency or item
product_icon: string; // Product image URL
name: string; // Product name
price_info: {
price: string; // Current price, e.g.: '69.99'
original_price: string; // Original price, e.g.: '77.99'
currency: string; // Currency code, e.g.: 'HKD'
display_price: string; // Display price with currency, e.g.: '69.99 HKD'
display_original_price: string; // Display original price with currency, e.g.: '77.99 HKD'
};
bonus: {
virtual_currency_quantity: number; // Bonus virtual currency amount
virtual_item_list: {
product_id: string; // Unique identification of the item within Midasbuy in bonus item
game_product_id: string; // Unique identification of the item within game in bonus item
name: string; // Bonus item name
quantity: number; // Bonus item quantity
icon: string; // Bonus item image URL
}[]; // Bonus virtual items list
};
meta: any; // Original shelf data, generally no attention required
}

interface ProductsResult {
products: ProductItem[];
}

function minigame(options: MinigameOptions): MinigameAPI;
}