@ait-kit/sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +197 -13
- package/dist/ads/adapter.d.ts +36 -0
- package/dist/ads/adapter.d.ts.map +1 -0
- package/dist/ads/adapter.js +219 -0
- package/dist/ads/platform-contract.d.ts +45 -0
- package/dist/ads/platform-contract.d.ts.map +1 -0
- package/dist/ads/platform-contract.js +7 -0
- package/dist/iap/adapter.d.ts +11 -1
- package/dist/iap/adapter.d.ts.map +1 -1
- package/dist/iap/adapter.js +13 -0
- package/dist/iap/order-history.d.ts +6 -0
- package/dist/iap/order-history.d.ts.map +1 -0
- package/dist/iap/order-history.js +54 -0
- package/dist/iap/platform-contract.d.ts +9 -1
- package/dist/iap/platform-contract.d.ts.map +1 -1
- package/dist/iap/platform-contract.js +1 -1
- package/dist/iap/purchase-flow.d.ts +1 -1
- package/dist/iap/purchase-flow.js +1 -1
- package/dist/iap/subscription-info.d.ts +6 -0
- package/dist/iap/subscription-info.d.ts.map +1 -0
- package/dist/iap/subscription-info.js +38 -0
- package/dist/identity/platform-contract.d.ts +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/notification/platform-contract.d.ts +1 -1
- package/dist/platform-loader.d.ts +16 -0
- package/dist/platform-loader.d.ts.map +1 -0
- package/dist/platform-loader.js +35 -0
- package/dist/promotion/adapter.d.ts +3 -0
- package/dist/promotion/adapter.d.ts.map +1 -0
- package/dist/promotion/adapter.js +128 -0
- package/dist/promotion/platform-contract.d.ts +37 -0
- package/dist/promotion/platform-contract.d.ts.map +1 -0
- package/dist/review/adapter.d.ts +3 -0
- package/dist/review/adapter.d.ts.map +1 -0
- package/dist/review/adapter.js +33 -0
- package/dist/review/platform-contract.d.ts +21 -0
- package/dist/review/platform-contract.d.ts.map +1 -0
- package/dist/review/platform-contract.js +1 -0
- package/dist/rn/ads.d.ts +7 -36
- package/dist/rn/ads.d.ts.map +1 -1
- package/dist/rn/ads.js +3 -229
- package/dist/rn/framework-contract.d.ts +1 -44
- package/dist/rn/framework-contract.d.ts.map +1 -1
- package/dist/rn/framework-contract.js +0 -6
- package/dist/rn/framework-loader.d.ts.map +1 -1
- package/dist/rn/framework-loader.js +6 -17
- package/dist/rn/iap.d.ts +1 -1
- package/dist/rn/iap.d.ts.map +1 -1
- package/dist/rn/iap.js +10 -29
- package/dist/rn/identity.d.ts.map +1 -1
- package/dist/rn/identity.js +4 -21
- package/dist/rn/index.d.ts +2 -0
- package/dist/rn/index.d.ts.map +1 -1
- package/dist/rn/index.js +2 -0
- package/dist/rn/notify-share.d.ts.map +1 -1
- package/dist/rn/notify-share.js +6 -48
- package/dist/rn/official-module.d.ts +16 -0
- package/dist/rn/official-module.d.ts.map +1 -1
- package/dist/rn/official-module.js +20 -0
- package/dist/rn/platform-loader.d.ts +4 -0
- package/dist/rn/platform-loader.d.ts.map +1 -0
- package/dist/rn/platform-loader.js +5 -0
- package/dist/rn/promotion.d.ts +9 -0
- package/dist/rn/promotion.d.ts.map +1 -0
- package/dist/rn/promotion.js +11 -0
- package/dist/rn/review.d.ts +7 -0
- package/dist/rn/review.d.ts.map +1 -0
- package/dist/rn/review.js +10 -0
- package/dist/rn/storage.d.ts.map +1 -1
- package/dist/rn/storage.js +4 -24
- package/dist/share/platform-contract.d.ts +1 -1
- package/dist/storage/platform-contract.d.ts +1 -1
- package/dist/webview/ads.d.ts +10 -0
- package/dist/webview/ads.d.ts.map +1 -0
- package/dist/webview/ads.js +14 -0
- package/dist/webview/banner-contract.d.ts +59 -0
- package/dist/webview/banner-contract.d.ts.map +1 -0
- package/dist/webview/banner-contract.js +1 -0
- package/dist/webview/banner.d.ts +15 -0
- package/dist/webview/banner.d.ts.map +1 -0
- package/dist/webview/banner.js +188 -0
- package/dist/{web → webview}/framework-loader.d.ts +1 -1
- package/dist/webview/framework-loader.d.ts.map +1 -0
- package/dist/webview/framework-loader.js +16 -0
- package/dist/{web → webview}/iap-contract.d.ts +4 -4
- package/dist/webview/iap-contract.d.ts.map +1 -0
- package/dist/webview/iap-contract.js +1 -0
- package/dist/webview/identity.d.ts +40 -0
- package/dist/webview/identity.d.ts.map +1 -0
- package/dist/webview/identity.js +70 -0
- package/dist/webview/index.d.ts +62 -0
- package/dist/webview/index.d.ts.map +1 -0
- package/dist/webview/index.js +51 -0
- package/dist/webview/notify-share.d.ts +50 -0
- package/dist/webview/notify-share.d.ts.map +1 -0
- package/dist/{web → webview}/notify-share.js +19 -59
- package/dist/webview/platform-loader.d.ts +4 -0
- package/dist/webview/platform-loader.d.ts.map +1 -0
- package/dist/webview/platform-loader.js +5 -0
- package/dist/webview/promotion.d.ts +13 -0
- package/dist/webview/promotion.d.ts.map +1 -0
- package/dist/webview/promotion.js +12 -0
- package/dist/webview/review.d.ts +11 -0
- package/dist/webview/review.d.ts.map +1 -0
- package/dist/webview/review.js +11 -0
- package/package.json +7 -3
- package/dist/web/framework-loader.d.ts.map +0 -1
- package/dist/web/framework-loader.js +0 -32
- package/dist/web/iap-contract.d.ts.map +0 -1
- package/dist/web/identity.d.ts +0 -30
- package/dist/web/identity.d.ts.map +0 -1
- package/dist/web/identity.js +0 -110
- package/dist/web/index.d.ts +0 -47
- package/dist/web/index.d.ts.map +0 -1
- package/dist/web/index.js +0 -43
- package/dist/web/notify-share.d.ts +0 -38
- package/dist/web/notify-share.d.ts.map +0 -1
- /package/dist/{web/iap-contract.js → promotion/platform-contract.js} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { resolvePlatformLoader } from "../platform-loader.js";
|
|
2
|
+
import { createWebViewPlatformLoader } from "./platform-loader.js";
|
|
3
|
+
import { SdkError } from "../index.js";
|
|
4
|
+
import { runSdkGetAnonymousKey, runSdkLogin } from "../identity/platform-contract.js";
|
|
5
|
+
import { createSdkStorageFromPlatform } from "../storage/platform-contract.js";
|
|
6
|
+
export function createWebViewIdentity(options = {}) {
|
|
7
|
+
const loader = normalizeWebViewIdentityLoader(options.framework);
|
|
8
|
+
const load = async () => {
|
|
9
|
+
const result = await loader();
|
|
10
|
+
if (!result.available) {
|
|
11
|
+
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
12
|
+
}
|
|
13
|
+
return result.module;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
login: async () => runSdkLogin(await load()),
|
|
17
|
+
getAnonymousKey: async () => runSdkGetAnonymousKey(await load())
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** SDK-backed storage for web with the same verbatim-key contract as /rn. */
|
|
21
|
+
export function createWebViewStorage(options = {}) {
|
|
22
|
+
const loader = normalizeWebViewStorageLoader(options.framework);
|
|
23
|
+
let cached;
|
|
24
|
+
let resolving;
|
|
25
|
+
const resolve = () => {
|
|
26
|
+
if (cached) {
|
|
27
|
+
return Promise.resolve(cached);
|
|
28
|
+
}
|
|
29
|
+
// Concurrent initial calls share one loader invocation so custom
|
|
30
|
+
// loaders cannot hand out independent stores.
|
|
31
|
+
if (!resolving) {
|
|
32
|
+
resolving = (async () => {
|
|
33
|
+
const result = await loader();
|
|
34
|
+
if (!result.available) {
|
|
35
|
+
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
36
|
+
}
|
|
37
|
+
cached = createSdkStorageFromPlatform(result.module);
|
|
38
|
+
return cached;
|
|
39
|
+
})();
|
|
40
|
+
resolving.catch(() => {
|
|
41
|
+
resolving = undefined;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return resolving;
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
get: async (key) => (await resolve()).get(key),
|
|
48
|
+
set: async (key, value) => (await resolve()).set(key, value),
|
|
49
|
+
remove: async (key) => (await resolve()).remove(key)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function normalizeWebViewIdentityLoader(framework) {
|
|
53
|
+
return resolvePlatformLoader(framework, createDefaultWebViewIdentityLoader);
|
|
54
|
+
}
|
|
55
|
+
function normalizeWebViewStorageLoader(framework) {
|
|
56
|
+
return resolvePlatformLoader(framework, createDefaultWebViewStorageLoader);
|
|
57
|
+
}
|
|
58
|
+
// The web SDK exposes the shared namespaced contract shapes directly, so
|
|
59
|
+
// the default loaders consume the official module without any conversion
|
|
60
|
+
// or type assertion; a failed import is never cached, successful loads are.
|
|
61
|
+
function createDefaultWebViewIdentityLoader() {
|
|
62
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }));
|
|
63
|
+
}
|
|
64
|
+
function createDefaultWebViewStorageLoader() {
|
|
65
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }));
|
|
66
|
+
}
|
|
67
|
+
/** @deprecated Use createWebViewIdentity from @ait-kit/sdk/webview. */
|
|
68
|
+
export const createWebIdentity = createWebViewIdentity;
|
|
69
|
+
/** @deprecated Use createWebViewStorage from @ait-kit/sdk/webview. */
|
|
70
|
+
export const createWebStorage = createWebViewStorage;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebView adapters for `@ait-kit/sdk`.
|
|
3
|
+
*
|
|
4
|
+
* Requires the official `@apps-in-toss/web-framework` package (declared as
|
|
5
|
+
* an optional peer): it is imported lazily at first use, so this entry
|
|
6
|
+
* never requires the React Native SDK, and the React Native entry never
|
|
7
|
+
* requires this one.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createWebViewIap } from "@ait-kit/sdk/webview";
|
|
11
|
+
*
|
|
12
|
+
* const iap = createWebViewIap({
|
|
13
|
+
* // Resolve only after YOUR server verified the order and persisted the
|
|
14
|
+
* // grant (see the ait-kit server packages for verification flows).
|
|
15
|
+
* grant: async ({ orderId, sku }) => {
|
|
16
|
+
* const response = await fetch("/api/iap/grant", {
|
|
17
|
+
* method: "POST",
|
|
18
|
+
* body: JSON.stringify({ orderId, sku })
|
|
19
|
+
* });
|
|
20
|
+
* if (!response.ok) {
|
|
21
|
+
* // Resolve-only-on-success is part of the contract: never report a
|
|
22
|
+
* // grant your server did not verify and persist.
|
|
23
|
+
* throw new Error(`grant request failed: HTTP ${response.status}`);
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
* const result = await iap.purchaseOneTime("SKU_100_COINS");
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { type IapAdapterOptions, type IapRecoveryResult } from "../iap/adapter.js";
|
|
31
|
+
import type { IapPlatformLoader, PartialIapPlatformSdk } from "../iap/platform-contract.js";
|
|
32
|
+
import type { WebViewIapFramework } from "./iap-contract.js";
|
|
33
|
+
export interface WebViewIapOptions extends Omit<IapAdapterOptions, "loader" | "orderHistoryPagination"> {
|
|
34
|
+
/**
|
|
35
|
+
* WebView framework injection: pass an `IAP` module instance or a custom
|
|
36
|
+
* loader (tests/consumers). Defaults to the lazy
|
|
37
|
+
* `import("@apps-in-toss/web-framework")` loader.
|
|
38
|
+
*/
|
|
39
|
+
framework?: WebViewIapFramework["IAP"] | PartialIapPlatformSdk | IapPlatformLoader;
|
|
40
|
+
}
|
|
41
|
+
export type WebViewIap = ReturnType<typeof createWebViewIap>;
|
|
42
|
+
export type { IapRecoveryResult };
|
|
43
|
+
export { createWebViewIdentity, type WebViewIdentity, type WebViewIdentityOptions } from "./identity.js";
|
|
44
|
+
export { createWebViewStorage, type WebViewStorageOptions } from "./identity.js";
|
|
45
|
+
export { createWebViewNotification, createWebViewShare, type WebViewNotification, type WebViewNotificationOptions, type WebViewShare, type WebViewShareOptions } from "./notify-share.js";
|
|
46
|
+
export declare function createWebViewIap(options: WebViewIapOptions): import("../iap/adapter.js").IapAdapter;
|
|
47
|
+
export { createWebViewReview, type WebViewReviewOptions } from "./review.js";
|
|
48
|
+
export { createWebViewPromotion, type WebViewPromotionOptions } from "./promotion.js";
|
|
49
|
+
/** @deprecated Use createWebViewIap from @ait-kit/sdk/webview. */
|
|
50
|
+
export declare const createWebIap: typeof createWebViewIap;
|
|
51
|
+
/** @deprecated Use WebViewIap from @ait-kit/sdk/webview. */
|
|
52
|
+
export type WebIap = WebViewIap;
|
|
53
|
+
/** @deprecated Use WebViewIapOptions from @ait-kit/sdk/webview. */
|
|
54
|
+
export type WebIapOptions = WebViewIapOptions;
|
|
55
|
+
export { createWebIdentity, createWebStorage, type WebIdentity, type WebIdentityOptions, type WebStorageOptions } from "./identity.js";
|
|
56
|
+
export { createWebNotification, createWebShare, type WebNotification, type WebNotificationOptions, type WebShare, type WebShareOptions } from "./notify-share.js";
|
|
57
|
+
export { createWebReview, type WebReviewOptions } from "./review.js";
|
|
58
|
+
export { createWebPromotion, type WebPromotionOptions } from "./promotion.js";
|
|
59
|
+
export { createWebViewAds, type WebViewAds, type WebViewAdsOptions, type SdkAdType } from "./ads.js";
|
|
60
|
+
export type { LoadFullScreenAdParams, FullScreenAdShowEvent, ShowFullScreenAdParams, FullScreenAdFunctions, FullScreenAdSupport } from "../ads/platform-contract.js";
|
|
61
|
+
export { createWebViewBannerAds, type WebViewBannerAds, type WebViewBannerAdsOptions, type WebViewBannerHandle, type WebViewBannerOptions, type WebViewBannerCallbacks, type WebViewBannerEvent, type WebViewBannerError, type WebViewBannerPlatform } from "./banner.js";
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webview/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAoB,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAE5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,wBAAwB,CAAC;IACrG;;;;OAIG;IACH,SAAS,CAAC,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAAG,qBAAqB,GAAG,iBAAiB,CAAC;CACpF;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGjF,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAE3B,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,0CAG1D;AAED,OAAO,EAAE,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,EAAE,sBAAsB,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,kEAAkE;AAClE,eAAO,MAAM,YAAY,yBAAmB,CAAC;AAC7C,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAChC,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvI,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,sBAAsB,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClK,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AACrG,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAErK,OAAO,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,KAAK,sBAAsB,EAAE,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { resolvePlatformLoader } from "../platform-loader.js";
|
|
2
|
+
/**
|
|
3
|
+
* WebView adapters for `@ait-kit/sdk`.
|
|
4
|
+
*
|
|
5
|
+
* Requires the official `@apps-in-toss/web-framework` package (declared as
|
|
6
|
+
* an optional peer): it is imported lazily at first use, so this entry
|
|
7
|
+
* never requires the React Native SDK, and the React Native entry never
|
|
8
|
+
* requires this one.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createWebViewIap } from "@ait-kit/sdk/webview";
|
|
12
|
+
*
|
|
13
|
+
* const iap = createWebViewIap({
|
|
14
|
+
* // Resolve only after YOUR server verified the order and persisted the
|
|
15
|
+
* // grant (see the ait-kit server packages for verification flows).
|
|
16
|
+
* grant: async ({ orderId, sku }) => {
|
|
17
|
+
* const response = await fetch("/api/iap/grant", {
|
|
18
|
+
* method: "POST",
|
|
19
|
+
* body: JSON.stringify({ orderId, sku })
|
|
20
|
+
* });
|
|
21
|
+
* if (!response.ok) {
|
|
22
|
+
* // Resolve-only-on-success is part of the contract: never report a
|
|
23
|
+
* // grant your server did not verify and persist.
|
|
24
|
+
* throw new Error(`grant request failed: HTTP ${response.status}`);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* const result = await iap.purchaseOneTime("SKU_100_COINS");
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import { createIapAdapter } from "../iap/adapter.js";
|
|
32
|
+
import { createDefaultWebViewFrameworkLoader } from "./framework-loader.js";
|
|
33
|
+
export { createWebViewIdentity } from "./identity.js";
|
|
34
|
+
export { createWebViewStorage } from "./identity.js";
|
|
35
|
+
// createWebViewStorage lives in identity.ts alongside the shared web loader helpers.
|
|
36
|
+
export { createWebViewNotification, createWebViewShare } from "./notify-share.js";
|
|
37
|
+
export function createWebViewIap(options) {
|
|
38
|
+
const loader = resolvePlatformLoader(options.framework, createDefaultWebViewFrameworkLoader);
|
|
39
|
+
return createIapAdapter({ ...options, loader, orderHistoryPagination: "first_page_only" });
|
|
40
|
+
}
|
|
41
|
+
export { createWebViewReview } from "./review.js";
|
|
42
|
+
export { createWebViewPromotion } from "./promotion.js";
|
|
43
|
+
/** @deprecated Use createWebViewIap from @ait-kit/sdk/webview. */
|
|
44
|
+
export const createWebIap = createWebViewIap;
|
|
45
|
+
// Compatibility exports for consumers migrating from the /web entry.
|
|
46
|
+
export { createWebIdentity, createWebStorage } from "./identity.js";
|
|
47
|
+
export { createWebNotification, createWebShare } from "./notify-share.js";
|
|
48
|
+
export { createWebReview } from "./review.js";
|
|
49
|
+
export { createWebPromotion } from "./promotion.js";
|
|
50
|
+
export { createWebViewAds } from "./ads.js";
|
|
51
|
+
export { createWebViewBannerAds } from "./banner.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type SdkNotificationAgreementResult, type SdkShareUiResult } from "../index.js";
|
|
2
|
+
import { type NotificationPlatformLoader, type NotificationPlatformSdk } from "../notification/platform-contract.js";
|
|
3
|
+
import { type SharePlatformLoader, type SharePlatformSdk } from "../share/platform-contract.js";
|
|
4
|
+
export interface WebViewNotificationOptions {
|
|
5
|
+
/**
|
|
6
|
+
* WebView framework injection: pass a module exposing Notification or a
|
|
7
|
+
* custom loader. Defaults to the lazy `import("@apps-in-toss/web-framework")`
|
|
8
|
+
* loader.
|
|
9
|
+
*/
|
|
10
|
+
framework?: NotificationPlatformSdk | NotificationPlatformLoader;
|
|
11
|
+
/** Overall deadline per agreement request (default 60000ms; 0 disables). */
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface WebViewNotification {
|
|
15
|
+
/** See ReactNativeNotification.requestAgreement for the contract. */
|
|
16
|
+
requestAgreement(templateCode: string): Promise<SdkNotificationAgreementResult>;
|
|
17
|
+
}
|
|
18
|
+
export declare function createWebViewNotification(options?: WebViewNotificationOptions): WebViewNotification;
|
|
19
|
+
export interface WebViewShareOptions {
|
|
20
|
+
/**
|
|
21
|
+
* WebView framework injection: pass a module exposing Share or a custom
|
|
22
|
+
* loader. Defaults to the lazy `import("@apps-in-toss/web-framework")`
|
|
23
|
+
* loader.
|
|
24
|
+
*/
|
|
25
|
+
framework?: SharePlatformSdk | SharePlatformLoader;
|
|
26
|
+
}
|
|
27
|
+
export interface WebViewShare {
|
|
28
|
+
/** Creates a share link for an `intoss://` deeplink path. */
|
|
29
|
+
createLink(path: string, ogImageUrl?: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Opens the native share sheet; `completed` means only that the SDK share
|
|
32
|
+
* call finished — it never proves the user shared and never grants reward
|
|
33
|
+
* eligibility.
|
|
34
|
+
*/
|
|
35
|
+
sendMessage(message: string): Promise<SdkShareUiResult>;
|
|
36
|
+
}
|
|
37
|
+
export declare function createWebViewShare(options?: WebViewShareOptions): WebViewShare;
|
|
38
|
+
/** @deprecated Use createWebViewNotification from @ait-kit/sdk/webview. */
|
|
39
|
+
export declare const createWebNotification: typeof createWebViewNotification;
|
|
40
|
+
/** @deprecated Use createWebViewShare from @ait-kit/sdk/webview. */
|
|
41
|
+
export declare const createWebShare: typeof createWebViewShare;
|
|
42
|
+
/** @deprecated Use WebViewNotification from @ait-kit/sdk/webview. */
|
|
43
|
+
export type WebNotification = WebViewNotification;
|
|
44
|
+
/** @deprecated Use WebViewNotificationOptions from @ait-kit/sdk/webview. */
|
|
45
|
+
export type WebNotificationOptions = WebViewNotificationOptions;
|
|
46
|
+
/** @deprecated Use WebViewShare from @ait-kit/sdk/webview. */
|
|
47
|
+
export type WebShare = WebViewShare;
|
|
48
|
+
/** @deprecated Use WebViewShareOptions from @ait-kit/sdk/webview. */
|
|
49
|
+
export type WebShareOptions = WebViewShareOptions;
|
|
50
|
+
//# sourceMappingURL=notify-share.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify-share.d.ts","sourceRoot":"","sources":["../../src/webview/notify-share.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAE7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAGtB,MAAM,+BAA+B,CAAC;AAIvC,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,SAAS,CAAC,EAAE,uBAAuB,GAAG,0BAA0B,CAAC;IACjE,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;CACjF;AAED,wBAAgB,yBAAyB,CAAC,OAAO,GAAE,0BAA+B,GAAG,mBAAmB,CAavG;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,CAAC;CACpD;AAED,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACzD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAwClF;AAoGD,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,kCAA4B,CAAC;AAC/D,oEAAoE;AACpE,eAAO,MAAM,cAAc,2BAAqB,CAAC;AACjD,qEAAqE;AACrE,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAClD,4EAA4E;AAC5E,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AAChE,8DAA8D;AAC9D,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AACpC,qEAAqE;AACrE,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { resolvePlatformLoader } from "../platform-loader.js";
|
|
2
|
+
import { createWebViewPlatformLoader } from "./platform-loader.js";
|
|
1
3
|
import { SdkError } from "../index.js";
|
|
2
4
|
import { runRequestAgreement } from "../notification/platform-contract.js";
|
|
3
5
|
import { runShareUi, validateSharePath } from "../share/platform-contract.js";
|
|
4
6
|
const DEFAULT_AGREEMENT_TIMEOUT_MS = 60_000;
|
|
5
|
-
export function
|
|
6
|
-
const loader =
|
|
7
|
+
export function createWebViewNotification(options = {}) {
|
|
8
|
+
const loader = normalizeWebViewNotificationLoader(options.framework);
|
|
7
9
|
const timeoutMs = options.timeoutMs ?? DEFAULT_AGREEMENT_TIMEOUT_MS;
|
|
8
10
|
return {
|
|
9
11
|
requestAgreement(templateCode) {
|
|
@@ -14,8 +16,8 @@ export function createWebNotification(options = {}) {
|
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
|
-
export function
|
|
18
|
-
const loader =
|
|
19
|
+
export function createWebViewShare(options = {}) {
|
|
20
|
+
const loader = normalizeWebViewShareLoader(options.framework);
|
|
19
21
|
const load = async () => {
|
|
20
22
|
const result = await loader();
|
|
21
23
|
if (!result.available) {
|
|
@@ -52,65 +54,19 @@ export function createWebShare(options = {}) {
|
|
|
52
54
|
}
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
return createDefaultWebNotificationLoader();
|
|
58
|
-
}
|
|
59
|
-
if (typeof framework === "function") {
|
|
60
|
-
return framework;
|
|
61
|
-
}
|
|
62
|
-
return async () => ({ available: true, module: framework });
|
|
57
|
+
function normalizeWebViewNotificationLoader(framework) {
|
|
58
|
+
return resolvePlatformLoader(framework, createDefaultWebViewNotificationLoader);
|
|
63
59
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
return createDefaultWebShareLoader();
|
|
67
|
-
}
|
|
68
|
-
if (typeof framework === "function") {
|
|
69
|
-
return framework;
|
|
70
|
-
}
|
|
71
|
-
return async () => ({ available: true, module: framework });
|
|
60
|
+
function normalizeWebViewShareLoader(framework) {
|
|
61
|
+
return resolvePlatformLoader(framework, createDefaultWebViewShareLoader);
|
|
72
62
|
}
|
|
73
|
-
// See
|
|
63
|
+
// See createDefaultWebViewIdentityLoader in ./identity.ts: the web SDK already
|
|
74
64
|
// matches the shared contract shapes, so no conversion or assertion is used.
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
return async () => {
|
|
78
|
-
if (cached) {
|
|
79
|
-
return { available: true, module: cached };
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const framework = await import("@apps-in-toss/web-framework");
|
|
83
|
-
cached = framework;
|
|
84
|
-
return { available: true, module: cached };
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
88
|
-
return {
|
|
89
|
-
available: false,
|
|
90
|
-
reason: `failed to import @apps-in-toss/web-framework: ${message}`
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
};
|
|
65
|
+
function createDefaultWebViewNotificationLoader() {
|
|
66
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }));
|
|
94
67
|
}
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
return async () => {
|
|
98
|
-
if (cached) {
|
|
99
|
-
return { available: true, module: cached };
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const framework = await import("@apps-in-toss/web-framework");
|
|
103
|
-
cached = framework;
|
|
104
|
-
return { available: true, module: cached };
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
-
return {
|
|
109
|
-
available: false,
|
|
110
|
-
reason: `failed to import @apps-in-toss/web-framework: ${message}`
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
};
|
|
68
|
+
function createDefaultWebViewShareLoader() {
|
|
69
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }));
|
|
114
70
|
}
|
|
115
71
|
/**
|
|
116
72
|
* Same loader-covering deadline as the React Native adapter; see
|
|
@@ -174,3 +130,7 @@ async function loadNotificationPlatform(loader) {
|
|
|
174
130
|
}
|
|
175
131
|
return result.module;
|
|
176
132
|
}
|
|
133
|
+
/** @deprecated Use createWebViewNotification from @ait-kit/sdk/webview. */
|
|
134
|
+
export const createWebNotification = createWebViewNotification;
|
|
135
|
+
/** @deprecated Use createWebViewShare from @ait-kit/sdk/webview. */
|
|
136
|
+
export const createWebShare = createWebViewShare;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PlatformLoader, type PlatformLoadResult } from "../platform-loader.js";
|
|
2
|
+
/** Lazy platform-local import followed by capability-specific selection. */
|
|
3
|
+
export declare function createWebViewPlatformLoader<T>(select: (module: typeof import("@apps-in-toss/web-framework")) => PlatformLoadResult<T>, includeErrorDetails?: boolean): PlatformLoader<T>;
|
|
4
|
+
//# sourceMappingURL=platform-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-loader.d.ts","sourceRoot":"","sources":["../../src/webview/platform-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACvI,4EAA4E;AAC5E,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,6BAA6B,CAAC,KAAK,kBAAkB,CAAC,CAAC,CAAC,EACvF,mBAAmB,UAAO,GACzB,cAAc,CAAC,CAAC,CAAC,CAKnB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createCachedPlatformLoader, frameworkImportError } from "../platform-loader.js";
|
|
2
|
+
/** Lazy platform-local import followed by capability-specific selection. */
|
|
3
|
+
export function createWebViewPlatformLoader(select, includeErrorDetails = true) {
|
|
4
|
+
return createCachedPlatformLoader(async () => select(await import("@apps-in-toss/web-framework")), error => frameworkImportError("@apps-in-toss/web-framework", error, includeErrorDetails));
|
|
5
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PromotionAdapter, PromotionPlatformLoader, PromotionPlatformSdk } from "../promotion/platform-contract.js";
|
|
2
|
+
export interface WebViewPromotionOptions {
|
|
3
|
+
/** Shared Promotion contract or async loader; defaults to the official SDK. */
|
|
4
|
+
framework?: PromotionPlatformSdk | PromotionPlatformLoader;
|
|
5
|
+
/** Overall wait deadline; 0 (default) disables it. Timeout does not cancel payment. */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function createWebViewPromotion(options?: WebViewPromotionOptions): PromotionAdapter;
|
|
9
|
+
/** @deprecated Use createWebViewPromotion from @ait-kit/sdk/webview. */
|
|
10
|
+
export declare const createWebPromotion: typeof createWebViewPromotion;
|
|
11
|
+
/** @deprecated Use WebViewPromotionOptions from @ait-kit/sdk/webview. */
|
|
12
|
+
export type WebPromotionOptions = WebViewPromotionOptions;
|
|
13
|
+
//# sourceMappingURL=promotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/webview/promotion.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzH,MAAM,WAAW,uBAAuB;IACtC,+EAA+E;IAC/E,SAAS,CAAC,EAAE,oBAAoB,GAAG,uBAAuB,CAAC;IAC3D,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAE9F;AAOD,wEAAwE;AACxE,eAAO,MAAM,kBAAkB,+BAAyB,CAAC;AACzD,yEAAyE;AACzE,MAAM,MAAM,mBAAmB,GAAG,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { resolvePlatformLoader } from "../platform-loader.js";
|
|
2
|
+
import { createWebViewPlatformLoader } from "./platform-loader.js";
|
|
3
|
+
import { createPromotionAdapter } from "../promotion/adapter.js";
|
|
4
|
+
export function createWebViewPromotion(options = {}) {
|
|
5
|
+
return createPromotionAdapter(resolvePlatformLoader(options.framework, createDefaultPromotionLoader), options.timeoutMs);
|
|
6
|
+
}
|
|
7
|
+
/** Keep import diagnostics redacted for direct-promotion operations. */
|
|
8
|
+
function createDefaultPromotionLoader() {
|
|
9
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }), false);
|
|
10
|
+
}
|
|
11
|
+
/** @deprecated Use createWebViewPromotion from @ait-kit/sdk/webview. */
|
|
12
|
+
export const createWebPromotion = createWebViewPromotion;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReviewAdapter, ReviewPlatformLoader, ReviewPlatformSdk } from "../review/platform-contract.js";
|
|
2
|
+
export interface WebViewReviewOptions {
|
|
3
|
+
/** Shared contract injection, or a loader; defaults to the lazy official SDK. */
|
|
4
|
+
framework?: ReviewPlatformSdk | ReviewPlatformLoader;
|
|
5
|
+
}
|
|
6
|
+
export declare function createWebViewReview(options?: WebViewReviewOptions): ReviewAdapter;
|
|
7
|
+
/** @deprecated Use createWebViewReview from @ait-kit/sdk/webview. */
|
|
8
|
+
export declare const createWebReview: typeof createWebViewReview;
|
|
9
|
+
/** @deprecated Use WebViewReviewOptions from @ait-kit/sdk/webview. */
|
|
10
|
+
export type WebReviewOptions = WebViewReviewOptions;
|
|
11
|
+
//# sourceMappingURL=review.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../../src/webview/review.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAE7G,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,SAAS,CAAC,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;CACtD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAErF;AAMD,qEAAqE;AACrE,eAAO,MAAM,eAAe,4BAAsB,CAAC;AACnD,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { resolvePlatformLoader } from "../platform-loader.js";
|
|
2
|
+
import { createWebViewPlatformLoader } from "./platform-loader.js";
|
|
3
|
+
import { createReviewAdapter } from "../review/adapter.js";
|
|
4
|
+
export function createWebViewReview(options = {}) {
|
|
5
|
+
return createReviewAdapter(resolvePlatformLoader(options.framework, createDefaultReviewLoader));
|
|
6
|
+
}
|
|
7
|
+
function createDefaultReviewLoader() {
|
|
8
|
+
return createWebViewPlatformLoader(module => ({ available: true, module: module }), false);
|
|
9
|
+
}
|
|
10
|
+
/** @deprecated Use createWebViewReview from @ait-kit/sdk/webview. */
|
|
11
|
+
export const createWebReview = createWebViewReview;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ait-kit/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Frontend SDK adapters for Apps in Toss mini apps: shared contracts plus per-runtime entry points.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,12 @@
|
|
|
35
35
|
"import": "./dist/rn/index.js"
|
|
36
36
|
},
|
|
37
37
|
"./web": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/
|
|
38
|
+
"types": "./dist/webview/index.d.ts",
|
|
39
|
+
"import": "./dist/webview/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./webview": {
|
|
42
|
+
"types": "./dist/webview/index.d.ts",
|
|
43
|
+
"import": "./dist/webview/index.js"
|
|
40
44
|
}
|
|
41
45
|
},
|
|
42
46
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framework-loader.d.ts","sourceRoot":"","sources":["../../src/web/framework-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;;;;GAKG;AACH,wBAAgB,+BAA+B,IAAI,iBAAiB,CAwBnE"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default lazy loader for the official web SDK: imports
|
|
3
|
-
* `@apps-in-toss/web-framework` (an optional peer) only when an IAP
|
|
4
|
-
* operation needs it. Failed imports are never cached, so a later call
|
|
5
|
-
* retries; successful loads are cached.
|
|
6
|
-
*/
|
|
7
|
-
export function createDefaultWebFrameworkLoader() {
|
|
8
|
-
let cached;
|
|
9
|
-
return async () => {
|
|
10
|
-
if (cached) {
|
|
11
|
-
return { available: true, module: cached };
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const framework = (await import("@apps-in-toss/web-framework"));
|
|
15
|
-
const iap = framework.IAP;
|
|
16
|
-
if (typeof iap !== "object" || iap === null) {
|
|
17
|
-
return {
|
|
18
|
-
available: false,
|
|
19
|
-
reason: "@apps-in-toss/web-framework does not expose an IAP domain"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// Per-operation capability is validated at each call site: an
|
|
23
|
-
// installed version may expose some IAP functions but not others.
|
|
24
|
-
cached = iap;
|
|
25
|
-
return { available: true, module: cached };
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
-
return { available: false, reason: `failed to import @apps-in-toss/web-framework: ${message}` };
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iap-contract.d.ts","sourceRoot":"","sources":["../../src/web/iap-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,YAAY,CAAC;CACnB,CAAC"}
|
package/dist/web/identity.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type SdkAnonymousKey, type SdkLoginResult, type SdkStorage } from "../index.js";
|
|
2
|
-
import { type IdentityPlatformLoader, type IdentityPlatformSdk } from "../identity/platform-contract.js";
|
|
3
|
-
import { type StoragePlatformLoader, type StoragePlatformSdk } from "../storage/platform-contract.js";
|
|
4
|
-
export interface WebIdentityOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Web framework injection: pass a module exposing TossAuth/User or a
|
|
7
|
-
* custom loader (tests, dev replacements). Defaults to the lazy
|
|
8
|
-
* `import("@apps-in-toss/web-framework")` loader. The default never
|
|
9
|
-
* guesses the environment or substitutes a fake login.
|
|
10
|
-
*/
|
|
11
|
-
framework?: IdentityPlatformSdk | IdentityPlatformLoader;
|
|
12
|
-
}
|
|
13
|
-
export interface WebIdentity {
|
|
14
|
-
/** Starts the platform login and validates/preserves the result. */
|
|
15
|
-
login(): Promise<SdkLoginResult>;
|
|
16
|
-
/** Looks up the SDK-issued anonymous key; never fabricates one. */
|
|
17
|
-
getAnonymousKey(): Promise<SdkAnonymousKey>;
|
|
18
|
-
}
|
|
19
|
-
export declare function createWebIdentity(options?: WebIdentityOptions): WebIdentity;
|
|
20
|
-
export interface WebStorageOptions {
|
|
21
|
-
/**
|
|
22
|
-
* Web framework injection: pass a module exposing Storage or a custom
|
|
23
|
-
* loader. Defaults to the lazy `import("@apps-in-toss/web-framework")`
|
|
24
|
-
* loader.
|
|
25
|
-
*/
|
|
26
|
-
framework?: StoragePlatformSdk | StoragePlatformLoader;
|
|
27
|
-
}
|
|
28
|
-
/** SDK-backed storage for web with the same verbatim-key contract as /rn. */
|
|
29
|
-
export declare function createWebStorage(options?: WebStorageOptions): SdkStorage;
|
|
30
|
-
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/web/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EAGzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACxB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,mBAAmB,GAAG,sBAAsB,CAAC;CAC1D;AAED,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;IACjC,mEAAmE;IACnE,eAAe,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7C;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CAa/E;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,SAAS,CAAC,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;CACxD;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CA8B5E"}
|
package/dist/web/identity.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { SdkError } from "../index.js";
|
|
2
|
-
import { runSdkGetAnonymousKey, runSdkLogin } from "../identity/platform-contract.js";
|
|
3
|
-
import { createSdkStorageFromPlatform } from "../storage/platform-contract.js";
|
|
4
|
-
export function createWebIdentity(options = {}) {
|
|
5
|
-
const loader = normalizeWebIdentityLoader(options.framework);
|
|
6
|
-
const load = async () => {
|
|
7
|
-
const result = await loader();
|
|
8
|
-
if (!result.available) {
|
|
9
|
-
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
10
|
-
}
|
|
11
|
-
return result.module;
|
|
12
|
-
};
|
|
13
|
-
return {
|
|
14
|
-
login: async () => runSdkLogin(await load()),
|
|
15
|
-
getAnonymousKey: async () => runSdkGetAnonymousKey(await load())
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/** SDK-backed storage for web with the same verbatim-key contract as /rn. */
|
|
19
|
-
export function createWebStorage(options = {}) {
|
|
20
|
-
const loader = normalizeWebStorageLoader(options.framework);
|
|
21
|
-
let cached;
|
|
22
|
-
let resolving;
|
|
23
|
-
const resolve = () => {
|
|
24
|
-
if (cached) {
|
|
25
|
-
return Promise.resolve(cached);
|
|
26
|
-
}
|
|
27
|
-
// Concurrent initial calls share one loader invocation so custom
|
|
28
|
-
// loaders cannot hand out independent stores.
|
|
29
|
-
if (!resolving) {
|
|
30
|
-
resolving = (async () => {
|
|
31
|
-
const result = await loader();
|
|
32
|
-
if (!result.available) {
|
|
33
|
-
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
34
|
-
}
|
|
35
|
-
cached = createSdkStorageFromPlatform(result.module);
|
|
36
|
-
return cached;
|
|
37
|
-
})();
|
|
38
|
-
resolving.catch(() => {
|
|
39
|
-
resolving = undefined;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return resolving;
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
get: async (key) => (await resolve()).get(key),
|
|
46
|
-
set: async (key, value) => (await resolve()).set(key, value),
|
|
47
|
-
remove: async (key) => (await resolve()).remove(key)
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function normalizeWebIdentityLoader(framework) {
|
|
51
|
-
if (!framework) {
|
|
52
|
-
return createDefaultWebIdentityLoader();
|
|
53
|
-
}
|
|
54
|
-
if (typeof framework === "function") {
|
|
55
|
-
return framework;
|
|
56
|
-
}
|
|
57
|
-
return async () => ({ available: true, module: framework });
|
|
58
|
-
}
|
|
59
|
-
function normalizeWebStorageLoader(framework) {
|
|
60
|
-
if (!framework) {
|
|
61
|
-
return createDefaultWebStorageLoader();
|
|
62
|
-
}
|
|
63
|
-
if (typeof framework === "function") {
|
|
64
|
-
return framework;
|
|
65
|
-
}
|
|
66
|
-
return async () => ({ available: true, module: framework });
|
|
67
|
-
}
|
|
68
|
-
// The web SDK exposes the shared namespaced contract shapes directly, so
|
|
69
|
-
// the default loaders consume the official module without any conversion
|
|
70
|
-
// or type assertion; a failed import is never cached, successful loads are.
|
|
71
|
-
function createDefaultWebIdentityLoader() {
|
|
72
|
-
let cached;
|
|
73
|
-
return async () => {
|
|
74
|
-
if (cached) {
|
|
75
|
-
return { available: true, module: cached };
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const framework = await import("@apps-in-toss/web-framework");
|
|
79
|
-
cached = framework;
|
|
80
|
-
return { available: true, module: cached };
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
-
return {
|
|
85
|
-
available: false,
|
|
86
|
-
reason: `failed to import @apps-in-toss/web-framework: ${message}`
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function createDefaultWebStorageLoader() {
|
|
92
|
-
let cached;
|
|
93
|
-
return async () => {
|
|
94
|
-
if (cached) {
|
|
95
|
-
return { available: true, module: cached };
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const framework = await import("@apps-in-toss/web-framework");
|
|
99
|
-
cached = framework;
|
|
100
|
-
return { available: true, module: cached };
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
-
return {
|
|
105
|
-
available: false,
|
|
106
|
-
reason: `failed to import @apps-in-toss/web-framework: ${message}`
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|