@codemem/core 0.44.0-alpha.1 → 0.44.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coordinator-actions.d.ts +5 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-Dlr65yhR.js → coordinator-api-BAufmPEa.js} +216 -198
- package/dist/coordinator-api-BAufmPEa.js.map +1 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/export-import.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8113 -7709
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +257 -257
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/legacy-team-setup-completion-manifest.d.ts +4 -0
- package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -1
- package/dist/legacy-team-setup-errors.d.ts +2 -0
- package/dist/legacy-team-setup-errors.d.ts.map +1 -1
- package/dist/native-runtime.d.ts +12 -0
- package/dist/native-runtime.d.ts.map +1 -0
- package/dist/project-identity.d.ts +4 -0
- package/dist/project-identity.d.ts.map +1 -0
- package/dist/project-scope-settings.d.ts.map +1 -1
- package/dist/raw-event-ingest.d.ts.map +1 -1
- package/dist/raw-event-sweeper.d.ts +2 -3
- package/dist/raw-event-sweeper.d.ts.map +1 -1
- package/dist/recipient-policy-review.d.ts +6 -0
- package/dist/recipient-policy-review.d.ts.map +1 -1
- package/dist/release-discovery.d.ts +4 -0
- package/dist/release-discovery.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-resolution.d.ts.map +1 -1
- package/dist/store.d.ts +6 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-daemon.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/vector-migration.d.ts.map +1 -1
- package/dist/vectors.d.ts +6 -0
- package/dist/vectors.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/coordinator-api-Dlr65yhR.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { $ as e,
|
|
1
|
+
import { $ as e, A as t, G as n, H as r, J as i, K as a, M as o, O as s, Q as c, T as l, U as u, V as d, W as f, X as p, Y as m, Z as h, at as g, et as _, it as v, lt as y, n as b, nt as x, ot as S, q as C, rt as w, st as T, t as ee, tt as te, ut as E, z as ne } from "../coordinator-api-BAufmPEa.js";
|
|
2
2
|
//#region src/d1-coordinator-store.ts
|
|
3
|
-
function
|
|
3
|
+
function D(e) {
|
|
4
4
|
if (e == null) throw Error("expected row");
|
|
5
5
|
return e;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
let { presence_capabilities_json: t, presence_expires_at: n, ...r } =
|
|
7
|
+
function re(e) {
|
|
8
|
+
let { presence_capabilities_json: t, presence_expires_at: n, ...r } = D(e);
|
|
9
9
|
if (typeof n != "string" || typeof t != "string") return r;
|
|
10
10
|
try {
|
|
11
11
|
let e = JSON.parse(t);
|
|
@@ -23,7 +23,7 @@ function ne(e) {
|
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function ie(e) {
|
|
27
27
|
let t = e.trim();
|
|
28
28
|
if (!t) return "";
|
|
29
29
|
let n = t.includes("://") ? t : `http://${t}`;
|
|
@@ -34,7 +34,7 @@ function re(e) {
|
|
|
34
34
|
return "";
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function ae(e) {
|
|
38
38
|
if (!e) return "";
|
|
39
39
|
try {
|
|
40
40
|
let t = new URL(e), n = t.hostname.toLowerCase();
|
|
@@ -42,18 +42,18 @@ function ie(e) {
|
|
|
42
42
|
} catch {}
|
|
43
43
|
return e;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function O(e, t) {
|
|
46
46
|
let n = [], r = /* @__PURE__ */ new Set();
|
|
47
47
|
for (let i of [...e, ...t]) {
|
|
48
|
-
let e =
|
|
48
|
+
let e = ie(i), t = ae(e);
|
|
49
49
|
!e || r.has(t) || (r.add(t), n.push(e));
|
|
50
50
|
}
|
|
51
51
|
return n;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function k() {
|
|
54
54
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function A(e, t) {
|
|
57
57
|
return e <= t ? {
|
|
58
58
|
low: e,
|
|
59
59
|
high: t
|
|
@@ -92,59 +92,59 @@ function I(e) {
|
|
|
92
92
|
return e?.trim() || null;
|
|
93
93
|
}
|
|
94
94
|
async function ce(e) {
|
|
95
|
-
let t = e.inviteKind ?? (I(e.operationId) ? "project_share" : "legacy_enrollment"),
|
|
95
|
+
let t = e.inviteKind ?? (I(e.operationId) ? "project_share" : "legacy_enrollment"), n = I(e.policyTeamId), r = I(e.targetIdentityId), i = I(e.reviewedPreviewDigest);
|
|
96
96
|
if (![
|
|
97
97
|
"legacy_enrollment",
|
|
98
98
|
"project_share",
|
|
99
99
|
"team_member",
|
|
100
100
|
"add_device"
|
|
101
101
|
].includes(t)) throw Error("inviteKind is invalid.");
|
|
102
|
-
if ([
|
|
103
|
-
if (
|
|
102
|
+
if ([n, r].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) throw Error("recipient invite identifier is invalid.");
|
|
103
|
+
if (i && !/^[a-f0-9]{64}$/u.test(i)) throw Error("reviewedPreviewDigest must be a SHA-256 digest.");
|
|
104
104
|
if (t === "project_share") {
|
|
105
105
|
if (!I(e.operationId)) throw Error("project_share invite requires operationId.");
|
|
106
|
-
if (
|
|
106
|
+
if (n || r || i) throw Error("recipient invite metadata requires a recipient invite kind.");
|
|
107
107
|
} else if (t === "legacy_enrollment") {
|
|
108
108
|
if (I(e.operationId)) throw Error("legacy_enrollment invite cannot reference an operation.");
|
|
109
|
-
if (
|
|
109
|
+
if (n || r || i) throw Error("recipient invite metadata requires a recipient invite kind.");
|
|
110
110
|
} else if (t === "team_member") {
|
|
111
|
-
if (!
|
|
112
|
-
} else if (t === "add_device" && (!
|
|
111
|
+
if (!n || !i || r || I(e.operationId)) throw Error("team_member invite metadata is invalid.");
|
|
112
|
+
} else if (t === "add_device" && (!r || !i || n || I(e.operationId))) throw Error("add_device invite metadata is invalid.");
|
|
113
113
|
if (e.reviewedIntent === void 0 || e.reviewedIntent === null) {
|
|
114
114
|
if (t === "team_member" || t === "add_device") throw Error("recipient_invite_review_unavailable");
|
|
115
115
|
return {
|
|
116
116
|
inviteKind: t,
|
|
117
|
-
policyTeamId:
|
|
118
|
-
targetIdentityId:
|
|
119
|
-
reviewedPreviewDigest:
|
|
117
|
+
policyTeamId: n,
|
|
118
|
+
targetIdentityId: r,
|
|
119
|
+
reviewedPreviewDigest: i,
|
|
120
120
|
reviewedIntentJson: null
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
let
|
|
124
|
-
if (t === "team_member" &&
|
|
123
|
+
let a;
|
|
124
|
+
if (t === "team_member" && n && i) a = {
|
|
125
125
|
kind: "team_member",
|
|
126
|
-
policyTeamId:
|
|
126
|
+
policyTeamId: n
|
|
127
127
|
};
|
|
128
|
-
else if (t === "add_device" &&
|
|
128
|
+
else if (t === "add_device" && r && i) a = {
|
|
129
129
|
kind: "add_device",
|
|
130
|
-
targetIdentityId:
|
|
130
|
+
targetIdentityId: r
|
|
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 o(e.reviewedIntent, {
|
|
134
|
+
target: a,
|
|
135
|
+
digest: i
|
|
136
136
|
}), {
|
|
137
137
|
inviteKind: t,
|
|
138
|
-
policyTeamId:
|
|
139
|
-
targetIdentityId:
|
|
140
|
-
reviewedPreviewDigest:
|
|
141
|
-
reviewedIntentJson:
|
|
138
|
+
policyTeamId: n,
|
|
139
|
+
targetIdentityId: r,
|
|
140
|
+
reviewedPreviewDigest: i,
|
|
141
|
+
reviewedIntentJson: s(e.reviewedIntent, a)
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
async function L(e) {
|
|
145
145
|
if (e.invite_kind === "team_member") {
|
|
146
|
-
if (!e.policy_team_id || !
|
|
147
|
-
let n = await
|
|
146
|
+
if (!e.policy_team_id || !d(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
|
|
147
|
+
let n = await t(e.reviewed_intent_json, {
|
|
148
148
|
target: {
|
|
149
149
|
kind: "team_member",
|
|
150
150
|
policyTeamId: e.policy_team_id
|
|
@@ -163,7 +163,7 @@ async function L(e) {
|
|
|
163
163
|
}
|
|
164
164
|
if (e.invite_kind === "add_device") {
|
|
165
165
|
if (!e.target_identity_id || !e.reviewed_preview_digest) throw Error("invite_invalid");
|
|
166
|
-
let
|
|
166
|
+
let n = await t(e.reviewed_intent_json, {
|
|
167
167
|
target: {
|
|
168
168
|
kind: "add_device",
|
|
169
169
|
targetIdentityId: e.target_identity_id
|
|
@@ -175,7 +175,7 @@ async function L(e) {
|
|
|
175
175
|
invite: e,
|
|
176
176
|
target_identity_id: e.target_identity_id,
|
|
177
177
|
reviewed_preview_digest: e.reviewed_preview_digest,
|
|
178
|
-
reviewed_intent:
|
|
178
|
+
reviewed_intent: n,
|
|
179
179
|
bound: !!e.consumed_at
|
|
180
180
|
};
|
|
181
181
|
}
|
|
@@ -234,16 +234,16 @@ function U(e, t, n) {
|
|
|
234
234
|
if (!r || !i) throw Error("scopeId and deviceId are required.");
|
|
235
235
|
let a = I(e.coordinatorId), o = I(e.groupId);
|
|
236
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
|
|
237
|
+
if (o && o !== t?.group_id) throw new f("scope_group_mismatch");
|
|
238
238
|
let s = e.membershipEpoch == null ? null : R(e.membershipEpoch), c = t?.membership_epoch ?? 0;
|
|
239
239
|
if (s != null && s < c) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
|
|
240
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
|
|
241
|
+
let l = s ?? (n ? Math.max(c, n.membership_epoch + +(n.status === "revoked")) : c);
|
|
242
242
|
return {
|
|
243
243
|
scopeId: r,
|
|
244
244
|
deviceId: i,
|
|
245
245
|
role: I(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: I(e.manifestIssuerDeviceId) ?? t?.manifest_issuer_device_id ?? null,
|
|
@@ -305,27 +305,27 @@ var $ = class {
|
|
|
305
305
|
}
|
|
306
306
|
async close() {}
|
|
307
307
|
async createGroup(e, t) {
|
|
308
|
-
await this.db.prepare("INSERT OR IGNORE INTO groups(group_id, display_name, archived_at, created_at) VALUES (?, ?, NULL, ?)").bind(e, t ?? null,
|
|
308
|
+
await this.db.prepare("INSERT OR IGNORE INTO groups(group_id, display_name, archived_at, created_at) VALUES (?, ?, NULL, ?)").bind(e, t ?? null, k()).run();
|
|
309
309
|
}
|
|
310
310
|
async getGroup(e) {
|
|
311
311
|
let t = await Z(this.db.prepare("SELECT group_id, display_name, archived_at, created_at FROM groups WHERE group_id = ?").bind(e));
|
|
312
|
-
return t ?
|
|
312
|
+
return t ? D(t) : null;
|
|
313
313
|
}
|
|
314
314
|
async listGroups(e = !1) {
|
|
315
315
|
let t = e ? "" : "WHERE archived_at IS NULL";
|
|
316
|
-
return (await X(this.db.prepare(`SELECT group_id, display_name, archived_at, created_at FROM groups ${t} ORDER BY created_at ASC`))).map((e) =>
|
|
316
|
+
return (await X(this.db.prepare(`SELECT group_id, display_name, archived_at, created_at FROM groups ${t} ORDER BY created_at ASC`))).map((e) => D(e));
|
|
317
317
|
}
|
|
318
318
|
async renameGroup(e, t) {
|
|
319
319
|
return await Q(this.db.prepare("UPDATE groups SET display_name = ? WHERE group_id = ?").bind(t, e)) > 0;
|
|
320
320
|
}
|
|
321
|
-
async archiveGroup(e, t =
|
|
321
|
+
async archiveGroup(e, t = k()) {
|
|
322
322
|
return await Q(this.db.prepare("UPDATE groups SET archived_at = ? WHERE group_id = ? AND archived_at IS NULL").bind(t, e)) > 0;
|
|
323
323
|
}
|
|
324
324
|
async unarchiveGroup(e) {
|
|
325
325
|
return await Q(this.db.prepare("UPDATE groups SET archived_at = NULL WHERE group_id = ? AND archived_at IS NOT NULL").bind(e)) > 0;
|
|
326
326
|
}
|
|
327
327
|
async enrollDevice(e, t) {
|
|
328
|
-
if (await Q(this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, 1, ?)\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n public_key = excluded.public_key,\n fingerprint = excluded.fingerprint,\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = excluded.display_name,\n enabled = 1\n WHERE excluded.identity_id IS NULL\n OR enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(e, t.deviceId, t.publicKey, t.fingerprint, t.identityId ?? null, t.displayName ?? null,
|
|
328
|
+
if (await Q(this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, 1, ?)\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n public_key = excluded.public_key,\n fingerprint = excluded.fingerprint,\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = excluded.display_name,\n enabled = 1\n WHERE excluded.identity_id IS NULL\n OR enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(e, t.deviceId, t.publicKey, t.fingerprint, t.identityId ?? null, t.displayName ?? null, k())) === 0) throw Error("invite_identity_conflict");
|
|
329
329
|
}
|
|
330
330
|
async listEnrolledDevices(e, t) {
|
|
331
331
|
let n = t ? "" : "AND enrolled_devices.enabled = 1";
|
|
@@ -335,13 +335,13 @@ var $ = class {
|
|
|
335
335
|
ON presence_records.group_id = enrolled_devices.group_id
|
|
336
336
|
AND presence_records.device_id = enrolled_devices.device_id
|
|
337
337
|
WHERE enrolled_devices.group_id = ? ${n}
|
|
338
|
-
ORDER BY enrolled_devices.created_at ASC, enrolled_devices.device_id ASC`).bind(e))).map(
|
|
338
|
+
ORDER BY enrolled_devices.created_at ASC, enrolled_devices.device_id ASC`).bind(e))).map(re);
|
|
339
339
|
}
|
|
340
340
|
async getEnrollment(e, t, n = !1) {
|
|
341
341
|
let r = n ? "" : "AND enabled = 1", i = await Z(this.db.prepare(`SELECT ${F}
|
|
342
342
|
FROM enrolled_devices
|
|
343
343
|
WHERE group_id = ? AND device_id = ? ${r}`).bind(e, t));
|
|
344
|
-
return i ?
|
|
344
|
+
return i ? D(i) : null;
|
|
345
345
|
}
|
|
346
346
|
async renameDevice(e, t, n) {
|
|
347
347
|
return await Q(this.db.prepare("UPDATE enrolled_devices SET display_name = ?\n WHERE group_id = ? AND device_id = ?").bind(n, e, t)) > 0;
|
|
@@ -364,48 +364,48 @@ var $ = 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 =
|
|
368
|
-
if (!!
|
|
367
|
+
let t = k(), n = M(12), i = M(24), a = await N(i), o = r(e.expiresAt), s = await this.getGroup(e.groupId), c = String(e.operationId ?? "").trim() || null, l = String(e.reviewedProjectSetDigest ?? "").trim() || null, u = await ce(e), d = u.inviteKind === "team_member" ? `identity:${M(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 Z(this.db.prepare(`SELECT ${P} FROM coordinator_invites WHERE operation_id = ?`).bind(
|
|
370
|
+
if (!c) return null;
|
|
371
|
+
let t = await Z(this.db.prepare(`SELECT ${P} 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 !==
|
|
375
|
-
return
|
|
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
|
+
return D(t);
|
|
376
376
|
}, p = async (n) => {
|
|
377
377
|
if (!n.revoked_at && n.expires_at > t) return n;
|
|
378
|
-
await Q(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(
|
|
379
|
-
let
|
|
380
|
-
if (!
|
|
381
|
-
return
|
|
378
|
+
await Q(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(i, a, o, t, e.createdBy ?? null, s?.display_name ?? null, c, n.token, t));
|
|
379
|
+
let r = await f();
|
|
380
|
+
if (!r) throw Error("invite_operation_reissue_failed");
|
|
381
|
+
return r;
|
|
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,
|
|
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, i, 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
|
}
|
|
394
394
|
throw e;
|
|
395
395
|
}
|
|
396
|
-
return
|
|
396
|
+
return D(await Z(this.db.prepare(`SELECT ${P} FROM coordinator_invites WHERE invite_id = ?`).bind(n)));
|
|
397
397
|
}
|
|
398
398
|
async getInviteByToken(e) {
|
|
399
399
|
let t = await N(e), n = await Z(this.db.prepare(`SELECT ${P}
|
|
400
400
|
FROM coordinator_invites
|
|
401
401
|
WHERE (token_digest = ? OR token = ?)
|
|
402
402
|
AND revoked_at IS NULL
|
|
403
|
-
AND expires_at > ?`).bind(t, e,
|
|
404
|
-
return n ?
|
|
403
|
+
AND expires_at > ?`).bind(t, e, k()));
|
|
404
|
+
return n ? D(n) : null;
|
|
405
405
|
}
|
|
406
406
|
async getInviteByTokenForInspection(e) {
|
|
407
407
|
let t = await N(e), n = await Z(this.db.prepare(`SELECT ${P} FROM coordinator_invites WHERE token_digest = ? OR token = ?`).bind(t, e));
|
|
408
|
-
return n ?
|
|
408
|
+
return n ? D(n) : null;
|
|
409
409
|
}
|
|
410
410
|
async inspectRecipientInvite(e) {
|
|
411
411
|
let t = await this.getInviteByTokenForInspection(e.token);
|
|
@@ -413,14 +413,14 @@ var $ = class {
|
|
|
413
413
|
let n = await L(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(
|
|
417
|
-
let
|
|
418
|
-
if (!
|
|
419
|
-
if (
|
|
416
|
+
if (!t.consumed_at && new Date(t.expires_at) <= new Date(r(e.now))) throw Error("invite_expired");
|
|
417
|
+
let i = await this.getGroup(t.group_id);
|
|
418
|
+
if (!i) throw Error("group_not_found");
|
|
419
|
+
if (i.archived_at) throw Error("group_archived");
|
|
420
420
|
return n;
|
|
421
421
|
}
|
|
422
422
|
async consumeRecipientInvite(e) {
|
|
423
|
-
let t =
|
|
423
|
+
let t = r(e.now), n = e.recipientDisplayName ?? null, i = 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
425
|
let a = await N(e.token), o = await this.getInviteByTokenForInspection(e.token), s = o ? await L(o) : null;
|
|
426
426
|
if (!o || !s || s.kind !== e.inviteKind || o.revoked_at) throw Error("invite_invalid");
|
|
@@ -428,121 +428,121 @@ var $ = class {
|
|
|
428
428
|
if (!c) throw Error("group_not_found");
|
|
429
429
|
if (c.archived_at) throw Error("group_archived");
|
|
430
430
|
if (!o.consumed_at && new Date(o.expires_at) <= new Date(t)) throw Error("invite_expired");
|
|
431
|
-
if (
|
|
432
|
-
let
|
|
433
|
-
if (
|
|
434
|
-
let
|
|
435
|
-
if (o.consumed_at && !
|
|
436
|
-
if (o.consumed_at && o.recipient_actor_id !==
|
|
437
|
-
let
|
|
431
|
+
if (l(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
|
|
432
|
+
let d = u(s);
|
|
433
|
+
if (d !== e.identityId) throw Error("invite_identity_conflict");
|
|
434
|
+
let f = o.bound_device_id === e.deviceId && o.bound_public_key === e.publicKey && o.bound_fingerprint === e.fingerprint;
|
|
435
|
+
if (o.consumed_at && !f) throw Error("invite_already_bound");
|
|
436
|
+
if (o.consumed_at && o.recipient_actor_id !== d) throw Error("invite_identity_conflict");
|
|
437
|
+
let p = await Z(this.db.prepare(`SELECT ${F}
|
|
438
438
|
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, e.deviceId));
|
|
439
|
-
if (
|
|
440
|
-
let
|
|
439
|
+
if (p && (p.public_key !== e.publicKey || p.fingerprint !== e.fingerprint || p.identity_id !== null && p.identity_id !== d)) throw Error("invite_identity_conflict");
|
|
440
|
+
let m = 0, h = M(12);
|
|
441
441
|
if (!o.consumed_at) {
|
|
442
442
|
if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
|
|
443
|
-
|
|
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:${o.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint,
|
|
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, a, e.token, e.deviceId, e.publicKey, e.fingerprint,
|
|
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(
|
|
443
|
+
m = J((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:${o.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, d, n, i, a, e.token, t, e.inviteKind, o.reviewed_intent_json, o.reviewed_preview_digest, d, d, e.deviceId, e.publicKey, e.fingerprint, d),
|
|
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, a, e.token, e.deviceId, e.publicKey, e.fingerprint, d),
|
|
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, a, e.token, t),
|
|
447
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, a, e.token, e.deviceId)
|
|
448
448
|
]))[0]);
|
|
449
449
|
}
|
|
450
|
-
let
|
|
451
|
-
if (!
|
|
452
|
-
if (
|
|
453
|
-
let
|
|
450
|
+
let g = await this.getGroup(o.group_id);
|
|
451
|
+
if (!g) throw Error("group_not_found");
|
|
452
|
+
if (g.archived_at) throw Error("group_archived");
|
|
453
|
+
let _ = await Z(this.db.prepare(`SELECT ${F}
|
|
454
454
|
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, e.deviceId));
|
|
455
|
-
if (
|
|
456
|
-
let
|
|
457
|
-
if (!
|
|
458
|
-
let
|
|
459
|
-
if (!
|
|
460
|
-
if (
|
|
461
|
-
if (
|
|
462
|
-
if (
|
|
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(
|
|
464
|
-
let
|
|
465
|
-
if (!
|
|
466
|
-
if (
|
|
467
|
-
let
|
|
468
|
-
if (
|
|
455
|
+
if (_ && (_.public_key !== e.publicKey || _.fingerprint !== e.fingerprint || _.identity_id !== null && _.identity_id !== d)) throw Error("invite_identity_conflict");
|
|
456
|
+
let v = await this.getInviteByTokenForInspection(e.token);
|
|
457
|
+
if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(t)) throw Error("invite_invalid");
|
|
458
|
+
let y = await L(v);
|
|
459
|
+
if (!y || y.kind !== e.inviteKind) throw Error("invite_invalid");
|
|
460
|
+
if (u(y) !== d) throw Error("invite_identity_conflict");
|
|
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 !== d) 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(d, v.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
|
|
464
|
+
let b = await this.getEnrollment(v.group_id, e.deviceId);
|
|
465
|
+
if (!b) throw Error("invite_acceptance_incomplete");
|
|
466
|
+
if (b.public_key !== e.publicKey || b.fingerprint !== e.fingerprint || b.identity_id !== d) throw Error("invite_identity_conflict");
|
|
467
|
+
let x = v;
|
|
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 = M(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,
|
|
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, d, 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;
|
|
475
475
|
}
|
|
476
|
-
let
|
|
476
|
+
let S = x.bootstrap_grant_id ? await this.getBootstrapGrant(x.bootstrap_grant_id) : null;
|
|
477
477
|
return {
|
|
478
|
-
status:
|
|
479
|
-
invite:
|
|
480
|
-
reviewed_intent:
|
|
481
|
-
bootstrap_grant:
|
|
478
|
+
status: m === 1 ? "accepted" : "existing",
|
|
479
|
+
invite: x,
|
|
480
|
+
reviewed_intent: y.reviewed_intent,
|
|
481
|
+
bootstrap_grant: S
|
|
482
482
|
};
|
|
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 =
|
|
487
|
-
if (!
|
|
488
|
-
let
|
|
489
|
-
if (!
|
|
490
|
-
if (
|
|
491
|
-
if (
|
|
492
|
-
if (
|
|
493
|
-
if (!
|
|
494
|
-
let
|
|
495
|
-
if (
|
|
496
|
-
if (
|
|
497
|
-
let
|
|
498
|
-
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(
|
|
499
|
-
if (
|
|
500
|
-
let
|
|
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:${
|
|
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, +!
|
|
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(
|
|
486
|
+
let t = r(e.now), n = await N(e.token), i = await this.getInviteByTokenForInspection(e.token);
|
|
487
|
+
if (!i?.operation_id || !i.project_intent_json || i.revoked_at) throw Error("invite_invalid");
|
|
488
|
+
let a = await this.getGroup(i.group_id);
|
|
489
|
+
if (!a) throw Error("group_not_found");
|
|
490
|
+
if (a.archived_at) throw Error("group_archived");
|
|
491
|
+
if (i.operation_id !== e.operationId) throw Error("invite_invalid");
|
|
492
|
+
if (l(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
|
|
493
|
+
if (!i.consumed_at && new Date(i.expires_at) <= new Date(t)) throw Error("invite_expired");
|
|
494
|
+
let o = i.bound_device_id === e.deviceId && i.bound_public_key === e.publicKey && i.bound_fingerprint === e.fingerprint;
|
|
495
|
+
if (i.consumed_at && !o) throw Error("invite_already_bound");
|
|
496
|
+
if (i.consumed_at && (i.recipient_actor_id !== e.recipientActorId || i.recipient_display_name !== e.recipientDisplayName || i.recipient_device_display_name !== e.deviceDisplayName)) throw Error("invite_identity_conflict");
|
|
497
|
+
let s = await Z(this.db.prepare(`SELECT ${F}
|
|
498
|
+
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(i.group_id, e.deviceId));
|
|
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 = M(12), u = J((await this.db.batch([
|
|
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:${i.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, e.recipientActorId, e.recipientDisplayName, e.deviceDisplayName, n, e.token),
|
|
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, +!i.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(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
|
-
]))[0]) === 1,
|
|
506
|
-
if (!
|
|
507
|
-
if (
|
|
508
|
-
let
|
|
509
|
-
if (!
|
|
510
|
-
if (
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
let
|
|
514
|
-
if (!
|
|
515
|
-
if (
|
|
516
|
-
let
|
|
505
|
+
]))[0]) === 1, d = await this.getGroup(i.group_id);
|
|
506
|
+
if (!d) throw Error("group_not_found");
|
|
507
|
+
if (d.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
|
+
u || 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;
|
|
517
517
|
return {
|
|
518
|
-
status:
|
|
519
|
-
invite:
|
|
520
|
-
enrollment:
|
|
521
|
-
seed_enrollment:
|
|
522
|
-
bootstrap_grant:
|
|
518
|
+
status: u ? "accepted" : "existing",
|
|
519
|
+
invite: f,
|
|
520
|
+
enrollment: p,
|
|
521
|
+
seed_enrollment: m,
|
|
522
|
+
bootstrap_grant: h
|
|
523
523
|
};
|
|
524
524
|
}
|
|
525
525
|
async listInvites(e) {
|
|
526
526
|
return (await X(this.db.prepare(`SELECT ${P}
|
|
527
527
|
FROM coordinator_invites WHERE group_id = ?
|
|
528
|
-
ORDER BY created_at DESC`).bind(e))).map((e) =>
|
|
528
|
+
ORDER BY created_at DESC`).bind(e))).map((e) => D(e));
|
|
529
529
|
}
|
|
530
530
|
async createJoinRequest(e) {
|
|
531
|
-
let t =
|
|
532
|
-
return await this.db.prepare("INSERT INTO coordinator_join_requests(\n request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n ) VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, NULL, NULL)").bind(n, e.groupId, e.deviceId, e.publicKey, e.fingerprint, e.displayName ?? null, e.token, t).run(),
|
|
531
|
+
let t = k(), n = M(12);
|
|
532
|
+
return await this.db.prepare("INSERT INTO coordinator_join_requests(\n request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n ) VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, NULL, NULL)").bind(n, e.groupId, e.deviceId, e.publicKey, e.fingerprint, e.displayName ?? null, e.token, t).run(), D(await Z(this.db.prepare("SELECT request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n FROM coordinator_join_requests WHERE request_id = ?").bind(n)));
|
|
533
533
|
}
|
|
534
534
|
async listJoinRequests(e, t) {
|
|
535
535
|
let n = t ?? "pending";
|
|
536
|
-
return (await X(this.db.prepare("SELECT request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n FROM coordinator_join_requests\n WHERE group_id = ? AND status = ?\n ORDER BY created_at ASC, device_id ASC").bind(e, n))).map((e) =>
|
|
536
|
+
return (await X(this.db.prepare("SELECT request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n FROM coordinator_join_requests\n WHERE group_id = ? AND status = ?\n ORDER BY created_at ASC, device_id ASC").bind(e, n))).map((e) => D(e));
|
|
537
537
|
}
|
|
538
538
|
async reviewJoinRequest(e) {
|
|
539
539
|
let t = await Z(this.db.prepare("SELECT request_id, group_id, device_id, public_key, fingerprint, display_name, token, status,\n created_at, reviewed_at, reviewed_by\n FROM coordinator_join_requests WHERE request_id = ?").bind(e.requestId));
|
|
540
540
|
if (!t) return null;
|
|
541
541
|
if (t.status !== "pending") return {
|
|
542
|
-
...
|
|
542
|
+
...D(t),
|
|
543
543
|
_no_transition: !0
|
|
544
544
|
};
|
|
545
|
-
let n = Y(e.bootstrapGrant), r =
|
|
545
|
+
let n = Y(e.bootstrapGrant), r = k(), i = e.approved ? "approved" : "denied", a = null, o = null;
|
|
546
546
|
if (e.approved && n) {
|
|
547
547
|
if (!await Z(this.db.prepare("SELECT device_id FROM enrolled_devices WHERE group_id = ? AND device_id = ? AND enabled = 1").bind(t.group_id, n.seedDeviceId))) throw Error("bootstrap grant seed device is not enrolled in the group.");
|
|
548
548
|
if (n.seedDeviceId === t.device_id) throw Error("bootstrap grant seed and worker device ids must differ.");
|
|
@@ -554,9 +554,9 @@ var $ = class {
|
|
|
554
554
|
}
|
|
555
555
|
if (this.db.batch) {
|
|
556
556
|
let t = [];
|
|
557
|
-
if (t.push(this.db.prepare("UPDATE coordinator_join_requests\n SET status = ?, reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(i, r, e.reviewedBy ?? null, e.requestId)), e.approved && (t.push(this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, display_name, enabled, created_at\n )\n SELECT group_id, device_id, public_key, fingerprint, display_name, 1, ?\n FROM coordinator_join_requests\n WHERE request_id = ?\n AND status = 'approved'\n AND reviewed_at = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n public_key = excluded.public_key,\n fingerprint = excluded.fingerprint,\n display_name = excluded.display_name,\n enabled = 1").bind(
|
|
557
|
+
if (t.push(this.db.prepare("UPDATE coordinator_join_requests\n SET status = ?, reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(i, r, e.reviewedBy ?? null, e.requestId)), e.approved && (t.push(this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, display_name, enabled, created_at\n )\n SELECT group_id, device_id, public_key, fingerprint, display_name, 1, ?\n FROM coordinator_join_requests\n WHERE request_id = ?\n AND status = 'approved'\n AND reviewed_at = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n public_key = excluded.public_key,\n fingerprint = excluded.fingerprint,\n display_name = excluded.display_name,\n enabled = 1").bind(k(), e.requestId, r)), a)) {
|
|
558
558
|
o = M(12);
|
|
559
|
-
let n =
|
|
559
|
+
let n = k();
|
|
560
560
|
t.push(this.db.prepare("INSERT INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n ) SELECT ?, ?, ?, ?, ?, ?, ?, NULL\n WHERE EXISTS (\n SELECT 1 FROM coordinator_join_requests\n WHERE request_id = ? AND status = 'approved' AND reviewed_at = ?\n )").bind(o, a.groupId, a.seedDeviceId, a.workerDeviceId, a.expiresAt, n, a.createdBy ?? null, e.requestId, r));
|
|
561
561
|
}
|
|
562
562
|
await this.db.batch(t);
|
|
@@ -575,7 +575,7 @@ var $ = class {
|
|
|
575
575
|
n && await this.revokeBootstrapGrant(n);
|
|
576
576
|
let t = await Z(this.db.prepare("SELECT request_id, group_id, device_id, public_key, fingerprint, display_name, token, status, created_at, reviewed_at, reviewed_by\n FROM coordinator_join_requests WHERE request_id = ?").bind(e.requestId));
|
|
577
577
|
return t ? {
|
|
578
|
-
...
|
|
578
|
+
...D(t),
|
|
579
579
|
_no_transition: !0
|
|
580
580
|
} : null;
|
|
581
581
|
}
|
|
@@ -584,7 +584,7 @@ var $ = class {
|
|
|
584
584
|
if (!s) return null;
|
|
585
585
|
let c = a ? o ? await this.getBootstrapGrant(o) : await this.createBootstrapGrant(a) : null;
|
|
586
586
|
return {
|
|
587
|
-
...
|
|
587
|
+
...D(s),
|
|
588
588
|
bootstrap_grant: c
|
|
589
589
|
};
|
|
590
590
|
}
|
|
@@ -593,49 +593,49 @@ var $ = class {
|
|
|
593
593
|
if (!t || !n || !r) throw Error("groupId, requestingDeviceId, and requestedDeviceId are required.");
|
|
594
594
|
if (n === r) throw Error("requesting and requested device ids must differ.");
|
|
595
595
|
if (i) {
|
|
596
|
-
let e =
|
|
597
|
-
if (await Q(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e, a, t, r, n)) !== 1) throw new
|
|
598
|
-
return
|
|
596
|
+
let e = k();
|
|
597
|
+
if (await Q(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e, a, t, r, n)) !== 1) throw new ne();
|
|
598
|
+
return D(await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(a)));
|
|
599
599
|
}
|
|
600
|
-
let o =
|
|
601
|
-
if (s) return
|
|
602
|
-
let
|
|
603
|
-
if (
|
|
604
|
-
let e =
|
|
605
|
-
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e,
|
|
600
|
+
let o = A(n, r), s = await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, n, r));
|
|
601
|
+
if (s) return D(s);
|
|
602
|
+
let c = await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, r, n));
|
|
603
|
+
if (c) {
|
|
604
|
+
let e = k();
|
|
605
|
+
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e, c.request_id).run(), D(await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(c.request_id)));
|
|
606
606
|
}
|
|
607
|
-
let
|
|
607
|
+
let l = M(12), u = k();
|
|
608
608
|
try {
|
|
609
|
-
await this.db.prepare("INSERT INTO coordinator_reciprocal_approvals(\n request_id,\n group_id,\n requesting_device_id,\n requested_device_id,\n pending_pair_low_device_id,\n pending_pair_high_device_id,\n status,\n created_at,\n resolved_at\n ) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, NULL)").bind(
|
|
609
|
+
await this.db.prepare("INSERT INTO coordinator_reciprocal_approvals(\n request_id,\n group_id,\n requesting_device_id,\n requested_device_id,\n pending_pair_low_device_id,\n pending_pair_high_device_id,\n status,\n created_at,\n resolved_at\n ) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, NULL)").bind(l, t, n, r, o.low, o.high, u).run();
|
|
610
610
|
} catch (e) {
|
|
611
611
|
if (!j(e)) throw e;
|
|
612
612
|
let i = await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, n, r));
|
|
613
|
-
if (i) return
|
|
613
|
+
if (i) return D(i);
|
|
614
614
|
let a = await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, r, n));
|
|
615
615
|
if (a) {
|
|
616
|
-
let e =
|
|
617
|
-
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e, a.request_id).run(),
|
|
616
|
+
let e = k();
|
|
617
|
+
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e, a.request_id).run(), D(await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(a.request_id)));
|
|
618
618
|
}
|
|
619
619
|
throw e;
|
|
620
620
|
}
|
|
621
|
-
return
|
|
621
|
+
return D(await Z(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(l)));
|
|
622
622
|
}
|
|
623
623
|
async createBootstrapGrant(e) {
|
|
624
|
-
let t = se(e), n = M(12), r =
|
|
625
|
-
return await this.db.prepare("INSERT INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, NULL)").bind(n, t.groupId, t.seedDeviceId, t.workerDeviceId, t.expiresAt, r, t.createdBy).run(),
|
|
624
|
+
let t = se(e), n = M(12), r = k();
|
|
625
|
+
return await this.db.prepare("INSERT INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, NULL)").bind(n, t.groupId, t.seedDeviceId, t.workerDeviceId, t.expiresAt, r, t.createdBy).run(), D(await Z(this.db.prepare("SELECT grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n FROM coordinator_bootstrap_grants WHERE grant_id = ?").bind(n)));
|
|
626
626
|
}
|
|
627
627
|
async getScope(e) {
|
|
628
628
|
let t = await Z(this.db.prepare("SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,\n manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at\n FROM coordinator_scopes WHERE scope_id = ?").bind(e));
|
|
629
|
-
return t ?
|
|
629
|
+
return t ? D(t) : null;
|
|
630
630
|
}
|
|
631
631
|
async getScopeMembership(e, t) {
|
|
632
632
|
let n = await Z(this.db.prepare("SELECT 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 FROM coordinator_scope_memberships\n WHERE scope_id = ? AND device_id = ?").bind(e, t));
|
|
633
|
-
return n ?
|
|
633
|
+
return n ? D(n) : null;
|
|
634
634
|
}
|
|
635
635
|
async createScope(e) {
|
|
636
636
|
let t = z(e);
|
|
637
637
|
if (await this.getScope(t.scopeId)) throw Error("scopeId already exists.");
|
|
638
|
-
let n =
|
|
638
|
+
let n = k();
|
|
639
639
|
await this.db.prepare("INSERT INTO coordinator_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(t.scopeId, t.label, t.kind, t.authorityType, t.coordinatorId, t.groupId, t.manifestIssuerDeviceId, t.membershipEpoch, t.manifestHash, t.status, n, n).run();
|
|
640
640
|
let r = await this.getScope(t.scopeId);
|
|
641
641
|
if (!r) throw Error("scope insert returned no row");
|
|
@@ -645,7 +645,7 @@ var $ = class {
|
|
|
645
645
|
let t = I(e.scopeId), n = t ? await this.getScope(t) : null;
|
|
646
646
|
if (!n) return null;
|
|
647
647
|
let r = H(e, n);
|
|
648
|
-
return await this.db.prepare("UPDATE coordinator_scopes\n SET label = ?,\n kind = ?,\n authority_type = ?,\n coordinator_id = ?,\n group_id = ?,\n manifest_issuer_device_id = ?,\n membership_epoch = ?,\n manifest_hash = ?,\n status = ?,\n updated_at = ?\n WHERE scope_id = ?").bind(r.label, r.kind, r.authorityType, r.coordinatorId, r.groupId, r.manifestIssuerDeviceId, r.membershipEpoch, r.manifestHash, r.status,
|
|
648
|
+
return await this.db.prepare("UPDATE coordinator_scopes\n SET label = ?,\n kind = ?,\n authority_type = ?,\n coordinator_id = ?,\n group_id = ?,\n manifest_issuer_device_id = ?,\n membership_epoch = ?,\n manifest_hash = ?,\n status = ?,\n updated_at = ?\n WHERE scope_id = ?").bind(r.label, r.kind, r.authorityType, r.coordinatorId, r.groupId, r.manifestIssuerDeviceId, r.membershipEpoch, r.manifestHash, r.status, k(), r.scopeId).run(), await this.getScope(r.scopeId);
|
|
649
649
|
}
|
|
650
650
|
async listScopes(e = {}) {
|
|
651
651
|
let t = [], n = [], r = I(e.coordinatorId), i = I(e.groupId), a = I(e.status);
|
|
@@ -654,69 +654,69 @@ var $ = class {
|
|
|
654
654
|
manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at
|
|
655
655
|
FROM coordinator_scopes ${o}
|
|
656
656
|
ORDER BY coordinator_id ASC, group_id ASC, scope_id ASC`);
|
|
657
|
-
return (await X(n.length ? s.bind(...n) : s)).map((e) =>
|
|
657
|
+
return (await X(n.length ? s.bind(...n) : s)).map((e) => D(e));
|
|
658
658
|
}
|
|
659
659
|
async grantScopeMembership(e) {
|
|
660
|
-
let t =
|
|
661
|
-
if (
|
|
662
|
-
let
|
|
663
|
-
if (!
|
|
664
|
-
if (
|
|
665
|
-
let u =
|
|
666
|
-
if (
|
|
667
|
-
let p =
|
|
660
|
+
let t = i(e.effectId), r = a(e), o = await K(this.db, t);
|
|
661
|
+
if (o) return n(o, "grant", r), C(o);
|
|
662
|
+
let s = I(e.scopeId), c = I(e.deviceId), l = s ? await this.getScope(s) : null;
|
|
663
|
+
if (!l) throw new f("scope_not_found");
|
|
664
|
+
if (l.status !== "active") throw new f("scope_inactive");
|
|
665
|
+
let u = s && c ? await this.getScopeMembership(s, c) : null, d = U(e, l, u);
|
|
666
|
+
if (d.groupId && !await this.getEnrollment(d.groupId, d.deviceId)) throw new f("device_not_enrolled");
|
|
667
|
+
let p = k();
|
|
668
668
|
await q(this.db, [
|
|
669
|
-
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(
|
|
669
|
+
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(d.scopeId, d.deviceId, d.role, d.membershipEpoch, d.coordinatorId, d.groupId, d.manifestIssuerDeviceId, d.manifestHash, d.signedManifestJson, p, t),
|
|
670
670
|
le(this.db, {
|
|
671
671
|
effectId: t,
|
|
672
|
-
requestJson:
|
|
673
|
-
scopeId:
|
|
674
|
-
deviceId:
|
|
672
|
+
requestJson: r,
|
|
673
|
+
scopeId: d.scopeId,
|
|
674
|
+
deviceId: d.deviceId,
|
|
675
675
|
createdAt: p
|
|
676
676
|
}),
|
|
677
677
|
G(this.db, {
|
|
678
678
|
effectId: t,
|
|
679
|
-
requestJson:
|
|
679
|
+
requestJson: r,
|
|
680
680
|
action: "grant",
|
|
681
681
|
previous: u,
|
|
682
|
-
scopeId:
|
|
683
|
-
deviceId:
|
|
682
|
+
scopeId: d.scopeId,
|
|
683
|
+
deviceId: d.deviceId,
|
|
684
684
|
status: "active",
|
|
685
|
-
membershipEpoch:
|
|
685
|
+
membershipEpoch: d.membershipEpoch,
|
|
686
686
|
updatedAt: p,
|
|
687
|
-
actorType:
|
|
688
|
-
actorId:
|
|
687
|
+
actorType: d.actorType,
|
|
688
|
+
actorId: d.actorId,
|
|
689
689
|
createdAt: p
|
|
690
690
|
})
|
|
691
691
|
]);
|
|
692
692
|
let m = await K(this.db, t);
|
|
693
693
|
if (!m) throw Error("scope membership grant was not applied.");
|
|
694
|
-
return
|
|
694
|
+
return n(m, "grant", r), C(m);
|
|
695
695
|
}
|
|
696
696
|
async revokeScopeMembership(e) {
|
|
697
|
-
let t = I(e.scopeId),
|
|
698
|
-
if (!t || !
|
|
699
|
-
let
|
|
700
|
-
if (
|
|
701
|
-
let
|
|
702
|
-
if (
|
|
703
|
-
let
|
|
704
|
-
if (
|
|
705
|
-
let p =
|
|
706
|
-
effectId:
|
|
707
|
-
requestJson:
|
|
697
|
+
let t = I(e.scopeId), r = I(e.deviceId);
|
|
698
|
+
if (!t || !r) throw Error("scopeId and deviceId are required.");
|
|
699
|
+
let a = i(e.effectId), o = m(e), s = await K(this.db, a);
|
|
700
|
+
if (s) return n(s, "revoke", o), s.outcome_applied === 1;
|
|
701
|
+
let c = e.membershipEpoch == null ? null : R(e.membershipEpoch), l = I(e.groupId), u = l ? await this.getScope(t) : null;
|
|
702
|
+
if (l && l !== u?.group_id) throw new f("scope_group_mismatch");
|
|
703
|
+
let d = await this.getScopeMembership(t, r);
|
|
704
|
+
if (c != null && d && c <= d.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
|
|
705
|
+
let p = k(), h = c ?? (d?.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(c, c, I(e.manifestHash), I(e.signedManifestJson), p, t, r, d?.membership_epoch ?? -1, d?.status ?? "", a), _ = ue(this.db, {
|
|
706
|
+
effectId: a,
|
|
707
|
+
requestJson: o,
|
|
708
708
|
scopeId: t,
|
|
709
|
-
deviceId:
|
|
709
|
+
deviceId: r,
|
|
710
710
|
createdAt: p
|
|
711
|
-
}),
|
|
712
|
-
effectId:
|
|
713
|
-
requestJson:
|
|
711
|
+
}), v = G(this.db, {
|
|
712
|
+
effectId: a,
|
|
713
|
+
requestJson: o,
|
|
714
714
|
action: "revoke",
|
|
715
|
-
previous:
|
|
715
|
+
previous: d,
|
|
716
716
|
scopeId: t,
|
|
717
|
-
deviceId:
|
|
717
|
+
deviceId: r,
|
|
718
718
|
status: "revoked",
|
|
719
|
-
membershipEpoch:
|
|
719
|
+
membershipEpoch: h,
|
|
720
720
|
updatedAt: p,
|
|
721
721
|
actorType: I(e.actorType),
|
|
722
722
|
actorId: I(e.actorId),
|
|
@@ -724,18 +724,18 @@ var $ = class {
|
|
|
724
724
|
});
|
|
725
725
|
try {
|
|
726
726
|
await q(this.db, [
|
|
727
|
-
h,
|
|
728
727
|
g,
|
|
729
|
-
_
|
|
728
|
+
_,
|
|
729
|
+
v
|
|
730
730
|
]);
|
|
731
731
|
} catch (e) {
|
|
732
|
-
let
|
|
733
|
-
if (
|
|
732
|
+
let n = await this.getScopeMembership(t, r);
|
|
733
|
+
if (d && (!n || n.membership_epoch !== d.membership_epoch || n.status !== d.status)) return !1;
|
|
734
734
|
throw e;
|
|
735
735
|
}
|
|
736
|
-
let
|
|
737
|
-
if (!
|
|
738
|
-
return
|
|
736
|
+
let y = await K(this.db, a);
|
|
737
|
+
if (!y) throw Error("scope membership revoke receipt was not persisted.");
|
|
738
|
+
return n(y, "revoke", o), y.outcome_applied === 1;
|
|
739
739
|
}
|
|
740
740
|
async listScopeMemberships(e, t = !1) {
|
|
741
741
|
let n = I(e);
|
|
@@ -745,7 +745,7 @@ var $ = class {
|
|
|
745
745
|
manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at
|
|
746
746
|
FROM coordinator_scope_memberships
|
|
747
747
|
WHERE scope_id = ? ${r}
|
|
748
|
-
ORDER BY device_id ASC`).bind(n))).map((e) =>
|
|
748
|
+
ORDER BY device_id ASC`).bind(n))).map((e) => D(e));
|
|
749
749
|
}
|
|
750
750
|
async listDeviceScopeMemberships(e, t = !1) {
|
|
751
751
|
let n = I(e);
|
|
@@ -755,7 +755,7 @@ var $ = class {
|
|
|
755
755
|
manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at
|
|
756
756
|
FROM coordinator_scope_memberships
|
|
757
757
|
WHERE device_id = ? ${r}
|
|
758
|
-
ORDER BY scope_id ASC`).bind(n))).map((e) =>
|
|
758
|
+
ORDER BY scope_id ASC`).bind(n))).map((e) => D(e));
|
|
759
759
|
}
|
|
760
760
|
async listScopeMembershipAuditEvents(e) {
|
|
761
761
|
let t = I(e.scopeId);
|
|
@@ -771,16 +771,16 @@ var $ = class {
|
|
|
771
771
|
FROM coordinator_scope_membership_audit_log
|
|
772
772
|
WHERE ${i}
|
|
773
773
|
ORDER BY event_id ASC
|
|
774
|
-
LIMIT ?`).bind(...a))).map((e) =>
|
|
774
|
+
LIMIT ?`).bind(...a))).map((e) => D(e));
|
|
775
775
|
}
|
|
776
776
|
async getBootstrapGrant(e) {
|
|
777
777
|
let t = await Z(this.db.prepare("SELECT grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n FROM coordinator_bootstrap_grants WHERE grant_id = ?").bind(e));
|
|
778
|
-
return t ?
|
|
778
|
+
return t ? D(t) : null;
|
|
779
779
|
}
|
|
780
780
|
async listBootstrapGrants(e) {
|
|
781
|
-
return (await X(this.db.prepare("SELECT grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n FROM coordinator_bootstrap_grants WHERE group_id = ?\n ORDER BY created_at DESC, grant_id DESC").bind(e))).map((e) =>
|
|
781
|
+
return (await X(this.db.prepare("SELECT grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at, created_by, revoked_at\n FROM coordinator_bootstrap_grants WHERE group_id = ?\n ORDER BY created_at DESC, grant_id DESC").bind(e))).map((e) => D(e));
|
|
782
782
|
}
|
|
783
|
-
async revokeBootstrapGrant(e, t =
|
|
783
|
+
async revokeBootstrapGrant(e, t = k()) {
|
|
784
784
|
return await Q(this.db.prepare("UPDATE coordinator_bootstrap_grants\n SET revoked_at = COALESCE(revoked_at, ?)\n WHERE grant_id = ?").bind(t, e)) > 0;
|
|
785
785
|
}
|
|
786
786
|
async listReciprocalApprovals(e) {
|
|
@@ -788,57 +788,57 @@ var $ = class {
|
|
|
788
788
|
return (await X(this.db.prepare(`SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at
|
|
789
789
|
FROM coordinator_reciprocal_approvals
|
|
790
790
|
WHERE group_id = ? AND ${t} = ? AND status = ?
|
|
791
|
-
ORDER BY created_at ASC, request_id ASC`).bind(e.groupId, e.deviceId, n))).map((e) =>
|
|
791
|
+
ORDER BY created_at ASC, request_id ASC`).bind(e.groupId, e.deviceId, n))).map((e) => D(e));
|
|
792
792
|
}
|
|
793
793
|
async createLegacyTeamCompletion(e, t) {
|
|
794
|
-
let [n] =
|
|
794
|
+
let [n] = S([e]);
|
|
795
795
|
if (!n) throw Error("completion_manifest_invalid");
|
|
796
796
|
let r = await this.getGroup(n);
|
|
797
797
|
if (!r) throw Error("group_not_found");
|
|
798
798
|
if (r.archived_at) throw Error("group_archived");
|
|
799
|
-
let i =
|
|
800
|
-
|
|
799
|
+
let i = v(t), a = JSON.parse(i);
|
|
800
|
+
E(a);
|
|
801
801
|
let o = await Z(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
|
|
802
802
|
if (o) {
|
|
803
|
-
if (o.manifest_json !== i) throw new
|
|
803
|
+
if (o.manifest_json !== i) throw new w();
|
|
804
804
|
return {
|
|
805
805
|
status: "existing",
|
|
806
|
-
manifest:
|
|
806
|
+
manifest: T(JSON.parse(o.manifest_json))
|
|
807
807
|
};
|
|
808
808
|
}
|
|
809
|
-
let s = await X(this.db.prepare("SELECT DISTINCT\n requested.scope_id,\n scope.authority_type,\n scope.coordinator_id,\n scope.group_id,\n scope.status\n FROM (\n SELECT json_extract(value, '$.scope_id') AS scope_id\n FROM json_each(?, '$.project_mappings')\n ) AS requested\n LEFT JOIN coordinator_scopes AS scope ON scope.scope_id = requested.scope_id").bind(i)), c =
|
|
809
|
+
let s = await X(this.db.prepare("SELECT DISTINCT\n requested.scope_id,\n scope.authority_type,\n scope.coordinator_id,\n scope.group_id,\n scope.status\n FROM (\n SELECT json_extract(value, '$.scope_id') AS scope_id\n FROM json_each(?, '$.project_mappings')\n ) AS requested\n LEFT JOIN coordinator_scopes AS scope ON scope.scope_id = requested.scope_id").bind(i)), c = y(a, n, s), l = await Q(this.db.prepare("INSERT OR IGNORE INTO coordinator_legacy_team_completions(\n group_id, candidate_ref, manifest_version, manifest_json, completed_at, created_at\n ) SELECT ?, ?, ?, ?, ?, ?\n FROM groups\n WHERE group_id = ? AND archived_at IS NULL\n AND NOT EXISTS (\n SELECT 1\n FROM json_each(?, '$.project_mappings') AS requested\n LEFT JOIN coordinator_scopes AS scope\n ON scope.scope_id = json_extract(requested.value, '$.scope_id')\n AND scope.authority_type = 'coordinator'\n AND scope.coordinator_id = ?\n AND scope.group_id = ?\n AND scope.status = 'active'\n WHERE scope.scope_id IS NULL\n )\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices AS enrolled\n WHERE enrolled.group_id = ?\n AND NOT EXISTS (\n SELECT 1 FROM json_each(?, '$.device_decisions') AS requested\n WHERE json_extract(requested.value, '$.device_id') = enrolled.device_id\n AND json_extract(requested.value, '$.key_fingerprint') = enrolled.fingerprint\n AND json_extract(requested.value, '$.enabled') = enrolled.enabled\n )\n )\n AND NOT EXISTS (\n SELECT 1 FROM json_each(?, '$.device_decisions') AS requested\n WHERE json_extract(requested.value, '$.decision') = 'included'\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices AS enrolled\n WHERE enrolled.group_id = ?\n AND enrolled.device_id = json_extract(requested.value, '$.device_id')\n AND enrolled.fingerprint = json_extract(requested.value, '$.key_fingerprint')\n AND enrolled.enabled = 1\n )\n )").bind(n, a.candidate_ref, a.version, i, a.completed_at, k(), n, i, c, n, n, i, i, n)), u = await Z(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
|
|
810
810
|
if (!u) {
|
|
811
811
|
let e = await this.getGroup(n);
|
|
812
812
|
if (!e) throw Error("group_not_found");
|
|
813
813
|
if (e.archived_at) throw Error("group_archived");
|
|
814
814
|
let t = await X(this.db.prepare("SELECT DISTINCT\n requested.scope_id,\n scope.authority_type,\n scope.coordinator_id,\n scope.group_id,\n scope.status\n FROM (\n SELECT json_extract(value, '$.scope_id') AS scope_id\n FROM json_each(?, '$.project_mappings')\n ) AS requested\n LEFT JOIN coordinator_scopes AS scope ON scope.scope_id = requested.scope_id").bind(i));
|
|
815
|
-
throw
|
|
815
|
+
throw y(a, n, t), Error("completion_manifest_unavailable");
|
|
816
816
|
}
|
|
817
|
-
if (u.manifest_json !== i) throw new
|
|
817
|
+
if (u.manifest_json !== i) throw new w();
|
|
818
818
|
return {
|
|
819
819
|
status: l === 1 ? "created" : "existing",
|
|
820
|
-
manifest:
|
|
820
|
+
manifest: T(JSON.parse(u.manifest_json))
|
|
821
821
|
};
|
|
822
822
|
}
|
|
823
823
|
async getLegacyTeamCompletion(e, t) {
|
|
824
|
-
let [n] =
|
|
824
|
+
let [n] = S([e]), r = g(t);
|
|
825
825
|
if (!n) throw Error("completion_manifest_invalid");
|
|
826
826
|
let i = await Z(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, r));
|
|
827
|
-
return i ?
|
|
827
|
+
return i ? T(JSON.parse(i.manifest_json)) : null;
|
|
828
828
|
}
|
|
829
|
-
async listLegacyTeamCompletions(
|
|
830
|
-
let
|
|
831
|
-
if (
|
|
832
|
-
let
|
|
829
|
+
async listLegacyTeamCompletions(t) {
|
|
830
|
+
let n = S(t);
|
|
831
|
+
if (n.length === 0) return [];
|
|
832
|
+
let r = n.map(() => "?").join(", "), i = await Z(this.db.prepare(`SELECT
|
|
833
833
|
COUNT(*) AS record_count,
|
|
834
834
|
COALESCE(SUM(
|
|
835
835
|
LENGTH(CAST(group_id AS BLOB)) + LENGTH(CAST(manifest_json AS BLOB))
|
|
836
836
|
), 0) AS batch_bytes,
|
|
837
837
|
COALESCE(MAX(LENGTH(CAST(manifest_json AS BLOB))), 0) AS max_manifest_bytes
|
|
838
838
|
FROM coordinator_legacy_team_completions
|
|
839
|
-
WHERE group_id IN (${
|
|
840
|
-
if (!
|
|
841
|
-
let
|
|
839
|
+
WHERE group_id IN (${r})`).bind(...n));
|
|
840
|
+
if (!i || i.record_count > 500 || i.batch_bytes > 375e5 || i.max_manifest_bytes > 15e5) throw Error("completion_results_too_large");
|
|
841
|
+
let a = await X(this.db.prepare(`WITH completion_stats AS (
|
|
842
842
|
SELECT
|
|
843
843
|
COUNT(*) AS record_count,
|
|
844
844
|
COALESCE(SUM(
|
|
@@ -846,27 +846,27 @@ var $ = class {
|
|
|
846
846
|
), 0) AS batch_bytes,
|
|
847
847
|
COALESCE(MAX(LENGTH(CAST(manifest_json AS BLOB))), 0) AS max_manifest_bytes
|
|
848
848
|
FROM coordinator_legacy_team_completions
|
|
849
|
-
WHERE group_id IN (${
|
|
849
|
+
WHERE group_id IN (${r})
|
|
850
850
|
)
|
|
851
851
|
SELECT completions.group_id, completions.manifest_json
|
|
852
852
|
FROM coordinator_legacy_team_completions AS completions
|
|
853
853
|
CROSS JOIN completion_stats
|
|
854
|
-
WHERE completions.group_id IN (${
|
|
854
|
+
WHERE completions.group_id IN (${r})
|
|
855
855
|
AND completion_stats.record_count <= 500
|
|
856
|
-
AND completion_stats.batch_bytes <= ${
|
|
857
|
-
AND completion_stats.max_manifest_bytes <= ${
|
|
858
|
-
AND LENGTH(completions.manifest_json) <= ${
|
|
859
|
-
AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${
|
|
856
|
+
AND completion_stats.batch_bytes <= ${h}
|
|
857
|
+
AND completion_stats.max_manifest_bytes <= ${e}
|
|
858
|
+
AND LENGTH(completions.manifest_json) <= ${e}
|
|
859
|
+
AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${e}
|
|
860
860
|
ORDER BY completions.group_id, completions.completed_at, completions.candidate_ref
|
|
861
|
-
LIMIT 501`).bind(...
|
|
862
|
-
if (
|
|
863
|
-
return
|
|
861
|
+
LIMIT 501`).bind(...n, ...n));
|
|
862
|
+
if (a.length === 0 && i.record_count > 0 || a.length > 500 || a.reduce((e, t) => e + new TextEncoder().encode(t.group_id).byteLength + new TextEncoder().encode(t.manifest_json).byteLength, 0) > 375e5) throw Error("completion_results_too_large");
|
|
863
|
+
return a.map((e) => ({
|
|
864
864
|
group_id: e.group_id,
|
|
865
|
-
manifest:
|
|
865
|
+
manifest: T(JSON.parse(e.manifest_json))
|
|
866
866
|
}));
|
|
867
867
|
}
|
|
868
868
|
async upsertPresence(e) {
|
|
869
|
-
let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r =
|
|
869
|
+
let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r = O([], e.addresses);
|
|
870
870
|
return await this.db.prepare("INSERT INTO presence_records(group_id, device_id, addresses_json, last_seen_at, expires_at, capabilities_json)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n addresses_json = excluded.addresses_json,\n last_seen_at = excluded.last_seen_at,\n expires_at = excluded.expires_at,\n capabilities_json = excluded.capabilities_json").bind(e.groupId, e.deviceId, JSON.stringify(r), t.toISOString(), n, JSON.stringify(e.capabilities ?? {})).run(), {
|
|
871
871
|
group_id: e.groupId,
|
|
872
872
|
device_id: e.deviceId,
|
|
@@ -875,14 +875,14 @@ var $ = class {
|
|
|
875
875
|
};
|
|
876
876
|
}
|
|
877
877
|
async listGroupPeers(e, t) {
|
|
878
|
-
let n =
|
|
878
|
+
let n = k();
|
|
879
879
|
return (await X(this.db.prepare("SELECT enrolled_devices.device_id, enrolled_devices.public_key, enrolled_devices.fingerprint, enrolled_devices.display_name,\n presence_records.addresses_json, presence_records.last_seen_at, presence_records.expires_at,\n presence_records.capabilities_json\n FROM enrolled_devices\n LEFT JOIN presence_records\n ON presence_records.group_id = enrolled_devices.group_id\n AND presence_records.device_id = enrolled_devices.device_id\n WHERE enrolled_devices.group_id = ?\n AND enrolled_devices.enabled = 1\n AND enrolled_devices.device_id != ?\n ORDER BY enrolled_devices.device_id ASC").bind(e, t))).map((e) => {
|
|
880
880
|
let t = String(e.expires_at ?? "").trim(), r = !0;
|
|
881
881
|
if (t) {
|
|
882
882
|
let e = new Date(t);
|
|
883
883
|
r = Number.isNaN(e.getTime()) || e.toISOString() <= n;
|
|
884
884
|
}
|
|
885
|
-
let i = r ? [] :
|
|
885
|
+
let i = r ? [] : O([], JSON.parse(String(e.addresses_json ?? "[]")));
|
|
886
886
|
return {
|
|
887
887
|
device_id: String(e.device_id ?? ""),
|
|
888
888
|
public_key: String(e.public_key ?? ""),
|
|
@@ -904,13 +904,13 @@ function de(e) {
|
|
|
904
904
|
adminSecret: () => String(e.adminSecret ?? "").trim() || null,
|
|
905
905
|
now: e.now ?? (() => (/* @__PURE__ */ new Date()).toISOString())
|
|
906
906
|
};
|
|
907
|
-
return
|
|
907
|
+
return ee({
|
|
908
908
|
storeFactory: () => new $(e.db),
|
|
909
909
|
runtime: t,
|
|
910
910
|
requestVerifier: e.requestVerifier
|
|
911
911
|
});
|
|
912
912
|
}
|
|
913
913
|
//#endregion
|
|
914
|
-
export { p as COORDINATOR_LEGACY_TEAM_COMPLETION_CONFLICT,
|
|
914
|
+
export { p as COORDINATOR_LEGACY_TEAM_COMPLETION_CONFLICT, h as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_BYTES, c as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_RESPONSE_BYTES, e as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BYTES, _ as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_GROUPS, te as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_RECORDS, x as COORDINATOR_LEGACY_TEAM_COMPLETION_VERSION, w as CoordinatorLegacyTeamCompletionConflictError, $ as D1CoordinatorStore, b as DEFAULT_TIME_WINDOW_S, v as canonicalCoordinatorLegacyTeamCompletionManifestJson, de as createD1CoordinatorApp, g as normalizeCoordinatorLegacyTeamCompletionCandidateRef, S as normalizeCoordinatorLegacyTeamCompletionGroupIds, T as normalizeCoordinatorLegacyTeamCompletionManifest };
|
|
915
915
|
|
|
916
916
|
//# sourceMappingURL=cloudflare-coordinator.js.map
|