@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,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFakeStore = createFakeStore;
|
|
7
|
+
exports.makePurchase = makePurchase;
|
|
8
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
9
|
+
/**
|
|
10
|
+
* Fake store — a full `ProviderPort` implementation for automated tests.
|
|
11
|
+
*
|
|
12
|
+
* Lives behind `@chipmobilesdk/rn-payment/testing` so test doubles cannot reach a
|
|
13
|
+
* production bundle.
|
|
14
|
+
*
|
|
15
|
+
* Nearly every requirement in this package concerns a rare ordering or failure
|
|
16
|
+
* path — a pending purchase settling two sessions later, an app killed between
|
|
17
|
+
* payment and acknowledgement, a billing connection dropping mid-sync. None of
|
|
18
|
+
* those are reachable on a real device on demand, so this is what makes them
|
|
19
|
+
* testable at all (NFR-007, SC-008).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const DEFAULT_CAPABILITIES = {
|
|
23
|
+
supportsSubscriptions: true,
|
|
24
|
+
supportsPlanChange: true,
|
|
25
|
+
supportsPriceChangeConfirmation: true,
|
|
26
|
+
// Matches Android reality: grace and hold are not separable client-side.
|
|
27
|
+
reportsGraceAndHoldDistinctly: false,
|
|
28
|
+
supportsExternalTransactions: false,
|
|
29
|
+
// The whole point of the fake: it moves no money, so the environment guard
|
|
30
|
+
// lets a test complete a purchase while still blocking the real adapter
|
|
31
|
+
// outside production (FR-014).
|
|
32
|
+
createsRealTransactions: false,
|
|
33
|
+
// Its launch returns at once, so the engine's launch timeout applies and stays
|
|
34
|
+
// testable (FR-035).
|
|
35
|
+
purchaseOutcomeIncludesStoreTime: false
|
|
36
|
+
};
|
|
37
|
+
let sequence = 0;
|
|
38
|
+
|
|
39
|
+
/** A purchase with sensible defaults, so tests state only what they care about. */
|
|
40
|
+
function makePurchase(overrides = {}) {
|
|
41
|
+
sequence += 1;
|
|
42
|
+
return {
|
|
43
|
+
storeProductId: overrides.storeProductId ?? 'store.product.default',
|
|
44
|
+
transactionId: overrides.transactionId ?? `txn_${sequence}`,
|
|
45
|
+
token: overrides.token ?? `token_${sequence}`,
|
|
46
|
+
state: overrides.state ?? 'purchased',
|
|
47
|
+
purchasedAt: overrides.purchasedAt ?? 1_700_000_000_000,
|
|
48
|
+
isAcknowledged: overrides.isAcknowledged ?? false,
|
|
49
|
+
expiresAt: overrides.expiresAt,
|
|
50
|
+
willAutoRenew: overrides.willAutoRenew,
|
|
51
|
+
verificationPayload: overrides.verificationPayload ?? 'fake-verification'
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createFakeStore(options = {}) {
|
|
55
|
+
let connectOutcome = options.connectOutcome ?? {
|
|
56
|
+
ok: true
|
|
57
|
+
};
|
|
58
|
+
const androidBinding = options.mode === 'android-16.7';
|
|
59
|
+
let capabilities = {
|
|
60
|
+
...DEFAULT_CAPABILITIES,
|
|
61
|
+
...(androidBinding ? {
|
|
62
|
+
supportsPriceChangeConfirmation: false
|
|
63
|
+
} : {}),
|
|
64
|
+
...options.capabilities
|
|
65
|
+
};
|
|
66
|
+
let products = [...(options.products ?? [])];
|
|
67
|
+
let owned = [...(options.owned ?? [])];
|
|
68
|
+
let scripted;
|
|
69
|
+
let finalizeFails = false;
|
|
70
|
+
let connected = false;
|
|
71
|
+
/** Why each pending purchase ended, for the ones `expirePending` or `cancelPending` ended. */
|
|
72
|
+
const endReasons = new Map();
|
|
73
|
+
const acknowledgedTokens = [];
|
|
74
|
+
const consumedTokens = [];
|
|
75
|
+
const managementOpenedFor = [];
|
|
76
|
+
// The same listener sets as the real adapter, so a throwing observer behaves
|
|
77
|
+
// identically here and on a device (PAY-17).
|
|
78
|
+
const connectionListeners = (0, _rnCore.createListenerSet)();
|
|
79
|
+
const purchaseListeners = (0, _rnCore.createListenerSet)();
|
|
80
|
+
let connectCalls = 0;
|
|
81
|
+
let launchCalls = 0;
|
|
82
|
+
let queryOwnedCalls = 0;
|
|
83
|
+
let disconnectCalls = 0;
|
|
84
|
+
const notifyConnection = (next, reason) => {
|
|
85
|
+
connected = next;
|
|
86
|
+
connectionListeners.notify(next, reason);
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
// --- ProviderPort ------------------------------------------------------
|
|
90
|
+
async connect() {
|
|
91
|
+
connectCalls += 1;
|
|
92
|
+
if (connectOutcome.ok) {
|
|
93
|
+
notifyConnection(true);
|
|
94
|
+
}
|
|
95
|
+
return connectOutcome;
|
|
96
|
+
},
|
|
97
|
+
async disconnect() {
|
|
98
|
+
disconnectCalls += 1;
|
|
99
|
+
if (connected) {
|
|
100
|
+
notifyConnection(false, 'disconnect');
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
observeConnection(listener) {
|
|
104
|
+
return connectionListeners.add(listener);
|
|
105
|
+
},
|
|
106
|
+
async queryProducts(storeProductIds, productType) {
|
|
107
|
+
return products.filter(p => storeProductIds.includes(p.storeProductId) && p.productType === productType);
|
|
108
|
+
},
|
|
109
|
+
async queryOwned() {
|
|
110
|
+
queryOwnedCalls += 1;
|
|
111
|
+
// Pending purchases are returned flagged, never filtered out: the engine
|
|
112
|
+
// must see them to raise the pending signal while never granting.
|
|
113
|
+
return [...owned];
|
|
114
|
+
},
|
|
115
|
+
async launchPurchase(request) {
|
|
116
|
+
launchCalls += 1;
|
|
117
|
+
const script = scripted;
|
|
118
|
+
scripted = undefined;
|
|
119
|
+
if (!script) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
reason: 'store_error',
|
|
123
|
+
detail: 'no script set'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (script.kind === 'failure') {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
reason: script.reason
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const purchase = makePurchase({
|
|
133
|
+
storeProductId: request.storeProductId,
|
|
134
|
+
state: script.kind === 'pending' ? 'pending' : 'purchased',
|
|
135
|
+
...script.overrides
|
|
136
|
+
});
|
|
137
|
+
owned = [...owned.filter(p => p.transactionId !== purchase.transactionId), purchase];
|
|
138
|
+
if (androidBinding) {
|
|
139
|
+
// The binding's update listener fires for every observer, the session-long
|
|
140
|
+
// one included, before the launch settles.
|
|
141
|
+
purchaseListeners.notify(purchase);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
ok: true,
|
|
145
|
+
purchase
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
observePurchases(listener) {
|
|
149
|
+
return purchaseListeners.add(listener);
|
|
150
|
+
},
|
|
151
|
+
async acknowledge(token) {
|
|
152
|
+
if (finalizeFails) {
|
|
153
|
+
throw new Error('fake acknowledge failure');
|
|
154
|
+
}
|
|
155
|
+
// Safe to call for an already-acknowledged transaction (FR-044).
|
|
156
|
+
if (!acknowledgedTokens.includes(token)) {
|
|
157
|
+
acknowledgedTokens.push(token);
|
|
158
|
+
}
|
|
159
|
+
owned = owned.map(p => p.token === token ? {
|
|
160
|
+
...p,
|
|
161
|
+
isAcknowledged: true
|
|
162
|
+
} : p);
|
|
163
|
+
},
|
|
164
|
+
async consume(token) {
|
|
165
|
+
if (finalizeFails) {
|
|
166
|
+
throw new Error('fake consume failure');
|
|
167
|
+
}
|
|
168
|
+
if (!consumedTokens.includes(token)) {
|
|
169
|
+
consumedTokens.push(token);
|
|
170
|
+
}
|
|
171
|
+
// A consumed purchase stops being owned, which is what lets the same
|
|
172
|
+
// product be bought again (FR-043).
|
|
173
|
+
owned = owned.filter(p => p.token !== token);
|
|
174
|
+
},
|
|
175
|
+
async openSubscriptionManagement(storeProductId) {
|
|
176
|
+
managementOpenedFor.push(storeProductId);
|
|
177
|
+
},
|
|
178
|
+
async confirmPriceChange() {
|
|
179
|
+
return {
|
|
180
|
+
ok: true,
|
|
181
|
+
confirmed: true
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
capabilities: () => capabilities,
|
|
185
|
+
pendingEndReason: transactionId => endReasons.get(transactionId),
|
|
186
|
+
// --- Scripting ---------------------------------------------------------
|
|
187
|
+
scriptPurchaseSuccess(overrides) {
|
|
188
|
+
scripted = {
|
|
189
|
+
kind: 'success',
|
|
190
|
+
overrides
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
scriptPurchaseFailure(reason) {
|
|
194
|
+
scripted = {
|
|
195
|
+
kind: 'failure',
|
|
196
|
+
reason
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
scriptPurchasePending(overrides) {
|
|
200
|
+
scripted = {
|
|
201
|
+
kind: 'pending',
|
|
202
|
+
overrides
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
// --- Store state -------------------------------------------------------
|
|
206
|
+
setOwned(purchases) {
|
|
207
|
+
owned = [...purchases];
|
|
208
|
+
},
|
|
209
|
+
pushPurchaseUpdate(purchase) {
|
|
210
|
+
owned = [...owned.filter(p => p.transactionId !== purchase.transactionId), purchase];
|
|
211
|
+
purchaseListeners.notify(purchase);
|
|
212
|
+
},
|
|
213
|
+
revoke(transactionId) {
|
|
214
|
+
owned = owned.filter(p => p.transactionId !== transactionId);
|
|
215
|
+
},
|
|
216
|
+
settlePending(transactionId) {
|
|
217
|
+
owned = owned.map(p => p.transactionId === transactionId ? {
|
|
218
|
+
...p,
|
|
219
|
+
state: 'purchased'
|
|
220
|
+
} : p);
|
|
221
|
+
},
|
|
222
|
+
cancelPending(transactionId) {
|
|
223
|
+
owned = owned.filter(p => p.transactionId !== transactionId);
|
|
224
|
+
endReasons.set(transactionId, 'cancelled');
|
|
225
|
+
},
|
|
226
|
+
expirePending(transactionId) {
|
|
227
|
+
owned = owned.filter(p => p.transactionId !== transactionId);
|
|
228
|
+
endReasons.set(transactionId, 'expired');
|
|
229
|
+
},
|
|
230
|
+
setProducts(next) {
|
|
231
|
+
products = [...next];
|
|
232
|
+
},
|
|
233
|
+
// --- Connection --------------------------------------------------------
|
|
234
|
+
setConnectOutcome(outcome) {
|
|
235
|
+
connectOutcome = outcome;
|
|
236
|
+
},
|
|
237
|
+
dropConnection(reason = 'service_disconnected') {
|
|
238
|
+
notifyConnection(false, reason);
|
|
239
|
+
},
|
|
240
|
+
restoreConnection() {
|
|
241
|
+
notifyConnection(true);
|
|
242
|
+
},
|
|
243
|
+
// --- Finalization ------------------------------------------------------
|
|
244
|
+
setFinalizeFailure(failing) {
|
|
245
|
+
finalizeFails = failing;
|
|
246
|
+
},
|
|
247
|
+
// --- Inspection --------------------------------------------------------
|
|
248
|
+
acknowledged: () => [...acknowledgedTokens],
|
|
249
|
+
consumed: () => [...consumedTokens],
|
|
250
|
+
connectCount: () => connectCalls,
|
|
251
|
+
launchCount: () => launchCalls,
|
|
252
|
+
queryOwnedCount: () => queryOwnedCalls,
|
|
253
|
+
disconnectCount: () => disconnectCalls,
|
|
254
|
+
subscriptionManagementOpenedFor: () => [...managementOpenedFor],
|
|
255
|
+
reset() {
|
|
256
|
+
connectOutcome = {
|
|
257
|
+
ok: true
|
|
258
|
+
};
|
|
259
|
+
capabilities = {
|
|
260
|
+
...DEFAULT_CAPABILITIES,
|
|
261
|
+
...options.capabilities
|
|
262
|
+
};
|
|
263
|
+
products = [];
|
|
264
|
+
owned = [];
|
|
265
|
+
scripted = undefined;
|
|
266
|
+
finalizeFails = false;
|
|
267
|
+
connected = false;
|
|
268
|
+
endReasons.clear();
|
|
269
|
+
acknowledgedTokens.length = 0;
|
|
270
|
+
consumedTokens.length = 0;
|
|
271
|
+
managementOpenedFor.length = 0;
|
|
272
|
+
connectionListeners.clear();
|
|
273
|
+
purchaseListeners.clear();
|
|
274
|
+
connectCalls = 0;
|
|
275
|
+
launchCalls = 0;
|
|
276
|
+
queryOwnedCalls = 0;
|
|
277
|
+
disconnectCalls = 0;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=fakeStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","DEFAULT_CAPABILITIES","supportsSubscriptions","supportsPlanChange","supportsPriceChangeConfirmation","reportsGraceAndHoldDistinctly","supportsExternalTransactions","createsRealTransactions","purchaseOutcomeIncludesStoreTime","sequence","makePurchase","overrides","storeProductId","transactionId","token","state","purchasedAt","isAcknowledged","expiresAt","willAutoRenew","verificationPayload","createFakeStore","options","connectOutcome","ok","androidBinding","mode","capabilities","products","owned","scripted","finalizeFails","connected","endReasons","Map","acknowledgedTokens","consumedTokens","managementOpenedFor","connectionListeners","createListenerSet","purchaseListeners","connectCalls","launchCalls","queryOwnedCalls","disconnectCalls","notifyConnection","next","reason","notify","connect","disconnect","observeConnection","listener","add","queryProducts","storeProductIds","productType","filter","p","includes","queryOwned","launchPurchase","request","script","undefined","detail","kind","purchase","observePurchases","acknowledge","Error","push","map","consume","openSubscriptionManagement","confirmPriceChange","confirmed","pendingEndReason","get","scriptPurchaseSuccess","scriptPurchaseFailure","scriptPurchasePending","setOwned","purchases","pushPurchaseUpdate","revoke","settlePending","cancelPending","set","expirePending","setProducts","setConnectOutcome","outcome","dropConnection","restoreConnection","setFinalizeFailure","failing","acknowledged","consumed","connectCount","launchCount","queryOwnedCount","disconnectCount","subscriptionManagementOpenedFor","reset","clear","length"],"sourceRoot":"../../../src","sources":["testing/fakeStore.ts"],"mappings":";;;;;;;AAaA,IAAAA,OAAA,GAAAC,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuFA,MAAMC,oBAA0C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,GAAG1B,oBAAoB;QAAE,GAAGqB,OAAO,CAACK;MAAa,CAAC;MACnEC,QAAQ,GAAG,EAAE;MACbC,KAAK,GAAG,EAAE;MACVC,QAAQ,GAAGkC,SAAS;MACpBjC,aAAa,GAAG,KAAK;MACrBC,SAAS,GAAG,KAAK;MACjBC,UAAU,CAACwE,KAAK,CAAC,CAAC;MAClBtE,kBAAkB,CAACuE,MAAM,GAAG,CAAC;MAC7BtE,cAAc,CAACsE,MAAM,GAAG,CAAC;MACzBrE,mBAAmB,CAACqE,MAAM,GAAG,CAAC;MAC9BpE,mBAAmB,CAACmE,KAAK,CAAC,CAAC;MAC3BjE,iBAAiB,CAACiE,KAAK,CAAC,CAAC;MACzBhE,YAAY,GAAG,CAAC;MAChBC,WAAW,GAAG,CAAC;MACfC,eAAe,GAAG,CAAC;MACnBC,eAAe,GAAG,CAAC;IACpB;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CONFORMANCE_STORE", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _conformance.CONFORMANCE_STORE;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createFakeStore", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _fakeStore.createFakeStore;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createMemorySnapshotStore", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _mmkvStore.createMemorySnapshotStore;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "makePurchase", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _fakeStore.makePurchase;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "providerPortChecks", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _conformance.providerPortChecks;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "runProviderPortConformance", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _conformance.runProviderPortConformance;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _fakeStore = require("./fakeStore.js");
|
|
43
|
+
var _mmkvStore = require("../persistence/mmkv-store.js");
|
|
44
|
+
var _conformance = require("./conformance.js");
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_fakeStore","require","_mmkvStore","_conformance"],"sourceRoot":"../../../src","sources":["testing/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform selection for the store adapter.
|
|
5
|
+
*
|
|
6
|
+
* This exists so the public surface never names a store. An app writes
|
|
7
|
+
* `createStoreProvider()`, not `createIapAdapter()` — the same call will pick the
|
|
8
|
+
* StoreKit adapter once iOS exists, and no consumer line changes (FR-002, FR-004,
|
|
9
|
+
* FR-007).
|
|
10
|
+
*
|
|
11
|
+
* On a platform with no adapter the result is a stub that reports
|
|
12
|
+
* `platform_unsupported` rather than throwing. That is what lets a host app start
|
|
13
|
+
* and run normally where selling is impossible, losing only the ability to sell
|
|
14
|
+
* (FR-021, FR-023).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Platform } from 'react-native';
|
|
18
|
+
import { createIapAdapter } from "./iap-adapter.js";
|
|
19
|
+
const UNSUPPORTED_CAPABILITIES = {
|
|
20
|
+
supportsSubscriptions: false,
|
|
21
|
+
supportsPlanChange: false,
|
|
22
|
+
supportsPriceChangeConfirmation: false,
|
|
23
|
+
reportsGraceAndHoldDistinctly: false,
|
|
24
|
+
supportsExternalTransactions: false,
|
|
25
|
+
/** Nothing here can charge anyone, so the environment guard has nothing to block. */
|
|
26
|
+
createsRealTransactions: false,
|
|
27
|
+
purchaseOutcomeIncludesStoreTime: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The no-adapter stub.
|
|
32
|
+
*
|
|
33
|
+
* Every operation fails safely and predictably. Notably `queryOwned` returns an
|
|
34
|
+
* empty list rather than throwing: the engine then computes `not_entitled` after a
|
|
35
|
+
* successful-but-empty sync, which is honest — on a platform with no store, the
|
|
36
|
+
* user genuinely holds nothing this package can verify.
|
|
37
|
+
*/
|
|
38
|
+
function createUnsupportedProvider() {
|
|
39
|
+
return {
|
|
40
|
+
async connect() {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
reason: 'platform_unsupported',
|
|
44
|
+
retryable: false
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
async disconnect() {
|
|
48
|
+
// Nothing was ever connected.
|
|
49
|
+
},
|
|
50
|
+
observeConnection() {
|
|
51
|
+
return () => undefined;
|
|
52
|
+
},
|
|
53
|
+
async queryProducts() {
|
|
54
|
+
return [];
|
|
55
|
+
},
|
|
56
|
+
async queryOwned() {
|
|
57
|
+
return [];
|
|
58
|
+
},
|
|
59
|
+
async launchPurchase() {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: 'not_ready',
|
|
63
|
+
detail: 'platform_unsupported'
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
observePurchases() {
|
|
67
|
+
return () => undefined;
|
|
68
|
+
},
|
|
69
|
+
async acknowledge() {
|
|
70
|
+
// No transaction can exist to acknowledge.
|
|
71
|
+
},
|
|
72
|
+
async consume() {
|
|
73
|
+
// As above.
|
|
74
|
+
},
|
|
75
|
+
async openSubscriptionManagement() {
|
|
76
|
+
// No store screen to open.
|
|
77
|
+
},
|
|
78
|
+
async confirmPriceChange() {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
reason: 'not_ready'
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
capabilities: () => UNSUPPORTED_CAPABILITIES
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The platform's store adapter.
|
|
89
|
+
*
|
|
90
|
+
* iOS deliberately returns the stub today rather than throwing: the contract is
|
|
91
|
+
* prepared for StoreKit, the implementation is not, and an app running on iOS
|
|
92
|
+
* should degrade to "cannot sell here" instead of crashing.
|
|
93
|
+
*/
|
|
94
|
+
export function createStoreProvider(options = {}) {
|
|
95
|
+
if (options.forceUnsupported) {
|
|
96
|
+
return createUnsupportedProvider();
|
|
97
|
+
}
|
|
98
|
+
if (Platform.OS === 'android') {
|
|
99
|
+
return createIapAdapter();
|
|
100
|
+
}
|
|
101
|
+
return createUnsupportedProvider();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Exported for a test or a screen that needs the stub explicitly. */
|
|
105
|
+
export { createUnsupportedProvider };
|
|
106
|
+
//# sourceMappingURL=createStoreProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","createIapAdapter","UNSUPPORTED_CAPABILITIES","supportsSubscriptions","supportsPlanChange","supportsPriceChangeConfirmation","reportsGraceAndHoldDistinctly","supportsExternalTransactions","createsRealTransactions","purchaseOutcomeIncludesStoreTime","createUnsupportedProvider","connect","ok","reason","retryable","disconnect","observeConnection","undefined","queryProducts","queryOwned","launchPurchase","detail","observePurchases","acknowledge","consume","openSubscriptionManagement","confirmPriceChange","capabilities","createStoreProvider","options","forceUnsupported","OS"],"sourceRoot":"../../../src","sources":["adapter/createStoreProvider.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,gBAAgB,QAAQ,kBAAe;AAWhD,MAAMC,wBAA8C,GAAG;EACtDC,qBAAqB,EAAE,KAAK;EAC5BC,kBAAkB,EAAE,KAAK;EACzBC,+BAA+B,EAAE,KAAK;EACtCC,6BAA6B,EAAE,KAAK;EACpCC,4BAA4B,EAAE,KAAK;EACnC;EACAC,uBAAuB,EAAE,KAAK;EAC9BC,gCAAgC,EAAE;AACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,yBAAyBA,CAAA,EAAiB;EAClD,OAAO;IACN,MAAMC,OAAOA,CAAA,EAAoC;MAChD,OAAO;QAAEC,EAAE,EAAE,KAAK;QAAEC,MAAM,EAAE,sBAAsB;QAAEC,SAAS,EAAE;MAAM,CAAC;IACvE,CAAC;IACD,MAAMC,UAAUA,CAAA,EAAkB;MACjC;IAAA,CACA;IACDC,iBAAiBA,CAAA,EAAgB;MAChC,OAAO,MAAMC,SAAS;IACvB,CAAC;IACD,MAAMC,aAAaA,CAAA,EAA+B;MACjD,OAAO,EAAE;IACV,CAAC;IACD,MAAMC,UAAUA,CAAA,EAAgC;MAC/C,OAAO,EAAE;IACV,CAAC;IACD,MAAMC,cAAcA,CAAA,EAAqC;MACxD,OAAO;QAAER,EAAE,EAAE,KAAK;QAAEC,MAAM,EAAE,WAAW;QAAEQ,MAAM,EAAE;MAAuB,CAAC;IAC1E,CAAC;IACDC,gBAAgBA,CAAA,EAAgB;MAC/B,OAAO,MAAML,SAAS;IACvB,CAAC;IACD,MAAMM,WAAWA,CAAA,EAAkB;MAClC;IAAA,CACA;IACD,MAAMC,OAAOA,CAAA,EAAkB;MAC9B;IAAA,CACA;IACD,MAAMC,0BAA0BA,CAAA,EAAkB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