@utk09/ui-observability 0.1.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 (62) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +217 -0
  3. package/dist/bus/bus.d.ts +134 -0
  4. package/dist/bus/links.d.ts +106 -0
  5. package/dist/capture/errors.d.ts +34 -0
  6. package/dist/capture/interactions.d.ts +29 -0
  7. package/dist/capture/network.d.ts +40 -0
  8. package/dist/capture/types.d.ts +78 -0
  9. package/dist/capture/web-vitals.d.ts +21 -0
  10. package/dist/constants-D8-4Ged5.cjs +2 -0
  11. package/dist/constants-D8-4Ged5.cjs.map +1 -0
  12. package/dist/constants-DbvMIryP.js +110 -0
  13. package/dist/constants-DbvMIryP.js.map +1 -0
  14. package/dist/constants.d.ts +339 -0
  15. package/dist/core/breadcrumbs.d.ts +48 -0
  16. package/dist/core/config.d.ts +16 -0
  17. package/dist/core/context.d.ts +35 -0
  18. package/dist/core/diagnostics.d.ts +76 -0
  19. package/dist/core/journey.d.ts +112 -0
  20. package/dist/core/logger.d.ts +117 -0
  21. package/dist/core/pipeline.d.ts +75 -0
  22. package/dist/core/record.d.ts +72 -0
  23. package/dist/core/runtime.d.ts +146 -0
  24. package/dist/core/sampling.d.ts +9 -0
  25. package/dist/index.cjs +4 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.ts +167 -0
  28. package/dist/index.js +2577 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/indexeddb-storage-DvsvCUlO.cjs +2 -0
  31. package/dist/indexeddb-storage-DvsvCUlO.cjs.map +1 -0
  32. package/dist/indexeddb-storage-DwpCDRnX.js +88 -0
  33. package/dist/indexeddb-storage-DwpCDRnX.js.map +1 -0
  34. package/dist/models/batch.d.ts +22 -0
  35. package/dist/models/bus.d.ts +97 -0
  36. package/dist/models/config.d.ts +528 -0
  37. package/dist/models/log-record.d.ts +54 -0
  38. package/dist/models/serializer.d.ts +23 -0
  39. package/dist/models/storage.d.ts +62 -0
  40. package/dist/storage/emergency-queue.d.ts +16 -0
  41. package/dist/storage/factory.d.ts +13 -0
  42. package/dist/storage/indexeddb-storage.d.ts +69 -0
  43. package/dist/storage/keys.d.ts +8 -0
  44. package/dist/storage/local-storage.d.ts +80 -0
  45. package/dist/storage/memory-storage.d.ts +52 -0
  46. package/dist/transport/compression.d.ts +7 -0
  47. package/dist/transport/errors.d.ts +29 -0
  48. package/dist/transport/exit-flush.d.ts +63 -0
  49. package/dist/transport/http-transport.d.ts +63 -0
  50. package/dist/transport/retry-engine.d.ts +69 -0
  51. package/dist/transport/serializers/ecs.d.ts +3 -0
  52. package/dist/transport/serializers/otlp.d.ts +3 -0
  53. package/dist/utils/console.d.ts +24 -0
  54. package/dist/utils/identity.d.ts +36 -0
  55. package/dist/utils/lock.d.ts +15 -0
  56. package/dist/utils/platform.d.ts +36 -0
  57. package/dist/utils/sanitize.d.ts +47 -0
  58. package/dist/utils/sequence.d.ts +15 -0
  59. package/dist/utils/timer.d.ts +19 -0
  60. package/dist/utils/tracing.d.ts +55 -0
  61. package/dist/utils/unref.d.ts +9 -0
  62. package/package.json +106 -0
@@ -0,0 +1,339 @@
1
+ import type { ResolvedConfig } from "./models/config";
2
+ import type { LogLevel, LogType } from "./models/log-record";
3
+ /** Prefix on console messages this library writes. */
4
+ export declare const LIBRARY_LOG_PREFIX = "[ui-observability]";
5
+ /** Throttle window per diagnostic code, in milliseconds. Limits how often an error loop can spam the handler. */
6
+ export declare const DIAGNOSTIC_THROTTLE_MS = 1000;
7
+ /** `localStorage` key for the session id and its last-seen time. */
8
+ export declare const SESSION_ID_KEY = "ui-observability.session";
9
+ /** `sessionStorage` key for the tab id. */
10
+ export declare const TAB_ID_KEY = "ui-observability.tab";
11
+ /** Session idle timeout, in milliseconds. */
12
+ export declare const SESSION_IDLE_MS: number;
13
+ /** Min gap between session last-seen writes, in milliseconds. */
14
+ export declare const SESSION_TOUCH_MS = 60000;
15
+ /** Random id length, in bytes, used when `crypto.randomUUID` is unavailable. */
16
+ export declare const ID_BYTE_LENGTH = 16;
17
+ /** Distinct values in one byte (256). */
18
+ export declare const BYTE_VALUE_COUNT = 256;
19
+ /** Matches OpenFin's user agent. */
20
+ export declare const OPENFIN_UA_PATTERN: RegExp;
21
+ /** Matches Android's webview token (`wv`). */
22
+ export declare const ANDROID_WEBVIEW_UA_PATTERN: RegExp;
23
+ /** Matches iOS hardware: iPhone, iPad, iPod. */
24
+ export declare const IOS_DEVICE_UA_PATTERN: RegExp;
25
+ /** Matches desktop macOS in a user agent. */
26
+ export declare const MACINTOSH_UA_PATTERN: RegExp;
27
+ /** Matches the mobile token. */
28
+ export declare const MOBILE_UA_PATTERN: RegExp;
29
+ /** WebKit engine token, present in every WebKit browser including webviews. */
30
+ export declare const WEBKIT_UA_TOKEN = "AppleWebKit";
31
+ /** Safari token sent by real iOS browsers, not in-app webviews. */
32
+ export declare const SAFARI_UA_TOKEN = "Safari/";
33
+ /** First UTF-16 high surrogate code unit. */
34
+ export declare const HIGH_SURROGATE_MIN = 55296;
35
+ /** Last UTF-16 high surrogate code unit. */
36
+ export declare const HIGH_SURROGATE_MAX = 56319;
37
+ /** Code units below this encode as one UTF-8 byte. */
38
+ export declare const UTF8_ONE_BYTE_CEILING = 128;
39
+ /** Code units below this, and at or above the one-byte ceiling, encode as two UTF-8 bytes. */
40
+ export declare const UTF8_TWO_BYTE_CEILING = 2048;
41
+ /** Class names kept in a `describeNode` selector. */
42
+ export declare const MAX_NODE_CLASS_NAMES = 3;
43
+ /** Byte cost of a null or undefined value. */
44
+ export declare const BYTES_PER_NULL = 4;
45
+ /** Byte cost of a number (flat estimate). */
46
+ export declare const BYTES_PER_NUMBER = 8;
47
+ /** Byte cost of a boolean. */
48
+ export declare const BYTES_PER_BOOLEAN = 5;
49
+ /** Byte cost of an object or array's wrapping braces or brackets. */
50
+ export declare const BYTES_PER_CONTAINER = 2;
51
+ /** Byte cost of a string's wrapping quotes. */
52
+ export declare const BYTES_PER_QUOTED_STRING = 2;
53
+ /** Byte cost of one key's punctuation: quotes, colon, comma. */
54
+ export declare const BYTES_PER_KEY_OVERHEAD = 4;
55
+ /**
56
+ * Log level to OpenTelemetry severity number.
57
+ * @see {@link LEVEL_ORDER}
58
+ */
59
+ export declare const SEVERITY_NUMBER: Record<LogLevel, number>;
60
+ /**
61
+ * Alias for `SEVERITY_NUMBER`, used by the level filter.
62
+ * @see {@link SEVERITY_NUMBER}
63
+ */
64
+ export declare const LEVEL_ORDER: Record<LogLevel, number>;
65
+ /** Record kind attribute key. */
66
+ export declare const ATTR_LOG_TYPE = "log.type";
67
+ /** Record sequence number within its context, from zero. */
68
+ export declare const ATTR_LOG_SEQ = "log.seq";
69
+ /** Logger namespace attribute key. */
70
+ export declare const ATTR_APP_NAMESPACE = "app.namespace";
71
+ /** Document URL when the record was built. */
72
+ export declare const ATTR_PAGE_URL = "page.url";
73
+ /**
74
+ * HTTP request URL attribute key, set by network capture. Don't reuse `ATTR_PAGE_URL`; it would overwrite the request's target.
75
+ * @see {@link ATTR_PAGE_URL}
76
+ */
77
+ export declare const ATTR_URL_FULL = "url.full";
78
+ /** Journey id attribute key. */
79
+ export declare const ATTR_JOURNEY_ID = "journey.id";
80
+ /** Journey name attribute key. */
81
+ export declare const ATTR_JOURNEY_NAME = "journey.name";
82
+ /** Parent journey id, present only on a child journey. */
83
+ export declare const ATTR_JOURNEY_PARENT_ID = "journey.parent_id";
84
+ /** Marks a record whose attributes failed to sanitize. */
85
+ export declare const ATTR_SANITIZE_FAILED = "uiobs.sanitize_failed";
86
+ /**
87
+ * Marks a record whose attributes were dropped for exceeding the byte budget.
88
+ * @see {@link ATTR_ATTRIBUTES_BYTES}
89
+ */
90
+ export declare const ATTR_ATTRIBUTES_DROPPED = "uiobs.attributes_dropped";
91
+ /**
92
+ * Byte size of the dropped attributes.
93
+ * @see {@link ATTR_ATTRIBUTES_DROPPED}
94
+ */
95
+ export declare const ATTR_ATTRIBUTES_BYTES = "uiobs.attributes_bytes";
96
+ /** Application name resource key. */
97
+ export declare const RESOURCE_SERVICE_NAME = "service.name";
98
+ /** Application build version resource key. */
99
+ export declare const RESOURCE_SERVICE_VERSION = "service.version";
100
+ /** Deployment environment resource key. */
101
+ export declare const RESOURCE_DEPLOYMENT_ENVIRONMENT = "deployment.environment";
102
+ /**
103
+ * Producer library name resource key.
104
+ * @see {@link TELEMETRY_SDK_NAME}
105
+ */
106
+ export declare const RESOURCE_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
107
+ /**
108
+ * Producer library version resource key.
109
+ * @see {@link TELEMETRY_SDK_VERSION}
110
+ */
111
+ export declare const RESOURCE_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
112
+ /**
113
+ * Producer SDK language resource key.
114
+ * @see {@link TELEMETRY_SDK_LANGUAGE}
115
+ */
116
+ export declare const RESOURCE_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
117
+ /** Host platform resource key: browser, webview, or OpenFin. */
118
+ export declare const RESOURCE_HOST_PLATFORM = "host.platform";
119
+ /** Session id resource key. */
120
+ export declare const RESOURCE_SESSION_ID = "session.id";
121
+ /** Tab id resource key. */
122
+ export declare const RESOURCE_TAB_ID = "tab.id";
123
+ /** Context (realm) id resource key. */
124
+ export declare const RESOURCE_CONTEXT_ID = "context.id";
125
+ /** Raw user agent resource key. */
126
+ export declare const RESOURCE_BROWSER_USER_AGENT = "browser.user_agent";
127
+ /** OpenFin application uuid resource key. */
128
+ export declare const RESOURCE_OPENFIN_UUID = "openfin.uuid";
129
+ /** OpenFin window or view name resource key. */
130
+ export declare const RESOURCE_OPENFIN_NAME = "openfin.name";
131
+ /**
132
+ * Value of `telemetry.sdk.name`.
133
+ * @see {@link RESOURCE_TELEMETRY_SDK_NAME}
134
+ */
135
+ export declare const TELEMETRY_SDK_NAME = "@utk09/ui-observability";
136
+ /**
137
+ * Value of `telemetry.sdk.version`. A literal, not read from package.json. Bump by hand alongside package.json.
138
+ * @see {@link RESOURCE_TELEMETRY_SDK_VERSION}
139
+ */
140
+ export declare const TELEMETRY_SDK_VERSION = "0.1.0";
141
+ /**
142
+ * Value of `telemetry.sdk.language`.
143
+ * @see {@link RESOURCE_TELEMETRY_SDK_LANGUAGE}
144
+ */
145
+ export declare const TELEMETRY_SDK_LANGUAGE = "webjs";
146
+ /** OTLP/JSON serializer name. */
147
+ export declare const SERIALIZER_NAME_OTLP = "otlp";
148
+ /** ECS serializer name. */
149
+ export declare const SERIALIZER_NAME_ECS = "ecs";
150
+ /** Content type for an OTLP/JSON body. */
151
+ export declare const CONTENT_TYPE_JSON = "application/json";
152
+ /** Content type for newline-delimited JSON. */
153
+ export declare const CONTENT_TYPE_NDJSON = "application/x-ndjson";
154
+ /** Nanoseconds per millisecond. */
155
+ export declare const NANOS_PER_MILLI = 1000000n;
156
+ /** Content-Type header name. */
157
+ export declare const HEADER_CONTENT_TYPE = "Content-Type";
158
+ /** Content-Encoding header name. */
159
+ export declare const HEADER_CONTENT_ENCODING = "Content-Encoding";
160
+ /** Retry-After header name. */
161
+ export declare const HEADER_RETRY_AFTER = "Retry-After";
162
+ /**
163
+ * Batch deduplication key header name.
164
+ * @see {@link QUERY_PARAM_BATCH_ID}
165
+ */
166
+ export declare const HEADER_BATCH_ID = "X-UiObs-Batch-Id";
167
+ /** Delivery attempt number header name. */
168
+ export declare const HEADER_ATTEMPT = "X-UiObs-Attempt";
169
+ /** Gzip encoding name. */
170
+ export declare const ENCODING_GZIP = "gzip";
171
+ /** 401, credentials missing or rejected. */
172
+ export declare const HTTP_UNAUTHORIZED = 401;
173
+ /** 403, valid credentials but access denied. */
174
+ export declare const HTTP_FORBIDDEN = 403;
175
+ /** 408, the server closed the connection after a timeout. Retryable. */
176
+ export declare const HTTP_REQUEST_TIMEOUT = 408;
177
+ /** 413, payload too large; batch must be split. */
178
+ export declare const HTTP_PAYLOAD_TOO_LARGE = 413;
179
+ /** 429, backpressure. */
180
+ export declare const HTTP_TOO_MANY_REQUESTS = 429;
181
+ /** 500, floor for server-side errors. */
182
+ export declare const HTTP_SERVER_ERROR_MIN = 500;
183
+ /** 503, temporary unavailability. */
184
+ export declare const HTTP_SERVICE_UNAVAILABLE = 503;
185
+ /** Milliseconds per second. */
186
+ export declare const MILLIS_PER_SECOND = 1000;
187
+ /** Max exit payload size, in bytes (`sendBeacon`/`fetch(keepalive)` shared budget). */
188
+ export declare const BEACON_LIMIT_BYTES = 60000;
189
+ /** Content type for an exit payload. CORS-safelisted, avoids a preflight. */
190
+ export declare const CONTENT_TYPE_TEXT_PLAIN = "text/plain;charset=UTF-8";
191
+ /**
192
+ * Batch id query param name, for the exit path.
193
+ * @see {@link HEADER_BATCH_ID}
194
+ */
195
+ export declare const QUERY_PARAM_BATCH_ID = "uiobs_batch_id";
196
+ /** Exit reason query param name, for logs only. */
197
+ export declare const QUERY_PARAM_EXIT_REASON = "uiobs_exit";
198
+ /** localStorage key prefix for a parked batch. */
199
+ export declare const BATCH_STORAGE_KEY_PREFIX = "ui-observability.batch.";
200
+ /** Zero-padded digit width for the creation time in a batch key. */
201
+ export declare const BATCH_KEY_TIME_WIDTH = 14;
202
+ /** localStorage key prefix for a batch parked by exit flush. */
203
+ export declare const EMERGENCY_STORAGE_KEY_PREFIX = "ui-observability.emergency.";
204
+ /** Max exit batches held at once. */
205
+ export declare const EMERGENCY_MAX_ENTRIES = 20;
206
+ /** Key used to test whether localStorage accepts writes. */
207
+ export declare const STORAGE_PROBE_KEY = "ui-observability.probe";
208
+ /** Fraction of the store evicted on a quota error (1 in N). */
209
+ export declare const QUOTA_EVICTION_DIVISOR = 4;
210
+ /** DOMException name for a full store. */
211
+ export declare const QUOTA_EXCEEDED_ERROR = "QuotaExceededError";
212
+ /** IndexedDB schema version. Bumping it requires a matching Dexie migration. */
213
+ export declare const INDEXEDDB_SCHEMA_VERSION = 1;
214
+ /** IndexedDB adapter/strategy name. */
215
+ export declare const STORAGE_NAME_INDEXEDDB = "indexeddb";
216
+ /** localStorage adapter/strategy name. */
217
+ export declare const STORAGE_NAME_LOCAL = "localstorage";
218
+ /** In-memory adapter/strategy name. */
219
+ export declare const STORAGE_NAME_MEMORY = "memory";
220
+ /** No-op adapter/strategy name. */
221
+ export declare const STORAGE_NAME_NONE = "none";
222
+ /**
223
+ * Origin-wide lock name a drain runs under.
224
+ * @see {@link EMERGENCY_LOCK_NAME}
225
+ */
226
+ export declare const DRAIN_LOCK_NAME = "ui-observability.drain";
227
+ /**
228
+ * Lock name startup recovery runs under.
229
+ * @see {@link DRAIN_LOCK_NAME}
230
+ */
231
+ export declare const EMERGENCY_LOCK_NAME = "ui-observability.emergency";
232
+ /** Batches sent per drain tick. */
233
+ export declare const BATCHES_PER_DRAIN = 20;
234
+ /** `sessionStorage` key for the current journey. */
235
+ export declare const JOURNEY_STORAGE_KEY = "ui-observability.journey";
236
+ /**
237
+ * Max journey name length in a token, in characters.
238
+ * @see {@link JOURNEY_TOKEN_MAX_CHARS}
239
+ */
240
+ export declare const JOURNEY_TOKEN_NAME_MAX_CHARS = 64;
241
+ /**
242
+ * Max whole-token length, in characters. A tripwire, not validation.
243
+ * @see {@link JOURNEY_TOKEN_NAME_MAX_CHARS}
244
+ */
245
+ export declare const JOURNEY_TOKEN_MAX_CHARS = 256;
246
+ /** Key under an OpenFin window's `customData` carrying a seeded journey token. */
247
+ export declare const OPENFIN_JOURNEY_CUSTOM_DATA_KEY = "uiObsJourney";
248
+ /** Matches `+` in standard base64 (`-` in URL-safe). */
249
+ export declare const BASE64_PLUS_PATTERN: RegExp;
250
+ /** Matches `/` in standard base64 (`_` in URL-safe). */
251
+ export declare const BASE64_SLASH_PATTERN: RegExp;
252
+ /** Matches trailing `=` padding. */
253
+ export declare const BASE64_PADDING_PATTERN: RegExp;
254
+ /** Matches `-` in URL-safe base64 (`+` in standard). */
255
+ export declare const BASE64URL_DASH_PATTERN: RegExp;
256
+ /** Matches `_` in URL-safe base64 (`/` in standard). */
257
+ export declare const BASE64URL_UNDERSCORE_PATTERN: RegExp;
258
+ /** Base64 characters per 3-byte group. */
259
+ export declare const BASE64_GROUP_CHARS = 4;
260
+ /** W3C trace id width, in bytes. */
261
+ export declare const TRACE_ID_BYTES = 16;
262
+ /** W3C span id width, in bytes. */
263
+ export declare const SPAN_ID_BYTES = 8;
264
+ /** Max ambient trace lifetime with no activity, in milliseconds. */
265
+ export declare const TRACE_MAX_AGE_MS: number;
266
+ /** trace-flags value with the sampled bit set. */
267
+ export declare const TRACE_FLAGS_SAMPLED = 1;
268
+ /** Mask for the one-byte trace-flags field. */
269
+ export declare const TRACE_FLAGS_MASK = 255;
270
+ /** traceparent header version prefix. */
271
+ export declare const TRACEPARENT_VERSION = "00";
272
+ /** Smallest valid breadcrumb buffer capacity. */
273
+ export declare const BREADCRUMB_MIN_CAPACITY = 1;
274
+ /** FNV-1a 32-bit offset basis. */
275
+ export declare const FNV_OFFSET_BASIS = 2166136261;
276
+ /** FNV-1a 32-bit prime. */
277
+ export declare const FNV_PRIME = 16777619;
278
+ /** Largest 32-bit unsigned value. */
279
+ export declare const UINT32_MAX = 4294967295;
280
+ /** Record kind routed to the metric stream. */
281
+ export declare const LOG_TYPE_METRIC: LogType;
282
+ /** Batches held per stream buffer before the oldest is dropped. */
283
+ export declare const PENDING_BUFFER_BATCHES = 10;
284
+ /** Protocol identifier for bus envelopes. Mismatched versions are dropped. */
285
+ export declare const BUS_PROTOCOL = "ui-observability/1";
286
+ /** Global window property key used to locate a same-origin runtime instance. */
287
+ export declare const RUNTIME_GLOBAL_KEY = "ui-observability.runtime";
288
+ /** Maximum error records captured per throttling window before suppression. */
289
+ export declare const ERROR_STORM_MAX_PER_WINDOW = 20;
290
+ /** Error rate-limiting window duration in milliseconds. */
291
+ export declare const ERROR_STORM_WINDOW_MS = 10000;
292
+ /** Maximum distinct error signatures tracked for deduplication before LRU eviction. */
293
+ export declare const MAX_TRACKED_ERROR_SIGNATURES = 200;
294
+ /** Maximum character length retained from clicked element text in breadcrumbs. */
295
+ export declare const CLICK_TEXT_MAX_CHARS = 50;
296
+ /** Maximum character length retained from an aria-label attribute in generated selectors. */
297
+ export declare const ARIA_LABEL_MAX_CHARS = 40;
298
+ /** Maximum class names included per element in generated CSS selectors. */
299
+ export declare const SELECTOR_MAX_CLASSES = 2;
300
+ /** CSS styling applied to console prefix labels. */
301
+ export declare const CONSOLE_PREFIX_STYLE = "color:#888";
302
+ /** Scaling factor for rounding duration measurements to three decimal places. */
303
+ export declare const DURATION_PRECISION = 1000;
304
+ /** Minimum duration in milliseconds between storage gap warning reports. */
305
+ export declare const GAP_REPORT_THROTTLE_MS = 60000;
306
+ /** Default namespace for telemetry records emitted by auto-capture modules. */
307
+ export declare const CAPTURE_NAMESPACE = "uiobs.capture";
308
+ /** Default namespace for telemetry records emitted by storage subsystems. */
309
+ export declare const STORAGE_NAMESPACE = "uiobs.storage";
310
+ /** Fallback measurement unit applied when none is specified. */
311
+ export declare const DEFAULT_METRIC_UNIT = "count";
312
+ /** Default `service.name` when a consumer sets none. */
313
+ export declare const UNKNOWN_SERVICE_NAME = "unknown-service";
314
+ /** Lowest sampling rate (drop everything). */
315
+ export declare const SAMPLING_RATE_MIN = 0;
316
+ /** Highest sampling rate (keep everything). */
317
+ export declare const SAMPLING_RATE_MAX = 1;
318
+ /**
319
+ * Fallback for an invalid sampling rate (keep everything).
320
+ * @see {@link SAMPLING_RATE_MAX}
321
+ */
322
+ export declare const SAMPLING_RATE_FALLBACK = 1;
323
+ /**
324
+ * Config keys with no default, excluded from `DEFAULT_CONFIG`.
325
+ * @see {@link DEFAULT_CONFIG}
326
+ */
327
+ export declare const UNDEFAULTED_CONFIG_KEYS: readonly ["redact", "onDiagnostic", "headers", "serializer"];
328
+ /**
329
+ * Nested config section keys.
330
+ * @see {@link ResolvedConfig}
331
+ */
332
+ export declare const CONFIG_SECTIONS: readonly ["streams", "storage", "retry", "sampling", "journey", "bus", "capture", "limits", "console"];
333
+ /**
334
+ * Default runtime config, before a consumer's `configure()` call.
335
+ * Excludes `serializer`; `resolveConfig` supplies its default to avoid a circular import.
336
+ * @see {@link ResolvedConfig}
337
+ * @see {@link UNDEFAULTED_CONFIG_KEYS}
338
+ */
339
+ export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, "serializer">;
@@ -0,0 +1,48 @@
1
+ /** Category classification for breadcrumb events. */
2
+ export type BreadcrumbCategory = "log" | "action" | "event" | "click" | "navigation" | "http" | "console";
3
+ /** Lightweight event summary recorded prior to errors. */
4
+ export interface Breadcrumb {
5
+ /** Timestamp in epoch milliseconds. */
6
+ t: number;
7
+ /** Event category classification. */
8
+ category: BreadcrumbCategory;
9
+ /** Human-readable event description. */
10
+ message: string;
11
+ /** Optional contextual metadata. */
12
+ data?: Record<string, unknown>;
13
+ }
14
+ /** Bounded circular ring buffer storing recent breadcrumb events in chronological order. */
15
+ export declare class BreadcrumbBuffer {
16
+ /** Internal storage array for the ring buffer. */
17
+ private buffer;
18
+ /** Next write index in the circular buffer. */
19
+ private pointer;
20
+ /**
21
+ * Indicates whether the buffer has wrapped around its capacity. The pointer alone
22
+ * cannot separate an unwritten ring from one wrapped exactly to the start.
23
+ */
24
+ private filled;
25
+ /** Maximum number of breadcrumbs retained in memory. */
26
+ private capacity;
27
+ /**
28
+ * @param capacity Maximum breadcrumb capacity, clamped to minimum allowed size.
29
+ */
30
+ constructor(capacity: number);
31
+ /**
32
+ * Resizes buffer capacity while preserving the newest breadcrumbs.
33
+ * @param capacity New maximum capacity.
34
+ */
35
+ resize(capacity: number): void;
36
+ /**
37
+ * Appends a breadcrumb, overwriting the oldest entry when capacity is reached.
38
+ * @param crumb Breadcrumb event to append.
39
+ */
40
+ push(crumb: Breadcrumb): void;
41
+ /**
42
+ * Returns all stored breadcrumbs ordered from oldest to newest.
43
+ * @returns Chronological list of breadcrumbs.
44
+ */
45
+ snapshot(): Breadcrumb[];
46
+ /** Clears all stored breadcrumbs and resets buffer state. */
47
+ clear(): void;
48
+ }
@@ -0,0 +1,16 @@
1
+ import type { ObservabilityConfig, ResolvedConfig } from "../models/config";
2
+ import type { Diagnostics } from "./diagnostics";
3
+ /**
4
+ * Resolves partial configuration inputs into a validated ResolvedConfig object.
5
+ * @param input Partial consumer configuration options.
6
+ * @param diagnostics Diagnostics reporter.
7
+ * @param previous Active configuration instance for incremental reconfigurations.
8
+ * @returns Fully populated and validated configuration object.
9
+ */
10
+ export declare function resolveConfig(input: Partial<ObservabilityConfig>, diagnostics: Diagnostics, previous?: ResolvedConfig): ResolvedConfig;
11
+ /**
12
+ * Mutates an existing configuration object in place to propagate updates to referenced sections.
13
+ * @param target Active configuration object to mutate.
14
+ * @param next Source configuration object containing updated values.
15
+ */
16
+ export declare function applyResolvedConfig(target: ResolvedConfig, next: ResolvedConfig): void;
@@ -0,0 +1,35 @@
1
+ /** Key-value store for ambient context attributes attached to log records. */
2
+ export declare class ContextStore {
3
+ /** Backing store mapping attribute keys to raw values. */
4
+ private readonly map;
5
+ /**
6
+ * Sets an ambient context attribute key and value.
7
+ * @param key Attribute key.
8
+ * @param value Raw attribute value.
9
+ */
10
+ set(key: string, value: unknown): void;
11
+ /**
12
+ * Merges multiple key-value pairs into the ambient context store.
13
+ * @param values Record of attributes to merge.
14
+ */
15
+ setMany(values: Record<string, unknown>): void;
16
+ /**
17
+ * Retrieves an attribute value by key.
18
+ * @param key Attribute key.
19
+ * @returns Stored attribute value or undefined if not set.
20
+ */
21
+ get(key: string): unknown;
22
+ /**
23
+ * Deletes an attribute from the ambient context store.
24
+ * @param key Attribute key to remove.
25
+ */
26
+ remove(key: string): void;
27
+ /** Clears all attributes from the ambient context store. */
28
+ clear(): void;
29
+ /**
30
+ * Returns a snapshot copy of all ambient context attributes. A copy: a merge
31
+ * target or sanitizer must not mutate the store.
32
+ * @returns Plain object containing stored key-value pairs.
33
+ */
34
+ getAll(): Record<string, unknown>;
35
+ }
@@ -0,0 +1,76 @@
1
+ /** Closed set of diagnostic event codes emitted by library subsystems. */
2
+ export type DiagnosticCode = "config.invalid" | "config.reconfigured" | "record.sanitize_failed" | "record.truncated" | "record.dropped_by_level" | "record.dropped_by_sampling" | "record.dropped_by_redact" | "record.dropped_boot_buffer_full" | "record.dropped_pending_full" | "record.dropped_malformed" | "journey.expired" | "journey.adopted" | "journey.token_too_large" | "trace.otel_failed" | "bus.role_resolved" | "bus.no_owner" | "bus.handshake_timeout" | "bus.untrusted_origin" | "bus.send_failed" | "transport.http_error" | "transport.timeout" | "transport.batch_split" | "transport.throttled" | "transport.dropped_permanent" | "transport.rejected_credentials" | "transport.serialize_failed" | "storage.unavailable" | "storage.degraded" | "storage.quota_exceeded" | "storage.evicted" | "storage.dead_lettered" | "pipeline.crashed" | "capture.install_failed" | "capture.rate_limited" | "capture.header_failed" | "capture.record_failed" | "openfin.unavailable" | "handler.threw";
3
+ /** Diagnostic event payload dispatched to consumer handlers. */
4
+ export interface DiagnosticEvent {
5
+ /** Diagnostic fault code. */
6
+ code: DiagnosticCode;
7
+ /** Human-readable description. */
8
+ message: string;
9
+ /** Structured context metadata. */
10
+ detail?: Record<string, unknown>;
11
+ /** Caught error instance or reason. */
12
+ cause?: unknown;
13
+ /** Event timestamp in epoch milliseconds. */
14
+ at: number;
15
+ /** Cumulative count of this code since startup, including rate-limited occurrences. */
16
+ count: number;
17
+ }
18
+ /** Consumer callback for receiving rate-limited diagnostic events. */
19
+ export type DiagnosticHandler = (event: DiagnosticEvent) => void;
20
+ /** Internal error reporting channel with rate-limited dispatch and unthrottled counters. */
21
+ export declare class Diagnostics {
22
+ private handler?;
23
+ private readonly throttleMs;
24
+ /** Running occurrence counts per diagnostic code. */
25
+ private readonly counters;
26
+ /** Timestamp of last emitted event per code in epoch milliseconds. */
27
+ private readonly lastEmitted;
28
+ /**
29
+ * @param handler Optional diagnostic event listener callback.
30
+ * @param throttleMs Minimum duration in milliseconds between emitted events for a single code.
31
+ */
32
+ constructor(handler?: DiagnosticHandler | undefined, throttleMs?: number);
33
+ /**
34
+ * Updates or removes the active diagnostic event handler.
35
+ * @param handler New diagnostic event handler.
36
+ */
37
+ setHandler(handler?: DiagnosticHandler): void;
38
+ /**
39
+ * Increments the occurrence count for a code without triggering handler emission.
40
+ * @param code Diagnostic code to increment.
41
+ * @param by Increment delta.
42
+ * @returns Updated cumulative total for the code.
43
+ */
44
+ count(code: DiagnosticCode, by?: number): number;
45
+ /**
46
+ * Increments counter and dispatches event if outside the throttling window. Never throws.
47
+ * @param code Diagnostic code.
48
+ * @param message Event description.
49
+ * @param detail Optional structured metadata.
50
+ * @param cause Caught error instance or reason.
51
+ */
52
+ report(code: DiagnosticCode, message: string, detail?: Record<string, unknown>, cause?: unknown): void;
53
+ /**
54
+ * Executes a synchronous function and reports any thrown error to diagnostics.
55
+ * @param code Diagnostic code to report on throw.
56
+ * @param message Error description.
57
+ * @param fn Function to execute.
58
+ * @returns Function return value, or undefined on throw.
59
+ */
60
+ guard<T>(code: DiagnosticCode, message: string, fn: () => T): T | undefined;
61
+ /**
62
+ * Executes an asynchronous function and reports any rejected promise to diagnostics.
63
+ * @param code Diagnostic code to report on rejection.
64
+ * @param message Error description.
65
+ * @param fn Async function to execute.
66
+ * @returns Promise resolving to the return value, or undefined on rejection.
67
+ */
68
+ guardAsync<T>(code: DiagnosticCode, message: string, fn: () => Promise<T>): Promise<T | undefined>;
69
+ /**
70
+ * Returns a copy of all cumulative diagnostic event counts since initialization.
71
+ * @returns Map of diagnostic codes to occurrence counts.
72
+ */
73
+ snapshot(): Record<string, number>;
74
+ /** Clears all counters and throttling history. */
75
+ reset(): void;
76
+ }
@@ -0,0 +1,112 @@
1
+ import type { JourneyOptions } from "../models/config";
2
+ import type { Diagnostics } from "./diagnostics";
3
+ /** User journey workflow context shared across windows and applications. */
4
+ export interface Journey {
5
+ /** Unique journey correlation identifier. */
6
+ id: string;
7
+ /** Human-readable journey workflow name. */
8
+ name: string;
9
+ /** Journey start timestamp in epoch milliseconds. */
10
+ startedAt: number;
11
+ /** Optional parent journey identifier when branched from an earlier workflow. */
12
+ parentId?: string;
13
+ /** Context identifier of the document that initiated the journey. */
14
+ ownerContextId: string;
15
+ }
16
+ /** Manages journey lifecycle, cross-window adoption, storage synchronization, and expiration. */
17
+ export declare class JourneyEngine {
18
+ private readonly options;
19
+ private readonly diagnostics;
20
+ private readonly contextId;
21
+ private readonly onLocalChange;
22
+ /** Active journey context, or null if none is in progress. */
23
+ private journey;
24
+ /** Active expiration timer handle. */
25
+ private expiryTimer;
26
+ /**
27
+ * @param options Journey configuration thresholds.
28
+ * @param diagnostics Diagnostics reporter.
29
+ * @param contextId Unique context identifier for this document.
30
+ * @param onLocalChange Callback invoked when journey state changes locally.
31
+ */
32
+ constructor(options: JourneyOptions, diagnostics: Diagnostics, contextId: string, onLocalChange: (journey: Journey | null) => void);
33
+ /** Returns the active journey instance or null. */
34
+ current(): Journey | null;
35
+ /**
36
+ * Discovers and adopts initial journey from URL query parameters, sessionStorage, or OpenFin customData.
37
+ * @returns Promise resolving when journey initialization completes.
38
+ */
39
+ bootstrap(): Promise<void>;
40
+ /**
41
+ * Initiates a new journey, replacing any active journey and notifying connected peers.
42
+ * @param name Human-readable workflow name.
43
+ * @param opts Optional parent linkage and pre-assigned identifier.
44
+ * @returns Started Journey instance.
45
+ */
46
+ start(name: string, opts?: {
47
+ parent?: boolean;
48
+ id?: string;
49
+ }): Journey;
50
+ /** Terminates the active journey and broadcasts the change. */
51
+ end(): void;
52
+ /**
53
+ * Applies journey updates received from external bus peers without echoing
54
+ * broadcasts. Echoing makes two windows ping the change back and forth. A journey
55
+ * matching the one in force is ignored, so an echo cannot restart the timer.
56
+ * @param journey Updated Journey instance or null.
57
+ */
58
+ applyRemote(journey: Journey | null): void;
59
+ /**
60
+ * Serializes the active journey into a compact token for URL or intent transfer.
61
+ * @returns Base64url token string or undefined if no journey is active or size cap is exceeded.
62
+ */
63
+ getToken(): string | undefined;
64
+ /**
65
+ * Validates and adopts a serialized journey token.
66
+ * @param token Base64url journey token.
67
+ * @param source Originating source description for diagnostics.
68
+ * @param broadcast Indicates whether to broadcast adoption to connected bus peers.
69
+ * @returns True if the token was valid, unexpired, and adopted.
70
+ */
71
+ adopt(token: string, source: string, broadcast?: boolean): boolean;
72
+ /**
73
+ * Ends the journey if the terminated context matches the journey owner and endOnOwnerClose is enabled.
74
+ * @param ownerContextId Context identifier of the closed window.
75
+ */
76
+ ownerClosed(ownerContextId: string): void;
77
+ /** Clears pending expiration timers and releases resources on shutdown. */
78
+ destroy(): void;
79
+ /**
80
+ * Resumes a persisted journey from raw sessionStorage data.
81
+ * @param raw Serialized JSON string from storage.
82
+ * @returns True if journey was successfully restored.
83
+ */
84
+ private restore;
85
+ /**
86
+ * Decodes a base64url token into a validated Journey object. Tokens come from URLs
87
+ * anyone can edit. Every step throws on non-token input, so the failure is
88
+ * reported, not raised.
89
+ * @param token Encoded token string.
90
+ * @returns Decoded Journey instance or null on decode error.
91
+ */
92
+ private decodeToken;
93
+ /**
94
+ * Sets the active journey, updates sessionStorage, and schedules expiration.
95
+ * @param journey Target Journey instance or null.
96
+ */
97
+ private setJourney;
98
+ /** Removes journey data from sessionStorage. */
99
+ private clearStored;
100
+ /** Cancels any active expiration timer. */
101
+ private clearTimer;
102
+ /**
103
+ * Extracts the journey token from the current window location search parameters.
104
+ * @returns Token string or null.
105
+ */
106
+ private readUrlToken;
107
+ /**
108
+ * Reads the journey token from OpenFin window creation customData.
109
+ * @returns Promise resolving to token string or null.
110
+ */
111
+ private readOpenFinToken;
112
+ }