@mpgd/adapter-ait 0.7.0 → 0.9.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/dist/host.d.ts CHANGED
@@ -1,22 +1,131 @@
1
- import { getTossShareLink, isMinVersionSupported, loadFullScreenAd, openGameCenterLeaderboard, share, showFullScreenAd, Storage, submitGameCenterLeaderBoardScore } from '@apps-in-toss/web-framework';
2
- import type { ShareResult } from '@mpgd/platform';
1
+ import { getTossShareLink, grantPromotionRewardForGame as grantPromotionReward, IAP, isMinVersionSupported, loadFullScreenAd, openGameCenterLeaderboard, requestNotificationAgreement, share, showFullScreenAd, Storage, submitGameCenterLeaderBoardScore } from '@apps-in-toss/web-framework';
2
+ import type { Entitlement, LogicalProductId, NotificationTopic, ShareResult } from '@mpgd/platform';
3
3
  import type { GamePlatformBridge } from './index.js';
4
4
  export type AitIdentityProvider = () => Promise<unknown>;
5
+ /**
6
+ * The AIT SDK adds support-version metadata to native functions over time.
7
+ * The host only depends on the callable surface and an optional support probe
8
+ * so adapter tests remain compatible with older wrappers and newer SDKs.
9
+ */
10
+ type AitOptionalCapabilityMethod<T extends (...args: never[]) => unknown> = (...args: Parameters<T>) => ReturnType<T>;
11
+ interface AitCapabilityProbe {
12
+ readonly isSupported?: () => boolean;
13
+ }
14
+ type AitNativeMethod<T extends (...args: never[]) => unknown> = AitOptionalCapabilityMethod<T> & AitCapabilityProbe;
15
+ interface AitIapDependencies {
16
+ readonly createOneTimePurchaseOrder: AitNativeMethod<typeof IAP.createOneTimePurchaseOrder>;
17
+ readonly getProductItemList: AitNativeMethod<typeof IAP.getProductItemList>;
18
+ readonly getPendingOrders: AitNativeMethod<typeof IAP.getPendingOrders>;
19
+ readonly completeProductGrant: AitNativeMethod<typeof IAP.completeProductGrant>;
20
+ }
5
21
  export interface AitHostDependencies {
6
22
  readonly identityProvider: AitIdentityProvider;
7
- readonly storage: Pick<typeof Storage, 'getItem' | 'setItem'>;
23
+ readonly storage: Pick<typeof Storage, 'getItem' | 'removeItem' | 'setItem'>;
8
24
  readonly getTossShareLink: typeof getTossShareLink;
9
25
  readonly share: typeof share;
26
+ readonly grantPromotionReward: AitNativeMethod<typeof grantPromotionReward>;
27
+ readonly requestNotificationAgreement: AitNativeMethod<typeof requestNotificationAgreement>;
10
28
  readonly isMinVersionSupported: typeof isMinVersionSupported;
11
- readonly loadFullScreenAd: typeof loadFullScreenAd;
12
- readonly showFullScreenAd: typeof showFullScreenAd;
13
- readonly openGameCenterLeaderboard: typeof openGameCenterLeaderboard;
14
- readonly submitGameCenterLeaderBoardScore: typeof submitGameCenterLeaderBoardScore;
29
+ readonly loadFullScreenAd: AitNativeMethod<typeof loadFullScreenAd>;
30
+ readonly showFullScreenAd: AitNativeMethod<typeof showFullScreenAd>;
31
+ readonly openGameCenterLeaderboard: AitNativeMethod<typeof openGameCenterLeaderboard>;
32
+ readonly submitGameCenterLeaderBoardScore: AitNativeMethod<typeof submitGameCenterLeaderBoardScore>;
33
+ readonly iap: AitIapDependencies;
34
+ }
35
+ /** Game-owned logical product mapped to a console-issued Apps in Toss SKU. */
36
+ export interface AitIapProductConfig {
37
+ readonly productId: LogicalProductId;
38
+ readonly sku: string;
39
+ /** Apps in Toss currently displays KRW prices; override only for a supported future catalog. */
40
+ readonly currencyCode?: string;
41
+ }
42
+ export interface AitIapPreparationInput {
43
+ readonly intent: 'purchase' | 'restore';
44
+ readonly productId?: LogicalProductId;
45
+ readonly platformSku?: string;
46
+ }
47
+ /**
48
+ * Game-owned server gate that ensures the anonymous game key is linked to a
49
+ * Toss login user before a purchase or pending-order recovery can proceed.
50
+ */
51
+ export type AitIapPreparer = (input: AitIapPreparationInput) => Promise<boolean>;
52
+ export interface AitIapProductGrantVerificationInput {
53
+ readonly orderId: string;
54
+ readonly productId: LogicalProductId;
55
+ readonly platformSku: string;
56
+ readonly idempotencyKey: string;
57
+ readonly source: 'process-product-grant' | 'pending-order-restore';
58
+ /** Client callback time only; the game authority must use the order status time. */
59
+ readonly purchasedAt: string;
60
+ readonly signal: AbortSignal;
61
+ readonly timeoutMs: number;
62
+ }
63
+ /**
64
+ * A server-backed verifier. Returning false keeps the provider-side grant
65
+ * pending; the bridge never manufactures a client-side entitlement.
66
+ */
67
+ export type AitIapProductGrantVerifier = (input: AitIapProductGrantVerificationInput) => Promise<boolean>;
68
+ /**
69
+ * Reads durable purchase entitlements from the game authority. Native product
70
+ * callbacks are intentionally not treated as a source of ownership state.
71
+ */
72
+ export type AitIapEntitlementReader = () => Promise<readonly Entitlement[]>;
73
+ export interface AitPromotionRewardConfig {
74
+ readonly promotionCode: string;
75
+ readonly amount: number;
76
+ }
77
+ export interface AitPendingPromotionGrantInput {
78
+ readonly campaignId: string;
79
+ readonly idempotencyKey: string;
80
+ /** Missing for legacy or malformed pending markers; resolvers must fail closed. */
81
+ readonly pendingSince?: string;
82
+ }
83
+ export type AitPendingPromotionGrantResolution = {
84
+ readonly status: 'granted';
85
+ readonly receiptKey: string;
86
+ } | {
87
+ readonly status: 'retry' | 'pending';
88
+ };
89
+ /**
90
+ * Server-backed reconciliation hook for an ambiguous native promotion call.
91
+ * Returning `retry` must only happen after the game authority decides that a
92
+ * second provider call is safe for this single-use claim id.
93
+ */
94
+ export type AitPendingPromotionGrantResolver = (input: AitPendingPromotionGrantInput) => Promise<AitPendingPromotionGrantResolution>;
95
+ export interface AitPromotionGrantAuthorizationInput {
96
+ readonly campaignId: string;
97
+ /** Single-use claim id issued by the game backend. */
98
+ readonly idempotencyKey: string;
15
99
  }
100
+ export type AitPromotionGrantAuthorization = {
101
+ readonly status: 'authorized';
102
+ } | {
103
+ readonly status: 'pending' | 'rejected';
104
+ };
105
+ /**
106
+ * Server-backed gate for the first provider call. A configured campaign is not
107
+ * available until this hook confirms that the idempotency key is a genuine,
108
+ * single-use game claim.
109
+ */
110
+ export type AitPromotionGrantAuthorizer = (input: AitPromotionGrantAuthorizationInput) => Promise<AitPromotionGrantAuthorization>;
16
111
  export interface InstallAitHostBridgeOptions {
17
112
  readonly appName?: string;
18
113
  readonly adGroupIds?: Readonly<Record<string, string>>;
19
114
  readonly adPlacementTypes?: Readonly<Record<string, 'rewarded' | 'interstitial'>>;
115
+ /** Logical campaign ids mapped to console-issued Apps in Toss promotion configuration. */
116
+ readonly promotionRewards?: Readonly<Record<string, AitPromotionRewardConfig>>;
117
+ readonly authorizePromotionGrant?: AitPromotionGrantAuthorizer;
118
+ readonly resolvePendingPromotionGrant?: AitPendingPromotionGrantResolver;
119
+ /** Enable IAP only with logical-to-native SKU mappings and both server hooks. */
120
+ readonly iapProducts?: readonly AitIapProductConfig[];
121
+ readonly prepareIap?: AitIapPreparer;
122
+ readonly verifyIapProductGrant?: AitIapProductGrantVerifier;
123
+ /** Required to expose native IAP so ownership survives a wrapper restart. */
124
+ readonly readIapEntitlements?: AitIapEntitlementReader;
125
+ /** May be shortened, but never extended beyond the native callback-safe default. */
126
+ readonly iapProductGrantTimeoutMs?: number;
127
+ /** Logical notification topics mapped to approved Apps in Toss template codes. */
128
+ readonly notificationTemplateCodes?: Partial<Readonly<Record<NotificationTopic, string>>>;
20
129
  /** Maximum total wait for the native show request before display is observed. */
21
130
  readonly adTimeoutMs?: number;
22
131
  /** Maximum wait to acquire the process-wide native full-screen load slot. */