@rocapine/react-native-onboarding 1.76.0 → 1.77.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 +30 -4
- package/dist/OnboardingStudioClient.d.ts +18 -0
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +44 -17
- package/dist/OnboardingStudioClient.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 +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/userProperties/reserved.d.ts +16 -15
- package/dist/userProperties/reserved.d.ts.map +1 -1
- package/dist/userProperties/reserved.js +18 -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/OnboardingStudioClient.ts +47 -19
- package/src/__tests__/getOnboarding.query.test.ts +30 -0
- package/src/__tests__/requestIdentity.client.test.ts +115 -0
- package/src/__tests__/requestIdentity.test.ts +112 -0
- package/src/paywalls/__tests__/getPaywalls.test.ts +30 -0
- package/src/requestIdentity.ts +101 -0
- package/src/types.ts +17 -0
- package/src/userProperties/__tests__/effectiveParams.test.ts +2 -2
- package/src/userProperties/__tests__/primitives.test.ts +1 -1
- package/src/userProperties/reserved.ts +18 -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,27 @@ 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
|
|
187
|
+
querystring itself: its own value is sent instead of yours, or, for
|
|
188
|
+
`appVersion` and `build` when it has none, nothing is:
|
|
189
189
|
|
|
190
|
-
`projectId`, `platform`, `appVersion`, `
|
|
191
|
-
`now`
|
|
190
|
+
`projectId`, `platform`, `appVersion`, `build`, `sdkVersion`, `environment`,
|
|
191
|
+
`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
|
+
|
|
206
|
+
They are ordinary query params, so an audience rule can target them, for
|
|
207
|
+
example `environment == "staging"` or a build range.
|
|
192
208
|
|
|
193
209
|
### Relationship to `customAudienceParams`
|
|
194
210
|
|
|
@@ -196,6 +212,11 @@ The prop still works and is not deprecated. Treat it as the **static** baseline
|
|
|
196
212
|
(build-time facts like an `onboardingId`) and the store as the **runtime** half.
|
|
197
213
|
Where both define a key, **the store wins**.
|
|
198
214
|
|
|
215
|
+
Neither can set `appVersion`, `build`, `sdkVersion` or `environment`: since the
|
|
216
|
+
SDK sends them itself, a value under one of those names in either source is
|
|
217
|
+
dropped (see [Reserved names](#reserved-names)), and an audience rule on them
|
|
218
|
+
sees the SDK's value.
|
|
219
|
+
|
|
199
220
|
---
|
|
200
221
|
|
|
201
222
|
## 🔓 Gating a Feature with `register`
|
|
@@ -360,6 +381,11 @@ Install these only if you're using the specific screen types:
|
|
|
360
381
|
| **Ratings** | `expo-store-review` | `npx expo install expo-store-review` |
|
|
361
382
|
| **Commitment** (signature) | `@shopify/react-native-skia` | `npx expo install @shopify/react-native-skia` |
|
|
362
383
|
|
|
384
|
+
`expo-application` (`npx expo install expo-application`) is optional too, and not
|
|
385
|
+
tied to a screen type: with it installed, the SDK reports your app's version and
|
|
386
|
+
build on every request without you passing them (see
|
|
387
|
+
[What every request carries](#what-every-request-carries)).
|
|
388
|
+
|
|
363
389
|
---
|
|
364
390
|
|
|
365
391
|
## 💡 Example Project
|
|
@@ -5,6 +5,24 @@ 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
|
+
private writeIdentity;
|
|
8
26
|
constructor(projectId: string, options: OnboardingStudioClientOptions);
|
|
9
27
|
/**
|
|
10
28
|
* 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;AAK1B,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;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;gBAQT,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;IA2E5E;;;;;;;;;;;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;CAwE1E"}
|
|
@@ -7,7 +7,36 @@ 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");
|
|
10
11
|
class OnboardingStudioClient {
|
|
12
|
+
/**
|
|
13
|
+
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
14
|
+
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
15
|
+
* can change while the process runs. Deliberately NOT part of any cache key:
|
|
16
|
+
* a key that changed with every app update would leave a user who is offline
|
|
17
|
+
* right after updating with no cached payload, and would stop a custom
|
|
18
|
+
* `cacheKey` from pinning content across updates.
|
|
19
|
+
*/
|
|
20
|
+
identityParams() {
|
|
21
|
+
if (!this.identity) {
|
|
22
|
+
this.identity = (0, requestIdentity_1.resolveRequestIdentity)(this.options, (0, requestIdentity_1.readNativeAppInfo)());
|
|
23
|
+
}
|
|
24
|
+
return this.identity;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Writes the identity onto a querystring that already holds the user params.
|
|
28
|
+
* `appVersion` and `build` are removed first, because the identity omits them
|
|
29
|
+
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
30
|
+
* would then leave a same-named user param on the wire (a property persisted
|
|
31
|
+
* before these names were reserved is re-read without a reserved-key check).
|
|
32
|
+
*/
|
|
33
|
+
writeIdentity(urlParams) {
|
|
34
|
+
urlParams.delete("appVersion");
|
|
35
|
+
urlParams.delete("build");
|
|
36
|
+
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
37
|
+
urlParams.set(key, value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
11
40
|
constructor(projectId, options) {
|
|
12
41
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
13
42
|
this.projectId = projectId;
|
|
@@ -55,18 +84,18 @@ class OnboardingStudioClient {
|
|
|
55
84
|
urlParams.append(key, value);
|
|
56
85
|
});
|
|
57
86
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
87
|
+
// SDK-owned keys use `set`, never `append`: the server reads each with
|
|
88
|
+
// `searchParams.get`, which returns the FIRST occurrence, so an appended
|
|
89
|
+
// value would lose to a same-named user param added above.
|
|
90
|
+
urlParams.set("projectId", this.projectId);
|
|
91
|
+
urlParams.set("platform", react_native_1.Platform.OS);
|
|
92
|
+
this.writeIdentity(urlParams);
|
|
64
93
|
if (isSandbox) {
|
|
65
|
-
urlParams.
|
|
94
|
+
urlParams.set("draft", "true");
|
|
66
95
|
}
|
|
67
96
|
// Add onboardingOptions to URL
|
|
68
97
|
if (onboardingOptions === null || onboardingOptions === void 0 ? void 0 : onboardingOptions.locale) {
|
|
69
|
-
urlParams.
|
|
98
|
+
urlParams.set("locale", onboardingOptions.locale);
|
|
70
99
|
}
|
|
71
100
|
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
72
101
|
console.info("OnboardingStudioClient getSteps url", url);
|
|
@@ -128,23 +157,21 @@ class OnboardingStudioClient {
|
|
|
128
157
|
urlParams.append(key, value);
|
|
129
158
|
});
|
|
130
159
|
}
|
|
131
|
-
|
|
132
|
-
urlParams.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
urlParams.append("appVersion", appVersion);
|
|
136
|
-
}
|
|
160
|
+
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
161
|
+
urlParams.set("projectId", this.projectId);
|
|
162
|
+
urlParams.set("platform", react_native_1.Platform.OS);
|
|
163
|
+
this.writeIdentity(urlParams);
|
|
137
164
|
if (isSandbox) {
|
|
138
|
-
urlParams.
|
|
165
|
+
urlParams.set("draft", "true");
|
|
139
166
|
}
|
|
140
167
|
// Add paywallOptions to URL
|
|
141
168
|
if (paywallOptions === null || paywallOptions === void 0 ? void 0 : paywallOptions.locale) {
|
|
142
|
-
urlParams.
|
|
169
|
+
urlParams.set("locale", paywallOptions.locale);
|
|
143
170
|
}
|
|
144
171
|
// Narrows the response to a single paywall. Omitted unless explicitly
|
|
145
172
|
// requested — see the method doc above.
|
|
146
173
|
if (paywallOptions === null || paywallOptions === void 0 ? void 0 : paywallOptions.moment) {
|
|
147
|
-
urlParams.
|
|
174
|
+
urlParams.set("moment", paywallOptions.moment);
|
|
148
175
|
}
|
|
149
176
|
// Deliberately NOT sending spec §6.1's `omitNulls=true`: it's a
|
|
150
177
|
// convenience for untyped consumers that strips null-valued keys from the
|
|
@@ -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;AAE9E,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,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server can tell which app
|
|
3
|
+
* version, build, SDK and environment it served: `appVersion`, `build`,
|
|
4
|
+
* `sdkVersion`, `environment`.
|
|
5
|
+
*
|
|
6
|
+
* These are ordinary query params, so an audience rule can target them too
|
|
7
|
+
* (`environment == "staging"`, a build range).
|
|
8
|
+
*/
|
|
9
|
+
export type NativeAppInfo = {
|
|
10
|
+
appVersion?: string;
|
|
11
|
+
build?: string;
|
|
12
|
+
};
|
|
13
|
+
export type ExpoApplicationModule = {
|
|
14
|
+
nativeApplicationVersion?: string | null;
|
|
15
|
+
nativeBuildVersion?: string | null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* `expo-application` is an OPTIONAL peer dependency. Required inside
|
|
19
|
+
* try/catch, so Metro treats it as optional and an app without it still
|
|
20
|
+
* bundles (same pattern as `expo-image` in `infra/preload/preloadAssets.ts`).
|
|
21
|
+
*/
|
|
22
|
+
export declare const loadExpoApplication: () => ExpoApplicationModule | null;
|
|
23
|
+
/** Never throws: no module, a throwing module, or null values all mean "unknown". */
|
|
24
|
+
export declare const readNativeAppInfo: (load?: () => ExpoApplicationModule | null) => NativeAppInfo;
|
|
25
|
+
export declare const ENVIRONMENT_MAX_LENGTH = 32;
|
|
26
|
+
export declare const defaultEnvironment: (isSandbox: boolean | undefined, isDev?: boolean) => "sandbox" | "development" | "production";
|
|
27
|
+
/**
|
|
28
|
+
* Developer-chosen, so it is normalized before it leaves the device: it must
|
|
29
|
+
* not blow up the server's cardinality, and a typo in case or punctuation must
|
|
30
|
+
* not split one environment into two.
|
|
31
|
+
*/
|
|
32
|
+
export declare const normalizeEnvironment: (raw: unknown, fallback: string) => string;
|
|
33
|
+
export type IdentityOptions = {
|
|
34
|
+
appVersion?: string;
|
|
35
|
+
build?: string;
|
|
36
|
+
environment?: string;
|
|
37
|
+
isSandbox?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** Host option → expo-application → omitted, for appVersion and build. */
|
|
40
|
+
export declare const resolveRequestIdentity: (options: IdentityOptions, native: NativeAppInfo, isDev?: boolean) => Record<string, string>;
|
|
41
|
+
//# sourceMappingURL=requestIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestIdentity.d.ts","sourceRoot":"","sources":["../src/requestIdentity.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,MAAM,MAAM,aAAa,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG;IAClC,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,qBAAqB,GAAG,IAM9D,CAAC;AAKF,qFAAqF;AACrF,eAAO,MAAM,iBAAiB,GAC5B,OAAM,MAAM,qBAAqB,GAAG,IAA0B,KAC7D,aAWF,CAAC;AAEF,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAIzC,eAAO,MAAM,kBAAkB,GAC7B,WAAW,OAAO,GAAG,SAAS,EAC9B,QAAO,OAAsB,KAC5B,SAAS,GAAG,aAAa,GAAG,YAC+B,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,OAAO,EAAE,UAAU,MAAM,KAAG,MAOrE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,sBAAsB,GACjC,SAAS,eAAe,EACxB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAYvB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRequestIdentity = exports.normalizeEnvironment = exports.defaultEnvironment = exports.ENVIRONMENT_MAX_LENGTH = exports.readNativeAppInfo = exports.loadExpoApplication = void 0;
|
|
4
|
+
const version_1 = require("./version");
|
|
5
|
+
/**
|
|
6
|
+
* `expo-application` is an OPTIONAL peer dependency. Required inside
|
|
7
|
+
* try/catch, so Metro treats it as optional and an app without it still
|
|
8
|
+
* bundles (same pattern as `expo-image` in `infra/preload/preloadAssets.ts`).
|
|
9
|
+
*/
|
|
10
|
+
const loadExpoApplication = () => {
|
|
11
|
+
try {
|
|
12
|
+
return require("expo-application");
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.loadExpoApplication = loadExpoApplication;
|
|
19
|
+
const nonEmpty = (v) => typeof v === "string" && v.trim() !== "" ? v.trim() : undefined;
|
|
20
|
+
/** Never throws: no module, a throwing module, or null values all mean "unknown". */
|
|
21
|
+
const readNativeAppInfo = (load = exports.loadExpoApplication) => {
|
|
22
|
+
try {
|
|
23
|
+
const mod = load();
|
|
24
|
+
if (!mod)
|
|
25
|
+
return {};
|
|
26
|
+
return {
|
|
27
|
+
appVersion: nonEmpty(mod.nativeApplicationVersion),
|
|
28
|
+
build: nonEmpty(mod.nativeBuildVersion),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.readNativeAppInfo = readNativeAppInfo;
|
|
36
|
+
exports.ENVIRONMENT_MAX_LENGTH = 32;
|
|
37
|
+
const isDevBuild = () => typeof __DEV__ !== "undefined" && __DEV__ === true;
|
|
38
|
+
const defaultEnvironment = (isSandbox, isDev = isDevBuild()) => isSandbox ? "sandbox" : isDev ? "development" : "production";
|
|
39
|
+
exports.defaultEnvironment = defaultEnvironment;
|
|
40
|
+
/**
|
|
41
|
+
* Developer-chosen, so it is normalized before it leaves the device: it must
|
|
42
|
+
* not blow up the server's cardinality, and a typo in case or punctuation must
|
|
43
|
+
* not split one environment into two.
|
|
44
|
+
*/
|
|
45
|
+
const normalizeEnvironment = (raw, fallback) => {
|
|
46
|
+
if (typeof raw !== "string")
|
|
47
|
+
return fallback;
|
|
48
|
+
const cleaned = raw
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.replace(/[^a-z0-9_-]/g, "")
|
|
51
|
+
.slice(0, exports.ENVIRONMENT_MAX_LENGTH);
|
|
52
|
+
return cleaned || fallback;
|
|
53
|
+
};
|
|
54
|
+
exports.normalizeEnvironment = normalizeEnvironment;
|
|
55
|
+
/** Host option → expo-application → omitted, for appVersion and build. */
|
|
56
|
+
const resolveRequestIdentity = (options, native, isDev) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const out = {};
|
|
59
|
+
const appVersion = (_a = nonEmpty(options.appVersion)) !== null && _a !== void 0 ? _a : native.appVersion;
|
|
60
|
+
const build = (_b = nonEmpty(options.build)) !== null && _b !== void 0 ? _b : native.build;
|
|
61
|
+
if (appVersion)
|
|
62
|
+
out.appVersion = appVersion;
|
|
63
|
+
if (build)
|
|
64
|
+
out.build = build;
|
|
65
|
+
out.sdkVersion = version_1.SDK_VERSION;
|
|
66
|
+
out.environment = (0, exports.normalizeEnvironment)(options.environment, (0, exports.defaultEnvironment)(options.isSandbox, isDev));
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
exports.resolveRequestIdentity = resolveRequestIdentity;
|
|
70
|
+
//# sourceMappingURL=requestIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestIdentity.js","sourceRoot":"","sources":["../src/requestIdentity.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAoBxC;;;;GAIG;AACI,MAAM,mBAA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,GAAY,EAAE,QAAgB,EAAU,EAAE;IAC7E,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC7C,MAAM,OAAO,GAAG,GAAG;SAChB,WAAW,EAAE;SACb,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,KAAK,CAAC,CAAC,EAAE,8BAAsB,CAAC,CAAC;IACpC,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC7B,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AASF,0EAA0E;AACnE,MAAM,sBAAsB,GAAG,CACpC,OAAwB,EACxB,MAAqB,EACrB,KAAe,EACS,EAAE;;IAC1B,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,MAAA,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,mCAAI,MAAM,CAAC,UAAU,CAAC;IACrE,MAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAI,MAAM,CAAC,KAAK,CAAC;IACtD,IAAI,UAAU;QAAE,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC;IAC5C,IAAI,KAAK;QAAE,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAC7B,GAAG,CAAC,UAAU,GAAG,qBAAW,CAAC;IAC7B,GAAG,CAAC,WAAW,GAAG,IAAA,4BAAoB,EACpC,OAAO,CAAC,WAAW,EACnB,IAAA,0BAAkB,EAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAC7C,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -15,7 +15,24 @@ export type BaseStepType = {
|
|
|
15
15
|
nextStep?: NextStep;
|
|
16
16
|
};
|
|
17
17
|
export type OnboardingStudioClientOptions<StepType extends BaseStepType = BaseStepType> = {
|
|
18
|
+
/**
|
|
19
|
+
* The app's version, e.g. "2.3.0". Optional: when omitted the SDK reads it
|
|
20
|
+
* from `expo-application` if that package is installed. Pass it only to
|
|
21
|
+
* override what the device reports.
|
|
22
|
+
*/
|
|
18
23
|
appVersion?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The app's build number, e.g. "45". Same precedence as `appVersion`: this
|
|
26
|
+
* option, else `expo-application`, else not sent.
|
|
27
|
+
*/
|
|
28
|
+
build?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Free text naming where this build runs, e.g. "staging". Defaults to
|
|
31
|
+
* "sandbox" when `isSandbox`, "development" under `__DEV__`, else
|
|
32
|
+
* "production". Lower-cased, reduced to `[a-z0-9_-]` and cut to 32
|
|
33
|
+
* characters before it is sent. An audience rule can target it.
|
|
34
|
+
*/
|
|
35
|
+
environment?: string;
|
|
19
36
|
isSandbox?: boolean;
|
|
20
37
|
baseUrl?: string;
|
|
21
38
|
fallbackOnboarding?: Onboarding<StepType>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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,YAAY,GAAG,YAAY,IAC1C;IACF,UAAU,CAAC,EAAE,MA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AkB,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"}
|
|
@@ -6,27 +6,28 @@
|
|
|
6
6
|
* `RESERVED_AUDIENCE_VARS`, which strips them because they are server-owned (a
|
|
7
7
|
* client supplying `now` is self-selecting into a time-gated audience).
|
|
8
8
|
*
|
|
9
|
-
* The
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* The others are the params the client writes on every request: `projectId`,
|
|
10
|
+
* `platform`, the request identity (`appVersion`, `build`, `sdkVersion`,
|
|
11
|
+
* `environment` — see `requestIdentity.ts`), `draft`, `locale`, `omitNulls`.
|
|
12
|
+
* The client adds user params FIRST, then writes its own with
|
|
13
|
+
* `URLSearchParams.set`, which replaces any same-named user param (and removes
|
|
14
|
+
* a user `appVersion`/`build` when it has none of its own to send):
|
|
12
15
|
*
|
|
13
16
|
* Object.entries(userDefinedParams).forEach(([k, v]) => urlParams.append(k, v));
|
|
14
|
-
* urlParams.
|
|
17
|
+
* urlParams.set("projectId", this.projectId);
|
|
15
18
|
*
|
|
16
|
-
* `
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* it.
|
|
19
|
+
* It used to `append` them, and the server's two readers disagree about which
|
|
20
|
+
* duplicate wins: `url.searchParams.get("projectId")` returns the FIRST
|
|
21
|
+
* occurrence (the user's value — so the request resolved the wrong project, or
|
|
22
|
+
* 400ed), while `Object.fromEntries(...)` is last-wins. `set` closes that on the
|
|
23
|
+
* wire, but a user property that silently loses to the SDK's value is still a
|
|
24
|
+
* bug in the host, so this is where it gets refused.
|
|
23
25
|
*
|
|
24
26
|
* A store whose whole purpose is to let a host name keys freely makes that a
|
|
25
|
-
* plausible accident
|
|
26
|
-
*
|
|
27
|
-
* at the call site responsible.
|
|
27
|
+
* plausible accident. Refusing — rather than prefixing or escaping — keeps the
|
|
28
|
+
* wire format unchanged and puts the warning at the call site responsible.
|
|
28
29
|
*/
|
|
29
|
-
export declare const RESERVED_USER_PROPERTY_KEYS: readonly ["projectId", "platform", "appVersion", "draft", "locale", "omitNulls", "moment", "now"];
|
|
30
|
+
export declare const RESERVED_USER_PROPERTY_KEYS: readonly ["projectId", "platform", "appVersion", "build", "sdkVersion", "environment", "draft", "locale", "omitNulls", "moment", "now"];
|
|
30
31
|
export type ReservedUserPropertyKey = (typeof RESERVED_USER_PROPERTY_KEYS)[number];
|
|
31
32
|
/** Exact match, never a prefix — `projectIdentifier` is a perfectly good property. */
|
|
32
33
|
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
|
|
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"}
|
|
@@ -9,30 +9,34 @@ exports.isReservedUserPropertyKey = exports.RESERVED_USER_PROPERTY_KEYS = void 0
|
|
|
9
9
|
* `RESERVED_AUDIENCE_VARS`, which strips them because they are server-owned (a
|
|
10
10
|
* client supplying `now` is self-selecting into a time-gated audience).
|
|
11
11
|
*
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* The others are the params the client writes on every request: `projectId`,
|
|
13
|
+
* `platform`, the request identity (`appVersion`, `build`, `sdkVersion`,
|
|
14
|
+
* `environment` — see `requestIdentity.ts`), `draft`, `locale`, `omitNulls`.
|
|
15
|
+
* The client adds user params FIRST, then writes its own with
|
|
16
|
+
* `URLSearchParams.set`, which replaces any same-named user param (and removes
|
|
17
|
+
* a user `appVersion`/`build` when it has none of its own to send):
|
|
15
18
|
*
|
|
16
19
|
* Object.entries(userDefinedParams).forEach(([k, v]) => urlParams.append(k, v));
|
|
17
|
-
* urlParams.
|
|
20
|
+
* urlParams.set("projectId", this.projectId);
|
|
18
21
|
*
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* it.
|
|
22
|
+
* It used to `append` them, and the server's two readers disagree about which
|
|
23
|
+
* duplicate wins: `url.searchParams.get("projectId")` returns the FIRST
|
|
24
|
+
* occurrence (the user's value — so the request resolved the wrong project, or
|
|
25
|
+
* 400ed), while `Object.fromEntries(...)` is last-wins. `set` closes that on the
|
|
26
|
+
* wire, but a user property that silently loses to the SDK's value is still a
|
|
27
|
+
* bug in the host, so this is where it gets refused.
|
|
26
28
|
*
|
|
27
29
|
* A store whose whole purpose is to let a host name keys freely makes that a
|
|
28
|
-
* plausible accident
|
|
29
|
-
*
|
|
30
|
-
* at the call site responsible.
|
|
30
|
+
* plausible accident. Refusing — rather than prefixing or escaping — keeps the
|
|
31
|
+
* wire format unchanged and puts the warning at the call site responsible.
|
|
31
32
|
*/
|
|
32
33
|
exports.RESERVED_USER_PROPERTY_KEYS = [
|
|
33
34
|
"projectId",
|
|
34
35
|
"platform",
|
|
35
36
|
"appVersion",
|
|
37
|
+
"build",
|
|
38
|
+
"sdkVersion",
|
|
39
|
+
"environment",
|
|
36
40
|
"draft",
|
|
37
41
|
"locale",
|
|
38
42
|
"omitNulls",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reserved.js","sourceRoot":"","sources":["../../src/userProperties/reserved.ts"],"names":[],"mappings":";;;AAAA
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This package's version, sent as `sdkVersion` on every request.
|
|
3
|
+
*
|
|
4
|
+
* A committed constant rather than a read of `package.json`: `rootDir` is
|
|
5
|
+
* `./src`, so the build cannot import it, and reading it at runtime would ship
|
|
6
|
+
* the file. `npm run check:versions` fails when this disagrees with
|
|
7
|
+
* `package.json`, and the `bump-version` skill updates it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SDK_VERSION = "1.77.0";
|
|
10
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,WAAW,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDK_VERSION = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This package's version, sent as `sdkVersion` on every request.
|
|
6
|
+
*
|
|
7
|
+
* A committed constant rather than a read of `package.json`: `rootDir` is
|
|
8
|
+
* `./src`, so the build cannot import it, and reading it at runtime would ship
|
|
9
|
+
* the file. `npm run check:versions` fails when this disagrees with
|
|
10
|
+
* `package.json`, and the `bump-version` skill updates it.
|
|
11
|
+
*/
|
|
12
|
+
exports.SDK_VERSION = "1.77.0";
|
|
13
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACU,QAAA,WAAW,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.77.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",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"vitest": "^4.1.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
+
"expo-application": "*",
|
|
42
43
|
"expo-font": "*",
|
|
43
44
|
"expo-image": "*",
|
|
44
45
|
"expo-router": ">=3.0.0",
|
|
@@ -46,6 +47,9 @@
|
|
|
46
47
|
"react-native": "*"
|
|
47
48
|
},
|
|
48
49
|
"peerDependenciesMeta": {
|
|
50
|
+
"expo-application": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
49
53
|
"expo-font": {
|
|
50
54
|
"optional": true
|
|
51
55
|
},
|
|
@@ -19,11 +19,43 @@ import {
|
|
|
19
19
|
} from "./paywalls/types";
|
|
20
20
|
|
|
21
21
|
import { Platform } from "react-native";
|
|
22
|
+
import { readNativeAppInfo, resolveRequestIdentity } from "./requestIdentity";
|
|
22
23
|
|
|
23
24
|
export class OnboardingStudioClient {
|
|
24
25
|
private baseUrl: string;
|
|
25
26
|
public projectId: string;
|
|
26
27
|
public options: OnboardingStudioClientOptions;
|
|
28
|
+
private identity?: Record<string, string>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
32
|
+
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
33
|
+
* can change while the process runs. Deliberately NOT part of any cache key:
|
|
34
|
+
* a key that changed with every app update would leave a user who is offline
|
|
35
|
+
* right after updating with no cached payload, and would stop a custom
|
|
36
|
+
* `cacheKey` from pinning content across updates.
|
|
37
|
+
*/
|
|
38
|
+
identityParams(): Record<string, string> {
|
|
39
|
+
if (!this.identity) {
|
|
40
|
+
this.identity = resolveRequestIdentity(this.options, readNativeAppInfo());
|
|
41
|
+
}
|
|
42
|
+
return this.identity;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Writes the identity onto a querystring that already holds the user params.
|
|
47
|
+
* `appVersion` and `build` are removed first, because the identity omits them
|
|
48
|
+
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
49
|
+
* would then leave a same-named user param on the wire (a property persisted
|
|
50
|
+
* before these names were reserved is re-read without a reserved-key check).
|
|
51
|
+
*/
|
|
52
|
+
private writeIdentity(urlParams: URLSearchParams): void {
|
|
53
|
+
urlParams.delete("appVersion");
|
|
54
|
+
urlParams.delete("build");
|
|
55
|
+
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
56
|
+
urlParams.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
27
59
|
|
|
28
60
|
constructor(projectId: string, options: OnboardingStudioClientOptions) {
|
|
29
61
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
@@ -80,21 +112,20 @@ export class OnboardingStudioClient {
|
|
|
80
112
|
});
|
|
81
113
|
}
|
|
82
114
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
115
|
+
// SDK-owned keys use `set`, never `append`: the server reads each with
|
|
116
|
+
// `searchParams.get`, which returns the FIRST occurrence, so an appended
|
|
117
|
+
// value would lose to a same-named user param added above.
|
|
118
|
+
urlParams.set("projectId", this.projectId);
|
|
119
|
+
urlParams.set("platform", Platform.OS);
|
|
120
|
+
this.writeIdentity(urlParams);
|
|
90
121
|
|
|
91
122
|
if (isSandbox) {
|
|
92
|
-
urlParams.
|
|
123
|
+
urlParams.set("draft", "true");
|
|
93
124
|
}
|
|
94
125
|
|
|
95
126
|
// Add onboardingOptions to URL
|
|
96
127
|
if (onboardingOptions?.locale) {
|
|
97
|
-
urlParams.
|
|
128
|
+
urlParams.set("locale", onboardingOptions.locale);
|
|
98
129
|
}
|
|
99
130
|
|
|
100
131
|
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
@@ -171,27 +202,24 @@ export class OnboardingStudioClient {
|
|
|
171
202
|
});
|
|
172
203
|
}
|
|
173
204
|
|
|
174
|
-
|
|
175
|
-
urlParams.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (appVersion) {
|
|
179
|
-
urlParams.append("appVersion", appVersion);
|
|
180
|
-
}
|
|
205
|
+
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
206
|
+
urlParams.set("projectId", this.projectId);
|
|
207
|
+
urlParams.set("platform", Platform.OS);
|
|
208
|
+
this.writeIdentity(urlParams);
|
|
181
209
|
|
|
182
210
|
if (isSandbox) {
|
|
183
|
-
urlParams.
|
|
211
|
+
urlParams.set("draft", "true");
|
|
184
212
|
}
|
|
185
213
|
|
|
186
214
|
// Add paywallOptions to URL
|
|
187
215
|
if (paywallOptions?.locale) {
|
|
188
|
-
urlParams.
|
|
216
|
+
urlParams.set("locale", paywallOptions.locale);
|
|
189
217
|
}
|
|
190
218
|
|
|
191
219
|
// Narrows the response to a single paywall. Omitted unless explicitly
|
|
192
220
|
// requested — see the method doc above.
|
|
193
221
|
if (paywallOptions?.moment) {
|
|
194
|
-
urlParams.
|
|
222
|
+
urlParams.set("moment", paywallOptions.moment);
|
|
195
223
|
}
|
|
196
224
|
|
|
197
225
|
// Deliberately NOT sending spec §6.1's `omitNulls=true`: it's a
|
|
@@ -209,3 +209,33 @@ describe("OnboardingStudioClient.clearCache", () => {
|
|
|
209
209
|
warn.mockRestore();
|
|
210
210
|
});
|
|
211
211
|
});
|
|
212
|
+
|
|
213
|
+
describe("cache key and request identity", () => {
|
|
214
|
+
beforeEach(() => {
|
|
215
|
+
getItem.mockReset();
|
|
216
|
+
setItem.mockReset();
|
|
217
|
+
getItem.mockResolvedValue(null);
|
|
218
|
+
setItem.mockResolvedValue(undefined);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// The SDK's own identity is sent on the request but must NOT enter the cache
|
|
222
|
+
// key: a key that changed with every app update would leave a returning user
|
|
223
|
+
// who is offline right after updating with no cached onboarding, and would stop a
|
|
224
|
+
// custom `cacheKey` from pinning content across updates.
|
|
225
|
+
const withIdentity = (client: any, identity: Record<string, string>) => {
|
|
226
|
+
client.identityParams = () => identity;
|
|
227
|
+
return client;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
it("same cache key across builds when only the SDK-derived identity changes", async () => {
|
|
231
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
232
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding }), { appVersion: "2.4.0", build: "46", sdkVersion: "1.78.0", environment: "production" }));
|
|
233
|
+
const keys = setItem.mock.calls.map(([key]) => key);
|
|
234
|
+
expect(keys).toEqual([CACHE_KEY, CACHE_KEY]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("custom cacheKey is unaffected by identity", async () => {
|
|
238
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding, cacheKey: CUSTOM_KEY }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
239
|
+
expect(setItem).toHaveBeenCalledWith(CUSTOM_CACHE_KEY, JSON.stringify(realOnboarding));
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
|
|
4
|
+
vi.mock("@react-native-async-storage/async-storage", () => ({
|
|
5
|
+
default: {
|
|
6
|
+
getItem: vi.fn(async () => null),
|
|
7
|
+
setItem: vi.fn(async () => {}),
|
|
8
|
+
removeItem: vi.fn(async () => {}),
|
|
9
|
+
getAllKeys: vi.fn(async () => []),
|
|
10
|
+
multiRemove: vi.fn(async () => {}),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
// The client reads expo-application through `readNativeAppInfo`; replace only
|
|
14
|
+
// that export so each test chooses what the device reports.
|
|
15
|
+
const native = vi.hoisted(() => ({ info: {} as { appVersion?: string; build?: string } }));
|
|
16
|
+
vi.mock("../requestIdentity", async (importOriginal) => ({
|
|
17
|
+
...(await importOriginal<typeof import("../requestIdentity")>()),
|
|
18
|
+
readNativeAppInfo: () => native.info,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
import { OnboardingStudioClient } from "../OnboardingStudioClient";
|
|
22
|
+
import { SDK_VERSION } from "../version";
|
|
23
|
+
|
|
24
|
+
const fakeResponse = (body: unknown) => ({
|
|
25
|
+
ok: true,
|
|
26
|
+
status: 200,
|
|
27
|
+
statusText: "OK",
|
|
28
|
+
json: async () => body,
|
|
29
|
+
headers: { get: () => null },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const fetches = {
|
|
33
|
+
getSteps: (c: OnboardingStudioClient, params?: Record<string, string>) =>
|
|
34
|
+
c.getSteps({ locale: "en" }, params),
|
|
35
|
+
getPaywalls: (c: OnboardingStudioClient, params?: Record<string, string>) =>
|
|
36
|
+
c.getPaywalls({ locale: "en" }, params),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe.each(Object.entries(fetches))("%s request identity", (_name, fetchWith) => {
|
|
40
|
+
let fetchMock: ReturnType<typeof vi.fn>;
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
native.info = {};
|
|
44
|
+
fetchMock = vi.fn().mockResolvedValue(fakeResponse({ metadata: {}, steps: [], paywalls: {} }));
|
|
45
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
46
|
+
vi.spyOn(console, "info").mockImplementation(() => {});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
vi.unstubAllGlobals();
|
|
51
|
+
vi.restoreAllMocks();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const sent = () => new URL(fetchMock.mock.calls[0][0] as string).searchParams;
|
|
55
|
+
|
|
56
|
+
it("sends appVersion and build from expo-application, plus sdkVersion and environment", async () => {
|
|
57
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
58
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}));
|
|
59
|
+
expect(sent().get("appVersion")).toBe("2.3.0");
|
|
60
|
+
expect(sent().get("build")).toBe("45");
|
|
61
|
+
expect(sent().get("sdkVersion")).toBe(SDK_VERSION);
|
|
62
|
+
expect(sent().get("environment")).toBe("production");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("host appVersion and build win over expo-application", async () => {
|
|
66
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
67
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { appVersion: "3.0.0", build: "300" }));
|
|
68
|
+
expect(sent().get("appVersion")).toBe("3.0.0");
|
|
69
|
+
expect(sent().get("build")).toBe("300");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("omits appVersion and build when neither source has them", async () => {
|
|
73
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}));
|
|
74
|
+
expect(sent().has("appVersion")).toBe(false);
|
|
75
|
+
expect(sent().has("build")).toBe(false);
|
|
76
|
+
expect(sent().get("sdkVersion")).toBe(SDK_VERSION);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("environment: sandbox in sandbox mode, normalized when the host sets it", async () => {
|
|
80
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { isSandbox: true }));
|
|
81
|
+
expect(sent().get("environment")).toBe("sandbox");
|
|
82
|
+
fetchMock.mockClear();
|
|
83
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { environment: "Staging Env!" }));
|
|
84
|
+
expect(sent().get("environment")).toBe("stagingenv");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("SDK-owned keys replace a same-named user param (the server reads the first occurrence)", async () => {
|
|
88
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
89
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}), {
|
|
90
|
+
build: "from-user",
|
|
91
|
+
environment: "from-user",
|
|
92
|
+
sdkVersion: "from-user",
|
|
93
|
+
projectId: "other",
|
|
94
|
+
plan: "pro",
|
|
95
|
+
});
|
|
96
|
+
expect(sent().getAll("build")).toEqual(["45"]);
|
|
97
|
+
expect(sent().getAll("environment")).toEqual(["production"]);
|
|
98
|
+
expect(sent().getAll("sdkVersion")).toEqual([SDK_VERSION]);
|
|
99
|
+
expect(sent().getAll("projectId")).toEqual(["proj-1"]);
|
|
100
|
+
expect(sent().get("plan")).toBe("pro");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("a user appVersion or build never reaches the wire, even when the SDK has none to send", async () => {
|
|
104
|
+
// A property persisted before these names were reserved is re-read from
|
|
105
|
+
// disk without a reserved-key check, so it can still arrive here.
|
|
106
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}), {
|
|
107
|
+
appVersion: "from-user",
|
|
108
|
+
build: "from-user",
|
|
109
|
+
plan: "pro",
|
|
110
|
+
});
|
|
111
|
+
expect(sent().has("appVersion")).toBe(false);
|
|
112
|
+
expect(sent().has("build")).toBe(false);
|
|
113
|
+
expect(sent().get("plan")).toBe("pro");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
defaultEnvironment,
|
|
6
|
+
normalizeEnvironment,
|
|
7
|
+
readNativeAppInfo,
|
|
8
|
+
resolveRequestIdentity,
|
|
9
|
+
} from "../requestIdentity";
|
|
10
|
+
import { SDK_VERSION } from "../version";
|
|
11
|
+
|
|
12
|
+
describe("SDK_VERSION", () => {
|
|
13
|
+
it("equals the package version", () => {
|
|
14
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "../..", "package.json"), "utf8"));
|
|
15
|
+
expect(SDK_VERSION).toBe(pkg.version);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("readNativeAppInfo", () => {
|
|
20
|
+
it("reads version and build from expo-application", () => {
|
|
21
|
+
expect(
|
|
22
|
+
readNativeAppInfo(() => ({ nativeApplicationVersion: "2.3.0", nativeBuildVersion: "45" })),
|
|
23
|
+
).toEqual({ appVersion: "2.3.0", build: "45" });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("is empty when expo-application is not installed", () => {
|
|
27
|
+
expect(readNativeAppInfo(() => null)).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("is empty, without throwing, when loading expo-application throws", () => {
|
|
31
|
+
expect(
|
|
32
|
+
readNativeAppInfo(() => {
|
|
33
|
+
throw new Error("Cannot find module 'expo-application'");
|
|
34
|
+
}),
|
|
35
|
+
).toEqual({});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("omits null and blank values (web, or an unlinked native module)", () => {
|
|
39
|
+
expect(
|
|
40
|
+
readNativeAppInfo(() => ({ nativeApplicationVersion: null, nativeBuildVersion: " " })),
|
|
41
|
+
).toEqual({ appVersion: undefined, build: undefined });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("the default loader never throws", () => {
|
|
45
|
+
expect(() => readNativeAppInfo()).not.toThrow();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("defaultEnvironment", () => {
|
|
50
|
+
it("is sandbox in sandbox mode, whatever __DEV__ says", () => {
|
|
51
|
+
expect(defaultEnvironment(true, true)).toBe("sandbox");
|
|
52
|
+
expect(defaultEnvironment(true, false)).toBe("sandbox");
|
|
53
|
+
});
|
|
54
|
+
it("is development under __DEV__, production otherwise", () => {
|
|
55
|
+
expect(defaultEnvironment(false, true)).toBe("development");
|
|
56
|
+
expect(defaultEnvironment(undefined, false)).toBe("production");
|
|
57
|
+
});
|
|
58
|
+
it("reads __DEV__ when not told, and treats an undefined __DEV__ as production", () => {
|
|
59
|
+
expect(defaultEnvironment(undefined)).toBe("production");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("normalizeEnvironment", () => {
|
|
64
|
+
it("lower-cases and drops characters outside [a-z0-9_-]", () => {
|
|
65
|
+
expect(normalizeEnvironment("Staging Env!", "production")).toBe("stagingenv");
|
|
66
|
+
expect(normalizeEnvironment("qa_2-eu", "production")).toBe("qa_2-eu");
|
|
67
|
+
});
|
|
68
|
+
it("caps at 32 characters", () => {
|
|
69
|
+
expect(normalizeEnvironment("a".repeat(200), "production")).toBe("a".repeat(32));
|
|
70
|
+
});
|
|
71
|
+
it("falls back when nothing survives or the value is not a string", () => {
|
|
72
|
+
expect(normalizeEnvironment(" ", "production")).toBe("production");
|
|
73
|
+
expect(normalizeEnvironment("!!!", "sandbox")).toBe("sandbox");
|
|
74
|
+
expect(normalizeEnvironment(undefined, "development")).toBe("development");
|
|
75
|
+
expect(normalizeEnvironment(42, "production")).toBe("production");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("resolveRequestIdentity", () => {
|
|
80
|
+
const native = { appVersion: "2.3.0", build: "45" };
|
|
81
|
+
|
|
82
|
+
it("host values win over expo-application", () => {
|
|
83
|
+
expect(resolveRequestIdentity({ appVersion: "9.9.9", build: "1" }, native, false)).toEqual({
|
|
84
|
+
appVersion: "9.9.9",
|
|
85
|
+
build: "1",
|
|
86
|
+
sdkVersion: SDK_VERSION,
|
|
87
|
+
environment: "production",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("expo-application fills what the host left out, and a blank host value counts as left out", () => {
|
|
92
|
+
expect(resolveRequestIdentity({ appVersion: " " }, native, false)).toEqual({
|
|
93
|
+
appVersion: "2.3.0",
|
|
94
|
+
build: "45",
|
|
95
|
+
sdkVersion: SDK_VERSION,
|
|
96
|
+
environment: "production",
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("omits appVersion and build when neither source has them", () => {
|
|
101
|
+
expect(resolveRequestIdentity({}, {}, false)).toEqual({
|
|
102
|
+
sdkVersion: SDK_VERSION,
|
|
103
|
+
environment: "production",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("normalizes a host environment and defaults from the mode", () => {
|
|
108
|
+
expect(resolveRequestIdentity({ environment: "Staging" }, {}, false).environment).toBe("staging");
|
|
109
|
+
expect(resolveRequestIdentity({ isSandbox: true }, {}, false).environment).toBe("sandbox");
|
|
110
|
+
expect(resolveRequestIdentity({}, {}, true).environment).toBe("development");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -353,3 +353,33 @@ describe("OnboardingStudioClient.clearCache", () => {
|
|
|
353
353
|
expect(multiRemove).toHaveBeenCalledWith([scoped]);
|
|
354
354
|
});
|
|
355
355
|
});
|
|
356
|
+
|
|
357
|
+
describe("getPaywallsQuery cache key and request identity", () => {
|
|
358
|
+
beforeEach(() => {
|
|
359
|
+
getItem.mockReset();
|
|
360
|
+
setItem.mockReset();
|
|
361
|
+
getItem.mockResolvedValue(null);
|
|
362
|
+
setItem.mockResolvedValue(undefined);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// The SDK's own identity is sent on the request but must NOT enter the cache
|
|
366
|
+
// key: a key that changed with every app update would leave a returning user
|
|
367
|
+
// who is offline right after updating with no cached catalog, and would stop a
|
|
368
|
+
// custom `cacheKey` from pinning content across updates.
|
|
369
|
+
const withIdentity = (client: any, identity: Record<string, string>) => {
|
|
370
|
+
client.identityParams = () => identity;
|
|
371
|
+
return client;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
it("same cache key across builds when only the SDK-derived identity changes", async () => {
|
|
375
|
+
await run(withIdentity(makeClient({ isSandbox: false, data: catalog }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
376
|
+
await run(withIdentity(makeClient({ isSandbox: false, data: catalog }), { appVersion: "2.4.0", build: "46", sdkVersion: "1.78.0", environment: "production" }));
|
|
377
|
+
const keys = setItem.mock.calls.map(([key]) => key);
|
|
378
|
+
expect(keys).toEqual([CACHE_KEY, CACHE_KEY]);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("custom cacheKey is unaffected by identity", async () => {
|
|
382
|
+
await run(withIdentity(makeClient({ isSandbox: false, cacheKey: CUSTOM_KEY, data: catalog }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
383
|
+
expect(setItem).toHaveBeenCalledWith(CUSTOM_CACHE_KEY, JSON.stringify(catalog));
|
|
384
|
+
});
|
|
385
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { SDK_VERSION } from "./version";
|
|
2
|
+
|
|
3
|
+
declare const __DEV__: boolean;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The identity every request carries, so the server can tell which app
|
|
7
|
+
* version, build, SDK and environment it served: `appVersion`, `build`,
|
|
8
|
+
* `sdkVersion`, `environment`.
|
|
9
|
+
*
|
|
10
|
+
* These are ordinary query params, so an audience rule can target them too
|
|
11
|
+
* (`environment == "staging"`, a build range).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type NativeAppInfo = { appVersion?: string; build?: string };
|
|
15
|
+
|
|
16
|
+
export type ExpoApplicationModule = {
|
|
17
|
+
nativeApplicationVersion?: string | null;
|
|
18
|
+
nativeBuildVersion?: string | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `expo-application` is an OPTIONAL peer dependency. Required inside
|
|
23
|
+
* try/catch, so Metro treats it as optional and an app without it still
|
|
24
|
+
* bundles (same pattern as `expo-image` in `infra/preload/preloadAssets.ts`).
|
|
25
|
+
*/
|
|
26
|
+
export const loadExpoApplication = (): ExpoApplicationModule | null => {
|
|
27
|
+
try {
|
|
28
|
+
return require("expo-application") as ExpoApplicationModule;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const nonEmpty = (v: unknown): string | undefined =>
|
|
35
|
+
typeof v === "string" && v.trim() !== "" ? v.trim() : undefined;
|
|
36
|
+
|
|
37
|
+
/** Never throws: no module, a throwing module, or null values all mean "unknown". */
|
|
38
|
+
export const readNativeAppInfo = (
|
|
39
|
+
load: () => ExpoApplicationModule | null = loadExpoApplication,
|
|
40
|
+
): NativeAppInfo => {
|
|
41
|
+
try {
|
|
42
|
+
const mod = load();
|
|
43
|
+
if (!mod) return {};
|
|
44
|
+
return {
|
|
45
|
+
appVersion: nonEmpty(mod.nativeApplicationVersion),
|
|
46
|
+
build: nonEmpty(mod.nativeBuildVersion),
|
|
47
|
+
};
|
|
48
|
+
} catch {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const ENVIRONMENT_MAX_LENGTH = 32;
|
|
54
|
+
|
|
55
|
+
const isDevBuild = (): boolean => typeof __DEV__ !== "undefined" && __DEV__ === true;
|
|
56
|
+
|
|
57
|
+
export const defaultEnvironment = (
|
|
58
|
+
isSandbox: boolean | undefined,
|
|
59
|
+
isDev: boolean = isDevBuild(),
|
|
60
|
+
): "sandbox" | "development" | "production" =>
|
|
61
|
+
isSandbox ? "sandbox" : isDev ? "development" : "production";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Developer-chosen, so it is normalized before it leaves the device: it must
|
|
65
|
+
* not blow up the server's cardinality, and a typo in case or punctuation must
|
|
66
|
+
* not split one environment into two.
|
|
67
|
+
*/
|
|
68
|
+
export const normalizeEnvironment = (raw: unknown, fallback: string): string => {
|
|
69
|
+
if (typeof raw !== "string") return fallback;
|
|
70
|
+
const cleaned = raw
|
|
71
|
+
.toLowerCase()
|
|
72
|
+
.replace(/[^a-z0-9_-]/g, "")
|
|
73
|
+
.slice(0, ENVIRONMENT_MAX_LENGTH);
|
|
74
|
+
return cleaned || fallback;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type IdentityOptions = {
|
|
78
|
+
appVersion?: string;
|
|
79
|
+
build?: string;
|
|
80
|
+
environment?: string;
|
|
81
|
+
isSandbox?: boolean;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Host option → expo-application → omitted, for appVersion and build. */
|
|
85
|
+
export const resolveRequestIdentity = (
|
|
86
|
+
options: IdentityOptions,
|
|
87
|
+
native: NativeAppInfo,
|
|
88
|
+
isDev?: boolean,
|
|
89
|
+
): Record<string, string> => {
|
|
90
|
+
const out: Record<string, string> = {};
|
|
91
|
+
const appVersion = nonEmpty(options.appVersion) ?? native.appVersion;
|
|
92
|
+
const build = nonEmpty(options.build) ?? native.build;
|
|
93
|
+
if (appVersion) out.appVersion = appVersion;
|
|
94
|
+
if (build) out.build = build;
|
|
95
|
+
out.sdkVersion = SDK_VERSION;
|
|
96
|
+
out.environment = normalizeEnvironment(
|
|
97
|
+
options.environment,
|
|
98
|
+
defaultEnvironment(options.isSandbox, isDev),
|
|
99
|
+
);
|
|
100
|
+
return out;
|
|
101
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -19,7 +19,24 @@ export type BaseStepType = {
|
|
|
19
19
|
export type OnboardingStudioClientOptions<
|
|
20
20
|
StepType extends BaseStepType = BaseStepType
|
|
21
21
|
> = {
|
|
22
|
+
/**
|
|
23
|
+
* The app's version, e.g. "2.3.0". Optional: when omitted the SDK reads it
|
|
24
|
+
* from `expo-application` if that package is installed. Pass it only to
|
|
25
|
+
* override what the device reports.
|
|
26
|
+
*/
|
|
22
27
|
appVersion?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The app's build number, e.g. "45". Same precedence as `appVersion`: this
|
|
30
|
+
* option, else `expo-application`, else not sent.
|
|
31
|
+
*/
|
|
32
|
+
build?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Free text naming where this build runs, e.g. "staging". Defaults to
|
|
35
|
+
* "sandbox" when `isSandbox`, "development" under `__DEV__`, else
|
|
36
|
+
* "production". Lower-cased, reduced to `[a-z0-9_-]` and cut to 32
|
|
37
|
+
* characters before it is sent. An audience rule can target it.
|
|
38
|
+
*/
|
|
39
|
+
environment?: string;
|
|
23
40
|
isSandbox?: boolean;
|
|
24
41
|
baseUrl?: string;
|
|
25
42
|
fallbackOnboarding?: Onboarding<StepType>;
|
|
@@ -14,8 +14,8 @@ describe("resolveEffectiveParams", () => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("serializes both sides to strings", () => {
|
|
17
|
-
expect(resolveEffectiveParams({
|
|
18
|
-
|
|
17
|
+
expect(resolveEffectiveParams({ level: 42 }, { days: 3, trial: true })).toEqual({
|
|
18
|
+
level: "42",
|
|
19
19
|
days: "3",
|
|
20
20
|
trial: "true",
|
|
21
21
|
});
|
|
@@ -6,7 +6,7 @@ import { applyUserPropertyPatch } from "../applyPatch";
|
|
|
6
6
|
describe("reserved keys", () => {
|
|
7
7
|
it("names every key the client itself puts on the querystring", () => {
|
|
8
8
|
expect([...RESERVED_USER_PROPERTY_KEYS].sort()).toEqual(
|
|
9
|
-
["appVersion", "draft", "locale", "moment", "now", "omitNulls", "platform", "projectId"],
|
|
9
|
+
["appVersion", "build", "draft", "environment", "locale", "moment", "now", "omitNulls", "platform", "projectId", "sdkVersion"],
|
|
10
10
|
);
|
|
11
11
|
});
|
|
12
12
|
|
|
@@ -6,30 +6,34 @@
|
|
|
6
6
|
* `RESERVED_AUDIENCE_VARS`, which strips them because they are server-owned (a
|
|
7
7
|
* client supplying `now` is self-selecting into a time-gated audience).
|
|
8
8
|
*
|
|
9
|
-
* The
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* The others are the params the client writes on every request: `projectId`,
|
|
10
|
+
* `platform`, the request identity (`appVersion`, `build`, `sdkVersion`,
|
|
11
|
+
* `environment` — see `requestIdentity.ts`), `draft`, `locale`, `omitNulls`.
|
|
12
|
+
* The client adds user params FIRST, then writes its own with
|
|
13
|
+
* `URLSearchParams.set`, which replaces any same-named user param (and removes
|
|
14
|
+
* a user `appVersion`/`build` when it has none of its own to send):
|
|
12
15
|
*
|
|
13
16
|
* Object.entries(userDefinedParams).forEach(([k, v]) => urlParams.append(k, v));
|
|
14
|
-
* urlParams.
|
|
17
|
+
* urlParams.set("projectId", this.projectId);
|
|
15
18
|
*
|
|
16
|
-
* `
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* it.
|
|
19
|
+
* It used to `append` them, and the server's two readers disagree about which
|
|
20
|
+
* duplicate wins: `url.searchParams.get("projectId")` returns the FIRST
|
|
21
|
+
* occurrence (the user's value — so the request resolved the wrong project, or
|
|
22
|
+
* 400ed), while `Object.fromEntries(...)` is last-wins. `set` closes that on the
|
|
23
|
+
* wire, but a user property that silently loses to the SDK's value is still a
|
|
24
|
+
* bug in the host, so this is where it gets refused.
|
|
23
25
|
*
|
|
24
26
|
* A store whose whole purpose is to let a host name keys freely makes that a
|
|
25
|
-
* plausible accident
|
|
26
|
-
*
|
|
27
|
-
* at the call site responsible.
|
|
27
|
+
* plausible accident. Refusing — rather than prefixing or escaping — keeps the
|
|
28
|
+
* wire format unchanged and puts the warning at the call site responsible.
|
|
28
29
|
*/
|
|
29
30
|
export const RESERVED_USER_PROPERTY_KEYS = [
|
|
30
31
|
"projectId",
|
|
31
32
|
"platform",
|
|
32
33
|
"appVersion",
|
|
34
|
+
"build",
|
|
35
|
+
"sdkVersion",
|
|
36
|
+
"environment",
|
|
33
37
|
"draft",
|
|
34
38
|
"locale",
|
|
35
39
|
"omitNulls",
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This package's version, sent as `sdkVersion` on every request.
|
|
3
|
+
*
|
|
4
|
+
* A committed constant rather than a read of `package.json`: `rootDir` is
|
|
5
|
+
* `./src`, so the build cannot import it, and reading it at runtime would ship
|
|
6
|
+
* the file. `npm run check:versions` fails when this disagrees with
|
|
7
|
+
* `package.json`, and the `bump-version` skill updates it.
|
|
8
|
+
*/
|
|
9
|
+
export const SDK_VERSION = "1.77.0";
|