@rocapine/react-native-onboarding 1.68.1 → 1.69.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +15 -1
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +21 -2
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/present.d.ts +33 -0
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +9 -1
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/usePaywall.d.ts +15 -0
- package/dist/paywalls/usePaywall.d.ts.map +1 -1
- package/dist/paywalls/usePaywall.js +2 -2
- package/dist/paywalls/usePaywall.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/paywalls/PaywallProvider.tsx +37 -3
- package/src/paywalls/__tests__/present.test.ts +45 -0
- package/src/paywalls/present.ts +43 -0
- package/src/paywalls/usePaywall.ts +18 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,5 +20,6 @@ export type { Paywall, PaywallCatalog, PaywallOptions, GetPaywallsResponseHeader
|
|
|
20
20
|
export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
|
|
21
21
|
export type { PaywallContextValue } from "./paywalls/PaywallProvider";
|
|
22
22
|
export { usePaywall } from "./paywalls/usePaywall";
|
|
23
|
+
export type { CatalogStatus } from "./paywalls/present";
|
|
23
24
|
export type { UsePaywallResult } from "./paywalls/usePaywall";
|
|
24
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,cAAc,SAAS,CAAC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,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { OnboardingStudioClient } from "../OnboardingStudioClient";
|
|
2
2
|
import { Paywall, PaywallCatalog, PresentResult } from "./types";
|
|
3
|
-
import {
|
|
3
|
+
import { type CatalogStatus } from "./present";
|
|
4
|
+
import { ProductProvider, ProductStatus } from "../products/types";
|
|
4
5
|
import type { CustomActions } from "../infra/provider/OnboardingProvider";
|
|
5
6
|
/**
|
|
6
7
|
* Everything a paywall consumer or a paywall HOST needs. Deliberately one
|
|
@@ -13,6 +14,19 @@ export type PaywallContextValue = {
|
|
|
13
14
|
present: (placement: string) => Promise<PresentResult>;
|
|
14
15
|
isReady: boolean;
|
|
15
16
|
catalog: PaywallCatalog | null;
|
|
17
|
+
/**
|
|
18
|
+
* What the catalog is doing — the states `isReady` collapses into one
|
|
19
|
+
* boolean. See `CatalogStatus`; `"revalidating"` in particular means the
|
|
20
|
+
* catalog on hand may be superseded within moments, so a missing placement
|
|
21
|
+
* does not yet mean an absent one.
|
|
22
|
+
*/
|
|
23
|
+
catalogStatus: CatalogStatus;
|
|
24
|
+
/**
|
|
25
|
+
* What the store products are doing. The other half of `isReady`: a host that
|
|
26
|
+
* sees `catalogStatus: "ready"` but `isReady: false` can tell it is waiting on
|
|
27
|
+
* the store rather than on us.
|
|
28
|
+
*/
|
|
29
|
+
productsStatus: ProductStatus;
|
|
16
30
|
/** The paywall currently being presented, or null. Read by `usePaywallHost()` — not by `usePaywall()`. */
|
|
17
31
|
activePaywall: Paywall | null;
|
|
18
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaywallProvider.d.ts","sourceRoot":"","sources":["../../src/paywalls/PaywallProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Payw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AAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3C;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,mFAAmF;IACnF,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;;;;OAQG;IACH,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAoRD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,0GAQ7B,oBAAoB,4CAetB,CAAC"}
|
|
@@ -34,6 +34,9 @@ const EMPTY_PAYWALL_CONTEXT = {
|
|
|
34
34
|
present: async () => ({ status: "error", reason: "unknown-placement" }),
|
|
35
35
|
isReady: false,
|
|
36
36
|
catalog: null,
|
|
37
|
+
// No provider above: nothing is loading and nothing will arrive.
|
|
38
|
+
catalogStatus: "loading",
|
|
39
|
+
productsStatus: "idle",
|
|
37
40
|
activePaywall: null,
|
|
38
41
|
complete: () => { },
|
|
39
42
|
acknowledgePresentation: () => { },
|
|
@@ -69,8 +72,12 @@ const PaywallProviderInner = ({ children, client, locale, customAudienceParams,
|
|
|
69
72
|
// for why the query still needs `paywallQueryClient` for the ONE case
|
|
70
73
|
// `data` alone can't cover: a background revalidation pushing a fresh
|
|
71
74
|
// payload while this query call already resolved with the cached one.
|
|
72
|
-
const { data, error } = (0, react_query_1.useQuery)((0, getPaywalls_query_1.getPaywallsQuery)(client, locale, customAudienceParams, paywallQueryClient));
|
|
75
|
+
const { data, error, isFetching } = (0, react_query_1.useQuery)((0, getPaywalls_query_1.getPaywallsQuery)(client, locale, customAudienceParams, paywallQueryClient));
|
|
73
76
|
const catalog = data !== null && data !== void 0 ? data : null;
|
|
77
|
+
// `isFetching` (not `isLoading`) on purpose: it is also true for a BACKGROUND
|
|
78
|
+
// revalidation behind an already-served cached catalog, which is precisely the
|
|
79
|
+
// case a host needs to see — see `CatalogStatus`.
|
|
80
|
+
const catalogStatus = (0, present_1.computeCatalogStatus)(catalog, error, isFetching);
|
|
74
81
|
(0, react_1.useEffect)(() => {
|
|
75
82
|
if (!error)
|
|
76
83
|
return;
|
|
@@ -261,11 +268,23 @@ const PaywallProviderInner = ({ children, client, locale, customAudienceParams,
|
|
|
261
268
|
present,
|
|
262
269
|
isReady,
|
|
263
270
|
catalog,
|
|
271
|
+
catalogStatus,
|
|
272
|
+
productsStatus: productRuntime.status,
|
|
264
273
|
activePaywall,
|
|
265
274
|
complete,
|
|
266
275
|
acknowledgePresentation,
|
|
267
276
|
customActions,
|
|
268
|
-
}), [
|
|
277
|
+
}), [
|
|
278
|
+
present,
|
|
279
|
+
isReady,
|
|
280
|
+
catalog,
|
|
281
|
+
catalogStatus,
|
|
282
|
+
productRuntime.status,
|
|
283
|
+
activePaywall,
|
|
284
|
+
complete,
|
|
285
|
+
acknowledgePresentation,
|
|
286
|
+
customActions,
|
|
287
|
+
]);
|
|
269
288
|
return ((0, jsx_runtime_1.jsx)(ProductRuntimeContext_1.ProductRuntimeContext.Provider, { value: productRuntimeWithPurchaseTracking, children: (0, jsx_runtime_1.jsx)(exports.PaywallContext.Provider, { value: contextValue, children: children }) }));
|
|
270
289
|
};
|
|
271
290
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaywallProvider.js","sourceRoot":"","sources":["../../src/paywalls/PaywallProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAAqG;AACrG,uDAAmF;AAEnF,2DAAuD;AAEvD,
|
|
1
|
+
{"version":3,"file":"PaywallProvider.js","sourceRoot":"","sources":["../../src/paywalls/PaywallProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAAqG;AACrG,uDAAmF;AAEnF,2DAAuD;AAEvD,uCAWmB;AACnB,yDAAsD;AAEtD,6EAA0E;AAG1E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,0EAA0E;AAC1E,iEAAiE;AACjE,yDAAyD;AACzD,gCAAgC;AAChC,MAAM,kBAAkB,GAAG,IAAI,yBA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Decision: (catalog: PaywallCatalog | null, ac
|
|
|
64
64
|
* unacknowledged presentation is ever torn down.
|
|
65
65
|
*/
|
|
66
66
|
export declare const shouldBreakPresentationWedge: (activePlacement: string | null, hostAcknowledged: boolean, timedOut: boolean) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* What the catalog is doing right now — the states `isReady` collapses.
|
|
69
|
+
*
|
|
70
|
+
* `isReady` is a single boolean over at least three distinct situations (no
|
|
71
|
+
* catalog yet, a catalog whose products are still resolving, and a failed query
|
|
72
|
+
* — which also presents as `catalog === null`). A host deciding "wait for the
|
|
73
|
+
* catalog" versus "fall back to another paywall engine" cannot tell those apart
|
|
74
|
+
* from one boolean, and every host that needs the distinction ends up building
|
|
75
|
+
* its own multi-input gate.
|
|
76
|
+
*
|
|
77
|
+
* `"revalidating"` is the state that motivated this, and it is not cosmetic.
|
|
78
|
+
* In production the catalog is served CACHE-FIRST from AsyncStorage under a key
|
|
79
|
+
* that is NOT scoped by `customAudienceParams` (`getPaywalls.query.ts` — the
|
|
80
|
+
* react-query key is param-scoped, the disk key is a bare constant). So a host
|
|
81
|
+
* sending volatile params gets an instantly-available catalog that was resolved
|
|
82
|
+
* under DIFFERENT params, with a fresh fetch in flight behind it. That catalog
|
|
83
|
+
* is present and non-null, so it reads as ready — and a host gating on
|
|
84
|
+
* `catalog.paywalls[placement]` can conclude the placement does not exist and
|
|
85
|
+
* route away, milliseconds before the correct catalog arrives.
|
|
86
|
+
*
|
|
87
|
+
* Observed consequence, reported from a production pilot: for an audience gated
|
|
88
|
+
* on a threshold (`hoursSinceOnboardingPaywall >= 44`), the launch where a user
|
|
89
|
+
* first becomes eligible is served the PRE-threshold catalog, so the arm under
|
|
90
|
+
* test loses exactly the launch that matters. `"revalidating"` is how a host
|
|
91
|
+
* distinguishes "this catalog is final" from "this catalog may be superseded in
|
|
92
|
+
* a moment", and therefore whether a missing placement means absent or not-yet.
|
|
93
|
+
*
|
|
94
|
+
* A present catalog outranks an error deliberately: if a background
|
|
95
|
+
* revalidation fails, react-query keeps the cached `data` AND sets `error`, and
|
|
96
|
+
* a usable catalog should not be reported as a failure.
|
|
97
|
+
*/
|
|
98
|
+
export type CatalogStatus = "loading" | "ready" | "revalidating" | "error";
|
|
99
|
+
export declare const computeCatalogStatus: (catalog: PaywallCatalog | null, error: unknown, isFetching: boolean) => CatalogStatus;
|
|
67
100
|
/**
|
|
68
101
|
* `isReady` = catalog resolved AND products resolved — the one flag a caller
|
|
69
102
|
* needs to know "presenting now will not show a spinner".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"present.d.ts","sourceRoot":"","sources":["../../src/paywalls/present.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,cAAc,GAAG,IAAI,KAAG,UAAU,EAa7E,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,cAAc,GAAG,IAAI,EAC9B,iBAAiB,MAAM,GAAG,IAAI,EAC9B,WAAW,MAAM,KAChB,eAaF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,4BAA4B,GACvC,iBAAiB,MAAM,GAAG,IAAI,EAC9B,kBAAkB,OAAO,EACzB,UAAU,OAAO,KAChB,OAAoE,CAAC;AAExE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cA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G;AACH,eAAO,MAAM,4BAA4B,GACvC,iBAAiB,MAAM,GAAG,IAAI,EAC9B,kBAAkB,OAAO,EACzB,UAAU,OAAO,KAChB,OAAoE,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,cAAc,GAAG,OAAO,CAAC;AAE3E,eAAO,MAAM,oBAAoB,GAC/B,SAAS,cAAc,GAAG,IAAI,EAC9B,OAAO,OAAO,EACd,YAAY,OAAO,KAClB,aAIF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,cAAc,GAAG,IAAI,EAC9B,aAAa,UAAU,EAAE,EACzB,gBAAgB,aAAa,KAC5B,OAAuF,CAAC;AAE3F;;;;;;;;;GASG;AACH,MAAM,MAAM,iCAAiC,GAAG,WAAW,GAAG,WAAW,GAAG,IAAI,CAAC;AAEjF,2FAA2F;AAC3F,eAAO,MAAM,yBAAyB,GAAI,QAAQ,cAAc,KAAG,iCACoB,CAAC;AAExF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,aAAa,EACvB,iBAAiB,iCAAiC,KACjD,aAC0F,CAAC;AAE9F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,2BAA2B,GACtC,qBAAqB,MAAM,EAC3B,mBAAmB,MAAM,KACxB,OAAoD,CAAC"}
|
package/dist/paywalls/present.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldRecordPurchaseOutcome = exports.resolvePresentedOutcome = exports.purchaseOutcomeFromResult = exports.computeIsReady = exports.shouldBreakPresentationWedge = exports.resolvePresentDecision = exports.collectProductRefs = void 0;
|
|
3
|
+
exports.shouldRecordPurchaseOutcome = exports.resolvePresentedOutcome = exports.purchaseOutcomeFromResult = exports.computeIsReady = exports.computeCatalogStatus = exports.shouldBreakPresentationWedge = exports.resolvePresentDecision = exports.collectProductRefs = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Union of every `paywall.products[]` across the WHOLE catalog, deduplicated
|
|
6
6
|
* by content — the same identity notion `useProducts`' `refsKey` uses
|
|
@@ -89,6 +89,14 @@ exports.resolvePresentDecision = resolvePresentDecision;
|
|
|
89
89
|
*/
|
|
90
90
|
const shouldBreakPresentationWedge = (activePlacement, hostAcknowledged, timedOut) => activePlacement !== null && !hostAcknowledged && timedOut;
|
|
91
91
|
exports.shouldBreakPresentationWedge = shouldBreakPresentationWedge;
|
|
92
|
+
const computeCatalogStatus = (catalog, error, isFetching) => {
|
|
93
|
+
if (catalog !== null)
|
|
94
|
+
return isFetching ? "revalidating" : "ready";
|
|
95
|
+
if (error)
|
|
96
|
+
return "error";
|
|
97
|
+
return "loading";
|
|
98
|
+
};
|
|
99
|
+
exports.computeCatalogStatus = computeCatalogStatus;
|
|
92
100
|
/**
|
|
93
101
|
* `isReady` = catalog resolved AND products resolved — the one flag a caller
|
|
94
102
|
* needs to know "presenting now will not show a spinner".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"present.js","sourceRoot":"","sources":["../../src/paywalls/present.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;GAYG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAA8B,EAAgB,EAAE;;IACjF,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,IAAI,GAAiB,EAAE,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,MAAA,G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AAW,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAD3E,QAAA,yBAAyB,6BACkD;AAExF;;;;;;;;;;;;;GAaG;AACI,MAAM,uBAAuB,GAAG,CACrC,QAAuB,EACvB,eAAkD,EACnC,EAAE,CACjB,QAAQ,CAAC,MAAM,KAAK,WAAW,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAJjF,QAAA,uBAAuB,2BAI0D;AAE9F;;;;;;;;;;;;;;;GAeG;AACI,MAAM,2BAA2B,GAAG,CACzC,mBAA2B,EAC3B,iBAAyB,EAChB,EAAE,CAAC,mBAAmB,KAAK,iBAAiB,CAAC;AAH3C,QAAA,2BAA2B,+BAGgB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PaywallCatalog, PresentResult } from "./types";
|
|
2
|
+
import type { CatalogStatus } from "./present";
|
|
3
|
+
import type { ProductStatus } from "../products/types";
|
|
2
4
|
export type UsePaywallResult = {
|
|
3
5
|
/**
|
|
4
6
|
* Present a paywall by placement. Never fetches — the catalog and its
|
|
@@ -18,6 +20,19 @@ export type UsePaywallResult = {
|
|
|
18
20
|
isReady: boolean;
|
|
19
21
|
/** The full resolved catalog (every placement), or `null` before it loads. */
|
|
20
22
|
catalog: PaywallCatalog | null;
|
|
23
|
+
/**
|
|
24
|
+
* What the catalog is doing, for hosts that need more than `isReady`'s one
|
|
25
|
+
* bit. `"revalidating"` is the important one: the catalog on hand was served
|
|
26
|
+
* from disk and a fresh fetch is in flight, so a placement missing from it may
|
|
27
|
+
* simply not have arrived yet. Gate "fall back to another engine" on
|
|
28
|
+
* `"ready"`, not merely on a non-null catalog.
|
|
29
|
+
*/
|
|
30
|
+
catalogStatus: CatalogStatus;
|
|
31
|
+
/**
|
|
32
|
+
* What the store products are doing — the other half of `isReady`. Lets a
|
|
33
|
+
* host tell "still waiting on the store" from "still waiting on us".
|
|
34
|
+
*/
|
|
35
|
+
productsStatus: ProductStatus;
|
|
21
36
|
};
|
|
22
37
|
/**
|
|
23
38
|
* Read the paywall runtime published by an ancestor `PaywallProvider`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePaywall.d.ts","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"usePaywall.d.ts","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;;OASG;IACH,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B;;;;;;OAMG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;;OAGG;IACH,cAAc,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAO,gBAI7B,CAAC"}
|
|
@@ -10,8 +10,8 @@ const PaywallProvider_1 = require("./PaywallProvider");
|
|
|
10
10
|
* `useProductRuntime()` degrades to `null` with no ancestor.
|
|
11
11
|
*/
|
|
12
12
|
const usePaywall = () => {
|
|
13
|
-
const { present, isReady, catalog } = (0, react_1.useContext)(PaywallProvider_1.PaywallContext);
|
|
14
|
-
return { present, isReady, catalog };
|
|
13
|
+
const { present, isReady, catalog, catalogStatus, productsStatus } = (0, react_1.useContext)(PaywallProvider_1.PaywallContext);
|
|
14
|
+
return { present, isReady, catalog, catalogStatus, productsStatus };
|
|
15
15
|
};
|
|
16
16
|
exports.usePaywall = usePaywall;
|
|
17
17
|
//# sourceMappingURL=usePaywall.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePaywall.js","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uDAAmD;
|
|
1
|
+
{"version":3,"file":"usePaywall.js","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uDAAmD;AAuCnD;;;;;GAKG;AACI,MAAM,UAAU,GAAG,GAAqB,EAAE;IAC/C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAChE,IAAA,kBAAU,EAAC,gCAAc,CAAC,CAAC;IAC7B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AACtE,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.0",
|
|
4
4
|
"description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -101,4 +101,7 @@ export type {
|
|
|
101
101
|
export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
|
|
102
102
|
export type { PaywallContextValue } from "./paywalls/PaywallProvider";
|
|
103
103
|
export { usePaywall } from "./paywalls/usePaywall";
|
|
104
|
+
// Exported so a host can switch exhaustively on what the catalog is doing
|
|
105
|
+
// rather than inferring it from `isReady` plus a non-null check.
|
|
106
|
+
export type { CatalogStatus } from "./paywalls/present";
|
|
104
107
|
export type { UsePaywallResult } from "./paywalls/usePaywall";
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
collectProductRefs,
|
|
8
8
|
computeIsReady,
|
|
9
9
|
purchaseOutcomeFromResult,
|
|
10
|
+
computeCatalogStatus,
|
|
11
|
+
type CatalogStatus,
|
|
10
12
|
resolvePresentDecision,
|
|
11
13
|
shouldBreakPresentationWedge,
|
|
12
14
|
resolvePresentedOutcome,
|
|
@@ -14,7 +16,7 @@ import {
|
|
|
14
16
|
type PurchaseOutcomeDuringPresentation,
|
|
15
17
|
} from "./present";
|
|
16
18
|
import { useProducts } from "../products/useProducts";
|
|
17
|
-
import { ProductProvider } from "../products/types";
|
|
19
|
+
import { ProductProvider, ProductStatus } from "../products/types";
|
|
18
20
|
import { ProductRuntimeContext } from "../products/ProductRuntimeContext";
|
|
19
21
|
import type { CustomActions } from "../infra/provider/OnboardingProvider";
|
|
20
22
|
|
|
@@ -51,6 +53,19 @@ export type PaywallContextValue = {
|
|
|
51
53
|
present: (placement: string) => Promise<PresentResult>;
|
|
52
54
|
isReady: boolean;
|
|
53
55
|
catalog: PaywallCatalog | null;
|
|
56
|
+
/**
|
|
57
|
+
* What the catalog is doing — the states `isReady` collapses into one
|
|
58
|
+
* boolean. See `CatalogStatus`; `"revalidating"` in particular means the
|
|
59
|
+
* catalog on hand may be superseded within moments, so a missing placement
|
|
60
|
+
* does not yet mean an absent one.
|
|
61
|
+
*/
|
|
62
|
+
catalogStatus: CatalogStatus;
|
|
63
|
+
/**
|
|
64
|
+
* What the store products are doing. The other half of `isReady`: a host that
|
|
65
|
+
* sees `catalogStatus: "ready"` but `isReady: false` can tell it is waiting on
|
|
66
|
+
* the store rather than on us.
|
|
67
|
+
*/
|
|
68
|
+
productsStatus: ProductStatus;
|
|
54
69
|
/** The paywall currently being presented, or null. Read by `usePaywallHost()` — not by `usePaywall()`. */
|
|
55
70
|
activePaywall: Paywall | null;
|
|
56
71
|
/**
|
|
@@ -78,6 +93,9 @@ const EMPTY_PAYWALL_CONTEXT: PaywallContextValue = {
|
|
|
78
93
|
present: async () => ({ status: "error", reason: "unknown-placement" }),
|
|
79
94
|
isReady: false,
|
|
80
95
|
catalog: null,
|
|
96
|
+
// No provider above: nothing is loading and nothing will arrive.
|
|
97
|
+
catalogStatus: "loading",
|
|
98
|
+
productsStatus: "idle",
|
|
81
99
|
activePaywall: null,
|
|
82
100
|
complete: () => {},
|
|
83
101
|
acknowledgePresentation: () => {},
|
|
@@ -164,10 +182,14 @@ const PaywallProviderInner = ({
|
|
|
164
182
|
// for why the query still needs `paywallQueryClient` for the ONE case
|
|
165
183
|
// `data` alone can't cover: a background revalidation pushing a fresh
|
|
166
184
|
// payload while this query call already resolved with the cached one.
|
|
167
|
-
const { data, error } = useQuery<PaywallCatalog>(
|
|
185
|
+
const { data, error, isFetching } = useQuery<PaywallCatalog>(
|
|
168
186
|
getPaywallsQuery(client, locale, customAudienceParams, paywallQueryClient)
|
|
169
187
|
);
|
|
170
188
|
const catalog = data ?? null;
|
|
189
|
+
// `isFetching` (not `isLoading`) on purpose: it is also true for a BACKGROUND
|
|
190
|
+
// revalidation behind an already-served cached catalog, which is precisely the
|
|
191
|
+
// case a host needs to see — see `CatalogStatus`.
|
|
192
|
+
const catalogStatus = computeCatalogStatus(catalog, error, isFetching);
|
|
171
193
|
|
|
172
194
|
useEffect(() => {
|
|
173
195
|
if (!error) return;
|
|
@@ -380,12 +402,24 @@ const PaywallProviderInner = ({
|
|
|
380
402
|
present,
|
|
381
403
|
isReady,
|
|
382
404
|
catalog,
|
|
405
|
+
catalogStatus,
|
|
406
|
+
productsStatus: productRuntime.status,
|
|
383
407
|
activePaywall,
|
|
384
408
|
complete,
|
|
385
409
|
acknowledgePresentation,
|
|
386
410
|
customActions,
|
|
387
411
|
}),
|
|
388
|
-
[
|
|
412
|
+
[
|
|
413
|
+
present,
|
|
414
|
+
isReady,
|
|
415
|
+
catalog,
|
|
416
|
+
catalogStatus,
|
|
417
|
+
productRuntime.status,
|
|
418
|
+
activePaywall,
|
|
419
|
+
complete,
|
|
420
|
+
acknowledgePresentation,
|
|
421
|
+
customActions,
|
|
422
|
+
]
|
|
389
423
|
);
|
|
390
424
|
|
|
391
425
|
return (
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
collectProductRefs,
|
|
4
|
+
computeCatalogStatus,
|
|
4
5
|
computeIsReady,
|
|
5
6
|
purchaseOutcomeFromResult,
|
|
6
7
|
resolvePresentDecision,
|
|
@@ -257,3 +258,47 @@ describe("shouldRecordPurchaseOutcome", () => {
|
|
|
257
258
|
expect(shouldRecordPurchaseOutcome(1, 5)).toBe(false);
|
|
258
259
|
});
|
|
259
260
|
});
|
|
261
|
+
|
|
262
|
+
describe("computeCatalogStatus", () => {
|
|
263
|
+
const catalog = makeCatalog([makePaywall({ id: "1", placement: "hard_paywall" })]);
|
|
264
|
+
|
|
265
|
+
it("is 'loading' before anything arrives", () => {
|
|
266
|
+
expect(computeCatalogStatus(null, null, true)).toBe("loading");
|
|
267
|
+
expect(computeCatalogStatus(null, null, false)).toBe("loading");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("is 'error' only when there is no catalog to fall back on", () => {
|
|
271
|
+
expect(computeCatalogStatus(null, new Error("network"), false)).toBe("error");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("is 'ready' for a settled catalog", () => {
|
|
275
|
+
expect(computeCatalogStatus(catalog, null, false)).toBe("ready");
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("is 'revalidating' when a catalog is on hand AND a fetch is in flight", () => {
|
|
279
|
+
// The state this type exists for. In production the catalog is served
|
|
280
|
+
// cache-first from a disk key that is NOT scoped by customAudienceParams,
|
|
281
|
+
// so this catalog may have been resolved under DIFFERENT params and be
|
|
282
|
+
// superseded in a moment. A host must be able to tell that a placement
|
|
283
|
+
// missing HERE might simply not have arrived yet.
|
|
284
|
+
expect(computeCatalogStatus(catalog, null, true)).toBe("revalidating");
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("prefers a usable catalog over reporting a failed revalidation", () => {
|
|
288
|
+
// react-query keeps cached `data` and sets `error` when a background
|
|
289
|
+
// refetch fails. Reporting "error" there would make a host discard a
|
|
290
|
+
// perfectly serviceable catalog.
|
|
291
|
+
expect(computeCatalogStatus(catalog, new Error("revalidation failed"), false)).toBe("ready");
|
|
292
|
+
expect(computeCatalogStatus(catalog, new Error("revalidation failed"), true)).toBe("revalidating");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("distinguishes every state `isReady` collapses", () => {
|
|
296
|
+
// isReady is false for all three of these; catalogStatus separates them,
|
|
297
|
+
// which is the whole point.
|
|
298
|
+
const loading = computeCatalogStatus(null, null, true);
|
|
299
|
+
const errored = computeCatalogStatus(null, new Error("x"), false);
|
|
300
|
+
const productsPending = computeCatalogStatus(catalog, null, false);
|
|
301
|
+
expect(computeIsReady(null, [], "idle")).toBe(false);
|
|
302
|
+
expect(new Set([loading, errored, productsPending]).size).toBe(3);
|
|
303
|
+
});
|
|
304
|
+
});
|
package/src/paywalls/present.ts
CHANGED
|
@@ -99,6 +99,49 @@ export const shouldBreakPresentationWedge = (
|
|
|
99
99
|
timedOut: boolean
|
|
100
100
|
): boolean => activePlacement !== null && !hostAcknowledged && timedOut;
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* What the catalog is doing right now — the states `isReady` collapses.
|
|
104
|
+
*
|
|
105
|
+
* `isReady` is a single boolean over at least three distinct situations (no
|
|
106
|
+
* catalog yet, a catalog whose products are still resolving, and a failed query
|
|
107
|
+
* — which also presents as `catalog === null`). A host deciding "wait for the
|
|
108
|
+
* catalog" versus "fall back to another paywall engine" cannot tell those apart
|
|
109
|
+
* from one boolean, and every host that needs the distinction ends up building
|
|
110
|
+
* its own multi-input gate.
|
|
111
|
+
*
|
|
112
|
+
* `"revalidating"` is the state that motivated this, and it is not cosmetic.
|
|
113
|
+
* In production the catalog is served CACHE-FIRST from AsyncStorage under a key
|
|
114
|
+
* that is NOT scoped by `customAudienceParams` (`getPaywalls.query.ts` — the
|
|
115
|
+
* react-query key is param-scoped, the disk key is a bare constant). So a host
|
|
116
|
+
* sending volatile params gets an instantly-available catalog that was resolved
|
|
117
|
+
* under DIFFERENT params, with a fresh fetch in flight behind it. That catalog
|
|
118
|
+
* is present and non-null, so it reads as ready — and a host gating on
|
|
119
|
+
* `catalog.paywalls[placement]` can conclude the placement does not exist and
|
|
120
|
+
* route away, milliseconds before the correct catalog arrives.
|
|
121
|
+
*
|
|
122
|
+
* Observed consequence, reported from a production pilot: for an audience gated
|
|
123
|
+
* on a threshold (`hoursSinceOnboardingPaywall >= 44`), the launch where a user
|
|
124
|
+
* first becomes eligible is served the PRE-threshold catalog, so the arm under
|
|
125
|
+
* test loses exactly the launch that matters. `"revalidating"` is how a host
|
|
126
|
+
* distinguishes "this catalog is final" from "this catalog may be superseded in
|
|
127
|
+
* a moment", and therefore whether a missing placement means absent or not-yet.
|
|
128
|
+
*
|
|
129
|
+
* A present catalog outranks an error deliberately: if a background
|
|
130
|
+
* revalidation fails, react-query keeps the cached `data` AND sets `error`, and
|
|
131
|
+
* a usable catalog should not be reported as a failure.
|
|
132
|
+
*/
|
|
133
|
+
export type CatalogStatus = "loading" | "ready" | "revalidating" | "error";
|
|
134
|
+
|
|
135
|
+
export const computeCatalogStatus = (
|
|
136
|
+
catalog: PaywallCatalog | null,
|
|
137
|
+
error: unknown,
|
|
138
|
+
isFetching: boolean
|
|
139
|
+
): CatalogStatus => {
|
|
140
|
+
if (catalog !== null) return isFetching ? "revalidating" : "ready";
|
|
141
|
+
if (error) return "error";
|
|
142
|
+
return "loading";
|
|
143
|
+
};
|
|
144
|
+
|
|
102
145
|
/**
|
|
103
146
|
* `isReady` = catalog resolved AND products resolved — the one flag a caller
|
|
104
147
|
* needs to know "presenting now will not show a spinner".
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { PaywallContext } from "./PaywallProvider";
|
|
3
3
|
import { PaywallCatalog, PresentResult } from "./types";
|
|
4
|
+
import type { CatalogStatus } from "./present";
|
|
5
|
+
import type { ProductStatus } from "../products/types";
|
|
4
6
|
|
|
5
7
|
export type UsePaywallResult = {
|
|
6
8
|
/**
|
|
@@ -21,6 +23,19 @@ export type UsePaywallResult = {
|
|
|
21
23
|
isReady: boolean;
|
|
22
24
|
/** The full resolved catalog (every placement), or `null` before it loads. */
|
|
23
25
|
catalog: PaywallCatalog | null;
|
|
26
|
+
/**
|
|
27
|
+
* What the catalog is doing, for hosts that need more than `isReady`'s one
|
|
28
|
+
* bit. `"revalidating"` is the important one: the catalog on hand was served
|
|
29
|
+
* from disk and a fresh fetch is in flight, so a placement missing from it may
|
|
30
|
+
* simply not have arrived yet. Gate "fall back to another engine" on
|
|
31
|
+
* `"ready"`, not merely on a non-null catalog.
|
|
32
|
+
*/
|
|
33
|
+
catalogStatus: CatalogStatus;
|
|
34
|
+
/**
|
|
35
|
+
* What the store products are doing — the other half of `isReady`. Lets a
|
|
36
|
+
* host tell "still waiting on the store" from "still waiting on us".
|
|
37
|
+
*/
|
|
38
|
+
productsStatus: ProductStatus;
|
|
24
39
|
};
|
|
25
40
|
|
|
26
41
|
/**
|
|
@@ -30,6 +45,7 @@ export type UsePaywallResult = {
|
|
|
30
45
|
* `useProductRuntime()` degrades to `null` with no ancestor.
|
|
31
46
|
*/
|
|
32
47
|
export const usePaywall = (): UsePaywallResult => {
|
|
33
|
-
const { present, isReady, catalog } =
|
|
34
|
-
|
|
48
|
+
const { present, isReady, catalog, catalogStatus, productsStatus } =
|
|
49
|
+
useContext(PaywallContext);
|
|
50
|
+
return { present, isReady, catalog, catalogStatus, productsStatus };
|
|
35
51
|
};
|