@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.
Files changed (161) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/beacon-types/index.d.mts +448 -432
  3. package/dist/beacon-types/index.d.mts.map +1 -0
  4. package/dist/beacon-types/index.d.ts +448 -432
  5. package/dist/beacon-types/index.d.ts.map +1 -0
  6. package/dist/beacon-types/index.js +286 -182
  7. package/dist/beacon-types/index.mjs +284 -180
  8. package/dist/beacon-types/index.mjs.map +1 -0
  9. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
  10. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
  11. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
  12. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
  13. package/dist/browser-posture-cookie.d.mts +2 -0
  14. package/dist/browser-posture-cookie.d.ts +2 -0
  15. package/dist/browser-posture-cookie.js +1 -0
  16. package/dist/browser-posture-cookie.mjs +2 -0
  17. package/dist/browser-posture-cookie.mjs.map +1 -0
  18. package/dist/browser-posture-report.d.mts +48 -44
  19. package/dist/browser-posture-report.d.mts.map +1 -0
  20. package/dist/browser-posture-report.d.ts +48 -44
  21. package/dist/browser-posture-report.d.ts.map +1 -0
  22. package/dist/browser-posture-report.js +1 -1
  23. package/dist/browser-posture-report.mjs +2 -1
  24. package/dist/browser-posture-report.mjs.map +1 -0
  25. package/dist/browser-posture.d.mts +82 -75
  26. package/dist/browser-posture.d.mts.map +1 -0
  27. package/dist/browser-posture.d.ts +82 -75
  28. package/dist/browser-posture.d.ts.map +1 -0
  29. package/dist/browser-posture.js +167 -18993
  30. package/dist/browser-posture.mjs +166 -18990
  31. package/dist/browser-posture.mjs.map +1 -0
  32. package/dist/browser.d.mts +323 -316
  33. package/dist/browser.d.mts.map +1 -0
  34. package/dist/browser.d.ts +323 -316
  35. package/dist/browser.d.ts.map +1 -0
  36. package/dist/browser.js +1 -1
  37. package/dist/browser.mjs +2 -1
  38. package/dist/browser.mjs.map +1 -0
  39. package/dist/canonical-signer/index.d.mts +38 -33
  40. package/dist/canonical-signer/index.d.mts.map +1 -0
  41. package/dist/canonical-signer/index.d.ts +38 -33
  42. package/dist/canonical-signer/index.d.ts.map +1 -0
  43. package/dist/canonical-signer/index.js +411 -181
  44. package/dist/canonical-signer/index.mjs +383 -175
  45. package/dist/canonical-signer/index.mjs.map +1 -0
  46. package/dist/clearance.d.mts +30 -0
  47. package/dist/clearance.d.mts.map +1 -0
  48. package/dist/clearance.d.ts +30 -0
  49. package/dist/clearance.d.ts.map +1 -0
  50. package/dist/clearance.js +120 -0
  51. package/dist/clearance.mjs +112 -0
  52. package/dist/clearance.mjs.map +1 -0
  53. package/dist/client-ip-1y2iXAYW.js +237 -0
  54. package/dist/client-ip-HOfe6ucV.mjs +215 -0
  55. package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
  56. package/dist/deploy/index.d.mts +339 -339
  57. package/dist/deploy/index.d.mts.map +1 -0
  58. package/dist/deploy/index.d.ts +339 -339
  59. package/dist/deploy/index.d.ts.map +1 -0
  60. package/dist/deploy/index.js +505 -413
  61. package/dist/deploy/index.mjs +504 -410
  62. package/dist/deploy/index.mjs.map +1 -0
  63. package/dist/errors/index.d.mts +101 -101
  64. package/dist/errors/index.d.mts.map +1 -0
  65. package/dist/errors/index.d.ts +101 -101
  66. package/dist/errors/index.d.ts.map +1 -0
  67. package/dist/errors/index.js +341 -314
  68. package/dist/errors/index.mjs +340 -311
  69. package/dist/errors/index.mjs.map +1 -0
  70. package/dist/external-jr_S4iSS.d.mts +4187 -0
  71. package/dist/external-jr_S4iSS.d.mts.map +1 -0
  72. package/dist/external-jr_S4iSS.d.ts +4187 -0
  73. package/dist/external-jr_S4iSS.d.ts.map +1 -0
  74. package/dist/gateway/index.d.mts +138 -132
  75. package/dist/gateway/index.d.mts.map +1 -0
  76. package/dist/gateway/index.d.ts +138 -132
  77. package/dist/gateway/index.d.ts.map +1 -0
  78. package/dist/gateway/index.js +117 -81
  79. package/dist/gateway/index.mjs +116 -78
  80. package/dist/gateway/index.mjs.map +1 -0
  81. package/dist/gateway-client-ip.d.mts +59 -0
  82. package/dist/gateway-client-ip.d.mts.map +1 -0
  83. package/dist/gateway-client-ip.d.ts +59 -0
  84. package/dist/gateway-client-ip.d.ts.map +1 -0
  85. package/dist/gateway-client-ip.js +149 -0
  86. package/dist/gateway-client-ip.mjs +139 -0
  87. package/dist/gateway-client-ip.mjs.map +1 -0
  88. package/dist/index.d.mts +14901 -14246
  89. package/dist/index.d.mts.map +1 -0
  90. package/dist/index.d.ts +14901 -14246
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +15180 -31025
  93. package/dist/index.mjs +15065 -30942
  94. package/dist/index.mjs.map +1 -0
  95. package/dist/mcpi/agentshield-api/index.d.mts +45 -44
  96. package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
  97. package/dist/mcpi/agentshield-api/index.d.ts +45 -44
  98. package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
  99. package/dist/mcpi/agentshield-api/index.js +0 -2
  100. package/dist/mcpi/agentshield-api/index.mjs +1 -1
  101. package/dist/mcpi/approval-grant/index.d.mts +63 -61
  102. package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
  103. package/dist/mcpi/approval-grant/index.d.ts +63 -61
  104. package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
  105. package/dist/mcpi/approval-grant/index.js +220 -140
  106. package/dist/mcpi/approval-grant/index.mjs +219 -137
  107. package/dist/mcpi/approval-grant/index.mjs.map +1 -0
  108. package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
  109. package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
  110. package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
  111. package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
  112. package/dist/mcpi/dashboard-config/index.js +605 -458
  113. package/dist/mcpi/dashboard-config/index.mjs +604 -455
  114. package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
  115. package/dist/mcpi/multibase-ed25519.d.mts +10 -8
  116. package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
  117. package/dist/mcpi/multibase-ed25519.d.ts +10 -8
  118. package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
  119. package/dist/mcpi/multibase-ed25519.js +182 -106
  120. package/dist/mcpi/multibase-ed25519.mjs +181 -103
  121. package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
  122. package/dist/patterns-CkRVOdtV.js +243 -0
  123. package/dist/patterns-DzkGy_qk.mjs +173 -0
  124. package/dist/patterns-DzkGy_qk.mjs.map +1 -0
  125. package/dist/project-verification-key-C3L5rd8a.js +41 -0
  126. package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
  127. package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
  128. package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
  129. package/dist/schemas-BmjNLAE7.js +5677 -0
  130. package/dist/schemas-DxY-dk9y.mjs +5511 -0
  131. package/dist/schemas-DxY-dk9y.mjs.map +1 -0
  132. package/dist/signals/index.d.mts +125 -115
  133. package/dist/signals/index.d.mts.map +1 -0
  134. package/dist/signals/index.d.ts +125 -115
  135. package/dist/signals/index.d.ts.map +1 -0
  136. package/dist/signals/index.js +1693 -1536
  137. package/dist/signals/index.mjs +1692 -1533
  138. package/dist/signals/index.mjs.map +1 -0
  139. package/dist/test-fixtures/index.d.mts +124 -119
  140. package/dist/test-fixtures/index.d.mts.map +1 -0
  141. package/dist/test-fixtures/index.d.ts +124 -119
  142. package/dist/test-fixtures/index.d.ts.map +1 -0
  143. package/dist/test-fixtures/index.js +460 -228
  144. package/dist/test-fixtures/index.mjs +459 -225
  145. package/dist/test-fixtures/index.mjs.map +1 -0
  146. package/dist/tool-protection/index.d.mts +343 -343
  147. package/dist/tool-protection/index.d.mts.map +1 -0
  148. package/dist/tool-protection/index.d.ts +343 -343
  149. package/dist/tool-protection/index.d.ts.map +1 -0
  150. package/dist/tool-protection/index.js +366 -285
  151. package/dist/tool-protection/index.mjs +365 -282
  152. package/dist/tool-protection/index.mjs.map +1 -0
  153. package/fixtures/bot-signal-resolution.json +142 -0
  154. package/fixtures/browser-posture-claims.json +421 -0
  155. package/fixtures/browser-posture-headers.json +46 -0
  156. package/fixtures/detection/reason-codes.json +10 -1
  157. package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
  158. package/fixtures/kya-http/challenge.delegation.full.json +9 -3
  159. package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
  160. package/fixtures/kya-http/error-codes.json +7 -2
  161. package/package.json +20 -6
@@ -1,222 +1,326 @@
1
- // src/beacon-types/index.ts
1
+ //#region src/beacon-types/index.ts
2
2
  function isRecord(input) {
3
- return typeof input === "object" && input !== null && !Array.isArray(input);
3
+ return typeof input === "object" && input !== null && !Array.isArray(input);
4
4
  }
5
5
  function toRecord(input) {
6
- return isRecord(input) ? input : {};
6
+ return isRecord(input) ? input : {};
7
7
  }
8
8
  function numberOr(value, fallback) {
9
- return typeof value === "number" && Number.isFinite(value) && value !== 0 ? value : fallback;
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
- return typeof value === "string" ? value : fallback;
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
- return isRecord(value) && Object.values(value).every(
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
- return isRecord(value) && typeof value.userId === "string" && value.userId.length > 0;
99
+ return isRecord(value) && typeof value.userId === "string" && value.userId.length > 0;
21
100
  }
22
101
  function isLogLevel(value) {
23
- return value === "error" || value === "warn" || value === "info" || value === "debug";
102
+ return value === "error" || value === "warn" || value === "info" || value === "debug";
24
103
  }
25
104
  function isBeaconWorkerMessageType(value) {
26
- return value === "init" || value === "collect" || value === "flush" || value === "config" || value === "status" || value === "error" || // `beacon.worker.ts`'s `respond()` has always sent this on every
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
- if (typeof config.useWorker === "boolean") {
34
- return config.useWorker;
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
- const strategy = toRecord(input);
43
- return {
44
- maxAttempts: numberOr(strategy.maxAttempts, 3),
45
- baseDelay: numberOr(strategy.baseDelay, 1e3),
46
- maxDelay: numberOr(strategy.maxDelay, 3e4),
47
- factor: numberOr(strategy.factor, 2),
48
- jitter: strategy.jitter !== false
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
- const config = toRecord(input);
53
- return {
54
- threshold: numberOr(config.threshold, 5),
55
- timeout: numberOr(config.timeout, 6e4),
56
- resetTimeout: numberOr(config.resetTimeout, 3e4)
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
- if (!isRecord(input)) {
61
- throw new Error("Invalid offline queue entry");
62
- }
63
- const entry = input;
64
- return {
65
- id: stringOr(entry.id, `${Date.now()}_${Math.random().toString(36).substr(2, 9)}`),
66
- events: Array.isArray(entry.events) ? entry.events : [],
67
- timestamp: numberOr(entry.timestamp, Date.now()),
68
- expiresAt: numberOr(entry.expiresAt, Date.now() + 864e5),
69
- // 24 hours
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
- if (!isRecord(input)) {
76
- throw new Error("Invalid beacon worker message");
77
- }
78
- const msg = input;
79
- const messageId = stringOr(msg.messageId) ?? stringOr(msg.id) ?? crypto.randomUUID();
80
- return {
81
- type: isBeaconWorkerMessageType(msg.type) ? msg.type : "init",
82
- data: msg.data,
83
- payload: msg.payload,
84
- messageId,
85
- timestamp: numberOr(msg.timestamp, Date.now()),
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
- return value === "low" || value === "normal" || value === "high" || value === "critical";
168
+ return value === "low" || value === "normal" || value === "high" || value === "critical";
91
169
  }
92
170
  function isWorkerMessageType(value) {
93
- return value === "request" || value === "response" || value === "error" || value === "heartbeat" || value === "status";
171
+ return value === "request" || value === "response" || value === "error" || value === "heartbeat" || value === "status";
94
172
  }
95
173
  function isWorkerErrorType(value) {
96
- return value === "initialization" || value === "runtime" || value === "communication" || value === "timeout" || value === "memory" || value === "network" || value === "permission" || value === "validation" || value === "processing" || value === "unknown";
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
- const msg = input && typeof input === "object" ? input : null;
100
- if (!msg) {
101
- throw new Error("Invalid worker message");
102
- }
103
- return {
104
- id: msg.id || crypto.randomUUID(),
105
- type: isWorkerMessageType(msg.type) ? msg.type : "request",
106
- action: msg.action,
107
- payload: msg.payload,
108
- timestamp: msg.timestamp || Date.now(),
109
- compressed: msg.compressed,
110
- priority: isMessagePriority(msg.priority) ? msg.priority : "normal",
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
- const error = input && typeof input === "object" ? input : {};
116
- return {
117
- type: isWorkerErrorType(error.type) ? error.type : "unknown",
118
- code: typeof error.code === "string" ? error.code : void 0,
119
- message: typeof error.message === "string" ? error.message : "Worker error",
120
- stack: typeof error.stack === "string" ? error.stack : void 0,
121
- timestamp: typeof error.timestamp === "number" ? error.timestamp : Date.now(),
122
- recoverable: error.recoverable !== false,
123
- retryAfter: typeof error.retryAfter === "number" ? error.retryAfter : void 0,
124
- context: error.context
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
- const config = input && typeof input === "object" ? input : {};
129
- return {
130
- maxWorkers: config.maxWorkers ?? 4,
131
- minWorkers: config.minWorkers ?? 1,
132
- workerIdleTimeout: config.workerIdleTimeout ?? 3e4,
133
- taskQueueSize: config.taskQueueSize ?? 100,
134
- resourceLimits: config.resourceLimits ?? {},
135
- autoScale: config.autoScale ?? true,
136
- scaleUpThreshold: config.scaleUpThreshold ?? 75,
137
- scaleDownThreshold: config.scaleDownThreshold ?? 25
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
- const usage = input && typeof input === "object" ? input : {};
142
- return {
143
- memory: usage.memory ?? { used: 0, limit: 0, percentage: 0 },
144
- cpu: usage.cpu ?? { usage: 0, limit: 100 },
145
- tasks: usage.tasks ?? { pending: 0, active: 0, completed: 0, failed: 0 },
146
- activeWorkers: usage.activeWorkers ?? 0
147
- };
148
- }
149
- var ResourceUsageSchema = {
150
- parse: parseResourceUsage
151
- };
152
- var WorkerPoolConfigSchema = {
153
- parse: parseWorkerPoolConfig
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
- const cap = toRecord(input);
157
- const csp = toRecord(cap.csp);
158
- const performance = toRecord(cap.performance);
159
- return {
160
- workerAPI: cap.workerAPI !== false,
161
- sharedArrayBuffer: cap.sharedArrayBuffer === true,
162
- transferableObjects: cap.transferableObjects === true,
163
- offscreenCanvas: cap.offscreenCanvas === true,
164
- webAssembly: cap.webAssembly === true,
165
- atomics: cap.atomics === true,
166
- bigInt: cap.bigInt === true,
167
- csp: {
168
- workerSrc: csp.workerSrc === true,
169
- scriptSrc: csp.scriptSrc === true,
170
- blobUrls: csp.blobUrls === true,
171
- inlineWorkers: csp.inlineWorkers === true
172
- },
173
- performance: {
174
- memory: performance.memory === true,
175
- measureUserAgentSpecificMemory: performance.measureUserAgentSpecificMemory === true
176
- }
177
- };
178
- }
179
- function parseBeaconConfig(input) {
180
- const config = toRecord(input);
181
- if (typeof config.projectId !== "string" || config.projectId.length === 0) {
182
- throw new Error("Project ID is required");
183
- }
184
- return {
185
- projectId: config.projectId,
186
- environment: stringOr(config.environment),
187
- tags: isBeaconTags(config.tags) ? config.tags : void 0,
188
- identity: isBeaconIdentity(config.identity) ? config.identity : void 0,
189
- // `parseBeaconConfig` is an allowlist: a key it does not name is dropped
190
- // silently, which is how `identity` first shipped inert.
191
- endpoint: stringOr(config.endpoint),
192
- enabled: config.enabled !== false,
193
- debug: config.debug === true,
194
- logLevel: isLogLevel(config.logLevel) ? config.logLevel : "error",
195
- respectDoNotTrack: config.respectDoNotTrack !== false,
196
- anonymizeIp: config.anonymizeIp === true,
197
- sessionTimeout: numberOr(config.sessionTimeout, 18e5),
198
- // 30 minutes
199
- sessionCookieName: stringOr(config.sessionCookieName, "_as_beacon_session"),
200
- batchSize: numberOr(config.batchSize, 10),
201
- flushInterval: numberOr(config.flushInterval, 5e3),
202
- // 1600ms — see packages/checkpoint-beacon/src/budget/thresholds.ts
203
- // (MAX_PER_SOURCE_DEADLINE_MS) for the full measurement-backed rationale;
204
- // sized to sit just above the vendored FingerprintJS pipeline's own
205
- // already-ratified 1500ms TOTAL_COLLECTION_BUDGET_MS
206
- // (collectors/entropy/vendored-fingerprint.ts), so a future collector
207
- // wrapping that pipeline gets to use its own internal timeout instead
208
- // of being truncated one layer up before it fires. Keep these two
209
- // literals in sync; checkpoint-shared can't import from
210
- // checkpoint-beacon (wrong direction of the package dependency graph).
211
- collectorDeadlineMs: numberOr(config.collectorDeadlineMs, 1600),
212
- maxQueueSize: numberOr(config.maxQueueSize, 100),
213
- retryAttempts: numberOr(config.retryAttempts, 3),
214
- retryDelay: numberOr(config.retryDelay, 2e3),
215
- useWorker: resolveUseWorker(config),
216
- workerUrl: stringOr(config.workerUrl),
217
- workerConfig: isRecord(config.workerConfig) ? config.workerConfig : void 0,
218
- lazySignalsUrl: stringOr(config.lazySignalsUrl)
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
- export { ResourceUsageSchema, WorkerPoolConfigSchema, isBeaconIdentity, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig };
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