@mrrocket/sdk 0.3.0 → 0.8.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 (64) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +240 -5
  3. package/dist/api.d.ts +23 -3
  4. package/dist/api.js +7 -3
  5. package/dist/api.js.map +1 -1
  6. package/dist/batch.d.ts +33 -0
  7. package/dist/batch.js +50 -0
  8. package/dist/batch.js.map +1 -0
  9. package/dist/browser/mrrocket-flows.js +64 -0
  10. package/dist/browser/mrrocket-push.js +1 -0
  11. package/dist/browser/mrrocket-replay.js +78 -0
  12. package/dist/browser/mrrocket-sw.js +1 -0
  13. package/dist/browser/mrrocket.js +2 -0
  14. package/dist/browser.d.ts +1 -1
  15. package/dist/browser.js +3 -1
  16. package/dist/browser.js.map +1 -1
  17. package/dist/client.d.ts +36 -1
  18. package/dist/client.js +163 -83
  19. package/dist/client.js.map +1 -1
  20. package/dist/context.d.ts +10 -0
  21. package/dist/context.js.map +1 -1
  22. package/dist/core.d.ts +91 -4
  23. package/dist/core.js +83 -6
  24. package/dist/core.js.map +1 -1
  25. package/dist/feedback.d.ts +19 -4
  26. package/dist/feedback.js +652 -190
  27. package/dist/feedback.js.map +1 -1
  28. package/dist/flows-ui.d.ts +23 -0
  29. package/dist/flows-ui.js +384 -0
  30. package/dist/flows-ui.js.map +1 -0
  31. package/dist/flows-web.d.ts +19 -0
  32. package/dist/flows-web.js +42 -0
  33. package/dist/flows-web.js.map +1 -0
  34. package/dist/flows.d.ts +222 -0
  35. package/dist/flows.js +409 -0
  36. package/dist/flows.js.map +1 -0
  37. package/dist/index.d.ts +5 -2
  38. package/dist/index.js +9 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/proxy.d.ts +34 -1
  41. package/dist/proxy.js +14 -1
  42. package/dist/proxy.js.map +1 -1
  43. package/dist/push-web.d.ts +43 -0
  44. package/dist/push-web.js +81 -0
  45. package/dist/push-web.js.map +1 -0
  46. package/dist/react-native/index.d.cts +561 -0
  47. package/dist/react-native/index.d.ts +561 -0
  48. package/dist/react-native/index.js +1743 -0
  49. package/dist/react-native/index.js.map +1 -0
  50. package/dist/react-native/package.json +3 -0
  51. package/dist/referral.d.ts +6 -0
  52. package/dist/referral.js +7 -3
  53. package/dist/referral.js.map +1 -1
  54. package/dist/styles.d.ts +1 -1
  55. package/dist/styles.js +127 -24
  56. package/dist/styles.js.map +1 -1
  57. package/dist/ui.d.ts +3 -0
  58. package/dist/ui.js +12 -0
  59. package/dist/ui.js.map +1 -1
  60. package/dist/web-state.d.ts +36 -0
  61. package/dist/web-state.js +64 -0
  62. package/dist/web-state.js.map +1 -0
  63. package/package.json +64 -6
  64. package/react-native/package.json +7 -0
@@ -0,0 +1,561 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * The cancel flow, onboarding and in-app messages (SDK 0.7.0): what MRRocket's config and `GET /api/sdk/inapp` serve,
6
+ * and one controller that decides what shows when and records what the person did. No DOM and no React: the web
7
+ * renderer (flows-ui.ts, loaded only when something shows) and the React Native one (native/flows-view.ts) draw
8
+ * `view()` and call the actions.
9
+ *
10
+ * What it records, as normal events under the SDK's analytics consent (nothing with consent "off"):
11
+ * - `$cancel_flow` `{action: "shown" | "answered" | "offer" | "finished", run, version, …}`. MRRocket turns a
12
+ * `finished` with `outcome: "saved"` into a save and with `outcome: "cancelled"` into a cancellation on the Churn page.
13
+ * MRRocket never changes a subscription: an accepted offer goes to the app's `onSave`, a confirmed cancel to its
14
+ * `onCancel`, and only after they succeed is the outcome recorded.
15
+ * - `$onboarding` `{flow, step?, action: "started" | "shown" | "completed" | "dismissed"}`.
16
+ * - `$inapp` `{message, journey, action: "shown" | "clicked" | "dismissed"}`; the journey moves the person on.
17
+ */
18
+
19
+ type CancelOfferKind = "discount" | "pause" | "downgrade" | "contact";
20
+ /** What one answer of the survey offers before the confirmation. An answer without one goes straight to it. */
21
+ interface CancelOffer {
22
+ kind: CancelOfferKind;
23
+ headline: string;
24
+ /** Discount: percent off. */
25
+ percent?: number;
26
+ /** Discount: for how many months; pause: up to how many months. */
27
+ months?: number;
28
+ /** Downgrade: the plan to switch to, as MRRocket knows it from the payment provider. */
29
+ plan?: string;
30
+ planName?: string;
31
+ }
32
+ /** The product's live cancel flow (MRRocket › Churn › Cancel flow). */
33
+ interface CancelFlowConfig {
34
+ /** Grows with every publish. */
35
+ version: number;
36
+ question: string;
37
+ /** The survey's answers, in order. */
38
+ reasons: {
39
+ id: string;
40
+ label: string;
41
+ }[];
42
+ /** The offer per answer id. */
43
+ offers: Record<string, CancelOffer>;
44
+ confirm: {
45
+ title: string;
46
+ body: string;
47
+ button: string;
48
+ };
49
+ /**
50
+ * Who gets the survey and the offers: business customers only. Anyone else (a consumer, or a customer the app does
51
+ * not say) gets the plain confirmation, with nothing in the way of cancelling (§ 312k BGB).
52
+ */
53
+ offersFor: "business";
54
+ }
55
+ type OnboardingStepKind = "tour" | "checklist" | "modal";
56
+ interface OnboardingStep {
57
+ id: string;
58
+ kind: OnboardingStepKind;
59
+ title: string;
60
+ body?: string;
61
+ button?: string;
62
+ /** Tour steps: the element they point at, marked `data-ck-target="<target>"` in the app. Without it: a card. */
63
+ target?: string;
64
+ /** Checklist items: the event that ticks them (`track("<event>")`). Without it the person ticks it themselves. */
65
+ event?: string;
66
+ }
67
+ /** A live onboarding flow's in-app steps (MRRocket › Conversion › Onboarding); its emails go out from MRRocket. */
68
+ interface OnboardingFlow {
69
+ id: string;
70
+ name: string;
71
+ /** When it starts: an event's words ("Signed up", "First export"), or "First launch" / "First visit". */
72
+ trigger: string;
73
+ steps: OnboardingStep[];
74
+ }
75
+ /** An in-app message a Lifecycle journey has for this person. */
76
+ interface InAppMessage {
77
+ id: string;
78
+ journey?: string;
79
+ title: string;
80
+ body?: string;
81
+ button?: string;
82
+ /** Where the button goes (http(s) or a path of the app). */
83
+ url?: string;
84
+ style: "banner" | "modal";
85
+ }
86
+ interface CancelFlowResult {
87
+ /** "cancelled": confirmed; "saved": took the offer; "kept": closed the dialog without cancelling. */
88
+ outcome: "cancelled" | "saved" | "kept";
89
+ reason?: string;
90
+ reasonLabel?: string;
91
+ offer?: CancelOffer;
92
+ /** What the customer wrote on the confirmation, if anything. */
93
+ comment?: string;
94
+ /** This run's id, the same as in the events. */
95
+ run: string;
96
+ }
97
+ interface CancelFlowOptions {
98
+ /**
99
+ * "business" shows the survey and the offers; anything else (the default) only the plain confirmation, so a
100
+ * consumer can always cancel in one step (§ 312k BGB).
101
+ */
102
+ customer?: "business" | "consumer";
103
+ /** The customer's current price, to show what a discount costs (`{ amount: 29, currency: "EUR" }`). */
104
+ price?: {
105
+ amount: number;
106
+ currency: string;
107
+ interval?: "month" | "year";
108
+ };
109
+ /** The customer confirmed: cancel the subscription in your code. Throwing keeps the dialog open with an error. */
110
+ onCancel?: (result: CancelFlowResult) => unknown;
111
+ /** The customer took an offer: apply it in your code (coupon, pause, plan change). Throwing keeps the dialog open. */
112
+ onSave?: (result: CancelFlowResult) => unknown;
113
+ /** Closed without cancelling or taking an offer. */
114
+ onClose?: (result: CancelFlowResult) => void;
115
+ }
116
+ /** What a renderer draws. */
117
+ type FlowView = {
118
+ type: "cancel";
119
+ screen: "survey" | "offer" | "confirm";
120
+ flow: CancelFlowConfig;
121
+ /** The answer picked on the survey. */
122
+ reason?: string;
123
+ offer?: CancelOffer;
124
+ price?: CancelFlowOptions["price"];
125
+ busy: boolean;
126
+ error?: string;
127
+ /** The step for the dots, 1 to `steps`. */
128
+ step: number;
129
+ steps: number;
130
+ } | {
131
+ type: "step";
132
+ flow: OnboardingFlow;
133
+ step: OnboardingStep;
134
+ index: number;
135
+ total: number;
136
+ last: boolean;
137
+ } | {
138
+ type: "checklist";
139
+ flow: OnboardingFlow;
140
+ items: {
141
+ step: OnboardingStep;
142
+ done: boolean;
143
+ }[];
144
+ } | {
145
+ type: "message";
146
+ message: InAppMessage;
147
+ };
148
+ interface FlowsController {
149
+ setConfig(config: CockpitConfig | null): void;
150
+ /** The person changed (identify, reset, consent): loads their messages and onboarding progress. */
151
+ refresh(): Promise<void>;
152
+ /** An event the app recorded: starts flows whose trigger it is and ticks checklist items. */
153
+ onEvent(name: string): void;
154
+ openCancelFlow(options?: CancelFlowOptions): Promise<CancelFlowResult>;
155
+ /** Starts an onboarding flow now (the first live one without an id). False when there is none to start. */
156
+ startOnboarding(id?: string): boolean;
157
+ view(): FlowView | null;
158
+ subscribe(listener: () => void): () => void;
159
+ /** `accept(comment)`: a "Talk to us" offer sends what the customer wrote with it. */
160
+ cancel: {
161
+ pick(reason: string): void;
162
+ next(): void;
163
+ accept(comment?: string): void;
164
+ decline(): void;
165
+ confirm(comment?: string): void;
166
+ close(): void;
167
+ };
168
+ onboarding: {
169
+ next(): void;
170
+ check(stepId: string): void;
171
+ dismiss(): void;
172
+ };
173
+ message: {
174
+ click(): void;
175
+ dismiss(): void;
176
+ };
177
+ }
178
+
179
+ /**
180
+ * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.
181
+ * No React, no browser APIs, so the server helper, the proxy helper and the client share it.
182
+ */
183
+
184
+ type VariantId = string;
185
+ /** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */
186
+ declare const SDK_VERSION = "0.8.0";
187
+ /** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */
188
+ interface VariantConfig {
189
+ id: VariantId;
190
+ /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */
191
+ weight: number;
192
+ changes?: Record<string, string>;
193
+ /**
194
+ * A redirect test: where this variant sends the visitor instead of the test's page (a path like "/pricing-b" or a
195
+ * full address). Control has none and stays. SDK 0.7.0+.
196
+ */
197
+ url?: string;
198
+ }
199
+ interface ExperimentConfig {
200
+ /** The experiment's key, the same as in Cockpit. */
201
+ key: string;
202
+ status: "running" | "draft" | "stopped";
203
+ /** Control first. */
204
+ variants: VariantConfig[];
205
+ /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */
206
+ winner?: VariantId;
207
+ /** A redirect test: the path of the page it runs on ("/pricing"). Visitors there are sent to their variant's `url`. */
208
+ path?: string;
209
+ }
210
+ /** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */
211
+ interface RedirectConfig {
212
+ /** A path of the site, like "/old-pricing". */
213
+ from: string;
214
+ /** A path or a full address. */
215
+ to: string;
216
+ }
217
+ interface CockpitConfig {
218
+ /** The product the public key belongs to. */
219
+ project: string;
220
+ experiments: ExperimentConfig[];
221
+ /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */
222
+ referral?: {
223
+ cookieDays: number;
224
+ };
225
+ /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */
226
+ replay?: ReplayConfig;
227
+ /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */
228
+ flags?: FlagConfig[];
229
+ /**
230
+ * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and
231
+ * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A
232
+ * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.
233
+ */
234
+ texts?: Record<string, string>;
235
+ /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */
236
+ cancelFlow?: CancelFlowConfig;
237
+ /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */
238
+ onboarding?: OnboardingFlow[];
239
+ /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */
240
+ messages?: boolean;
241
+ /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */
242
+ redirects?: RedirectConfig[];
243
+ }
244
+ /** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */
245
+ interface FlagCondition {
246
+ /** "Email", "Plan", "Country", "id", "path" … Matched against the person's properties without regard to case. */
247
+ property: string;
248
+ op: "is" | "is not" | "in" | "not in" | "≥" | "in cohort";
249
+ values: string[];
250
+ }
251
+ /** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */
252
+ interface FlagConditionSet {
253
+ conditions: FlagCondition[];
254
+ /** 0 to 100. */
255
+ rollout: number;
256
+ }
257
+ interface FlagConfig {
258
+ key: string;
259
+ /** Off: everyone gets the off side. */
260
+ on: boolean;
261
+ /** The first set a person matches decides; none matched: off. */
262
+ sets: FlagConditionSet[];
263
+ /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */
264
+ variants?: {
265
+ key: string;
266
+ split: number;
267
+ payload?: string;
268
+ }[];
269
+ }
270
+ /**
271
+ * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent
272
+ * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.
273
+ */
274
+ interface ReplayConfig {
275
+ /**
276
+ * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in
277
+ * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.
278
+ */
279
+ sampleRate: number;
280
+ }
281
+ /** One event as it goes over the wire to `POST /api/sdk/events`. */
282
+ interface CockpitEvent {
283
+ event: string;
284
+ /** The visitor. Missing in "cookieless" mode until identify(): the server then uses its daily visitor hash. */
285
+ distinctId?: string;
286
+ /** Ends after 30 minutes without an event. */
287
+ sessionId?: string;
288
+ props?: Record<string, unknown>;
289
+ /** Milliseconds since the epoch. */
290
+ ts: number;
291
+ url?: string;
292
+ /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */
293
+ referrer?: string;
294
+ utm_source?: string;
295
+ utm_medium?: string;
296
+ utm_campaign?: string;
297
+ utm_term?: string;
298
+ utm_content?: string;
299
+ /** The screen size in CSS pixels (points on a phone). */
300
+ screen?: {
301
+ w: number;
302
+ h: number;
303
+ };
304
+ /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */
305
+ app?: AppContext;
306
+ }
307
+ /** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */
308
+ interface AppContext {
309
+ /** "ios" or "android" (React Native's `Platform.OS`). */
310
+ platform: string;
311
+ /** The app's version, like "1.4.0" (`expo-application`'s `nativeApplicationVersion`). */
312
+ appVersion?: string;
313
+ /** The build number, like "42". */
314
+ build?: string;
315
+ /** The OS version, like "17.4". */
316
+ osVersion?: string;
317
+ /** The device model, like "iPhone 15 Pro" (`expo-device`). */
318
+ deviceModel?: string;
319
+ /** "phone", "tablet", "desktop" or "tv" when `expo-device` knows it. */
320
+ deviceType?: string;
321
+ /** The first preferred locale, like "de-DE". */
322
+ locale?: string;
323
+ }
324
+
325
+ /**
326
+ * What the app may send and store.
327
+ * - "anonymous" (default): no id is stored on the device. Events go without a person id until `identify()` (MRRocket
328
+ * counts visitors by its daily hash); flags and experiments use a random id that lives until the app is closed.
329
+ * - "persistent": a random install id is stored on the device (removed with the app) and sent with every event.
330
+ * - "off": nothing is sent, and what the SDK stored is deleted.
331
+ */
332
+ type NativeConsent = "anonymous" | "persistent" | "off";
333
+ interface MRRocketOptions {
334
+ /** The product's public key (MRRocket › Settings › Products), the same as on the website. */
335
+ apiKey: string;
336
+ /** Where MRRocket runs. Default `https://app.mrrocket.dev`. */
337
+ host?: string;
338
+ /** Default "anonymous". The SDK does not remember it: pass it on every start (from your consent screen's stored answer). */
339
+ consent?: NativeConsent;
340
+ /** Uncaught JavaScript errors and `captureError` go to Build › Errors (default true). */
341
+ errors?: boolean;
342
+ /** Your release, for Build › Errors. Default: the app version and build, like "1.4.0 (42)". */
343
+ release?: string;
344
+ /** `$app_open` and `$app_background` events (default true). */
345
+ lifecycle?: boolean;
346
+ /** Read UTM and referral parameters of the deep link that opened the app the first time, sent with `$install` (default true). */
347
+ attribution?: boolean;
348
+ /** How often the queue is sent while the app is open, in ms (default 10 000). It is also sent when the app goes to the background. */
349
+ flushIntervalMs?: number;
350
+ /** At most this many events wait on the device; the oldest go first (default 1,000). */
351
+ maxQueue?: number;
352
+ /** Log what the SDK does to the console. */
353
+ debug?: boolean;
354
+ /** Onboarding flows start on their own when the person does their trigger (default true). False: only `startOnboarding()`. */
355
+ onboarding?: boolean;
356
+ }
357
+ /** AsyncStorage's shape. */
358
+ interface KeyValueStorage {
359
+ getItem(key: string): Promise<string | null>;
360
+ setItem(key: string, value: string): Promise<void>;
361
+ removeItem(key: string): Promise<void>;
362
+ }
363
+ interface RegisterForPushOptions {
364
+ /** Ask for the permission when it was not decided yet (default true). False: only register when already allowed. */
365
+ ask?: boolean;
366
+ /** Your EAS project id; default: the one in your app config (`expo-constants`). */
367
+ projectId?: string;
368
+ }
369
+ type NativePushStatus = "registered" | "denied" | "not-asked" | "unavailable" | "not-signed-in" | "error";
370
+ interface NativePushResult {
371
+ status: NativePushStatus;
372
+ /** The Expo push token, once registered. */
373
+ token?: string;
374
+ /** Why it is unavailable or failed. */
375
+ reason?: string;
376
+ }
377
+ /** What the app (and the React hooks) use. */
378
+ interface MRRocketClient {
379
+ track(event: string, props?: Record<string, unknown>): void;
380
+ /** A screen view: a route name ("Settings") or an Expo Router path ("/settings"). */
381
+ screen(name: string, props?: Record<string, unknown>): void;
382
+ identify(id: string, props?: Record<string, unknown>): void;
383
+ /** Forgets the signed-in person (sign-out): a new anonymous id and a new session. */
384
+ reset(): void;
385
+ setConsent(consent: NativeConsent): void;
386
+ captureError(error: unknown): void;
387
+ getFlag(key: string): boolean;
388
+ getFlagVariant(key: string): string | null;
389
+ /** The variant of an experiment ("control" until the config is known); records the exposure once per screen. */
390
+ getVariant(key: string): VariantId;
391
+ /** The variant without recording anything (render code); pair it with `expose`. */
392
+ peekVariant(key: string): VariantId;
393
+ /** Records that the person saw `variant` of `key`, once per screen. */
394
+ expose(key: string, variant: VariantId): void;
395
+ /**
396
+ * The copy for text `id` as published in MRRocket (a paywall's `paywall.<placement>.headline`, an onboarding title …)
397
+ * with this person's experiment variant applied on top, the same rules as `<Text id>` on the web; `fallback` (your
398
+ * own words) while nothing is published or the config is unknown. Records the exposure to every test that changes
399
+ * `id`, once per screen.
400
+ */
401
+ getText(id: string, fallback: string): string;
402
+ /** The text without recording anything (render code); undefined when MRRocket has none. Pair it with `exposeText`. */
403
+ peekText(id: string): string | undefined;
404
+ /** Records that the person saw text `id`: an exposure to each test that changes it, once per screen. */
405
+ exposeText(id: string): void;
406
+ /**
407
+ * Shows the cancel flow built in MRRocket › Churn (drawn by `<MRRocketProvider>`), resolves with what the customer
408
+ * did. MRRocket never changes the subscription: your `onCancel` and `onSave` do.
409
+ */
410
+ openCancelFlow(options?: CancelFlowOptions): Promise<CancelFlowResult>;
411
+ /** Starts an onboarding flow now (the first live one without an id). False when there is none. */
412
+ startOnboarding(id?: string): boolean;
413
+ /**
414
+ * Push notifications from your Lifecycle journeys for the signed-in person (call `identify` first). Asks the
415
+ * permission (unless `ask: false`), gets the Expo push token and sends it to MRRocket. Needs `expo-notifications`.
416
+ * Safe to call on every start: an existing token is sent again without asking. Opens of MRRocket's notifications
417
+ * are counted from then on.
418
+ */
419
+ registerForPush(options?: RegisterForPushOptions): Promise<NativePushResult>;
420
+ /** Removes this device's token for the signed-in person (sign-out does it on its own in `reset`). */
421
+ unregisterForPush(): Promise<boolean>;
422
+ /** The cancel flow, onboarding and messages for a renderer (the provider's, or your own). */
423
+ flows: FlowsController;
424
+ /** Sends what is queued now. */
425
+ flush(): Promise<void>;
426
+ /** Resolves once stored state and the config (cached or fetched) are known. */
427
+ ready: Promise<void>;
428
+ isReady(): boolean;
429
+ getDistinctId(): string;
430
+ getConsent(): NativeConsent;
431
+ getConfig(): CockpitConfig | null;
432
+ /** For React: called after every change flags, variants or the consent depend on. Returns the unsubscribe. */
433
+ subscribe(listener: () => void): () => void;
434
+ /** Grows with every such change (useSyncExternalStore's snapshot). */
435
+ getVersion(): number;
436
+ /** Stops timers and listeners and sends what is queued (tests, or an app that tears the SDK down). */
437
+ close(): Promise<void>;
438
+ /** For tests: what waits to be sent. */
439
+ queued(): readonly CockpitEvent[];
440
+ }
441
+ /** The name of the screen a React Navigation state shows: the focused route, followed into nested navigators. */
442
+ declare const activeRouteName: (state: unknown) => string | undefined;
443
+
444
+ interface NativeAppearance {
445
+ theme?: "light" | "dark" | "auto";
446
+ accent?: string;
447
+ }
448
+ declare const MRRocketFlows: ({ flows, appearance }: {
449
+ flows: FlowsController;
450
+ appearance?: NativeAppearance;
451
+ }) => react.FunctionComponentElement<Record<string, unknown>> | null;
452
+
453
+ /**
454
+ * The SDK's client outside React (a background task, a store, an API layer): the one the provider made, or a new one.
455
+ * One client per app; a second call returns the first.
456
+ */
457
+ declare const createMRRocket: (options: MRRocketOptions & {
458
+ storage?: KeyValueStorage | null;
459
+ }) => MRRocketClient;
460
+ /** The running client, or null before the provider (or createMRRocket) started it. */
461
+ declare const getMRRocket: () => MRRocketClient | null;
462
+ interface MRRocketProviderProps extends Partial<MRRocketOptions> {
463
+ /** The product's public key (MRRocket › Settings › Products), the same as on the website. */
464
+ apiKey: string;
465
+ /** A storage with AsyncStorage's shape instead of AsyncStorage (MMKV, SecureStore); null keeps everything in memory. */
466
+ storage?: KeyValueStorage | null;
467
+ /** A client you made with createMRRocket; the other props are then ignored. */
468
+ client?: MRRocketClient;
469
+ /**
470
+ * Draw the cancel flow, onboarding and in-app messages (default true). False: draw `client.flows` yourself, or
471
+ * place `<MRRocketFlows flows={client.flows} />` where you want it.
472
+ */
473
+ flows?: boolean;
474
+ /** The look of those dialogs: `{ theme: "light" | "dark" | "auto", accent: "#0f766e" }`. */
475
+ appearance?: NativeAppearance;
476
+ children?: ReactNode;
477
+ }
478
+ /**
479
+ * Put it once around your app (Expo Router: app/_layout.tsx; React Navigation: around the NavigationContainer). It
480
+ * starts the SDK: lifecycle events, the event queue, flags and experiments, error capture. Changing `consent` later
481
+ * calls setConsent.
482
+ */
483
+ declare const MRRocketProvider: ({ client: given, children, consent, flows, appearance, ...options }: MRRocketProviderProps) => react.FunctionComponentElement<react.ProviderProps<MRRocketClient | null>>;
484
+ /**
485
+ * `track`, `screen`, `identify`, `reset`, `setConsent`, `captureError`, `flush`, the visitor id, the consent and whether
486
+ * flags and experiments have loaded.
487
+ */
488
+ declare const useMRRocket: () => {
489
+ track: (event: string, props?: Record<string, unknown>) => void;
490
+ screen: (name: string, props?: Record<string, unknown>) => void;
491
+ identify: (id: string, props?: Record<string, unknown>) => void;
492
+ reset: () => void;
493
+ setConsent: (consent: NativeConsent) => void;
494
+ captureError: (error: unknown) => void;
495
+ flush: () => Promise<void>;
496
+ distinctId: string;
497
+ consent: NativeConsent;
498
+ ready: boolean;
499
+ };
500
+ /**
501
+ * The cancel flow built in MRRocket › Churn › Cancel flow. Call `open` from your Cancel button; the provider draws it.
502
+ * MRRocket never changes the subscription: your `onCancel` and `onSave` do (RevenueCat, your server, the store's
503
+ * subscription page).
504
+ *
505
+ * const cancelFlow = useCancelFlow();
506
+ * <Button title="Cancel subscription" onPress={() => cancelFlow.open({ customer: "consumer", onCancel: openStoreSubscriptions })} />
507
+ */
508
+ declare const useCancelFlow: () => {
509
+ open: (options?: CancelFlowOptions) => Promise<CancelFlowResult>;
510
+ };
511
+ /**
512
+ * Push notifications from your Lifecycle journeys (needs `expo-notifications`). After sign-in (`identify`), call
513
+ * `register()`: it asks the permission, gets the Expo push token and sends it to MRRocket. Sign-out (`reset`) takes the
514
+ * token back on its own.
515
+ *
516
+ * const push = usePush();
517
+ * useEffect(() => { if (user) void push.register(); }, [user]);
518
+ */
519
+ declare const usePush: () => {
520
+ register: MRRocketClient["registerForPush"];
521
+ unregister: MRRocketClient["unregisterForPush"];
522
+ };
523
+ /** Starts an onboarding flow now (the first live one without an id), whatever its trigger. */
524
+ declare const useOnboarding: () => {
525
+ start: (id?: string) => boolean;
526
+ };
527
+ /** A feature flag from MRRocket › Build › Feature flags: true while it is on for this person; false while off, unknown or loading. */
528
+ declare const useFlag: (key: string) => boolean;
529
+ /** The variant of a multivariate flag ("control", "test" …), or null while it is off. */
530
+ declare const useFlagVariant: (key: string) => string | null;
531
+ /**
532
+ * The variant of an experiment this person sees ("control" until the config is known; the cached config is used on a
533
+ * cold start, so the first screen is already stable). Records the exposure once per screen.
534
+ */
535
+ declare const useVariant: (key: string) => VariantId;
536
+ /**
537
+ * Copy MRRocket can change without an app update: the text published for `id` (a paywall's
538
+ * `paywall.<placement>.headline`, `.body`, `.cta`), with this person's variant of a running text test on top,
539
+ * the same rules as `<Text id>` on the web. Write your own words as `fallback`: they show while nothing is published
540
+ * and on a first start before the config arrives. Records the exposure to every test that changes `id`, once per screen.
541
+ *
542
+ * const headline = useText("paywall.onboarding.headline", "Unlock everything");
543
+ * <Text style={styles.title}>{headline}</Text>
544
+ */
545
+ declare const useText: (id: string, fallback: string) => string;
546
+ /**
547
+ * Screen views for Expo Router: one `$screen` per path ("/settings", "/product/[id]" as its real path). Call it in a
548
+ * component inside both the router and MRRocketProvider, for example the root layout's child.
549
+ */
550
+ declare const useExpoRouterTracking: () => void;
551
+ /**
552
+ * Screen views for React Navigation: pass the result to the container's `onStateChange`, and call it once in `onReady`
553
+ * with the root state, so the first screen counts too.
554
+ *
555
+ * const ref = useNavigationContainerRef();
556
+ * const onStateChange = useNavigationTracking();
557
+ * <NavigationContainer ref={ref} onReady={() => onStateChange(ref.getRootState())} onStateChange={onStateChange}>
558
+ */
559
+ declare const useNavigationTracking: () => (state: unknown) => void;
560
+
561
+ export { type AppContext, type CancelFlowConfig, type CancelFlowOptions, type CancelFlowResult, type CancelOffer, type CockpitConfig, type FlagConfig, type FlowView, type InAppMessage, type KeyValueStorage, type MRRocketClient, MRRocketFlows, type MRRocketOptions, MRRocketProvider, type MRRocketProviderProps, type NativeAppearance, type NativeConsent, type NativePushResult, type NativePushStatus, type OnboardingFlow, type OnboardingStep, type RegisterForPushOptions, SDK_VERSION, type VariantId, activeRouteName, createMRRocket, getMRRocket, useCancelFlow, useExpoRouterTracking, useFlag, useFlagVariant, useMRRocket, useNavigationTracking, useOnboarding, usePush, useText, useVariant };