@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.
Files changed (141) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/dist/beacon-nonce/index.d.mts +36 -0
  3. package/dist/beacon-nonce/index.d.mts.map +1 -0
  4. package/dist/beacon-nonce/index.d.ts +36 -0
  5. package/dist/beacon-nonce/index.d.ts.map +1 -0
  6. package/dist/beacon-nonce/index.js +305 -0
  7. package/dist/beacon-nonce/index.mjs +294 -0
  8. package/dist/beacon-nonce/index.mjs.map +1 -0
  9. package/dist/beacon-types/index.d.mts +50 -14
  10. package/dist/beacon-types/index.d.mts.map +1 -1
  11. package/dist/beacon-types/index.d.ts +50 -14
  12. package/dist/beacon-types/index.d.ts.map +1 -1
  13. package/dist/beacon-types/index.js +127 -8
  14. package/dist/beacon-types/index.mjs +122 -9
  15. package/dist/beacon-types/index.mjs.map +1 -1
  16. package/dist/browser-posture-D4j2a5gi.d.ts +169 -0
  17. package/dist/browser-posture-D4j2a5gi.d.ts.map +1 -0
  18. package/dist/browser-posture-DVoHMHjY.d.mts +169 -0
  19. package/dist/browser-posture-DVoHMHjY.d.mts.map +1 -0
  20. package/dist/browser-posture-cookie.d.mts +4 -2
  21. package/dist/browser-posture-cookie.d.mts.map +1 -0
  22. package/dist/browser-posture-cookie.d.ts +4 -2
  23. package/dist/browser-posture-cookie.d.ts.map +1 -0
  24. package/dist/browser-posture-cookie.mjs.map +1 -1
  25. package/dist/browser-posture-proof.d.mts +18 -0
  26. package/dist/browser-posture-proof.d.mts.map +1 -0
  27. package/dist/browser-posture-proof.d.ts +18 -0
  28. package/dist/browser-posture-proof.d.ts.map +1 -0
  29. package/dist/browser-posture-proof.js +66 -0
  30. package/dist/browser-posture-proof.mjs +63 -0
  31. package/dist/browser-posture-proof.mjs.map +1 -0
  32. package/dist/browser-posture-report.d.mts +59 -2
  33. package/dist/browser-posture-report.d.mts.map +1 -1
  34. package/dist/browser-posture-report.d.ts +59 -2
  35. package/dist/browser-posture-report.d.ts.map +1 -1
  36. package/dist/browser-posture-report.js +1 -1
  37. package/dist/browser-posture-report.mjs +1 -1
  38. package/dist/browser-posture-report.mjs.map +1 -1
  39. package/dist/browser-posture.d.mts +2 -83
  40. package/dist/browser-posture.d.ts +2 -83
  41. package/dist/browser-posture.js +214 -44
  42. package/dist/browser-posture.mjs +203 -45
  43. package/dist/browser-posture.mjs.map +1 -1
  44. package/dist/browser.d.mts +3 -11
  45. package/dist/browser.d.mts.map +1 -1
  46. package/dist/browser.d.ts +3 -11
  47. package/dist/browser.d.ts.map +1 -1
  48. package/dist/browser.js +1 -1
  49. package/dist/browser.mjs +1 -1
  50. package/dist/browser.mjs.map +1 -1
  51. package/dist/clearance.d.mts +1 -1
  52. package/dist/clearance.d.ts +1 -1
  53. package/dist/{client-ip-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
  54. package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
  55. package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
  56. package/dist/consent-handoff.d.mts +41 -0
  57. package/dist/consent-handoff.d.mts.map +1 -0
  58. package/dist/consent-handoff.d.ts +41 -0
  59. package/dist/consent-handoff.d.ts.map +1 -0
  60. package/dist/consent-handoff.js +1 -0
  61. package/dist/consent-handoff.mjs +2 -0
  62. package/dist/consent-handoff.mjs.map +1 -0
  63. package/dist/errors/index.d.mts +138 -0
  64. package/dist/errors/index.d.mts.map +1 -1
  65. package/dist/errors/index.d.ts +138 -0
  66. package/dist/errors/index.d.ts.map +1 -1
  67. package/dist/errors/index.js +441 -9
  68. package/dist/errors/index.mjs +441 -10
  69. package/dist/errors/index.mjs.map +1 -1
  70. package/dist/{external-jr_S4iSS.d.mts → external-Ct8j_hto.d.mts} +2 -2
  71. package/dist/{external-jr_S4iSS.d.mts.map → external-Ct8j_hto.d.mts.map} +1 -1
  72. package/dist/{external-jr_S4iSS.d.ts → external-Ct8j_hto.d.ts} +2 -2
  73. package/dist/{external-jr_S4iSS.d.ts.map → external-Ct8j_hto.d.ts.map} +1 -1
  74. package/dist/gateway-client-ip.d.mts +1 -1
  75. package/dist/gateway-client-ip.d.ts +1 -1
  76. package/dist/gateway-client-ip.js +1 -1
  77. package/dist/gateway-client-ip.mjs +1 -1
  78. package/dist/index.d.mts +5227 -1063
  79. package/dist/index.d.mts.map +1 -1
  80. package/dist/index.d.ts +5227 -1063
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +3678 -546
  83. package/dist/index.mjs +3446 -534
  84. package/dist/index.mjs.map +1 -1
  85. package/dist/mcpi/approval-grant/index.d.mts +1 -1
  86. package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
  87. package/dist/mcpi/approval-grant/index.d.ts +1 -1
  88. package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
  89. package/dist/mcpi/approval-grant/index.js +48 -48
  90. package/dist/mcpi/approval-grant/index.mjs +48 -48
  91. package/dist/mcpi/approval-grant/index.mjs.map +1 -1
  92. package/dist/posture-origins/index.d.mts +41 -0
  93. package/dist/posture-origins/index.d.mts.map +1 -0
  94. package/dist/posture-origins/index.d.ts +41 -0
  95. package/dist/posture-origins/index.d.ts.map +1 -0
  96. package/dist/posture-origins/index.js +441 -0
  97. package/dist/posture-origins/index.mjs +430 -0
  98. package/dist/posture-origins/index.mjs.map +1 -0
  99. package/dist/posture-origins-CEm83u4D.js +621 -0
  100. package/dist/posture-origins-Dl7i8j93.mjs +533 -0
  101. package/dist/posture-origins-Dl7i8j93.mjs.map +1 -0
  102. package/dist/rules.json +0 -1
  103. package/dist/signals/index.d.mts +75 -55
  104. package/dist/signals/index.d.mts.map +1 -1
  105. package/dist/signals/index.d.ts +75 -55
  106. package/dist/signals/index.d.ts.map +1 -1
  107. package/dist/signals/index.js +246 -2
  108. package/dist/signals/index.mjs +236 -3
  109. package/dist/signals/index.mjs.map +1 -1
  110. package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
  111. package/fixtures/browser-integrity/null-score.json +11 -0
  112. package/fixtures/browser-integrity/numeric-score.json +11 -0
  113. package/fixtures/browser-posture-claims.json +168 -0
  114. package/fixtures/browser-posture-headers.json +6 -0
  115. package/fixtures/kya-http/README.md +1 -0
  116. package/fixtures/kya-http/consent-handoff.codes.json +34 -0
  117. package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
  118. package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
  119. package/fixtures/workbench/delegation-management.v1.json +507 -0
  120. package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
  121. package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
  122. package/fixtures/workbench/identity-provisioning.v1.json +643 -0
  123. package/fixtures/workbench/linear-installation.v1.json +484 -0
  124. package/fixtures/workbench/management-session.v1.json +716 -0
  125. package/fixtures/workbench/model-credentials.v1.json +630 -0
  126. package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
  127. package/fixtures/workbench/task-grant.v1.json +695 -0
  128. package/fixtures/workbench/task-status-projection.v1.json +591 -0
  129. package/fixtures/workbench/workload-enrollment.v1.json +580 -0
  130. package/package.json +21 -2
  131. package/src/data/compiled/merged-rules.json +2 -9
  132. package/src/data/default-rules.json +0 -1
  133. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
  134. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
  135. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
  136. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
  137. package/dist/browser-posture.d.mts.map +0 -1
  138. package/dist/browser-posture.d.ts.map +0 -1
  139. package/dist/patterns-CkRVOdtV.js +0 -243
  140. package/dist/patterns-DzkGy_qk.mjs +0 -173
  141. package/dist/patterns-DzkGy_qk.mjs.map +0 -1
@@ -0,0 +1,294 @@
1
+ //#region src/beacon-nonce/index.ts
2
+ /**
3
+ * Stateless, client-bound beacon nonce, issued and verified by both the
4
+ * origin (`apps/web/lib/services/nonce.service.ts`) and the beacon-ingest
5
+ * edge Worker.
6
+ *
7
+ * Every pixel/beacon response hands the browser a per-session nonce that its
8
+ * next post must echo. A queue-only edge returns its receipt before the
9
+ * origin has seen the batch, so the nonce cannot depend on origin state:
10
+ * it is an HMAC-SHA256 under a secret shared by origin and edge. The origin
11
+ * verifies it at synchronous ingest, or on replay using the edge's
12
+ * acceptance time as the clock.
13
+ *
14
+ * Web Crypto only (`crypto.subtle`, `crypto.getRandomValues`): this runs
15
+ * unchanged in Cloudflare Workers, Node ≥ 20 and the browser bundle.
16
+ *
17
+ * Wire format (56 chars, inside the schema's 64-char cap):
18
+ *
19
+ * n2.<issuedAt base36 seconds>.<random 8 bytes b64url>.<HMAC 16 bytes b64url>.<ctx tag 8 bytes b64url>
20
+ *
21
+ * The first HMAC binds the format version + project + session + issue time +
22
+ * random. The trailing context tag additionally binds the requester's
23
+ * network prefix and User-Agent (`beaconNonceContext`), so a nonce lifted
24
+ * from one client does not verify from another. The version is inside the
25
+ * MAC, so a nonce cannot be relabelled to dodge the context tag.
26
+ *
27
+ * Verdict semantics — three states, never two:
28
+ * - `verified`: signature matches THIS project+session, the context matches,
29
+ * and it is within TTL.
30
+ * - `forged`: well-formed but the MAC does not match this session/secret.
31
+ * The only outcome that counts as evidence against the client.
32
+ * - `unverified`: nothing could be proven — not signed-format (absent, or
33
+ * a value from before signing existed), expired, from the future, this
34
+ * side has no secret, or the session signature is genuine but the
35
+ * requester's network/User-Agent differs from the one it was issued to (a
36
+ * roaming phone and a replay from elsewhere look the same, so neither is
37
+ * treated as fabrication). Staleness is not forgery: an edge that stopped
38
+ * issuing (secret unset) leaves clients echoing old values, and that must
39
+ * degrade to "unknown", never to "failed".
40
+ *
41
+ * Any unexpired signature for the session verifies, so a nonce is not
42
+ * single-use within its TTL. Multi-tab sessions need no window at all.
43
+ */
44
+ const NONCE_VERSION = "n2";
45
+ const MAC_INPUT_PREFIX = `checkpoint-beacon-nonce:${NONCE_VERSION}`;
46
+ const CONTEXT_INPUT_PREFIX = `checkpoint-beacon-nonce:ctx:${NONCE_VERSION}`;
47
+ const RANDOM_BYTES = 8;
48
+ const MAC_BYTES = 16;
49
+ const CONTEXT_TAG_BYTES = 8;
50
+ const MAX_CONTEXT_USER_AGENT_LENGTH = 512;
51
+ const IPV4_PATTERN = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
52
+ const IPV6_GROUP_PATTERN = /^[0-9a-f]{1,4}$/;
53
+ const ISSUED_AT_PATTERN = /^[0-9a-z]{1,16}$/;
54
+ const BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
55
+ const HANDOFF_TOKEN_INPUT_PREFIX = "checkpoint-handoff-token:v1";
56
+ const HANDOFF_ID_BYTES = 16;
57
+ const HANDOFF_TAG_BYTES = 16;
58
+ const HANDOFF_TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
59
+ /** How long an issued nonce stays verifiable. */
60
+ const BEACON_NONCE_TTL_SECONDS = 600;
61
+ /** Edge and origin clocks may disagree; a nonce this far "in the future" still verifies. */
62
+ const BEACON_NONCE_CLOCK_SKEW_SECONDS = 60;
63
+ /** The beacon wire schema's `nonce: z.string().max(64)`. */
64
+ const BEACON_NONCE_MAX_LENGTH = 64;
65
+ function ipv4Prefix(ip) {
66
+ const match = IPV4_PATTERN.exec(ip);
67
+ return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
68
+ }
69
+ /**
70
+ * The first three groups (a /48) of an IPv6 address, expanded so compressed
71
+ * forms agree with their spelled-out equivalents. An IPv4-mapped address
72
+ * (`::ffff:a.b.c.d` or its hex spelling) is a v4 client and keys on its /24.
73
+ * `null` for anything that is not a well-formed address.
74
+ */
75
+ function ipv6Prefix(ip) {
76
+ const bare = ip.toLowerCase().split("%")[0];
77
+ const lastColon = bare.lastIndexOf(":");
78
+ const embedded = IPV4_PATTERN.exec(bare.slice(lastColon + 1));
79
+ const halves = (embedded ? `${bare.slice(0, lastColon + 1)}${(Number(embedded[1]) << 8 | Number(embedded[2])).toString(16)}:${(Number(embedded[3]) << 8 | Number(embedded[4])).toString(16)}` : bare).split("::");
80
+ if (halves.length > 2) return null;
81
+ const head = halves[0] ? halves[0].split(":") : [];
82
+ const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
83
+ const missing = 8 - head.length - tail.length;
84
+ if (halves.length === 1 ? missing !== 0 : missing < 1) return null;
85
+ const groups = [
86
+ ...head,
87
+ ...Array(halves.length === 2 ? missing : 0).fill("0"),
88
+ ...tail
89
+ ];
90
+ if (!groups.every((group) => IPV6_GROUP_PATTERN.test(group))) return null;
91
+ const words = groups.map((group) => parseInt(group, 16));
92
+ if (words.slice(0, 5).every((word) => word === 0) && words[5] === 65535) return `${words[6] >> 8}.${words[6] & 255}.${words[7] >> 8}`;
93
+ return words.slice(0, 3).map((word) => word.toString(16)).join(":");
94
+ }
95
+ /**
96
+ * The requester facts a nonce is bound to: the network prefix (IPv4 /24,
97
+ * IPv6 /48, so NAT and DHCP churn inside one access network still verify)
98
+ * and the User-Agent. Empty when neither is known, which binds nothing.
99
+ */
100
+ function beaconNonceContext(client) {
101
+ const ip = client.ip?.trim() ?? "";
102
+ const prefix = ipv4Prefix(ip) ?? (ip.includes(":") ? ipv6Prefix(ip) : null) ?? "";
103
+ const userAgent = (client.userAgent ?? "").slice(0, MAX_CONTEXT_USER_AGENT_LENGTH);
104
+ return prefix || userAgent ? `${prefix}|${userAgent}` : "";
105
+ }
106
+ const encoder = new TextEncoder();
107
+ const keyCache = /* @__PURE__ */ new Map();
108
+ function hmacKey(secret) {
109
+ let key = keyCache.get(secret);
110
+ if (!key) {
111
+ key = crypto.subtle.importKey("raw", encoder.encode(secret), {
112
+ name: "HMAC",
113
+ hash: "SHA-256"
114
+ }, false, ["sign"]);
115
+ keyCache.set(secret, key);
116
+ }
117
+ return key;
118
+ }
119
+ function base64url(bytes) {
120
+ let binary = "";
121
+ for (const byte of bytes) binary += String.fromCharCode(byte);
122
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
123
+ }
124
+ /**
125
+ * Length-prefixed canonical encoding (`<byteLength>:<field>`), never a bare
126
+ * delimiter join: `sessionId` is caller-controlled at the edge, so a value
127
+ * that embeds the delimiter must not be able to shift the field boundaries
128
+ * and re-bind the MAC to another session (Cursor Bugbot, PR #5255).
129
+ */
130
+ function canonical(fields) {
131
+ const chunks = fields.map((field) => {
132
+ const bytes = encoder.encode(field);
133
+ return [encoder.encode(`${bytes.length}:`), bytes];
134
+ });
135
+ const total = chunks.reduce((sum, [len, bytes]) => sum + len.length + bytes.length, 0);
136
+ const out = new Uint8Array(new ArrayBuffer(total));
137
+ let offset = 0;
138
+ for (const [len, bytes] of chunks) {
139
+ out.set(len, offset);
140
+ offset += len.length;
141
+ out.set(bytes, offset);
142
+ offset += bytes.length;
143
+ }
144
+ return out;
145
+ }
146
+ async function mac(secret, binding, issuedAt, random) {
147
+ const input = canonical([
148
+ MAC_INPUT_PREFIX,
149
+ binding.projectId,
150
+ binding.sessionId,
151
+ issuedAt,
152
+ random
153
+ ]);
154
+ const signature = await crypto.subtle.sign("HMAC", await hmacKey(secret), input);
155
+ return base64url(new Uint8Array(signature, 0, MAC_BYTES));
156
+ }
157
+ async function contextTag(secret, binding, issuedAt, random) {
158
+ const input = canonical([
159
+ CONTEXT_INPUT_PREFIX,
160
+ binding.projectId,
161
+ binding.sessionId,
162
+ issuedAt,
163
+ random,
164
+ binding.context
165
+ ]);
166
+ const signature = await crypto.subtle.sign("HMAC", await hmacKey(secret), input);
167
+ return base64url(new Uint8Array(signature, 0, CONTEXT_TAG_BYTES));
168
+ }
169
+ function constantTimeEqual(left, right) {
170
+ if (left.length !== right.length) return false;
171
+ let diff = 0;
172
+ for (let i = 0; i < left.length; i += 1) diff |= left.charCodeAt(i) ^ right.charCodeAt(i);
173
+ return diff === 0;
174
+ }
175
+ /** True when `nonce` is in the signed wire format (not necessarily valid). */
176
+ function isSignedBeaconNonce(nonce) {
177
+ return typeof nonce === "string" && nonce.startsWith(`${NONCE_VERSION}.`);
178
+ }
179
+ /**
180
+ * Mint a nonce for `binding` at `issuedAtMs`. Throws when `secret` is
181
+ * empty — issuing an unsigned value would be indistinguishable from a
182
+ * real one on the wire, so the caller must decide to issue nothing.
183
+ */
184
+ async function issueSignedBeaconNonce(secret, binding, issuedAtMs) {
185
+ if (!secret) throw new Error("beacon nonce secret is required to issue a signed nonce");
186
+ const issuedAt = Math.floor(issuedAtMs / 1e3).toString(36);
187
+ const random = base64url(crypto.getRandomValues(new Uint8Array(RANDOM_BYTES)));
188
+ return [
189
+ NONCE_VERSION,
190
+ issuedAt,
191
+ random,
192
+ await mac(secret, binding, issuedAt, random),
193
+ await contextTag(secret, binding, issuedAt, random)
194
+ ].join(".");
195
+ }
196
+ /**
197
+ * Verify `nonce` against `binding` as of `nowMs`. Never throws; every
198
+ * failure mode is a verdict (see the module doc for why expiry is
199
+ * `unverified` rather than `forged`).
200
+ */
201
+ async function verifySignedBeaconNonce(secret, binding, nonce, nowMs) {
202
+ if (!isSignedBeaconNonce(nonce)) return {
203
+ verdict: "unverified",
204
+ reason: "malformed"
205
+ };
206
+ const parts = nonce.split(".");
207
+ if (parts.length !== 5 || parts.some((part) => part.length === 0)) return {
208
+ verdict: "unverified",
209
+ reason: "malformed"
210
+ };
211
+ const [, issuedAt, random, providedMac, providedContextTag] = parts;
212
+ if (!ISSUED_AT_PATTERN.test(issuedAt) || !BASE64URL_PATTERN.test(random) || !BASE64URL_PATTERN.test(providedMac) || !BASE64URL_PATTERN.test(providedContextTag)) return {
213
+ verdict: "unverified",
214
+ reason: "malformed"
215
+ };
216
+ if (!secret) return {
217
+ verdict: "unverified",
218
+ reason: "no_secret"
219
+ };
220
+ if (!constantTimeEqual(providedMac, await mac(secret, binding, issuedAt, random))) return {
221
+ verdict: "forged",
222
+ reason: "signature"
223
+ };
224
+ const issuedAtSeconds = parseInt(issuedAt, 36);
225
+ const nowSeconds = Math.floor(nowMs / 1e3);
226
+ if (!Number.isFinite(issuedAtSeconds)) return {
227
+ verdict: "unverified",
228
+ reason: "malformed"
229
+ };
230
+ if (issuedAtSeconds - nowSeconds > 60) return {
231
+ verdict: "unverified",
232
+ reason: "future"
233
+ };
234
+ if (nowSeconds - issuedAtSeconds > 600) return {
235
+ verdict: "unverified",
236
+ reason: "expired"
237
+ };
238
+ if (!constantTimeEqual(providedContextTag, await contextTag(secret, binding, issuedAt, random))) return {
239
+ verdict: "unverified",
240
+ reason: "context"
241
+ };
242
+ return { verdict: "verified" };
243
+ }
244
+ async function handoffTag(secret, projectId, idBytes) {
245
+ const input = canonical([
246
+ HANDOFF_TOKEN_INPUT_PREFIX,
247
+ projectId,
248
+ base64url(idBytes)
249
+ ]);
250
+ const signature = await crypto.subtle.sign("HMAC", await hmacKey(secret), input);
251
+ return new Uint8Array(signature, 0, HANDOFF_TAG_BYTES);
252
+ }
253
+ function base64urlDecode(text) {
254
+ const padded = text.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(text.length / 4) * 4, "=");
255
+ return Uint8Array.from(atob(padded), (char) => char.charCodeAt(0));
256
+ }
257
+ function bytesEqual(left, right) {
258
+ if (left.length !== right.length) return false;
259
+ let diff = 0;
260
+ for (let i = 0; i < left.length; i += 1) diff |= left[i] ^ right[i];
261
+ return diff === 0;
262
+ }
263
+ async function issueHandoffToken(secret, projectId) {
264
+ if (!secret) throw new Error("beacon nonce secret is required to issue a handoff token");
265
+ const id = crypto.getRandomValues(new Uint8Array(HANDOFF_ID_BYTES));
266
+ const token = /* @__PURE__ */ new Uint8Array(32);
267
+ token.set(id, 0);
268
+ token.set(await handoffTag(secret, projectId, id), HANDOFF_ID_BYTES);
269
+ return base64url(token);
270
+ }
271
+ const HANDOFF_USER_HASH_PATTERN = /^[0-9a-f]{8}$/;
272
+ const HANDOFF_USER_SEPARATOR = "~";
273
+ function splitHandoffToken(raw) {
274
+ const parts = raw.split(HANDOFF_USER_SEPARATOR);
275
+ const [token, userHash] = parts;
276
+ if (parts.length > 2 || userHash !== void 0 && !HANDOFF_USER_HASH_PATTERN.test(userHash)) return { token: raw };
277
+ return {
278
+ token,
279
+ ...userHash === void 0 ? {} : { userHash }
280
+ };
281
+ }
282
+ async function handoffTokenAuthentic(secrets, projectId, token) {
283
+ if (typeof token !== "string" || !HANDOFF_TOKEN_PATTERN.test(token)) return false;
284
+ const bytes = base64urlDecode(token);
285
+ if (bytes.length !== 32) return false;
286
+ if (base64url(bytes) !== token) return false;
287
+ const id = bytes.slice(0, HANDOFF_ID_BYTES);
288
+ const providedTag = bytes.slice(HANDOFF_ID_BYTES);
289
+ return (await Promise.all(secrets.filter((secret) => secret.length > 0).map(async (secret) => bytesEqual(providedTag, await handoffTag(secret, projectId, id))))).includes(true);
290
+ }
291
+
292
+ //#endregion
293
+ export { BEACON_NONCE_CLOCK_SKEW_SECONDS, BEACON_NONCE_MAX_LENGTH, BEACON_NONCE_TTL_SECONDS, HANDOFF_TOKEN_PATTERN, HANDOFF_USER_HASH_PATTERN, beaconNonceContext, handoffTokenAuthentic, isSignedBeaconNonce, issueHandoffToken, issueSignedBeaconNonce, splitHandoffToken, verifySignedBeaconNonce };
294
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/beacon-nonce/index.ts"],"sourcesContent":["/**\n * Stateless, client-bound beacon nonce, issued and verified by both the\n * origin (`apps/web/lib/services/nonce.service.ts`) and the beacon-ingest\n * edge Worker.\n *\n * Every pixel/beacon response hands the browser a per-session nonce that its\n * next post must echo. A queue-only edge returns its receipt before the\n * origin has seen the batch, so the nonce cannot depend on origin state:\n * it is an HMAC-SHA256 under a secret shared by origin and edge. The origin\n * verifies it at synchronous ingest, or on replay using the edge's\n * acceptance time as the clock.\n *\n * Web Crypto only (`crypto.subtle`, `crypto.getRandomValues`): this runs\n * unchanged in Cloudflare Workers, Node ≥ 20 and the browser bundle.\n *\n * Wire format (56 chars, inside the schema's 64-char cap):\n *\n * n2.<issuedAt base36 seconds>.<random 8 bytes b64url>.<HMAC 16 bytes b64url>.<ctx tag 8 bytes b64url>\n *\n * The first HMAC binds the format version + project + session + issue time +\n * random. The trailing context tag additionally binds the requester's\n * network prefix and User-Agent (`beaconNonceContext`), so a nonce lifted\n * from one client does not verify from another. The version is inside the\n * MAC, so a nonce cannot be relabelled to dodge the context tag.\n *\n * Verdict semantics — three states, never two:\n * - `verified`: signature matches THIS project+session, the context matches,\n * and it is within TTL.\n * - `forged`: well-formed but the MAC does not match this session/secret.\n * The only outcome that counts as evidence against the client.\n * - `unverified`: nothing could be proven — not signed-format (absent, or\n * a value from before signing existed), expired, from the future, this\n * side has no secret, or the session signature is genuine but the\n * requester's network/User-Agent differs from the one it was issued to (a\n * roaming phone and a replay from elsewhere look the same, so neither is\n * treated as fabrication). Staleness is not forgery: an edge that stopped\n * issuing (secret unset) leaves clients echoing old values, and that must\n * degrade to \"unknown\", never to \"failed\".\n *\n * Any unexpired signature for the session verifies, so a nonce is not\n * single-use within its TTL. Multi-tab sessions need no window at all.\n */\n\nconst NONCE_VERSION = 'n2';\nconst MAC_INPUT_PREFIX = `checkpoint-beacon-nonce:${NONCE_VERSION}`;\nconst CONTEXT_INPUT_PREFIX = `checkpoint-beacon-nonce:ctx:${NONCE_VERSION}`;\nconst RANDOM_BYTES = 8;\nconst MAC_BYTES = 16;\nconst CONTEXT_TAG_BYTES = 8;\nconst MAX_CONTEXT_USER_AGENT_LENGTH = 512;\nconst IPV4_PATTERN = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/;\nconst IPV6_GROUP_PATTERN = /^[0-9a-f]{1,4}$/;\n// Each wire part has a closed alphabet and is rejected as malformed before any\n// MAC work when it strays outside it — a nonce is no place for `\\0` or `.`.\nconst ISSUED_AT_PATTERN = /^[0-9a-z]{1,16}$/;\nconst BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;\nconst HANDOFF_TOKEN_INPUT_PREFIX = 'checkpoint-handoff-token:v1';\nconst HANDOFF_ID_BYTES = 16;\nconst HANDOFF_TAG_BYTES = 16;\n\nexport const HANDOFF_TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;\n\n/** How long an issued nonce stays verifiable. */\nexport const BEACON_NONCE_TTL_SECONDS = 10 * 60;\n/** Edge and origin clocks may disagree; a nonce this far \"in the future\" still verifies. */\nexport const BEACON_NONCE_CLOCK_SKEW_SECONDS = 60;\n/** The beacon wire schema's `nonce: z.string().max(64)`. */\nexport const BEACON_NONCE_MAX_LENGTH = 64;\n\nexport type BeaconNonceVerdict = 'verified' | 'forged' | 'unverified';\n\nexport type BeaconNonceVerification =\n | { verdict: 'verified' }\n | { verdict: 'forged'; reason: 'signature' }\n | {\n verdict: 'unverified';\n reason: 'malformed' | 'expired' | 'future' | 'no_secret' | 'context';\n };\n\nexport interface BeaconNonceBinding {\n projectId: string;\n sessionId: string;\n /** `beaconNonceContext(...)` of the request being issued to or verified. */\n context: string;\n}\n\nfunction ipv4Prefix(ip: string): string | null {\n const match = IPV4_PATTERN.exec(ip);\n return match ? `${match[1]}.${match[2]}.${match[3]}` : null;\n}\n\n/**\n * The first three groups (a /48) of an IPv6 address, expanded so compressed\n * forms agree with their spelled-out equivalents. An IPv4-mapped address\n * (`::ffff:a.b.c.d` or its hex spelling) is a v4 client and keys on its /24.\n * `null` for anything that is not a well-formed address.\n */\nfunction ipv6Prefix(ip: string): string | null {\n const bare = ip.toLowerCase().split('%')[0];\n const lastColon = bare.lastIndexOf(':');\n const embedded = IPV4_PATTERN.exec(bare.slice(lastColon + 1));\n const text = embedded\n ? `${bare.slice(0, lastColon + 1)}${((Number(embedded[1]) << 8) | Number(embedded[2])).toString(16)}:${((Number(embedded[3]) << 8) | Number(embedded[4])).toString(16)}`\n : bare;\n const halves = text.split('::');\n if (halves.length > 2) return null;\n const head = halves[0] ? halves[0].split(':') : [];\n const tail = halves.length === 2 && halves[1] ? halves[1].split(':') : [];\n const missing = 8 - head.length - tail.length;\n if (halves.length === 1 ? missing !== 0 : missing < 1) return null;\n const groups = [...head, ...Array<string>(halves.length === 2 ? missing : 0).fill('0'), ...tail];\n if (!groups.every((group) => IPV6_GROUP_PATTERN.test(group))) return null;\n const words = groups.map((group) => parseInt(group, 16));\n const mapped = words.slice(0, 5).every((word) => word === 0) && words[5] === 0xffff;\n if (mapped) return `${words[6] >> 8}.${words[6] & 0xff}.${words[7] >> 8}`;\n return words\n .slice(0, 3)\n .map((word) => word.toString(16))\n .join(':');\n}\n\n/**\n * The requester facts a nonce is bound to: the network prefix (IPv4 /24,\n * IPv6 /48, so NAT and DHCP churn inside one access network still verify)\n * and the User-Agent. Empty when neither is known, which binds nothing.\n */\nexport function beaconNonceContext(client: { ip?: string; userAgent?: string }): string {\n const ip = client.ip?.trim() ?? '';\n const prefix = ipv4Prefix(ip) ?? (ip.includes(':') ? ipv6Prefix(ip) : null) ?? '';\n const userAgent = (client.userAgent ?? '').slice(0, MAX_CONTEXT_USER_AGENT_LENGTH);\n return prefix || userAgent ? `${prefix}|${userAgent}` : '';\n}\n\nconst encoder = new TextEncoder();\n\nconst keyCache = new Map<string, Promise<CryptoKey>>();\n\nfunction hmacKey(secret: string): Promise<CryptoKey> {\n let key = keyCache.get(secret);\n if (!key) {\n key = crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign']\n );\n keyCache.set(secret, key);\n }\n return key;\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n}\n\n/**\n * Length-prefixed canonical encoding (`<byteLength>:<field>`), never a bare\n * delimiter join: `sessionId` is caller-controlled at the edge, so a value\n * that embeds the delimiter must not be able to shift the field boundaries\n * and re-bind the MAC to another session (Cursor Bugbot, PR #5255).\n */\nfunction canonical(fields: readonly string[]): Uint8Array<ArrayBuffer> {\n const chunks = fields.map((field) => {\n const bytes = encoder.encode(field);\n return [encoder.encode(`${bytes.length}:`), bytes] as const;\n });\n const total = chunks.reduce((sum, [len, bytes]) => sum + len.length + bytes.length, 0);\n const out = new Uint8Array(new ArrayBuffer(total));\n let offset = 0;\n for (const [len, bytes] of chunks) {\n out.set(len, offset);\n offset += len.length;\n out.set(bytes, offset);\n offset += bytes.length;\n }\n return out;\n}\n\nasync function mac(\n secret: string,\n binding: BeaconNonceBinding,\n issuedAt: string,\n random: string\n): Promise<string> {\n const input = canonical([\n MAC_INPUT_PREFIX,\n binding.projectId,\n binding.sessionId,\n issuedAt,\n random,\n ]);\n const signature = await crypto.subtle.sign('HMAC', await hmacKey(secret), input);\n return base64url(new Uint8Array(signature, 0, MAC_BYTES));\n}\n\nasync function contextTag(\n secret: string,\n binding: BeaconNonceBinding,\n issuedAt: string,\n random: string\n): Promise<string> {\n const input = canonical([\n CONTEXT_INPUT_PREFIX,\n binding.projectId,\n binding.sessionId,\n issuedAt,\n random,\n binding.context,\n ]);\n const signature = await crypto.subtle.sign('HMAC', await hmacKey(secret), input);\n return base64url(new Uint8Array(signature, 0, CONTEXT_TAG_BYTES));\n}\n\nfunction constantTimeEqual(left: string, right: string): boolean {\n if (left.length !== right.length) return false;\n let diff = 0;\n for (let i = 0; i < left.length; i += 1) diff |= left.charCodeAt(i) ^ right.charCodeAt(i);\n return diff === 0;\n}\n\n/** True when `nonce` is in the signed wire format (not necessarily valid). */\nexport function isSignedBeaconNonce(nonce: string | undefined): nonce is string {\n return typeof nonce === 'string' && nonce.startsWith(`${NONCE_VERSION}.`);\n}\n\n/**\n * Mint a nonce for `binding` at `issuedAtMs`. Throws when `secret` is\n * empty — issuing an unsigned value would be indistinguishable from a\n * real one on the wire, so the caller must decide to issue nothing.\n */\nexport async function issueSignedBeaconNonce(\n secret: string,\n binding: BeaconNonceBinding,\n issuedAtMs: number\n): Promise<string> {\n if (!secret) throw new Error('beacon nonce secret is required to issue a signed nonce');\n const issuedAt = Math.floor(issuedAtMs / 1000).toString(36);\n const random = base64url(crypto.getRandomValues(new Uint8Array(RANDOM_BYTES)));\n return [\n NONCE_VERSION,\n issuedAt,\n random,\n await mac(secret, binding, issuedAt, random),\n await contextTag(secret, binding, issuedAt, random),\n ].join('.');\n}\n\n/**\n * Verify `nonce` against `binding` as of `nowMs`. Never throws; every\n * failure mode is a verdict (see the module doc for why expiry is\n * `unverified` rather than `forged`).\n */\nexport async function verifySignedBeaconNonce(\n secret: string | undefined,\n binding: BeaconNonceBinding,\n nonce: string | undefined,\n nowMs: number\n): Promise<BeaconNonceVerification> {\n if (!isSignedBeaconNonce(nonce)) return { verdict: 'unverified', reason: 'malformed' };\n const parts = nonce.split('.');\n if (parts.length !== 5 || parts.some((part) => part.length === 0)) {\n return { verdict: 'unverified', reason: 'malformed' };\n }\n const [, issuedAt, random, providedMac, providedContextTag] = parts;\n if (\n !ISSUED_AT_PATTERN.test(issuedAt) ||\n !BASE64URL_PATTERN.test(random) ||\n !BASE64URL_PATTERN.test(providedMac) ||\n !BASE64URL_PATTERN.test(providedContextTag)\n ) {\n return { verdict: 'unverified', reason: 'malformed' };\n }\n if (!secret) return { verdict: 'unverified', reason: 'no_secret' };\n\n const expectedMac = await mac(secret, binding, issuedAt, random);\n if (!constantTimeEqual(providedMac, expectedMac))\n return { verdict: 'forged', reason: 'signature' };\n\n const issuedAtSeconds = parseInt(issuedAt, 36);\n const nowSeconds = Math.floor(nowMs / 1000);\n if (!Number.isFinite(issuedAtSeconds)) return { verdict: 'unverified', reason: 'malformed' };\n if (issuedAtSeconds - nowSeconds > BEACON_NONCE_CLOCK_SKEW_SECONDS) {\n return { verdict: 'unverified', reason: 'future' };\n }\n if (nowSeconds - issuedAtSeconds > BEACON_NONCE_TTL_SECONDS) {\n return { verdict: 'unverified', reason: 'expired' };\n }\n if (!constantTimeEqual(providedContextTag, await contextTag(secret, binding, issuedAt, random))) {\n return { verdict: 'unverified', reason: 'context' };\n }\n return { verdict: 'verified' };\n}\n\nasync function handoffTag(\n secret: string,\n projectId: string,\n idBytes: Uint8Array\n): Promise<Uint8Array> {\n const input = canonical([HANDOFF_TOKEN_INPUT_PREFIX, projectId, base64url(idBytes)]);\n const signature = await crypto.subtle.sign('HMAC', await hmacKey(secret), input);\n return new Uint8Array(signature, 0, HANDOFF_TAG_BYTES);\n}\n\nfunction base64urlDecode(text: string): Uint8Array {\n const padded = text\n .replace(/-/g, '+')\n .replace(/_/g, '/')\n .padEnd(Math.ceil(text.length / 4) * 4, '=');\n return Uint8Array.from(atob(padded), (char) => char.charCodeAt(0));\n}\n\nfunction bytesEqual(left: Uint8Array, right: Uint8Array): boolean {\n if (left.length !== right.length) return false;\n let diff = 0;\n for (let i = 0; i < left.length; i += 1) diff |= left[i] ^ right[i];\n return diff === 0;\n}\n\nexport async function issueHandoffToken(secret: string, projectId: string): Promise<string> {\n if (!secret) throw new Error('beacon nonce secret is required to issue a handoff token');\n const id = crypto.getRandomValues(new Uint8Array(HANDOFF_ID_BYTES));\n const token = new Uint8Array(HANDOFF_ID_BYTES + HANDOFF_TAG_BYTES);\n token.set(id, 0);\n token.set(await handoffTag(secret, projectId, id), HANDOFF_ID_BYTES);\n return base64url(token);\n}\n\nexport const HANDOFF_USER_HASH_PATTERN = /^[0-9a-f]{8}$/;\nconst HANDOFF_USER_SEPARATOR = '~';\n\nexport function splitHandoffToken(raw: string): { token: string; userHash?: string } {\n const parts = raw.split(HANDOFF_USER_SEPARATOR);\n const [token, userHash] = parts;\n if (parts.length > 2 || (userHash !== undefined && !HANDOFF_USER_HASH_PATTERN.test(userHash))) {\n return { token: raw };\n }\n return { token, ...(userHash === undefined ? {} : { userHash }) };\n}\n\nexport async function handoffTokenAuthentic(\n secrets: readonly string[],\n projectId: string,\n token: unknown\n): Promise<boolean> {\n if (typeof token !== 'string' || !HANDOFF_TOKEN_PATTERN.test(token)) return false;\n const bytes = base64urlDecode(token);\n if (bytes.length !== HANDOFF_ID_BYTES + HANDOFF_TAG_BYTES) return false;\n if (base64url(bytes) !== token) return false;\n const id = bytes.slice(0, HANDOFF_ID_BYTES);\n const providedTag = bytes.slice(HANDOFF_ID_BYTES);\n const matches = await Promise.all(\n secrets\n .filter((secret) => secret.length > 0)\n .map(async (secret) => bytesEqual(providedTag, await handoffTag(secret, projectId, id)))\n );\n return matches.includes(true);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,gBAAgB;AACtB,MAAM,mBAAmB,2BAA2B;AACpD,MAAM,uBAAuB,+BAA+B;AAC5D,MAAM,eAAe;AACrB,MAAM,YAAY;AAClB,MAAM,oBAAoB;AAC1B,MAAM,gCAAgC;AACtC,MAAM,eAAe;AACrB,MAAM,qBAAqB;AAG3B,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAC1B,MAAM,6BAA6B;AACnC,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAE1B,MAAa,wBAAwB;;AAGrC,MAAa,2BAA2B;;AAExC,MAAa,kCAAkC;;AAE/C,MAAa,0BAA0B;AAmBvC,SAAS,WAAW,IAA2B;CAC7C,MAAM,QAAQ,aAAa,KAAK,EAAE;CAClC,OAAO,QAAQ,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,MAAM,OAAO;AACzD;;;;;;;AAQA,SAAS,WAAW,IAA2B;CAC7C,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;CACzC,MAAM,YAAY,KAAK,YAAY,GAAG;CACtC,MAAM,WAAW,aAAa,KAAK,KAAK,MAAM,YAAY,CAAC,CAAC;CAI5D,MAAM,UAHO,WACT,GAAG,KAAK,MAAM,GAAG,YAAY,CAAC,KAAM,OAAO,SAAS,EAAE,KAAK,IAAK,OAAO,SAAS,EAAE,EAAC,CAAE,SAAS,EAAE,EAAE,IAAK,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I,UAAU,KAAK,MAAM,OAAO,OAAO;CACvC,MAAM,KAAK,MAAM,MAAM,GAAG,gBAAgB;CAC1C,MAAM,cAAc,MAAM,MAAM,gBAAgB;CAMhD,QAAO,MALe,QAAQ,IAC5B,QACG,QAAQ,WAAW,OAAO,SAAS,CAAC,CAAC,CACrC,IAAI,OAAO,WAAW,WAAW,aAAa,MAAM,WAAW,QAAQ,WAAW,EAAE,CAAC,CAAC,CAC3F,EACc,CAAC,SAAS,IAAI;AAC9B"}
@@ -59,6 +59,15 @@ export interface LargestContentfulPaintEntry extends PerformanceEntry {
59
59
  export interface BeaconIdentity {
60
60
  userId: string;
61
61
  }
62
+ export interface BeaconDispatchTriggers {
63
+ arrival?: boolean;
64
+ signals?: boolean;
65
+ interaction?: boolean;
66
+ untrusted?: boolean;
67
+ posture?: boolean;
68
+ unload?: boolean;
69
+ navigation?: boolean;
70
+ }
62
71
  export interface BeaconConfig {
63
72
  projectId: string;
64
73
  identity?: BeaconIdentity;
@@ -69,14 +78,26 @@ export interface BeaconConfig {
69
78
  debug?: boolean;
70
79
  logLevel?: 'error' | 'warn' | 'info' | 'debug';
71
80
  respectDoNotTrack?: boolean;
81
+ requireConsent?: boolean;
72
82
  anonymizeIp?: boolean;
73
83
  stripUrlFragment?: boolean;
74
84
  scrubQueryParams?: string[];
75
85
  dropQueryParams?: boolean;
76
86
  sessionTimeout?: number;
77
87
  sessionCookieName?: string;
88
+ browserSessionId?: string;
89
+ onReceipt?: (receipt: BeaconReceipt) => void;
78
90
  batchSize?: number;
79
91
  flushInterval?: number;
92
+ evidenceGrowthFactor?: number;
93
+ postureRefreshFraction?: number;
94
+ triggers?: BeaconDispatchTriggers;
95
+ proactiveRefreshMinIntervalMs?: number;
96
+ proactiveRefreshMaxIntervalMs?: number;
97
+ proactiveRefreshFreshnessMs?: number;
98
+ proactiveRefreshOnVisibilityResume?: boolean;
99
+ proactiveRefreshOnOnline?: boolean;
100
+ proactiveRefreshJitterSeed?: number;
80
101
  collectorDeadlineMs?: number;
81
102
  maxQueueSize?: number;
82
103
  retryAttempts?: number;
@@ -173,15 +194,11 @@ export interface SessionData {
173
194
  isNew: boolean;
174
195
  }
175
196
  export interface TransportConfig {
176
- batchSize: number;
177
- flushInterval: number;
178
197
  maxRetries: number;
179
198
  retryDelayBase: number;
180
199
  offlineQueueSize: number;
181
200
  useCompression: boolean;
182
201
  compressionThreshold: number;
183
- networkAdaptation: boolean;
184
- dedupWindow: number;
185
202
  anonymizeIp?: boolean;
186
203
  }
187
204
  export interface TransportOptions {
@@ -189,6 +206,9 @@ export interface TransportOptions {
189
206
  priority?: 'low' | 'normal' | 'high' | 'critical';
190
207
  retry?: boolean;
191
208
  timeout?: number;
209
+ publicJwk?: EcPublicJwk;
210
+ deviceId?: string;
211
+ handoffToken?: string;
192
212
  }
193
213
  export interface TransportResponse {
194
214
  success: boolean;
@@ -209,14 +229,6 @@ export interface TransportMetrics {
209
229
  lastSuccessTimestamp?: number;
210
230
  lastErrorTimestamp?: number;
211
231
  }
212
- export interface BatchEvent {
213
- id: string;
214
- event: BeaconEvent;
215
- timestamp: number;
216
- retryCount: number;
217
- hash: string;
218
- priority: 'low' | 'normal' | 'high' | 'critical';
219
- }
220
232
  export type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
221
233
  export interface NetworkInfo {
222
234
  type?: string;
@@ -385,15 +397,33 @@ export interface OfflineQueueEntry {
385
397
  retryCount: number;
386
398
  size: number;
387
399
  }
400
+ export interface EcPublicJwk {
401
+ kty: 'EC';
402
+ crv: 'P-256';
403
+ x: string;
404
+ y: string;
405
+ }
406
+ export interface BeaconReceipt {
407
+ sessionId?: string;
408
+ browserSessionId: string;
409
+ posture?: {
410
+ token: string;
411
+ expiresAt: number;
412
+ };
413
+ postureStatus?: string;
414
+ }
388
415
  export interface BeaconBatch {
389
416
  projectId: string;
390
417
  events: BeaconEvent[];
391
418
  sessionId: string;
419
+ handoffToken?: string;
420
+ deviceId?: string;
392
421
  batchId: string;
393
422
  timestamp: number;
394
423
  anonymizeIp?: boolean;
395
424
  nonce?: string;
396
425
  nonceEcho?: boolean;
426
+ publicJwk?: EcPublicJwk;
397
427
  }
398
428
  export interface BeaconCollectorData {
399
429
  userAgent?: string;
@@ -417,7 +447,7 @@ export interface BeaconCollectorData {
417
447
  timestamp?: number;
418
448
  [key: string]: unknown;
419
449
  }
420
- export type BeaconEventType = 'pageview' | 'pageunload' | 'heartbeat' | 'custom' | 'error' | 'performance';
450
+ export type BeaconEventType = 'pageview' | 'pageunload' | 'heartbeat' | 'evidence' | 'custom' | 'error' | 'performance';
421
451
  export declare function parseRetryStrategy(input: unknown): RetryStrategy;
422
452
  export declare function parseCircuitBreakerConfig(input: unknown): CircuitBreakerConfig;
423
453
  export declare function parseOfflineQueueEntry(input: unknown): OfflineQueueEntry;
@@ -433,7 +463,7 @@ export declare const WorkerPoolConfigSchema: {
433
463
  parse: typeof parseWorkerPoolConfig;
434
464
  };
435
465
  export declare function parseWorkerCapabilities(input: unknown): WorkerCapabilities;
436
- export declare function parseBeaconConfig(input: unknown): BeaconConfig;
466
+ export declare function parseBeaconConfig(input: unknown, onWarn?: (message: string) => void): BeaconConfig;
437
467
  export declare class AgentShieldBeacon implements IAgentShieldBeacon {
438
468
  constructor(config: BeaconConfig);
439
469
  collect(eventType: string, data?: BeaconPayload): Promise<void>;
@@ -443,5 +473,11 @@ export declare class AgentShieldBeacon implements IAgentShieldBeacon {
443
473
  updateConfig(updates: Partial<BeaconConfig>): void;
444
474
  destroy(): Promise<void>;
445
475
  }
476
+ export declare const BEACON_MAX_EVENTS_PER_BATCH = 100;
477
+ export declare const SESSION_IDLE_GAP_MAX_MS = 21600000;
478
+ export declare const BEACON_MAX_BATCH_ID_LENGTH = 255;
479
+ export declare const BEACON_ORIGIN_CONTRACT_VERSION = 1;
480
+ export declare const BEACON_ORIGIN_CAPABILITIES: readonly ["batch-replay-v1", "receipt-status-v1"];
481
+ export declare const POSTURE_TTL_SECONDS = 120;
446
482
  //#endregion
447
483
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","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
+ {"version":3,"file":"index.d.mts","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;wBA4KI,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;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U;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;;iBAUe;EACf;EACA;EACA;EACA;;iBAIe;EAOf;EAKA;EAEA;IAAY;IAAe;;EAE3B;;iBAGe;EACf;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;EAEA;EAEA;EAEA;EAIA,YAAY;;iBAGG;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EAGA;EACA;GAGC;;YAGS;wBAaI,mBAAmB,iBAAiB;wBAWpC,0BAA0B,iBAAiB;wBAS3C,uBAAuB,iBAAiB;wBA2BxC,yBAAyB,iBAAiB;wBA8C1C,mBAAmB,iBAAiB;wBAkBpC,iBAAiB,iBAAiB;wBAclC,sBAAsB,iBAAiB;wBAcvC,mBAAmB,iBAAiB;qBAUvC;gBAAA;;qBAIA;gBAAA;;wBAIG,wBAAwB,iBAAiB;wBAiCzC,kBACd,gBACA,UAAU,2BACT;qBA6HkB,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;;qBAQA;qBAEA;qBACA;qBAEA;qBAEA;qBAOA"}
@@ -59,6 +59,15 @@ export interface LargestContentfulPaintEntry extends PerformanceEntry {
59
59
  export interface BeaconIdentity {
60
60
  userId: string;
61
61
  }
62
+ export interface BeaconDispatchTriggers {
63
+ arrival?: boolean;
64
+ signals?: boolean;
65
+ interaction?: boolean;
66
+ untrusted?: boolean;
67
+ posture?: boolean;
68
+ unload?: boolean;
69
+ navigation?: boolean;
70
+ }
62
71
  export interface BeaconConfig {
63
72
  projectId: string;
64
73
  identity?: BeaconIdentity;
@@ -69,14 +78,26 @@ export interface BeaconConfig {
69
78
  debug?: boolean;
70
79
  logLevel?: 'error' | 'warn' | 'info' | 'debug';
71
80
  respectDoNotTrack?: boolean;
81
+ requireConsent?: boolean;
72
82
  anonymizeIp?: boolean;
73
83
  stripUrlFragment?: boolean;
74
84
  scrubQueryParams?: string[];
75
85
  dropQueryParams?: boolean;
76
86
  sessionTimeout?: number;
77
87
  sessionCookieName?: string;
88
+ browserSessionId?: string;
89
+ onReceipt?: (receipt: BeaconReceipt) => void;
78
90
  batchSize?: number;
79
91
  flushInterval?: number;
92
+ evidenceGrowthFactor?: number;
93
+ postureRefreshFraction?: number;
94
+ triggers?: BeaconDispatchTriggers;
95
+ proactiveRefreshMinIntervalMs?: number;
96
+ proactiveRefreshMaxIntervalMs?: number;
97
+ proactiveRefreshFreshnessMs?: number;
98
+ proactiveRefreshOnVisibilityResume?: boolean;
99
+ proactiveRefreshOnOnline?: boolean;
100
+ proactiveRefreshJitterSeed?: number;
80
101
  collectorDeadlineMs?: number;
81
102
  maxQueueSize?: number;
82
103
  retryAttempts?: number;
@@ -173,15 +194,11 @@ export interface SessionData {
173
194
  isNew: boolean;
174
195
  }
175
196
  export interface TransportConfig {
176
- batchSize: number;
177
- flushInterval: number;
178
197
  maxRetries: number;
179
198
  retryDelayBase: number;
180
199
  offlineQueueSize: number;
181
200
  useCompression: boolean;
182
201
  compressionThreshold: number;
183
- networkAdaptation: boolean;
184
- dedupWindow: number;
185
202
  anonymizeIp?: boolean;
186
203
  }
187
204
  export interface TransportOptions {
@@ -189,6 +206,9 @@ export interface TransportOptions {
189
206
  priority?: 'low' | 'normal' | 'high' | 'critical';
190
207
  retry?: boolean;
191
208
  timeout?: number;
209
+ publicJwk?: EcPublicJwk;
210
+ deviceId?: string;
211
+ handoffToken?: string;
192
212
  }
193
213
  export interface TransportResponse {
194
214
  success: boolean;
@@ -209,14 +229,6 @@ export interface TransportMetrics {
209
229
  lastSuccessTimestamp?: number;
210
230
  lastErrorTimestamp?: number;
211
231
  }
212
- export interface BatchEvent {
213
- id: string;
214
- event: BeaconEvent;
215
- timestamp: number;
216
- retryCount: number;
217
- hash: string;
218
- priority: 'low' | 'normal' | 'high' | 'critical';
219
- }
220
232
  export type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
221
233
  export interface NetworkInfo {
222
234
  type?: string;
@@ -385,15 +397,33 @@ export interface OfflineQueueEntry {
385
397
  retryCount: number;
386
398
  size: number;
387
399
  }
400
+ export interface EcPublicJwk {
401
+ kty: 'EC';
402
+ crv: 'P-256';
403
+ x: string;
404
+ y: string;
405
+ }
406
+ export interface BeaconReceipt {
407
+ sessionId?: string;
408
+ browserSessionId: string;
409
+ posture?: {
410
+ token: string;
411
+ expiresAt: number;
412
+ };
413
+ postureStatus?: string;
414
+ }
388
415
  export interface BeaconBatch {
389
416
  projectId: string;
390
417
  events: BeaconEvent[];
391
418
  sessionId: string;
419
+ handoffToken?: string;
420
+ deviceId?: string;
392
421
  batchId: string;
393
422
  timestamp: number;
394
423
  anonymizeIp?: boolean;
395
424
  nonce?: string;
396
425
  nonceEcho?: boolean;
426
+ publicJwk?: EcPublicJwk;
397
427
  }
398
428
  export interface BeaconCollectorData {
399
429
  userAgent?: string;
@@ -417,7 +447,7 @@ export interface BeaconCollectorData {
417
447
  timestamp?: number;
418
448
  [key: string]: unknown;
419
449
  }
420
- export type BeaconEventType = 'pageview' | 'pageunload' | 'heartbeat' | 'custom' | 'error' | 'performance';
450
+ export type BeaconEventType = 'pageview' | 'pageunload' | 'heartbeat' | 'evidence' | 'custom' | 'error' | 'performance';
421
451
  export declare function parseRetryStrategy(input: unknown): RetryStrategy;
422
452
  export declare function parseCircuitBreakerConfig(input: unknown): CircuitBreakerConfig;
423
453
  export declare function parseOfflineQueueEntry(input: unknown): OfflineQueueEntry;
@@ -433,7 +463,7 @@ export declare const WorkerPoolConfigSchema: {
433
463
  parse: typeof parseWorkerPoolConfig;
434
464
  };
435
465
  export declare function parseWorkerCapabilities(input: unknown): WorkerCapabilities;
436
- export declare function parseBeaconConfig(input: unknown): BeaconConfig;
466
+ export declare function parseBeaconConfig(input: unknown, onWarn?: (message: string) => void): BeaconConfig;
437
467
  export declare class AgentShieldBeacon implements IAgentShieldBeacon {
438
468
  constructor(config: BeaconConfig);
439
469
  collect(eventType: string, data?: BeaconPayload): Promise<void>;
@@ -443,5 +473,11 @@ export declare class AgentShieldBeacon implements IAgentShieldBeacon {
443
473
  updateConfig(updates: Partial<BeaconConfig>): void;
444
474
  destroy(): Promise<void>;
445
475
  }
476
+ export declare const BEACON_MAX_EVENTS_PER_BATCH = 100;
477
+ export declare const SESSION_IDLE_GAP_MAX_MS = 21600000;
478
+ export declare const BEACON_MAX_BATCH_ID_LENGTH = 255;
479
+ export declare const BEACON_ORIGIN_CONTRACT_VERSION = 1;
480
+ export declare const BEACON_ORIGIN_CAPABILITIES: readonly ["batch-replay-v1", "receipt-status-v1"];
481
+ export declare const POSTURE_TTL_SECONDS = 120;
446
482
  //#endregion
447
483
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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
+ {"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;wBA4KI,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;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U;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;;iBAUe;EACf;EACA;EACA;EACA;;iBAIe;EAOf;EAKA;EAEA;IAAY;IAAe;;EAE3B;;iBAGe;EACf;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;EAEA;EAEA;EAEA;EAIA,YAAY;;iBAGG;EAEf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EAGA;EACA;GAGC;;YAGS;wBAaI,mBAAmB,iBAAiB;wBAWpC,0BAA0B,iBAAiB;wBAS3C,uBAAuB,iBAAiB;wBA2BxC,yBAAyB,iBAAiB;wBA8C1C,mBAAmB,iBAAiB;wBAkBpC,iBAAiB,iBAAiB;wBAclC,sBAAsB,iBAAiB;wBAcvC,mBAAmB,iBAAiB;qBAUvC;gBAAA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