@mpgd/platform 0.17.0 → 0.19.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/capability-conformance.js +103 -1
- package/dist/commerce-capabilities.d.ts +9 -0
- package/dist/commerce-capabilities.js +24 -0
- package/dist/commerce-conformance.d.ts +386 -0
- package/dist/commerce-conformance.js +1701 -0
- package/dist/commerce-vectors.d.ts +269 -0
- package/dist/commerce-vectors.js +3084 -0
- package/dist/commerce.d.ts +445 -0
- package/dist/commerce.js +5623 -0
- package/dist/index.d.ts +60 -0
- package/package.json +18 -2
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { type tags } from 'typia';
|
|
2
|
+
import { PlatformOperationError, type CommerceAdapter, type CommerceCapabilities, type LogicalProductId, type PlatformEvidenceEnvelope, type StarterLogicalProductId } from './index.js';
|
|
3
|
+
export { createUnsupportedCommerceCapabilities, deriveLegacyCommerceCapabilities, type LegacyCommerceCapabilities, } from './commerce-capabilities.js';
|
|
4
|
+
export type { CommerceAccountBindingPolicy, CommerceAuthorityCapabilities, CommerceCapabilities, CommerceCatalogCapabilities, CommerceEvidenceAuthority, CommerceFinishOwner, CommerceLifecycleCapabilities, CommercePurchaseCapabilities, } from './index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Commerce v2 client contract. Pure types, validators, and helpers only: no
|
|
7
|
+
* provider lives here, and nothing in this module grants a purchase. The
|
|
8
|
+
* contract is described by docs/specs/commerce/commerce-v2-rfc.md and is a
|
|
9
|
+
* draft until the protocol version is released as 2.0.0.
|
|
10
|
+
*/
|
|
11
|
+
export declare const commerceProtocolVersion: '2.0.0-draft.1';
|
|
12
|
+
export declare const commerceProtocol: 'mpgd.commerce.v2';
|
|
13
|
+
type NonEmptyString = string & tags.MinLength<1>;
|
|
14
|
+
type IsoTimestamp = string & tags.Format<'date-time'>;
|
|
15
|
+
type PositiveQuantity = number & tags.Type<'uint32'> & tags.Minimum<1>;
|
|
16
|
+
type NonNegativeInteger = number & tags.Type<'uint32'>;
|
|
17
|
+
/**
|
|
18
|
+
* Open store identifier. Reference providers use 'google-play', 'app-store',
|
|
19
|
+
* 'microsoft-store', 'apps-in-toss', 'devvit', and 'verse8'; a consuming
|
|
20
|
+
* project adds its own, for example a credit wallet id.
|
|
21
|
+
*/
|
|
22
|
+
export type StoreId = NonEmptyString;
|
|
23
|
+
export type PurchaseKind = 'consumable' | 'durable' | 'subscription';
|
|
24
|
+
/**
|
|
25
|
+
* `LogicalProductId` narrowed to its open string branch and tagged non-empty,
|
|
26
|
+
* so validators and the generated schemas carry `minLength: 1`. Starter ids and
|
|
27
|
+
* plain `LogicalProductId` values remain assignable.
|
|
28
|
+
*/
|
|
29
|
+
export type CommerceLogicalProductId = Exclude<LogicalProductId, StarterLogicalProductId> & tags.MinLength<1>;
|
|
30
|
+
export interface StorePrice {
|
|
31
|
+
readonly formatted: string;
|
|
32
|
+
/** ISO 4217 code or a project-declared code such as a wallet currency. */
|
|
33
|
+
readonly currencyCode: NonEmptyString;
|
|
34
|
+
readonly amountMicros?: number & tags.Type<'int64'>;
|
|
35
|
+
}
|
|
36
|
+
export interface StoreOffer {
|
|
37
|
+
readonly offerId: NonEmptyString;
|
|
38
|
+
readonly price: StorePrice;
|
|
39
|
+
readonly title?: string;
|
|
40
|
+
readonly description?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface StoreProduct {
|
|
43
|
+
readonly logicalId: CommerceLogicalProductId;
|
|
44
|
+
readonly store: StoreId;
|
|
45
|
+
readonly storeSku: NonEmptyString;
|
|
46
|
+
readonly kind: PurchaseKind;
|
|
47
|
+
readonly title: string;
|
|
48
|
+
readonly description: string;
|
|
49
|
+
readonly price: StorePrice;
|
|
50
|
+
readonly offers?: readonly StoreOffer[];
|
|
51
|
+
}
|
|
52
|
+
export type StorePurchaseState = 'pending' | 'purchased' | 'revoked';
|
|
53
|
+
export interface StorePurchaseAccountBinding {
|
|
54
|
+
readonly kind: 'obfuscated-account-id' | 'app-account-token' | 'host-identity';
|
|
55
|
+
readonly value?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface StorePurchase {
|
|
58
|
+
readonly store: StoreId;
|
|
59
|
+
/** Store transaction id; a provider derives one when the store has none. */
|
|
60
|
+
readonly transactionId: NonEmptyString;
|
|
61
|
+
readonly originalTransactionId?: NonEmptyString;
|
|
62
|
+
readonly storeSku: NonEmptyString;
|
|
63
|
+
readonly logicalId?: CommerceLogicalProductId;
|
|
64
|
+
readonly quantity: PositiveQuantity;
|
|
65
|
+
readonly state: StorePurchaseState;
|
|
66
|
+
readonly purchasedAt?: IsoTimestamp;
|
|
67
|
+
/** Play purchase token, App Store signed transaction (JWS), or host order id. */
|
|
68
|
+
readonly token: NonEmptyString;
|
|
69
|
+
readonly evidence: PlatformEvidenceEnvelope;
|
|
70
|
+
readonly accountBinding?: StorePurchaseAccountBinding;
|
|
71
|
+
/** Present only for `authority.evidence: 'adapter-settled'`; a reconciler pointer, not a grant. */
|
|
72
|
+
readonly settlement?: {
|
|
73
|
+
readonly ledgerEntryId: NonEmptyString;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export type PurchaseSource = 'shop' | 'stage_fail' | 'result' | 'event';
|
|
77
|
+
export interface RequestPurchaseInput {
|
|
78
|
+
readonly logicalId: CommerceLogicalProductId;
|
|
79
|
+
readonly idempotencyKey: NonEmptyString;
|
|
80
|
+
readonly source: PurchaseSource;
|
|
81
|
+
readonly offerId?: NonEmptyString;
|
|
82
|
+
/** Integer >= 1. Rejected with ITEM_UNAVAILABLE when the provider does not declare `purchase.quantity`. */
|
|
83
|
+
readonly quantity?: PositiveQuantity;
|
|
84
|
+
}
|
|
85
|
+
export type RequestPurchaseResult = {
|
|
86
|
+
readonly outcome: 'launched';
|
|
87
|
+
} | {
|
|
88
|
+
readonly outcome: 'purchased';
|
|
89
|
+
readonly purchase: StorePurchase;
|
|
90
|
+
} | {
|
|
91
|
+
readonly outcome: 'cancelled' | 'failed';
|
|
92
|
+
readonly error: CommerceErrorInfo;
|
|
93
|
+
};
|
|
94
|
+
export type CommerceErrorCode = 'USER_CANCELLED' | 'OUTCOME_UNKNOWN' | 'ALREADY_OWNED' | 'IN_PROGRESS' | 'ITEM_UNAVAILABLE' | 'NOT_PREPARED' | 'NETWORK' | 'STORE_UNAVAILABLE' | 'CONFIGURATION_REQUIRED' | 'ACTION_REQUIRED' | 'ACCOUNT_BINDING_REQUIRED' | 'INSUFFICIENT_BALANCE' | 'INVALID_RESPONSE' | 'UNKNOWN';
|
|
95
|
+
export declare const commerceErrorCodes: readonly ["USER_CANCELLED", "OUTCOME_UNKNOWN", "ALREADY_OWNED", "IN_PROGRESS", "ITEM_UNAVAILABLE", "NOT_PREPARED", "NETWORK", "STORE_UNAVAILABLE", "CONFIGURATION_REQUIRED", "ACTION_REQUIRED", "ACCOUNT_BINDING_REQUIRED", "INSUFFICIENT_BALANCE", "INVALID_RESPONSE", "UNKNOWN"];
|
|
96
|
+
export interface CommerceErrorInfo {
|
|
97
|
+
readonly code: CommerceErrorCode;
|
|
98
|
+
readonly retryable: boolean;
|
|
99
|
+
/** The store's original code, for example PLAY_BILLING_SERVICE_UNAVAILABLE. */
|
|
100
|
+
readonly storeCode?: string;
|
|
101
|
+
readonly message?: string;
|
|
102
|
+
}
|
|
103
|
+
export type CommerceEvent = {
|
|
104
|
+
readonly type: 'purchaseUpdated';
|
|
105
|
+
readonly purchase: StorePurchase;
|
|
106
|
+
} | {
|
|
107
|
+
readonly type: 'purchaseError';
|
|
108
|
+
readonly logicalId?: CommerceLogicalProductId;
|
|
109
|
+
readonly error: CommerceErrorInfo;
|
|
110
|
+
} | {
|
|
111
|
+
readonly type: 'subscriptionUpdated';
|
|
112
|
+
readonly subscription: ActiveSubscription;
|
|
113
|
+
};
|
|
114
|
+
/** Bridge event envelope; `sequence` is per session and starts at 0. */
|
|
115
|
+
export interface CommerceEventEnvelope {
|
|
116
|
+
readonly protocol: typeof commerceProtocol;
|
|
117
|
+
readonly sequence: NonNegativeInteger;
|
|
118
|
+
readonly event: CommerceEvent;
|
|
119
|
+
}
|
|
120
|
+
export type FetchProductsType = 'in-app' | 'subscription' | 'all';
|
|
121
|
+
export interface FetchProductsInput {
|
|
122
|
+
readonly logicalIds?: readonly CommerceLogicalProductId[];
|
|
123
|
+
readonly type?: FetchProductsType;
|
|
124
|
+
}
|
|
125
|
+
export interface GetAvailablePurchasesInput {
|
|
126
|
+
readonly includePending?: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface FinishTransactionInput {
|
|
129
|
+
readonly transactionId: NonEmptyString;
|
|
130
|
+
readonly ledgerEntryId: NonEmptyString;
|
|
131
|
+
readonly isConsumable: boolean;
|
|
132
|
+
}
|
|
133
|
+
export interface FinishTransactionResult {
|
|
134
|
+
readonly finished: boolean;
|
|
135
|
+
}
|
|
136
|
+
export interface CommerceProvider {
|
|
137
|
+
readonly store: StoreId;
|
|
138
|
+
getCapabilities(): Promise<CommerceCapabilities>;
|
|
139
|
+
fetchProducts(input: FetchProductsInput): Promise<readonly StoreProduct[]>;
|
|
140
|
+
/** Returns `launched` when the result arrives later as a `purchaseUpdated` event. */
|
|
141
|
+
requestPurchase(input: RequestPurchaseInput): Promise<RequestPurchaseResult>;
|
|
142
|
+
/** Purchases the store still reports as unfinished. */
|
|
143
|
+
getAvailablePurchases(input?: GetAvailablePurchasesInput): Promise<readonly StorePurchase[]>;
|
|
144
|
+
/** Required when `lifecycle.finish` is 'client' or 'host'. */
|
|
145
|
+
finishTransaction?(input: FinishTransactionInput): Promise<FinishTransactionResult>;
|
|
146
|
+
/** Asks the store to resynchronize, for example `AppStore.sync`. */
|
|
147
|
+
restorePurchases?(): Promise<void>;
|
|
148
|
+
/** Designed, not implemented by any reference store provider. */
|
|
149
|
+
getActiveSubscriptions?(): Promise<readonly ActiveSubscription[]>;
|
|
150
|
+
/** Events emitted before the first listener are delivered to that listener. */
|
|
151
|
+
subscribe(listener: (event: CommerceEvent) => void): () => void;
|
|
152
|
+
}
|
|
153
|
+
export type ActiveSubscriptionState = 'active' | 'lapsed' | 'revoked';
|
|
154
|
+
export interface ActiveSubscription {
|
|
155
|
+
readonly store: StoreId;
|
|
156
|
+
readonly logicalId: CommerceLogicalProductId;
|
|
157
|
+
readonly subscriptionId: NonEmptyString;
|
|
158
|
+
readonly periodIndex: NonNegativeInteger;
|
|
159
|
+
readonly state: ActiveSubscriptionState;
|
|
160
|
+
readonly startedAt: IsoTimestamp;
|
|
161
|
+
readonly expiresAt: IsoTimestamp;
|
|
162
|
+
readonly autoRenew: boolean;
|
|
163
|
+
}
|
|
164
|
+
export type CommerceBillingAuthority = 'store' | 'host';
|
|
165
|
+
export type CreditMembershipScope = 'title' | 'platform';
|
|
166
|
+
export interface CreditPrice {
|
|
167
|
+
readonly currency: NonEmptyString;
|
|
168
|
+
readonly amount: number & tags.ExclusiveMinimum<0>;
|
|
169
|
+
}
|
|
170
|
+
export interface CreditMembershipTerms {
|
|
171
|
+
readonly scope: CreditMembershipScope;
|
|
172
|
+
readonly price: CreditPrice;
|
|
173
|
+
/** ISO 8601 duration, for example P30D. */
|
|
174
|
+
readonly period: NonEmptyString;
|
|
175
|
+
}
|
|
176
|
+
export interface CreditOffer {
|
|
177
|
+
readonly logicalId: CommerceLogicalProductId;
|
|
178
|
+
readonly storeSku: NonEmptyString;
|
|
179
|
+
readonly kind: PurchaseKind;
|
|
180
|
+
readonly title: string;
|
|
181
|
+
readonly description: string;
|
|
182
|
+
readonly price: CreditPrice;
|
|
183
|
+
/** Present only for credit-funded memberships. */
|
|
184
|
+
readonly membership?: CreditMembershipTerms;
|
|
185
|
+
}
|
|
186
|
+
export interface CreditSpendInput {
|
|
187
|
+
readonly titleId: NonEmptyString;
|
|
188
|
+
readonly currency: NonEmptyString;
|
|
189
|
+
readonly amount: number & tags.ExclusiveMinimum<0>;
|
|
190
|
+
readonly idempotencyKey: NonEmptyString;
|
|
191
|
+
readonly logicalId?: CommerceLogicalProductId;
|
|
192
|
+
}
|
|
193
|
+
export interface CreditDebit {
|
|
194
|
+
readonly lotId: NonEmptyString;
|
|
195
|
+
readonly amount: number & tags.ExclusiveMinimum<0>;
|
|
196
|
+
}
|
|
197
|
+
export type CreditSpendResult = {
|
|
198
|
+
readonly status: 'debited';
|
|
199
|
+
readonly entitlementId: NonEmptyString;
|
|
200
|
+
readonly debits: readonly CreditDebit[];
|
|
201
|
+
/** A repeated idempotency key returns the original debits. */
|
|
202
|
+
readonly alreadyProcessed?: boolean;
|
|
203
|
+
} | {
|
|
204
|
+
readonly status: 'rejected';
|
|
205
|
+
readonly error: CommerceErrorInfo;
|
|
206
|
+
};
|
|
207
|
+
export interface CreditEntitlement {
|
|
208
|
+
readonly entitlementId: NonEmptyString;
|
|
209
|
+
readonly titleId: NonEmptyString;
|
|
210
|
+
readonly logicalId: CommerceLogicalProductId;
|
|
211
|
+
readonly idempotencyKey: NonEmptyString;
|
|
212
|
+
readonly createdAt: IsoTimestamp;
|
|
213
|
+
readonly debits: readonly CreditDebit[];
|
|
214
|
+
}
|
|
215
|
+
export interface CreditBalance {
|
|
216
|
+
readonly titleId: NonEmptyString;
|
|
217
|
+
/** Spendable amount per currency, including eligible cross-title lots. */
|
|
218
|
+
readonly balances: Readonly<Record<string, number>>;
|
|
219
|
+
}
|
|
220
|
+
export type CreditLotChannel = 'store' | 'off-store' | 'promotion';
|
|
221
|
+
export interface CreditLotOrigin {
|
|
222
|
+
readonly channel: CreditLotChannel;
|
|
223
|
+
readonly store: StoreId;
|
|
224
|
+
readonly titleId: NonEmptyString;
|
|
225
|
+
}
|
|
226
|
+
export type CreditLotSpendScope = {
|
|
227
|
+
readonly kind: 'title';
|
|
228
|
+
readonly titleId: NonEmptyString;
|
|
229
|
+
} | {
|
|
230
|
+
readonly kind: 'cross-title';
|
|
231
|
+
};
|
|
232
|
+
export interface CreditLot {
|
|
233
|
+
/** Equals the ledgerEntryId of the granting purchase, so a replayed grant cannot create a second lot. */
|
|
234
|
+
readonly lotId: NonEmptyString;
|
|
235
|
+
readonly currency: NonEmptyString;
|
|
236
|
+
readonly amount: number & tags.ExclusiveMinimum<0>;
|
|
237
|
+
readonly remaining: number & tags.Minimum<0>;
|
|
238
|
+
readonly createdAt: IsoTimestamp;
|
|
239
|
+
readonly expiresAt?: IsoTimestamp;
|
|
240
|
+
readonly origin: CreditLotOrigin;
|
|
241
|
+
/** Derived from the origin, never supplied by the caller. */
|
|
242
|
+
readonly spendScope: CreditLotSpendScope;
|
|
243
|
+
}
|
|
244
|
+
export interface CreditWalletClient {
|
|
245
|
+
readonly store: StoreId;
|
|
246
|
+
listOffers(input: {
|
|
247
|
+
readonly titleId: string;
|
|
248
|
+
}): Promise<readonly CreditOffer[]>;
|
|
249
|
+
spend(input: CreditSpendInput): Promise<CreditSpendResult>;
|
|
250
|
+
listUnredeemed(input: {
|
|
251
|
+
readonly titleId: string;
|
|
252
|
+
}): Promise<readonly CreditEntitlement[]>;
|
|
253
|
+
redeem(input: {
|
|
254
|
+
readonly entitlementId: string;
|
|
255
|
+
readonly ledgerEntryId: string;
|
|
256
|
+
}): Promise<{
|
|
257
|
+
readonly redeemed: boolean;
|
|
258
|
+
}>;
|
|
259
|
+
getBalance(input: {
|
|
260
|
+
readonly titleId: string;
|
|
261
|
+
}): Promise<CreditBalance>;
|
|
262
|
+
subscribe?(listener: (event: CommerceEvent) => void): () => void;
|
|
263
|
+
}
|
|
264
|
+
export interface CommerceBridgeGetCapabilitiesPayload {
|
|
265
|
+
readonly protocol: typeof commerceProtocol;
|
|
266
|
+
}
|
|
267
|
+
export interface CommerceBridgeGetCapabilitiesResult {
|
|
268
|
+
readonly protocolVersion: NonEmptyString;
|
|
269
|
+
readonly store: StoreId;
|
|
270
|
+
readonly capabilities: CommerceCapabilities;
|
|
271
|
+
}
|
|
272
|
+
export type CommerceBridgeFetchProductsPayload = FetchProductsInput;
|
|
273
|
+
export interface CommerceBridgeFetchProductsResult {
|
|
274
|
+
readonly products: readonly StoreProduct[];
|
|
275
|
+
}
|
|
276
|
+
export type CommerceBridgeRequestPurchasePayload = RequestPurchaseInput;
|
|
277
|
+
export type CommerceBridgeRequestPurchaseResult = RequestPurchaseResult;
|
|
278
|
+
export type CommerceBridgeGetAvailablePurchasesPayload = GetAvailablePurchasesInput;
|
|
279
|
+
export interface CommerceBridgeGetAvailablePurchasesResult {
|
|
280
|
+
readonly purchases: readonly StorePurchase[];
|
|
281
|
+
}
|
|
282
|
+
export type CommerceBridgeFinishTransactionPayload = FinishTransactionInput;
|
|
283
|
+
export type CommerceBridgeFinishTransactionResult = FinishTransactionResult;
|
|
284
|
+
export interface CommerceBridgeRestorePurchasesPayload {
|
|
285
|
+
readonly protocol: typeof commerceProtocol;
|
|
286
|
+
}
|
|
287
|
+
export interface CommerceBridgeRestorePurchasesResult {
|
|
288
|
+
readonly restored: boolean;
|
|
289
|
+
}
|
|
290
|
+
export interface CommerceBridgeMethods {
|
|
291
|
+
readonly 'commerce.v2.getCapabilities': {
|
|
292
|
+
readonly payload: CommerceBridgeGetCapabilitiesPayload;
|
|
293
|
+
readonly result: CommerceBridgeGetCapabilitiesResult;
|
|
294
|
+
};
|
|
295
|
+
readonly 'commerce.v2.fetchProducts': {
|
|
296
|
+
readonly payload: CommerceBridgeFetchProductsPayload;
|
|
297
|
+
readonly result: CommerceBridgeFetchProductsResult;
|
|
298
|
+
};
|
|
299
|
+
readonly 'commerce.v2.requestPurchase': {
|
|
300
|
+
readonly payload: CommerceBridgeRequestPurchasePayload;
|
|
301
|
+
readonly result: CommerceBridgeRequestPurchaseResult;
|
|
302
|
+
};
|
|
303
|
+
readonly 'commerce.v2.getAvailablePurchases': {
|
|
304
|
+
readonly payload: CommerceBridgeGetAvailablePurchasesPayload;
|
|
305
|
+
readonly result: CommerceBridgeGetAvailablePurchasesResult;
|
|
306
|
+
};
|
|
307
|
+
readonly 'commerce.v2.finishTransaction': {
|
|
308
|
+
readonly payload: CommerceBridgeFinishTransactionPayload;
|
|
309
|
+
readonly result: CommerceBridgeFinishTransactionResult;
|
|
310
|
+
};
|
|
311
|
+
readonly 'commerce.v2.restorePurchases': {
|
|
312
|
+
readonly payload: CommerceBridgeRestorePurchasesPayload;
|
|
313
|
+
readonly result: CommerceBridgeRestorePurchasesResult;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
export type CommerceBridgeMethod = keyof CommerceBridgeMethods;
|
|
317
|
+
export declare const commerceBridgeMethods: readonly ["commerce.v2.getCapabilities", "commerce.v2.fetchProducts", "commerce.v2.requestPurchase", "commerce.v2.getAvailablePurchases", "commerce.v2.finishTransaction", "commerce.v2.restorePurchases"];
|
|
318
|
+
/** Only NETWORK and STORE_UNAVAILABLE are retryable without reconciling first. */
|
|
319
|
+
export declare function defaultCommerceErrorRetryable(code: CommerceErrorCode): boolean;
|
|
320
|
+
export declare function isCommerceErrorCode(value: unknown): value is CommerceErrorCode;
|
|
321
|
+
export interface CommerceErrorOptions {
|
|
322
|
+
readonly message?: string;
|
|
323
|
+
readonly storeCode?: string;
|
|
324
|
+
readonly retryable?: boolean;
|
|
325
|
+
readonly cause?: unknown;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Normalized commerce failure. `code` is one of the v2 codes, `storeCode`
|
|
329
|
+
* keeps the store's own code verbatim, and `retryable` defaults from the code.
|
|
330
|
+
*/
|
|
331
|
+
export declare class CommerceError extends PlatformOperationError {
|
|
332
|
+
readonly code: CommerceErrorCode;
|
|
333
|
+
readonly storeCode: string | undefined;
|
|
334
|
+
constructor(code: CommerceErrorCode, options?: CommerceErrorOptions);
|
|
335
|
+
toCommerceErrorInfo(): CommerceErrorInfo;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Reads a normalized error info from any thrown value. A `CommerceError` keeps
|
|
339
|
+
* its code; a plain object with a v2 `code` is accepted; any other platform
|
|
340
|
+
* failure or error maps to UNKNOWN with the original code kept as `storeCode`.
|
|
341
|
+
*/
|
|
342
|
+
export declare function commerceErrorInfoOf(error: unknown): CommerceErrorInfo;
|
|
343
|
+
export type CommercePurchaseState = 'requested' | 'launched' | 'pending' | 'purchased' | 'verifying' | 'granted' | 'finishing' | 'finished' | 'cancelled' | 'failed' | 'rejected' | 'revoked';
|
|
344
|
+
export declare const commercePurchaseStates: readonly ["requested", "launched", "pending", "purchased", "verifying", "granted", "finishing", "finished", "cancelled", "failed", "rejected", "revoked"];
|
|
345
|
+
/** Allowed transitions, from the RFC lifecycle table. `pending` covers both store-side and server-side waits. */
|
|
346
|
+
export declare const commercePurchaseTransitions: Readonly<Record<CommercePurchaseState, readonly CommercePurchaseState[]>>;
|
|
347
|
+
export declare const terminalCommercePurchaseStates: readonly ["finished", "cancelled", "failed", "rejected", "revoked"];
|
|
348
|
+
export declare function canTransitionCommercePurchase(from: CommercePurchaseState, to: CommercePurchaseState): boolean;
|
|
349
|
+
export declare function assertCommercePurchaseTransition(from: CommercePurchaseState, to: CommercePurchaseState): void;
|
|
350
|
+
export declare function isTerminalCommercePurchaseState(state: CommercePurchaseState): boolean;
|
|
351
|
+
/** Only `granted` may unlock content, and only because the ledger says so. */
|
|
352
|
+
export type CommercePurchaseSummaryStatus = 'pending' | 'granted' | 'cancelled' | 'failed' | 'rejected' | 'revoked';
|
|
353
|
+
export declare function summarizeCommercePurchaseState(state: CommercePurchaseState): CommercePurchaseSummaryStatus;
|
|
354
|
+
/**
|
|
355
|
+
* Rejects a purchase the provider cannot serve before any store UI opens.
|
|
356
|
+
* `kind` is the catalog kind of `input.logicalId`; the caller resolves it.
|
|
357
|
+
*/
|
|
358
|
+
export declare function assertRequestPurchaseSupported(capabilities: CommerceCapabilities, input: RequestPurchaseInput, kind: PurchaseKind): void;
|
|
359
|
+
export interface DerivedPurchaseIdempotencyKeyInput {
|
|
360
|
+
readonly store: StoreId;
|
|
361
|
+
readonly transactionId: string;
|
|
362
|
+
readonly token: string;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Key for a purchase discovered without a journal record. Every runtime derives
|
|
366
|
+
* the same key: `store:<storeId>:<transactionId>` by default, with each
|
|
367
|
+
* component percent-encoded (`encodeURIComponent`) so ids containing `:`
|
|
368
|
+
* cannot collide, and the forms v1 ledgers already use for Google Play
|
|
369
|
+
* (`play-token-sha256:<hex>`) and Apps in Toss (`apps-in-toss:purchase:<orderId>`),
|
|
370
|
+
* which stay byte-identical.
|
|
371
|
+
*/
|
|
372
|
+
export declare function createDerivedPurchaseIdempotencyKey(input: DerivedPurchaseIdempotencyKeyInput): Promise<string>;
|
|
373
|
+
/** Byte-for-byte the v1 `createGooglePlayTokenTransactionId` form; A4 replaces the two copies with this helper. */
|
|
374
|
+
export declare function createGooglePlayTokenPurchaseKey(purchaseToken: string): Promise<string>;
|
|
375
|
+
export declare const commerceEventBufferLimit = 64;
|
|
376
|
+
export interface CommerceEventBuffer {
|
|
377
|
+
readonly size: number;
|
|
378
|
+
/** Keeps the event for the first subscriber; drops the oldest recoverable `purchaseUpdated` when full. */
|
|
379
|
+
push(event: CommerceEvent): void;
|
|
380
|
+
/** Delivers and clears every buffered event in order. */
|
|
381
|
+
drain(listener: (event: CommerceEvent) => void): number;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Buffer for events emitted before the first `subscribe` call. Over the limit
|
|
385
|
+
* it drops the oldest recoverable `purchaseUpdated` first: a pending or
|
|
386
|
+
* purchased purchase is still returned by `getAvailablePurchases`. A revoked
|
|
387
|
+
* purchase is not, so revoked `purchaseUpdated`, `purchaseError`, and
|
|
388
|
+
* `subscriptionUpdated` events are dropped oldest-first only when no
|
|
389
|
+
* recoverable `purchaseUpdated` remains.
|
|
390
|
+
*/
|
|
391
|
+
export declare function createCommerceEventBuffer(options?: {
|
|
392
|
+
readonly limit?: number;
|
|
393
|
+
}): CommerceEventBuffer;
|
|
394
|
+
export declare const assertStoreProduct: (input: unknown) => StoreProduct;
|
|
395
|
+
export declare const isStoreProduct: (input: unknown) => input is StoreProduct;
|
|
396
|
+
export declare const assertStorePurchase: (input: unknown) => StorePurchase;
|
|
397
|
+
export declare const isStorePurchase: (input: unknown) => input is StorePurchase;
|
|
398
|
+
export declare const assertRequestPurchaseInput: (input: unknown) => RequestPurchaseInput;
|
|
399
|
+
export declare const isRequestPurchaseInput: (input: unknown) => input is RequestPurchaseInput;
|
|
400
|
+
export declare const assertRequestPurchaseResult: (input: unknown) => RequestPurchaseResult;
|
|
401
|
+
export declare const isRequestPurchaseResult: (input: unknown) => input is RequestPurchaseResult;
|
|
402
|
+
export declare const assertCommerceEvent: (input: unknown) => CommerceEvent;
|
|
403
|
+
export declare const isCommerceEvent: (input: unknown) => input is CommerceEvent;
|
|
404
|
+
export declare const assertCommerceEventEnvelope: (input: unknown) => CommerceEventEnvelope;
|
|
405
|
+
export declare const isCommerceEventEnvelope: (input: unknown) => input is CommerceEventEnvelope;
|
|
406
|
+
export declare const assertActiveSubscription: (input: unknown) => ActiveSubscription;
|
|
407
|
+
export declare const isActiveSubscription: (input: unknown) => input is ActiveSubscription;
|
|
408
|
+
export declare const assertFetchProductsInput: (input: unknown) => FetchProductsInput;
|
|
409
|
+
export declare const assertCommerceCapabilities: (input: unknown) => CommerceCapabilities;
|
|
410
|
+
export declare const isCommerceCapabilities: (input: unknown) => input is CommerceCapabilities;
|
|
411
|
+
export declare const assertCommerceErrorInfo: (input: unknown) => CommerceErrorInfo;
|
|
412
|
+
export declare const assertCreditOffer: (input: unknown) => CreditOffer;
|
|
413
|
+
export declare const assertCreditSpendInput: (input: unknown) => CreditSpendInput;
|
|
414
|
+
export declare const assertCreditSpendResult: (input: unknown) => CreditSpendResult;
|
|
415
|
+
export declare const assertCreditEntitlement: (input: unknown) => CreditEntitlement;
|
|
416
|
+
export declare const assertCreditBalance: (input: unknown) => CreditBalance;
|
|
417
|
+
export declare const assertCreditLot: (input: unknown) => CreditLot;
|
|
418
|
+
export declare const assertFinishTransactionInput: (input: unknown) => FinishTransactionInput;
|
|
419
|
+
export declare const assertFinishTransactionResult: (input: unknown) => FinishTransactionResult;
|
|
420
|
+
export declare const assertGetAvailablePurchasesInput: (input: unknown) => GetAvailablePurchasesInput;
|
|
421
|
+
export declare const assertCommerceBridgeGetCapabilitiesPayload: (input: unknown) => CommerceBridgeGetCapabilitiesPayload;
|
|
422
|
+
export declare const assertCommerceBridgeGetCapabilitiesResult: (input: unknown) => CommerceBridgeGetCapabilitiesResult;
|
|
423
|
+
export declare const assertCommerceBridgeFetchProductsPayload: (input: unknown) => FetchProductsInput;
|
|
424
|
+
export declare const assertCommerceBridgeFetchProductsResult: (input: unknown) => CommerceBridgeFetchProductsResult;
|
|
425
|
+
export declare const assertCommerceBridgeRequestPurchasePayload: (input: unknown) => RequestPurchaseInput;
|
|
426
|
+
export declare const assertCommerceBridgeRequestPurchaseResult: (input: unknown) => RequestPurchaseResult;
|
|
427
|
+
export declare const assertCommerceBridgeGetAvailablePurchasesPayload: (input: unknown) => GetAvailablePurchasesInput;
|
|
428
|
+
export declare const assertCommerceBridgeGetAvailablePurchasesResult: (input: unknown) => CommerceBridgeGetAvailablePurchasesResult;
|
|
429
|
+
export declare const assertCommerceBridgeFinishTransactionPayload: (input: unknown) => FinishTransactionInput;
|
|
430
|
+
export declare const assertCommerceBridgeFinishTransactionResult: (input: unknown) => FinishTransactionResult;
|
|
431
|
+
export declare const assertCommerceBridgeRestorePurchasesPayload: (input: unknown) => CommerceBridgeRestorePurchasesPayload;
|
|
432
|
+
export declare const assertCommerceBridgeRestorePurchasesResult: (input: unknown) => CommerceBridgeRestorePurchasesResult;
|
|
433
|
+
export interface ToCommerceAdapterOptions {
|
|
434
|
+
/** Forwarded to `getAvailablePurchases` during `restore`. Defaults to false. */
|
|
435
|
+
readonly includePending?: boolean;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Serves v1 `CommerceAdapter` callers from a v2 provider. The wrapper never
|
|
439
|
+
* grants: a `purchased` outcome becomes a `completed` result with no
|
|
440
|
+
* entitlements, and `authoritativeGrant` appears only when the provider reports
|
|
441
|
+
* an adapter settlement that already points at a ledger entry. `restore`
|
|
442
|
+
* returns settled purchases from `getAvailablePurchases` and no entitlements;
|
|
443
|
+
* entitlements come from the ledger, not from the provider.
|
|
444
|
+
*/
|
|
445
|
+
export declare function toCommerceAdapter(provider: CommerceProvider, options?: ToCommerceAdapterOptions): CommerceAdapter;
|