@incodetech/tri-sdk 0.1.0 → 0.1.1
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/chunks/index-BYO0AI0T.js +420 -0
- package/dist/chunks/index-BYO0AI0T.js.map +1 -0
- package/dist/chunks/index-BxmW7qox.cjs +432 -0
- package/dist/chunks/index-BxmW7qox.cjs.map +1 -0
- package/dist/chunks/index-CKUPedC4.cjs +432 -0
- package/dist/chunks/index-CKUPedC4.cjs.map +1 -0
- package/dist/chunks/index-NNGWKwfy.js +420 -0
- package/dist/chunks/index-NNGWKwfy.js.map +1 -0
- package/dist/chunks/start-B4n8DLY_.cjs +5554 -0
- package/dist/chunks/start-B4n8DLY_.cjs.map +1 -0
- package/dist/chunks/start-CJOOPw78.cjs +5554 -0
- package/dist/chunks/start-CJOOPw78.cjs.map +1 -0
- package/dist/chunks/start-CrKx_Alk.js +5552 -0
- package/dist/chunks/start-CrKx_Alk.js.map +1 -0
- package/dist/chunks/start-y4ZhvkRa.js +5552 -0
- package/dist/chunks/start-y4ZhvkRa.js.map +1 -0
- package/dist/index.d.ts +166 -37
- package/dist/tri.cjs.js +2 -5467
- package/dist/tri.cjs.js.map +1 -1
- package/dist/tri.esm.js +1 -5470
- package/dist/tri.esm.js.map +1 -1
- package/dist/tri.umd.js +2160 -1658
- package/dist/tri.umd.js.map +1 -1
- 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' | '
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
43
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
101
|
-
constructor();
|
|
102
|
-
static get instance():
|
|
221
|
+
private eventReportManager;
|
|
222
|
+
private constructor();
|
|
223
|
+
static get instance(): TRI$1;
|
|
224
|
+
/**
|
|
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.
|
|
230
|
+
*/
|
|
231
|
+
start(config?: TRIConfig): void;
|
|
103
232
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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.
|
|
107
237
|
*/
|
|
108
|
-
|
|
109
|
-
private _start;
|
|
238
|
+
stop(): void;
|
|
110
239
|
/**
|
|
111
|
-
* Reports a host-defined event to the TRI backend. Fire-and-forget —
|
|
112
|
-
* throws and never returns a promise the host must handle. Drops the
|
|
113
|
-
* silently (with a dev warning) if called before `
|
|
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
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
private
|
|
123
|
-
private _createCollectorsManagerContext;
|
|
245
|
+
private runStart;
|
|
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
|
|
254
|
+
declare const TRI: TRI$1;
|
|
127
255
|
|
|
128
|
-
export {
|
|
256
|
+
export { TRI as default };
|
|
257
|
+
export type { SanitizeUrlHook, TRIConfig, TriEnv as TRIEnv, TRIInterface as TRIInstance };
|