@rocapine/react-native-onboarding 1.77.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 +24 -6
- 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 +29 -0
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +76 -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 +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/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 +3 -2
- package/dist/userProperties/reserved.d.ts.map +1 -1
- package/dist/userProperties/reserved.js +3 -1
- 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 +79 -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 +1 -0
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +51 -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/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/types.ts +48 -0
- package/src/userProperties/__tests__/primitives.test.ts +1 -1
- package/src/userProperties/reserved.ts +3 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -185,10 +185,10 @@ 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
192
|
|
|
193
193
|
### What every request carries
|
|
194
194
|
|
|
@@ -202,9 +202,26 @@ Each onboarding and paywall request sends, besides your audience params:
|
|
|
202
202
|
- `environment`: the `environment` option, else `"sandbox"` in sandbox mode,
|
|
203
203
|
`"development"` under `__DEV__`, `"production"` otherwise. Lower-cased,
|
|
204
204
|
reduced to `a-z`, `0-9`, `_` and `-`, at most 32 characters.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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.
|
|
208
225
|
|
|
209
226
|
### Relationship to `customAudienceParams`
|
|
210
227
|
|
|
@@ -212,7 +229,8 @@ The prop still works and is not deprecated. Treat it as the **static** baseline
|
|
|
212
229
|
(build-time facts like an `onboardingId`) and the store as the **runtime** half.
|
|
213
230
|
Where both define a key, **the store wins**.
|
|
214
231
|
|
|
215
|
-
Neither can set `appVersion`, `build`, `sdkVersion
|
|
232
|
+
Neither can set `appVersion`, `build`, `sdkVersion`, `environment` or
|
|
233
|
+
`assignmentId`: since the
|
|
216
234
|
SDK sends them itself, a value under one of those names in either source is
|
|
217
235
|
dropped (see [Reserved names](#reserved-names)), and an audience rule on them
|
|
218
236
|
sees the SDK's value.
|
|
@@ -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","sourceRoot":"","sources":["../src/OnboardingStudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,O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AAgB,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;YACJ,CAAC;YAED,MAAM,GAAG,IAAI,+CAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACxD,SAAS,GAAG,IAAI,C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37 @@ export declare class OnboardingStudioClient {
|
|
|
21
21
|
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
22
22
|
* would then leave a same-named user param on the wire (a property persisted
|
|
23
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.
|
|
24
28
|
*/
|
|
25
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;
|
|
26
55
|
constructor(projectId: string, options: OnboardingStudioClientOptions);
|
|
27
56
|
/**
|
|
28
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"}
|
|
@@ -8,6 +8,9 @@ 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 {
|
|
12
15
|
/**
|
|
13
16
|
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
@@ -29,13 +32,65 @@ class OnboardingStudioClient {
|
|
|
29
32
|
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
30
33
|
* would then leave a same-named user param on the wire (a property persisted
|
|
31
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.
|
|
32
39
|
*/
|
|
33
|
-
writeIdentity(urlParams) {
|
|
40
|
+
async writeIdentity(urlParams) {
|
|
34
41
|
urlParams.delete("appVersion");
|
|
35
42
|
urlParams.delete("build");
|
|
36
43
|
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
37
44
|
urlParams.set(key, value);
|
|
38
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));
|
|
39
94
|
}
|
|
40
95
|
constructor(projectId, options) {
|
|
41
96
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
@@ -89,7 +144,6 @@ class OnboardingStudioClient {
|
|
|
89
144
|
// value would lose to a same-named user param added above.
|
|
90
145
|
urlParams.set("projectId", this.projectId);
|
|
91
146
|
urlParams.set("platform", react_native_1.Platform.OS);
|
|
92
|
-
this.writeIdentity(urlParams);
|
|
93
147
|
if (isSandbox) {
|
|
94
148
|
urlParams.set("draft", "true");
|
|
95
149
|
}
|
|
@@ -97,15 +151,17 @@ class OnboardingStudioClient {
|
|
|
97
151
|
if (onboardingOptions === null || onboardingOptions === void 0 ? void 0 : onboardingOptions.locale) {
|
|
98
152
|
urlParams.set("locale", onboardingOptions.locale);
|
|
99
153
|
}
|
|
100
|
-
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
101
|
-
console.info("OnboardingStudioClient getSteps url", url);
|
|
102
154
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
+
});
|
|
109
165
|
if (!response.ok) {
|
|
110
166
|
throw new Error(`Failed to fetch onboarding steps: ${response.status} ${response.statusText}`);
|
|
111
167
|
}
|
|
@@ -160,7 +216,6 @@ class OnboardingStudioClient {
|
|
|
160
216
|
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
161
217
|
urlParams.set("projectId", this.projectId);
|
|
162
218
|
urlParams.set("platform", react_native_1.Platform.OS);
|
|
163
|
-
this.writeIdentity(urlParams);
|
|
164
219
|
if (isSandbox) {
|
|
165
220
|
urlParams.set("draft", "true");
|
|
166
221
|
}
|
|
@@ -179,15 +234,17 @@ class OnboardingStudioClient {
|
|
|
179
234
|
// and `Paywall`'s declared `| null` fields. This client parses into those
|
|
180
235
|
// typed objects, so the fields must always be present (possibly `null`),
|
|
181
236
|
// not sometimes missing.
|
|
182
|
-
const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
|
|
183
|
-
console.info("OnboardingStudioClient getPaywalls url", url);
|
|
184
237
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
+
});
|
|
191
248
|
if (!response.ok) {
|
|
192
249
|
throw new Error(`Failed to fetch paywalls: ${response.status} ${response.statusText}`);
|
|
193
250
|
}
|
|
@@ -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,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;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;;;;;;;OAUG;IACK,KAAK,CAAC,aAAa,CAAC,SAA0B;QACpD,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/B,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC;YACjE,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,CAA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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.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,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