@kya-os/checkpoint-shared 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/beacon-types/index.d.mts +441 -432
- package/dist/beacon-types/index.d.mts.map +1 -0
- package/dist/beacon-types/index.d.ts +441 -432
- package/dist/beacon-types/index.d.ts.map +1 -0
- package/dist/beacon-types/index.js +198 -182
- package/dist/beacon-types/index.mjs +197 -179
- 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 +80 -75
- package/dist/browser-posture.d.mts.map +1 -0
- package/dist/browser-posture.d.ts +80 -75
- package/dist/browser-posture.d.ts.map +1 -0
- package/dist/browser-posture.js +159 -18993
- package/dist/browser-posture.mjs +158 -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 +14895 -14240
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +14895 -14240
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/beacon-types/index.ts"],"mappings":";YAOY;YACA,YAAY,gBAAgB;GAAiB,cAAc;;YAC3D,kBAAkB;YAClB,kBAAkB;YAClB,mBAAmB,eAAe;YAClC,gBAAgB,sBAAsB;YACtC;wBA0DI,iBAAiB,iBAAiB,SAAS;iBA+C1C,+BAA+B;EAC9C;EACA;EACA;EACA;EACA;;iBAGe,wCAAwC;EACvD,aAAa;EACb,gBAAgB;EAChB,mBAAmB;EACnB;EACA;EACA;EACA;;iBAGe,iCAAiC;EAChD;EACA;IACE;;;iBAIa;EACf,gBAAgB;EAChB,aAAa;;iBAGE,+BAA+B;EAC9C;IACE,aACE,cACA;MACE,mBAAmB;MACnB,gBAAgB;QAEjB;;;iBAIU;EACf;EACA;EACA;;iBAGe,8BAA8B;EAC7C,SAAS;EACT,uCAAuC;;iBAGxB,oCAAoC;EACnD;EACA;;iBAiBe;EAKf;;iBAGe;EAEf;EAOA,WAAW;EAaX;EAGA;EAGA,OAAO;EAQP;EAOA;EAOA;EAOA;EASA;EAcA;EAcA;EAUA;EAQA;EASA;EAOA;EAOA;EAWA;EAOA;EAOA;EAOA;EASA;EAUA;EAMA;EAQA;EAOA,eAAe;EAWf;;iBAOe;EAEf,MAAM;EAGN,MAAM;EAGN,UAAU;;iBAGK;EAEf;EAGA;EAGA;EAGA,WAAW;GAGV;;iBAOc;EAIf,QAAQ,mBAAmB,OAAO,gBAAgB;EAKlD,WAAW,mBAAmB,YAAY,gBAAgB;EAK1D,cAAc,WAAW,gBAAgB;EAKzC,mBAAmB;EAKnB,aAAa,SAAS,QAAQ;EAK9B,WAAW;;iBAOI;EAEf;EAGA;EAGA;IACE;IACA;;;iBAQa;EAEf;IACE;IACA;IACA;;EAIF;IACE;IACA;;EAIF;IACE;IACA;IACA;;EAIF;IACE;IACA;IACA;IACA;;EAIF;IACE;IACA;IACA;IACA;IACA;;;iBAQa;EAEf;EAGA;EAGA;EAGA;EAGA;EAGA;EAGA;EAGA;EAGA;EAGA;IACE;IACA;IACA;IACA;IACA;;;iBAQa;EAEf;EAGA;EAGA;EAGA;EAGA;EAGA;EAGA;;iBAOe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;;iBAGe;EACf;EACA;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;;YAGU;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA,OAAO;EACP;EACA;EACA;EACA;;YAGU;iBAUK;EACf;EACA;EACA;EACA;EACA;;YAOU;YACA;YAWA;YAQA;iBAEK;EACf;EACA;EACA;EACA,UAAU;EACV;EACA;EACA,WAAW;EACX;;YAGU;YAUA;iBAEK;EACf;EACA;EACA;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;;iBAGK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;IACA;;EAEF;IACE;IACA;;;iBAIa;EACf;EACA;EACA,MAAM;EACN;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;;iBAGe;EACf;IACE;IACA;IACA;;EAEF;IACE;IACA;;EAEF;IACE;IACA;IACA;IACA;;EAEF;;iBAGe;EACf;EACA;EACA;EACA;EACA,gBAAgB;EAChB;EACA;EACA;;YAGU;YAWA;iBAEK;EACf,MAAM;EACN,OAAO;EACP,UAAU;EACV;EACA;EACA;;iBAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAWA;;iBAOe;EACf;EACA;EACA;;YAGU;iBAEK;EACf;EACA;EACA;EACA;EACA;;iBAOe;EACf;EACA,QAAQ;EACR;EACA;EACA;EACA;;iBAOe;EACf;EACA,QAAQ;EACR;EACA;EACA;EAEA;EAEA;EAEA;;iBAGe;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EAGA;EACA;GAGC;;YAGS;wBAYI,mBAAmB,iBAAiB;wBAWpC,0BAA0B,iBAAiB;wBAS3C,uBAAuB,iBAAiB;wBAgBxC,yBAAyB,iBAAiB;wBA8C1C,mBAAmB,iBAAiB;wBAkBpC,iBAAiB,iBAAiB;wBAclC,sBAAsB,iBAAiB;wBAcvC,mBAAmB,iBAAiB;qBAUvC;gBAAA;;qBAIA;gBAAA;;wBAIG,wBAAwB,iBAAiB;wBA0BzC,kBAAkB,iBAAiB;qBAsD9B,6BAA6B;EACpC,YAAA,QAAQ;EACpB,QAAQ,mBAAmB,OAAO,gBAAgB;EAClD,WAAW,mBAAmB,YAAY,gBAAgB;EAC1D,cAAc,WAAW,gBAAgB;EACzC,mBAAmB;EACnB,aAAa,SAAS,QAAQ;EAC9B,WAAW"}
|
|
@@ -1,226 +1,242 @@
|
|
|
1
|
-
'
|
|
2
|
-
|
|
3
|
-
// src/beacon-types/index.ts
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region src/beacon-types/index.ts
|
|
4
3
|
function isRecord(input) {
|
|
5
|
-
|
|
4
|
+
return typeof input === "object" && input !== null && !Array.isArray(input);
|
|
6
5
|
}
|
|
7
6
|
function toRecord(input) {
|
|
8
|
-
|
|
7
|
+
return isRecord(input) ? input : {};
|
|
9
8
|
}
|
|
10
9
|
function numberOr(value, fallback) {
|
|
11
|
-
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) && value !== 0 ? value : fallback;
|
|
12
11
|
}
|
|
13
12
|
function stringOr(value, fallback) {
|
|
14
|
-
|
|
13
|
+
return typeof value === "string" ? value : fallback;
|
|
15
14
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
function isStringArray(value) {
|
|
16
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Non-empty on purpose: an empty schedule would mean "zero posture-recovery
|
|
20
|
+
* attempts", silently disabling recovery rather than configuring it. A
|
|
21
|
+
* deployment that actually wants no retries sets `flushInterval` instead.
|
|
22
|
+
*/
|
|
23
|
+
function isPositiveNumberArray(value) {
|
|
24
|
+
return Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "number" && Number.isFinite(entry) && entry > 0);
|
|
20
25
|
}
|
|
26
|
+
function isBeaconTags(value) {
|
|
27
|
+
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Exported because `parseBeaconConfig` is an allowlist: a key it does not
|
|
31
|
+
* name is dropped, silently. The beacon's other public entry point
|
|
32
|
+
* (`checkpoint-shared/browser`) carries its own copy of that allowlist, so
|
|
33
|
+
* the CHECK at least lives in one place even while the two parsers do not —
|
|
34
|
+
* see the note on `BeaconConfig.identity`.
|
|
35
|
+
*
|
|
36
|
+
* Rejects an identity with no usable `userId` rather than passing through a
|
|
37
|
+
* half-formed object: downstream this becomes `detections.user_id`, and an
|
|
38
|
+
* empty string there is worse than an absent one — it reads as "identified"
|
|
39
|
+
* while naming nobody.
|
|
40
|
+
*/
|
|
21
41
|
function isBeaconIdentity(value) {
|
|
22
|
-
|
|
42
|
+
return isRecord(value) && typeof value.userId === "string" && value.userId.length > 0;
|
|
23
43
|
}
|
|
24
44
|
function isLogLevel(value) {
|
|
25
|
-
|
|
45
|
+
return value === "error" || value === "warn" || value === "info" || value === "debug";
|
|
26
46
|
}
|
|
27
47
|
function isBeaconWorkerMessageType(value) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
return value === "init" || value === "collect" || value === "flush" || value === "config" || value === "status" || value === "error" || value === "response" || value === "posture";
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves whether a beacon should use its Web Worker transport.
|
|
52
|
+
*
|
|
53
|
+
* `enableWebWorker` is accepted as an alias for `useWorker`: the package's
|
|
54
|
+
* own test suite (`checkpoint-beacon/src/index.test.ts`) has always
|
|
55
|
+
* constructed with `enableWebWorker: false`, but `parseBeaconConfig`'s
|
|
56
|
+
* allowlist only ever named `useWorker`, so that key was silently dropped —
|
|
57
|
+
* the beacon kept auto-detecting worker support regardless of what the
|
|
58
|
+
* caller passed. `useWorker` wins when both are set, since it's the
|
|
59
|
+
* canonical name every other config field (`workerUrl`, `workerConfig`)
|
|
60
|
+
* pairs with.
|
|
61
|
+
*/
|
|
34
62
|
function resolveUseWorker(config) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (typeof config.enableWebWorker === "boolean") {
|
|
39
|
-
return config.enableWebWorker;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
63
|
+
if (typeof config.useWorker === "boolean") return config.useWorker;
|
|
64
|
+
if (typeof config.enableWebWorker === "boolean") return config.enableWebWorker;
|
|
65
|
+
return true;
|
|
42
66
|
}
|
|
43
67
|
function parseRetryStrategy(input) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
const strategy = toRecord(input);
|
|
69
|
+
return {
|
|
70
|
+
maxAttempts: numberOr(strategy.maxAttempts, 3),
|
|
71
|
+
baseDelay: numberOr(strategy.baseDelay, 1e3),
|
|
72
|
+
maxDelay: numberOr(strategy.maxDelay, 3e4),
|
|
73
|
+
factor: numberOr(strategy.factor, 2),
|
|
74
|
+
jitter: strategy.jitter !== false
|
|
75
|
+
};
|
|
52
76
|
}
|
|
53
77
|
function parseCircuitBreakerConfig(input) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
const config = toRecord(input);
|
|
79
|
+
return {
|
|
80
|
+
threshold: numberOr(config.threshold, 5),
|
|
81
|
+
timeout: numberOr(config.timeout, 6e4),
|
|
82
|
+
resetTimeout: numberOr(config.resetTimeout, 3e4)
|
|
83
|
+
};
|
|
60
84
|
}
|
|
61
85
|
function parseOfflineQueueEntry(input) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
retryCount: numberOr(entry.retryCount, 0),
|
|
73
|
-
size: numberOr(entry.size, 0)
|
|
74
|
-
};
|
|
86
|
+
if (!isRecord(input)) throw new Error("Invalid offline queue entry");
|
|
87
|
+
const entry = input;
|
|
88
|
+
return {
|
|
89
|
+
id: stringOr(entry.id, `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`),
|
|
90
|
+
events: Array.isArray(entry.events) ? entry.events : [],
|
|
91
|
+
timestamp: numberOr(entry.timestamp, Date.now()),
|
|
92
|
+
expiresAt: numberOr(entry.expiresAt, Date.now() + 864e5),
|
|
93
|
+
retryCount: numberOr(entry.retryCount, 0),
|
|
94
|
+
size: numberOr(entry.size, 0)
|
|
95
|
+
};
|
|
75
96
|
}
|
|
76
97
|
function parseBeaconWorkerMessage(input) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
id: stringOr(msg.id, messageId)
|
|
89
|
-
};
|
|
98
|
+
if (!isRecord(input)) throw new Error("Invalid beacon worker message");
|
|
99
|
+
const msg = input;
|
|
100
|
+
const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ?? crypto.randomUUID();
|
|
101
|
+
return {
|
|
102
|
+
type: isBeaconWorkerMessageType(msg.type) ? msg.type : "init",
|
|
103
|
+
data: msg.data,
|
|
104
|
+
payload: msg.payload,
|
|
105
|
+
messageId,
|
|
106
|
+
timestamp: numberOr(msg.timestamp, Date.now()),
|
|
107
|
+
id: stringOr(msg.id, messageId)
|
|
108
|
+
};
|
|
90
109
|
}
|
|
91
110
|
function isMessagePriority(value) {
|
|
92
|
-
|
|
111
|
+
return value === "low" || value === "normal" || value === "high" || value === "critical";
|
|
93
112
|
}
|
|
94
113
|
function isWorkerMessageType(value) {
|
|
95
|
-
|
|
114
|
+
return value === "request" || value === "response" || value === "error" || value === "heartbeat" || value === "status";
|
|
96
115
|
}
|
|
97
116
|
function isWorkerErrorType(value) {
|
|
98
|
-
|
|
117
|
+
return value === "initialization" || value === "runtime" || value === "communication" || value === "timeout" || value === "memory" || value === "network" || value === "permission" || value === "validation" || value === "processing" || value === "unknown";
|
|
99
118
|
}
|
|
100
119
|
function parseWorkerMessage(input) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
correlationId: msg.correlationId
|
|
114
|
-
};
|
|
120
|
+
const msg = input && typeof input === "object" ? input : null;
|
|
121
|
+
if (!msg) throw new Error("Invalid worker message");
|
|
122
|
+
return {
|
|
123
|
+
id: msg.id || crypto.randomUUID(),
|
|
124
|
+
type: isWorkerMessageType(msg.type) ? msg.type : "request",
|
|
125
|
+
action: msg.action,
|
|
126
|
+
payload: msg.payload,
|
|
127
|
+
timestamp: msg.timestamp || Date.now(),
|
|
128
|
+
compressed: msg.compressed,
|
|
129
|
+
priority: isMessagePriority(msg.priority) ? msg.priority : "normal",
|
|
130
|
+
correlationId: msg.correlationId
|
|
131
|
+
};
|
|
115
132
|
}
|
|
116
133
|
function parseWorkerError(input) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
const error = input && typeof input === "object" ? input : {};
|
|
135
|
+
return {
|
|
136
|
+
type: isWorkerErrorType(error.type) ? error.type : "unknown",
|
|
137
|
+
code: typeof error.code === "string" ? error.code : void 0,
|
|
138
|
+
message: typeof error.message === "string" ? error.message : "Worker error",
|
|
139
|
+
stack: typeof error.stack === "string" ? error.stack : void 0,
|
|
140
|
+
timestamp: typeof error.timestamp === "number" ? error.timestamp : Date.now(),
|
|
141
|
+
recoverable: error.recoverable !== false,
|
|
142
|
+
retryAfter: typeof error.retryAfter === "number" ? error.retryAfter : void 0,
|
|
143
|
+
context: error.context
|
|
144
|
+
};
|
|
128
145
|
}
|
|
129
146
|
function parseWorkerPoolConfig(input) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
const config = input && typeof input === "object" ? input : {};
|
|
148
|
+
return {
|
|
149
|
+
maxWorkers: config.maxWorkers ?? 4,
|
|
150
|
+
minWorkers: config.minWorkers ?? 1,
|
|
151
|
+
workerIdleTimeout: config.workerIdleTimeout ?? 3e4,
|
|
152
|
+
taskQueueSize: config.taskQueueSize ?? 100,
|
|
153
|
+
resourceLimits: config.resourceLimits ?? {},
|
|
154
|
+
autoScale: config.autoScale ?? true,
|
|
155
|
+
scaleUpThreshold: config.scaleUpThreshold ?? 75,
|
|
156
|
+
scaleDownThreshold: config.scaleDownThreshold ?? 25
|
|
157
|
+
};
|
|
141
158
|
}
|
|
142
159
|
function parseResourceUsage(input) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
const usage = input && typeof input === "object" ? input : {};
|
|
161
|
+
return {
|
|
162
|
+
memory: usage.memory ?? {
|
|
163
|
+
used: 0,
|
|
164
|
+
limit: 0,
|
|
165
|
+
percentage: 0
|
|
166
|
+
},
|
|
167
|
+
cpu: usage.cpu ?? {
|
|
168
|
+
usage: 0,
|
|
169
|
+
limit: 100
|
|
170
|
+
},
|
|
171
|
+
tasks: usage.tasks ?? {
|
|
172
|
+
pending: 0,
|
|
173
|
+
active: 0,
|
|
174
|
+
completed: 0,
|
|
175
|
+
failed: 0
|
|
176
|
+
},
|
|
177
|
+
activeWorkers: usage.activeWorkers ?? 0
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const ResourceUsageSchema = { parse: parseResourceUsage };
|
|
181
|
+
const WorkerPoolConfigSchema = { parse: parseWorkerPoolConfig };
|
|
157
182
|
function parseWorkerCapabilities(input) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
const cap = toRecord(input);
|
|
184
|
+
const csp = toRecord(cap.csp);
|
|
185
|
+
const performance = toRecord(cap.performance);
|
|
186
|
+
return {
|
|
187
|
+
workerAPI: cap.workerAPI !== false,
|
|
188
|
+
sharedArrayBuffer: cap.sharedArrayBuffer === true,
|
|
189
|
+
transferableObjects: cap.transferableObjects === true,
|
|
190
|
+
offscreenCanvas: cap.offscreenCanvas === true,
|
|
191
|
+
webAssembly: cap.webAssembly === true,
|
|
192
|
+
atomics: cap.atomics === true,
|
|
193
|
+
bigInt: cap.bigInt === true,
|
|
194
|
+
csp: {
|
|
195
|
+
workerSrc: csp.workerSrc === true,
|
|
196
|
+
scriptSrc: csp.scriptSrc === true,
|
|
197
|
+
blobUrls: csp.blobUrls === true,
|
|
198
|
+
inlineWorkers: csp.inlineWorkers === true
|
|
199
|
+
},
|
|
200
|
+
performance: {
|
|
201
|
+
memory: performance.memory === true,
|
|
202
|
+
measureUserAgentSpecificMemory: performance.measureUserAgentSpecificMemory === true
|
|
203
|
+
}
|
|
204
|
+
};
|
|
180
205
|
}
|
|
181
206
|
function parseBeaconConfig(input) {
|
|
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
|
-
// checkpoint-beacon (wrong direction of the package dependency graph).
|
|
213
|
-
collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
|
|
214
|
-
maxQueueSize: numberOr(config.maxQueueSize, 100),
|
|
215
|
-
retryAttempts: numberOr(config.retryAttempts, 3),
|
|
216
|
-
retryDelay: numberOr(config.retryDelay, 2e3),
|
|
217
|
-
useWorker: resolveUseWorker(config),
|
|
218
|
-
workerUrl: stringOr(config.workerUrl),
|
|
219
|
-
workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
|
|
220
|
-
lazySignalsUrl: stringOr(config.lazySignalsUrl)
|
|
221
|
-
};
|
|
207
|
+
const config = toRecord(input);
|
|
208
|
+
if (typeof config.projectId !== "string" || config.projectId.length === 0) throw new Error("Project ID is required");
|
|
209
|
+
return {
|
|
210
|
+
projectId: config.projectId,
|
|
211
|
+
environment: stringOr(config.environment),
|
|
212
|
+
tags: isBeaconTags(config.tags) ? config.tags : void 0,
|
|
213
|
+
identity: isBeaconIdentity(config.identity) ? config.identity : void 0,
|
|
214
|
+
endpoint: stringOr(config.endpoint),
|
|
215
|
+
enabled: config.enabled !== false,
|
|
216
|
+
debug: config.debug === true,
|
|
217
|
+
logLevel: isLogLevel(config.logLevel) ? config.logLevel : "error",
|
|
218
|
+
respectDoNotTrack: config.respectDoNotTrack !== false,
|
|
219
|
+
anonymizeIp: config.anonymizeIp === true,
|
|
220
|
+
stripUrlFragment: config.stripUrlFragment !== false,
|
|
221
|
+
scrubQueryParams: isStringArray(config.scrubQueryParams) ? config.scrubQueryParams : void 0,
|
|
222
|
+
dropQueryParams: config.dropQueryParams === true,
|
|
223
|
+
sessionTimeout: numberOr(config.sessionTimeout, 18e5),
|
|
224
|
+
sessionCookieName: stringOr(config.sessionCookieName, "_as_beacon_session"),
|
|
225
|
+
batchSize: numberOr(config.batchSize, 10),
|
|
226
|
+
flushInterval: numberOr(config.flushInterval, 5e3),
|
|
227
|
+
collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
|
|
228
|
+
maxQueueSize: numberOr(config.maxQueueSize, 100),
|
|
229
|
+
retryAttempts: numberOr(config.retryAttempts, 3),
|
|
230
|
+
retryDelay: numberOr(config.retryDelay, 2e3),
|
|
231
|
+
postureRetryScheduleMs: isPositiveNumberArray(config.postureRetryScheduleMs) ? config.postureRetryScheduleMs : void 0,
|
|
232
|
+
useWorker: resolveUseWorker(config),
|
|
233
|
+
workerUrl: stringOr(config.workerUrl),
|
|
234
|
+
workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
|
|
235
|
+
lazySignalsUrl: stringOr(config.lazySignalsUrl)
|
|
236
|
+
};
|
|
222
237
|
}
|
|
223
238
|
|
|
239
|
+
//#endregion
|
|
224
240
|
exports.ResourceUsageSchema = ResourceUsageSchema;
|
|
225
241
|
exports.WorkerPoolConfigSchema = WorkerPoolConfigSchema;
|
|
226
242
|
exports.isBeaconIdentity = isBeaconIdentity;
|
|
@@ -233,4 +249,4 @@ exports.parseRetryStrategy = parseRetryStrategy;
|
|
|
233
249
|
exports.parseWorkerCapabilities = parseWorkerCapabilities;
|
|
234
250
|
exports.parseWorkerError = parseWorkerError;
|
|
235
251
|
exports.parseWorkerMessage = parseWorkerMessage;
|
|
236
|
-
exports.parseWorkerPoolConfig = parseWorkerPoolConfig;
|
|
252
|
+
exports.parseWorkerPoolConfig = parseWorkerPoolConfig;
|