expo-iap 3.0.2-rc.1 → 3.0.3
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/CHANGELOG.md +11 -1
- package/README.md +4 -6
- package/build/ExpoIap.types.d.ts +49 -36
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js +79 -70
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/types/ExpoIapAndroid.types.d.ts +2 -3
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -1
- package/build/types/ExpoIapAndroid.types.js.map +1 -1
- package/build/types/ExpoIapIOS.types.d.ts +7 -1
- package/build/types/ExpoIapIOS.types.d.ts.map +1 -1
- package/build/types/ExpoIapIOS.types.js +7 -1
- package/build/types/ExpoIapIOS.types.js.map +1 -1
- package/build/useIAP.d.ts +2 -2
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +13 -2
- package/build/useIAP.js.map +1 -1
- package/build/utils/errorMapping.d.ts +10 -4
- package/build/utils/errorMapping.d.ts.map +1 -1
- package/build/utils/errorMapping.js +54 -46
- package/build/utils/errorMapping.js.map +1 -1
- package/bun.lock +340 -137
- package/ios/ExpoIapModule.swift +24 -11
- package/package.json +1 -1
- package/plugin/src/withIAP.ts +5 -1
- package/plugin/src/withLocalOpenIAP.ts +3 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/src/ExpoIap.types.ts +89 -74
- package/src/index.ts +6 -6
- package/src/types/ExpoIapAndroid.types.ts +2 -5
- package/src/types/ExpoIapIOS.types.ts +8 -3
- package/src/useIAP.ts +21 -10
- package/src/utils/errorMapping.ts +67 -54
- package/coverage/clover.xml +0 -358
- package/coverage/coverage-final.json +0 -7
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -176
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/ExpoIap.types.ts.html +0 -1396
- package/coverage/lcov-report/src/helpers/index.html +0 -116
- package/coverage/lcov-report/src/helpers/subscription.ts.html +0 -532
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/index.ts.html +0 -1945
- package/coverage/lcov-report/src/modules/android.ts.html +0 -496
- package/coverage/lcov-report/src/modules/index.html +0 -131
- package/coverage/lcov-report/src/modules/ios.ts.html +0 -1012
- package/coverage/lcov-report/src/types/ExpoIapAndroid.types.ts.html +0 -502
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/src/useIAP.ts.html +0 -1654
- package/coverage/lcov-report/src/utils/constants.ts.html +0 -127
- package/coverage/lcov-report/src/utils/errorMapping.ts.html +0 -427
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -685
- package/ios/expoiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/expoiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
|
@@ -3,19 +3,22 @@
|
|
|
3
3
|
* Provides helper functions for handling platform-specific errors
|
|
4
4
|
*/
|
|
5
5
|
import { ErrorCode } from '../ExpoIap.types';
|
|
6
|
+
function extractCode(error) {
|
|
7
|
+
if (typeof error === 'string') {
|
|
8
|
+
return error;
|
|
9
|
+
}
|
|
10
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
11
|
+
return error.code;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
6
15
|
/**
|
|
7
16
|
* Checks if an error is a user cancellation
|
|
8
17
|
* @param error Error object or error code
|
|
9
18
|
* @returns True if the error represents user cancellation
|
|
10
19
|
*/
|
|
11
20
|
export function isUserCancelledError(error) {
|
|
12
|
-
|
|
13
|
-
return error === ErrorCode.E_USER_CANCELLED;
|
|
14
|
-
}
|
|
15
|
-
if (error && error.code) {
|
|
16
|
-
return error.code === ErrorCode.E_USER_CANCELLED;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
21
|
+
return extractCode(error) === ErrorCode.UserCancelled;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Checks if an error is related to network connectivity
|
|
@@ -24,14 +27,14 @@ export function isUserCancelledError(error) {
|
|
|
24
27
|
*/
|
|
25
28
|
export function isNetworkError(error) {
|
|
26
29
|
const networkErrors = [
|
|
27
|
-
ErrorCode.
|
|
28
|
-
ErrorCode.
|
|
29
|
-
ErrorCode.
|
|
30
|
-
ErrorCode.
|
|
31
|
-
ErrorCode.
|
|
30
|
+
ErrorCode.NetworkError,
|
|
31
|
+
ErrorCode.RemoteError,
|
|
32
|
+
ErrorCode.ServiceError,
|
|
33
|
+
ErrorCode.ServiceDisconnected,
|
|
34
|
+
ErrorCode.BillingUnavailable,
|
|
32
35
|
];
|
|
33
|
-
const
|
|
34
|
-
return networkErrors.includes(
|
|
36
|
+
const code = extractCode(error);
|
|
37
|
+
return !!code && networkErrors.includes(code);
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* Checks if an error is recoverable (user can retry)
|
|
@@ -40,17 +43,17 @@ export function isNetworkError(error) {
|
|
|
40
43
|
*/
|
|
41
44
|
export function isRecoverableError(error) {
|
|
42
45
|
const recoverableErrors = [
|
|
43
|
-
ErrorCode.
|
|
44
|
-
ErrorCode.
|
|
45
|
-
ErrorCode.
|
|
46
|
-
ErrorCode.
|
|
47
|
-
ErrorCode.
|
|
48
|
-
ErrorCode.
|
|
49
|
-
ErrorCode.
|
|
50
|
-
ErrorCode.
|
|
46
|
+
ErrorCode.NetworkError,
|
|
47
|
+
ErrorCode.RemoteError,
|
|
48
|
+
ErrorCode.ServiceError,
|
|
49
|
+
ErrorCode.Interrupted,
|
|
50
|
+
ErrorCode.ServiceDisconnected,
|
|
51
|
+
ErrorCode.BillingUnavailable,
|
|
52
|
+
ErrorCode.QueryProduct,
|
|
53
|
+
ErrorCode.InitConnection,
|
|
51
54
|
];
|
|
52
|
-
const
|
|
53
|
-
return recoverableErrors.includes(
|
|
55
|
+
const code = extractCode(error);
|
|
56
|
+
return !!code && recoverableErrors.includes(code);
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
59
|
* Gets a user-friendly error message for display
|
|
@@ -58,48 +61,53 @@ export function isRecoverableError(error) {
|
|
|
58
61
|
* @returns User-friendly error message
|
|
59
62
|
*/
|
|
60
63
|
export function getUserFriendlyErrorMessage(error) {
|
|
61
|
-
const errorCode =
|
|
64
|
+
const errorCode = extractCode(error);
|
|
62
65
|
switch (errorCode) {
|
|
63
|
-
case ErrorCode.
|
|
66
|
+
case ErrorCode.UserCancelled:
|
|
64
67
|
return 'Purchase was cancelled by user';
|
|
65
|
-
case ErrorCode.
|
|
68
|
+
case ErrorCode.NetworkError:
|
|
66
69
|
return 'Network connection error. Please check your internet connection and try again.';
|
|
67
|
-
case ErrorCode.
|
|
70
|
+
case ErrorCode.ReceiptFinished:
|
|
68
71
|
return 'Receipt already finished';
|
|
69
|
-
case ErrorCode.
|
|
72
|
+
case ErrorCode.ServiceDisconnected:
|
|
70
73
|
return 'Billing service disconnected. Please try again.';
|
|
71
|
-
case ErrorCode.
|
|
74
|
+
case ErrorCode.BillingUnavailable:
|
|
72
75
|
return 'Billing is unavailable on this device or account.';
|
|
73
|
-
case ErrorCode.
|
|
76
|
+
case ErrorCode.ItemUnavailable:
|
|
74
77
|
return 'This item is not available for purchase';
|
|
75
|
-
case ErrorCode.
|
|
78
|
+
case ErrorCode.ItemNotOwned:
|
|
76
79
|
return "You don't own this item";
|
|
77
|
-
case ErrorCode.
|
|
80
|
+
case ErrorCode.AlreadyOwned:
|
|
78
81
|
return 'You already own this item';
|
|
79
|
-
case ErrorCode.
|
|
82
|
+
case ErrorCode.SkuNotFound:
|
|
80
83
|
return 'Requested product could not be found';
|
|
81
|
-
case ErrorCode.
|
|
84
|
+
case ErrorCode.SkuOfferMismatch:
|
|
82
85
|
return 'Selected offer does not match the SKU';
|
|
83
|
-
case ErrorCode.
|
|
86
|
+
case ErrorCode.DeferredPayment:
|
|
84
87
|
return 'Payment is pending approval';
|
|
85
|
-
case ErrorCode.
|
|
88
|
+
case ErrorCode.NotPrepared:
|
|
86
89
|
return 'In-app purchase is not ready. Please try again later.';
|
|
87
|
-
case ErrorCode.
|
|
90
|
+
case ErrorCode.ServiceError:
|
|
88
91
|
return 'Store service error. Please try again later.';
|
|
89
|
-
case ErrorCode.
|
|
92
|
+
case ErrorCode.FeatureNotSupported:
|
|
90
93
|
return 'This feature is not supported on this device.';
|
|
91
|
-
case ErrorCode.
|
|
94
|
+
case ErrorCode.TransactionValidationFailed:
|
|
92
95
|
return 'Transaction could not be verified';
|
|
93
|
-
case ErrorCode.
|
|
96
|
+
case ErrorCode.ReceiptFailed:
|
|
94
97
|
return 'Receipt processing failed';
|
|
95
|
-
case ErrorCode.
|
|
98
|
+
case ErrorCode.EmptySkuList:
|
|
96
99
|
return 'No product IDs provided';
|
|
97
|
-
case ErrorCode.
|
|
100
|
+
case ErrorCode.InitConnection:
|
|
98
101
|
return 'Failed to initialize billing connection';
|
|
99
|
-
case ErrorCode.
|
|
102
|
+
case ErrorCode.QueryProduct:
|
|
100
103
|
return 'Failed to query products. Please try again later.';
|
|
101
|
-
default:
|
|
102
|
-
|
|
104
|
+
default: {
|
|
105
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
106
|
+
return (error.message ??
|
|
107
|
+
'An unexpected error occurred');
|
|
108
|
+
}
|
|
109
|
+
return 'An unexpected error occurred';
|
|
110
|
+
}
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
//# sourceMappingURL=errorMapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAI3C,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QAC1D,OAAQ,KAAyB,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,aAAa,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,aAAa,GAAgB;QACjC,SAAS,CAAC,YAAY;QACtB,SAAS,CAAC,WAAW;QACrB,SAAS,CAAC,YAAY;QACtB,SAAS,CAAC,mBAAmB;QAC7B,SAAS,CAAC,kBAAkB;KAC7B,CAAC;IAEF,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,CAAC,CAAC,IAAI,IAAK,aAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,MAAM,iBAAiB,GAAgB;QACrC,SAAS,CAAC,YAAY;QACtB,SAAS,CAAC,WAAW;QACrB,SAAS,CAAC,YAAY;QACtB,SAAS,CAAC,WAAW;QACrB,SAAS,CAAC,mBAAmB;QAC7B,S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C,CAAC;QAC7C,KAAK,SAAS,CAAC,aAAa;YAC1B,OAAO,2BAA2B,CAAC;QACrC,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 helper functions for handling platform-specific errors\n */\n\nimport {ErrorCode} from '../ExpoIap.types';\n\ntype ErrorLike = string | {code?: ErrorCode | string; message?: string};\n\nfunction extractCode(error: unknown): string | undefined {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error && typeof error === 'object' && 'code' in error) {\n return (error as {code?: string}).code;\n }\n\n return undefined;\n}\n\n/**\n * Checks if an error is a user cancellation\n * @param error Error object or error code\n * @returns True if the error represents user cancellation\n */\nexport function isUserCancelledError(error: unknown): boolean {\n return extractCode(error) === ErrorCode.UserCancelled;\n}\n\n/**\n * Checks if an error is related to network connectivity\n * @param error Error object or error code\n * @returns True if the error is network-related\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\n/**\n * Checks if an error is recoverable (user can retry)\n * @param error Error object or error code\n * @returns True if the error is potentially recoverable\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 * Gets a user-friendly error message for display\n * @param error Error object or error code\n * @returns User-friendly 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.ReceiptFinished:\n return 'Receipt 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.ReceiptFailed:\n return 'Receipt processing 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"]}
|