@codemem/core 0.49.0-beta.1 → 0.49.0-beta.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 (73) hide show
  1. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  2. package/dist/coordinator-account-connection-link.d.ts +1 -1
  3. package/dist/coordinator-account-connection-link.d.ts.map +1 -1
  4. package/dist/coordinator-account-link-status-client.d.ts +4 -0
  5. package/dist/coordinator-account-link-status-client.d.ts.map +1 -1
  6. package/dist/coordinator-api.d.ts.map +1 -1
  7. package/dist/coordinator-auth-device-claim-eligibility.d.ts +12 -1
  8. package/dist/coordinator-auth-device-claim-eligibility.d.ts.map +1 -1
  9. package/dist/coordinator-auth-historical-store-test-fixture.d.ts.map +1 -1
  10. package/dist/coordinator-auth-link.d.ts +1 -0
  11. package/dist/coordinator-auth-link.d.ts.map +1 -1
  12. package/dist/coordinator-device-claim-binding-contract.d.ts +37 -0
  13. package/dist/coordinator-device-claim-binding-contract.d.ts.map +1 -0
  14. package/dist/coordinator-device-claim-binding-reuse.d.ts +21 -0
  15. package/dist/coordinator-device-claim-binding-reuse.d.ts.map +1 -0
  16. package/dist/coordinator-device-claim-binding-sql.d.ts +32 -0
  17. package/dist/coordinator-device-claim-binding-sql.d.ts.map +1 -0
  18. package/dist/coordinator-device-claim-binding.d.ts +21 -0
  19. package/dist/coordinator-device-claim-binding.d.ts.map +1 -0
  20. package/dist/coordinator-device-rebind-browser.d.ts +1 -1
  21. package/dist/coordinator-device-rebind-ceremony.d.ts.map +1 -1
  22. package/dist/coordinator-device-rebind-commit.d.ts.map +1 -1
  23. package/dist/coordinator-device-rebind-proof.d.ts +1 -0
  24. package/dist/coordinator-device-rebind-proof.d.ts.map +1 -1
  25. package/dist/coordinator-device-rebind-schema.d.ts +4 -3
  26. package/dist/coordinator-device-rebind-schema.d.ts.map +1 -1
  27. package/dist/coordinator-device-self-bind-authority.d.ts +20 -0
  28. package/dist/coordinator-device-self-bind-authority.d.ts.map +1 -0
  29. package/dist/coordinator-device-self-bind-test-fixtures.d.ts +103 -0
  30. package/dist/coordinator-device-self-bind-test-fixtures.d.ts.map +1 -0
  31. package/dist/coordinator-device-setup-client.d.ts +26 -0
  32. package/dist/coordinator-device-setup-client.d.ts.map +1 -0
  33. package/dist/coordinator-device-setup-http.d.ts +9 -0
  34. package/dist/coordinator-device-setup-http.d.ts.map +1 -0
  35. package/dist/{coordinator-runtime-Bdad5KeL.js → coordinator-runtime-kbPwxxKq.js} +3 -3
  36. package/dist/{coordinator-runtime-Bdad5KeL.js.map → coordinator-runtime-kbPwxxKq.js.map} +1 -1
  37. package/dist/index.d.ts +3 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +5222 -5059
  40. package/dist/index.js.map +1 -1
  41. package/dist/ingest-events.d.ts.map +1 -1
  42. package/dist/ingest-pipeline.d.ts +38 -2
  43. package/dist/ingest-pipeline.d.ts.map +1 -1
  44. package/dist/internal/cloudflare-coordinator.js +295 -295
  45. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  46. package/dist/internal/relay-runtime.js +2 -2
  47. package/dist/linked-legacy-setup-test-fixtures.d.ts +69 -0
  48. package/dist/linked-legacy-setup-test-fixtures.d.ts.map +1 -0
  49. package/dist/operational-status.d.ts +3 -0
  50. package/dist/operational-status.d.ts.map +1 -1
  51. package/dist/{owner-enrollment-start-DgToUaFZ.js → owner-enrollment-start-BtoRKf3z.js} +2469 -2254
  52. package/dist/owner-enrollment-start-BtoRKf3z.js.map +1 -0
  53. package/dist/owner-qualified-consumer-access-test-harness.d.ts.map +1 -1
  54. package/dist/owner-qualified-consumer-adversarial-test-harness.d.ts +1 -1
  55. package/dist/owner-qualified-consumer-adversarial-test-harness.d.ts.map +1 -1
  56. package/dist/owner-qualified-consumer-test-harness.d.ts +3 -0
  57. package/dist/owner-qualified-consumer-test-harness.d.ts.map +1 -1
  58. package/dist/owner-qualified-headless-test-harness.d.ts +1 -1
  59. package/dist/owner-qualified-headless-test-harness.d.ts.map +1 -1
  60. package/dist/project-scope-settings.d.ts.map +1 -1
  61. package/dist/raw-event-flush.d.ts.map +1 -1
  62. package/dist/{relay-peer-client-DdhDwDFz.js → relay-peer-client-0XpekgnZ.js} +2076 -2067
  63. package/dist/relay-peer-client-0XpekgnZ.js.map +1 -0
  64. package/dist/{sync-auth-constants-WKqJ9CX5.js → sync-auth-constants-DvALG0T0.js} +2339 -1987
  65. package/dist/sync-auth-constants-DvALG0T0.js.map +1 -0
  66. package/dist/sync-reachability-pass-Bi4GBi-x.js +2 -0
  67. package/dist/{sync-reachability-pass-CSg85Qmd.js → sync-reachability-pass-BpDt2z4y.js} +3 -3
  68. package/dist/{sync-reachability-pass-CSg85Qmd.js.map → sync-reachability-pass-BpDt2z4y.js.map} +1 -1
  69. package/package.json +3 -3
  70. package/dist/owner-enrollment-start-DgToUaFZ.js.map +0 -1
  71. package/dist/relay-peer-client-DdhDwDFz.js.map +0 -1
  72. package/dist/sync-auth-constants-WKqJ9CX5.js.map +0 -1
  73. package/dist/sync-reachability-pass-CQe7nZnN.js +0 -2
@@ -1,6 +1,6 @@
1
1
  import { a as e, c as t, d as n, f as r, i, l as a, m as o, o as s, p as c, s as l, u } from "../scope-membership-semantics-B8qXaMqx.js";
2
- import { $ as d, $r as f, $t as p, Ai as m, An as h, B as g, Br as _, Bt as ee, Ci as te, Cn as ne, Cr as v, Ct as re, Di as ie, Dn as y, Ei as ae, En as b, Et as oe, F as se, Fr as ce, G as le, Gr as ue, Gt as de, H as fe, Hr as pe, Ht as me, I as he, Ir as ge, Jn as _e, Jr as ve, K as ye, Kt as be, L as xe, Ln as Se, M as Ce, Mn as we, Mt as Te, N as Ee, Nn as De, Nr as Oe, O as ke, Ot as Ae, Pr as je, Pt as Me, Q as Ne, Qr as Pe, Qt as Fe, R as Ie, Rr as Le, Rt as Re, Si as ze, Sn as Be, St as Ve, Ti as He, Tn as Ue, Tt as We, U as Ge, Un as Ke, Ur as qe, Ut as Je, V as Ye, Vr as Xe, Vt as Ze, Wr as Qe, Wt as $e, X as et, Xn as tt, Xr as nt, Y as rt, Yr as it, Yt as at, Z as ot, Zr as st, Zt as ct, _i as lt, _n as ut, _t as dt, a as ft, ai as pt, ar as mt, at as ht, bi as gt, bn as x, bt as _t, c as vt, ci as yt, cn as S, cr as bt, ct as xt, d as St, di as Ct, dn as wt, dr as Tt, dt as Et, ei as Dt, en as Ot, et as kt, f as At, fn as jt, fr as Mt, ft as Nt, gi as Pt, gn as Ft, gt as It, hi as Lt, hn as Rt, ht as zt, i as Bt, ii as C, in as w, it as Vt, j as Ht, jn as Ut, jt as Wt, ki as Gt, kn as Kt, kt as qt, l as Jt, ln as Yt, lt as Xt, mn as Zt, mt as Qt, ni as $t, nn as en, nt as tn, o as nn, oi as rn, or as an, ot as on, p as sn, pn as cn, pr as ln, pt as un, q as dn, qn as fn, qr as pn, qt as mn, r as T, rn as hn, rr as gn, rt as _n, s as vn, sn as yn, sr as bn, st as xn, t as Sn, ti as Cn, tn as wn, tr as Tn, tt as En, u as Dn, un as On, ur as kn, ut as An, vi as jn, vn as Mn, vt as Nn, wn as E, wt as Pn, xi as Fn, xn as In, xr as Ln, xt as Rn, yi as zn, yr as Bn, yt as Vn, z as Hn, zr as Un, zt as Wn } from "../sync-auth-constants-WKqJ9CX5.js";
3
- import { $ as Gn, B as Kn, C as qn, G as D, J as Jn, K as Yn, Q as Xn, R as Zn, W as O, X as Qn, Y as k, Z as $n, _ as er, a as tr, b as nr, c as rr, d as ir, et as ar, f as or, g as A, h as sr, i as cr, l as lr, m as ur, n as dr, nt as fr, o as pr, p as mr, q as hr, rt as gr, s as _r, st as vr, t as yr, tt as br, u as xr, x as Sr, y as Cr, z as wr } from "../owner-enrollment-start-DgToUaFZ.js";
2
+ import { $ as d, $r as f, $t as p, Ai as m, An as h, B as g, Bt as ee, Ci as te, Cn as ne, Ct as re, Di as _, Dn as v, Dr as ie, Ei as y, En as b, Et as ae, F as oe, Fi as se, Fn as ce, G as le, Gn as ue, Gt as de, H as fe, Hr as pe, Ht as me, I as he, Ii as ge, Jr as _e, K as ve, Kr as ye, Kt as be, L as xe, M as Se, Mt as Ce, N as we, O as Te, Oi as Ee, Ot as De, Pi as Oe, Pn as ke, Pt as Ae, Q as je, Qn as Me, Qr as Ne, Qt as Pe, R as Fe, Ri as Ie, Rt as Le, Sn as Re, St as ze, Ti as Be, Tn as x, Tt as Ve, U as He, Ur as Ue, Ut as We, V as Ge, Vr as Ke, Vt as qe, Wr as Je, Wt as Ye, X as Xe, Xn as Ze, Xr as Qe, Y as $e, Yn as et, Yr as tt, Yt as nt, Z as rt, Zr as it, Zt as at, _n as ot, _t as st, a as ct, ai as lt, ar as ut, at as dt, bn as S, br as ft, bt as pt, c as mt, ci as ht, cn as C, cr as gt, ct as _t, d as vt, dn as yt, dt as bt, en as xt, et as St, f as Ct, fi as w, fn as wt, fr as Tt, ft as Et, gi as Dt, gn as Ot, gt as kt, hn as At, ht as jt, i as Mt, ii as Nt, in as T, it as Pt, j as Ft, ji as It, jn as Lt, jr as Rt, jt as zt, ki as Bt, kn as Vt, kr as Ht, kt as Ut, l as Wt, li as Gt, ln as Kt, lr as qt, lt as Jt, mi as Yt, mn as Xt, mt as Zt, ni as Qt, nn as $t, nt as en, o as tn, oi as nn, ot as rn, p as an, pi as on, pn as sn, pt as cn, q as ln, qr as un, qt as dn, r as E, ri as fn, rn as pn, rr as mn, rt as hn, s as gn, si as _n, sn as vn, sr as yn, st as bn, t as xn, ti as Sn, tn as Cn, tt as wn, u as Tn, ui as En, un as Dn, ur as On, ut as kn, vn as An, vt as jn, wi as Mn, wn as Nn, wt as Pn, xn as Fn, xr as In, xt as Ln, yi as Rn, yr as zn, yt as Bn, z as Vn, zi as Hn, zn as Un, zt as Wn } from "../sync-auth-constants-DvALG0T0.js";
3
+ import { $ as Gn, B as Kn, C as qn, G as D, J as Jn, K as Yn, Q as Xn, R as Zn, W as O, X as Qn, Y as k, Z as $n, _ as er, a as tr, b as nr, c as rr, d as ir, et as ar, f as or, g as A, h as sr, i as cr, l as lr, m as ur, n as dr, nt as fr, o as pr, p as mr, q as hr, rt as gr, s as _r, st as vr, t as yr, tt as br, u as xr, x as Sr, y as Cr, z as wr } from "../owner-enrollment-start-BtoRKf3z.js";
4
4
  import { n as Tr, t as Er } from "../relay-health-zrKtNQLQ.js";
5
5
  import { i as Dr, n as Or, s as kr } from "../relay-quota-sqlite-C1th1yVy.js";
6
6
  //#region src/coordinator-account-change-browser.ts
@@ -19,7 +19,7 @@ function Mr(e) {
19
19
  }
20
20
  async function j(e = 403) {
21
21
  try {
22
- return jr(await S("auth_unavailable"), e);
22
+ return jr(await C("auth_unavailable"), e);
23
23
  } catch {
24
24
  return new Response("Account change unavailable. Return to your terminal and try again.", {
25
25
  status: 503,
@@ -32,7 +32,7 @@ async function j(e = 403) {
32
32
  }
33
33
  }
34
34
  async function Nr(e, t, n, r = "") {
35
- let i = (await S("auth_unavailable")).headers;
35
+ let i = (await C("auth_unavailable")).headers;
36
36
  i["Referrer-Policy"] = "same-origin";
37
37
  let a = Object.entries(n).map(([e, t]) => `<input type="hidden" name="${Mr(e)}" value="${Mr(t)}">`).join("");
38
38
  return new Response(`<!doctype html><html lang="en"><meta charset="utf-8"><meta name="referrer" content="same-origin"><title>${Mr(e)}</title><main><h1>${Mr(e)}</h1><p>${Mr(r)}</p><form method="post" action="${t}">${a}<button type="submit">${Mr(e)}</button></form></main></html>`, { headers: i });
@@ -46,15 +46,15 @@ function Fr(e, t) {
46
46
  let n = new URL(e);
47
47
  if (n.href !== e || `${n.origin}${n.pathname}` !== t || n.username || n.password || [...n.searchParams].length !== 2 || n.searchParams.getAll("attempt_id").length !== 1 || n.searchParams.getAll("start_code").length !== 1) return null;
48
48
  let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
49
- return !C(r) || !i || !je(i) ? null : {
49
+ return !w(r) || !i || !pe(i) ? null : {
50
50
  attemptId: r,
51
51
  startCode: i
52
52
  };
53
53
  }
54
54
  async function Ir(e, t, n, r) {
55
- let i = je(n);
55
+ let i = pe(n);
56
56
  if (!i) return null;
57
- let a = await ge(i), o = await e.readStart({
57
+ let a = await Je(i), o = await e.readStart({
58
58
  attemptId: t,
59
59
  browserStartHash: a
60
60
  }, r);
@@ -70,7 +70,7 @@ async function Lr(e, t, n) {
70
70
  return i.kind === "absent" || i.kind === "present" && (await t.readers.readManagementActivity({ binderHash: i.cookieHash }, n)).kind === "inactive";
71
71
  }
72
72
  async function Rr(e, t) {
73
- return jr(await Yt({
73
+ return jr(await Kt({
74
74
  destination: e.loopbackRedirect,
75
75
  attemptId: e.attemptId,
76
76
  completionSecret: t
@@ -78,7 +78,7 @@ async function Rr(e, t) {
78
78
  }
79
79
  async function zr(e) {
80
80
  let t = await b(e, "start");
81
- return t.kind === "invalid" ? null : t.kind === "present" ? t : Ue("start");
81
+ return t.kind === "invalid" ? null : t.kind === "present" ? t : x("start");
82
82
  }
83
83
  async function Br(e, t) {
84
84
  let { input: n, config: r, scope: i, startUrl: a } = e;
@@ -91,7 +91,7 @@ async function Br(e, t) {
91
91
  if (!await Lr(e.cookie, n, r)) return j(409);
92
92
  let s = await zr(e.cookie);
93
93
  if (!s) return j(400);
94
- let c = await x(n.csrfKey, s.secret, "start", i), l = await Nr("Continue with Google", Ar.start, {
94
+ let c = await S(n.csrfKey, s.secret, "start", i), l = await Nr("Continue with Google", Ar.start, {
95
95
  attempt_id: o.attemptId,
96
96
  start_code: o.startCode,
97
97
  csrf: c
@@ -123,7 +123,7 @@ async function Vr(e, t, n) {
123
123
  async function Hr(e, t, n) {
124
124
  let { input: r, config: i, client: a } = e, o = await Ir(r.readers, n.attemptId, n.startCode, i), s = await b(t, "start");
125
125
  if (!o || s.kind !== "present" || s.cookieHash !== n.cookieHash) return j();
126
- let c = await a.createAuthorizationRequest(), l = jr(await cn({ authorizationUrl: c.authorizationUrl }));
126
+ let c = await a.createAuthorizationRequest(), l = jr(await sn({ authorizationUrl: c.authorizationUrl }));
127
127
  return await r.operations.claimBrowser({
128
128
  attemptId: n.attemptId,
129
129
  browserStartHash: o.browserStartHash,
@@ -131,7 +131,7 @@ async function Hr(e, t, n) {
131
131
  binderHash: n.cookieHash,
132
132
  nonce: c.material.nonce,
133
133
  pkceVerifier: c.material.pkceVerifier
134
- }, i) ? (l.headers.append("Set-Cookie", y(s.secret)), l.headers.append("Set-Cookie", E("start")), l) : j(409);
134
+ }, i) ? (l.headers.append("Set-Cookie", v(s.secret)), l.headers.append("Set-Cookie", Nn("start")), l) : j(409);
135
135
  }
136
136
  async function Ur(e, t) {
137
137
  let { config: n } = e, r = D(t);
@@ -166,7 +166,7 @@ async function Gr(e, t, n, r, i) {
166
166
  if (!c || c.attemptId !== t.attemptId) throw Error("callback_unavailable");
167
167
  if (c.intent === "refresh") return Rr(c, n);
168
168
  if (c.intent !== "disconnect") throw Error("callback_unavailable");
169
- let l = await x(a.csrfKey, r.secret, "transaction", s), u = yn(i, o.issuer);
169
+ let l = await S(a.csrfKey, r.secret, "transaction", s), u = vn(i, o.issuer);
170
170
  return Nr("Disconnect Google account", Ar.confirm, {
171
171
  attempt_id: t.attemptId,
172
172
  csrf: l
@@ -187,7 +187,7 @@ async function Kr(e, t) {
187
187
  async function qr(e, t, n) {
188
188
  let { input: r, config: i } = e;
189
189
  try {
190
- if (!C(n)) return j(503);
190
+ if (!w(n)) return j(503);
191
191
  if (!Jn(t, r.limiter, JSON.stringify([
192
192
  "browser-callback",
193
193
  i.coordinatorId,
@@ -222,13 +222,13 @@ async function Jr(e, t, n, r) {
222
222
  }
223
223
  });
224
224
  if (!s.ok) throw Error("provider_rejected");
225
- let c = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), l = await Gr(e, r, ce(c), t.cookie, s.profile);
225
+ let c = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), l = await Gr(e, r, Ue(c), t.cookie, s.profile);
226
226
  if (!await i.operations.recordVerifiedCallback({
227
227
  ...r,
228
228
  issuer: s.account.issuer,
229
229
  subject: s.account.subject,
230
230
  profile: s.profile,
231
- completionSecretHash: await ge(c)
231
+ completionSecretHash: await Je(c)
232
232
  }, a)) throw Error("account_rejected");
233
233
  return l;
234
234
  } catch {
@@ -256,12 +256,12 @@ async function Yr(e, t, n) {
256
256
  binderHash: c.cookieHash
257
257
  });
258
258
  if (!l || !Xr(l, c)) return j();
259
- let u = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), d = await Rr(l, ce(u));
259
+ let u = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), d = await Rr(l, Ue(u));
260
260
  return await r.operations.confirmDisconnect({
261
261
  attemptId: l.attemptId,
262
262
  stateHash: l.stateHash,
263
263
  binderHash: c.cookieHash,
264
- completionSecretHash: await ge(u)
264
+ completionSecretHash: await Je(u)
265
265
  }, i) ? d : j();
266
266
  } catch {
267
267
  return j(503);
@@ -276,7 +276,7 @@ async function Zr(e) {
276
276
  ok: !1,
277
277
  error: "browser_auth_unavailable"
278
278
  };
279
- if (!Mn(e.csrfKey) || !e.readers || [
279
+ if (!An(e.csrfKey) || !e.readers || [
280
280
  "readStart",
281
281
  "readManagementActivity",
282
282
  "readBrowserBinding"
@@ -367,7 +367,7 @@ function ri() {
367
367
  }
368
368
  async function N(e, t, n) {
369
369
  try {
370
- return ti(ni(await S(e === 200 ? "signed_out" : "auth_unavailable"), e, n), t);
370
+ return ti(ni(await C(e === 200 ? "signed_out" : "auth_unavailable"), e, n), t);
371
371
  } catch {
372
372
  return ri();
373
373
  }
@@ -380,7 +380,7 @@ function ai(e, t) {
380
380
  let n = M(e, "account");
381
381
  $r(n);
382
382
  let r = M(n, "issuer"), i = M(e, "identityId");
383
- if (r !== t.storeConfig.issuer || !C(i)) throw Error();
383
+ if (r !== t.storeConfig.issuer || !w(i)) throw Error();
384
384
  return i;
385
385
  }
386
386
  async function oi(e, t) {
@@ -393,8 +393,8 @@ async function oi(e, t) {
393
393
  let a = await e.store.readAuthSessionAccount(i.cookieHash, e.storeConfig);
394
394
  if (a === null) return await N(200, "signed_out");
395
395
  $r(a);
396
- let o = ai(M(a, "session"), e), s = M(a, "profile"), c = await x(e.csrfKey, i.secret, "session", e.scope);
397
- return ti(ni(await Rt({
396
+ let o = ai(M(a, "session"), e), s = M(a, "profile"), c = await S(e.csrfKey, i.secret, "session", e.scope);
397
+ return ti(ni(await At({
398
398
  profile: s,
399
399
  issuer: e.storeConfig.issuer,
400
400
  identity: { id: o },
@@ -418,8 +418,8 @@ function si(e) {
418
418
  }
419
419
  }
420
420
  async function ci(e, t) {
421
- let n = ni(await S("signed_out"));
422
- n.headers.append("Set-Cookie", E("session"));
421
+ let n = ni(await C("signed_out"));
422
+ n.headers.append("Set-Cookie", Nn("session"));
423
423
  let r = await e.store.readAuthSession(t, e.storeConfig);
424
424
  if (r === null) return ti(n, "already_signed_out");
425
425
  ai(r, e);
@@ -430,7 +430,7 @@ async function ci(e, t) {
430
430
  }
431
431
  async function li(e, t, n) {
432
432
  try {
433
- let r = D(t), i = ii(r, `${e.publicOrigin}${en.signOut}`, "POST");
433
+ let r = D(t), i = ii(r, `${e.publicOrigin}${$t.signOut}`, "POST");
434
434
  if (i) return await i;
435
435
  let a = await k({
436
436
  request: t,
@@ -569,7 +569,7 @@ function F(e, t) {
569
569
  }
570
570
  async function I(e, t, n = {}) {
571
571
  try {
572
- let r = await S("auth_unavailable"), i = new Headers(r.headers);
572
+ let r = await C("auth_unavailable"), i = new Headers(r.headers);
573
573
  return n.allow && i.set("Allow", n.allow), F(new Response(r.body, {
574
574
  status: e,
575
575
  headers: i
@@ -671,7 +671,7 @@ async function Ei(e, t, n, r) {
671
671
  let i = await b(t.cookie, "session");
672
672
  if (i.kind === "invalid") throw Error();
673
673
  if (i.kind === "present" && await e.store.readAuthSession(i.cookieHash, e.storeConfig)) return F(bi(e), "session_live");
674
- let a = await Ue("session"), o = bi(e, a.setCookie);
674
+ let a = await x("session"), o = bi(e, a.setCookie);
675
675
  return (await e.store.signInWithConsumedBrowserTransaction({
676
676
  browserTransactionHash: n.browserTransactionHash,
677
677
  account: r.account,
@@ -781,15 +781,15 @@ function Fi(e) {
781
781
  nowMs: r
782
782
  };
783
783
  }
784
- var Ii = `INSERT INTO ${Ke} (coordinator_id, scope, key_hash, window_start_ms, failures)
784
+ var Ii = `INSERT INTO ${ue} (coordinator_id, scope, key_hash, window_start_ms, failures)
785
785
  VALUES (?, ?, ?, ?, 1)
786
786
  ON CONFLICT (coordinator_id, scope, key_hash) DO UPDATE SET
787
787
  failures = CASE WHEN window_start_ms + ${Ai} <= excluded.window_start_ms
788
788
  THEN 1 ELSE failures + 1 END,
789
789
  window_start_ms = CASE WHEN window_start_ms + ${Ai} <= excluded.window_start_ms
790
790
  THEN excluded.window_start_ms ELSE window_start_ms END
791
- RETURNING failures, window_start_ms`, Li = `DELETE FROM ${Ke} WHERE (coordinator_id, scope, key_hash) IN (
792
- SELECT coordinator_id, scope, key_hash FROM ${Ke}
791
+ RETURNING failures, window_start_ms`, Li = `DELETE FROM ${ue} WHERE (coordinator_id, scope, key_hash) IN (
792
+ SELECT coordinator_id, scope, key_hash FROM ${ue}
793
793
  WHERE window_start_ms + ${Ai} <= ? LIMIT 32)`;
794
794
  async function Ri(e, t, n) {
795
795
  let r = n === "client" ? t.clientKeyHash : "", i = await e.first({
@@ -832,7 +832,7 @@ function Gi(e, t = 200) {
832
832
  });
833
833
  }
834
834
  async function L(e, t = {}) {
835
- let n = Gi(await S("unavailable"), e);
835
+ let n = Gi(await C("unavailable"), e);
836
836
  for (let [e, r] of Object.entries(t)) n.headers.set(e, r);
837
837
  return n;
838
838
  }
@@ -842,7 +842,7 @@ async function Ki(e, t, n) {
842
842
  if (r === "active") return L(409);
843
843
  let i = await b(t, "start");
844
844
  if (i.kind === "invalid") return L(400);
845
- let a = i.kind === "present" ? i : await Ue("start"), o = await x(e.csrfKey, a.secret, "start", e.scope), s = n.rejected ? Hi : 200, c = Gi(await ar({
845
+ let a = i.kind === "present" ? i : await x("start"), o = await S(e.csrfKey, a.secret, "start", e.scope), s = n.rejected ? Hi : 200, c = Gi(await ar({
846
846
  csrfToken: o,
847
847
  rejected: n.rejected
848
848
  }), s);
@@ -878,16 +878,16 @@ async function Yi(e) {
878
878
  async function Xi(e, t, n) {
879
879
  let r = await b(t.cookie, "start");
880
880
  if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return L(503);
881
- let i = gn(n.userCode);
881
+ let i = ut(n.userCode);
882
882
  if (i === null) return null;
883
- let a = await Tn(i), o;
883
+ let a = await mn(i), o;
884
884
  try {
885
885
  o = await e.client.createAuthorizationRequest();
886
886
  } catch {
887
887
  return L(503);
888
888
  }
889
- let s = Gi(await cn({ authorizationUrl: o.authorizationUrl }));
890
- return s.headers.append("Set-Cookie", y(r.secret)), s.headers.append("Set-Cookie", E("start")), (await e.store.startHeadlessAuthLinkBrowserTransaction({
889
+ let s = Gi(await sn({ authorizationUrl: o.authorizationUrl }));
890
+ return s.headers.append("Set-Cookie", v(r.secret)), s.headers.append("Set-Cookie", Nn("start")), (await e.store.startHeadlessAuthLinkBrowserTransaction({
891
891
  userCodeHash: a,
892
892
  stateHash: await Yi(o.material.state),
893
893
  binderHash: n.cookieHash,
@@ -951,7 +951,7 @@ async function $i(e) {
951
951
  limits: e.limits,
952
952
  limiter: e.limiter,
953
953
  client: n.client,
954
- clientHashKey: await Ft(e.csrfKey, Vi),
954
+ clientHashKey: await Ot(e.csrfKey, Vi),
955
955
  pageUrl: new URL(Xn.code, t.publicOrigin).href
956
956
  });
957
957
  return Object.freeze({
@@ -992,7 +992,7 @@ function na() {
992
992
  }
993
993
  async function R(e, t, n) {
994
994
  try {
995
- return ea(ta(await S("auth_unavailable"), e, n), t);
995
+ return ea(ta(await C("auth_unavailable"), e, n), t);
996
996
  } catch {
997
997
  return na();
998
998
  }
@@ -1011,7 +1011,7 @@ function ra(e) {
1011
1011
  }
1012
1012
  }
1013
1013
  async function ia(e, t, n, r) {
1014
- let i = ta(await S(r === "cancelled" ? "link_cancelled" : "auth_unavailable"), r === "cancelled" ? 200 : 403), a = await e.store.failAuthLinkAttempt({
1014
+ let i = ta(await C(r === "cancelled" ? "link_cancelled" : "auth_unavailable"), r === "cancelled" ? 200 : 403), a = await e.store.failAuthLinkAttempt({
1015
1015
  attemptId: t,
1016
1016
  requester: {
1017
1017
  kind: "browser",
@@ -1027,7 +1027,7 @@ async function aa(e, t) {
1027
1027
  try {
1028
1028
  let n = ca(t);
1029
1029
  if (n === null) return (await R(403, "link_rejected")).response;
1030
- let r = await b(`${Be.transaction}=${n}`, "transaction");
1030
+ let r = await b(`${Re.transaction}=${n}`, "transaction");
1031
1031
  if (r.kind !== "present" || r.cookieHash !== t.transactionCookieHash) return (await R(403, "link_rejected")).response;
1032
1032
  let i = await e.store.resolveAuthLinkBrowserTransaction({
1033
1033
  attemptId: t.attemptId,
@@ -1056,7 +1056,7 @@ async function oa(e, t, n, r) {
1056
1056
  let s = await e.store.readHeadlessAuthLinkDeviceName?.({
1057
1057
  attemptId: t.attemptId,
1058
1058
  browserTransactionHash: t.browserTransactionHash
1059
- }, e.config) ?? null, c = await x(e.csrfKey, n, "transaction", e.scope);
1059
+ }, e.config) ?? null, c = await S(e.csrfKey, n, "transaction", e.scope);
1060
1060
  return ta(await fr({
1061
1061
  profile: i,
1062
1062
  issuer: e.config.issuer,
@@ -1067,8 +1067,8 @@ async function oa(e, t, n, r) {
1067
1067
  }));
1068
1068
  }
1069
1069
  async function sa(e, t, n, r, i) {
1070
- let a = await x(e.csrfKey, n, "transaction", e.scope);
1071
- return ta(await wt({
1070
+ let a = await S(e.csrfKey, n, "transaction", e.scope);
1071
+ return ta(await yt({
1072
1072
  profile: r,
1073
1073
  issuer: e.config.issuer,
1074
1074
  identity: { id: i.identityId },
@@ -1091,7 +1091,7 @@ async function la(e, t, n) {
1091
1091
  browserTransactionHash: n
1092
1092
  }, e.config);
1093
1093
  if (!r) return da(e, t, n);
1094
- let i = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), a = btoa(String.fromCharCode(...i)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), o = await globalThis.crypto.subtle.digest("SHA-256", i), s = Array.from(new Uint8Array(o), (e) => e.toString(16).padStart(2, "0")).join(""), c = ta(await Yt({
1094
+ let i = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), a = btoa(String.fromCharCode(...i)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), o = await globalThis.crypto.subtle.digest("SHA-256", i), s = Array.from(new Uint8Array(o), (e) => e.toString(16).padStart(2, "0")).join(""), c = ta(await Kt({
1095
1095
  destination: r.destination,
1096
1096
  attemptId: t,
1097
1097
  completionSecret: a
@@ -1103,8 +1103,8 @@ async function la(e, t, n) {
1103
1103
  }, e.config)).kind === "applied" ? ea(c, "link_confirmed") : R(403, "link_rejected");
1104
1104
  }
1105
1105
  var ua = Object.freeze({
1106
- confirmLink: en.confirmLink,
1107
- cancelLink: en.cancelLink,
1106
+ confirmLink: $t.confirmLink,
1107
+ cancelLink: $t.cancelLink,
1108
1108
  confirmHeadless: Xn.confirm
1109
1109
  });
1110
1110
  async function da(e, t, n) {
@@ -1211,7 +1211,7 @@ function ga(e, t = 200, n) {
1211
1211
  }
1212
1212
  async function z(e, t, n) {
1213
1213
  try {
1214
- return ha(ga(await S("auth_unavailable"), e, n), t);
1214
+ return ha(ga(await C("auth_unavailable"), e, n), t);
1215
1215
  } catch {
1216
1216
  return ha(new Response("Linking unavailable. Try again.", {
1217
1217
  status: 503,
@@ -1233,7 +1233,7 @@ function va(e) {
1233
1233
  let t = [...e.searchParams], n = t[0];
1234
1234
  if (t.length !== 1 || !n || n[0] !== "attempt_id") return null;
1235
1235
  let r = n[1];
1236
- return C(r) ? r : null;
1236
+ return w(r) ? r : null;
1237
1237
  }
1238
1238
  async function ya(e, t, n) {
1239
1239
  let r = await e.store.resolveAuthLinkBrowserTransaction({
@@ -1269,20 +1269,20 @@ async function ba(e, t) {
1269
1269
  if (n.method !== "GET") return await z(405, "method_not_allowed", { Allow: "GET" });
1270
1270
  if (n.url.length > 8192) return await z(400, "query_invalid");
1271
1271
  let r = new URL(n.url);
1272
- if (n.url.includes("#") || `${r.origin}${r.pathname}` != `${e.publicOrigin}${en.completeLink}` || r.username || r.password) return await z(404, "not_found");
1272
+ if (n.url.includes("#") || `${r.origin}${r.pathname}` != `${e.publicOrigin}${$t.completeLink}` || r.username || r.password) return await z(404, "not_found");
1273
1273
  let i = va(r);
1274
1274
  if (i === null) return await z(400, "query_invalid");
1275
1275
  let a = await b(n.cookie, "transaction");
1276
1276
  if (a.kind !== "present") return await z(403, "cookie_invalid");
1277
1277
  let o = await ya(e, i, a.cookieHash);
1278
1278
  if (o?.headless) return _a.has(o.state) ? ha(ga(await gr()), "waiting") : await z(403, "completion_rejected");
1279
- if (o?.state === "confirmed") return ha(ga(await On({
1279
+ if (o?.state === "confirmed") return ha(ga(await Dn({
1280
1280
  attemptId: i,
1281
1281
  state: "waiting"
1282
1282
  })), "waiting");
1283
1283
  if (o?.state !== "finalized") return await z(403, "completion_rejected");
1284
- let s = await x(e.csrfKey, a.secret, "transaction", e.scope);
1285
- return ha(ga(await On({
1284
+ let s = await S(e.csrfKey, a.secret, "transaction", e.scope);
1285
+ return ha(ga(await Dn({
1286
1286
  attemptId: i,
1287
1287
  state: "ready",
1288
1288
  csrfToken: s
@@ -1328,7 +1328,7 @@ async function Ca(e, t, n, r, i) {
1328
1328
  credentialHash: a.cookieHash
1329
1329
  }, e.config)).kind === "preserved" ? ha(t, "session_preserved") : z(403, "completion_rejected");
1330
1330
  }
1331
- let o = await Ue("session"), s = Sa(e, o.setCookie);
1331
+ let o = await x("session"), s = Sa(e, o.setCookie);
1332
1332
  return (await e.store.redeemAuthLinkSessionWithBrowserTransaction({
1333
1333
  attemptId: n,
1334
1334
  browserTransactionHash: i,
@@ -1340,7 +1340,7 @@ async function wa(e, t, n) {
1340
1340
  try {
1341
1341
  let r = D(t);
1342
1342
  if (r.method !== "POST") return await z(405, "method_not_allowed", { Allow: "POST" });
1343
- if (r.url !== `${e.publicOrigin}${en.completeLink}`) return await z(404, "not_found");
1343
+ if (r.url !== `${e.publicOrigin}${$t.completeLink}`) return await z(404, "not_found");
1344
1344
  let i = await k({
1345
1345
  request: t,
1346
1346
  scope: e.scope,
@@ -1437,7 +1437,7 @@ function Ma(e, t = 200, n) {
1437
1437
  }
1438
1438
  async function B(e, t, n) {
1439
1439
  try {
1440
- return ja(Ma(await S("unavailable"), e, n), t);
1440
+ return ja(Ma(await C("unavailable"), e, n), t);
1441
1441
  } catch {
1442
1442
  return ja(new Response("Account linking unavailable. Return to your terminal and try again.", {
1443
1443
  status: 503,
@@ -1454,7 +1454,7 @@ function Na(e, t) {
1454
1454
  let n = new URL(t);
1455
1455
  if (t.includes("#") || n.href !== t || `${n.origin}${n.pathname}` !== e.startUrl || n.username || n.password || [...n.searchParams].length !== 2 || n.searchParams.getAll("attempt_id").length !== 1 || n.searchParams.getAll("start_code").length !== 1) return null;
1456
1456
  let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
1457
- return !C(r) || typeof i != "string" || !je(i) ? null : Object.freeze({
1457
+ return !w(r) || typeof i != "string" || !pe(i) ? null : Object.freeze({
1458
1458
  attemptId: r,
1459
1459
  startCode: i
1460
1460
  });
@@ -1473,7 +1473,7 @@ async function Pa(e, t) {
1473
1473
  if (o === "active") return await B(409, "link_in_progress");
1474
1474
  let s = await b(a.cookie, "start");
1475
1475
  if (s.kind === "invalid") return await B(400, "cookie_invalid");
1476
- let c = s.kind === "present" ? s : await Ue("start"), l = await x(e.csrfKey, c.secret, "start", e.scope), u = Ma(await jt({
1476
+ let c = s.kind === "present" ? s : await x("start"), l = await S(e.csrfKey, c.secret, "start", e.scope), u = Ma(await wt({
1477
1477
  ...i,
1478
1478
  csrfToken: l
1479
1479
  }));
@@ -1499,16 +1499,16 @@ function Ia(e) {
1499
1499
  async function La(e, t, n) {
1500
1500
  let r = await b(t.cookie, "start");
1501
1501
  if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return B(503, "internal_error");
1502
- let i = je(n.startCode);
1502
+ let i = pe(n.startCode);
1503
1503
  if (!i) return B(400, "form_invalid");
1504
- let a = await ge(i), o;
1504
+ let a = await Je(i), o;
1505
1505
  try {
1506
1506
  o = await e.client.createAuthorizationRequest();
1507
1507
  } catch {
1508
1508
  return B(503, "provider_request_failed");
1509
1509
  }
1510
- let s = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(o.material.state)), c = Array.from(new Uint8Array(s), (e) => e.toString(16).padStart(2, "0")).join(""), l = Ma(await cn({ authorizationUrl: o.authorizationUrl }));
1511
- l.headers.append("Set-Cookie", y(r.secret)), l.headers.append("Set-Cookie", E("start"));
1510
+ let s = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(o.material.state)), c = Array.from(new Uint8Array(s), (e) => e.toString(16).padStart(2, "0")).join(""), l = Ma(await sn({ authorizationUrl: o.authorizationUrl }));
1511
+ l.headers.append("Set-Cookie", v(r.secret)), l.headers.append("Set-Cookie", Nn("start"));
1512
1512
  let u = await e.store.startAuthBrowserTransaction({
1513
1513
  purpose: "link",
1514
1514
  attemptId: n.attemptId,
@@ -1677,7 +1677,7 @@ function Ya() {
1677
1677
  }
1678
1678
  async function V(e, t, n) {
1679
1679
  try {
1680
- return qa(Ja(await S(t === "signin_in_progress" || t === "start_conflict" ? "signin_in_progress" : "signin_unavailable"), e, n), t);
1680
+ return qa(Ja(await C(t === "signin_in_progress" || t === "start_conflict" ? "signin_in_progress" : "signin_unavailable"), e, n), t);
1681
1681
  } catch {
1682
1682
  return Ya();
1683
1683
  }
@@ -1710,7 +1710,7 @@ async function $a(e, t) {
1710
1710
  if (await Za(e, n)) return Xa(e);
1711
1711
  let a = await b(n.cookie, "start");
1712
1712
  if (a.kind === "invalid") return await V(400, "cookie_invalid");
1713
- let o = a.kind === "present" ? a : await Ue("start"), s = await x(e.csrfKey, o.secret, "start", e.scope), c = Ja(await Zt({ csrfToken: s }));
1713
+ let o = a.kind === "present" ? a : await x("start"), s = await S(e.csrfKey, o.secret, "start", e.scope), c = Ja(await Xt({ csrfToken: s }));
1714
1714
  return "setCookie" in o && c.headers.append("Set-Cookie", o.setCookie), qa(c, "signin_page");
1715
1715
  } catch {
1716
1716
  return await V(503, "internal_error");
@@ -1739,8 +1739,8 @@ async function no(e, t, n) {
1739
1739
  } catch {
1740
1740
  return V(503, "provider_request_failed");
1741
1741
  }
1742
- let a = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(i.material.state)), o = Array.from(new Uint8Array(a), (e) => e.toString(16).padStart(2, "0")).join(""), s = Ja(await cn({ authorizationUrl: i.authorizationUrl }));
1743
- s.headers.append("Set-Cookie", y(r.secret)), s.headers.append("Set-Cookie", E("start"));
1742
+ let a = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(i.material.state)), o = Array.from(new Uint8Array(a), (e) => e.toString(16).padStart(2, "0")).join(""), s = Ja(await sn({ authorizationUrl: i.authorizationUrl }));
1743
+ s.headers.append("Set-Cookie", v(r.secret)), s.headers.append("Set-Cookie", Nn("start"));
1744
1744
  let c = await e.store.startAuthBrowserTransaction({
1745
1745
  purpose: "signin",
1746
1746
  stateHash: o,
@@ -1840,10 +1840,10 @@ var H = Object.freeze({
1840
1840
  confirm: "/auth/rebind/confirm"
1841
1841
  });
1842
1842
  function oo(e) {
1843
- return Object.entries(e).map(([e, t]) => `<input type="hidden" name="${w(e)}" value="${w(t)}">`).join("");
1843
+ return Object.entries(e).map(([e, t]) => `<input type="hidden" name="${T(e)}" value="${T(t)}">`).join("");
1844
1844
  }
1845
1845
  function so(e, t, n) {
1846
- return `<form method="post" action="${e}">${oo(t)}<button type="submit">${w(n)}</button></form>`;
1846
+ return `<form method="post" action="${e}">${oo(t)}<button type="submit">${T(n)}</button></form>`;
1847
1847
  }
1848
1848
  function co(e) {
1849
1849
  let t = {
@@ -1851,13 +1851,13 @@ function co(e) {
1851
1851
  attempt_id: e.attemptId,
1852
1852
  start_code: e.startCode
1853
1853
  };
1854
- return hn("Sign in on this device", `<h1>Connecting to Google…</h1><p>You’ll choose an account and confirm before this device changes.</p><p class="note">If nothing happens, continue below. Do not share this page.</p><div class="actions">${so(H.start, t, "Continue with Google")}</div>`, void 0, {
1854
+ return pn("Sign in on this device", `<h1>Connecting to Google…</h1><p>You’ll choose an account and confirm before this device changes.</p><p class="note">If nothing happens, continue below. Do not share this page.</p><div class="actions">${so(H.start, t, "Continue with Google")}</div>`, void 0, {
1855
1855
  referrerPolicy: "same-origin",
1856
1856
  autoSubmit: !0
1857
1857
  });
1858
1858
  }
1859
1859
  function U(e, t) {
1860
- return `<dt>${w(e)}</dt><dd><code>${w(t)}</code></dd>`;
1860
+ return `<dt>${T(e)}</dt><dd><code>${T(t)}</code></dd>`;
1861
1861
  }
1862
1862
  function lo(e) {
1863
1863
  let t = e.confirmation, n = U("Device", t.deviceId) + U("Key fingerprint", t.fingerprint) + U("Identity", t.currentIdentityId), r = {
@@ -1865,7 +1865,7 @@ function lo(e) {
1865
1865
  attempt_id: t.attemptId,
1866
1866
  confirmation_hash: t.confirmationHash
1867
1867
  };
1868
- return hn("Use this account on this device", `<h1>Use this account on this device</h1><p>This Google account already belongs to this device’s Identity. Confirming lets this device refresh and unlink it too.</p><section aria-label="Device"><dl>${n}</dl></section><p>A device can do this only once.</p><div class="actions">${so(H.confirm, r, "Confirm")}</div>`, void 0, { referrerPolicy: "same-origin" });
1868
+ return pn("Use this account on this device", `<h1>Use this account on this device</h1><p>This Google account already belongs to this device’s Identity. Confirming lets this device refresh and unlink it too.</p><section aria-label="Device"><dl>${n}</dl></section><p>A device can do this only once.</p><div class="actions">${so(H.confirm, r, "Confirm")}</div>`, void 0, { referrerPolicy: "same-origin" });
1869
1869
  }
1870
1870
  function uo(e) {
1871
1871
  let t = e.confirmation;
@@ -1875,13 +1875,13 @@ function uo(e) {
1875
1875
  attempt_id: t.attemptId,
1876
1876
  confirmation_hash: t.confirmationHash
1877
1877
  };
1878
- return hn("Sign in on this device", `<h1>Sign in on this device</h1><p>This device will use the Identity of the Google account you chose. Its existing memories keep their author.</p><section aria-label="Change"><dl>${r}</dl></section><p>Teams the new Identity isn’t in won’t sync on this device until a Team admin adds it. A device can switch only once.</p><div class="actions">${so(H.confirm, i, "Switch this device")}</div>`, void 0, { referrerPolicy: "same-origin" });
1878
+ return pn("Sign in on this device", `<h1>Sign in on this device</h1><p>This device will use the Identity of the Google account you chose. Its existing memories keep their author.</p><section aria-label="Change"><dl>${r}</dl></section><p>Teams the new Identity isn’t in won’t sync on this device until a Team admin adds it. A device can switch only once.</p><div class="actions">${so(H.confirm, i, "Switch this device")}</div>`, void 0, { referrerPolicy: "same-origin" });
1879
1879
  }
1880
1880
  function fo(e) {
1881
- let t = Se(e.loopbackRedirect);
1881
+ let t = Un(e.loopbackRedirect);
1882
1882
  if (!t.ok || !/^[A-Za-z0-9_-]{43}$/.test(e.completionSecret) || !/^[a-f0-9]{64}$/.test(e.confirmationHash)) throw Error("device_rebind_view_invalid_input");
1883
1883
  let n = `${t.destination}?attempt_id=${encodeURIComponent(e.attemptId)}&completion=${e.completionSecret}&confirmation=${e.confirmationHash}`;
1884
- return hn("Finishing sign-in", `<h1>Finishing sign-in…</h1><p>Returning to Codemem on this computer. If nothing happens, continue below.</p><p class="note">Do not share this link.</p><div class="actions"><a class="link" href="${w(n)}" referrerpolicy="no-referrer" rel="noreferrer">Continue on this computer</a></div>`, void 0, { refreshUrl: n });
1884
+ return pn("Finishing sign-in", `<h1>Finishing sign-in…</h1><p>Returning to Codemem on this computer. If nothing happens, continue below.</p><p class="note">Do not share this link.</p><div class="actions"><a class="link" href="${T(n)}" referrerpolicy="no-referrer" rel="noreferrer">Continue on this computer</a></div>`, void 0, { refreshUrl: n });
1885
1885
  }
1886
1886
  var po = {
1887
1887
  rate_limited: ["Too many tries", "Wait a minute, then start again from Codemem on this device."],
@@ -1897,14 +1897,14 @@ var po = {
1897
1897
  target_headless_linked: ["Link this account from a browser first", "This account was linked from a device without a browser. Link it once from a computer with a browser before moving other devices into it."]
1898
1898
  };
1899
1899
  function mo(e) {
1900
- let t = Se(e.loopbackRedirect);
1900
+ let t = Un(e.loopbackRedirect);
1901
1901
  if (!t.ok) throw Error("device_rebind_view_invalid_input");
1902
1902
  let [n, r] = po[e.reason], i = `${t.destination}?attempt_id=${encodeURIComponent(e.attemptId)}&refused=${Kn(e.reason)}`;
1903
- return hn(n, `<h1>${w(n)}</h1><p>${w(r)}</p><p>Returning to Codemem on this computer.</p><div class="actions"><a class="link" href="${w(i)}" referrerpolicy="no-referrer" rel="noreferrer">Return to Codemem</a></div>`, void 0, { refreshUrl: i });
1903
+ return pn(n, `<h1>${T(n)}</h1><p>${T(r)}</p><p>Returning to Codemem on this computer.</p><div class="actions"><a class="link" href="${T(i)}" referrerpolicy="no-referrer" rel="noreferrer">Return to Codemem</a></div>`, void 0, { refreshUrl: i });
1904
1904
  }
1905
1905
  function ho(e) {
1906
1906
  let [t, n] = po[e];
1907
- return hn(t, `<h1>${w(t)}</h1><p>${w(n)}</p>`);
1907
+ return pn(t, `<h1>${T(t)}</h1><p>${T(n)}</p>`);
1908
1908
  }
1909
1909
  //#endregion
1910
1910
  //#region src/coordinator-device-rebind-browser.ts
@@ -1926,7 +1926,7 @@ function vo(e, t) {
1926
1926
  let n = new URL(e);
1927
1927
  if (`${n.origin}${n.pathname}` !== t || n.username || n.password) return null;
1928
1928
  let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
1929
- return [...n.searchParams].length !== 2 || !C(r) || !i || !je(i) ? null : {
1929
+ return [...n.searchParams].length !== 2 || !w(r) || !i || !pe(i) ? null : {
1930
1930
  attemptId: r,
1931
1931
  startCode: i
1932
1932
  };
@@ -1945,9 +1945,9 @@ async function yo(e, t, n) {
1945
1945
  kind: "refused",
1946
1946
  reason: "unavailable"
1947
1947
  }, 400);
1948
- let c = s.kind === "absent" ? await Ue("start") : null, l = s.kind === "present" ? s.secret : c?.secret;
1948
+ let c = s.kind === "absent" ? await x("start") : null, l = s.kind === "present" ? s.secret : c?.secret;
1949
1949
  if (!l) return W(null);
1950
- let u = await x(e.csrfKey, l, "start", e.scope), d = go(await co({
1950
+ let u = await S(e.csrfKey, l, "start", e.scope), d = go(await co({
1951
1951
  ...a,
1952
1952
  csrf: u
1953
1953
  }));
@@ -1956,7 +1956,7 @@ async function yo(e, t, n) {
1956
1956
  async function bo(e, t, n) {
1957
1957
  let r = await e.ceremony.claimBrowser(t, n);
1958
1958
  if (r?.kind !== "browser_claimed") return W(r);
1959
- let i = go(await cn({ authorizationUrl: r.authorizationUrl }));
1959
+ let i = go(await sn({ authorizationUrl: r.authorizationUrl }));
1960
1960
  for (let e of r.setCookies) i.headers.append("Set-Cookie", e);
1961
1961
  return i;
1962
1962
  }
@@ -2001,7 +2001,7 @@ async function So(e, t, n) {
2001
2001
  completionSecret: i.completionSecret,
2002
2002
  confirmationHash: r.confirmationHash
2003
2003
  }));
2004
- return a.headers.append("Set-Cookie", E("transaction")), a;
2004
+ return a.headers.append("Set-Cookie", Nn("transaction")), a;
2005
2005
  }
2006
2006
  async function Co(e, t) {
2007
2007
  let n = await e.ceremony.verifyCallback(t);
@@ -2011,7 +2011,7 @@ async function Co(e, t) {
2011
2011
  reason: n.reason,
2012
2012
  ...n.returnTo
2013
2013
  })) : await W(n);
2014
- return e.headers.append("Set-Cookie", E("transaction")), e;
2014
+ return e.headers.append("Set-Cookie", Nn("transaction")), e;
2015
2015
  }
2016
2016
  return n.kind === "verified" ? go(await uo({
2017
2017
  confirmation: n.confirmation,
@@ -2131,9 +2131,9 @@ async function Lo(e, t) {
2131
2131
  async function Ro(e, t, n) {
2132
2132
  let { scope: r, key: i } = t, a = await t.transactionActivity(e.headers.get("cookie")), o = await b(e.headers.get("cookie"), "start");
2133
2133
  if (a === "active" || a === "invalid" || o.kind === "invalid") return G();
2134
- let s = o.kind === "absent" ? await Ue("start") : null, c = o.kind === "present" ? o.secret : s?.secret;
2134
+ let s = o.kind === "absent" ? await x("start") : null, c = o.kind === "present" ? o.secret : s?.secret;
2135
2135
  if (!c) return G();
2136
- let l = await x(i, c, "start", r);
2136
+ let l = await S(i, c, "start", r);
2137
2137
  return Po(`<h1>Enroll owner device</h1>${n.deviceId && n.fingerprint ? `<p>Compare these details with your local device review before choosing an account.</p><dl><dt>Device ID</dt><dd>${jo(n.deviceId)}</dd><dt>Key fingerprint</dt><dd>${jo(n.fingerprint)}</dd></dl>` : ""}${No(Eo, {
2138
2138
  csrf: l,
2139
2139
  attempt_id: n.attemptId,
@@ -2183,10 +2183,10 @@ async function Vo(e, t, n, r) {
2183
2183
  body: l
2184
2184
  }), f = await t.confirm(d, n, c[0]);
2185
2185
  if (f.kind !== "confirmed") return G();
2186
- let p = Se(f.loopbackRedirect);
2186
+ let p = Un(f.loopbackRedirect);
2187
2187
  if (!p.ok) return G();
2188
2188
  let m = new URL(p.destination);
2189
- return m.searchParams.set("attempt_id", f.confirmation.attemptId), m.searchParams.set("completion", f.completionSecret), m.searchParams.set("confirmation", f.confirmation.confirmationHash), Io(m.href, [E("transaction")]);
2189
+ return m.searchParams.set("attempt_id", f.confirmation.attemptId), m.searchParams.set("completion", f.completionSecret), m.searchParams.set("confirmation", f.confirmation.confirmationHash), Io(m.href, [Nn("transaction")]);
2190
2190
  }
2191
2191
  async function Ho(e, t, n) {
2192
2192
  if (!/^application\/json(?:\s*;\s*charset=utf-8)?$/i.test(e.headers.get("content-type") ?? "")) return G(415);
@@ -2247,7 +2247,7 @@ function Ko(e, t) {
2247
2247
  }
2248
2248
  async function qo(e, t, n) {
2249
2249
  try {
2250
- return Ko(e, n) || (!C(t) || t.length > 128 ? G() : Jn(e, n.limiter, JSON.stringify([
2250
+ return Ko(e, n) || (!w(t) || t.length > 128 ? G() : Jn(e, n.limiter, JSON.stringify([
2251
2251
  "owner-http",
2252
2252
  n.pin.coordinatorId,
2253
2253
  t
@@ -2282,7 +2282,7 @@ async function Yo(e) {
2282
2282
  if (t.kind !== "enabled") throw Error("owner_enrollment_http_unavailable");
2283
2283
  let n = new URL(t.store.redirectUri).pathname;
2284
2284
  if (Wo(n, "private") || Wo(n, "production")) throw Error("owner_enrollment_http_unavailable");
2285
- let r = e.mode === "production", i = r ? e.csrfKey : await ut(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))), a = r ? e.limiter : Zn({ now: e.clock }), o = Jo(e, i, a, { production: r }), s = await yr(o);
2285
+ let r = e.mode === "production", i = r ? e.csrfKey : await ot(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))), a = r ? e.limiter : Zn({ now: e.clock }), o = Jo(e, i, a, { production: r }), s = await yr(o);
2286
2286
  if (!s.ok) throw Error("owner_enrollment_http_unavailable");
2287
2287
  let c = Object.freeze({
2288
2288
  coordinatorId: t.store.coordinatorId,
@@ -2424,7 +2424,7 @@ function os(e, t) {
2424
2424
  function ss(e) {
2425
2425
  let t = A(e.config);
2426
2426
  if (t.kind === "enabled" && new URL(t.store.redirectUri).pathname === "/auth/owner/admit") throw Error("owner_admission_callback_collision");
2427
- let n = e.enabled && t.kind === "enabled" && Mn(e.csrfKey) && _r(e.admissionKey);
2427
+ let n = e.enabled && t.kind === "enabled" && An(e.csrfKey) && _r(e.admissionKey);
2428
2428
  return async (r, i) => {
2429
2429
  if (new URL(r.url).pathname !== "/auth/owner/admit") return null;
2430
2430
  if (!n || t.kind !== "enabled") return K(404);
@@ -2436,7 +2436,7 @@ function ss(e) {
2436
2436
  };
2437
2437
  }
2438
2438
  function cs(e, t, n, r) {
2439
- return os(e, r.publicOrigin) ? e.method !== "GET" && e.method !== "POST" ? K(405) : !C(t) || t.length > 128 ? K() : n.limiter.check(JSON.stringify([
2439
+ return os(e, r.publicOrigin) ? e.method !== "GET" && e.method !== "POST" ? K(405) : !w(t) || t.length > 128 ? K() : n.limiter.check(JSON.stringify([
2440
2440
  "owner-admit-client",
2441
2441
  r.store.coordinatorId,
2442
2442
  t
@@ -2453,7 +2453,7 @@ async function us(e, t, n, r) {
2453
2453
  if (o.kind !== "present") return K(403);
2454
2454
  let s = await n.readSession(o.cookieHash, r.store);
2455
2455
  if (!s) return K(403);
2456
- let c = () => Ut(n.clock ?? Date.now), l = {
2456
+ let c = () => Lt(n.clock ?? Date.now), l = {
2457
2457
  backend: i,
2458
2458
  config: r.store,
2459
2459
  sessionCookieHash: o.cookieHash
@@ -2473,7 +2473,7 @@ async function us(e, t, n, r) {
2473
2473
  publicOrigin: r.publicOrigin,
2474
2474
  store: r.store
2475
2475
  }, f = await ls(e, i, r, c);
2476
- return f ? e.method === "GET" ? as(await x(a, o.secret, "session", d)) : ds(e, t, n, r, {
2476
+ return f ? e.method === "GET" ? as(await S(a, o.secret, "session", d)) : ds(e, t, n, r, {
2477
2477
  cookie: o,
2478
2478
  owner: u,
2479
2479
  transactionActivity: f,
@@ -2485,7 +2485,7 @@ async function ds(e, t, n, r, i) {
2485
2485
  publicOrigin: r.publicOrigin,
2486
2486
  store: r.store
2487
2487
  }, p = await ts(e);
2488
- if (!p || !await In(u, a.secret, "session", f, p.csrf)) return K();
2488
+ if (!p || !await Fn(u, a.secret, "session", f, p.csrf)) return K();
2489
2489
  let { start: m } = p, h = await dr(m.publicKey), g = await tr({
2490
2490
  backend: l,
2491
2491
  config: r.store,
@@ -2495,18 +2495,18 @@ async function ds(e, t, n, r, i) {
2495
2495
  fingerprint: h
2496
2496
  });
2497
2497
  if (!g || JSON.stringify(g) !== JSON.stringify(o)) return K(403);
2498
- let _ = {
2498
+ let ee = {
2499
2499
  coordinatorId: r.store.coordinatorId,
2500
2500
  origin: r.publicOrigin,
2501
2501
  issuer: r.store.issuer,
2502
2502
  revision: r.store.revision
2503
- }, ee = await lr(d, _, m, {
2503
+ }, te = await lr(d, ee, m, {
2504
2504
  resolvedOwner: g,
2505
2505
  nowMs: c(),
2506
2506
  ttlMs: 6e4
2507
2507
  });
2508
2508
  return (await (await n.getEnrollment()).startOwnerBound(m, t, {
2509
- admissionToken: ee,
2509
+ admissionToken: te,
2510
2510
  resolvedOwner: g,
2511
2511
  sessionCookieHash: a.cookieHash
2512
2512
  })).kind === "started" ? Ro(e, {
@@ -2572,7 +2572,7 @@ function vs(e) {
2572
2572
  let t = q(e, "config"), n = A(t);
2573
2573
  if (n.kind === "disabled") {
2574
2574
  let e = Object.freeze({ kind: "disabled" }), n = t === void 0 ? void 0 : q(t, "coordinatorId");
2575
- return C(n) && ps.set(e, n), e;
2575
+ return w(n) && ps.set(e, n), e;
2576
2576
  }
2577
2577
  if (n.kind === "invalid") return gs(n.field);
2578
2578
  let r = new URL(n.store.redirectUri).pathname;
@@ -2583,7 +2583,7 @@ function vs(e) {
2583
2583
  } catch {
2584
2584
  return gs("csrfKey");
2585
2585
  }
2586
- if (!Mn(i)) return gs("csrfKey");
2586
+ if (!An(i)) return gs("csrfKey");
2587
2587
  let a;
2588
2588
  try {
2589
2589
  a = _s(q(e, "oidcOptions"));
@@ -2638,7 +2638,7 @@ function xs(e, t, n, r) {
2638
2638
  pinPath: "/v1/auth/owner-config"
2639
2639
  });
2640
2640
  if (i) return i;
2641
- if (!C(r) || r.length > 128) return new Response("Invalid request.", { status: 400 });
2641
+ if (!w(r) || r.length > 128) return new Response("Invalid request.", { status: 400 });
2642
2642
  let a = Jn(t, n, JSON.stringify([
2643
2643
  "owner-http",
2644
2644
  e.config.coordinatorId,
@@ -2943,15 +2943,15 @@ function Ms(e, t, n) {
2943
2943
  async function Ns(e) {
2944
2944
  try {
2945
2945
  let t = Ls(e, "readAccountChangeCapability");
2946
- return t ? { operations: await t() } : (await mt(e), { operations: await Rs(e) });
2946
+ return t ? { operations: await t() } : (await yn(e), { operations: await Rs(e) });
2947
2947
  } catch (e) {
2948
- return e instanceof Ln ? { error: Bn } : { error: "browser_auth_store_unavailable" };
2948
+ return e instanceof Ht ? { error: ie } : { error: "browser_auth_store_unavailable" };
2949
2949
  }
2950
2950
  }
2951
2951
  function Ps(e) {
2952
- return e instanceof Ln ? Object.freeze({
2952
+ return e instanceof Ht ? Object.freeze({
2953
2953
  ok: !1,
2954
- error: Bn
2954
+ error: ie
2955
2955
  }) : Object.freeze({
2956
2956
  ok: !1,
2957
2957
  error: "browser_auth_setup_failed"
@@ -3003,7 +3003,7 @@ async function Rs(e) {
3003
3003
  if (!n || !r) throw Error();
3004
3004
  let i = await n();
3005
3005
  if (i === "v2") return null;
3006
- if (i !== "ready") throw new Ln();
3006
+ if (i !== "ready") throw new Ht();
3007
3007
  return await r();
3008
3008
  }
3009
3009
  function zs(e) {
@@ -3179,10 +3179,10 @@ var Us = {
3179
3179
  link: "l",
3180
3180
  connections: !0
3181
3181
  })})
3182
- AND (${yt({
3182
+ AND (${Dt({
3183
3183
  link: "l",
3184
3184
  connections: !0
3185
- })})`, Ks = Object.entries(Us).map(([e, t]) => `${t} AS ${e}`).join(","), qs = mr.map((e, t) => Oe(e.replace(/^(?:\s|--[^\n]*\n)*/u, "").replace(/;\s*$/u, ""), t === 0 ? { auxiliaryObjects: 5 } : void 0).matches).join(" AND ");
3185
+ })})`, Ks = Object.entries(Us).map(([e, t]) => `${t} AS ${e}`).join(","), qs = mr.map((e, t) => Ke(e.replace(/^(?:\s|--[^\n]*\n)*/u, "").replace(/;\s*$/u, ""), t === 0 ? { auxiliaryObjects: 5 } : void 0).matches).join(" AND ");
3186
3186
  async function Js(e, t) {
3187
3187
  let n = new TextEncoder().encode(JSON.stringify([
3188
3188
  "codemem.owner-enrollment-qualification.preview.v1",
@@ -3216,10 +3216,10 @@ var Xs = () => ({
3216
3216
  clock;
3217
3217
  config;
3218
3218
  constructor(e, t, n = Date.now) {
3219
- this.backend = e, this.clock = n, this.config = Mt(t);
3219
+ this.backend = e, this.clock = n, this.config = ft(t);
3220
3220
  }
3221
3221
  async schemaReady() {
3222
- return await v(this.backend) === "ready" && (await this.backend.first({
3222
+ return await Rt(this.backend) === "ready" && (await this.backend.first({
3223
3223
  sql: `SELECT (${qs}) AS ready`,
3224
3224
  values: []
3225
3225
  }))?.ready === 1;
@@ -3235,12 +3235,12 @@ var Xs = () => ({
3235
3235
  n.issuer
3236
3236
  ]
3237
3237
  });
3238
- if (!r || !ln(r.evidence_digest)) return null;
3238
+ if (!r || !In(r.evidence_digest)) return null;
3239
3239
  let i = await o(r.public_key);
3240
3240
  if (!i || i !== r.key_id) return null;
3241
3241
  let a = {
3242
3242
  source: r,
3243
- guard: await kn(this.backend, r.identity_id, {
3243
+ guard: await Tt(this.backend, r.identity_id, {
3244
3244
  groupId: r.source_group_id,
3245
3245
  deviceId: r.device_id,
3246
3246
  publicKey: r.public_key,
@@ -3277,13 +3277,13 @@ var Xs = () => ({
3277
3277
  });
3278
3278
  }
3279
3279
  async preview(e) {
3280
- let t = Tt(e, ["attestationId"]);
3281
- if (!C(t?.attestationId)) return {
3280
+ let t = zn(e, ["attestationId"]);
3281
+ if (!w(t?.attestationId)) return {
3282
3282
  kind: "rejected",
3283
3283
  error: "invalid_input"
3284
3284
  };
3285
3285
  try {
3286
- let e = await this.prepare(t.attestationId, Ut(this.clock));
3286
+ let e = await this.prepare(t.attestationId, Lt(this.clock));
3287
3287
  if (!e) return Xs();
3288
3288
  let n = await this.existing(e);
3289
3289
  return n && !this.matches(n, e.source) ? {
@@ -3295,14 +3295,14 @@ var Xs = () => ({
3295
3295
  }
3296
3296
  }
3297
3297
  async issue(e) {
3298
- let t = Tt(e, ["attestationId", "expectedDigest"]);
3299
- if (!C(t?.attestationId) || !ln(t?.expectedDigest)) return {
3298
+ let t = zn(e, ["attestationId", "expectedDigest"]);
3299
+ if (!w(t?.attestationId) || !In(t?.expectedDigest)) return {
3300
3300
  kind: "rejected",
3301
3301
  error: "invalid_input"
3302
3302
  };
3303
3303
  let n = !1;
3304
3304
  try {
3305
- let e = Ut(this.clock), r = await this.prepare(t.attestationId, e);
3305
+ let e = Lt(this.clock), r = await this.prepare(t.attestationId, e);
3306
3306
  if (!r) return Xs();
3307
3307
  if (r.digest !== t.expectedDigest) return {
3308
3308
  kind: "rejected",
@@ -3336,14 +3336,14 @@ var Xs = () => ({
3336
3336
  });
3337
3337
  }
3338
3338
  async revoke(e) {
3339
- let t = Tt(e, ["qualificationId", "linkId"]);
3340
- if (!C(t?.qualificationId) || !C(t?.linkId)) return {
3339
+ let t = zn(e, ["qualificationId", "linkId"]);
3340
+ if (!w(t?.qualificationId) || !w(t?.linkId)) return {
3341
3341
  kind: "rejected",
3342
3342
  error: "invalid_input"
3343
3343
  };
3344
3344
  let n = !1;
3345
3345
  try {
3346
- let e = this.config, r = Ut(this.clock);
3346
+ let e = this.config, r = Lt(this.clock);
3347
3347
  if (!e?.enabled || !await this.schemaReady()) return Xs();
3348
3348
  let i = [
3349
3349
  e.coordinatorId,
@@ -3389,8 +3389,8 @@ var Xs = () => ({
3389
3389
  error: "qualification_conflict"
3390
3390
  };
3391
3391
  }
3392
- }, Qs = "CASE WHEN substr(sql, 1, 52) = 'CREATE TABLE \"coordinator_owner_enrollment_attempts\"'\n THEN 'CREATE TABLE coordinator_owner_enrollment_attempts' || substr(sql, 53) ELSE sql END", $s = ye.replace(/^--[^\n]*$/gm, "").trim().split(/\n(?=CREATE )/u).map((e, t) => {
3393
- let n = Oe(e.trim().replace(/;$/u, ""), t === 0 ? { auxiliaryObjects: 13 } : void 0);
3392
+ }, Qs = "CASE WHEN substr(sql, 1, 52) = 'CREATE TABLE \"coordinator_owner_enrollment_attempts\"'\n THEN 'CREATE TABLE coordinator_owner_enrollment_attempts' || substr(sql, 53) ELSE sql END", $s = ve.replace(/^--[^\n]*$/gm, "").trim().split(/\n(?=CREATE )/u).map((e, t) => {
3393
+ let n = Ke(e.trim().replace(/;$/u, ""), t === 0 ? { auxiliaryObjects: 13 } : void 0);
3394
3394
  return t === 0 ? {
3395
3395
  ...n,
3396
3396
  matches: n.matches.replace(/\bsql\b/u, Qs)
@@ -3405,7 +3405,7 @@ async function ec(e, t) {
3405
3405
  return crypto.subtle.verify("HMAC", a, o, i);
3406
3406
  }
3407
3407
  function tc(e) {
3408
- return !e || Object.keys(e).some((e) => !["attestation_id", "confirm_evidence_digest"].includes(e)) || !er(e.attestation_id) || Object.hasOwn(e, "confirm_evidence_digest") && !ln(e.confirm_evidence_digest) ? null : {
3408
+ return !e || Object.keys(e).some((e) => !["attestation_id", "confirm_evidence_digest"].includes(e)) || !er(e.attestation_id) || Object.hasOwn(e, "confirm_evidence_digest") && !In(e.confirm_evidence_digest) ? null : {
3409
3409
  attestationId: e.attestation_id,
3410
3410
  expectedDigest: e.confirm_evidence_digest
3411
3411
  };
@@ -3459,7 +3459,7 @@ async function oc(e, t) {
3459
3459
  }))?.ready === 1 && await t.schemaReady();
3460
3460
  }
3461
3461
  function sc(e) {
3462
- let t = Mt(e.config), n = { ...e }, r = n.backend, i = t && r ? new Zs(r, t) : null;
3462
+ let t = ft(e.config), n = { ...e }, r = n.backend, i = t && r ? new Zs(r, t) : null;
3463
3463
  return async (e) => {
3464
3464
  e.header("Cache-Control", "no-store"), e.header("Referrer-Policy", "no-referrer"), e.header("X-Content-Type-Options", "nosniff");
3465
3465
  try {
@@ -3610,7 +3610,7 @@ function Dc(e) {
3610
3610
  return Number(e?.meta?.changes ?? 0);
3611
3611
  }
3612
3612
  function Oc(e, t = {}) {
3613
- return bt(kc(e), t);
3613
+ return On(kc(e), t);
3614
3614
  }
3615
3615
  function kc(e) {
3616
3616
  return {
@@ -3642,8 +3642,8 @@ async function $(e) {
3642
3642
  let t = await e.run();
3643
3643
  return Number(t?.meta?.changes ?? 0);
3644
3644
  }
3645
- var jc = `${ct}
3646
- OR ${ct}`, Mc = Et, Nc = `EXISTS (
3645
+ var jc = `${at}
3646
+ OR ${at}`, Mc = bt, Nc = `EXISTS (
3647
3647
  SELECT 1 FROM coordinator_invites ri
3648
3648
  JOIN groups rg ON rg.group_id = ri.group_id AND rg.archived_at IS NULL
3649
3649
  WHERE ri.invite_id = ? AND ri.group_id = ? AND ri.revoked_at IS NULL
@@ -3774,9 +3774,9 @@ async function Vc(e, t, n) {
3774
3774
  let i = await e.batch([...t, e.prepare(`WITH recipient_negative AS MATERIALIZED (${r.sql})
3775
3775
  SELECT CASE WHEN (${n.sql}) AND (SELECT matches FROM recipient_negative)
3776
3776
  THEN 1 ELSE json('recipient_invite_authorization_failed') END AS confirmed`).bind(...r.values, ...n.values)]), a = i[t.length];
3777
- if (Rn(a) !== 0 || a?.results?.[0]?.confirmed !== 1) throw Error("device_ownership_authorization_unavailable");
3778
- for (let e of i.slice(0, t.length)) Rn(e);
3779
- return Rn(i[0]);
3777
+ if (Ln(a) !== 0 || a?.results?.[0]?.confirmed !== 1) throw Error("device_ownership_authorization_unavailable");
3778
+ for (let e of i.slice(0, t.length)) Ln(e);
3779
+ return Ln(i[0]);
3780
3780
  } catch {
3781
3781
  throw await n.assertEligible({ requireBinding: !1 }), Error("device_ownership_authorization_unavailable");
3782
3782
  }
@@ -3825,11 +3825,11 @@ async function qc(e, t, n) {
3825
3825
  let r = {
3826
3826
  ...n,
3827
3827
  identityId: n.recipientActorId
3828
- }, i = await Q(e.prepare(`SELECT ${bc} FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, n.deviceId)), a = dt(i), s = i ? { ...i } : null, c = await o(n.publicKey), l = a === null ? null : await o(a), u = t.inviter_device_id ? await Q(e.prepare(`SELECT ${bc}
3829
- FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null, d = dt(u), f = u ? { ...u } : null, p = d === null ? null : await o(d), m = Hn(t, n, f, {
3828
+ }, i = await Q(e.prepare(`SELECT ${bc} FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, n.deviceId)), a = st(i), s = i ? { ...i } : null, c = await o(n.publicKey), l = a === null ? null : await o(a), u = t.inviter_device_id ? await Q(e.prepare(`SELECT ${bc}
3829
+ FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null, d = st(u), f = u ? { ...u } : null, p = d === null ? null : await o(d), m = Vn(t, n, f, {
3830
3830
  recipient: c,
3831
3831
  inviter: p
3832
- }), h = Ve(m, n.deviceId, {
3832
+ }), h = ze(m, n.deviceId, {
3833
3833
  incoming: c,
3834
3834
  current: l
3835
3835
  }), g = async (i) => {
@@ -3880,7 +3880,7 @@ var el = class {
3880
3880
  db;
3881
3881
  authLinks;
3882
3882
  async assertAuthSchemaReady() {
3883
- await an({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
3883
+ await gt({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
3884
3884
  }
3885
3885
  accountLinkStatus;
3886
3886
  accountOwnerTarget;
@@ -3889,7 +3889,7 @@ var el = class {
3889
3889
  authAccountProfiles;
3890
3890
  authBrowserTransactions;
3891
3891
  constructor(e, t = {}) {
3892
- this.db = e, this.deviceRevocations = new Fe({
3892
+ this.db = e, this.deviceRevocations = new Pe({
3893
3893
  all: (t) => e.prepare(t.sql).bind(...t.values).all(),
3894
3894
  batch: async (t) => {
3895
3895
  if (!e.batch) throw Error("device_revocation_atomic_batch_required");
@@ -3897,13 +3897,13 @@ var el = class {
3897
3897
  }
3898
3898
  }, t.authClock);
3899
3899
  let n = Oc(e);
3900
- this.accountChangeBackend = Oc(e, { connections: !0 }), this.accountChangesCapability = new Kt(this.accountChangeBackend, t.authClock), this.authLinks = new h(n, t.authClock), this.accountLinkStatus = new wn(n, t.authClock), this.accountOwnerTarget = new Ot(n, this), this.authSessions = new tt(n, t.authClock), this.authAccountProfiles = new _e(n, t.authClock), this.authBrowserTransactions = new p(n, t.authClock);
3900
+ this.accountChangeBackend = Oc(e, { connections: !0 }), this.accountChangesCapability = new Vt(this.accountChangeBackend, t.authClock), this.authLinks = new h(n, t.authClock), this.accountLinkStatus = new Cn(n, t.authClock), this.accountOwnerTarget = new xt(n, this), this.authSessions = new Me(n, t.authClock), this.authAccountProfiles = new Ze(n, t.authClock), this.authBrowserTransactions = new p(n, t.authClock);
3901
3901
  }
3902
3902
  readDeviceRebindBackend() {
3903
- return Me(kc(this.db));
3903
+ return Ae(kc(this.db));
3904
3904
  }
3905
3905
  readHeadlessLinkBackend() {
3906
- return fn(kc(this.db));
3906
+ return et(kc(this.db));
3907
3907
  }
3908
3908
  async getAccountChanges() {
3909
3909
  return await this.accountChangeBackend.first({
@@ -3912,11 +3912,11 @@ var el = class {
3912
3912
  }), this.accountChangesCapability;
3913
3913
  }
3914
3914
  readAccountConnectionSchemaState() {
3915
- return v({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
3915
+ return Rt({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
3916
3916
  }
3917
3917
  async readAccountChangeCapability() {
3918
3918
  let e = await this.readAccountConnectionSchemaState();
3919
- if (e === "upgrade_required") throw new Ln();
3919
+ if (e === "upgrade_required") throw new Ht();
3920
3920
  return e === "ready" ? this.accountChangesCapability : null;
3921
3921
  }
3922
3922
  async readAuthBrowserTransactionActivity(e, t) {
@@ -3998,7 +3998,7 @@ var el = class {
3998
3998
  return this.accountOwnerTarget.readAccountOwnerTarget(...e);
3999
3999
  }
4000
4000
  readResolvedAccountOwnerStatus(...e) {
4001
- return new Ee({
4001
+ return new we({
4002
4002
  ...this.accountChangeBackend,
4003
4003
  all: async ({ sql: e, values: t }) => {
4004
4004
  let n = await this.db.prepare(e).bind(...t).all();
@@ -4070,13 +4070,13 @@ var el = class {
4070
4070
  }
4071
4071
  async close() {}
4072
4072
  async issueIdentityGroupGrantFromControllerAttestation(e) {
4073
- let t = qt(e, ["coordinatorId", "attestationId"]);
4073
+ let t = Ut(e, ["coordinatorId", "attestationId"]);
4074
4074
  if (!t) return {
4075
4075
  kind: "rejected",
4076
4076
  error: "invalid_grant_input"
4077
4077
  };
4078
4078
  try {
4079
- let e = await Q(this.db.prepare(Ae).bind(t.coordinatorId, t.attestationId));
4079
+ let e = await Q(this.db.prepare(De).bind(t.coordinatorId, t.attestationId));
4080
4080
  if (!e) return {
4081
4081
  kind: "rejected",
4082
4082
  error: "grant_authority_unavailable"
@@ -4096,7 +4096,7 @@ var el = class {
4096
4096
  kind: "created",
4097
4097
  grant: r
4098
4098
  };
4099
- let i = await Q(this.db.prepare(We).bind(...n));
4099
+ let i = await Q(this.db.prepare(Ve).bind(...n));
4100
4100
  return i ? {
4101
4101
  kind: "existing",
4102
4102
  grant: i
@@ -4109,50 +4109,50 @@ var el = class {
4109
4109
  }
4110
4110
  }
4111
4111
  async listIdentityGroupGrantRevisions(e) {
4112
- let t = qt(e, ["coordinatorId", "identityId"]);
4112
+ let t = Ut(e, ["coordinatorId", "identityId"]);
4113
4113
  if (!t) throw Error("invalid_grant_input");
4114
4114
  let n = await this.db.prepare(Pn).bind(t.coordinatorId, t.identityId).all();
4115
4115
  if (!Array.isArray(n?.results)) throw Error("identity_group_grant_read_incomplete");
4116
4116
  return n.results;
4117
4117
  }
4118
4118
  async revokeIdentityGroupGrant(e) {
4119
- let t = qt(e, [
4119
+ let t = Ut(e, [
4120
4120
  "coordinatorId",
4121
4121
  "identityId",
4122
4122
  "groupId",
4123
4123
  "expectedRevision"
4124
4124
  ]);
4125
4125
  if (!t) return !1;
4126
- let n = (await this.db.prepare(oe).bind(Y(), t.coordinatorId, t.identityId, t.groupId, t.expectedRevision).run())?.meta?.changes;
4126
+ let n = (await this.db.prepare(ae).bind(Y(), t.coordinatorId, t.identityId, t.groupId, t.expectedRevision).run())?.meta?.changes;
4127
4127
  if (typeof n != "number" || !Number.isSafeInteger(n) || n < 0 || n > 1) throw Error("identity_group_grant_write_incomplete");
4128
4128
  return n === 1;
4129
4129
  }
4130
4130
  async createAuthControllerAttestation(e) {
4131
- let t = $t(e);
4131
+ let t = En(e);
4132
4132
  if (!t) return {
4133
4133
  kind: "rejected",
4134
4134
  error: "invalid_review_input"
4135
4135
  };
4136
- let n = await Q(this.db.prepare(Xe).bind(t.groupId, t.deviceId));
4137
- if (!n) return Cn(t);
4138
- let r = pn(n, await o(n.public_key));
4139
- if (await Q(this.db.prepare(Un).bind(...ve(t)))) return this.resolveAuthControllerRetry(t, r);
4136
+ let n = await Q(this.db.prepare(tt).bind(t.groupId, t.deviceId));
4137
+ if (!n) return Gt(t);
4138
+ let r = Sn(n, await o(n.public_key));
4139
+ if (await Q(this.db.prepare(un).bind(...Qt(t)))) return this.resolveAuthControllerRetry(t, r);
4140
4140
  let i = await this.prepareAuthControllerConsistency(t);
4141
- if (!i) return Cn(t);
4141
+ if (!i) return Gt(t);
4142
4142
  try {
4143
- let e = De({
4144
- sql: f(pe, t),
4145
- values: it(t, Y(), r)
4143
+ let e = ce({
4144
+ sql: _n(Qe, t),
4145
+ values: fn(t, Y(), r)
4146
4146
  }, i);
4147
4147
  if (await $(this.db.prepare(e.sql).bind(...e.values)) === 0) {
4148
4148
  let e = await this.prepareAuthControllerConsistency(t);
4149
- return e ? this.resolveAuthControllerRetry(t, r, e) : Cn(t);
4149
+ return e ? this.resolveAuthControllerRetry(t, r, e) : Gt(t);
4150
4150
  }
4151
4151
  } catch (e) {
4152
- if (!pt(e)) throw e;
4152
+ if (!on(e)) throw e;
4153
4153
  return this.resolveAuthControllerRetry(t, r);
4154
4154
  }
4155
- let a = await Q(this.db.prepare(Le).bind(t.coordinatorId, t.attestationId, ...r));
4155
+ let a = await Q(this.db.prepare(ye).bind(t.coordinatorId, t.attestationId, ...r));
4156
4156
  if (!a) throw Error("auth_controller_persistence_incomplete");
4157
4157
  return {
4158
4158
  kind: "created",
@@ -4160,7 +4160,7 @@ var el = class {
4160
4160
  };
4161
4161
  }
4162
4162
  prepareAuthControllerConsistency(e) {
4163
- return we({
4163
+ return ke({
4164
4164
  first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first(),
4165
4165
  all: async ({ sql: e, values: t }) => {
4166
4166
  let n = await this.db.prepare(e).bind(...t).all();
@@ -4175,40 +4175,40 @@ var el = class {
4175
4175
  });
4176
4176
  }
4177
4177
  async resolveAuthControllerRetry(e, t, n) {
4178
- if (!await Q(this.db.prepare(f(Qe, e)).bind(...st(e, t)))) return Cn(e);
4179
- let r = await Q(this.db.prepare(Un).bind(...ve(e))), i = Pe(e, r);
4178
+ if (!await Q(this.db.prepare(_n(Ne, e)).bind(...lt(e, t)))) return Gt(e);
4179
+ let r = await Q(this.db.prepare(un).bind(...Qt(e))), i = nn(e, r);
4180
4180
  if (i.kind === "rejected") return i;
4181
4181
  let a = {
4182
- sql: f(qe, e),
4183
- values: nt(e, t)
4182
+ sql: _n(it, e),
4183
+ values: Nt(e, t)
4184
4184
  };
4185
- n && (a = De(a, n));
4185
+ n && (a = ce(a, n));
4186
4186
  let o = await Q(this.db.prepare(a.sql).bind(...a.values));
4187
- return o ? Pe(e, o) : {
4187
+ return o ? nn(e, o) : {
4188
4188
  kind: "rejected",
4189
4189
  error: e.verifiedSnapshot ? "review_stale" : "enrollment_mismatch"
4190
4190
  };
4191
4191
  }
4192
4192
  async getActiveAuthControllerAttestation(e, t) {
4193
- if (!C(e) || !C(t)) return null;
4194
- let n = await Q(this.db.prepare(_).bind(e, t));
4193
+ if (!w(e) || !w(t)) return null;
4194
+ let n = await Q(this.db.prepare(_e).bind(e, t));
4195
4195
  if (!n) return null;
4196
- let r = pn(n, await o(n.public_key));
4197
- return Q(this.db.prepare(Le).bind(e, t, ...r));
4196
+ let r = Sn(n, await o(n.public_key));
4197
+ return Q(this.db.prepare(ye).bind(e, t, ...r));
4198
4198
  }
4199
4199
  async readAuthControllerAttestationForSnapshot(e) {
4200
- let t = $t(e);
4200
+ let t = En(e);
4201
4201
  if (!t?.verifiedSnapshot?.accountOwnerTarget) return null;
4202
- let n = await Q(this.db.prepare(Xe).bind(t.groupId, t.deviceId));
4202
+ let n = await Q(this.db.prepare(tt).bind(t.groupId, t.deviceId));
4203
4203
  if (!n) return null;
4204
- let r = pn(n, await o(n.public_key));
4205
- return Q(this.db.prepare(f(qe, t)).bind(...nt(t, r)));
4204
+ let r = Sn(n, await o(n.public_key));
4205
+ return Q(this.db.prepare(_n(it, t)).bind(...Nt(t, r)));
4206
4206
  }
4207
4207
  async hasAuthControllerSubjectOwnerConflict(e) {
4208
- return !!await Q(this.db.prepare(rn).bind(...Dt(e)));
4208
+ return !!await Q(this.db.prepare(Yt).bind(...ht(e)));
4209
4209
  }
4210
4210
  async revokeAuthControllerAttestation(e, t) {
4211
- return !C(e) || !C(t) ? !1 : await $(this.db.prepare(ue).bind(Y(), e, t)) > 0;
4211
+ return !w(e) || !w(t) ? !1 : await $(this.db.prepare(f).bind(Y(), e, t)) > 0;
4212
4212
  }
4213
4213
  async createGroup(e, t) {
4214
4214
  await this.db.prepare("INSERT OR IGNORE INTO groups(group_id, display_name, archived_at, created_at) VALUES (?, ?, NULL, ?)").bind(e, t ?? null, Y()).run();
@@ -4231,32 +4231,32 @@ var el = class {
4231
4231
  return await $(this.db.prepare("UPDATE groups SET archived_at = NULL WHERE group_id = ? AND archived_at IS NOT NULL").bind(e)) > 0;
4232
4232
  }
4233
4233
  async enrollDevice(e, t) {
4234
- let { deviceId: n, publicKey: r, fingerprint: i, identityId: a, displayName: s } = It(e, t);
4234
+ let { deviceId: n, publicKey: r, fingerprint: i, identityId: a, displayName: s } = kt(e, t);
4235
4235
  try {
4236
- let t = dt(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e, n))), c = await o(r), l = t === null ? null : await o(t), u = [
4236
+ let t = st(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e, n))), c = await o(r), l = t === null ? null : await o(t), u = [
4237
4237
  t,
4238
4238
  e,
4239
4239
  n,
4240
4240
  e,
4241
4241
  n,
4242
4242
  t
4243
- ], d = await this.db.prepare(Qt).bind(e, n, r, i, a ?? null, s ?? null, Y(), n, c, n, c, n, l, ...u, n, c, n, l, t).run();
4244
- if (Rn(d) === 1) return;
4245
- let f = await Q(this.db.prepare(un).bind(n, c, n, c, n, l, ...u));
4246
- throw Error(_t(f));
4243
+ ], d = await this.db.prepare(Zt).bind(e, n, r, i, a ?? null, s ?? null, Y(), n, c, n, c, n, l, ...u, n, c, n, l, t).run();
4244
+ if (Ln(d) === 1) return;
4245
+ let f = await Q(this.db.prepare(cn).bind(n, c, n, c, n, l, ...u));
4246
+ throw Error(pt(f));
4247
4247
  } catch (e) {
4248
- Vn(e);
4248
+ Bn(e);
4249
4249
  }
4250
4250
  }
4251
4251
  async listEnrolledDevices(e, t) {
4252
- let n = t ? "" : "AND enrolled_devices.enabled = 1", r = (await Z(this.db.prepare(`SELECT ${xc}, ${Wt}
4252
+ let n = t ? "" : "AND enrolled_devices.enabled = 1", r = (await Z(this.db.prepare(`SELECT ${xc}, ${zt}
4253
4253
  FROM enrolled_devices
4254
4254
  LEFT JOIN presence_records
4255
4255
  ON presence_records.group_id = enrolled_devices.group_id
4256
4256
  AND presence_records.device_id = enrolled_devices.device_id
4257
4257
  WHERE enrolled_devices.group_id = ? ${n}
4258
4258
  ORDER BY enrolled_devices.created_at ASC, enrolled_devices.device_id ASC`).bind(e))).map(hc);
4259
- return Te(r);
4259
+ return Ce(r);
4260
4260
  }
4261
4261
  async getEnrollment(e, t, n = !1) {
4262
4262
  let r = n ? "" : "AND enabled = 1", i = await Q(this.db.prepare(`SELECT ${bc}
@@ -4268,7 +4268,7 @@ var el = class {
4268
4268
  return await $(this.db.prepare("UPDATE enrolled_devices SET display_name = ?\n WHERE group_id = ? AND device_id = ?").bind(n, e, t)) > 0;
4269
4269
  }
4270
4270
  async setDeviceEnabled(e, t, n) {
4271
- if (zt(e, t), typeof n != "boolean") throw Error("invalid_input");
4271
+ if (jt(e, t), typeof n != "boolean") throw Error("invalid_input");
4272
4272
  if (n) try {
4273
4273
  let n = await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e, t));
4274
4274
  if (n === null) return !1;
@@ -4277,14 +4277,14 @@ var el = class {
4277
4277
  if (typeof r != "string") throw Error("device_ownership_authorization_unavailable");
4278
4278
  let i = await o(r), a = await this.db.prepare(`UPDATE enrolled_devices SET enabled = 1
4279
4279
  WHERE group_id = ? AND device_id = ? AND public_key = ?
4280
- AND NOT ${ct}
4281
- AND NOT ${Et}`).bind(e, t, r, t, i, t, i).run();
4282
- if (Rn(a) === 1) return !0;
4283
- let s = _t(await Q(this.db.prepare(Nt).bind(t, i, t, i)));
4280
+ AND NOT ${at}
4281
+ AND NOT ${bt}`).bind(e, t, r, t, i, t, i).run();
4282
+ if (Ln(a) === 1) return !0;
4283
+ let s = pt(await Q(this.db.prepare(Et).bind(t, i, t, i)));
4284
4284
  if (s === "device_ownership_requires_verified_identity") throw Error(s);
4285
4285
  return !1;
4286
4286
  } catch (e) {
4287
- Vn(e);
4287
+ Bn(e);
4288
4288
  }
4289
4289
  return await $(this.db.prepare("UPDATE enrolled_devices SET enabled = ?\n WHERE group_id = ? AND device_id = ?").bind(+!!n, e, t)) > 0;
4290
4290
  }
@@ -4312,7 +4312,7 @@ var el = class {
4312
4312
  return this.deviceRevocations.recordAuthorizedNonce(e);
4313
4313
  }
4314
4314
  async createInvite(e) {
4315
- let t = Y(), n = X(12), r = X(24), i = await vc(r), a = Ht(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, l = await St(e), u = l.inviteKind === "team_member" ? `identity:${X(18)}` : null;
4315
+ let t = Y(), n = X(12), r = X(24), i = await vc(r), a = Ft(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, l = await vt(e), u = l.inviteKind === "team_member" ? `identity:${X(18)}` : null;
4316
4316
  if (!!s != !!c) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
4317
4317
  let d = async () => {
4318
4318
  if (!s) return null;
@@ -4363,10 +4363,10 @@ var el = class {
4363
4363
  async inspectRecipientInvite(e) {
4364
4364
  let t = await this.getInviteByTokenForInspection(e.token);
4365
4365
  if (!t) return null;
4366
- let n = await Bt(t);
4366
+ let n = await Mt(t);
4367
4367
  if (!n) return null;
4368
4368
  if (t.revoked_at) throw Error("invite_invalid");
4369
- if (!t.consumed_at && new Date(t.expires_at) <= new Date(Ht(e.now))) throw Error("invite_expired");
4369
+ if (!t.consumed_at && new Date(t.expires_at) <= new Date(Ft(e.now))) throw Error("invite_expired");
4370
4370
  let r = await this.getGroup(t.group_id);
4371
4371
  if (!r) throw Error("group_not_found");
4372
4372
  if (r.archived_at) throw Error("group_archived");
@@ -4396,28 +4396,28 @@ var el = class {
4396
4396
  async prepareEligibleRecipientOwner(e) {
4397
4397
  let t = Uc(this.db), n = await he(t, e);
4398
4398
  if (!n) throw Error("device_ownership_authorization_unavailable");
4399
- return await se(t, n), n;
4399
+ return await oe(t, n), n;
4400
4400
  }
4401
4401
  async consumeRecipientInvite(e) {
4402
- let t = { ...e }, n = Ht(t.now), r = t.recipientDisplayName ?? null, i = t.deviceDisplayName ?? null;
4403
- Ie(t);
4404
- let a = await vc(t.token), o = structuredClone(await this.getInviteByTokenForInspection(t.token)), s = o ? await Bt(o) : null;
4402
+ let t = { ...e }, n = Ft(t.now), r = t.recipientDisplayName ?? null, i = t.deviceDisplayName ?? null;
4403
+ Fe(t);
4404
+ let a = await vc(t.token), o = structuredClone(await this.getInviteByTokenForInspection(t.token)), s = o ? await Mt(o) : null;
4405
4405
  if (!o || !s || s.kind !== t.inviteKind || o.revoked_at) throw Error("invite_invalid");
4406
4406
  let l = await this.getGroup(o.group_id);
4407
4407
  if (!l) throw Error("group_not_found");
4408
4408
  if (l.archived_at) throw Error("group_archived");
4409
4409
  if (!o.consumed_at && new Date(o.expires_at) <= new Date(n)) throw Error("invite_expired");
4410
4410
  if (c(t.publicKey) !== t.fingerprint) throw Error("fingerprint_mismatch");
4411
- let u = Ce(s);
4411
+ let u = Se(s);
4412
4412
  if (u !== t.identityId) throw Error("invite_identity_conflict");
4413
4413
  Ic(o, t, { requireBinding: !1 }), Fc(await Q(this.db.prepare(`SELECT ${bc}
4414
4414
  FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId)), t);
4415
4415
  let { eligibilitySql: d, eligibilityValues: f, boundEligibilitySql: p, boundEligibilityValues: m, assertEligible: h } = await Bc(this.db, o, t);
4416
4416
  await h({ requireBinding: !!o.consumed_at });
4417
- let g = await this.prepareEligibleRecipientOwner(t), _ = g.retainedRecheck, ee = 0, te = X(12);
4417
+ let g = await this.prepareEligibleRecipientOwner(t), ee = g.retainedRecheck, te = 0, ne = X(12);
4418
4418
  if (!o.consumed_at) {
4419
4419
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
4420
- ee = await Vc(this.db, [
4420
+ te = await Vc(this.db, [
4421
4421
  Hc(this.db, `UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,
4422
4422
  bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,
4423
4423
  recipient_display_name = ?, recipient_device_display_name = ?
@@ -4451,7 +4451,7 @@ var el = class {
4451
4451
  display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),
4452
4452
  enabled = 1
4453
4453
  WHERE enrolled_devices.identity_id IS NULL
4454
- OR enrolled_devices.identity_id = excluded.identity_id`, _).bind(n, a, t.token, t.deviceId, o.invite_id, o.group_id, t.publicKey, t.fingerprint, u, ...m),
4454
+ OR enrolled_devices.identity_id = excluded.identity_id`, ee).bind(n, a, t.token, t.deviceId, o.invite_id, o.group_id, t.publicKey, t.fingerprint, u, ...m),
4455
4455
  Hc(this.db, `UPDATE coordinator_invites SET bootstrap_grant_id = ?,
4456
4456
  trust_state = 'bootstrap_grant_created'
4457
4457
  WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'
@@ -4461,7 +4461,7 @@ var el = class {
4461
4461
  AND EXISTS (SELECT 1 FROM enrolled_devices e
4462
4462
  WHERE e.group_id = coordinator_invites.group_id
4463
4463
  AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)
4464
- AND changes() = 1 AND ${p}`, _).bind(te, a, t.token, o.invite_id, o.group_id, n, ...m),
4464
+ AND changes() = 1 AND ${p}`, ee).bind(ne, a, t.token, o.invite_id, o.group_id, n, ...m),
4465
4465
  Hc(this.db, `INSERT OR IGNORE INTO coordinator_bootstrap_grants(
4466
4466
  grant_id, group_id, seed_device_id, worker_device_id, expires_at,
4467
4467
  created_at, created_by, revoked_at
@@ -4472,38 +4472,38 @@ var el = class {
4472
4472
  WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'
4473
4473
  AND i.invite_id = ? AND i.group_id = ?
4474
4474
  AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?
4475
- AND changes() = 1 AND ${p}`, _).bind(n, a, t.token, o.invite_id, o.group_id, t.deviceId, ...m)
4475
+ AND changes() = 1 AND ${p}`, ee).bind(n, a, t.token, o.invite_id, o.group_id, t.deviceId, ...m)
4476
4476
  ], {
4477
4477
  sql: d,
4478
4478
  values: f,
4479
4479
  assertEligible: h,
4480
- negative: _
4480
+ negative: ee
4481
4481
  });
4482
4482
  }
4483
4483
  await h({ requireBinding: !1 });
4484
- let ne = await this.getGroup(o.group_id);
4485
- if (!ne) throw Error("group_not_found");
4486
- if (ne.archived_at) throw Error("group_archived");
4484
+ let re = await this.getGroup(o.group_id);
4485
+ if (!re) throw Error("group_not_found");
4486
+ if (re.archived_at) throw Error("group_archived");
4487
4487
  Fc(await Q(this.db.prepare(`SELECT ${bc}
4488
4488
  FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId)), t);
4489
- let v = await this.getInviteByTokenForInspection(t.token);
4490
- if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(n)) throw Error("invite_invalid");
4491
- let re = await Bt(v);
4492
- if (!re || re.kind !== t.inviteKind) throw Error("invite_invalid");
4493
- if (Ce(re) !== u) throw Error("invite_identity_conflict");
4494
- let ie = await Wc(this.db, t, v, {
4489
+ let _ = await this.getInviteByTokenForInspection(t.token);
4490
+ if (!_ || _.revoked_at || !_.consumed_at && new Date(_.expires_at) <= new Date(n)) throw Error("invite_invalid");
4491
+ let v = await Mt(_);
4492
+ if (!v || v.kind !== t.inviteKind) throw Error("invite_invalid");
4493
+ if (Se(v) !== u) throw Error("invite_identity_conflict");
4494
+ let ie = await Wc(this.db, t, _, {
4495
4495
  sql: p,
4496
4496
  values: m,
4497
4497
  assertEligible: h,
4498
- negative: _
4498
+ negative: ee
4499
4499
  }, {
4500
- winningChanges: ee,
4500
+ winningChanges: te,
4501
4501
  consistency: g
4502
4502
  });
4503
- await h({ requireBinding: !0 }), Lc(await this.getEnrollment(v.group_id, t.deviceId), t);
4504
- let y = v;
4505
- if (re.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(n)) {
4506
- await this.recoverRecipientInviteGrant(v, t, {
4503
+ await h({ requireBinding: !0 }), Lc(await this.getEnrollment(_.group_id, t.deviceId), t);
4504
+ let y = _;
4505
+ if (v.kind === "add_device" && _.inviter_device_id && !_.bootstrap_grant_id && new Date(_.expires_at) > new Date(n)) {
4506
+ await this.recoverRecipientInviteGrant(_, t, {
4507
4507
  sql: p,
4508
4508
  values: m,
4509
4509
  consumedAt: n,
@@ -4514,18 +4514,18 @@ var el = class {
4514
4514
  if (!e) throw Error("invite_invalid");
4515
4515
  y = e;
4516
4516
  }
4517
- let ae = y.bootstrap_grant_id ? await this.getBootstrapGrant(y.bootstrap_grant_id) : null;
4517
+ let b = y.bootstrap_grant_id ? await this.getBootstrapGrant(y.bootstrap_grant_id) : null;
4518
4518
  return await h({ requireBinding: !0 }), {
4519
- status: ee === 1 ? "accepted" : "existing",
4519
+ status: te === 1 ? "accepted" : "existing",
4520
4520
  invite: y,
4521
- reviewed_intent: re.reviewed_intent,
4522
- bootstrap_grant: ae
4521
+ reviewed_intent: v.reviewed_intent,
4522
+ bootstrap_grant: b
4523
4523
  };
4524
4524
  }
4525
4525
  async consumeProjectInvite(e) {
4526
- let t = Nn(e);
4526
+ let t = jn(e);
4527
4527
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
4528
- let n = Ht(t.now), r = await vc(t.token), i = await this.getInviteByTokenForInspection(t.token), a = i ? { ...i } : null;
4528
+ let n = Ft(t.now), r = await vc(t.token), i = await this.getInviteByTokenForInspection(t.token), a = i ? { ...i } : null;
4529
4529
  if (!a?.operation_id || !a.project_intent_json || a.revoked_at) throw Error("invite_invalid");
4530
4530
  let o = await this.getGroup(a.group_id);
4531
4531
  if (!o) throw Error("group_not_found");
@@ -4587,7 +4587,7 @@ var el = class {
4587
4587
  let m = await this.getInviteByTokenForInspection(t.token);
4588
4588
  if (!m) throw Error("invite_invalid");
4589
4589
  Yc(m, t);
4590
- let h = await this.getEnrollment(m.group_id, t.deviceId), g = m.inviter_device_id ? await this.getEnrollment(m.group_id, m.inviter_device_id) : null, _ = m.bootstrap_grant_id ? await this.getBootstrapGrant(m.bootstrap_grant_id) : null;
4590
+ let h = await this.getEnrollment(m.group_id, t.deviceId), g = m.inviter_device_id ? await this.getEnrollment(m.group_id, m.inviter_device_id) : null, ee = m.bootstrap_grant_id ? await this.getBootstrapGrant(m.bootstrap_grant_id) : null;
4591
4591
  if (await s.assertEligible({ requireBinding: !0 }), !h) throw Error("invite_acceptance_incomplete");
4592
4592
  if (h.identity_id !== t.recipientActorId) throw Error("invite_identity_conflict");
4593
4593
  return {
@@ -4595,7 +4595,7 @@ var el = class {
4595
4595
  invite: m,
4596
4596
  enrollment: h,
4597
4597
  seed_enrollment: g,
4598
- bootstrap_grant: _
4598
+ bootstrap_grant: ee
4599
4599
  };
4600
4600
  }
4601
4601
  async listInvites(e) {
@@ -4623,7 +4623,7 @@ var el = class {
4623
4623
  ...J(n),
4624
4624
  _no_transition: !0
4625
4625
  };
4626
- let r = vt(e.bootstrapGrant);
4626
+ let r = mt(e.bootstrapGrant);
4627
4627
  if (!e.approved) return this.denyJoinRequest(e);
4628
4628
  if (!this.db.batch) throw Error("join_review_unavailable");
4629
4629
  let i = Y(), { guard: a, bootstrapGrantInput: o } = await this.prepareJoinApproval(n, r), s = [this.db.prepare(`UPDATE coordinator_join_requests
@@ -4646,7 +4646,7 @@ var el = class {
4646
4646
  workerDeviceId: e.device_id
4647
4647
  };
4648
4648
  }
4649
- let i = dt(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e.group_id, e.device_id))), a = Xt(e, r, {
4649
+ let i = st(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e.group_id, e.device_id))), a = Jt(e, r, {
4650
4650
  recipient: await o(e.public_key),
4651
4651
  seed: r ? await o(r.public_key) : null,
4652
4652
  current: i === null ? null : await o(i)
@@ -4677,19 +4677,19 @@ var el = class {
4677
4677
  throw e?.status === "pending" && await this.assertJoinOwnershipAvailable(t.guard), Error("join_review_incomplete");
4678
4678
  }
4679
4679
  if (n.length !== e.length) throw Error("join_review_incomplete");
4680
- xt(n.at(-1));
4681
- let r = n.slice(0, -1).map(An), i = r[0];
4680
+ _t(n.at(-1));
4681
+ let r = n.slice(0, -1).map(kn), i = r[0];
4682
4682
  if (i !== 0 && i !== 1 || r.some((e) => e !== i)) throw Error("join_review_incomplete");
4683
4683
  return i === 1;
4684
4684
  }
4685
4685
  async denyJoinRequest(e) {
4686
- let t = this.db.prepare("UPDATE coordinator_join_requests SET status = 'denied', reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(Y(), e.reviewedBy ?? null, e.requestId), n = this.db.batch ? An((await this.db.batch([t]))[0]) : await $(t);
4686
+ let t = this.db.prepare("UPDATE coordinator_join_requests SET status = 'denied', reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(Y(), e.reviewedBy ?? null, e.requestId), n = this.db.batch ? kn((await this.db.batch([t]))[0]) : await $(t);
4687
4687
  if (n === 0) return this.classifyJoinReviewFailure(e.requestId, null);
4688
4688
  if (n !== 1) throw Error("join_review_incomplete");
4689
4689
  return this.readCompletedJoinReview(e.requestId, null);
4690
4690
  }
4691
4691
  async readCompletedJoinReview(e, t) {
4692
- let n = await Q(this.db.prepare(`SELECT ${xn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
4692
+ let n = await Q(this.db.prepare(`SELECT ${bn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
4693
4693
  if (!n) throw Error("join_review_incomplete");
4694
4694
  let r = t ? await this.getBootstrapGrant(t) : null;
4695
4695
  if (t && !r) throw Error("join_review_incomplete");
@@ -4736,7 +4736,7 @@ var el = class {
4736
4736
  WHEN ${c} THEN 1 ELSE json('join_review_incomplete') END AS confirmed`).bind(e.request_id, t, n, ...r.eligibilityValues, ...a, s, s, e.group_id, o?.seedDeviceId ?? null, e.device_id, o?.expiresAt ?? null);
4737
4737
  }
4738
4738
  async classifyJoinReviewFailure(e, t) {
4739
- let n = await Q(this.db.prepare(`SELECT ${xn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
4739
+ let n = await Q(this.db.prepare(`SELECT ${bn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
4740
4740
  if (!n) return null;
4741
4741
  if (n.status !== "pending") return {
4742
4742
  ...n,
@@ -4750,7 +4750,7 @@ var el = class {
4750
4750
  if (n === r) throw Error("requesting and requested device ids must differ.");
4751
4751
  if (i) {
4752
4752
  let e = Y();
4753
- if (await $(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e, a, t, r, n)) !== 1) throw new ke();
4753
+ if (await $(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e, a, t, r, n)) !== 1) throw new Te();
4754
4754
  return J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(a)));
4755
4755
  }
4756
4756
  let o = gc(n, r), s = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, n, r));
@@ -4781,9 +4781,9 @@ var el = class {
4781
4781
  return me(n);
4782
4782
  }
4783
4783
  async createBootstrapGrant(e) {
4784
- let t = vn(e);
4784
+ let t = gn(e);
4785
4785
  try {
4786
- let e = () => this.db.prepare(Re);
4786
+ let e = () => this.db.prepare(Le);
4787
4787
  if (await Q(e().bind(t.seedDeviceId, null, t.workerDeviceId, null))) throw Error("device_revoked");
4788
4788
  let n = await this.getBootstrapParticipantSource(t.groupId, t.seedDeviceId), r = await this.getBootstrapParticipantSource(t.groupId, t.workerDeviceId), i = [
4789
4789
  t.seedDeviceId,
@@ -4792,7 +4792,7 @@ var el = class {
4792
4792
  r ? await o(r.public_key) : null
4793
4793
  ];
4794
4794
  if (await Q(e().bind(...i))) throw Error("device_revoked");
4795
- let a = Ze(t, {
4795
+ let a = qe(t, {
4796
4796
  grantId: X(12),
4797
4797
  createdAt: Y()
4798
4798
  }, {
@@ -4814,7 +4814,7 @@ var el = class {
4814
4814
  return n ? J(n) : null;
4815
4815
  }
4816
4816
  async createScope(e) {
4817
- let t = Jt(e);
4817
+ let t = Wt(e);
4818
4818
  if (await this.getScope(t.scopeId)) throw Error("scopeId already exists.");
4819
4819
  let n = Y();
4820
4820
  await this.db.prepare("INSERT INTO coordinator_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(t.scopeId, t.label, t.kind, t.authorityType, t.coordinatorId, t.groupId, t.manifestIssuerDeviceId, t.membershipEpoch, t.manifestHash, t.status, n, n).run();
@@ -4823,13 +4823,13 @@ var el = class {
4823
4823
  return r;
4824
4824
  }
4825
4825
  async updateScope(e) {
4826
- let t = T(e.scopeId), n = t ? await this.getScope(t) : null;
4826
+ let t = E(e.scopeId), n = t ? await this.getScope(t) : null;
4827
4827
  if (!n) return null;
4828
- let r = At(e, n);
4828
+ let r = Ct(e, n);
4829
4829
  return await this.db.prepare("UPDATE coordinator_scopes\n SET label = ?,\n kind = ?,\n authority_type = ?,\n coordinator_id = ?,\n group_id = ?,\n manifest_issuer_device_id = ?,\n membership_epoch = ?,\n manifest_hash = ?,\n status = ?,\n updated_at = ?\n WHERE scope_id = ?").bind(r.label, r.kind, r.authorityType, r.coordinatorId, r.groupId, r.manifestIssuerDeviceId, r.membershipEpoch, r.manifestHash, r.status, Y(), r.scopeId).run(), await this.getScope(r.scopeId);
4830
4830
  }
4831
4831
  async listScopes(e = {}) {
4832
- let t = [], n = [], r = T(e.coordinatorId), i = T(e.groupId), a = T(e.status);
4832
+ let t = [], n = [], r = E(e.coordinatorId), i = E(e.groupId), a = E(e.status);
4833
4833
  r && (t.push("coordinator_id = ?"), n.push(r)), i && (t.push("group_id = ?"), n.push(i)), a ? (t.push("status = ?"), n.push(a)) : e.includeInactive || t.push("status = 'active'");
4834
4834
  let o = t.length ? `WHERE ${t.join(" AND ")}` : "", s = this.db.prepare(`SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,
4835
4835
  manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at
@@ -4906,13 +4906,13 @@ var el = class {
4906
4906
  return o;
4907
4907
  }
4908
4908
  async grantScopeMembership(e) {
4909
- let t = Ne(e.effectId), n = et(e), r = await Cc(this.db, t);
4910
- if (r) return rt(r, "grant", n), ot(r);
4911
- let i = T(e.scopeId), a = T(e.deviceId), o = i ? await this.getScope(i) : null;
4912
- if (!o) throw new dn("scope_not_found");
4913
- if (o.status !== "active") throw new dn("scope_inactive");
4914
- let s = i && a ? await this.getScopeMembership(i, a) : null, c = Dn(e, o, s);
4915
- if (c.groupId && !await this.getEnrollment(c.groupId, c.deviceId)) throw new dn("device_not_enrolled");
4909
+ let t = je(e.effectId), n = Xe(e), r = await Cc(this.db, t);
4910
+ if (r) return $e(r, "grant", n), rt(r);
4911
+ let i = E(e.scopeId), a = E(e.deviceId), o = i ? await this.getScope(i) : null;
4912
+ if (!o) throw new ln("scope_not_found");
4913
+ if (o.status !== "active") throw new ln("scope_inactive");
4914
+ let s = i && a ? await this.getScopeMembership(i, a) : null, c = Tn(e, o, s);
4915
+ if (c.groupId && !await this.getEnrollment(c.groupId, c.deviceId)) throw new ln("device_not_enrolled");
4916
4916
  let l = Y();
4917
4917
  await Ec(this.db, [
4918
4918
  this.db.prepare("INSERT INTO coordinator_scope_memberships(\n scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,\n manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at\n ) SELECT ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?\n WHERE NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )\n ON CONFLICT(scope_id, device_id) DO UPDATE SET\n role = excluded.role,\n status = 'active',\n membership_epoch = excluded.membership_epoch,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n manifest_hash = excluded.manifest_hash,\n signed_manifest_json = excluded.signed_manifest_json,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch > coordinator_scope_memberships.membership_epoch\n OR (\n excluded.membership_epoch = coordinator_scope_memberships.membership_epoch\n AND coordinator_scope_memberships.status != 'revoked'\n )").bind(c.scopeId, c.deviceId, c.role, c.membershipEpoch, c.coordinatorId, c.groupId, c.manifestIssuerDeviceId, c.manifestHash, c.signedManifestJson, l, t),
@@ -4940,18 +4940,18 @@ var el = class {
4940
4940
  ]);
4941
4941
  let u = await Cc(this.db, t);
4942
4942
  if (!u) throw Error("scope membership grant was not applied.");
4943
- return rt(u, "grant", n), ot(u);
4943
+ return $e(u, "grant", n), rt(u);
4944
4944
  }
4945
4945
  async revokeScopeMembership(e) {
4946
- let t = T(e.scopeId), n = T(e.deviceId);
4946
+ let t = E(e.scopeId), n = E(e.deviceId);
4947
4947
  if (!t || !n) throw Error("scopeId and deviceId are required.");
4948
- let r = Ne(e.effectId), i = d(e), a = await Cc(this.db, r);
4949
- if (a) return rt(a, "revoke", i), a.outcome_applied === 1;
4950
- let o = e.membershipEpoch == null ? null : sn(e.membershipEpoch), s = T(e.groupId), c = s ? await this.getScope(t) : null;
4951
- if (s && s !== c?.group_id) throw new dn("scope_group_mismatch");
4948
+ let r = je(e.effectId), i = d(e), a = await Cc(this.db, r);
4949
+ if (a) return $e(a, "revoke", i), a.outcome_applied === 1;
4950
+ let o = e.membershipEpoch == null ? null : an(e.membershipEpoch), s = E(e.groupId), c = s ? await this.getScope(t) : null;
4951
+ if (s && s !== c?.group_id) throw new ln("scope_group_mismatch");
4952
4952
  let l = await this.getScopeMembership(t, n);
4953
4953
  if (o != null && l && o <= l.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
4954
- let u = Y(), f = o ?? (l?.membership_epoch ?? -1) + 1, p = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(o, o, T(e.manifestHash), T(e.signedManifestJson), u, t, n, l?.membership_epoch ?? -1, l?.status ?? "", r), m = Tc(this.db, {
4954
+ let u = Y(), f = o ?? (l?.membership_epoch ?? -1) + 1, p = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(o, o, E(e.manifestHash), E(e.signedManifestJson), u, t, n, l?.membership_epoch ?? -1, l?.status ?? "", r), m = Tc(this.db, {
4955
4955
  effectId: r,
4956
4956
  requestJson: i,
4957
4957
  scopeId: t,
@@ -4967,8 +4967,8 @@ var el = class {
4967
4967
  status: "revoked",
4968
4968
  membershipEpoch: f,
4969
4969
  updatedAt: u,
4970
- actorType: T(e.actorType),
4971
- actorId: T(e.actorId),
4970
+ actorType: E(e.actorType),
4971
+ actorId: E(e.actorId),
4972
4972
  createdAt: u
4973
4973
  });
4974
4974
  try {
@@ -4984,10 +4984,10 @@ var el = class {
4984
4984
  }
4985
4985
  let g = await Cc(this.db, r);
4986
4986
  if (!g) throw Error("scope membership revoke receipt was not persisted.");
4987
- return rt(g, "revoke", i), g.outcome_applied === 1;
4987
+ return $e(g, "revoke", i), g.outcome_applied === 1;
4988
4988
  }
4989
4989
  async listScopeMemberships(e, t = !1) {
4990
- let n = T(e);
4990
+ let n = E(e);
4991
4991
  if (!n) throw Error("scopeId is required.");
4992
4992
  let r = t ? "" : "AND status = 'active'";
4993
4993
  return (await Z(this.db.prepare(`SELECT scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,
@@ -4997,7 +4997,7 @@ var el = class {
4997
4997
  ORDER BY device_id ASC`).bind(n))).map((e) => J(e));
4998
4998
  }
4999
4999
  async listDeviceScopeMemberships(e, t = !1) {
5000
- let n = T(e);
5000
+ let n = E(e);
5001
5001
  if (!n) throw Error("deviceId is required.");
5002
5002
  let r = t ? "" : "AND status = 'active'";
5003
5003
  return (await Z(this.db.prepare(`SELECT scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,
@@ -5007,9 +5007,9 @@ var el = class {
5007
5007
  ORDER BY scope_id ASC`).bind(n))).map((e) => J(e));
5008
5008
  }
5009
5009
  async listScopeMembershipAuditEvents(e) {
5010
- let t = T(e.scopeId);
5010
+ let t = E(e.scopeId);
5011
5011
  if (!t) throw Error("scopeId is required.");
5012
- let n = T(e.deviceId), r = nn(e.limit), i = n ? "scope_id = ? AND device_id = ?" : "scope_id = ?", a = n ? [
5012
+ let n = E(e.deviceId), r = tn(e.limit), i = n ? "scope_id = ? AND device_id = ?" : "scope_id = ?", a = n ? [
5013
5013
  t,
5014
5014
  n,
5015
5015
  r
@@ -5028,16 +5028,16 @@ var el = class {
5028
5028
  }
5029
5029
  async getBootstrapGrantAuthorization(e) {
5030
5030
  try {
5031
- let t = mn(e), n = await Q(this.db.prepare(Je).bind(t.grantId)), r = be(t, n);
5032
- if (r) return at(r);
5033
- if (!n) return at("bootstrap_authorization_unavailable");
5031
+ let t = dn(e), n = await Q(this.db.prepare(We).bind(t.grantId)), r = be(t, n);
5032
+ if (r) return nt(r);
5033
+ if (!n) return nt("bootstrap_authorization_unavailable");
5034
5034
  let i = { ...n }, a = {
5035
5035
  seed: i.seed_enrollment_public_key === null ? null : await o(i.seed_enrollment_public_key),
5036
5036
  worker: i.worker_enrollment_public_key === null ? null : await o(i.worker_enrollment_public_key)
5037
- }, s = $e(t, i, a), c = await Q(this.db.prepare(s.sql).bind(...s.values));
5037
+ }, s = Ye(t, i, a), c = await Q(this.db.prepare(s.sql).bind(...s.values));
5038
5038
  return de(c);
5039
5039
  } catch {
5040
- return at("bootstrap_authorization_unavailable");
5040
+ return nt("bootstrap_authorization_unavailable");
5041
5041
  }
5042
5042
  }
5043
5043
  async listBootstrapGrants(e) {
@@ -5054,16 +5054,16 @@ var el = class {
5054
5054
  ORDER BY created_at ASC, request_id ASC`).bind(e.groupId, e.deviceId, n))).map((e) => J(e));
5055
5055
  }
5056
5056
  async createLegacyTeamCompletion(e, t) {
5057
- let [n] = ae([e]);
5057
+ let [n] = se([e]);
5058
5058
  if (!n) throw Error("completion_manifest_invalid");
5059
5059
  let r = await this.getGroup(n);
5060
5060
  if (!r) throw Error("group_not_found");
5061
5061
  if (r.archived_at) throw Error("group_archived");
5062
- let i = te(t), a = JSON.parse(i);
5063
- m(a);
5062
+ let i = It(t), a = JSON.parse(i);
5063
+ Hn(a);
5064
5064
  let o = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
5065
- if (o) return ht(o.manifest_json, i, "existing");
5066
- let s = await this.requireLegacyTeamCompletionSources(n, a, i), c = await this.prepareLegacyTeamCompletionOwnerProof(n, i), l = await $(this.db.prepare(`${tn}${c.ctes}
5065
+ if (o) return dt(o.manifest_json, i, "existing");
5066
+ let s = await this.requireLegacyTeamCompletionSources(n, a, i), c = await this.prepareLegacyTeamCompletionOwnerProof(n, i), l = await $(this.db.prepare(`${en}${c.ctes}
5067
5067
  INSERT OR IGNORE INTO coordinator_legacy_team_completions(
5068
5068
  group_id, candidate_ref, manifest_version, manifest_json, completed_at, created_at
5069
5069
  ) SELECT ?, ?, ?, ?, ?, ?
@@ -5100,13 +5100,13 @@ var el = class {
5100
5100
  AND enrolled.fingerprint = json_extract(requested.value, '$.key_fingerprint')
5101
5101
  AND enrolled.enabled = 1
5102
5102
  )
5103
- ) AND ${Vt}
5103
+ ) AND ${Pt}
5104
5104
  AND (${c.currentSql}) AND (${c.compatibleSql})`).bind(...c.values, n, a.candidate_ref, a.version, i, a.completed_at, Y(), n, i, s, n, n, i, i, n)), u = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
5105
- if (!u) throw await this.requireLegacyTeamCompletionSources(n, a, i), (await Q(this.db.prepare(c.denialSql).bind(...c.values)))?.denial === "completion_conflict" ? new ze() : Error("completion_manifest_unavailable");
5106
- return ht(u.manifest_json, i, l === 1 ? "created" : "existing");
5105
+ if (!u) throw await this.requireLegacyTeamCompletionSources(n, a, i), (await Q(this.db.prepare(c.denialSql).bind(...c.values)))?.denial === "completion_conflict" ? new m() : Error("completion_manifest_unavailable");
5106
+ return dt(u.manifest_json, i, l === 1 ? "created" : "existing");
5107
5107
  }
5108
5108
  async prepareLegacyTeamCompletionOwnerProof(e, t) {
5109
- let n = await on(await Z(this.db.prepare(_n).bind(t, e))), r = En(await kt({
5109
+ let n = await rn(await Z(this.db.prepare(hn).bind(t, e))), r = wn(await St({
5110
5110
  backend: {
5111
5111
  first: ({ sql: e, values: t }) => Q(this.db.prepare(e).bind(...t)),
5112
5112
  all: ({ sql: e, values: t }) => Z(this.db.prepare(e).bind(...t))
@@ -5123,8 +5123,8 @@ var el = class {
5123
5123
  n,
5124
5124
  ...r.values
5125
5125
  ],
5126
- denialSql: `${tn}${r.ctes}
5127
- SELECT CASE WHEN NOT (${Vt}) OR NOT (${r.currentSql})
5126
+ denialSql: `${en}${r.ctes}
5127
+ SELECT CASE WHEN NOT (${Pt}) OR NOT (${r.currentSql})
5128
5128
  THEN 'completion_manifest_unavailable'
5129
5129
  WHEN NOT (${r.compatibleSql}) THEN 'completion_conflict'
5130
5130
  ELSE 'completion_manifest_unavailable' END AS denial`
@@ -5135,16 +5135,16 @@ var el = class {
5135
5135
  if (!r) throw Error("group_not_found");
5136
5136
  if (r.archived_at) throw Error("group_archived");
5137
5137
  let i = await Z(this.db.prepare("SELECT DISTINCT requested.scope_id, scope.authority_type,\n scope.coordinator_id, scope.group_id, scope.status\n FROM (SELECT json_extract(value, '$.scope_id') AS scope_id\n FROM json_each(?, '$.project_mappings')) AS requested\n LEFT JOIN coordinator_scopes AS scope ON scope.scope_id = requested.scope_id").bind(n));
5138
- return Gt(t, e, i);
5138
+ return Ie(t, e, i);
5139
5139
  }
5140
5140
  async getLegacyTeamCompletion(e, t) {
5141
- let [n] = ae([e]), r = He(t);
5141
+ let [n] = se([e]), r = Oe(t);
5142
5142
  if (!n) throw Error("completion_manifest_invalid");
5143
5143
  let i = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, r));
5144
- return i ? ie(JSON.parse(i.manifest_json)) : null;
5144
+ return i ? ge(JSON.parse(i.manifest_json)) : null;
5145
5145
  }
5146
5146
  async listLegacyTeamCompletions(e) {
5147
- let t = ae(e);
5147
+ let t = se(e);
5148
5148
  if (t.length === 0) return [];
5149
5149
  let n = t.map(() => "?").join(", "), r = await Q(this.db.prepare(`SELECT
5150
5150
  COUNT(*) AS record_count,
@@ -5170,23 +5170,23 @@ var el = class {
5170
5170
  CROSS JOIN completion_stats
5171
5171
  WHERE completions.group_id IN (${n})
5172
5172
  AND completion_stats.record_count <= 500
5173
- AND completion_stats.batch_bytes <= ${Pt}
5174
- AND completion_stats.max_manifest_bytes <= ${jn}
5175
- AND LENGTH(completions.manifest_json) <= ${jn}
5176
- AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${jn}
5173
+ AND completion_stats.batch_bytes <= ${Mn}
5174
+ AND completion_stats.max_manifest_bytes <= ${y}
5175
+ AND LENGTH(completions.manifest_json) <= ${y}
5176
+ AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${y}
5177
5177
  ORDER BY completions.group_id, completions.completed_at, completions.candidate_ref
5178
5178
  LIMIT 501`).bind(...t, ...t));
5179
5179
  if (i.length === 0 && r.record_count > 0 || i.length > 500 || i.reduce((e, t) => e + new TextEncoder().encode(t.group_id).byteLength + new TextEncoder().encode(t.manifest_json).byteLength, 0) > 375e5) throw Error("completion_results_too_large");
5180
5180
  return i.map((e) => ({
5181
5181
  group_id: e.group_id,
5182
- manifest: ie(JSON.parse(e.manifest_json))
5182
+ manifest: ge(JSON.parse(e.manifest_json))
5183
5183
  }));
5184
5184
  }
5185
5185
  async captureAuthControllerLegacyHistory(e) {
5186
- return Ct(e, (e, t) => Z(this.db.prepare(e).bind(...t)));
5186
+ return Rn(e, (e, t) => Z(this.db.prepare(e).bind(...t)));
5187
5187
  }
5188
5188
  async upsertPresence(e) {
5189
- let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r = ft([], e.addresses);
5189
+ let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r = ct([], e.addresses);
5190
5190
  return await this.db.prepare("INSERT INTO presence_records(group_id, device_id, addresses_json, last_seen_at, expires_at, capabilities_json)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n addresses_json = excluded.addresses_json,\n last_seen_at = excluded.last_seen_at,\n expires_at = excluded.expires_at,\n capabilities_json = excluded.capabilities_json").bind(e.groupId, e.deviceId, JSON.stringify(r), t.toISOString(), n, JSON.stringify(e.capabilities ?? {})).run(), {
5191
5191
  group_id: e.groupId,
5192
5192
  device_id: e.deviceId,
@@ -5207,15 +5207,15 @@ var el = class {
5207
5207
  let i = fe(r.results), a = await Promise.all(i.map(async (e) => ({
5208
5208
  ...e,
5209
5209
  keyId: await o(e.public_key)
5210
- }))), s = await this.db.prepare(Ye).bind(JSON.stringify(a), e, t).all();
5210
+ }))), s = await this.db.prepare(Ge).bind(JSON.stringify(a), e, t).all();
5211
5211
  if (s?.success === !1) throw Error("peer_discovery_unavailable");
5212
- return Ge(s?.results).map((e) => {
5212
+ return He(s?.results).map((e) => {
5213
5213
  let t = String(e.expires_at ?? "").trim(), r = !0;
5214
5214
  if (t) {
5215
5215
  let e = new Date(t);
5216
5216
  r = Number.isNaN(e.getTime()) || e.toISOString() <= n;
5217
5217
  }
5218
- let i = r ? [] : ft([], JSON.parse(String(e.addresses_json ?? "[]")));
5218
+ let i = r ? [] : ct([], JSON.parse(String(e.addresses_json ?? "[]")));
5219
5219
  return {
5220
5220
  device_id: String(e.device_id ?? ""),
5221
5221
  public_key: String(e.public_key ?? ""),
@@ -5270,6 +5270,6 @@ function nl(e, t) {
5270
5270
  return e.onMonitor(n), n;
5271
5271
  }
5272
5272
  //#endregion
5273
- export { wn as AccountLinkStatusOperations, tt as AuthSessionOperations, Lt as COORDINATOR_LEGACY_TEAM_COMPLETION_CONFLICT, Pt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_BYTES, lt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_RESPONSE_BYTES, jn as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BYTES, zn as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_GROUPS, gt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_RECORDS, Fn as COORDINATOR_LEGACY_TEAM_COMPLETION_VERSION, ze as CoordinatorLegacyTeamCompletionConflictError, el as D1CoordinatorStore, Sn as DEFAULT_TIME_WINDOW_S, ns as OWNER_BROWSER_ADMISSION_PATH, cc as OWNER_QUALIFICATION_PATH, Er as RelayHealthInstrumentation, Tr as RelayHealthMonitor, bs as admitCoordinatorBrowserAuthSetup, Cr as aggregateRelayHealthAuthority, bn as authSchemaUpgradeResponse, te as canonicalCoordinatorLegacyTeamCompletionManifestJson, A as captureCoordinatorBrowserAuthConfig, vs as captureCoordinatorBrowserAuthOptions, ys as coordinatorBrowserAuthDeviceRoutes, Cs as coordinatorBrowserAuthUnavailableResponse, qn as createCoordinatorApp, Ds as createCoordinatorBrowserAuth, Yo as createCoordinatorOwnerEnrollmentHttp, Oc as createD1AuthLinkBackend, tl as createD1CoordinatorApp, Or as createExclusiveWriterRelayQuota, Zn as createInMemoryRequestRateLimiter, ss as createOwnerBrowserAdmissionHandler, sc as createOwnerQualificationHandler, mc as createOwnerQualificationHttp, nr as d1RelayHealthPublisher, Sr as ensureD1RelayHealthRows, ut as importBrowserCsrfKey, pr as importOwnerEnrollmentAdmissionKey, Dr as initializeRelayQuotaSchema, _r as isOwnerEnrollmentAdmissionKey, rr as issueOwnerEnrollmentAdmission, lr as issueOwnerEnrollmentAdmissionV2, Bs as maintainCoordinatorBrowserAuth, Wo as matchesCoordinatorOwnerEnrollmentHttpPath, He as normalizeCoordinatorLegacyTeamCompletionCandidateRef, ae as normalizeCoordinatorLegacyTeamCompletionGroupIds, ie as normalizeCoordinatorLegacyTeamCompletionManifest, xr as ownerEnrollmentOwnerCommitment, kr as setRelayQuotaEnabled, ir as verifyOwnerEnrollmentAdmission, or as verifyOwnerEnrollmentAdmissionV2 };
5273
+ export { Cn as AccountLinkStatusOperations, Me as AuthSessionOperations, te as COORDINATOR_LEGACY_TEAM_COMPLETION_CONFLICT, Mn as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_BYTES, Be as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_RESPONSE_BYTES, y as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BYTES, _ as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_GROUPS, Ee as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_RECORDS, Bt as COORDINATOR_LEGACY_TEAM_COMPLETION_VERSION, m as CoordinatorLegacyTeamCompletionConflictError, el as D1CoordinatorStore, xn as DEFAULT_TIME_WINDOW_S, ns as OWNER_BROWSER_ADMISSION_PATH, cc as OWNER_QUALIFICATION_PATH, Er as RelayHealthInstrumentation, Tr as RelayHealthMonitor, bs as admitCoordinatorBrowserAuthSetup, Cr as aggregateRelayHealthAuthority, qt as authSchemaUpgradeResponse, It as canonicalCoordinatorLegacyTeamCompletionManifestJson, A as captureCoordinatorBrowserAuthConfig, vs as captureCoordinatorBrowserAuthOptions, ys as coordinatorBrowserAuthDeviceRoutes, Cs as coordinatorBrowserAuthUnavailableResponse, qn as createCoordinatorApp, Ds as createCoordinatorBrowserAuth, Yo as createCoordinatorOwnerEnrollmentHttp, Oc as createD1AuthLinkBackend, tl as createD1CoordinatorApp, Or as createExclusiveWriterRelayQuota, Zn as createInMemoryRequestRateLimiter, ss as createOwnerBrowserAdmissionHandler, sc as createOwnerQualificationHandler, mc as createOwnerQualificationHttp, nr as d1RelayHealthPublisher, Sr as ensureD1RelayHealthRows, ot as importBrowserCsrfKey, pr as importOwnerEnrollmentAdmissionKey, Dr as initializeRelayQuotaSchema, _r as isOwnerEnrollmentAdmissionKey, rr as issueOwnerEnrollmentAdmission, lr as issueOwnerEnrollmentAdmissionV2, Bs as maintainCoordinatorBrowserAuth, Wo as matchesCoordinatorOwnerEnrollmentHttpPath, Oe as normalizeCoordinatorLegacyTeamCompletionCandidateRef, se as normalizeCoordinatorLegacyTeamCompletionGroupIds, ge as normalizeCoordinatorLegacyTeamCompletionManifest, xr as ownerEnrollmentOwnerCommitment, kr as setRelayQuotaEnabled, ir as verifyOwnerEnrollmentAdmission, or as verifyOwnerEnrollmentAdmissionV2 };
5274
5274
 
5275
5275
  //# sourceMappingURL=cloudflare-coordinator.js.map