@chipmobilesdk/rn-payment 0.6.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 +111 -0
- package/README.md +1 -1
- 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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Catalog validation (FR-011).
|
|
5
|
+
*
|
|
6
|
+
* Runs at `configure`, before any connection is opened, so a bad catalog fails
|
|
7
|
+
* at configuration time rather than at the moment a user taps Buy. Every failure
|
|
8
|
+
* **names the offending entry** — "invalid catalog" alone is useless in an app
|
|
9
|
+
* with thirty products.
|
|
10
|
+
*
|
|
11
|
+
* All problems are collected rather than thrown one at a time, so a developer
|
|
12
|
+
* fixes the catalog in one pass instead of rerunning to find the next fault.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { PaymentConfigError } from "../diagnostics/errors.js";
|
|
16
|
+
import { resolveForegroundSyncMinIntervalMs, resolveProductCacheTtlMs, resolveRetry, resolveStaleAfterMs, resolveTimeouts } from "../core/timers.js";
|
|
17
|
+
const PRODUCT_TYPES = ['one_time_permanent', 'one_time_consumable', 'subscription'];
|
|
18
|
+
|
|
19
|
+
/** The platform whose store identifiers a catalog must supply. */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A validated, indexed catalog plus every resolved policy value.
|
|
23
|
+
*
|
|
24
|
+
* Produced once so the hot paths never re-derive it, and so `getEntitlement` can
|
|
25
|
+
* stay a synchronous in-memory read (PERF-001).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export function validateConfig(config, platform = 'android') {
|
|
29
|
+
const problems = [];
|
|
30
|
+
const offenders = [];
|
|
31
|
+
const entries = new Map();
|
|
32
|
+
const grants = new Map();
|
|
33
|
+
const sources = new Map();
|
|
34
|
+
const byStoreId = new Map();
|
|
35
|
+
if (config.catalog.length === 0) {
|
|
36
|
+
problems.push('catalog is empty');
|
|
37
|
+
offenders.push('catalog');
|
|
38
|
+
}
|
|
39
|
+
for (const entry of config.catalog) {
|
|
40
|
+
const key = entry.productKey;
|
|
41
|
+
if (!key || key.trim() === '') {
|
|
42
|
+
problems.push('a catalog entry has an empty productKey');
|
|
43
|
+
offenders.push('(empty productKey)');
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (entries.has(key)) {
|
|
47
|
+
problems.push(`duplicate productKey "${key}"`);
|
|
48
|
+
offenders.push(key);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!PRODUCT_TYPES.includes(entry.productType)) {
|
|
52
|
+
problems.push(`productKey "${key}" has invalid productType "${String(entry.productType)}"`);
|
|
53
|
+
offenders.push(key);
|
|
54
|
+
}
|
|
55
|
+
const storeId = entry.storeProductIds[platform];
|
|
56
|
+
if (!storeId || storeId.trim() === '') {
|
|
57
|
+
problems.push(`productKey "${key}" is missing a store product id for platform "${platform}"`);
|
|
58
|
+
offenders.push(key);
|
|
59
|
+
} else {
|
|
60
|
+
const existing = byStoreId.get(storeId);
|
|
61
|
+
if (existing !== undefined) {
|
|
62
|
+
// Two product keys pointing at one store id would make a store callback
|
|
63
|
+
// ambiguous, so the wrong entitlement could be granted.
|
|
64
|
+
problems.push(`store product id "${storeId}" is used by both "${existing}" and "${key}"`);
|
|
65
|
+
offenders.push(key);
|
|
66
|
+
} else {
|
|
67
|
+
byStoreId.set(storeId, key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!Array.isArray(entry.grants) || entry.grants.length === 0) {
|
|
71
|
+
problems.push(`productKey "${key}" grants no entitlement`);
|
|
72
|
+
offenders.push(key);
|
|
73
|
+
}
|
|
74
|
+
entries.set(key, entry);
|
|
75
|
+
grants.set(key, [...(entry.grants ?? [])]);
|
|
76
|
+
for (const entitlement of entry.grants ?? []) {
|
|
77
|
+
const list = sources.get(entitlement);
|
|
78
|
+
if (list) {
|
|
79
|
+
list.push(key);
|
|
80
|
+
} else {
|
|
81
|
+
sources.set(entitlement, [key]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// An entitlement the app intends to query but no product can grant is almost
|
|
87
|
+
// always a typo, and it would otherwise sit at `not_entitled` forever with no
|
|
88
|
+
// indication why.
|
|
89
|
+
for (const entitlement of config.entitlements) {
|
|
90
|
+
if (!sources.has(entitlement)) {
|
|
91
|
+
problems.push(`entitlement "${entitlement}" is declared but no catalog product grants it`);
|
|
92
|
+
offenders.push(entitlement);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// A product granting something the app never declared is the mirror problem:
|
|
97
|
+
// harmless at runtime, but a strong signal of a rename half-applied.
|
|
98
|
+
const declared = new Set(config.entitlements);
|
|
99
|
+
for (const entitlement of sources.keys()) {
|
|
100
|
+
if (!declared.has(entitlement)) {
|
|
101
|
+
problems.push(`entitlement "${entitlement}" is granted by a product but not declared in config.entitlements`);
|
|
102
|
+
offenders.push(entitlement);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (problems.length > 0) {
|
|
106
|
+
throw new PaymentConfigError({
|
|
107
|
+
code: 'PAYMENT_INVALID_CATALOG',
|
|
108
|
+
message: `Payment catalog is invalid: ${problems.join('; ')}`,
|
|
109
|
+
operation: 'configure',
|
|
110
|
+
offenders: [...new Set(offenders)]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
entries,
|
|
115
|
+
grants,
|
|
116
|
+
sources: new Map([...sources].map(([k, v]) => [k, [...v]])),
|
|
117
|
+
byStoreId,
|
|
118
|
+
entitlementKeys: [...config.entitlements],
|
|
119
|
+
platform,
|
|
120
|
+
enabled: config.enabled ?? true,
|
|
121
|
+
gracePolicy: config.gracePolicy ?? 'grant',
|
|
122
|
+
holdPolicy: config.holdPolicy ?? 'withhold',
|
|
123
|
+
staleAfterMs: resolveStaleAfterMs(config.staleAfterMs),
|
|
124
|
+
productCacheTtlMs: resolveProductCacheTtlMs(config.productCacheTtlMs),
|
|
125
|
+
foregroundSyncMinIntervalMs: resolveForegroundSyncMinIntervalMs(config.foregroundSyncMinIntervalMs),
|
|
126
|
+
timeouts: resolveTimeouts(config.timeouts),
|
|
127
|
+
retry: resolveRetry(config.retry),
|
|
128
|
+
onValidationUnavailable: config.onValidationUnavailable ?? 'grant_and_queue'
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The fail-closed environment guard (FR-015).
|
|
134
|
+
*
|
|
135
|
+
* Separate from catalog validation because it is not about the catalog's shape
|
|
136
|
+
* but about whether this binary is allowed to move real money at all. Checked
|
|
137
|
+
* before connecting, and it refuses rather than warns: a non-production build
|
|
138
|
+
* that declares `production` is one tap away from charging a real card, and
|
|
139
|
+
* continuing silently is exactly the failure this package exists to prevent.
|
|
140
|
+
*/
|
|
141
|
+
export function assertEnvironmentSafe(config) {
|
|
142
|
+
if (config.allowStoreTestPurchases === true && config.environment !== 'test') {
|
|
143
|
+
throw new PaymentConfigError({
|
|
144
|
+
code: 'PAYMENT_INVALID_CONFIG',
|
|
145
|
+
message: `allowStoreTestPurchases is only accepted with environment "test", not ` + `"${config.environment}": it exists for license testers, not for real users.`,
|
|
146
|
+
operation: 'configure',
|
|
147
|
+
offenders: ['allowStoreTestPurchases']
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (config.environment === 'production' && !config.isProductionBuild) {
|
|
151
|
+
throw new PaymentConfigError({
|
|
152
|
+
code: 'PAYMENT_PRODUCTION_CONFIG_IN_NON_PRODUCTION_BUILD',
|
|
153
|
+
message: 'environment is "production" but isProductionBuild is false. Refusing to ' + 'initialize: a non-production build must not be able to create a real ' + 'transaction.',
|
|
154
|
+
operation: 'configure',
|
|
155
|
+
offenders: ['environment']
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Whether this configuration may hand a purchase to a real store (FR-014).
|
|
162
|
+
*
|
|
163
|
+
* True in a production build configured for production, and in a `test`
|
|
164
|
+
* environment that opted in with `allowStoreTestPurchases` (PAY-16). False
|
|
165
|
+
* everywhere else. The engine records each refusal in observable status so a
|
|
166
|
+
* test can assert the block happened — the difference between a guarantee and a
|
|
167
|
+
* hope.
|
|
168
|
+
*/
|
|
169
|
+
export function mayCreateRealTransaction(config) {
|
|
170
|
+
if (config.environment === 'test' && config.allowStoreTestPurchases === true) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return config.environment === 'production' && config.isProductionBuild;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PaymentConfigError","resolveForegroundSyncMinIntervalMs","resolveProductCacheTtlMs","resolveRetry","resolveStaleAfterMs","resolveTimeouts","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","code","message","join","operation","map","k","v","entitlementKeys","enabled","gracePolicy","holdPolicy","staleAfterMs","productCacheTtlMs","foregroundSyncMinIntervalMs","timeouts","retry","onValidationUnavailable","assertEnvironmentSafe","allowStoreTestPurchases","environment","isProductionBuild","mayCreateRealTransaction"],"sourceRoot":"../../../src","sources":["config/validate.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,kBAAkB,QAAQ,0BAAuB;AAC1D,SACCC,kCAAkC,EAClCC,wBAAwB,EACxBC,YAAY,EACZC,mBAAmB,EACnBC,eAAe,QAGT,mBA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ACrE,MAAM,IAAI9D,kBAAkB,CAAC;MAC5B0C,IAAI,EAAE,mDAAmD;MACzDC,OAAO,EACN,0EAA0E,GAC1E,uEAAuE,GACvE,cAAc;MACfE,SAAS,EAAE,WAAW;MACtBlC,SAAS,EAAE,CAAC,aAAa;IAC1B,CAAC,CAAC;EACH;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASoD,wBAAwBA,CAACvD,MAAqB,EAAW;EACxE,IAAIA,MAAM,CAACqD,WAAW,KAAK,MAAM,IAAIrD,MAAM,CAACoD,uBAAuB,KAAK,IAAI,EAAE;IAC7E,OAAO,IAAI;EACZ;EACA,OAAOpD,MAAM,CAACqD,WAAW,KAAK,YAAY,IAAIrD,MAAM,CAACsD,iBAAiB;AACvE","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Concurrency primitives.
|
|
5
|
+
*
|
|
6
|
+
* These are what make three of the specification's guarantees structurally true
|
|
7
|
+
* rather than hoped for: concurrent initialization opens exactly one connection
|
|
8
|
+
* (FR-018), concurrent syncs make exactly one store request (FR-063), and a
|
|
9
|
+
* second purchase while one is open is refused rather than queued (FR-031).
|
|
10
|
+
*
|
|
11
|
+
* The distinction between the two primitives matters. `singleFlight` **joins**
|
|
12
|
+
* concurrent callers onto one operation — correct for init and sync, where every
|
|
13
|
+
* caller wants the same answer. `exclusive` **refuses** the second caller —
|
|
14
|
+
* correct for purchase, where joining would silently give two callers one
|
|
15
|
+
* transaction, and queueing would open a store surface the user no longer
|
|
16
|
+
* expects.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// The primitives themselves are rn-core's; the reasoning above is why rn-payment
|
|
20
|
+
// uses each where it does.
|
|
21
|
+
export { createExclusive, createRateLimiter, createSingleFlight, withTimeout } from '@chipmobilesdk/rn-core';
|
|
22
|
+
//# sourceMappingURL=mutex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createExclusive","createRateLimiter","createSingleFlight","withTimeout"],"sourceRoot":"../../../src","sources":["core/mutex.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,SACCA,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,QAEL,wBAAwB","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bounded backoff.
|
|
5
|
+
*
|
|
6
|
+
* "Bounded" is the whole point (FR-020, FR-045): an unbounded reconnect loop
|
|
7
|
+
* against a billing service that is down drains battery and hammers a system
|
|
8
|
+
* service, and an unbounded finalize loop hides a real failure behind noise.
|
|
9
|
+
*
|
|
10
|
+
* Delay computation is pure and separated from waiting so tests can assert the
|
|
11
|
+
* schedule without burning real time.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { computeBackoff } from '@chipmobilesdk/rn-core';
|
|
15
|
+
/**
|
|
16
|
+
* Delay before `attempt` (1-based), capped and optionally jittered.
|
|
17
|
+
*
|
|
18
|
+
* Jitter is full jitter over [0, capped]: several devices that lost the billing
|
|
19
|
+
* connection at the same moment should not retry in lockstep.
|
|
20
|
+
*/
|
|
21
|
+
export function backoffDelayMs(attempt, config, random = Math.random) {
|
|
22
|
+
return computeBackoff(attempt, toSpec(config), random);
|
|
23
|
+
}
|
|
24
|
+
function toSpec(config) {
|
|
25
|
+
return {
|
|
26
|
+
initialDelayMs: config.initialDelayMs,
|
|
27
|
+
maxDelayMs: config.maxDelayMs,
|
|
28
|
+
factor: config.factor,
|
|
29
|
+
jitter: config.jitter ? 'full' : 'none',
|
|
30
|
+
maxAttempts: config.maxAttempts
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["computeBackoff","backoffDelayMs","attempt","config","random","Math","toSpec","initialDelayMs","maxDelayMs","factor","jitter","maxAttempts"],"sourceRoot":"../../../src","sources":["core/retry.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,wBAAwB;AAIvD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC7BC,OAAe,EACfC,MAA+B,EAC/BC,MAAoB,GAAGC,IAAI,CAACD,MAAM,EACzB;EACT,OAAOJ,cAAc,CAACE,OAAO,EAAEI,MAAM,CAACH,MAAM,CAAC,EAAEC,MAAM,CAAC;AACvD;AAEA,SAASE,MAAMA,CAACH,MAA+B,EAAE;EAChD,OAAO;IACNI,cAAc,EAAEJ,MAAM,CAACI,cAAc;IACrCC,UAAU,EAAEL,MAAM,CAACK,UAAU;IAC7BC,MAAM,EAAEN,MAAM,CAACM,MAAM;IACrBC,MAAM,EAAEP,MAAM,CAACO,MAAM,GAAI,MAAM,GAAc,MAAgB;IAC7DC,WAAW,EAAER,MAAM,CAACQ;EACrB,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Timeout, retry, and cache policy.
|
|
5
|
+
*
|
|
6
|
+
* Defaults and bounds live here rather than at each call site so there is one
|
|
7
|
+
* place to read what the package will wait for, and so consumers can read the
|
|
8
|
+
* values they are bound by instead of discovering them from a timeout in
|
|
9
|
+
* production.
|
|
10
|
+
*
|
|
11
|
+
* Out-of-band values are a configuration error rather than being silently
|
|
12
|
+
* clamped: quietly turning a 1-second timeout into 3 seconds would tell the app
|
|
13
|
+
* it configured something it did not.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { checkRange } from '@chipmobilesdk/rn-core';
|
|
17
|
+
import { PaymentConfigError } from "../diagnostics/errors.js";
|
|
18
|
+
/** Local IPC to Play Services. Slower than this means unavailable, not busy. */
|
|
19
|
+
export const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
|
|
20
|
+
/** A network round trip; a paywall that hangs longer should show its error state. */
|
|
21
|
+
export const DEFAULT_PRODUCT_QUERY_TIMEOUT_MS = 15_000;
|
|
22
|
+
/** Runs at startup, so it must not hold the first render hostage. */
|
|
23
|
+
export const DEFAULT_SYNC_TIMEOUT_MS = 20_000;
|
|
24
|
+
/**
|
|
25
|
+
* Covers opening the store surface only.
|
|
26
|
+
*
|
|
27
|
+
* Time the user spends *inside* the store's own UI is deliberately excluded
|
|
28
|
+
* (FR-035): a user reading the terms, switching to their banking app for an OTP,
|
|
29
|
+
* or simply hesitating must never have their purchase cancelled by our clock.
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS = 30_000;
|
|
32
|
+
/** Per finalize attempt, not per transaction — the queue owns overall persistence. */
|
|
33
|
+
export const DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS = 15_000;
|
|
34
|
+
/** The app's backend hook. A user is waiting on a purchase result behind it. */
|
|
35
|
+
export const DEFAULT_VALIDATE_TIMEOUT_MS = 15_000;
|
|
36
|
+
/**
|
|
37
|
+
* The ceiling on a purchase flow whose outcome includes the user's own time in
|
|
38
|
+
* the store UI, so is otherwise untimed (FR-035). Not a timeout on the user: it
|
|
39
|
+
* exists only so a binding that never answers cannot hold the purchase lock for
|
|
40
|
+
* the rest of the session. A purchase that completes later still arrives through
|
|
41
|
+
* the store update channel and is granted then.
|
|
42
|
+
*/
|
|
43
|
+
export const PURCHASE_FLOW_CEILING_MS = 10 * 60_000;
|
|
44
|
+
export const CONNECT_TIMEOUT_BOUNDS = {
|
|
45
|
+
min: 3_000,
|
|
46
|
+
max: 60_000
|
|
47
|
+
};
|
|
48
|
+
export const PRODUCT_QUERY_TIMEOUT_BOUNDS = {
|
|
49
|
+
min: 3_000,
|
|
50
|
+
max: 60_000
|
|
51
|
+
};
|
|
52
|
+
export const SYNC_TIMEOUT_BOUNDS = {
|
|
53
|
+
min: 5_000,
|
|
54
|
+
max: 120_000
|
|
55
|
+
};
|
|
56
|
+
export const PURCHASE_LAUNCH_TIMEOUT_BOUNDS = {
|
|
57
|
+
min: 5_000,
|
|
58
|
+
max: 120_000
|
|
59
|
+
};
|
|
60
|
+
export const FINALIZE_ATTEMPT_TIMEOUT_BOUNDS = {
|
|
61
|
+
min: 3_000,
|
|
62
|
+
max: 60_000
|
|
63
|
+
};
|
|
64
|
+
export const VALIDATE_TIMEOUT_BOUNDS = {
|
|
65
|
+
min: 3_000,
|
|
66
|
+
max: 120_000
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Prices and offer eligibility are shown at the moment of purchase, so a short
|
|
71
|
+
* TTL with on-demand refresh beats a long one (FR-029).
|
|
72
|
+
*/
|
|
73
|
+
export const DEFAULT_PRODUCT_CACHE_TTL_MS = 900_000;
|
|
74
|
+
export const PRODUCT_CACHE_TTL_BOUNDS = {
|
|
75
|
+
min: 60_000,
|
|
76
|
+
max: 86_400_000
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* How long a successful sync keeps entitlements trustworthy offline: **7 days**.
|
|
81
|
+
*
|
|
82
|
+
* Fixed by the specification (FR-055) after weighing both failure directions.
|
|
83
|
+
* The realistic offline cases — travel, poor coverage, a device left unused —
|
|
84
|
+
* resolve within days. Seven days covers a holiday without connectivity while
|
|
85
|
+
* bounding how long a refunded entitlement can outlive its refund to one week.
|
|
86
|
+
*
|
|
87
|
+
* Past this the entitlement becomes `unknown`, never `not_entitled` (FR-055a):
|
|
88
|
+
* the package stops asserting rather than telling a paying customer they did not
|
|
89
|
+
* pay.
|
|
90
|
+
*/
|
|
91
|
+
export const DEFAULT_STALE_AFTER_MS = 604_800_000;
|
|
92
|
+
export const STALE_AFTER_BOUNDS = {
|
|
93
|
+
min: 3_600_000,
|
|
94
|
+
max: 7_776_000_000
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Keeps rapid app switching from becoming a request storm (PERF-002). */
|
|
98
|
+
export const DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS = 60_000;
|
|
99
|
+
export const FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS = {
|
|
100
|
+
min: 0,
|
|
101
|
+
max: 3_600_000
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Bounded so a dropped billing connection cannot become a retry storm (FR-020). */
|
|
105
|
+
export const DEFAULT_RECONNECT_BACKOFF = {
|
|
106
|
+
initialDelayMs: 1_000,
|
|
107
|
+
maxDelayMs: 30_000,
|
|
108
|
+
factor: 2,
|
|
109
|
+
maxAttempts: 5,
|
|
110
|
+
jitter: true
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Finalize retry.
|
|
115
|
+
*
|
|
116
|
+
* Bounded **per session** but never permanently abandoned: Google auto-refunds
|
|
117
|
+
* an unacknowledged purchase after three days, so exhausting this session's
|
|
118
|
+
* attempts must leave the transaction queued for the next launch, not dropped
|
|
119
|
+
* (FR-045).
|
|
120
|
+
*/
|
|
121
|
+
export const DEFAULT_FINALIZE_BACKOFF = {
|
|
122
|
+
initialDelayMs: 2_000,
|
|
123
|
+
maxDelayMs: 60_000,
|
|
124
|
+
factor: 2,
|
|
125
|
+
maxAttempts: 5,
|
|
126
|
+
jitter: true
|
|
127
|
+
};
|
|
128
|
+
export const BACKOFF_MAX_DELAY_BOUNDS = {
|
|
129
|
+
min: 5_000,
|
|
130
|
+
max: 600_000
|
|
131
|
+
};
|
|
132
|
+
export const BACKOFF_ATTEMPT_BOUNDS = {
|
|
133
|
+
min: 1,
|
|
134
|
+
max: 10
|
|
135
|
+
};
|
|
136
|
+
/** A first retry sooner than this is a storm; later than this, the user has given up. */
|
|
137
|
+
export const BACKOFF_INITIAL_DELAY_BOUNDS = {
|
|
138
|
+
min: 100,
|
|
139
|
+
max: 60_000
|
|
140
|
+
};
|
|
141
|
+
/** 1 is a constant delay; 0 or below would retry at once, forever (CORE-05). */
|
|
142
|
+
export const BACKOFF_FACTOR_BOUNDS = {
|
|
143
|
+
min: 1,
|
|
144
|
+
max: 10
|
|
145
|
+
};
|
|
146
|
+
function invalidConfig(label) {
|
|
147
|
+
return message => new PaymentConfigError({
|
|
148
|
+
code: 'PAYMENT_INVALID_CONFIG',
|
|
149
|
+
message,
|
|
150
|
+
operation: 'configure',
|
|
151
|
+
offenders: [label]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function requireInBounds(label, value, fallback, bounds, unit = 'ms') {
|
|
155
|
+
return value === undefined ? fallback : checkRange(label, value, bounds, invalidConfig(label), unit);
|
|
156
|
+
}
|
|
157
|
+
export function resolveTimeouts(config) {
|
|
158
|
+
return {
|
|
159
|
+
connectMs: requireInBounds('timeouts.connectMs', config?.connectMs, DEFAULT_CONNECT_TIMEOUT_MS, CONNECT_TIMEOUT_BOUNDS),
|
|
160
|
+
productQueryMs: requireInBounds('timeouts.productQueryMs', config?.productQueryMs, DEFAULT_PRODUCT_QUERY_TIMEOUT_MS, PRODUCT_QUERY_TIMEOUT_BOUNDS),
|
|
161
|
+
syncMs: requireInBounds('timeouts.syncMs', config?.syncMs, DEFAULT_SYNC_TIMEOUT_MS, SYNC_TIMEOUT_BOUNDS),
|
|
162
|
+
purchaseLaunchMs: requireInBounds('timeouts.purchaseLaunchMs', config?.purchaseLaunchMs, DEFAULT_PURCHASE_LAUNCH_TIMEOUT_MS, PURCHASE_LAUNCH_TIMEOUT_BOUNDS),
|
|
163
|
+
finalizeAttemptMs: requireInBounds('timeouts.finalizeAttemptMs', config?.finalizeAttemptMs, DEFAULT_FINALIZE_ATTEMPT_TIMEOUT_MS, FINALIZE_ATTEMPT_TIMEOUT_BOUNDS),
|
|
164
|
+
validateMs: requireInBounds('timeouts.validateMs', config?.validateMs, DEFAULT_VALIDATE_TIMEOUT_MS, VALIDATE_TIMEOUT_BOUNDS)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function resolveBackoff(label, config, fallback) {
|
|
168
|
+
const maxDelayMs = requireInBounds(`${label}.maxDelayMs`, config?.maxDelayMs, fallback.maxDelayMs, BACKOFF_MAX_DELAY_BOUNDS);
|
|
169
|
+
const maxAttempts = requireInBounds(`${label}.maxAttempts`, config?.maxAttempts, fallback.maxAttempts, BACKOFF_ATTEMPT_BOUNDS, '');
|
|
170
|
+
const initialDelayMs = requireInBounds(`${label}.initialDelayMs`, config?.initialDelayMs, fallback.initialDelayMs, BACKOFF_INITIAL_DELAY_BOUNDS);
|
|
171
|
+
const factor = requireInBounds(`${label}.factor`, config?.factor, fallback.factor, BACKOFF_FACTOR_BOUNDS, '');
|
|
172
|
+
if (initialDelayMs > maxDelayMs) {
|
|
173
|
+
throw invalidConfig(`${label}.initialDelayMs`)(`${label}.initialDelayMs (${initialDelayMs}ms) exceeds ${label}.maxDelayMs (${maxDelayMs}ms)`);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
initialDelayMs,
|
|
177
|
+
maxDelayMs,
|
|
178
|
+
factor,
|
|
179
|
+
maxAttempts,
|
|
180
|
+
jitter: config?.jitter ?? fallback.jitter
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export function resolveRetry(config) {
|
|
184
|
+
return {
|
|
185
|
+
reconnect: resolveBackoff('retry.reconnect', config?.reconnect, DEFAULT_RECONNECT_BACKOFF),
|
|
186
|
+
finalize: resolveBackoff('retry.finalize', config?.finalize, DEFAULT_FINALIZE_BACKOFF)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export function resolveStaleAfterMs(value) {
|
|
190
|
+
return requireInBounds('staleAfterMs', value, DEFAULT_STALE_AFTER_MS, STALE_AFTER_BOUNDS);
|
|
191
|
+
}
|
|
192
|
+
export function resolveProductCacheTtlMs(value) {
|
|
193
|
+
return requireInBounds('productCacheTtlMs', value, DEFAULT_PRODUCT_CACHE_TTL_MS, PRODUCT_CACHE_TTL_BOUNDS);
|
|
194
|
+
}
|
|
195
|
+
export function resolveForegroundSyncMinIntervalMs(value) {
|
|
196
|
+
return requireInBounds('foregroundSyncMinIntervalMs', value, DEFAULT_FOREGROUND_SYNC_MIN_INTERVAL_MS, FOREGROUND_SYNC_MIN_INTERVAL_BOUNDS);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=timers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["checkRange","PaymentConfigError","DEFAULT_CONNECT_TIMEOUT_MS","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","code","operation","offenders","requireInBounds","value","fallback","bounds","unit","undefined","resolveTimeouts","config","connectMs","productQueryMs","syncMs","purchaseLaunchMs","finalizeAttemptMs","validateMs","resolveBackoff","resolveRetry","reconnect","finalize","resolveStaleAfterMs","resolveProductCacheTtlMs","resolveForegroundSyncMinIntervalMs"],"sourceRoot":"../../../src","sources":["core/timers.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAoB,wBAAwB;AAE/D,SAASC,kBAAkB,QAAQ,0BAAuB;AAG1D;AACA,OAAO,MAAMC,0BAA0B,GAAG,MAAM;AAChD;AACA,OAAO,MAAMC,gCAAgC,GAAG,MAAM;AACtD;AACA,OAAO,MAAMC,uBAAuB,GAAG,MAAM;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kCAAkC,GAAG,MAAM;AACxD;AACA,OAAO,MAAMC,mCAAmC,GAAG,MAAM;AACzD;AACA,OAAO,MAAMC,2BAA2B,GAAG,MAAM;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAG,EAAE,GAAG,MAAM;AAEnD,OAAO,MAAMC,sBAAsB,GAAG;EAAEC,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAO,CAAU;AAC1E,OAAO,MAAMC,4BAA4B,GAAG;EAAEF,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAO,CAAU;AAChF,OAAO,MAAME,mBAAmB,GAAG;EAAEH,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAQ,CAAU;AACxE,OAAO,MAAMG,8BAA8B,GAAG;EAC7CJ,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACN,CAAU;AACV,OAAO,MAAMI,+BAA+B,GAAG;EAC9CL,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACN,CAAU;AACV,OAAO,MAAMK,uBAAuB,GAAG;EAAEN,GAAG,EAAE,KAAK;EAAEC,GAAG,EAAE;AAAQ,CAAU;;AAE5E;AACA;AACA;AACA;AACA,OAAO,MAAMM,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C,wBAAwBA,CAAClB,KAAc,EAAU;EAChE,OAAOD,eAAe,CACrB,mBAAmB,EACnBC,KAAK,EACLxB,4BAA4B,EAC5BC,wBACD,CAAC;AACF;AAEA,OAAO,SAAS0C,kCAAkCA,CAACnB,KAAc,EAAU;EAC1E,OAAOD,eAAe,CACrB,6BAA6B,EAC7BC,KAAK,EACLpB,uCAAuC,EACvCC,mCACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalized public errors.
|
|
5
|
+
*
|
|
6
|
+
* Error codes are **public API**: renaming one is a breaking change (FR-078,
|
|
7
|
+
* LIB-008). They are the vocabulary an app branches on, so they must outlive any
|
|
8
|
+
* internal refactor and must never leak a store's own code.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { REDACTED, SdkError, createRedactor } from '@chipmobilesdk/rn-core';
|
|
12
|
+
const identifiers = createRedactor();
|
|
13
|
+
export const 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. */
|
|
14
|
+
'PAYMENT_NOT_CONSUMABLE',
|
|
15
|
+
/**
|
|
16
|
+
* A timeout, backoff or interval outside its bounds, added in 0.5.0. These
|
|
17
|
+
* used to be reported as `PAYMENT_INVALID_CATALOG`, which is about products.
|
|
18
|
+
*/
|
|
19
|
+
'PAYMENT_INVALID_CONFIG'];
|
|
20
|
+
|
|
21
|
+
/** Which operation produced an error. Part of the public error shape (FR-078). */
|
|
22
|
+
|
|
23
|
+
/** The package's error; an `SdkError` (`@chipmobilesdk/rn-core`) with `pkg: 'rn-payment'`. */
|
|
24
|
+
export class PaymentError extends SdkError {
|
|
25
|
+
/** Redacted where appropriate — never a raw receipt, token, or store object (FR-074). */
|
|
26
|
+
|
|
27
|
+
constructor(init) {
|
|
28
|
+
super('rn-payment', init.code, {
|
|
29
|
+
message: init.message,
|
|
30
|
+
retryable: init.retryable ?? false,
|
|
31
|
+
redactedCause: init.cause
|
|
32
|
+
});
|
|
33
|
+
this.name = 'PaymentError';
|
|
34
|
+
this.operation = init.operation;
|
|
35
|
+
this.cause = init.cause;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A configuration problem the app can act on.
|
|
41
|
+
*
|
|
42
|
+
* Separate from `PaymentError` because configuration faults are developer-facing
|
|
43
|
+
* and must never be shown to an end user — the message-key map keeps that
|
|
44
|
+
* separation explicit (FR-085).
|
|
45
|
+
*/
|
|
46
|
+
export class PaymentConfigError extends PaymentError {
|
|
47
|
+
/** The offending catalog entries or entitlement keys, named (FR-011). */
|
|
48
|
+
|
|
49
|
+
constructor(init) {
|
|
50
|
+
super({
|
|
51
|
+
...init,
|
|
52
|
+
retryable: false
|
|
53
|
+
});
|
|
54
|
+
this.name = 'PaymentConfigError';
|
|
55
|
+
this.offenders = init.offenders ?? [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Strips anything that must never reach a log or event.
|
|
61
|
+
*
|
|
62
|
+
* Applied at the boundary rather than trusted to call sites: a single forgotten
|
|
63
|
+
* interpolation is how receipts end up in logs (NFR-006).
|
|
64
|
+
*
|
|
65
|
+
* Identifier-only: what survives is what code defined, never what data carried.
|
|
66
|
+
* A `PaymentError` keeps its code and an `Error` its class name; every message
|
|
67
|
+
* and every string is dropped, because a store or consumer message can embed a
|
|
68
|
+
* purchase token or an account id and nothing here can tell which.
|
|
69
|
+
*/
|
|
70
|
+
export function redact(value) {
|
|
71
|
+
// An SDK error reduces to its code and any other Error to its class name
|
|
72
|
+
// (rn-core's identifier-only redactor). Strings never survive here, not even
|
|
73
|
+
// a leading constant: a store message is free text from a payments SDK.
|
|
74
|
+
return value instanceof Error ? identifiers.text(value) : REDACTED;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["REDACTED","SdkError","createRedactor","identifiers","PAYMENT_ERROR_CODES","PaymentError","constructor","init","code","message","retryable","redactedCause","cause","name","operation","PaymentConfigError","offenders","redact","value","Error","text"],"sourceRoot":"../../../src","sources":["diagnostics/errors.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,wBAAwB;AAE3E,MAAMC,WAAW,GAAGD,cAAc,CAAC,CAAC;AAEpC,OAAO,MAAME,mBAAmB,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;AACA,OAAO,MAAMC,YAAY,SAASJ,QAAQ,CAAmB;EAE5D;;EAGAK,WAAWA,CAACC,IAMX,EAAE;IACF,KAAK,CAAC,YAAY,EAAEA,IAAI,CAACC,IAAI,EAAE;MAC9BC,OAAO,EAAEF,IAAI,CAACE,OAAO;MACrBC,SAAS,EAAEH,IAAI,CAACG,SAAS,IAAI,KAAK;MAClCC,aAAa,EAAEJ,IAAI,CAACK;IACrB,CAAC,CAAC;IACF,IAAI,CAACC,IAAI,GAAG,cAAc;IAC1B,IAAI,CAACC,SAAS,GAAGP,IAAI,CAACO,SAAS;IAC/B,IAAI,CAACF,KAAK,GAAGL,IAAI,CAACK,KAAK;EACxB;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,kBAAkB,SAASV,YAAY,CAAC;EACpD;;EAGAC,WAAWA,CAACC,IAKX,EAAE;IACF,KAAK,CAAC;MAAE,GAAGA,IAAI;MAAEG,SAAS,EAAE;IAAM,CAAC,CAAC;IACpC,IAAI,CAACG,IAAI,GAAG,oBAAoB;IAChC,IAAI,CAACG,SAAS,GAAGT,IAAI,CAACS,SAAS,IAAI,EAAE;EACtC;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CAACC,KAAc,EAAU;EAC9C;EACA;EACA;EACA,OAAOA,KAAK,YAAYC,KAAK,GAAGhB,WAAW,CAACiB,IAAI,CAACF,KAAK,CAAC,GAAGlB,QAAQ;AACnE","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed events and the emitter.
|
|
5
|
+
*
|
|
6
|
+
* The bar is FR-077: the event stream **alone** must be enough to reconstruct a
|
|
7
|
+
* transaction's full lifecycle, so that "the user says they paid but has no
|
|
8
|
+
* entitlement" can be investigated from logs without a reproduction.
|
|
9
|
+
*
|
|
10
|
+
* Forbidden in every payload, without exception (FR-076, FR-074): store objects,
|
|
11
|
+
* raw receipts, verification payloads, backend tokens, payment details, the
|
|
12
|
+
* obfuscated account identifier, and the cache-scope token.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createDiagnosticChannel, createEmitter as createCoreEmitter } from '@chipmobilesdk/rn-core';
|
|
16
|
+
|
|
17
|
+
/** Every delivered event also goes to the app's SDK sinks (`installSdkSink`, CORE-08). */
|
|
18
|
+
const channel = createDiagnosticChannel('rn-payment');
|
|
19
|
+
import { redact } from "./errors.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A `PaymentEvent` with the timestamp left to the emitter.
|
|
23
|
+
*
|
|
24
|
+
* Distributive on purpose: a plain `Omit<PaymentEvent, 'timestamp'>` collapses the
|
|
25
|
+
* discriminated union into one object type with only the shared keys, which would
|
|
26
|
+
* reject every variant-specific field. `T extends unknown` forces the mapping to
|
|
27
|
+
* apply per member and keeps the union discriminated.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates the emitter.
|
|
32
|
+
*
|
|
33
|
+
* Two properties are deliberate:
|
|
34
|
+
*
|
|
35
|
+
* 1. **A throwing listener cannot break anything** (FR-081). Each listener is
|
|
36
|
+
* invoked defensively, the throw is handed to `onListenerError`, and delivery
|
|
37
|
+
* continues to the remaining listeners. One app's broken analytics callback
|
|
38
|
+
* must not stop the package granting an entitlement or stop another listener
|
|
39
|
+
* hearing about it.
|
|
40
|
+
*
|
|
41
|
+
* The failure is **not** re-emitted as an event, deliberately. A consumer's own
|
|
42
|
+
* bug is not a payment-lifecycle event, and reporting it through the channel
|
|
43
|
+
* that just failed would both invite recursion and double event traffic for
|
|
44
|
+
* every event while that listener stays broken. It goes to the logger instead.
|
|
45
|
+
*
|
|
46
|
+
* 2. **After `dispose`, nothing is emitted** (FR-082). A store callback can
|
|
47
|
+
* arrive after cleanup; it must be dropped silently rather than reach a
|
|
48
|
+
* listener whose component is gone.
|
|
49
|
+
*/
|
|
50
|
+
export function createEmitter(onListenerError) {
|
|
51
|
+
// The event whose listeners are running, so a failure is reported against it.
|
|
52
|
+
let dispatching = null;
|
|
53
|
+
let isDisposed = false;
|
|
54
|
+
// rn-core's emitter: a snapshot per emit, each listener isolated, idempotent
|
|
55
|
+
// unsubscribe. Even the error reporter is isolated: if it throws, rn-core
|
|
56
|
+
// rethrows that on a fresh task rather than into the emit.
|
|
57
|
+
const emitter = createCoreEmitter({
|
|
58
|
+
onListenerError: error => {
|
|
59
|
+
if (!dispatching) return;
|
|
60
|
+
try {
|
|
61
|
+
onListenerError?.(error, dispatching);
|
|
62
|
+
} catch {
|
|
63
|
+
// The app's own reporter failed: nothing in the app is left to tell, so
|
|
64
|
+
// the failure goes to the SDK sinks rather than becoming an uncaught
|
|
65
|
+
// error on some later tick (FR-080).
|
|
66
|
+
channel.emit('listener_reporter_failed', 'error', {
|
|
67
|
+
eventType: dispatching.type
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
emit(event) {
|
|
74
|
+
if (isDisposed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const previous = dispatching;
|
|
78
|
+
dispatching = event;
|
|
79
|
+
try {
|
|
80
|
+
if (emitter.emit(event)) {
|
|
81
|
+
// The type and the cycle only: payment events carry product and
|
|
82
|
+
// entitlement keys an app may treat as personal.
|
|
83
|
+
channel.emit(event.type, /failed|error|blocked|rejected|revoked/.test(event.type) ? 'warn' : 'info', undefined, event.correlationId);
|
|
84
|
+
}
|
|
85
|
+
} finally {
|
|
86
|
+
dispatching = previous;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
subscribe(listener) {
|
|
90
|
+
return isDisposed ? () => undefined : emitter.subscribe(listener);
|
|
91
|
+
},
|
|
92
|
+
dispose() {
|
|
93
|
+
isDisposed = true;
|
|
94
|
+
emitter.dispose();
|
|
95
|
+
},
|
|
96
|
+
listenerCount: () => emitter.listenerCount(),
|
|
97
|
+
disposed: () => isDisposed
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Fields that must never appear in an event payload.
|
|
103
|
+
*
|
|
104
|
+
* Used by `__tests__/diagnostics.test.ts` to walk every emitted event across the
|
|
105
|
+
* whole suite. Enumerating the ban here rather than in the test keeps the rule
|
|
106
|
+
* next to the type it constrains.
|
|
107
|
+
*/
|
|
108
|
+
export const FORBIDDEN_EVENT_FIELDS = ['verificationPayload', 'receipt', 'purchaseToken', 'transactionReceipt', 'obfuscatedAccountId', 'scopeToken', 'token', 'signature'];
|
|
109
|
+
|
|
110
|
+
/** Correlation ids tie one purchase cycle together; no user data goes into them. */
|
|
111
|
+
export function createCorrelationId(counter, prefix = 'pc') {
|
|
112
|
+
const id = `${prefix}_${counter.next.toString(36)}`;
|
|
113
|
+
counter.next += 1;
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
116
|
+
export { redact };
|
|
117
|
+
//# sourceMappingURL=events.js.map
|