@guidelytech/react-native 0.9.0 → 0.11.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/dist/index.d.cts CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { SelectorStrategy, MessengerConfig, MessengerMessage, MessengerConversation, SdkArticlesResponse, ResourceCenterArticle, PublishedGuide, ProjectTheme, GuideStep, SdkConfigResponse, ChecklistTask, SdkEvent, TargetingContext, StepButton, ResourceCenterConfig, Placement } from '@guidelytech/shared';
4
- export { GuideStep, PublishedGuide, SdkConfigResponse } from '@guidelytech/shared';
3
+ import { SelectorStrategy, AutocaptureSettings, HeatmapPoint, MessengerConfig, MessengerMessage, MessengerConversation, SdkArticlesResponse, ResourceCenterArticle, PublishedGuide, ProjectTheme, GuideStep, SdkConfigResponse, ChecklistTask, SdkEvent, TargetingContext, StepButton, ResourceCenterConfig, RuleGroup, ResourceCenterAnnouncement, Placement } from '@guidelytech/shared';
4
+ export { AutocaptureSettings, GuideStep, HeatmapPoint, PublishedGuide, SdkConfigResponse } from '@guidelytech/shared';
5
5
  import { FlagsClientOptions, FlagsClient, JsonValue, FlagValue, FlagDetails, FlagsBootstrap, Attributes } from '@guidelytech/flags';
6
6
  export { Attributes, EvaluationResult, FlagDetails, FlagsBootstrap, FlagsClient, FlagsClientOptions, FlagsPayload, InMemoryStickyBucketStore, JsonValue, createFlagsClient } from '@guidelytech/flags';
7
- import { KeyValueStore, ChecklistProgressState, GuidelyEnvironment, ConsentState, GuidelyUser, GuidelyAccount, GuideLocalState, SessionState } from '@guidelytech/sdk-core/headless';
7
+ import { ResourceCenterModuleId } from '@guidelytech/shared/runtime';
8
+ import { KeyValueStore, ServerHealth, ChecklistProgressState, GuidelyEnvironment, ConsentState, GuidelyUser, GuidelyAccount, GuideLocalState, SessionState } from '@guidelytech/sdk-core/headless';
8
9
  export { ChecklistProgressState, ConsentState, GuidelyAccount, GuidelyEnvironment, GuidelyUser } from '@guidelytech/sdk-core/headless';
9
10
  import { ViewProps, StyleProp, ViewStyle, View, GestureResponderEvent } from 'react-native';
10
11
 
@@ -50,6 +51,15 @@ declare class TargetRegistry {
50
51
  /** Frame of a visible target (the most recently mounted visible one when an id is used twice), else null. */
51
52
  measure(id: string): Promise<Rect | null>;
52
53
  private measureHandle;
54
+ /**
55
+ * The registered target on the current screen whose visible frame contains the point (window
56
+ * coordinates); the smallest one when targets are nested. Frames that do not answer within
57
+ * `timeoutMs` are skipped.
58
+ */
59
+ hitTest(x: number, y: number, timeoutMs?: number): Promise<{
60
+ id: string;
61
+ rect: Rect;
62
+ } | null>;
53
63
  /** First of `ids` that is mounted and visible. */
54
64
  resolve(ids: string[]): Promise<{
55
65
  id: string;
@@ -67,6 +77,88 @@ declare class TargetRegistry {
67
77
 
68
78
  type GuideStatus = "idle" | "running" | "waiting_url" | "waiting_target" | "ended";
69
79
 
80
+ /** `autocapture` option: `false` turns every capability off, an object turns single ones off. */
81
+ type AutocaptureOption = boolean | Partial<AutocaptureSettings>;
82
+ /** The element a tap resolved to (or the view it hit), as `click` properties need it. */
83
+ interface TapElement {
84
+ selector: string;
85
+ /** Component / host name (`Pressable`, `TouchableOpacity`, `Text`, `View`). */
86
+ tag: string;
87
+ /** Visible label; already empty for text fields and masked content. */
88
+ text?: string;
89
+ /** Window frame of the element, for the position inside it (heatmaps). */
90
+ measure?: () => Promise<Rect | null>;
91
+ }
92
+ /** One observed tap, reported by the provider's touch observer. */
93
+ interface TapInfo {
94
+ /** Window coordinates in points. */
95
+ x: number;
96
+ y: number;
97
+ /** When the tap ended (ms since epoch); defaults to now. */
98
+ t?: number;
99
+ /** Innermost interactive element under the tap (touchable, `Pressable`, `accessibilityRole="button"`…), if found. */
100
+ element?: TapElement | null;
101
+ /** The view the tap hit, used for rage taps and heatmaps when there is no interactive element. */
102
+ hit?: TapElement | null;
103
+ }
104
+ /** `click` / `rage_click` properties on mobile (`ClickProperties` on the web plus `platform`). */
105
+ interface TapProperties {
106
+ selector: string;
107
+ tag: string;
108
+ text?: string;
109
+ x: number;
110
+ y: number;
111
+ platform: string;
112
+ count?: number;
113
+ }
114
+ /**
115
+ * Detects rage taps: 3+ taps within 1s (each within 1s of the previous) and 30pt of the burst's
116
+ * first tap, reported once per burst. Same semantics as the web SDK's `RageClickDetector`
117
+ * (conformance vectors: `rageClicks` in `mobile/conformance/vectors.json`).
118
+ */
119
+ declare class RageClickDetector {
120
+ private readonly threshold;
121
+ private readonly windowMs;
122
+ private readonly radius;
123
+ private clicks;
124
+ private fired;
125
+ constructor(threshold?: number, windowMs?: number, radius?: number);
126
+ /** Taps in the current burst once it has fired (rage), otherwise 0. */
127
+ get burst(): number;
128
+ /** Records a tap; returns the tap count when it completes a burst, otherwise 0. */
129
+ add(x: number, y: number, t: number): number;
130
+ }
131
+ /** Tap positions on the current screen, sent as one `heatmap` event per batch (40 points, screen change, background). */
132
+ declare class HeatmapBuffer {
133
+ /** Screen path the buffered points belong to. */
134
+ url: string;
135
+ points: HeatmapPoint[];
136
+ /** Adds a tap (`burst` > 0 marks it and the burst's previous taps as rage); true when the batch is full. */
137
+ add(url: string, point: HeatmapPoint, burst: number): boolean;
138
+ /** Empties the buffer, returning what was in it. */
139
+ take(): {
140
+ url: string;
141
+ points: HeatmapPoint[];
142
+ } | null;
143
+ }
144
+ /**
145
+ * Tracks one primary-pointer touch and decides whether it was a tap. Feed it the touch events the
146
+ * provider observes; `end` returns the tap position (window points) or null.
147
+ */
148
+ declare class TapTracker {
149
+ private start;
150
+ private moved;
151
+ /** A finger went down. A second finger while one is tracked cancels the gesture (not a tap). */
152
+ begin(x: number, y: number, t: number, touches: number, id?: unknown): void;
153
+ move(x: number, y: number, id?: unknown): void;
154
+ /** The finger lifted: the tap position when it moved ≤ 10pt and lasted < 1s, else null. */
155
+ end(x: number, y: number, t: number, id?: unknown): {
156
+ x: number;
157
+ y: number;
158
+ } | null;
159
+ cancel(): void;
160
+ }
161
+
70
162
  /**
71
163
  * Scout messenger for React Native: the transport of `@guidelytech/sdk-core`'s messenger-api plus
72
164
  * the conversation state the web widget keeps, as a headless store the overlay renders.
@@ -135,6 +227,10 @@ interface MessengerDeps {
135
227
  onMessage: (message: MessengerMessage, conversation: MessengerConversation) => void;
136
228
  onStartGuide: (key: string) => void;
137
229
  onError: (err: unknown) => void;
230
+ /** The SDK API's circuit breaker, told how each reply stream went. */
231
+ health?: ServerHealth;
232
+ /** The help center's language when it isn't the default; translated articles are fetched with `?locale=`. */
233
+ locale?: () => string | undefined;
138
234
  /** Poll intervals (ms): open thread, and unread badge otherwise. */
139
235
  pollMs?: {
140
236
  thread: number;
@@ -216,22 +312,38 @@ interface GuidelyOptions {
216
312
  /** Base URL of your Guidely deployment, e.g. `https://guidelytech.com`. */
217
313
  apiUrl?: string;
218
314
  /**
219
- * Where identity, cached config and queued events are persisted. Pass AsyncStorage
220
- * (`@react-native-async-storage/async-storage`); without it state lasts only for the app session.
315
+ * Where identity, cached config, queued events and unsent survey answers are persisted. Pass AsyncStorage
316
+ * (`@react-native-async-storage/async-storage`); without it state lasts only for the app session,
317
+ * so anything not yet sent during a Guidely outage is lost when the app restarts.
221
318
  */
222
319
  storage?: GuidelyStorage;
223
320
  debug?: boolean;
224
321
  /** Send analytics events (default `true`). Guides still render when disabled. */
225
322
  analytics?: boolean;
226
323
  consent?: ConsentState;
227
- /** Host app version for `app.version` targeting rules. */
324
+ /** Host app version for `app.version` targeting rules and `app_install` / `app_update` events (e.g. from `expo-application`). */
228
325
  appVersion?: string;
326
+ /** Host app build number (`CFBundleVersion` / `versionCode`), sent as `build` with app lifecycle events. */
327
+ appBuild?: string;
328
+ /**
329
+ * Product analytics autocapture: taps (`click`), rage taps, heatmaps, time on screen
330
+ * (`page_leave`) and app lifecycle events. Each capability runs when the project enables it in
331
+ * Settings → Product analytics; this option can only turn things off: `false` for everything,
332
+ * or `{ clicks: false, heatmaps: false, … }` per capability. `false` also removes the provider's
333
+ * touch-observing wrapper view.
334
+ */
335
+ autocapture?: boolean | Partial<AutocaptureSettings>;
229
336
  /** How often to refresh the published config (default 5 minutes). */
230
337
  configRefreshMs?: number;
231
338
  /** Overrides for the project theme. */
232
339
  theme?: Partial<ProjectTheme>;
233
340
  /** Identify this user as soon as the client initialises. */
234
341
  user?: GuidelyUser;
342
+ /**
343
+ * Language for guides and the resource center (BCP 47, e.g. `fr` or `pt-BR`). Defaults to the
344
+ * user's `language` / `locale` trait, then the device language. Change it later with `setLocale()`.
345
+ */
346
+ locale?: string;
235
347
  /** Handles relative and custom-scheme URLs from buttons, links and tasks (deep links, in-app routes). Return `true` when handled. */
236
348
  onNavigate?: (url: string) => boolean | void;
237
349
  onError?: (error: Error) => void;
@@ -331,13 +443,18 @@ interface UiState {
331
443
  }
332
444
 
333
445
  declare const SDK_NAME = "@guidelytech/react-native";
334
- declare const SDK_VERSION = "0.9.0";
446
+ declare const SDK_VERSION = "0.11.0";
335
447
  declare const DEFAULT_API_URL = "https://guidelytech.com";
336
448
  /** Host-platform services the engine needs; the provider supplies React Native implementations. */
337
449
  interface PlatformBridge {
338
450
  device: DeviceEnvironment;
339
451
  /** Opens an external URL (React Native `Linking.openURL`). */
340
452
  openExternal(url: string): void;
453
+ /** Window size in points (React Native `Dimensions.get("window")`), for heatmaps. */
454
+ windowSize?(): {
455
+ width: number;
456
+ height: number;
457
+ };
341
458
  }
342
459
  /** Mobile sessions persist across launches and expire after the configured inactivity timeout. */
343
460
  interface MobileSession extends SessionState {
@@ -362,6 +479,8 @@ declare class GuidelyClient {
362
479
  private readonly store;
363
480
  private readonly emitter;
364
481
  private queue;
482
+ /** Survey answers, guide completions/dismissals and checklist progress, kept until the server has them. */
483
+ private outbox;
365
484
  private config;
366
485
  private configFetchedAt;
367
486
  private etag;
@@ -379,6 +498,7 @@ declare class GuidelyClient {
379
498
  private activeSurvey;
380
499
  private queued;
381
500
  private flows;
501
+ /** Checklists on screen, with the guide as rendered (in the visitor's language). */
382
502
  private checklists;
383
503
  private expanded;
384
504
  private surveyView;
@@ -398,6 +518,26 @@ declare class GuidelyClient {
398
518
  readonly flags: FlagsClient;
399
519
  /** Experiments already reported this session (`experiment_viewed` is sent once per session). */
400
520
  private exposures;
521
+ private readonly rage;
522
+ private readonly heatmap;
523
+ /** Taps are processed in order (target frames are measured asynchronously). */
524
+ private tapChain;
525
+ /** When the current screen's foreground measurement started; `screenLeft` once it has been reported. */
526
+ private screenStartedAt;
527
+ private screenLeft;
528
+ /** Last `app_open` (cold start or return to the foreground), for `app_background.foregroundMs`. */
529
+ private openedAt;
530
+ private launchChecked;
531
+ /** An identity was stored before this launch (an existing install adopting lifecycle events). */
532
+ private hadIdentity;
533
+ /** Language set with `setLocale()` (or the `locale` option). */
534
+ private locale;
535
+ /** Language each shown guide was rendered in; added to its events as `locale`. */
536
+ private guideLocales;
537
+ /** The resource center in the visitor's language, recomputed when the config or language changes. */
538
+ private localizedRc;
539
+ /** "What's new" last-seen time when the resource center opened (entries after it read as new). */
540
+ private announcementsSeenAtOpen;
401
541
  private readonly customListeners;
402
542
  private readonly eventBus;
403
543
  constructor(options: GuidelyOptions, bridge: PlatformBridge);
@@ -411,6 +551,8 @@ declare class GuidelyClient {
411
551
  private wireTimers;
412
552
  /** Re-fetches the published config and re-evaluates triggers. */
413
553
  refresh(): Promise<void>;
554
+ /** Re-renders after a config change (refresh, or a config that arrived after start). */
555
+ private applyConfigChange;
414
556
  /** Called by the provider with React Native `AppState` changes. */
415
557
  setAppState(state: "active" | "background" | "inactive" | string): void;
416
558
  private sessionExpired;
@@ -442,10 +584,54 @@ declare class GuidelyClient {
442
584
  /** The current screen name (last value passed to `screen()`). */
443
585
  getScreen(): string;
444
586
  private handleTap;
587
+ private captureAllowed;
588
+ /** A capability runs when the project enables it (absent on old servers → off), no option turns it off and analytics are allowed. */
589
+ private autocaptureOn;
590
+ /** `page_view` from `screen()` predates autocapture: only an explicit opt-out stops it. */
591
+ private pageviewsOn;
592
+ /** True when taps are worth observing (clicks, rage taps or heatmaps are on); the provider skips resolving views otherwise. */
593
+ isTapCaptureOn(): boolean;
594
+ /**
595
+ * Records a tap observed by the provider: `click` for an interactive element, `rage_click` for
596
+ * bursts and a heatmap point. A registered `<GuidelyTarget>` whose frame contains the point
597
+ * (smallest wins) takes precedence over the resolved element and is reported as `#<id>`.
598
+ */
599
+ recordTap(tap: TapInfo): void;
600
+ private processTap;
601
+ /** Sends the buffered heatmap taps as one `heatmap` event attributed to the screen they happened on. */
602
+ private flushHeatmap;
603
+ private windowSize;
604
+ /** Ends the foreground measurement of the current screen with a `page_leave` (once per measurement). */
605
+ private leaveScreen;
606
+ /** `{ appVersion, build }` of this launch, without unknown keys. */
607
+ private appInfo;
608
+ /**
609
+ * Once per launch, as soon as a config is known: `app_install` / `app_update` from the stored
610
+ * version (when the app passes `appVersion` and `storage`), then `app_open` with `coldStart: true`.
611
+ */
612
+ private checkLaunch;
613
+ private wentToBackground;
614
+ private cameToForeground;
445
615
  /** Builds the targeting context for the current moment. */
446
616
  getContext(): TargetingContext;
447
617
  private isTargeted;
448
618
  private isEligible;
619
+ /** Guide throttling: may this guide launch automatically now? */
620
+ private throttleAllows;
621
+ private recordLaunch;
622
+ /** Guides and A/B test control groups, which are evaluated the same way but never render. */
623
+ private candidates;
624
+ private holdoutFor;
625
+ /** The visitor's language candidates, most preferred first: `setLocale()` / `locale` option, traits, device. */
626
+ private locales;
627
+ private defaultLocale;
628
+ /** The guide in the visitor's language (remembered so its events carry `locale`). */
629
+ private localize;
630
+ /**
631
+ * Sets the language for guides and the resource center (`null` = back to the user's traits and
632
+ * the device language). Guides already on screen keep their language; the resource center re-renders.
633
+ */
634
+ setLocale(locale: string | null): void;
449
635
  private triggerFires;
450
636
  private evaluate;
451
637
  private armVisibility;
@@ -459,6 +645,8 @@ declare class GuidelyClient {
459
645
  private recordImpression;
460
646
  private recordEnd;
461
647
  private syncGuideState;
648
+ /** Queues a write in the persisted outbox (sent now, or once the API is reachable again). */
649
+ private sendDurably;
462
650
  private show;
463
651
  private showFlow;
464
652
  private showChecklist;
@@ -493,8 +681,28 @@ declare class GuidelyClient {
493
681
  closeSurvey(guideId: string): void;
494
682
  /** The visitor's audiences (from the last identify), for audience-targeted help articles. */
495
683
  getAudienceIds(): readonly string[];
684
+ /** The published resource center in the visitor's language, or null when it is off. */
496
685
  getResourceCenter(): ResourceCenterConfig | null;
686
+ /** The resource center in the visitor's language (cached until the config or language changes). */
687
+ private localizedResourceCenter;
688
+ /** Evaluates targeting rules (e.g. a resource-center section's) for the current visitor and screen. */
689
+ matchesTargeting(rules: RuleGroup | null | undefined): boolean;
690
+ /** Resource-center sections this visitor sees, in order (disabled and non-matching ones left out). */
691
+ getResourceCenterModules(): ResourceCenterModuleId[];
692
+ /**
693
+ * Sections of the messenger's Help tab, in order: the resource center's modules without "What's
694
+ * new" (the messenger has its own News tab); every section when no resource center is published.
695
+ */
696
+ getHelpModules(): ResourceCenterModuleId[];
697
+ /** "What's new" entries this visitor sees (newest first); empty when the section is off. */
698
+ getAnnouncements(): ResourceCenterAnnouncement[];
699
+ /** "What's new" entries published since the visitor last opened the resource center. */
700
+ getUnreadAnnouncements(): number;
701
+ /** Whether an entry is new to the visitor in the resource center that is open now. */
702
+ isAnnouncementNew(a: ResourceCenterAnnouncement): boolean;
497
703
  searchResourceCenter(q: string): Promise<ResourceCenterArticle[]>;
704
+ /** The language of the resource center as shown, when it isn't the default (sent with article fetches). */
705
+ private articleLocale;
498
706
  articleViewed(article: ResourceCenterArticle): void;
499
707
  getChecklistProgress(idOrKey: string): ChecklistProgressState;
500
708
  completeChecklistTask(idOrKey: string, taskId: string): void;
@@ -554,7 +762,7 @@ declare class GuidelyClient {
554
762
  guides: {
555
763
  id: string;
556
764
  key: string;
557
- kind: "tooltip" | "modal" | "banner" | "checklist" | "survey" | "flow" | "announcement";
765
+ kind: "banner" | "tooltip" | "modal" | "checklist" | "survey" | "flow" | "announcement";
558
766
  }[];
559
767
  activeGuide: {
560
768
  status: GuideStatus;
@@ -574,6 +782,7 @@ declare class GuidelyClient {
574
782
  audienceIds: string[];
575
783
  session: MobileSession;
576
784
  pendingEvents: number;
785
+ pendingWrites: number;
577
786
  targets: string[];
578
787
  flagsReady: boolean;
579
788
  };
@@ -664,6 +873,15 @@ interface OverlayProps {
664
873
  */
665
874
  declare function GuidelyOverlay({ client, insets: insetsProp, launcherOffset }: OverlayProps): react.JSX.Element;
666
875
 
876
+ interface GuidelyMaskProps extends ViewProps {
877
+ children?: ReactNode;
878
+ }
879
+ /**
880
+ * Keeps the text of its children out of product analytics: taps inside it (or on an element that
881
+ * contains it) are captured without `text`. Renders a plain `View`.
882
+ */
883
+ declare function GuidelyMask({ children, ...rest }: GuidelyMaskProps): react.JSX.Element;
884
+
667
885
  /**
668
886
  * Tiny, tolerant HTML → rich-text converter for guide bodies (already sanitized server-side).
669
887
  * Supports p, div, br, strong/b, em/i, u, a, code, ul/ol/li, h1–h6 and blockquote; every other tag
@@ -817,4 +1035,4 @@ declare function useGuideState(idOrKey: string): {
817
1035
  /** The guide currently running exclusively (flow, modal, survey…), or null. */
818
1036
  declare function useActiveGuide(): PublishedGuide | null;
819
1037
 
820
- export { type ChecklistView, DEFAULT_API_URL, type DeviceEnvironment, Feature, FeatureFlag, type FeatureProps, FeatureValue, type FeatureValueProps, FlagsProvider, type FlagsProviderProps, type GuideStepInfo, GuidelyClient, type GuidelyEventName, type GuidelyEvents, type GuidelyOptions, GuidelyOverlay, GuidelyProvider, type GuidelyProviderProps, GuidelyScreenScope, type GuidelyStorage, GuidelyTarget, type GuidelyTargetProps, type Insets, Messenger, type MessengerSnapshot, type MessengerTab, type MessengerThread, type MessengerView, type PlatformBridge, SDK_NAME, SDK_VERSION, type StepView, type SurveyView, TargetRegistry, type UiState, createSseParser, guidelyScreenLayout, htmlToText, noopClient, parseHtml, positionCard, targetIdsFor, useActiveGuide, useChecklistProgress, useFeatureValue, useFlag, useFlagDetails, useFlags, useFlagsClient, useFlagsReady, useGuideState, useGuidely, useGuidelyEvent, useGuidelyIdentify, useGuidelyNavigation, useGuidelyReady, useGuidelyScreen, useGuidelyTarget };
1038
+ export { type AutocaptureOption, type ChecklistView, DEFAULT_API_URL, type DeviceEnvironment, Feature, FeatureFlag, type FeatureProps, FeatureValue, type FeatureValueProps, FlagsProvider, type FlagsProviderProps, type GuideStepInfo, GuidelyClient, type GuidelyEventName, type GuidelyEvents, GuidelyMask, type GuidelyMaskProps, type GuidelyOptions, GuidelyOverlay, GuidelyProvider, type GuidelyProviderProps, GuidelyScreenScope, type GuidelyStorage, GuidelyTarget, type GuidelyTargetProps, HeatmapBuffer, type Insets, Messenger, type MessengerSnapshot, type MessengerTab, type MessengerThread, type MessengerView, type PlatformBridge, RageClickDetector, SDK_NAME, SDK_VERSION, type StepView, type SurveyView, type TapElement, type TapInfo, type TapProperties, TapTracker, TargetRegistry, type UiState, createSseParser, guidelyScreenLayout, htmlToText, noopClient, parseHtml, positionCard, targetIdsFor, useActiveGuide, useChecklistProgress, useFeatureValue, useFlag, useFlagDetails, useFlags, useFlagsClient, useFlagsReady, useGuideState, useGuidely, useGuidelyEvent, useGuidelyIdentify, useGuidelyNavigation, useGuidelyReady, useGuidelyScreen, useGuidelyTarget };