@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/index.d.ts CHANGED
@@ -47,6 +47,15 @@ export declare class PlatformOperationError extends Error implements PlatformOpe
47
47
  }>);
48
48
  }
49
49
  export declare function readPlatformOperationFailure(error: unknown): PlatformOperationFailure | null;
50
+ /**
51
+ * Stable, non-sensitive reason attached to a commerce outcome that did not
52
+ * fully complete. It is diagnostic only: it never grants or revokes anything.
53
+ * Games may use it for UI copy, retry decisions and support logs.
54
+ */
55
+ export interface CommerceDiagnostic extends PlatformOperationFailure {
56
+ /** Provider SDK error code, passed through only when it is a safe identifier. */
57
+ readonly providerCode?: string;
58
+ }
50
59
  export interface PurchaseResult {
51
60
  readonly status: 'completed' | 'cancelled' | 'pending' | 'failed';
52
61
  readonly transactionId?: string;
@@ -57,11 +66,15 @@ export interface PurchaseResult {
57
66
  readonly ledgerEntryId: string;
58
67
  readonly alreadyProcessed?: boolean;
59
68
  }>;
69
+ /** Optional reason for a cancelled, pending or failed result. */
70
+ readonly diagnostic?: CommerceDiagnostic;
60
71
  }
61
72
  export interface PurchaseRestoreResult {
62
73
  readonly restoredEntitlements: readonly Entitlement[];
63
74
  /** Server-confirmed consumable outcomes; native order visibility alone is not a grant. */
64
75
  readonly settledPurchases?: readonly PurchaseSettlement[];
76
+ /** Present when restore finished only partially, for example with orders still unresolved. */
77
+ readonly diagnostic?: CommerceDiagnostic;
65
78
  }
66
79
  export interface PurchaseSettlement {
67
80
  readonly transactionId: string;
@@ -69,6 +82,8 @@ export interface PurchaseSettlement {
69
82
  readonly status: 'granted' | 'refunded';
70
83
  readonly ledgerEntryId?: string;
71
84
  readonly alreadyProcessed?: boolean;
85
+ /** Client purchase idempotency key the order was started with, when the adapter can link it. */
86
+ readonly idempotencyKey?: string;
72
87
  }
73
88
  /**
74
89
  * Resolve a specific purchase from authoritative checkout or restore evidence.
@@ -193,6 +208,45 @@ export interface LeaderboardAdapter {
193
208
  export type PlatformProviderAvailability = 'unsupported' | 'configuration-required' | 'action-required' | 'temporarily-unavailable' | 'available';
194
209
  /** Existing capabilities and integrations annotated by optional providers. */
195
210
  export type PlatformProviderFeature = 'nativeIap' | 'subscriptionIap' | 'rewardedAds' | 'interstitialAds' | 'bannerAds' | 'nativeLeaderboard' | 'identityUpgrade' | 'pushNotifications';
211
+ export type CommerceFinishOwner = 'client' | 'server' | 'host' | 'none';
212
+ export type CommerceEvidenceAuthority = 'client-token' | 'host-callback' | 'adapter-settled' | 'server-push';
213
+ export type CommerceAccountBindingPolicy = 'required' | 'optional' | 'host';
214
+ export interface CommercePurchaseCapabilities {
215
+ readonly consumable: boolean;
216
+ readonly durable: boolean;
217
+ readonly subscription: boolean;
218
+ readonly quantity: boolean;
219
+ }
220
+ export interface CommerceCatalogCapabilities {
221
+ readonly products: boolean;
222
+ readonly offers: boolean;
223
+ readonly localizedPrice: boolean;
224
+ }
225
+ export interface CommerceLifecycleCapabilities {
226
+ readonly availablePurchases: boolean;
227
+ readonly pending: boolean;
228
+ readonly restore: boolean;
229
+ readonly events: boolean;
230
+ /** Who finishes a granted purchase. */
231
+ readonly finish: CommerceFinishOwner;
232
+ }
233
+ export interface CommerceAuthorityCapabilities {
234
+ /** What the backend verifies to grant. */
235
+ readonly evidence: CommerceEvidenceAuthority;
236
+ readonly accountBinding: CommerceAccountBindingPolicy;
237
+ }
238
+ /**
239
+ * Commerce v2 capability declaration (`@mpgd/platform/commerce`). Declared
240
+ * here so the main entry stays free of validator imports; code branches on
241
+ * these declarations, never on a store id or target name.
242
+ */
243
+ export interface CommerceCapabilities {
244
+ readonly purchase: CommercePurchaseCapabilities;
245
+ readonly catalog: CommerceCatalogCapabilities;
246
+ readonly lifecycle: CommerceLifecycleCapabilities;
247
+ readonly authority: CommerceAuthorityCapabilities;
248
+ readonly availability: PlatformProviderAvailability;
249
+ }
196
250
  export interface PlatformCapabilities {
197
251
  readonly nativeIap: boolean;
198
252
  /** Optional for adapters published before subscription-specific support. */
@@ -212,6 +266,12 @@ export interface PlatformCapabilities {
212
266
  readonly localizedContent: boolean;
213
267
  /** Explains a false capability without claiming an unavailable SDK works. */
214
268
  readonly providerAvailability?: Readonly<Partial<Record<PlatformProviderFeature, PlatformProviderAvailability>>>;
269
+ /**
270
+ * Optional commerce v2 capability block. When present it must be a fresh
271
+ * object on every read with no unknown keys, and `nativeIap` and
272
+ * `subscriptionIap` must equal `deriveLegacyCommerceCapabilities(commerce)`.
273
+ */
274
+ readonly commerce?: CommerceCapabilities;
215
275
  }
216
276
  export interface PlayerIdentity {
217
277
  readonly playerId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/platform",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "Shared platform gateway, monetization, ads, leaderboard, identity, lifecycle, and storage contracts for mpgd games.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,12 +44,28 @@
44
44
  "./storage-conformance": {
45
45
  "types": "./dist/storage-conformance.d.ts",
46
46
  "default": "./dist/storage-conformance.js"
47
+ },
48
+ "./commerce": {
49
+ "types": "./dist/commerce.d.ts",
50
+ "default": "./dist/commerce.js"
51
+ },
52
+ "./commerce-vectors": {
53
+ "types": "./dist/commerce-vectors.d.ts",
54
+ "default": "./dist/commerce-vectors.js"
55
+ },
56
+ "./commerce-conformance": {
57
+ "types": "./dist/commerce-conformance.d.ts",
58
+ "default": "./dist/commerce-conformance.js"
47
59
  }
48
60
  },
49
61
  "files": [
50
62
  "dist"
51
63
  ],
64
+ "dependencies": {
65
+ "typia": "13.0.2"
66
+ },
52
67
  "devDependencies": {
68
+ "@ttsc/unplugin": "0.30.4",
53
69
  "ttsc": "0.30.4",
54
70
  "typescript": "7.0.2",
55
71
  "vitest": "^4.0.0"
@@ -64,6 +80,6 @@
64
80
  "lint": "ttsc --noEmit",
65
81
  "format": "ttsc format",
66
82
  "fix": "ttsc fix",
67
- "test": "vitest run && node test/capability-conformance-dist-import.mjs && node test/storage-conformance-dist-import.mjs && node test/ads-dist-import.mjs"
83
+ "test": "vitest run && node test/capability-conformance-dist-import.mjs && node test/storage-conformance-dist-import.mjs && node test/ads-dist-import.mjs && node test/commerce-dist-import.mjs && node test/commerce-conformance-dist-import.mjs && cd ../.. && node tools/run-ttsx.mjs packages/platform/test/commerce-derived-key-parity.ts"
68
84
  }
69
85
  }