@mpgd/platform 0.10.0 → 0.12.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
@@ -1,4 +1,4 @@
1
- export type PlatformTarget = 'browser' | 'microsoft-store' | 'android' | 'ios' | 'ait' | 'reddit' | 'verse8' | 'telegram' | 'tauri';
1
+ export type PlatformTarget = 'browser' | 'microsoft-store' | 'android' | 'ios' | 'ait' | 'reddit' | 'verse8' | 'telegram' | 'tauri' | 'wechat' | 'tiktok';
2
2
  export type StarterLogicalProductId = 'COINS_100' | 'COINS_500' | 'REMOVE_ADS';
3
3
  export type LogicalProductId = StarterLogicalProductId | (string & Record<never, never>);
4
4
  export type StarterLogicalAdPlacementId = 'CONTINUE_AFTER_FAIL' | 'STAGE_END_INTERSTITIAL';
@@ -24,6 +24,28 @@ export interface PlatformEvidenceEnvelope {
24
24
  readonly schema: string;
25
25
  readonly payload: Readonly<Record<string, string | number | boolean>>;
26
26
  }
27
+ export interface PlatformOperationFailure {
28
+ readonly code: string;
29
+ readonly retryable: boolean;
30
+ }
31
+ /**
32
+ * Provider-neutral error raised when a platform bridge rejects an operation.
33
+ *
34
+ * Adapters preserve a stable, non-sensitive code and retry hint so game UI can
35
+ * distinguish configuration, environment, and transient failures without
36
+ * importing a provider SDK or parsing localized error messages.
37
+ */
38
+ export declare class PlatformOperationError extends Error implements PlatformOperationFailure {
39
+ readonly name = "PlatformOperationError";
40
+ readonly code: string;
41
+ readonly retryable: boolean;
42
+ constructor(input?: Readonly<{
43
+ readonly code?: unknown;
44
+ readonly message?: unknown;
45
+ readonly retryable?: unknown;
46
+ }>);
47
+ }
48
+ export declare function readPlatformOperationFailure(error: unknown): PlatformOperationFailure | null;
27
49
  export interface PurchaseResult {
28
50
  readonly status: 'completed' | 'cancelled' | 'pending' | 'failed';
29
51
  readonly transactionId?: string;
package/dist/index.js CHANGED
@@ -1,3 +1,46 @@
1
+ /**
2
+ * Provider-neutral error raised when a platform bridge rejects an operation.
3
+ *
4
+ * Adapters preserve a stable, non-sensitive code and retry hint so game UI can
5
+ * distinguish configuration, environment, and transient failures without
6
+ * importing a provider SDK or parsing localized error messages.
7
+ */
8
+ export class PlatformOperationError extends Error {
9
+ name = 'PlatformOperationError';
10
+ code;
11
+ retryable;
12
+ constructor(input) {
13
+ const diagnostics = input ?? {};
14
+ super(typeof diagnostics.message === 'string'
15
+ ? diagnostics.message
16
+ : 'The platform operation failed.');
17
+ this.code = normalizePlatformOperationCode(diagnostics.code);
18
+ this.retryable = diagnostics.retryable === true;
19
+ }
20
+ }
21
+ export function readPlatformOperationFailure(error) {
22
+ if (error instanceof PlatformOperationError) {
23
+ return { code: error.code, retryable: error.retryable };
24
+ }
25
+ if (typeof error !== 'object' || error === null || Array.isArray(error)) {
26
+ return null;
27
+ }
28
+ const record = error;
29
+ return typeof record.code === 'string'
30
+ && isPlatformOperationCode(record.code)
31
+ && typeof record.retryable === 'boolean'
32
+ ? { code: record.code, retryable: record.retryable }
33
+ : null;
34
+ }
35
+ function normalizePlatformOperationCode(code) {
36
+ return isPlatformOperationCode(code) ? code : 'PLATFORM_OPERATION_FAILED';
37
+ }
38
+ function isPlatformOperationCode(code) {
39
+ return typeof code === 'string'
40
+ && code.length > 0
41
+ && code.length <= 128
42
+ && /^[A-Z][A-Z0-9_:-]*$/u.test(code);
43
+ }
1
44
  export function resolveShareCompletion(result) {
2
45
  if (result.status !== 'shared') {
3
46
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/platform",
3
- "version": "0.10.0",
3
+ "version": "0.12.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": {