@codemem/core 0.41.0 → 0.42.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 +14 -0
- package/dist/api-types.d.ts.map +1 -1
- package/dist/claude-hooks.d.ts +12 -4
- package/dist/claude-hooks.d.ts.map +1 -1
- package/dist/codex-hooks.d.ts +7 -3
- package/dist/codex-hooks.d.ts.map +1 -1
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-Bxw5Q3py.js → coordinator-api-SeLosPIq.js} +489 -459
- package/dist/coordinator-api-SeLosPIq.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/db.d.ts +2 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/device-identity-binding.d.ts +50 -0
- package/dist/device-identity-binding.d.ts.map +1 -0
- package/dist/device-identity-inventory.d.ts +72 -0
- package/dist/device-identity-inventory.d.ts.map +1 -0
- package/dist/hook-transcript.d.ts +25 -0
- package/dist/hook-transcript.d.ts.map +1 -0
- package/dist/identity-target.d.ts +16 -0
- package/dist/identity-target.d.ts.map +1 -0
- package/dist/index.d.ts +17 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8601 -7482
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +149 -149
- package/dist/project-invite-identity.d.ts +2 -0
- package/dist/project-invite-identity.d.ts.map +1 -1
- package/dist/prompt-transport.d.ts +36 -0
- package/dist/prompt-transport.d.ts.map +1 -0
- package/dist/raw-event-flush.d.ts +1 -0
- package/dist/raw-event-flush.d.ts.map +1 -1
- package/dist/raw-event-ingest.d.ts +19 -0
- package/dist/raw-event-ingest.d.ts.map +1 -0
- package/dist/raw-event-sweeper.d.ts +6 -1
- package/dist/raw-event-sweeper.d.ts.map +1 -1
- package/dist/schema-bootstrap.d.ts +9 -0
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +817 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/share-operation.d.ts.map +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-auth.d.ts +62 -2
- package/dist/sync-auth.d.ts.map +1 -1
- package/dist/sync-bootstrap.d.ts +2 -0
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-http-client.d.ts +1 -0
- package/dist/sync-http-client.d.ts.map +1 -1
- package/dist/sync-pass.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/package.json +1 -1
- package/dist/coordinator-api-Bxw5Q3py.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as e, D as t,
|
|
1
|
+
import { B as e, D as t, G as n, H as r, K 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-SeLosPIq.js";
|
|
2
2
|
//#region src/d1-coordinator-store.ts
|
|
3
3
|
function h(e) {
|
|
4
4
|
if (e == null) throw Error("expected row");
|
|
@@ -143,7 +143,7 @@ async function A(e) {
|
|
|
143
143
|
}
|
|
144
144
|
async function j(e) {
|
|
145
145
|
if (e.invite_kind === "team_member") {
|
|
146
|
-
if (!e.policy_team_id || !
|
|
146
|
+
if (!e.policy_team_id || !a(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
|
|
147
147
|
let t = await u(e.reviewed_intent_json, {
|
|
148
148
|
target: {
|
|
149
149
|
kind: "team_member",
|
|
@@ -234,16 +234,16 @@ function L(e, t, n) {
|
|
|
234
234
|
if (!r || !i) throw Error("scopeId and deviceId are required.");
|
|
235
235
|
let a = k(e.coordinatorId), o = k(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
|
|
238
|
-
let
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
241
|
-
let
|
|
237
|
+
if (o && o !== t?.group_id) throw new s("scope_group_mismatch");
|
|
238
|
+
let c = e.membershipEpoch == null ? null : M(e.membershipEpoch), l = t?.membership_epoch ?? 0;
|
|
239
|
+
if (c != null && c < l) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
|
|
240
|
+
if (c != null && n && c < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
|
|
241
|
+
let u = c ?? (n ? Math.max(l, n.membership_epoch + +(n.status === "revoked")) : l);
|
|
242
242
|
return {
|
|
243
243
|
scopeId: r,
|
|
244
244
|
deviceId: i,
|
|
245
245
|
role: k(e.role) ?? "member",
|
|
246
|
-
membershipEpoch:
|
|
246
|
+
membershipEpoch: u,
|
|
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,32 +364,32 @@ 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 (!!
|
|
369
|
-
let
|
|
370
|
-
if (!
|
|
371
|
-
let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(
|
|
367
|
+
let t = b(), n = C(12), r = C(24), i = await w(r), a = m(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, l = await A(e), u = l.inviteKind === "team_member" ? `identity:${C(18)}` : null;
|
|
368
|
+
if (!!s != !!c) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
|
|
369
|
+
let d = async () => {
|
|
370
|
+
if (!s) return null;
|
|
371
|
+
let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(s));
|
|
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 !==
|
|
374
|
+
if (t.group_id !== e.groupId || t.policy !== e.policy || t.invite_kind !== l.inviteKind || t.reviewed_project_set_digest !== c || t.inviter_actor_id !== (String(e.inviterActorId ?? "").trim() || null) || t.inviter_display_name !== (String(e.inviterDisplayName ?? "").trim() || null) || t.inviter_device_id !== (String(e.inviterDeviceId ?? "").trim() || null) || t.pending_person_id !== (String(e.pendingPersonId ?? "").trim() || null) || t.project_summaries_json !== (e.projectSummaries ? JSON.stringify(e.projectSummaries) : null) || t.project_intent_json !== (e.projectIntent ? JSON.stringify(e.projectIntent) : null) || t.policy_team_id !== l.policyTeamId || t.target_identity_id !== l.targetIdentityId || t.reviewed_preview_digest !== l.reviewedPreviewDigest || t.reviewed_intent_json !== l.reviewedIntentJson) throw Error("invite_operation_intent_conflict");
|
|
375
375
|
return h(t);
|
|
376
|
-
},
|
|
376
|
+
}, f = 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, i, a, t, e.createdBy ?? null, o?.display_name ?? null, s, n.token, t));
|
|
379
|
+
let c = await d();
|
|
380
|
+
if (!c) throw Error("invite_operation_reissue_failed");
|
|
381
|
+
return c;
|
|
382
382
|
};
|
|
383
|
-
if (
|
|
384
|
-
let e = await
|
|
385
|
-
if (e) return await
|
|
383
|
+
if (s) {
|
|
384
|
+
let e = await d();
|
|
385
|
+
if (e) return await f(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, a, t, e.createdBy ?? null, o?.display_name ?? null, s, c, i, String(e.inviterActorId ?? "").trim() || null, String(e.inviterDisplayName ?? "").trim() || null, String(e.inviterDeviceId ?? "").trim() || null, String(e.pendingPersonId ?? "").trim() || null, e.projectSummaries ? JSON.stringify(e.projectSummaries) : null, e.projectIntent ? JSON.stringify(e.projectIntent) : null, s ? "pending" : null, l.inviteKind, l.policyTeamId, l.targetIdentityId, u, l.reviewedPreviewDigest, l.reviewedIntentJson).run();
|
|
389
389
|
} catch (e) {
|
|
390
|
-
if (
|
|
391
|
-
let e = await
|
|
392
|
-
if (e) return await
|
|
390
|
+
if (s) {
|
|
391
|
+
let e = await d();
|
|
392
|
+
if (e) return await f(e);
|
|
393
393
|
}
|
|
394
394
|
throw e;
|
|
395
395
|
}
|
|
@@ -413,69 +413,69 @@ 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(m(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
|
-
async consumeRecipientInvite(
|
|
423
|
-
let
|
|
424
|
-
if (!
|
|
425
|
-
let
|
|
426
|
-
if (!
|
|
427
|
-
let
|
|
428
|
-
if (!
|
|
429
|
-
if (
|
|
430
|
-
if (!
|
|
431
|
-
if (p(
|
|
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 (
|
|
440
|
-
let
|
|
441
|
-
if (!
|
|
422
|
+
async consumeRecipientInvite(t) {
|
|
423
|
+
let n = m(t.now), r = t.recipientDisplayName ?? null, i = t.deviceDisplayName ?? null;
|
|
424
|
+
if (!t.identityId || !t.deviceId || !t.publicKey || !t.fingerprint || t.identityId !== t.identityId.trim() || t.deviceId !== t.deviceId.trim() || t.identityId.length > 256 || t.deviceId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(t.identityId) || /[\p{Cc}\p{Cf}]/u.test(t.deviceId)) throw Error("invite_identity_conflict");
|
|
425
|
+
let a = await w(t.token), o = await this.getInviteByTokenForInspection(t.token), s = o ? await j(o) : null;
|
|
426
|
+
if (!o || !s || s.kind !== t.inviteKind || o.revoked_at) throw Error("invite_invalid");
|
|
427
|
+
let c = await this.getGroup(o.group_id);
|
|
428
|
+
if (!c) throw Error("group_not_found");
|
|
429
|
+
if (c.archived_at) throw Error("group_archived");
|
|
430
|
+
if (!o.consumed_at && new Date(o.expires_at) <= new Date(n)) throw Error("invite_expired");
|
|
431
|
+
if (p(t.publicKey) !== t.fingerprint) throw Error("fingerprint_mismatch");
|
|
432
|
+
let l = e(s);
|
|
433
|
+
if (l !== t.identityId) throw Error("invite_identity_conflict");
|
|
434
|
+
let u = o.bound_device_id === t.deviceId && o.bound_public_key === t.publicKey && o.bound_fingerprint === t.fingerprint;
|
|
435
|
+
if (o.consumed_at && !u) throw Error("invite_already_bound");
|
|
436
|
+
if (o.consumed_at && o.recipient_actor_id !== l) throw Error("invite_identity_conflict");
|
|
437
|
+
let d = await q(this.db.prepare(`SELECT ${E}
|
|
438
|
+
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId));
|
|
439
|
+
if (d && (d.public_key !== t.publicKey || d.fingerprint !== t.fingerprint || d.identity_id !== null && d.identity_id !== l)) throw Error("invite_identity_conflict");
|
|
440
|
+
let f = 0, h = C(12);
|
|
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:${
|
|
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(
|
|
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(
|
|
443
|
+
f = 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:${o.invite_id}`, n, t.deviceId, t.publicKey, t.fingerprint, l, r, i, a, t.token, n, t.inviteKind, o.reviewed_intent_json, o.reviewed_preview_digest, l, l, t.deviceId, t.publicKey, t.fingerprint, l),
|
|
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(n, a, t.token, t.deviceId, t.publicKey, t.fingerprint, l),
|
|
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, t.token, n),
|
|
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(n, a, t.token, t.deviceId)
|
|
448
448
|
]))[0]);
|
|
449
449
|
}
|
|
450
|
-
let g = await this.getGroup(
|
|
450
|
+
let g = await this.getGroup(o.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 !==
|
|
456
|
-
let v = await this.getInviteByTokenForInspection(
|
|
457
|
-
if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(
|
|
454
|
+
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId));
|
|
455
|
+
if (_ && (_.public_key !== t.publicKey || _.fingerprint !== t.fingerprint || _.identity_id !== null && _.identity_id !== l)) throw Error("invite_identity_conflict");
|
|
456
|
+
let v = await this.getInviteByTokenForInspection(t.token);
|
|
457
|
+
if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(n)) throw Error("invite_invalid");
|
|
458
458
|
let y = await j(v);
|
|
459
|
-
if (!y || y.kind !==
|
|
460
|
-
if (
|
|
461
|
-
if (v.bound_device_id !==
|
|
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(
|
|
464
|
-
let b = await this.getEnrollment(v.group_id,
|
|
459
|
+
if (!y || y.kind !== t.inviteKind) throw Error("invite_invalid");
|
|
460
|
+
if (e(y) !== l) throw Error("invite_identity_conflict");
|
|
461
|
+
if (v.bound_device_id !== t.deviceId || v.bound_public_key !== t.publicKey || v.bound_fingerprint !== t.fingerprint) throw Error("invite_already_bound");
|
|
462
|
+
if (v.recipient_actor_id !== l) 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(l, v.group_id, t.deviceId, t.publicKey, t.fingerprint).run();
|
|
464
|
+
let b = await this.getEnrollment(v.group_id, t.deviceId);
|
|
465
465
|
if (!b) throw Error("invite_acceptance_incomplete");
|
|
466
|
-
if (b.public_key !==
|
|
466
|
+
if (b.public_key !== t.publicKey || b.fingerprint !== t.fingerprint || b.identity_id !== l) throw Error("invite_identity_conflict");
|
|
467
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(
|
|
468
|
+
if (y.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(n)) {
|
|
469
469
|
if (!this.db.batch) throw Error("D1 batch support is required for atomic bootstrap grant recovery.");
|
|
470
|
-
let
|
|
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(
|
|
472
|
-
let r = await this.getInviteByTokenForInspection(
|
|
470
|
+
let e = 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(e, v.invite_id, t.deviceId, l, n), 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(n, v.invite_id, t.deviceId)]);
|
|
472
|
+
let r = await this.getInviteByTokenForInspection(t.token);
|
|
473
473
|
if (!r) throw Error("invite_invalid");
|
|
474
474
|
x = r;
|
|
475
475
|
}
|
|
476
476
|
let S = x.bootstrap_grant_id ? await this.getBootstrapGrant(x.bootstrap_grant_id) : null;
|
|
477
477
|
return {
|
|
478
|
-
status:
|
|
478
|
+
status: f === 1 ? "accepted" : "existing",
|
|
479
479
|
invite: x,
|
|
480
480
|
reviewed_intent: y.reviewed_intent,
|
|
481
481
|
bootstrap_grant: S
|
|
@@ -483,42 +483,42 @@ 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 = m(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 i = await this.getGroup(r.group_id);
|
|
489
|
+
if (!i) throw Error("group_not_found");
|
|
490
|
+
if (i.archived_at) throw Error("group_archived");
|
|
491
491
|
if (r.operation_id !== e.operationId) throw Error("invite_invalid");
|
|
492
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 a = r.bound_device_id === e.deviceId && r.bound_public_key === e.publicKey && r.bound_fingerprint === e.fingerprint;
|
|
495
|
+
if (r.consumed_at && !a) throw Error("invite_already_bound");
|
|
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 o = 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 (o && (o.public_key !== e.publicKey || o.fingerprint !== e.fingerprint || o.identity_id != null && o.identity_id !== e.recipientActorId)) throw Error("invite_identity_conflict");
|
|
500
|
+
let s = C(12), c = W((await this.db.batch([
|
|
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(s, 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, l = await this.getGroup(r.group_id);
|
|
506
|
+
if (!l) throw Error("group_not_found");
|
|
507
|
+
if (l.archived_at) throw Error("group_archived");
|
|
508
|
+
let u = await this.getInviteByTokenForInspection(e.token);
|
|
509
|
+
if (!u) throw Error("invite_invalid");
|
|
510
|
+
if (u.bound_device_id !== e.deviceId || u.bound_public_key !== e.publicKey || u.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
|
|
511
|
+
if (u.recipient_actor_id !== e.recipientActorId || u.recipient_display_name !== e.recipientDisplayName || u.recipient_device_display_name !== e.deviceDisplayName) throw Error("invite_identity_conflict");
|
|
512
|
+
c || await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL AND enabled = 1\n AND public_key = ? AND fingerprint = ?").bind(e.recipientActorId, u.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
|
|
513
|
+
let d = await this.getEnrollment(u.group_id, e.deviceId);
|
|
514
|
+
if (!d) throw Error("invite_acceptance_incomplete");
|
|
515
|
+
if (d.identity_id !== e.recipientActorId) throw Error("invite_identity_conflict");
|
|
516
|
+
let f = u.inviter_device_id ? await this.getEnrollment(u.group_id, u.inviter_device_id) : null, h = u.bootstrap_grant_id ? await this.getBootstrapGrant(u.bootstrap_grant_id) : null;
|
|
517
517
|
return {
|
|
518
|
-
status:
|
|
519
|
-
invite:
|
|
520
|
-
enrollment:
|
|
521
|
-
seed_enrollment:
|
|
518
|
+
status: c ? "accepted" : "existing",
|
|
519
|
+
invite: u,
|
|
520
|
+
enrollment: d,
|
|
521
|
+
seed_enrollment: f,
|
|
522
522
|
bootstrap_grant: h
|
|
523
523
|
};
|
|
524
524
|
}
|
|
@@ -651,71 +651,71 @@ 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
|
|
658
|
-
if (!
|
|
659
|
-
if (
|
|
660
|
-
let
|
|
661
|
-
if (
|
|
662
|
-
let
|
|
654
|
+
async grantScopeMembership(e) {
|
|
655
|
+
let t = n(e.effectId), i = o(e), a = await B(this.db, t);
|
|
656
|
+
if (a) return r(a, "grant", i), c(a);
|
|
657
|
+
let l = k(e.scopeId), u = k(e.deviceId), d = l ? await this.getScope(l) : null;
|
|
658
|
+
if (!d) throw new s("scope_not_found");
|
|
659
|
+
if (d.status !== "active") throw new s("scope_inactive");
|
|
660
|
+
let f = l && u ? await this.getScopeMembership(l, u) : null, p = L(e, d, f);
|
|
661
|
+
if (p.groupId && !await this.getEnrollment(p.groupId, p.deviceId)) throw new s("device_not_enrolled");
|
|
662
|
+
let m = 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(
|
|
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(p.scopeId, p.deviceId, p.role, p.membershipEpoch, p.coordinatorId, p.groupId, p.manifestIssuerDeviceId, p.manifestHash, p.signedManifestJson, m, t),
|
|
665
665
|
V(this.db, {
|
|
666
|
-
effectId:
|
|
666
|
+
effectId: t,
|
|
667
667
|
requestJson: i,
|
|
668
|
-
scopeId:
|
|
669
|
-
deviceId:
|
|
670
|
-
createdAt:
|
|
668
|
+
scopeId: p.scopeId,
|
|
669
|
+
deviceId: p.deviceId,
|
|
670
|
+
createdAt: m
|
|
671
671
|
}),
|
|
672
672
|
z(this.db, {
|
|
673
|
-
effectId:
|
|
673
|
+
effectId: t,
|
|
674
674
|
requestJson: i,
|
|
675
675
|
action: "grant",
|
|
676
|
-
previous:
|
|
677
|
-
scopeId:
|
|
678
|
-
deviceId:
|
|
676
|
+
previous: f,
|
|
677
|
+
scopeId: p.scopeId,
|
|
678
|
+
deviceId: p.deviceId,
|
|
679
679
|
status: "active",
|
|
680
|
-
membershipEpoch:
|
|
681
|
-
updatedAt:
|
|
682
|
-
actorType:
|
|
683
|
-
actorId:
|
|
684
|
-
createdAt:
|
|
680
|
+
membershipEpoch: p.membershipEpoch,
|
|
681
|
+
updatedAt: m,
|
|
682
|
+
actorType: p.actorType,
|
|
683
|
+
actorId: p.actorId,
|
|
684
|
+
createdAt: m
|
|
685
685
|
})
|
|
686
686
|
]);
|
|
687
|
-
let h = await B(this.db,
|
|
687
|
+
let h = await B(this.db, t);
|
|
688
688
|
if (!h) throw Error("scope membership grant was not applied.");
|
|
689
|
-
return
|
|
690
|
-
}
|
|
691
|
-
async revokeScopeMembership(
|
|
692
|
-
let
|
|
693
|
-
if (!
|
|
694
|
-
let
|
|
695
|
-
if (
|
|
696
|
-
let
|
|
697
|
-
if (
|
|
698
|
-
let
|
|
699
|
-
if (
|
|
700
|
-
let
|
|
701
|
-
effectId:
|
|
702
|
-
requestJson:
|
|
703
|
-
scopeId:
|
|
704
|
-
deviceId:
|
|
705
|
-
createdAt:
|
|
689
|
+
return r(h, "grant", i), c(h);
|
|
690
|
+
}
|
|
691
|
+
async revokeScopeMembership(e) {
|
|
692
|
+
let t = k(e.scopeId), a = k(e.deviceId);
|
|
693
|
+
if (!t || !a) throw Error("scopeId and deviceId are required.");
|
|
694
|
+
let o = n(e.effectId), c = i(e), l = await B(this.db, o);
|
|
695
|
+
if (l) return r(l, "revoke", c), l.outcome_applied === 1;
|
|
696
|
+
let u = e.membershipEpoch == null ? null : M(e.membershipEpoch), d = k(e.groupId), f = d ? await this.getScope(t) : null;
|
|
697
|
+
if (d && d !== f?.group_id) throw new s("scope_group_mismatch");
|
|
698
|
+
let p = await this.getScopeMembership(t, a);
|
|
699
|
+
if (u != null && p && u <= p.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
|
|
700
|
+
let m = b(), h = u ?? (p?.membership_epoch ?? -1) + 1, g = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(u, u, k(e.manifestHash), k(e.signedManifestJson), m, t, a, p?.membership_epoch ?? -1, p?.status ?? "", o), _ = H(this.db, {
|
|
701
|
+
effectId: o,
|
|
702
|
+
requestJson: c,
|
|
703
|
+
scopeId: t,
|
|
704
|
+
deviceId: a,
|
|
705
|
+
createdAt: m
|
|
706
706
|
}), v = z(this.db, {
|
|
707
|
-
effectId:
|
|
708
|
-
requestJson:
|
|
707
|
+
effectId: o,
|
|
708
|
+
requestJson: c,
|
|
709
709
|
action: "revoke",
|
|
710
|
-
previous:
|
|
711
|
-
scopeId:
|
|
712
|
-
deviceId:
|
|
710
|
+
previous: p,
|
|
711
|
+
scopeId: t,
|
|
712
|
+
deviceId: a,
|
|
713
713
|
status: "revoked",
|
|
714
714
|
membershipEpoch: h,
|
|
715
|
-
updatedAt:
|
|
716
|
-
actorType: k(
|
|
717
|
-
actorId: k(
|
|
718
|
-
createdAt:
|
|
715
|
+
updatedAt: m,
|
|
716
|
+
actorType: k(e.actorType),
|
|
717
|
+
actorId: k(e.actorId),
|
|
718
|
+
createdAt: m
|
|
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 n = await this.getScopeMembership(t, a);
|
|
728
|
+
if (p && (!n || n.membership_epoch !== p.membership_epoch || n.status !== p.status)) return !1;
|
|
729
729
|
throw e;
|
|
730
730
|
}
|
|
731
|
-
let y = await B(this.db,
|
|
731
|
+
let y = await B(this.db, o);
|
|
732
732
|
if (!y) throw Error("scope membership revoke receipt was not persisted.");
|
|
733
|
-
return
|
|
733
|
+
return r(y, "revoke", c), y.outcome_applied === 1;
|
|
734
734
|
}
|
|
735
735
|
async listScopeMemberships(e, t = !1) {
|
|
736
736
|
let n = k(e);
|
|
@@ -3,6 +3,8 @@ export interface ProjectInviteSummary {
|
|
|
3
3
|
existing_memory_count: number;
|
|
4
4
|
}
|
|
5
5
|
export declare function normalizeIdentityDisplayName(value: string, field: string): string;
|
|
6
|
+
export declare function isHumanPresentationName(value: unknown): boolean;
|
|
7
|
+
export declare function normalizeHumanPresentationName(value: string, field: string): string;
|
|
6
8
|
export declare function normalizeDeviceNameHint(value: string | null | undefined): string | null;
|
|
7
9
|
export declare function friendlyDeviceName(input: {
|
|
8
10
|
explicitName?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-invite-identity.d.ts","sourceRoot":"","sources":["../src/project-invite-identity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project-invite-identity.d.ts","sourceRoot":"","sources":["../src/project-invite-identity.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUjF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAe/D;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAInF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIvF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACzC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GAAG,MAAM,CAmBT;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,EAAE,CAoBtF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PromptTransportProtocolRange {
|
|
2
|
+
minSupportedProtocolVersion: number;
|
|
3
|
+
protocolVersion: number;
|
|
4
|
+
}
|
|
5
|
+
/** Current prompt-transport protocol range implemented by this release. */
|
|
6
|
+
export declare const PROMPT_TRANSPORT_PROTOCOL_RANGE: {
|
|
7
|
+
readonly minSupportedProtocolVersion: 1;
|
|
8
|
+
readonly protocolVersion: 1;
|
|
9
|
+
};
|
|
10
|
+
export type PromptTransportDisposition = "fallback" | "local_fallback" | "terminal";
|
|
11
|
+
export type PromptTransportFailure = {
|
|
12
|
+
kind: "profile_absent" | "profile_malformed" | "protocol_range_mismatch" | "network_unavailable" | "network_timeout" | "network_reset" | "viewer_restart" | "malformed_response";
|
|
13
|
+
} | {
|
|
14
|
+
kind: "database_mismatch" | "runtime_identity_mismatch";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "invalid_request";
|
|
17
|
+
compatibleProfile: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "policy_failure" | "authorization_failure";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "viewer_contract_unsupported";
|
|
22
|
+
compatibleProfile: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Normalize a current/minimum pair into a closed supported range.
|
|
26
|
+
*
|
|
27
|
+
* A missing minimum is interpreted as an older single-version profile. Any
|
|
28
|
+
* explicitly malformed minimum remains invalid instead of being silently
|
|
29
|
+
* widened.
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizePromptTransportProtocolRange(protocolVersion: unknown, minSupportedProtocolVersion?: unknown): PromptTransportProtocolRange | null;
|
|
32
|
+
/** Return true when two closed protocol-version ranges overlap. */
|
|
33
|
+
export declare function arePromptTransportProtocolRangesCompatible(left: PromptTransportProtocolRange, right: PromptTransportProtocolRange): boolean;
|
|
34
|
+
/** Classify whether a prompt transport failure may use local compatibility fallback. */
|
|
35
|
+
export declare function classifyPromptTransportFailure(failure: PromptTransportFailure): PromptTransportDisposition;
|
|
36
|
+
//# sourceMappingURL=prompt-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-transport.d.ts","sourceRoot":"","sources":["../src/prompt-transport.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC5C,2BAA2B,EAAE,MAAM,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC;CACxB;AAED,2EAA2E;AAC3E,eAAO,MAAM,+BAA+B;;;CAGK,CAAC;AAElD,MAAM,MAAM,0BAA0B,GAAG,UAAU,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEpF,MAAM,MAAM,sBAAsB,GAC/B;IACA,IAAI,EACD,gBAAgB,GAChB,mBAAmB,GACnB,yBAAyB,GACzB,qBAAqB,GACrB,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,mBAAmB,GAAG,2BAA2B,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,gBAAgB,GAAG,uBAAuB,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,6BAA6B,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC;AAMvE;;;;;;GAMG;AACH,wBAAgB,qCAAqC,CACpD,eAAe,EAAE,OAAO,EACxB,2BAA2B,CAAC,EAAE,OAAO,GACnC,4BAA4B,GAAG,IAAI,CASrC;AAED,mEAAmE;AACnE,wBAAgB,0CAA0C,CACzD,IAAI,EAAE,4BAA4B,EAClC,KAAK,EAAE,4BAA4B,GACjC,OAAO,CAKT;AAED,wFAAwF;AACxF,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,sBAAsB,GAC7B,0BAA0B,CAe5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-event-flush.d.ts","sourceRoot":"","sources":["../src/raw-event-flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyD9C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,cAAc,CA2FrF;AA0CD,MAAM,WAAW,qBAAqB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"raw-event-flush.d.ts","sourceRoot":"","sources":["../src/raw-event-flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyD9C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,cAAc,CA2FrF;AA0CD,MAAM,WAAW,qBAAqB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CACnC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,qBAAqB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CA+IpD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Database } from "./db.js";
|
|
2
|
+
export interface RawEventIngestStore {
|
|
3
|
+
db: Database;
|
|
4
|
+
}
|
|
5
|
+
export interface RawEventIngestSession {
|
|
6
|
+
source: string;
|
|
7
|
+
streamId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface RawEventIngestResult {
|
|
10
|
+
inserted: number;
|
|
11
|
+
skipped: number;
|
|
12
|
+
received: number;
|
|
13
|
+
sessions: RawEventIngestSession[];
|
|
14
|
+
}
|
|
15
|
+
export declare class RawEventIngestValidationError extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
export declare function ingestRawEvents(store: RawEventIngestStore, request: object): RawEventIngestResult;
|
|
19
|
+
//# sourceMappingURL=raw-event-ingest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-event-ingest.d.ts","sourceRoot":"","sources":["../src/raw-event-ingest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAcxC,MAAM,WAAW,mBAAmB;IACnC,EAAE,EAAE,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,qBAAqB,EAAE,CAAC;CAClC;AAuBD,qBAAa,6BAA8B,SAAQ,KAAK;gBAC3C,OAAO,EAAE,MAAM;CAI3B;AA0VD,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAoCjG"}
|
|
@@ -21,12 +21,14 @@ export declare class RawEventSweeper {
|
|
|
21
21
|
private store;
|
|
22
22
|
private ingestOpts;
|
|
23
23
|
private active;
|
|
24
|
+
private stopping;
|
|
24
25
|
private running;
|
|
25
26
|
private currentTick;
|
|
26
27
|
private wakeHandle;
|
|
27
28
|
private loopHandle;
|
|
28
29
|
private autoFlushTimers;
|
|
29
|
-
private
|
|
30
|
+
private sessionFlushPromises;
|
|
31
|
+
private sessionBoundaryWaiters;
|
|
30
32
|
private autoFlushPending;
|
|
31
33
|
private autoFlushPromises;
|
|
32
34
|
private authBackoffUntil;
|
|
@@ -77,6 +79,9 @@ export declare class RawEventSweeper {
|
|
|
77
79
|
* Mirrors Python's RawEventAutoFlusher.note_activity() behavior.
|
|
78
80
|
*/
|
|
79
81
|
nudge(opencodeSessionId: string, source?: string): void;
|
|
82
|
+
/** Flush one session immediately through the event visible at this boundary. */
|
|
83
|
+
flushBoundary(opencodeSessionId: string, source?: string): Promise<void>;
|
|
84
|
+
private acquireSessionFlush;
|
|
80
85
|
private trackAutoFlush;
|
|
81
86
|
private scheduleAutoFlush;
|
|
82
87
|
private flushNow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-event-sweeper.d.ts","sourceRoot":"","sources":["../src/raw-event-sweeper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B9C,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,eAAe,CAAoD;IAC3E,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"raw-event-sweeper.d.ts","sourceRoot":"","sources":["../src/raw-event-sweeper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B9C,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,eAAe,CAAoD;IAC3E,OAAO,CAAC,oBAAoB,CAAoC;IAChE,OAAO,CAAC,sBAAsB,CAA6B;IAC3D,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,eAAe,CAAS;gBAEpB,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa;IASzD,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAYvB;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,iBAAiB,IAAI;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAU5D;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;IAQb;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3B;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAI3B;;;OAGG;IACH,KAAK,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,IAAI;IA2B3D,gFAAgF;IAC1E,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAqBpE,mBAAmB;IAwCjC,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,iBAAiB;YAsBX,QAAQ;IA6DtB,4DAA4D;IAC5D,OAAO,CAAC,YAAY;IAYpB,iDAAiD;YACnC,OAAO;IAgBrB,OAAO,CAAC,IAAI;IAmBZ;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAkG3B"}
|
|
@@ -11,6 +11,15 @@ import type { Database } from "./db.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function ensureVectorSchema(db: Database): void;
|
|
13
13
|
export declare function bootstrapSchema(db: Database): void;
|
|
14
|
+
/** Add sticky direct-peer signature state without requiring a schema-version bump. */
|
|
15
|
+
export declare function ensureSyncPeerDirectSignatureVersionColumn(db: Database): void;
|
|
16
|
+
/**
|
|
17
|
+
* Keep signature downgrade protection outside deletable peer trust rows.
|
|
18
|
+
*
|
|
19
|
+
* The copy is advancing-only so this repair can run on every open, including
|
|
20
|
+
* databases whose compatibility marker was written before this table existed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureSyncPeerSignatureStateSchema(db: Database): void;
|
|
14
23
|
/** Add the local-only retrieval ledger to an already initialized database. */
|
|
15
24
|
export declare function ensureRetrievalLedgerSchema(db: Database): void;
|
|
16
25
|
/**
|