@mrrocket/sdk 0.8.0 → 0.10.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 (45) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +35 -1
  3. package/dist/api-client.d.ts +221 -0
  4. package/dist/api-client.js +79 -0
  5. package/dist/api-client.js.map +1 -0
  6. package/dist/api.d.ts +2 -122
  7. package/dist/api.js +2 -61
  8. package/dist/api.js.map +1 -1
  9. package/dist/browser/mrrocket-messenger.js +348 -0
  10. package/dist/browser/mrrocket-replay.js +3 -3
  11. package/dist/browser/mrrocket.js +1 -1
  12. package/dist/browser.d.ts +2 -1
  13. package/dist/browser.js +3 -0
  14. package/dist/browser.js.map +1 -1
  15. package/dist/capture.d.ts +1 -13
  16. package/dist/capture.js +1 -22
  17. package/dist/capture.js.map +1 -1
  18. package/dist/core.d.ts +1 -1
  19. package/dist/core.js +1 -1
  20. package/dist/core.js.map +1 -1
  21. package/dist/feedback.js +132 -24
  22. package/dist/feedback.js.map +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/messenger-ui.d.ts +49 -0
  27. package/dist/messenger-ui.js +619 -0
  28. package/dist/messenger-ui.js.map +1 -0
  29. package/dist/messenger.d.ts +37 -0
  30. package/dist/messenger.js +69 -0
  31. package/dist/messenger.js.map +1 -0
  32. package/dist/rage.d.ts +14 -0
  33. package/dist/rage.js +27 -0
  34. package/dist/rage.js.map +1 -0
  35. package/dist/react-native/index.d.cts +349 -4
  36. package/dist/react-native/index.d.ts +349 -4
  37. package/dist/react-native/index.js +1345 -31
  38. package/dist/react-native/index.js.map +1 -1
  39. package/dist/styles-css.d.ts +6 -0
  40. package/dist/styles-css.js +362 -0
  41. package/dist/styles-css.js.map +1 -0
  42. package/dist/styles.d.ts +1 -2
  43. package/dist/styles.js +3 -237
  44. package/dist/styles.js.map +1 -1
  45. package/package.json +17 -5
@@ -1,6 +1,218 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
 
4
+ /**
5
+ * The SDK's fetch client and the shapes it reads, without React, so the script tag's widgets (src/script) use it too.
6
+ * `./api` re-exports all of it with the `useApi` hook.
7
+ */
8
+ type PostStatus = "review" | "planned" | "progress" | "shipped";
9
+ interface FeedbackBoardInfo {
10
+ id: string;
11
+ label: string;
12
+ }
13
+ interface FeedbackPost {
14
+ id: string;
15
+ title: string;
16
+ body: string;
17
+ board: string;
18
+ status: PostStatus;
19
+ votes: number;
20
+ comments: number;
21
+ voted: boolean;
22
+ createdAt: string;
23
+ /** "Lena K.", "Anonymous" or "Team". Missing from servers before SDK 0.6. */
24
+ author?: string;
25
+ }
26
+ /** The product's public face for the board's header. */
27
+ interface FeedbackProduct {
28
+ name: string;
29
+ logo: string | null;
30
+ /** The domain's favicon, tried when `logo` does not load. Older servers leave it out. */
31
+ logoFallback?: string | null;
32
+ }
33
+ interface FeedbackList {
34
+ boards: FeedbackBoardInfo[];
35
+ posts: FeedbackPost[];
36
+ product?: FeedbackProduct;
37
+ }
38
+ interface FeedbackRoadmap {
39
+ /** `review` (Backlog) comes from servers of SDK 0.6 on. */
40
+ columns: {
41
+ review?: FeedbackPost[];
42
+ planned: FeedbackPost[];
43
+ progress: FeedbackPost[];
44
+ shipped: FeedbackPost[];
45
+ };
46
+ }
47
+ interface ChangelogEntry {
48
+ id: string;
49
+ title: string;
50
+ body: string;
51
+ publishedAt: string;
52
+ }
53
+ interface FeedbackComment {
54
+ id: string;
55
+ body: string;
56
+ author: string;
57
+ isTeam: boolean;
58
+ postedAt: string;
59
+ }
60
+ type SurveyQuestionKind = "nps" | "rating" | "single" | "multi" | "text";
61
+ interface SurveyQuestion {
62
+ key: string;
63
+ kind: SurveyQuestionKind;
64
+ title: string;
65
+ description?: string;
66
+ required: boolean;
67
+ options?: string[];
68
+ scale?: number;
69
+ low?: string;
70
+ high?: string;
71
+ placeholder?: string;
72
+ }
73
+ interface SurveyDefinition {
74
+ id: string;
75
+ name: string;
76
+ type: string;
77
+ thanks: string;
78
+ questions: SurveyQuestion[];
79
+ }
80
+ type SurveyAnswer = number | string | string[];
81
+ /** One message of the messenger's chat. "visitor" is the person on the site; the rest come from the product's team. */
82
+ interface ChatMessage {
83
+ id: string;
84
+ from: "visitor" | "team" | "ai" | "auto";
85
+ body: string;
86
+ at: string;
87
+ /** Help articles an answer drew on (servers from SDK 0.9 on). */
88
+ articles?: {
89
+ id: string;
90
+ title: string;
91
+ }[];
92
+ }
93
+ /** A published help article in a list (the messenger's Help tab). */
94
+ interface ArticleSummary {
95
+ id: string;
96
+ title: string;
97
+ collection: string;
98
+ excerpt: string;
99
+ updatedAt: string;
100
+ }
101
+ /** A run of text inside an article block. Links are http(s), mailto or tel only. */
102
+ interface ArticleSpan {
103
+ text: string;
104
+ href?: string;
105
+ bold?: boolean;
106
+ italic?: boolean;
107
+ code?: boolean;
108
+ }
109
+ /** An article's content as blocks, written with textContent (never parsed as HTML). */
110
+ type ArticleBlock = {
111
+ type: "h2" | "h3" | "p" | "quote";
112
+ spans: ArticleSpan[];
113
+ } | {
114
+ type: "ul" | "ol";
115
+ items: ArticleSpan[][];
116
+ } | {
117
+ type: "code";
118
+ text: string;
119
+ } | {
120
+ type: "hr";
121
+ };
122
+ interface Article {
123
+ id: string;
124
+ title: string;
125
+ collection: string;
126
+ updatedAt: string;
127
+ blocks: ArticleBlock[];
128
+ }
129
+ /** The messenger's look and texts as set in MRRocket › Support › Messenger (servers from SDK 0.9 on). */
130
+ interface MessengerLook {
131
+ accent: string;
132
+ theme: "light" | "dark" | "auto";
133
+ position: "bottom-right" | "bottom-left";
134
+ title: string;
135
+ greeting: string;
136
+ label: string;
137
+ /** How soon the team usually answers (MRRocket from 0.10; older servers leave it out). */
138
+ replyTime?: "minutes" | "hours" | "day";
139
+ /** A round chat button in the app (React Native) too. */
140
+ appLauncher?: boolean;
141
+ help: boolean;
142
+ sound: boolean;
143
+ preview: boolean;
144
+ askEmail: boolean;
145
+ }
146
+ /** The visitor's newest chat (open or closed) and its messages. */
147
+ interface ChatThread {
148
+ conversation: {
149
+ id: string;
150
+ status: "open" | "solved";
151
+ } | null;
152
+ messages: ChatMessage[];
153
+ /** The visitor gave an email already: the messenger stops asking. */
154
+ hasEmail: boolean;
155
+ }
156
+ interface Conn {
157
+ host: string;
158
+ apiKey: string;
159
+ distinctId: string;
160
+ user?: {
161
+ id?: string;
162
+ [key: string]: unknown;
163
+ };
164
+ }
165
+ /** The small fetch client behind the widgets. Every read takes an AbortSignal so unmounting cancels it. */
166
+ declare const createApi: (c: Conn) => {
167
+ list: (o: {
168
+ board?: string;
169
+ sort?: "top" | "new";
170
+ q?: string;
171
+ }, signal?: AbortSignal) => Promise<FeedbackList>;
172
+ post: (id: string, signal?: AbortSignal) => Promise<FeedbackPost>;
173
+ roadmap: (signal?: AbortSignal) => Promise<FeedbackRoadmap>;
174
+ changelog: (signal?: AbortSignal) => Promise<{
175
+ entries: ChangelogEntry[];
176
+ }>;
177
+ submit: (p: {
178
+ title: string;
179
+ body?: string;
180
+ board: string;
181
+ }) => Promise<FeedbackPost>;
182
+ vote: (id: string) => Promise<{
183
+ voted: boolean;
184
+ votes: number;
185
+ }>;
186
+ comments: (id: string, signal?: AbortSignal) => Promise<{
187
+ comments: FeedbackComment[];
188
+ }>;
189
+ comment: (id: string, body: string) => Promise<FeedbackComment>;
190
+ survey: (url: string, signal?: AbortSignal) => Promise<{
191
+ survey: SurveyDefinition | null;
192
+ }>;
193
+ seen: (id: string) => Promise<unknown>;
194
+ respond: (id: string, r: {
195
+ answers: Record<string, SurveyAnswer>;
196
+ completed: boolean;
197
+ seconds: number;
198
+ }) => Promise<unknown>;
199
+ chat: (signal?: AbortSignal) => Promise<ChatThread>;
200
+ sendChat: (m: {
201
+ body: string;
202
+ email?: string;
203
+ url?: string;
204
+ }) => Promise<ChatThread>;
205
+ articles: (q?: string, signal?: AbortSignal) => Promise<{
206
+ articles: ArticleSummary[];
207
+ }>;
208
+ article: (id: string, signal?: AbortSignal) => Promise<Article>;
209
+ messengerLook: (signal?: AbortSignal) => Promise<MessengerLook>;
210
+ rateArticle: (id: string, helpful: boolean) => Promise<{
211
+ counted: boolean;
212
+ }>;
213
+ };
214
+ type Api = ReturnType<typeof createApi>;
215
+
4
216
  /**
5
217
  * The cancel flow, onboarding and in-app messages (SDK 0.7.0): what MRRocket's config and `GET /api/sdk/inapp` serve,
6
218
  * and one controller that decides what shows when and records what the person did. No DOM and no React: the web
@@ -183,7 +395,7 @@ interface FlowsController {
183
395
 
184
396
  type VariantId = string;
185
397
  /** 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";
398
+ declare const SDK_VERSION = "0.10.0";
187
399
  /** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */
188
400
  interface VariantConfig {
189
401
  id: VariantId;
@@ -322,6 +534,14 @@ interface AppContext {
322
534
  locale?: string;
323
535
  }
324
536
 
537
+ /**
538
+ * The React Native client without React: the event queue (batched, persisted for offline use, retried with backoff),
539
+ * the app lifecycle (`$app_open`, `$app_background`, a new session after 30 minutes away), screens, identity and
540
+ * consent, the cached config for flags and experiments, install attribution from the first open's deep link, and error
541
+ * capture. Everything the platform gives (storage, AppState, ErrorUtils, device info, fetch) comes in as `deps`, so
542
+ * it runs in tests without React Native; `platform.ts` builds the real ones.
543
+ */
544
+
325
545
  /**
326
546
  * What the app may send and store.
327
547
  * - "anonymous" (default): no id is stored on the device. Events go without a person id until `identify()` (MRRocket
@@ -353,6 +573,14 @@ interface MRRocketOptions {
353
573
  debug?: boolean;
354
574
  /** Onboarding flows start on their own when the person does their trigger (default true). False: only `startOnboarding()`. */
355
575
  onboarding?: boolean;
576
+ /** Taps go to Heatmaps as clicks on the screen they happened on (default true; `MRRocketProvider` captures them). */
577
+ heatmaps?: boolean;
578
+ /**
579
+ * The person agreed to session recordings (default false; ask them first). Needs `react-native-view-shot` and the
580
+ * product's recordings switched on in MRRocket. No frame while the keyboard is open; wrap private views in
581
+ * `<MRRocketMask>`. Change it later with `setReplay`.
582
+ */
583
+ replay?: boolean;
356
584
  }
357
585
  /** AsyncStorage's shape. */
358
586
  interface KeyValueStorage {
@@ -379,6 +607,10 @@ interface MRRocketClient {
379
607
  track(event: string, props?: Record<string, unknown>): void;
380
608
  /** A screen view: a route name ("Settings") or an Expo Router path ("/settings"). */
381
609
  screen(name: string, props?: Record<string, unknown>): void;
610
+ /** A tap at screen points (x, y) for Heatmaps, on the current screen; `MRRocketProvider` calls it. */
611
+ tap(x: number, y: number): void;
612
+ /** The person's answer to session recordings (`replay` in the options); false stops and forgets what was not sent. */
613
+ setReplay(on: boolean): void;
382
614
  identify(id: string, props?: Record<string, unknown>): void;
383
615
  /** Forgets the signed-in person (sign-out): a new anonymous id and a new session. */
384
616
  reset(): void;
@@ -428,6 +660,23 @@ interface MRRocketClient {
428
660
  isReady(): boolean;
429
661
  getDistinctId(): string;
430
662
  getConsent(): NativeConsent;
663
+ /**
664
+ * The client of the SDK's widget API (surveys, feedback, the messenger) for the person now: their id, and the name and
665
+ * email given to identify (or `as`, typed into a widget). Null while the consent is off or without a key.
666
+ */
667
+ api(as?: {
668
+ name?: string;
669
+ email?: string;
670
+ }): Api | null;
671
+ /** The signed-in person (identify): their id, and the name and email given there. Undefined before identify. */
672
+ getUser(): {
673
+ id: string;
674
+ name?: string;
675
+ email?: string;
676
+ } | undefined;
677
+ /** Surveys answered or closed on this device: not shown again (kept on the device only with "persistent"). */
678
+ isSurveyDone(id: string): boolean;
679
+ markSurveyDone(id: string): void;
431
680
  getConfig(): CockpitConfig | null;
432
681
  /** For React: called after every change flags, variants or the consent depend on. Returns the unsubscribe. */
433
682
  subscribe(listener: () => void): () => void;
@@ -450,6 +699,90 @@ declare const MRRocketFlows: ({ flows, appearance }: {
450
699
  appearance?: NativeAppearance;
451
700
  }) => react.FunctionComponentElement<Record<string, unknown>> | null;
452
701
 
702
+ interface Palette {
703
+ accent: string;
704
+ bg: string;
705
+ fg: string;
706
+ muted: string;
707
+ soft: string;
708
+ line: string;
709
+ danger: string;
710
+ }
711
+ /** Asks the person the survey MRRocket picks for them, a few seconds after start and again for a new person. */
712
+ declare const MRRocketSurveys: ({ client, appearance }: {
713
+ client: MRRocketClient;
714
+ appearance?: NativeAppearance;
715
+ }) => react.FunctionComponentElement<{
716
+ survey: SurveyDefinition;
717
+ api: Api;
718
+ p: Palette;
719
+ onDone: () => void;
720
+ }> | null;
721
+ /** Opens the feedback sheet: the top requests with votes, and a form to suggest one. */
722
+ declare const useFeedback: () => {
723
+ open: () => void;
724
+ close: () => void;
725
+ };
726
+ interface NativeFeedbackOptions {
727
+ /** The sheet's title. Default "Feedback". */
728
+ title?: string;
729
+ }
730
+ declare const MRRocketFeedback: ({ client, appearance, options }: {
731
+ client: MRRocketClient;
732
+ appearance?: NativeAppearance;
733
+ options?: NativeFeedbackOptions;
734
+ }) => react.FunctionComponentElement<{
735
+ client: MRRocketClient;
736
+ p: Palette;
737
+ title: string;
738
+ }> | null;
739
+ type MsgView = "home" | "messages" | "help" | {
740
+ article: string;
741
+ };
742
+ /** Opens (on Home, a tab or `{ article: id }`), closes or toggles the messenger. */
743
+ declare const useMessenger: () => {
744
+ open: (view?: MsgView) => void;
745
+ close: () => void;
746
+ toggle: () => void;
747
+ };
748
+ interface NativeMessengerOptions {
749
+ /** A round chat button (default false: open it with `useMessenger().open()` from your own button). */
750
+ launcher?: boolean;
751
+ /** Where the chat button sits (default bottom right). */
752
+ position?: "bottom-right" | "bottom-left";
753
+ /** Text beside the chat button's icon; empty: the round button. */
754
+ label?: string;
755
+ title?: string;
756
+ /** The big line on Home and the first line of an empty chat. */
757
+ greeting?: string;
758
+ /** How soon the team usually answers, said under "Send us a message" and in the chat's head. */
759
+ replyTime?: "minutes" | "hours" | "day";
760
+ /** Ask people the app did not identify with an email for an email (optional for them). Default true. */
761
+ askEmail?: boolean;
762
+ /** The Help tab with your published help articles (default true; hidden while there are none). */
763
+ help?: boolean;
764
+ /** A banner at the top when an answer arrives while the messenger is closed (default true). */
765
+ preview?: boolean;
766
+ /** A light haptic when an answer arrives (default true; needs expo-haptics). */
767
+ haptics?: boolean;
768
+ }
769
+ declare const MRRocketMessenger: ({ client, appearance, options: given }: {
770
+ client: MRRocketClient;
771
+ appearance?: NativeAppearance;
772
+ options?: NativeMessengerOptions;
773
+ }) => react.FunctionComponentElement<Record<string, unknown>> | null;
774
+
775
+ /**
776
+ * Hides what it wraps in session recordings: its area is painted black on every frame before the frame is stored. Use
777
+ * it for anything private on screen (balances, addresses, messages). Text fields need no wrapper: nothing is recorded
778
+ * while the keyboard is open.
779
+ *
780
+ * <MRRocketMask><Text>{iban}</Text></MRRocketMask>
781
+ */
782
+ declare const MRRocketMask: ({ children, style }: {
783
+ children?: ReactNode;
784
+ style?: unknown;
785
+ }) => react.FunctionComponentElement<Record<string, unknown>>;
453
786
  /**
454
787
  * The SDK's client outside React (a background task, a store, an API layer): the one the provider made, or a new one.
455
788
  * One client per app; a second call returns the first.
@@ -471,8 +804,19 @@ interface MRRocketProviderProps extends Partial<MRRocketOptions> {
471
804
  * place `<MRRocketFlows flows={client.flows} />` where you want it.
472
805
  */
473
806
  flows?: boolean;
474
- /** The look of those dialogs: `{ theme: "light" | "dark" | "auto", accent: "#0f766e" }`. */
807
+ /** The look of those dialogs and the widgets: `{ theme: "light" | "dark" | "auto", accent: "#0f766e" }`. */
475
808
  appearance?: NativeAppearance;
809
+ /** Show the live in-app survey MRRocket picks for the person, a few seconds after start (default true). */
810
+ surveys?: boolean;
811
+ /** The chat with your team, opened with `useMessenger().open()`; `{ launcher: true }` adds a round button. False: none. */
812
+ messenger?: NativeMessengerOptions | false;
813
+ /** The feedback sheet opened with `useFeedback().open()` (`{ title }`). False: none. */
814
+ feedback?: NativeFeedbackOptions | false;
815
+ /**
816
+ * Taps for Heatmaps (default true). The provider then wraps the app in one `View` with `flex: 1` to see them; false
817
+ * leaves the app as it is.
818
+ */
819
+ heatmaps?: boolean;
476
820
  children?: ReactNode;
477
821
  }
478
822
  /**
@@ -480,7 +824,7 @@ interface MRRocketProviderProps extends Partial<MRRocketOptions> {
480
824
  * starts the SDK: lifecycle events, the event queue, flags and experiments, error capture. Changing `consent` later
481
825
  * calls setConsent.
482
826
  */
483
- declare const MRRocketProvider: ({ client: given, children, consent, flows, appearance, ...options }: MRRocketProviderProps) => react.FunctionComponentElement<react.ProviderProps<MRRocketClient | null>>;
827
+ declare const MRRocketProvider: ({ client: given, children, consent, flows, appearance, surveys, messenger, feedback, heatmaps, ...options }: MRRocketProviderProps) => react.FunctionComponentElement<react.ProviderProps<MRRocketClient | null>>;
484
828
  /**
485
829
  * `track`, `screen`, `identify`, `reset`, `setConsent`, `captureError`, `flush`, the visitor id, the consent and whether
486
830
  * flags and experiments have loaded.
@@ -491,6 +835,7 @@ declare const useMRRocket: () => {
491
835
  identify: (id: string, props?: Record<string, unknown>) => void;
492
836
  reset: () => void;
493
837
  setConsent: (consent: NativeConsent) => void;
838
+ setReplay: (on: boolean) => void;
494
839
  captureError: (error: unknown) => void;
495
840
  flush: () => Promise<void>;
496
841
  distinctId: string;
@@ -558,4 +903,4 @@ declare const useExpoRouterTracking: () => void;
558
903
  */
559
904
  declare const useNavigationTracking: () => (state: unknown) => void;
560
905
 
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 };
906
+ export { type AppContext, type CancelFlowConfig, type CancelFlowOptions, type CancelFlowResult, type CancelOffer, type ChatMessage, type ChatThread, type CockpitConfig, type FeedbackPost, type FlagConfig, type FlowView, type InAppMessage, type KeyValueStorage, type MRRocketClient, MRRocketFeedback, MRRocketFlows, MRRocketMask, MRRocketMessenger, type MRRocketOptions, MRRocketProvider, type MRRocketProviderProps, MRRocketSurveys, type NativeAppearance, type NativeConsent, type NativeFeedbackOptions, type NativeMessengerOptions, type NativePushResult, type NativePushStatus, type OnboardingFlow, type OnboardingStep, type RegisterForPushOptions, SDK_VERSION, type SurveyDefinition, type VariantId, activeRouteName, createMRRocket, getMRRocket, useCancelFlow, useExpoRouterTracking, useFeedback, useFlag, useFlagVariant, useMRRocket, useMessenger, useNavigationTracking, useOnboarding, usePush, useText, useVariant };