@plasius/analytics 1.3.1 → 1.3.3
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/README.md +10 -1
- package/dist/index.cjs +422 -246
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +110 -10
- package/dist/index.js.map +1 -1
- package/dist/metrics.cjs +121 -7
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.js +92 -4
- package/dist/metrics.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5BHE32SK.cjs +0 -98
- package/dist/chunk-5BHE32SK.cjs.map +0 -1
- package/dist/chunk-OEVYIQET.js +0 -98
- package/dist/chunk-OEVYIQET.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,80 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
19
|
|
|
4
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AnalyticsProvider: () => AnalyticsProvider,
|
|
24
|
+
SEMANTIC_JOURNEY_AGGREGATE_SCHEMA_VERSION: () => SEMANTIC_JOURNEY_AGGREGATE_SCHEMA_VERSION,
|
|
25
|
+
SEMANTIC_JOURNEY_RECEIPT_HEADER: () => SEMANTIC_JOURNEY_RECEIPT_HEADER,
|
|
26
|
+
SEMANTIC_JOURNEY_RECEIPT_MAX_BYTES: () => SEMANTIC_JOURNEY_RECEIPT_MAX_BYTES,
|
|
27
|
+
SEMANTIC_JOURNEY_RECEIPT_MAX_COUNT: () => SEMANTIC_JOURNEY_RECEIPT_MAX_COUNT,
|
|
28
|
+
SEMANTIC_JOURNEY_RECEIPT_VERSION: () => SEMANTIC_JOURNEY_RECEIPT_VERSION,
|
|
29
|
+
SEMANTIC_JOURNEY_STRICT_POLICY_VERSION: () => SEMANTIC_JOURNEY_STRICT_POLICY_VERSION,
|
|
30
|
+
SemanticJourneyAggregateStore: () => SemanticJourneyAggregateStore,
|
|
31
|
+
SemanticJourneyTransportError: () => SemanticJourneyTransportError,
|
|
32
|
+
SemanticJourneyValidationError: () => SemanticJourneyValidationError,
|
|
33
|
+
USEFUL_METRIC_EVENT_DEFINITIONS: () => USEFUL_METRIC_EVENT_DEFINITIONS,
|
|
34
|
+
assertSemanticSource: () => assertSemanticSource,
|
|
35
|
+
assertSemanticToken: () => assertSemanticToken,
|
|
36
|
+
createBackendAnalyticsClient: () => createBackendAnalyticsClient,
|
|
37
|
+
createChildJourneyContext: () => createChildJourneyContext,
|
|
38
|
+
createDefaultSemanticJourneyAggregateTransport: () => createDefaultSemanticJourneyAggregateTransport,
|
|
39
|
+
createEventId: () => createEventId,
|
|
40
|
+
createFrontendAnalyticsClient: () => createFrontendAnalyticsClient,
|
|
41
|
+
createJourneyContext: () => createJourneyContext,
|
|
42
|
+
createJourneyId: () => createJourneyId,
|
|
43
|
+
createLocalSpaceAnalyticsClient: () => createLocalSpaceAnalyticsClient,
|
|
44
|
+
createNoopLocalSpaceAnalyticsClient: () => createNoopLocalSpaceAnalyticsClient,
|
|
45
|
+
createProducerId: () => createProducerId,
|
|
46
|
+
createRequestJourneyContext: () => createRequestJourneyContext,
|
|
47
|
+
createSecureRandomHex: () => createSecureRandomHex,
|
|
48
|
+
createSemanticJourneyClient: () => createSemanticJourneyClient,
|
|
49
|
+
createSpanId: () => createSpanId,
|
|
50
|
+
createTraceId: () => createTraceId,
|
|
51
|
+
defineJourneyEvent: () => defineJourneyEvent,
|
|
52
|
+
defineSemanticJourneyCatalog: () => defineSemanticJourneyCatalog,
|
|
53
|
+
formatTraceparent: () => formatTraceparent,
|
|
54
|
+
getJourneyEventDefinition: () => getJourneyEventDefinition,
|
|
55
|
+
isEventId: () => isEventId,
|
|
56
|
+
isJourneyId: () => isJourneyId,
|
|
57
|
+
isJourneyToken: () => isJourneyToken,
|
|
58
|
+
isProducerId: () => isProducerId,
|
|
59
|
+
isSecureSemanticJourneyEndpoint: () => isSecureSemanticJourneyEndpoint,
|
|
60
|
+
isSemanticSource: () => isSemanticSource,
|
|
61
|
+
isSemanticToken: () => isSemanticToken,
|
|
62
|
+
isSpanId: () => isSpanId,
|
|
63
|
+
isTraceId: () => isTraceId,
|
|
64
|
+
observeSemanticJourneyInteractions: () => observeSemanticJourneyInteractions,
|
|
65
|
+
parseSemanticJourneyReceipts: () => parseSemanticJourneyReceipts,
|
|
66
|
+
parseTraceparent: () => parseTraceparent,
|
|
67
|
+
projectUsefulMetric: () => projectUsefulMetric,
|
|
68
|
+
reconstructSemanticJourney: () => reconstructSemanticJourney,
|
|
69
|
+
serializeSemanticJourneyReceipts: () => serializeSemanticJourneyReceipts,
|
|
70
|
+
useAnalytics: () => useAnalytics,
|
|
71
|
+
useComponentInteractionTracker: () => useComponentInteractionTracker,
|
|
72
|
+
validateSemanticJourneyEventInput: () => validateSemanticJourneyEventInput
|
|
73
|
+
});
|
|
74
|
+
module.exports = __toCommonJS(src_exports);
|
|
5
75
|
|
|
6
76
|
// src/core/client.ts
|
|
7
|
-
var
|
|
77
|
+
var import_schema = require("@plasius/schema");
|
|
8
78
|
var DEFAULT_FLUSH_INTERVAL_MS = 5e3;
|
|
9
79
|
var DEFAULT_BATCH_SIZE = 20;
|
|
10
80
|
var DEFAULT_MAX_QUEUE_SIZE = 500;
|
|
@@ -34,9 +104,9 @@ var DEFAULT_ERROR_REDACT_KEYS = [
|
|
|
34
104
|
];
|
|
35
105
|
var JSON_CONTENT_TYPE_HEADER = "application/json";
|
|
36
106
|
var LOCALHOST_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"]);
|
|
37
|
-
var PlainLogValueSchema =
|
|
107
|
+
var PlainLogValueSchema = (0, import_schema.createSchema)(
|
|
38
108
|
{
|
|
39
|
-
value:
|
|
109
|
+
value: import_schema.field.generalText().PID({
|
|
40
110
|
classification: "none",
|
|
41
111
|
action: "none",
|
|
42
112
|
logHandling: "plain",
|
|
@@ -46,9 +116,9 @@ var PlainLogValueSchema = _schema.createSchema.call(void 0,
|
|
|
46
116
|
"analytics-log-safe-value",
|
|
47
117
|
{ version: "1.0.0", piiEnforcement: "none" }
|
|
48
118
|
);
|
|
49
|
-
var SensitiveLogValueSchema =
|
|
119
|
+
var SensitiveLogValueSchema = (0, import_schema.createSchema)(
|
|
50
120
|
{
|
|
51
|
-
value:
|
|
121
|
+
value: import_schema.field.generalText().PID({
|
|
52
122
|
classification: "high",
|
|
53
123
|
action: "none",
|
|
54
124
|
logHandling: "redact",
|
|
@@ -60,105 +130,105 @@ var SensitiveLogValueSchema = _schema.createSchema.call(void 0,
|
|
|
60
130
|
);
|
|
61
131
|
function applySchemaLogHandling(value, sensitive) {
|
|
62
132
|
const schema = sensitive ? SensitiveLogValueSchema : PlainLogValueSchema;
|
|
63
|
-
const sanitized = schema.sanitizeForLog({ value }, (input) => `p(${String(
|
|
133
|
+
const sanitized = schema.sanitizeForLog({ value }, (input) => `p(${String(input ?? "")})`);
|
|
64
134
|
return typeof sanitized.value === "string" ? sanitized.value : "";
|
|
65
135
|
}
|
|
66
136
|
var REDACTED_VALUE = applySchemaLogHandling("sensitive", true) || "[REDACTED]";
|
|
67
|
-
var CrashIdentitySchema =
|
|
137
|
+
var CrashIdentitySchema = (0, import_schema.createSchema)(
|
|
68
138
|
{
|
|
69
|
-
source:
|
|
139
|
+
source: import_schema.field.generalText().PID({
|
|
70
140
|
classification: "none",
|
|
71
141
|
action: "none",
|
|
72
142
|
logHandling: "plain",
|
|
73
143
|
purpose: "analytics source identifier"
|
|
74
144
|
}).optional(),
|
|
75
|
-
channel:
|
|
145
|
+
channel: import_schema.field.generalText().PID({
|
|
76
146
|
classification: "none",
|
|
77
147
|
action: "none",
|
|
78
148
|
logHandling: "plain",
|
|
79
149
|
purpose: "analytics channel identifier"
|
|
80
150
|
}).optional(),
|
|
81
|
-
runtime:
|
|
151
|
+
runtime: import_schema.field.generalText().PID({
|
|
82
152
|
classification: "none",
|
|
83
153
|
action: "none",
|
|
84
154
|
logHandling: "plain",
|
|
85
155
|
purpose: "analytics runtime identifier"
|
|
86
156
|
}).optional(),
|
|
87
|
-
sessionId:
|
|
157
|
+
sessionId: import_schema.field.generalText().PID({
|
|
88
158
|
classification: "high",
|
|
89
159
|
action: "hash",
|
|
90
160
|
logHandling: "redact",
|
|
91
161
|
purpose: "client session identifier"
|
|
92
162
|
}).optional(),
|
|
93
|
-
userAgent:
|
|
163
|
+
userAgent: import_schema.field.generalText().PID({
|
|
94
164
|
classification: "low",
|
|
95
165
|
action: "hash",
|
|
96
166
|
logHandling: "pseudonym",
|
|
97
167
|
purpose: "browser user agent"
|
|
98
168
|
}).optional(),
|
|
99
|
-
platform:
|
|
169
|
+
platform: import_schema.field.generalText().PID({
|
|
100
170
|
classification: "low",
|
|
101
171
|
action: "hash",
|
|
102
172
|
logHandling: "pseudonym",
|
|
103
173
|
purpose: "client platform"
|
|
104
174
|
}).optional(),
|
|
105
|
-
language:
|
|
175
|
+
language: import_schema.field.generalText().PID({
|
|
106
176
|
classification: "low",
|
|
107
177
|
action: "hash",
|
|
108
178
|
logHandling: "pseudonym",
|
|
109
179
|
purpose: "client language"
|
|
110
180
|
}).optional(),
|
|
111
|
-
timezone:
|
|
181
|
+
timezone: import_schema.field.generalText().PID({
|
|
112
182
|
classification: "low",
|
|
113
183
|
action: "hash",
|
|
114
184
|
logHandling: "pseudonym",
|
|
115
185
|
purpose: "client timezone"
|
|
116
186
|
}).optional(),
|
|
117
|
-
origin:
|
|
187
|
+
origin: import_schema.field.generalText().PID({
|
|
118
188
|
classification: "low",
|
|
119
189
|
action: "hash",
|
|
120
190
|
logHandling: "pseudonym",
|
|
121
191
|
purpose: "client origin"
|
|
122
192
|
}).optional(),
|
|
123
|
-
pathname:
|
|
193
|
+
pathname: import_schema.field.generalText().PID({
|
|
124
194
|
classification: "low",
|
|
125
195
|
action: "hash",
|
|
126
196
|
logHandling: "pseudonym",
|
|
127
197
|
purpose: "client route path"
|
|
128
198
|
}).optional(),
|
|
129
|
-
screenWidth:
|
|
199
|
+
screenWidth: import_schema.field.number().PID({
|
|
130
200
|
classification: "none",
|
|
131
201
|
action: "none",
|
|
132
202
|
logHandling: "plain",
|
|
133
203
|
purpose: "viewport width"
|
|
134
204
|
}).optional(),
|
|
135
|
-
screenHeight:
|
|
205
|
+
screenHeight: import_schema.field.number().PID({
|
|
136
206
|
classification: "none",
|
|
137
207
|
action: "none",
|
|
138
208
|
logHandling: "plain",
|
|
139
209
|
purpose: "viewport height"
|
|
140
210
|
}).optional(),
|
|
141
|
-
colorDepth:
|
|
211
|
+
colorDepth: import_schema.field.number().PID({
|
|
142
212
|
classification: "none",
|
|
143
213
|
action: "none",
|
|
144
214
|
logHandling: "plain",
|
|
145
215
|
purpose: "screen color depth"
|
|
146
216
|
}).optional(),
|
|
147
|
-
hardwareConcurrency:
|
|
217
|
+
hardwareConcurrency: import_schema.field.number().PID({
|
|
148
218
|
classification: "none",
|
|
149
219
|
action: "none",
|
|
150
220
|
logHandling: "plain",
|
|
151
221
|
purpose: "cpu concurrency"
|
|
152
222
|
}).optional(),
|
|
153
|
-
identifiers:
|
|
154
|
-
|
|
155
|
-
key:
|
|
223
|
+
identifiers: import_schema.field.array(
|
|
224
|
+
import_schema.field.object({
|
|
225
|
+
key: import_schema.field.generalText().PID({
|
|
156
226
|
classification: "none",
|
|
157
227
|
action: "none",
|
|
158
228
|
logHandling: "plain",
|
|
159
229
|
purpose: "identifier field key"
|
|
160
230
|
}),
|
|
161
|
-
value:
|
|
231
|
+
value: import_schema.field.generalText().PID({
|
|
162
232
|
classification: "high",
|
|
163
233
|
action: "hash",
|
|
164
234
|
logHandling: "redact",
|
|
@@ -202,7 +272,7 @@ function buildDefaultStorageKey(source, channel) {
|
|
|
202
272
|
return `${DEFAULT_STORAGE_KEY_PREFIX}.${channel}.${sanitizeStorageSourceSegment(source)}`;
|
|
203
273
|
}
|
|
204
274
|
function resolveStorageKey(configStorageKey, source, channel, previous) {
|
|
205
|
-
const explicitStorageKey =
|
|
275
|
+
const explicitStorageKey = configStorageKey?.trim();
|
|
206
276
|
if (explicitStorageKey) {
|
|
207
277
|
return explicitStorageKey;
|
|
208
278
|
}
|
|
@@ -220,7 +290,8 @@ async function defaultTransport({
|
|
|
220
290
|
endpoint,
|
|
221
291
|
body,
|
|
222
292
|
headers,
|
|
223
|
-
keepalive
|
|
293
|
+
keepalive,
|
|
294
|
+
signal
|
|
224
295
|
}) {
|
|
225
296
|
if (typeof fetch !== "function") {
|
|
226
297
|
return;
|
|
@@ -229,7 +300,8 @@ async function defaultTransport({
|
|
|
229
300
|
method: "POST",
|
|
230
301
|
headers,
|
|
231
302
|
body,
|
|
232
|
-
keepalive
|
|
303
|
+
keepalive,
|
|
304
|
+
signal
|
|
233
305
|
});
|
|
234
306
|
if (!response.ok) {
|
|
235
307
|
throw new Error(`Analytics transport failed with status ${response.status}.`);
|
|
@@ -246,7 +318,7 @@ function toNumberWithMinimum(value, fallback, minimum) {
|
|
|
246
318
|
return Math.max(toPositiveInteger(value, fallback), minimum);
|
|
247
319
|
}
|
|
248
320
|
function resolveSessionId(configSessionId, previousSessionId) {
|
|
249
|
-
const explicitSessionId =
|
|
321
|
+
const explicitSessionId = configSessionId?.trim();
|
|
250
322
|
if (explicitSessionId) {
|
|
251
323
|
return explicitSessionId;
|
|
252
324
|
}
|
|
@@ -256,7 +328,7 @@ function resolveSessionId(configSessionId, previousSessionId) {
|
|
|
256
328
|
return createId("session");
|
|
257
329
|
}
|
|
258
330
|
function normalizeRedactKeys(keys, previousKeys) {
|
|
259
|
-
const values =
|
|
331
|
+
const values = keys ?? previousKeys ?? DEFAULT_ERROR_REDACT_KEYS;
|
|
260
332
|
const normalized = values.map((value) => value.trim().toLowerCase()).filter((value) => value.length > 0);
|
|
261
333
|
if (normalized.length === 0) {
|
|
262
334
|
return [...DEFAULT_ERROR_REDACT_KEYS];
|
|
@@ -265,97 +337,97 @@ function normalizeRedactKeys(keys, previousKeys) {
|
|
|
265
337
|
}
|
|
266
338
|
function resolveErrorReportingConfig(config, previous) {
|
|
267
339
|
return {
|
|
268
|
-
enabled:
|
|
269
|
-
secureEndpointOnly:
|
|
340
|
+
enabled: config?.enabled ?? previous?.enabled ?? true,
|
|
341
|
+
secureEndpointOnly: config?.secureEndpointOnly ?? previous?.secureEndpointOnly ?? true,
|
|
270
342
|
maxMessageLength: toNumberWithMinimum(
|
|
271
|
-
|
|
343
|
+
config?.maxMessageLength ?? previous?.maxMessageLength,
|
|
272
344
|
DEFAULT_ERROR_MESSAGE_LENGTH,
|
|
273
345
|
16
|
|
274
346
|
),
|
|
275
347
|
maxStackLength: toNumberWithMinimum(
|
|
276
|
-
|
|
348
|
+
config?.maxStackLength ?? previous?.maxStackLength,
|
|
277
349
|
DEFAULT_ERROR_STACK_LENGTH,
|
|
278
350
|
32
|
|
279
351
|
),
|
|
280
352
|
maxComponentStackLength: toNumberWithMinimum(
|
|
281
|
-
|
|
353
|
+
config?.maxComponentStackLength ?? previous?.maxComponentStackLength,
|
|
282
354
|
DEFAULT_ERROR_COMPONENT_STACK_LENGTH,
|
|
283
355
|
32
|
|
284
356
|
),
|
|
285
357
|
maxContextDepth: toNumberWithMinimum(
|
|
286
|
-
|
|
358
|
+
config?.maxContextDepth ?? previous?.maxContextDepth,
|
|
287
359
|
DEFAULT_ERROR_CONTEXT_DEPTH,
|
|
288
360
|
1
|
|
289
361
|
),
|
|
290
362
|
maxContextBreadth: toNumberWithMinimum(
|
|
291
|
-
|
|
363
|
+
config?.maxContextBreadth ?? previous?.maxContextBreadth,
|
|
292
364
|
DEFAULT_ERROR_CONTEXT_BREADTH,
|
|
293
365
|
1
|
|
294
366
|
),
|
|
295
367
|
maxTagCount: toNumberWithMinimum(
|
|
296
|
-
|
|
368
|
+
config?.maxTagCount ?? previous?.maxTagCount,
|
|
297
369
|
DEFAULT_ERROR_TAG_COUNT,
|
|
298
370
|
1
|
|
299
371
|
),
|
|
300
372
|
thresholdCount: toNumberWithMinimum(
|
|
301
|
-
|
|
373
|
+
config?.thresholdCount ?? previous?.thresholdCount,
|
|
302
374
|
DEFAULT_ERROR_THRESHOLD_COUNT,
|
|
303
375
|
1
|
|
304
376
|
),
|
|
305
377
|
thresholdWindowMs: toNumberWithMinimum(
|
|
306
|
-
|
|
378
|
+
config?.thresholdWindowMs ?? previous?.thresholdWindowMs,
|
|
307
379
|
DEFAULT_ERROR_THRESHOLD_WINDOW_MS,
|
|
308
380
|
1e3
|
|
309
381
|
),
|
|
310
|
-
redactKeys: normalizeRedactKeys(
|
|
311
|
-
onThresholdReached:
|
|
382
|
+
redactKeys: normalizeRedactKeys(config?.redactKeys, previous?.redactKeys),
|
|
383
|
+
onThresholdReached: config?.onThresholdReached ?? previous?.onThresholdReached
|
|
312
384
|
};
|
|
313
385
|
}
|
|
314
386
|
function resolveConfig(config, previous) {
|
|
315
|
-
const source = (
|
|
387
|
+
const source = (config.source ?? previous?.source ?? "").trim();
|
|
316
388
|
if (!source) {
|
|
317
389
|
throw new Error("Local space analytics requires a non-empty source.");
|
|
318
390
|
}
|
|
319
|
-
const runtime = resolveRuntime(config.runtime,
|
|
320
|
-
const channel = resolveChannel(config.channel, runtime,
|
|
321
|
-
const endpointCandidate = config.endpoint !== void 0 ? config.endpoint :
|
|
322
|
-
const endpoint =
|
|
391
|
+
const runtime = resolveRuntime(config.runtime, previous?.runtime);
|
|
392
|
+
const channel = resolveChannel(config.channel, runtime, previous?.channel);
|
|
393
|
+
const endpointCandidate = config.endpoint !== void 0 ? config.endpoint : previous?.endpoint;
|
|
394
|
+
const endpoint = endpointCandidate?.trim() || void 0;
|
|
323
395
|
return {
|
|
324
396
|
source,
|
|
325
397
|
endpoint,
|
|
326
398
|
channel,
|
|
327
399
|
runtime,
|
|
328
|
-
sessionId: resolveSessionId(config.sessionId,
|
|
329
|
-
injectChannelContext:
|
|
330
|
-
enabled:
|
|
400
|
+
sessionId: resolveSessionId(config.sessionId, previous?.sessionId),
|
|
401
|
+
injectChannelContext: config.injectChannelContext ?? previous?.injectChannelContext ?? true,
|
|
402
|
+
enabled: config.enabled ?? previous?.enabled ?? true,
|
|
331
403
|
defaultContext: {
|
|
332
|
-
...
|
|
333
|
-
...
|
|
404
|
+
...previous?.defaultContext ?? {},
|
|
405
|
+
...config.defaultContext ?? {}
|
|
334
406
|
},
|
|
335
407
|
headers: {
|
|
336
408
|
"content-type": JSON_CONTENT_TYPE_HEADER,
|
|
337
|
-
...
|
|
338
|
-
...
|
|
409
|
+
...previous?.headers ?? {},
|
|
410
|
+
...config.headers ?? {}
|
|
339
411
|
},
|
|
340
412
|
flushIntervalMs: toPositiveInteger(
|
|
341
|
-
|
|
413
|
+
config.flushIntervalMs ?? previous?.flushIntervalMs,
|
|
342
414
|
DEFAULT_FLUSH_INTERVAL_MS
|
|
343
415
|
),
|
|
344
416
|
batchSize: toPositiveInteger(
|
|
345
|
-
|
|
417
|
+
config.batchSize ?? previous?.batchSize,
|
|
346
418
|
DEFAULT_BATCH_SIZE
|
|
347
419
|
),
|
|
348
420
|
maxQueueSize: toPositiveInteger(
|
|
349
|
-
|
|
421
|
+
config.maxQueueSize ?? previous?.maxQueueSize,
|
|
350
422
|
DEFAULT_MAX_QUEUE_SIZE
|
|
351
423
|
),
|
|
352
424
|
storageKey: resolveStorageKey(config.storageKey, source, channel, previous),
|
|
353
425
|
errorReporting: resolveErrorReportingConfig(
|
|
354
426
|
config.errorReporting,
|
|
355
|
-
|
|
427
|
+
previous?.errorReporting
|
|
356
428
|
),
|
|
357
|
-
transport:
|
|
358
|
-
onError:
|
|
429
|
+
transport: config.transport ?? previous?.transport ?? defaultTransport,
|
|
430
|
+
onError: config.onError ?? previous?.onError
|
|
359
431
|
};
|
|
360
432
|
}
|
|
361
433
|
function isStoredRecordCandidate(value) {
|
|
@@ -382,7 +454,7 @@ function redactSensitiveText(value) {
|
|
|
382
454
|
);
|
|
383
455
|
}
|
|
384
456
|
function sanitizeSingleLine(value, maxLength) {
|
|
385
|
-
const raw = typeof value === "string" ? value : String(
|
|
457
|
+
const raw = typeof value === "string" ? value : String(value ?? "");
|
|
386
458
|
const flattened = raw.replace(/\p{Cc}/gu, " ").replace(/\s+/g, " ").trim();
|
|
387
459
|
if (!flattened) {
|
|
388
460
|
return "";
|
|
@@ -391,7 +463,7 @@ function sanitizeSingleLine(value, maxLength) {
|
|
|
391
463
|
return applySchemaLogHandling(redacted, false).slice(0, maxLength);
|
|
392
464
|
}
|
|
393
465
|
function sanitizeMultiline(value, maxLength) {
|
|
394
|
-
const raw = typeof value === "string" ? value : String(
|
|
466
|
+
const raw = typeof value === "string" ? value : String(value ?? "");
|
|
395
467
|
const normalized = raw.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
396
468
|
const sanitized = redactSensitiveText(normalized).split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join("\n");
|
|
397
469
|
if (!sanitized) {
|
|
@@ -487,7 +559,7 @@ function sanitizeContextValue(value, resolvedErrorReporting, depth, seen, identi
|
|
|
487
559
|
for (const [key, nestedValue] of entries) {
|
|
488
560
|
const childPath = keyPath ? `${keyPath}.${key}` : key;
|
|
489
561
|
if (shouldRedactContextKey(key, resolvedErrorReporting)) {
|
|
490
|
-
sanitized[key] = applySchemaLogHandling(String(
|
|
562
|
+
sanitized[key] = applySchemaLogHandling(String(nestedValue ?? ""), true) || REDACTED_VALUE;
|
|
491
563
|
pushIdentifier(
|
|
492
564
|
identifiers,
|
|
493
565
|
childPath,
|
|
@@ -519,7 +591,7 @@ function sanitizeErrorContext(context, resolvedErrorReporting) {
|
|
|
519
591
|
const entries = Object.entries(context).slice(0, resolvedErrorReporting.maxContextBreadth);
|
|
520
592
|
for (const [key, value] of entries) {
|
|
521
593
|
if (shouldRedactContextKey(key, resolvedErrorReporting)) {
|
|
522
|
-
sanitized[key] = applySchemaLogHandling(String(
|
|
594
|
+
sanitized[key] = applySchemaLogHandling(String(value ?? ""), true) || REDACTED_VALUE;
|
|
523
595
|
pushIdentifier(identifiers, key, value, resolvedErrorReporting.maxMessageLength);
|
|
524
596
|
continue;
|
|
525
597
|
}
|
|
@@ -603,7 +675,7 @@ function normalizeTags(tags, maxTagCount, maxTagLength) {
|
|
|
603
675
|
function safeSerialize(value) {
|
|
604
676
|
try {
|
|
605
677
|
return JSON.stringify(value);
|
|
606
|
-
} catch
|
|
678
|
+
} catch {
|
|
607
679
|
return "[unserializable]";
|
|
608
680
|
}
|
|
609
681
|
}
|
|
@@ -646,13 +718,13 @@ function normalizeErrorReport(report, resolvedErrorReporting, existingFingerprin
|
|
|
646
718
|
resolvedErrorReporting.maxComponentStackLength
|
|
647
719
|
) : void 0;
|
|
648
720
|
const severity = report.severity === "fatal" ? "fatal" : "error";
|
|
649
|
-
const handled =
|
|
721
|
+
const handled = report.handled ?? true;
|
|
650
722
|
const tags = normalizeTags(
|
|
651
723
|
report.tags,
|
|
652
724
|
resolvedErrorReporting.maxTagCount,
|
|
653
725
|
resolvedErrorReporting.maxMessageLength
|
|
654
726
|
);
|
|
655
|
-
const fingerprintBase = `${boundary}|${name}|${message}|${
|
|
727
|
+
const fingerprintBase = `${boundary}|${name}|${message}|${stack?.split("\n")[0] ?? ""}|${severity}`;
|
|
656
728
|
const fallbackFingerprint = `err_${hashString(fingerprintBase).toString(16)}`;
|
|
657
729
|
const fingerprint = sanitizeSingleLine(existingFingerprint, 120) || fallbackFingerprint;
|
|
658
730
|
return {
|
|
@@ -714,7 +786,7 @@ function readQueue(storageKey, fallbackConfig) {
|
|
|
714
786
|
return [];
|
|
715
787
|
}
|
|
716
788
|
return parsed.filter(isStoredRecordCandidate).map((record) => normalizeStoredRecord(record, fallbackConfig));
|
|
717
|
-
} catch
|
|
789
|
+
} catch {
|
|
718
790
|
return [];
|
|
719
791
|
}
|
|
720
792
|
}
|
|
@@ -728,7 +800,7 @@ function writeQueue(storageKey, queue) {
|
|
|
728
800
|
return;
|
|
729
801
|
}
|
|
730
802
|
window.localStorage.setItem(storageKey, JSON.stringify(queue));
|
|
731
|
-
} catch
|
|
803
|
+
} catch {
|
|
732
804
|
}
|
|
733
805
|
}
|
|
734
806
|
function createPayload(config, events) {
|
|
@@ -743,7 +815,7 @@ function createPayload(config, events) {
|
|
|
743
815
|
function createMergedContext(config, eventChannel, eventContext) {
|
|
744
816
|
const mergedContext = {
|
|
745
817
|
...config.defaultContext,
|
|
746
|
-
...
|
|
818
|
+
...eventContext ?? {}
|
|
747
819
|
};
|
|
748
820
|
if (config.injectChannelContext) {
|
|
749
821
|
if (mergedContext.analyticsChannel === void 0) {
|
|
@@ -770,7 +842,7 @@ function isSecureEndpoint(endpoint) {
|
|
|
770
842
|
return true;
|
|
771
843
|
}
|
|
772
844
|
return parsedUrl.protocol === "http:" && LOCALHOST_HOSTS.has(parsedUrl.hostname);
|
|
773
|
-
} catch
|
|
845
|
+
} catch {
|
|
774
846
|
return false;
|
|
775
847
|
}
|
|
776
848
|
}
|
|
@@ -783,6 +855,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
783
855
|
let isFlushing = false;
|
|
784
856
|
let flushQueuedAfterCurrent = false;
|
|
785
857
|
let isDestroyed = false;
|
|
858
|
+
const transportController = new AbortController();
|
|
786
859
|
const issueAggregates = /* @__PURE__ */ new Map();
|
|
787
860
|
const persistQueue = () => writeQueue(resolvedConfig.storageKey, queue);
|
|
788
861
|
const trimQueue = () => {
|
|
@@ -804,8 +877,8 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
804
877
|
fingerprint,
|
|
805
878
|
boundary: state.sample.boundary,
|
|
806
879
|
count: sortedTimestamps.length,
|
|
807
|
-
firstSeen:
|
|
808
|
-
lastSeen:
|
|
880
|
+
firstSeen: sortedTimestamps[0] ?? Date.now(),
|
|
881
|
+
lastSeen: sortedTimestamps[sortedTimestamps.length - 1] ?? Date.now(),
|
|
809
882
|
severity: state.sample.severity,
|
|
810
883
|
sample: state.sample
|
|
811
884
|
};
|
|
@@ -859,7 +932,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
859
932
|
report
|
|
860
933
|
});
|
|
861
934
|
} catch (error) {
|
|
862
|
-
|
|
935
|
+
resolvedConfig.onError?.(error);
|
|
863
936
|
}
|
|
864
937
|
};
|
|
865
938
|
const getIssueReports = () => {
|
|
@@ -895,11 +968,11 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
895
968
|
if (!events.some((event) => event.kind === "error")) {
|
|
896
969
|
return true;
|
|
897
970
|
}
|
|
898
|
-
|
|
971
|
+
resolvedConfig.onError?.(
|
|
899
972
|
new Error(
|
|
900
973
|
`Error reporting requires an https or localhost endpoint. Refused endpoint: ${resolvedConfig.endpoint}`
|
|
901
974
|
)
|
|
902
|
-
)
|
|
975
|
+
);
|
|
903
976
|
return false;
|
|
904
977
|
};
|
|
905
978
|
const flushWithBeacon = () => {
|
|
@@ -922,7 +995,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
922
995
|
persistQueue();
|
|
923
996
|
}
|
|
924
997
|
return sent;
|
|
925
|
-
} catch
|
|
998
|
+
} catch {
|
|
926
999
|
return false;
|
|
927
1000
|
}
|
|
928
1001
|
};
|
|
@@ -949,12 +1022,14 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
949
1022
|
body,
|
|
950
1023
|
headers: resolvedConfig.headers,
|
|
951
1024
|
// Normal flushes do not need fetch keepalive; unload/pagehide uses sendBeacon.
|
|
952
|
-
keepalive: false
|
|
1025
|
+
keepalive: false,
|
|
1026
|
+
signal: transportController.signal
|
|
953
1027
|
});
|
|
1028
|
+
if (transportController.signal.aborted) return;
|
|
954
1029
|
queue = queue.slice(events.length);
|
|
955
1030
|
persistQueue();
|
|
956
1031
|
} catch (error) {
|
|
957
|
-
|
|
1032
|
+
if (!transportController.signal.aborted) resolvedConfig.onError?.(error);
|
|
958
1033
|
} finally {
|
|
959
1034
|
isFlushing = false;
|
|
960
1035
|
if (flushQueuedAfterCurrent) {
|
|
@@ -1014,7 +1089,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1014
1089
|
if (isDestroyed || !resolvedConfig.enabled) {
|
|
1015
1090
|
return;
|
|
1016
1091
|
}
|
|
1017
|
-
const eventChannel =
|
|
1092
|
+
const eventChannel = event.channel ?? resolvedConfig.channel;
|
|
1018
1093
|
const requestId = typeof event.requestId === "string" && event.requestId.trim() ? event.requestId.trim() : void 0;
|
|
1019
1094
|
const kind = event.kind === "error" ? "error" : "interaction";
|
|
1020
1095
|
const normalizedError = kind === "error" && isErrorDetailsCandidate(event.error) ? normalizeStoredErrorDetails(event.error, resolvedConfig.errorReporting) : void 0;
|
|
@@ -1031,7 +1106,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1031
1106
|
requestId,
|
|
1032
1107
|
source: resolvedConfig.source,
|
|
1033
1108
|
sessionId: resolvedConfig.sessionId,
|
|
1034
|
-
timestamp:
|
|
1109
|
+
timestamp: event.timestamp ?? Date.now(),
|
|
1035
1110
|
context: createMergedContext(resolvedConfig, eventChannel, event.context),
|
|
1036
1111
|
error: normalizedError
|
|
1037
1112
|
};
|
|
@@ -1045,15 +1120,15 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1045
1120
|
return;
|
|
1046
1121
|
}
|
|
1047
1122
|
if (resolvedConfig.errorReporting.secureEndpointOnly && resolvedConfig.endpoint && !isSecureEndpoint(resolvedConfig.endpoint)) {
|
|
1048
|
-
|
|
1123
|
+
resolvedConfig.onError?.(
|
|
1049
1124
|
new Error(
|
|
1050
1125
|
`Error reporting requires an https or localhost endpoint. Refused endpoint: ${resolvedConfig.endpoint}`
|
|
1051
1126
|
)
|
|
1052
|
-
)
|
|
1127
|
+
);
|
|
1053
1128
|
return;
|
|
1054
1129
|
}
|
|
1055
|
-
const eventChannel =
|
|
1056
|
-
const timestamp =
|
|
1130
|
+
const eventChannel = report.channel ?? resolvedConfig.channel;
|
|
1131
|
+
const timestamp = report.timestamp ?? Date.now();
|
|
1057
1132
|
const normalizedError = normalizeErrorReport(report, resolvedConfig.errorReporting);
|
|
1058
1133
|
const {
|
|
1059
1134
|
context: errorContext,
|
|
@@ -1111,7 +1186,7 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1111
1186
|
{
|
|
1112
1187
|
...resolvedConfig,
|
|
1113
1188
|
...nextConfig,
|
|
1114
|
-
source:
|
|
1189
|
+
source: nextConfig.source ?? resolvedConfig.source
|
|
1115
1190
|
},
|
|
1116
1191
|
resolvedConfig
|
|
1117
1192
|
);
|
|
@@ -1127,7 +1202,14 @@ function createLocalSpaceAnalyticsClient(config) {
|
|
|
1127
1202
|
getConfig() {
|
|
1128
1203
|
return resolvedConfig;
|
|
1129
1204
|
},
|
|
1130
|
-
destroy() {
|
|
1205
|
+
destroy(options) {
|
|
1206
|
+
if (options?.discard) {
|
|
1207
|
+
transportController.abort();
|
|
1208
|
+
queue = [];
|
|
1209
|
+
flushQueuedAfterCurrent = false;
|
|
1210
|
+
issueAggregates.clear();
|
|
1211
|
+
writeQueue(resolvedConfig.storageKey, []);
|
|
1212
|
+
}
|
|
1131
1213
|
if (isDestroyed) {
|
|
1132
1214
|
return;
|
|
1133
1215
|
}
|
|
@@ -1148,14 +1230,14 @@ function createFrontendAnalyticsClient(config) {
|
|
|
1148
1230
|
return createLocalSpaceAnalyticsClient({
|
|
1149
1231
|
...config,
|
|
1150
1232
|
channel: "frontend",
|
|
1151
|
-
runtime:
|
|
1233
|
+
runtime: config.runtime ?? "browser"
|
|
1152
1234
|
});
|
|
1153
1235
|
}
|
|
1154
1236
|
function createBackendAnalyticsClient(config) {
|
|
1155
1237
|
return createLocalSpaceAnalyticsClient({
|
|
1156
1238
|
...config,
|
|
1157
1239
|
channel: "backend",
|
|
1158
|
-
runtime:
|
|
1240
|
+
runtime: config.runtime ?? "server"
|
|
1159
1241
|
});
|
|
1160
1242
|
}
|
|
1161
1243
|
function createNoopLocalSpaceAnalyticsClient(source = "noop", channel = "frontend") {
|
|
@@ -1320,7 +1402,7 @@ var EVENT_DEFINITION_FIELDS = /* @__PURE__ */ new Set([
|
|
|
1320
1402
|
var TARGET_FIELDS = /* @__PURE__ */ new Set(["type", "id"]);
|
|
1321
1403
|
var CATALOG_OPTIONS_FIELDS = /* @__PURE__ */ new Set(["sources"]);
|
|
1322
1404
|
var SemanticJourneyValidationError = class extends Error {
|
|
1323
|
-
|
|
1405
|
+
code;
|
|
1324
1406
|
constructor(code) {
|
|
1325
1407
|
super(
|
|
1326
1408
|
code === "invalid-token" ? "Semantic journey token is invalid." : "Semantic journey input is invalid."
|
|
@@ -1535,7 +1617,7 @@ function defineSemanticJourneyCatalogUnsafe(definitions, options) {
|
|
|
1535
1617
|
function defineSemanticJourneyCatalog(definitions, options) {
|
|
1536
1618
|
try {
|
|
1537
1619
|
return defineSemanticJourneyCatalogUnsafe(definitions, options);
|
|
1538
|
-
} catch
|
|
1620
|
+
} catch {
|
|
1539
1621
|
return invalidDefinition();
|
|
1540
1622
|
}
|
|
1541
1623
|
}
|
|
@@ -1556,10 +1638,10 @@ function validateTarget(candidate, definition) {
|
|
|
1556
1638
|
if (keys === null || keys.length !== 2 || !hasOnlyFields(keys, TARGET_FIELDS) || !isSemanticToken(candidate.type) || !isSemanticToken(candidate.id) || looksSensitive(candidate.type) || looksSensitive(candidate.id)) {
|
|
1557
1639
|
return invalidInput();
|
|
1558
1640
|
}
|
|
1559
|
-
const allowedTarget = (
|
|
1641
|
+
const allowedTarget = (definition.targets ?? []).some(
|
|
1560
1642
|
(target) => target.type === candidate.type && target.id === candidate.id
|
|
1561
1643
|
);
|
|
1562
|
-
const allowedEffect = candidate.type === "effect" && (
|
|
1644
|
+
const allowedEffect = candidate.type === "effect" && (definition.effects ?? []).includes(candidate.id);
|
|
1563
1645
|
if (!allowedTarget && !allowedEffect) {
|
|
1564
1646
|
return invalidInput();
|
|
1565
1647
|
}
|
|
@@ -1590,7 +1672,7 @@ function validateSemanticJourneyEventInputUnsafe(catalogue, input) {
|
|
|
1590
1672
|
return invalidInput();
|
|
1591
1673
|
}
|
|
1592
1674
|
const target = input.target === void 0 ? void 0 : validateTarget(input.target, definition);
|
|
1593
|
-
const candidateAttributes =
|
|
1675
|
+
const candidateAttributes = input.attributes ?? {};
|
|
1594
1676
|
if (!isRecord(candidateAttributes)) {
|
|
1595
1677
|
return invalidInput();
|
|
1596
1678
|
}
|
|
@@ -1598,7 +1680,7 @@ function validateSemanticJourneyEventInputUnsafe(catalogue, input) {
|
|
|
1598
1680
|
if (attributeNames === null || attributeNames.length > MAX_EVENT_ATTRIBUTES) {
|
|
1599
1681
|
return invalidInput();
|
|
1600
1682
|
}
|
|
1601
|
-
const registeredAttributes =
|
|
1683
|
+
const registeredAttributes = definition.attributes ?? {};
|
|
1602
1684
|
for (const attributeName of attributeNames) {
|
|
1603
1685
|
if (!Object.prototype.hasOwnProperty.call(registeredAttributes, attributeName)) {
|
|
1604
1686
|
return invalidInput();
|
|
@@ -1670,7 +1752,7 @@ function createNonZeroIdentifier(byteLength2, randomBytes) {
|
|
|
1670
1752
|
for (let attempt = 0; attempt < MAX_IDENTIFIER_ATTEMPTS; attempt += 1) {
|
|
1671
1753
|
const identifier = createSecureRandomHex(
|
|
1672
1754
|
byteLength2,
|
|
1673
|
-
|
|
1755
|
+
randomBytes ?? webCryptoRandomBytes
|
|
1674
1756
|
);
|
|
1675
1757
|
if (!/^0+$/.test(identifier)) {
|
|
1676
1758
|
return identifier;
|
|
@@ -1817,12 +1899,12 @@ function addSafeCount(current, increment) {
|
|
|
1817
1899
|
}
|
|
1818
1900
|
return next;
|
|
1819
1901
|
}
|
|
1820
|
-
var SemanticJourneyAggregateStore =
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
constructor(options) {
|
|
1902
|
+
var SemanticJourneyAggregateStore = class {
|
|
1903
|
+
counters = /* @__PURE__ */ new Map();
|
|
1904
|
+
options;
|
|
1905
|
+
dropped = 0;
|
|
1906
|
+
coalesced = 0;
|
|
1907
|
+
constructor(options) {
|
|
1826
1908
|
if (!isSemanticSource(options.source) || !options.catalogue.sources.includes(options.source) || options.channel !== "frontend" && options.channel !== "backend" || options.runtime !== "browser" && options.runtime !== "server") {
|
|
1827
1909
|
invalidAggregate();
|
|
1828
1910
|
}
|
|
@@ -1838,7 +1920,7 @@ var SemanticJourneyAggregateStore = (_class = class {
|
|
|
1838
1920
|
this.counters.set(key, Object.freeze({
|
|
1839
1921
|
eventName,
|
|
1840
1922
|
outcome,
|
|
1841
|
-
count: addSafeCount(
|
|
1923
|
+
count: addSafeCount(existing?.count ?? 0, count)
|
|
1842
1924
|
}));
|
|
1843
1925
|
}
|
|
1844
1926
|
recordDropped(count = 1) {
|
|
@@ -1932,7 +2014,100 @@ var SemanticJourneyAggregateStore = (_class = class {
|
|
|
1932
2014
|
return byName !== 0 ? byName : left.outcome.localeCompare(right.outcome);
|
|
1933
2015
|
}));
|
|
1934
2016
|
}
|
|
1935
|
-
}
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
// src/journey/metrics.ts
|
|
2020
|
+
var durationBuckets = [
|
|
2021
|
+
[100, "lt100ms"],
|
|
2022
|
+
[250, "lt250ms"],
|
|
2023
|
+
[500, "lt500ms"],
|
|
2024
|
+
[1e3, "lt1000ms"],
|
|
2025
|
+
[2500, "lt2500ms"],
|
|
2026
|
+
[5e3, "lt5000ms"],
|
|
2027
|
+
[1e4, "lt10000ms"],
|
|
2028
|
+
[Infinity, "gte10000ms"]
|
|
2029
|
+
];
|
|
2030
|
+
var duration = (category) => ({
|
|
2031
|
+
category,
|
|
2032
|
+
outcome: "unknown",
|
|
2033
|
+
buckets: durationBuckets,
|
|
2034
|
+
maximum: 864e5
|
|
2035
|
+
});
|
|
2036
|
+
var metrics = /* @__PURE__ */ (() => ({
|
|
2037
|
+
"page.load": duration("presentation"),
|
|
2038
|
+
"route.ready": duration("presentation"),
|
|
2039
|
+
"world.ready": duration("presentation"),
|
|
2040
|
+
"request.duration": duration("request"),
|
|
2041
|
+
"vital.lcp": duration("presentation"),
|
|
2042
|
+
"vital.fcp": duration("presentation"),
|
|
2043
|
+
"vital.inp": duration("interaction"),
|
|
2044
|
+
"vital.ttfb": duration("request"),
|
|
2045
|
+
"vital.cls": {
|
|
2046
|
+
category: "presentation",
|
|
2047
|
+
outcome: "unknown",
|
|
2048
|
+
maximum: 100,
|
|
2049
|
+
buckets: [[0.1, "lt01"], [0.25, "lt025"], [Infinity, "gte025"]]
|
|
2050
|
+
},
|
|
2051
|
+
"episode.active-duration": {
|
|
2052
|
+
category: "state",
|
|
2053
|
+
outcome: "unknown",
|
|
2054
|
+
maximum: 864e5,
|
|
2055
|
+
buckets: [
|
|
2056
|
+
[1e4, "lt10s"],
|
|
2057
|
+
[6e4, "lt60s"],
|
|
2058
|
+
[3e5, "lt300s"],
|
|
2059
|
+
[9e5, "lt900s"],
|
|
2060
|
+
[36e5, "lt3600s"],
|
|
2061
|
+
[Infinity, "gte3600s"]
|
|
2062
|
+
]
|
|
2063
|
+
},
|
|
2064
|
+
"episode.started": { category: "state", outcome: "unknown" },
|
|
2065
|
+
"episode.completed": { category: "state", outcome: "unknown" },
|
|
2066
|
+
"request.started": { category: "request", outcome: "unknown" },
|
|
2067
|
+
"request.completed": { category: "request", outcome: "success" },
|
|
2068
|
+
"request.failed": { category: "request", outcome: "failure" },
|
|
2069
|
+
"request.cancelled": { category: "request", outcome: "cancelled" },
|
|
2070
|
+
"request.rejected": { category: "request", outcome: "denied" },
|
|
2071
|
+
"error.runtime": { category: "error", outcome: "failure" },
|
|
2072
|
+
"error.resource": { category: "error", outcome: "failure" },
|
|
2073
|
+
"error.render": { category: "error", outcome: "failure" },
|
|
2074
|
+
"error.unhandled": { category: "error", outcome: "failure" }
|
|
2075
|
+
}))();
|
|
2076
|
+
var USEFUL_METRIC_EVENT_DEFINITIONS = /* @__PURE__ */ (() => Object.freeze(Object.fromEntries(Object.entries(metrics).flatMap(([metric, definition]) => {
|
|
2077
|
+
const names = definition.buckets ? definition.buckets.map(([, bucket]) => `metric.${metric}.${bucket}`) : [`metric.${metric}`];
|
|
2078
|
+
return names.map((name) => [name, Object.freeze({ category: definition.category })]);
|
|
2079
|
+
}))))();
|
|
2080
|
+
function projectUsefulMetric(input) {
|
|
2081
|
+
try {
|
|
2082
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) return null;
|
|
2083
|
+
const prototype = Object.getPrototypeOf(input);
|
|
2084
|
+
if (prototype !== Object.prototype && prototype !== null) return null;
|
|
2085
|
+
const keys = Reflect.ownKeys(input);
|
|
2086
|
+
if (keys.length < 1 || keys.length > 2 || keys.some((key) => key !== "metric" && key !== "value")) return null;
|
|
2087
|
+
const descriptors = Object.getOwnPropertyDescriptors(input);
|
|
2088
|
+
const metric = descriptors.metric;
|
|
2089
|
+
if (!metric || !("value" in metric) || typeof metric.value !== "string" || !Object.hasOwn(metrics, metric.value)) return null;
|
|
2090
|
+
const definition = metrics[metric.value];
|
|
2091
|
+
let name = `metric.${metric.value}`;
|
|
2092
|
+
if (definition.buckets) {
|
|
2093
|
+
const value = descriptors.value;
|
|
2094
|
+
if (keys.length !== 2 || !value || !("value" in value) || typeof value.value !== "number" || !Number.isFinite(value.value) || value.value < 0 || value.value > definition.maximum) return null;
|
|
2095
|
+
const bucket = definition.buckets.find(([upper]) => value.value < upper);
|
|
2096
|
+
name += `.${bucket[1]}`;
|
|
2097
|
+
} else if (keys.length !== 1) {
|
|
2098
|
+
return null;
|
|
2099
|
+
}
|
|
2100
|
+
return Object.freeze({
|
|
2101
|
+
name,
|
|
2102
|
+
category: definition.category,
|
|
2103
|
+
phase: metric.value.endsWith(".started") ? "start" : "end",
|
|
2104
|
+
outcome: definition.outcome,
|
|
2105
|
+
modality: "system"
|
|
2106
|
+
});
|
|
2107
|
+
} catch {
|
|
2108
|
+
return null;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
1936
2111
|
|
|
1937
2112
|
// src/journey/transport.ts
|
|
1938
2113
|
var SemanticJourneyTransportError = class extends Error {
|
|
@@ -1944,10 +2119,10 @@ var SemanticJourneyTransportError = class extends Error {
|
|
|
1944
2119
|
this.retryAfterMs = retryAfterMs;
|
|
1945
2120
|
this.name = "SemanticJourneyTransportError";
|
|
1946
2121
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
2122
|
+
code;
|
|
2123
|
+
retryable;
|
|
2124
|
+
status;
|
|
2125
|
+
retryAfterMs;
|
|
1951
2126
|
};
|
|
1952
2127
|
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
1953
2128
|
var MAX_RETRY_AFTER_MS = 5 * 60 * 1e3;
|
|
@@ -1956,7 +2131,7 @@ function resolveBaseUrl(explicitBaseUrl) {
|
|
|
1956
2131
|
if (explicitBaseUrl) {
|
|
1957
2132
|
return explicitBaseUrl;
|
|
1958
2133
|
}
|
|
1959
|
-
if (typeof window !== "undefined" &&
|
|
2134
|
+
if (typeof window !== "undefined" && window.location?.origin) {
|
|
1960
2135
|
return window.location.origin;
|
|
1961
2136
|
}
|
|
1962
2137
|
return void 0;
|
|
@@ -1981,7 +2156,7 @@ function isSecureSemanticJourneyEndpoint(endpoint, baseUrl) {
|
|
|
1981
2156
|
return true;
|
|
1982
2157
|
}
|
|
1983
2158
|
return parsed.protocol === "http:" && LOCAL_HOSTS.has(parsed.hostname);
|
|
1984
|
-
} catch
|
|
2159
|
+
} catch {
|
|
1985
2160
|
return false;
|
|
1986
2161
|
}
|
|
1987
2162
|
}
|
|
@@ -2007,8 +2182,8 @@ function isRetryableStatus(status) {
|
|
|
2007
2182
|
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
2008
2183
|
}
|
|
2009
2184
|
function createDefaultSemanticJourneyAggregateTransport(options = {}) {
|
|
2010
|
-
const fetchImplementation =
|
|
2011
|
-
const now =
|
|
2185
|
+
const fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
2186
|
+
const now = options.now ?? (() => Date.now());
|
|
2012
2187
|
return async (request) => {
|
|
2013
2188
|
if (!isSecureSemanticJourneyEndpoint(request.endpoint, options.baseUrl)) {
|
|
2014
2189
|
throw new SemanticJourneyTransportError("rejected", false);
|
|
@@ -2024,7 +2199,7 @@ function createDefaultSemanticJourneyAggregateTransport(options = {}) {
|
|
|
2024
2199
|
}
|
|
2025
2200
|
try {
|
|
2026
2201
|
resolvedEndpoint = new URL(request.endpoint, base).toString();
|
|
2027
|
-
} catch
|
|
2202
|
+
} catch {
|
|
2028
2203
|
throw new SemanticJourneyTransportError("rejected", false);
|
|
2029
2204
|
}
|
|
2030
2205
|
}
|
|
@@ -2034,13 +2209,13 @@ function createDefaultSemanticJourneyAggregateTransport(options = {}) {
|
|
|
2034
2209
|
method: "POST",
|
|
2035
2210
|
body: request.body,
|
|
2036
2211
|
headers: request.headers,
|
|
2037
|
-
keepalive:
|
|
2212
|
+
keepalive: request.keepalive ?? false,
|
|
2038
2213
|
signal: request.signal,
|
|
2039
2214
|
credentials: "omit",
|
|
2040
2215
|
referrerPolicy: "no-referrer",
|
|
2041
2216
|
redirect: "error"
|
|
2042
2217
|
});
|
|
2043
|
-
} catch
|
|
2218
|
+
} catch {
|
|
2044
2219
|
if (request.signal.aborted) {
|
|
2045
2220
|
throw new SemanticJourneyTransportError("aborted", true);
|
|
2046
2221
|
}
|
|
@@ -2101,7 +2276,7 @@ function isValidReceipt(value, catalogue) {
|
|
|
2101
2276
|
}
|
|
2102
2277
|
const receipt = value;
|
|
2103
2278
|
const definition = isJourneyToken(receipt.name) ? getJourneyEventDefinition(catalogue, receipt.name) : void 0;
|
|
2104
|
-
return receipt.version === SEMANTIC_JOURNEY_RECEIPT_VERSION && definition !== void 0 && isReceiptOutcome(receipt.outcome) && isReceiptPhase(receipt.phase) && isJourneyToken(receipt.effect) && (
|
|
2279
|
+
return receipt.version === SEMANTIC_JOURNEY_RECEIPT_VERSION && definition !== void 0 && isReceiptOutcome(receipt.outcome) && isReceiptPhase(receipt.phase) && isJourneyToken(receipt.effect) && (definition.effects ?? []).includes(receipt.effect);
|
|
2105
2280
|
}
|
|
2106
2281
|
function serializeReceipt(receipt) {
|
|
2107
2282
|
return `version=${receipt.version};name=${receipt.name};outcome=${receipt.outcome};phase=${receipt.phase};effect=${receipt.effect}`;
|
|
@@ -2119,11 +2294,11 @@ function parseReceipt(encoded, catalogue) {
|
|
|
2119
2294
|
if (fields.length !== RECEIPT_FIELDS.length) {
|
|
2120
2295
|
return void 0;
|
|
2121
2296
|
}
|
|
2122
|
-
const version = parseCanonicalField(
|
|
2123
|
-
const name = parseCanonicalField(
|
|
2124
|
-
const outcome = parseCanonicalField(
|
|
2125
|
-
const phase = parseCanonicalField(
|
|
2126
|
-
const effect = parseCanonicalField(
|
|
2297
|
+
const version = parseCanonicalField(fields[0] ?? "", "version");
|
|
2298
|
+
const name = parseCanonicalField(fields[1] ?? "", "name");
|
|
2299
|
+
const outcome = parseCanonicalField(fields[2] ?? "", "outcome");
|
|
2300
|
+
const phase = parseCanonicalField(fields[3] ?? "", "phase");
|
|
2301
|
+
const effect = parseCanonicalField(fields[4] ?? "", "effect");
|
|
2127
2302
|
const candidate = { version, name, outcome, phase, effect };
|
|
2128
2303
|
return isValidReceipt(candidate, catalogue) ? candidate : void 0;
|
|
2129
2304
|
}
|
|
@@ -2137,7 +2312,7 @@ function serializeSemanticJourneyReceipts(receipts, catalogue) {
|
|
|
2137
2312
|
throw new Error(SERIALIZE_ERROR_MESSAGE);
|
|
2138
2313
|
}
|
|
2139
2314
|
return header;
|
|
2140
|
-
} catch
|
|
2315
|
+
} catch {
|
|
2141
2316
|
throw new Error(SERIALIZE_ERROR_MESSAGE);
|
|
2142
2317
|
}
|
|
2143
2318
|
}
|
|
@@ -2162,7 +2337,7 @@ function parseSemanticJourneyReceipts(header, catalogue) {
|
|
|
2162
2337
|
receipts.push(receipt);
|
|
2163
2338
|
}
|
|
2164
2339
|
return receipts;
|
|
2165
|
-
} catch
|
|
2340
|
+
} catch {
|
|
2166
2341
|
return [];
|
|
2167
2342
|
}
|
|
2168
2343
|
}
|
|
@@ -2253,7 +2428,7 @@ function compareTokens(left, right) {
|
|
|
2253
2428
|
return 0;
|
|
2254
2429
|
}
|
|
2255
2430
|
function compareOptionalTokens(left, right) {
|
|
2256
|
-
return compareTokens(
|
|
2431
|
+
return compareTokens(left ?? "", right ?? "");
|
|
2257
2432
|
}
|
|
2258
2433
|
function compareEventsForOrder(left, right) {
|
|
2259
2434
|
const timestampComparison = left.occurredAtEpochMs - right.occurredAtEpochMs;
|
|
@@ -2294,11 +2469,11 @@ function compareEvidence(left, right) {
|
|
|
2294
2469
|
compareOptionalTokens(left.spanId, right.spanId),
|
|
2295
2470
|
compareOptionalTokens(left.producerId, right.producerId),
|
|
2296
2471
|
compareTokens(
|
|
2297
|
-
|
|
2298
|
-
|
|
2472
|
+
left.eventIds?.join(":") ?? "",
|
|
2473
|
+
right.eventIds?.join(":") ?? ""
|
|
2299
2474
|
)
|
|
2300
2475
|
];
|
|
2301
|
-
const tokenComparison =
|
|
2476
|
+
const tokenComparison = tokenComparisons.find((comparison) => comparison !== 0) ?? 0;
|
|
2302
2477
|
if (tokenComparison !== 0) {
|
|
2303
2478
|
return tokenComparison;
|
|
2304
2479
|
}
|
|
@@ -2309,7 +2484,7 @@ function compareEvidence(left, right) {
|
|
|
2309
2484
|
"observedCount"
|
|
2310
2485
|
];
|
|
2311
2486
|
for (const field2 of numericFields) {
|
|
2312
|
-
const comparison = (
|
|
2487
|
+
const comparison = (left[field2] ?? -1) - (right[field2] ?? -1);
|
|
2313
2488
|
if (comparison !== 0) {
|
|
2314
2489
|
return comparison;
|
|
2315
2490
|
}
|
|
@@ -2487,7 +2662,7 @@ function attributesEqual(left, right) {
|
|
|
2487
2662
|
);
|
|
2488
2663
|
}
|
|
2489
2664
|
function eventsEqual(left, right) {
|
|
2490
|
-
return left.schemaVersion === right.schemaVersion && left.eventId === right.eventId && left.journeyId === right.journeyId && left.traceId === right.traceId && left.spanId === right.spanId && left.parentSpanId === right.parentSpanId && left.causedByEventId === right.causedByEventId && left.producerId === right.producerId && left.producerSequence === right.producerSequence && left.occurredAtEpochMs === right.occurredAtEpochMs && left.source === right.source && left.channel === right.channel && left.runtime === right.runtime && left.name === right.name && left.category === right.category && left.phase === right.phase && left.outcome === right.outcome && left.modality === right.modality &&
|
|
2665
|
+
return left.schemaVersion === right.schemaVersion && left.eventId === right.eventId && left.journeyId === right.journeyId && left.traceId === right.traceId && left.spanId === right.spanId && left.parentSpanId === right.parentSpanId && left.causedByEventId === right.causedByEventId && left.producerId === right.producerId && left.producerSequence === right.producerSequence && left.occurredAtEpochMs === right.occurredAtEpochMs && left.source === right.source && left.channel === right.channel && left.runtime === right.runtime && left.name === right.name && left.category === right.category && left.phase === right.phase && left.outcome === right.outcome && left.modality === right.modality && left.target?.type === right.target?.type && left.target?.id === right.target?.id && left.privacy.mode === right.privacy.mode && left.privacy.policyVersion === right.privacy.policyVersion && left.privacy.droppedAttributeCount === right.privacy.droppedAttributeCount && attributesEqual(left.attributes, right.attributes);
|
|
2491
2666
|
}
|
|
2492
2667
|
function deduplicateEvents(events) {
|
|
2493
2668
|
const byEventId = /* @__PURE__ */ new Map();
|
|
@@ -2496,7 +2671,7 @@ function deduplicateEvents(events) {
|
|
|
2496
2671
|
if (existing && !eventsEqual(existing, event)) {
|
|
2497
2672
|
return invalidRuntimeEvidence();
|
|
2498
2673
|
}
|
|
2499
|
-
byEventId.set(event.eventId,
|
|
2674
|
+
byEventId.set(event.eventId, existing ?? event);
|
|
2500
2675
|
}
|
|
2501
2676
|
return [...byEventId.values()].sort(compareEventsForOrder);
|
|
2502
2677
|
}
|
|
@@ -2529,7 +2704,7 @@ function buildReferenceEdges(nodes, nodesByEventId, reconstructionEvidence, limi
|
|
|
2529
2704
|
spans = /* @__PURE__ */ new Map();
|
|
2530
2705
|
spansByTrace.set(node.event.traceId, spans);
|
|
2531
2706
|
}
|
|
2532
|
-
const spanNodes =
|
|
2707
|
+
const spanNodes = spans.get(node.event.spanId) ?? [];
|
|
2533
2708
|
addBoundedNode(spanNodes, node);
|
|
2534
2709
|
spans.set(node.event.spanId, spanNodes);
|
|
2535
2710
|
}
|
|
@@ -2556,7 +2731,7 @@ function buildReferenceEdges(nodes, nodesByEventId, reconstructionEvidence, limi
|
|
|
2556
2731
|
addEdge(node, node, limits);
|
|
2557
2732
|
continue;
|
|
2558
2733
|
}
|
|
2559
|
-
const parentCandidates =
|
|
2734
|
+
const parentCandidates = spansByTrace.get(event.traceId)?.get(event.parentSpanId);
|
|
2560
2735
|
if (!parentCandidates || parentCandidates.length === 0) {
|
|
2561
2736
|
appendEvidence(
|
|
2562
2737
|
reconstructionEvidence,
|
|
@@ -2587,7 +2762,7 @@ function buildProducerEdges(nodes, reconstructionEvidence, limits) {
|
|
|
2587
2762
|
sequences = /* @__PURE__ */ new Map();
|
|
2588
2763
|
producers.set(node.event.producerId, sequences);
|
|
2589
2764
|
}
|
|
2590
|
-
const sequenceNodes =
|
|
2765
|
+
const sequenceNodes = sequences.get(node.event.producerSequence) ?? [];
|
|
2591
2766
|
addBoundedNode(sequenceNodes, node);
|
|
2592
2767
|
sequences.set(node.event.producerSequence, sequenceNodes);
|
|
2593
2768
|
}
|
|
@@ -2598,7 +2773,7 @@ function buildProducerEdges(nodes, reconstructionEvidence, limits) {
|
|
|
2598
2773
|
const sequenceEntries = [...sequences.entries()].sort(
|
|
2599
2774
|
([left], [right]) => left - right
|
|
2600
2775
|
);
|
|
2601
|
-
const firstSequence =
|
|
2776
|
+
const firstSequence = sequenceEntries[0]?.[0];
|
|
2602
2777
|
if (firstSequence !== void 0 && firstSequence > 1) {
|
|
2603
2778
|
appendEvidence(
|
|
2604
2779
|
reconstructionEvidence,
|
|
@@ -2681,7 +2856,7 @@ function stronglyConnectedComponents(nodes, nodesByEventId) {
|
|
|
2681
2856
|
const stack = [
|
|
2682
2857
|
{
|
|
2683
2858
|
node: root,
|
|
2684
|
-
adjacent:
|
|
2859
|
+
adjacent: successors.get(root.event.eventId) ?? [],
|
|
2685
2860
|
next: 0
|
|
2686
2861
|
}
|
|
2687
2862
|
];
|
|
@@ -2697,7 +2872,7 @@ function stronglyConnectedComponents(nodes, nodesByEventId) {
|
|
|
2697
2872
|
visited.add(next.event.eventId);
|
|
2698
2873
|
stack.push({
|
|
2699
2874
|
node: next,
|
|
2700
|
-
adjacent:
|
|
2875
|
+
adjacent: successors.get(next.event.eventId) ?? [],
|
|
2701
2876
|
next: 0
|
|
2702
2877
|
});
|
|
2703
2878
|
}
|
|
@@ -2723,7 +2898,7 @@ function stronglyConnectedComponents(nodes, nodesByEventId) {
|
|
|
2723
2898
|
return invalidRuntimeEvidence();
|
|
2724
2899
|
}
|
|
2725
2900
|
members.push(current);
|
|
2726
|
-
const adjacentNodes =
|
|
2901
|
+
const adjacentNodes = predecessors.get(current.event.eventId) ?? [];
|
|
2727
2902
|
for (let adjacentIndex = adjacentNodes.length - 1; adjacentIndex >= 0; adjacentIndex -= 1) {
|
|
2728
2903
|
const predecessor = adjacentNodes[adjacentIndex];
|
|
2729
2904
|
if (predecessor && !assigned.has(predecessor.event.eventId)) {
|
|
@@ -2757,8 +2932,8 @@ function stronglyConnectedComponents(nodes, nodesByEventId) {
|
|
|
2757
2932
|
return invalidRuntimeEvidence();
|
|
2758
2933
|
}
|
|
2759
2934
|
if (fromIndex !== toIndex) {
|
|
2760
|
-
|
|
2761
|
-
|
|
2935
|
+
components[fromIndex]?.successors.add(toIndex);
|
|
2936
|
+
components[toIndex]?.predecessors.add(fromIndex);
|
|
2762
2937
|
}
|
|
2763
2938
|
}
|
|
2764
2939
|
}
|
|
@@ -2789,7 +2964,7 @@ function condensedCausalOrder(components) {
|
|
|
2789
2964
|
ordered.push(...current.nodes);
|
|
2790
2965
|
const successors = [...current.successors].map((index) => components[index]).filter((component) => component !== void 0).sort(compareComponents);
|
|
2791
2966
|
for (const successor of successors) {
|
|
2792
|
-
const remaining = (
|
|
2967
|
+
const remaining = (indegrees.get(successor.index) ?? 0) - 1;
|
|
2793
2968
|
indegrees.set(successor.index, remaining);
|
|
2794
2969
|
if (remaining === 0) {
|
|
2795
2970
|
ready.push(successor);
|
|
@@ -2919,7 +3094,7 @@ function reconstructSemanticJourneyUnsafe(catalogue, events) {
|
|
|
2919
3094
|
addCycleEvidence(components, reconstructionEvidence);
|
|
2920
3095
|
const ordered = condensedCausalOrder(components);
|
|
2921
3096
|
reconstructionEvidence.sort(compareEvidence);
|
|
2922
|
-
const journeyId =
|
|
3097
|
+
const journeyId = normalized[0]?.journeyId;
|
|
2923
3098
|
if (!journeyId) {
|
|
2924
3099
|
return invalidRuntimeEvidence();
|
|
2925
3100
|
}
|
|
@@ -3007,7 +3182,7 @@ function observeSemanticJourneyInteractions(config) {
|
|
|
3007
3182
|
if (config.enabled !== true) {
|
|
3008
3183
|
return () => void 0;
|
|
3009
3184
|
}
|
|
3010
|
-
const root =
|
|
3185
|
+
const root = config.root ?? (typeof document === "undefined" ? void 0 : document);
|
|
3011
3186
|
if (!root) {
|
|
3012
3187
|
return () => void 0;
|
|
3013
3188
|
}
|
|
@@ -3040,7 +3215,7 @@ function observeSemanticJourneyInteractions(config) {
|
|
|
3040
3215
|
try {
|
|
3041
3216
|
validateSemanticJourneyEventInput(config.catalogue, input);
|
|
3042
3217
|
config.onEvent(input);
|
|
3043
|
-
} catch
|
|
3218
|
+
} catch {
|
|
3044
3219
|
}
|
|
3045
3220
|
};
|
|
3046
3221
|
for (const eventType of OBSERVED_EVENT_TYPES) {
|
|
@@ -3088,7 +3263,7 @@ function invalidConfig() {
|
|
|
3088
3263
|
throw new Error("Semantic journey client configuration is invalid.");
|
|
3089
3264
|
}
|
|
3090
3265
|
function resolveInteger(value, fallback, minimum, maximum) {
|
|
3091
|
-
const resolved =
|
|
3266
|
+
const resolved = value ?? fallback;
|
|
3092
3267
|
if (!Number.isSafeInteger(resolved) || resolved < minimum || resolved > maximum) {
|
|
3093
3268
|
return invalidConfig();
|
|
3094
3269
|
}
|
|
@@ -3101,7 +3276,7 @@ function resolveRuntime2(runtime) {
|
|
|
3101
3276
|
return typeof window === "undefined" ? "server" : "browser";
|
|
3102
3277
|
}
|
|
3103
3278
|
function resolveChannel2(channel, runtime) {
|
|
3104
|
-
return
|
|
3279
|
+
return channel ?? (runtime === "server" ? "backend" : "frontend");
|
|
3105
3280
|
}
|
|
3106
3281
|
function defaultRetryDelay(delayMs, signal) {
|
|
3107
3282
|
if (signal.aborted) {
|
|
@@ -3150,13 +3325,13 @@ function resolveConfig2(config) {
|
|
|
3150
3325
|
source: config.source,
|
|
3151
3326
|
channel: resolveChannel2(config.channel, runtime),
|
|
3152
3327
|
runtime,
|
|
3153
|
-
enabled:
|
|
3328
|
+
enabled: config.enabled ?? false,
|
|
3154
3329
|
...config.aggregateEndpoint ? { aggregateEndpoint: config.aggregateEndpoint } : {},
|
|
3155
|
-
aggregateTransport:
|
|
3330
|
+
aggregateTransport: config.aggregateTransport ?? createDefaultSemanticJourneyAggregateTransport({
|
|
3156
3331
|
...config.aggregateBaseUrl ? { baseUrl: config.aggregateBaseUrl } : {},
|
|
3157
3332
|
...config.now ? { now: config.now } : {}
|
|
3158
|
-
})
|
|
3159
|
-
autoFlush:
|
|
3333
|
+
}),
|
|
3334
|
+
autoFlush: config.autoFlush ?? true,
|
|
3160
3335
|
aggregateFlushIntervalMs: resolveInteger(
|
|
3161
3336
|
config.aggregateFlushIntervalMs,
|
|
3162
3337
|
DEFAULT_AGGREGATE_FLUSH_INTERVAL_MS,
|
|
@@ -3226,8 +3401,8 @@ function resolveConfig2(config) {
|
|
|
3226
3401
|
retryBaseDelayMs,
|
|
3227
3402
|
retryMaxDelayMs,
|
|
3228
3403
|
...config.randomBytes ? { randomBytes: config.randomBytes } : {},
|
|
3229
|
-
now:
|
|
3230
|
-
retryDelay:
|
|
3404
|
+
now: config.now ?? (() => Date.now()),
|
|
3405
|
+
retryDelay: config.retryDelay ?? defaultRetryDelay,
|
|
3231
3406
|
...config.onDrop ? { onDrop: config.onDrop } : {}
|
|
3232
3407
|
};
|
|
3233
3408
|
}
|
|
@@ -3243,7 +3418,7 @@ function eventBytes(event) {
|
|
|
3243
3418
|
return textEncoder2.encode(JSON.stringify(event)).byteLength;
|
|
3244
3419
|
}
|
|
3245
3420
|
function sameTarget(left, right) {
|
|
3246
|
-
return
|
|
3421
|
+
return left?.type === right?.type && left?.id === right?.id;
|
|
3247
3422
|
}
|
|
3248
3423
|
function shouldCoalesce(previous, next, windowMs) {
|
|
3249
3424
|
return Boolean(
|
|
@@ -3259,7 +3434,7 @@ function jitteredDelay(attempt, config) {
|
|
|
3259
3434
|
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== 2) {
|
|
3260
3435
|
throw new Error("Semantic journey retry random source is invalid.");
|
|
3261
3436
|
}
|
|
3262
|
-
const sample = (
|
|
3437
|
+
const sample = (bytes[0] ?? 0) << 8 | (bytes[1] ?? 0);
|
|
3263
3438
|
const factor = 0.5 + sample / 65535;
|
|
3264
3439
|
return Math.min(config.retryMaxDelayMs, Math.max(1, Math.round(exponential * factor)));
|
|
3265
3440
|
}
|
|
@@ -3267,7 +3442,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3267
3442
|
let config;
|
|
3268
3443
|
try {
|
|
3269
3444
|
config = resolveConfig2(inputConfig);
|
|
3270
|
-
} catch
|
|
3445
|
+
} catch {
|
|
3271
3446
|
return invalidConfig();
|
|
3272
3447
|
}
|
|
3273
3448
|
const aggregateStore = new SemanticJourneyAggregateStore({
|
|
@@ -3289,8 +3464,8 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3289
3464
|
let interval;
|
|
3290
3465
|
const notifyDrop = (reason) => {
|
|
3291
3466
|
try {
|
|
3292
|
-
|
|
3293
|
-
} catch
|
|
3467
|
+
config.onDrop?.(reason);
|
|
3468
|
+
} catch {
|
|
3294
3469
|
}
|
|
3295
3470
|
};
|
|
3296
3471
|
const newEpisode = (nowEpochMs) => ({
|
|
@@ -3341,7 +3516,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3341
3516
|
}
|
|
3342
3517
|
const usesLocalProducer = options.producerId === void 0;
|
|
3343
3518
|
const producerSequence = usesLocalProducer ? currentEpisode.producerSequence + 1 : options.producerSequence;
|
|
3344
|
-
if (!Number.isSafeInteger(producerSequence) || (
|
|
3519
|
+
if (!Number.isSafeInteger(producerSequence) || (producerSequence ?? 0) < 1) {
|
|
3345
3520
|
notifyDrop("invalid");
|
|
3346
3521
|
return void 0;
|
|
3347
3522
|
}
|
|
@@ -3353,12 +3528,12 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3353
3528
|
spanId: options.context.spanId,
|
|
3354
3529
|
...options.context.parentSpanId ? { parentSpanId: options.context.parentSpanId } : {},
|
|
3355
3530
|
...options.causedByEventId ? { causedByEventId: options.causedByEventId } : {},
|
|
3356
|
-
producerId:
|
|
3531
|
+
producerId: options.producerId ?? currentEpisode.producerId,
|
|
3357
3532
|
producerSequence,
|
|
3358
3533
|
occurredAtEpochMs: nowEpochMs,
|
|
3359
|
-
source:
|
|
3360
|
-
channel:
|
|
3361
|
-
runtime:
|
|
3534
|
+
source: options.source ?? config.source,
|
|
3535
|
+
channel: options.channel ?? config.channel,
|
|
3536
|
+
runtime: options.runtime ?? config.runtime,
|
|
3362
3537
|
name: validated.name,
|
|
3363
3538
|
category: validated.category,
|
|
3364
3539
|
phase: validated.phase,
|
|
@@ -3374,7 +3549,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3374
3549
|
});
|
|
3375
3550
|
aggregateStore.record(event.name, event.outcome);
|
|
3376
3551
|
if (shouldCoalesce(
|
|
3377
|
-
|
|
3552
|
+
queue[queue.length - 1]?.event,
|
|
3378
3553
|
event,
|
|
3379
3554
|
config.coalesceWindowMs
|
|
3380
3555
|
)) {
|
|
@@ -3401,7 +3576,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3401
3576
|
const validateInput = (input) => {
|
|
3402
3577
|
try {
|
|
3403
3578
|
return validateSemanticJourneyEventInput(config.catalogue, input);
|
|
3404
|
-
} catch
|
|
3579
|
+
} catch {
|
|
3405
3580
|
notifyDrop("invalid");
|
|
3406
3581
|
return void 0;
|
|
3407
3582
|
}
|
|
@@ -3416,7 +3591,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3416
3591
|
const causeContext = causedByEventId ? contextByEventId.get(causedByEventId) : void 0;
|
|
3417
3592
|
if (request) {
|
|
3418
3593
|
return createRequestJourneyContext(
|
|
3419
|
-
|
|
3594
|
+
causeContext ?? currentEpisode.root,
|
|
3420
3595
|
config.randomBytes
|
|
3421
3596
|
);
|
|
3422
3597
|
}
|
|
@@ -3454,7 +3629,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3454
3629
|
},
|
|
3455
3630
|
nowEpochMs
|
|
3456
3631
|
);
|
|
3457
|
-
} catch
|
|
3632
|
+
} catch {
|
|
3458
3633
|
notifyDrop("invalid");
|
|
3459
3634
|
return void 0;
|
|
3460
3635
|
}
|
|
@@ -3564,13 +3739,13 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3564
3739
|
added.push(consequence);
|
|
3565
3740
|
}
|
|
3566
3741
|
return added;
|
|
3567
|
-
} catch
|
|
3742
|
+
} catch {
|
|
3568
3743
|
notifyDrop("invalid");
|
|
3569
3744
|
return [];
|
|
3570
3745
|
}
|
|
3571
3746
|
}
|
|
3572
3747
|
});
|
|
3573
|
-
} catch
|
|
3748
|
+
} catch {
|
|
3574
3749
|
notifyDrop("invalid");
|
|
3575
3750
|
return void 0;
|
|
3576
3751
|
}
|
|
@@ -3645,11 +3820,11 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3645
3820
|
if (attempt >= config.maxRetries) {
|
|
3646
3821
|
return "retained";
|
|
3647
3822
|
}
|
|
3648
|
-
const retryAfterMs =
|
|
3823
|
+
const retryAfterMs = transportError?.retryAfterMs;
|
|
3649
3824
|
const delayMs = retryAfterMs === void 0 ? jitteredDelay(attempt, config) : Math.min(config.retryMaxDelayMs, Math.max(0, retryAfterMs));
|
|
3650
3825
|
try {
|
|
3651
3826
|
await config.retryDelay(delayMs, signal);
|
|
3652
|
-
} catch
|
|
3827
|
+
} catch {
|
|
3653
3828
|
return "retained";
|
|
3654
3829
|
}
|
|
3655
3830
|
}
|
|
@@ -3663,12 +3838,12 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3663
3838
|
const generation = aggregateGeneration;
|
|
3664
3839
|
const signal = aggregateController.signal;
|
|
3665
3840
|
for (let sentBatchCount = 0; sentBatchCount < config.maxBatchesPerFlush; sentBatchCount += 1) {
|
|
3666
|
-
const batch =
|
|
3841
|
+
const batch = pendingBatch ?? aggregateStore.createBatch({
|
|
3667
3842
|
batchId: createEventId(config.randomBytes),
|
|
3668
3843
|
nowEpochMs: config.now(),
|
|
3669
3844
|
maxCounters: config.aggregateMaxCounters,
|
|
3670
3845
|
maxBytes: config.aggregateMaxBytes
|
|
3671
|
-
})
|
|
3846
|
+
});
|
|
3672
3847
|
if (!batch) {
|
|
3673
3848
|
return;
|
|
3674
3849
|
}
|
|
@@ -3701,7 +3876,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3701
3876
|
try {
|
|
3702
3877
|
pruneExpired(config.now());
|
|
3703
3878
|
return queue.map(({ event }) => copyEvent(event));
|
|
3704
|
-
} catch
|
|
3879
|
+
} catch {
|
|
3705
3880
|
return [];
|
|
3706
3881
|
}
|
|
3707
3882
|
};
|
|
@@ -3719,7 +3894,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3719
3894
|
aggregateGeneration += 1;
|
|
3720
3895
|
aggregateController.abort();
|
|
3721
3896
|
aggregateController = new AbortController();
|
|
3722
|
-
|
|
3897
|
+
activeTransportController?.abort();
|
|
3723
3898
|
pendingBatch = void 0;
|
|
3724
3899
|
clearLocalQueue();
|
|
3725
3900
|
aggregateStore.clear();
|
|
@@ -3755,7 +3930,7 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3755
3930
|
destroyed = true;
|
|
3756
3931
|
aggregateGeneration += 1;
|
|
3757
3932
|
aggregateController.abort();
|
|
3758
|
-
|
|
3933
|
+
activeTransportController?.abort();
|
|
3759
3934
|
pendingBatch = void 0;
|
|
3760
3935
|
if (interval !== void 0) {
|
|
3761
3936
|
globalThis.clearInterval(interval);
|
|
@@ -3787,9 +3962,9 @@ function createSemanticJourneyClient(inputConfig) {
|
|
|
3787
3962
|
}
|
|
3788
3963
|
|
|
3789
3964
|
// src/react/provider.tsx
|
|
3790
|
-
var
|
|
3791
|
-
var
|
|
3792
|
-
var AnalyticsContext =
|
|
3965
|
+
var import_react = require("react");
|
|
3966
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3967
|
+
var AnalyticsContext = (0, import_react.createContext)(null);
|
|
3793
3968
|
function AnalyticsProvider({
|
|
3794
3969
|
children,
|
|
3795
3970
|
source = "react-app",
|
|
@@ -3809,7 +3984,7 @@ function AnalyticsProvider({
|
|
|
3809
3984
|
onError,
|
|
3810
3985
|
client
|
|
3811
3986
|
}) {
|
|
3812
|
-
const managedClient =
|
|
3987
|
+
const managedClient = (0, import_react.useMemo)(() => {
|
|
3813
3988
|
if (client) {
|
|
3814
3989
|
return client;
|
|
3815
3990
|
}
|
|
@@ -3851,14 +4026,14 @@ function AnalyticsProvider({
|
|
|
3851
4026
|
transport,
|
|
3852
4027
|
onError
|
|
3853
4028
|
]);
|
|
3854
|
-
|
|
4029
|
+
(0, import_react.useEffect)(() => {
|
|
3855
4030
|
return () => {
|
|
3856
4031
|
if (!client) {
|
|
3857
4032
|
managedClient.destroy();
|
|
3858
4033
|
}
|
|
3859
4034
|
};
|
|
3860
4035
|
}, [client, managedClient]);
|
|
3861
|
-
const value =
|
|
4036
|
+
const value = (0, import_react.useMemo)(
|
|
3862
4037
|
() => ({
|
|
3863
4038
|
client: managedClient,
|
|
3864
4039
|
trackInteraction: (event) => {
|
|
@@ -3868,10 +4043,10 @@ function AnalyticsProvider({
|
|
|
3868
4043
|
}),
|
|
3869
4044
|
[managedClient]
|
|
3870
4045
|
);
|
|
3871
|
-
return /* @__PURE__ */
|
|
4046
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnalyticsContext.Provider, { value, children });
|
|
3872
4047
|
}
|
|
3873
4048
|
function useAnalytics() {
|
|
3874
|
-
const context =
|
|
4049
|
+
const context = (0, import_react.useContext)(AnalyticsContext);
|
|
3875
4050
|
if (!context) {
|
|
3876
4051
|
throw new Error("useAnalytics must be used within AnalyticsProvider.");
|
|
3877
4052
|
}
|
|
@@ -3879,79 +4054,80 @@ function useAnalytics() {
|
|
|
3879
4054
|
}
|
|
3880
4055
|
|
|
3881
4056
|
// src/react/hooks.ts
|
|
3882
|
-
|
|
4057
|
+
var import_react2 = require("react");
|
|
3883
4058
|
function useComponentInteractionTracker(component, baseContext = {}) {
|
|
3884
4059
|
const { trackInteraction } = useAnalytics();
|
|
3885
|
-
return
|
|
4060
|
+
return (0, import_react2.useCallback)(
|
|
3886
4061
|
(action, details) => {
|
|
3887
4062
|
trackInteraction({
|
|
3888
4063
|
component,
|
|
3889
4064
|
action,
|
|
3890
|
-
channel:
|
|
3891
|
-
label:
|
|
3892
|
-
href:
|
|
3893
|
-
variant:
|
|
3894
|
-
requestId:
|
|
3895
|
-
timestamp:
|
|
4065
|
+
channel: details?.channel,
|
|
4066
|
+
label: details?.label,
|
|
4067
|
+
href: details?.href,
|
|
4068
|
+
variant: details?.variant,
|
|
4069
|
+
requestId: details?.requestId,
|
|
4070
|
+
timestamp: details?.timestamp,
|
|
3896
4071
|
context: {
|
|
3897
4072
|
...baseContext,
|
|
3898
|
-
...
|
|
4073
|
+
...details?.context ?? {}
|
|
3899
4074
|
}
|
|
3900
4075
|
});
|
|
3901
4076
|
},
|
|
3902
4077
|
[baseContext, component, trackInteraction]
|
|
3903
4078
|
);
|
|
3904
4079
|
}
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
4080
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4081
|
+
0 && (module.exports = {
|
|
4082
|
+
AnalyticsProvider,
|
|
4083
|
+
SEMANTIC_JOURNEY_AGGREGATE_SCHEMA_VERSION,
|
|
4084
|
+
SEMANTIC_JOURNEY_RECEIPT_HEADER,
|
|
4085
|
+
SEMANTIC_JOURNEY_RECEIPT_MAX_BYTES,
|
|
4086
|
+
SEMANTIC_JOURNEY_RECEIPT_MAX_COUNT,
|
|
4087
|
+
SEMANTIC_JOURNEY_RECEIPT_VERSION,
|
|
4088
|
+
SEMANTIC_JOURNEY_STRICT_POLICY_VERSION,
|
|
4089
|
+
SemanticJourneyAggregateStore,
|
|
4090
|
+
SemanticJourneyTransportError,
|
|
4091
|
+
SemanticJourneyValidationError,
|
|
4092
|
+
USEFUL_METRIC_EVENT_DEFINITIONS,
|
|
4093
|
+
assertSemanticSource,
|
|
4094
|
+
assertSemanticToken,
|
|
4095
|
+
createBackendAnalyticsClient,
|
|
4096
|
+
createChildJourneyContext,
|
|
4097
|
+
createDefaultSemanticJourneyAggregateTransport,
|
|
4098
|
+
createEventId,
|
|
4099
|
+
createFrontendAnalyticsClient,
|
|
4100
|
+
createJourneyContext,
|
|
4101
|
+
createJourneyId,
|
|
4102
|
+
createLocalSpaceAnalyticsClient,
|
|
4103
|
+
createNoopLocalSpaceAnalyticsClient,
|
|
4104
|
+
createProducerId,
|
|
4105
|
+
createRequestJourneyContext,
|
|
4106
|
+
createSecureRandomHex,
|
|
4107
|
+
createSemanticJourneyClient,
|
|
4108
|
+
createSpanId,
|
|
4109
|
+
createTraceId,
|
|
4110
|
+
defineJourneyEvent,
|
|
4111
|
+
defineSemanticJourneyCatalog,
|
|
4112
|
+
formatTraceparent,
|
|
4113
|
+
getJourneyEventDefinition,
|
|
4114
|
+
isEventId,
|
|
4115
|
+
isJourneyId,
|
|
4116
|
+
isJourneyToken,
|
|
4117
|
+
isProducerId,
|
|
4118
|
+
isSecureSemanticJourneyEndpoint,
|
|
4119
|
+
isSemanticSource,
|
|
4120
|
+
isSemanticToken,
|
|
4121
|
+
isSpanId,
|
|
4122
|
+
isTraceId,
|
|
4123
|
+
observeSemanticJourneyInteractions,
|
|
4124
|
+
parseSemanticJourneyReceipts,
|
|
4125
|
+
parseTraceparent,
|
|
4126
|
+
projectUsefulMetric,
|
|
4127
|
+
reconstructSemanticJourney,
|
|
4128
|
+
serializeSemanticJourneyReceipts,
|
|
4129
|
+
useAnalytics,
|
|
4130
|
+
useComponentInteractionTracker,
|
|
4131
|
+
validateSemanticJourneyEventInput
|
|
4132
|
+
});
|
|
3957
4133
|
//# sourceMappingURL=index.cjs.map
|