expo-iap 3.0.3 → 3.0.4

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/CLAUDE.md +2 -0
  3. package/build/helpers/subscription.d.ts +1 -12
  4. package/build/helpers/subscription.d.ts.map +1 -1
  5. package/build/helpers/subscription.js +12 -7
  6. package/build/helpers/subscription.js.map +1 -1
  7. package/build/index.d.ts +8 -6
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +4 -2
  10. package/build/index.js.map +1 -1
  11. package/build/modules/android.d.ts +7 -6
  12. package/build/modules/android.d.ts.map +1 -1
  13. package/build/modules/android.js +19 -4
  14. package/build/modules/android.js.map +1 -1
  15. package/build/modules/ios.d.ts +7 -10
  16. package/build/modules/ios.d.ts.map +1 -1
  17. package/build/modules/ios.js +3 -1
  18. package/build/modules/ios.js.map +1 -1
  19. package/build/purchase-error.d.ts +69 -0
  20. package/build/purchase-error.d.ts.map +1 -0
  21. package/build/purchase-error.js +164 -0
  22. package/build/purchase-error.js.map +1 -0
  23. package/build/types.d.ts +649 -0
  24. package/build/types.d.ts.map +1 -0
  25. package/build/types.js +100 -0
  26. package/build/types.js.map +1 -0
  27. package/build/useIAP.d.ts +5 -4
  28. package/build/useIAP.d.ts.map +1 -1
  29. package/build/useIAP.js +1 -1
  30. package/build/useIAP.js.map +1 -1
  31. package/build/utils/errorMapping.d.ts +1 -1
  32. package/build/utils/errorMapping.d.ts.map +1 -1
  33. package/build/utils/errorMapping.js +19 -3
  34. package/build/utils/errorMapping.js.map +1 -1
  35. package/jest.config.js +1 -1
  36. package/package.json +1 -1
  37. package/src/helpers/subscription.ts +12 -20
  38. package/src/index.ts +14 -14
  39. package/src/modules/android.ts +28 -10
  40. package/src/modules/ios.ts +11 -13
  41. package/src/purchase-error.ts +268 -0
  42. package/src/types.ts +738 -0
  43. package/src/useIAP.ts +8 -8
  44. package/src/utils/errorMapping.ts +24 -3
  45. package/build/ExpoIap.types.d.ts +0 -307
  46. package/build/ExpoIap.types.d.ts.map +0 -1
  47. package/build/ExpoIap.types.js +0 -235
  48. package/build/ExpoIap.types.js.map +0 -1
  49. package/build/types/ExpoIapAndroid.types.d.ts +0 -114
  50. package/build/types/ExpoIapAndroid.types.d.ts.map +0 -1
  51. package/build/types/ExpoIapAndroid.types.js +0 -29
  52. package/build/types/ExpoIapAndroid.types.js.map +0 -1
  53. package/build/types/ExpoIapIOS.types.d.ts +0 -149
  54. package/build/types/ExpoIapIOS.types.d.ts.map +0 -1
  55. package/build/types/ExpoIapIOS.types.js +0 -8
  56. package/build/types/ExpoIapIOS.types.js.map +0 -1
  57. package/src/ExpoIap.types.ts +0 -444
  58. package/src/types/ExpoIapAndroid.types.ts +0 -133
  59. package/src/types/ExpoIapIOS.types.ts +0 -172
@@ -0,0 +1,69 @@
1
+ import { ErrorCode, Platform } from './types';
2
+ /** Platform identifiers supported by {@link PurchaseError}. */
3
+ export type PurchaseErrorPlatform = Platform | 'ios' | 'android';
4
+ /** Properties used to construct a {@link PurchaseError}. */
5
+ export interface PurchaseErrorProps {
6
+ message: string;
7
+ responseCode?: number;
8
+ debugMessage?: string;
9
+ code?: ErrorCode;
10
+ productId?: string;
11
+ platform?: PurchaseErrorPlatform;
12
+ }
13
+ /** Shape of raw platform error objects coming from native modules. */
14
+ type PlatformErrorData = {
15
+ code?: string | number;
16
+ message?: string;
17
+ responseCode?: number;
18
+ debugMessage?: string;
19
+ productId?: string;
20
+ };
21
+ /**
22
+ * Mapping between platforms and their canonical error codes.
23
+ * Values are platform-native string identifiers.
24
+ */
25
+ export declare const ErrorCodeMapping: {
26
+ readonly ios: Record<ErrorCode, string>;
27
+ readonly android: Record<ErrorCode, string>;
28
+ };
29
+ /**
30
+ * Error thrown by expo-iap when purchases fail.
31
+ */
32
+ export declare class PurchaseError extends Error {
33
+ responseCode?: number;
34
+ debugMessage?: string;
35
+ code?: ErrorCode;
36
+ productId?: string;
37
+ platform?: PurchaseErrorPlatform;
38
+ constructor(message: string, responseCode?: number, debugMessage?: string, code?: ErrorCode, productId?: string, platform?: PurchaseErrorPlatform);
39
+ constructor(props: PurchaseErrorProps);
40
+ /**
41
+ * Create a {@link PurchaseError} from raw platform error data.
42
+ */
43
+ static fromPlatformError(errorData: PlatformErrorData, platform: PurchaseErrorPlatform): PurchaseError;
44
+ /**
45
+ * Returns the platform specific error code for this instance.
46
+ */
47
+ getPlatformCode(): string | number | undefined;
48
+ }
49
+ /** Utility helpers for translating error codes between platforms. */
50
+ export declare const ErrorCodeUtils: {
51
+ /**
52
+ * Returns the native error code for the provided {@link ErrorCode}.
53
+ */
54
+ getNativeErrorCode: (errorCode: ErrorCode) => string;
55
+ /**
56
+ * Converts a platform-specific error code into a standardized {@link ErrorCode}.
57
+ */
58
+ fromPlatformCode: (platformCode: string | number, _platform: PurchaseErrorPlatform) => ErrorCode;
59
+ /**
60
+ * Converts a standardized {@link ErrorCode} into its platform-specific value.
61
+ */
62
+ toPlatformCode: (errorCode: ErrorCode, _platform: PurchaseErrorPlatform) => string | number;
63
+ /**
64
+ * Determines whether the error code is supported on the given platform.
65
+ */
66
+ isValidForPlatform: (errorCode: ErrorCode, platform: PurchaseErrorPlatform) => boolean;
67
+ };
68
+ export {};
69
+ //# sourceMappingURL=purchase-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purchase-error.d.ts","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE5C,+DAA+D;AAC/D,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAEjE,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CA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;IAOlB;;OAEG;oCAEU,SAAS,YACV,qBAAqB,KAC9B,OAAO;CAUX,CAAC"}
@@ -0,0 +1,164 @@
1
+ import { NATIVE_ERROR_CODES } from './ExpoIapModule';
2
+ import { ErrorCode, Platform } from './types';
3
+ const toStandardizedCode = (errorCode) => errorCode.startsWith('E_') ? errorCode : `E_${errorCode}`;
4
+ const normalizePlatform = (platform) => platform === Platform.Ios || platform === 'ios' ? 'ios' : 'android';
5
+ const OPENIAP_ERROR_CODE_SET = new Set(Object.values(ErrorCode).map((code) => toStandardizedCode(code)));
6
+ const COMMON_ERROR_CODE_MAP = {
7
+ [ErrorCode.Unknown]: toStandardizedCode(ErrorCode.Unknown),
8
+ [ErrorCode.UserCancelled]: toStandardizedCode(ErrorCode.UserCancelled),
9
+ [ErrorCode.UserError]: toStandardizedCode(ErrorCode.UserError),
10
+ [ErrorCode.ItemUnavailable]: toStandardizedCode(ErrorCode.ItemUnavailable),
11
+ [ErrorCode.RemoteError]: toStandardizedCode(ErrorCode.RemoteError),
12
+ [ErrorCode.NetworkError]: toStandardizedCode(ErrorCode.NetworkError),
13
+ [ErrorCode.ServiceError]: toStandardizedCode(ErrorCode.ServiceError),
14
+ [ErrorCode.ReceiptFailed]: toStandardizedCode(ErrorCode.ReceiptFailed),
15
+ [ErrorCode.ReceiptFinished]: toStandardizedCode(ErrorCode.ReceiptFinished),
16
+ [ErrorCode.ReceiptFinishedFailed]: toStandardizedCode(ErrorCode.ReceiptFinishedFailed),
17
+ [ErrorCode.NotPrepared]: toStandardizedCode(ErrorCode.NotPrepared),
18
+ [ErrorCode.NotEnded]: toStandardizedCode(ErrorCode.NotEnded),
19
+ [ErrorCode.AlreadyOwned]: toStandardizedCode(ErrorCode.AlreadyOwned),
20
+ [ErrorCode.DeveloperError]: toStandardizedCode(ErrorCode.DeveloperError),
21
+ [ErrorCode.BillingResponseJsonParseError]: toStandardizedCode(ErrorCode.BillingResponseJsonParseError),
22
+ [ErrorCode.DeferredPayment]: toStandardizedCode(ErrorCode.DeferredPayment),
23
+ [ErrorCode.Interrupted]: toStandardizedCode(ErrorCode.Interrupted),
24
+ [ErrorCode.IapNotAvailable]: toStandardizedCode(ErrorCode.IapNotAvailable),
25
+ [ErrorCode.PurchaseError]: toStandardizedCode(ErrorCode.PurchaseError),
26
+ [ErrorCode.SyncError]: toStandardizedCode(ErrorCode.SyncError),
27
+ [ErrorCode.TransactionValidationFailed]: toStandardizedCode(ErrorCode.TransactionValidationFailed),
28
+ [ErrorCode.ActivityUnavailable]: toStandardizedCode(ErrorCode.ActivityUnavailable),
29
+ [ErrorCode.AlreadyPrepared]: toStandardizedCode(ErrorCode.AlreadyPrepared),
30
+ [ErrorCode.Pending]: toStandardizedCode(ErrorCode.Pending),
31
+ [ErrorCode.ConnectionClosed]: toStandardizedCode(ErrorCode.ConnectionClosed),
32
+ [ErrorCode.InitConnection]: toStandardizedCode(ErrorCode.InitConnection),
33
+ [ErrorCode.ServiceDisconnected]: toStandardizedCode(ErrorCode.ServiceDisconnected),
34
+ [ErrorCode.QueryProduct]: toStandardizedCode(ErrorCode.QueryProduct),
35
+ [ErrorCode.SkuNotFound]: toStandardizedCode(ErrorCode.SkuNotFound),
36
+ [ErrorCode.SkuOfferMismatch]: toStandardizedCode(ErrorCode.SkuOfferMismatch),
37
+ [ErrorCode.ItemNotOwned]: toStandardizedCode(ErrorCode.ItemNotOwned),
38
+ [ErrorCode.BillingUnavailable]: toStandardizedCode(ErrorCode.BillingUnavailable),
39
+ [ErrorCode.FeatureNotSupported]: toStandardizedCode(ErrorCode.FeatureNotSupported),
40
+ [ErrorCode.EmptySkuList]: toStandardizedCode(ErrorCode.EmptySkuList),
41
+ };
42
+ /**
43
+ * Mapping between platforms and their canonical error codes.
44
+ * Values are platform-native string identifiers.
45
+ */
46
+ export const ErrorCodeMapping = {
47
+ ios: COMMON_ERROR_CODE_MAP,
48
+ android: COMMON_ERROR_CODE_MAP,
49
+ };
50
+ /**
51
+ * Error thrown by expo-iap when purchases fail.
52
+ */
53
+ export class PurchaseError extends Error {
54
+ responseCode;
55
+ debugMessage;
56
+ code;
57
+ productId;
58
+ platform;
59
+ constructor(messageOrProps, responseCode, debugMessage, code, productId, platform) {
60
+ super(typeof messageOrProps === 'string'
61
+ ? messageOrProps
62
+ : messageOrProps.message);
63
+ this.name = '[expo-iap]: PurchaseError';
64
+ Object.setPrototypeOf(this, new.target.prototype);
65
+ if (typeof messageOrProps === 'string') {
66
+ this.responseCode = responseCode;
67
+ this.debugMessage = debugMessage;
68
+ this.code = code;
69
+ this.productId = productId;
70
+ this.platform = platform;
71
+ }
72
+ else {
73
+ this.responseCode = messageOrProps.responseCode;
74
+ this.debugMessage = messageOrProps.debugMessage;
75
+ this.code = messageOrProps.code;
76
+ this.productId = messageOrProps.productId;
77
+ this.platform = messageOrProps.platform;
78
+ }
79
+ }
80
+ /**
81
+ * Create a {@link PurchaseError} from raw platform error data.
82
+ */
83
+ static fromPlatformError(errorData, platform) {
84
+ const normalizedPlatform = normalizePlatform(platform);
85
+ const errorCode = errorData.code
86
+ ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)
87
+ : ErrorCode.Unknown;
88
+ return new PurchaseError({
89
+ message: errorData.message ?? 'Unknown error occurred',
90
+ responseCode: errorData.responseCode,
91
+ debugMessage: errorData.debugMessage,
92
+ code: errorCode,
93
+ productId: errorData.productId,
94
+ platform,
95
+ });
96
+ }
97
+ /**
98
+ * Returns the platform specific error code for this instance.
99
+ */
100
+ getPlatformCode() {
101
+ if (!this.code || !this.platform) {
102
+ return undefined;
103
+ }
104
+ return ErrorCodeUtils.toPlatformCode(this.code, this.platform);
105
+ }
106
+ }
107
+ /** Utility helpers for translating error codes between platforms. */
108
+ export const ErrorCodeUtils = {
109
+ /**
110
+ * Returns the native error code for the provided {@link ErrorCode}.
111
+ */
112
+ getNativeErrorCode: (errorCode) => {
113
+ const standardized = toStandardizedCode(errorCode);
114
+ return (NATIVE_ERROR_CODES[standardized] ?? standardized);
115
+ },
116
+ /**
117
+ * Converts a platform-specific error code into a standardized {@link ErrorCode}.
118
+ */
119
+ fromPlatformCode: (platformCode, _platform) => {
120
+ if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {
121
+ if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {
122
+ const match = Object.entries(COMMON_ERROR_CODE_MAP).find(([, value]) => value === platformCode);
123
+ if (match) {
124
+ return match[0];
125
+ }
126
+ }
127
+ }
128
+ for (const [standardized, nativeCode] of Object.entries((NATIVE_ERROR_CODES || {}))) {
129
+ if (nativeCode === platformCode &&
130
+ OPENIAP_ERROR_CODE_SET.has(standardized)) {
131
+ const match = Object.entries(COMMON_ERROR_CODE_MAP).find(([, mappedCode]) => mappedCode === standardized);
132
+ if (match) {
133
+ return match[0];
134
+ }
135
+ }
136
+ }
137
+ for (const [errorCode, mappedCode] of Object.entries(COMMON_ERROR_CODE_MAP)) {
138
+ if (mappedCode === platformCode) {
139
+ return errorCode;
140
+ }
141
+ }
142
+ return ErrorCode.Unknown;
143
+ },
144
+ /**
145
+ * Converts a standardized {@link ErrorCode} into its platform-specific value.
146
+ */
147
+ toPlatformCode: (errorCode, _platform) => {
148
+ const standardized = toStandardizedCode(errorCode);
149
+ const native = NATIVE_ERROR_CODES[standardized];
150
+ return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';
151
+ },
152
+ /**
153
+ * Determines whether the error code is supported on the given platform.
154
+ */
155
+ isValidForPlatform: (errorCode, platform) => {
156
+ const standardized = toStandardizedCode(errorCode);
157
+ if (NATIVE_ERROR_CODES[standardized] !==
158
+ undefined) {
159
+ return true;
160
+ }
161
+ return standardized in ErrorCodeMapping[normalizePlatform(platform)];
162
+ },
163
+ };
164
+ //# sourceMappingURL=purchase-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purchase-error.js","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,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C,CAAC,CAAC;IACvE,CAAC;CACF,CAAC","sourcesContent":["import {NATIVE_ERROR_CODES} from './ExpoIapModule';\nimport {ErrorCode, Platform} from './types';\n\n/** Platform identifiers supported by {@link PurchaseError}. */\nexport type PurchaseErrorPlatform = Platform | 'ios' | 'android';\n\n/** Properties used to construct a {@link PurchaseError}. */\nexport interface PurchaseErrorProps {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: PurchaseErrorPlatform;\n}\n\n/** Shape of raw platform error objects coming from native modules. */\ntype PlatformErrorData = {\n code?: string | number;\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n productId?: string;\n};\n\nconst toStandardizedCode = (errorCode: ErrorCode): string =>\n errorCode.startsWith('E_') ? errorCode : `E_${errorCode}`;\n\nconst normalizePlatform = (\n platform: PurchaseErrorPlatform,\n): 'ios' | 'android' =>\n platform === Platform.Ios || platform === 'ios' ? 'ios' : 'android';\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode).map((code) => toStandardizedCode(code)),\n);\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: toStandardizedCode(ErrorCode.Unknown),\n [ErrorCode.UserCancelled]: toStandardizedCode(ErrorCode.UserCancelled),\n [ErrorCode.UserError]: toStandardizedCode(ErrorCode.UserError),\n [ErrorCode.ItemUnavailable]: toStandardizedCode(ErrorCode.ItemUnavailable),\n [ErrorCode.RemoteError]: toStandardizedCode(ErrorCode.RemoteError),\n [ErrorCode.NetworkError]: toStandardizedCode(ErrorCode.NetworkError),\n [ErrorCode.ServiceError]: toStandardizedCode(ErrorCode.ServiceError),\n [ErrorCode.ReceiptFailed]: toStandardizedCode(ErrorCode.ReceiptFailed),\n [ErrorCode.ReceiptFinished]: toStandardizedCode(ErrorCode.ReceiptFinished),\n [ErrorCode.ReceiptFinishedFailed]: toStandardizedCode(\n ErrorCode.ReceiptFinishedFailed,\n ),\n [ErrorCode.NotPrepared]: toStandardizedCode(ErrorCode.NotPrepared),\n [ErrorCode.NotEnded]: toStandardizedCode(ErrorCode.NotEnded),\n [ErrorCode.AlreadyOwned]: toStandardizedCode(ErrorCode.AlreadyOwned),\n [ErrorCode.DeveloperError]: toStandardizedCode(ErrorCode.DeveloperError),\n [ErrorCode.BillingResponseJsonParseError]: toStandardizedCode(\n ErrorCode.BillingResponseJsonParseError,\n ),\n [ErrorCode.DeferredPayment]: toStandardizedCode(ErrorCode.DeferredPayment),\n [ErrorCode.Interrupted]: toStandardizedCode(ErrorCode.Interrupted),\n [ErrorCode.IapNotAvailable]: toStandardizedCode(ErrorCode.IapNotAvailable),\n [ErrorCode.PurchaseError]: toStandardizedCode(ErrorCode.PurchaseError),\n [ErrorCode.SyncError]: toStandardizedCode(ErrorCode.SyncError),\n [ErrorCode.TransactionValidationFailed]: toStandardizedCode(\n ErrorCode.TransactionValidationFailed,\n ),\n [ErrorCode.ActivityUnavailable]: toStandardizedCode(\n ErrorCode.ActivityUnavailable,\n ),\n [ErrorCode.AlreadyPrepared]: toStandardizedCode(ErrorCode.AlreadyPrepared),\n [ErrorCode.Pending]: toStandardizedCode(ErrorCode.Pending),\n [ErrorCode.ConnectionClosed]: toStandardizedCode(ErrorCode.ConnectionClosed),\n [ErrorCode.InitConnection]: toStandardizedCode(ErrorCode.InitConnection),\n [ErrorCode.ServiceDisconnected]: toStandardizedCode(\n ErrorCode.ServiceDisconnected,\n ),\n [ErrorCode.QueryProduct]: toStandardizedCode(ErrorCode.QueryProduct),\n [ErrorCode.SkuNotFound]: toStandardizedCode(ErrorCode.SkuNotFound),\n [ErrorCode.SkuOfferMismatch]: toStandardizedCode(ErrorCode.SkuOfferMismatch),\n [ErrorCode.ItemNotOwned]: toStandardizedCode(ErrorCode.ItemNotOwned),\n [ErrorCode.BillingUnavailable]: toStandardizedCode(\n ErrorCode.BillingUnavailable,\n ),\n [ErrorCode.FeatureNotSupported]: toStandardizedCode(\n ErrorCode.FeatureNotSupported,\n ),\n [ErrorCode.EmptySkuList]: toStandardizedCode(ErrorCode.EmptySkuList),\n};\n\n/**\n * Mapping between platforms and their canonical error codes.\n * Values are platform-native string identifiers.\n */\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\n/**\n * Error thrown by expo-iap when purchases fail.\n */\nexport class PurchaseError extends Error {\n public responseCode?: number;\n public debugMessage?: string;\n public code?: ErrorCode;\n public productId?: string;\n public platform?: PurchaseErrorPlatform;\n\n constructor(\n message: string,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: PurchaseErrorPlatform,\n );\n constructor(props: PurchaseErrorProps);\n constructor(\n messageOrProps: string | PurchaseErrorProps,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: PurchaseErrorPlatform,\n ) {\n super(\n typeof messageOrProps === 'string'\n ? messageOrProps\n : messageOrProps.message,\n );\n this.name = '[expo-iap]: PurchaseError';\n Object.setPrototypeOf(this, new.target.prototype);\n\n if (typeof messageOrProps === 'string') {\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n this.platform = platform;\n } else {\n this.responseCode = messageOrProps.responseCode;\n this.debugMessage = messageOrProps.debugMessage;\n this.code = messageOrProps.code;\n this.productId = messageOrProps.productId;\n this.platform = messageOrProps.platform;\n }\n }\n\n /**\n * Create a {@link PurchaseError} from raw platform error data.\n */\n static fromPlatformError(\n errorData: PlatformErrorData,\n platform: PurchaseErrorPlatform,\n ): PurchaseError {\n const normalizedPlatform = normalizePlatform(platform);\n\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : ErrorCode.Unknown;\n\n return new PurchaseError({\n message: errorData.message ?? 'Unknown error occurred',\n responseCode: errorData.responseCode,\n debugMessage: errorData.debugMessage,\n code: errorCode,\n productId: errorData.productId,\n platform,\n });\n }\n\n /**\n * Returns the platform specific error code for this instance.\n */\n getPlatformCode(): string | number | undefined {\n if (!this.code || !this.platform) {\n return undefined;\n }\n return ErrorCodeUtils.toPlatformCode(this.code, this.platform);\n }\n}\n\n/** Utility helpers for translating error codes between platforms. */\nexport const ErrorCodeUtils = {\n /**\n * Returns the native error code for the provided {@link ErrorCode}.\n */\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n const standardized = toStandardizedCode(errorCode);\n return (\n (NATIVE_ERROR_CODES as Record<string, string | undefined>)[\n standardized\n ] ?? standardized\n );\n },\n /**\n * Converts a platform-specific error code into a standardized {@link ErrorCode}.\n */\n fromPlatformCode: (\n platformCode: string | number,\n _platform: PurchaseErrorPlatform,\n ): ErrorCode => {\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, value]) => value === platformCode,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [standardized, nativeCode] of Object.entries(\n (NATIVE_ERROR_CODES || {}) as Record<string, string | number>,\n )) {\n if (\n nativeCode === platformCode &&\n OPENIAP_ERROR_CODE_SET.has(standardized)\n ) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, mappedCode]) => mappedCode === standardized,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [errorCode, mappedCode] of Object.entries(\n COMMON_ERROR_CODE_MAP,\n )) {\n if (mappedCode === platformCode) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.Unknown;\n },\n /**\n * Converts a standardized {@link ErrorCode} into its platform-specific value.\n */\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: PurchaseErrorPlatform,\n ): string | number => {\n const standardized = toStandardizedCode(errorCode);\n const native = (NATIVE_ERROR_CODES as Record<string, string | number>)[\n standardized\n ];\n return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';\n },\n /**\n * Determines whether the error code is supported on the given platform.\n */\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: PurchaseErrorPlatform,\n ): boolean => {\n const standardized = toStandardizedCode(errorCode);\n if (\n (NATIVE_ERROR_CODES as Record<string, unknown>)[standardized] !==\n undefined\n ) {\n return true;\n }\n return standardized in ErrorCodeMapping[normalizePlatform(platform)];\n },\n};\n"]}