dop-sdk
Version:
Mini App SDK for JavaScript by VTB
233 lines (232 loc) • 10.8 kB
TypeScript
import { UserInfoProvider } from './modules/user-info';
import { ChatService } from './modules/chat-service';
import { SecureStorageService } from './modules/secure-storage';
import { UniversalBridge } from './modules/universal-bridge';
import { MiniAppUtils } from './modules/utils';
import { Purchases } from './modules/in-app-purchase';
import { CookieManager } from './modules/cookie-manager';
import { MiniAppPreference } from './modules/miniapp-preferences';
import { GalleryBridge } from './modules/gallery-manager';
import { ShareInfoType } from './types/share-info';
import { WebviewManager } from './modules/webview-config-provider';
import { CustomPermission, CustomPermissionResult } from './types/custom-permission';
import { Points } from './types/point';
import { HostEnvironmentInfo } from './types/host-environment-info';
import { Reward } from './types/response-types';
import { DownloadFileHeaders } from './types/download-file-header';
import { CloseAlertInfo } from './types/close-alert';
/**
* A module layer for webapps and mobile native interaction.
*/
interface MiniAppFeatures {
/**
* @deprecated
* Use `getMessagingUniqueId` or `getMauid` instead
* Request the mini app's unique id from the host app.
* @returns The Promise of provided id of mini app from injected side.
*
*/
getUniqueId(): Promise<string>;
/**
* Request the mini app's messaging unique id from the host app.
* @returns The Promise of provided id of mini app from injected side.
*/
getMessagingUniqueId(): Promise<string>;
/**
* Request the mini app's mauid from the host app.
* @returns The Promise of provided id of mini app from injected side.
*/
getMauid(): Promise<string>;
/**
* Request the location permission from the host app.
* You must call this before using `navigator.geolocation`.
* This will request both the Android/iOS device permission for location (if not yet granted to the host app),
* and the custom permission for location {@link CustomPermissionName.LOCATION}.
* @param permissionDescription Description of location permission.
* @returns The Promise of permission result of mini app from injected side.
* Rejects the promise if the user denied the location permission (either the device permission or custom permission).
*/
requestLocationPermission(permissionDescription?: string): Promise<string>;
/**
*
* Request that the user grant custom permissions related to accessing user data.
* Typically, this will show a dialog in the Host App asking the user grant access to your Mini App.
* You can pass multiple permissions at once and the Host App will request all of those permissions within a single dialog.
*
* @param permissions An array containing CustomPermission objects - permission name and description
* @returns Promise with the custom permission results - "ALLOWED" or "DENIED" for each permission
*/
requestCustomPermissions(permissions: CustomPermission[]): Promise<CustomPermissionResult[]>;
/**
* Share text and image with another App or with the host app.
* @param info The shared data must match the property in [ShareInfoType].
* @returns The Promise of share info action state from injected side.
*/
shareInfo(info: ShareInfoType): Promise<string>;
/**
* Swap and lock the screen orientation.
* There is no guarantee that all hostapps and devices allow the force screen change so MiniApp should not rely on this.
* @param screenOrientation The action that miniapp wants to request on device.
* @returns The Promise of screen action state from injected side.
*/
setScreenOrientation(screenOrientation: ScreenOrientation): Promise<string>;
/**
* Request the point balance from the host app.
* @returns Promise of the provided point balance from mini app.
*/
getPoints(): Promise<Points>;
/**
* Request the host environment information.
* @returns Promise of the provided environment info from mini app.
*/
getHostEnvironmentInfo(): Promise<HostEnvironmentInfo>;
/**
* Request to download a file and save to the user's device.
* @returns Promise of the downloaded files name. Response will be `null` in case the user cancelled the download.
* Can be rejected with {@link MiniAppError}, {@link DownloadFailedError}, {@link DownloadHttpError}, {@link InvalidUrlError}, or {@link SaveFailureError}.
*/
downloadFile(filename: string, url: string, headers?: DownloadFileHeaders): Promise<string>;
/**
* Mini App can choose whether to display Close confirmation alert dialog when mini app is closed
*/
setCloseAlert(alertInfo: CloseAlertInfo): Promise<string>;
}
/**
* A contract declaring the interaction mechanism between mini-apps and native host app to display ads.
*/
interface Ad {
/**
* Loads the specified Interstittial Ad Unit ID.
* Can be called multiple times to pre-load multiple ads.
* Promise is resolved when successfully loaded.
* @returns The Promise of load success response.
* Promise is rejected if failed to load.
*/
loadInterstitialAd(id: string): Promise<string>;
/**
* Loads the specified Rewarded Ad Unit ID.
* Can be called multiple times to pre-load multiple ads.
* Promise is resolved when successfully loaded.
* @returns The Promise of load success response.
* Promise is rejected if failed to load.
*/
loadRewardedAd(id: string): Promise<string>;
/**
* Shows the Interstitial Ad for the specified ID.
* Promise is resolved after the user closes the Ad.
* @returns The Promise of close success response.
* Promise is rejected if the Ad failed to display wasn't loaded first using MiniApp.loadInterstitialAd.
*/
showInterstitialAd(id: string): Promise<string>;
/**
* Shows the Rewarded Ad for the specified ID.
* Promise is resolved with an object after the user closes the Ad. The object contains the reward earned by the user.
* Reward will be null if the user did not earn the reward.
* @returns The Promise of Rewarded ad response result from injected side.
* Promise is rejected if the Ad failed to display wasn't loaded first using MiniApp.loadRewardedAds.
*/
showRewardedAd(id: string): Promise<Reward>;
}
interface Platform {
/**
* Detect which platform your mini app is running on.
* @returns `Android`, `iOS`, or `Unknown`
*/
getPlatform(): string;
}
export declare class MiniApp implements MiniAppFeatures, Ad, Platform {
user: UserInfoProvider;
chatService: ChatService;
secureStorageService: SecureStorageService;
universalBridge: UniversalBridge;
miniappUtils: MiniAppUtils;
purchaseService: Purchases;
cookieManager: CookieManager;
preferences: MiniAppPreference;
galleryManager: GalleryBridge;
webviewManager: WebviewManager;
private requestPermission;
/**
* @deprecated Deprecated method for getting the uniqueId use `getMessagingUniqueId` or `getMauid` instead
*/
/**
* Deprecated method for associating getUniqueId function to MiniAppBridge object.
* Use `getMessagingUniqueId` or `getMauid` instead
*/
getUniqueId(): Promise<string>;
/**
* Associating getMessagingUniqueId function to MiniAppBridge object.
*/
getMessagingUniqueId(): Promise<string>;
/**
* Associating getMauid function to MiniAppBridge object.
*/
getMauid(): Promise<string>;
requestLocationPermission(permissionDescription?: string): Promise<string>;
/**
* Associating requestCustomPermissions function to MiniAppBridge object
* @param [CustomPermissionType[] permissionTypes, Types of custom permissions that are requested
* using an Array including the parameters eg. name, description.
*
* For eg., Miniapps can pass the array of valid custom permissions as following
* [
* {"name":"rakuten.miniapp.user.USER_NAME", "description": "Reason to request for the custom permission"},
* {"name":"rakuten.miniapp.user.PROFILE_PHOTO", "description": "Reason to request for the custom permission"},
* {"name":"rakuten.miniapp.user.CONTACT_LIST", "description": "Reason to request for the custom permission"}
* ]
*/
requestCustomPermissions(permissions: CustomPermission[]): Promise<CustomPermissionResult[]>;
/**
* Associating loadInterstitialAd function to MiniAppBridge object.
* This function preloads interstitial ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the interstitial ad that needs to be loaded.
*/
loadInterstitialAd(id: string): Promise<string>;
/**
* Associating loadRewardedAd function to MiniAppBridge object.
* This function preloads Rewarded ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the Rewarded ad that needs to be loaded.
*/
loadRewardedAd(id: string): Promise<string>;
/**
* Associating showInterstitialAd function to MiniAppBridge object.
* @param {string} id ad unit id of the intertitial ad
*/
showInterstitialAd(id: string): Promise<string>;
/**
* Associating showRewardedAd function to MiniAppBridge object.
* @param {string} id ad unit id of the Rewarded ad
*/
showRewardedAd(id: string): Promise<Reward>;
/**
* Associating shareInfo function to MiniAppBridge object.
* This function returns the shared info action state.
* @param {info} The shared info object.
*/
shareInfo(info: ShareInfoType): Promise<string>;
/**
* Get the platform which injects this bridge.
* @returns The platform name. It could be 'Android' or 'iOS'.
*/
getPlatform(): string;
/**
* This function does not return anything back on success.
* @param {screenAction} The screen state that miniapp wants to set on device.
*/
setScreenOrientation(screenOrientation: ScreenOrientation): Promise<string>;
/**
* Associating get point balance function to MiniAppBridge object.
* (provided rakuten.miniapp.user.POINTS is allowed by the user)
*/
getPoints(): Promise<Points>;
getHostEnvironmentInfo(): Promise<HostEnvironmentInfo>;
downloadFile(filename: string, url: string, headers?: DownloadFileHeaders): Promise<string>;
/**
* @param alertInfo Close confirmation alert info.
* @see {setCloseAlert}
*/
setCloseAlert(alertInfo: CloseAlertInfo): Promise<string>;
}
export {};