@mpgd/platform 0.20.0 → 0.22.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/commerce-conformance.d.ts +34 -51
- package/dist/commerce-conformance.js +72 -465
- package/dist/commerce-contract.d.ts +31 -2
- package/dist/commerce-wallet.d.ts +324 -0
- package/dist/commerce-wallet.js +2087 -0
- package/dist/commerce.d.ts +34 -5
- package/dist/commerce.js +238 -10
- package/package.json +6 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { type ActiveSubscription, type CommerceBillingAuthority, type CommerceCapabilities, type CommerceErrorCode, type CommerceErrorInfo, type CommerceEvent, type CommerceEvidenceAuthority, type CommerceFinishOwner, type CommerceLogicalProductId, type CommerceProvider, type CommercePurchaseState, type CreditBalance, type
|
|
2
|
-
import type { CommerceConformanceCatalogEntry, CommerceConformanceErrorFixture, CommerceConformanceExpectation, CommerceConformanceFinishResultFixture, CommerceConformanceLotFixture, CommerceConformanceProfile, CommerceConformancePurchaseFixture, CommerceConformanceRequestResultFixture,
|
|
1
|
+
import { type ActiveSubscription, type CommerceBillingAuthority, type CommerceCapabilities, type CommerceErrorCode, type CommerceErrorInfo, type CommerceEvent, type CommerceEvidenceAuthority, type CommerceFinishOwner, type CommerceLogicalProductId, type CommerceProvider, type CommercePurchaseState, type CreditBalance, type CreditEntitlement, type CreditLot, type CreditLotSpendScope, type CreditOffer, type CreditSpendInput, type CreditSpendResult, type CreditWalletClient, type CreditWalletSubscribeInput, type FetchProductsInput, type PurchaseKind, type RequestPurchaseInput, type RequestPurchaseResult, type StoreId, type StoreProduct, type StorePurchase } from './commerce.js';
|
|
2
|
+
import type { CommerceConformanceCatalogEntry, CommerceConformanceErrorFixture, CommerceConformanceExpectation, CommerceConformanceFinishResultFixture, CommerceConformanceLotFixture, CommerceConformanceProfile, CommerceConformancePurchaseFixture, CommerceConformanceRequestResultFixture, CommerceConformanceVector, CommerceConformanceVerifyDecision } from './commerce-vectors.js';
|
|
3
|
+
import { type CreditMembershipStartInput, type CreditMembershipStartResult, type CreditScheduledDebit, type CreditSubscriptionEvent } from './commerce-wallet.js';
|
|
3
4
|
import type { PlatformEvidenceEnvelope } from './index.js';
|
|
5
|
+
export { addIsoDuration, compareCreditLotSpendOrder, deriveCreditLotSpendScope, normalizeIsoTimestamp, } from './commerce-wallet.js';
|
|
4
6
|
/**
|
|
5
7
|
* Commerce v2 conformance runner (RFC "Conformance vectors") with the in-memory
|
|
6
8
|
* reference pieces every vector needs: a fake clock, a fake store with its
|
|
@@ -31,10 +33,6 @@ export interface CommerceConformanceClock {
|
|
|
31
33
|
set(at: string): void;
|
|
32
34
|
}
|
|
33
35
|
export declare function createCommerceConformanceClock(initial?: string): CommerceConformanceClock;
|
|
34
|
-
/** Canonical `YYYY-MM-DDTHH:mm:ssZ`; milliseconds are kept only when non-zero. */
|
|
35
|
-
export declare function normalizeIsoTimestamp(input: string): string;
|
|
36
|
-
/** Adds an ISO-8601 duration (`P30D`, `P1M`, `PT12H`, ...) to a timestamp, in UTC calendar units. */
|
|
37
|
-
export declare function addIsoDuration(at: string, duration: string): string;
|
|
38
36
|
/** Capabilities of a vector profile: omitted blocks default to all supported and `available`. */
|
|
39
37
|
export declare function createCommerceConformanceCapabilities(profile: CommerceConformanceProfile): CommerceCapabilities;
|
|
40
38
|
export interface CommerceConformanceFixtureContext {
|
|
@@ -270,33 +268,11 @@ export interface CreateCommerceConformanceRuntimeInput {
|
|
|
270
268
|
* `granted`, and only a ledger revocation moves it to `revoked`.
|
|
271
269
|
*/
|
|
272
270
|
export declare function createCommerceConformanceRuntime(input: CreateCommerceConformanceRuntimeInput): CommerceConformanceRuntime;
|
|
273
|
-
export
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
export
|
|
277
|
-
|
|
278
|
-
readonly eventId: string;
|
|
279
|
-
readonly type: CommerceConformanceSubscriptionEventType;
|
|
280
|
-
readonly subscriptionId: string;
|
|
281
|
-
readonly logicalId: CommerceLogicalProductId;
|
|
282
|
-
readonly periodIndex: number;
|
|
283
|
-
readonly expiresAt: string;
|
|
284
|
-
readonly reason?: CommerceErrorCode;
|
|
285
|
-
}
|
|
286
|
-
export interface CommerceConformanceMembershipStart {
|
|
287
|
-
readonly subscriptionId: string;
|
|
288
|
-
readonly titleId: string;
|
|
289
|
-
readonly logicalId: CommerceLogicalProductId;
|
|
290
|
-
readonly terms: CreditMembershipTerms;
|
|
291
|
-
}
|
|
292
|
-
export type CommerceConformanceMembershipResult = {
|
|
293
|
-
readonly status: 'started';
|
|
294
|
-
readonly subscription: ActiveSubscription;
|
|
295
|
-
readonly entitlementId: string;
|
|
296
|
-
} | {
|
|
297
|
-
readonly status: 'rejected';
|
|
298
|
-
readonly error: CommerceErrorInfo;
|
|
299
|
-
};
|
|
271
|
+
export type CommerceScheduledDebit = CreditScheduledDebit;
|
|
272
|
+
/** Stable id `<subscriptionId>:<periodIndex>:<type>`, so redelivery is idempotent. */
|
|
273
|
+
export type CommerceConformanceSubscriptionEvent = CreditSubscriptionEvent;
|
|
274
|
+
export type CommerceConformanceMembershipStart = CreditMembershipStartInput;
|
|
275
|
+
export type CommerceConformanceMembershipResult = CreditMembershipStartResult;
|
|
300
276
|
/** The wallet actor of a vector: wallet steps plus wallet observations. */
|
|
301
277
|
export interface CommerceConformanceWalletActor {
|
|
302
278
|
readonly lots: readonly CreditLot[];
|
|
@@ -321,8 +297,14 @@ export interface CommerceConformanceWalletActor {
|
|
|
321
297
|
}
|
|
322
298
|
export interface CommerceConformanceWallet extends CreditWalletClient, CommerceConformanceWalletActor {
|
|
323
299
|
readonly entitlements: readonly CreditEntitlement[];
|
|
300
|
+
/** Offers the wallet prices spends against; the provider registers the vector catalog when empty. */
|
|
301
|
+
readonly offers: readonly CreditOffer[];
|
|
302
|
+
addOffers(offers: readonly CreditOffer[]): void;
|
|
324
303
|
startMembership(input: CommerceConformanceMembershipStart): Promise<CommerceConformanceMembershipResult>;
|
|
325
|
-
|
|
304
|
+
getActiveSubscriptions(input?: {
|
|
305
|
+
readonly titleId?: string;
|
|
306
|
+
}): Promise<readonly ActiveSubscription[]>;
|
|
307
|
+
subscribe(listener: (event: CommerceEvent) => void, input?: CreditWalletSubscribeInput): () => void;
|
|
326
308
|
}
|
|
327
309
|
export interface CreateCommerceConformanceWalletInput {
|
|
328
310
|
readonly store: StoreId;
|
|
@@ -332,18 +314,12 @@ export interface CreateCommerceConformanceWalletInput {
|
|
|
332
314
|
readonly offers?: readonly CreditOffer[];
|
|
333
315
|
}
|
|
334
316
|
/**
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* `INSUFFICIENT_BALANCE`; memberships debit `membership:<id>:<period>` per
|
|
340
|
-
* paid period and lapse at period end when the eligible balance runs out.
|
|
317
|
+
* The reference wallet (`createInMemoryCreditWallet`) on the vector clock,
|
|
318
|
+
* with the actor surface: fixture lots credit through `creditFromGrant`, the
|
|
319
|
+
* backend finalizer redeems through `finalize`, and owner-side mistakes in a
|
|
320
|
+
* vector surface as script errors.
|
|
341
321
|
*/
|
|
342
322
|
export declare function createCommerceConformanceWallet(input: CreateCommerceConformanceWalletInput): CommerceConformanceWallet;
|
|
343
|
-
/** Store lots are title-scoped, off-store lots cross-title, promotion lots as issued (title by default). */
|
|
344
|
-
export declare function deriveCreditLotSpendScope(origin: CreditLot['origin'], explicit?: CreditLotSpendScope): CreditLotSpendScope;
|
|
345
|
-
/** RFC spend order: earliest `expiresAt` (none last), `title` before `cross-title`, oldest `createdAt`, then `lotId`. */
|
|
346
|
-
export declare function compareCreditLotSpendOrder(left: CreditLot, right: CreditLot): number;
|
|
347
323
|
export interface CreateCommerceConformanceWalletProviderInput {
|
|
348
324
|
readonly wallet: CommerceConformanceWallet;
|
|
349
325
|
readonly profile: CommerceConformanceProfile;
|
|
@@ -354,13 +330,12 @@ export interface CreateCommerceConformanceWalletProviderInput {
|
|
|
354
330
|
readonly clock: CommerceConformanceClock;
|
|
355
331
|
}
|
|
356
332
|
/**
|
|
357
|
-
* `
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
* `host`.
|
|
333
|
+
* `createCreditCommerceProvider` over the reference wallet with the vector
|
|
334
|
+
* profile as its capability block. A wallet that lists no offers has the
|
|
335
|
+
* vector catalog registered as its offers first (a fixture price of one unit
|
|
336
|
+
* of the first wallet currency for entries without membership terms), so the
|
|
337
|
+
* wallet prices every spend and starts memberships itself. Memberships exist
|
|
338
|
+
* only where the billing authority is `host`.
|
|
364
339
|
*/
|
|
365
340
|
export declare function createCommerceConformanceWalletProvider(input: CreateCommerceConformanceWalletProviderInput): CommerceProvider;
|
|
366
341
|
export interface CommerceConformanceHarness {
|
|
@@ -380,6 +355,14 @@ export interface CommerceConformanceContext extends CommerceConformanceFixtureCo
|
|
|
380
355
|
export interface CommerceConformanceRunOptions {
|
|
381
356
|
/** Supplies a provider over the caller's fake SDK; defaults to the fake store or the reference wallet. */
|
|
382
357
|
readonly createProvider?: (context: CommerceConformanceContext) => CommerceConformanceHarness | Promise<CommerceConformanceHarness>;
|
|
358
|
+
/**
|
|
359
|
+
* Supplies the runtime under test over the harness provider, backend, and
|
|
360
|
+
* journal; defaults to the reference reconciler
|
|
361
|
+
* (`createCommerceConformanceRuntime`). The reference run an adaptive
|
|
362
|
+
* vector is derived from always uses the reference reconciler, so the
|
|
363
|
+
* derived expectations stay the RFC's regardless of the runtime under test.
|
|
364
|
+
*/
|
|
365
|
+
readonly createRuntime?: (input: CreateCommerceConformanceRuntimeInput, context: CommerceConformanceContext) => CommerceConformanceRuntime | Promise<CommerceConformanceRuntime>;
|
|
383
366
|
readonly playerId?: string;
|
|
384
367
|
readonly titleId?: string;
|
|
385
368
|
}
|