@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.
Files changed (77) hide show
  1. package/README.md +38 -10
  2. package/dist/OnboardingStudio.d.ts +14 -1
  3. package/dist/OnboardingStudio.d.ts.map +1 -1
  4. package/dist/OnboardingStudio.js +5 -1
  5. package/dist/OnboardingStudio.js.map +1 -1
  6. package/dist/OnboardingStudioClient.d.ts +31 -0
  7. package/dist/OnboardingStudioClient.d.ts.map +1 -1
  8. package/dist/OnboardingStudioClient.js +80 -19
  9. package/dist/OnboardingStudioClient.js.map +1 -1
  10. package/dist/assignmentId.d.ts +107 -0
  11. package/dist/assignmentId.d.ts.map +1 -0
  12. package/dist/assignmentId.js +215 -0
  13. package/dist/assignmentId.js.map +1 -0
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +9 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/paywalls/PaywallProvider.d.ts +8 -1
  19. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  20. package/dist/paywalls/PaywallProvider.js +5 -1
  21. package/dist/paywalls/PaywallProvider.js.map +1 -1
  22. package/dist/paywalls/customScreens.d.ts +7 -0
  23. package/dist/paywalls/customScreens.d.ts.map +1 -1
  24. package/dist/paywalls/devHook.d.ts +26 -0
  25. package/dist/paywalls/devHook.d.ts.map +1 -0
  26. package/dist/paywalls/devHook.js +29 -0
  27. package/dist/paywalls/devHook.js.map +1 -0
  28. package/dist/paywalls/observer.d.ts +2 -0
  29. package/dist/paywalls/observer.d.ts.map +1 -1
  30. package/dist/paywalls/observer.js +21 -9
  31. package/dist/paywalls/observer.js.map +1 -1
  32. package/dist/paywalls/types.d.ts +22 -0
  33. package/dist/paywalls/types.d.ts.map +1 -1
  34. package/dist/products/adapters/expoIap.d.ts +34 -13
  35. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  36. package/dist/products/adapters/expoIap.js +136 -21
  37. package/dist/products/adapters/expoIap.js.map +1 -1
  38. package/dist/steps/ComposableScreen/types.d.ts +21 -0
  39. package/dist/steps/ComposableScreen/types.d.ts.map +1 -1
  40. package/dist/steps/ComposableScreen/types.js +14 -0
  41. package/dist/steps/ComposableScreen/types.js.map +1 -1
  42. package/dist/types.d.ts +47 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js +6 -0
  45. package/dist/types.js.map +1 -1
  46. package/dist/userProperties/reserved.d.ts +8 -5
  47. package/dist/userProperties/reserved.d.ts.map +1 -1
  48. package/dist/userProperties/reserved.js +9 -4
  49. package/dist/userProperties/reserved.js.map +1 -1
  50. package/dist/version.d.ts +1 -1
  51. package/dist/version.js +1 -1
  52. package/package.json +1 -1
  53. package/src/OnboardingStudio.ts +19 -1
  54. package/src/OnboardingStudioClient.ts +84 -31
  55. package/src/__tests__/assignmentId.clear.test.ts +413 -0
  56. package/src/__tests__/assignmentId.client.test.ts +288 -0
  57. package/src/__tests__/assignmentId.test.ts +195 -0
  58. package/src/__tests__/onboardingMetadata.client.test.ts +76 -0
  59. package/src/assignmentId.ts +278 -0
  60. package/src/index.ts +9 -0
  61. package/src/paywalls/PaywallProvider.tsx +13 -0
  62. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +51 -0
  63. package/src/paywalls/__tests__/devHook.test.ts +70 -0
  64. package/src/paywalls/__tests__/getPaywalls.test.ts +77 -2
  65. package/src/paywalls/__tests__/observer.test.ts +37 -0
  66. package/src/paywalls/__tests__/present.test.ts +14 -0
  67. package/src/paywalls/customScreens.ts +7 -0
  68. package/src/paywalls/devHook.ts +48 -0
  69. package/src/paywalls/observer.ts +22 -2
  70. package/src/paywalls/types.ts +22 -0
  71. package/src/products/adapters/__tests__/expoIap.contract.test.ts +305 -0
  72. package/src/products/adapters/expoIap.ts +171 -32
  73. package/src/steps/ComposableScreen/types.ts +21 -0
  74. package/src/types.ts +48 -0
  75. package/src/userProperties/__tests__/primitives.test.ts +1 -1
  76. package/src/userProperties/reserved.ts +9 -4
  77. package/src/version.ts +1 -1
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { NextStep } from "./steps/common.types";
2
+ import type { AssignmentIdOption } from "./assignmentId";
2
3
  /**
3
4
  * Base step type that all onboarding steps must conform to.
4
5
  * This is the minimal interface required by the headless SDK.
@@ -33,9 +34,36 @@ export type OnboardingStudioClientOptions<StepType extends BaseStepType = BaseSt
33
34
  * characters before it is sent. An audience rule can target it.
34
35
  */
35
36
  environment?: string;
37
+ /**
38
+ * The stable per-person id sent as `assignmentId`, so the server can keep a
39
+ * person in the same variant across launches. A string, or a getter called
40
+ * on every request (sync or async) — e.g. `() => Purchases.getAppUserID()`
41
+ * to use the RevenueCat App User ID (call `Purchases.configure()` before
42
+ * the first request). When omitted, or when the value is `undefined`,
43
+ * `null` or `""`, the SDK sends an installation id it generates once and
44
+ * persists. Absent from the request when neither is available.
45
+ *
46
+ * `false` (or a getter returning `false`) opts out: nothing is sent, and the
47
+ * installation id is never read, created or written. Use it until the user
48
+ * has consented. `null` and `""` are not an opt-out.
49
+ *
50
+ * Fails closed: a getter that throws, rejects or takes longer than 2s is
51
+ * treated like `false` for that request — nothing is sent and the
52
+ * installation id is not touched. Resolving it counts against `timeout`.
53
+ *
54
+ * Changing the value (e.g. anonymous → identified on login) can move the
55
+ * person to another variant, once.
56
+ */
57
+ assignmentId?: AssignmentIdOption;
36
58
  isSandbox?: boolean;
37
59
  baseUrl?: string;
38
60
  fallbackOnboarding?: Onboarding<StepType>;
61
+ /**
62
+ * End-to-end budget in ms for each `getSteps` / `getPaywalls` request:
63
+ * resolving the request identity (including the `assignmentId` getter) and
64
+ * the fetch together. On expiry `getSteps` returns `fallbackOnboarding` if
65
+ * set; otherwise both reject with `Error("timeout")`.
66
+ */
39
67
  timeout?: number;
40
68
  /**
41
69
  * Optional custom cache key. When provided, the fetched onboarding is
@@ -54,6 +82,11 @@ export type OnboardingOptions = {
54
82
  export type UserDefinedParams = {
55
83
  [key: string]: string;
56
84
  };
85
+ /**
86
+ * Reserved `OnboardingMetadata.variantKey` reported by the parent (main)
87
+ * onboarding, as opposed to one of its variants.
88
+ */
89
+ export declare const MAIN_VARIANT_KEY: "main";
57
90
  export interface OnboardingMetadata {
58
91
  id: string;
59
92
  name?: string;
@@ -62,6 +95,20 @@ export interface OnboardingMetadata {
62
95
  audienceOrder?: number;
63
96
  locale?: string;
64
97
  draft?: boolean;
98
+ /**
99
+ * Which variant of the onboarding this user was served. The parent (main)
100
+ * onboarding reports the reserved key `MAIN_VARIANT_KEY` (`"main"`).
101
+ * `null` and absent mean the same thing — the server sent no variant
102
+ * information (e.g. an older server) — and hosts should treat them
103
+ * identically (e.g. `metadata.variantKey ?? undefined`).
104
+ */
105
+ variantKey?: string | null;
106
+ /**
107
+ * Id of the published deployment that was served. `null` for a draft
108
+ * (sandbox) payload, which has no deployment; absent when the server does
109
+ * not send it.
110
+ */
111
+ deploymentId?: number | null;
65
112
  }
66
113
  /**
67
114
  * Studio-authored, project-level configuration returned alongside the steps
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,6BAA6B,CACvC,QAAQ,SAAS,Y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AAC;AAEV,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,GAAG,gBAAgB,EAAE,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAEpE,MAAM,WAAW,UAAU,CAAC,QAAQ,SAAS,YAAY,GAAG,YAAY;IACtE,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,aAAa,EAAE,uBAAuB,CAAC;IACvC,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
package/dist/types.js CHANGED
@@ -1,3 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAIN_VARIANT_KEY = void 0;
4
+ /**
5
+ * Reserved `OnboardingMetadata.variantKey` reported by the parent (main)
6
+ * onboarding, as opposed to one of its variants.
7
+ */
8
+ exports.MAIN_VARIANT_KEY = "main";
3
9
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA2FA;;;GAGG;AACU,QAAA,gBAAgB,GAAG,MAAe,CAAC"}
@@ -2,13 +2,16 @@
2
2
  * Property names a host may NOT use, because `OnboardingStudioClient` puts them
3
3
  * on the querystring itself.
4
4
  *
5
- * Two of them — `moment` and `now` — mirror the server's own
6
- * `RESERVED_AUDIENCE_VARS`, which strips them because they are server-owned (a
7
- * client supplying `now` is self-selecting into a time-gated audience).
5
+ * Three of them — `moment`, `now` and `appleReview` — are server-owned audience
6
+ * variables: the server sets them per request. They mirror the server's own
7
+ * list of server-owned names (`moment`, `now`, `appleReview`), which strips
8
+ * any client-supplied value (a client supplying `now` is self-selecting into a
9
+ * time-gated audience).
8
10
  *
9
11
  * The others are the params the client writes on every request: `projectId`,
10
12
  * `platform`, the request identity (`appVersion`, `build`, `sdkVersion`,
11
- * `environment` — see `requestIdentity.ts`), `draft`, `locale`, `omitNulls`.
13
+ * `environment` — see `requestIdentity.ts`), `assignmentId` (see
14
+ * `assignmentId.ts`), `draft`, `locale`, `omitNulls`.
12
15
  * The client adds user params FIRST, then writes its own with
13
16
  * `URLSearchParams.set`, which replaces any same-named user param (and removes
14
17
  * a user `appVersion`/`build` when it has none of its own to send):
@@ -27,7 +30,7 @@
27
30
  * plausible accident. Refusing — rather than prefixing or escaping — keeps the
28
31
  * wire format unchanged and puts the warning at the call site responsible.
29
32
  */
30
- export declare const RESERVED_USER_PROPERTY_KEYS: readonly ["projectId", "platform", "appVersion", "build", "sdkVersion", "environment", "draft", "locale", "omitNulls", "moment", "now"];
33
+ export declare const RESERVED_USER_PROPERTY_KEYS: readonly ["projectId", "platform", "appVersion", "build", "sdkVersion", "environment", "assignmentId", "draft", "locale", "omitNulls", "moment", "now", "appleReview"];
31
34
  export type ReservedUserPropertyKey = (typeof RESERVED_USER_PROPERTY_KEYS)[number];
32
35
  /** Exact match, never a prefix — `projectIdentifier` is a perfectly good property. */
33
36
  export declare const isReservedUserPropertyKey: (key: string) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"reserved.d.ts","sourceRoot":"","sources":["../../src/userProperties/reserved.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,2BAA2B,yIAY9B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,sFAAsF;AACtF,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OACU,CAAC"}
1
+ {"version":3,"file":"reserved.d.ts","sourceRoot":"","sources":["../../src/userProperties/reserved.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,2BAA2B,wKAc9B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnF,sFAAsF;AACtF,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OACU,CAAC"}
@@ -5,13 +5,16 @@ exports.isReservedUserPropertyKey = exports.RESERVED_USER_PROPERTY_KEYS = void 0
5
5
  * Property names a host may NOT use, because `OnboardingStudioClient` puts them
6
6
  * on the querystring itself.
7
7
  *
8
- * Two of them — `moment` and `now` — mirror the server's own
9
- * `RESERVED_AUDIENCE_VARS`, which strips them because they are server-owned (a
10
- * client supplying `now` is self-selecting into a time-gated audience).
8
+ * Three of them — `moment`, `now` and `appleReview` — are server-owned audience
9
+ * variables: the server sets them per request. They mirror the server's own
10
+ * list of server-owned names (`moment`, `now`, `appleReview`), which strips
11
+ * any client-supplied value (a client supplying `now` is self-selecting into a
12
+ * time-gated audience).
11
13
  *
12
14
  * The others are the params the client writes on every request: `projectId`,
13
15
  * `platform`, the request identity (`appVersion`, `build`, `sdkVersion`,
14
- * `environment` — see `requestIdentity.ts`), `draft`, `locale`, `omitNulls`.
16
+ * `environment` — see `requestIdentity.ts`), `assignmentId` (see
17
+ * `assignmentId.ts`), `draft`, `locale`, `omitNulls`.
15
18
  * The client adds user params FIRST, then writes its own with
16
19
  * `URLSearchParams.set`, which replaces any same-named user param (and removes
17
20
  * a user `appVersion`/`build` when it has none of its own to send):
@@ -37,11 +40,13 @@ exports.RESERVED_USER_PROPERTY_KEYS = [
37
40
  "build",
38
41
  "sdkVersion",
39
42
  "environment",
43
+ "assignmentId",
40
44
  "draft",
41
45
  "locale",
42
46
  "omitNulls",
43
47
  "moment",
44
48
  "now",
49
+ "appleReview",
45
50
  ];
46
51
  /** Exact match, never a prefix — `projectIdentifier` is a perfectly good property. */
47
52
  const isReservedUserPropertyKey = (key) => exports.RESERVED_USER_PROPERTY_KEYS.includes(key);
@@ -1 +1 @@
1
- {"version":3,"file":"reserved.js","sourceRoot":"","sources":["../../src/userProperties/reserved.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACU,QAAA,2BAA2B,GAAG;IACzC,WAAW;IACX,UAAU;IACV,YAAY;IACZ,OAAO;IACP,YAAY;IACZ,aAAa;IACb,OAAO;IACP,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,KAAK;CACG,CAAC;AAIX,sFAAsF;AAC/E,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAW,EAAE,CAC/D,mCAAiD,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AADtD,QAAA,yBAAyB,6BAC6B"}
1
+ {"version":3,"file":"reserved.js","sourceRoot":"","sources":["../../src/userProperties/reserved.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACU,QAAA,2BAA2B,GAAG;IACzC,WAAW;IACX,UAAU;IACV,YAAY;IACZ,OAAO;IACP,YAAY;IACZ,aAAa;IACb,cAAc;IACd,OAAO;IACP,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,KAAK;IACL,aAAa;CACL,CAAC;AAIX,sFAAsF;AAC/E,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAW,EAAE,CAC/D,mCAAiD,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AADtD,QAAA,yBAAyB,6BAC6B"}
package/dist/version.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  * the file. `npm run check:versions` fails when this disagrees with
7
7
  * `package.json`, and the `bump-version` skill updates it.
8
8
  */
9
- export declare const SDK_VERSION = "1.77.0";
9
+ export declare const SDK_VERSION = "1.79.0";
10
10
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -9,5 +9,5 @@ exports.SDK_VERSION = void 0;
9
9
  * the file. `npm run check:versions` fails when this disagrees with
10
10
  * `package.json`, and the `bump-version` skill updates it.
11
11
  */
12
- exports.SDK_VERSION = "1.77.0";
12
+ exports.SDK_VERSION = "1.79.0";
13
13
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocapine/react-native-onboarding",
3
- "version": "1.77.0",
3
+ "version": "1.79.0",
4
4
  "description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,7 @@
1
1
  import { OnboardingStudioClient } from "./OnboardingStudioClient";
2
2
  import type { OnboardingStudioClientOptions } from "./types";
3
3
  import { userPropertyStore } from "./userProperties/store";
4
+ import { getInstallationIdStore, type InstallationIdStore } from "./assignmentId";
4
5
  import type { UserPropertyStore } from "./userProperties/store";
5
6
  import type {
6
7
  UserProperties,
@@ -53,6 +54,18 @@ export type OnboardingStudioFacade = {
53
54
  * not changed — `getClient()?.clearCache()` is right there if both are wanted.
54
55
  */
55
56
  reset: () => void;
57
+ /**
58
+ * Deletes the stored installation id sent as `assignmentId`
59
+ * (`rocapine-assignment-id`) and forgets it in memory; a request already
60
+ * resolving it sends none. Works before `init`. The next request without a
61
+ * host id mints a NEW id, so on consent withdrawal also make the
62
+ * `assignmentId` option return `false`. Rejects if the removal fails or is
63
+ * still waiting after 2s.
64
+ *
65
+ * Separate from `reset()` on purpose: logging out must not move an install
66
+ * to another variant.
67
+ */
68
+ clearAssignmentId: () => Promise<void>;
56
69
  };
57
70
 
58
71
  /** Stable signature of a config, for the idempotency check in `init`. */
@@ -72,7 +85,11 @@ const configSignature = (projectId: string, options: Record<string, unknown>): s
72
85
  * `usePaywall()`, where that state is reachable and where a call cannot be made
73
86
  * before a provider exists.
74
87
  */
75
- export const createOnboardingStudio = (store: UserPropertyStore): OnboardingStudioFacade => {
88
+ export const createOnboardingStudio = (
89
+ store: UserPropertyStore,
90
+ // A getter, not the store: tests swap the process-wide store between cases.
91
+ installation: () => InstallationIdStore = getInstallationIdStore,
92
+ ): OnboardingStudioFacade => {
76
93
  let client: OnboardingStudioClient | null = null;
77
94
  let signature: string | null = null;
78
95
 
@@ -118,6 +135,7 @@ export const createOnboardingStudio = (store: UserPropertyStore): OnboardingStud
118
135
  removeUserProperty: (key) => store.remove(key),
119
136
  getUserProperties: () => store.get(),
120
137
  reset: () => store.reset(),
138
+ clearAssignmentId: () => installation().clear(),
121
139
  };
122
140
  };
123
141
 
@@ -20,6 +20,10 @@ import {
20
20
 
21
21
  import { Platform } from "react-native";
22
22
  import { readNativeAppInfo, resolveRequestIdentity } from "./requestIdentity";
23
+ import { getInstallationIdStore, resolveAssignmentId } from "./assignmentId";
24
+
25
+ /** Request header carrying the `assignmentId`; the server reads it case-insensitively. */
26
+ const ASSIGNMENT_ID_HEADER = "X-Assignment-Id";
23
27
 
24
28
  export class OnboardingStudioClient {
25
29
  private baseUrl: string;
@@ -27,6 +31,11 @@ export class OnboardingStudioClient {
27
31
  public options: OnboardingStudioClientOptions;
28
32
  private identity?: Record<string, string>;
29
33
 
34
+ /** Edge functions base URL this client talks to. Read-only; devtools use it. */
35
+ get functionsBaseUrl(): string {
36
+ return this.baseUrl;
37
+ }
38
+
30
39
  /**
31
40
  * `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
32
41
  * adds to every request (see `requestIdentity.ts`). Memoized: none of them
@@ -48,13 +57,67 @@ export class OnboardingStudioClient {
48
57
  * when neither the host nor `expo-application` has a value, and `set` alone
49
58
  * would then leave a same-named user param on the wire (a property persisted
50
59
  * before these names were reserved is re-read without a reserved-key check).
60
+ *
61
+ * Returns the request headers: the `assignmentId` travels as the
62
+ * `X-Assignment-Id` header, never on the querystring, because edge invocation
63
+ * logs record the full URL and the id may be a host's user id.
51
64
  */
52
- private writeIdentity(urlParams: URLSearchParams): void {
65
+ private async writeIdentity(urlParams: URLSearchParams): Promise<Record<string, string>> {
53
66
  urlParams.delete("appVersion");
54
67
  urlParams.delete("build");
55
68
  for (const [key, value] of Object.entries(this.identityParams())) {
56
69
  urlParams.set(key, value);
57
70
  }
71
+ // A user param of that name never reaches the URL, whatever the id resolves to.
72
+ urlParams.delete("assignmentId");
73
+ const assignmentId = await this.getAssignmentId();
74
+ return assignmentId ? { [ASSIGNMENT_ID_HEADER]: assignmentId } : {};
75
+ }
76
+
77
+ /**
78
+ * The `assignmentId` the next request will carry: the host's `assignmentId`
79
+ * option, else the persisted installation id, else `undefined` (sent as
80
+ * absent). Resolved per request, never memoized here, because a host getter
81
+ * may change value on login. Never throws. See `assignmentId.ts`.
82
+ */
83
+ getAssignmentId(): Promise<string | undefined> {
84
+ return resolveAssignmentId(this.options.assignmentId, getInstallationIdStore());
85
+ }
86
+
87
+ /**
88
+ * Deletes the stored installation id (`rocapine-assignment-id`) and forgets
89
+ * the in-memory one; a request already resolving it sends none. The next
90
+ * request without a host id mints a NEW id — to stop sending one at all (e.g.
91
+ * consent withdrawn), also make the `assignmentId` option return `false`.
92
+ * Process-wide, like the id: same effect as `OnboardingStudio.clearAssignmentId()`.
93
+ * Rejects if the removal fails or is still waiting after 2s.
94
+ */
95
+ clearAssignmentId(): Promise<void> {
96
+ return getInstallationIdStore().clear();
97
+ }
98
+
99
+ /**
100
+ * Races `work` against `options.timeout`, rejecting with `Error("timeout")`.
101
+ * `work` covers identity resolution AND the fetch, so `timeout` is one
102
+ * end-to-end budget: a slow `assignmentId` getter cannot push
103
+ * `fallbackOnboarding` (or the rejection) past it. `work` gets an `expired()`
104
+ * check so a request whose budget ran out while the id resolved is never
105
+ * sent afterwards (the server would count a serve nobody receives).
106
+ */
107
+ private withTimeout<T>(work: (expired: () => boolean) => Promise<T>): Promise<T> {
108
+ const ms = this.options.timeout;
109
+ if (!ms) return work(() => false);
110
+ let timer: ReturnType<typeof setTimeout> | undefined;
111
+ let timedOut = false;
112
+ return Promise.race([
113
+ work(() => timedOut),
114
+ new Promise<never>((_, reject) => {
115
+ timer = setTimeout(() => {
116
+ timedOut = true;
117
+ reject(new Error("timeout"));
118
+ }, ms);
119
+ }),
120
+ ]).finally(() => clearTimeout(timer));
58
121
  }
59
122
 
60
123
  constructor(projectId: string, options: OnboardingStudioClientOptions) {
@@ -117,7 +180,6 @@ export class OnboardingStudioClient {
117
180
  // value would lose to a same-named user param added above.
118
181
  urlParams.set("projectId", this.projectId);
119
182
  urlParams.set("platform", Platform.OS);
120
- this.writeIdentity(urlParams);
121
183
 
122
184
  if (isSandbox) {
123
185
  urlParams.set("draft", "true");
@@ -128,21 +190,17 @@ export class OnboardingStudioClient {
128
190
  urlParams.set("locale", onboardingOptions.locale);
129
191
  }
130
192
 
131
- const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
132
- console.info("OnboardingStudioClient getSteps url", url);
133
193
  try {
134
- const response = await Promise.race(
135
- this.options.timeout
136
- ? [
137
- fetch(url),
138
- new Promise<Response>((_, reject) =>
139
- setTimeout(
140
- () => reject(new Error("timeout")),
141
- this.options.timeout
142
- )
143
- ),
144
- ]
145
- : [fetch(url)]
194
+ // Identity (incl. the host's assignmentId getter) resolves inside the
195
+ // same timeout budget as the fetch — see `withTimeout`.
196
+ const response = await this.withTimeout(
197
+ async (expired) => {
198
+ const headers = await this.writeIdentity(urlParams);
199
+ if (expired()) throw new Error("timeout");
200
+ const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
201
+ console.info("OnboardingStudioClient getSteps url", url);
202
+ return fetch(url, { headers });
203
+ }
146
204
  );
147
205
  if (!response.ok) {
148
206
  throw new Error(
@@ -205,7 +263,6 @@ export class OnboardingStudioClient {
205
263
  // SDK-owned keys use `set`, never `append` (see getSteps).
206
264
  urlParams.set("projectId", this.projectId);
207
265
  urlParams.set("platform", Platform.OS);
208
- this.writeIdentity(urlParams);
209
266
 
210
267
  if (isSandbox) {
211
268
  urlParams.set("draft", "true");
@@ -228,21 +285,17 @@ export class OnboardingStudioClient {
228
285
  // and `Paywall`'s declared `| null` fields. This client parses into those
229
286
  // typed objects, so the fields must always be present (possibly `null`),
230
287
  // not sometimes missing.
231
- const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
232
- console.info("OnboardingStudioClient getPaywalls url", url);
233
288
  try {
234
- const response = await Promise.race(
235
- this.options.timeout
236
- ? [
237
- fetch(url),
238
- new Promise<Response>((_, reject) =>
239
- setTimeout(
240
- () => reject(new Error("timeout")),
241
- this.options.timeout
242
- )
243
- ),
244
- ]
245
- : [fetch(url)]
289
+ // Identity (incl. the host's assignmentId getter) resolves inside the
290
+ // same timeout budget as the fetch — see `withTimeout`.
291
+ const response = await this.withTimeout(
292
+ async (expired) => {
293
+ const headers = await this.writeIdentity(urlParams);
294
+ if (expired()) throw new Error("timeout");
295
+ const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
296
+ console.info("OnboardingStudioClient getPaywalls url", url);
297
+ return fetch(url, { headers });
298
+ }
246
299
  );
247
300
  if (!response.ok) {
248
301
  throw new Error(