@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
package/dist/iap/adapter.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SdkError } from "../index.js";
|
|
2
2
|
import { IapGrantCoordinator } from "./grant-coordinator.js";
|
|
3
3
|
import {} from "./platform-contract.js";
|
|
4
|
+
import { queryOrderHistory } from "./order-history.js";
|
|
5
|
+
import { querySubscriptionInfo } from "./subscription-info.js";
|
|
4
6
|
import { runPurchaseFlow } from "./purchase-flow.js";
|
|
5
7
|
const DEFAULT_PURCHASE_TIMEOUT_MS = 180_000;
|
|
6
8
|
/**
|
|
@@ -34,6 +36,17 @@ export function createIapAdapter(options) {
|
|
|
34
36
|
return fn;
|
|
35
37
|
};
|
|
36
38
|
return {
|
|
39
|
+
async getCompletedOrRefundedOrders(params) {
|
|
40
|
+
return queryOrderHistory(load, options.orderHistoryPagination, params);
|
|
41
|
+
},
|
|
42
|
+
async getSubscriptionInfo(orderId) {
|
|
43
|
+
if (typeof orderId !== "string" || !orderId.trim()) {
|
|
44
|
+
throw new SdkError("INVALID_IAP_INPUT", "orderId must be a non-empty string");
|
|
45
|
+
}
|
|
46
|
+
const platform = await load();
|
|
47
|
+
ensureOperation(platform.getSubscriptionInfo, "getSubscriptionInfo");
|
|
48
|
+
return querySubscriptionInfo(platform, orderId);
|
|
49
|
+
},
|
|
37
50
|
async getProductItemList() {
|
|
38
51
|
const platform = await load();
|
|
39
52
|
ensureOperation(platform.getProductItemList, "getProductItemList");
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IapOrderHistoryPage } from "../index.js";
|
|
2
|
+
import { type PartialIapPlatformSdk } from "./platform-contract.js";
|
|
3
|
+
export declare function queryOrderHistory(load: () => Promise<PartialIapPlatformSdk>, pagination: IapOrderHistoryPage["pagination"], params?: {
|
|
4
|
+
key?: string | null;
|
|
5
|
+
}): Promise<IapOrderHistoryPage>;
|
|
6
|
+
//# sourceMappingURL=order-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-history.d.ts","sourceRoot":"","sources":["../../src/iap/order-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,mBAAmB,EAAoC,MAAM,aAAa,CAAC;AACnG,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,EAC1C,UAAU,EAAE,mBAAmB,CAAC,YAAY,CAAC,EAC7C,MAAM,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAyC9B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SdkError } from "../index.js";
|
|
2
|
+
import { toIapErrorCode } from "./platform-contract.js";
|
|
3
|
+
export async function queryOrderHistory(load, pagination, params) {
|
|
4
|
+
if (params !== undefined && (!isRecord(params) || Array.isArray(params))) {
|
|
5
|
+
throw new SdkError("INVALID_IAP_INPUT", "history params must be an object with an optional key");
|
|
6
|
+
}
|
|
7
|
+
const key = params?.key;
|
|
8
|
+
if (key !== undefined && key !== null && (typeof key !== "string" || !key.trim())) {
|
|
9
|
+
throw new SdkError("INVALID_IAP_INPUT", "history key must be a non-empty string or null");
|
|
10
|
+
}
|
|
11
|
+
if (pagination === "first_page_only" && key !== undefined && key !== null) {
|
|
12
|
+
throw new SdkError("UNSUPPORTED", "the WebView SDK only supports the first order history page");
|
|
13
|
+
}
|
|
14
|
+
const platform = await load();
|
|
15
|
+
const query = platform.getCompletedOrRefundedOrders;
|
|
16
|
+
if (typeof query !== "function" || (typeof query.isSupported === "function" && !query.isSupported())) {
|
|
17
|
+
throw new SdkError("UNSUPPORTED", "order history is not supported on this app version");
|
|
18
|
+
}
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
// WebView's official function takes no arguments; never send a fabricated cursor.
|
|
22
|
+
result = pagination === "cursor" && key !== undefined
|
|
23
|
+
? await query.call(platform, { key })
|
|
24
|
+
: await query.call(platform);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (toIapErrorCode(error) === "UNSUPPORTED_APP_VERSION") {
|
|
28
|
+
throw new SdkError("UNSUPPORTED", "order history is not supported on this app version", { cause: error });
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
if (result === undefined)
|
|
33
|
+
throw new SdkError("UNSUPPORTED", "order history is not supported on this app version");
|
|
34
|
+
if (!isRecord(result) || typeof result.hasNext !== "boolean" || !Array.isArray(result.orders) ||
|
|
35
|
+
(result.nextKey !== undefined && result.nextKey !== null &&
|
|
36
|
+
(typeof result.nextKey !== "string" || !result.nextKey.trim())) ||
|
|
37
|
+
!result.orders.every(isOrder)) {
|
|
38
|
+
throw new SdkError("INVALID_IAP_RESULT", "the provider returned malformed order history");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
orders: result.orders.map(order => ({ orderId: order.orderId, sku: order.sku, status: order.status, date: order.date })),
|
|
42
|
+
hasNext: result.hasNext,
|
|
43
|
+
...(result.nextKey !== undefined ? { nextKey: result.nextKey } : {}),
|
|
44
|
+
pagination
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function isRecord(value) {
|
|
48
|
+
return typeof value === "object" && value !== null;
|
|
49
|
+
}
|
|
50
|
+
function isOrder(value) {
|
|
51
|
+
return isRecord(value) && typeof value.orderId === "string" && !!value.orderId.trim() &&
|
|
52
|
+
typeof value.sku === "string" && !!value.sku.trim() && typeof value.date === "string" && !!value.date.trim() &&
|
|
53
|
+
(value.status === "COMPLETED" || value.status === "REFUNDED");
|
|
54
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Internal platform contract shared by the /rn and /
|
|
2
|
+
* Internal platform contract shared by the /rn and /webview IAP adapters.
|
|
3
3
|
* Each entry point declares its own structural copy of the official SDK
|
|
4
4
|
* surface (they are different npm packages with identical Domains API
|
|
5
5
|
* shapes); this module is the common, platform-neutral engine boundary and
|
|
@@ -20,6 +20,14 @@ type WithSupport<F> = F & {
|
|
|
20
20
|
isSupported?: () => boolean;
|
|
21
21
|
};
|
|
22
22
|
export interface IapPlatformSdk {
|
|
23
|
+
getCompletedOrRefundedOrders: WithSupport<(params?: {
|
|
24
|
+
key?: string | null;
|
|
25
|
+
}) => Promise<unknown>>;
|
|
26
|
+
getSubscriptionInfo: WithSupport<(args: {
|
|
27
|
+
params: {
|
|
28
|
+
orderId: string;
|
|
29
|
+
};
|
|
30
|
+
}) => Promise<unknown>>;
|
|
23
31
|
getProductItemList: WithSupport<() => Promise<{
|
|
24
32
|
products: IapProduct[];
|
|
25
33
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-contract.d.ts","sourceRoot":"","sources":["../../src/iap/platform-contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,UAAU,EACV,6BAA6B,EAC9B,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,2EAA2E;AAC3E,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,OAAO,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,kBAAkB,EAAE,WAAW,CAAC,MAAM,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC,CAAC,CAAC;IAC3E,0BAA0B,EAAE,WAAW,CAAC,CAAC,MAAM,EAAE,wBAAwB,KAAK,MAAM,IAAI,CAAC,CAAC;IAC1F,+BAA+B,EAAE,WAAW,CAC1C,CAAC,MAAM,EAAE,6BAA6B,KAAK,MAAM,IAAI,CACtD,CAAC;IACF,gBAAgB,EAAE,WAAW,CAAC,MAAM,OAAO,CAAC;QAAE,MAAM,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC,CAAC,CAAC;IAC5E,oBAAoB,EAAE,WAAW,CAC/B,CAAC,IAAI,EAA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,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMjE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Internal platform contract shared by the /rn and /
|
|
2
|
+
* Internal platform contract shared by the /rn and /webview IAP adapters.
|
|
3
3
|
* Each entry point declares its own structural copy of the official SDK
|
|
4
4
|
* surface (they are different npm packages with identical Domains API
|
|
5
5
|
* shapes); this module is the common, platform-neutral engine boundary and
|
|
@@ -11,7 +11,7 @@ export interface PurchaseFlowOptions {
|
|
|
11
11
|
timeoutMs: number;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Shared purchase flow for the /rn and /
|
|
14
|
+
* Shared purchase flow for the /rn and /webview IAP adapters, built on the
|
|
15
15
|
* common event-flow base:
|
|
16
16
|
*
|
|
17
17
|
* - The platform's `processProductGrant` slot wraps the consumer-injected
|
|
@@ -2,7 +2,7 @@ import { runEventFlow } from "../event-flow.js";
|
|
|
2
2
|
import {} from "./grant-coordinator.js";
|
|
3
3
|
import { toIapErrorCode, toIapErrorMessage } from "./platform-contract.js";
|
|
4
4
|
/**
|
|
5
|
-
* Shared purchase flow for the /rn and /
|
|
5
|
+
* Shared purchase flow for the /rn and /webview IAP adapters, built on the
|
|
6
6
|
* common event-flow base:
|
|
7
7
|
*
|
|
8
8
|
* - The platform's `processProductGrant` slot wraps the consumer-injected
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IapSubscriptionInfo } from "../index.js";
|
|
2
|
+
import { type PartialIapPlatformSdk } from "./platform-contract.js";
|
|
3
|
+
export declare function querySubscriptionInfo(platform: PartialIapPlatformSdk, orderId: string): Promise<{
|
|
4
|
+
subscription: IapSubscriptionInfo;
|
|
5
|
+
}>;
|
|
6
|
+
//# sourceMappingURL=subscription-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-info.d.ts","sourceRoot":"","sources":["../../src/iap/subscription-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,mBAAmB,CAAA;CAAE,CAAC,CA2B5I"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SdkError } from "../index.js";
|
|
2
|
+
import { toIapErrorCode } from "./platform-contract.js";
|
|
3
|
+
export async function querySubscriptionInfo(platform, orderId) {
|
|
4
|
+
let result;
|
|
5
|
+
try {
|
|
6
|
+
result = await platform.getSubscriptionInfo({ params: { orderId } });
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (toIapErrorCode(error) === "UNSUPPORTED_APP_VERSION") {
|
|
10
|
+
throw new SdkError("UNSUPPORTED", "subscription queries are not supported on this app version", { cause: error });
|
|
11
|
+
}
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
// The RN SDK returns undefined on unsupported host versions.
|
|
15
|
+
if (result === undefined)
|
|
16
|
+
throw new SdkError("UNSUPPORTED", "subscription queries are not supported on this app version");
|
|
17
|
+
const info = isRecord(result) ? result.subscription : undefined;
|
|
18
|
+
if (!isRecord(info) || typeof info.catalogId !== "number" || !Number.isFinite(info.catalogId) ||
|
|
19
|
+
typeof info.status !== "string" || !info.status.trim() ||
|
|
20
|
+
!nullableString(info.expiresAt) || !nullableString(info.gracePeriodExpiresAt) ||
|
|
21
|
+
typeof info.isAutoRenew !== "boolean" || typeof info.isAccessible !== "boolean") {
|
|
22
|
+
throw new SdkError("INVALID_IAP_RESULT", "the provider returned malformed subscription information");
|
|
23
|
+
}
|
|
24
|
+
return { subscription: {
|
|
25
|
+
catalogId: info.catalogId,
|
|
26
|
+
status: info.status,
|
|
27
|
+
expiresAt: info.expiresAt,
|
|
28
|
+
isAutoRenew: info.isAutoRenew,
|
|
29
|
+
gracePeriodExpiresAt: info.gracePeriodExpiresAt,
|
|
30
|
+
isAccessible: info.isAccessible
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
function isRecord(value) {
|
|
34
|
+
return typeof value === "object" && value !== null;
|
|
35
|
+
}
|
|
36
|
+
function nullableString(value) {
|
|
37
|
+
return value === null || typeof value === "string";
|
|
38
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type SdkAnonymousKey, type SdkLoginResult } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Internal platform contract for the login/anonymous-identity adapters,
|
|
4
|
-
* shared by /rn and /
|
|
4
|
+
* shared by /rn and /webview. Each entry declares its own structural copy of
|
|
5
5
|
* the official SDK surface; this module is the common engine boundary and
|
|
6
6
|
* is never exported from a public subpath.
|
|
7
7
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The root entry is runtime-neutral: common types and errors only, with no
|
|
5
5
|
* imports of any official runtime SDK. Runtime adapters live in subpaths —
|
|
6
|
-
* `@ait-kit/sdk/rn` for React Native
|
|
6
|
+
* `@ait-kit/sdk/rn` for React Native and `@ait-kit/sdk/webview` for WebView.
|
|
7
7
|
*/
|
|
8
8
|
/** Reward payload reported by rewarded ad flows. */
|
|
9
9
|
export interface AdReward {
|
|
@@ -28,7 +28,7 @@ export type AdShowResult = {
|
|
|
28
28
|
reason?: string;
|
|
29
29
|
};
|
|
30
30
|
/** Stable error codes for SDK adapter failures. */
|
|
31
|
-
export type SdkErrorCode = "SDK_UNAVAILABLE" | "UNSUPPORTED" | "AD_NOT_LOADED" | "AD_ALREADY_SHOWING" | "AD_LOAD_FAILED" | "AD_LOAD_TIMEOUT" | "INVALID_LOGIN_RESULT" | "INVALID_ANONYMOUS_KEY" | "INVALID_SHARE_PATH";
|
|
31
|
+
export type SdkErrorCode = "SDK_UNAVAILABLE" | "UNSUPPORTED" | "AD_NOT_LOADED" | "AD_ALREADY_SHOWING" | "AD_LOAD_FAILED" | "AD_LOAD_TIMEOUT" | "INVALID_BANNER_INPUT" | "BANNER_INIT_TIMEOUT" | "BANNER_TARGET_IN_USE" | "BANNER_ATTACH_FAILED" | "INVALID_IAP_INPUT" | "INVALID_IAP_RESULT" | "INVALID_LOGIN_RESULT" | "INVALID_ANONYMOUS_KEY" | "INVALID_PROMOTION_INPUT" | "PROMOTION_IN_PROGRESS" | "INVALID_SHARE_PATH";
|
|
32
32
|
/** Terminal agreement outcomes delivered by the platform event. */
|
|
33
33
|
export type SdkNotificationAgreementType = "newAgreement" | "alreadyAgreed" | "agreementRejected";
|
|
34
34
|
/**
|
|
@@ -95,7 +95,7 @@ export interface SdkAnonymousKey {
|
|
|
95
95
|
type: "HASH";
|
|
96
96
|
hash: string;
|
|
97
97
|
}
|
|
98
|
-
/** Minimal storage contract shared by the /rn and /
|
|
98
|
+
/** Minimal storage contract shared by the /rn and /webview adapters. */
|
|
99
99
|
export interface SdkStorage {
|
|
100
100
|
/** Resolves the stored string, or null when the key has no value. */
|
|
101
101
|
get(key: string): Promise<string | null>;
|
|
@@ -214,4 +214,31 @@ export declare class SdkError extends Error {
|
|
|
214
214
|
cause?: unknown;
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
export type { ReviewAdapter } from "./review/platform-contract.js";
|
|
218
|
+
export type { PromotionAdapter, PromotionSupport, PromotionGrantInput, PromotionGrantResult } from "./promotion/platform-contract.js";
|
|
219
|
+
/** Provider subscription state; unknown future states are preserved without inference. */
|
|
220
|
+
export type IapSubscriptionStatus = "ACTIVE" | "EXPIRED" | "IN_GRACE_PERIOD" | "ON_HOLD" | "PAUSED" | "REVOKED" | (string & {});
|
|
221
|
+
/** Provider snapshot only; server verification remains the source of entitlement decisions. */
|
|
222
|
+
export interface IapSubscriptionInfo {
|
|
223
|
+
catalogId: number;
|
|
224
|
+
status: IapSubscriptionStatus;
|
|
225
|
+
expiresAt: string | null;
|
|
226
|
+
isAutoRenew: boolean;
|
|
227
|
+
gracePeriodExpiresAt: string | null;
|
|
228
|
+
isAccessible: boolean;
|
|
229
|
+
}
|
|
230
|
+
/** One completed purchase or refund reported by the provider. */
|
|
231
|
+
export interface IapCompletedOrRefundedOrder {
|
|
232
|
+
orderId: string;
|
|
233
|
+
sku: string;
|
|
234
|
+
status: "COMPLETED" | "REFUNDED";
|
|
235
|
+
date: string;
|
|
236
|
+
}
|
|
237
|
+
export interface IapOrderHistoryPage {
|
|
238
|
+
orders: IapCompletedOrRefundedOrder[];
|
|
239
|
+
hasNext: boolean;
|
|
240
|
+
nextKey?: string | null;
|
|
241
|
+
/** WebView currently exposes only the first page, even when hasNext is true. */
|
|
242
|
+
pagination: "cursor" | "first_page_only";
|
|
243
|
+
}
|
|
217
244
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oDAAoD;AACpD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,GACxC;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GACvB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,mDAAmD;AACnD,MAAM,MAAM,YAAY,GACpB,iBAAiB,GACjB,aAAa,GACb,eAAe,GACf,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,sBAAsB,GACtB,uBAAuB,GACvB,oBAAoB,CAAC;AAMzB,mEAAm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,MAAM,GAAG,IAAI,CAAC;IACxB,gFAAgF;IAChF,UAAU,EAAE,QAAQ,GAAG,iBAAiB,CAAC;CAC1C"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The root entry is runtime-neutral: common types and errors only, with no
|
|
5
5
|
* imports of any official runtime SDK. Runtime adapters live in subpaths —
|
|
6
|
-
* `@ait-kit/sdk/rn` for React Native
|
|
6
|
+
* `@ait-kit/sdk/rn` for React Native and `@ait-kit/sdk/webview` for WebView.
|
|
7
7
|
*/
|
|
8
8
|
/** Typed error surfaced by the SDK adapters. */
|
|
9
9
|
export class SdkError extends Error {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SdkNotificationAgreementResult } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Internal platform contract for the notification-agreement adapter,
|
|
4
|
-
* shared by /rn and /
|
|
4
|
+
* shared by /rn and /webview (never exported from a public subpath).
|
|
5
5
|
*/
|
|
6
6
|
export interface NotificationAgreementParams {
|
|
7
7
|
options: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Internal runtime-neutral loader primitives; no official SDK is imported here. */
|
|
2
|
+
export type PlatformLoadResult<T> = {
|
|
3
|
+
available: true;
|
|
4
|
+
module: T;
|
|
5
|
+
} | {
|
|
6
|
+
available: false;
|
|
7
|
+
reason: string;
|
|
8
|
+
};
|
|
9
|
+
export type PlatformLoader<T> = () => Promise<PlatformLoadResult<T>>;
|
|
10
|
+
/** Preserve injected loaders verbatim and construct defaults only when needed. */
|
|
11
|
+
export declare function resolvePlatformLoader<T>(framework: T | PlatformLoader<T> | undefined, createDefault: () => PlatformLoader<T>): PlatformLoader<T>;
|
|
12
|
+
/** Cache only successful selections; unavailable results and thrown loads retry. */
|
|
13
|
+
export declare function createCachedPlatformLoader<T>(load: PlatformLoader<T>, errorReason: (error: unknown) => string): PlatformLoader<T>;
|
|
14
|
+
/** Preserve existing diagnostic detail policies chosen by each adapter. */
|
|
15
|
+
export declare function frameworkImportError(packageName: string, error: unknown, includeDetails: boolean): string;
|
|
16
|
+
//# sourceMappingURL=platform-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-loader.d.ts","sourceRoot":"","sources":["../src/platform-loader.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAC5B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,GAC9B;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AACzC,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,SAAS,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,EAC5C,aAAa,EAAE,MAAM,cAAc,CAAC,CAAC,CAAC,GACrC,cAAc,CAAC,CAAC,CAAC,CAInB;AAED,oFAAoF;AACpF,wBAAgB,0BAA0B,CAAC,CAAC,EAC1C,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACtC,cAAc,CAAC,CAAC,CAAC,CAcnB;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,GAAG,MAAM,CAKzG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Preserve injected loaders verbatim and construct defaults only when needed. */
|
|
2
|
+
export function resolvePlatformLoader(framework, createDefault) {
|
|
3
|
+
if (!framework)
|
|
4
|
+
return createDefault();
|
|
5
|
+
if (typeof framework === "function")
|
|
6
|
+
return framework;
|
|
7
|
+
return async () => ({ available: true, module: framework });
|
|
8
|
+
}
|
|
9
|
+
/** Cache only successful selections; unavailable results and thrown loads retry. */
|
|
10
|
+
export function createCachedPlatformLoader(load, errorReason) {
|
|
11
|
+
let cached;
|
|
12
|
+
return async () => {
|
|
13
|
+
if (cached)
|
|
14
|
+
return { available: true, module: cached.module };
|
|
15
|
+
try {
|
|
16
|
+
const result = await load();
|
|
17
|
+
// Keep the cache independent from the mutable result envelope returned
|
|
18
|
+
// to callers, as the original per-adapter loaders did.
|
|
19
|
+
if (result.available)
|
|
20
|
+
cached = { available: true, module: result.module };
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return { available: false, reason: errorReason(error) };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Preserve existing diagnostic detail policies chosen by each adapter. */
|
|
29
|
+
export function frameworkImportError(packageName, error, includeDetails) {
|
|
30
|
+
const prefix = `failed to import ${packageName}`;
|
|
31
|
+
if (!includeDetails)
|
|
32
|
+
return prefix;
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
return `${prefix}: ${message}`;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/promotion/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAiDhC,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,uBAAuB,EAAE,SAAS,SAAI,GAAG,gBAAgB,CA+DvG"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SdkError } from "../index.js";
|
|
2
|
+
// Official Promotion.grantReward documentation (RN 2.10.10 / Web 3.4.0).
|
|
3
|
+
// 4113 is intentionally absent: it cannot establish this attempt's outcome.
|
|
4
|
+
const REJECTION_CODES = new Set(["4100", "4104", "4105", "4108", "4109", "4110", "4112", "4114"]);
|
|
5
|
+
function unknown(reason, providerCode) {
|
|
6
|
+
return providerCode === undefined ? { status: "unknown", reason } : { status: "unknown", reason, providerCode };
|
|
7
|
+
}
|
|
8
|
+
function normalize(value, thrown) {
|
|
9
|
+
if (typeof value !== "object" || value === null) {
|
|
10
|
+
return unknown(thrown || value === "ERROR" ? "sdk_error" : "invalid_response");
|
|
11
|
+
}
|
|
12
|
+
const data = value;
|
|
13
|
+
const rawCode = data.errorCode ?? data.code;
|
|
14
|
+
const code = typeof rawCode === "string" && /^[A-Z0-9_]{1,64}$/.test(rawCode) ? rawCode : undefined;
|
|
15
|
+
const hasError = "errorCode" in data || "code" in data || "error" in data || "message" in data;
|
|
16
|
+
if (("key" in data && (thrown || hasError)) ||
|
|
17
|
+
(data.code !== undefined && data.errorCode !== undefined && data.code !== data.errorCode)) {
|
|
18
|
+
return unknown("invalid_response", code);
|
|
19
|
+
}
|
|
20
|
+
if (!thrown && typeof data.key === "string" && data.key.trim().length > 0) {
|
|
21
|
+
return { status: "granted", rewardKey: data.key };
|
|
22
|
+
}
|
|
23
|
+
if ("key" in data)
|
|
24
|
+
return unknown("invalid_response", code);
|
|
25
|
+
if (code === "UNSUPPORTED_APP_VERSION") {
|
|
26
|
+
throw new SdkError("UNSUPPORTED", "direct promotion rewards are not supported on this app version");
|
|
27
|
+
}
|
|
28
|
+
if (code && REJECTION_CODES.has(code))
|
|
29
|
+
return { status: "rejected", providerCode: code };
|
|
30
|
+
return unknown(code ? "ambiguous_provider_error" : thrown ? "sdk_error" : "invalid_response", code);
|
|
31
|
+
}
|
|
32
|
+
function support(platform) {
|
|
33
|
+
const grant = platform.Promotion?.grantReward;
|
|
34
|
+
if (typeof grant !== "function")
|
|
35
|
+
return "unsupported";
|
|
36
|
+
if (typeof grant.isSupported !== "function")
|
|
37
|
+
return "unknown";
|
|
38
|
+
return grant.isSupported() ? "supported" : "unsupported";
|
|
39
|
+
}
|
|
40
|
+
function validate(input) {
|
|
41
|
+
if (!input || typeof input.promotionCode !== "string" || !input.promotionCode.trim() ||
|
|
42
|
+
input.promotionCode !== input.promotionCode.trim() || !Number.isSafeInteger(input.amount) || input.amount <= 0) {
|
|
43
|
+
throw new SdkError("INVALID_PROMOTION_INPUT", "promotionCode must be non-empty without surrounding whitespace and amount must be a positive safe integer");
|
|
44
|
+
}
|
|
45
|
+
// Snapshot before loading; callers cannot change the pending payment input.
|
|
46
|
+
return { promotionCode: input.promotionCode, amount: input.amount };
|
|
47
|
+
}
|
|
48
|
+
export function createPromotionAdapter(loader, timeoutMs = 0) {
|
|
49
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2_147_483_647) {
|
|
50
|
+
throw new SdkError("INVALID_PROMOTION_INPUT", "timeoutMs must be an integer from 0 to 2147483647");
|
|
51
|
+
}
|
|
52
|
+
let inFlight = false;
|
|
53
|
+
const load = async () => {
|
|
54
|
+
const result = await loader();
|
|
55
|
+
if (!result.available)
|
|
56
|
+
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
57
|
+
return result.module;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
async getSupport() { return support(await load()); },
|
|
61
|
+
grantReward(input) {
|
|
62
|
+
let validated;
|
|
63
|
+
try {
|
|
64
|
+
validated = validate(input);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return Promise.reject(error);
|
|
68
|
+
}
|
|
69
|
+
if (inFlight)
|
|
70
|
+
return Promise.reject(new SdkError("PROMOTION_IN_PROGRESS", "a direct promotion request is still in progress"));
|
|
71
|
+
inFlight = true;
|
|
72
|
+
const now = typeof performance !== "undefined" && typeof performance.now === "function"
|
|
73
|
+
? performance.now.bind(performance)
|
|
74
|
+
: Date.now;
|
|
75
|
+
const startedAt = now();
|
|
76
|
+
let expired = false;
|
|
77
|
+
// Timers cannot run while JS is blocked or draining microtasks. Check the
|
|
78
|
+
// elapsed budget too, using one clock source for the entire request.
|
|
79
|
+
const hasExpired = () => expired || (timeoutMs > 0 && now() - startedAt >= timeoutMs);
|
|
80
|
+
let timer;
|
|
81
|
+
const work = Promise.resolve().then(async () => {
|
|
82
|
+
if (hasExpired())
|
|
83
|
+
return unknown("timeout");
|
|
84
|
+
const platform = await load();
|
|
85
|
+
// A loading timeout must not launch a new payment later.
|
|
86
|
+
if (hasExpired())
|
|
87
|
+
return unknown("timeout");
|
|
88
|
+
const availability = support(platform);
|
|
89
|
+
if (hasExpired())
|
|
90
|
+
return unknown("timeout");
|
|
91
|
+
if (availability === "unsupported") {
|
|
92
|
+
throw new SdkError("UNSUPPORTED", "the installed SDK or app does not support direct promotion rewards");
|
|
93
|
+
}
|
|
94
|
+
let response;
|
|
95
|
+
try {
|
|
96
|
+
response = await platform.Promotion.grantReward(validated);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (hasExpired())
|
|
100
|
+
return unknown("timeout");
|
|
101
|
+
// The RN conversion uses this only for the documented undefined result.
|
|
102
|
+
if (error instanceof SdkError && error.code === "UNSUPPORTED")
|
|
103
|
+
throw error;
|
|
104
|
+
return normalize(error, true);
|
|
105
|
+
}
|
|
106
|
+
if (hasExpired())
|
|
107
|
+
return unknown("timeout");
|
|
108
|
+
return normalize(response, false);
|
|
109
|
+
}).catch((error) => {
|
|
110
|
+
// A delayed loader/support failure must not beat an elapsed deadline.
|
|
111
|
+
if (hasExpired())
|
|
112
|
+
return unknown("timeout");
|
|
113
|
+
throw error;
|
|
114
|
+
}).finally(() => {
|
|
115
|
+
inFlight = false;
|
|
116
|
+
if (timer !== undefined)
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
});
|
|
119
|
+
if (timeoutMs === 0)
|
|
120
|
+
return work;
|
|
121
|
+
const deadline = new Promise(resolve => {
|
|
122
|
+
timer = setTimeout(() => { expired = true; resolve(unknown("timeout")); }, timeoutMs);
|
|
123
|
+
});
|
|
124
|
+
// Only actual SDK/load settlement releases the lock, not this race.
|
|
125
|
+
return Promise.race([work, deadline]);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type PromotionSupport = "supported" | "unsupported" | "unknown";
|
|
2
|
+
export interface PromotionGrantInput {
|
|
3
|
+
promotionCode: string;
|
|
4
|
+
amount: number;
|
|
5
|
+
}
|
|
6
|
+
export type PromotionGrantResult = {
|
|
7
|
+
status: "granted";
|
|
8
|
+
rewardKey: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "rejected";
|
|
11
|
+
providerCode: string;
|
|
12
|
+
} | {
|
|
13
|
+
status: "unknown";
|
|
14
|
+
reason: "sdk_error" | "timeout" | "invalid_response" | "ambiguous_provider_error";
|
|
15
|
+
providerCode?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Client SDK reports are not independently verified server ledger evidence. */
|
|
18
|
+
export interface PromotionAdapter {
|
|
19
|
+
getSupport(): Promise<PromotionSupport>;
|
|
20
|
+
grantReward(input: PromotionGrantInput): Promise<PromotionGrantResult>;
|
|
21
|
+
}
|
|
22
|
+
/** Injected results are untrusted, just like the native bridge response. */
|
|
23
|
+
export interface PromotionPlatformSdk {
|
|
24
|
+
Promotion?: {
|
|
25
|
+
grantReward?: ((input: PromotionGrantInput) => Promise<unknown>) & {
|
|
26
|
+
isSupported?: () => boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export type PromotionPlatformLoader = () => Promise<{
|
|
31
|
+
available: true;
|
|
32
|
+
module: PromotionPlatformSdk;
|
|
33
|
+
} | {
|
|
34
|
+
available: false;
|
|
35
|
+
reason: string;
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=platform-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-contract.d.ts","sourceRoot":"","sources":["../../src/promotion/platform-contract.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,aAAa,G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,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CA6B/E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SdkError } from "../index.js";
|
|
2
|
+
export function createReviewAdapter(loader) {
|
|
3
|
+
let inFlight;
|
|
4
|
+
const load = async () => {
|
|
5
|
+
const result = await loader();
|
|
6
|
+
if (!result.available)
|
|
7
|
+
throw new SdkError("SDK_UNAVAILABLE", result.reason);
|
|
8
|
+
return result.module;
|
|
9
|
+
};
|
|
10
|
+
const supported = (platform) => {
|
|
11
|
+
const request = platform.Review?.request;
|
|
12
|
+
return typeof request === "function" &&
|
|
13
|
+
typeof request.isSupported === "function" && request.isSupported() === true;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
async isSupported() {
|
|
17
|
+
return supported(await load());
|
|
18
|
+
},
|
|
19
|
+
request() {
|
|
20
|
+
if (inFlight)
|
|
21
|
+
return inFlight;
|
|
22
|
+
// Schedule loading after publishing the lock, including reentrant loaders.
|
|
23
|
+
inFlight = Promise.resolve().then(async () => {
|
|
24
|
+
const platform = await load();
|
|
25
|
+
if (!supported(platform)) {
|
|
26
|
+
throw new SdkError("UNSUPPORTED", "review requests are not supported on this app version");
|
|
27
|
+
}
|
|
28
|
+
await platform.Review.request();
|
|
29
|
+
}).finally(() => { inFlight = undefined; });
|
|
30
|
+
return inFlight;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Minimal injectable shape shared by the platform adapters. */
|
|
2
|
+
export interface ReviewPlatformSdk {
|
|
3
|
+
Review?: {
|
|
4
|
+
request?: (() => Promise<void>) & {
|
|
5
|
+
isSupported?: () => boolean;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export type ReviewPlatformLoader = () => Promise<{
|
|
10
|
+
available: true;
|
|
11
|
+
module: ReviewPlatformSdk;
|
|
12
|
+
} | {
|
|
13
|
+
available: false;
|
|
14
|
+
reason: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Completion only means the SDK call settled, never that a review was written. */
|
|
17
|
+
export interface ReviewAdapter {
|
|
18
|
+
isSupported(): Promise<boolean>;
|
|
19
|
+
request(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=platform-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-contract.d.ts","sourceRoot":"","sources":["../../src/review/platform-contract.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG;YAAE,WAAW,CAAC,EAAE,MAAM,OAAO,CAAA;SAAE,CAAC;KACnE,CAAC;CACH;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAC5C;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAC9C;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CACvC,CAAC;AAEF,mFAAmF;AACnF,MAAM,WAAW,aAAa;IAC5B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|