@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.
- package/dist/api-types.d.ts +3 -0
- package/dist/api-types.d.ts.map +1 -1
- package/dist/coordinator-api-Bxw5Q3py.js +3072 -0
- package/dist/coordinator-api-Bxw5Q3py.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/coordinator-runtime.d.ts.map +1 -1
- package/dist/db.d.ts +7 -3
- package/dist/db.d.ts.map +1 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23263 -4185
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +156 -156
- package/dist/legacy-recipient-policy-projection.d.ts +2 -0
- package/dist/legacy-recipient-policy-projection.d.ts.map +1 -1
- package/dist/operational-status.d.ts +36 -0
- package/dist/operational-status.d.ts.map +1 -0
- package/dist/policy-team-device-eligibility.d.ts +51 -0
- package/dist/policy-team-device-eligibility.d.ts.map +1 -0
- package/dist/project-share-intent.d.ts +16 -0
- package/dist/project-share-intent.d.ts.map +1 -0
- package/dist/recipient-policy-edges.d.ts.map +1 -1
- package/dist/recipient-policy-intent.d.ts.map +1 -1
- package/dist/recipient-policy-onboarding.d.ts +3 -1
- package/dist/recipient-policy-onboarding.d.ts.map +1 -1
- package/dist/recipient-policy-reconciliation.d.ts +10 -1
- package/dist/recipient-policy-reconciliation.d.ts.map +1 -1
- package/dist/recipient-policy-review.d.ts +4 -0
- package/dist/recipient-policy-review.d.ts.map +1 -1
- package/dist/release-discovery.d.ts +47 -0
- package/dist/release-discovery.d.ts.map +1 -0
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +464 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-membership-cache.d.ts +2 -0
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/share-operation.d.ts +4 -15
- package/dist/share-operation.d.ts.map +1 -1
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-auth.d.ts +3 -0
- package/dist/sync-auth.d.ts.map +1 -1
- package/dist/sync-bootstrap-constants.d.ts +7 -0
- package/dist/sync-bootstrap-constants.d.ts.map +1 -0
- package/dist/sync-bootstrap.d.ts +2 -11
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-daemon.d.ts +2 -2
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-identity.d.ts +10 -2
- package/dist/sync-identity.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +1 -0
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-scope-protocol.d.ts +1 -3
- package/dist/sync-scope-protocol.d.ts.map +1 -1
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/dist/viewer-probe.d.ts +50 -0
- package/dist/viewer-probe.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/coordinator-api-CvU8oTg1.js +0 -21107
- package/dist/coordinator-api-CvU8oTg1.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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),
|
|
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 (
|
|
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 ||
|
|
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 ||
|
|
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 || !
|
|
112
|
-
} else if (n === "add_device" && (!i || !
|
|
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:
|
|
119
|
+
reviewedPreviewDigest: a,
|
|
120
120
|
reviewedIntentJson: null
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
let
|
|
124
|
-
if (n === "team_member" && r &&
|
|
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 &&
|
|
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
|
|
134
|
-
target:
|
|
135
|
-
digest:
|
|
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:
|
|
141
|
-
reviewedIntentJson: t(e.reviewedIntent,
|
|
140
|
+
reviewedPreviewDigest: a,
|
|
141
|
+
reviewedIntentJson: t(e.reviewedIntent, o)
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
async function j(
|
|
145
|
-
if (
|
|
146
|
-
if (!
|
|
147
|
-
let
|
|
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:
|
|
150
|
+
policyTeamId: e.policy_team_id
|
|
151
151
|
},
|
|
152
|
-
digest:
|
|
152
|
+
digest: e.reviewed_preview_digest
|
|
153
153
|
});
|
|
154
154
|
return {
|
|
155
155
|
kind: "team_member",
|
|
156
|
-
invite:
|
|
157
|
-
policy_team_id:
|
|
158
|
-
assigned_identity_id:
|
|
159
|
-
reviewed_preview_digest:
|
|
160
|
-
reviewed_intent:
|
|
161
|
-
bound: !!
|
|
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 (
|
|
165
|
-
if (!
|
|
166
|
-
let
|
|
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:
|
|
169
|
+
targetIdentityId: e.target_identity_id
|
|
170
170
|
},
|
|
171
|
-
digest:
|
|
171
|
+
digest: e.reviewed_preview_digest
|
|
172
172
|
});
|
|
173
173
|
return {
|
|
174
174
|
kind: "add_device",
|
|
175
|
-
invite:
|
|
176
|
-
target_identity_id:
|
|
177
|
-
reviewed_preview_digest:
|
|
178
|
-
reviewed_intent:
|
|
179
|
-
bound: !!
|
|
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
|
|
234
|
-
if (!
|
|
235
|
-
let
|
|
236
|
-
if (
|
|
237
|
-
if (
|
|
238
|
-
let
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
241
|
-
let
|
|
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:
|
|
244
|
-
deviceId:
|
|
243
|
+
scopeId: r,
|
|
244
|
+
deviceId: i,
|
|
245
245
|
role: k(e.role) ?? "member",
|
|
246
|
-
membershipEpoch:
|
|
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),
|
|
368
|
-
if (!!
|
|
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 (!
|
|
371
|
-
let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(
|
|
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 !==
|
|
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,
|
|
379
|
-
let
|
|
380
|
-
if (!
|
|
381
|
-
return
|
|
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 (
|
|
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,
|
|
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 (
|
|
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(
|
|
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 =
|
|
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
|
|
426
|
-
if (!
|
|
427
|
-
let
|
|
428
|
-
if (!
|
|
429
|
-
if (
|
|
430
|
-
if (!
|
|
431
|
-
if (
|
|
432
|
-
let
|
|
433
|
-
if (
|
|
434
|
-
let
|
|
435
|
-
if (
|
|
436
|
-
if (
|
|
437
|
-
let
|
|
438
|
-
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(
|
|
439
|
-
if (
|
|
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 (!
|
|
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:${
|
|
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,
|
|
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,
|
|
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,
|
|
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(
|
|
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(
|
|
455
|
-
if (_ && (_.public_key !== e.publicKey || _.fingerprint !== e.fingerprint || _.identity_id !== null && _.identity_id !==
|
|
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 (
|
|
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 !==
|
|
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(
|
|
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 !==
|
|
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,
|
|
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 =
|
|
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
|
|
489
|
-
if (!
|
|
490
|
-
if (
|
|
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 (
|
|
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
|
|
495
|
-
if (r.consumed_at && !
|
|
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
|
|
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 (
|
|
500
|
-
let
|
|
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(
|
|
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
|
|
509
|
-
if (!
|
|
510
|
-
if (
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
let
|
|
514
|
-
if (!
|
|
515
|
-
if (
|
|
516
|
-
let m =
|
|
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:
|
|
519
|
-
invite:
|
|
520
|
-
enrollment:
|
|
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(
|
|
655
|
-
let
|
|
656
|
-
if (a) return
|
|
657
|
-
let c = k(
|
|
658
|
-
if (!u) throw new
|
|
659
|
-
if (u.status !== "active") throw new
|
|
660
|
-
let d = c && l ? await this.getScopeMembership(c, l) : null, f = L(
|
|
661
|
-
if (f.groupId && !await this.getEnrollment(f.groupId, f.deviceId)) throw new
|
|
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,
|
|
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:
|
|
667
|
-
requestJson:
|
|
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:
|
|
674
|
-
requestJson:
|
|
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,
|
|
687
|
+
let h = await B(this.db, r);
|
|
688
688
|
if (!h) throw Error("scope membership grant was not applied.");
|
|
689
|
-
return
|
|
690
|
-
}
|
|
691
|
-
async revokeScopeMembership(
|
|
692
|
-
let
|
|
693
|
-
if (!
|
|
694
|
-
let i = o(
|
|
695
|
-
if (
|
|
696
|
-
let l =
|
|
697
|
-
if (
|
|
698
|
-
let
|
|
699
|
-
if (l != null &&
|
|
700
|
-
let
|
|
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:
|
|
704
|
-
deviceId:
|
|
705
|
-
createdAt:
|
|
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:
|
|
711
|
-
scopeId:
|
|
712
|
-
deviceId:
|
|
710
|
+
previous: f,
|
|
711
|
+
scopeId: n,
|
|
712
|
+
deviceId: r,
|
|
713
713
|
status: "revoked",
|
|
714
714
|
membershipEpoch: h,
|
|
715
|
-
updatedAt:
|
|
716
|
-
actorType: k(
|
|
717
|
-
actorId: k(
|
|
718
|
-
createdAt:
|
|
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
|
|
728
|
-
if (
|
|
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
|
|
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
|
|
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,
|
|
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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wBAAwB,GACxB,wBAAwB,GACxB,6BAA6B,GAC7B,+BAA+B,GAC/B,wBAAwB,GACxB,+BAA+B,GAC/B,yBAAyB,GACzB,yBAAyB,CAAC;AAE7B,MAAM,WAAW,gCAAgC;IAChD,OAAO,EAAE,8BAA8B,CAAC;IACxC,IAAI,EAAE,oCAAoC,CAAC;IAC3C,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;
|
|
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,8BAA8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oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,4BAA4B;IAC5C,wBAAwB,EAAE,MAAM,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;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;AAWD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,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
|