@kya-os/checkpoint-shared 1.5.0 → 1.5.2
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/CHANGELOG.md +129 -0
- package/dist/beacon-nonce/index.d.mts +36 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -0
- package/dist/beacon-nonce/index.d.ts +36 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -0
- package/dist/beacon-nonce/index.js +305 -0
- package/dist/beacon-nonce/index.mjs +294 -0
- package/dist/beacon-nonce/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +50 -14
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +50 -14
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +127 -8
- package/dist/beacon-types/index.mjs +122 -9
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/browser-posture-D4j2a5gi.d.ts +169 -0
- package/dist/browser-posture-D4j2a5gi.d.ts.map +1 -0
- package/dist/browser-posture-DVoHMHjY.d.mts +169 -0
- package/dist/browser-posture-DVoHMHjY.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +4 -2
- package/dist/browser-posture-cookie.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.ts +4 -2
- package/dist/browser-posture-cookie.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof.d.mts +18 -0
- package/dist/browser-posture-proof.d.mts.map +1 -0
- package/dist/browser-posture-proof.d.ts +18 -0
- package/dist/browser-posture-proof.d.ts.map +1 -0
- package/dist/browser-posture-proof.js +66 -0
- package/dist/browser-posture-proof.mjs +63 -0
- package/dist/browser-posture-proof.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +59 -2
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +59 -2
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +1 -1
- package/dist/browser-posture-report.mjs.map +1 -1
- package/dist/browser-posture.d.mts +2 -83
- package/dist/browser-posture.d.ts +2 -83
- package/dist/browser-posture.js +214 -44
- package/dist/browser-posture.mjs +203 -45
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +3 -11
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +3 -11
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/{client-ip-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
- package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
- package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
- package/dist/consent-handoff.d.mts +41 -0
- package/dist/consent-handoff.d.mts.map +1 -0
- package/dist/consent-handoff.d.ts +41 -0
- package/dist/consent-handoff.d.ts.map +1 -0
- package/dist/consent-handoff.js +1 -0
- package/dist/consent-handoff.mjs +2 -0
- package/dist/consent-handoff.mjs.map +1 -0
- package/dist/errors/index.d.mts +138 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +138 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +441 -9
- package/dist/errors/index.mjs +441 -10
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-jr_S4iSS.d.mts → external-Ct8j_hto.d.mts} +2 -2
- package/dist/{external-jr_S4iSS.d.mts.map → external-Ct8j_hto.d.mts.map} +1 -1
- package/dist/{external-jr_S4iSS.d.ts → external-Ct8j_hto.d.ts} +2 -2
- package/dist/{external-jr_S4iSS.d.ts.map → external-Ct8j_hto.d.ts.map} +1 -1
- package/dist/gateway-client-ip.d.mts +1 -1
- package/dist/gateway-client-ip.d.ts +1 -1
- package/dist/gateway-client-ip.js +1 -1
- package/dist/gateway-client-ip.mjs +1 -1
- package/dist/index.d.mts +5227 -1063
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +5227 -1063
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3678 -546
- package/dist/index.mjs +3446 -534
- package/dist/index.mjs.map +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +1 -1
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
- package/dist/mcpi/approval-grant/index.d.ts +1 -1
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
- package/dist/mcpi/approval-grant/index.js +48 -48
- package/dist/mcpi/approval-grant/index.mjs +48 -48
- package/dist/mcpi/approval-grant/index.mjs.map +1 -1
- package/dist/posture-origins/index.d.mts +41 -0
- package/dist/posture-origins/index.d.mts.map +1 -0
- package/dist/posture-origins/index.d.ts +41 -0
- package/dist/posture-origins/index.d.ts.map +1 -0
- package/dist/posture-origins/index.js +441 -0
- package/dist/posture-origins/index.mjs +430 -0
- package/dist/posture-origins/index.mjs.map +1 -0
- package/dist/posture-origins-CEm83u4D.js +621 -0
- package/dist/posture-origins-Dl7i8j93.mjs +533 -0
- package/dist/posture-origins-Dl7i8j93.mjs.map +1 -0
- package/dist/rules.json +0 -1
- package/dist/signals/index.d.mts +75 -55
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts +75 -55
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +246 -2
- package/dist/signals/index.mjs +236 -3
- package/dist/signals/index.mjs.map +1 -1
- package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
- package/fixtures/browser-integrity/null-score.json +11 -0
- package/fixtures/browser-integrity/numeric-score.json +11 -0
- package/fixtures/browser-posture-claims.json +168 -0
- package/fixtures/browser-posture-headers.json +6 -0
- package/fixtures/kya-http/README.md +1 -0
- package/fixtures/kya-http/consent-handoff.codes.json +34 -0
- package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
- package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
- package/fixtures/workbench/delegation-management.v1.json +507 -0
- package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
- package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
- package/fixtures/workbench/identity-provisioning.v1.json +643 -0
- package/fixtures/workbench/linear-installation.v1.json +484 -0
- package/fixtures/workbench/management-session.v1.json +716 -0
- package/fixtures/workbench/model-credentials.v1.json +630 -0
- package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
- package/fixtures/workbench/task-grant.v1.json +695 -0
- package/fixtures/workbench/task-status-projection.v1.json +591 -0
- package/fixtures/workbench/workload-enrollment.v1.json +580 -0
- package/package.json +21 -2
- package/src/data/compiled/merged-rules.json +2 -9
- package/src/data/default-rules.json +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
- package/dist/browser-posture.d.mts.map +0 -1
- package/dist/browser-posture.d.ts.map +0 -1
- package/dist/patterns-CkRVOdtV.js +0 -243
- package/dist/patterns-DzkGy_qk.mjs +0 -173
- package/dist/patterns-DzkGy_qk.mjs.map +0 -1
|
@@ -9,6 +9,77 @@ function toRecord(input) {
|
|
|
9
9
|
function numberOr(value, fallback) {
|
|
10
10
|
return typeof value === "number" && Number.isFinite(value) && value !== 0 ? value : fallback;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Validates a numeric config value against `ok`, falling back to `fallback`
|
|
14
|
+
* when it fails. Only calls `onReject` when the caller actually supplied a
|
|
15
|
+
* value (an `undefined` field, the common case, is not a rejection, it just
|
|
16
|
+
* never overrode the default): H0BB5 (PR #5095 review, item 4) — a rejected
|
|
17
|
+
* value used to fall back silently, with no way for a host to discover a
|
|
18
|
+
* config typo.
|
|
19
|
+
*/
|
|
20
|
+
function boundedNumberOr(value, fallback, ok, onReject) {
|
|
21
|
+
if (typeof value === "number" && Number.isFinite(value) && ok(value)) return value;
|
|
22
|
+
if (value !== void 0) onReject?.(value);
|
|
23
|
+
return fallback;
|
|
24
|
+
}
|
|
25
|
+
/** Same as `boundedNumberOr`, but an absent/rejected value stays `undefined` rather than defaulting. */
|
|
26
|
+
function optionalPositiveNumber(value, onReject) {
|
|
27
|
+
if (value === void 0) return void 0;
|
|
28
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
29
|
+
onReject?.(value);
|
|
30
|
+
}
|
|
31
|
+
/** Same as `optionalPositiveNumber`, without the positivity requirement (a jitter seed may be any finite number). */
|
|
32
|
+
function optionalFiniteNumber(value, onReject) {
|
|
33
|
+
if (value === void 0) return void 0;
|
|
34
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
35
|
+
onReject?.(value);
|
|
36
|
+
}
|
|
37
|
+
/** Same shape as `boundedNumberOr`/`optionalPositiveNumber`, for a boolean config flag. */
|
|
38
|
+
function booleanOr(value, fallback, onReject) {
|
|
39
|
+
if (value === void 0) return fallback;
|
|
40
|
+
if (typeof value === "boolean") return value;
|
|
41
|
+
onReject?.(value);
|
|
42
|
+
return fallback;
|
|
43
|
+
}
|
|
44
|
+
/** Ingest's own `sessionId` bound (1-255), limited to characters a cookie value carries unescaped. */
|
|
45
|
+
const RESUMABLE_SESSION_ID = /^[A-Za-z0-9._~-]{1,255}$/;
|
|
46
|
+
function resumableSessionId(value, onReject) {
|
|
47
|
+
if (value === void 0) return void 0;
|
|
48
|
+
if (typeof value === "string" && RESUMABLE_SESSION_ID.test(value)) return value;
|
|
49
|
+
onReject?.(value);
|
|
50
|
+
}
|
|
51
|
+
function receiptCallback(value, onReject) {
|
|
52
|
+
if (value === void 0) return void 0;
|
|
53
|
+
if (typeof value === "function") return value;
|
|
54
|
+
onReject?.(value);
|
|
55
|
+
}
|
|
56
|
+
const DISPATCH_TRIGGER_NAMES = [
|
|
57
|
+
"arrival",
|
|
58
|
+
"signals",
|
|
59
|
+
"interaction",
|
|
60
|
+
"untrusted",
|
|
61
|
+
"posture",
|
|
62
|
+
"unload",
|
|
63
|
+
"navigation"
|
|
64
|
+
];
|
|
65
|
+
/**
|
|
66
|
+
* Keeps only the known trigger names with a real boolean; anything else is
|
|
67
|
+
* dropped and, when the caller actually named a known trigger with a
|
|
68
|
+
* non-boolean value (`triggers: { posture: 0 }`, say), reported through
|
|
69
|
+
* `onReject` — H0BB5 (PR #5095 review, item 4): a numeric `0` used to be
|
|
70
|
+
* dropped silently and that trigger stayed at its default-enabled state,
|
|
71
|
+
* the opposite of what the "0 is falsy" convention suggests.
|
|
72
|
+
*/
|
|
73
|
+
function pickTriggers(value, onReject) {
|
|
74
|
+
if (!isRecord(value)) return void 0;
|
|
75
|
+
const picked = {};
|
|
76
|
+
for (const name of DISPATCH_TRIGGER_NAMES) {
|
|
77
|
+
const raw = value[name];
|
|
78
|
+
if (typeof raw === "boolean") picked[name] = raw;
|
|
79
|
+
else if (raw !== void 0) onReject?.(name, raw);
|
|
80
|
+
}
|
|
81
|
+
return picked;
|
|
82
|
+
}
|
|
12
83
|
function stringOr(value, fallback) {
|
|
13
84
|
return typeof value === "string" ? value : fallback;
|
|
14
85
|
}
|
|
@@ -86,7 +157,7 @@ function parseOfflineQueueEntry(input) {
|
|
|
86
157
|
if (!isRecord(input)) throw new Error("Invalid offline queue entry");
|
|
87
158
|
const entry = input;
|
|
88
159
|
return {
|
|
89
|
-
id: stringOr(entry.id, `${Date.now()}_${
|
|
160
|
+
id: stringOr(entry.id, `${Date.now()}_${Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(6)), (byte) => byte.toString(16).padStart(2, "0")).join("")}`),
|
|
90
161
|
events: Array.isArray(entry.events) ? entry.events : [],
|
|
91
162
|
timestamp: numberOr(entry.timestamp, Date.now()),
|
|
92
163
|
expiresAt: numberOr(entry.expiresAt, Date.now() + 864e5),
|
|
@@ -94,10 +165,17 @@ function parseOfflineQueueEntry(input) {
|
|
|
94
165
|
size: numberOr(entry.size, 0)
|
|
95
166
|
};
|
|
96
167
|
}
|
|
168
|
+
function randomId() {
|
|
169
|
+
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
170
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
171
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
172
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
173
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
174
|
+
}
|
|
97
175
|
function parseBeaconWorkerMessage(input) {
|
|
98
176
|
if (!isRecord(input)) throw new Error("Invalid beacon worker message");
|
|
99
177
|
const msg = input;
|
|
100
|
-
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ??
|
|
178
|
+
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ?? randomId();
|
|
101
179
|
return {
|
|
102
180
|
type: isBeaconWorkerMessageType(msg.type) ? msg.type : "init",
|
|
103
181
|
data: msg.data,
|
|
@@ -120,7 +198,7 @@ function parseWorkerMessage(input) {
|
|
|
120
198
|
const msg = input && typeof input === "object" ? input : null;
|
|
121
199
|
if (!msg) throw new Error("Invalid worker message");
|
|
122
200
|
return {
|
|
123
|
-
id: msg.id ||
|
|
201
|
+
id: msg.id || randomId(),
|
|
124
202
|
type: isWorkerMessageType(msg.type) ? msg.type : "request",
|
|
125
203
|
action: msg.action,
|
|
126
204
|
payload: msg.payload,
|
|
@@ -203,7 +281,14 @@ function parseWorkerCapabilities(input) {
|
|
|
203
281
|
}
|
|
204
282
|
};
|
|
205
283
|
}
|
|
206
|
-
|
|
284
|
+
/**
|
|
285
|
+
* @param onWarn Called once per rejected config value (a supplied value that
|
|
286
|
+
* failed validation and fell back to its default), for a caller that wants
|
|
287
|
+
* to surface it — `BeaconConfigManager.validateAndMergeConfig` wires this to
|
|
288
|
+
* `log('warn', ...)`. Never called for an omitted field; only for one the
|
|
289
|
+
* caller actually set to something invalid.
|
|
290
|
+
*/
|
|
291
|
+
function parseBeaconConfig(input, onWarn) {
|
|
207
292
|
const config = toRecord(input);
|
|
208
293
|
if (typeof config.projectId !== "string" || config.projectId.length === 0) throw new Error("Project ID is required");
|
|
209
294
|
return {
|
|
@@ -216,15 +301,21 @@ function parseBeaconConfig(input) {
|
|
|
216
301
|
debug: config.debug === true,
|
|
217
302
|
logLevel: isLogLevel(config.logLevel) ? config.logLevel : "error",
|
|
218
303
|
respectDoNotTrack: config.respectDoNotTrack !== false,
|
|
304
|
+
requireConsent: config.requireConsent === true,
|
|
219
305
|
anonymizeIp: config.anonymizeIp === true,
|
|
220
306
|
stripUrlFragment: config.stripUrlFragment !== false,
|
|
221
307
|
scrubQueryParams: isStringArray(config.scrubQueryParams) ? config.scrubQueryParams : void 0,
|
|
222
308
|
dropQueryParams: config.dropQueryParams === true,
|
|
223
|
-
sessionTimeout: numberOr(config.sessionTimeout,
|
|
309
|
+
sessionTimeout: numberOr(config.sessionTimeout, void 0),
|
|
224
310
|
sessionCookieName: stringOr(config.sessionCookieName, "_as_beacon_session"),
|
|
225
|
-
|
|
226
|
-
|
|
311
|
+
browserSessionId: resumableSessionId(config.browserSessionId, (received) => onWarn?.(`browserSessionId must match ${RESUMABLE_SESSION_ID} (received ${JSON.stringify(received)}); ignoring it`)),
|
|
312
|
+
onReceipt: receiptCallback(config.onReceipt, (received) => onWarn?.(`onReceipt must be a function (received ${typeof received}); ignoring it`)),
|
|
313
|
+
batchSize: typeof config.batchSize === "number" ? config.batchSize : void 0,
|
|
314
|
+
flushInterval: typeof config.flushInterval === "number" ? config.flushInterval : void 0,
|
|
227
315
|
collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
|
|
316
|
+
evidenceGrowthFactor: boundedNumberOr(config.evidenceGrowthFactor, 2, (n) => n > 1, (received) => onWarn?.(`evidenceGrowthFactor must be a number greater than 1 (received ${JSON.stringify(received)}); using default 2`)),
|
|
317
|
+
postureRefreshFraction: boundedNumberOr(config.postureRefreshFraction, .5, (n) => n > 0 && n <= 1, (received) => onWarn?.(`postureRefreshFraction must be a number in (0, 1] (received ${JSON.stringify(received)}); using default 0.5`)),
|
|
318
|
+
triggers: pickTriggers(config.triggers, (name, received) => onWarn?.(`triggers.${name} must be a boolean (received ${JSON.stringify(received)}); ignoring it and keeping its default`)),
|
|
228
319
|
maxQueueSize: numberOr(config.maxQueueSize, 100),
|
|
229
320
|
retryAttempts: numberOr(config.retryAttempts, 3),
|
|
230
321
|
retryDelay: numberOr(config.retryDelay, 2e3),
|
|
@@ -232,12 +323,40 @@ function parseBeaconConfig(input) {
|
|
|
232
323
|
useWorker: resolveUseWorker(config),
|
|
233
324
|
workerUrl: stringOr(config.workerUrl),
|
|
234
325
|
workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
|
|
235
|
-
lazySignalsUrl: stringOr(config.lazySignalsUrl)
|
|
326
|
+
lazySignalsUrl: stringOr(config.lazySignalsUrl),
|
|
327
|
+
proactiveRefreshMinIntervalMs: boundedNumberOr(config.proactiveRefreshMinIntervalMs, 3e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMinIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 30000`)),
|
|
328
|
+
proactiveRefreshMaxIntervalMs: boundedNumberOr(config.proactiveRefreshMaxIntervalMs, 6e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMaxIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 60000`)),
|
|
329
|
+
proactiveRefreshFreshnessMs: optionalPositiveNumber(config.proactiveRefreshFreshnessMs, (received) => onWarn?.(`proactiveRefreshFreshnessMs must be a positive number (received ${JSON.stringify(received)}); ignoring it and inheriting postureRefreshFraction's threshold`)),
|
|
330
|
+
proactiveRefreshOnVisibilityResume: booleanOr(config.proactiveRefreshOnVisibilityResume, true, (received) => onWarn?.(`proactiveRefreshOnVisibilityResume must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
331
|
+
proactiveRefreshOnOnline: booleanOr(config.proactiveRefreshOnOnline, true, (received) => onWarn?.(`proactiveRefreshOnOnline must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
332
|
+
proactiveRefreshJitterSeed: optionalFiniteNumber(config.proactiveRefreshJitterSeed, (received) => onWarn?.(`proactiveRefreshJitterSeed must be a finite number (received ${JSON.stringify(received)}); ignoring it, jitter will use Math.random()`))
|
|
236
333
|
};
|
|
237
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* The most events one beacon POST may carry. The ingest route's
|
|
337
|
+
* `BeaconBatchSchema` refuses a larger batch whole (a 400, not a retry), so
|
|
338
|
+
* the SDK's offline drain never dequeues more than this per request.
|
|
339
|
+
*/
|
|
340
|
+
const BEACON_MAX_EVENTS_PER_BATCH = 100;
|
|
341
|
+
const SESSION_IDLE_GAP_MAX_MS = 216e5;
|
|
342
|
+
const BEACON_MAX_BATCH_ID_LENGTH = 255;
|
|
343
|
+
const BEACON_ORIGIN_CONTRACT_VERSION = 1;
|
|
344
|
+
const BEACON_ORIGIN_CAPABILITIES = ["batch-replay-v1", "receipt-status-v1"];
|
|
345
|
+
/**
|
|
346
|
+
* Lifetime of the signed browser posture token, in seconds. Defined here and
|
|
347
|
+
* re-exported by `browser-posture.ts` (which imports `jose`) so the
|
|
348
|
+
* size-budgeted beacon bundle can read it without pulling in a JWT library.
|
|
349
|
+
*/
|
|
350
|
+
const POSTURE_TTL_SECONDS = 120;
|
|
238
351
|
|
|
239
352
|
//#endregion
|
|
353
|
+
exports.BEACON_MAX_BATCH_ID_LENGTH = BEACON_MAX_BATCH_ID_LENGTH;
|
|
354
|
+
exports.BEACON_MAX_EVENTS_PER_BATCH = BEACON_MAX_EVENTS_PER_BATCH;
|
|
355
|
+
exports.BEACON_ORIGIN_CAPABILITIES = BEACON_ORIGIN_CAPABILITIES;
|
|
356
|
+
exports.BEACON_ORIGIN_CONTRACT_VERSION = BEACON_ORIGIN_CONTRACT_VERSION;
|
|
357
|
+
exports.POSTURE_TTL_SECONDS = POSTURE_TTL_SECONDS;
|
|
240
358
|
exports.ResourceUsageSchema = ResourceUsageSchema;
|
|
359
|
+
exports.SESSION_IDLE_GAP_MAX_MS = SESSION_IDLE_GAP_MAX_MS;
|
|
241
360
|
exports.WorkerPoolConfigSchema = WorkerPoolConfigSchema;
|
|
242
361
|
exports.isBeaconIdentity = isBeaconIdentity;
|
|
243
362
|
exports.parseBeaconConfig = parseBeaconConfig;
|
|
@@ -8,6 +8,77 @@ function toRecord(input) {
|
|
|
8
8
|
function numberOr(value, fallback) {
|
|
9
9
|
return typeof value === "number" && Number.isFinite(value) && value !== 0 ? value : fallback;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Validates a numeric config value against `ok`, falling back to `fallback`
|
|
13
|
+
* when it fails. Only calls `onReject` when the caller actually supplied a
|
|
14
|
+
* value (an `undefined` field, the common case, is not a rejection, it just
|
|
15
|
+
* never overrode the default): H0BB5 (PR #5095 review, item 4) — a rejected
|
|
16
|
+
* value used to fall back silently, with no way for a host to discover a
|
|
17
|
+
* config typo.
|
|
18
|
+
*/
|
|
19
|
+
function boundedNumberOr(value, fallback, ok, onReject) {
|
|
20
|
+
if (typeof value === "number" && Number.isFinite(value) && ok(value)) return value;
|
|
21
|
+
if (value !== void 0) onReject?.(value);
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
/** Same as `boundedNumberOr`, but an absent/rejected value stays `undefined` rather than defaulting. */
|
|
25
|
+
function optionalPositiveNumber(value, onReject) {
|
|
26
|
+
if (value === void 0) return void 0;
|
|
27
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
28
|
+
onReject?.(value);
|
|
29
|
+
}
|
|
30
|
+
/** Same as `optionalPositiveNumber`, without the positivity requirement (a jitter seed may be any finite number). */
|
|
31
|
+
function optionalFiniteNumber(value, onReject) {
|
|
32
|
+
if (value === void 0) return void 0;
|
|
33
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
34
|
+
onReject?.(value);
|
|
35
|
+
}
|
|
36
|
+
/** Same shape as `boundedNumberOr`/`optionalPositiveNumber`, for a boolean config flag. */
|
|
37
|
+
function booleanOr(value, fallback, onReject) {
|
|
38
|
+
if (value === void 0) return fallback;
|
|
39
|
+
if (typeof value === "boolean") return value;
|
|
40
|
+
onReject?.(value);
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
/** Ingest's own `sessionId` bound (1-255), limited to characters a cookie value carries unescaped. */
|
|
44
|
+
const RESUMABLE_SESSION_ID = /^[A-Za-z0-9._~-]{1,255}$/;
|
|
45
|
+
function resumableSessionId(value, onReject) {
|
|
46
|
+
if (value === void 0) return void 0;
|
|
47
|
+
if (typeof value === "string" && RESUMABLE_SESSION_ID.test(value)) return value;
|
|
48
|
+
onReject?.(value);
|
|
49
|
+
}
|
|
50
|
+
function receiptCallback(value, onReject) {
|
|
51
|
+
if (value === void 0) return void 0;
|
|
52
|
+
if (typeof value === "function") return value;
|
|
53
|
+
onReject?.(value);
|
|
54
|
+
}
|
|
55
|
+
const DISPATCH_TRIGGER_NAMES = [
|
|
56
|
+
"arrival",
|
|
57
|
+
"signals",
|
|
58
|
+
"interaction",
|
|
59
|
+
"untrusted",
|
|
60
|
+
"posture",
|
|
61
|
+
"unload",
|
|
62
|
+
"navigation"
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Keeps only the known trigger names with a real boolean; anything else is
|
|
66
|
+
* dropped and, when the caller actually named a known trigger with a
|
|
67
|
+
* non-boolean value (`triggers: { posture: 0 }`, say), reported through
|
|
68
|
+
* `onReject` — H0BB5 (PR #5095 review, item 4): a numeric `0` used to be
|
|
69
|
+
* dropped silently and that trigger stayed at its default-enabled state,
|
|
70
|
+
* the opposite of what the "0 is falsy" convention suggests.
|
|
71
|
+
*/
|
|
72
|
+
function pickTriggers(value, onReject) {
|
|
73
|
+
if (!isRecord(value)) return void 0;
|
|
74
|
+
const picked = {};
|
|
75
|
+
for (const name of DISPATCH_TRIGGER_NAMES) {
|
|
76
|
+
const raw = value[name];
|
|
77
|
+
if (typeof raw === "boolean") picked[name] = raw;
|
|
78
|
+
else if (raw !== void 0) onReject?.(name, raw);
|
|
79
|
+
}
|
|
80
|
+
return picked;
|
|
81
|
+
}
|
|
11
82
|
function stringOr(value, fallback) {
|
|
12
83
|
return typeof value === "string" ? value : fallback;
|
|
13
84
|
}
|
|
@@ -85,7 +156,7 @@ function parseOfflineQueueEntry(input) {
|
|
|
85
156
|
if (!isRecord(input)) throw new Error("Invalid offline queue entry");
|
|
86
157
|
const entry = input;
|
|
87
158
|
return {
|
|
88
|
-
id: stringOr(entry.id, `${Date.now()}_${
|
|
159
|
+
id: stringOr(entry.id, `${Date.now()}_${Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(6)), (byte) => byte.toString(16).padStart(2, "0")).join("")}`),
|
|
89
160
|
events: Array.isArray(entry.events) ? entry.events : [],
|
|
90
161
|
timestamp: numberOr(entry.timestamp, Date.now()),
|
|
91
162
|
expiresAt: numberOr(entry.expiresAt, Date.now() + 864e5),
|
|
@@ -93,10 +164,17 @@ function parseOfflineQueueEntry(input) {
|
|
|
93
164
|
size: numberOr(entry.size, 0)
|
|
94
165
|
};
|
|
95
166
|
}
|
|
167
|
+
function randomId() {
|
|
168
|
+
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
169
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
170
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
171
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
172
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
173
|
+
}
|
|
96
174
|
function parseBeaconWorkerMessage(input) {
|
|
97
175
|
if (!isRecord(input)) throw new Error("Invalid beacon worker message");
|
|
98
176
|
const msg = input;
|
|
99
|
-
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ??
|
|
177
|
+
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ?? randomId();
|
|
100
178
|
return {
|
|
101
179
|
type: isBeaconWorkerMessageType(msg.type) ? msg.type : "init",
|
|
102
180
|
data: msg.data,
|
|
@@ -119,7 +197,7 @@ function parseWorkerMessage(input) {
|
|
|
119
197
|
const msg = input && typeof input === "object" ? input : null;
|
|
120
198
|
if (!msg) throw new Error("Invalid worker message");
|
|
121
199
|
return {
|
|
122
|
-
id: msg.id ||
|
|
200
|
+
id: msg.id || randomId(),
|
|
123
201
|
type: isWorkerMessageType(msg.type) ? msg.type : "request",
|
|
124
202
|
action: msg.action,
|
|
125
203
|
payload: msg.payload,
|
|
@@ -202,7 +280,14 @@ function parseWorkerCapabilities(input) {
|
|
|
202
280
|
}
|
|
203
281
|
};
|
|
204
282
|
}
|
|
205
|
-
|
|
283
|
+
/**
|
|
284
|
+
* @param onWarn Called once per rejected config value (a supplied value that
|
|
285
|
+
* failed validation and fell back to its default), for a caller that wants
|
|
286
|
+
* to surface it — `BeaconConfigManager.validateAndMergeConfig` wires this to
|
|
287
|
+
* `log('warn', ...)`. Never called for an omitted field; only for one the
|
|
288
|
+
* caller actually set to something invalid.
|
|
289
|
+
*/
|
|
290
|
+
function parseBeaconConfig(input, onWarn) {
|
|
206
291
|
const config = toRecord(input);
|
|
207
292
|
if (typeof config.projectId !== "string" || config.projectId.length === 0) throw new Error("Project ID is required");
|
|
208
293
|
return {
|
|
@@ -215,15 +300,21 @@ function parseBeaconConfig(input) {
|
|
|
215
300
|
debug: config.debug === true,
|
|
216
301
|
logLevel: isLogLevel(config.logLevel) ? config.logLevel : "error",
|
|
217
302
|
respectDoNotTrack: config.respectDoNotTrack !== false,
|
|
303
|
+
requireConsent: config.requireConsent === true,
|
|
218
304
|
anonymizeIp: config.anonymizeIp === true,
|
|
219
305
|
stripUrlFragment: config.stripUrlFragment !== false,
|
|
220
306
|
scrubQueryParams: isStringArray(config.scrubQueryParams) ? config.scrubQueryParams : void 0,
|
|
221
307
|
dropQueryParams: config.dropQueryParams === true,
|
|
222
|
-
sessionTimeout: numberOr(config.sessionTimeout,
|
|
308
|
+
sessionTimeout: numberOr(config.sessionTimeout, void 0),
|
|
223
309
|
sessionCookieName: stringOr(config.sessionCookieName, "_as_beacon_session"),
|
|
224
|
-
|
|
225
|
-
|
|
310
|
+
browserSessionId: resumableSessionId(config.browserSessionId, (received) => onWarn?.(`browserSessionId must match ${RESUMABLE_SESSION_ID} (received ${JSON.stringify(received)}); ignoring it`)),
|
|
311
|
+
onReceipt: receiptCallback(config.onReceipt, (received) => onWarn?.(`onReceipt must be a function (received ${typeof received}); ignoring it`)),
|
|
312
|
+
batchSize: typeof config.batchSize === "number" ? config.batchSize : void 0,
|
|
313
|
+
flushInterval: typeof config.flushInterval === "number" ? config.flushInterval : void 0,
|
|
226
314
|
collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
|
|
315
|
+
evidenceGrowthFactor: boundedNumberOr(config.evidenceGrowthFactor, 2, (n) => n > 1, (received) => onWarn?.(`evidenceGrowthFactor must be a number greater than 1 (received ${JSON.stringify(received)}); using default 2`)),
|
|
316
|
+
postureRefreshFraction: boundedNumberOr(config.postureRefreshFraction, .5, (n) => n > 0 && n <= 1, (received) => onWarn?.(`postureRefreshFraction must be a number in (0, 1] (received ${JSON.stringify(received)}); using default 0.5`)),
|
|
317
|
+
triggers: pickTriggers(config.triggers, (name, received) => onWarn?.(`triggers.${name} must be a boolean (received ${JSON.stringify(received)}); ignoring it and keeping its default`)),
|
|
227
318
|
maxQueueSize: numberOr(config.maxQueueSize, 100),
|
|
228
319
|
retryAttempts: numberOr(config.retryAttempts, 3),
|
|
229
320
|
retryDelay: numberOr(config.retryDelay, 2e3),
|
|
@@ -231,10 +322,32 @@ function parseBeaconConfig(input) {
|
|
|
231
322
|
useWorker: resolveUseWorker(config),
|
|
232
323
|
workerUrl: stringOr(config.workerUrl),
|
|
233
324
|
workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
|
|
234
|
-
lazySignalsUrl: stringOr(config.lazySignalsUrl)
|
|
325
|
+
lazySignalsUrl: stringOr(config.lazySignalsUrl),
|
|
326
|
+
proactiveRefreshMinIntervalMs: boundedNumberOr(config.proactiveRefreshMinIntervalMs, 3e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMinIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 30000`)),
|
|
327
|
+
proactiveRefreshMaxIntervalMs: boundedNumberOr(config.proactiveRefreshMaxIntervalMs, 6e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMaxIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 60000`)),
|
|
328
|
+
proactiveRefreshFreshnessMs: optionalPositiveNumber(config.proactiveRefreshFreshnessMs, (received) => onWarn?.(`proactiveRefreshFreshnessMs must be a positive number (received ${JSON.stringify(received)}); ignoring it and inheriting postureRefreshFraction's threshold`)),
|
|
329
|
+
proactiveRefreshOnVisibilityResume: booleanOr(config.proactiveRefreshOnVisibilityResume, true, (received) => onWarn?.(`proactiveRefreshOnVisibilityResume must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
330
|
+
proactiveRefreshOnOnline: booleanOr(config.proactiveRefreshOnOnline, true, (received) => onWarn?.(`proactiveRefreshOnOnline must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
331
|
+
proactiveRefreshJitterSeed: optionalFiniteNumber(config.proactiveRefreshJitterSeed, (received) => onWarn?.(`proactiveRefreshJitterSeed must be a finite number (received ${JSON.stringify(received)}); ignoring it, jitter will use Math.random()`))
|
|
235
332
|
};
|
|
236
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* The most events one beacon POST may carry. The ingest route's
|
|
336
|
+
* `BeaconBatchSchema` refuses a larger batch whole (a 400, not a retry), so
|
|
337
|
+
* the SDK's offline drain never dequeues more than this per request.
|
|
338
|
+
*/
|
|
339
|
+
const BEACON_MAX_EVENTS_PER_BATCH = 100;
|
|
340
|
+
const SESSION_IDLE_GAP_MAX_MS = 216e5;
|
|
341
|
+
const BEACON_MAX_BATCH_ID_LENGTH = 255;
|
|
342
|
+
const BEACON_ORIGIN_CONTRACT_VERSION = 1;
|
|
343
|
+
const BEACON_ORIGIN_CAPABILITIES = ["batch-replay-v1", "receipt-status-v1"];
|
|
344
|
+
/**
|
|
345
|
+
* Lifetime of the signed browser posture token, in seconds. Defined here and
|
|
346
|
+
* re-exported by `browser-posture.ts` (which imports `jose`) so the
|
|
347
|
+
* size-budgeted beacon bundle can read it without pulling in a JWT library.
|
|
348
|
+
*/
|
|
349
|
+
const POSTURE_TTL_SECONDS = 120;
|
|
237
350
|
|
|
238
351
|
//#endregion
|
|
239
|
-
export { ResourceUsageSchema, WorkerPoolConfigSchema, isBeaconIdentity, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig };
|
|
352
|
+
export { BEACON_MAX_BATCH_ID_LENGTH, BEACON_MAX_EVENTS_PER_BATCH, BEACON_ORIGIN_CAPABILITIES, BEACON_ORIGIN_CONTRACT_VERSION, POSTURE_TTL_SECONDS, ResourceUsageSchema, SESSION_IDLE_GAP_MAX_MS, WorkerPoolConfigSchema, isBeaconIdentity, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig };
|
|
240
353
|
//# sourceMappingURL=index.mjs.map
|