@rocapine/react-native-onboarding 1.76.0 → 1.78.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 +49 -5
- 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 +47 -0
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +117 -33
- 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 +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +7 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- 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/requestIdentity.d.ts +41 -0
- package/dist/requestIdentity.d.ts.map +1 -0
- package/dist/requestIdentity.js +70 -0
- package/dist/requestIdentity.js.map +1 -0
- package/dist/types.d.ts +64 -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 +17 -15
- package/dist/userProperties/reserved.d.ts.map +1 -1
- package/dist/userProperties/reserved.js +20 -14
- package/dist/userProperties/reserved.js.map +1 -1
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/package.json +5 -1
- package/src/OnboardingStudio.ts +19 -1
- package/src/OnboardingStudioClient.ts +123 -47
- 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__/getOnboarding.query.test.ts +30 -0
- package/src/__tests__/onboardingMetadata.client.test.ts +76 -0
- package/src/__tests__/requestIdentity.client.test.ts +115 -0
- package/src/__tests__/requestIdentity.test.ts +112 -0
- package/src/assignmentId.ts +278 -0
- package/src/index.ts +1 -0
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +51 -0
- package/src/paywalls/__tests__/getPaywalls.test.ts +107 -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/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/requestIdentity.ts +101 -0
- package/src/types.ts +65 -0
- package/src/userProperties/__tests__/effectiveParams.test.ts +2 -2
- package/src/userProperties/__tests__/primitives.test.ts +1 -1
- package/src/userProperties/reserved.ts +20 -14
- package/src/version.ts +9 -0
package/README.md
CHANGED
|
@@ -42,7 +42,6 @@ import {
|
|
|
42
42
|
// Once, at module scope — before anything renders.
|
|
43
43
|
OnboardingStudio.init({
|
|
44
44
|
projectId: "your-project-id",
|
|
45
|
-
appVersion: "1.0.0",
|
|
46
45
|
});
|
|
47
46
|
|
|
48
47
|
export default function RootLayout() {
|
|
@@ -185,10 +184,44 @@ lexicographic, so `"10"` is *not* greater than `"9"`:
|
|
|
185
184
|
### Reserved names
|
|
186
185
|
|
|
187
186
|
These are refused with a warning, because the SDK puts them on the request
|
|
188
|
-
querystring itself
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
`
|
|
187
|
+
querystring itself: its own value is sent instead of yours, or, for
|
|
188
|
+
`appVersion`, `build` and `assignmentId` when it has none, nothing is:
|
|
189
|
+
|
|
190
|
+
`projectId`, `platform`, `appVersion`, `build`, `sdkVersion`, `environment`,
|
|
191
|
+
`assignmentId`, `draft`, `locale`, `omitNulls`, `moment`, `now`
|
|
192
|
+
|
|
193
|
+
### What every request carries
|
|
194
|
+
|
|
195
|
+
Each onboarding and paywall request sends, besides your audience params:
|
|
196
|
+
|
|
197
|
+
- `appVersion` and `build`: the options of the same name if you pass them,
|
|
198
|
+
else read from `expo-application` when it is installed (an optional peer
|
|
199
|
+
dependency), else not sent. Do not hard-code them: a fixed value hides the
|
|
200
|
+
version your users actually run.
|
|
201
|
+
- `sdkVersion`: this package's version.
|
|
202
|
+
- `environment`: the `environment` option, else `"sandbox"` in sandbox mode,
|
|
203
|
+
`"development"` under `__DEV__`, `"production"` otherwise. Lower-cased,
|
|
204
|
+
reduced to `a-z`, `0-9`, `_` and `-`, at most 32 characters.
|
|
205
|
+
- `assignmentId`: a stable per-person id, so the server can keep a person in
|
|
206
|
+
the same variant across launches. Sent as the `X-Assignment-Id` request
|
|
207
|
+
header, never on the querystring: it may be one of your user ids, and request
|
|
208
|
+
URLs end up in server logs. The `assignmentId` option if you pass one
|
|
209
|
+
(a string, or a getter called on every request, e.g.
|
|
210
|
+
`() => Purchases.getAppUserID()`), else an installation id generated once and
|
|
211
|
+
persisted in AsyncStorage, else not sent. `false` (or a getter returning
|
|
212
|
+
`false`) sends nothing and never reads or writes the stored id: use it until
|
|
213
|
+
the user consents. A getter that throws, rejects or takes over 2s fails
|
|
214
|
+
closed the same way (nothing sent, stored id untouched); only `undefined`,
|
|
215
|
+
`null` or `""` fall back to the installation id. To delete the stored id
|
|
216
|
+
(e.g. consent withdrawn), call `OnboardingStudio.clearAssignmentId()` after
|
|
217
|
+
making the getter return `false`. With RevenueCat, call
|
|
218
|
+
`Purchases.configure()` before the providers mount. Changing the id (anonymous to logged in) can move a person
|
|
219
|
+
to another variant once. See the API reference's "Sticky variant assignment",
|
|
220
|
+
which also covers what to declare in privacy disclosures.
|
|
221
|
+
|
|
222
|
+
All but `assignmentId` are ordinary query params, so an audience rule can
|
|
223
|
+
target them, for example `environment == "staging"` or a build range.
|
|
224
|
+
`assignmentId` is a header, not an audience param: no rule can read it.
|
|
192
225
|
|
|
193
226
|
### Relationship to `customAudienceParams`
|
|
194
227
|
|
|
@@ -196,6 +229,12 @@ The prop still works and is not deprecated. Treat it as the **static** baseline
|
|
|
196
229
|
(build-time facts like an `onboardingId`) and the store as the **runtime** half.
|
|
197
230
|
Where both define a key, **the store wins**.
|
|
198
231
|
|
|
232
|
+
Neither can set `appVersion`, `build`, `sdkVersion`, `environment` or
|
|
233
|
+
`assignmentId`: since the
|
|
234
|
+
SDK sends them itself, a value under one of those names in either source is
|
|
235
|
+
dropped (see [Reserved names](#reserved-names)), and an audience rule on them
|
|
236
|
+
sees the SDK's value.
|
|
237
|
+
|
|
199
238
|
---
|
|
200
239
|
|
|
201
240
|
## 🔓 Gating a Feature with `register`
|
|
@@ -360,6 +399,11 @@ Install these only if you're using the specific screen types:
|
|
|
360
399
|
| **Ratings** | `expo-store-review` | `npx expo install expo-store-review` |
|
|
361
400
|
| **Commitment** (signature) | `@shopify/react-native-skia` | `npx expo install @shopify/react-native-skia` |
|
|
362
401
|
|
|
402
|
+
`expo-application` (`npx expo install expo-application`) is optional too, and not
|
|
403
|
+
tied to a screen type: with it installed, the SDK reports your app's version and
|
|
404
|
+
build on every request without you passing them (see
|
|
405
|
+
[What every request carries](#what-every-request-carries)).
|
|
406
|
+
|
|
363
407
|
---
|
|
364
408
|
|
|
365
409
|
## 💡 Example Project
|
|
@@ -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,O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0B,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":"O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,CAAC,cAAc,EAAE,CAAC;YAE5B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,aAAa,EAAE,GAAG,EAAE,CAAC,MAAM,KAAK,IAAI;QAEpC,eAAe,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;QAC5D,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAC9C,kBAAkB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAC9C,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;QACpC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE;QAC1B,iBAAiB,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE;KAChD,CAAC;AACJ,CAAC,CAAC;AApDW,QAAA,sBAAsB,0BAoDjC;AAEF,kCAAkC;AACrB,QAAA,gBAAgB,GAAG,IAAA,8BAAsB,EAAC,yBAAiB,CAAC,CAAC;AAE1E;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,CACnC,IAAwC,EACxC,UAAyC,EACV,EAAE,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,UAAU,CAAC;AAH1C,QAAA,qBAAqB,yBAGqB;AAEvD;;;;GAIG;AACU,QAAA,sBAAsB,GACjC,kFAAkF;IAClF,2DAA2D;IAC3D,mDAAmD,CAAC"}
|
|
@@ -5,6 +5,53 @@ export declare class OnboardingStudioClient {
|
|
|
5
5
|
private baseUrl;
|
|
6
6
|
projectId: string;
|
|
7
7
|
options: OnboardingStudioClientOptions;
|
|
8
|
+
private identity?;
|
|
9
|
+
/**
|
|
10
|
+
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
11
|
+
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
12
|
+
* can change while the process runs. Deliberately NOT part of any cache key:
|
|
13
|
+
* a key that changed with every app update would leave a user who is offline
|
|
14
|
+
* right after updating with no cached payload, and would stop a custom
|
|
15
|
+
* `cacheKey` from pinning content across updates.
|
|
16
|
+
*/
|
|
17
|
+
identityParams(): Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Writes the identity onto a querystring that already holds the user params.
|
|
20
|
+
* `appVersion` and `build` are removed first, because the identity omits them
|
|
21
|
+
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
22
|
+
* would then leave a same-named user param on the wire (a property persisted
|
|
23
|
+
* before these names were reserved is re-read without a reserved-key check).
|
|
24
|
+
*
|
|
25
|
+
* Returns the request headers: the `assignmentId` travels as the
|
|
26
|
+
* `X-Assignment-Id` header, never on the querystring, because edge invocation
|
|
27
|
+
* logs record the full URL and the id may be a host's user id.
|
|
28
|
+
*/
|
|
29
|
+
private writeIdentity;
|
|
30
|
+
/**
|
|
31
|
+
* The `assignmentId` the next request will carry: the host's `assignmentId`
|
|
32
|
+
* option, else the persisted installation id, else `undefined` (sent as
|
|
33
|
+
* absent). Resolved per request, never memoized here, because a host getter
|
|
34
|
+
* may change value on login. Never throws. See `assignmentId.ts`.
|
|
35
|
+
*/
|
|
36
|
+
getAssignmentId(): Promise<string | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Deletes the stored installation id (`rocapine-assignment-id`) and forgets
|
|
39
|
+
* the in-memory one; a request already resolving it sends none. The next
|
|
40
|
+
* request without a host id mints a NEW id — to stop sending one at all (e.g.
|
|
41
|
+
* consent withdrawn), also make the `assignmentId` option return `false`.
|
|
42
|
+
* Process-wide, like the id: same effect as `OnboardingStudio.clearAssignmentId()`.
|
|
43
|
+
* Rejects if the removal fails or is still waiting after 2s.
|
|
44
|
+
*/
|
|
45
|
+
clearAssignmentId(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Races `work` against `options.timeout`, rejecting with `Error("timeout")`.
|
|
48
|
+
* `work` covers identity resolution AND the fetch, so `timeout` is one
|
|
49
|
+
* end-to-end budget: a slow `assignmentId` getter cannot push
|
|
50
|
+
* `fallbackOnboarding` (or the rejection) past it. `work` gets an `expired()`
|
|
51
|
+
* check so a request whose budget ran out while the id resolved is never
|
|
52
|
+
* sent afterwards (the server would count a serve nobody receives).
|
|
53
|
+
*/
|
|
54
|
+
private withTimeout;
|
|
8
55
|
constructor(projectId: string, options: OnboardingStudioClientOptions);
|
|
9
56
|
/**
|
|
10
57
|
* 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;;;;;;;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"}
|
|
@@ -7,7 +7,91 @@ exports.OnboardingStudioClient = void 0;
|
|
|
7
7
|
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
8
8
|
const cacheKey_1 = require("./infra/queries/cacheKey");
|
|
9
9
|
const react_native_1 = require("react-native");
|
|
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";
|
|
10
14
|
class OnboardingStudioClient {
|
|
15
|
+
/**
|
|
16
|
+
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
17
|
+
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
18
|
+
* can change while the process runs. Deliberately NOT part of any cache key:
|
|
19
|
+
* a key that changed with every app update would leave a user who is offline
|
|
20
|
+
* right after updating with no cached payload, and would stop a custom
|
|
21
|
+
* `cacheKey` from pinning content across updates.
|
|
22
|
+
*/
|
|
23
|
+
identityParams() {
|
|
24
|
+
if (!this.identity) {
|
|
25
|
+
this.identity = (0, requestIdentity_1.resolveRequestIdentity)(this.options, (0, requestIdentity_1.readNativeAppInfo)());
|
|
26
|
+
}
|
|
27
|
+
return this.identity;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Writes the identity onto a querystring that already holds the user params.
|
|
31
|
+
* `appVersion` and `build` are removed first, because the identity omits them
|
|
32
|
+
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
33
|
+
* would then leave a same-named user param on the wire (a property persisted
|
|
34
|
+
* before these names were reserved is re-read without a reserved-key check).
|
|
35
|
+
*
|
|
36
|
+
* Returns the request headers: the `assignmentId` travels as the
|
|
37
|
+
* `X-Assignment-Id` header, never on the querystring, because edge invocation
|
|
38
|
+
* logs record the full URL and the id may be a host's user id.
|
|
39
|
+
*/
|
|
40
|
+
async writeIdentity(urlParams) {
|
|
41
|
+
urlParams.delete("appVersion");
|
|
42
|
+
urlParams.delete("build");
|
|
43
|
+
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
44
|
+
urlParams.set(key, value);
|
|
45
|
+
}
|
|
46
|
+
// A user param of that name never reaches the URL, whatever the id resolves to.
|
|
47
|
+
urlParams.delete("assignmentId");
|
|
48
|
+
const assignmentId = await this.getAssignmentId();
|
|
49
|
+
return assignmentId ? { [ASSIGNMENT_ID_HEADER]: assignmentId } : {};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The `assignmentId` the next request will carry: the host's `assignmentId`
|
|
53
|
+
* option, else the persisted installation id, else `undefined` (sent as
|
|
54
|
+
* absent). Resolved per request, never memoized here, because a host getter
|
|
55
|
+
* may change value on login. Never throws. See `assignmentId.ts`.
|
|
56
|
+
*/
|
|
57
|
+
getAssignmentId() {
|
|
58
|
+
return (0, assignmentId_1.resolveAssignmentId)(this.options.assignmentId, (0, assignmentId_1.getInstallationIdStore)());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Deletes the stored installation id (`rocapine-assignment-id`) and forgets
|
|
62
|
+
* the in-memory one; a request already resolving it sends none. The next
|
|
63
|
+
* request without a host id mints a NEW id — to stop sending one at all (e.g.
|
|
64
|
+
* consent withdrawn), also make the `assignmentId` option return `false`.
|
|
65
|
+
* Process-wide, like the id: same effect as `OnboardingStudio.clearAssignmentId()`.
|
|
66
|
+
* Rejects if the removal fails or is still waiting after 2s.
|
|
67
|
+
*/
|
|
68
|
+
clearAssignmentId() {
|
|
69
|
+
return (0, assignmentId_1.getInstallationIdStore)().clear();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Races `work` against `options.timeout`, rejecting with `Error("timeout")`.
|
|
73
|
+
* `work` covers identity resolution AND the fetch, so `timeout` is one
|
|
74
|
+
* end-to-end budget: a slow `assignmentId` getter cannot push
|
|
75
|
+
* `fallbackOnboarding` (or the rejection) past it. `work` gets an `expired()`
|
|
76
|
+
* check so a request whose budget ran out while the id resolved is never
|
|
77
|
+
* sent afterwards (the server would count a serve nobody receives).
|
|
78
|
+
*/
|
|
79
|
+
withTimeout(work) {
|
|
80
|
+
const ms = this.options.timeout;
|
|
81
|
+
if (!ms)
|
|
82
|
+
return work(() => false);
|
|
83
|
+
let timer;
|
|
84
|
+
let timedOut = false;
|
|
85
|
+
return Promise.race([
|
|
86
|
+
work(() => timedOut),
|
|
87
|
+
new Promise((_, reject) => {
|
|
88
|
+
timer = setTimeout(() => {
|
|
89
|
+
timedOut = true;
|
|
90
|
+
reject(new Error("timeout"));
|
|
91
|
+
}, ms);
|
|
92
|
+
}),
|
|
93
|
+
]).finally(() => clearTimeout(timer));
|
|
94
|
+
}
|
|
11
95
|
constructor(projectId, options) {
|
|
12
96
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
13
97
|
this.projectId = projectId;
|
|
@@ -55,28 +139,29 @@ class OnboardingStudioClient {
|
|
|
55
139
|
urlParams.append(key, value);
|
|
56
140
|
});
|
|
57
141
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
142
|
+
// SDK-owned keys use `set`, never `append`: the server reads each with
|
|
143
|
+
// `searchParams.get`, which returns the FIRST occurrence, so an appended
|
|
144
|
+
// value would lose to a same-named user param added above.
|
|
145
|
+
urlParams.set("projectId", this.projectId);
|
|
146
|
+
urlParams.set("platform", react_native_1.Platform.OS);
|
|
64
147
|
if (isSandbox) {
|
|
65
|
-
urlParams.
|
|
148
|
+
urlParams.set("draft", "true");
|
|
66
149
|
}
|
|
67
150
|
// Add onboardingOptions to URL
|
|
68
151
|
if (onboardingOptions === null || onboardingOptions === void 0 ? void 0 : onboardingOptions.locale) {
|
|
69
|
-
urlParams.
|
|
152
|
+
urlParams.set("locale", onboardingOptions.locale);
|
|
70
153
|
}
|
|
71
|
-
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
72
|
-
console.info("OnboardingStudioClient getSteps url", url);
|
|
73
154
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
155
|
+
// Identity (incl. the host's assignmentId getter) resolves inside the
|
|
156
|
+
// same timeout budget as the fetch — see `withTimeout`.
|
|
157
|
+
const response = await this.withTimeout(async (expired) => {
|
|
158
|
+
const headers = await this.writeIdentity(urlParams);
|
|
159
|
+
if (expired())
|
|
160
|
+
throw new Error("timeout");
|
|
161
|
+
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
162
|
+
console.info("OnboardingStudioClient getSteps url", url);
|
|
163
|
+
return fetch(url, { headers });
|
|
164
|
+
});
|
|
80
165
|
if (!response.ok) {
|
|
81
166
|
throw new Error(`Failed to fetch onboarding steps: ${response.status} ${response.statusText}`);
|
|
82
167
|
}
|
|
@@ -128,23 +213,20 @@ class OnboardingStudioClient {
|
|
|
128
213
|
urlParams.append(key, value);
|
|
129
214
|
});
|
|
130
215
|
}
|
|
131
|
-
|
|
132
|
-
urlParams.
|
|
133
|
-
|
|
134
|
-
if (appVersion) {
|
|
135
|
-
urlParams.append("appVersion", appVersion);
|
|
136
|
-
}
|
|
216
|
+
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
217
|
+
urlParams.set("projectId", this.projectId);
|
|
218
|
+
urlParams.set("platform", react_native_1.Platform.OS);
|
|
137
219
|
if (isSandbox) {
|
|
138
|
-
urlParams.
|
|
220
|
+
urlParams.set("draft", "true");
|
|
139
221
|
}
|
|
140
222
|
// Add paywallOptions to URL
|
|
141
223
|
if (paywallOptions === null || paywallOptions === void 0 ? void 0 : paywallOptions.locale) {
|
|
142
|
-
urlParams.
|
|
224
|
+
urlParams.set("locale", paywallOptions.locale);
|
|
143
225
|
}
|
|
144
226
|
// Narrows the response to a single paywall. Omitted unless explicitly
|
|
145
227
|
// requested — see the method doc above.
|
|
146
228
|
if (paywallOptions === null || paywallOptions === void 0 ? void 0 : paywallOptions.moment) {
|
|
147
|
-
urlParams.
|
|
229
|
+
urlParams.set("moment", paywallOptions.moment);
|
|
148
230
|
}
|
|
149
231
|
// Deliberately NOT sending spec §6.1's `omitNulls=true`: it's a
|
|
150
232
|
// convenience for untyped consumers that strips null-valued keys from the
|
|
@@ -152,15 +234,17 @@ class OnboardingStudioClient {
|
|
|
152
234
|
// and `Paywall`'s declared `| null` fields. This client parses into those
|
|
153
235
|
// typed objects, so the fields must always be present (possibly `null`),
|
|
154
236
|
// not sometimes missing.
|
|
155
|
-
const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
|
|
156
|
-
console.info("OnboardingStudioClient getPaywalls url", url);
|
|
157
237
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
238
|
+
// Identity (incl. the host's assignmentId getter) resolves inside the
|
|
239
|
+
// same timeout budget as the fetch — see `withTimeout`.
|
|
240
|
+
const response = await this.withTimeout(async (expired) => {
|
|
241
|
+
const headers = await this.writeIdentity(urlParams);
|
|
242
|
+
if (expired())
|
|
243
|
+
throw new Error("timeout");
|
|
244
|
+
const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
|
|
245
|
+
console.info("OnboardingStudioClient getPaywalls url", url);
|
|
246
|
+
return fetch(url, { headers });
|
|
247
|
+
});
|
|
164
248
|
if (!response.ok) {
|
|
165
249
|
throw new Error(`Failed to fetch paywalls: ${response.status} ${response.statusText}`);
|
|
166
250
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingStudioClient.js","sourceRoot":"","sources":["../src/OnboardingStudioClient.ts"],"names":[],"mappings":";;;;;;AAAA,8FAAqE;AAUrE,uDAGkC;AAOlC,+CAAwC;
|
|
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,CAAC;AAE/C,MAAa,sBAAsB;IAMjC;;;;;;;OAOG;IACH,cAAc;QACZ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAA,wCAAsB,EAAC,IAAI,CAAC,OAAO,EAAE,IAAA,mCAAiB,GAAE,CAAC,CAAC;QAC5E,CAAC;Q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a,CAAC,SAAS,CAAC,CAAC;gBACpD,IAAI,OAAO,EAAE;oBAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC1C,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,iBAAiB,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACnE,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;gBAC5D,OAAO,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YACjC,CAAC,CACF,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACtE,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO;gBACL,IAAI;gBACJ,OAAO,EAAE;oBACP,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;oBAC9D,kBAAkB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;iBAC7D;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;YACjE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA7RD,wDA6RC"}
|
|
@@ -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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