import type { CompatiblePlaceholderArgument, ContactResult, ImageResponse, Location, PermissionAccess, PermissionName, PermissionStatus, } from '@apps-in-toss/types'; import type { AppsInTossSignTossCertParams } from './native-modules/appsInTossSignTossCert'; import type { CheckoutPaymentOptions, CheckoutPaymentResult } from './native-modules/checkoutPayment'; import type { GetAnonymousKeyResponse } from './native-modules/getAnonymousKey'; import type { GameCenterGameProfileResponse } from './native-modules/getGameCenterGameProfile'; import type { GetUserKeyForGameResponse } from './native-modules/getUserKeyForGame'; import type { GrantPromotionRewardForGameResponse } from './native-modules/grantPromotionRewardForGame'; import type { IapCreateOneTimePurchaseOrderResult, IapSubscriptionInfoResult } from './native-modules/iap'; import type { SaveBase64DataParams } from './native-modules/saveBase64Data'; import type { SubmitGameCenterLeaderBoardScoreResponse } from './native-modules/submitGameCenterLeaderBoardScore'; import { MiniAppModule } from '../spec/MiniAppModule.brick'; /** * Async Methods Map * Type definitions for all async methods accessed via postMessage */ export interface AsyncMethodsMap { // Storage (4) getStorageItem: (params: { key: string }) => Promise; setStorageItem: (params: { key: string; value: string }) => Promise; removeStorageItem: (params: { key: string }) => Promise; clearStorage: (params: CompatiblePlaceholderArgument) => Promise; // Permissions (2) getPermission: (params: { name: PermissionName; access: PermissionAccess }) => Promise; openPermissionDialog: (params: { name: PermissionName; access: PermissionAccess }) => Promise<'allowed' | 'denied'>; // Clipboard (2) getClipboardText: (params: CompatiblePlaceholderArgument) => Promise; setClipboardText: (params: { text: string }) => Promise; // Contacts & Photos (3) fetchContacts: (params: { size: number; offset: number; query?: { contains?: string } }) => Promise; fetchAlbumPhotos: (params: { base64?: boolean; maxCount?: number; maxWidth?: number }) => Promise; openCamera: (params: { base64?: boolean; maxWidth?: number }) => Promise; // Location (1) startUpdateLocation: (params: { accuracy: number; timeInterval: number; distanceInterval: number }) => Promise; getCurrentLocation: (params: { accuracy: number }) => Promise; // IAP (7) iapCreateOneTimePurchaseOrder: (params: { productId: string }) => Promise; processProductGrant: (params: { orderId: string; isProductGranted: boolean }) => Promise; iapGetProductItemList: (params: CompatiblePlaceholderArgument) => Promise<{ products: any[] }>; getPendingOrders: ( params: CompatiblePlaceholderArgument ) => Promise<{ orders: Array<{ orderId: string; sku: string }> }>; getCompletedOrRefundedOrders: (params: { key?: string | null }) => Promise; completeProductGrant: (params: { orderId: string }) => Promise; getSubscriptionInfo: (params: { params: { orderId: string }; }) => Promise<{ subscription: IapSubscriptionInfoResult }>; // Other (9) eventLog: (params: { log_name: string; log_type: string; params: Record }) => Promise; getTossShareLink: (params: CompatiblePlaceholderArgument) => Promise<{ shareLink: string }>; appLogin: ( params: CompatiblePlaceholderArgument ) => Promise<{ authorizationCode: string; referrer: 'DEFAULT' | 'SANDBOX' }>; checkoutPayment: (params: CheckoutPaymentOptions) => Promise; setDeviceOrientation: (params: { type: 'portrait' | 'landscape' }) => Promise; saveBase64Data: (params: SaveBase64DataParams) => Promise; appsInTossSignTossCert: (params: AppsInTossSignTossCertParams) => Promise; getGameCenterGameProfile: ( params: CompatiblePlaceholderArgument ) => Promise; getUserKeyForGame: (params: CompatiblePlaceholderArgument) => Promise; getUserKey: (params: CompatiblePlaceholderArgument) => Promise; grantPromotionRewardForGame: (params: { promotionCode: string; amount: number; }) => Promise; submitGameCenterLeaderBoardScore: (params: { score: string; }) => Promise; // INTERNAL__appBridgeHandler methods (9) requestOneTimePurchase: (params: { sku: string }) => Promise; contactsViral: (params: { moduleId: string }) => Promise; getMiniAppsSupportContact: (params: object) => Promise; loadAdMobInterstitialAd: (params: { adUnitId: string }) => Promise; showAdMobInterstitialAd: (params: { adUnitId: string }) => Promise; loadAdMobRewardedAd: (params: { adUnitId: string }) => Promise; showAdMobRewardedAd: (params: { adUnitId: string }) => Promise; loadAppsInTossAdmob: (params: { adGroupId: string; referrer: string }) => Promise; showAppsInTossAdmob: (params: { adGroupId: string; referrer: string }) => Promise; getIsTossLoginIntegratedService: (params: object) => Promise; getServerTime: (params: CompatiblePlaceholderArgument) => Promise<{ serverTime: number }>; shareWithScheme: (params: { schemeURL: string }) => Promise; requestMiniAppReview: (params: { title: string }) => Promise; } /** * Sync Methods Map * Type definitions for all sync methods accessed via postMessageSync */ export interface SyncMethodsMap { getWebBundleURL: (params: CompatiblePlaceholderArgument) => { url: string }; stopUpdateLocation: (params: object) => void; } /** * Type-safe postMessage wrapper * Provides type inference for async method calls without requiring 'as unknown' casts */ export function safePostMessage( method: K, params: Parameters[0] ): ReturnType { return MiniAppModule.postMessage(method, params, {}) as ReturnType; } /** * Type-safe postMessageSync wrapper * Provides type inference for sync method calls without requiring 'as unknown' casts */ export function safeSyncPostMessage( method: K, params: Parameters[0] ): ReturnType { return MiniAppModule.postMessageSync(method, params, {}) as ReturnType; }