@incodetech/tri-sdk 0.1.0 → 0.1.2-dev-20260528

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 (65) hide show
  1. package/dist/bundle-analysis.html +4950 -0
  2. package/dist/chunks/index-BAwek9Id.cjs +489 -0
  3. package/dist/chunks/index-BAwek9Id.cjs.map +1 -0
  4. package/dist/chunks/index-BBnHO5vA.js +477 -0
  5. package/dist/chunks/index-BBnHO5vA.js.map +1 -0
  6. package/dist/chunks/index-BMVAKptw.cjs +432 -0
  7. package/dist/chunks/index-BMVAKptw.cjs.map +1 -0
  8. package/dist/chunks/index-BYO0AI0T.js +420 -0
  9. package/dist/chunks/index-BYO0AI0T.js.map +1 -0
  10. package/dist/chunks/index-B_sPgtA6.cjs +489 -0
  11. package/dist/chunks/index-B_sPgtA6.cjs.map +1 -0
  12. package/dist/chunks/index-BlclLEsV.js +420 -0
  13. package/dist/chunks/index-BlclLEsV.js.map +1 -0
  14. package/dist/chunks/index-BxmW7qox.cjs +432 -0
  15. package/dist/chunks/index-BxmW7qox.cjs.map +1 -0
  16. package/dist/chunks/index-CECrIW-A.js +420 -0
  17. package/dist/chunks/index-CECrIW-A.js.map +1 -0
  18. package/dist/chunks/index-CKUPedC4.cjs +432 -0
  19. package/dist/chunks/index-CKUPedC4.cjs.map +1 -0
  20. package/dist/chunks/index-DUZ-lBzx.js +477 -0
  21. package/dist/chunks/index-DUZ-lBzx.js.map +1 -0
  22. package/dist/chunks/index-NNGWKwfy.js +420 -0
  23. package/dist/chunks/index-NNGWKwfy.js.map +1 -0
  24. package/dist/chunks/index-SQXEe_Yi.cjs +432 -0
  25. package/dist/chunks/index-SQXEe_Yi.cjs.map +1 -0
  26. package/dist/chunks/index-kx-dpbK_.cjs +432 -0
  27. package/dist/chunks/index-kx-dpbK_.cjs.map +1 -0
  28. package/dist/chunks/index-uSwsY9-F.js +420 -0
  29. package/dist/chunks/index-uSwsY9-F.js.map +1 -0
  30. package/dist/chunks/start-B4n8DLY_.cjs +5554 -0
  31. package/dist/chunks/start-B4n8DLY_.cjs.map +1 -0
  32. package/dist/chunks/start-BnvikGDT.cjs +5059 -0
  33. package/dist/chunks/start-BnvikGDT.cjs.map +1 -0
  34. package/dist/chunks/start-CJOOPw78.cjs +5554 -0
  35. package/dist/chunks/start-CJOOPw78.cjs.map +1 -0
  36. package/dist/chunks/start-CMqC8j2A.cjs +5561 -0
  37. package/dist/chunks/start-CMqC8j2A.cjs.map +1 -0
  38. package/dist/chunks/start-CkLlbFOM.cjs +5554 -0
  39. package/dist/chunks/start-CkLlbFOM.cjs.map +1 -0
  40. package/dist/chunks/start-CrKx_Alk.js +5552 -0
  41. package/dist/chunks/start-CrKx_Alk.js.map +1 -0
  42. package/dist/chunks/start-CwAEBqvW.js +5057 -0
  43. package/dist/chunks/start-CwAEBqvW.js.map +1 -0
  44. package/dist/chunks/start-CymdUpX5.js +5060 -0
  45. package/dist/chunks/start-CymdUpX5.js.map +1 -0
  46. package/dist/chunks/start-DTFRIfeO.js +5552 -0
  47. package/dist/chunks/start-DTFRIfeO.js.map +1 -0
  48. package/dist/chunks/start-Dpgr8IbP.js +5559 -0
  49. package/dist/chunks/start-Dpgr8IbP.js.map +1 -0
  50. package/dist/chunks/start-Dtnxf7k4.cjs +5554 -0
  51. package/dist/chunks/start-Dtnxf7k4.cjs.map +1 -0
  52. package/dist/chunks/start-DwQtOigF.cjs +5062 -0
  53. package/dist/chunks/start-DwQtOigF.cjs.map +1 -0
  54. package/dist/chunks/start-MKWGpbIO.js +5552 -0
  55. package/dist/chunks/start-MKWGpbIO.js.map +1 -0
  56. package/dist/chunks/start-y4ZhvkRa.js +5552 -0
  57. package/dist/chunks/start-y4ZhvkRa.js.map +1 -0
  58. package/dist/index.d.ts +166 -37
  59. package/dist/tri.cjs.js +2 -5467
  60. package/dist/tri.cjs.js.map +1 -1
  61. package/dist/tri.esm.js +1 -5470
  62. package/dist/tri.esm.js.map +1 -1
  63. package/dist/tri.umd.js +2567 -2500
  64. package/dist/tri.umd.js.map +1 -1
  65. package/package.json +5 -7
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type CollectorKey = 'fingerprint' | 'pointer' | 'pointermove' | 'focus' | 'input' | 'keystroke' | 'clipboard' | 'form' | 'change' | 'selection' | 'visibility' | 'navigation' | 'viewportresize' | 'viewport' | 'scroll' | 'devicemotion' | 'networkrequest' | 'networkconnection' | 'permissionchange' | 'environmental';
1
+ type CollectorKey = 'fingerprint' | 'pointer' | 'pointermove' | 'focus' | 'input' | 'keystroke' | 'clipboard' | 'form' | 'change' | 'selection' | 'visibility' | 'navigation' | 'viewportresize' | 'viewport' | 'scroll' | 'devicemotion' | 'network-request' | 'networkconnection' | 'permissionchange' | 'environmental';
2
2
  type CollectorEventMap = {
3
3
  pointer: 'pointerdown' | 'pointerup' | 'click' | 'dblclick' | 'contextmenu' | 'dragend';
4
4
  focus: 'focusin' | 'focusout';
@@ -16,7 +16,7 @@ type CollectorEventMap = {
16
16
  viewportresize: never;
17
17
  scroll: never;
18
18
  devicemotion: never;
19
- networkrequest: never;
19
+ 'network-request': never;
20
20
  networkconnection: never;
21
21
  permissionchange: never;
22
22
  environmental: never;
@@ -24,44 +24,119 @@ type CollectorEventMap = {
24
24
  type Layer = 'session' | 'behavioral' | 'device-fingerprinting' | 'environmental-integrity' | 'network-intelligence' | 'persistent-identity';
25
25
 
26
26
  /**
27
- * Global PII capture level for the SDK.
27
+ * Hook that allows the host application to extend or replace the SDK's default
28
+ * URL sanitiser. Called for every URL before it is placed on the wire.
28
29
  *
29
- * - `'all'` — all fields emitted; PII identifiers and labels included.
30
+ * Receives the raw URL and the SDK's `defaultSanitize` implementation.
31
+ * The host may call `defaultSanitize(url)` to obtain the already-sanitised
32
+ * string and further transform it (e.g. remove additional path segments it
33
+ * knows are PII), or may bypass the default entirely for full control.
34
+ *
35
+ * If this function throws, the SDK falls back to `defaultSanitize(url)`.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * sanitizeUrl: (url, defaultSanitize) => {
40
+ * const sanitised = defaultSanitize(url)
41
+ * return sanitised.replace(/\/internal\/[^/]+/, '/internal/:id')
42
+ * }
43
+ * ```
44
+ */
45
+ type SanitizeUrlHook = (url: string, defaultSanitize: (url: string) => string) => string;
46
+ /**
47
+ * Global PII capture level for element context.
48
+ *
49
+ * - `'all'` — all element fields emitted; PII identifiers and labels included.
30
50
  * Consumers should annotate sensitive elements with `data-tri-redact`.
31
51
  * - `'redact'` — PII identifiers (`id`, `name`, label, classes) set to `null`.
32
- * Default. Per-element overrides via `data-tri-redact` / `data-tri-ignore`.
52
+ * **Default.** Per-element overrides via `data-tri-redact` / `data-tri-ignore`.
33
53
  * - `'off'` — Element Context Processor is skipped entirely; `element` is always `null`.
34
54
  */
35
55
  type CaptureElementLevel = 'all' | 'redact' | 'off';
56
+ /**
57
+ * Controls whether text content is captured from interacted elements.
58
+ *
59
+ * - `'on'` — text content emitted (default).
60
+ * - `'off'` — text content field is always `null`.
61
+ */
36
62
  type CaptureContentLevel = 'on' | 'off';
37
63
  /**
38
64
  * Public SDK configuration. Both `layers` and `collectors` are optional; pass at
39
65
  * most one. When neither is provided, every collector defaults to enabled (same
40
66
  * behaviour as calling `start()` with no config).
41
67
  */
42
- type TriSDKConfig = TriSDKConfigBase & (LayerBasedConfig | CollectorBasedConfig | NoCollectorSelectionConfig);
43
- type TriSDKConfigBase = {
68
+ type TRIConfig = TRIConfigBase & (LayerBasedConfig | CollectorBasedConfig | NoCollectorSelectionConfig);
69
+ /**
70
+ * Supported backend deployment environments.
71
+ *
72
+ * Currently provisioned (have a base URL):
73
+ * - `'STAGE_K8S'` — Kubernetes staging cluster.
74
+ *
75
+ * Known but **not yet provisioned** (will produce a fatal error at start):
76
+ * - `'SAAS'`, `'STAGE'`, `'DEMO'`, `'DEMO_K8S'`
77
+ *
78
+ * Prefer `apiURL` when targeting a self-hosted or custom deployment.
79
+ */
80
+ type TriEnv = 'STAGE_K8S' | 'SAAS' | 'STAGE' | 'DEMO' | 'DEMO_K8S';
81
+ /** Shared config fields present regardless of which selector variant is used. */
82
+ type TRIConfigShared = {
44
83
  capture?: {
45
84
  element?: CaptureElementLevel;
46
85
  content?: CaptureContentLevel;
47
86
  };
48
87
  profileId?: string;
49
- api: {
50
- key: string;
51
- version: string;
52
- url: string;
53
- };
88
+ apiKey: string;
89
+ apiVersion?: string;
90
+ /**
91
+ * Optional URL sanitiser hook. When omitted, the SDK applies its built-in
92
+ * default (strip credentials + fragment, redact query values, tokenise
93
+ * identifier path segments). Supply this to apply additional redaction
94
+ * on top of the default or to replace it entirely.
95
+ */
96
+ sanitizeUrl?: SanitizeUrlHook;
97
+ /**
98
+ * When `true`, the SDK emits diagnostic messages via `logger.warn`,
99
+ * `logger.error`, and `logger.info`. Defaults to `false`. Has no effect on
100
+ * `logger.fatal`, which always emits regardless of this flag.
101
+ */
102
+ debug?: boolean;
54
103
  };
104
+ /**
105
+ * Exactly one of `env` or `apiURL` must be supplied; both may be supplied
106
+ * (in which case `apiURL` takes precedence). Omitting both is a type error.
107
+ */
108
+ type TRIConfigBase = TRIConfigShared & ({
109
+ env: TriEnv;
110
+ apiURL?: string;
111
+ } | {
112
+ apiURL: string;
113
+ env?: TriEnv;
114
+ });
115
+ /**
116
+ * Optional per-event configuration inside a collector's `events` map.
117
+ * Omitted fields take their documented defaults (enabled = true, exclude = []).
118
+ */
55
119
  type EventConfig = {
120
+ /** When `false` the event type is never emitted. Defaults to `true`. */
56
121
  enabled?: boolean;
122
+ /** DOM selector strings whose targets are excluded from this event type. */
57
123
  exclude?: string[];
58
124
  };
125
+ /**
126
+ * Per-collector event configuration exposed in the public `CollectorsConfig`.
127
+ * Provides a collector-wide exclude list plus per-event `EventConfig` overrides.
128
+ */
59
129
  type CollectorEventsConfig<C extends CollectorKey> = {
60
130
  /** Applied to every event emitted by this collector. */
61
131
  exclude?: string[];
62
132
  } & {
63
133
  [E in CollectorEventMap[C]]?: EventConfig;
64
134
  };
135
+ /**
136
+ * Per-collector configuration. Eventless collectors (whose `CollectorEventMap`
137
+ * entry is `never`) only accept `enabled`; event-bearing collectors additionally
138
+ * accept an `events` map.
139
+ */
65
140
  type CollectorConfig<C extends CollectorKey> = [CollectorEventMap[C]] extends [
66
141
  never
67
142
  ] ? {
@@ -70,59 +145,113 @@ type CollectorConfig<C extends CollectorKey> = [CollectorEventMap[C]] extends [
70
145
  enabled?: boolean;
71
146
  events?: CollectorEventsConfig<C>;
72
147
  };
148
+ /**
149
+ * Host-supplied collector configuration map. Every key is optional — omitted
150
+ * collectors default to `disabled` when this field is present on `TRIConfig`.
151
+ */
73
152
  type CollectorsConfig = {
74
153
  [C in CollectorKey]?: CollectorConfig<C>;
75
154
  };
155
+ /** Enables all collectors whose `layer` matches one of the provided keys. Omitted layers default to disabled. */
76
156
  type LayerBasedConfig = {
77
157
  layers: Partial<Record<Layer, boolean>>;
78
158
  collectors?: never;
79
159
  };
160
+ /** Enables only the collectors explicitly listed, each with optional per-event overrides. */
80
161
  type CollectorBasedConfig = {
81
162
  layers?: never;
82
163
  collectors: CollectorsConfig;
83
164
  };
165
+ /** No collector filtering — all collectors are enabled by default. */
84
166
  type NoCollectorSelectionConfig = {
85
167
  layers?: never;
86
168
  collectors?: never;
87
169
  };
88
- interface TriSDKInterface {
89
- start(config?: TriSDKConfig): void;
170
+ /**
171
+ * Contract for the singleton `TRI` instance exposed to the host application.
172
+ * All methods are fire-and-forget — none throw, none return values the host must
173
+ * handle.
174
+ */
175
+ interface TRIInterface {
176
+ /** Starts the SDK with the supplied config. Idempotent while running. */
177
+ start(config?: TRIConfig): void;
178
+ /** Stops all collectors and tears down every manager. Idempotent. */
179
+ stop(): void;
180
+ /** Reports a host-defined event. Drops silently (with a dev warn) if not yet started. */
90
181
  reportEvent(name: string, metadata: Record<string, unknown>): void;
91
182
  }
92
183
 
93
- declare class TriSDK$1 implements TriSDKInterface {
184
+ /**
185
+ * Singleton entry-point for the TRI SDK.
186
+ *
187
+ * Obtain the instance via `TRI.instance`; the constructor is private.
188
+ *
189
+ * ### Life-cycle states
190
+ * The instance moves through three states:
191
+ * - `'idle'` — not started, or fully stopped.
192
+ * - `'starting'` — `start()` has been called; preflight and lazy bundle load in progress.
193
+ * - `'started'` — all managers are running and `reportEvent()` is active.
194
+ *
195
+ * ### Never throws
196
+ * All public methods are fire-and-forget. Errors are logged via `logger` and
197
+ * swallowed so the host application is never disrupted.
198
+ *
199
+ * ### Bundle split
200
+ * Only the preflight config validator and collection-status check live in the
201
+ * static bundle. The full manager wiring (`internal/start.ts`) is dynamically
202
+ * imported only when the backend confirms collection is enabled, keeping the
203
+ * initial page-load cost minimal.
204
+ */
205
+ declare class TRI$1 implements TRIInterface {
94
206
  private static _instance;
95
- private initialized;
207
+ /**
208
+ * Monotonically-increasing counter incremented by every `start()` and
209
+ * `stop()` call. Each in-flight `runStart` captures its own generation value
210
+ * and bails out after every `await` if the counter has moved on, preventing
211
+ * orphaned manager instances from being installed after a concurrent stop.
212
+ */
213
+ private startGeneration;
214
+ private startState;
215
+ private falconServiceManager;
96
216
  private activityManager;
97
217
  private transportManager;
98
218
  private tabManager;
219
+ private lifecycleManager;
99
220
  private collectorManager;
100
- private falconServiceManager;
101
- constructor();
102
- static get instance(): TriSDK$1;
221
+ private eventReportManager;
222
+ private constructor();
223
+ static get instance(): TRI$1;
103
224
  /**
104
- * Initialises the TRI SDK. Synchronous and idempotent — a second call is a
105
- * no-op. Safe to call in SSR environments; if `document` is unavailable the
106
- * function logs an error and returns without throwing.
225
+ * @description Starts the TRI SDK. Fire-and-forget and idempotent — a second
226
+ * call while the SDK is starting or already started is a no-op. Checks the
227
+ * backend `/collection-status` endpoint and only loads the full manager bundle
228
+ * when collection is enabled. Safe to call in SSR environments; if `document`
229
+ * is unavailable the function logs a fatal and returns without throwing.
107
230
  */
108
- start(config?: TriSDKConfig): void;
109
- private _start;
231
+ start(config?: TRIConfig): void;
110
232
  /**
111
- * Reports a host-defined event to the TRI backend. Fire-and-forget — never
112
- * throws and never returns a promise the host must handle. Drops the event
113
- * silently (with a dev warning) if called before `init`.
233
+ * @description Stops all collectors, flushes pending events, and tears down
234
+ * every manager. Safe to call more than once. After `stop()`, `start()` may be
235
+ * called again with a fresh config. Any in-flight `start()` is cancelled at
236
+ * the next async checkpoint.
237
+ */
238
+ stop(): void;
239
+ /**
240
+ * @description Reports a host-defined event to the TRI backend. Fire-and-forget —
241
+ * never throws and never returns a promise the host must handle. Drops the
242
+ * event silently (with a dev warning) if called before `start` completes.
114
243
  */
115
244
  reportEvent(name: string, metadata: Record<string, unknown>): void;
116
- private _shouldEarlyEscapeInit;
117
- private _shouldEarlyEscapeReportEvent;
118
- private _createFalconServiceManagerContext;
119
- private _createActivityManagerContext;
120
- private _createTransportManagerContext;
121
- private _createTabManagerContext;
122
- private _createLifecycleManagerContext;
123
- private _createCollectorsManagerContext;
245
+ private _start;
246
+ /**
247
+ * Returns `true` (and logs a dev warning) when `reportEvent()` should be a
248
+ * no-op. Guards against calling before the SDK is fully started, or when
249
+ * the `eventReportManager` is unexpectedly absent.
250
+ */
251
+ private _shouldEarlyEscapeReport;
124
252
  }
125
253
 
126
- declare const TriSDK: TriSDK$1;
254
+ declare const TRI: TRI$1;
127
255
 
128
- export { TriSDK as default };
256
+ export { TRI as default };
257
+ export type { SanitizeUrlHook, TRIConfig, TriEnv as TRIEnv, TRIInterface as TRIInstance };