@codemem/core 0.40.1 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/api-types.d.ts +3 -0
  2. package/dist/api-types.d.ts.map +1 -1
  3. package/dist/coordinator-api-Bxw5Q3py.js +3072 -0
  4. package/dist/coordinator-api-Bxw5Q3py.js.map +1 -0
  5. package/dist/coordinator-api.d.ts.map +1 -1
  6. package/dist/coordinator-runtime.d.ts.map +1 -1
  7. package/dist/db.d.ts +7 -3
  8. package/dist/db.d.ts.map +1 -1
  9. package/dist/index.d.ts +12 -6
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +23263 -4185
  12. package/dist/index.js.map +1 -1
  13. package/dist/internal/cloudflare-coordinator.js +156 -156
  14. package/dist/legacy-recipient-policy-projection.d.ts +2 -0
  15. package/dist/legacy-recipient-policy-projection.d.ts.map +1 -1
  16. package/dist/operational-status.d.ts +36 -0
  17. package/dist/operational-status.d.ts.map +1 -0
  18. package/dist/policy-team-device-eligibility.d.ts +51 -0
  19. package/dist/policy-team-device-eligibility.d.ts.map +1 -0
  20. package/dist/project-share-intent.d.ts +16 -0
  21. package/dist/project-share-intent.d.ts.map +1 -0
  22. package/dist/recipient-policy-edges.d.ts.map +1 -1
  23. package/dist/recipient-policy-intent.d.ts.map +1 -1
  24. package/dist/recipient-policy-onboarding.d.ts +3 -1
  25. package/dist/recipient-policy-onboarding.d.ts.map +1 -1
  26. package/dist/recipient-policy-reconciliation.d.ts +10 -1
  27. package/dist/recipient-policy-reconciliation.d.ts.map +1 -1
  28. package/dist/recipient-policy-review.d.ts +4 -0
  29. package/dist/recipient-policy-review.d.ts.map +1 -1
  30. package/dist/release-discovery.d.ts +47 -0
  31. package/dist/release-discovery.d.ts.map +1 -0
  32. package/dist/schema-bootstrap.d.ts.map +1 -1
  33. package/dist/schema.d.ts +464 -0
  34. package/dist/schema.d.ts.map +1 -1
  35. package/dist/scope-membership-cache.d.ts +2 -0
  36. package/dist/scope-membership-cache.d.ts.map +1 -1
  37. package/dist/share-operation.d.ts +4 -15
  38. package/dist/share-operation.d.ts.map +1 -1
  39. package/dist/store.d.ts +1 -0
  40. package/dist/store.d.ts.map +1 -1
  41. package/dist/sync-auth.d.ts +3 -0
  42. package/dist/sync-auth.d.ts.map +1 -1
  43. package/dist/sync-bootstrap-constants.d.ts +7 -0
  44. package/dist/sync-bootstrap-constants.d.ts.map +1 -0
  45. package/dist/sync-bootstrap.d.ts +2 -11
  46. package/dist/sync-bootstrap.d.ts.map +1 -1
  47. package/dist/sync-daemon.d.ts +2 -2
  48. package/dist/sync-daemon.d.ts.map +1 -1
  49. package/dist/sync-identity.d.ts +10 -2
  50. package/dist/sync-identity.d.ts.map +1 -1
  51. package/dist/sync-pass.d.ts +1 -0
  52. package/dist/sync-pass.d.ts.map +1 -1
  53. package/dist/sync-replication.d.ts.map +1 -1
  54. package/dist/sync-scope-protocol.d.ts +1 -3
  55. package/dist/sync-scope-protocol.d.ts.map +1 -1
  56. package/dist/test-schema.generated.d.ts +1 -1
  57. package/dist/test-schema.generated.d.ts.map +1 -1
  58. package/dist/viewer-probe.d.ts +50 -0
  59. package/dist/viewer-probe.d.ts.map +1 -0
  60. package/package.json +1 -1
  61. package/dist/coordinator-api-CvU8oTg1.js +0 -21107
  62. package/dist/coordinator-api-CvU8oTg1.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { Qa as e, Xa as t, ao as n, co as r, do as i, eo as a, fo as o, lo as s, ma as c, oo as l, po as u, qa as d, so as f, t as p, uo as m } from "../coordinator-api-CvU8oTg1.js";
1
+ import { B as e, D as t, H as n, I as r, L as i, R as a, U as o, V as s, W as c, j as l, k as u, n as d, t as f, w as p, z as m } from "../coordinator-api-Bxw5Q3py.js";
2
2
  //#region src/d1-coordinator-store.ts
3
3
  function h(e) {
4
4
  if (e == null) throw Error("expected row");
@@ -92,7 +92,7 @@ function k(e) {
92
92
  return e?.trim() || null;
93
93
  }
94
94
  async function A(e) {
95
- let n = e.inviteKind ?? (k(e.operationId) ? "project_share" : "legacy_enrollment"), r = k(e.policyTeamId), i = k(e.targetIdentityId), o = k(e.reviewedPreviewDigest);
95
+ let n = e.inviteKind ?? (k(e.operationId) ? "project_share" : "legacy_enrollment"), r = k(e.policyTeamId), i = k(e.targetIdentityId), a = k(e.reviewedPreviewDigest);
96
96
  if (![
97
97
  "legacy_enrollment",
98
98
  "project_share",
@@ -100,83 +100,83 @@ async function A(e) {
100
100
  "add_device"
101
101
  ].includes(n)) throw Error("inviteKind is invalid.");
102
102
  if ([r, i].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) throw Error("recipient invite identifier is invalid.");
103
- if (o && !/^[a-f0-9]{64}$/u.test(o)) throw Error("reviewedPreviewDigest must be a SHA-256 digest.");
103
+ if (a && !/^[a-f0-9]{64}$/u.test(a)) throw Error("reviewedPreviewDigest must be a SHA-256 digest.");
104
104
  if (n === "project_share") {
105
105
  if (!k(e.operationId)) throw Error("project_share invite requires operationId.");
106
- if (r || i || o) throw Error("recipient invite metadata requires a recipient invite kind.");
106
+ if (r || i || a) throw Error("recipient invite metadata requires a recipient invite kind.");
107
107
  } else if (n === "legacy_enrollment") {
108
108
  if (k(e.operationId)) throw Error("legacy_enrollment invite cannot reference an operation.");
109
- if (r || i || o) throw Error("recipient invite metadata requires a recipient invite kind.");
109
+ if (r || i || a) throw Error("recipient invite metadata requires a recipient invite kind.");
110
110
  } else if (n === "team_member") {
111
- if (!r || !o || i || k(e.operationId)) throw Error("team_member invite metadata is invalid.");
112
- } else if (n === "add_device" && (!i || !o || r || k(e.operationId))) throw Error("add_device invite metadata is invalid.");
111
+ if (!r || !a || i || k(e.operationId)) throw Error("team_member invite metadata is invalid.");
112
+ } else if (n === "add_device" && (!i || !a || r || k(e.operationId))) throw Error("add_device invite metadata is invalid.");
113
113
  if (!(e.reviewedIntent !== void 0 && e.reviewedIntent !== null)) {
114
114
  if (n === "team_member" || n === "add_device") throw Error("recipient_invite_review_unavailable");
115
115
  return {
116
116
  inviteKind: n,
117
117
  policyTeamId: r,
118
118
  targetIdentityId: i,
119
- reviewedPreviewDigest: o,
119
+ reviewedPreviewDigest: a,
120
120
  reviewedIntentJson: null
121
121
  };
122
122
  }
123
- let s;
124
- if (n === "team_member" && r && o) s = {
123
+ let o;
124
+ if (n === "team_member" && r && a) o = {
125
125
  kind: "team_member",
126
126
  policyTeamId: r
127
127
  };
128
- else if (n === "add_device" && i && o) s = {
128
+ else if (n === "add_device" && i && a) o = {
129
129
  kind: "add_device",
130
130
  targetIdentityId: i
131
131
  };
132
132
  else throw Error("recipient invite metadata requires a recipient invite kind.");
133
- return await a(e.reviewedIntent, {
134
- target: s,
135
- digest: o
133
+ return await l(e.reviewedIntent, {
134
+ target: o,
135
+ digest: a
136
136
  }), {
137
137
  inviteKind: n,
138
138
  policyTeamId: r,
139
139
  targetIdentityId: i,
140
- reviewedPreviewDigest: o,
141
- reviewedIntentJson: t(e.reviewedIntent, s)
140
+ reviewedPreviewDigest: a,
141
+ reviewedIntentJson: t(e.reviewedIntent, o)
142
142
  };
143
143
  }
144
- async function j(t) {
145
- if (t.invite_kind === "team_member") {
146
- if (!t.policy_team_id || !n(t.assigned_identity_id) || !t.reviewed_preview_digest) throw Error("invite_invalid");
147
- let r = await e(t.reviewed_intent_json, {
144
+ async function j(e) {
145
+ if (e.invite_kind === "team_member") {
146
+ if (!e.policy_team_id || !r(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
147
+ let t = await u(e.reviewed_intent_json, {
148
148
  target: {
149
149
  kind: "team_member",
150
- policyTeamId: t.policy_team_id
150
+ policyTeamId: e.policy_team_id
151
151
  },
152
- digest: t.reviewed_preview_digest
152
+ digest: e.reviewed_preview_digest
153
153
  });
154
154
  return {
155
155
  kind: "team_member",
156
- invite: t,
157
- policy_team_id: t.policy_team_id,
158
- assigned_identity_id: t.assigned_identity_id,
159
- reviewed_preview_digest: t.reviewed_preview_digest,
160
- reviewed_intent: r,
161
- bound: !!t.consumed_at
156
+ invite: e,
157
+ policy_team_id: e.policy_team_id,
158
+ assigned_identity_id: e.assigned_identity_id,
159
+ reviewed_preview_digest: e.reviewed_preview_digest,
160
+ reviewed_intent: t,
161
+ bound: !!e.consumed_at
162
162
  };
163
163
  }
164
- if (t.invite_kind === "add_device") {
165
- if (!t.target_identity_id || !t.reviewed_preview_digest) throw Error("invite_invalid");
166
- let n = await e(t.reviewed_intent_json, {
164
+ if (e.invite_kind === "add_device") {
165
+ if (!e.target_identity_id || !e.reviewed_preview_digest) throw Error("invite_invalid");
166
+ let t = await u(e.reviewed_intent_json, {
167
167
  target: {
168
168
  kind: "add_device",
169
- targetIdentityId: t.target_identity_id
169
+ targetIdentityId: e.target_identity_id
170
170
  },
171
- digest: t.reviewed_preview_digest
171
+ digest: e.reviewed_preview_digest
172
172
  });
173
173
  return {
174
174
  kind: "add_device",
175
- invite: t,
176
- target_identity_id: t.target_identity_id,
177
- reviewed_preview_digest: t.reviewed_preview_digest,
178
- reviewed_intent: n,
179
- bound: !!t.consumed_at
175
+ invite: e,
176
+ target_identity_id: e.target_identity_id,
177
+ reviewed_preview_digest: e.reviewed_preview_digest,
178
+ reviewed_intent: t,
179
+ bound: !!e.consumed_at
180
180
  };
181
181
  }
182
182
  return null;
@@ -230,20 +230,20 @@ function I(e, t) {
230
230
  };
231
231
  }
232
232
  function L(e, t, n) {
233
- let i = k(e.scopeId), a = k(e.deviceId);
234
- if (!i || !a) throw Error("scopeId and deviceId are required.");
235
- let o = k(e.coordinatorId), s = k(e.groupId);
236
- if (o && o !== t?.coordinator_id) throw Error("membership coordinatorId must match the scope coordinatorId.");
237
- if (s && s !== t?.group_id) throw new r("scope_group_mismatch");
238
- let c = e.membershipEpoch == null ? null : M(e.membershipEpoch), l = t?.membership_epoch ?? 0;
239
- if (c != null && c < l) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
240
- if (c != null && n && c < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
241
- let u = c ?? (n ? Math.max(l, n.membership_epoch + +(n.status === "revoked")) : l);
233
+ let r = k(e.scopeId), i = k(e.deviceId);
234
+ if (!r || !i) throw Error("scopeId and deviceId are required.");
235
+ let a = k(e.coordinatorId), o = k(e.groupId);
236
+ if (a && a !== t?.coordinator_id) throw Error("membership coordinatorId must match the scope coordinatorId.");
237
+ if (o && o !== t?.group_id) throw new m("scope_group_mismatch");
238
+ let s = e.membershipEpoch == null ? null : M(e.membershipEpoch), c = t?.membership_epoch ?? 0;
239
+ if (s != null && s < c) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
240
+ if (s != null && n && s < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
241
+ let l = s ?? (n ? Math.max(c, n.membership_epoch + +(n.status === "revoked")) : c);
242
242
  return {
243
- scopeId: i,
244
- deviceId: a,
243
+ scopeId: r,
244
+ deviceId: i,
245
245
  role: k(e.role) ?? "member",
246
- membershipEpoch: u,
246
+ membershipEpoch: l,
247
247
  coordinatorId: t?.coordinator_id ?? null,
248
248
  groupId: t?.group_id ?? null,
249
249
  manifestIssuerDeviceId: k(e.manifestIssuerDeviceId) ?? t?.manifest_issuer_device_id ?? null,
@@ -364,30 +364,30 @@ var Y = class {
364
364
  await this.db.prepare("DELETE FROM request_nonces WHERE created_at < ?").bind(e).run();
365
365
  }
366
366
  async createInvite(e) {
367
- let t = b(), n = C(12), r = C(24), i = await w(r), a = l(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, u = await A(e), d = u.inviteKind === "team_member" ? `identity:${C(18)}` : null;
368
- if (!!s != !!c) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
367
+ let t = b(), n = C(12), r = C(24), a = await w(r), o = i(e.expiresAt), s = await this.getGroup(e.groupId), c = String(e.operationId ?? "").trim() || null, l = String(e.reviewedProjectSetDigest ?? "").trim() || null, u = await A(e), d = u.inviteKind === "team_member" ? `identity:${C(18)}` : null;
368
+ if (!!c != !!l) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
369
369
  let f = async () => {
370
- if (!s) return null;
371
- let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(s));
370
+ if (!c) return null;
371
+ let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(c));
372
372
  if (!t) return null;
373
373
  if (t.consumed_at) throw Error("invite_already_bound");
374
- if (t.group_id !== e.groupId || t.policy !== e.policy || t.invite_kind !== u.inviteKind || t.reviewed_project_set_digest !== c || t.inviter_actor_id !== (String(e.inviterActorId ?? "").trim() || null) || t.inviter_display_name !== (String(e.inviterDisplayName ?? "").trim() || null) || t.inviter_device_id !== (String(e.inviterDeviceId ?? "").trim() || null) || t.pending_person_id !== (String(e.pendingPersonId ?? "").trim() || null) || t.project_summaries_json !== (e.projectSummaries ? JSON.stringify(e.projectSummaries) : null) || t.project_intent_json !== (e.projectIntent ? JSON.stringify(e.projectIntent) : null) || t.policy_team_id !== u.policyTeamId || t.target_identity_id !== u.targetIdentityId || t.reviewed_preview_digest !== u.reviewedPreviewDigest || t.reviewed_intent_json !== u.reviewedIntentJson) throw Error("invite_operation_intent_conflict");
374
+ if (t.group_id !== e.groupId || t.policy !== e.policy || t.invite_kind !== u.inviteKind || t.reviewed_project_set_digest !== l || t.inviter_actor_id !== (String(e.inviterActorId ?? "").trim() || null) || t.inviter_display_name !== (String(e.inviterDisplayName ?? "").trim() || null) || t.inviter_device_id !== (String(e.inviterDeviceId ?? "").trim() || null) || t.pending_person_id !== (String(e.pendingPersonId ?? "").trim() || null) || t.project_summaries_json !== (e.projectSummaries ? JSON.stringify(e.projectSummaries) : null) || t.project_intent_json !== (e.projectIntent ? JSON.stringify(e.projectIntent) : null) || t.policy_team_id !== u.policyTeamId || t.target_identity_id !== u.targetIdentityId || t.reviewed_preview_digest !== u.reviewedPreviewDigest || t.reviewed_intent_json !== u.reviewedIntentJson) throw Error("invite_operation_intent_conflict");
375
375
  return h(t);
376
376
  }, p = async (n) => {
377
377
  if (!n.revoked_at && n.expires_at > t) return n;
378
- await J(this.db.prepare("UPDATE coordinator_invites\n SET token = ?, token_digest = ?, expires_at = ?, created_at = ?, created_by = ?,\n team_name_snapshot = ?, revoked_at = NULL\n WHERE operation_id = ? AND token = ?\n AND (revoked_at IS NOT NULL OR expires_at <= ?)").bind(r, i, a, t, e.createdBy ?? null, o?.display_name ?? null, s, n.token, t));
379
- let c = await f();
380
- if (!c) throw Error("invite_operation_reissue_failed");
381
- return c;
378
+ await J(this.db.prepare("UPDATE coordinator_invites\n SET token = ?, token_digest = ?, expires_at = ?, created_at = ?, created_by = ?,\n team_name_snapshot = ?, revoked_at = NULL\n WHERE operation_id = ? AND token = ?\n AND (revoked_at IS NOT NULL OR expires_at <= ?)").bind(r, a, o, t, e.createdBy ?? null, s?.display_name ?? null, c, n.token, t));
379
+ let i = await f();
380
+ if (!i) throw Error("invite_operation_reissue_failed");
381
+ return i;
382
382
  };
383
- if (s) {
383
+ if (c) {
384
384
  let e = await f();
385
385
  if (e) return await p(e);
386
386
  }
387
387
  try {
388
- await this.db.prepare("INSERT INTO coordinator_invites(\n invite_id, group_id, token, policy, expires_at, created_at, created_by,\n team_name_snapshot, revoked_at, operation_id, reviewed_project_set_digest,\n token_digest, inviter_actor_id, inviter_display_name, inviter_device_id,\n pending_person_id, project_summaries_json, project_intent_json, trust_state,\n invite_kind, policy_team_id, target_identity_id, assigned_identity_id,\n reviewed_preview_digest, reviewed_intent_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(n, e.groupId, r, e.policy, a, t, e.createdBy ?? null, o?.display_name ?? null, s, c, i, String(e.inviterActorId ?? "").trim() || null, String(e.inviterDisplayName ?? "").trim() || null, String(e.inviterDeviceId ?? "").trim() || null, String(e.pendingPersonId ?? "").trim() || null, e.projectSummaries ? JSON.stringify(e.projectSummaries) : null, e.projectIntent ? JSON.stringify(e.projectIntent) : null, s ? "pending" : null, u.inviteKind, u.policyTeamId, u.targetIdentityId, d, u.reviewedPreviewDigest, u.reviewedIntentJson).run();
388
+ await this.db.prepare("INSERT INTO coordinator_invites(\n invite_id, group_id, token, policy, expires_at, created_at, created_by,\n team_name_snapshot, revoked_at, operation_id, reviewed_project_set_digest,\n token_digest, inviter_actor_id, inviter_display_name, inviter_device_id,\n pending_person_id, project_summaries_json, project_intent_json, trust_state,\n invite_kind, policy_team_id, target_identity_id, assigned_identity_id,\n reviewed_preview_digest, reviewed_intent_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(n, e.groupId, r, e.policy, o, t, e.createdBy ?? null, s?.display_name ?? null, c, l, a, String(e.inviterActorId ?? "").trim() || null, String(e.inviterDisplayName ?? "").trim() || null, String(e.inviterDeviceId ?? "").trim() || null, String(e.pendingPersonId ?? "").trim() || null, e.projectSummaries ? JSON.stringify(e.projectSummaries) : null, e.projectIntent ? JSON.stringify(e.projectIntent) : null, c ? "pending" : null, u.inviteKind, u.policyTeamId, u.targetIdentityId, d, u.reviewedPreviewDigest, u.reviewedIntentJson).run();
389
389
  } catch (e) {
390
- if (s) {
390
+ if (c) {
391
391
  let e = await f();
392
392
  if (e) return await p(e);
393
393
  }
@@ -413,62 +413,62 @@ var Y = class {
413
413
  let n = await j(t);
414
414
  if (!n) return null;
415
415
  if (t.revoked_at) throw Error("invite_invalid");
416
- if (!t.consumed_at && new Date(t.expires_at) <= new Date(l(e.now))) throw Error("invite_expired");
416
+ if (!t.consumed_at && new Date(t.expires_at) <= new Date(i(e.now))) throw Error("invite_expired");
417
417
  let r = await this.getGroup(t.group_id);
418
418
  if (!r) throw Error("group_not_found");
419
419
  if (r.archived_at) throw Error("group_archived");
420
420
  return n;
421
421
  }
422
422
  async consumeRecipientInvite(e) {
423
- let t = l(e.now), n = e.recipientDisplayName ?? null, r = e.deviceDisplayName ?? null;
423
+ let t = i(e.now), n = e.recipientDisplayName ?? null, r = e.deviceDisplayName ?? null;
424
424
  if (!e.identityId || !e.deviceId || !e.publicKey || !e.fingerprint || e.identityId !== e.identityId.trim() || e.deviceId !== e.deviceId.trim() || e.identityId.length > 256 || e.deviceId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e.identityId) || /[\p{Cc}\p{Cf}]/u.test(e.deviceId)) throw Error("invite_identity_conflict");
425
- let i = await w(e.token), a = await this.getInviteByTokenForInspection(e.token), o = a ? await j(a) : null;
426
- if (!a || !o || o.kind !== e.inviteKind || a.revoked_at) throw Error("invite_invalid");
427
- let s = await this.getGroup(a.group_id);
428
- if (!s) throw Error("group_not_found");
429
- if (s.archived_at) throw Error("group_archived");
430
- if (!a.consumed_at && new Date(a.expires_at) <= new Date(t)) throw Error("invite_expired");
431
- if (d(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
432
- let c = f(o);
433
- if (c !== e.identityId) throw Error("invite_identity_conflict");
434
- let u = a.bound_device_id === e.deviceId && a.bound_public_key === e.publicKey && a.bound_fingerprint === e.fingerprint;
435
- if (a.consumed_at && !u) throw Error("invite_already_bound");
436
- if (a.consumed_at && a.recipient_actor_id !== c) throw Error("invite_identity_conflict");
437
- let p = await q(this.db.prepare(`SELECT ${E}
438
- FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(a.group_id, e.deviceId));
439
- if (p && (p.public_key !== e.publicKey || p.fingerprint !== e.fingerprint || p.identity_id !== null && p.identity_id !== c)) throw Error("invite_identity_conflict");
425
+ let o = await w(e.token), s = await this.getInviteByTokenForInspection(e.token), c = s ? await j(s) : null;
426
+ if (!s || !c || c.kind !== e.inviteKind || s.revoked_at) throw Error("invite_invalid");
427
+ let l = await this.getGroup(s.group_id);
428
+ if (!l) throw Error("group_not_found");
429
+ if (l.archived_at) throw Error("group_archived");
430
+ if (!s.consumed_at && new Date(s.expires_at) <= new Date(t)) throw Error("invite_expired");
431
+ if (p(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
432
+ let u = a(c);
433
+ if (u !== e.identityId) throw Error("invite_identity_conflict");
434
+ let d = s.bound_device_id === e.deviceId && s.bound_public_key === e.publicKey && s.bound_fingerprint === e.fingerprint;
435
+ if (s.consumed_at && !d) throw Error("invite_already_bound");
436
+ if (s.consumed_at && s.recipient_actor_id !== u) throw Error("invite_identity_conflict");
437
+ let f = await q(this.db.prepare(`SELECT ${E}
438
+ FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(s.group_id, e.deviceId));
439
+ if (f && (f.public_key !== e.publicKey || f.fingerprint !== e.fingerprint || f.identity_id !== null && f.identity_id !== u)) throw Error("invite_identity_conflict");
440
440
  let m = 0, h = C(12);
441
- if (!a.consumed_at) {
441
+ if (!s.consumed_at) {
442
442
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
443
443
  m = W((await this.db.batch([
444
- this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND revoked_at IS NULL AND expires_at > ? AND invite_kind = ?\n AND reviewed_intent_json = ? AND reviewed_preview_digest = ?\n AND ((invite_kind = 'team_member' AND assigned_identity_id = ?)\n OR (invite_kind = 'add_device' AND target_identity_id = ?))\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id AND e.device_id = ?\n AND (e.public_key <> ? OR e.fingerprint <> ?\n OR (e.identity_id IS NOT NULL AND e.identity_id <> ?))\n )\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${a.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, c, n, r, i, e.token, t, e.inviteKind, a.reviewed_intent_json, a.reviewed_preview_digest, c, c, e.deviceId, e.publicKey, e.fingerprint, c),
445
- this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ?\n AND i.bound_public_key = ? AND i.bound_fingerprint = ?\n AND i.recipient_actor_id = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),\n enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(t, i, e.token, e.deviceId, e.publicKey, e.fingerprint, c),
446
- this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(h, i, e.token, t),
447
- this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, i, e.token, e.deviceId)
444
+ this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND revoked_at IS NULL AND expires_at > ? AND invite_kind = ?\n AND reviewed_intent_json = ? AND reviewed_preview_digest = ?\n AND ((invite_kind = 'team_member' AND assigned_identity_id = ?)\n OR (invite_kind = 'add_device' AND target_identity_id = ?))\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id AND e.device_id = ?\n AND (e.public_key <> ? OR e.fingerprint <> ?\n OR (e.identity_id IS NOT NULL AND e.identity_id <> ?))\n )\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${s.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, u, n, r, o, e.token, t, e.inviteKind, s.reviewed_intent_json, s.reviewed_preview_digest, u, u, e.deviceId, e.publicKey, e.fingerprint, u),
445
+ this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ?\n AND i.bound_public_key = ? AND i.bound_fingerprint = ?\n AND i.recipient_actor_id = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),\n enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(t, o, e.token, e.deviceId, e.publicKey, e.fingerprint, u),
446
+ this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(h, o, e.token, t),
447
+ this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, o, e.token, e.deviceId)
448
448
  ]))[0]);
449
449
  }
450
- let g = await this.getGroup(a.group_id);
450
+ let g = await this.getGroup(s.group_id);
451
451
  if (!g) throw Error("group_not_found");
452
452
  if (g.archived_at) throw Error("group_archived");
453
453
  let _ = await q(this.db.prepare(`SELECT ${E}
454
- FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(a.group_id, e.deviceId));
455
- if (_ && (_.public_key !== e.publicKey || _.fingerprint !== e.fingerprint || _.identity_id !== null && _.identity_id !== c)) throw Error("invite_identity_conflict");
454
+ FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(s.group_id, e.deviceId));
455
+ if (_ && (_.public_key !== e.publicKey || _.fingerprint !== e.fingerprint || _.identity_id !== null && _.identity_id !== u)) throw Error("invite_identity_conflict");
456
456
  let v = await this.getInviteByTokenForInspection(e.token);
457
457
  if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(t)) throw Error("invite_invalid");
458
458
  let y = await j(v);
459
459
  if (!y || y.kind !== e.inviteKind) throw Error("invite_invalid");
460
- if (f(y) !== c) throw Error("invite_identity_conflict");
460
+ if (a(y) !== u) throw Error("invite_identity_conflict");
461
461
  if (v.bound_device_id !== e.deviceId || v.bound_public_key !== e.publicKey || v.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
462
- if (v.recipient_actor_id !== c) throw Error("invite_identity_conflict");
463
- await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL\n AND public_key = ? AND fingerprint = ?").bind(c, v.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
462
+ if (v.recipient_actor_id !== u) throw Error("invite_identity_conflict");
463
+ await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL\n AND public_key = ? AND fingerprint = ?").bind(u, v.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
464
464
  let b = await this.getEnrollment(v.group_id, e.deviceId);
465
465
  if (!b) throw Error("invite_acceptance_incomplete");
466
- if (b.public_key !== e.publicKey || b.fingerprint !== e.fingerprint || b.identity_id !== c) throw Error("invite_identity_conflict");
466
+ if (b.public_key !== e.publicKey || b.fingerprint !== e.fingerprint || b.identity_id !== u) throw Error("invite_identity_conflict");
467
467
  let x = v;
468
468
  if (y.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(t)) {
469
469
  if (!this.db.batch) throw Error("D1 batch support is required for atomic bootstrap grant recovery.");
470
470
  let n = C(12);
471
- await this.db.batch([this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE invite_id = ? AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND bound_device_id = ? AND recipient_actor_id = ? AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(n, v.invite_id, e.deviceId, c, t), this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE i.invite_id = ? AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, v.invite_id, e.deviceId)]);
471
+ await this.db.batch([this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE invite_id = ? AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND bound_device_id = ? AND recipient_actor_id = ? AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(n, v.invite_id, e.deviceId, u, t), this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE i.invite_id = ? AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, v.invite_id, e.deviceId)]);
472
472
  let r = await this.getInviteByTokenForInspection(e.token);
473
473
  if (!r) throw Error("invite_invalid");
474
474
  x = r;
@@ -483,41 +483,41 @@ var Y = class {
483
483
  }
484
484
  async consumeProjectInvite(e) {
485
485
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
486
- let t = l(e.now), n = await w(e.token), r = await this.getInviteByTokenForInspection(e.token);
486
+ let t = i(e.now), n = await w(e.token), r = await this.getInviteByTokenForInspection(e.token);
487
487
  if (!r?.operation_id || !r.project_intent_json || r.revoked_at) throw Error("invite_invalid");
488
- let i = await this.getGroup(r.group_id);
489
- if (!i) throw Error("group_not_found");
490
- if (i.archived_at) throw Error("group_archived");
488
+ let a = await this.getGroup(r.group_id);
489
+ if (!a) throw Error("group_not_found");
490
+ if (a.archived_at) throw Error("group_archived");
491
491
  if (r.operation_id !== e.operationId) throw Error("invite_invalid");
492
- if (d(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
492
+ if (p(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
493
493
  if (!r.consumed_at && new Date(r.expires_at) <= new Date(t)) throw Error("invite_expired");
494
- let a = r.bound_device_id === e.deviceId && r.bound_public_key === e.publicKey && r.bound_fingerprint === e.fingerprint;
495
- if (r.consumed_at && !a) throw Error("invite_already_bound");
494
+ let o = r.bound_device_id === e.deviceId && r.bound_public_key === e.publicKey && r.bound_fingerprint === e.fingerprint;
495
+ if (r.consumed_at && !o) throw Error("invite_already_bound");
496
496
  if (r.consumed_at && (r.recipient_actor_id !== e.recipientActorId || r.recipient_display_name !== e.recipientDisplayName || r.recipient_device_display_name !== e.deviceDisplayName)) throw Error("invite_identity_conflict");
497
- let o = await q(this.db.prepare(`SELECT ${E}
497
+ let s = await q(this.db.prepare(`SELECT ${E}
498
498
  FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(r.group_id, e.deviceId));
499
- if (o && (o.public_key !== e.publicKey || o.fingerprint !== e.fingerprint || o.identity_id != null && o.identity_id !== e.recipientActorId)) throw Error("invite_identity_conflict");
500
- let s = C(12), c = W((await this.db.batch([
499
+ if (s && (s.public_key !== e.publicKey || s.fingerprint !== e.fingerprint || s.identity_id != null && s.identity_id !== e.recipientActorId)) throw Error("invite_identity_conflict");
500
+ let c = C(12), l = W((await this.db.batch([
501
501
  this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?,\n trust_state = 'pending_inviter_device'\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${r.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, e.recipientActorId, e.recipientDisplayName, e.deviceDisplayName, n, e.token),
502
502
  this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ? AND ? = 1\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = excluded.display_name, enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(t, n, e.token, e.deviceId, +!r.consumed_at),
503
- this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND bootstrap_grant_id IS NULL\n AND bound_device_id = ?\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(s, n, e.token, e.deviceId, t),
503
+ this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND bootstrap_grant_id IS NULL\n AND bound_device_id = ?\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(c, n, e.token, e.deviceId, t),
504
504
  this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at,\n created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.inviter_actor_id, NULL FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n JOIN enrolled_devices e ON e.group_id = i.group_id AND e.device_id = i.inviter_device_id\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bootstrap_grant_id IS NOT NULL\n AND i.bound_device_id = ? AND e.enabled = 1").bind(t, n, e.token, e.deviceId)
505
505
  ]))[0]) === 1, u = await this.getGroup(r.group_id);
506
506
  if (!u) throw Error("group_not_found");
507
507
  if (u.archived_at) throw Error("group_archived");
508
- let f = await this.getInviteByTokenForInspection(e.token);
509
- if (!f) throw Error("invite_invalid");
510
- if (f.bound_device_id !== e.deviceId || f.bound_public_key !== e.publicKey || f.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
511
- if (f.recipient_actor_id !== e.recipientActorId || f.recipient_display_name !== e.recipientDisplayName || f.recipient_device_display_name !== e.deviceDisplayName) throw Error("invite_identity_conflict");
512
- c || await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL AND enabled = 1\n AND public_key = ? AND fingerprint = ?").bind(e.recipientActorId, f.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
513
- let p = await this.getEnrollment(f.group_id, e.deviceId);
514
- if (!p) throw Error("invite_acceptance_incomplete");
515
- if (p.identity_id !== e.recipientActorId) throw Error("invite_identity_conflict");
516
- let m = f.inviter_device_id ? await this.getEnrollment(f.group_id, f.inviter_device_id) : null, h = f.bootstrap_grant_id ? await this.getBootstrapGrant(f.bootstrap_grant_id) : null;
508
+ let d = await this.getInviteByTokenForInspection(e.token);
509
+ if (!d) throw Error("invite_invalid");
510
+ if (d.bound_device_id !== e.deviceId || d.bound_public_key !== e.publicKey || d.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
511
+ if (d.recipient_actor_id !== e.recipientActorId || d.recipient_display_name !== e.recipientDisplayName || d.recipient_device_display_name !== e.deviceDisplayName) throw Error("invite_identity_conflict");
512
+ l || await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL AND enabled = 1\n AND public_key = ? AND fingerprint = ?").bind(e.recipientActorId, d.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
513
+ let f = await this.getEnrollment(d.group_id, e.deviceId);
514
+ if (!f) throw Error("invite_acceptance_incomplete");
515
+ if (f.identity_id !== e.recipientActorId) throw Error("invite_identity_conflict");
516
+ let m = d.inviter_device_id ? await this.getEnrollment(d.group_id, d.inviter_device_id) : null, h = d.bootstrap_grant_id ? await this.getBootstrapGrant(d.bootstrap_grant_id) : null;
517
517
  return {
518
- status: c ? "accepted" : "existing",
519
- invite: f,
520
- enrollment: p,
518
+ status: l ? "accepted" : "existing",
519
+ invite: d,
520
+ enrollment: f,
521
521
  seed_enrollment: m,
522
522
  bootstrap_grant: h
523
523
  };
@@ -651,27 +651,27 @@ var Y = class {
651
651
  ORDER BY coordinator_id ASC, group_id ASC, scope_id ASC`);
652
652
  return (await K(n.length ? s.bind(...n) : s)).map((e) => h(e));
653
653
  }
654
- async grantScopeMembership(e) {
655
- let t = o(e.effectId), n = m(e), a = await B(this.db, t);
656
- if (a) return s(a, "grant", n), i(a);
657
- let c = k(e.scopeId), l = k(e.deviceId), u = c ? await this.getScope(c) : null;
658
- if (!u) throw new r("scope_not_found");
659
- if (u.status !== "active") throw new r("scope_inactive");
660
- let d = c && l ? await this.getScopeMembership(c, l) : null, f = L(e, u, d);
661
- if (f.groupId && !await this.getEnrollment(f.groupId, f.deviceId)) throw new r("device_not_enrolled");
654
+ async grantScopeMembership(t) {
655
+ let r = o(t.effectId), i = s(t), a = await B(this.db, r);
656
+ if (a) return e(a, "grant", i), n(a);
657
+ let c = k(t.scopeId), l = k(t.deviceId), u = c ? await this.getScope(c) : null;
658
+ if (!u) throw new m("scope_not_found");
659
+ if (u.status !== "active") throw new m("scope_inactive");
660
+ let d = c && l ? await this.getScopeMembership(c, l) : null, f = L(t, u, d);
661
+ if (f.groupId && !await this.getEnrollment(f.groupId, f.deviceId)) throw new m("device_not_enrolled");
662
662
  let p = b();
663
663
  await U(this.db, [
664
- 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(f.scopeId, f.deviceId, f.role, f.membershipEpoch, f.coordinatorId, f.groupId, f.manifestIssuerDeviceId, f.manifestHash, f.signedManifestJson, p, t),
664
+ 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(f.scopeId, f.deviceId, f.role, f.membershipEpoch, f.coordinatorId, f.groupId, f.manifestIssuerDeviceId, f.manifestHash, f.signedManifestJson, p, r),
665
665
  V(this.db, {
666
- effectId: t,
667
- requestJson: n,
666
+ effectId: r,
667
+ requestJson: i,
668
668
  scopeId: f.scopeId,
669
669
  deviceId: f.deviceId,
670
670
  createdAt: p
671
671
  }),
672
672
  z(this.db, {
673
- effectId: t,
674
- requestJson: n,
673
+ effectId: r,
674
+ requestJson: i,
675
675
  action: "grant",
676
676
  previous: d,
677
677
  scopeId: f.scopeId,
@@ -684,38 +684,38 @@ var Y = class {
684
684
  createdAt: p
685
685
  })
686
686
  ]);
687
- let h = await B(this.db, t);
687
+ let h = await B(this.db, r);
688
688
  if (!h) throw Error("scope membership grant was not applied.");
689
- return s(h, "grant", n), i(h);
690
- }
691
- async revokeScopeMembership(e) {
692
- let t = k(e.scopeId), n = k(e.deviceId);
693
- if (!t || !n) throw Error("scopeId and deviceId are required.");
694
- let i = o(e.effectId), a = u(e), c = await B(this.db, i);
695
- if (c) return s(c, "revoke", a), c.outcome_applied === 1;
696
- let l = e.membershipEpoch == null ? null : M(e.membershipEpoch), d = k(e.groupId), f = d ? await this.getScope(t) : null;
697
- if (d && d !== f?.group_id) throw new r("scope_group_mismatch");
698
- let p = await this.getScopeMembership(t, n);
699
- if (l != null && p && l <= p.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
700
- let m = b(), h = l ?? (p?.membership_epoch ?? -1) + 1, g = 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(l, l, k(e.manifestHash), k(e.signedManifestJson), m, t, n, p?.membership_epoch ?? -1, p?.status ?? "", i), _ = H(this.db, {
689
+ return e(h, "grant", i), n(h);
690
+ }
691
+ async revokeScopeMembership(t) {
692
+ let n = k(t.scopeId), r = k(t.deviceId);
693
+ if (!n || !r) throw Error("scopeId and deviceId are required.");
694
+ let i = o(t.effectId), a = c(t), s = await B(this.db, i);
695
+ if (s) return e(s, "revoke", a), s.outcome_applied === 1;
696
+ let l = t.membershipEpoch == null ? null : M(t.membershipEpoch), u = k(t.groupId), d = u ? await this.getScope(n) : null;
697
+ if (u && u !== d?.group_id) throw new m("scope_group_mismatch");
698
+ let f = await this.getScopeMembership(n, r);
699
+ if (l != null && f && l <= f.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
700
+ let p = b(), h = l ?? (f?.membership_epoch ?? -1) + 1, g = 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(l, l, k(t.manifestHash), k(t.signedManifestJson), p, n, r, f?.membership_epoch ?? -1, f?.status ?? "", i), _ = H(this.db, {
701
701
  effectId: i,
702
702
  requestJson: a,
703
- scopeId: t,
704
- deviceId: n,
705
- createdAt: m
703
+ scopeId: n,
704
+ deviceId: r,
705
+ createdAt: p
706
706
  }), v = z(this.db, {
707
707
  effectId: i,
708
708
  requestJson: a,
709
709
  action: "revoke",
710
- previous: p,
711
- scopeId: t,
712
- deviceId: n,
710
+ previous: f,
711
+ scopeId: n,
712
+ deviceId: r,
713
713
  status: "revoked",
714
714
  membershipEpoch: h,
715
- updatedAt: m,
716
- actorType: k(e.actorType),
717
- actorId: k(e.actorId),
718
- createdAt: m
715
+ updatedAt: p,
716
+ actorType: k(t.actorType),
717
+ actorId: k(t.actorId),
718
+ createdAt: p
719
719
  });
720
720
  try {
721
721
  await U(this.db, [
@@ -724,13 +724,13 @@ var Y = class {
724
724
  v
725
725
  ]);
726
726
  } catch (e) {
727
- let r = await this.getScopeMembership(t, n);
728
- if (p && (!r || r.membership_epoch !== p.membership_epoch || r.status !== p.status)) return !1;
727
+ let t = await this.getScopeMembership(n, r);
728
+ if (f && (!t || t.membership_epoch !== f.membership_epoch || t.status !== f.status)) return !1;
729
729
  throw e;
730
730
  }
731
731
  let y = await B(this.db, i);
732
732
  if (!y) throw Error("scope membership revoke receipt was not persisted.");
733
- return s(y, "revoke", a), y.outcome_applied === 1;
733
+ return e(y, "revoke", a), y.outcome_applied === 1;
734
734
  }
735
735
  async listScopeMemberships(e, t = !1) {
736
736
  let n = k(e);
@@ -810,7 +810,7 @@ var Y = class {
810
810
  //#endregion
811
811
  //#region src/d1-coordinator-runtime.ts
812
812
  function X(e) {
813
- return p({
813
+ return f({
814
814
  storeFactory: () => new Y(e.db),
815
815
  runtime: {
816
816
  adminSecret: () => String(e.adminSecret ?? "").trim() || null,
@@ -820,6 +820,6 @@ function X(e) {
820
820
  });
821
821
  }
822
822
  //#endregion
823
- export { Y as D1CoordinatorStore, c as DEFAULT_TIME_WINDOW_S, X as createD1CoordinatorApp };
823
+ export { Y as D1CoordinatorStore, d as DEFAULT_TIME_WINDOW_S, X as createD1CoordinatorApp };
824
824
 
825
825
  //# sourceMappingURL=cloudflare-coordinator.js.map
@@ -46,6 +46,7 @@ export interface LegacyRecipientPolicyConditionV1 {
46
46
  code: LegacyRecipientPolicyConditionCodeV1;
47
47
  kind: "actionable" | "diagnostic";
48
48
  message: string;
49
+ scopeKinds?: string[];
49
50
  }
50
51
  export interface LegacyRecipientPolicyProjectionV1 {
51
52
  version: RecipientPolicyContractVersion;
@@ -116,6 +117,7 @@ export interface ListLegacyRecipientPolicyProjectionsOptions {
116
117
  localActorId: string;
117
118
  localDeviceId: string;
118
119
  }
120
+ export declare function isLegacyUmbrellaScopeKind(kind: string): boolean;
119
121
  export declare function projectLegacyRecipientPolicyProjections(snapshot: LegacyRecipientPolicySnapshot, options: ListLegacyRecipientPolicyProjectionsOptions): LegacyRecipientPolicyProjectionV1[];
120
122
  export declare function resolveLegacyRecipientPolicyLocalIdentity(db: Database, options: ListLegacyRecipientPolicyProjectionsOptions): ListLegacyRecipientPolicyProjectionsOptions;
121
123
  export declare function listLegacyRecipientPolicyProjections(db: Database, options: ListLegacyRecipientPolicyProjectionsOptions): LegacyRecipientPolicyProjectionV1[];
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-recipient-policy-projection.d.ts","sourceRoot":"","sources":["../src/legacy-recipient-policy-projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAEN,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,uBAAuB,CAAC;AAI/B,MAAM,MAAM,iCAAiC,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,iCAAiC,GAC1C,yBAAyB,GACzB,8BAA8B,GAC9B,sBAAsB,GACtB,uBAAuB,GACvB,gBAAgB,GAChB,gBAAgB,GAChB,0BAA0B,CAAC;AAE9B,MAAM,WAAW,wCAAwC;IACxD,OAAO,EAAE,8BAA8B,CAAC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,UAAU,GAAG,IAAI,CAAC;IACjC,UAAU,EAAE,iCAAiC,CAAC;IAC9C,UAAU,EAAE,iCAAiC,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,oCAAoC;IACpD,OAAO,EAAE,8BAA8B,CAAC;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,iCAAiC,CAAC;IAC9C,UAAU,EAAE,iCAAiC,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,sCAAsC;IACtD,OAAO,EAAE,8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AAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,WAAW,EAAE,wBAAwB,EAAE,CAAC;IACxC,UAAU,EAAE,sBAAsB,EAAE,CAAC;IACrC,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,eAAe,EAAE,4BAA4B,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,2CAA2C;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACtB;AAuVD,wBAAgB,uCAAuC,CACtD,QAAQ,EAAE,6BAA6B,EACvC,OAAO,EAAE,2CAA2C,GAClD,iCAAiC,EAAE,CA8JrC;AAsPD,wBAAgB,yCAAyC,CACxD,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE,2CAA2C,GAClD,2CAA2C,CAwB7C;AAED,wBAAgB,oCAAoC,CACnD,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE,2CAA2C,GAClD,iCAAiC,EAAE,CAYrC"}
1
+ {"version":3,"file":"legacy-recipient-policy-projection.d.ts","sourceRoot":"","sources":["../src/legacy-recipient-policy-projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAEN,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,uBAAuB,CAAC;AAI/B,MAAM,MAAM,iCAAiC,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,iCAAiC,GAC1C,yBAAyB,GACzB,8BAA8B,GAC9B,sBAAs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,MAAM,GAAG,OAAO,CAE/D;AA+VD,wBAAgB,uCAAuC,CACtD,QAAQ,EAAE,6BAA6B,EACvC,OAAO,EAAE,2CAA2C,GAClD,iCAAiC,EAAE,CAgKrC;AAsPD,wBAAgB,yCAAyC,CACxD,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE,2CAA2C,GAClD,2CAA2C,CAwB7C;AAED,wBAAgB,oCAAoC,CACnD,EAAE,EAAE,QAAQ,EACZ,OAAO,EAAE,2CAA2C,GAClD,iCAAiC,EAAE,CAYrC"}
@@ -0,0 +1,36 @@
1
+ import { type Database } from "./db.js";
2
+ export type OperationalMaintenanceState = "idle" | "running" | "failed" | "unknown";
3
+ export type OperationalSemanticState = "healthy" | "pending" | "degraded" | "failed" | "unknown";
4
+ export interface OperationalStatusSnapshot {
5
+ sync: {
6
+ available: boolean;
7
+ daemon_error: boolean;
8
+ needs_attention: boolean;
9
+ peer_errors: number;
10
+ };
11
+ maintenance: {
12
+ state: OperationalMaintenanceState;
13
+ running: number;
14
+ failed: number;
15
+ };
16
+ semantic_index: {
17
+ state: OperationalSemanticState;
18
+ vector_table_present: boolean;
19
+ };
20
+ raw_events: {
21
+ available: boolean;
22
+ pending: number;
23
+ failed_batches: number;
24
+ };
25
+ observer: {
26
+ available: boolean;
27
+ failed_batches: number;
28
+ backoff_batches: number;
29
+ };
30
+ }
31
+ /** Collect bounded operational aggregates from an already-open database without writing schema. */
32
+ export declare function collectOperationalStatus(db: Database, options?: {
33
+ embeddingDisabled?: boolean;
34
+ recentFailureCutoff?: string;
35
+ }): OperationalStatusSnapshot;
36
+ //# sourceMappingURL=operational-status.d.ts.map