expo-iap 5.6.1 → 5.6.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"errorMapping.d.ts","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC5B,MAAM,UAAU,CAAC;AAgBlB,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,wBAAwB,CAAC;AA0FnE,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAuCX,eAAO,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,KAAG,OAAO;CAE5E,CAAC;AAMF,KAAK,SAAS,GAAG,MAAM,GAAG;IAAC,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AAiDxE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWtD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc1D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAoDpE"}
@@ -33,12 +33,50 @@ const asBoolean = (value) => typeof value === 'boolean' ? value : undefined;
33
33
  const asStringArray = (value) => Array.isArray(value)
34
34
  ? value.filter((candidate) => typeof candidate === 'string')
35
35
  : undefined;
36
+ // On iOS, Expo appends " (at <file>:<line>)" to a rejected function's message,
37
+ // so the envelope is rarely the end of the string. Take the object and stop there.
38
+ const sliceEnvelopeObject = (payload) => {
39
+ const start = payload.indexOf('{');
40
+ if (start < 0)
41
+ return undefined;
42
+ let depth = 0;
43
+ let inString = false;
44
+ let escaped = false;
45
+ for (let index = start; index < payload.length; index += 1) {
46
+ const character = payload[index];
47
+ if (escaped) {
48
+ escaped = false;
49
+ continue;
50
+ }
51
+ if (character === '\\') {
52
+ escaped = true;
53
+ continue;
54
+ }
55
+ if (character === '"') {
56
+ inString = !inString;
57
+ continue;
58
+ }
59
+ if (inString)
60
+ continue;
61
+ if (character === '{')
62
+ depth += 1;
63
+ else if (character === '}') {
64
+ depth -= 1;
65
+ if (depth === 0)
66
+ return payload.slice(start, index + 1);
67
+ }
68
+ }
69
+ return undefined;
70
+ };
36
71
  const parseNativeErrorEnvelope = (message) => {
37
72
  const markerIndex = message.indexOf(OPENIAP_ERROR_ENVELOPE_PREFIX);
38
73
  if (markerIndex < 0)
39
74
  return undefined;
75
+ const envelope = sliceEnvelopeObject(message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length));
76
+ if (envelope === undefined)
77
+ return undefined;
40
78
  try {
41
- return asRecord(JSON.parse(message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length)));
79
+ return asRecord(JSON.parse(envelope));
42
80
  }
43
81
  catch {
44
82
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,SAAS,GAGV,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE;IAC1C,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,GAAG;aACP,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;aACjC,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,GAAG;aACP,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;aAC1B,WAAW,EAAE;aACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AA2BF;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AAInE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA6B,EAAE,CAC7D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;IACzC,CAAC,CAAE,KAAuB;IAC1B,CAAC,CAAC,SAAS,CAAC;AAEhB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAsB,EAAE,CACtD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhD,MAAM,QAAQ,GAAG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O,iDAAiD,CAAC;QAC3D,KAAK,SAAS,CAAC,kBAAkB;YAC/B,OAAO,mDAAmD,CAAC;QAC7D,KAAK,SAAS,CAAC,eAAe;YAC5B,OAAO,yCAAyC,CAAC;QACnD,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,yBAAyB,CAAC;QACnC,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,2BAA2B,CAAC;QACrC,KAAK,SAAS,CAAC,WAAW;YACxB,OAAO,sCAAsC,CAAC;QAChD,KAAK,SAAS,CAAC,gBAAgB;YAC7B,OAAO,uCAAuC,CAAC;QACjD,KAAK,SAAS,CAAC,eAAe;YAC5B,OAAO,6BAA6B,CAAC;QACvC,KAAK,SAAS,CAAC,WAAW;YACxB,OAAO,uDAAuD,CAAC;QACjE,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,8CAA8C,CAAC;QACxD,KAAK,SAAS,CAAC,mBAAmB;YAChC,OAAO,+CAA+C,CAAC;QACzD,KAAK,SAAS,CAAC,2BAA2B;YACxC,OAAO,mCAAmC,CAAC;QAC7C,KAAK,SAAS,CAAC,0BAA0B;YACvC,OAAO,8BAA8B,CAAC;QACxC,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,yBAAyB,CAAC;QACnC,KAAK,SAAS,CAAC,cAAc;YAC3B,OAAO,yCAAyC,CAAC;QACnD,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,mDAAmD,CAAC;QAC7D,OAAO,CAAC,CAAC,CAAC;YACR,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;gBAC7D,OAAO,CACJ,KAA4B,CAAC,OAAO;oBACrC,8BAA8B,CAC/B,CAAC;YACJ,CAAC;YACD,OAAO,8BAA8B,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Error mapping utilities for expo-iap.\n * Provides helpers for working with platform-specific error codes\n * and constructing structured purchase errors.\n */\n\nimport {\n ErrorCode,\n type IapPlatform,\n type SubResponseCodeAndroid,\n} from '../types';\n\nconst toKebabCase = (str: string): string => {\n if (str.includes('_')) {\n return str\n .split('_')\n .map((word) => word.toLowerCase())\n .join('-');\n } else {\n return str\n .replace(/([A-Z])/g, '-$1')\n .toLowerCase()\n .replace(/^-/, '');\n }\n};\n\nexport interface PurchaseErrorProps {\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode | string | number;\n productId?: string;\n productIds?: string[];\n productType?: string;\n isEmptyProductList?: boolean;\n subResponseCodeAndroid?: SubResponseCodeAndroid;\n platform?: IapPlatform;\n}\n\nexport interface PurchaseError extends Error {\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n productIds?: string[];\n productType?: string;\n isEmptyProductList?: boolean;\n subResponseCodeAndroid?: SubResponseCodeAndroid;\n platform?: IapPlatform;\n}\n\n/**\n * Prefix shared with the native Expo bridges. Expo Modules only transports an\n * exception code and message for rejected async functions, so native bridges\n * append the canonical PurchaseError payload to the message with this marker.\n */\nexport const OPENIAP_ERROR_ENVELOPE_PREFIX = 'OPENIAP_ERROR_JSON:';\n\ntype UnknownRecord = Record<string, unknown>;\n\nconst asRecord = (value: unknown): UnknownRecord | undefined =>\n typeof value === 'object' && value !== null\n ? (value as UnknownRecord)\n : undefined;\n\nconst asString = (value: unknown): string | undefined =>\n typeof value === 'string' ? value : undefined;\n\nconst asNumber = (value: unknown): number | undefined =>\n typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n\nconst asBoolean = (value: unknown): boolean | undefined =>\n typeof value === 'boolean' ? value : undefined;\n\nconst asStringArray = (value: unknown): string[] | undefined =>\n Array.isArray(value)\n ? value.filter(\n (candidate): candidate is string => typeof candidate === 'string',\n )\n : undefined;\n\nconst parseNativeErrorEnvelope = (\n message: string,\n): UnknownRecord | undefined => {\n const markerIndex = message.indexOf(OPENIAP_ERROR_ENVELOPE_PREFIX);\n if (markerIndex < 0) return undefined;\n\n try {\n return asRecord(\n JSON.parse(\n message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length),\n ),\n );\n } catch {\n return undefined;\n }\n};\n\nconst normalizePlatform = (platform: IapPlatform): 'ios' | 'android' =>\n typeof platform === 'string' && platform.toLowerCase() === 'ios'\n ? 'ios'\n : 'android';\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: ErrorCode.Unknown,\n [ErrorCode.UserCancelled]: ErrorCode.UserCancelled,\n [ErrorCode.UserError]: ErrorCode.UserError,\n [ErrorCode.ItemUnavailable]: ErrorCode.ItemUnavailable,\n [ErrorCode.RemoteError]: ErrorCode.RemoteError,\n [ErrorCode.NetworkError]: ErrorCode.NetworkError,\n [ErrorCode.ServiceError]: ErrorCode.ServiceError,\n [ErrorCode.NotPrepared]: ErrorCode.NotPrepared,\n [ErrorCode.NotEnded]: ErrorCode.NotEnded,\n [ErrorCode.AlreadyOwned]: ErrorCode.AlreadyOwned,\n [ErrorCode.DeveloperError]: ErrorCode.DeveloperError,\n [ErrorCode.BillingResponseJsonParseError]:\n ErrorCode.BillingResponseJsonParseError,\n [ErrorCode.DeferredPayment]: ErrorCode.DeferredPayment,\n [ErrorCode.Interrupted]: ErrorCode.Interrupted,\n [ErrorCode.IapNotAvailable]: ErrorCode.IapNotAvailable,\n [ErrorCode.PurchaseError]: ErrorCode.PurchaseError,\n [ErrorCode.SyncError]: ErrorCode.SyncError,\n [ErrorCode.TransactionValidationFailed]:\n ErrorCode.TransactionValidationFailed,\n [ErrorCode.ActivityUnavailable]: ErrorCode.ActivityUnavailable,\n [ErrorCode.AlreadyPrepared]: ErrorCode.AlreadyPrepared,\n [ErrorCode.Pending]: ErrorCode.Pending,\n [ErrorCode.ConnectionClosed]: ErrorCode.ConnectionClosed,\n [ErrorCode.InitConnection]: ErrorCode.InitConnection,\n [ErrorCode.ServiceDisconnected]: ErrorCode.ServiceDisconnected,\n [ErrorCode.QueryProduct]: ErrorCode.QueryProduct,\n [ErrorCode.SkuNotFound]: ErrorCode.SkuNotFound,\n [ErrorCode.SkuOfferMismatch]: ErrorCode.SkuOfferMismatch,\n [ErrorCode.ItemNotOwned]: ErrorCode.ItemNotOwned,\n [ErrorCode.BillingUnavailable]: ErrorCode.BillingUnavailable,\n [ErrorCode.FeatureNotSupported]: ErrorCode.FeatureNotSupported,\n [ErrorCode.DuplicatePurchase]: ErrorCode.DuplicatePurchase,\n [ErrorCode.ServiceTimeout]: ErrorCode.ServiceTimeout,\n [ErrorCode.EmptySkuList]: ErrorCode.EmptySkuList,\n [ErrorCode.PurchaseVerificationFailed]: ErrorCode.PurchaseVerificationFailed,\n [ErrorCode.PurchaseVerificationFinishFailed]:\n ErrorCode.PurchaseVerificationFinishFailed,\n [ErrorCode.PurchaseVerificationFinished]:\n ErrorCode.PurchaseVerificationFinished,\n};\n\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(Object.values(ErrorCode));\n\nconst HISTORICAL_ERROR_CODE_INPUTS: Record<string, ErrorCode> = {\n RECEIPT_FAILED: ErrorCode.PurchaseVerificationFailed,\n E_RECEIPT_FAILED: ErrorCode.PurchaseVerificationFailed,\n RECEIPT_FINISHED: ErrorCode.PurchaseVerificationFinished,\n E_RECEIPT_FINISHED: ErrorCode.PurchaseVerificationFinished,\n RECEIPT_FINISHED_FAILED: ErrorCode.PurchaseVerificationFinishFailed,\n E_RECEIPT_FINISHED_FAILED: ErrorCode.PurchaseVerificationFinishFailed,\n};\n\nconst historicalErrorCode = (code: string): ErrorCode | undefined =>\n HISTORICAL_ERROR_CODE_INPUTS[\n code\n .trim()\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/-/g, '_')\n .toUpperCase()\n ];\n\n// Legacy Google Play Billing response codes accepted by older JS call sites.\n// Native ERROR_CODES constants are code -> message tables, not response-code maps.\nconst LEGACY_ANDROID_RESPONSE_CODES = new Map<number, ErrorCode>([\n [-3, ErrorCode.ServiceTimeout],\n [-2, ErrorCode.FeatureNotSupported],\n [-1, ErrorCode.ServiceDisconnected],\n [1, ErrorCode.UserCancelled],\n [2, ErrorCode.ServiceError],\n [3, ErrorCode.BillingUnavailable],\n [4, ErrorCode.ItemUnavailable],\n [5, ErrorCode.DeveloperError],\n [6, ErrorCode.ServiceError],\n [7, ErrorCode.AlreadyOwned],\n [8, ErrorCode.ItemNotOwned],\n [12, ErrorCode.NetworkError],\n]);\n\nexport const createPurchaseError = (\n props: PurchaseErrorProps,\n): PurchaseError => {\n const errorCode = props.code\n ? typeof props.code === 'string' || typeof props.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(props.code, props.platform || 'ios')\n : props.code\n : undefined;\n\n const error = new Error(\n props.message ?? 'Unknown error occurred',\n ) as PurchaseError;\n error.name = '[expo-iap]: PurchaseError';\n error.responseCode = props.responseCode;\n error.debugMessage = props.debugMessage;\n error.code = errorCode;\n error.productId = props.productId;\n error.productIds = props.productIds;\n error.productType = props.productType;\n error.isEmptyProductList = props.isEmptyProductList;\n error.subResponseCodeAndroid = props.subResponseCodeAndroid;\n error.platform = props.platform;\n return error;\n};\n\nexport const createPurchaseErrorFromPlatform = (\n errorData: PurchaseErrorProps,\n platform: IapPlatform,\n): PurchaseError => {\n const normalizedPlatform = normalizePlatform(platform);\n const errorCode = errorData.code\n ? typeof errorData.code === 'string' || typeof errorData.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : errorData.code\n : ErrorCode.Unknown;\n\n return createPurchaseError({\n message: errorData.message ?? 'Unknown error occurred',\n responseCode: errorData.responseCode,\n debugMessage: errorData.debugMessage,\n code: errorCode,\n productId: errorData.productId,\n productIds: errorData.productIds,\n productType: errorData.productType,\n isEmptyProductList: errorData.isEmptyProductList,\n subResponseCodeAndroid: errorData.subResponseCodeAndroid,\n platform,\n });\n};\n\n/**\n * Rebuild a canonical PurchaseError from an Expo Modules Promise rejection.\n *\n * Native Expo async functions cannot attach arbitrary fields to the rejected\n * JavaScript Error. The iOS and Android bridges therefore place the complete\n * payload in a marked JSON envelope inside the rejection message. This helper\n * also accepts direct fields so the Vega/Onside adapters and older native\n * builds continue to work.\n */\nexport const createPurchaseErrorFromNativeException = (\n error: unknown,\n platform: IapPlatform,\n fallback: PurchaseErrorProps = {},\n): PurchaseError => {\n const direct = asRecord(error) ?? {};\n const nativeMessage =\n asString(direct.message) ??\n (typeof error === 'string' ? error : undefined) ??\n fallback.message ??\n 'Unknown error occurred';\n const envelope = parseNativeErrorEnvelope(nativeMessage) ?? {};\n\n const envelopePlatform = asString(envelope.platform);\n const resolvedPlatform: IapPlatform =\n envelopePlatform === 'ios' || envelopePlatform === 'android'\n ? envelopePlatform\n : platform;\n const subResponseCode =\n asString(envelope.subResponseCodeAndroid) ??\n asString(direct.subResponseCodeAndroid) ??\n fallback.subResponseCodeAndroid;\n\n return createPurchaseErrorFromPlatform(\n {\n code:\n asString(envelope.code) ??\n asNumber(envelope.code) ??\n asString(direct.code) ??\n asNumber(direct.code) ??\n fallback.code ??\n ErrorCode.Unknown,\n message: asString(envelope.message) ?? fallback.message ?? nativeMessage,\n debugMessage:\n asString(envelope.debugMessage) ??\n asString(direct.debugMessage) ??\n fallback.debugMessage,\n responseCode:\n asNumber(envelope.responseCode) ??\n asNumber(direct.responseCode) ??\n fallback.responseCode,\n productId:\n asString(envelope.productId) ??\n asString(direct.productId) ??\n fallback.productId,\n productIds:\n asStringArray(envelope.productIds) ??\n asStringArray(direct.productIds) ??\n fallback.productIds,\n productType:\n asString(envelope.productType) ??\n asString(direct.productType) ??\n fallback.productType,\n isEmptyProductList:\n asBoolean(envelope.isEmptyProductList) ??\n asBoolean(direct.isEmptyProductList) ??\n fallback.isEmptyProductList,\n subResponseCodeAndroid: subResponseCode as\n SubResponseCodeAndroid | undefined,\n platform: resolvedPlatform,\n },\n resolvedPlatform,\n );\n};\n\nexport const ErrorCodeUtils = {\n // OpenIAP native bridges already exchange canonical error-code strings.\n getNativeErrorCode: (errorCode: ErrorCode): string => errorCode,\n fromPlatformCode: (\n platformCode: string | number | null | undefined,\n platform: IapPlatform,\n ): ErrorCode => {\n if (platformCode == null) {\n return ErrorCode.Unknown;\n }\n if (typeof platformCode === 'number') {\n return normalizePlatform(platform) === 'android'\n ? (LEGACY_ANDROID_RESPONSE_CODES.get(platformCode) ?? ErrorCode.Unknown)\n : ErrorCode.Unknown;\n }\n const historical = historicalErrorCode(platformCode);\n if (historical) {\n return historical;\n }\n const normalized = toKebabCase(platformCode.replace(/^E_/i, ''));\n return OPENIAP_ERROR_CODE_SET.has(normalized)\n ? (normalized as ErrorCode)\n : ErrorCode.Unknown;\n },\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: IapPlatform,\n ): string | number => errorCode,\n isValidForPlatform: (errorCode: ErrorCode, _platform: IapPlatform): boolean =>\n OPENIAP_ERROR_CODE_SET.has(errorCode),\n};\n\n// ---------------------------------------------------------------------------\n// Convenience helpers for interpreting error objects\n// ---------------------------------------------------------------------------\n\ntype ErrorLike = string | {code?: ErrorCode | string; message?: string};\n\nconst ERROR_CODES = new Set<string>(Object.values(ErrorCode));\n\nconst normalizeErrorCode = (code?: string | null): string | undefined => {\n if (!code) {\n return undefined;\n }\n\n if (ERROR_CODES.has(code)) {\n return code;\n }\n\n const historical = historicalErrorCode(code);\n if (historical) {\n return historical;\n }\n\n const camelCased = toKebabCase(code);\n if (ERROR_CODES.has(camelCased)) {\n return camelCased;\n }\n\n if (code.startsWith('E_')) {\n const trimmed = code.substring(2);\n if (ERROR_CODES.has(trimmed)) {\n return trimmed;\n }\n const camelTrimmed = toKebabCase(trimmed);\n if (ERROR_CODES.has(camelTrimmed)) {\n return camelTrimmed;\n }\n }\n\n return code;\n};\n\nfunction extractCode(error: unknown): string | undefined {\n if (typeof error === 'string') {\n return normalizeErrorCode(error);\n }\n\n if (error && typeof error === 'object' && 'code' in error) {\n return normalizeErrorCode((error as {code?: string}).code);\n }\n\n return undefined;\n}\n\nexport function isUserCancelledError(error: unknown): boolean {\n return extractCode(error) === ErrorCode.UserCancelled;\n}\n\nexport function isNetworkError(error: unknown): boolean {\n const networkErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ];\n\n const code = extractCode(error);\n return !!code && (networkErrors as string[]).includes(code);\n}\n\nexport function isRecoverableError(error: unknown): boolean {\n const recoverableErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.Interrupted,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ErrorCode.QueryProduct,\n ErrorCode.InitConnection,\n ];\n\n const code = extractCode(error);\n return !!code && (recoverableErrors as string[]).includes(code);\n}\n\n/**\n * End-user copy for a known error code, derived from the code by design: the\n * native message can name build configuration a customer must not be shown.\n * Developers get that diagnostic as `error.message`.\n */\nexport function getUserFriendlyErrorMessage(error: ErrorLike): string {\n const errorCode = extractCode(error);\n\n switch (errorCode) {\n case ErrorCode.UserCancelled:\n return 'Purchase was cancelled by user';\n case ErrorCode.NetworkError:\n return 'Network connection error. Please check your internet connection and try again.';\n case ErrorCode.PurchaseVerificationFinished:\n return 'Purchase verification already finished';\n case ErrorCode.ServiceDisconnected:\n return 'Billing service disconnected. Please try again.';\n case ErrorCode.BillingUnavailable:\n return 'Billing is unavailable on this device or account.';\n case ErrorCode.ItemUnavailable:\n return 'This item is not available for purchase';\n case ErrorCode.ItemNotOwned:\n return \"You don't own this item\";\n case ErrorCode.AlreadyOwned:\n return 'You already own this item';\n case ErrorCode.SkuNotFound:\n return 'Requested product could not be found';\n case ErrorCode.SkuOfferMismatch:\n return 'Selected offer does not match the SKU';\n case ErrorCode.DeferredPayment:\n return 'Payment is pending approval';\n case ErrorCode.NotPrepared:\n return 'In-app purchase is not ready. Please try again later.';\n case ErrorCode.ServiceError:\n return 'Store service error. Please try again later.';\n case ErrorCode.FeatureNotSupported:\n return 'This feature is not supported on this device.';\n case ErrorCode.TransactionValidationFailed:\n return 'Transaction could not be verified';\n case ErrorCode.PurchaseVerificationFailed:\n return 'Purchase verification failed';\n case ErrorCode.EmptySkuList:\n return 'No product IDs provided';\n case ErrorCode.InitConnection:\n return 'Failed to initialize billing connection';\n case ErrorCode.QueryProduct:\n return 'Failed to query products. Please try again later.';\n default: {\n if (error && typeof error === 'object' && 'message' in error) {\n return (\n (error as {message?: string}).message ??\n 'An unexpected error occurred'\n );\n }\n return 'An unexpected error occurred';\n }\n }\n}\n"]}
1
+ {"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,SAAS,GAGV,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE;IAC1C,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,GAAG;aACP,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;aACjC,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,GAAG;aACP,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;aAC1B,WAAW,EAAE;aACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AA2BF;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AAInE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA6B,EAAE,CAC7D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;IACzC,CAAC,CAAE,KAAuB;IAC1B,CAAC,CAA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AAC;YACD,OAAO,8BAA8B,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Error mapping utilities for expo-iap.\n * Provides helpers for working with platform-specific error codes\n * and constructing structured purchase errors.\n */\n\nimport {\n ErrorCode,\n type IapPlatform,\n type SubResponseCodeAndroid,\n} from '../types';\n\nconst toKebabCase = (str: string): string => {\n if (str.includes('_')) {\n return str\n .split('_')\n .map((word) => word.toLowerCase())\n .join('-');\n } else {\n return str\n .replace(/([A-Z])/g, '-$1')\n .toLowerCase()\n .replace(/^-/, '');\n }\n};\n\nexport interface PurchaseErrorProps {\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode | string | number;\n productId?: string;\n productIds?: string[];\n productType?: string;\n isEmptyProductList?: boolean;\n subResponseCodeAndroid?: SubResponseCodeAndroid;\n platform?: IapPlatform;\n}\n\nexport interface PurchaseError extends Error {\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n productIds?: string[];\n productType?: string;\n isEmptyProductList?: boolean;\n subResponseCodeAndroid?: SubResponseCodeAndroid;\n platform?: IapPlatform;\n}\n\n/**\n * Prefix shared with the native Expo bridges. Expo Modules only transports an\n * exception code and message for rejected async functions, so native bridges\n * append the canonical PurchaseError payload to the message with this marker.\n */\nexport const OPENIAP_ERROR_ENVELOPE_PREFIX = 'OPENIAP_ERROR_JSON:';\n\ntype UnknownRecord = Record<string, unknown>;\n\nconst asRecord = (value: unknown): UnknownRecord | undefined =>\n typeof value === 'object' && value !== null\n ? (value as UnknownRecord)\n : undefined;\n\nconst asString = (value: unknown): string | undefined =>\n typeof value === 'string' ? value : undefined;\n\nconst asNumber = (value: unknown): number | undefined =>\n typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n\nconst asBoolean = (value: unknown): boolean | undefined =>\n typeof value === 'boolean' ? value : undefined;\n\nconst asStringArray = (value: unknown): string[] | undefined =>\n Array.isArray(value)\n ? value.filter(\n (candidate): candidate is string => typeof candidate === 'string',\n )\n : undefined;\n\n// On iOS, Expo appends \" (at <file>:<line>)\" to a rejected function's message,\n// so the envelope is rarely the end of the string. Take the object and stop there.\nconst sliceEnvelopeObject = (payload: string): string | undefined => {\n const start = payload.indexOf('{');\n if (start < 0) return undefined;\n\n let depth = 0;\n let inString = false;\n let escaped = false;\n for (let index = start; index < payload.length; index += 1) {\n const character = payload[index];\n if (escaped) {\n escaped = false;\n continue;\n }\n if (character === '\\\\') {\n escaped = true;\n continue;\n }\n if (character === '\"') {\n inString = !inString;\n continue;\n }\n if (inString) continue;\n if (character === '{') depth += 1;\n else if (character === '}') {\n depth -= 1;\n if (depth === 0) return payload.slice(start, index + 1);\n }\n }\n return undefined;\n};\n\nconst parseNativeErrorEnvelope = (\n message: string,\n): UnknownRecord | undefined => {\n const markerIndex = message.indexOf(OPENIAP_ERROR_ENVELOPE_PREFIX);\n if (markerIndex < 0) return undefined;\n\n const envelope = sliceEnvelopeObject(\n message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length),\n );\n if (envelope === undefined) return undefined;\n\n try {\n return asRecord(JSON.parse(envelope));\n } catch {\n return undefined;\n }\n};\n\nconst normalizePlatform = (platform: IapPlatform): 'ios' | 'android' =>\n typeof platform === 'string' && platform.toLowerCase() === 'ios'\n ? 'ios'\n : 'android';\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: ErrorCode.Unknown,\n [ErrorCode.UserCancelled]: ErrorCode.UserCancelled,\n [ErrorCode.UserError]: ErrorCode.UserError,\n [ErrorCode.ItemUnavailable]: ErrorCode.ItemUnavailable,\n [ErrorCode.RemoteError]: ErrorCode.RemoteError,\n [ErrorCode.NetworkError]: ErrorCode.NetworkError,\n [ErrorCode.ServiceError]: ErrorCode.ServiceError,\n [ErrorCode.NotPrepared]: ErrorCode.NotPrepared,\n [ErrorCode.NotEnded]: ErrorCode.NotEnded,\n [ErrorCode.AlreadyOwned]: ErrorCode.AlreadyOwned,\n [ErrorCode.DeveloperError]: ErrorCode.DeveloperError,\n [ErrorCode.BillingResponseJsonParseError]:\n ErrorCode.BillingResponseJsonParseError,\n [ErrorCode.DeferredPayment]: ErrorCode.DeferredPayment,\n [ErrorCode.Interrupted]: ErrorCode.Interrupted,\n [ErrorCode.IapNotAvailable]: ErrorCode.IapNotAvailable,\n [ErrorCode.PurchaseError]: ErrorCode.PurchaseError,\n [ErrorCode.SyncError]: ErrorCode.SyncError,\n [ErrorCode.TransactionValidationFailed]:\n ErrorCode.TransactionValidationFailed,\n [ErrorCode.ActivityUnavailable]: ErrorCode.ActivityUnavailable,\n [ErrorCode.AlreadyPrepared]: ErrorCode.AlreadyPrepared,\n [ErrorCode.Pending]: ErrorCode.Pending,\n [ErrorCode.ConnectionClosed]: ErrorCode.ConnectionClosed,\n [ErrorCode.InitConnection]: ErrorCode.InitConnection,\n [ErrorCode.ServiceDisconnected]: ErrorCode.ServiceDisconnected,\n [ErrorCode.QueryProduct]: ErrorCode.QueryProduct,\n [ErrorCode.SkuNotFound]: ErrorCode.SkuNotFound,\n [ErrorCode.SkuOfferMismatch]: ErrorCode.SkuOfferMismatch,\n [ErrorCode.ItemNotOwned]: ErrorCode.ItemNotOwned,\n [ErrorCode.BillingUnavailable]: ErrorCode.BillingUnavailable,\n [ErrorCode.FeatureNotSupported]: ErrorCode.FeatureNotSupported,\n [ErrorCode.DuplicatePurchase]: ErrorCode.DuplicatePurchase,\n [ErrorCode.ServiceTimeout]: ErrorCode.ServiceTimeout,\n [ErrorCode.EmptySkuList]: ErrorCode.EmptySkuList,\n [ErrorCode.PurchaseVerificationFailed]: ErrorCode.PurchaseVerificationFailed,\n [ErrorCode.PurchaseVerificationFinishFailed]:\n ErrorCode.PurchaseVerificationFinishFailed,\n [ErrorCode.PurchaseVerificationFinished]:\n ErrorCode.PurchaseVerificationFinished,\n};\n\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(Object.values(ErrorCode));\n\nconst HISTORICAL_ERROR_CODE_INPUTS: Record<string, ErrorCode> = {\n RECEIPT_FAILED: ErrorCode.PurchaseVerificationFailed,\n E_RECEIPT_FAILED: ErrorCode.PurchaseVerificationFailed,\n RECEIPT_FINISHED: ErrorCode.PurchaseVerificationFinished,\n E_RECEIPT_FINISHED: ErrorCode.PurchaseVerificationFinished,\n RECEIPT_FINISHED_FAILED: ErrorCode.PurchaseVerificationFinishFailed,\n E_RECEIPT_FINISHED_FAILED: ErrorCode.PurchaseVerificationFinishFailed,\n};\n\nconst historicalErrorCode = (code: string): ErrorCode | undefined =>\n HISTORICAL_ERROR_CODE_INPUTS[\n code\n .trim()\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/-/g, '_')\n .toUpperCase()\n ];\n\n// Legacy Google Play Billing response codes accepted by older JS call sites.\n// Native ERROR_CODES constants are code -> message tables, not response-code maps.\nconst LEGACY_ANDROID_RESPONSE_CODES = new Map<number, ErrorCode>([\n [-3, ErrorCode.ServiceTimeout],\n [-2, ErrorCode.FeatureNotSupported],\n [-1, ErrorCode.ServiceDisconnected],\n [1, ErrorCode.UserCancelled],\n [2, ErrorCode.ServiceError],\n [3, ErrorCode.BillingUnavailable],\n [4, ErrorCode.ItemUnavailable],\n [5, ErrorCode.DeveloperError],\n [6, ErrorCode.ServiceError],\n [7, ErrorCode.AlreadyOwned],\n [8, ErrorCode.ItemNotOwned],\n [12, ErrorCode.NetworkError],\n]);\n\nexport const createPurchaseError = (\n props: PurchaseErrorProps,\n): PurchaseError => {\n const errorCode = props.code\n ? typeof props.code === 'string' || typeof props.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(props.code, props.platform || 'ios')\n : props.code\n : undefined;\n\n const error = new Error(\n props.message ?? 'Unknown error occurred',\n ) as PurchaseError;\n error.name = '[expo-iap]: PurchaseError';\n error.responseCode = props.responseCode;\n error.debugMessage = props.debugMessage;\n error.code = errorCode;\n error.productId = props.productId;\n error.productIds = props.productIds;\n error.productType = props.productType;\n error.isEmptyProductList = props.isEmptyProductList;\n error.subResponseCodeAndroid = props.subResponseCodeAndroid;\n error.platform = props.platform;\n return error;\n};\n\nexport const createPurchaseErrorFromPlatform = (\n errorData: PurchaseErrorProps,\n platform: IapPlatform,\n): PurchaseError => {\n const normalizedPlatform = normalizePlatform(platform);\n const errorCode = errorData.code\n ? typeof errorData.code === 'string' || typeof errorData.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : errorData.code\n : ErrorCode.Unknown;\n\n return createPurchaseError({\n message: errorData.message ?? 'Unknown error occurred',\n responseCode: errorData.responseCode,\n debugMessage: errorData.debugMessage,\n code: errorCode,\n productId: errorData.productId,\n productIds: errorData.productIds,\n productType: errorData.productType,\n isEmptyProductList: errorData.isEmptyProductList,\n subResponseCodeAndroid: errorData.subResponseCodeAndroid,\n platform,\n });\n};\n\n/**\n * Rebuild a canonical PurchaseError from an Expo Modules Promise rejection.\n *\n * Native Expo async functions cannot attach arbitrary fields to the rejected\n * JavaScript Error. The iOS and Android bridges therefore place the complete\n * payload in a marked JSON envelope inside the rejection message. This helper\n * also accepts direct fields so the Vega/Onside adapters and older native\n * builds continue to work.\n */\nexport const createPurchaseErrorFromNativeException = (\n error: unknown,\n platform: IapPlatform,\n fallback: PurchaseErrorProps = {},\n): PurchaseError => {\n const direct = asRecord(error) ?? {};\n const nativeMessage =\n asString(direct.message) ??\n (typeof error === 'string' ? error : undefined) ??\n fallback.message ??\n 'Unknown error occurred';\n const envelope = parseNativeErrorEnvelope(nativeMessage) ?? {};\n\n const envelopePlatform = asString(envelope.platform);\n const resolvedPlatform: IapPlatform =\n envelopePlatform === 'ios' || envelopePlatform === 'android'\n ? envelopePlatform\n : platform;\n const subResponseCode =\n asString(envelope.subResponseCodeAndroid) ??\n asString(direct.subResponseCodeAndroid) ??\n fallback.subResponseCodeAndroid;\n\n return createPurchaseErrorFromPlatform(\n {\n code:\n asString(envelope.code) ??\n asNumber(envelope.code) ??\n asString(direct.code) ??\n asNumber(direct.code) ??\n fallback.code ??\n ErrorCode.Unknown,\n message: asString(envelope.message) ?? fallback.message ?? nativeMessage,\n debugMessage:\n asString(envelope.debugMessage) ??\n asString(direct.debugMessage) ??\n fallback.debugMessage,\n responseCode:\n asNumber(envelope.responseCode) ??\n asNumber(direct.responseCode) ??\n fallback.responseCode,\n productId:\n asString(envelope.productId) ??\n asString(direct.productId) ??\n fallback.productId,\n productIds:\n asStringArray(envelope.productIds) ??\n asStringArray(direct.productIds) ??\n fallback.productIds,\n productType:\n asString(envelope.productType) ??\n asString(direct.productType) ??\n fallback.productType,\n isEmptyProductList:\n asBoolean(envelope.isEmptyProductList) ??\n asBoolean(direct.isEmptyProductList) ??\n fallback.isEmptyProductList,\n subResponseCodeAndroid: subResponseCode as\n SubResponseCodeAndroid | undefined,\n platform: resolvedPlatform,\n },\n resolvedPlatform,\n );\n};\n\nexport const ErrorCodeUtils = {\n // OpenIAP native bridges already exchange canonical error-code strings.\n getNativeErrorCode: (errorCode: ErrorCode): string => errorCode,\n fromPlatformCode: (\n platformCode: string | number | null | undefined,\n platform: IapPlatform,\n ): ErrorCode => {\n if (platformCode == null) {\n return ErrorCode.Unknown;\n }\n if (typeof platformCode === 'number') {\n return normalizePlatform(platform) === 'android'\n ? (LEGACY_ANDROID_RESPONSE_CODES.get(platformCode) ?? ErrorCode.Unknown)\n : ErrorCode.Unknown;\n }\n const historical = historicalErrorCode(platformCode);\n if (historical) {\n return historical;\n }\n const normalized = toKebabCase(platformCode.replace(/^E_/i, ''));\n return OPENIAP_ERROR_CODE_SET.has(normalized)\n ? (normalized as ErrorCode)\n : ErrorCode.Unknown;\n },\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: IapPlatform,\n ): string | number => errorCode,\n isValidForPlatform: (errorCode: ErrorCode, _platform: IapPlatform): boolean =>\n OPENIAP_ERROR_CODE_SET.has(errorCode),\n};\n\n// ---------------------------------------------------------------------------\n// Convenience helpers for interpreting error objects\n// ---------------------------------------------------------------------------\n\ntype ErrorLike = string | {code?: ErrorCode | string; message?: string};\n\nconst ERROR_CODES = new Set<string>(Object.values(ErrorCode));\n\nconst normalizeErrorCode = (code?: string | null): string | undefined => {\n if (!code) {\n return undefined;\n }\n\n if (ERROR_CODES.has(code)) {\n return code;\n }\n\n const historical = historicalErrorCode(code);\n if (historical) {\n return historical;\n }\n\n const camelCased = toKebabCase(code);\n if (ERROR_CODES.has(camelCased)) {\n return camelCased;\n }\n\n if (code.startsWith('E_')) {\n const trimmed = code.substring(2);\n if (ERROR_CODES.has(trimmed)) {\n return trimmed;\n }\n const camelTrimmed = toKebabCase(trimmed);\n if (ERROR_CODES.has(camelTrimmed)) {\n return camelTrimmed;\n }\n }\n\n return code;\n};\n\nfunction extractCode(error: unknown): string | undefined {\n if (typeof error === 'string') {\n return normalizeErrorCode(error);\n }\n\n if (error && typeof error === 'object' && 'code' in error) {\n return normalizeErrorCode((error as {code?: string}).code);\n }\n\n return undefined;\n}\n\nexport function isUserCancelledError(error: unknown): boolean {\n return extractCode(error) === ErrorCode.UserCancelled;\n}\n\nexport function isNetworkError(error: unknown): boolean {\n const networkErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ];\n\n const code = extractCode(error);\n return !!code && (networkErrors as string[]).includes(code);\n}\n\nexport function isRecoverableError(error: unknown): boolean {\n const recoverableErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.Interrupted,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ErrorCode.QueryProduct,\n ErrorCode.InitConnection,\n ];\n\n const code = extractCode(error);\n return !!code && (recoverableErrors as string[]).includes(code);\n}\n\n/**\n * End-user copy for a known error code, derived from the code by design: the\n * native message can name build configuration a customer must not be shown.\n * Developers get that diagnostic as `error.message`.\n */\nexport function getUserFriendlyErrorMessage(error: ErrorLike): string {\n const errorCode = extractCode(error);\n\n switch (errorCode) {\n case ErrorCode.UserCancelled:\n return 'Purchase was cancelled by user';\n case ErrorCode.NetworkError:\n return 'Network connection error. Please check your internet connection and try again.';\n case ErrorCode.PurchaseVerificationFinished:\n return 'Purchase verification already finished';\n case ErrorCode.ServiceDisconnected:\n return 'Billing service disconnected. Please try again.';\n case ErrorCode.BillingUnavailable:\n return 'Billing is unavailable on this device or account.';\n case ErrorCode.ItemUnavailable:\n return 'This item is not available for purchase';\n case ErrorCode.ItemNotOwned:\n return \"You don't own this item\";\n case ErrorCode.AlreadyOwned:\n return 'You already own this item';\n case ErrorCode.SkuNotFound:\n return 'Requested product could not be found';\n case ErrorCode.SkuOfferMismatch:\n return 'Selected offer does not match the SKU';\n case ErrorCode.DeferredPayment:\n return 'Payment is pending approval';\n case ErrorCode.NotPrepared:\n return 'In-app purchase is not ready. Please try again later.';\n case ErrorCode.ServiceError:\n return 'Store service error. Please try again later.';\n case ErrorCode.FeatureNotSupported:\n return 'This feature is not supported on this device.';\n case ErrorCode.TransactionValidationFailed:\n return 'Transaction could not be verified';\n case ErrorCode.PurchaseVerificationFailed:\n return 'Purchase verification failed';\n case ErrorCode.EmptySkuList:\n return 'No product IDs provided';\n case ErrorCode.InitConnection:\n return 'Failed to initialize billing connection';\n case ErrorCode.QueryProduct:\n return 'Failed to query products. Please try again later.';\n default: {\n if (error && typeof error === 'object' && 'message' in error) {\n return (\n (error as {message?: string}).message ??\n 'An unexpected error occurred'\n );\n }\n return 'An unexpected error occurred';\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-iap",
3
- "version": "5.6.1",
3
+ "version": "5.6.2",
4
4
  "description": "In App Purchase module in Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -79,18 +79,52 @@ const asStringArray = (value: unknown): string[] | undefined =>
79
79
  )
80
80
  : undefined;
81
81
 
82
+ // On iOS, Expo appends " (at <file>:<line>)" to a rejected function's message,
83
+ // so the envelope is rarely the end of the string. Take the object and stop there.
84
+ const sliceEnvelopeObject = (payload: string): string | undefined => {
85
+ const start = payload.indexOf('{');
86
+ if (start < 0) return undefined;
87
+
88
+ let depth = 0;
89
+ let inString = false;
90
+ let escaped = false;
91
+ for (let index = start; index < payload.length; index += 1) {
92
+ const character = payload[index];
93
+ if (escaped) {
94
+ escaped = false;
95
+ continue;
96
+ }
97
+ if (character === '\\') {
98
+ escaped = true;
99
+ continue;
100
+ }
101
+ if (character === '"') {
102
+ inString = !inString;
103
+ continue;
104
+ }
105
+ if (inString) continue;
106
+ if (character === '{') depth += 1;
107
+ else if (character === '}') {
108
+ depth -= 1;
109
+ if (depth === 0) return payload.slice(start, index + 1);
110
+ }
111
+ }
112
+ return undefined;
113
+ };
114
+
82
115
  const parseNativeErrorEnvelope = (
83
116
  message: string,
84
117
  ): UnknownRecord | undefined => {
85
118
  const markerIndex = message.indexOf(OPENIAP_ERROR_ENVELOPE_PREFIX);
86
119
  if (markerIndex < 0) return undefined;
87
120
 
121
+ const envelope = sliceEnvelopeObject(
122
+ message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length),
123
+ );
124
+ if (envelope === undefined) return undefined;
125
+
88
126
  try {
89
- return asRecord(
90
- JSON.parse(
91
- message.slice(markerIndex + OPENIAP_ERROR_ENVELOPE_PREFIX.length),
92
- ),
93
- );
127
+ return asRecord(JSON.parse(envelope));
94
128
  } catch {
95
129
  return undefined;
96
130
  }