@chipmobilesdk/rn-payment 0.5.0 → 0.7.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/CHANGELOG.md +172 -0
- package/README.md +47 -16
- package/lib/commonjs/adapter/createStoreProvider.js +110 -0
- package/lib/commonjs/adapter/createStoreProvider.js.map +1 -0
- package/lib/commonjs/adapter/iap-adapter.js +393 -0
- package/lib/commonjs/adapter/iap-adapter.js.map +1 -0
- package/lib/commonjs/adapter/iapShapes.js +169 -0
- package/lib/commonjs/adapter/iapShapes.js.map +1 -0
- package/lib/commonjs/adapter/port.js +6 -0
- package/lib/commonjs/adapter/port.js.map +1 -0
- package/lib/commonjs/config/types.js +2 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/config/validate.js +181 -0
- package/lib/commonjs/config/validate.js.map +1 -0
- package/lib/commonjs/core/mutex.js +31 -0
- package/lib/commonjs/core/mutex.js.map +1 -0
- package/lib/commonjs/core/retry.js +37 -0
- package/lib/commonjs/core/retry.js.map +1 -0
- package/lib/commonjs/core/timers.js +207 -0
- package/lib/commonjs/core/timers.js.map +1 -0
- package/lib/commonjs/diagnostics/errors.js +83 -0
- package/lib/commonjs/diagnostics/errors.js.map +1 -0
- package/lib/commonjs/diagnostics/events.js +126 -0
- package/lib/commonjs/diagnostics/events.js.map +1 -0
- package/lib/commonjs/diagnostics/messageKeys.js +70 -0
- package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
- package/lib/commonjs/engine/connection.js +189 -0
- package/lib/commonjs/engine/connection.js.map +1 -0
- package/lib/commonjs/engine/engine.js +279 -0
- package/lib/commonjs/engine/engine.js.map +1 -0
- package/lib/commonjs/engine/finalize.js +325 -0
- package/lib/commonjs/engine/finalize.js.map +1 -0
- package/lib/commonjs/engine/foreground.js +26 -0
- package/lib/commonjs/engine/foreground.js.map +1 -0
- package/lib/commonjs/engine/internals.js +31 -0
- package/lib/commonjs/engine/internals.js.map +1 -0
- package/lib/commonjs/engine/pending.js +102 -0
- package/lib/commonjs/engine/pending.js.map +1 -0
- package/lib/commonjs/engine/products.js +198 -0
- package/lib/commonjs/engine/products.js.map +1 -0
- package/lib/commonjs/engine/purchase.js +395 -0
- package/lib/commonjs/engine/purchase.js.map +1 -0
- package/lib/commonjs/engine/purchaseFailure.js +77 -0
- package/lib/commonjs/engine/purchaseFailure.js.map +1 -0
- package/lib/commonjs/engine/receiptValidation.js +90 -0
- package/lib/commonjs/engine/receiptValidation.js.map +1 -0
- package/lib/commonjs/engine/state.js +201 -0
- package/lib/commonjs/engine/state.js.map +1 -0
- package/lib/commonjs/engine/subscriptions.js +122 -0
- package/lib/commonjs/engine/subscriptions.js.map +1 -0
- package/lib/commonjs/engine/sync.js +163 -0
- package/lib/commonjs/engine/sync.js.map +1 -0
- package/lib/commonjs/entitlements/aggregate.js +212 -0
- package/lib/commonjs/entitlements/aggregate.js.map +1 -0
- package/lib/commonjs/entitlements/mapping.js +41 -0
- package/lib/commonjs/entitlements/mapping.js.map +1 -0
- package/lib/commonjs/entitlements/policy.js +110 -0
- package/lib/commonjs/entitlements/policy.js.map +1 -0
- package/lib/commonjs/index.js +266 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/persistence/mmkv-store.js +149 -0
- package/lib/commonjs/persistence/mmkv-store.js.map +1 -0
- package/lib/commonjs/persistence/snapshot.js +229 -0
- package/lib/commonjs/persistence/snapshot.js.map +1 -0
- package/lib/commonjs/react/PaymentProvider.js +96 -0
- package/lib/commonjs/react/PaymentProvider.js.map +1 -0
- package/lib/commonjs/react/hooks.js +202 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +136 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/fakeStore.js +281 -0
- package/lib/commonjs/testing/fakeStore.js.map +1 -0
- package/lib/commonjs/testing/index.js +45 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/module/adapter/createStoreProvider.js +106 -0
- package/lib/module/adapter/createStoreProvider.js.map +1 -0
- package/lib/module/adapter/iap-adapter.js +383 -0
- package/lib/module/adapter/iap-adapter.js.map +1 -0
- package/lib/module/adapter/iapShapes.js +160 -0
- package/lib/module/adapter/iapShapes.js.map +1 -0
- package/lib/module/adapter/port.js +4 -0
- package/lib/module/adapter/port.js.map +1 -0
- package/lib/module/config/types.js +2 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/config/validate.js +175 -0
- package/lib/module/config/validate.js.map +1 -0
- package/lib/module/core/mutex.js +22 -0
- package/lib/module/core/mutex.js.map +1 -0
- package/lib/module/core/retry.js +33 -0
- package/lib/module/core/retry.js.map +1 -0
- package/lib/module/core/timers.js +198 -0
- package/lib/module/core/timers.js.map +1 -0
- package/lib/module/diagnostics/errors.js +76 -0
- package/lib/module/diagnostics/errors.js.map +1 -0
- package/lib/module/diagnostics/events.js +117 -0
- package/lib/module/diagnostics/events.js.map +1 -0
- package/lib/module/diagnostics/messageKeys.js +64 -0
- package/lib/module/diagnostics/messageKeys.js.map +1 -0
- package/lib/module/engine/connection.js +185 -0
- package/lib/module/engine/connection.js.map +1 -0
- package/lib/module/engine/engine.js +274 -0
- package/lib/module/engine/engine.js.map +1 -0
- package/lib/module/engine/finalize.js +322 -0
- package/lib/module/engine/finalize.js.map +1 -0
- package/lib/module/engine/foreground.js +21 -0
- package/lib/module/engine/foreground.js.map +1 -0
- package/lib/module/engine/internals.js +26 -0
- package/lib/module/engine/internals.js.map +1 -0
- package/lib/module/engine/pending.js +95 -0
- package/lib/module/engine/pending.js.map +1 -0
- package/lib/module/engine/products.js +195 -0
- package/lib/module/engine/products.js.map +1 -0
- package/lib/module/engine/purchase.js +390 -0
- package/lib/module/engine/purchase.js.map +1 -0
- package/lib/module/engine/purchaseFailure.js +72 -0
- package/lib/module/engine/purchaseFailure.js.map +1 -0
- package/lib/module/engine/receiptValidation.js +87 -0
- package/lib/module/engine/receiptValidation.js.map +1 -0
- package/lib/module/engine/state.js +196 -0
- package/lib/module/engine/state.js.map +1 -0
- package/lib/module/engine/subscriptions.js +119 -0
- package/lib/module/engine/subscriptions.js.map +1 -0
- package/lib/module/engine/sync.js +158 -0
- package/lib/module/engine/sync.js.map +1 -0
- package/lib/module/entitlements/aggregate.js +204 -0
- package/lib/module/entitlements/aggregate.js.map +1 -0
- package/lib/module/entitlements/mapping.js +35 -0
- package/lib/module/entitlements/mapping.js.map +1 -0
- package/lib/module/entitlements/policy.js +104 -0
- package/lib/module/entitlements/policy.js.map +1 -0
- package/lib/module/index.js +59 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/persistence/mmkv-store.js +144 -0
- package/lib/module/persistence/mmkv-store.js.map +1 -0
- package/lib/module/persistence/snapshot.js +221 -0
- package/lib/module/persistence/snapshot.js.map +1 -0
- package/lib/module/react/PaymentProvider.js +90 -0
- package/lib/module/react/PaymentProvider.js.map +1 -0
- package/lib/module/react/hooks.js +192 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/testing/conformance.js +130 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/fakeStore.js +276 -0
- package/lib/module/testing/fakeStore.js.map +1 -0
- package/lib/module/testing/index.js +13 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts +45 -0
- package/lib/typescript/commonjs/adapter/createStoreProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/iap-adapter.d.ts +80 -0
- package/lib/typescript/commonjs/adapter/iap-adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/iapShapes.d.ts +94 -0
- package/lib/typescript/commonjs/adapter/iapShapes.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/port.d.ts +184 -0
- package/lib/typescript/commonjs/adapter/port.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/types.d.ts +326 -0
- package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/validate.d.ts +63 -0
- package/lib/typescript/commonjs/config/validate.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/mutex.d.ts +17 -0
- package/lib/typescript/commonjs/core/mutex.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/retry.d.ts +19 -0
- package/lib/typescript/commonjs/core/retry.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/timers.d.ts +142 -0
- package/lib/typescript/commonjs/core/timers.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts +55 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts +158 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +54 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/connection.d.ts +30 -0
- package/lib/typescript/commonjs/engine/connection.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/engine.d.ts +93 -0
- package/lib/typescript/commonjs/engine/engine.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/finalize.d.ts +53 -0
- package/lib/typescript/commonjs/engine/finalize.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/foreground.d.ts +15 -0
- package/lib/typescript/commonjs/engine/foreground.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/internals.d.ts +28 -0
- package/lib/typescript/commonjs/engine/internals.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/pending.d.ts +51 -0
- package/lib/typescript/commonjs/engine/pending.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/products.d.ts +82 -0
- package/lib/typescript/commonjs/engine/products.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/purchase.d.ts +61 -0
- package/lib/typescript/commonjs/engine/purchase.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/purchaseFailure.d.ts +15 -0
- package/lib/typescript/commonjs/engine/purchaseFailure.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/receiptValidation.d.ts +42 -0
- package/lib/typescript/commonjs/engine/receiptValidation.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/state.d.ts +46 -0
- package/lib/typescript/commonjs/engine/state.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/subscriptions.d.ts +61 -0
- package/lib/typescript/commonjs/engine/subscriptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/sync.d.ts +36 -0
- package/lib/typescript/commonjs/engine/sync.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/aggregate.d.ts +97 -0
- package/lib/typescript/commonjs/entitlements/aggregate.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/mapping.d.ts +27 -0
- package/lib/typescript/commonjs/entitlements/mapping.d.ts.map +1 -0
- package/lib/typescript/commonjs/entitlements/policy.d.ts +75 -0
- package/lib/typescript/commonjs/entitlements/policy.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +44 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/persistence/mmkv-store.d.ts +45 -0
- package/lib/typescript/commonjs/persistence/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/persistence/snapshot.d.ts +106 -0
- package/lib/typescript/commonjs/persistence/snapshot.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/PaymentProvider.d.ts +57 -0
- package/lib/typescript/commonjs/react/PaymentProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/hooks.d.ts +80 -0
- package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +41 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/fakeStore.d.ts +69 -0
- package/lib/typescript/commonjs/testing/fakeStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +12 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/adapter/createStoreProvider.d.ts +45 -0
- package/lib/typescript/module/adapter/createStoreProvider.d.ts.map +1 -0
- package/lib/typescript/module/adapter/iap-adapter.d.ts +80 -0
- package/lib/typescript/module/adapter/iap-adapter.d.ts.map +1 -0
- package/lib/typescript/module/adapter/iapShapes.d.ts +94 -0
- package/lib/typescript/module/adapter/iapShapes.d.ts.map +1 -0
- package/lib/typescript/module/adapter/port.d.ts +184 -0
- package/lib/typescript/module/adapter/port.d.ts.map +1 -0
- package/lib/typescript/module/config/types.d.ts +326 -0
- package/lib/typescript/module/config/types.d.ts.map +1 -0
- package/lib/typescript/module/config/validate.d.ts +63 -0
- package/lib/typescript/module/config/validate.d.ts.map +1 -0
- package/lib/typescript/module/core/mutex.d.ts +17 -0
- package/lib/typescript/module/core/mutex.d.ts.map +1 -0
- package/lib/typescript/module/core/retry.d.ts +19 -0
- package/lib/typescript/module/core/retry.d.ts.map +1 -0
- package/lib/typescript/module/core/timers.d.ts +142 -0
- package/lib/typescript/module/core/timers.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/errors.d.ts +55 -0
- package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/events.d.ts +158 -0
- package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts +54 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/module/engine/connection.d.ts +30 -0
- package/lib/typescript/module/engine/connection.d.ts.map +1 -0
- package/lib/typescript/module/engine/engine.d.ts +93 -0
- package/lib/typescript/module/engine/engine.d.ts.map +1 -0
- package/lib/typescript/module/engine/finalize.d.ts +53 -0
- package/lib/typescript/module/engine/finalize.d.ts.map +1 -0
- package/lib/typescript/module/engine/foreground.d.ts +15 -0
- package/lib/typescript/module/engine/foreground.d.ts.map +1 -0
- package/lib/typescript/module/engine/internals.d.ts +28 -0
- package/lib/typescript/module/engine/internals.d.ts.map +1 -0
- package/lib/typescript/module/engine/pending.d.ts +51 -0
- package/lib/typescript/module/engine/pending.d.ts.map +1 -0
- package/lib/typescript/module/engine/products.d.ts +82 -0
- package/lib/typescript/module/engine/products.d.ts.map +1 -0
- package/lib/typescript/module/engine/purchase.d.ts +61 -0
- package/lib/typescript/module/engine/purchase.d.ts.map +1 -0
- package/lib/typescript/module/engine/purchaseFailure.d.ts +15 -0
- package/lib/typescript/module/engine/purchaseFailure.d.ts.map +1 -0
- package/lib/typescript/module/engine/receiptValidation.d.ts +42 -0
- package/lib/typescript/module/engine/receiptValidation.d.ts.map +1 -0
- package/lib/typescript/module/engine/state.d.ts +46 -0
- package/lib/typescript/module/engine/state.d.ts.map +1 -0
- package/lib/typescript/module/engine/subscriptions.d.ts +61 -0
- package/lib/typescript/module/engine/subscriptions.d.ts.map +1 -0
- package/lib/typescript/module/engine/sync.d.ts +36 -0
- package/lib/typescript/module/engine/sync.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/aggregate.d.ts +97 -0
- package/lib/typescript/module/entitlements/aggregate.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/mapping.d.ts +27 -0
- package/lib/typescript/module/entitlements/mapping.d.ts.map +1 -0
- package/lib/typescript/module/entitlements/policy.d.ts +75 -0
- package/lib/typescript/module/entitlements/policy.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +44 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/persistence/mmkv-store.d.ts +45 -0
- package/lib/typescript/module/persistence/mmkv-store.d.ts.map +1 -0
- package/lib/typescript/module/persistence/snapshot.d.ts +106 -0
- package/lib/typescript/module/persistence/snapshot.d.ts.map +1 -0
- package/lib/typescript/module/react/PaymentProvider.d.ts +57 -0
- package/lib/typescript/module/react/PaymentProvider.d.ts.map +1 -0
- package/lib/typescript/module/react/hooks.d.ts +80 -0
- package/lib/typescript/module/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +41 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/fakeStore.d.ts +69 -0
- package/lib/typescript/module/testing/fakeStore.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +12 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/package.json +49 -13
- package/skills/sdk-rn-payment/SKILL.md +4 -4
- package/src/adapter/iap-adapter.ts +12 -216
- package/src/adapter/iapShapes.ts +232 -0
- package/src/config/types.ts +8 -0
- package/src/config/validate.ts +19 -4
- package/src/core/retry.ts +1 -58
- package/src/diagnostics/events.ts +1 -1
- package/src/engine/connection.ts +194 -0
- package/src/engine/engine.ts +140 -700
- package/src/engine/internals.ts +40 -0
- package/src/engine/products.ts +39 -17
- package/src/engine/purchase.ts +22 -130
- package/src/engine/purchaseFailure.ts +48 -0
- package/src/engine/receiptValidation.ts +101 -0
- package/src/engine/state.ts +253 -0
- package/src/engine/sync.ts +161 -0
- package/src/entitlements/aggregate.ts +3 -5
- package/src/entitlements/mapping.ts +0 -22
- package/src/persistence/mmkv-store.ts +10 -3
- package/src/persistence/snapshot.ts +102 -27
- package/src/react/PaymentProvider.tsx +73 -24
- package/src/react/hooks.ts +13 -3
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assertEnvironmentSafe = assertEnvironmentSafe;
|
|
7
|
+
exports.mayCreateRealTransaction = mayCreateRealTransaction;
|
|
8
|
+
exports.validateConfig = validateConfig;
|
|
9
|
+
var _errors = require("../diagnostics/errors.js");
|
|
10
|
+
var _timers = require("../core/timers.js");
|
|
11
|
+
/**
|
|
12
|
+
* Catalog validation (FR-011).
|
|
13
|
+
*
|
|
14
|
+
* Runs at `configure`, before any connection is opened, so a bad catalog fails
|
|
15
|
+
* at configuration time rather than at the moment a user taps Buy. Every failure
|
|
16
|
+
* **names the offending entry** — "invalid catalog" alone is useless in an app
|
|
17
|
+
* with thirty products.
|
|
18
|
+
*
|
|
19
|
+
* All problems are collected rather than thrown one at a time, so a developer
|
|
20
|
+
* fixes the catalog in one pass instead of rerunning to find the next fault.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const PRODUCT_TYPES = ['one_time_permanent', 'one_time_consumable', 'subscription'];
|
|
24
|
+
|
|
25
|
+
/** The platform whose store identifiers a catalog must supply. */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A validated, indexed catalog plus every resolved policy value.
|
|
29
|
+
*
|
|
30
|
+
* Produced once so the hot paths never re-derive it, and so `getEntitlement` can
|
|
31
|
+
* stay a synchronous in-memory read (PERF-001).
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function validateConfig(config, platform = 'android') {
|
|
35
|
+
const problems = [];
|
|
36
|
+
const offenders = [];
|
|
37
|
+
const entries = new Map();
|
|
38
|
+
const grants = new Map();
|
|
39
|
+
const sources = new Map();
|
|
40
|
+
const byStoreId = new Map();
|
|
41
|
+
if (config.catalog.length === 0) {
|
|
42
|
+
problems.push('catalog is empty');
|
|
43
|
+
offenders.push('catalog');
|
|
44
|
+
}
|
|
45
|
+
for (const entry of config.catalog) {
|
|
46
|
+
const key = entry.productKey;
|
|
47
|
+
if (!key || key.trim() === '') {
|
|
48
|
+
problems.push('a catalog entry has an empty productKey');
|
|
49
|
+
offenders.push('(empty productKey)');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (entries.has(key)) {
|
|
53
|
+
problems.push(`duplicate productKey "${key}"`);
|
|
54
|
+
offenders.push(key);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!PRODUCT_TYPES.includes(entry.productType)) {
|
|
58
|
+
problems.push(`productKey "${key}" has invalid productType "${String(entry.productType)}"`);
|
|
59
|
+
offenders.push(key);
|
|
60
|
+
}
|
|
61
|
+
const storeId = entry.storeProductIds[platform];
|
|
62
|
+
if (!storeId || storeId.trim() === '') {
|
|
63
|
+
problems.push(`productKey "${key}" is missing a store product id for platform "${platform}"`);
|
|
64
|
+
offenders.push(key);
|
|
65
|
+
} else {
|
|
66
|
+
const existing = byStoreId.get(storeId);
|
|
67
|
+
if (existing !== undefined) {
|
|
68
|
+
// Two product keys pointing at one store id would make a store callback
|
|
69
|
+
// ambiguous, so the wrong entitlement could be granted.
|
|
70
|
+
problems.push(`store product id "${storeId}" is used by both "${existing}" and "${key}"`);
|
|
71
|
+
offenders.push(key);
|
|
72
|
+
} else {
|
|
73
|
+
byStoreId.set(storeId, key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!Array.isArray(entry.grants) || entry.grants.length === 0) {
|
|
77
|
+
problems.push(`productKey "${key}" grants no entitlement`);
|
|
78
|
+
offenders.push(key);
|
|
79
|
+
}
|
|
80
|
+
entries.set(key, entry);
|
|
81
|
+
grants.set(key, [...(entry.grants ?? [])]);
|
|
82
|
+
for (const entitlement of entry.grants ?? []) {
|
|
83
|
+
const list = sources.get(entitlement);
|
|
84
|
+
if (list) {
|
|
85
|
+
list.push(key);
|
|
86
|
+
} else {
|
|
87
|
+
sources.set(entitlement, [key]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// An entitlement the app intends to query but no product can grant is almost
|
|
93
|
+
// always a typo, and it would otherwise sit at `not_entitled` forever with no
|
|
94
|
+
// indication why.
|
|
95
|
+
for (const entitlement of config.entitlements) {
|
|
96
|
+
if (!sources.has(entitlement)) {
|
|
97
|
+
problems.push(`entitlement "${entitlement}" is declared but no catalog product grants it`);
|
|
98
|
+
offenders.push(entitlement);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A product granting something the app never declared is the mirror problem:
|
|
103
|
+
// harmless at runtime, but a strong signal of a rename half-applied.
|
|
104
|
+
const declared = new Set(config.entitlements);
|
|
105
|
+
for (const entitlement of sources.keys()) {
|
|
106
|
+
if (!declared.has(entitlement)) {
|
|
107
|
+
problems.push(`entitlement "${entitlement}" is granted by a product but not declared in config.entitlements`);
|
|
108
|
+
offenders.push(entitlement);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (problems.length > 0) {
|
|
112
|
+
throw new _errors.PaymentConfigError({
|
|
113
|
+
code: 'PAYMENT_INVALID_CATALOG',
|
|
114
|
+
message: `Payment catalog is invalid: ${problems.join('; ')}`,
|
|
115
|
+
operation: 'configure',
|
|
116
|
+
offenders: [...new Set(offenders)]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
entries,
|
|
121
|
+
grants,
|
|
122
|
+
sources: new Map([...sources].map(([k, v]) => [k, [...v]])),
|
|
123
|
+
byStoreId,
|
|
124
|
+
entitlementKeys: [...config.entitlements],
|
|
125
|
+
platform,
|
|
126
|
+
enabled: config.enabled ?? true,
|
|
127
|
+
gracePolicy: config.gracePolicy ?? 'grant',
|
|
128
|
+
holdPolicy: config.holdPolicy ?? 'withhold',
|
|
129
|
+
staleAfterMs: (0, _timers.resolveStaleAfterMs)(config.staleAfterMs),
|
|
130
|
+
productCacheTtlMs: (0, _timers.resolveProductCacheTtlMs)(config.productCacheTtlMs),
|
|
131
|
+
foregroundSyncMinIntervalMs: (0, _timers.resolveForegroundSyncMinIntervalMs)(config.foregroundSyncMinIntervalMs),
|
|
132
|
+
timeouts: (0, _timers.resolveTimeouts)(config.timeouts),
|
|
133
|
+
retry: (0, _timers.resolveRetry)(config.retry),
|
|
134
|
+
onValidationUnavailable: config.onValidationUnavailable ?? 'grant_and_queue'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The fail-closed environment guard (FR-015).
|
|
140
|
+
*
|
|
141
|
+
* Separate from catalog validation because it is not about the catalog's shape
|
|
142
|
+
* but about whether this binary is allowed to move real money at all. Checked
|
|
143
|
+
* before connecting, and it refuses rather than warns: a non-production build
|
|
144
|
+
* that declares `production` is one tap away from charging a real card, and
|
|
145
|
+
* continuing silently is exactly the failure this package exists to prevent.
|
|
146
|
+
*/
|
|
147
|
+
function assertEnvironmentSafe(config) {
|
|
148
|
+
if (config.allowStoreTestPurchases === true && config.environment !== 'test') {
|
|
149
|
+
throw new _errors.PaymentConfigError({
|
|
150
|
+
code: 'PAYMENT_INVALID_CONFIG',
|
|
151
|
+
message: `allowStoreTestPurchases is only accepted with environment "test", not ` + `"${config.environment}": it exists for license testers, not for real users.`,
|
|
152
|
+
operation: 'configure',
|
|
153
|
+
offenders: ['allowStoreTestPurchases']
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (config.environment === 'production' && !config.isProductionBuild) {
|
|
157
|
+
throw new _errors.PaymentConfigError({
|
|
158
|
+
code: 'PAYMENT_PRODUCTION_CONFIG_IN_NON_PRODUCTION_BUILD',
|
|
159
|
+
message: 'environment is "production" but isProductionBuild is false. Refusing to ' + 'initialize: a non-production build must not be able to create a real ' + 'transaction.',
|
|
160
|
+
operation: 'configure',
|
|
161
|
+
offenders: ['environment']
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Whether this configuration may hand a purchase to a real store (FR-014).
|
|
168
|
+
*
|
|
169
|
+
* True in a production build configured for production, and in a `test`
|
|
170
|
+
* environment that opted in with `allowStoreTestPurchases` (PAY-16). False
|
|
171
|
+
* everywhere else. The engine records each refusal in observable status so a
|
|
172
|
+
* test can assert the block happened — the difference between a guarantee and a
|
|
173
|
+
* hope.
|
|
174
|
+
*/
|
|
175
|
+
function mayCreateRealTransaction(config) {
|
|
176
|
+
if (config.environment === 'test' && config.allowStoreTestPurchases === true) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return config.environment === 'production' && config.isProductionBuild;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","_timers","PRODUCT_TYPES","validateConfig","config","platform","problems","offenders","entries","Map","grants","sources","byStoreId","catalog","length","push","entry","key","productKey","trim","has","includes","productType","String","storeId","storeProductIds","existing","get","undefined","set","Array","isArray","entitlement","list","entitlements","declared","Set","keys","PaymentConfigError","code","message","join","operation","map","k","v","entitlementKeys","enabled","gracePolicy","holdPolicy","staleAfterMs","resolveStaleAfterMs","productCacheTtlMs","resolveProductCacheTtlMs","foregroundSyncMinIntervalMs","resolveForegroundSyncMinIntervalMs","timeouts","resolveTimeouts","retry","resolveRetry","onValidationUnavailable","assertEnvironmentSafe","allowStoreTestPurchases","environment","isProductionBuild","mayCreateRealTransaction"],"sourceRoot":"../../../src","sources":["config/validate.ts"],"mappings":";;;;;;;;AAYA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAsBA,MAAME,aAAqC,GAAG,CAC7C,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,CACd;;AAED;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAsBO,SAASC,cAAcA,CAC7BC,MAAqB,EACrBC,QAAwB,GAAG,SAAS,EACnB;EACjB,MAAMC,QAAkB,GAAG,EAAE;EAC7B,MAAMC,SAAmB,GAAG,EAAE;EAE9B,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAA2B,CAAC;EACnD,MAAMC,MAAM,GAAG,IAAID,GAAG,CAAwC,CAAC;EAC/D,MAAME,OAAO,GAAG,IAAIF,GAAG,CAA+B,CAAC;EACvD,MAAMG,SAAS,GAAG,IAAIH,GAAG,CAAqB,CAAC;EAE/C,IAAIL,MAAM,CAACS,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;IAChCR,QAAQ,CAACS,IAAI,CA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 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createExclusive", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _rnCore.createExclusive;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createRateLimiter", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _rnCore.createRateLimiter;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createSingleFlight", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _rnCore.createSingleFlight;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "withTimeout", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _rnCore.withTimeout;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
31
|
+
//# sourceMappingURL=mutex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require"],"sourceRoot":"../../../src","sources":["core/mutex.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAAA,OAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.backoffDelayMs = backoffDelayMs;
|
|
7
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
8
|
+
/**
|
|
9
|
+
* Bounded backoff.
|
|
10
|
+
*
|
|
11
|
+
* "Bounded" is the whole point (FR-020, FR-045): an unbounded reconnect loop
|
|
12
|
+
* against a billing service that is down drains battery and hammers a system
|
|
13
|
+
* service, and an unbounded finalize loop hides a real failure behind noise.
|
|
14
|
+
*
|
|
15
|
+
* Delay computation is pure and separated from waiting so tests can assert the
|
|
16
|
+
* schedule without burning real time.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Delay before `attempt` (1-based), capped and optionally jittered.
|
|
21
|
+
*
|
|
22
|
+
* Jitter is full jitter over [0, capped]: several devices that lost the billing
|
|
23
|
+
* connection at the same moment should not retry in lockstep.
|
|
24
|
+
*/
|
|
25
|
+
function backoffDelayMs(attempt, config, random = Math.random) {
|
|
26
|
+
return (0, _rnCore.computeBackoff)(attempt, toSpec(config), random);
|
|
27
|
+
}
|
|
28
|
+
function toSpec(config) {
|
|
29
|
+
return {
|
|
30
|
+
initialDelayMs: config.initialDelayMs,
|
|
31
|
+
maxDelayMs: config.maxDelayMs,
|
|
32
|
+
factor: config.factor,
|
|
33
|
+
jitter: config.jitter ? 'full' : 'none',
|
|
34
|
+
maxAttempts: config.maxAttempts
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","backoffDelayMs","attempt","config","random","Math","computeBackoff","toSpec","initialDelayMs","maxDelayMs","factor","jitter","maxAttempts"],"sourceRoot":"../../../src","sources":["core/retry.ts"],"mappings":";;;;;;AAWA,IAAAA,OAAA,GAAAC,OAAA;AAXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAC7BC,OAAe,EACfC,MAA+B,EAC/BC,MAAoB,GAAGC,IAAI,CAACD,MAAM,EACzB;EACT,OAAO,IAAAE,sBAAc,EAACJ,OAAO,EAAEK,MAAM,CAACJ,MAAM,CAAC,EAAEC,MAAM,CAAC;AACvD;AAEA,SAASG,MAAMA,CAACJ,MAA+B,EAAE;EAChD,OAAO;IACNK,cAAc,EAAEL,MAAM,CAACK,cAAc;IACrCC,UAAU,EAAEN,MAAM,CAACM,UAAU;IAC7BC,MAAM,EAAEP,MAAM,CAACO,MAAM;IACrBC,MAAM,EAAER,MAAM,CAACQ,MAAM,GAAI,MAAM,GAAc,MAAgB;IAC7DC,WAAW,EAAET,MAAM,CAACS;EACrB,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VALIDATE_TIMEOUT_BOUNDS = exports.SYNC_TIMEOUT_BOUNDS = exports.STALE_AFTER_BOUNDS = exports.PURCHASE_LAUNCH_TIMEOUT_BOUNDS = exports.PURCHASE_FLOW_CEILING_MS = exports.PRODUCT_QUERY_TIMEOUT_BOUNDS = exports.PRODUCT_CACHE_TTL_BOUNDS = exports.FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS = exports.FINALIZE_ATTEMPT_TIMEOUT_BOUNDS = exports.DEFAULT_VALIDATE_TIMEOUT_MS = exports.DEFAULT_SYNC_TIMEOUT_MS = exports.DEFAULT_STALE_AFTER_MS = exports.DEFAULT_RECONNECT_BACKOFF = exports.DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS = exports.DEFAULT_PRODUCT_QUERY_TIMEOUT_MS = exports.DEFAULT_PRODUCT_CACHE_TTL_MS = exports.DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS = exports.DEFAULT_FINALIZE_BACKOFF = exports.DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS = exports.DEFAULT_CONNECT_TIMEOUT_MS = exports.CONNECT_TIMEOUT_BOUNDS = exports.BACKOFF_MAX_DELAY_BOUNDS = exports.BACKOFF_INITIAL_DELAY_BOUNDS = exports.BACKOFF_FACTOR_BOUNDS = exports.BACKOFF_ATTEMPT_BOUNDS = void 0;
|
|
7
|
+
exports.resolveForegroundSyncMinIntervalMs = resolveForegroundSyncMinIntervalMs;
|
|
8
|
+
exports.resolveProductCacheTtlMs = resolveProductCacheTtlMs;
|
|
9
|
+
exports.resolveRetry = resolveRetry;
|
|
10
|
+
exports.resolveStaleAfterMs = resolveStaleAfterMs;
|
|
11
|
+
exports.resolveTimeouts = resolveTimeouts;
|
|
12
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
13
|
+
var _errors = require("../diagnostics/errors.js");
|
|
14
|
+
/**
|
|
15
|
+
* Timeout, retry, and cache policy.
|
|
16
|
+
*
|
|
17
|
+
* Defaults and bounds live here rather than at each call site so there is one
|
|
18
|
+
* place to read what the package will wait for, and so consumers can read the
|
|
19
|
+
* values they are bound by instead of discovering them from a timeout in
|
|
20
|
+
* production.
|
|
21
|
+
*
|
|
22
|
+
* Out-of-band values are a configuration error rather than being silently
|
|
23
|
+
* clamped: quietly turning a 1-second timeout into 3 seconds would tell the app
|
|
24
|
+
* it configured something it did not.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** Local IPC to Play Services. Slower than this means unavailable, not busy. */
|
|
28
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = exports.DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
|
|
29
|
+
/** A network round trip; a paywall that hangs longer should show its error state. */
|
|
30
|
+
const DEFAULT_PRODUCT_QUERY_TIMEOUT_MS = exports.DEFAULT_PRODUCT_QUERY_TIMEOUT_MS = 15_000;
|
|
31
|
+
/** Runs at startup, so it must not hold the first render hostage. */
|
|
32
|
+
const DEFAULT_SYNC_TIMEOUT_MS = exports.DEFAULT_SYNC_TIMEOUT_MS = 20_000;
|
|
33
|
+
/**
|
|
34
|
+
* Covers opening the store surface only.
|
|
35
|
+
*
|
|
36
|
+
* Time the user spends *inside* the store's own UI is deliberately excluded
|
|
37
|
+
* (FR-035): a user reading the terms, switching to their banking app for an OTP,
|
|
38
|
+
* or simply hesitating must never have their purchase cancelled by our clock.
|
|
39
|
+
*/
|
|
40
|
+
const DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS = exports.DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS = 30_000;
|
|
41
|
+
/** Per finalize attempt, not per transaction — the queue owns overall persistence. */
|
|
42
|
+
const DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS = exports.DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS = 15_000;
|
|
43
|
+
/** The app's backend hook. A user is waiting on a purchase result behind it. */
|
|
44
|
+
const DEFAULT_VALIDATE_TIMEOUT_MS = exports.DEFAULT_VALIDATE_TIMEOUT_MS = 15_000;
|
|
45
|
+
/**
|
|
46
|
+
* The ceiling on a purchase flow whose outcome includes the user's own time in
|
|
47
|
+
* the store UI, so is otherwise untimed (FR-035). Not a timeout on the user: it
|
|
48
|
+
* exists only so a binding that never answers cannot hold the purchase lock for
|
|
49
|
+
* the rest of the session. A purchase that completes later still arrives through
|
|
50
|
+
* the store update channel and is granted then.
|
|
51
|
+
*/
|
|
52
|
+
const PURCHASE_FLOW_CEILING_MS = exports.PURCHASE_FLOW_CEILING_MS = 10 * 60_000;
|
|
53
|
+
const CONNECT_TIMEOUT_BOUNDS = exports.CONNECT_TIMEOUT_BOUNDS = {
|
|
54
|
+
min: 3_000,
|
|
55
|
+
max: 60_000
|
|
56
|
+
};
|
|
57
|
+
const PRODUCT_QUERY_TIMEOUT_BOUNDS = exports.PRODUCT_QUERY_TIMEOUT_BOUNDS = {
|
|
58
|
+
min: 3_000,
|
|
59
|
+
max: 60_000
|
|
60
|
+
};
|
|
61
|
+
const SYNC_TIMEOUT_BOUNDS = exports.SYNC_TIMEOUT_BOUNDS = {
|
|
62
|
+
min: 5_000,
|
|
63
|
+
max: 120_000
|
|
64
|
+
};
|
|
65
|
+
const PURCHASE_LAUNCH_TIMEOUT_BOUNDS = exports.PURCHASE_LAUNCH_TIMEOUT_BOUNDS = {
|
|
66
|
+
min: 5_000,
|
|
67
|
+
max: 120_000
|
|
68
|
+
};
|
|
69
|
+
const FINALIZE_ATTEMPT_TIMEOUT_BOUNDS = exports.FINALIZE_ATTEMPT_TIMEOUT_BOUNDS = {
|
|
70
|
+
min: 3_000,
|
|
71
|
+
max: 60_000
|
|
72
|
+
};
|
|
73
|
+
const VALIDATE_TIMEOUT_BOUNDS = exports.VALIDATE_TIMEOUT_BOUNDS = {
|
|
74
|
+
min: 3_000,
|
|
75
|
+
max: 120_000
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Prices and offer eligibility are shown at the moment of purchase, so a short
|
|
80
|
+
* TTL with on-demand refresh beats a long one (FR-029).
|
|
81
|
+
*/
|
|
82
|
+
const DEFAULT_PRODUCT_CACHE_TTL_MS = exports.DEFAULT_PRODUCT_CACHE_TTL_MS = 900_000;
|
|
83
|
+
const PRODUCT_CACHE_TTL_BOUNDS = exports.PRODUCT_CACHE_TTL_BOUNDS = {
|
|
84
|
+
min: 60_000,
|
|
85
|
+
max: 86_400_000
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* How long a successful sync keeps entitlements trustworthy offline: **7 days**.
|
|
90
|
+
*
|
|
91
|
+
* Fixed by the specification (FR-055) after weighing both failure directions.
|
|
92
|
+
* The realistic offline cases — travel, poor coverage, a device left unused —
|
|
93
|
+
* resolve within days. Seven days covers a holiday without connectivity while
|
|
94
|
+
* bounding how long a refunded entitlement can outlive its refund to one week.
|
|
95
|
+
*
|
|
96
|
+
* Past this the entitlement becomes `unknown`, never `not_entitled` (FR-055a):
|
|
97
|
+
* the package stops asserting rather than telling a paying customer they did not
|
|
98
|
+
* pay.
|
|
99
|
+
*/
|
|
100
|
+
const DEFAULT_STALE_AFTER_MS = exports.DEFAULT_STALE_AFTER_MS = 604_800_000;
|
|
101
|
+
const STALE_AFTER_BOUNDS = exports.STALE_AFTER_BOUNDS = {
|
|
102
|
+
min: 3_600_000,
|
|
103
|
+
max: 7_776_000_000
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Keeps rapid app switching from becoming a request storm (PERF-002). */
|
|
107
|
+
const DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS = exports.DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS = 60_000;
|
|
108
|
+
const FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS = exports.FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS = {
|
|
109
|
+
min: 0,
|
|
110
|
+
max: 3_600_000
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Bounded so a dropped billing connection cannot become a retry storm (FR-020). */
|
|
114
|
+
const DEFAULT_RECONNECT_BACKOFF = exports.DEFAULT_RECONNECT_BACKOFF = {
|
|
115
|
+
initialDelayMs: 1_000,
|
|
116
|
+
maxDelayMs: 30_000,
|
|
117
|
+
factor: 2,
|
|
118
|
+
maxAttempts: 5,
|
|
119
|
+
jitter: true
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Finalize retry.
|
|
124
|
+
*
|
|
125
|
+
* Bounded **per session** but never permanently abandoned: Google auto-refunds
|
|
126
|
+
* an unacknowledged purchase after three days, so exhausting this session's
|
|
127
|
+
* attempts must leave the transaction queued for the next launch, not dropped
|
|
128
|
+
* (FR-045).
|
|
129
|
+
*/
|
|
130
|
+
const DEFAULT_FINALIZE_BACKOFF = exports.DEFAULT_FINALIZE_BACKOFF = {
|
|
131
|
+
initialDelayMs: 2_000,
|
|
132
|
+
maxDelayMs: 60_000,
|
|
133
|
+
factor: 2,
|
|
134
|
+
maxAttempts: 5,
|
|
135
|
+
jitter: true
|
|
136
|
+
};
|
|
137
|
+
const BACKOFF_MAX_DELAY_BOUNDS = exports.BACKOFF_MAX_DELAY_BOUNDS = {
|
|
138
|
+
min: 5_000,
|
|
139
|
+
max: 600_000
|
|
140
|
+
};
|
|
141
|
+
const BACKOFF_ATTEMPT_BOUNDS = exports.BACKOFF_ATTEMPT_BOUNDS = {
|
|
142
|
+
min: 1,
|
|
143
|
+
max: 10
|
|
144
|
+
};
|
|
145
|
+
/** A first retry sooner than this is a storm; later than this, the user has given up. */
|
|
146
|
+
const BACKOFF_INITIAL_DELAY_BOUNDS = exports.BACKOFF_INITIAL_DELAY_BOUNDS = {
|
|
147
|
+
min: 100,
|
|
148
|
+
max: 60_000
|
|
149
|
+
};
|
|
150
|
+
/** 1 is a constant delay; 0 or below would retry at once, forever (CORE-05). */
|
|
151
|
+
const BACKOFF_FACTOR_BOUNDS = exports.BACKOFF_FACTOR_BOUNDS = {
|
|
152
|
+
min: 1,
|
|
153
|
+
max: 10
|
|
154
|
+
};
|
|
155
|
+
function invalidConfig(label) {
|
|
156
|
+
return message => new _errors.PaymentConfigError({
|
|
157
|
+
code: 'PAYMENT_INVALID_CONFIG',
|
|
158
|
+
message,
|
|
159
|
+
operation: 'configure',
|
|
160
|
+
offenders: [label]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function requireInBounds(label, value, fallback, bounds, unit = 'ms') {
|
|
164
|
+
return value === undefined ? fallback : (0, _rnCore.checkRange)(label, value, bounds, invalidConfig(label), unit);
|
|
165
|
+
}
|
|
166
|
+
function resolveTimeouts(config) {
|
|
167
|
+
return {
|
|
168
|
+
connectMs: requireInBounds('timeouts.connectMs', config?.connectMs, DEFAULT_CONNECT_TIMEOUT_MS, CONNECT_TIMEOUT_BOUNDS),
|
|
169
|
+
productQueryMs: requireInBounds('timeouts.productQueryMs', config?.productQueryMs, DEFAULT_PRODUCT_QUERY_TIMEOUT_MS, PRODUCT_QUERY_TIMEOUT_BOUNDS),
|
|
170
|
+
syncMs: requireInBounds('timeouts.syncMs', config?.syncMs, DEFAULT_SYNC_TIMEOUT_MS, SYNC_TIMEOUT_BOUNDS),
|
|
171
|
+
purchaseLaunchMs: requireInBounds('timeouts.purchaseLaunchMs', config?.purchaseLaunchMs, DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS, PURCHASE_LAUNCH_TIMEOUT_BOUNDS),
|
|
172
|
+
finalizeAttemptMs: requireInBounds('timeouts.finalizeAttemptMs', config?.finalizeAttemptMs, DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS, FINALIZE_ATTEMPT_TIMEOUT_BOUNDS),
|
|
173
|
+
validateMs: requireInBounds('timeouts.validateMs', config?.validateMs, DEFAULT_VALIDATE_TIMEOUT_MS, VALIDATE_TIMEOUT_BOUNDS)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function resolveBackoff(label, config, fallback) {
|
|
177
|
+
const maxDelayMs = requireInBounds(`${label}.maxDelayMs`, config?.maxDelayMs, fallback.maxDelayMs, BACKOFF_MAX_DELAY_BOUNDS);
|
|
178
|
+
const maxAttempts = requireInBounds(`${label}.maxAttempts`, config?.maxAttempts, fallback.maxAttempts, BACKOFF_ATTEMPT_BOUNDS, '');
|
|
179
|
+
const initialDelayMs = requireInBounds(`${label}.initialDelayMs`, config?.initialDelayMs, fallback.initialDelayMs, BACKOFF_INITIAL_DELAY_BOUNDS);
|
|
180
|
+
const factor = requireInBounds(`${label}.factor`, config?.factor, fallback.factor, BACKOFF_FACTOR_BOUNDS, '');
|
|
181
|
+
if (initialDelayMs > maxDelayMs) {
|
|
182
|
+
throw invalidConfig(`${label}.initialDelayMs`)(`${label}.initialDelayMs (${initialDelayMs}ms) exceeds ${label}.maxDelayMs (${maxDelayMs}ms)`);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
initialDelayMs,
|
|
186
|
+
maxDelayMs,
|
|
187
|
+
factor,
|
|
188
|
+
maxAttempts,
|
|
189
|
+
jitter: config?.jitter ?? fallback.jitter
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function resolveRetry(config) {
|
|
193
|
+
return {
|
|
194
|
+
reconnect: resolveBackoff('retry.reconnect', config?.reconnect, DEFAULT_RECONNECT_BACKOFF),
|
|
195
|
+
finalize: resolveBackoff('retry.finalize', config?.finalize, DEFAULT_FINALIZE_BACKOFF)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function resolveStaleAfterMs(value) {
|
|
199
|
+
return requireInBounds('staleAfterMs', value, DEFAULT_STALE_AFTER_MS, STALE_AFTER_BOUNDS);
|
|
200
|
+
}
|
|
201
|
+
function resolveProductCacheTtlMs(value) {
|
|
202
|
+
return requireInBounds('productCacheTtlMs', value, DEFAULT_PRODUCT_CACHE_TTL_MS, PRODUCT_CACHE_TTL_BOUNDS);
|
|
203
|
+
}
|
|
204
|
+
function resolveForegroundSyncMinIntervalMs(value) {
|
|
205
|
+
return requireInBounds('foregroundSyncMinIntervalMs', value, DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS, FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS);
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=timers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","_errors","DEFAULT_CONNECT_TIMEOUT_MS","exports","DEFAULT_PRODUCT_QUERY_TIMEOUT_MS","DEFAULT_SYNC_TIMEOUT_MS","DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS","DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS","DEFAULT_VALIDATE_TIMEOUT_MS","PURCHASE_FLOW_CEILING_MS","CONNECT_TIMEOUT_BOUNDS","min","max","PRODUCT_QUERY_TIMEOUT_BOUNDS","SYNC_TIMEOUT_BOUNDS","PURCHASE_LAUNCH_TIMEOUT_BOUNDS","FINALIZE_ATTEMPT_TIMEOUT_BOUNDS","VALIDATE_TIMEOUT_BOUNDS","DEFAULT_PRODUCT_CACHE_TTL_MS","PRODUCT_CACHE_TTL_BOUNDS","DEFAULT_STALE_AFTER_MS","STALE_AFTER_BOUNDS","DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS","FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS","DEFAULT_RECONNECT_BACKOFF","initialDelayMs","maxDelayMs","factor","maxAttempts","jitter","DEFAULT_FINALIZE_BACKOFF","BACKOFF_MAX_DELAY_BOUNDS","BACKOFF_ATTEMPT_BOUNDS","BACKOFF_INITIAL_DELAY_BOUNDS","BACKOFF_FACTOR_BOUNDS","invalidConfig","label","message","PaymentConfigError","code","operation","offenders","requireInBounds","value","fallback","bounds","unit","undefined","checkRange","resolveTimeouts","config","connectMs","productQueryMs","syncMs","purchaseLaunchMs","finalizeAttemptMs","validateMs","resolveBackoff","resolveRetry","reconnect","finalize","resolveStaleAfterMs","resolveProductCacheTtlMs","resolveForegroundSyncMinIntervalMs"],"sourceRoot":"../../../src","sources":["core/timers.ts"],"mappings":";;;;;;;;;;;AAaA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACO,MAAME,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,MAAM;AAChD;AACO,MAAME,gCAAgC,GAAAD,OAAA,CAAAC,gCAAA,GAAG,MAAM;AACtD;AACO,MAAMC,uBAAuB,GAAAF,OAAA,CAAAE,uBAAA,GAAG,MAAM;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kCAAkC,GAAAH,OAAA,CAAAG,kCAAA,GAAG,MAAM;AACxD;AACO,MAAMC,mCAAmC,GAAAJ,OAAA,CAAAI,mCAAA,GAAG,MAAM;AACzD;AACO,MAAMC,2BAA2B,GAAAL,OAAA,CAAAK,2BAAA,GAAG,MAAM;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,wBAAwB,GAAAN,OAAA,CAAAM,wBAAA,GAAG,EAAE,GAAG,MAAM;AAE5C,MAAMC,sBAAsB,GAAAP,OAAA,CAAAO,sBAAA,GAAG;EAAEC,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAO,CAAU;AACnE,MAAMC,4BAA4B,GAAAV,OAAA,CAAAU,4BAAA,GAA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ymentError = exports.PaymentConfigError = exports.PAYMENT_ERROR_CODES = void 0;
|
|
7
|
+
exports.redact = redact;
|
|
8
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
9
|
+
/**
|
|
10
|
+
* Normalized public errors.
|
|
11
|
+
*
|
|
12
|
+
* Error codes are **public API**: renaming one is a breaking change (FR-078,
|
|
13
|
+
* LIB-008). They are the vocabulary an app branches on, so they must outlive any
|
|
14
|
+
* internal refactor and must never leak a store's own code.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const identifiers = (0, _rnCore.createRedactor)();
|
|
18
|
+
const PAYMENT_ERROR_CODES = exports.PAYMENT_ERROR_CODES = ['PAYMENT_NOT_CONFIGURED', 'PAYMENT_INVALID_CATALOG', 'PAYMENT_NOT_READY', 'PAYMENT_DISABLED', 'PAYMENT_UNAVAILABLE', 'PAYMENT_UNSUPPORTED_PLATFORM', 'PAYMENT_ENVIRONMENT_BLOCKED', 'PAYMENT_PRODUCTION_CONFIG_IN_NON_PRODUCTION_BUILD', 'PAYMENT_PURCHASE_IN_PROGRESS', 'PAYMENT_USER_CANCELLED', 'PAYMENT_PENDING', 'PAYMENT_ALREADY_OWNED', 'PAYMENT_INELIGIBLE', 'PAYMENT_UNKNOWN_PRODUCT', 'PAYMENT_PRODUCT_UNAVAILABLE_IN_REGION', 'PAYMENT_TIMEOUT', 'PAYMENT_NETWORK_ERROR', 'PAYMENT_STORE_ERROR', 'PAYMENT_FINALIZE_FAILED', 'PAYMENT_VALIDATION_REJECTED', 'PAYMENT_VALIDATION_UNAVAILABLE', 'PAYMENT_STORAGE_UNAVAILABLE', /** `consume` on a transaction that is not a consumable, added in 0.3.2. */
|
|
19
|
+
'PAYMENT_NOT_CONSUMABLE',
|
|
20
|
+
/**
|
|
21
|
+
* A timeout, backoff or interval outside its bounds, added in 0.5.0. These
|
|
22
|
+
* used to be reported as `PAYMENT_INVALID_CATALOG`, which is about products.
|
|
23
|
+
*/
|
|
24
|
+
'PAYMENT_INVALID_CONFIG'];
|
|
25
|
+
|
|
26
|
+
/** Which operation produced an error. Part of the public error shape (FR-078). */
|
|
27
|
+
|
|
28
|
+
/** The package's error; an `SdkError` (`@chipmobilesdk/rn-core`) with `pkg: 'rn-payment'`. */
|
|
29
|
+
class PaymentError extends _rnCore.SdkError {
|
|
30
|
+
/** Redacted where appropriate — never a raw receipt, token, or store object (FR-074). */
|
|
31
|
+
|
|
32
|
+
constructor(init) {
|
|
33
|
+
super('rn-payment', init.code, {
|
|
34
|
+
message: init.message,
|
|
35
|
+
retryable: init.retryable ?? false,
|
|
36
|
+
redactedCause: init.cause
|
|
37
|
+
});
|
|
38
|
+
this.name = 'PaymentError';
|
|
39
|
+
this.operation = init.operation;
|
|
40
|
+
this.cause = init.cause;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A configuration problem the app can act on.
|
|
46
|
+
*
|
|
47
|
+
* Separate from `PaymentError` because configuration faults are developer-facing
|
|
48
|
+
* and must never be shown to an end user — the message-key map keeps that
|
|
49
|
+
* separation explicit (FR-085).
|
|
50
|
+
*/
|
|
51
|
+
exports.PaymentError = PaymentError;
|
|
52
|
+
class PaymentConfigError extends PaymentError {
|
|
53
|
+
/** The offending catalog entries or entitlement keys, named (FR-011). */
|
|
54
|
+
|
|
55
|
+
constructor(init) {
|
|
56
|
+
super({
|
|
57
|
+
...init,
|
|
58
|
+
retryable: false
|
|
59
|
+
});
|
|
60
|
+
this.name = 'PaymentConfigError';
|
|
61
|
+
this.offenders = init.offenders ?? [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Strips anything that must never reach a log or event.
|
|
67
|
+
*
|
|
68
|
+
* Applied at the boundary rather than trusted to call sites: a single forgotten
|
|
69
|
+
* interpolation is how receipts end up in logs (NFR-006).
|
|
70
|
+
*
|
|
71
|
+
* Identifier-only: what survives is what code defined, never what data carried.
|
|
72
|
+
* A `PaymentError` keeps its code and an `Error` its class name; every message
|
|
73
|
+
* and every string is dropped, because a store or consumer message can embed a
|
|
74
|
+
* purchase token or an account id and nothing here can tell which.
|
|
75
|
+
*/
|
|
76
|
+
exports.PaymentConfigError = PaymentConfigError;
|
|
77
|
+
function redact(value) {
|
|
78
|
+
// An SDK error reduces to its code and any other Error to its class name
|
|
79
|
+
// (rn-core's identifier-only redactor). Strings never survive here, not even
|
|
80
|
+
// a leading constant: a store message is free text from a payments SDK.
|
|
81
|
+
return value instanceof Error ? identifiers.text(value) : _rnCore.REDACTED;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","identifiers","createRedactor","PAYMENT_ERROR_CODES","exports","PaymentError","SdkError","constructor","init","code","message","retryable","redactedCause","cause","name","operation","PaymentConfigError","offenders","redact","value","Error","text","REDACTED"],"sourceRoot":"../../../src","sources":["diagnostics/errors.ts"],"mappings":";;;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMC,WAAW,GAAG,IAAAC,sBAAc,EAAC,CAAC;AAE7B,MAAMC,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,CAClC,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,8BAA8B,EAC9B,6BAA6B,EAC7B,mDAAmD,EACnD,8BAA8B,EAC9B,wBAAwB,EACxB,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,uCAAuC,EACvC,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,gCAAgC,EAChC,6BAA6B,EAC7B;AACA,wBAAwB;AACxB;AACD;AACA;AACA;AACC,wBAAwB,CACf;;AAIV;;AAcA;AACO,MAAME,YAAY,SAASC,gBAAQ,C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