@kya-os/checkpoint-shared 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/beacon-types/index.d.mts +448 -432
- package/dist/beacon-types/index.d.mts.map +1 -0
- package/dist/beacon-types/index.d.ts +448 -432
- package/dist/beacon-types/index.d.ts.map +1 -0
- package/dist/beacon-types/index.js +286 -182
- package/dist/beacon-types/index.mjs +284 -180
- package/dist/beacon-types/index.mjs.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +2 -0
- package/dist/browser-posture-cookie.d.ts +2 -0
- package/dist/browser-posture-cookie.js +1 -0
- package/dist/browser-posture-cookie.mjs +2 -0
- package/dist/browser-posture-cookie.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +48 -44
- package/dist/browser-posture-report.d.mts.map +1 -0
- package/dist/browser-posture-report.d.ts +48 -44
- package/dist/browser-posture-report.d.ts.map +1 -0
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +2 -1
- package/dist/browser-posture-report.mjs.map +1 -0
- package/dist/browser-posture.d.mts +82 -75
- package/dist/browser-posture.d.mts.map +1 -0
- package/dist/browser-posture.d.ts +82 -75
- package/dist/browser-posture.d.ts.map +1 -0
- package/dist/browser-posture.js +167 -18993
- package/dist/browser-posture.mjs +166 -18990
- package/dist/browser-posture.mjs.map +1 -0
- package/dist/browser.d.mts +323 -316
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.d.ts +323 -316
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +2 -1
- package/dist/browser.mjs.map +1 -0
- package/dist/canonical-signer/index.d.mts +38 -33
- package/dist/canonical-signer/index.d.mts.map +1 -0
- package/dist/canonical-signer/index.d.ts +38 -33
- package/dist/canonical-signer/index.d.ts.map +1 -0
- package/dist/canonical-signer/index.js +411 -181
- package/dist/canonical-signer/index.mjs +383 -175
- package/dist/canonical-signer/index.mjs.map +1 -0
- package/dist/clearance.d.mts +30 -0
- package/dist/clearance.d.mts.map +1 -0
- package/dist/clearance.d.ts +30 -0
- package/dist/clearance.d.ts.map +1 -0
- package/dist/clearance.js +120 -0
- package/dist/clearance.mjs +112 -0
- package/dist/clearance.mjs.map +1 -0
- package/dist/client-ip-1y2iXAYW.js +237 -0
- package/dist/client-ip-HOfe6ucV.mjs +215 -0
- package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
- package/dist/deploy/index.d.mts +339 -339
- package/dist/deploy/index.d.mts.map +1 -0
- package/dist/deploy/index.d.ts +339 -339
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +505 -413
- package/dist/deploy/index.mjs +504 -410
- package/dist/deploy/index.mjs.map +1 -0
- package/dist/errors/index.d.mts +101 -101
- package/dist/errors/index.d.mts.map +1 -0
- package/dist/errors/index.d.ts +101 -101
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +341 -314
- package/dist/errors/index.mjs +340 -311
- package/dist/errors/index.mjs.map +1 -0
- package/dist/external-jr_S4iSS.d.mts +4187 -0
- package/dist/external-jr_S4iSS.d.mts.map +1 -0
- package/dist/external-jr_S4iSS.d.ts +4187 -0
- package/dist/external-jr_S4iSS.d.ts.map +1 -0
- package/dist/gateway/index.d.mts +138 -132
- package/dist/gateway/index.d.mts.map +1 -0
- package/dist/gateway/index.d.ts +138 -132
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +117 -81
- package/dist/gateway/index.mjs +116 -78
- package/dist/gateway/index.mjs.map +1 -0
- package/dist/gateway-client-ip.d.mts +59 -0
- package/dist/gateway-client-ip.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.ts +59 -0
- package/dist/gateway-client-ip.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +149 -0
- package/dist/gateway-client-ip.mjs +139 -0
- package/dist/gateway-client-ip.mjs.map +1 -0
- package/dist/index.d.mts +14901 -14246
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +14901 -14246
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15180 -31025
- package/dist/index.mjs +15065 -30942
- package/dist/index.mjs.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.mts +45 -44
- package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.ts +45 -44
- package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
- package/dist/mcpi/agentshield-api/index.js +0 -2
- package/dist/mcpi/agentshield-api/index.mjs +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +63 -61
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
- package/dist/mcpi/approval-grant/index.d.ts +63 -61
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
- package/dist/mcpi/approval-grant/index.js +220 -140
- package/dist/mcpi/approval-grant/index.mjs +219 -137
- package/dist/mcpi/approval-grant/index.mjs.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
- package/dist/mcpi/dashboard-config/index.js +605 -458
- package/dist/mcpi/dashboard-config/index.mjs +604 -455
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.mts +10 -8
- package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.ts +10 -8
- package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
- package/dist/mcpi/multibase-ed25519.js +182 -106
- package/dist/mcpi/multibase-ed25519.mjs +181 -103
- package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
- package/dist/patterns-CkRVOdtV.js +243 -0
- package/dist/patterns-DzkGy_qk.mjs +173 -0
- package/dist/patterns-DzkGy_qk.mjs.map +1 -0
- package/dist/project-verification-key-C3L5rd8a.js +41 -0
- package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
- package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
- package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
- package/dist/schemas-BmjNLAE7.js +5677 -0
- package/dist/schemas-DxY-dk9y.mjs +5511 -0
- package/dist/schemas-DxY-dk9y.mjs.map +1 -0
- package/dist/signals/index.d.mts +125 -115
- package/dist/signals/index.d.mts.map +1 -0
- package/dist/signals/index.d.ts +125 -115
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +1693 -1536
- package/dist/signals/index.mjs +1692 -1533
- package/dist/signals/index.mjs.map +1 -0
- package/dist/test-fixtures/index.d.mts +124 -119
- package/dist/test-fixtures/index.d.mts.map +1 -0
- package/dist/test-fixtures/index.d.ts +124 -119
- package/dist/test-fixtures/index.d.ts.map +1 -0
- package/dist/test-fixtures/index.js +460 -228
- package/dist/test-fixtures/index.mjs +459 -225
- package/dist/test-fixtures/index.mjs.map +1 -0
- package/dist/tool-protection/index.d.mts +343 -343
- package/dist/tool-protection/index.d.mts.map +1 -0
- package/dist/tool-protection/index.d.ts +343 -343
- package/dist/tool-protection/index.d.ts.map +1 -0
- package/dist/tool-protection/index.js +366 -285
- package/dist/tool-protection/index.mjs +365 -282
- package/dist/tool-protection/index.mjs.map +1 -0
- package/fixtures/bot-signal-resolution.json +142 -0
- package/fixtures/browser-posture-claims.json +421 -0
- package/fixtures/browser-posture-headers.json +46 -0
- package/fixtures/detection/reason-codes.json +10 -1
- package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
- package/fixtures/kya-http/challenge.delegation.full.json +9 -3
- package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
- package/fixtures/kya-http/error-codes.json +7 -2
- package/package.json +20 -6
|
@@ -1,222 +1,326 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/beacon-types/index.ts
|
|
2
2
|
function isRecord(input) {
|
|
3
|
-
|
|
3
|
+
return typeof input === "object" && input !== null && !Array.isArray(input);
|
|
4
4
|
}
|
|
5
5
|
function toRecord(input) {
|
|
6
|
-
|
|
6
|
+
return isRecord(input) ? input : {};
|
|
7
7
|
}
|
|
8
8
|
function numberOr(value, fallback) {
|
|
9
|
-
|
|
9
|
+
return typeof value === "number" && Number.isFinite(value) && value !== 0 ? value : fallback;
|
|
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
|
+
const DISPATCH_TRIGGER_NAMES = [
|
|
44
|
+
"arrival",
|
|
45
|
+
"signals",
|
|
46
|
+
"interaction",
|
|
47
|
+
"untrusted",
|
|
48
|
+
"posture",
|
|
49
|
+
"unload"
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Keeps only the known trigger names with a real boolean; anything else is
|
|
53
|
+
* dropped and, when the caller actually named a known trigger with a
|
|
54
|
+
* non-boolean value (`triggers: { posture: 0 }`, say), reported through
|
|
55
|
+
* `onReject` — H0BB5 (PR #5095 review, item 4): a numeric `0` used to be
|
|
56
|
+
* dropped silently and that trigger stayed at its default-enabled state,
|
|
57
|
+
* the opposite of what the "0 is falsy" convention suggests.
|
|
58
|
+
*/
|
|
59
|
+
function pickTriggers(value, onReject) {
|
|
60
|
+
if (!isRecord(value)) return void 0;
|
|
61
|
+
const picked = {};
|
|
62
|
+
for (const name of DISPATCH_TRIGGER_NAMES) {
|
|
63
|
+
const raw = value[name];
|
|
64
|
+
if (typeof raw === "boolean") picked[name] = raw;
|
|
65
|
+
else if (raw !== void 0) onReject?.(name, raw);
|
|
66
|
+
}
|
|
67
|
+
return picked;
|
|
10
68
|
}
|
|
11
69
|
function stringOr(value, fallback) {
|
|
12
|
-
|
|
70
|
+
return typeof value === "string" ? value : fallback;
|
|
71
|
+
}
|
|
72
|
+
function isStringArray(value) {
|
|
73
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Non-empty on purpose: an empty schedule would mean "zero posture-recovery
|
|
77
|
+
* attempts", silently disabling recovery rather than configuring it. A
|
|
78
|
+
* deployment that actually wants no retries sets `flushInterval` instead.
|
|
79
|
+
*/
|
|
80
|
+
function isPositiveNumberArray(value) {
|
|
81
|
+
return Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "number" && Number.isFinite(entry) && entry > 0);
|
|
13
82
|
}
|
|
14
83
|
function isBeaconTags(value) {
|
|
15
|
-
|
|
16
|
-
(entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean"
|
|
17
|
-
);
|
|
84
|
+
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean");
|
|
18
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Exported because `parseBeaconConfig` is an allowlist: a key it does not
|
|
88
|
+
* name is dropped, silently. The beacon's other public entry point
|
|
89
|
+
* (`checkpoint-shared/browser`) carries its own copy of that allowlist, so
|
|
90
|
+
* the CHECK at least lives in one place even while the two parsers do not —
|
|
91
|
+
* see the note on `BeaconConfig.identity`.
|
|
92
|
+
*
|
|
93
|
+
* Rejects an identity with no usable `userId` rather than passing through a
|
|
94
|
+
* half-formed object: downstream this becomes `detections.user_id`, and an
|
|
95
|
+
* empty string there is worse than an absent one — it reads as "identified"
|
|
96
|
+
* while naming nobody.
|
|
97
|
+
*/
|
|
19
98
|
function isBeaconIdentity(value) {
|
|
20
|
-
|
|
99
|
+
return isRecord(value) && typeof value.userId === "string" && value.userId.length > 0;
|
|
21
100
|
}
|
|
22
101
|
function isLogLevel(value) {
|
|
23
|
-
|
|
102
|
+
return value === "error" || value === "warn" || value === "info" || value === "debug";
|
|
24
103
|
}
|
|
25
104
|
function isBeaconWorkerMessageType(value) {
|
|
26
|
-
|
|
27
|
-
// successful request (init/collect/flush/config/status) — the allowlist
|
|
28
|
-
// just never named it, so `parseBeaconWorkerMessage` silently coerced
|
|
29
|
-
// every success response to `'init'` (see that function's fallback).
|
|
30
|
-
value === "response";
|
|
105
|
+
return value === "init" || value === "collect" || value === "flush" || value === "config" || value === "status" || value === "error" || value === "response" || value === "posture";
|
|
31
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Resolves whether a beacon should use its Web Worker transport.
|
|
109
|
+
*
|
|
110
|
+
* `enableWebWorker` is accepted as an alias for `useWorker`: the package's
|
|
111
|
+
* own test suite (`checkpoint-beacon/src/index.test.ts`) has always
|
|
112
|
+
* constructed with `enableWebWorker: false`, but `parseBeaconConfig`'s
|
|
113
|
+
* allowlist only ever named `useWorker`, so that key was silently dropped —
|
|
114
|
+
* the beacon kept auto-detecting worker support regardless of what the
|
|
115
|
+
* caller passed. `useWorker` wins when both are set, since it's the
|
|
116
|
+
* canonical name every other config field (`workerUrl`, `workerConfig`)
|
|
117
|
+
* pairs with.
|
|
118
|
+
*/
|
|
32
119
|
function resolveUseWorker(config) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (typeof config.enableWebWorker === "boolean") {
|
|
37
|
-
return config.enableWebWorker;
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
120
|
+
if (typeof config.useWorker === "boolean") return config.useWorker;
|
|
121
|
+
if (typeof config.enableWebWorker === "boolean") return config.enableWebWorker;
|
|
122
|
+
return true;
|
|
40
123
|
}
|
|
41
124
|
function parseRetryStrategy(input) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
125
|
+
const strategy = toRecord(input);
|
|
126
|
+
return {
|
|
127
|
+
maxAttempts: numberOr(strategy.maxAttempts, 3),
|
|
128
|
+
baseDelay: numberOr(strategy.baseDelay, 1e3),
|
|
129
|
+
maxDelay: numberOr(strategy.maxDelay, 3e4),
|
|
130
|
+
factor: numberOr(strategy.factor, 2),
|
|
131
|
+
jitter: strategy.jitter !== false
|
|
132
|
+
};
|
|
50
133
|
}
|
|
51
134
|
function parseCircuitBreakerConfig(input) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
135
|
+
const config = toRecord(input);
|
|
136
|
+
return {
|
|
137
|
+
threshold: numberOr(config.threshold, 5),
|
|
138
|
+
timeout: numberOr(config.timeout, 6e4),
|
|
139
|
+
resetTimeout: numberOr(config.resetTimeout, 3e4)
|
|
140
|
+
};
|
|
58
141
|
}
|
|
59
142
|
function parseOfflineQueueEntry(input) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
retryCount: numberOr(entry.retryCount, 0),
|
|
71
|
-
size: numberOr(entry.size, 0)
|
|
72
|
-
};
|
|
143
|
+
if (!isRecord(input)) throw new Error("Invalid offline queue entry");
|
|
144
|
+
const entry = input;
|
|
145
|
+
return {
|
|
146
|
+
id: stringOr(entry.id, `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`),
|
|
147
|
+
events: Array.isArray(entry.events) ? entry.events : [],
|
|
148
|
+
timestamp: numberOr(entry.timestamp, Date.now()),
|
|
149
|
+
expiresAt: numberOr(entry.expiresAt, Date.now() + 864e5),
|
|
150
|
+
retryCount: numberOr(entry.retryCount, 0),
|
|
151
|
+
size: numberOr(entry.size, 0)
|
|
152
|
+
};
|
|
73
153
|
}
|
|
74
154
|
function parseBeaconWorkerMessage(input) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
id: stringOr(msg.id, messageId)
|
|
87
|
-
};
|
|
155
|
+
if (!isRecord(input)) throw new Error("Invalid beacon worker message");
|
|
156
|
+
const msg = input;
|
|
157
|
+
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ?? crypto.randomUUID();
|
|
158
|
+
return {
|
|
159
|
+
type: isBeaconWorkerMessageType(msg.type) ? msg.type : "init",
|
|
160
|
+
data: msg.data,
|
|
161
|
+
payload: msg.payload,
|
|
162
|
+
messageId,
|
|
163
|
+
timestamp: numberOr(msg.timestamp, Date.now()),
|
|
164
|
+
id: stringOr(msg.id, messageId)
|
|
165
|
+
};
|
|
88
166
|
}
|
|
89
167
|
function isMessagePriority(value) {
|
|
90
|
-
|
|
168
|
+
return value === "low" || value === "normal" || value === "high" || value === "critical";
|
|
91
169
|
}
|
|
92
170
|
function isWorkerMessageType(value) {
|
|
93
|
-
|
|
171
|
+
return value === "request" || value === "response" || value === "error" || value === "heartbeat" || value === "status";
|
|
94
172
|
}
|
|
95
173
|
function isWorkerErrorType(value) {
|
|
96
|
-
|
|
174
|
+
return value === "initialization" || value === "runtime" || value === "communication" || value === "timeout" || value === "memory" || value === "network" || value === "permission" || value === "validation" || value === "processing" || value === "unknown";
|
|
97
175
|
}
|
|
98
176
|
function parseWorkerMessage(input) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
correlationId: msg.correlationId
|
|
112
|
-
};
|
|
177
|
+
const msg = input && typeof input === "object" ? input : null;
|
|
178
|
+
if (!msg) throw new Error("Invalid worker message");
|
|
179
|
+
return {
|
|
180
|
+
id: msg.id || crypto.randomUUID(),
|
|
181
|
+
type: isWorkerMessageType(msg.type) ? msg.type : "request",
|
|
182
|
+
action: msg.action,
|
|
183
|
+
payload: msg.payload,
|
|
184
|
+
timestamp: msg.timestamp || Date.now(),
|
|
185
|
+
compressed: msg.compressed,
|
|
186
|
+
priority: isMessagePriority(msg.priority) ? msg.priority : "normal",
|
|
187
|
+
correlationId: msg.correlationId
|
|
188
|
+
};
|
|
113
189
|
}
|
|
114
190
|
function parseWorkerError(input) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
191
|
+
const error = input && typeof input === "object" ? input : {};
|
|
192
|
+
return {
|
|
193
|
+
type: isWorkerErrorType(error.type) ? error.type : "unknown",
|
|
194
|
+
code: typeof error.code === "string" ? error.code : void 0,
|
|
195
|
+
message: typeof error.message === "string" ? error.message : "Worker error",
|
|
196
|
+
stack: typeof error.stack === "string" ? error.stack : void 0,
|
|
197
|
+
timestamp: typeof error.timestamp === "number" ? error.timestamp : Date.now(),
|
|
198
|
+
recoverable: error.recoverable !== false,
|
|
199
|
+
retryAfter: typeof error.retryAfter === "number" ? error.retryAfter : void 0,
|
|
200
|
+
context: error.context
|
|
201
|
+
};
|
|
126
202
|
}
|
|
127
203
|
function parseWorkerPoolConfig(input) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
204
|
+
const config = input && typeof input === "object" ? input : {};
|
|
205
|
+
return {
|
|
206
|
+
maxWorkers: config.maxWorkers ?? 4,
|
|
207
|
+
minWorkers: config.minWorkers ?? 1,
|
|
208
|
+
workerIdleTimeout: config.workerIdleTimeout ?? 3e4,
|
|
209
|
+
taskQueueSize: config.taskQueueSize ?? 100,
|
|
210
|
+
resourceLimits: config.resourceLimits ?? {},
|
|
211
|
+
autoScale: config.autoScale ?? true,
|
|
212
|
+
scaleUpThreshold: config.scaleUpThreshold ?? 75,
|
|
213
|
+
scaleDownThreshold: config.scaleDownThreshold ?? 25
|
|
214
|
+
};
|
|
139
215
|
}
|
|
140
216
|
function parseResourceUsage(input) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
217
|
+
const usage = input && typeof input === "object" ? input : {};
|
|
218
|
+
return {
|
|
219
|
+
memory: usage.memory ?? {
|
|
220
|
+
used: 0,
|
|
221
|
+
limit: 0,
|
|
222
|
+
percentage: 0
|
|
223
|
+
},
|
|
224
|
+
cpu: usage.cpu ?? {
|
|
225
|
+
usage: 0,
|
|
226
|
+
limit: 100
|
|
227
|
+
},
|
|
228
|
+
tasks: usage.tasks ?? {
|
|
229
|
+
pending: 0,
|
|
230
|
+
active: 0,
|
|
231
|
+
completed: 0,
|
|
232
|
+
failed: 0
|
|
233
|
+
},
|
|
234
|
+
activeWorkers: usage.activeWorkers ?? 0
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const ResourceUsageSchema = { parse: parseResourceUsage };
|
|
238
|
+
const WorkerPoolConfigSchema = { parse: parseWorkerPoolConfig };
|
|
155
239
|
function parseWorkerCapabilities(input) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
240
|
+
const cap = toRecord(input);
|
|
241
|
+
const csp = toRecord(cap.csp);
|
|
242
|
+
const performance = toRecord(cap.performance);
|
|
243
|
+
return {
|
|
244
|
+
workerAPI: cap.workerAPI !== false,
|
|
245
|
+
sharedArrayBuffer: cap.sharedArrayBuffer === true,
|
|
246
|
+
transferableObjects: cap.transferableObjects === true,
|
|
247
|
+
offscreenCanvas: cap.offscreenCanvas === true,
|
|
248
|
+
webAssembly: cap.webAssembly === true,
|
|
249
|
+
atomics: cap.atomics === true,
|
|
250
|
+
bigInt: cap.bigInt === true,
|
|
251
|
+
csp: {
|
|
252
|
+
workerSrc: csp.workerSrc === true,
|
|
253
|
+
scriptSrc: csp.scriptSrc === true,
|
|
254
|
+
blobUrls: csp.blobUrls === true,
|
|
255
|
+
inlineWorkers: csp.inlineWorkers === true
|
|
256
|
+
},
|
|
257
|
+
performance: {
|
|
258
|
+
memory: performance.memory === true,
|
|
259
|
+
measureUserAgentSpecificMemory: performance.measureUserAgentSpecificMemory === true
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @param onWarn Called once per rejected config value (a supplied value that
|
|
265
|
+
* failed validation and fell back to its default), for a caller that wants
|
|
266
|
+
* to surface it — `BeaconConfigManager.validateAndMergeConfig` wires this to
|
|
267
|
+
* `log('warn', ...)`. Never called for an omitted field; only for one the
|
|
268
|
+
* caller actually set to something invalid.
|
|
269
|
+
*/
|
|
270
|
+
function parseBeaconConfig(input, onWarn) {
|
|
271
|
+
const config = toRecord(input);
|
|
272
|
+
if (typeof config.projectId !== "string" || config.projectId.length === 0) throw new Error("Project ID is required");
|
|
273
|
+
return {
|
|
274
|
+
projectId: config.projectId,
|
|
275
|
+
environment: stringOr(config.environment),
|
|
276
|
+
tags: isBeaconTags(config.tags) ? config.tags : void 0,
|
|
277
|
+
identity: isBeaconIdentity(config.identity) ? config.identity : void 0,
|
|
278
|
+
endpoint: stringOr(config.endpoint),
|
|
279
|
+
enabled: config.enabled !== false,
|
|
280
|
+
debug: config.debug === true,
|
|
281
|
+
logLevel: isLogLevel(config.logLevel) ? config.logLevel : "error",
|
|
282
|
+
respectDoNotTrack: config.respectDoNotTrack !== false,
|
|
283
|
+
anonymizeIp: config.anonymizeIp === true,
|
|
284
|
+
stripUrlFragment: config.stripUrlFragment !== false,
|
|
285
|
+
scrubQueryParams: isStringArray(config.scrubQueryParams) ? config.scrubQueryParams : void 0,
|
|
286
|
+
dropQueryParams: config.dropQueryParams === true,
|
|
287
|
+
sessionTimeout: numberOr(config.sessionTimeout, 18e5),
|
|
288
|
+
sessionCookieName: stringOr(config.sessionCookieName, "_as_beacon_session"),
|
|
289
|
+
batchSize: typeof config.batchSize === "number" ? config.batchSize : void 0,
|
|
290
|
+
flushInterval: typeof config.flushInterval === "number" ? config.flushInterval : void 0,
|
|
291
|
+
collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
|
|
292
|
+
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`)),
|
|
293
|
+
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`)),
|
|
294
|
+
triggers: pickTriggers(config.triggers, (name, received) => onWarn?.(`triggers.${name} must be a boolean (received ${JSON.stringify(received)}); ignoring it and keeping its default`)),
|
|
295
|
+
maxQueueSize: numberOr(config.maxQueueSize, 100),
|
|
296
|
+
retryAttempts: numberOr(config.retryAttempts, 3),
|
|
297
|
+
retryDelay: numberOr(config.retryDelay, 2e3),
|
|
298
|
+
postureRetryScheduleMs: isPositiveNumberArray(config.postureRetryScheduleMs) ? config.postureRetryScheduleMs : void 0,
|
|
299
|
+
useWorker: resolveUseWorker(config),
|
|
300
|
+
workerUrl: stringOr(config.workerUrl),
|
|
301
|
+
workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
|
|
302
|
+
lazySignalsUrl: stringOr(config.lazySignalsUrl),
|
|
303
|
+
proactiveRefreshMinIntervalMs: boundedNumberOr(config.proactiveRefreshMinIntervalMs, 3e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMinIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 30000`)),
|
|
304
|
+
proactiveRefreshMaxIntervalMs: boundedNumberOr(config.proactiveRefreshMaxIntervalMs, 6e4, (n) => n > 0, (received) => onWarn?.(`proactiveRefreshMaxIntervalMs must be a positive number (received ${JSON.stringify(received)}); using default 60000`)),
|
|
305
|
+
proactiveRefreshFreshnessMs: optionalPositiveNumber(config.proactiveRefreshFreshnessMs, (received) => onWarn?.(`proactiveRefreshFreshnessMs must be a positive number (received ${JSON.stringify(received)}); ignoring it and inheriting postureRefreshFraction's threshold`)),
|
|
306
|
+
proactiveRefreshOnVisibilityResume: booleanOr(config.proactiveRefreshOnVisibilityResume, true, (received) => onWarn?.(`proactiveRefreshOnVisibilityResume must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
307
|
+
proactiveRefreshOnOnline: booleanOr(config.proactiveRefreshOnOnline, true, (received) => onWarn?.(`proactiveRefreshOnOnline must be a boolean (received ${JSON.stringify(received)}); using default true`)),
|
|
308
|
+
proactiveRefreshJitterSeed: optionalFiniteNumber(config.proactiveRefreshJitterSeed, (received) => onWarn?.(`proactiveRefreshJitterSeed must be a finite number (received ${JSON.stringify(received)}); ignoring it, jitter will use Math.random()`))
|
|
309
|
+
};
|
|
220
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* The most events one beacon POST may carry. The ingest route's
|
|
313
|
+
* `BeaconBatchSchema` refuses a larger batch whole (a 400, not a retry), so
|
|
314
|
+
* the SDK's offline drain never dequeues more than this per request.
|
|
315
|
+
*/
|
|
316
|
+
const BEACON_MAX_EVENTS_PER_BATCH = 100;
|
|
317
|
+
/**
|
|
318
|
+
* Lifetime of the signed browser posture token, in seconds. Defined here and
|
|
319
|
+
* re-exported by `browser-posture.ts` (which imports `jose`) so the
|
|
320
|
+
* size-budgeted beacon bundle can read it without pulling in a JWT library.
|
|
321
|
+
*/
|
|
322
|
+
const POSTURE_TTL_SECONDS = 120;
|
|
221
323
|
|
|
222
|
-
|
|
324
|
+
//#endregion
|
|
325
|
+
export { BEACON_MAX_EVENTS_PER_BATCH, POSTURE_TTL_SECONDS, ResourceUsageSchema, WorkerPoolConfigSchema, isBeaconIdentity, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig };
|
|
326
|
+
//# sourceMappingURL=index.mjs.map
|