@rocapine/react-native-onboarding 1.76.0 → 1.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -5
- package/dist/OnboardingStudio.d.ts +14 -1
- package/dist/OnboardingStudio.d.ts.map +1 -1
- package/dist/OnboardingStudio.js +5 -1
- package/dist/OnboardingStudio.js.map +1 -1
- package/dist/OnboardingStudioClient.d.ts +47 -0
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +117 -33
- package/dist/OnboardingStudioClient.js.map +1 -1
- package/dist/assignmentId.d.ts +107 -0
- package/dist/assignmentId.d.ts.map +1 -0
- package/dist/assignmentId.js +215 -0
- package/dist/assignmentId.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +7 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- package/dist/paywalls/observer.d.ts +2 -0
- package/dist/paywalls/observer.d.ts.map +1 -1
- package/dist/paywalls/observer.js +21 -9
- package/dist/paywalls/observer.js.map +1 -1
- package/dist/paywalls/types.d.ts +22 -0
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +34 -13
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +136 -21
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/requestIdentity.d.ts +41 -0
- package/dist/requestIdentity.d.ts.map +1 -0
- package/dist/requestIdentity.js +70 -0
- package/dist/requestIdentity.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -1
- package/dist/userProperties/reserved.d.ts +17 -15
- package/dist/userProperties/reserved.d.ts.map +1 -1
- package/dist/userProperties/reserved.js +20 -14
- package/dist/userProperties/reserved.js.map +1 -1
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/package.json +5 -1
- package/src/OnboardingStudio.ts +19 -1
- package/src/OnboardingStudioClient.ts +123 -47
- package/src/__tests__/assignmentId.clear.test.ts +413 -0
- package/src/__tests__/assignmentId.client.test.ts +288 -0
- package/src/__tests__/assignmentId.test.ts +195 -0
- package/src/__tests__/getOnboarding.query.test.ts +30 -0
- package/src/__tests__/onboardingMetadata.client.test.ts +76 -0
- package/src/__tests__/requestIdentity.client.test.ts +115 -0
- package/src/__tests__/requestIdentity.test.ts +112 -0
- package/src/assignmentId.ts +278 -0
- package/src/index.ts +1 -0
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +51 -0
- package/src/paywalls/__tests__/getPaywalls.test.ts +107 -2
- package/src/paywalls/__tests__/observer.test.ts +37 -0
- package/src/paywalls/__tests__/present.test.ts +14 -0
- package/src/paywalls/customScreens.ts +7 -0
- package/src/paywalls/observer.ts +22 -2
- package/src/paywalls/types.ts +22 -0
- package/src/products/adapters/__tests__/expoIap.contract.test.ts +305 -0
- package/src/products/adapters/expoIap.ts +171 -32
- package/src/requestIdentity.ts +101 -0
- package/src/types.ts +65 -0
- package/src/userProperties/__tests__/effectiveParams.test.ts +2 -2
- package/src/userProperties/__tests__/primitives.test.ts +1 -1
- package/src/userProperties/reserved.ts +20 -14
- package/src/version.ts +9 -0
|
@@ -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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NextStep } from "./steps/common.types";
|
|
2
|
+
import type { AssignmentIdOption } from "./assignmentId";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Base step type that all onboarding steps must conform to.
|
|
@@ -19,10 +20,54 @@ export type BaseStepType = {
|
|
|
19
20
|
export type OnboardingStudioClientOptions<
|
|
20
21
|
StepType extends BaseStepType = BaseStepType
|
|
21
22
|
> = {
|
|
23
|
+
/**
|
|
24
|
+
* The app's version, e.g. "2.3.0". Optional: when omitted the SDK reads it
|
|
25
|
+
* from `expo-application` if that package is installed. Pass it only to
|
|
26
|
+
* override what the device reports.
|
|
27
|
+
*/
|
|
22
28
|
appVersion?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The app's build number, e.g. "45". Same precedence as `appVersion`: this
|
|
31
|
+
* option, else `expo-application`, else not sent.
|
|
32
|
+
*/
|
|
33
|
+
build?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Free text naming where this build runs, e.g. "staging". Defaults to
|
|
36
|
+
* "sandbox" when `isSandbox`, "development" under `__DEV__`, else
|
|
37
|
+
* "production". Lower-cased, reduced to `[a-z0-9_-]` and cut to 32
|
|
38
|
+
* characters before it is sent. An audience rule can target it.
|
|
39
|
+
*/
|
|
40
|
+
environment?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The stable per-person id sent as `assignmentId`, so the server can keep a
|
|
43
|
+
* person in the same variant across launches. A string, or a getter called
|
|
44
|
+
* on every request (sync or async) — e.g. `() => Purchases.getAppUserID()`
|
|
45
|
+
* to use the RevenueCat App User ID (call `Purchases.configure()` before
|
|
46
|
+
* the first request). When omitted, or when the value is `undefined`,
|
|
47
|
+
* `null` or `""`, the SDK sends an installation id it generates once and
|
|
48
|
+
* persists. Absent from the request when neither is available.
|
|
49
|
+
*
|
|
50
|
+
* `false` (or a getter returning `false`) opts out: nothing is sent, and the
|
|
51
|
+
* installation id is never read, created or written. Use it until the user
|
|
52
|
+
* has consented. `null` and `""` are not an opt-out.
|
|
53
|
+
*
|
|
54
|
+
* Fails closed: a getter that throws, rejects or takes longer than 2s is
|
|
55
|
+
* treated like `false` for that request — nothing is sent and the
|
|
56
|
+
* installation id is not touched. Resolving it counts against `timeout`.
|
|
57
|
+
*
|
|
58
|
+
* Changing the value (e.g. anonymous → identified on login) can move the
|
|
59
|
+
* person to another variant, once.
|
|
60
|
+
*/
|
|
61
|
+
assignmentId?: AssignmentIdOption;
|
|
23
62
|
isSandbox?: boolean;
|
|
24
63
|
baseUrl?: string;
|
|
25
64
|
fallbackOnboarding?: Onboarding<StepType>;
|
|
65
|
+
/**
|
|
66
|
+
* End-to-end budget in ms for each `getSteps` / `getPaywalls` request:
|
|
67
|
+
* resolving the request identity (including the `assignmentId` getter) and
|
|
68
|
+
* the fetch together. On expiry `getSteps` returns `fallbackOnboarding` if
|
|
69
|
+
* set; otherwise both reject with `Error("timeout")`.
|
|
70
|
+
*/
|
|
26
71
|
timeout?: number;
|
|
27
72
|
/**
|
|
28
73
|
* Optional custom cache key. When provided, the fetched onboarding is
|
|
@@ -44,6 +89,12 @@ export type UserDefinedParams = {
|
|
|
44
89
|
[key: string]: string;
|
|
45
90
|
};
|
|
46
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Reserved `OnboardingMetadata.variantKey` reported by the parent (main)
|
|
94
|
+
* onboarding, as opposed to one of its variants.
|
|
95
|
+
*/
|
|
96
|
+
export const MAIN_VARIANT_KEY = "main" as const;
|
|
97
|
+
|
|
47
98
|
export interface OnboardingMetadata {
|
|
48
99
|
id: string;
|
|
49
100
|
name?: string;
|
|
@@ -52,6 +103,20 @@ export interface OnboardingMetadata {
|
|
|
52
103
|
audienceOrder?: number;
|
|
53
104
|
locale?: string;
|
|
54
105
|
draft?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Which variant of the onboarding this user was served. The parent (main)
|
|
108
|
+
* onboarding reports the reserved key `MAIN_VARIANT_KEY` (`"main"`).
|
|
109
|
+
* `null` and absent mean the same thing — the server sent no variant
|
|
110
|
+
* information (e.g. an older server) — and hosts should treat them
|
|
111
|
+
* identically (e.g. `metadata.variantKey ?? undefined`).
|
|
112
|
+
*/
|
|
113
|
+
variantKey?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Id of the published deployment that was served. `null` for a draft
|
|
116
|
+
* (sandbox) payload, which has no deployment; absent when the server does
|
|
117
|
+
* not send it.
|
|
118
|
+
*/
|
|
119
|
+
deploymentId?: number | null;
|
|
55
120
|
}
|
|
56
121
|
|
|
57
122
|
/**
|
|
@@ -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", "assignmentId", "build", "draft", "environment", "locale", "moment", "now", "omitNulls", "platform", "projectId", "sdkVersion"],
|
|
10
10
|
);
|
|
11
11
|
});
|
|
12
12
|
|
|
@@ -6,30 +6,36 @@
|
|
|
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`), `assignmentId` (see
|
|
12
|
+
* `assignmentId.ts`), `draft`, `locale`, `omitNulls`.
|
|
13
|
+
* The client adds user params FIRST, then writes its own with
|
|
14
|
+
* `URLSearchParams.set`, which replaces any same-named user param (and removes
|
|
15
|
+
* a user `appVersion`/`build` when it has none of its own to send):
|
|
12
16
|
*
|
|
13
17
|
* Object.entries(userDefinedParams).forEach(([k, v]) => urlParams.append(k, v));
|
|
14
|
-
* urlParams.
|
|
18
|
+
* urlParams.set("projectId", this.projectId);
|
|
15
19
|
*
|
|
16
|
-
* `
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* it.
|
|
20
|
+
* It used to `append` them, and the server's two readers disagree about which
|
|
21
|
+
* duplicate wins: `url.searchParams.get("projectId")` returns the FIRST
|
|
22
|
+
* occurrence (the user's value — so the request resolved the wrong project, or
|
|
23
|
+
* 400ed), while `Object.fromEntries(...)` is last-wins. `set` closes that on the
|
|
24
|
+
* wire, but a user property that silently loses to the SDK's value is still a
|
|
25
|
+
* bug in the host, so this is where it gets refused.
|
|
23
26
|
*
|
|
24
27
|
* 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.
|
|
28
|
+
* plausible accident. Refusing — rather than prefixing or escaping — keeps the
|
|
29
|
+
* wire format unchanged and puts the warning at the call site responsible.
|
|
28
30
|
*/
|
|
29
31
|
export const RESERVED_USER_PROPERTY_KEYS = [
|
|
30
32
|
"projectId",
|
|
31
33
|
"platform",
|
|
32
34
|
"appVersion",
|
|
35
|
+
"build",
|
|
36
|
+
"sdkVersion",
|
|
37
|
+
"environment",
|
|
38
|
+
"assignmentId",
|
|
33
39
|
"draft",
|
|
34
40
|
"locale",
|
|
35
41
|
"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.78.0";
|