GAP MiniApp SDK Usage Guide
Installation
To install the gap-miniapp-sdk package, run the following command:
npm install gap-miniapp-sdk
Initialization
-
Import and initialize the SDK in your JavaScript or TypeScript application, preferring a Singleton object to communicate with the super app:
import { GapMiniAppSdk } from 'gap-miniapp-sdk';
const gapMiniAppSdk = new GapMiniAppSdk();
-
Detect the platform on which the super app is running for the mini app to function correctly:
let userAgent = gapMiniAppSdk.detectPlatform();
gapMiniAppSdk.setPlatformExecutor(userAgent);
Usage
Example Functions Using the SDK
-
Get the super app's current authentication information:
const response = await gapMiniAppSdk.getInstance().getAccessToken();
-
Set/Get storage item in the super app (This storage is constant and separate for each app and can be publicable):
-
Set a storage item:
let data = {
key: "test_key_1",
value: { data: false },
isPublic: 0
};
gapMiniAppSdk.setStorageItem(data).then((res) => console.log(res));
-
Get a storage item:
let data = {
key: "test_key_1"
};
await gapMiniAppSdk.getStorageItem(data)
.then((res) => {
console.log(res);
})
.catch((e) => {
console.log(e);
});
Full Functions
For a complete list of available functions, refer to the following interface file that defines each request/response type:
/gap-miniapp-sdk/dist/interface/gap_miniapp_interface