@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.
- package/LICENSE +202 -0
- package/README.md +217 -0
- package/dist/bus/bus.d.ts +134 -0
- package/dist/bus/links.d.ts +106 -0
- package/dist/capture/errors.d.ts +34 -0
- package/dist/capture/interactions.d.ts +29 -0
- package/dist/capture/network.d.ts +40 -0
- package/dist/capture/types.d.ts +78 -0
- package/dist/capture/web-vitals.d.ts +21 -0
- package/dist/constants-D8-4Ged5.cjs +2 -0
- package/dist/constants-D8-4Ged5.cjs.map +1 -0
- package/dist/constants-DbvMIryP.js +110 -0
- package/dist/constants-DbvMIryP.js.map +1 -0
- package/dist/constants.d.ts +339 -0
- package/dist/core/breadcrumbs.d.ts +48 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/context.d.ts +35 -0
- package/dist/core/diagnostics.d.ts +76 -0
- package/dist/core/journey.d.ts +112 -0
- package/dist/core/logger.d.ts +117 -0
- package/dist/core/pipeline.d.ts +75 -0
- package/dist/core/record.d.ts +72 -0
- package/dist/core/runtime.d.ts +146 -0
- package/dist/core/sampling.d.ts +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +2577 -0
- package/dist/index.js.map +1 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs +2 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs.map +1 -0
- package/dist/indexeddb-storage-DwpCDRnX.js +88 -0
- package/dist/indexeddb-storage-DwpCDRnX.js.map +1 -0
- package/dist/models/batch.d.ts +22 -0
- package/dist/models/bus.d.ts +97 -0
- package/dist/models/config.d.ts +528 -0
- package/dist/models/log-record.d.ts +54 -0
- package/dist/models/serializer.d.ts +23 -0
- package/dist/models/storage.d.ts +62 -0
- package/dist/storage/emergency-queue.d.ts +16 -0
- package/dist/storage/factory.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +69 -0
- package/dist/storage/keys.d.ts +8 -0
- package/dist/storage/local-storage.d.ts +80 -0
- package/dist/storage/memory-storage.d.ts +52 -0
- package/dist/transport/compression.d.ts +7 -0
- package/dist/transport/errors.d.ts +29 -0
- package/dist/transport/exit-flush.d.ts +63 -0
- package/dist/transport/http-transport.d.ts +63 -0
- package/dist/transport/retry-engine.d.ts +69 -0
- package/dist/transport/serializers/ecs.d.ts +3 -0
- package/dist/transport/serializers/otlp.d.ts +3 -0
- package/dist/utils/console.d.ts +24 -0
- package/dist/utils/identity.d.ts +36 -0
- package/dist/utils/lock.d.ts +15 -0
- package/dist/utils/platform.d.ts +36 -0
- package/dist/utils/sanitize.d.ts +47 -0
- package/dist/utils/sequence.d.ts +15 -0
- package/dist/utils/timer.d.ts +19 -0
- package/dist/utils/tracing.d.ts +55 -0
- package/dist/utils/unref.d.ts +9 -0
- package/package.json +106 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { LogBatch } from "../models/batch";
|
|
3
|
+
import type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from "../models/storage";
|
|
4
|
+
/** Persistent StorageAdapter implementation backed by IndexedDB. */
|
|
5
|
+
export declare class IndexedDbStorage implements StorageAdapter {
|
|
6
|
+
private readonly limits;
|
|
7
|
+
private readonly diagnostics;
|
|
8
|
+
private readonly onGap?;
|
|
9
|
+
/** Storage adapter strategy name. */
|
|
10
|
+
readonly name = "indexeddb";
|
|
11
|
+
/** Underlying Dexie database instance. */
|
|
12
|
+
private readonly db;
|
|
13
|
+
/**
|
|
14
|
+
* @param dbName Database name.
|
|
15
|
+
* @param limits Storage capacity and retention thresholds.
|
|
16
|
+
* @param diagnostics Diagnostics reporter.
|
|
17
|
+
* @param onGap Optional callback for dropped record reporting.
|
|
18
|
+
*/
|
|
19
|
+
constructor(dbName: string, limits: StorageLimits, diagnostics: Diagnostics, onGap?: GapReporter | undefined);
|
|
20
|
+
/**
|
|
21
|
+
* Persists a batch to IndexedDB and triggers storage pruning.
|
|
22
|
+
* @param batch Batch to store.
|
|
23
|
+
*/
|
|
24
|
+
save(batch: LogBatch): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Reads up to limit batches in chronological order without deletion.
|
|
27
|
+
* @param limit Maximum number of batches to retrieve.
|
|
28
|
+
* @returns Array of retrieved batches.
|
|
29
|
+
*/
|
|
30
|
+
take(limit: number): Promise<LogBatch[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Deletes a batch from IndexedDB by ID.
|
|
33
|
+
* @param id Batch identifier to delete.
|
|
34
|
+
*/
|
|
35
|
+
remove(id: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Updates delivery attempt count for a stored batch.
|
|
38
|
+
* @param id Batch identifier.
|
|
39
|
+
* @param attempts New absolute attempt count.
|
|
40
|
+
*/
|
|
41
|
+
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Removes expired batches and evicts oldest entries exceeding capacity.
|
|
44
|
+
* @returns Prune summary metrics.
|
|
45
|
+
*/
|
|
46
|
+
prune(): Promise<PruneResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns total count of stored batches.
|
|
49
|
+
* @returns Total batch count or 0 on failure.
|
|
50
|
+
*/
|
|
51
|
+
count(): Promise<number>;
|
|
52
|
+
/** Deletes all stored batches from the database. */
|
|
53
|
+
clear(): Promise<void>;
|
|
54
|
+
/** Closes the active IndexedDB connection. */
|
|
55
|
+
close(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Reports dropped records to diagnostics and registered gap handlers.
|
|
58
|
+
* @param result Prune result metrics.
|
|
59
|
+
*/
|
|
60
|
+
private reportGap;
|
|
61
|
+
/**
|
|
62
|
+
* Deletes a specified count of the oldest stored batches. Unguarded: both callers
|
|
63
|
+
* guard it, and swallowing the failure here reports an eviction that did not
|
|
64
|
+
* happen.
|
|
65
|
+
* @param howMany Number of oldest batches to evict.
|
|
66
|
+
* @returns Metrics of evicted batches and records.
|
|
67
|
+
*/
|
|
68
|
+
private evictOldest;
|
|
69
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
/**
|
|
3
|
+
* Returns all sorted localStorage keys matching the specified prefix.
|
|
4
|
+
* @param prefix Storage key prefix to filter by.
|
|
5
|
+
* @param diagnostics Diagnostics reporter.
|
|
6
|
+
* @returns Sorted array of matching storage keys.
|
|
7
|
+
*/
|
|
8
|
+
export declare function keysWithPrefix(prefix: string, diagnostics: Diagnostics): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { LogBatch } from "../models/batch";
|
|
3
|
+
import type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from "../models/storage";
|
|
4
|
+
/** Persistent StorageAdapter implementation backed by localStorage. */
|
|
5
|
+
export declare class LocalStorageStorage implements StorageAdapter {
|
|
6
|
+
private readonly limits;
|
|
7
|
+
private readonly diagnostics;
|
|
8
|
+
private readonly onGap?;
|
|
9
|
+
/** Storage adapter strategy name. */
|
|
10
|
+
readonly name = "localstorage";
|
|
11
|
+
/**
|
|
12
|
+
* @param limits Storage capacity and retention thresholds.
|
|
13
|
+
* @param diagnostics Diagnostics reporter.
|
|
14
|
+
* @param onGap Optional callback for dropped record reporting.
|
|
15
|
+
*/
|
|
16
|
+
constructor(limits: StorageLimits, diagnostics: Diagnostics, onGap?: GapReporter | undefined);
|
|
17
|
+
/**
|
|
18
|
+
* Persists a batch to localStorage, evicting oldest entries on quota errors.
|
|
19
|
+
* @param batch Batch to store.
|
|
20
|
+
*/
|
|
21
|
+
save(batch: LogBatch): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves up to limit batches in chronological order without deletion.
|
|
24
|
+
* @param limit Maximum number of batches to retrieve.
|
|
25
|
+
* @returns Promise resolving to an array of valid batches.
|
|
26
|
+
*/
|
|
27
|
+
take(limit: number): Promise<LogBatch[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Deletes a batch from localStorage by batch ID.
|
|
30
|
+
* @param id Batch identifier.
|
|
31
|
+
*/
|
|
32
|
+
remove(id: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Updates delivery attempt count for a stored batch without changing its key.
|
|
35
|
+
* @param id Batch identifier.
|
|
36
|
+
* @param attempts New absolute attempt count.
|
|
37
|
+
*/
|
|
38
|
+
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes expired batches and evicts oldest entries exceeding capacity limits.
|
|
41
|
+
* @returns Promise resolving to prune summary metrics.
|
|
42
|
+
*/
|
|
43
|
+
prune(): Promise<PruneResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns total count of stored batch keys without deserialization.
|
|
46
|
+
* @returns Promise resolving to batch count.
|
|
47
|
+
*/
|
|
48
|
+
count(): Promise<number>;
|
|
49
|
+
/** Deletes all matching batch keys from localStorage. */
|
|
50
|
+
clear(): Promise<void>;
|
|
51
|
+
/** No-op storage teardown method. */
|
|
52
|
+
close(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Deserializes and validates a stored batch from a key.
|
|
55
|
+
* @param key Storage key to read.
|
|
56
|
+
* @returns Validated LogBatch or null if missing or malformed.
|
|
57
|
+
*/
|
|
58
|
+
private read;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves storage key containing the specified batch ID suffix.
|
|
61
|
+
* @param id Batch identifier.
|
|
62
|
+
* @returns Matching storage key string or null.
|
|
63
|
+
*/
|
|
64
|
+
private keyOf;
|
|
65
|
+
/**
|
|
66
|
+
* Deletes an array of storage keys.
|
|
67
|
+
* @param keys Keys to delete.
|
|
68
|
+
*/
|
|
69
|
+
private evict;
|
|
70
|
+
/**
|
|
71
|
+
* Deletes a single storage key with error guarding.
|
|
72
|
+
* @param key Storage key to remove.
|
|
73
|
+
*/
|
|
74
|
+
private removeKey;
|
|
75
|
+
/**
|
|
76
|
+
* Returns all sorted batch storage keys matching prefix.
|
|
77
|
+
* @returns Sorted array of storage keys.
|
|
78
|
+
*/
|
|
79
|
+
private keys;
|
|
80
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { LogBatch } from "../models/batch";
|
|
2
|
+
import type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from "../models/storage";
|
|
3
|
+
/** In-memory StorageAdapter implementation retaining batches in volatile memory. */
|
|
4
|
+
export declare class MemoryStorage implements StorageAdapter {
|
|
5
|
+
private readonly limits;
|
|
6
|
+
private readonly onGap?;
|
|
7
|
+
/** Storage adapter strategy name. */
|
|
8
|
+
readonly name = "memory";
|
|
9
|
+
/** Internal array holding batches in chronological FIFO order. */
|
|
10
|
+
private batches;
|
|
11
|
+
/**
|
|
12
|
+
* @param limits Storage capacity and retention thresholds.
|
|
13
|
+
* @param onGap Optional callback for dropped record reporting.
|
|
14
|
+
*/
|
|
15
|
+
constructor(limits: StorageLimits, onGap?: GapReporter | undefined);
|
|
16
|
+
/**
|
|
17
|
+
* Appends a batch to memory storage and applies retention pruning.
|
|
18
|
+
* @param batch Batch to store.
|
|
19
|
+
*/
|
|
20
|
+
save(batch: LogBatch): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves up to limit batches in chronological order without deletion.
|
|
23
|
+
* @param limit Maximum number of batches to retrieve.
|
|
24
|
+
* @returns Promise resolving to an array of batches.
|
|
25
|
+
*/
|
|
26
|
+
take(limit: number): Promise<LogBatch[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Deletes a batch from memory storage by batch ID.
|
|
29
|
+
* @param id Batch identifier.
|
|
30
|
+
*/
|
|
31
|
+
remove(id: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Updates delivery attempt count for a stored batch.
|
|
34
|
+
* @param id Batch identifier.
|
|
35
|
+
* @param attempts New absolute attempt count.
|
|
36
|
+
*/
|
|
37
|
+
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Removes expired batches and evicts oldest entries exceeding capacity limits.
|
|
40
|
+
* @returns Promise resolving to prune summary metrics.
|
|
41
|
+
*/
|
|
42
|
+
prune(): Promise<PruneResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns total count of stored batches.
|
|
45
|
+
* @returns Promise resolving to batch count.
|
|
46
|
+
*/
|
|
47
|
+
count(): Promise<number>;
|
|
48
|
+
/** Clears all stored batches from memory. */
|
|
49
|
+
clear(): Promise<void>;
|
|
50
|
+
/** Clears stored batches on storage teardown. */
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compresses a string into a gzip-encoded byte array using CompressionStream.
|
|
3
|
+
* Returns non-shared ArrayBuffer backed Uint8Array compatible with fetch BodyInit.
|
|
4
|
+
* @param text Raw serialized payload to compress.
|
|
5
|
+
* @returns Promise resolving to compressed Uint8Array, or null if CompressionStream is unsupported.
|
|
6
|
+
*/
|
|
7
|
+
export declare function gzip(text: string): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure classification determining retry, backoff, or drop behavior. transient,
|
|
3
|
+
* offline and timeout retry with backoff. throttled waits the server's delay.
|
|
4
|
+
* too_large splits the batch. permanent drops it: it will never be accepted.
|
|
5
|
+
*/
|
|
6
|
+
export type TransportFailureKind = "transient" | "throttled" | "too_large" | "permanent" | "timeout" | "offline";
|
|
7
|
+
/** Error representing a failed transport attempt with failure classification and metadata. */
|
|
8
|
+
export declare class TransportError extends Error {
|
|
9
|
+
readonly kind: TransportFailureKind;
|
|
10
|
+
readonly status?: number | undefined;
|
|
11
|
+
readonly retryAfterMs?: number | undefined;
|
|
12
|
+
readonly maxBytes?: number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* @param kind Failure classification.
|
|
15
|
+
* @param message Error description.
|
|
16
|
+
* @param status Optional HTTP response status code.
|
|
17
|
+
* @param retryAfterMs Delay requested by the server in milliseconds.
|
|
18
|
+
* @param maxBytes Maximum payload bytes suggested by a 413 response.
|
|
19
|
+
*/
|
|
20
|
+
constructor(kind: TransportFailureKind, message: string, status?: number | undefined, retryAfterMs?: number | undefined, maxBytes?: number | undefined);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parses HTTP Retry-After header value (seconds or HTTP date) into millisecond
|
|
24
|
+
* delay. Both forms are legal. A date already past clamps to zero.
|
|
25
|
+
* Clamps negative delays to zero.
|
|
26
|
+
* @param header Raw Retry-After header string or null.
|
|
27
|
+
* @returns Non-negative delay in milliseconds, or undefined if invalid or missing.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseRetryAfter(header: string | null): number | undefined;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { LogBatch } from "../models/batch";
|
|
3
|
+
import type { ResolvedConfig } from "../models/config";
|
|
4
|
+
/** Document lifecycle event or manual action that triggered an exit flush. */
|
|
5
|
+
export type ExitReason = "hidden" | "pagehide" | "freeze" | "openfin-close" | "shutdown";
|
|
6
|
+
/** Injected dependencies required by ExitFlush. */
|
|
7
|
+
export interface ExitFlushDeps {
|
|
8
|
+
/** Active configuration instance. */
|
|
9
|
+
config: ResolvedConfig;
|
|
10
|
+
/** Diagnostics reporter instance. */
|
|
11
|
+
diagnostics: Diagnostics;
|
|
12
|
+
/** Callback draining all pending buffered and unconfirmed batches into a single LogBatch. */
|
|
13
|
+
drainPending: () => LogBatch | null;
|
|
14
|
+
}
|
|
15
|
+
/** Flushes pending telemetry on document unload using sendBeacon, keepalive fetch, or emergency storage. */
|
|
16
|
+
export declare class ExitFlush {
|
|
17
|
+
private readonly deps;
|
|
18
|
+
/** Indicates whether unload listeners are currently active. */
|
|
19
|
+
private installed;
|
|
20
|
+
/** Handles visibilitychange events when the document becomes hidden. */
|
|
21
|
+
private readonly onVisibility;
|
|
22
|
+
/** Handles window pagehide events. */
|
|
23
|
+
private readonly onPageHide;
|
|
24
|
+
/** Handles document freeze events. */
|
|
25
|
+
private readonly onFreeze;
|
|
26
|
+
/** Handles OpenFin close-requested events. */
|
|
27
|
+
private readonly onOpenFinClose;
|
|
28
|
+
/**
|
|
29
|
+
* @param deps Injected configuration, diagnostics, and drain callback.
|
|
30
|
+
*/
|
|
31
|
+
constructor(deps: ExitFlushDeps);
|
|
32
|
+
/** Attaches unload listeners across document, window, and OpenFin environments. */
|
|
33
|
+
install(): void;
|
|
34
|
+
/** Removes all registered unload listeners and subscriptions. */
|
|
35
|
+
uninstall(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Synchronously drains pending records and transmits via beacon, keepalive, or
|
|
38
|
+
* emergency storage. Never awaits and never throws. The caller is an unload
|
|
39
|
+
* listener.
|
|
40
|
+
* @param reason Trigger reason code.
|
|
41
|
+
*/
|
|
42
|
+
flush(reason: ExitReason): void;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves and parses the destination endpoint URL.
|
|
45
|
+
* @returns URL instance or null if missing or invalid.
|
|
46
|
+
*/
|
|
47
|
+
private endpointUrl;
|
|
48
|
+
/**
|
|
49
|
+
* Attempts transmission via navigator.sendBeacon with text/plain payload.
|
|
50
|
+
* @param url Target endpoint URL with query parameters.
|
|
51
|
+
* @param body Serialized payload string.
|
|
52
|
+
* @returns True if the beacon was accepted by the browser.
|
|
53
|
+
*/
|
|
54
|
+
private beacon;
|
|
55
|
+
/**
|
|
56
|
+
* Fallback POST delivery using fetch with keepalive: true. keepalive outlives the
|
|
57
|
+
* document. A plain fetch is cancelled as the page goes.
|
|
58
|
+
* @param url Target endpoint URL.
|
|
59
|
+
* @param body Serialized payload string.
|
|
60
|
+
* @param reason Trigger reason code.
|
|
61
|
+
*/
|
|
62
|
+
private keepaliveFetch;
|
|
63
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { LogBatch } from "../models/batch";
|
|
3
|
+
import type { ResolvedConfig } from "../models/config";
|
|
4
|
+
/** HTTP transport delivering serialized log batches with header resolution, gzip compression, and error classification. */
|
|
5
|
+
export declare class HttpTransport {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly diagnostics;
|
|
8
|
+
/** Timestamp in epoch milliseconds until which requests are throttled. */
|
|
9
|
+
private throttledUntil;
|
|
10
|
+
/**
|
|
11
|
+
* @param config Active configuration instance.
|
|
12
|
+
* @param diagnostics Diagnostics reporter.
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: ResolvedConfig, diagnostics: Diagnostics);
|
|
15
|
+
/**
|
|
16
|
+
* Delivers a single log batch over HTTP.
|
|
17
|
+
* @param batch Batch to send.
|
|
18
|
+
* @throws TransportError on transient, throttled, 413, or permanent network failures.
|
|
19
|
+
*/
|
|
20
|
+
send(batch: LogBatch): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the remaining throttle backoff duration in milliseconds.
|
|
23
|
+
* @returns Milliseconds remaining in throttle window, or 0 if unthrottled.
|
|
24
|
+
*/
|
|
25
|
+
throttledForMs(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Serializes, encodes, and dispatches a batch, throwing a classified TransportError on failure.
|
|
28
|
+
* @param batch Batch to deliver.
|
|
29
|
+
*/
|
|
30
|
+
private post;
|
|
31
|
+
/**
|
|
32
|
+
* Compresses the serialized payload if gzip compression is enabled and size exceeds threshold.
|
|
33
|
+
* @param text Serialized payload string.
|
|
34
|
+
* @returns Promise resolving to original string or compressed byte array.
|
|
35
|
+
*/
|
|
36
|
+
private encodeBody;
|
|
37
|
+
/**
|
|
38
|
+
* Executes the HTTP POST request with timeout and network error mapping.
|
|
39
|
+
* @param headers HTTP request headers.
|
|
40
|
+
* @param body Request body string or byte array.
|
|
41
|
+
* @returns Promise resolving to the HTTP Response.
|
|
42
|
+
* @throws TransportError on network failure, timeout, or offline status.
|
|
43
|
+
*/
|
|
44
|
+
private dispatch;
|
|
45
|
+
/**
|
|
46
|
+
* Classifies an HTTP error response into a structured TransportError.
|
|
47
|
+
* @param response Unsuccessful HTTP response.
|
|
48
|
+
* @param batchId Identifier of the rejected batch.
|
|
49
|
+
* @returns Classified TransportError instance.
|
|
50
|
+
*/
|
|
51
|
+
private classify;
|
|
52
|
+
/**
|
|
53
|
+
* Extracts optional maxBytes payload limit from a 413 response body.
|
|
54
|
+
* @param response HTTP 413 Response instance.
|
|
55
|
+
* @returns Promise resolving to maximum byte limit or undefined.
|
|
56
|
+
*/
|
|
57
|
+
private readMaxBytes;
|
|
58
|
+
/**
|
|
59
|
+
* Evaluates configured static or dynamic request headers.
|
|
60
|
+
* @returns Promise resolving to resolved header map.
|
|
61
|
+
*/
|
|
62
|
+
private resolveHeaders;
|
|
63
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { ResolvedConfig } from "../models/config";
|
|
3
|
+
import type { StorageAdapter } from "../models/storage";
|
|
4
|
+
import type { HttpTransport } from "./http-transport";
|
|
5
|
+
/** Manages timed redelivery of persisted offline batches with backoff, lock coordination, and batch splitting. */
|
|
6
|
+
export declare class RetryEngine {
|
|
7
|
+
private readonly storage;
|
|
8
|
+
private readonly transport;
|
|
9
|
+
private readonly diagnostics;
|
|
10
|
+
private readonly config;
|
|
11
|
+
private readonly batchesPerDrain;
|
|
12
|
+
/** Active retry timer handle or null if unreserved. */
|
|
13
|
+
private timer;
|
|
14
|
+
/** Consecutive failed delivery attempts for exponential backoff calculation. */
|
|
15
|
+
private attempt;
|
|
16
|
+
/** Indicates whether a storage drain operation is actively executing. */
|
|
17
|
+
private draining;
|
|
18
|
+
/** Indicates whether the engine is stopped. */
|
|
19
|
+
private stopped;
|
|
20
|
+
/** Online event listener resetting attempts and scheduling immediate drain. */
|
|
21
|
+
private readonly onOnline;
|
|
22
|
+
/**
|
|
23
|
+
* @param storage Storage adapter holding undelivered batches.
|
|
24
|
+
* @param transport HTTP transport for batch delivery.
|
|
25
|
+
* @param diagnostics Diagnostics reporter.
|
|
26
|
+
* @param config Active configuration instance.
|
|
27
|
+
* @param batchesPerDrain Maximum batches processed per drain tick.
|
|
28
|
+
*/
|
|
29
|
+
constructor(storage: StorageAdapter, transport: HttpTransport, diagnostics: Diagnostics, config: ResolvedConfig, batchesPerDrain?: number);
|
|
30
|
+
/** Starts the retry engine, listens for online events, and arms the initial timer. */
|
|
31
|
+
start(): void;
|
|
32
|
+
/** Triggers an accelerated retry schedule when a new batch is stored offline. */
|
|
33
|
+
nudge(): void;
|
|
34
|
+
/** Halts retry execution, removes listeners, and clears pending timers. */
|
|
35
|
+
stop(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Clears existing timers and schedules a new drain execution after a delay.
|
|
38
|
+
* @param delayMs Delay duration in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
private schedule;
|
|
41
|
+
/** Clears the pending timer handle if active. */
|
|
42
|
+
private clearTimer;
|
|
43
|
+
/**
|
|
44
|
+
* Computes jittered exponential backoff delay based on consecutive failures. Full
|
|
45
|
+
* jitter, not a fixed offset. Tabs reconnecting together stampede otherwise.
|
|
46
|
+
* @returns Backoff duration in milliseconds.
|
|
47
|
+
*/
|
|
48
|
+
private backoffMs;
|
|
49
|
+
/** Executes a drain operation protected by the origin-wide Web Lock. */
|
|
50
|
+
private drain;
|
|
51
|
+
/**
|
|
52
|
+
* Processes batches while holding the Web Lock and schedules subsequent ticks.
|
|
53
|
+
* Always resolves. A throw leaves the engine idle with no timer armed.
|
|
54
|
+
* @returns Promise resolving to true on completion.
|
|
55
|
+
*/
|
|
56
|
+
private drainLocked;
|
|
57
|
+
/**
|
|
58
|
+
* Attempts delivery of a single batch, removing it on success or handling errors.
|
|
59
|
+
* @param batch Log batch to deliver.
|
|
60
|
+
* @returns True to continue processing next batch; false to halt current drain.
|
|
61
|
+
*/
|
|
62
|
+
private deliver;
|
|
63
|
+
/**
|
|
64
|
+
* Splits an oversized batch into two smaller stored batches after a 413 rejection.
|
|
65
|
+
* @param batch Rejected log batch.
|
|
66
|
+
* @param serverMaxBytes Optional byte limit reported by the server.
|
|
67
|
+
*/
|
|
68
|
+
private splitStored;
|
|
69
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LogLevel } from "../models/log-record";
|
|
2
|
+
/** Mirrors log records directly to browser or Node console methods based on severity. */
|
|
3
|
+
export declare class ConsoleSink {
|
|
4
|
+
private enabled;
|
|
5
|
+
private minLevel;
|
|
6
|
+
/**
|
|
7
|
+
* @param enabled Indicates whether console mirroring is active.
|
|
8
|
+
* @param minLevel Minimum log level required to emit to the console.
|
|
9
|
+
*/
|
|
10
|
+
constructor(enabled: boolean, minLevel: LogLevel);
|
|
11
|
+
/**
|
|
12
|
+
* Updates console sink configuration settings.
|
|
13
|
+
* @param enabled Indicates whether console mirroring is active.
|
|
14
|
+
* @param minLevel Minimum log level required to emit to the console.
|
|
15
|
+
*/
|
|
16
|
+
update(enabled: boolean, minLevel: LogLevel): void;
|
|
17
|
+
/**
|
|
18
|
+
* Emits a styled log record to the console if severity clears the configured threshold.
|
|
19
|
+
* @param level Severity level of the record.
|
|
20
|
+
* @param message Primary log message.
|
|
21
|
+
* @param payload Optional contextual payload or object reference.
|
|
22
|
+
*/
|
|
23
|
+
write(level: LogLevel, message: string, payload?: unknown): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
/** Correlation identifiers attached to log records across session, tab, and realm scopes. */
|
|
3
|
+
export interface Identity {
|
|
4
|
+
/** Origin-wide user session identifier surviving across tabs until idle expiration. */
|
|
5
|
+
sessionId: string;
|
|
6
|
+
/** Browser tab or desktop window identifier surviving document reloads. */
|
|
7
|
+
tabId: string;
|
|
8
|
+
/** Unique execution realm identifier regenerated on every document load. */
|
|
9
|
+
contextId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generates a random lowercase hexadecimal string of the specified byte length.
|
|
13
|
+
* Uses crypto.getRandomValues when available, falling back to Math.random.
|
|
14
|
+
* @param byteLength Number of random bytes to generate.
|
|
15
|
+
* @returns Hexadecimal string of length byteLength * 2.
|
|
16
|
+
*/
|
|
17
|
+
export declare function randomHex(byteLength: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generates a unique identifier string using crypto.randomUUID or randomHex fallback.
|
|
20
|
+
* @returns UUID or random hex identifier.
|
|
21
|
+
*/
|
|
22
|
+
export declare function newId(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves or initializes session, tab, and context identifiers for the active realm.
|
|
25
|
+
* @param diagnostics Diagnostics reporter.
|
|
26
|
+
* @returns Populated Identity object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveIdentity(diagnostics: Diagnostics): Identity;
|
|
29
|
+
/**
|
|
30
|
+
* Updates session activity timestamp in localStorage, throttled by SESSION_TOUCH_MS.
|
|
31
|
+
* @param sessionId Active session identifier.
|
|
32
|
+
* @param diagnostics Diagnostics reporter.
|
|
33
|
+
*/
|
|
34
|
+
export declare function touchSession(sessionId: string, diagnostics: Diagnostics): void;
|
|
35
|
+
/** Resets the session touch throttle timer state for testing. */
|
|
36
|
+
export declare function resetSessionTouch(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
/**
|
|
3
|
+
* Executes an asynchronous function under a Web Locks API origin-wide lock.
|
|
4
|
+
* Falls back to direct execution in environments without Web Locks support.
|
|
5
|
+
* @param name Origin-scoped lock identifier.
|
|
6
|
+
* @param diagnostics Diagnostics reporter.
|
|
7
|
+
* @param fn Asynchronous task to execute while holding the lock.
|
|
8
|
+
* @param options Lock acquisition options.
|
|
9
|
+
* @param options.skipIfBusy Skips execution if lock is currently held by another context.
|
|
10
|
+
* @returns Promise resolving to the task result, or undefined if the lock was held
|
|
11
|
+
* and nothing ran. A caller that conflates the two stops rescheduling.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withDrainLock<T>(name: string, diagnostics: Diagnostics, fn: () => Promise<T>, { skipIfBusy }?: {
|
|
14
|
+
skipIfBusy?: boolean;
|
|
15
|
+
}): Promise<T | undefined>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
/** Host runtime environment classification attached to resource attributes. */
|
|
3
|
+
export type PlatformType = "openfin" | "openfin_web" | "browser" | "mobile_webview" | "ionic" | "web_worker" | "shared_worker" | "service_worker" | "node";
|
|
4
|
+
/** Host environment and runtime container metadata resolved at startup. */
|
|
5
|
+
export interface PlatformMetadata {
|
|
6
|
+
/** Detected platform runtime classification. */
|
|
7
|
+
platform: PlatformType;
|
|
8
|
+
/** OpenFin application UUID if running inside an OpenFin container. */
|
|
9
|
+
openfinUuid?: string;
|
|
10
|
+
/** OpenFin window or view identifier. */
|
|
11
|
+
openfinName?: string;
|
|
12
|
+
/** Raw navigator user agent string or empty string if unavailable. */
|
|
13
|
+
userAgent: string;
|
|
14
|
+
/** Indicates whether execution occurs inside any worker realm. */
|
|
15
|
+
isWorker: boolean;
|
|
16
|
+
/** Indicates whether this context is the top-level document rather than an iframe. */
|
|
17
|
+
isTopLevelDocument: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detects and caches host platform metadata for the active realm.
|
|
21
|
+
* @param diagnostics Diagnostics reporter.
|
|
22
|
+
* @returns Detected PlatformMetadata.
|
|
23
|
+
*/
|
|
24
|
+
export declare function detectPlatform(diagnostics: Diagnostics): PlatformMetadata;
|
|
25
|
+
/**
|
|
26
|
+
* Determines whether the current window is the top-level browsing context.
|
|
27
|
+
* @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isTopLevel(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the current document URL without caching.
|
|
32
|
+
* @returns Current location.href or empty string.
|
|
33
|
+
*/
|
|
34
|
+
export declare function currentUrl(): string;
|
|
35
|
+
/** Resets the cached platform metadata for testing. */
|
|
36
|
+
export declare function resetPlatformCache(): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Structural depth and size limits enforced during object sanitization. */
|
|
2
|
+
export interface SanitizeLimits {
|
|
3
|
+
/** Maximum recursion depth before truncating nested objects. */
|
|
4
|
+
maxDepth: number;
|
|
5
|
+
/** Maximum items retained in arrays, sets, and maps before truncating. */
|
|
6
|
+
maxArrayLength: number;
|
|
7
|
+
/** Maximum string attribute length in characters. */
|
|
8
|
+
maxAttributeChars: number;
|
|
9
|
+
/** Maximum key-value properties retained in a single object. */
|
|
10
|
+
maxAttributeCount: number;
|
|
11
|
+
/** Maximum error stack trace length in characters. */
|
|
12
|
+
maxStackChars: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Truncates a string to maximum character length while preserving UTF-16 surrogate pairs.
|
|
16
|
+
* @param value Target string.
|
|
17
|
+
* @param max Maximum allowed character length.
|
|
18
|
+
* @returns Truncated string with appended drop count suffix.
|
|
19
|
+
*/
|
|
20
|
+
export declare function truncate(value: string, max: number): string;
|
|
21
|
+
/** Sanitized JSON-safe output with estimated serialized byte size. */
|
|
22
|
+
export interface SanitizeResult {
|
|
23
|
+
/** JSON-safe sanitized structure. */
|
|
24
|
+
value: unknown;
|
|
25
|
+
/** Approximate serialized byte count. */
|
|
26
|
+
bytes: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sanitizes arbitrary values into JSON-safe structures without throwing.
|
|
30
|
+
* @param value Raw value to sanitize.
|
|
31
|
+
* @param limits Configuration limits for depth, count, and character lengths.
|
|
32
|
+
* @returns JSON-safe sanitized value.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sanitize(value: unknown, limits: SanitizeLimits): unknown;
|
|
35
|
+
/**
|
|
36
|
+
* Sanitizes arbitrary values and calculates approximate serialized byte sizes.
|
|
37
|
+
* @param value Raw value to sanitize.
|
|
38
|
+
* @param limits Configuration limits.
|
|
39
|
+
* @returns SanitizeResult containing sanitized value and byte count.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sanitizeWithSize(value: unknown, limits: SanitizeLimits): SanitizeResult;
|
|
42
|
+
/**
|
|
43
|
+
* Estimates UTF-8 encoded byte length for a string.
|
|
44
|
+
* @param value Target string.
|
|
45
|
+
* @returns Estimated UTF-8 byte length.
|
|
46
|
+
*/
|
|
47
|
+
export declare function estimateBytes(value: string): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Monotonic sequence counter establishing total record ordering within an execution context. */
|
|
2
|
+
export declare class Sequence {
|
|
3
|
+
/** Last emitted sequence counter value. */
|
|
4
|
+
private value;
|
|
5
|
+
/**
|
|
6
|
+
* Increments and returns the next monotonic sequence number starting at 1.
|
|
7
|
+
* @returns Next sequence number.
|
|
8
|
+
*/
|
|
9
|
+
next(): number;
|
|
10
|
+
/**
|
|
11
|
+
* Resets the sequence counter to zero, for a runtime configured afresh.
|
|
12
|
+
* Continuing the count implies continuity with the previous run.
|
|
13
|
+
*/
|
|
14
|
+
reset(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CaptureLogger } from "../capture/types";
|
|
2
|
+
/**
|
|
3
|
+
* Executes and measures the duration of a synchronous function.
|
|
4
|
+
* @param logger Target telemetry logger.
|
|
5
|
+
* @param label Metric name prefix.
|
|
6
|
+
* @param fn Synchronous function to execute.
|
|
7
|
+
* @param attributes Optional contextual attributes.
|
|
8
|
+
* @returns Result returned by the wrapped function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function timeSync<T>(logger: CaptureLogger, label: string, fn: () => T, attributes?: Record<string, unknown>): T;
|
|
11
|
+
/**
|
|
12
|
+
* Executes and measures the duration of an asynchronous promise-returning function.
|
|
13
|
+
* @param logger Target telemetry logger.
|
|
14
|
+
* @param label Metric name prefix.
|
|
15
|
+
* @param fn Asynchronous function to execute.
|
|
16
|
+
* @param attributes Optional contextual attributes.
|
|
17
|
+
* @returns Promise resolving to the result of the wrapped function.
|
|
18
|
+
*/
|
|
19
|
+
export declare function timeAsync<T>(logger: CaptureLogger, label: string, fn: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>;
|