@rocapine/react-native-onboarding 1.77.0 → 1.79.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/README.md +38 -10
- package/dist/OnboardingStudio.d.ts +14 -1
- package/dist/OnboardingStudio.d.ts.map +1 -1
- package/dist/OnboardingStudio.js +5 -1
- package/dist/OnboardingStudio.js.map +1 -1
- package/dist/OnboardingStudioClient.d.ts +31 -0
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +80 -19
- package/dist/OnboardingStudioClient.js.map +1 -1
- package/dist/assignmentId.d.ts +107 -0
- package/dist/assignmentId.d.ts.map +1 -0
- package/dist/assignmentId.js +215 -0
- package/dist/assignmentId.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +8 -1
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +5 -1
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +7 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- package/dist/paywalls/devHook.d.ts +26 -0
- package/dist/paywalls/devHook.d.ts.map +1 -0
- package/dist/paywalls/devHook.js +29 -0
- package/dist/paywalls/devHook.js.map +1 -0
- package/dist/paywalls/observer.d.ts +2 -0
- package/dist/paywalls/observer.d.ts.map +1 -1
- package/dist/paywalls/observer.js +21 -9
- package/dist/paywalls/observer.js.map +1 -1
- package/dist/paywalls/types.d.ts +22 -0
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +34 -13
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +136 -21
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/steps/ComposableScreen/types.d.ts +21 -0
- package/dist/steps/ComposableScreen/types.d.ts.map +1 -1
- package/dist/steps/ComposableScreen/types.js +14 -0
- package/dist/steps/ComposableScreen/types.js.map +1 -1
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -1
- package/dist/userProperties/reserved.d.ts +8 -5
- package/dist/userProperties/reserved.d.ts.map +1 -1
- package/dist/userProperties/reserved.js +9 -4
- package/dist/userProperties/reserved.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudio.ts +19 -1
- package/src/OnboardingStudioClient.ts +84 -31
- package/src/__tests__/assignmentId.clear.test.ts +413 -0
- package/src/__tests__/assignmentId.client.test.ts +288 -0
- package/src/__tests__/assignmentId.test.ts +195 -0
- package/src/__tests__/onboardingMetadata.client.test.ts +76 -0
- package/src/assignmentId.ts +278 -0
- package/src/index.ts +9 -0
- package/src/paywalls/PaywallProvider.tsx +13 -0
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +51 -0
- package/src/paywalls/__tests__/devHook.test.ts +70 -0
- package/src/paywalls/__tests__/getPaywalls.test.ts +77 -2
- package/src/paywalls/__tests__/observer.test.ts +37 -0
- package/src/paywalls/__tests__/present.test.ts +14 -0
- package/src/paywalls/customScreens.ts +7 -0
- package/src/paywalls/devHook.ts +48 -0
- package/src/paywalls/observer.ts +22 -2
- package/src/paywalls/types.ts +22 -0
- package/src/products/adapters/__tests__/expoIap.contract.test.ts +305 -0
- package/src/products/adapters/expoIap.ts +171 -32
- package/src/steps/ComposableScreen/types.ts +21 -0
- package/src/types.ts +48 -0
- package/src/userProperties/__tests__/primitives.test.ts +1 -1
- package/src/userProperties/reserved.ts +9 -4
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -185,10 +185,12 @@ lexicographic, so `"10"` is *not* greater than `"9"`:
|
|
|
185
185
|
|
|
186
186
|
These are refused with a warning, because the SDK puts them on the request
|
|
187
187
|
querystring itself: its own value is sent instead of yours, or, for
|
|
188
|
-
`appVersion` and `
|
|
188
|
+
`appVersion`, `build` and `assignmentId` when it has none, nothing is:
|
|
189
189
|
|
|
190
190
|
`projectId`, `platform`, `appVersion`, `build`, `sdkVersion`, `environment`,
|
|
191
|
-
`draft`, `locale`, `omitNulls`, `moment`, `now`
|
|
191
|
+
`assignmentId`, `draft`, `locale`, `omitNulls`, `moment`, `now`
|
|
192
|
+
|
|
193
|
+
`appleReview` is refused too: the server sets it on every request and overwrites any value sent.
|
|
192
194
|
|
|
193
195
|
### What every request carries
|
|
194
196
|
|
|
@@ -202,9 +204,26 @@ Each onboarding and paywall request sends, besides your audience params:
|
|
|
202
204
|
- `environment`: the `environment` option, else `"sandbox"` in sandbox mode,
|
|
203
205
|
`"development"` under `__DEV__`, `"production"` otherwise. Lower-cased,
|
|
204
206
|
reduced to `a-z`, `0-9`, `_` and `-`, at most 32 characters.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
- `assignmentId`: a stable per-person id, so the server can keep a person in
|
|
208
|
+
the same variant across launches. Sent as the `X-Assignment-Id` request
|
|
209
|
+
header, never on the querystring: it may be one of your user ids, and request
|
|
210
|
+
URLs end up in server logs. The `assignmentId` option if you pass one
|
|
211
|
+
(a string, or a getter called on every request, e.g.
|
|
212
|
+
`() => Purchases.getAppUserID()`), else an installation id generated once and
|
|
213
|
+
persisted in AsyncStorage, else not sent. `false` (or a getter returning
|
|
214
|
+
`false`) sends nothing and never reads or writes the stored id: use it until
|
|
215
|
+
the user consents. A getter that throws, rejects or takes over 2s fails
|
|
216
|
+
closed the same way (nothing sent, stored id untouched); only `undefined`,
|
|
217
|
+
`null` or `""` fall back to the installation id. To delete the stored id
|
|
218
|
+
(e.g. consent withdrawn), call `OnboardingStudio.clearAssignmentId()` after
|
|
219
|
+
making the getter return `false`. With RevenueCat, call
|
|
220
|
+
`Purchases.configure()` before the providers mount. Changing the id (anonymous to logged in) can move a person
|
|
221
|
+
to another variant once. See the API reference's "Sticky variant assignment",
|
|
222
|
+
which also covers what to declare in privacy disclosures.
|
|
223
|
+
|
|
224
|
+
All but `assignmentId` are ordinary query params, so an audience rule can
|
|
225
|
+
target them, for example `environment == "staging"` or a build range.
|
|
226
|
+
`assignmentId` is a header, not an audience param: no rule can read it.
|
|
208
227
|
|
|
209
228
|
### Relationship to `customAudienceParams`
|
|
210
229
|
|
|
@@ -212,7 +231,8 @@ The prop still works and is not deprecated. Treat it as the **static** baseline
|
|
|
212
231
|
(build-time facts like an `onboardingId`) and the store as the **runtime** half.
|
|
213
232
|
Where both define a key, **the store wins**.
|
|
214
233
|
|
|
215
|
-
Neither can set `appVersion`, `build`, `sdkVersion
|
|
234
|
+
Neither can set `appVersion`, `build`, `sdkVersion`, `environment` or
|
|
235
|
+
`assignmentId`: since the
|
|
216
236
|
SDK sends them itself, a value under one of those names in either source is
|
|
217
237
|
dropped (see [Reserved names](#reserved-names)), and an audience rule on them
|
|
218
238
|
sees the SDK's value.
|
|
@@ -362,10 +382,18 @@ export default function OnboardingScreen() {
|
|
|
362
382
|
- **Loader** - Sequential progress animation with optional carousel
|
|
363
383
|
- **Ratings** - App store rating prompts with social proof
|
|
364
384
|
- **Commitment** - User commitment and agreement screens
|
|
365
|
-
- **
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
385
|
+
- **Paywall** - A paywall rendered in flow position, chosen by a moment's
|
|
386
|
+
audience waterfall
|
|
387
|
+
- **ComposableScreen** _(deprecated)_ - Declarative layout system driven
|
|
388
|
+
entirely from the CMS, built from a tree of UIElements.
|
|
389
|
+
|
|
390
|
+
> **`ComposableScreen` is deprecated as a step type** (#353). Existing
|
|
391
|
+
> ComposableScreen steps keep parsing and rendering unchanged, and the step
|
|
392
|
+
> type will be removed in a future major version. Author new steps with one of
|
|
393
|
+
> the built-in step types above. The `ComposableScreenStepTypeSchema`,
|
|
394
|
+
> `ComposableScreenStepType` and `ComposableScreenStepPayloadSchema` exports
|
|
395
|
+
> are marked `@deprecated`. The UIElement types and schemas are **not**
|
|
396
|
+
> deprecated: paywalls are built from them.
|
|
369
397
|
|
|
370
398
|
[Learn more about page types →](./docs/page-types.mdx)
|
|
371
399
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OnboardingStudioClient } from "./OnboardingStudioClient";
|
|
2
2
|
import type { OnboardingStudioClientOptions } from "./types";
|
|
3
|
+
import { type InstallationIdStore } from "./assignmentId";
|
|
3
4
|
import type { UserPropertyStore } from "./userProperties/store";
|
|
4
5
|
import type { UserProperties, UserPropertyPatch, UserPropertyValue } from "./userProperties/types";
|
|
5
6
|
/**
|
|
@@ -48,6 +49,18 @@ export type OnboardingStudioFacade = {
|
|
|
48
49
|
* not changed — `getClient()?.clearCache()` is right there if both are wanted.
|
|
49
50
|
*/
|
|
50
51
|
reset: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Deletes the stored installation id sent as `assignmentId`
|
|
54
|
+
* (`rocapine-assignment-id`) and forgets it in memory; a request already
|
|
55
|
+
* resolving it sends none. Works before `init`. The next request without a
|
|
56
|
+
* host id mints a NEW id, so on consent withdrawal also make the
|
|
57
|
+
* `assignmentId` option return `false`. Rejects if the removal fails or is
|
|
58
|
+
* still waiting after 2s.
|
|
59
|
+
*
|
|
60
|
+
* Separate from `reset()` on purpose: logging out must not move an install
|
|
61
|
+
* to another variant.
|
|
62
|
+
*/
|
|
63
|
+
clearAssignmentId: () => Promise<void>;
|
|
51
64
|
};
|
|
52
65
|
/**
|
|
53
66
|
* The SDK's front door, in the shape the SDKs it sits alongside use
|
|
@@ -62,7 +75,7 @@ export type OnboardingStudioFacade = {
|
|
|
62
75
|
* `usePaywall()`, where that state is reachable and where a call cannot be made
|
|
63
76
|
* before a provider exists.
|
|
64
77
|
*/
|
|
65
|
-
export declare const createOnboardingStudio: (store: UserPropertyStore) => OnboardingStudioFacade;
|
|
78
|
+
export declare const createOnboardingStudio: (store: UserPropertyStore, installation?: () => InstallationIdStore) => OnboardingStudioFacade;
|
|
66
79
|
/** The facade every host uses. */
|
|
67
80
|
export declare const OnboardingStudio: OnboardingStudioFacade;
|
|
68
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingStudio.d.ts","sourceRoot":"","sources":["../src/OnboardingStudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,6BAA6B,GAAG;IACzF,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;;;;OAQG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,sBAAsB,CAAC;IACjE,sDAAsD;IACtD,SAAS,EAAE,MAAM,sBAAsB,GAAG,IAAI,CAAC;IAC/C,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,2CAA2C;IAC3C,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IACxE,oEAAoE;IACpE,iBAAiB,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACtD,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,iBAAiB,EAAE,MAAM,cAAc,CAAC;IACxC;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"OnboardingStudio.d.ts","sourceR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GACjC,OAAO,iBAAiB,EAExB,eAAc,MAAM,mBAA4C,KAC/D,sBAgDF,CAAC;AAEF,kCAAkC;AAClC,eAAO,MAAM,gBAAgB,wBAA4C,CAAC;AAE1E;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,MAAM,sBAAsB,GAAG,SAAS,EACxC,YAAY,sBAAsB,GAAG,IAAI,KACxC,sBAAsB,GAAG,IAA0B,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAGkB,CAAC"}
|
package/dist/OnboardingStudio.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.MISSING_CLIENT_MESSAGE = exports.resolveProviderClient = exports.OnboardingStudio = exports.createOnboardingStudio = void 0;
|
|
15
15
|
const OnboardingStudioClient_1 = require("./OnboardingStudioClient");
|
|
16
16
|
const store_1 = require("./userProperties/store");
|
|
17
|
+
const assignmentId_1 = require("./assignmentId");
|
|
17
18
|
/** Stable signature of a config, for the idempotency check in `init`. */
|
|
18
19
|
const configSignature = (projectId, options) => `${projectId}::${JSON.stringify(options)}`;
|
|
19
20
|
/**
|
|
@@ -29,7 +30,9 @@ const configSignature = (projectId, options) => `${projectId}::${JSON.stringify(
|
|
|
29
30
|
* `usePaywall()`, where that state is reachable and where a call cannot be made
|
|
30
31
|
* before a provider exists.
|
|
31
32
|
*/
|
|
32
|
-
const createOnboardingStudio = (store
|
|
33
|
+
const createOnboardingStudio = (store,
|
|
34
|
+
// A getter, not the store: tests swap the process-wide store between cases.
|
|
35
|
+
installation = assignmentId_1.getInstallationIdStore) => {
|
|
33
36
|
let client = null;
|
|
34
37
|
let signature = null;
|
|
35
38
|
return {
|
|
@@ -66,6 +69,7 @@ const createOnboardingStudio = (store) => {
|
|
|
66
69
|
removeUserProperty: (key) => store.remove(key),
|
|
67
70
|
getUserProperties: () => store.get(),
|
|
68
71
|
reset: () => store.reset(),
|
|
72
|
+
clearAssignmentId: () => installation().clear(),
|
|
69
73
|
};
|
|
70
74
|
};
|
|
71
75
|
exports.createOnboardingStudio = createOnboardingStudio;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingStudio.js","sourceRoot":"","sources":["../src/OnboardingStudio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qEAAkE;AAElE,kDAA2D;
|
|
1
|
+
{"version":3,"file":"OnboardingStudio.js","sourceRoot":"","sources":["../src/OnboardingStudio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qEAAkE;AAElE,kDAA2D;AAC3D,iDAAkF;AAmElF,yEAAyE;AACzE,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,OAAgC,EAAU,EAAE,CACtF,GAAG,SAAS,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACI,MAAM,sBAAsB,GAAG,CACpC,KAAwB;AACxB,4EAA4E;AAC5E,eAA0C,qCAAsB,EACxC,EAAE;IAC1B,IAAI,MAAM,GAAkC,IAAI,CAAC;IACjD,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,OAAO;QACL,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACf,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,KAAiB,MAAM,EAAlB,OAAO,UAAK,MAAM,EAArE,+BAA4D,CAAS,CAAC;YAC5E,MAAM,IAAI,GAAG,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAEjD,IAAI,MAAM,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACjC,sEAAsE;gBACtE,sEAAsE;gBACtE,qEAAqE;gBACrE,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CACV,sEAAsE;oBACpE,eAAe,SAAS,6CAA6C;oBACrE,oEAAoE;oBACpE,gDAAgD,CACnD,CAAC;Y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vD;;;;GAIG;AACU,QAAA,sBAAsB,GACjC,kFAAkF;IAClF,2DAA2D;IAC3D,mDAAmD,CAAC"}
|
|
@@ -6,6 +6,8 @@ export declare class OnboardingStudioClient {
|
|
|
6
6
|
projectId: string;
|
|
7
7
|
options: OnboardingStudioClientOptions;
|
|
8
8
|
private identity?;
|
|
9
|
+
/** Edge functions base URL this client talks to. Read-only; devtools use it. */
|
|
10
|
+
get functionsBaseUrl(): string;
|
|
9
11
|
/**
|
|
10
12
|
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
11
13
|
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
@@ -21,8 +23,37 @@ export declare class OnboardingStudioClient {
|
|
|
21
23
|
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
22
24
|
* would then leave a same-named user param on the wire (a property persisted
|
|
23
25
|
* before these names were reserved is re-read without a reserved-key check).
|
|
26
|
+
*
|
|
27
|
+
* Returns the request headers: the `assignmentId` travels as the
|
|
28
|
+
* `X-Assignment-Id` header, never on the querystring, because edge invocation
|
|
29
|
+
* logs record the full URL and the id may be a host's user id.
|
|
24
30
|
*/
|
|
25
31
|
private writeIdentity;
|
|
32
|
+
/**
|
|
33
|
+
* The `assignmentId` the next request will carry: the host's `assignmentId`
|
|
34
|
+
* option, else the persisted installation id, else `undefined` (sent as
|
|
35
|
+
* absent). Resolved per request, never memoized here, because a host getter
|
|
36
|
+
* may change value on login. Never throws. See `assignmentId.ts`.
|
|
37
|
+
*/
|
|
38
|
+
getAssignmentId(): Promise<string | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes the stored installation id (`rocapine-assignment-id`) and forgets
|
|
41
|
+
* the in-memory one; a request already resolving it sends none. The next
|
|
42
|
+
* request without a host id mints a NEW id — to stop sending one at all (e.g.
|
|
43
|
+
* consent withdrawn), also make the `assignmentId` option return `false`.
|
|
44
|
+
* Process-wide, like the id: same effect as `OnboardingStudio.clearAssignmentId()`.
|
|
45
|
+
* Rejects if the removal fails or is still waiting after 2s.
|
|
46
|
+
*/
|
|
47
|
+
clearAssignmentId(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Races `work` against `options.timeout`, rejecting with `Error("timeout")`.
|
|
50
|
+
* `work` covers identity resolution AND the fetch, so `timeout` is one
|
|
51
|
+
* end-to-end budget: a slow `assignmentId` getter cannot push
|
|
52
|
+
* `fallbackOnboarding` (or the rejection) past it. `work` gets an `expired()`
|
|
53
|
+
* check so a request whose budget ran out while the id resolved is never
|
|
54
|
+
* sent afterwards (the server would count a serve nobody receives).
|
|
55
|
+
*/
|
|
56
|
+
private withTimeout;
|
|
26
57
|
constructor(projectId: string, options: OnboardingStudioClientOptions);
|
|
27
58
|
/**
|
|
28
59
|
* Removes EVERY cached onboarding payload and paywall catalog this SDK wrote,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingStudioClient.d.ts","sourceRoot":"","sources":["../src/OnboardingStudioClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,EACb,MAAM,SAAS,CAAC;AAKjB,OAAO,EACL,cAAc,EACd,cAAc,EACd,0BAA0B,EAC3B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"OnboardingStudioClient.d.ts","sourceRoot":"","sources":["../src/OnboardingStudioClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,EACb,MAAM,SAAS,CAAC;AAKjB,OAAO,EACL,cAAc,EACd,cAAc,EACd,0BAA0B,EAC3B,MAAM,kBAAkB,CAAC;AAS1B,qBAAa,sBAAsB;IACjC,OAAO,CAAC,OAAO,CAAS;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,6BAA6B,CAAC;IAC9C,OAAO,CAAC,QAAQ,CAAC,CAAyB;IAE1C,gFAAgF;IAChF,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAED;;;;;;;OAOG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOxC;;;;;;;;;;OAUG;YACW,aAAa;IAY3B;;;;;OAKG;IACH,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI9C;;;;;;;OAOG;IACH,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;gBAgBP,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,6BAA6B;IASrE;;;;;;;;;;;;;;;;OAgBG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B,QAAQ,CAAC,QAAQ,SAAS,YAAY,GAAG,kBAAkB,EAC/D,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,iBAAiB,CAAC,EAAE,iBAAiB,GACpC,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;QAAC,OAAO,EAAE,uBAAuB,CAAA;KAAE,CAAC;IAsE5E;;;;;;;;;;;OAWG;IACG,WAAW,CACf,cAAc,CAAC,EAAE,cAAc,EAC/B,iBAAiB,CAAC,EAAE,iBAAiB,GACpC,OAAO,CAAC;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,0BAA0B,CAAA;KAAE,CAAC;CAmE1E"}
|
|
@@ -8,7 +8,14 @@ const async_storage_1 = __importDefault(require("@react-native-async-storage/asy
|
|
|
8
8
|
const cacheKey_1 = require("./infra/queries/cacheKey");
|
|
9
9
|
const react_native_1 = require("react-native");
|
|
10
10
|
const requestIdentity_1 = require("./requestIdentity");
|
|
11
|
+
const assignmentId_1 = require("./assignmentId");
|
|
12
|
+
/** Request header carrying the `assignmentId`; the server reads it case-insensitively. */
|
|
13
|
+
const ASSIGNMENT_ID_HEADER = "X-Assignment-Id";
|
|
11
14
|
class OnboardingStudioClient {
|
|
15
|
+
/** Edge functions base URL this client talks to. Read-only; devtools use it. */
|
|
16
|
+
get functionsBaseUrl() {
|
|
17
|
+
return this.baseUrl;
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
14
21
|
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
@@ -29,13 +36,65 @@ class OnboardingStudioClient {
|
|
|
29
36
|
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
30
37
|
* would then leave a same-named user param on the wire (a property persisted
|
|
31
38
|
* before these names were reserved is re-read without a reserved-key check).
|
|
39
|
+
*
|
|
40
|
+
* Returns the request headers: the `assignmentId` travels as the
|
|
41
|
+
* `X-Assignment-Id` header, never on the querystring, because edge invocation
|
|
42
|
+
* logs record the full URL and the id may be a host's user id.
|
|
32
43
|
*/
|
|
33
|
-
writeIdentity(urlParams) {
|
|
44
|
+
async writeIdentity(urlParams) {
|
|
34
45
|
urlParams.delete("appVersion");
|
|
35
46
|
urlParams.delete("build");
|
|
36
47
|
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
37
48
|
urlParams.set(key, value);
|
|
38
49
|
}
|
|
50
|
+
// A user param of that name never reaches the URL, whatever the id resolves to.
|
|
51
|
+
urlParams.delete("assignmentId");
|
|
52
|
+
const assignmentId = await this.getAssignmentId();
|
|
53
|
+
return assignmentId ? { [ASSIGNMENT_ID_HEADER]: assignmentId } : {};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The `assignmentId` the next request will carry: the host's `assignmentId`
|
|
57
|
+
* option, else the persisted installation id, else `undefined` (sent as
|
|
58
|
+
* absent). Resolved per request, never memoized here, because a host getter
|
|
59
|
+
* may change value on login. Never throws. See `assignmentId.ts`.
|
|
60
|
+
*/
|
|
61
|
+
getAssignmentId() {
|
|
62
|
+
return (0, assignmentId_1.resolveAssignmentId)(this.options.assignmentId, (0, assignmentId_1.getInstallationIdStore)());
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Deletes the stored installation id (`rocapine-assignment-id`) and forgets
|
|
66
|
+
* the in-memory one; a request already resolving it sends none. The next
|
|
67
|
+
* request without a host id mints a NEW id — to stop sending one at all (e.g.
|
|
68
|
+
* consent withdrawn), also make the `assignmentId` option return `false`.
|
|
69
|
+
* Process-wide, like the id: same effect as `OnboardingStudio.clearAssignmentId()`.
|
|
70
|
+
* Rejects if the removal fails or is still waiting after 2s.
|
|
71
|
+
*/
|
|
72
|
+
clearAssignmentId() {
|
|
73
|
+
return (0, assignmentId_1.getInstallationIdStore)().clear();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Races `work` against `options.timeout`, rejecting with `Error("timeout")`.
|
|
77
|
+
* `work` covers identity resolution AND the fetch, so `timeout` is one
|
|
78
|
+
* end-to-end budget: a slow `assignmentId` getter cannot push
|
|
79
|
+
* `fallbackOnboarding` (or the rejection) past it. `work` gets an `expired()`
|
|
80
|
+
* check so a request whose budget ran out while the id resolved is never
|
|
81
|
+
* sent afterwards (the server would count a serve nobody receives).
|
|
82
|
+
*/
|
|
83
|
+
withTimeout(work) {
|
|
84
|
+
const ms = this.options.timeout;
|
|
85
|
+
if (!ms)
|
|
86
|
+
return work(() => false);
|
|
87
|
+
let timer;
|
|
88
|
+
let timedOut = false;
|
|
89
|
+
return Promise.race([
|
|
90
|
+
work(() => timedOut),
|
|
91
|
+
new Promise((_, reject) => {
|
|
92
|
+
timer = setTimeout(() => {
|
|
93
|
+
timedOut = true;
|
|
94
|
+
reject(new Error("timeout"));
|
|
95
|
+
}, ms);
|
|
96
|
+
}),
|
|
97
|
+
]).finally(() => clearTimeout(timer));
|
|
39
98
|
}
|
|
40
99
|
constructor(projectId, options) {
|
|
41
100
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
@@ -89,7 +148,6 @@ class OnboardingStudioClient {
|
|
|
89
148
|
// value would lose to a same-named user param added above.
|
|
90
149
|
urlParams.set("projectId", this.projectId);
|
|
91
150
|
urlParams.set("platform", react_native_1.Platform.OS);
|
|
92
|
-
this.writeIdentity(urlParams);
|
|
93
151
|
if (isSandbox) {
|
|
94
152
|
urlParams.set("draft", "true");
|
|
95
153
|
}
|
|
@@ -97,15 +155,17 @@ class OnboardingStudioClient {
|
|
|
97
155
|
if (onboardingOptions === null || onboardingOptions === void 0 ? void 0 : onboardingOptions.locale) {
|
|
98
156
|
urlParams.set("locale", onboardingOptions.locale);
|
|
99
157
|
}
|
|
100
|
-
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
101
|
-
console.info("OnboardingStudioClient getSteps url", url);
|
|
102
158
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
159
|
+
// Identity (incl. the host's assignmentId getter) resolves inside the
|
|
160
|
+
// same timeout budget as the fetch — see `withTimeout`.
|
|
161
|
+
const response = await this.withTimeout(async (expired) => {
|
|
162
|
+
const headers = await this.writeIdentity(urlParams);
|
|
163
|
+
if (expired())
|
|
164
|
+
throw new Error("timeout");
|
|
165
|
+
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
166
|
+
console.info("OnboardingStudioClient getSteps url", url);
|
|
167
|
+
return fetch(url, { headers });
|
|
168
|
+
});
|
|
109
169
|
if (!response.ok) {
|
|
110
170
|
throw new Error(`Failed to fetch onboarding steps: ${response.status} ${response.statusText}`);
|
|
111
171
|
}
|
|
@@ -160,7 +220,6 @@ class OnboardingStudioClient {
|
|
|
160
220
|
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
161
221
|
urlParams.set("projectId", this.projectId);
|
|
162
222
|
urlParams.set("platform", react_native_1.Platform.OS);
|
|
163
|
-
this.writeIdentity(urlParams);
|
|
164
223
|
if (isSandbox) {
|
|
165
224
|
urlParams.set("draft", "true");
|
|
166
225
|
}
|
|
@@ -179,15 +238,17 @@ class OnboardingStudioClient {
|
|
|
179
238
|
// and `Paywall`'s declared `| null` fields. This client parses into those
|
|
180
239
|
// typed objects, so the fields must always be present (possibly `null`),
|
|
181
240
|
// not sometimes missing.
|
|
182
|
-
const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
|
|
183
|
-
console.info("OnboardingStudioClient getPaywalls url", url);
|
|
184
241
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
242
|
+
// Identity (incl. the host's assignmentId getter) resolves inside the
|
|
243
|
+
// same timeout budget as the fetch — see `withTimeout`.
|
|
244
|
+
const response = await this.withTimeout(async (expired) => {
|
|
245
|
+
const headers = await this.writeIdentity(urlParams);
|
|
246
|
+
if (expired())
|
|
247
|
+
throw new Error("timeout");
|
|
248
|
+
const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
|
|
249
|
+
console.info("OnboardingStudioClient getPaywalls url", url);
|
|
250
|
+
return fetch(url, { headers });
|
|
251
|
+
});
|
|
191
252
|
if (!response.ok) {
|
|
192
253
|
throw new Error(`Failed to fetch paywalls: ${response.status} ${response.statusText}`);
|
|
193
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingStudioClient.js","sourceRoot":"","sources":["../src/OnboardingStudioClient.ts"],"names":[],"mappings":";;;;;;AAAA,8FAAqE;AAUrE,uDAGkC;AAOlC,+CAAwC;AACxC,uDAA8E;
|
|
1
|
+
{"version":3,"file":"OnboardingStudioClient.js","sourceRoot":"","sources":["../src/OnboardingStudioClient.ts"],"names":[],"mappings":";;;;;;AAAA,8FAAqE;AAUrE,uDAGkC;AAOlC,+CAAwC;AACxC,uDAA8E;AAC9E,iDAA6E;AAE7E,0FAA0F;AAC1F,MAAM,oBAAoB,GAAG,iBAAiB,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C;IACH,CAAC;CACF;AAlSD,wDAkSC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `assignmentId`: the stable per-person value every `getSteps` / `getPaywalls`
|
|
3
|
+
* request carries, so the server can put the same person in the same variant
|
|
4
|
+
* every time (it hashes this value with the id of the group being split).
|
|
5
|
+
* The SDK's only job is to send the same value every time for the same person.
|
|
6
|
+
*
|
|
7
|
+
* Resolution, per request:
|
|
8
|
+
* 1. the host's `assignmentId` option (a string, or a getter called on every
|
|
9
|
+
* request — e.g. `() => Purchases.getAppUserID()`),
|
|
10
|
+
* 2. else an installation id, generated once and persisted under
|
|
11
|
+
* `ASSIGNMENT_ID_STORAGE_KEY`,
|
|
12
|
+
* 3. else nothing: the `X-Assignment-Id` header is not sent rather than
|
|
13
|
+
* carrying an invented id, so the server can tell "no stable id" from "a
|
|
14
|
+
* fresh id it will never see again".
|
|
15
|
+
*
|
|
16
|
+
* `false` (as the option, or returned by the getter) OPTS OUT: nothing is sent
|
|
17
|
+
* and the installation id is never read, created or written — e.g. until the
|
|
18
|
+
* user consents. `null` / `""` are not an opt-out; they fall through to 2.
|
|
19
|
+
*
|
|
20
|
+
* A host value of `undefined`, `null` or `""` falls through to the installation
|
|
21
|
+
* id. A getter that throws, rejects, or does not settle within
|
|
22
|
+
* `HOST_ASSIGNMENT_ID_TIMEOUT_MS` FAILS CLOSED: the id is omitted for that
|
|
23
|
+
* request and the installation id is not read, created or written. A getter
|
|
24
|
+
* that cannot answer may be one that would have answered `false` (no consent
|
|
25
|
+
* yet), so it must never be overridden by the stored id.
|
|
26
|
+
*/
|
|
27
|
+
/** `false` opts out; `null` / `undefined` / `""` mean "no host value". */
|
|
28
|
+
export type AssignmentIdValue = string | false | null | undefined;
|
|
29
|
+
/** The `OnboardingStudioClientOptions.assignmentId` option. */
|
|
30
|
+
export type AssignmentIdOption = AssignmentIdValue | (() => AssignmentIdValue | Promise<AssignmentIdValue>);
|
|
31
|
+
/**
|
|
32
|
+
* Deliberately NOT under the `rocapine-onboarding` / `rocapine-paywalls`
|
|
33
|
+
* prefixes `OnboardingStudioClient.clearCache` scans, and not the user
|
|
34
|
+
* property key `OnboardingStudio.reset()` removes: clearing a payload cache or
|
|
35
|
+
* logging out must not move the install to another variant.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ASSIGNMENT_ID_STORAGE_KEY = "rocapine-assignment-id";
|
|
38
|
+
/** How long a host getter may take before the installation id is used instead. */
|
|
39
|
+
export declare const HOST_ASSIGNMENT_ID_TIMEOUT_MS = 2000;
|
|
40
|
+
export type AssignmentIdStorage = {
|
|
41
|
+
getItem: (key: string) => Promise<string | null>;
|
|
42
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
43
|
+
removeItem: (key: string) => Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Bound on how long a CALLER waits for each queued operation. The queue itself
|
|
47
|
+
* still waits for the real storage call, so ordering holds even when it hangs.
|
|
48
|
+
*/
|
|
49
|
+
export declare const STORAGE_OP_TIMEOUT_MS = 2000;
|
|
50
|
+
export type InstallationIdStore = {
|
|
51
|
+
/**
|
|
52
|
+
* The current clear() generation. Take it BEFORE any await that precedes
|
|
53
|
+
* `get(token)` (e.g. a host getter), so a `clear()` in between is seen.
|
|
54
|
+
*/
|
|
55
|
+
token: () => number;
|
|
56
|
+
/**
|
|
57
|
+
* The installation id, or `undefined`. With a `token` older than the last
|
|
58
|
+
* `clear()`, returns `undefined` without reading or writing storage.
|
|
59
|
+
*/
|
|
60
|
+
get: (token?: number) => Promise<string | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Removes the stored id and forgets the in-memory one, so a later request
|
|
63
|
+
* mints a new id. Rejects if the removal fails or the caller's wait for it
|
|
64
|
+
* exceeds `STORAGE_OP_TIMEOUT_MS` (the removal itself still runs, in order).
|
|
65
|
+
*/
|
|
66
|
+
clear: () => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* One in-flight resolution per store, so `getSteps` and `getPaywalls` fired
|
|
70
|
+
* together on a first launch share one generated id and write it once. A
|
|
71
|
+
* failure is not memoized: the next request retries.
|
|
72
|
+
*
|
|
73
|
+
* `clear()` must win against a load already in flight, or the id it removes
|
|
74
|
+
* comes back. Two mechanisms:
|
|
75
|
+
* - every storage operation runs on ONE queue, so a removal is ordered after
|
|
76
|
+
* any write already started, and a load started after `clear()` runs after
|
|
77
|
+
* the removal (and is therefore never deleted by it);
|
|
78
|
+
* - an `epoch` bumped by `clear()`: a load that began before it neither writes
|
|
79
|
+
* nor returns an id, so the request in flight sends nothing. Callers that
|
|
80
|
+
* await something first (`resolveAssignmentId` awaits the host getter) take
|
|
81
|
+
* the epoch as a `token()` up front and pass it to `get(token)`.
|
|
82
|
+
*
|
|
83
|
+
* The caller's wait on each queued operation is bounded by
|
|
84
|
+
* `STORAGE_OP_TIMEOUT_MS`, counted from when it was queued. On expiry the
|
|
85
|
+
* caller's promise rejects (`clear()` rejects; `get()` fails closed with
|
|
86
|
+
* `undefined`). A write or removal still holds the queue until the real call
|
|
87
|
+
* settles, so a removal can never overtake a write in flight; callers behind a
|
|
88
|
+
* hung write or removal fail closed at their own bound. A load abandoned BEFORE
|
|
89
|
+
* it issued `setItem` releases the queue at once, since it can no longer write:
|
|
90
|
+
* a hung read does not stall the rest of the process.
|
|
91
|
+
*
|
|
92
|
+
* A timed-out load is marked abandoned, and checks that right before minting
|
|
93
|
+
* and right before writing: a timed-out request never mints. (A write that had
|
|
94
|
+
* already started when the bound fired cannot be recalled; it lands, in order,
|
|
95
|
+
* ahead of any later removal.)
|
|
96
|
+
*/
|
|
97
|
+
export declare const createInstallationIdStore: (storage: AssignmentIdStorage, generate?: () => string) => InstallationIdStore;
|
|
98
|
+
/**
|
|
99
|
+
* Opt-out, throw or timeout → `undefined` (store untouched); host value →
|
|
100
|
+
* installation id → `undefined`. Never throws.
|
|
101
|
+
*/
|
|
102
|
+
export declare const resolveAssignmentId: (option: AssignmentIdOption, installation: Pick<InstallationIdStore, "get" | "token">) => Promise<string | undefined>;
|
|
103
|
+
/** The process-wide installation id store: shared by every client, like the disk it reads. */
|
|
104
|
+
export declare const getInstallationIdStore: () => InstallationIdStore;
|
|
105
|
+
/** Test-only: forget the in-memory id, as a new process would. */
|
|
106
|
+
export declare const __resetInstallationIdForTests: () => void;
|
|
107
|
+
//# sourceMappingURL=assignmentId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assignmentId.d.ts","sourceRoot":"","sources":["../src/assignmentId.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAElE,+DAA+D;AAC/D,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,2BAA2B,CAAC;AAElE,kFAAkF;AAClF,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C,CAAC;AAeF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,OAAgC,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;OAGG;IACH,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB;;;OAGG;IACH,GAAG,EAAE,CAAC,KA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