@codemem/core 0.39.0 → 0.40.0-alpha.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/api-types.d.ts +35 -1
- package/dist/api-types.d.ts.map +1 -1
- package/dist/better-sqlite-coordinator-store.d.ts +6 -2
- package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
- package/dist/coordinator-actions.d.ts +35 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-hZ1RVJUN.js → coordinator-api-Btb6CEhw.js} +1204 -497
- package/dist/coordinator-api-Btb6CEhw.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/coordinator-invites.d.ts +13 -1
- package/dist/coordinator-invites.d.ts.map +1 -1
- package/dist/coordinator-membership-effects.d.ts +31 -0
- package/dist/coordinator-membership-effects.d.ts.map +1 -0
- package/dist/coordinator-store-contract.d.ts +127 -1
- package/dist/coordinator-store-contract.d.ts.map +1 -1
- package/dist/coordinator-store-test-harness.d.ts +3 -0
- package/dist/coordinator-store-test-harness.d.ts.map +1 -1
- package/dist/coordinator-store.d.ts +1 -1
- package/dist/coordinator-store.d.ts.map +1 -1
- package/dist/d1-coordinator-store.d.ts +6 -2
- package/dist/d1-coordinator-store.d.ts.map +1 -1
- package/dist/db.d.ts +1 -18
- package/dist/db.d.ts.map +1 -1
- package/dist/extraction-benchmark-scoring.d.ts +99 -0
- package/dist/extraction-benchmark-scoring.d.ts.map +1 -0
- package/dist/extraction-benchmarks.d.ts +29 -0
- package/dist/extraction-benchmarks.d.ts.map +1 -1
- package/dist/extraction-eval.d.ts +5 -0
- package/dist/extraction-eval.d.ts.map +1 -1
- package/dist/extraction-model-pricing.d.ts +21 -0
- package/dist/extraction-model-pricing.d.ts.map +1 -0
- package/dist/extraction-replay.d.ts +23 -2
- package/dist/extraction-replay.d.ts.map +1 -1
- package/dist/extraction-tier-routing.d.ts.map +1 -1
- package/dist/index.d.ts +51 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15017 -9210
- package/dist/index.js.map +1 -1
- package/dist/ingest-xml-parser.d.ts +17 -0
- package/dist/ingest-xml-parser.d.ts.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +495 -220
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/legacy-recipient-policy-projection.d.ts +122 -0
- package/dist/legacy-recipient-policy-projection.d.ts.map +1 -0
- package/dist/observer-client.d.ts +15 -6
- package/dist/observer-client.d.ts.map +1 -1
- package/dist/observer-config.d.ts +2 -0
- package/dist/observer-config.d.ts.map +1 -1
- package/dist/project-invite-acceptance.d.ts +10 -0
- package/dist/project-invite-acceptance.d.ts.map +1 -0
- package/dist/project-invite-identity.d.ts +14 -0
- package/dist/project-invite-identity.d.ts.map +1 -0
- package/dist/project-scope-settings.d.ts.map +1 -1
- package/dist/recipient-policy-contract.d.ts +153 -0
- package/dist/recipient-policy-contract.d.ts.map +1 -0
- package/dist/recipient-policy-edges.d.ts +85 -0
- package/dist/recipient-policy-edges.d.ts.map +1 -0
- package/dist/recipient-policy-intent.d.ts +12 -0
- package/dist/recipient-policy-intent.d.ts.map +1 -0
- package/dist/recipient-policy-migration.d.ts +22 -0
- package/dist/recipient-policy-migration.d.ts.map +1 -0
- package/dist/recipient-policy-onboarding.d.ts +111 -0
- package/dist/recipient-policy-onboarding.d.ts.map +1 -0
- package/dist/recipient-policy-reconciler.d.ts +69 -0
- package/dist/recipient-policy-reconciler.d.ts.map +1 -0
- package/dist/recipient-policy-reconciliation.d.ts +199 -0
- package/dist/recipient-policy-reconciliation.d.ts.map +1 -0
- package/dist/recipient-policy-review.d.ts +47 -0
- package/dist/recipient-policy-review.d.ts.map +1 -0
- package/dist/recipient-reviewed-intent.d.ts +63 -0
- package/dist/recipient-reviewed-intent.d.ts.map +1 -0
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +5676 -1920
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-membership-cache.d.ts +1 -1
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/share-operation-lifecycle.d.ts +44 -0
- package/dist/share-operation-lifecycle.d.ts.map +1 -0
- package/dist/share-operation.d.ts +85 -0
- package/dist/share-operation.d.ts.map +1 -0
- package/dist/share-provisioning.d.ts +57 -0
- package/dist/share-provisioning.d.ts.map +1 -0
- package/dist/store.d.ts +6 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-bootstrap.d.ts +3 -2
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-capability.d.ts +7 -0
- package/dist/sync-capability.d.ts.map +1 -1
- package/dist/sync-daemon.d.ts +14 -1
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +1 -0
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts +24 -0
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-scope-protocol.d.ts.map +1 -1
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/coordinator-api-hZ1RVJUN.js.map +0 -1
|
@@ -1,13 +1,305 @@
|
|
|
1
1
|
import { createHash as e } from "node:crypto";
|
|
2
|
+
//#region src/coordinator-membership-effects.ts
|
|
3
|
+
var t = "scope_membership_effect_conflict", n = {
|
|
4
|
+
device_not_enrolled: "device must be enrolled and enabled in the scope group.",
|
|
5
|
+
scope_group_mismatch: "membership groupId must match the scope groupId.",
|
|
6
|
+
scope_inactive: "scope is not active.",
|
|
7
|
+
scope_not_found: "scopeId must reference an existing scope."
|
|
8
|
+
}, r = class extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(e) {
|
|
11
|
+
super(n[e]), this.name = "CoordinatorMembershipError", this.code = e;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function i(e) {
|
|
15
|
+
return e?.trim() || null;
|
|
16
|
+
}
|
|
17
|
+
function a(e) {
|
|
18
|
+
let t = i(e);
|
|
19
|
+
if (!t) throw Error("effectId is required.");
|
|
20
|
+
if (t.length > 512 || /[\p{Cc}\p{Cf}]/u.test(t)) throw Error("effectId is invalid.");
|
|
21
|
+
return t;
|
|
22
|
+
}
|
|
23
|
+
function o(e) {
|
|
24
|
+
return JSON.stringify({
|
|
25
|
+
scopeId: i(e.scopeId),
|
|
26
|
+
deviceId: i(e.deviceId),
|
|
27
|
+
role: i(e.role),
|
|
28
|
+
membershipEpoch: e.membershipEpoch ?? null,
|
|
29
|
+
coordinatorId: i(e.coordinatorId),
|
|
30
|
+
groupId: i(e.groupId),
|
|
31
|
+
manifestIssuerDeviceId: i(e.manifestIssuerDeviceId),
|
|
32
|
+
manifestHash: i(e.manifestHash),
|
|
33
|
+
signedManifestJson: i(e.signedManifestJson),
|
|
34
|
+
actorType: i(e.actorType),
|
|
35
|
+
actorId: i(e.actorId)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function s(e) {
|
|
39
|
+
return JSON.stringify({
|
|
40
|
+
scopeId: i(e.scopeId),
|
|
41
|
+
deviceId: i(e.deviceId),
|
|
42
|
+
groupId: i(e.groupId),
|
|
43
|
+
membershipEpoch: e.membershipEpoch ?? null,
|
|
44
|
+
manifestHash: i(e.manifestHash),
|
|
45
|
+
signedManifestJson: i(e.signedManifestJson),
|
|
46
|
+
actorType: i(e.actorType),
|
|
47
|
+
actorId: i(e.actorId)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function c(e, n, r) {
|
|
51
|
+
if (e.action !== n || e.request_json !== r) throw Error(t);
|
|
52
|
+
}
|
|
53
|
+
function l(e) {
|
|
54
|
+
if (e.action !== "grant" || e.outcome_applied !== 1 || e.role == null || e.status == null || e.membership_epoch == null || e.updated_at == null) throw Error("scope_membership_effect_receipt_invalid");
|
|
55
|
+
return {
|
|
56
|
+
scope_id: e.scope_id,
|
|
57
|
+
device_id: e.device_id,
|
|
58
|
+
role: e.role,
|
|
59
|
+
status: e.status,
|
|
60
|
+
membership_epoch: e.membership_epoch,
|
|
61
|
+
coordinator_id: e.coordinator_id,
|
|
62
|
+
group_id: e.group_id,
|
|
63
|
+
manifest_issuer_device_id: e.manifest_issuer_device_id,
|
|
64
|
+
manifest_hash: e.manifest_hash,
|
|
65
|
+
signed_manifest_json: e.signed_manifest_json,
|
|
66
|
+
updated_at: e.updated_at
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
2
70
|
//#region src/coordinator-store-contract.ts
|
|
3
|
-
function
|
|
71
|
+
function u(e) {
|
|
4
72
|
let t = e.trim(), n = new Date(t);
|
|
5
73
|
if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
|
|
6
74
|
return n.toISOString();
|
|
7
75
|
}
|
|
76
|
+
var d = /^identity:[A-Za-z0-9_-]{18,24}$/u;
|
|
77
|
+
function f(e) {
|
|
78
|
+
return typeof e == "string" && e === e.trim() && d.test(e);
|
|
79
|
+
}
|
|
80
|
+
function p(e) {
|
|
81
|
+
return String(e.kind === "team_member" ? e.assigned_identity_id ?? "" : e.target_identity_id ?? "").trim();
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/project-invite-identity.ts
|
|
85
|
+
var m = 120;
|
|
86
|
+
function h(e, t) {
|
|
87
|
+
if ([...e].some((e) => /[\p{Cc}\p{Cf}]/u.test(e))) throw Error(`${t}_invalid`);
|
|
88
|
+
let n = e.replace(/\s+/gu, " ").trim();
|
|
89
|
+
if (!n) throw Error(`${t}_required`);
|
|
90
|
+
if ([...n].length > m) throw Error(`${t}_too_long`);
|
|
91
|
+
return n;
|
|
92
|
+
}
|
|
93
|
+
function g(e) {
|
|
94
|
+
let t = String(e ?? "").replace(/\.local$/iu, "");
|
|
95
|
+
return t.trim() ? h(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
|
|
96
|
+
}
|
|
97
|
+
function _(e) {
|
|
98
|
+
for (let t of [
|
|
99
|
+
e.explicitName,
|
|
100
|
+
e.osName,
|
|
101
|
+
e.coordinatorName
|
|
102
|
+
]) {
|
|
103
|
+
let e = g(t);
|
|
104
|
+
if (e) return e;
|
|
105
|
+
}
|
|
106
|
+
let t = String(e.fallbackSeed ?? "").replace(/[^a-z0-9]/giu, "").slice(0, 6);
|
|
107
|
+
return t ? `Codemem device ${t}` : "Codemem device";
|
|
108
|
+
}
|
|
109
|
+
function v(e) {
|
|
110
|
+
if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("project_summaries_invalid");
|
|
111
|
+
return e.map((e) => {
|
|
112
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_summaries_invalid");
|
|
113
|
+
let t = e;
|
|
114
|
+
if (!Number.isSafeInteger(t.existing_memory_count) || Number(t.existing_memory_count) < 0) throw Error("project_summaries_invalid");
|
|
115
|
+
return {
|
|
116
|
+
display_name: h(String(t.display_name ?? ""), "project_name"),
|
|
117
|
+
existing_memory_count: Number(t.existing_memory_count)
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/recipient-reviewed-intent.ts
|
|
123
|
+
var y = 1, b = class extends Error {
|
|
124
|
+
code;
|
|
125
|
+
constructor(e) {
|
|
126
|
+
super(e), this.name = "RecipientReviewedIntentError", this.code = e;
|
|
127
|
+
}
|
|
128
|
+
}, x = /[\p{Cc}\p{Cf}]/u, S = 100, C = 64 * 1024;
|
|
129
|
+
function w() {
|
|
130
|
+
throw new b("recipient_reviewed_intent_invalid");
|
|
131
|
+
}
|
|
132
|
+
function T(e) {
|
|
133
|
+
return (!e || typeof e != "object" || Array.isArray(e)) && w(), e;
|
|
134
|
+
}
|
|
135
|
+
function E(e, t) {
|
|
136
|
+
Object.keys(e).some((e) => !t.includes(e)) && w();
|
|
137
|
+
}
|
|
138
|
+
function D(e, t) {
|
|
139
|
+
return (typeof e != "string" || !e || e !== e.trim() || e.length > t || x.test(e)) && w(), e;
|
|
140
|
+
}
|
|
141
|
+
function O(e) {
|
|
142
|
+
(typeof e != "string" || x.test(e)) && w();
|
|
143
|
+
let t = e.trim().replace(/\s+/gu, " ");
|
|
144
|
+
return (!t || t.length > 256) && w(), t;
|
|
145
|
+
}
|
|
146
|
+
function k(e) {
|
|
147
|
+
typeof e != "string" && w();
|
|
148
|
+
try {
|
|
149
|
+
return h(e, "identity_display_name");
|
|
150
|
+
} catch {
|
|
151
|
+
return w();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function A(e) {
|
|
155
|
+
return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && w(), e;
|
|
156
|
+
}
|
|
157
|
+
function j(e, t) {
|
|
158
|
+
return e < t ? -1 : +(e > t);
|
|
159
|
+
}
|
|
160
|
+
function ee(e) {
|
|
161
|
+
return e.kind === "direct" ? "direct" : `team\u0000${e.teamId}`;
|
|
162
|
+
}
|
|
163
|
+
function te(e) {
|
|
164
|
+
let t = T(e);
|
|
165
|
+
return t.kind === "direct" ? (E(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && w(), E(t, [
|
|
166
|
+
"kind",
|
|
167
|
+
"teamId",
|
|
168
|
+
"displayName"
|
|
169
|
+
]), {
|
|
170
|
+
kind: "team",
|
|
171
|
+
teamId: D(t.teamId, 256),
|
|
172
|
+
displayName: O(t.displayName)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function ne(e) {
|
|
176
|
+
let t = T(e);
|
|
177
|
+
E(t, [
|
|
178
|
+
"canonicalProjectIdentity",
|
|
179
|
+
"displayName",
|
|
180
|
+
"existingMemoryCount",
|
|
181
|
+
"futureMemoriesShared",
|
|
182
|
+
"sources"
|
|
183
|
+
]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && w();
|
|
184
|
+
let n = t.sources.map(te).toSorted((e, t) => j(ee(e), ee(t)));
|
|
185
|
+
return new Set(n.map(ee)).size !== n.length && w(), {
|
|
186
|
+
canonicalProjectIdentity: D(t.canonicalProjectIdentity, 512),
|
|
187
|
+
displayName: O(t.displayName),
|
|
188
|
+
existingMemoryCount: A(t.existingMemoryCount),
|
|
189
|
+
futureMemoriesShared: !0,
|
|
190
|
+
sources: n
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function re(e) {
|
|
194
|
+
let t = T(e);
|
|
195
|
+
return E(t, [
|
|
196
|
+
"canonicalProjectIdentity",
|
|
197
|
+
"displayName",
|
|
198
|
+
"existingMemoryCount"
|
|
199
|
+
]), {
|
|
200
|
+
canonicalProjectIdentity: D(t.canonicalProjectIdentity, 512),
|
|
201
|
+
displayName: O(t.displayName),
|
|
202
|
+
existingMemoryCount: A(t.existingMemoryCount)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function ie(e) {
|
|
206
|
+
(!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > S) && w();
|
|
207
|
+
let t = e.projects.map(ne).toSorted((e, t) => j(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(re).toSorted((e, t) => j(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
|
|
208
|
+
return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && w(), {
|
|
209
|
+
projects: t,
|
|
210
|
+
excludedProjects: n
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function ae(e, t) {
|
|
214
|
+
if (!(e.journey === "team" && t.kind === "team_member" && e.team.teamId === t.policyTeamId || e.journey === "add_device" && t.kind === "add_device" && e.targetIdentity.identityId === t.targetIdentityId)) throw new b("recipient_invite_intent_mismatch");
|
|
215
|
+
}
|
|
216
|
+
function M(e, t) {
|
|
217
|
+
let n = T(e);
|
|
218
|
+
n.version !== 1 && w();
|
|
219
|
+
let r = ie(n), i;
|
|
220
|
+
if (n.journey === "team") {
|
|
221
|
+
E(n, [
|
|
222
|
+
"version",
|
|
223
|
+
"journey",
|
|
224
|
+
"team",
|
|
225
|
+
"projects",
|
|
226
|
+
"excludedProjects"
|
|
227
|
+
]);
|
|
228
|
+
let e = T(n.team);
|
|
229
|
+
E(e, [
|
|
230
|
+
"teamId",
|
|
231
|
+
"displayName",
|
|
232
|
+
"futureProjectsInherit"
|
|
233
|
+
]), e.futureProjectsInherit !== !0 && w(), i = {
|
|
234
|
+
version: 1,
|
|
235
|
+
journey: "team",
|
|
236
|
+
team: {
|
|
237
|
+
teamId: D(e.teamId, 256),
|
|
238
|
+
displayName: O(e.displayName),
|
|
239
|
+
futureProjectsInherit: !0
|
|
240
|
+
},
|
|
241
|
+
...r
|
|
242
|
+
};
|
|
243
|
+
} else if (n.journey === "add_device") {
|
|
244
|
+
E(n, [
|
|
245
|
+
"version",
|
|
246
|
+
"journey",
|
|
247
|
+
"targetIdentity",
|
|
248
|
+
"projects",
|
|
249
|
+
"excludedProjects"
|
|
250
|
+
]);
|
|
251
|
+
let e = T(n.targetIdentity);
|
|
252
|
+
E(e, ["identityId", "displayName"]), i = {
|
|
253
|
+
version: 1,
|
|
254
|
+
journey: "add_device",
|
|
255
|
+
targetIdentity: {
|
|
256
|
+
identityId: D(e.identityId, 256),
|
|
257
|
+
displayName: k(e.displayName)
|
|
258
|
+
},
|
|
259
|
+
...r
|
|
260
|
+
};
|
|
261
|
+
} else w();
|
|
262
|
+
return t && ae(i, t), new TextEncoder().encode(N(i)).byteLength > C && w(), i;
|
|
263
|
+
}
|
|
264
|
+
function N(e) {
|
|
265
|
+
return Array.isArray(e) ? `[${e.map(N).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => j(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${N(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
266
|
+
}
|
|
267
|
+
function oe(e, t) {
|
|
268
|
+
return N(M(e, t));
|
|
269
|
+
}
|
|
270
|
+
async function se(e, t) {
|
|
271
|
+
let n = oe(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
|
|
272
|
+
return Array.from(new Uint8Array(i), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
273
|
+
}
|
|
274
|
+
async function P(e, t) {
|
|
275
|
+
let n = M(e, t.target);
|
|
276
|
+
if (await se(n) !== t.digest) throw new b("recipient_invite_intent_mismatch");
|
|
277
|
+
return n;
|
|
278
|
+
}
|
|
279
|
+
async function ce(e, t) {
|
|
280
|
+
if (!e) throw Error("recipient_invite_review_unavailable");
|
|
281
|
+
let n;
|
|
282
|
+
try {
|
|
283
|
+
n = JSON.parse(e);
|
|
284
|
+
} catch {
|
|
285
|
+
throw Error("recipient_invite_review_unavailable");
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
let r = M(n, t.target);
|
|
289
|
+
if (N(r) !== e) throw Error("recipient_invite_review_unavailable");
|
|
290
|
+
return await P(r, t);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
throw e instanceof b && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/sync-fingerprint.ts
|
|
297
|
+
function F(t) {
|
|
298
|
+
return e("sha256").update(t, "utf-8").digest("hex");
|
|
299
|
+
}
|
|
8
300
|
//#endregion
|
|
9
301
|
//#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/compose.js
|
|
10
|
-
var
|
|
302
|
+
var le = (e, t, n) => (r, i) => {
|
|
11
303
|
let a = -1;
|
|
12
304
|
return o(0);
|
|
13
305
|
async function o(s) {
|
|
@@ -23,40 +315,40 @@ var n = (e, t, n) => (r, i) => {
|
|
|
23
315
|
else r.finalized === !1 && n && (c = await n(r));
|
|
24
316
|
return c && (r.finalized === !1 || l) && (r.res = c), r;
|
|
25
317
|
}
|
|
26
|
-
},
|
|
27
|
-
let { all: n = !1, dot: r = !1 } = t, i = (e instanceof
|
|
28
|
-
return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ?
|
|
318
|
+
}, ue = /* @__PURE__ */ Symbol(), de = async (e, t = /* @__PURE__ */ Object.create(null)) => {
|
|
319
|
+
let { all: n = !1, dot: r = !1 } = t, i = (e instanceof je ? e.raw.headers : e.headers).get("Content-Type");
|
|
320
|
+
return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ? fe(e, {
|
|
29
321
|
all: n,
|
|
30
322
|
dot: r
|
|
31
323
|
}) : {};
|
|
32
324
|
};
|
|
33
|
-
async function
|
|
325
|
+
async function fe(e, t) {
|
|
34
326
|
let n = await e.formData();
|
|
35
|
-
return n ?
|
|
327
|
+
return n ? pe(n, t) : {};
|
|
36
328
|
}
|
|
37
|
-
function
|
|
329
|
+
function pe(e, t) {
|
|
38
330
|
let n = /* @__PURE__ */ Object.create(null);
|
|
39
331
|
return e.forEach((e, r) => {
|
|
40
|
-
t.all || r.endsWith("[]") ?
|
|
332
|
+
t.all || r.endsWith("[]") ? me(n, r, e) : n[r] = e;
|
|
41
333
|
}), t.dot && Object.entries(n).forEach(([e, t]) => {
|
|
42
|
-
e.includes(".") && (
|
|
334
|
+
e.includes(".") && (he(n, e, t), delete n[e]);
|
|
43
335
|
}), n;
|
|
44
336
|
}
|
|
45
|
-
var
|
|
337
|
+
var me = (e, t, n) => {
|
|
46
338
|
e[t] === void 0 ? t.endsWith("[]") ? e[t] = [n] : e[t] = n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
|
|
47
|
-
},
|
|
339
|
+
}, he = (e, t, n) => {
|
|
48
340
|
if (/(?:^|\.)__proto__\./.test(t)) return;
|
|
49
341
|
let r = e, i = t.split(".");
|
|
50
342
|
i.forEach((e, t) => {
|
|
51
343
|
t === i.length - 1 ? r[e] = n : ((!r[e] || typeof r[e] != "object" || Array.isArray(r[e]) || r[e] instanceof File) && (r[e] = /* @__PURE__ */ Object.create(null)), r = r[e]);
|
|
52
344
|
});
|
|
53
|
-
},
|
|
345
|
+
}, ge = (e) => {
|
|
54
346
|
let t = e.split("/");
|
|
55
347
|
return t[0] === "" && t.shift(), t;
|
|
56
|
-
},
|
|
57
|
-
let { groups: t, path: n } =
|
|
58
|
-
return
|
|
59
|
-
},
|
|
348
|
+
}, _e = (e) => {
|
|
349
|
+
let { groups: t, path: n } = ve(e);
|
|
350
|
+
return ye(ge(n), t);
|
|
351
|
+
}, ve = (e) => {
|
|
60
352
|
let t = [];
|
|
61
353
|
return e = e.replace(/\{[^}]+\}/g, (e, n) => {
|
|
62
354
|
let r = `@${n}`;
|
|
@@ -65,7 +357,7 @@ var s = (e, t, n) => {
|
|
|
65
357
|
groups: t,
|
|
66
358
|
path: e
|
|
67
359
|
};
|
|
68
|
-
},
|
|
360
|
+
}, ye = (e, t) => {
|
|
69
361
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
70
362
|
let [r] = t[n];
|
|
71
363
|
for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
|
|
@@ -74,12 +366,12 @@ var s = (e, t, n) => {
|
|
|
74
366
|
}
|
|
75
367
|
}
|
|
76
368
|
return e;
|
|
77
|
-
},
|
|
369
|
+
}, I = {}, be = (e, t) => {
|
|
78
370
|
if (e === "*") return "*";
|
|
79
371
|
let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
80
372
|
if (n) {
|
|
81
373
|
let r = `${e}#${t}`;
|
|
82
|
-
return
|
|
374
|
+
return I[r] || (n[2] ? I[r] = t && t[0] !== ":" && t[0] !== "*" ? [
|
|
83
375
|
r,
|
|
84
376
|
n[1],
|
|
85
377
|
RegExp(`^${n[2]}(?=/${t})`)
|
|
@@ -87,14 +379,14 @@ var s = (e, t, n) => {
|
|
|
87
379
|
e,
|
|
88
380
|
n[1],
|
|
89
381
|
RegExp(`^${n[2]}$`)
|
|
90
|
-
] :
|
|
382
|
+
] : I[r] = [
|
|
91
383
|
e,
|
|
92
384
|
n[1],
|
|
93
385
|
!0
|
|
94
|
-
]),
|
|
386
|
+
]), I[r];
|
|
95
387
|
}
|
|
96
388
|
return null;
|
|
97
|
-
},
|
|
389
|
+
}, L = (e, t) => {
|
|
98
390
|
try {
|
|
99
391
|
return t(e);
|
|
100
392
|
} catch {
|
|
@@ -106,20 +398,20 @@ var s = (e, t, n) => {
|
|
|
106
398
|
}
|
|
107
399
|
});
|
|
108
400
|
}
|
|
109
|
-
},
|
|
401
|
+
}, xe = (e) => L(e, decodeURI), Se = (e) => {
|
|
110
402
|
let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
|
|
111
403
|
for (; r < t.length; r++) {
|
|
112
404
|
let e = t.charCodeAt(r);
|
|
113
405
|
if (e === 37) {
|
|
114
406
|
let e = t.indexOf("?", r), i = t.indexOf("#", r), a = e === -1 ? i === -1 ? void 0 : i : i === -1 ? e : Math.min(e, i), o = t.slice(n, a);
|
|
115
|
-
return
|
|
407
|
+
return xe(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
|
|
116
408
|
} else if (e === 63 || e === 35) break;
|
|
117
409
|
}
|
|
118
410
|
return t.slice(n, r);
|
|
119
|
-
},
|
|
120
|
-
let t =
|
|
411
|
+
}, Ce = (e) => {
|
|
412
|
+
let t = Se(e);
|
|
121
413
|
return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
|
|
122
|
-
},
|
|
414
|
+
}, R = (e, t, ...n) => (n.length && (t = R(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), we = (e) => {
|
|
123
415
|
if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
|
|
124
416
|
let t = e.split("/"), n = [], r = "";
|
|
125
417
|
return t.forEach((e) => {
|
|
@@ -130,7 +422,7 @@ var s = (e, t, n) => {
|
|
|
130
422
|
r += "/" + t, n.push(r);
|
|
131
423
|
} else r += "/" + e;
|
|
132
424
|
}), n.filter((e, t, n) => n.indexOf(e) === t);
|
|
133
|
-
},
|
|
425
|
+
}, Te = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : L(e, ke)) : e, Ee = (e, t, n) => {
|
|
134
426
|
let r;
|
|
135
427
|
if (!n && t && !/[%+]/.test(t)) {
|
|
136
428
|
let n = e.indexOf("?", 8);
|
|
@@ -139,7 +431,7 @@ var s = (e, t, n) => {
|
|
|
139
431
|
let r = e.charCodeAt(n + t.length + 1);
|
|
140
432
|
if (r === 61) {
|
|
141
433
|
let r = n + t.length + 2, i = e.indexOf("&", r);
|
|
142
|
-
return
|
|
434
|
+
return Te(e.slice(r, i === -1 ? void 0 : i));
|
|
143
435
|
} else if (r == 38 || isNaN(r)) return "";
|
|
144
436
|
n = e.indexOf(`&${t}`, n + 1);
|
|
145
437
|
}
|
|
@@ -152,12 +444,12 @@ var s = (e, t, n) => {
|
|
|
152
444
|
let t = e.indexOf("&", a + 1), o = e.indexOf("=", a);
|
|
153
445
|
o > t && t !== -1 && (o = -1);
|
|
154
446
|
let s = e.slice(a + 1, o === -1 ? t === -1 ? void 0 : t : o);
|
|
155
|
-
if (r && (s =
|
|
447
|
+
if (r && (s = Te(s)), a = t, s === "") continue;
|
|
156
448
|
let c;
|
|
157
|
-
o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c =
|
|
449
|
+
o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = Te(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
|
|
158
450
|
}
|
|
159
451
|
return t ? i[t] : i;
|
|
160
|
-
},
|
|
452
|
+
}, De = Ee, Oe = (e, t) => Ee(e, t, !0), ke = decodeURIComponent, Ae = (e) => L(e, ke), je = class {
|
|
161
453
|
raw;
|
|
162
454
|
#e;
|
|
163
455
|
#t;
|
|
@@ -172,13 +464,13 @@ var s = (e, t, n) => {
|
|
|
172
464
|
}
|
|
173
465
|
#n(e) {
|
|
174
466
|
let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
|
|
175
|
-
return n && /\%/.test(n) ?
|
|
467
|
+
return n && /\%/.test(n) ? Ae(n) : n;
|
|
176
468
|
}
|
|
177
469
|
#r() {
|
|
178
470
|
let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
|
|
179
471
|
for (let n of t) {
|
|
180
472
|
let t = this.#i(this.#t[0][this.routeIndex][1][n]);
|
|
181
|
-
t !== void 0 && (e[n] = /\%/.test(t) ?
|
|
473
|
+
t !== void 0 && (e[n] = /\%/.test(t) ? Ae(t) : t);
|
|
182
474
|
}
|
|
183
475
|
return e;
|
|
184
476
|
}
|
|
@@ -186,10 +478,10 @@ var s = (e, t, n) => {
|
|
|
186
478
|
return this.#t[1] ? this.#t[1][e] : e;
|
|
187
479
|
}
|
|
188
480
|
query(e) {
|
|
189
|
-
return
|
|
481
|
+
return De(this.url, e);
|
|
190
482
|
}
|
|
191
483
|
queries(e) {
|
|
192
|
-
return
|
|
484
|
+
return Oe(this.url, e);
|
|
193
485
|
}
|
|
194
486
|
header(e) {
|
|
195
487
|
if (e) return this.raw.headers.get(e) ?? void 0;
|
|
@@ -199,7 +491,7 @@ var s = (e, t, n) => {
|
|
|
199
491
|
}), t;
|
|
200
492
|
}
|
|
201
493
|
async parseBody(e) {
|
|
202
|
-
return
|
|
494
|
+
return de(this, e);
|
|
203
495
|
}
|
|
204
496
|
#a = (e) => {
|
|
205
497
|
let { bodyCache: t, raw: n } = this, r = t[e];
|
|
@@ -237,7 +529,7 @@ var s = (e, t, n) => {
|
|
|
237
529
|
get method() {
|
|
238
530
|
return this.raw.method;
|
|
239
531
|
}
|
|
240
|
-
get [
|
|
532
|
+
get [ue]() {
|
|
241
533
|
return this.#t;
|
|
242
534
|
}
|
|
243
535
|
get matchedRoutes() {
|
|
@@ -246,14 +538,14 @@ var s = (e, t, n) => {
|
|
|
246
538
|
get routePath() {
|
|
247
539
|
return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
|
|
248
540
|
}
|
|
249
|
-
},
|
|
541
|
+
}, Me = {
|
|
250
542
|
Stringify: 1,
|
|
251
543
|
BeforeStream: 2,
|
|
252
544
|
Stream: 3
|
|
253
|
-
},
|
|
545
|
+
}, Ne = (e, t) => {
|
|
254
546
|
let n = new String(e);
|
|
255
547
|
return n.isEscaped = !0, n.callbacks = t, n;
|
|
256
|
-
},
|
|
548
|
+
}, Pe = async (e, t, n, r, i) => {
|
|
257
549
|
typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
|
|
258
550
|
let a = e.callbacks;
|
|
259
551
|
if (!a?.length) return Promise.resolve(e);
|
|
@@ -262,12 +554,12 @@ var s = (e, t, n) => {
|
|
|
262
554
|
phase: t,
|
|
263
555
|
buffer: i,
|
|
264
556
|
context: r
|
|
265
|
-
}))).then((e) => Promise.all(e.filter(Boolean).map((e) =>
|
|
266
|
-
return n ?
|
|
267
|
-
},
|
|
557
|
+
}))).then((e) => Promise.all(e.filter(Boolean).map((e) => Pe(e, t, !1, r, i))).then(() => i[0]));
|
|
558
|
+
return n ? Ne(await o, a) : o;
|
|
559
|
+
}, Fe = "text/plain; charset=UTF-8", Ie = (e, t) => ({
|
|
268
560
|
"Content-Type": e,
|
|
269
561
|
...t
|
|
270
|
-
}),
|
|
562
|
+
}), z = (e, t) => new Response(e, t), Le = class {
|
|
271
563
|
#e;
|
|
272
564
|
#t;
|
|
273
565
|
env = {};
|
|
@@ -287,7 +579,7 @@ var s = (e, t, n) => {
|
|
|
287
579
|
this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
|
|
288
580
|
}
|
|
289
581
|
get req() {
|
|
290
|
-
return this.#t ??= new
|
|
582
|
+
return this.#t ??= new je(this.#e, this.#d, this.#u), this.#t;
|
|
291
583
|
}
|
|
292
584
|
get event() {
|
|
293
585
|
if (this.#i && "respondWith" in this.#i) return this.#i;
|
|
@@ -298,11 +590,11 @@ var s = (e, t, n) => {
|
|
|
298
590
|
throw Error("This context has no ExecutionContext");
|
|
299
591
|
}
|
|
300
592
|
get res() {
|
|
301
|
-
return this.#a ||=
|
|
593
|
+
return this.#a ||= z(null, { headers: this.#l ??= new Headers() });
|
|
302
594
|
}
|
|
303
595
|
set res(e) {
|
|
304
596
|
if (this.#a && e) {
|
|
305
|
-
e =
|
|
597
|
+
e = z(e.body, e);
|
|
306
598
|
for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") if (t === "set-cookie") {
|
|
307
599
|
let t = this.#a.headers.getSetCookie();
|
|
308
600
|
e.headers.delete("set-cookie");
|
|
@@ -318,7 +610,7 @@ var s = (e, t, n) => {
|
|
|
318
610
|
this.#s = e;
|
|
319
611
|
};
|
|
320
612
|
header = (e, t, n) => {
|
|
321
|
-
this.finalized && (this.#a =
|
|
613
|
+
this.finalized && (this.#a = z(this.#a.body, this.#a));
|
|
322
614
|
let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
|
|
323
615
|
t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
|
|
324
616
|
};
|
|
@@ -343,38 +635,38 @@ var s = (e, t, n) => {
|
|
|
343
635
|
r.delete(e);
|
|
344
636
|
for (let n of t) r.append(e, n);
|
|
345
637
|
}
|
|
346
|
-
return
|
|
638
|
+
return z(e, {
|
|
347
639
|
status: typeof t == "number" ? t : t?.status ?? this.#r,
|
|
348
640
|
headers: r
|
|
349
641
|
});
|
|
350
642
|
}
|
|
351
643
|
newResponse = (...e) => this.#f(...e);
|
|
352
644
|
body = (e, t, n) => this.#f(e, t, n);
|
|
353
|
-
text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t,
|
|
354
|
-
json = (e, t, n) => this.#f(JSON.stringify(e), t,
|
|
645
|
+
text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, Ie(Fe, n));
|
|
646
|
+
json = (e, t, n) => this.#f(JSON.stringify(e), t, Ie("application/json", n));
|
|
355
647
|
html = (e, t, n) => {
|
|
356
|
-
let r = (e) => this.#f(e, t,
|
|
357
|
-
return typeof e == "object" ?
|
|
648
|
+
let r = (e) => this.#f(e, t, Ie("text/html; charset=UTF-8", n));
|
|
649
|
+
return typeof e == "object" ? Pe(e, Me.Stringify, !1, {}).then(r) : r(e);
|
|
358
650
|
};
|
|
359
651
|
redirect = (e, t) => {
|
|
360
652
|
let n = String(e);
|
|
361
653
|
return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
|
|
362
654
|
};
|
|
363
|
-
notFound = () => (this.#c ??= () =>
|
|
364
|
-
},
|
|
655
|
+
notFound = () => (this.#c ??= () => z(), this.#c(this));
|
|
656
|
+
}, Re = [
|
|
365
657
|
"get",
|
|
366
658
|
"post",
|
|
367
659
|
"put",
|
|
368
660
|
"delete",
|
|
369
661
|
"options",
|
|
370
662
|
"patch"
|
|
371
|
-
],
|
|
663
|
+
], ze = "Can not add a route since the matcher is already built.", Be = class extends Error {}, Ve = "__COMPOSED_HANDLER", He = (e) => e.text("404 Not Found", 404), Ue = (e, t) => {
|
|
372
664
|
if ("getResponse" in e) {
|
|
373
665
|
let n = e.getResponse();
|
|
374
666
|
return t.newResponse(n.body, n);
|
|
375
667
|
}
|
|
376
668
|
return console.error(e), t.text("Internal Server Error", 500);
|
|
377
|
-
},
|
|
669
|
+
}, We = class e {
|
|
378
670
|
get;
|
|
379
671
|
post;
|
|
380
672
|
put;
|
|
@@ -390,7 +682,7 @@ var s = (e, t, n) => {
|
|
|
390
682
|
#e = "/";
|
|
391
683
|
routes = [];
|
|
392
684
|
constructor(e = {}) {
|
|
393
|
-
[...
|
|
685
|
+
[...Re, "all"].forEach((e) => {
|
|
394
686
|
this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
|
|
395
687
|
this.#r(e, this.#e, t);
|
|
396
688
|
}), this);
|
|
@@ -406,7 +698,7 @@ var s = (e, t, n) => {
|
|
|
406
698
|
this.#r("ALL", this.#e, e);
|
|
407
699
|
}), this);
|
|
408
700
|
let { strict: t, ...n } = e;
|
|
409
|
-
Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ??
|
|
701
|
+
Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Se : Ce;
|
|
410
702
|
}
|
|
411
703
|
#t() {
|
|
412
704
|
let t = new e({
|
|
@@ -415,18 +707,18 @@ var s = (e, t, n) => {
|
|
|
415
707
|
});
|
|
416
708
|
return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
|
|
417
709
|
}
|
|
418
|
-
#n =
|
|
419
|
-
errorHandler =
|
|
710
|
+
#n = He;
|
|
711
|
+
errorHandler = Ue;
|
|
420
712
|
route(e, t) {
|
|
421
|
-
let
|
|
713
|
+
let n = this.basePath(e);
|
|
422
714
|
return t.routes.map((e) => {
|
|
423
|
-
let
|
|
424
|
-
t.errorHandler ===
|
|
715
|
+
let r;
|
|
716
|
+
t.errorHandler === Ue ? r = e.handler : (r = async (n, r) => (await le([], t.errorHandler)(n, () => e.handler(n, r))).res, r[Ve] = e.handler), n.#r(e.method, e.path, r, e.basePath);
|
|
425
717
|
}), this;
|
|
426
718
|
}
|
|
427
719
|
basePath(e) {
|
|
428
720
|
let t = this.#t();
|
|
429
|
-
return t._basePath =
|
|
721
|
+
return t._basePath = R(this._basePath, e), t;
|
|
430
722
|
}
|
|
431
723
|
onError = (e) => (this.errorHandler = e, this);
|
|
432
724
|
notFound = (e) => (this.#n = e, this);
|
|
@@ -444,21 +736,21 @@ var s = (e, t, n) => {
|
|
|
444
736
|
return [e.env, t];
|
|
445
737
|
};
|
|
446
738
|
return r ||= (() => {
|
|
447
|
-
let t =
|
|
739
|
+
let t = R(this._basePath, e), n = t === "/" ? 0 : t.length;
|
|
448
740
|
return (e) => {
|
|
449
741
|
let t = new URL(e.url);
|
|
450
742
|
return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
|
|
451
743
|
};
|
|
452
|
-
})(), this.#r("ALL",
|
|
744
|
+
})(), this.#r("ALL", R(e, "*"), async (e, n) => {
|
|
453
745
|
let i = await t(r(e.req.raw), ...a(e));
|
|
454
746
|
if (i) return i;
|
|
455
747
|
await n();
|
|
456
748
|
}), this;
|
|
457
749
|
}
|
|
458
750
|
#r(e, t, n, r) {
|
|
459
|
-
e = e.toUpperCase(), t =
|
|
751
|
+
e = e.toUpperCase(), t = R(this._basePath, t);
|
|
460
752
|
let i = {
|
|
461
|
-
basePath: r === void 0 ? this._basePath :
|
|
753
|
+
basePath: r === void 0 ? this._basePath : R(this._basePath, r),
|
|
462
754
|
path: t,
|
|
463
755
|
method: e,
|
|
464
756
|
handler: n
|
|
@@ -469,51 +761,51 @@ var s = (e, t, n) => {
|
|
|
469
761
|
if (e instanceof Error) return this.errorHandler(e, t);
|
|
470
762
|
throw e;
|
|
471
763
|
}
|
|
472
|
-
#a(e, t,
|
|
473
|
-
if (
|
|
474
|
-
let
|
|
475
|
-
path:
|
|
476
|
-
matchResult:
|
|
477
|
-
env:
|
|
764
|
+
#a(e, t, n, r) {
|
|
765
|
+
if (r === "HEAD") return (async () => new Response(null, await this.#a(e, t, n, "GET")))();
|
|
766
|
+
let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Le(e, {
|
|
767
|
+
path: i,
|
|
768
|
+
matchResult: a,
|
|
769
|
+
env: n,
|
|
478
770
|
executionCtx: t,
|
|
479
771
|
notFoundHandler: this.#n
|
|
480
772
|
});
|
|
481
|
-
if (
|
|
773
|
+
if (a[0].length === 1) {
|
|
482
774
|
let e;
|
|
483
775
|
try {
|
|
484
|
-
e =
|
|
485
|
-
|
|
776
|
+
e = a[0][0][0][0](o, async () => {
|
|
777
|
+
o.res = await this.#n(o);
|
|
486
778
|
});
|
|
487
779
|
} catch (e) {
|
|
488
|
-
return this.#i(e,
|
|
780
|
+
return this.#i(e, o);
|
|
489
781
|
}
|
|
490
|
-
return e instanceof Promise ? e.then((e) => e || (
|
|
782
|
+
return e instanceof Promise ? e.then((e) => e || (o.finalized ? o.res : this.#n(o))).catch((e) => this.#i(e, o)) : e ?? this.#n(o);
|
|
491
783
|
}
|
|
492
|
-
let
|
|
784
|
+
let s = le(a[0], this.errorHandler, this.#n);
|
|
493
785
|
return (async () => {
|
|
494
786
|
try {
|
|
495
|
-
let e = await
|
|
787
|
+
let e = await s(o);
|
|
496
788
|
if (!e.finalized) throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
497
789
|
return e.res;
|
|
498
790
|
} catch (e) {
|
|
499
|
-
return this.#i(e,
|
|
791
|
+
return this.#i(e, o);
|
|
500
792
|
}
|
|
501
793
|
})();
|
|
502
794
|
}
|
|
503
795
|
fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
|
|
504
|
-
request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${
|
|
796
|
+
request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${R("/", e)}`, t), n, r));
|
|
505
797
|
fire = () => {
|
|
506
798
|
addEventListener("fetch", (e) => {
|
|
507
799
|
e.respondWith(this.#a(e.request, e, void 0, e.request.method));
|
|
508
800
|
});
|
|
509
801
|
};
|
|
510
|
-
},
|
|
511
|
-
function
|
|
802
|
+
}, Ge = [];
|
|
803
|
+
function Ke(e, t) {
|
|
512
804
|
let n = this.buildAllMatchers(), r = ((e, t) => {
|
|
513
805
|
let r = n[e] || n.ALL, i = r[2][t];
|
|
514
806
|
if (i) return i;
|
|
515
807
|
let a = t.match(r[0]);
|
|
516
|
-
if (!a) return [[],
|
|
808
|
+
if (!a) return [[], Ge];
|
|
517
809
|
let o = a.indexOf("", 1);
|
|
518
810
|
return [r[1][o], a];
|
|
519
811
|
});
|
|
@@ -521,17 +813,17 @@ function le(e, t) {
|
|
|
521
813
|
}
|
|
522
814
|
//#endregion
|
|
523
815
|
//#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
524
|
-
var
|
|
525
|
-
function
|
|
526
|
-
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e ===
|
|
816
|
+
var B = "[^/]+", V = ".*", H = "(?:|/.*)", U = /* @__PURE__ */ Symbol(), qe = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
817
|
+
function Je(e, t) {
|
|
818
|
+
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === V || e === H ? 1 : t === V || t === H ? -1 : e === B ? 1 : t === B ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
|
|
527
819
|
}
|
|
528
|
-
var
|
|
820
|
+
var Ye = class e {
|
|
529
821
|
#e;
|
|
530
822
|
#t;
|
|
531
823
|
#n = /* @__PURE__ */ Object.create(null);
|
|
532
824
|
insert(t, n, r, i, a) {
|
|
533
825
|
if (t.length === 0) {
|
|
534
|
-
if (this.#e !== void 0) throw
|
|
826
|
+
if (this.#e !== void 0) throw U;
|
|
535
827
|
if (a) return;
|
|
536
828
|
this.#e = n;
|
|
537
829
|
return;
|
|
@@ -539,42 +831,42 @@ var fe = class e {
|
|
|
539
831
|
let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
|
|
540
832
|
"",
|
|
541
833
|
"",
|
|
542
|
-
|
|
834
|
+
V
|
|
543
835
|
] : [
|
|
544
836
|
"",
|
|
545
837
|
"",
|
|
546
|
-
|
|
838
|
+
B
|
|
547
839
|
] : o === "/*" ? [
|
|
548
840
|
"",
|
|
549
841
|
"",
|
|
550
|
-
|
|
842
|
+
H
|
|
551
843
|
] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
|
|
552
844
|
if (c) {
|
|
553
|
-
let t = c[1], n = c[2] ||
|
|
554
|
-
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw
|
|
845
|
+
let t = c[1], n = c[2] || B;
|
|
846
|
+
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw U;
|
|
555
847
|
if (l = this.#n[n], !l) {
|
|
556
|
-
if (Object.keys(this.#n).some((e) => e !==
|
|
848
|
+
if (Object.keys(this.#n).some((e) => e !== V && e !== H)) throw U;
|
|
557
849
|
if (a) return;
|
|
558
850
|
l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
|
|
559
851
|
}
|
|
560
852
|
!a && t !== "" && r.push([t, l.#t]);
|
|
561
853
|
} else if (l = this.#n[o], !l) {
|
|
562
|
-
if (Object.keys(this.#n).some((e) => e.length > 1 && e !==
|
|
854
|
+
if (Object.keys(this.#n).some((e) => e.length > 1 && e !== V && e !== H)) throw U;
|
|
563
855
|
if (a) return;
|
|
564
856
|
l = this.#n[o] = new e();
|
|
565
857
|
}
|
|
566
858
|
l.insert(s, n, r, i, a);
|
|
567
859
|
}
|
|
568
860
|
buildRegExpStr() {
|
|
569
|
-
let e = Object.keys(this.#n).sort(
|
|
861
|
+
let e = Object.keys(this.#n).sort(Je).map((e) => {
|
|
570
862
|
let t = this.#n[e];
|
|
571
|
-
return (typeof t.#t == "number" ? `(${e})@${t.#t}` :
|
|
863
|
+
return (typeof t.#t == "number" ? `(${e})@${t.#t}` : qe.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
|
|
572
864
|
});
|
|
573
865
|
return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
|
|
574
866
|
}
|
|
575
|
-
},
|
|
867
|
+
}, Xe = class {
|
|
576
868
|
#e = { varIndex: 0 };
|
|
577
|
-
#t = new
|
|
869
|
+
#t = new Ye();
|
|
578
870
|
insert(e, t, n) {
|
|
579
871
|
let r = [], i = [];
|
|
580
872
|
for (let t = 0;;) {
|
|
@@ -608,29 +900,29 @@ var fe = class e {
|
|
|
608
900
|
r
|
|
609
901
|
];
|
|
610
902
|
}
|
|
611
|
-
},
|
|
903
|
+
}, Ze = [
|
|
612
904
|
/^$/,
|
|
613
905
|
[],
|
|
614
906
|
/* @__PURE__ */ Object.create(null)
|
|
615
|
-
],
|
|
616
|
-
function
|
|
617
|
-
return
|
|
907
|
+
], Qe = /* @__PURE__ */ Object.create(null);
|
|
908
|
+
function $e(e) {
|
|
909
|
+
return Qe[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
|
|
618
910
|
}
|
|
619
|
-
function
|
|
620
|
-
|
|
911
|
+
function et() {
|
|
912
|
+
Qe = /* @__PURE__ */ Object.create(null);
|
|
621
913
|
}
|
|
622
|
-
function
|
|
623
|
-
let t = new
|
|
624
|
-
if (e.length === 0) return
|
|
914
|
+
function tt(e) {
|
|
915
|
+
let t = new Xe(), n = [];
|
|
916
|
+
if (e.length === 0) return Ze;
|
|
625
917
|
let r = e.map((e) => [!/\*|\/:/.test(e[0]), ...e]).sort(([e, t], [n, r]) => e ? 1 : n ? -1 : t.length - r.length), i = /* @__PURE__ */ Object.create(null);
|
|
626
918
|
for (let e = 0, a = -1, o = r.length; e < o; e++) {
|
|
627
919
|
let [o, s, c] = r[e];
|
|
628
|
-
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]),
|
|
920
|
+
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), Ge] : a++;
|
|
629
921
|
let l;
|
|
630
922
|
try {
|
|
631
923
|
l = t.insert(s, a, o);
|
|
632
924
|
} catch (e) {
|
|
633
|
-
throw e ===
|
|
925
|
+
throw e === U ? new Be(s) : e;
|
|
634
926
|
}
|
|
635
927
|
o || (n[a] = c.map(([e, t]) => {
|
|
636
928
|
let n = /* @__PURE__ */ Object.create(null);
|
|
@@ -656,12 +948,12 @@ function ge(e) {
|
|
|
656
948
|
i
|
|
657
949
|
];
|
|
658
950
|
}
|
|
659
|
-
function
|
|
951
|
+
function W(e, t) {
|
|
660
952
|
if (e) {
|
|
661
|
-
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (
|
|
953
|
+
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if ($e(n).test(t)) return [...e[n]];
|
|
662
954
|
}
|
|
663
955
|
}
|
|
664
|
-
var
|
|
956
|
+
var nt = class {
|
|
665
957
|
name = "RegExpRouter";
|
|
666
958
|
#e;
|
|
667
959
|
#t;
|
|
@@ -670,7 +962,7 @@ var _e = class {
|
|
|
670
962
|
}
|
|
671
963
|
add(e, t, n) {
|
|
672
964
|
let r = this.#e, i = this.#t;
|
|
673
|
-
if (!r || !i) throw Error(
|
|
965
|
+
if (!r || !i) throw Error(ze);
|
|
674
966
|
r[e] || [r, i].forEach((t) => {
|
|
675
967
|
t[e] = /* @__PURE__ */ Object.create(null), Object.keys(t.ALL).forEach((n) => {
|
|
676
968
|
t[e][n] = [...t.ALL[n]];
|
|
@@ -678,10 +970,10 @@ var _e = class {
|
|
|
678
970
|
}), t === "/*" && (t = "*");
|
|
679
971
|
let a = (t.match(/\/:/g) || []).length;
|
|
680
972
|
if (/\*$/.test(t)) {
|
|
681
|
-
let o =
|
|
973
|
+
let o = $e(t);
|
|
682
974
|
e === "ALL" ? Object.keys(r).forEach((e) => {
|
|
683
|
-
r[e][t] ||=
|
|
684
|
-
}) : r[e][t] ||=
|
|
975
|
+
r[e][t] ||= W(r[e], t) || W(r.ALL, t) || [];
|
|
976
|
+
}) : r[e][t] ||= W(r[e], t) || W(r.ALL, t) || [], Object.keys(r).forEach((t) => {
|
|
685
977
|
(e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
|
|
686
978
|
o.test(e) && r[t][e].push([n, a]);
|
|
687
979
|
});
|
|
@@ -690,29 +982,29 @@ var _e = class {
|
|
|
690
982
|
});
|
|
691
983
|
return;
|
|
692
984
|
}
|
|
693
|
-
let o =
|
|
985
|
+
let o = we(t) || [t];
|
|
694
986
|
for (let t = 0, s = o.length; t < s; t++) {
|
|
695
987
|
let c = o[t];
|
|
696
988
|
Object.keys(i).forEach((o) => {
|
|
697
|
-
(e === "ALL" || e === o) && (i[o][c] ||= [...
|
|
989
|
+
(e === "ALL" || e === o) && (i[o][c] ||= [...W(r[o], c) || W(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
|
|
698
990
|
});
|
|
699
991
|
}
|
|
700
992
|
}
|
|
701
|
-
match =
|
|
993
|
+
match = Ke;
|
|
702
994
|
buildAllMatchers() {
|
|
703
995
|
let e = /* @__PURE__ */ Object.create(null);
|
|
704
996
|
return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
|
|
705
997
|
e[t] ||= this.#n(t);
|
|
706
|
-
}), this.#e = this.#t = void 0,
|
|
998
|
+
}), this.#e = this.#t = void 0, et(), e;
|
|
707
999
|
}
|
|
708
1000
|
#n(e) {
|
|
709
1001
|
let t = [], n = e === "ALL";
|
|
710
1002
|
return [this.#e, this.#t].forEach((r) => {
|
|
711
1003
|
let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
|
|
712
1004
|
i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
|
|
713
|
-
}), n ?
|
|
1005
|
+
}), n ? tt(t) : null;
|
|
714
1006
|
}
|
|
715
|
-
},
|
|
1007
|
+
}, rt = class {
|
|
716
1008
|
name = "SmartRouter";
|
|
717
1009
|
#e = [];
|
|
718
1010
|
#t = [];
|
|
@@ -720,7 +1012,7 @@ var _e = class {
|
|
|
720
1012
|
this.#e = e.routers;
|
|
721
1013
|
}
|
|
722
1014
|
add(e, t, n) {
|
|
723
|
-
if (!this.#t) throw Error(
|
|
1015
|
+
if (!this.#t) throw Error(ze);
|
|
724
1016
|
this.#t.push([
|
|
725
1017
|
e,
|
|
726
1018
|
t,
|
|
@@ -736,7 +1028,7 @@ var _e = class {
|
|
|
736
1028
|
for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
|
|
737
1029
|
o = i.match(e, t);
|
|
738
1030
|
} catch (e) {
|
|
739
|
-
if (e instanceof
|
|
1031
|
+
if (e instanceof Be) continue;
|
|
740
1032
|
throw e;
|
|
741
1033
|
}
|
|
742
1034
|
this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
|
|
@@ -749,15 +1041,15 @@ var _e = class {
|
|
|
749
1041
|
if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
|
|
750
1042
|
return this.#e[0];
|
|
751
1043
|
}
|
|
752
|
-
},
|
|
1044
|
+
}, G = /* @__PURE__ */ Object.create(null), it = (e) => {
|
|
753
1045
|
for (let t in e) return !0;
|
|
754
1046
|
return !1;
|
|
755
|
-
},
|
|
1047
|
+
}, at = class e {
|
|
756
1048
|
#e;
|
|
757
1049
|
#t;
|
|
758
1050
|
#n;
|
|
759
1051
|
#r = 0;
|
|
760
|
-
#i =
|
|
1052
|
+
#i = G;
|
|
761
1053
|
constructor(e, t, n) {
|
|
762
1054
|
if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
|
|
763
1055
|
let n = /* @__PURE__ */ Object.create(null);
|
|
@@ -771,9 +1063,9 @@ var _e = class {
|
|
|
771
1063
|
}
|
|
772
1064
|
insert(t, n, r) {
|
|
773
1065
|
this.#r = ++this.#r;
|
|
774
|
-
let i = this, a =
|
|
1066
|
+
let i = this, a = _e(n), o = [];
|
|
775
1067
|
for (let t = 0, n = a.length; t < n; t++) {
|
|
776
|
-
let n = a[t], r = a[t + 1], s =
|
|
1068
|
+
let n = a[t], r = a[t + 1], s = be(n, r), c = Array.isArray(s) ? s[0] : n;
|
|
777
1069
|
if (c in i.#t) {
|
|
778
1070
|
i = i.#t[c], s && o.push(s[1]);
|
|
779
1071
|
continue;
|
|
@@ -789,7 +1081,7 @@ var _e = class {
|
|
|
789
1081
|
#a(e, t, n, r, i) {
|
|
790
1082
|
for (let a = 0, o = t.#e.length; a < o; a++) {
|
|
791
1083
|
let o = t.#e[a], s = o[n] || o.ALL, c = {};
|
|
792
|
-
if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !==
|
|
1084
|
+
if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== G || i && i !== G)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
|
|
793
1085
|
let t = s.possibleKeys[e], n = c[s.score];
|
|
794
1086
|
s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
|
|
795
1087
|
}
|
|
@@ -797,15 +1089,15 @@ var _e = class {
|
|
|
797
1089
|
}
|
|
798
1090
|
search(e, t) {
|
|
799
1091
|
let n = [];
|
|
800
|
-
this.#i =
|
|
801
|
-
let r = [this], i =
|
|
1092
|
+
this.#i = G;
|
|
1093
|
+
let r = [this], i = ge(t), a = [], o = i.length, s = null;
|
|
802
1094
|
for (let c = 0; c < o; c++) {
|
|
803
1095
|
let l = i[c], u = c === o - 1, d = [];
|
|
804
1096
|
for (let f = 0, p = r.length; f < p; f++) {
|
|
805
1097
|
let p = r[f], m = p.#t[l];
|
|
806
1098
|
m && (m.#i = p.#i, u ? (m.#t["*"] && this.#a(n, m.#t["*"], e, p.#i), this.#a(n, m, e, p.#i)) : d.push(m));
|
|
807
1099
|
for (let r = 0, f = p.#n.length; r < f; r++) {
|
|
808
|
-
let f = p.#n[r], m = p.#i ===
|
|
1100
|
+
let f = p.#n[r], m = p.#i === G ? {} : { ...p.#i };
|
|
809
1101
|
if (f === "*") {
|
|
810
1102
|
let t = p.#t["*"];
|
|
811
1103
|
t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
|
|
@@ -822,7 +1114,7 @@ var _e = class {
|
|
|
822
1114
|
}
|
|
823
1115
|
let r = t.substring(s[c]), l = _.exec(r);
|
|
824
1116
|
if (l) {
|
|
825
|
-
if (m[g] = l[0], this.#a(n, v, e, p.#i, m),
|
|
1117
|
+
if (m[g] = l[0], this.#a(n, v, e, p.#i, m), it(v.#t)) {
|
|
826
1118
|
v.#i = m;
|
|
827
1119
|
let e = l[0].match(/\//)?.length ?? 0;
|
|
828
1120
|
(a[e] ||= []).push(v);
|
|
@@ -838,14 +1130,14 @@ var _e = class {
|
|
|
838
1130
|
}
|
|
839
1131
|
return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
|
|
840
1132
|
}
|
|
841
|
-
},
|
|
1133
|
+
}, ot = class {
|
|
842
1134
|
name = "TrieRouter";
|
|
843
1135
|
#e;
|
|
844
1136
|
constructor() {
|
|
845
|
-
this.#e = new
|
|
1137
|
+
this.#e = new at();
|
|
846
1138
|
}
|
|
847
1139
|
add(e, t, n) {
|
|
848
|
-
let r =
|
|
1140
|
+
let r = we(t);
|
|
849
1141
|
if (r) {
|
|
850
1142
|
for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
|
|
851
1143
|
return;
|
|
@@ -855,43 +1147,43 @@ var _e = class {
|
|
|
855
1147
|
match(e, t) {
|
|
856
1148
|
return this.#e.search(e, t);
|
|
857
1149
|
}
|
|
858
|
-
},
|
|
1150
|
+
}, st = class extends We {
|
|
859
1151
|
constructor(e = {}) {
|
|
860
|
-
super(e), this.router = e.router ?? new
|
|
1152
|
+
super(e), this.router = e.router ?? new rt({ routers: [new nt(), new ot()] });
|
|
861
1153
|
}
|
|
862
1154
|
};
|
|
863
1155
|
//#endregion
|
|
864
1156
|
//#region src/coordinator-invites.ts
|
|
865
|
-
function
|
|
1157
|
+
function ct(e) {
|
|
866
1158
|
let t = "";
|
|
867
1159
|
for (let n of e) t += String.fromCharCode(n);
|
|
868
1160
|
return btoa(t);
|
|
869
1161
|
}
|
|
870
|
-
function
|
|
1162
|
+
function lt(e) {
|
|
871
1163
|
let t = atob(e), n = new Uint8Array(t.length);
|
|
872
1164
|
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
873
1165
|
return n;
|
|
874
1166
|
}
|
|
875
|
-
function
|
|
1167
|
+
function ut(e) {
|
|
876
1168
|
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
877
1169
|
}
|
|
878
|
-
function
|
|
1170
|
+
function dt(e) {
|
|
879
1171
|
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
880
1172
|
return t + "=".repeat((4 - t.length % 4) % 4);
|
|
881
1173
|
}
|
|
882
|
-
function
|
|
1174
|
+
function K(e) {
|
|
883
1175
|
let t = JSON.stringify(e);
|
|
884
|
-
return
|
|
1176
|
+
return ut(ct(new TextEncoder().encode(t)));
|
|
885
1177
|
}
|
|
886
|
-
function
|
|
887
|
-
let t = new TextDecoder().decode(
|
|
1178
|
+
function ft(e) {
|
|
1179
|
+
let t = new TextDecoder().decode(lt(dt(e))), n = JSON.parse(t);
|
|
888
1180
|
if (typeof n != "object" || !n) throw Error("invalid invite payload");
|
|
889
1181
|
return n;
|
|
890
1182
|
}
|
|
891
|
-
function
|
|
1183
|
+
function q(e) {
|
|
892
1184
|
return `codemem://join?invite=${encodeURIComponent(e)}`;
|
|
893
1185
|
}
|
|
894
|
-
function
|
|
1186
|
+
function pt(e) {
|
|
895
1187
|
let t = e.trim();
|
|
896
1188
|
if (t.startsWith("codemem://")) {
|
|
897
1189
|
let e = new URL(t).searchParams.get("invite") ?? "";
|
|
@@ -901,21 +1193,33 @@ function Oe(e) {
|
|
|
901
1193
|
return t;
|
|
902
1194
|
}
|
|
903
1195
|
//#endregion
|
|
1196
|
+
//#region src/project-invite-acceptance.ts
|
|
1197
|
+
var mt = "pending_setup", ht = "project_sync_enablement_failed", gt = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", _t = class extends Error {
|
|
1198
|
+
code = ht;
|
|
1199
|
+
detail = gt;
|
|
1200
|
+
constructor(e) {
|
|
1201
|
+
super(gt, e), this.name = "ProjectSyncEnablementError";
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
function vt(e) {
|
|
1205
|
+
return typeof e == "object" && !!e && "code" in e && e.code === "project_sync_enablement_failed" && "detail" in e && e.detail === "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.";
|
|
1206
|
+
}
|
|
1207
|
+
//#endregion
|
|
904
1208
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
|
|
905
|
-
function
|
|
1209
|
+
function yt(e) {
|
|
906
1210
|
let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
|
|
907
1211
|
return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
|
|
908
1212
|
}
|
|
909
|
-
function
|
|
910
|
-
let [e, t] =
|
|
1213
|
+
function J() {
|
|
1214
|
+
let [e, t] = yt();
|
|
911
1215
|
return e * 1e3 + Math.floor(t / 1e6);
|
|
912
1216
|
}
|
|
913
|
-
function
|
|
1217
|
+
function bt(e) {
|
|
914
1218
|
return new Promise((t) => setTimeout(t, e));
|
|
915
1219
|
}
|
|
916
1220
|
//#endregion
|
|
917
1221
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
|
|
918
|
-
var
|
|
1222
|
+
var xt = class {
|
|
919
1223
|
bucketSize;
|
|
920
1224
|
tokensPerInterval;
|
|
921
1225
|
interval;
|
|
@@ -942,13 +1246,13 @@ var Ae = class {
|
|
|
942
1246
|
default: throw Error("Invalid interval " + n);
|
|
943
1247
|
}
|
|
944
1248
|
else this.interval = n;
|
|
945
|
-
this.parentBucket = r, this.content = 0, this.lastDrip =
|
|
1249
|
+
this.parentBucket = r, this.content = 0, this.lastDrip = J();
|
|
946
1250
|
}
|
|
947
1251
|
async removeTokens(e) {
|
|
948
1252
|
if (this.bucketSize === 0) return Infinity;
|
|
949
1253
|
if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
|
|
950
1254
|
this.drip();
|
|
951
|
-
let t = async () => (await
|
|
1255
|
+
let t = async () => (await bt(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
|
|
952
1256
|
if (e > this.content) return t();
|
|
953
1257
|
if (this.parentBucket != null) {
|
|
954
1258
|
let n = await this.parentBucket.removeTokens(e);
|
|
@@ -963,30 +1267,30 @@ var Ae = class {
|
|
|
963
1267
|
let e = this.content;
|
|
964
1268
|
return this.content = this.bucketSize, this.content > e;
|
|
965
1269
|
}
|
|
966
|
-
let e =
|
|
1270
|
+
let e = J(), t = Math.max(e - this.lastDrip, 0);
|
|
967
1271
|
this.lastDrip = e;
|
|
968
1272
|
let n = t * (this.tokensPerInterval / this.interval), r = this.content;
|
|
969
1273
|
return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
|
|
970
1274
|
}
|
|
971
|
-
},
|
|
1275
|
+
}, St = class {
|
|
972
1276
|
tokenBucket;
|
|
973
1277
|
curIntervalStart;
|
|
974
1278
|
tokensThisInterval;
|
|
975
1279
|
fireImmediately;
|
|
976
1280
|
constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
|
|
977
|
-
this.tokenBucket = new
|
|
1281
|
+
this.tokenBucket = new xt({
|
|
978
1282
|
bucketSize: e,
|
|
979
1283
|
tokensPerInterval: e,
|
|
980
1284
|
interval: t
|
|
981
|
-
}), this.tokenBucket.content = e, this.curIntervalStart =
|
|
1285
|
+
}), this.tokenBucket.content = e, this.curIntervalStart = J(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
|
|
982
1286
|
}
|
|
983
1287
|
async removeTokens(e) {
|
|
984
1288
|
if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
|
|
985
|
-
let t =
|
|
1289
|
+
let t = J();
|
|
986
1290
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
|
|
987
1291
|
if (this.fireImmediately) return -1;
|
|
988
1292
|
{
|
|
989
|
-
await
|
|
1293
|
+
await bt(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
|
|
990
1294
|
let n = await this.tokenBucket.removeTokens(e);
|
|
991
1295
|
return this.tokensThisInterval += e, n;
|
|
992
1296
|
}
|
|
@@ -996,7 +1300,7 @@ var Ae = class {
|
|
|
996
1300
|
}
|
|
997
1301
|
tryRemoveTokens(e) {
|
|
998
1302
|
if (e > this.tokenBucket.bucketSize) return !1;
|
|
999
|
-
let t =
|
|
1303
|
+
let t = J();
|
|
1000
1304
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
|
|
1001
1305
|
let n = this.tokenBucket.tryRemoveTokens(e);
|
|
1002
1306
|
return n && (this.tokensThisInterval += e), n;
|
|
@@ -1007,7 +1311,7 @@ var Ae = class {
|
|
|
1007
1311
|
};
|
|
1008
1312
|
//#endregion
|
|
1009
1313
|
//#region src/request-rate-limit.ts
|
|
1010
|
-
function
|
|
1314
|
+
function Ct(e = {}) {
|
|
1011
1315
|
let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
|
|
1012
1316
|
function a(e) {
|
|
1013
1317
|
return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
|
|
@@ -1024,7 +1328,7 @@ function Me(e = {}) {
|
|
|
1024
1328
|
o(l);
|
|
1025
1329
|
let u = `${c}:${e}`, d = r.get(u);
|
|
1026
1330
|
return d || (d = {
|
|
1027
|
-
limiter: new
|
|
1331
|
+
limiter: new St({
|
|
1028
1332
|
tokensPerInterval: c,
|
|
1029
1333
|
interval: t,
|
|
1030
1334
|
fireImmediately: !0
|
|
@@ -1041,8 +1345,8 @@ function Me(e = {}) {
|
|
|
1041
1345
|
}
|
|
1042
1346
|
//#endregion
|
|
1043
1347
|
//#region src/scope-membership-semantics.ts
|
|
1044
|
-
var
|
|
1045
|
-
function
|
|
1348
|
+
var wt = "Revocation blocks future sync for this Space. It does not remove data already copied to the revoked device; offline devices, backups, copied databases, malicious peers, or old versions may retain data.";
|
|
1349
|
+
function Tt(e) {
|
|
1046
1350
|
let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
|
|
1047
1351
|
return t == null || n == null ? {
|
|
1048
1352
|
membership_epoch: t,
|
|
@@ -1056,28 +1360,20 @@ function Ne(e) {
|
|
|
1056
1360
|
reason: t < n ? "stale_epoch" : "current"
|
|
1057
1361
|
};
|
|
1058
1362
|
}
|
|
1059
|
-
function
|
|
1363
|
+
function Et(e) {
|
|
1060
1364
|
return {
|
|
1061
1365
|
scope_id: e.scopeId,
|
|
1062
1366
|
device_id: e.deviceId,
|
|
1063
1367
|
membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
|
|
1064
1368
|
prevents_future_sync: !0,
|
|
1065
1369
|
deletes_already_copied_data: !1,
|
|
1066
|
-
message:
|
|
1370
|
+
message: wt
|
|
1067
1371
|
};
|
|
1068
1372
|
}
|
|
1069
1373
|
//#endregion
|
|
1070
1374
|
//#region src/sync-auth-constants.ts
|
|
1071
|
-
var
|
|
1072
|
-
|
|
1073
|
-
//#region src/sync-fingerprint.ts
|
|
1074
|
-
function J(t) {
|
|
1075
|
-
return e("sha256").update(t, "utf-8").digest("hex");
|
|
1076
|
-
}
|
|
1077
|
-
//#endregion
|
|
1078
|
-
//#region src/coordinator-api.ts
|
|
1079
|
-
var Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Z = "X-Codemem-Coordinator-Admin-Actor", Fe = 120, Ie = 30;
|
|
1080
|
-
function Q(e, t) {
|
|
1375
|
+
var Dt = 300, Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Ot = "X-Codemem-Coordinator-Admin-Actor", kt = 120, At = 30;
|
|
1376
|
+
function Z(e, t) {
|
|
1081
1377
|
let n = t.adminSecret();
|
|
1082
1378
|
if (!n) return {
|
|
1083
1379
|
ok: !1,
|
|
@@ -1095,29 +1391,34 @@ function Q(e, t) {
|
|
|
1095
1391
|
error: "missing_admin_header"
|
|
1096
1392
|
};
|
|
1097
1393
|
}
|
|
1098
|
-
function
|
|
1394
|
+
function jt(e) {
|
|
1099
1395
|
let t = new URL(e);
|
|
1100
1396
|
return t.search ? `${t.pathname}${t.search}` : t.pathname;
|
|
1101
1397
|
}
|
|
1102
|
-
async function
|
|
1398
|
+
async function Mt(e, t, n, r) {
|
|
1103
1399
|
return await e.recordNonce(t, n, r);
|
|
1104
1400
|
}
|
|
1105
|
-
async function
|
|
1401
|
+
async function Nt(e, t) {
|
|
1106
1402
|
await e.cleanupNonces(t);
|
|
1107
1403
|
}
|
|
1108
|
-
async function
|
|
1404
|
+
async function Q(e, t, n, r) {
|
|
1109
1405
|
let { deviceId: i, signature: a, timestamp: o, nonce: s } = r;
|
|
1110
1406
|
if (!i || !a || !o || !s) return {
|
|
1111
1407
|
ok: !1,
|
|
1112
1408
|
error: "missing_headers",
|
|
1113
1409
|
enrollment: null
|
|
1114
1410
|
};
|
|
1115
|
-
let c = await e.getEnrollment(r.groupId, i);
|
|
1411
|
+
let c = await e.getEnrollment(r.groupId, i, !0);
|
|
1116
1412
|
if (!c) return {
|
|
1117
1413
|
ok: !1,
|
|
1118
1414
|
error: "unknown_device",
|
|
1119
1415
|
enrollment: null
|
|
1120
1416
|
};
|
|
1417
|
+
if (c.enabled !== 1) return {
|
|
1418
|
+
ok: !1,
|
|
1419
|
+
error: "device_disabled",
|
|
1420
|
+
enrollment: null
|
|
1421
|
+
};
|
|
1121
1422
|
let l = await e.getGroup(r.groupId);
|
|
1122
1423
|
if (!l) return {
|
|
1123
1424
|
ok: !1,
|
|
@@ -1133,7 +1434,7 @@ async function $(e, t, n, r) {
|
|
|
1133
1434
|
try {
|
|
1134
1435
|
u = await n({
|
|
1135
1436
|
method: r.method,
|
|
1136
|
-
pathWithQuery:
|
|
1437
|
+
pathWithQuery: jt(r.url),
|
|
1137
1438
|
bodyBytes: r.body,
|
|
1138
1439
|
timestamp: o,
|
|
1139
1440
|
nonce: s,
|
|
@@ -1154,7 +1455,7 @@ async function $(e, t, n, r) {
|
|
|
1154
1455
|
enrollment: null
|
|
1155
1456
|
};
|
|
1156
1457
|
let d = t.now();
|
|
1157
|
-
return await
|
|
1458
|
+
return await Mt(e, i, s, d) ? (await Nt(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
|
|
1158
1459
|
ok: !0,
|
|
1159
1460
|
error: "ok",
|
|
1160
1461
|
enrollment: c
|
|
@@ -1164,17 +1465,20 @@ async function $(e, t, n, r) {
|
|
|
1164
1465
|
enrollment: null
|
|
1165
1466
|
};
|
|
1166
1467
|
}
|
|
1167
|
-
function
|
|
1468
|
+
function $(e) {
|
|
1469
|
+
return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
|
|
1470
|
+
}
|
|
1471
|
+
function Pt(e) {
|
|
1168
1472
|
if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
|
|
1169
|
-
let t = e.runtime, n = e.storeFactory,
|
|
1170
|
-
function
|
|
1171
|
-
let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i =
|
|
1473
|
+
let t = e.runtime, n = e.storeFactory, i = e.requestVerifier, a = e.requestRateLimit ?? {}, o = a.limiter ?? Ct(), s = Math.max(1, Math.trunc(a.readLimit ?? kt)), c = Math.max(1, Math.trunc(a.mutationLimit ?? At)), l = Math.max(1, Math.trunc(a.unauthenticatedReadLimit ?? Math.min(20, s))), u = Math.max(1, Math.trunc(a.unauthenticatedMutationLimit ?? Math.min(10, c))), d = new st(), f = new TextDecoder();
|
|
1474
|
+
function p(e, t, n) {
|
|
1475
|
+
let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = o.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? s : c : r ? l : u);
|
|
1172
1476
|
return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
|
|
1173
1477
|
error: "rate_limited",
|
|
1174
1478
|
retry_after_s: i.retryAfterS
|
|
1175
1479
|
}, 429));
|
|
1176
1480
|
}
|
|
1177
|
-
async function
|
|
1481
|
+
async function m(e) {
|
|
1178
1482
|
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1179
1483
|
if (Number.isFinite(t) && t > Y) return null;
|
|
1180
1484
|
let n = e.req.raw.body;
|
|
@@ -1196,22 +1500,22 @@ function Be(e) {
|
|
|
1196
1500
|
for (let e of i) o.set(e, s), s += e.byteLength;
|
|
1197
1501
|
return o;
|
|
1198
1502
|
}
|
|
1199
|
-
function
|
|
1503
|
+
function g(e) {
|
|
1200
1504
|
try {
|
|
1201
|
-
let t = JSON.parse(
|
|
1505
|
+
let t = JSON.parse(f.decode(e));
|
|
1202
1506
|
return typeof t != "object" || !t || Array.isArray(t) ? null : t;
|
|
1203
1507
|
} catch {
|
|
1204
1508
|
return null;
|
|
1205
1509
|
}
|
|
1206
1510
|
}
|
|
1207
|
-
function
|
|
1511
|
+
function _(e, t) {
|
|
1208
1512
|
let n = e[t];
|
|
1209
1513
|
return n == null ? null : String(n).trim() || null;
|
|
1210
1514
|
}
|
|
1211
|
-
function
|
|
1515
|
+
function y(e) {
|
|
1212
1516
|
return e?.trim() || null;
|
|
1213
1517
|
}
|
|
1214
|
-
function
|
|
1518
|
+
function x(e, t) {
|
|
1215
1519
|
let n = e[t];
|
|
1216
1520
|
if (n == null || n === "") return null;
|
|
1217
1521
|
if (typeof n != "number" && typeof n != "string") return NaN;
|
|
@@ -1224,20 +1528,41 @@ function Be(e) {
|
|
|
1224
1528
|
let r = n;
|
|
1225
1529
|
return Number.isFinite(r) ? Math.trunc(r) : NaN;
|
|
1226
1530
|
}
|
|
1227
|
-
function
|
|
1531
|
+
function S(e) {
|
|
1228
1532
|
return [
|
|
1229
1533
|
"1",
|
|
1230
1534
|
"true",
|
|
1231
1535
|
"yes"
|
|
1232
1536
|
].includes(String(e ?? "").trim().toLowerCase());
|
|
1233
1537
|
}
|
|
1234
|
-
|
|
1538
|
+
function C(e) {
|
|
1539
|
+
try {
|
|
1540
|
+
let t = JSON.parse(e ?? "");
|
|
1541
|
+
if (!Array.isArray(t) || t.length === 0 || t.length > 100) throw Error("operation_intent_invalid");
|
|
1542
|
+
return t.map((e) => {
|
|
1543
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
|
|
1544
|
+
let t = e;
|
|
1545
|
+
if (!String(t.canonical_identity ?? "").trim() || !String(t.display_name ?? "").trim() || !Number.isSafeInteger(t.existing_memory_count)) throw Error("operation_intent_invalid");
|
|
1546
|
+
return t;
|
|
1547
|
+
});
|
|
1548
|
+
} catch {
|
|
1549
|
+
throw Error("operation_intent_invalid");
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
function w(e) {
|
|
1553
|
+
try {
|
|
1554
|
+
return v(JSON.parse(e ?? ""));
|
|
1555
|
+
} catch {
|
|
1556
|
+
throw Error("operation_intent_invalid");
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
async function T(e, t, n) {
|
|
1235
1560
|
if (!t) return n.json({ error: "group_id_required" }, 400);
|
|
1236
1561
|
let r = await e.getGroup(t);
|
|
1237
1562
|
return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
|
|
1238
1563
|
}
|
|
1239
|
-
async function
|
|
1240
|
-
let i = await
|
|
1564
|
+
async function E(e, t, n, r) {
|
|
1565
|
+
let i = await T(e, t, r);
|
|
1241
1566
|
if (i) return {
|
|
1242
1567
|
scope: null,
|
|
1243
1568
|
response: i
|
|
@@ -1258,52 +1583,52 @@ function Be(e) {
|
|
|
1258
1583
|
response: r.json({ error: "scope_not_found" }, 404)
|
|
1259
1584
|
};
|
|
1260
1585
|
}
|
|
1261
|
-
async function
|
|
1262
|
-
let a = await
|
|
1263
|
-
method:
|
|
1264
|
-
url:
|
|
1586
|
+
async function D(e, n, r) {
|
|
1587
|
+
let a = await Q(e, t, i, {
|
|
1588
|
+
method: r.req.method,
|
|
1589
|
+
url: r.req.url,
|
|
1265
1590
|
groupId: n,
|
|
1266
1591
|
body: new Uint8Array(),
|
|
1267
|
-
deviceId:
|
|
1268
|
-
signature:
|
|
1269
|
-
timestamp:
|
|
1270
|
-
nonce:
|
|
1592
|
+
deviceId: r.req.header("X-Opencode-Device") ?? null,
|
|
1593
|
+
signature: r.req.header("X-Opencode-Signature") ?? null,
|
|
1594
|
+
timestamp: r.req.header("X-Opencode-Timestamp") ?? null,
|
|
1595
|
+
nonce: r.req.header("X-Opencode-Nonce") ?? null
|
|
1271
1596
|
});
|
|
1272
1597
|
return !a.ok || !a.enrollment ? {
|
|
1273
1598
|
auth: a,
|
|
1274
|
-
response:
|
|
1599
|
+
response: p(r, r.req.path, !1) ?? r.json({ error: a.error }, $(a.error))
|
|
1275
1600
|
} : {
|
|
1276
1601
|
auth: a,
|
|
1277
|
-
response:
|
|
1602
|
+
response: p(r, String(a.enrollment.device_id), !0)
|
|
1278
1603
|
};
|
|
1279
1604
|
}
|
|
1280
|
-
function
|
|
1605
|
+
function O(e, t) {
|
|
1281
1606
|
return e.status === "active" && e.membership_epoch >= t.membership_epoch;
|
|
1282
1607
|
}
|
|
1283
|
-
async function
|
|
1284
|
-
return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n &&
|
|
1608
|
+
async function k(e, t, n) {
|
|
1609
|
+
return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n && O(e, t));
|
|
1285
1610
|
}
|
|
1286
|
-
return
|
|
1287
|
-
let
|
|
1288
|
-
if (
|
|
1289
|
-
let a =
|
|
1611
|
+
return d.post("/v1/presence", async (e) => {
|
|
1612
|
+
let r = await m(e);
|
|
1613
|
+
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
1614
|
+
let a = g(r);
|
|
1290
1615
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1291
1616
|
let o = String(a.group_id ?? "").trim();
|
|
1292
1617
|
if (!o) return e.json({ error: "group_id_required" }, 400);
|
|
1293
1618
|
let s = n();
|
|
1294
1619
|
try {
|
|
1295
|
-
let n = await
|
|
1620
|
+
let n = await Q(s, t, i, {
|
|
1296
1621
|
method: e.req.method,
|
|
1297
1622
|
url: e.req.url,
|
|
1298
1623
|
groupId: o,
|
|
1299
|
-
body:
|
|
1624
|
+
body: r,
|
|
1300
1625
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1301
1626
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1302
1627
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1303
1628
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1304
1629
|
});
|
|
1305
|
-
if (!n.ok || !n.enrollment) return
|
|
1306
|
-
let c =
|
|
1630
|
+
if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
1631
|
+
let c = p(e, String(n.enrollment.device_id), !0);
|
|
1307
1632
|
if (c) return c;
|
|
1308
1633
|
if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
|
|
1309
1634
|
let l = a.addresses ?? [];
|
|
@@ -1328,53 +1653,53 @@ function Be(e) {
|
|
|
1328
1653
|
} finally {
|
|
1329
1654
|
await s.close();
|
|
1330
1655
|
}
|
|
1331
|
-
}),
|
|
1332
|
-
let
|
|
1333
|
-
if (!
|
|
1656
|
+
}), d.get("/v1/peers", async (e) => {
|
|
1657
|
+
let r = (e.req.query("group_id") ?? "").trim();
|
|
1658
|
+
if (!r) return e.json({ error: "group_id_required" }, 400);
|
|
1334
1659
|
let a = n();
|
|
1335
1660
|
try {
|
|
1336
|
-
let n = await
|
|
1661
|
+
let n = await Q(a, t, i, {
|
|
1337
1662
|
method: e.req.method,
|
|
1338
1663
|
url: e.req.url,
|
|
1339
|
-
groupId:
|
|
1664
|
+
groupId: r,
|
|
1340
1665
|
body: new Uint8Array(),
|
|
1341
1666
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1342
1667
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1343
1668
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1344
1669
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1345
1670
|
});
|
|
1346
|
-
if (!n.ok || !n.enrollment) return
|
|
1347
|
-
let o =
|
|
1671
|
+
if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
1672
|
+
let o = p(e, String(n.enrollment.device_id), !0);
|
|
1348
1673
|
if (o) return o;
|
|
1349
|
-
let s = await a.listGroupPeers(
|
|
1674
|
+
let s = await a.listGroupPeers(r, String(n.enrollment.device_id));
|
|
1350
1675
|
return e.json({ items: s });
|
|
1351
1676
|
} finally {
|
|
1352
1677
|
await a.close();
|
|
1353
1678
|
}
|
|
1354
|
-
}),
|
|
1679
|
+
}), d.get("/v1/scopes", async (e) => {
|
|
1355
1680
|
let t = (e.req.query("group_id") ?? "").trim();
|
|
1356
1681
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1357
1682
|
let r = n();
|
|
1358
1683
|
try {
|
|
1359
|
-
let { auth: n, response: i } = await
|
|
1684
|
+
let { auth: n, response: i } = await D(r, t, e);
|
|
1360
1685
|
if (i) return i;
|
|
1361
1686
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1362
1687
|
let a = await r.listScopes({
|
|
1363
1688
|
groupId: t,
|
|
1364
1689
|
includeInactive: !1
|
|
1365
1690
|
}), o = [];
|
|
1366
|
-
for (let e of a) e.status === "active" && await
|
|
1691
|
+
for (let e of a) e.status === "active" && await k(r, e, String(n.enrollment.device_id)) && o.push(e);
|
|
1367
1692
|
return e.json({ items: o });
|
|
1368
1693
|
} finally {
|
|
1369
1694
|
await r.close();
|
|
1370
1695
|
}
|
|
1371
|
-
}),
|
|
1696
|
+
}), d.get("/v1/scopes/:scope_id/members", async (e) => {
|
|
1372
1697
|
let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
|
|
1373
1698
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1374
1699
|
if (!r) return e.json({ error: "scope_id_required" }, 400);
|
|
1375
1700
|
let i = n();
|
|
1376
1701
|
try {
|
|
1377
|
-
let { auth: n, response: a } = await
|
|
1702
|
+
let { auth: n, response: a } = await D(i, t, e);
|
|
1378
1703
|
if (a) return a;
|
|
1379
1704
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1380
1705
|
let o = (await i.listScopes({
|
|
@@ -1383,31 +1708,31 @@ function Be(e) {
|
|
|
1383
1708
|
})).find((e) => e.scope_id === r) ?? null;
|
|
1384
1709
|
if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
|
|
1385
1710
|
let s = await i.listScopeMemberships(r, !1);
|
|
1386
|
-
return s.some((e) => e.device_id === String(n.enrollment?.device_id) &&
|
|
1711
|
+
return s.some((e) => e.device_id === String(n.enrollment?.device_id) && O(e, o)) ? e.json({ items: s.filter((e) => O(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
|
|
1387
1712
|
} finally {
|
|
1388
1713
|
await i.close();
|
|
1389
1714
|
}
|
|
1390
|
-
}),
|
|
1391
|
-
let
|
|
1392
|
-
if (!
|
|
1715
|
+
}), d.get("/v1/reciprocal-approvals", async (e) => {
|
|
1716
|
+
let r = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
|
|
1717
|
+
if (!r) return e.json({ error: "group_id_required" }, 400);
|
|
1393
1718
|
if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
|
|
1394
1719
|
let s = n();
|
|
1395
1720
|
try {
|
|
1396
|
-
let n = await
|
|
1721
|
+
let n = await Q(s, t, i, {
|
|
1397
1722
|
method: e.req.method,
|
|
1398
1723
|
url: e.req.url,
|
|
1399
|
-
groupId:
|
|
1724
|
+
groupId: r,
|
|
1400
1725
|
body: new Uint8Array(),
|
|
1401
1726
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1402
1727
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1403
1728
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1404
1729
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1405
1730
|
});
|
|
1406
|
-
if (!n.ok || !n.enrollment) return
|
|
1407
|
-
let c =
|
|
1731
|
+
if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
1732
|
+
let c = p(e, String(n.enrollment.device_id), !0);
|
|
1408
1733
|
if (c) return c;
|
|
1409
1734
|
let l = await s.listReciprocalApprovals({
|
|
1410
|
-
groupId:
|
|
1735
|
+
groupId: r,
|
|
1411
1736
|
deviceId: String(n.enrollment.device_id),
|
|
1412
1737
|
direction: a,
|
|
1413
1738
|
status: o
|
|
@@ -1416,27 +1741,27 @@ function Be(e) {
|
|
|
1416
1741
|
} finally {
|
|
1417
1742
|
await s.close();
|
|
1418
1743
|
}
|
|
1419
|
-
}),
|
|
1420
|
-
let
|
|
1421
|
-
if (
|
|
1422
|
-
let a =
|
|
1744
|
+
}), d.post("/v1/reciprocal-approvals", async (e) => {
|
|
1745
|
+
let r = await m(e);
|
|
1746
|
+
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
1747
|
+
let a = g(r);
|
|
1423
1748
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1424
1749
|
let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim();
|
|
1425
1750
|
if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
|
|
1426
1751
|
let c = n();
|
|
1427
1752
|
try {
|
|
1428
|
-
let n = await
|
|
1753
|
+
let n = await Q(c, t, i, {
|
|
1429
1754
|
method: e.req.method,
|
|
1430
1755
|
url: e.req.url,
|
|
1431
1756
|
groupId: o,
|
|
1432
|
-
body:
|
|
1757
|
+
body: r,
|
|
1433
1758
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1434
1759
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1435
1760
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1436
1761
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1437
1762
|
});
|
|
1438
|
-
if (!n.ok || !n.enrollment) return
|
|
1439
|
-
let a =
|
|
1763
|
+
if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
1764
|
+
let a = p(e, String(n.enrollment.device_id), !0);
|
|
1440
1765
|
if (a) return a;
|
|
1441
1766
|
if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
|
|
1442
1767
|
if (!await c.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
|
|
@@ -1452,34 +1777,111 @@ function Be(e) {
|
|
|
1452
1777
|
} finally {
|
|
1453
1778
|
await c.close();
|
|
1454
1779
|
}
|
|
1455
|
-
}),
|
|
1456
|
-
let r =
|
|
1457
|
-
if (
|
|
1458
|
-
let
|
|
1780
|
+
}), d.post("/v1/invites/add-device", async (e) => {
|
|
1781
|
+
let r = await m(e);
|
|
1782
|
+
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
1783
|
+
let a = g(r);
|
|
1784
|
+
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1785
|
+
let o = new Set([
|
|
1786
|
+
"group_id",
|
|
1787
|
+
"expires_at",
|
|
1788
|
+
"reviewed_preview_digest",
|
|
1789
|
+
"reviewed_intent"
|
|
1790
|
+
]);
|
|
1791
|
+
if (Object.keys(a).some((e) => !o.has(e))) return e.json({ error: "unexpected_add_device_invite_fields" }, 400);
|
|
1792
|
+
let s = String(a.group_id ?? "").trim(), c = String(a.expires_at ?? "").trim(), l = String(a.reviewed_preview_digest ?? "").trim();
|
|
1793
|
+
if (!s || !c) return e.json({ error: "group_id_and_expires_at_required" }, 400);
|
|
1794
|
+
if (Number.isNaN(new Date(c).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
|
|
1795
|
+
if (!/^[a-f0-9]{64}$/u.test(l)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
|
|
1796
|
+
if (a.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
1797
|
+
let u = n();
|
|
1798
|
+
try {
|
|
1799
|
+
let n = await Q(u, t, i, {
|
|
1800
|
+
method: e.req.method,
|
|
1801
|
+
url: e.req.url,
|
|
1802
|
+
groupId: s,
|
|
1803
|
+
body: r,
|
|
1804
|
+
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1805
|
+
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1806
|
+
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1807
|
+
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1808
|
+
});
|
|
1809
|
+
if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
1810
|
+
let o = p(e, String(n.enrollment.device_id), !0);
|
|
1811
|
+
if (o) return o;
|
|
1812
|
+
let d = n.enrollment.identity_id;
|
|
1813
|
+
if (!d || d !== d.trim() || d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "identity_binding_required" }, 403);
|
|
1814
|
+
let f;
|
|
1815
|
+
try {
|
|
1816
|
+
f = await P(a.reviewed_intent, {
|
|
1817
|
+
target: {
|
|
1818
|
+
kind: "add_device",
|
|
1819
|
+
targetIdentityId: d
|
|
1820
|
+
},
|
|
1821
|
+
digest: l
|
|
1822
|
+
});
|
|
1823
|
+
} catch (t) {
|
|
1824
|
+
return t instanceof b && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
1825
|
+
}
|
|
1826
|
+
let m = await u.createInvite({
|
|
1827
|
+
groupId: s,
|
|
1828
|
+
policy: "auto_admit",
|
|
1829
|
+
expiresAt: c,
|
|
1830
|
+
createdBy: d,
|
|
1831
|
+
inviteKind: "add_device",
|
|
1832
|
+
targetIdentityId: d,
|
|
1833
|
+
reviewedPreviewDigest: l,
|
|
1834
|
+
reviewedIntent: f
|
|
1835
|
+
}), h = {
|
|
1836
|
+
v: 1,
|
|
1837
|
+
kind: "add_device",
|
|
1838
|
+
coordinator_url: new URL(e.req.url).origin,
|
|
1839
|
+
group_id: s,
|
|
1840
|
+
policy: m.policy,
|
|
1841
|
+
token: String(m.token ?? ""),
|
|
1842
|
+
expires_at: m.expires_at,
|
|
1843
|
+
team_name: m.team_name_snapshot ?? null,
|
|
1844
|
+
target_identity_id: m.target_identity_id ?? void 0,
|
|
1845
|
+
reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
|
|
1846
|
+
}, g = K(h), { token: _, ...v } = m;
|
|
1847
|
+
return e.json({
|
|
1848
|
+
ok: !0,
|
|
1849
|
+
invite: v,
|
|
1850
|
+
payload: h,
|
|
1851
|
+
encoded: g,
|
|
1852
|
+
link: q(g)
|
|
1853
|
+
});
|
|
1854
|
+
} finally {
|
|
1855
|
+
await u.close();
|
|
1856
|
+
}
|
|
1857
|
+
}), d.post("/v1/admin/devices", async (e) => {
|
|
1858
|
+
let r = Z(e.req.header(X), t);
|
|
1859
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1860
|
+
let i = p(e, "admin", !0);
|
|
1459
1861
|
if (i) return i;
|
|
1460
|
-
let a = await
|
|
1862
|
+
let a = await m(e);
|
|
1461
1863
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1462
|
-
let o =
|
|
1864
|
+
let o = g(a);
|
|
1463
1865
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1464
1866
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.fingerprint ?? "").trim(), u = String(o.public_key ?? "").trim(), d = String(o.display_name ?? "").trim() || null;
|
|
1465
1867
|
if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
|
|
1466
|
-
if (
|
|
1467
|
-
let
|
|
1868
|
+
if (F(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
1869
|
+
let f = n();
|
|
1468
1870
|
try {
|
|
1469
|
-
await
|
|
1871
|
+
await f.createGroup(s), await f.enrollDevice(s, {
|
|
1470
1872
|
deviceId: c,
|
|
1471
1873
|
fingerprint: l,
|
|
1472
1874
|
publicKey: u,
|
|
1473
1875
|
displayName: d
|
|
1474
1876
|
});
|
|
1475
1877
|
} finally {
|
|
1476
|
-
await
|
|
1878
|
+
await f.close();
|
|
1477
1879
|
}
|
|
1478
1880
|
return e.json({ ok: !0 });
|
|
1479
|
-
}),
|
|
1480
|
-
let r =
|
|
1481
|
-
if (!r.ok) return
|
|
1482
|
-
let i =
|
|
1881
|
+
}), d.get("/v1/admin/groups", async (e) => {
|
|
1882
|
+
let r = Z(e.req.header(X), t);
|
|
1883
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1884
|
+
let i = p(e, "admin", !0);
|
|
1483
1885
|
if (i) return i;
|
|
1484
1886
|
let a = [
|
|
1485
1887
|
"1",
|
|
@@ -1491,14 +1893,14 @@ function Be(e) {
|
|
|
1491
1893
|
} finally {
|
|
1492
1894
|
await o.close();
|
|
1493
1895
|
}
|
|
1494
|
-
}),
|
|
1495
|
-
let r =
|
|
1496
|
-
if (!r.ok) return
|
|
1497
|
-
let i =
|
|
1896
|
+
}), d.post("/v1/admin/groups", async (e) => {
|
|
1897
|
+
let r = Z(e.req.header(X), t);
|
|
1898
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1899
|
+
let i = p(e, "admin", !0);
|
|
1498
1900
|
if (i) return i;
|
|
1499
|
-
let a = await
|
|
1901
|
+
let a = await m(e);
|
|
1500
1902
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1501
|
-
let o =
|
|
1903
|
+
let o = g(a);
|
|
1502
1904
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1503
1905
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
|
|
1504
1906
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1511,14 +1913,14 @@ function Be(e) {
|
|
|
1511
1913
|
} finally {
|
|
1512
1914
|
await l.close();
|
|
1513
1915
|
}
|
|
1514
|
-
}),
|
|
1515
|
-
let r =
|
|
1516
|
-
if (!r.ok) return
|
|
1517
|
-
let i =
|
|
1916
|
+
}), d.post("/v1/admin/groups/rename", async (e) => {
|
|
1917
|
+
let r = Z(e.req.header(X), t);
|
|
1918
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1919
|
+
let i = p(e, "admin", !0);
|
|
1518
1920
|
if (i) return i;
|
|
1519
|
-
let a = await
|
|
1921
|
+
let a = await m(e);
|
|
1520
1922
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1521
|
-
let o =
|
|
1923
|
+
let o = g(a);
|
|
1522
1924
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1523
1925
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
|
|
1524
1926
|
if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
|
|
@@ -1531,14 +1933,14 @@ function Be(e) {
|
|
|
1531
1933
|
} finally {
|
|
1532
1934
|
await l.close();
|
|
1533
1935
|
}
|
|
1534
|
-
}),
|
|
1535
|
-
let r =
|
|
1536
|
-
if (!r.ok) return
|
|
1537
|
-
let i =
|
|
1936
|
+
}), d.post("/v1/admin/groups/archive", async (e) => {
|
|
1937
|
+
let r = Z(e.req.header(X), t);
|
|
1938
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1939
|
+
let i = p(e, "admin", !0);
|
|
1538
1940
|
if (i) return i;
|
|
1539
|
-
let a = await
|
|
1941
|
+
let a = await m(e);
|
|
1540
1942
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1541
|
-
let o =
|
|
1943
|
+
let o = g(a);
|
|
1542
1944
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1543
1945
|
let s = String(o.group_id ?? "").trim();
|
|
1544
1946
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1551,14 +1953,14 @@ function Be(e) {
|
|
|
1551
1953
|
} finally {
|
|
1552
1954
|
await c.close();
|
|
1553
1955
|
}
|
|
1554
|
-
}),
|
|
1555
|
-
let r =
|
|
1556
|
-
if (!r.ok) return
|
|
1557
|
-
let i =
|
|
1956
|
+
}), d.post("/v1/admin/groups/unarchive", async (e) => {
|
|
1957
|
+
let r = Z(e.req.header(X), t);
|
|
1958
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1959
|
+
let i = p(e, "admin", !0);
|
|
1558
1960
|
if (i) return i;
|
|
1559
|
-
let a = await
|
|
1961
|
+
let a = await m(e);
|
|
1560
1962
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1561
|
-
let o =
|
|
1963
|
+
let o = g(a);
|
|
1562
1964
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1563
1965
|
let s = String(o.group_id ?? "").trim();
|
|
1564
1966
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1571,16 +1973,16 @@ function Be(e) {
|
|
|
1571
1973
|
} finally {
|
|
1572
1974
|
await c.close();
|
|
1573
1975
|
}
|
|
1574
|
-
}),
|
|
1575
|
-
let r =
|
|
1576
|
-
if (!r.ok) return
|
|
1577
|
-
let i =
|
|
1976
|
+
}), d.get("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1977
|
+
let r = Z(e.req.header(X), t);
|
|
1978
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1979
|
+
let i = p(e, "admin", !0);
|
|
1578
1980
|
if (i) return i;
|
|
1579
1981
|
let a = String(e.req.param("group_id") ?? "").trim(), o = n();
|
|
1580
1982
|
try {
|
|
1581
|
-
let t = await
|
|
1983
|
+
let t = await T(o, a, e);
|
|
1582
1984
|
if (t) return t;
|
|
1583
|
-
let n =
|
|
1985
|
+
let n = S(e.req.query("include_inactive"));
|
|
1584
1986
|
return e.json({ items: await o.listScopes({
|
|
1585
1987
|
groupId: a,
|
|
1586
1988
|
includeInactive: n
|
|
@@ -1588,33 +1990,33 @@ function Be(e) {
|
|
|
1588
1990
|
} finally {
|
|
1589
1991
|
await o.close();
|
|
1590
1992
|
}
|
|
1591
|
-
}),
|
|
1592
|
-
let r =
|
|
1593
|
-
if (!r.ok) return
|
|
1594
|
-
let i =
|
|
1993
|
+
}), d.post("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1994
|
+
let r = Z(e.req.header(X), t);
|
|
1995
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1996
|
+
let i = p(e, "admin", !0);
|
|
1595
1997
|
if (i) return i;
|
|
1596
|
-
let a = await
|
|
1998
|
+
let a = await m(e);
|
|
1597
1999
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1598
|
-
let o =
|
|
2000
|
+
let o = g(a);
|
|
1599
2001
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1600
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c =
|
|
2002
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = _(o, "scope_id"), l = _(o, "label"), u = x(o, "membership_epoch");
|
|
1601
2003
|
if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
|
|
1602
2004
|
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1603
2005
|
let d = n();
|
|
1604
2006
|
try {
|
|
1605
|
-
let t = await
|
|
2007
|
+
let t = await T(d, s, e);
|
|
1606
2008
|
if (t) return t;
|
|
1607
2009
|
let n = await d.createScope({
|
|
1608
2010
|
scopeId: c,
|
|
1609
2011
|
label: l,
|
|
1610
|
-
kind:
|
|
1611
|
-
authorityType:
|
|
1612
|
-
coordinatorId:
|
|
2012
|
+
kind: _(o, "kind"),
|
|
2013
|
+
authorityType: _(o, "authority_type"),
|
|
2014
|
+
coordinatorId: _(o, "coordinator_id"),
|
|
1613
2015
|
groupId: s,
|
|
1614
|
-
manifestIssuerDeviceId:
|
|
2016
|
+
manifestIssuerDeviceId: _(o, "manifest_issuer_device_id"),
|
|
1615
2017
|
membershipEpoch: u,
|
|
1616
|
-
manifestHash:
|
|
1617
|
-
status:
|
|
2018
|
+
manifestHash: _(o, "manifest_hash"),
|
|
2019
|
+
status: _(o, "status")
|
|
1618
2020
|
});
|
|
1619
2021
|
return e.json({
|
|
1620
2022
|
ok: !0,
|
|
@@ -1625,33 +2027,33 @@ function Be(e) {
|
|
|
1625
2027
|
} finally {
|
|
1626
2028
|
await d.close();
|
|
1627
2029
|
}
|
|
1628
|
-
}),
|
|
1629
|
-
let r =
|
|
1630
|
-
if (!r.ok) return
|
|
1631
|
-
let i =
|
|
2030
|
+
}), d.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
|
|
2031
|
+
let r = Z(e.req.header(X), t);
|
|
2032
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2033
|
+
let i = p(e, "admin", !0);
|
|
1632
2034
|
if (i) return i;
|
|
1633
|
-
let a = await
|
|
2035
|
+
let a = await m(e);
|
|
1634
2036
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1635
|
-
let o =
|
|
2037
|
+
let o = g(a);
|
|
1636
2038
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1637
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l =
|
|
2039
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = x(o, "membership_epoch");
|
|
1638
2040
|
if (!c) return e.json({ error: "scope_id_required" }, 400);
|
|
1639
2041
|
if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1640
2042
|
let u = n();
|
|
1641
2043
|
try {
|
|
1642
|
-
let t = await
|
|
2044
|
+
let t = await E(u, s, c, e);
|
|
1643
2045
|
if (t.response) return t.response;
|
|
1644
2046
|
let n = await u.updateScope({
|
|
1645
2047
|
scopeId: c,
|
|
1646
|
-
label: o.label === void 0 ? void 0 :
|
|
1647
|
-
kind: o.kind === void 0 ? void 0 :
|
|
1648
|
-
authorityType: o.authority_type === void 0 ? void 0 :
|
|
1649
|
-
coordinatorId: o.coordinator_id === void 0 ? void 0 :
|
|
2048
|
+
label: o.label === void 0 ? void 0 : _(o, "label"),
|
|
2049
|
+
kind: o.kind === void 0 ? void 0 : _(o, "kind"),
|
|
2050
|
+
authorityType: o.authority_type === void 0 ? void 0 : _(o, "authority_type"),
|
|
2051
|
+
coordinatorId: o.coordinator_id === void 0 ? void 0 : _(o, "coordinator_id"),
|
|
1650
2052
|
groupId: s,
|
|
1651
|
-
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 :
|
|
2053
|
+
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : _(o, "manifest_issuer_device_id"),
|
|
1652
2054
|
membershipEpoch: l,
|
|
1653
|
-
manifestHash: o.manifest_hash === void 0 ? void 0 :
|
|
1654
|
-
status: o.status === void 0 ? void 0 :
|
|
2055
|
+
manifestHash: o.manifest_hash === void 0 ? void 0 : _(o, "manifest_hash"),
|
|
2056
|
+
status: o.status === void 0 ? void 0 : _(o, "status")
|
|
1655
2057
|
});
|
|
1656
2058
|
return n ? e.json({
|
|
1657
2059
|
ok: !0,
|
|
@@ -1662,108 +2064,116 @@ function Be(e) {
|
|
|
1662
2064
|
} finally {
|
|
1663
2065
|
await u.close();
|
|
1664
2066
|
}
|
|
1665
|
-
}),
|
|
1666
|
-
let r =
|
|
1667
|
-
if (!r.ok) return
|
|
1668
|
-
let i =
|
|
2067
|
+
}), d.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2068
|
+
let r = Z(e.req.header(X), t);
|
|
2069
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2070
|
+
let i = p(e, "admin", !0);
|
|
1669
2071
|
if (i) return i;
|
|
1670
2072
|
let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
|
|
1671
2073
|
try {
|
|
1672
|
-
let t = await
|
|
1673
|
-
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o,
|
|
2074
|
+
let t = await E(s, a, o, e);
|
|
2075
|
+
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, S(e.req.query("include_revoked"))) });
|
|
1674
2076
|
} finally {
|
|
1675
2077
|
await s.close();
|
|
1676
2078
|
}
|
|
1677
|
-
}),
|
|
1678
|
-
let
|
|
1679
|
-
if (!
|
|
1680
|
-
let
|
|
1681
|
-
if (
|
|
1682
|
-
let
|
|
1683
|
-
if (
|
|
1684
|
-
let
|
|
1685
|
-
if (!
|
|
1686
|
-
let
|
|
1687
|
-
if (!
|
|
1688
|
-
if (
|
|
1689
|
-
|
|
2079
|
+
}), d.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2080
|
+
let i = Z(e.req.header(X), t);
|
|
2081
|
+
if (!i.ok) return p(e, e.req.path, !1) ?? e.json({ error: i.error }, 401);
|
|
2082
|
+
let a = p(e, "admin", !0);
|
|
2083
|
+
if (a) return a;
|
|
2084
|
+
let o = await m(e);
|
|
2085
|
+
if (o == null) return e.json({ error: "body_too_large" }, 413);
|
|
2086
|
+
let s = g(o);
|
|
2087
|
+
if (!s) return e.json({ error: "invalid_json" }, 400);
|
|
2088
|
+
let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = _(s, "effect_id"), d = _(s, "device_id"), f = x(s, "membership_epoch");
|
|
2089
|
+
if (!u) return e.json({ error: "effect_id_required" }, 400);
|
|
2090
|
+
if (!d) return e.json({ error: "device_id_required" }, 400);
|
|
2091
|
+
if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2092
|
+
let h = n();
|
|
1690
2093
|
try {
|
|
1691
|
-
let t = await
|
|
2094
|
+
let t = await E(h, c, l, e);
|
|
1692
2095
|
if (t.response) return t.response;
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
signedManifestJson: h(o, "signed_manifest_json"),
|
|
2096
|
+
let n = await h.grantScopeMembership({
|
|
2097
|
+
effectId: u,
|
|
2098
|
+
scopeId: l,
|
|
2099
|
+
deviceId: d,
|
|
2100
|
+
role: _(s, "role"),
|
|
2101
|
+
membershipEpoch: f,
|
|
2102
|
+
coordinatorId: _(s, "coordinator_id"),
|
|
2103
|
+
groupId: c,
|
|
2104
|
+
manifestIssuerDeviceId: _(s, "manifest_issuer_device_id"),
|
|
2105
|
+
manifestHash: _(s, "manifest_hash"),
|
|
2106
|
+
signedManifestJson: _(s, "signed_manifest_json"),
|
|
1705
2107
|
actorType: "admin",
|
|
1706
|
-
actorId:
|
|
2108
|
+
actorId: y(e.req.header(Ot))
|
|
1707
2109
|
});
|
|
1708
2110
|
return e.json({
|
|
1709
2111
|
ok: !0,
|
|
1710
2112
|
membership: n
|
|
1711
2113
|
}, 201);
|
|
1712
2114
|
} catch (t) {
|
|
1713
|
-
|
|
2115
|
+
let n = t instanceof Error ? t.message : String(t);
|
|
2116
|
+
if (t instanceof r && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
|
|
2117
|
+
if (t instanceof r && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
|
|
2118
|
+
let i = t instanceof r && t.code === "scope_inactive";
|
|
2119
|
+
return e.json({ error: i ? "scope_not_active" : n }, n === "scope_membership_effect_conflict" || i ? 409 : 400);
|
|
1714
2120
|
} finally {
|
|
1715
|
-
await
|
|
2121
|
+
await h.close();
|
|
1716
2122
|
}
|
|
1717
|
-
}),
|
|
1718
|
-
let
|
|
1719
|
-
if (!
|
|
1720
|
-
let
|
|
1721
|
-
if (
|
|
1722
|
-
let
|
|
1723
|
-
if (
|
|
1724
|
-
let
|
|
1725
|
-
if (!
|
|
1726
|
-
let
|
|
1727
|
-
if (!
|
|
1728
|
-
if (
|
|
1729
|
-
|
|
2123
|
+
}), d.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
|
|
2124
|
+
let i = Z(e.req.header(X), t);
|
|
2125
|
+
if (!i.ok) return p(e, e.req.path, !1) ?? e.json({ error: i.error }, 401);
|
|
2126
|
+
let a = p(e, "admin", !0);
|
|
2127
|
+
if (a) return a;
|
|
2128
|
+
let o = await m(e);
|
|
2129
|
+
if (o == null) return e.json({ error: "body_too_large" }, 413);
|
|
2130
|
+
let s = o.byteLength > 0 ? g(o) : {};
|
|
2131
|
+
if (!s) return e.json({ error: "invalid_json" }, 400);
|
|
2132
|
+
let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = String(e.req.param("device_id") ?? "").trim(), d = _(s, "effect_id"), f = x(s, "membership_epoch");
|
|
2133
|
+
if (!d) return e.json({ error: "effect_id_required" }, 400);
|
|
2134
|
+
if (!u) return e.json({ error: "device_id_required" }, 400);
|
|
2135
|
+
if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2136
|
+
let h = n();
|
|
1730
2137
|
try {
|
|
1731
|
-
let t = await
|
|
2138
|
+
let t = await E(h, c, l, e);
|
|
1732
2139
|
if (t.response) return t.response;
|
|
1733
|
-
if (!await
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
2140
|
+
if (!await h.revokeScopeMembership({
|
|
2141
|
+
effectId: d,
|
|
2142
|
+
scopeId: l,
|
|
2143
|
+
deviceId: u,
|
|
2144
|
+
groupId: c,
|
|
2145
|
+
membershipEpoch: f,
|
|
2146
|
+
manifestHash: _(s, "manifest_hash"),
|
|
2147
|
+
signedManifestJson: _(s, "signed_manifest_json"),
|
|
1739
2148
|
actorType: "admin",
|
|
1740
|
-
actorId:
|
|
2149
|
+
actorId: y(e.req.header(Ot))
|
|
1741
2150
|
})) return e.json({ error: "membership_not_found" }, 404);
|
|
1742
2151
|
let n;
|
|
1743
2152
|
try {
|
|
1744
|
-
n = (await
|
|
2153
|
+
n = (await h.listScopeMemberships(l, !0)).find((e) => e.device_id === u);
|
|
1745
2154
|
} catch {
|
|
1746
2155
|
n = void 0;
|
|
1747
2156
|
}
|
|
1748
2157
|
return e.json({
|
|
1749
2158
|
ok: !0,
|
|
1750
|
-
scope_id:
|
|
1751
|
-
device_id:
|
|
1752
|
-
revocation:
|
|
1753
|
-
scopeId:
|
|
1754
|
-
deviceId:
|
|
1755
|
-
membershipEpoch: n?.membership_epoch ??
|
|
2159
|
+
scope_id: l,
|
|
2160
|
+
device_id: u,
|
|
2161
|
+
revocation: Et({
|
|
2162
|
+
scopeId: l,
|
|
2163
|
+
deviceId: u,
|
|
2164
|
+
membershipEpoch: n?.membership_epoch ?? f
|
|
1756
2165
|
})
|
|
1757
2166
|
});
|
|
1758
2167
|
} catch (t) {
|
|
1759
|
-
|
|
2168
|
+
let n = t instanceof Error ? t.message : String(t);
|
|
2169
|
+
return t instanceof r && t.code === "scope_group_mismatch" ? e.json({ error: "scope_not_found" }, 404) : e.json({ error: n }, n === "scope_membership_effect_conflict" ? 409 : 400);
|
|
1760
2170
|
} finally {
|
|
1761
|
-
await
|
|
2171
|
+
await h.close();
|
|
1762
2172
|
}
|
|
1763
|
-
}),
|
|
1764
|
-
let r =
|
|
1765
|
-
if (!r.ok) return
|
|
1766
|
-
let i =
|
|
2173
|
+
}), d.get("/v1/admin/devices", async (e) => {
|
|
2174
|
+
let r = Z(e.req.header(X), t);
|
|
2175
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2176
|
+
let i = p(e, "admin", !0);
|
|
1767
2177
|
if (i) return i;
|
|
1768
2178
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
1769
2179
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1777,14 +2187,14 @@ function Be(e) {
|
|
|
1777
2187
|
} finally {
|
|
1778
2188
|
await s.close();
|
|
1779
2189
|
}
|
|
1780
|
-
}),
|
|
1781
|
-
let r =
|
|
1782
|
-
if (!r.ok) return
|
|
1783
|
-
let i =
|
|
2190
|
+
}), d.post("/v1/admin/devices/rename", async (e) => {
|
|
2191
|
+
let r = Z(e.req.header(X), t);
|
|
2192
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2193
|
+
let i = p(e, "admin", !0);
|
|
1784
2194
|
if (i) return i;
|
|
1785
|
-
let a = await
|
|
2195
|
+
let a = await m(e);
|
|
1786
2196
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1787
|
-
let o =
|
|
2197
|
+
let o = g(a);
|
|
1788
2198
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1789
2199
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
|
|
1790
2200
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -1800,14 +2210,14 @@ function Be(e) {
|
|
|
1800
2210
|
} finally {
|
|
1801
2211
|
await u.close();
|
|
1802
2212
|
}
|
|
1803
|
-
}),
|
|
1804
|
-
let r =
|
|
1805
|
-
if (!r.ok) return
|
|
1806
|
-
let i =
|
|
2213
|
+
}), d.post("/v1/admin/devices/disable", async (e) => {
|
|
2214
|
+
let r = Z(e.req.header(X), t);
|
|
2215
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2216
|
+
let i = p(e, "admin", !0);
|
|
1807
2217
|
if (i) return i;
|
|
1808
|
-
let a = await
|
|
2218
|
+
let a = await m(e);
|
|
1809
2219
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1810
|
-
let o =
|
|
2220
|
+
let o = g(a);
|
|
1811
2221
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1812
2222
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1813
2223
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -1817,14 +2227,14 @@ function Be(e) {
|
|
|
1817
2227
|
} finally {
|
|
1818
2228
|
await l.close();
|
|
1819
2229
|
}
|
|
1820
|
-
}),
|
|
1821
|
-
let r =
|
|
1822
|
-
if (!r.ok) return
|
|
1823
|
-
let i =
|
|
2230
|
+
}), d.post("/v1/admin/devices/enable", async (e) => {
|
|
2231
|
+
let r = Z(e.req.header(X), t);
|
|
2232
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2233
|
+
let i = p(e, "admin", !0);
|
|
1824
2234
|
if (i) return i;
|
|
1825
|
-
let a = await
|
|
2235
|
+
let a = await m(e);
|
|
1826
2236
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1827
|
-
let o =
|
|
2237
|
+
let o = g(a);
|
|
1828
2238
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1829
2239
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1830
2240
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -1834,14 +2244,14 @@ function Be(e) {
|
|
|
1834
2244
|
} finally {
|
|
1835
2245
|
await l.close();
|
|
1836
2246
|
}
|
|
1837
|
-
}),
|
|
1838
|
-
let r =
|
|
1839
|
-
if (!r.ok) return
|
|
1840
|
-
let i =
|
|
2247
|
+
}), d.post("/v1/admin/devices/remove", async (e) => {
|
|
2248
|
+
let r = Z(e.req.header(X), t);
|
|
2249
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2250
|
+
let i = p(e, "admin", !0);
|
|
1841
2251
|
if (i) return i;
|
|
1842
|
-
let a = await
|
|
2252
|
+
let a = await m(e);
|
|
1843
2253
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1844
|
-
let o =
|
|
2254
|
+
let o = g(a);
|
|
1845
2255
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1846
2256
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1847
2257
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -1851,52 +2261,193 @@ function Be(e) {
|
|
|
1851
2261
|
} finally {
|
|
1852
2262
|
await l.close();
|
|
1853
2263
|
}
|
|
1854
|
-
}),
|
|
1855
|
-
let r =
|
|
1856
|
-
if (!r.ok) return
|
|
1857
|
-
let i =
|
|
2264
|
+
}), d.post("/v1/admin/invites", async (e) => {
|
|
2265
|
+
let r = Z(e.req.header(X), t);
|
|
2266
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2267
|
+
let i = p(e, "admin", !0);
|
|
1858
2268
|
if (i) return i;
|
|
1859
|
-
let a = await
|
|
2269
|
+
let a = await m(e);
|
|
1860
2270
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1861
|
-
let o =
|
|
2271
|
+
let o = g(a);
|
|
1862
2272
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1863
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null;
|
|
2273
|
+
let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null, d = String(o.operation_id ?? "").trim() || null, f = String(o.reviewed_project_set_digest ?? "").trim() || null, _ = String(o.inviter_actor_id ?? "").trim() || null, y = String(o.inviter_display_name ?? "").trim() || null, x = String(o.inviter_device_id ?? "").trim() || null, S = String(o.pending_person_id ?? "").trim() || null, C = String(o.invite_kind ?? o.kind ?? "").trim(), w = String(o.policy_team_id ?? "").trim() || null, T = String(o.target_identity_id ?? "").trim() || null, E = String(o.reviewed_preview_digest ?? "").trim() || null, D, O = null, k = null;
|
|
1864
2274
|
if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
|
|
2275
|
+
if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
|
|
1865
2276
|
if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
|
|
1866
|
-
|
|
2277
|
+
if (!!d != !!f) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
|
|
2278
|
+
let A = C || (d ? "project_share" : "legacy_enrollment");
|
|
2279
|
+
if (![
|
|
2280
|
+
"legacy_enrollment",
|
|
2281
|
+
"project_share",
|
|
2282
|
+
"team_member",
|
|
2283
|
+
"add_device"
|
|
2284
|
+
].includes(A)) return e.json({ error: "invite_kind_invalid" }, 400);
|
|
2285
|
+
if (A === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
|
|
2286
|
+
if (E && !/^[a-f0-9]{64}$/u.test(E)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
|
|
2287
|
+
if (A === "team_member" && (!w || !E || T) || A === "add_device" && (!T || !E || w) || !["team_member", "add_device"].includes(A) && (w || T || E)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
|
|
2288
|
+
if ([w, T].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
|
|
2289
|
+
if (A === "team_member" || A === "add_device") {
|
|
2290
|
+
if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2291
|
+
try {
|
|
2292
|
+
D = await P(o.reviewed_intent, {
|
|
2293
|
+
target: A === "team_member" ? {
|
|
2294
|
+
kind: "team_member",
|
|
2295
|
+
policyTeamId: String(w)
|
|
2296
|
+
} : {
|
|
2297
|
+
kind: "add_device",
|
|
2298
|
+
targetIdentityId: String(T)
|
|
2299
|
+
},
|
|
2300
|
+
digest: String(E)
|
|
2301
|
+
});
|
|
2302
|
+
} catch (t) {
|
|
2303
|
+
return t instanceof b && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2304
|
+
}
|
|
2305
|
+
} else if (o.reviewed_intent != null) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
|
|
2306
|
+
if (d && !/^share_[a-f0-9]{40}$/u.test(d) || f && !/^[a-f0-9]{64}$/u.test(f)) return e.json({ error: "operation_intent_reference_invalid" }, 400);
|
|
2307
|
+
if (d) {
|
|
2308
|
+
if (!_ || !y || !x || !S) return e.json({ error: "project_invite_identity_context_required" }, 400);
|
|
2309
|
+
if ([
|
|
2310
|
+
_,
|
|
2311
|
+
x,
|
|
2312
|
+
S
|
|
2313
|
+
].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
|
|
2314
|
+
try {
|
|
2315
|
+
if (h(y, "inviter_display_name"), O = v(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== O.length || (k = o.project_intent.map((e, t) => {
|
|
2316
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_intent_invalid");
|
|
2317
|
+
let n = e, r = String(n.canonical_identity ?? "").trim(), i = O?.[t];
|
|
2318
|
+
if (!r || r.length > 2048 || /[\p{Cc}\p{Cf}]/u.test(r) || !i || n.display_name !== i.display_name || n.existing_memory_count !== i.existing_memory_count) throw Error("project_intent_invalid");
|
|
2319
|
+
return {
|
|
2320
|
+
canonical_identity: r,
|
|
2321
|
+
...i
|
|
2322
|
+
};
|
|
2323
|
+
}), new Set(k.map((e) => e.canonical_identity)).size !== k.length)) throw Error("project_intent_invalid");
|
|
2324
|
+
} catch (t) {
|
|
2325
|
+
return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
let j = n();
|
|
1867
2329
|
try {
|
|
1868
|
-
let t = await
|
|
2330
|
+
let t = await j.getGroup(s);
|
|
1869
2331
|
if (!t) return e.json({ error: "group_not_found" }, 404);
|
|
1870
2332
|
if (t.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
1871
|
-
let n = await
|
|
2333
|
+
let n = await j.createInvite({
|
|
1872
2334
|
groupId: s,
|
|
1873
2335
|
policy: c,
|
|
1874
2336
|
expiresAt: l,
|
|
1875
|
-
createdBy: u
|
|
2337
|
+
createdBy: u,
|
|
2338
|
+
operationId: d,
|
|
2339
|
+
reviewedProjectSetDigest: f,
|
|
2340
|
+
inviterActorId: _,
|
|
2341
|
+
inviterDisplayName: y,
|
|
2342
|
+
inviterDeviceId: x,
|
|
2343
|
+
pendingPersonId: S,
|
|
2344
|
+
projectSummaries: O,
|
|
2345
|
+
projectIntent: k,
|
|
2346
|
+
inviteKind: A,
|
|
2347
|
+
policyTeamId: w,
|
|
2348
|
+
targetIdentityId: T,
|
|
2349
|
+
reviewedPreviewDigest: E,
|
|
2350
|
+
reviewedIntent: D
|
|
1876
2351
|
}), r = {
|
|
1877
2352
|
v: 1,
|
|
1878
|
-
kind: "coordinator_team_invite",
|
|
2353
|
+
kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
|
|
1879
2354
|
coordinator_url: String(o.coordinator_url ?? "").trim(),
|
|
1880
2355
|
group_id: s,
|
|
1881
|
-
policy:
|
|
2356
|
+
policy: n.policy,
|
|
1882
2357
|
token: String(n.token ?? ""),
|
|
1883
|
-
expires_at:
|
|
1884
|
-
team_name: n.team_name_snapshot ?? null
|
|
1885
|
-
|
|
2358
|
+
expires_at: n.expires_at,
|
|
2359
|
+
team_name: n.team_name_snapshot ?? null,
|
|
2360
|
+
...n.operation_id ? {
|
|
2361
|
+
operation_id: n.operation_id,
|
|
2362
|
+
inviter_name: n.inviter_display_name ?? null,
|
|
2363
|
+
project_summaries: O ?? []
|
|
2364
|
+
} : {},
|
|
2365
|
+
...n.invite_kind === "team_member" ? {
|
|
2366
|
+
policy_team_id: n.policy_team_id ?? void 0,
|
|
2367
|
+
assigned_identity_id: n.assigned_identity_id ?? void 0,
|
|
2368
|
+
reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
|
|
2369
|
+
} : {},
|
|
2370
|
+
...n.invite_kind === "add_device" ? {
|
|
2371
|
+
target_identity_id: n.target_identity_id ?? void 0,
|
|
2372
|
+
reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
|
|
2373
|
+
} : {}
|
|
2374
|
+
}, i = K(r), { token: a, ...p } = n;
|
|
1886
2375
|
return e.json({
|
|
1887
2376
|
ok: !0,
|
|
1888
|
-
invite:
|
|
2377
|
+
invite: p,
|
|
1889
2378
|
payload: r,
|
|
1890
2379
|
encoded: i,
|
|
1891
|
-
link:
|
|
2380
|
+
link: q(i)
|
|
1892
2381
|
});
|
|
2382
|
+
} catch (t) {
|
|
2383
|
+
if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
|
|
2384
|
+
if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
|
|
2385
|
+
throw t;
|
|
1893
2386
|
} finally {
|
|
1894
|
-
await
|
|
2387
|
+
await j.close();
|
|
2388
|
+
}
|
|
2389
|
+
}), d.post("/v1/invites/inspect", async (e) => {
|
|
2390
|
+
let r = await m(e);
|
|
2391
|
+
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
2392
|
+
let i = g(r);
|
|
2393
|
+
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
2394
|
+
let a = String(i.token ?? "").trim();
|
|
2395
|
+
if (!a) return e.json({ error: "invite_invalid" }, 404);
|
|
2396
|
+
let o = n();
|
|
2397
|
+
try {
|
|
2398
|
+
let n = await o.getInviteByTokenForInspection(a);
|
|
2399
|
+
if (!n || n.revoked_at) return e.json({ error: "invite_invalid" }, 404);
|
|
2400
|
+
if (n.invite_kind === "team_member" || n.invite_kind === "add_device") try {
|
|
2401
|
+
let n = await o.inspectRecipientInvite({
|
|
2402
|
+
token: a,
|
|
2403
|
+
now: t.now()
|
|
2404
|
+
});
|
|
2405
|
+
return n ? e.json(n.kind === "team_member" ? {
|
|
2406
|
+
kind: n.kind,
|
|
2407
|
+
policy_team_id: n.policy_team_id,
|
|
2408
|
+
assigned_identity_id: n.assigned_identity_id,
|
|
2409
|
+
reviewed_preview_digest: n.reviewed_preview_digest,
|
|
2410
|
+
reviewed_intent: n.reviewed_intent,
|
|
2411
|
+
bound: n.bound
|
|
2412
|
+
} : {
|
|
2413
|
+
kind: n.kind,
|
|
2414
|
+
target_identity_id: n.target_identity_id,
|
|
2415
|
+
reviewed_preview_digest: n.reviewed_preview_digest,
|
|
2416
|
+
reviewed_intent: n.reviewed_intent,
|
|
2417
|
+
bound: n.bound
|
|
2418
|
+
}) : e.json({ error: "invite_invalid" }, 404);
|
|
2419
|
+
} catch (t) {
|
|
2420
|
+
let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
|
|
2421
|
+
return e.json({ error: n }, r);
|
|
2422
|
+
}
|
|
2423
|
+
let r = !!(n.operation_id || n.reviewed_project_set_digest);
|
|
2424
|
+
if (new Date(n.expires_at) <= new Date(t.now()) && (!r || !n.consumed_at)) return e.json({ error: "invite_expired" }, 410);
|
|
2425
|
+
if (!n.operation_id) return e.json({
|
|
2426
|
+
kind: "legacy_team_invite",
|
|
2427
|
+
team_name: n.team_name_snapshot
|
|
2428
|
+
});
|
|
2429
|
+
if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
|
|
2430
|
+
let i;
|
|
2431
|
+
try {
|
|
2432
|
+
i = w(n.project_summaries_json);
|
|
2433
|
+
} catch {
|
|
2434
|
+
return e.json({ error: "invite_invalid" }, 409);
|
|
2435
|
+
}
|
|
2436
|
+
return e.json({
|
|
2437
|
+
kind: "project_share_invite",
|
|
2438
|
+
operation_id: n.operation_id,
|
|
2439
|
+
inviter_name: n.inviter_display_name,
|
|
2440
|
+
team_name: n.team_name_snapshot,
|
|
2441
|
+
projects: i,
|
|
2442
|
+
bound: !!n.consumed_at
|
|
2443
|
+
});
|
|
2444
|
+
} finally {
|
|
2445
|
+
await o.close();
|
|
1895
2446
|
}
|
|
1896
|
-
}),
|
|
1897
|
-
let r =
|
|
1898
|
-
if (!r.ok) return
|
|
1899
|
-
let i =
|
|
2447
|
+
}), d.get("/v1/admin/invites", async (e) => {
|
|
2448
|
+
let r = Z(e.req.header(X), t);
|
|
2449
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2450
|
+
let i = p(e, "admin", !0);
|
|
1900
2451
|
if (i) return i;
|
|
1901
2452
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
1902
2453
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1907,10 +2458,66 @@ function Be(e) {
|
|
|
1907
2458
|
} finally {
|
|
1908
2459
|
await o.close();
|
|
1909
2460
|
}
|
|
1910
|
-
}),
|
|
1911
|
-
let r =
|
|
1912
|
-
if (!r.ok) return
|
|
1913
|
-
let i =
|
|
2461
|
+
}), d.get("/v1/admin/project-invites/:operationId", async (e) => {
|
|
2462
|
+
let r = Z(e.req.header(X), t);
|
|
2463
|
+
if (!r.ok) return e.json({ error: r.error }, 401);
|
|
2464
|
+
let i = String(e.req.param("operationId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
|
|
2465
|
+
if (!i || !a) return e.json({ error: "operation_id_and_group_id_required" }, 400);
|
|
2466
|
+
let o = n();
|
|
2467
|
+
try {
|
|
2468
|
+
let n = (await o.listInvites(a)).find((e) => e.operation_id === i);
|
|
2469
|
+
if (!n) return e.json({ error: "operation_not_found" }, 404);
|
|
2470
|
+
let r;
|
|
2471
|
+
try {
|
|
2472
|
+
r = C(n.project_intent_json);
|
|
2473
|
+
} catch {
|
|
2474
|
+
return e.json({ error: "operation_intent_invalid" }, 409);
|
|
2475
|
+
}
|
|
2476
|
+
let s = null;
|
|
2477
|
+
if (!n.consumed_at && !n.revoked_at && new Date(n.expires_at) > new Date(t.now()) && n.token && !n.token.startsWith("consumed:")) {
|
|
2478
|
+
let t = r.map((e) => ({
|
|
2479
|
+
display_name: String(e.display_name ?? ""),
|
|
2480
|
+
existing_memory_count: Number(e.existing_memory_count ?? 0)
|
|
2481
|
+
}));
|
|
2482
|
+
s = q(K({
|
|
2483
|
+
v: 1,
|
|
2484
|
+
kind: "coordinator_team_invite",
|
|
2485
|
+
coordinator_url: new URL(e.req.url).origin,
|
|
2486
|
+
group_id: n.group_id,
|
|
2487
|
+
policy: n.policy,
|
|
2488
|
+
token: n.token,
|
|
2489
|
+
expires_at: n.expires_at,
|
|
2490
|
+
team_name: n.team_name_snapshot,
|
|
2491
|
+
operation_id: i,
|
|
2492
|
+
inviter_name: n.inviter_display_name ?? null,
|
|
2493
|
+
project_summaries: t
|
|
2494
|
+
}));
|
|
2495
|
+
}
|
|
2496
|
+
return e.json({
|
|
2497
|
+
operation_id: n.operation_id,
|
|
2498
|
+
group_id: n.group_id,
|
|
2499
|
+
reviewed_project_set_digest: n.reviewed_project_set_digest,
|
|
2500
|
+
state: n.consumed_at ? "accepted" : "waiting_for_acceptance",
|
|
2501
|
+
pending_person_id: n.pending_person_id,
|
|
2502
|
+
recipient_actor_id: n.recipient_actor_id,
|
|
2503
|
+
recipient_display_name: n.recipient_display_name,
|
|
2504
|
+
recipient_device_id: n.bound_device_id,
|
|
2505
|
+
recipient_device_display_name: n.recipient_device_display_name,
|
|
2506
|
+
recipient_public_key: n.bound_public_key,
|
|
2507
|
+
recipient_fingerprint: n.bound_fingerprint,
|
|
2508
|
+
consumed_at: n.consumed_at,
|
|
2509
|
+
bootstrap_grant_id: n.bootstrap_grant_id,
|
|
2510
|
+
trust_state: n.trust_state,
|
|
2511
|
+
projects: r,
|
|
2512
|
+
invite_link: s
|
|
2513
|
+
});
|
|
2514
|
+
} finally {
|
|
2515
|
+
await o.close();
|
|
2516
|
+
}
|
|
2517
|
+
}), d.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
|
|
2518
|
+
let r = Z(e.req.header(X), t);
|
|
2519
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2520
|
+
let i = p(e, "admin", !0);
|
|
1914
2521
|
if (i) return i;
|
|
1915
2522
|
let a = String(e.req.param("grantId") ?? "").trim();
|
|
1916
2523
|
if (!a) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -1928,10 +2535,10 @@ function Be(e) {
|
|
|
1928
2535
|
} finally {
|
|
1929
2536
|
await o.close();
|
|
1930
2537
|
}
|
|
1931
|
-
}),
|
|
1932
|
-
let r =
|
|
1933
|
-
if (!r.ok) return
|
|
1934
|
-
let i =
|
|
2538
|
+
}), d.get("/v1/admin/bootstrap-grants", async (e) => {
|
|
2539
|
+
let r = Z(e.req.header(X), t);
|
|
2540
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2541
|
+
let i = p(e, "admin", !0);
|
|
1935
2542
|
if (i) return i;
|
|
1936
2543
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
1937
2544
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1941,14 +2548,14 @@ function Be(e) {
|
|
|
1941
2548
|
} finally {
|
|
1942
2549
|
await o.close();
|
|
1943
2550
|
}
|
|
1944
|
-
}),
|
|
1945
|
-
let r =
|
|
1946
|
-
if (!r.ok) return
|
|
1947
|
-
let i =
|
|
2551
|
+
}), d.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
|
|
2552
|
+
let r = Z(e.req.header(X), t);
|
|
2553
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2554
|
+
let i = p(e, "admin", !0);
|
|
1948
2555
|
if (i) return i;
|
|
1949
|
-
let a = await
|
|
2556
|
+
let a = await m(e);
|
|
1950
2557
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1951
|
-
let o =
|
|
2558
|
+
let o = g(a);
|
|
1952
2559
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1953
2560
|
let s = String(o.grant_id ?? "").trim();
|
|
1954
2561
|
if (!s) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -1961,18 +2568,18 @@ function Be(e) {
|
|
|
1961
2568
|
} finally {
|
|
1962
2569
|
await c.close();
|
|
1963
2570
|
}
|
|
1964
|
-
}),
|
|
2571
|
+
}), d.post("/v1/admin/join-requests/approve", async (e) => Ft(e, !0, {
|
|
1965
2572
|
createStore: n,
|
|
1966
2573
|
runtime: t,
|
|
1967
|
-
rateLimitedResponse:
|
|
1968
|
-
})),
|
|
2574
|
+
rateLimitedResponse: p
|
|
2575
|
+
})), d.post("/v1/admin/join-requests/deny", async (e) => Ft(e, !1, {
|
|
1969
2576
|
createStore: n,
|
|
1970
2577
|
runtime: t,
|
|
1971
|
-
rateLimitedResponse:
|
|
1972
|
-
})),
|
|
1973
|
-
let r =
|
|
1974
|
-
if (!r.ok) return
|
|
1975
|
-
let i =
|
|
2578
|
+
rateLimitedResponse: p
|
|
2579
|
+
})), d.get("/v1/admin/join-requests", async (e) => {
|
|
2580
|
+
let r = Z(e.req.header(X), t);
|
|
2581
|
+
if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2582
|
+
let i = p(e, "admin", !0);
|
|
1976
2583
|
if (i) return i;
|
|
1977
2584
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
1978
2585
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1982,36 +2589,136 @@ function Be(e) {
|
|
|
1982
2589
|
} finally {
|
|
1983
2590
|
await o.close();
|
|
1984
2591
|
}
|
|
1985
|
-
}),
|
|
1986
|
-
let r = await
|
|
2592
|
+
}), d.post("/v1/join", async (e) => {
|
|
2593
|
+
let r = await m(e);
|
|
1987
2594
|
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
1988
|
-
let i =
|
|
2595
|
+
let i = g(r);
|
|
1989
2596
|
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
1990
|
-
let a = String(i.token ?? "").trim(), o = String(i.device_id ?? "").trim(), s = String(i.fingerprint ?? "").trim(), c = String(i.public_key ?? "").trim(), l = String(i.display_name ?? "").trim() || null;
|
|
2597
|
+
let a = String(i.token ?? "").trim(), o = String(i.device_id ?? "").trim(), s = String(i.fingerprint ?? "").trim(), c = String(i.public_key ?? "").trim(), l = String(i.display_name ?? "").trim() || null, u = String(i.operation_id ?? "").trim(), d = String(i.recipient_actor_id ?? "").trim(), f = String(i.recipient_display_name ?? "").trim(), p = String(i.device_display_name ?? "").trim();
|
|
1991
2598
|
if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
|
|
1992
|
-
if (
|
|
1993
|
-
let
|
|
2599
|
+
if (F(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
2600
|
+
let _ = n();
|
|
1994
2601
|
try {
|
|
1995
|
-
let n = await
|
|
1996
|
-
if (!n) return e.json({ error: "
|
|
1997
|
-
let r =
|
|
1998
|
-
if (
|
|
1999
|
-
if (
|
|
2000
|
-
if (
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2602
|
+
let n = await _.getInviteByTokenForInspection(a);
|
|
2603
|
+
if (!n) return e.json({ error: "invite_invalid" }, 404);
|
|
2604
|
+
let r = !!(n.operation_id || n.reviewed_project_set_digest), m = n.invite_kind === "team_member" || n.invite_kind === "add_device";
|
|
2605
|
+
if (n.revoked_at) return e.json({ error: r || m ? "invite_invalid" : "revoked_token" }, 400);
|
|
2606
|
+
if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || m ? "invite_expired" : "expired_token" }, 410);
|
|
2607
|
+
if (m) {
|
|
2608
|
+
let r = new Set([
|
|
2609
|
+
"token",
|
|
2610
|
+
"invite_kind",
|
|
2611
|
+
"kind",
|
|
2612
|
+
"identity_id",
|
|
2613
|
+
"device_id",
|
|
2614
|
+
"public_key",
|
|
2615
|
+
"fingerprint"
|
|
2616
|
+
]);
|
|
2617
|
+
if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_recipient_invite_fields" }, 400);
|
|
2618
|
+
let l = String(i.invite_kind ?? i.kind ?? "").trim(), u = String(i.identity_id ?? "").trim();
|
|
2619
|
+
if (!u || l !== n.invite_kind) return e.json({ error: "recipient_invite_binding_required" }, 400);
|
|
2620
|
+
if (u.length > 256 || /[\p{Cc}\p{Cf}]/u.test(u)) return e.json({ error: "identity_id_invalid" }, 400);
|
|
2621
|
+
try {
|
|
2622
|
+
let r = await _.consumeRecipientInvite({
|
|
2623
|
+
token: a,
|
|
2624
|
+
inviteKind: n.invite_kind,
|
|
2625
|
+
identityId: u,
|
|
2626
|
+
deviceId: o,
|
|
2627
|
+
publicKey: c,
|
|
2628
|
+
fingerprint: s,
|
|
2629
|
+
now: t.now()
|
|
2630
|
+
});
|
|
2631
|
+
return e.json({
|
|
2632
|
+
ok: !0,
|
|
2633
|
+
status: r.status,
|
|
2634
|
+
kind: r.invite.invite_kind,
|
|
2635
|
+
group_id: r.invite.group_id,
|
|
2636
|
+
identity_id: r.invite.recipient_actor_id,
|
|
2637
|
+
policy_team_id: r.invite.policy_team_id ?? null,
|
|
2638
|
+
target_identity_id: r.invite.target_identity_id ?? null,
|
|
2639
|
+
assigned_identity_id: r.invite.assigned_identity_id ?? null,
|
|
2640
|
+
reviewed_preview_digest: r.invite.reviewed_preview_digest,
|
|
2641
|
+
reviewed_intent: r.reviewed_intent
|
|
2642
|
+
});
|
|
2643
|
+
} catch (t) {
|
|
2644
|
+
let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
|
|
2645
|
+
return e.json({ error: n }, r);
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
if (n.operation_id || n.reviewed_project_set_digest) {
|
|
2649
|
+
let r = new Set([
|
|
2650
|
+
"token",
|
|
2651
|
+
"operation_id",
|
|
2652
|
+
"device_id",
|
|
2653
|
+
"public_key",
|
|
2654
|
+
"fingerprint",
|
|
2655
|
+
"display_name",
|
|
2656
|
+
"recipient_actor_id",
|
|
2657
|
+
"recipient_display_name",
|
|
2658
|
+
"device_display_name"
|
|
2659
|
+
]);
|
|
2660
|
+
if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
2661
|
+
if (!u || !d || !f || !p) return e.json({ error: "project_invite_identity_required" }, 400);
|
|
2662
|
+
if (String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "project_invite_self_acceptance_forbidden" }, 409);
|
|
2663
|
+
if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
|
|
2664
|
+
let l, m;
|
|
2665
|
+
try {
|
|
2666
|
+
l = h(f, "recipient_display_name"), m = h(p, "device_display_name");
|
|
2667
|
+
} catch (t) {
|
|
2668
|
+
return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
|
|
2669
|
+
}
|
|
2670
|
+
try {
|
|
2671
|
+
let n = await _.consumeProjectInvite({
|
|
2672
|
+
token: a,
|
|
2673
|
+
operationId: u,
|
|
2674
|
+
deviceId: o,
|
|
2675
|
+
publicKey: c,
|
|
2676
|
+
fingerprint: s,
|
|
2677
|
+
recipientActorId: d,
|
|
2678
|
+
recipientDisplayName: l,
|
|
2679
|
+
deviceDisplayName: m,
|
|
2680
|
+
now: t.now()
|
|
2681
|
+
});
|
|
2682
|
+
return e.json({
|
|
2683
|
+
ok: !0,
|
|
2684
|
+
status: mt,
|
|
2685
|
+
group_id: n.invite.group_id,
|
|
2686
|
+
operation_id: n.invite.operation_id,
|
|
2687
|
+
trust_state: n.invite.trust_state,
|
|
2688
|
+
bootstrap_grant_id: n.bootstrap_grant?.grant_id ?? null,
|
|
2689
|
+
inviter_device: n.seed_enrollment ? {
|
|
2690
|
+
device_id: n.seed_enrollment.device_id,
|
|
2691
|
+
public_key: n.seed_enrollment.public_key,
|
|
2692
|
+
fingerprint: n.seed_enrollment.fingerprint,
|
|
2693
|
+
display_name: n.seed_enrollment.display_name
|
|
2694
|
+
} : null
|
|
2695
|
+
});
|
|
2696
|
+
} catch (t) {
|
|
2697
|
+
let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
|
|
2698
|
+
return e.json({ error: n }, r);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
if ([
|
|
2702
|
+
"operation_id",
|
|
2703
|
+
"recipient_actor_id",
|
|
2704
|
+
"recipient_display_name",
|
|
2705
|
+
"device_display_name"
|
|
2706
|
+
].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
2707
|
+
let g = await _.getGroup(String(n.group_id));
|
|
2708
|
+
if (!g) return e.json({ error: "group_not_found" }, 404);
|
|
2709
|
+
if (g.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
2710
|
+
let v = String(n.group_id);
|
|
2711
|
+
if (await _.getEnrollment(v, o)) return e.json({
|
|
2005
2712
|
ok: !0,
|
|
2006
2713
|
status: "already_enrolled",
|
|
2007
2714
|
group_id: n.group_id,
|
|
2008
2715
|
policy: n.policy
|
|
2009
2716
|
});
|
|
2010
|
-
let
|
|
2011
|
-
if (!["auto_admit", "approval_required"].includes(
|
|
2012
|
-
if (
|
|
2013
|
-
let t = await
|
|
2014
|
-
groupId:
|
|
2717
|
+
let y = String(n.policy);
|
|
2718
|
+
if (!["auto_admit", "approval_required"].includes(y)) return e.json({ error: `unknown invite policy: ${y}` }, 400);
|
|
2719
|
+
if (y === "approval_required") {
|
|
2720
|
+
let t = await _.createJoinRequest({
|
|
2721
|
+
groupId: v,
|
|
2015
2722
|
deviceId: o,
|
|
2016
2723
|
publicKey: c,
|
|
2017
2724
|
fingerprint: s,
|
|
@@ -2026,7 +2733,7 @@ function Be(e) {
|
|
|
2026
2733
|
request_id: t.request_id
|
|
2027
2734
|
});
|
|
2028
2735
|
}
|
|
2029
|
-
return await
|
|
2736
|
+
return await _.enrollDevice(v, {
|
|
2030
2737
|
deviceId: o,
|
|
2031
2738
|
fingerprint: s,
|
|
2032
2739
|
publicKey: c,
|
|
@@ -2038,12 +2745,12 @@ function Be(e) {
|
|
|
2038
2745
|
policy: n.policy
|
|
2039
2746
|
});
|
|
2040
2747
|
} finally {
|
|
2041
|
-
await
|
|
2748
|
+
await _.close();
|
|
2042
2749
|
}
|
|
2043
|
-
}),
|
|
2750
|
+
}), d;
|
|
2044
2751
|
}
|
|
2045
|
-
async function
|
|
2046
|
-
let r =
|
|
2752
|
+
async function Ft(e, t, n) {
|
|
2753
|
+
let r = Z(e.req.header(X), n.runtime);
|
|
2047
2754
|
if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2048
2755
|
let i = n.rateLimitedResponse(e, "admin", !0);
|
|
2049
2756
|
if (i) return i;
|
|
@@ -2106,6 +2813,6 @@ async function Ve(e, t, n) {
|
|
|
2106
2813
|
}
|
|
2107
2814
|
}
|
|
2108
2815
|
//#endregion
|
|
2109
|
-
export {
|
|
2816
|
+
export { r as A, _ as C, f as D, v as E, s as F, o as M, l as N, u as O, a as P, P as S, h as T, b as _, Tt as a, ce as b, gt as c, ft as d, K as f, y as g, F as h, Et as i, c as j, p as k, _t as l, q as m, Dt as n, mt as o, pt as p, wt as r, ht as s, Pt as t, vt as u, oe as v, g as w, se as x, M as y };
|
|
2110
2817
|
|
|
2111
|
-
//# sourceMappingURL=coordinator-api-
|
|
2818
|
+
//# sourceMappingURL=coordinator-api-Btb6CEhw.js.map
|