@codemem/core 0.43.2 → 0.44.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attribution-diagnostics.d.ts.map +1 -1
- package/dist/better-sqlite-coordinator-store.d.ts +5 -0
- package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
- package/dist/coordinator-actions.d.ts +29 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-DGTIU3Ri.js → coordinator-api-BAufmPEa.js} +1272 -924
- package/dist/coordinator-api-BAufmPEa.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/coordinator-enrollment-reconciler.d.ts +1 -1
- package/dist/coordinator-enrollment-reconciler.d.ts.map +1 -1
- package/dist/coordinator-legacy-team-completion.d.ts +75 -0
- package/dist/coordinator-legacy-team-completion.d.ts.map +1 -0
- package/dist/coordinator-membership-effects.d.ts.map +1 -1
- package/dist/coordinator-runtime.d.ts +11 -1
- package/dist/coordinator-runtime.d.ts.map +1 -1
- package/dist/coordinator-store-contract.d.ts +11 -0
- package/dist/coordinator-store-contract.d.ts.map +1 -1
- package/dist/coordinator-store-test-harness.d.ts.map +1 -1
- package/dist/coordinator-store.d.ts +2 -0
- package/dist/coordinator-store.d.ts.map +1 -1
- package/dist/d1-coordinator-store.d.ts +5 -0
- package/dist/d1-coordinator-store.d.ts.map +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/dedup-key-backfill.d.ts.map +1 -1
- package/dist/distill.d.ts.map +1 -1
- package/dist/embeddings.d.ts +69 -6
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/export-import.d.ts.map +1 -1
- package/dist/hook-transcript.d.ts.map +1 -1
- package/dist/identity-device-assignment.d.ts.map +1 -1
- package/dist/identity-target.d.ts +3 -1
- package/dist/identity-target.d.ts.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10779 -8897
- package/dist/index.js.map +1 -1
- package/dist/ingest-pipeline.d.ts +9 -0
- package/dist/ingest-pipeline.d.ts.map +1 -1
- package/dist/internal/cloudflare-coordinator.d.ts +2 -0
- package/dist/internal/cloudflare-coordinator.d.ts.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +440 -354
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/legacy-team-candidate.d.ts.map +1 -1
- package/dist/legacy-team-setup-activation.d.ts +40 -1
- package/dist/legacy-team-setup-activation.d.ts.map +1 -1
- package/dist/legacy-team-setup-completion-manifest.d.ts +57 -0
- package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -0
- package/dist/legacy-team-setup-draft.d.ts.map +1 -1
- package/dist/legacy-team-setup-errors.d.ts +11 -2
- package/dist/legacy-team-setup-errors.d.ts.map +1 -1
- package/dist/legacy-team-setup-limits.d.ts +19 -1
- package/dist/legacy-team-setup-limits.d.ts.map +1 -1
- package/dist/memory-kinds.d.ts.map +1 -1
- package/dist/native-runtime.d.ts +12 -0
- package/dist/native-runtime.d.ts.map +1 -0
- package/dist/observer-auth.d.ts.map +1 -1
- package/dist/observer-client.d.ts.map +1 -1
- package/dist/policy-team-device-eligibility.d.ts.map +1 -1
- package/dist/project-identity.d.ts +4 -0
- package/dist/project-identity.d.ts.map +1 -0
- package/dist/project-invite-acceptance.d.ts.map +1 -1
- package/dist/project-scope-settings.d.ts.map +1 -1
- package/dist/prompt-transport.d.ts.map +1 -1
- package/dist/raw-event-flush.d.ts.map +1 -1
- package/dist/raw-event-ingest.d.ts.map +1 -1
- package/dist/raw-event-sweeper.d.ts +2 -3
- package/dist/raw-event-sweeper.d.ts.map +1 -1
- package/dist/recipient-policy-edges.d.ts.map +1 -1
- package/dist/recipient-policy-identifiers.d.ts.map +1 -1
- package/dist/recipient-policy-onboarding.d.ts.map +1 -1
- package/dist/recipient-policy-review.d.ts +6 -0
- package/dist/recipient-policy-review.d.ts.map +1 -1
- package/dist/recipient-policy-team-metadata.d.ts +7 -0
- package/dist/recipient-policy-team-metadata.d.ts.map +1 -1
- package/dist/recipient-reviewed-intent.d.ts.map +1 -1
- package/dist/ref-backfill.d.ts.map +1 -1
- package/dist/release-discovery.d.ts +4 -0
- package/dist/release-discovery.d.ts.map +1 -1
- package/dist/schema.d.ts +109 -109
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-backfill.d.ts.map +1 -1
- package/dist/scope-resolution.d.ts.map +1 -1
- package/dist/secret-scanner.d.ts.map +1 -1
- package/dist/session-context-backfill.d.ts.map +1 -1
- package/dist/store.d.ts +9 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/summary-dedup-backfill.d.ts.map +1 -1
- package/dist/sync-capability.d.ts.map +1 -1
- package/dist/sync-daemon.d.ts +15 -0
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-identity.d.ts.map +1 -1
- package/dist/sync-retention-runner.d.ts.map +1 -1
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/dist/vector-migration.d.ts +1 -0
- package/dist/vector-migration.d.ts.map +1 -1
- package/dist/vectors.d.ts +42 -3
- package/dist/vectors.d.ts.map +1 -1
- package/package.json +18 -10
- package/dist/coordinator-api-DGTIU3Ri.js.map +0 -1
|
@@ -1,57 +1,338 @@
|
|
|
1
1
|
import { resolve as e } from "node:path";
|
|
2
2
|
import { createHash as t } from "node:crypto";
|
|
3
|
+
function n(e) {
|
|
4
|
+
if (e.devices.length > 500 || e.projects.length > 500 || e.devices.length * e.projects.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
|
|
5
|
+
}
|
|
6
|
+
function r(e) {
|
|
7
|
+
if (e.projectIdentities.size * e.deviceCount > 1e4) throw Error("legacy_team_setup_roster_too_large");
|
|
8
|
+
}
|
|
9
|
+
function i(e, t, n) {
|
|
10
|
+
if (n.length === 0) return;
|
|
11
|
+
let r = Number(e.prepare("SELECT COUNT(*) FROM identity_devices").pluck().get() ?? 0);
|
|
12
|
+
if ((t.length + r) * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
|
|
13
|
+
}
|
|
14
|
+
function a(e, t, n, r) {
|
|
15
|
+
if (!r) return;
|
|
16
|
+
let i = [...new Set(t.map((e) => e.deviceId))], a = i.map(() => "?").join(", "), o = a ? `AND device_id NOT IN (${a})` : "", s = Number(e.prepare(`SELECT COUNT(*) FROM legacy_team_setup_draft_devices
|
|
17
|
+
WHERE attempt_id = ? ${o}`).pluck().get(r, ...i) ?? 0), c = t.length + s;
|
|
18
|
+
if (c > 500 || c * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/recipient-policy-identifiers.ts
|
|
22
|
+
function o(e, t) {
|
|
23
|
+
return e < t ? -1 : +(e > t);
|
|
24
|
+
}
|
|
25
|
+
var s = /[\p{Cc}\p{Cf}]/u;
|
|
26
|
+
function c(e, t) {
|
|
27
|
+
return typeof e == "string" && e.length > 0 && e === e.trim() && e.length <= t && !s.test(e);
|
|
28
|
+
}
|
|
29
|
+
function l(e) {
|
|
30
|
+
return c(e, 256);
|
|
31
|
+
}
|
|
32
|
+
function u(e) {
|
|
33
|
+
return c(e, 2048);
|
|
34
|
+
}
|
|
35
|
+
var d = "Recipient policy value must be strict JSON data";
|
|
36
|
+
function f() {
|
|
37
|
+
throw TypeError(d);
|
|
38
|
+
}
|
|
39
|
+
function p(e) {
|
|
40
|
+
let t = JSON.stringify(e);
|
|
41
|
+
return t === void 0 ? f() : t;
|
|
42
|
+
}
|
|
43
|
+
function m(e, t) {
|
|
44
|
+
if (e === null) return "null";
|
|
45
|
+
if (typeof e == "boolean") return e ? "true" : "false";
|
|
46
|
+
if (typeof e == "string") return p(e);
|
|
47
|
+
if (typeof e == "number") return !Number.isFinite(e) || Object.is(e, -0) ? f() : String(e);
|
|
48
|
+
if (typeof e != "object" || t.has(e)) return f();
|
|
49
|
+
t.add(e);
|
|
50
|
+
try {
|
|
51
|
+
if (Array.isArray(e)) {
|
|
52
|
+
if (Object.getPrototypeOf(e) !== Array.prototype) return f();
|
|
53
|
+
let n = Reflect.ownKeys(e);
|
|
54
|
+
if (n.length !== e.length + 1 || n.some((e) => typeof e != "string")) return f();
|
|
55
|
+
let r = [];
|
|
56
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
57
|
+
let i = Object.getOwnPropertyDescriptor(e, String(n));
|
|
58
|
+
if (!i?.enumerable || !("value" in i)) return f();
|
|
59
|
+
r.push(m(i.value, t));
|
|
60
|
+
}
|
|
61
|
+
return `[${r.join(",")}]`;
|
|
62
|
+
}
|
|
63
|
+
let n = Object.getPrototypeOf(e);
|
|
64
|
+
return n !== Object.prototype && n !== null ? f() : `{${Reflect.ownKeys(e).map((t) => {
|
|
65
|
+
if (typeof t != "string") return f();
|
|
66
|
+
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
67
|
+
return !n?.enumerable || !("value" in n) ? f() : [t, n.value];
|
|
68
|
+
}).toSorted(([e], [t]) => o(e, t)).map(([e, n]) => `${p(e)}:${m(n, t)}`).join(",")}}`;
|
|
69
|
+
} finally {
|
|
70
|
+
t.delete(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function h(e) {
|
|
74
|
+
return m(e, /* @__PURE__ */ new WeakSet());
|
|
75
|
+
}
|
|
76
|
+
function g(e, n) {
|
|
77
|
+
if (e.includes("\0") || !e.isWellFormed()) throw TypeError("Recipient policy digest prefix must be well-formed without NUL");
|
|
78
|
+
return `${e}:${t("sha256").update(e, "utf8").update("\0", "utf8").update(h(n), "utf8").digest("hex")}`;
|
|
79
|
+
}
|
|
80
|
+
function _(e, n) {
|
|
81
|
+
return `${e}:${t("sha256").update(h(n), "utf8").digest("hex")}`;
|
|
82
|
+
}
|
|
83
|
+
var v = ["team_invite", "coordinator_invite"];
|
|
84
|
+
function y(e, n) {
|
|
85
|
+
return `legacy-team-candidate:${t("sha256").update(JSON.stringify([e, n])).digest("hex").slice(0, 32)}`;
|
|
86
|
+
}
|
|
87
|
+
function ee(e, t) {
|
|
88
|
+
return g("legacy-team-project-ref-v1", [e, t]);
|
|
89
|
+
}
|
|
90
|
+
function b(e, t) {
|
|
91
|
+
return g("legacy-team-canonical-project-ref-v1", [e, t]);
|
|
92
|
+
}
|
|
93
|
+
function x(e, t) {
|
|
94
|
+
return g("legacy-team-device-ref-v1", [e, t]);
|
|
95
|
+
}
|
|
96
|
+
function S(e) {
|
|
97
|
+
return _("policy-team-v1", e);
|
|
98
|
+
}
|
|
99
|
+
function te(e) {
|
|
100
|
+
return g("legacy-team-roster-v1", e.map((e) => ({
|
|
101
|
+
deviceId: e.deviceId,
|
|
102
|
+
fingerprint: e.fingerprint,
|
|
103
|
+
enabled: e.enabled,
|
|
104
|
+
identityId: e.identityId
|
|
105
|
+
})).toSorted((e, t) => o(e.deviceId, t.deviceId)));
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/coordinator-legacy-team-completion.ts
|
|
109
|
+
var C = 1, w = 50, T = 500, E = 15e5, ne = 25 * E, re = 256, ie = 37661024, ae = "completion_conflict", oe = class extends Error {
|
|
110
|
+
code = ae;
|
|
111
|
+
constructor() {
|
|
112
|
+
super(ae), this.name = "CoordinatorLegacyTeamCompletionConflictError";
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function D() {
|
|
116
|
+
throw Error("completion_manifest_invalid");
|
|
117
|
+
}
|
|
118
|
+
function O(e) {
|
|
119
|
+
return (!e || typeof e != "object" || Array.isArray(e)) && D(), e;
|
|
120
|
+
}
|
|
121
|
+
function k(e, t) {
|
|
122
|
+
let n = new Set(t);
|
|
123
|
+
Object.keys(e).some((e) => !n.has(e)) && D();
|
|
124
|
+
}
|
|
125
|
+
function se(e) {
|
|
126
|
+
return /^(?:[\\/]{2}|\.{1,2}[\\/]|\/|~[\\/]|[a-z]:[\\/]|file:)/iu.test(e);
|
|
127
|
+
}
|
|
128
|
+
function A(e) {
|
|
129
|
+
return (typeof e != "string" || !e || e !== e.trim() || e.length > re || /[\p{Cc}\p{Cf}]/u.test(e) || se(e)) && D(), e;
|
|
130
|
+
}
|
|
131
|
+
function j(e) {
|
|
132
|
+
let t = A(e);
|
|
133
|
+
return /^[a-f0-9]{64}$/u.test(t) || D(), t;
|
|
134
|
+
}
|
|
135
|
+
function ce(e) {
|
|
136
|
+
typeof e != "string" && D();
|
|
137
|
+
let t = e.normalize("NFC").trim();
|
|
138
|
+
return (!t || [...t].length > 120 || /[\p{Cc}\p{Cf}]/u.test(t) || se(t)) && D(), t;
|
|
139
|
+
}
|
|
140
|
+
function le(e) {
|
|
141
|
+
(typeof e != "string" || !e) && D();
|
|
142
|
+
let t = new Date(e);
|
|
143
|
+
return (Number.isNaN(t.getTime()) || t.toISOString() !== e) && D(), e;
|
|
144
|
+
}
|
|
145
|
+
function ue(e, t) {
|
|
146
|
+
return (!Array.isArray(e) || e.length > t) && D(), e;
|
|
147
|
+
}
|
|
148
|
+
function M(e, t) {
|
|
149
|
+
let n = e.toSorted((e, n) => o(t(e), t(n)));
|
|
150
|
+
return n.some((e, r) => r > 0 && t(n[r - 1]) === t(e)) && D(), n;
|
|
151
|
+
}
|
|
152
|
+
function de(e) {
|
|
153
|
+
return M(ue(e, 50).map(A), (e) => e);
|
|
154
|
+
}
|
|
155
|
+
function fe(e) {
|
|
156
|
+
let t = A(e);
|
|
157
|
+
return /^legacy-team-candidate:[a-f0-9]{32}$/u.test(t) || D(), t;
|
|
158
|
+
}
|
|
159
|
+
function pe(e) {
|
|
160
|
+
let t = O(e);
|
|
161
|
+
k(t, [
|
|
162
|
+
"version",
|
|
163
|
+
"coordinator_id",
|
|
164
|
+
"candidate_ref",
|
|
165
|
+
"candidate_digest",
|
|
166
|
+
"team_id",
|
|
167
|
+
"team_digest",
|
|
168
|
+
"source_digest",
|
|
169
|
+
"finish_digest",
|
|
170
|
+
"access_delta_digest",
|
|
171
|
+
"team",
|
|
172
|
+
"memberships",
|
|
173
|
+
"device_decisions",
|
|
174
|
+
"project_mappings",
|
|
175
|
+
"project_recipients",
|
|
176
|
+
"completed_at"
|
|
177
|
+
]), t.version !== 1 && D();
|
|
178
|
+
let n = O(t.team);
|
|
179
|
+
k(n, [
|
|
180
|
+
"display_name",
|
|
181
|
+
"policy_revision",
|
|
182
|
+
"device_eligibility_mode"
|
|
183
|
+
]), n.device_eligibility_mode !== "reviewed_allowlist" && D();
|
|
184
|
+
let r = A(t.team_id), i = M(ue(t.memberships, 500).map((e) => {
|
|
185
|
+
let t = O(e);
|
|
186
|
+
return k(t, ["identity_id", "role"]), t.role !== "member" && D(), {
|
|
187
|
+
identity_id: A(t.identity_id),
|
|
188
|
+
role: "member"
|
|
189
|
+
};
|
|
190
|
+
}), (e) => e.identity_id), a = M(ue(t.device_decisions, 500).map((e) => {
|
|
191
|
+
let t = O(e);
|
|
192
|
+
k(t, [
|
|
193
|
+
"device_id",
|
|
194
|
+
"key_fingerprint",
|
|
195
|
+
"enabled",
|
|
196
|
+
"identity_id",
|
|
197
|
+
"decision"
|
|
198
|
+
]), t.decision !== "included" && t.decision !== "excluded" && D(), typeof t.enabled != "boolean" && D();
|
|
199
|
+
let n = t.identity_id == null ? null : A(t.identity_id);
|
|
200
|
+
t.decision === "included" != !!n && D(), t.decision === "included" && !t.enabled && D();
|
|
201
|
+
let r = t.decision;
|
|
202
|
+
return {
|
|
203
|
+
device_id: A(t.device_id),
|
|
204
|
+
key_fingerprint: j(t.key_fingerprint),
|
|
205
|
+
enabled: t.enabled,
|
|
206
|
+
identity_id: n,
|
|
207
|
+
decision: r
|
|
208
|
+
};
|
|
209
|
+
}), (e) => e.device_id);
|
|
210
|
+
a.length === 0 && D();
|
|
211
|
+
let s = new Set(i.map((e) => e.identity_id)), c = new Set(a.flatMap((e) => e.identity_id ? [e.identity_id] : []));
|
|
212
|
+
(s.size !== c.size || [...c].some((e) => !s.has(e))) && D();
|
|
213
|
+
let l = M(ue(t.project_mappings, 500).map((e) => {
|
|
214
|
+
let t = O(e);
|
|
215
|
+
k(t, [
|
|
216
|
+
"project_ref",
|
|
217
|
+
"resolved_project_ref",
|
|
218
|
+
"scope_id"
|
|
219
|
+
]);
|
|
220
|
+
let n = A(t.project_ref), r = A(t.resolved_project_ref);
|
|
221
|
+
return /^legacy-team-project-ref-v1:[0-9a-f]{64}$/u.test(n) || D(), /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(r) || D(), {
|
|
222
|
+
project_ref: n,
|
|
223
|
+
resolved_project_ref: r,
|
|
224
|
+
scope_id: A(t.scope_id)
|
|
225
|
+
};
|
|
226
|
+
}), (e) => e.project_ref), u = /* @__PURE__ */ new Map();
|
|
227
|
+
for (let e of l) {
|
|
228
|
+
let t = u.get(e.resolved_project_ref);
|
|
229
|
+
t && t !== e.scope_id && D(), u.set(e.resolved_project_ref, e.scope_id);
|
|
230
|
+
}
|
|
231
|
+
let d = M(ue(t.project_recipients, 500).map((e) => {
|
|
232
|
+
let t = O(e);
|
|
233
|
+
k(t, ["resolved_project_ref", "team_id"]);
|
|
234
|
+
let n = A(t.team_id);
|
|
235
|
+
n !== r && D();
|
|
236
|
+
let i = A(t.resolved_project_ref);
|
|
237
|
+
return /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(i) || D(), {
|
|
238
|
+
resolved_project_ref: i,
|
|
239
|
+
team_id: n
|
|
240
|
+
};
|
|
241
|
+
}), (e) => e.resolved_project_ref), f = [...new Set(l.map((e) => e.resolved_project_ref))].toSorted(o), p = d.map((e) => e.resolved_project_ref);
|
|
242
|
+
JSON.stringify(p) !== JSON.stringify(f) && D();
|
|
243
|
+
let m = {
|
|
244
|
+
version: 1,
|
|
245
|
+
coordinator_id: A(t.coordinator_id),
|
|
246
|
+
candidate_ref: fe(t.candidate_ref),
|
|
247
|
+
candidate_digest: j(t.candidate_digest),
|
|
248
|
+
team_id: r,
|
|
249
|
+
team_digest: j(t.team_digest),
|
|
250
|
+
source_digest: j(t.source_digest),
|
|
251
|
+
finish_digest: j(t.finish_digest),
|
|
252
|
+
access_delta_digest: j(t.access_delta_digest),
|
|
253
|
+
team: {
|
|
254
|
+
display_name: ce(n.display_name),
|
|
255
|
+
policy_revision: j(n.policy_revision),
|
|
256
|
+
device_eligibility_mode: "reviewed_allowlist"
|
|
257
|
+
},
|
|
258
|
+
memberships: i,
|
|
259
|
+
device_decisions: a,
|
|
260
|
+
project_mappings: l,
|
|
261
|
+
project_recipients: d,
|
|
262
|
+
completed_at: le(t.completed_at)
|
|
263
|
+
};
|
|
264
|
+
return new TextEncoder().encode(JSON.stringify(m)).byteLength > 15e5 && D(), m;
|
|
265
|
+
}
|
|
266
|
+
function me(e) {
|
|
267
|
+
return JSON.stringify(pe(e));
|
|
268
|
+
}
|
|
269
|
+
function he(e) {
|
|
270
|
+
e.team_id !== S(e.candidate_ref) && D();
|
|
271
|
+
}
|
|
272
|
+
function ge(e, t) {
|
|
273
|
+
y(e.coordinator_id, t) !== e.candidate_ref && D();
|
|
274
|
+
}
|
|
275
|
+
function _e(e, t, n) {
|
|
276
|
+
ge(e, t);
|
|
277
|
+
let r = new Set(e.project_mappings.map((e) => e.scope_id));
|
|
278
|
+
n.length !== r.size && D();
|
|
279
|
+
let i = e.coordinator_id;
|
|
280
|
+
for (let e of n) (!e.scope_id || !r.has(e.scope_id) || e.authority_type !== "coordinator" || !e.coordinator_id || e.group_id !== t || e.status !== "active" || e.coordinator_id !== i) && D();
|
|
281
|
+
return i;
|
|
282
|
+
}
|
|
283
|
+
//#endregion
|
|
3
284
|
//#region src/coordinator-membership-effects.ts
|
|
4
|
-
var
|
|
285
|
+
var ve = "scope_membership_effect_conflict", ye = {
|
|
5
286
|
device_not_enrolled: "device must be enrolled and enabled in the scope group.",
|
|
6
287
|
scope_group_mismatch: "membership groupId must match the scope groupId.",
|
|
7
288
|
scope_inactive: "scope is not active.",
|
|
8
289
|
scope_not_found: "scopeId must reference an existing scope."
|
|
9
|
-
},
|
|
290
|
+
}, N = class extends Error {
|
|
10
291
|
code;
|
|
11
292
|
constructor(e) {
|
|
12
|
-
super(
|
|
293
|
+
super(ye[e]), this.name = "CoordinatorMembershipError", this.code = e;
|
|
13
294
|
}
|
|
14
295
|
};
|
|
15
|
-
function
|
|
296
|
+
function P(e) {
|
|
16
297
|
return e?.trim() || null;
|
|
17
298
|
}
|
|
18
|
-
function
|
|
19
|
-
let t =
|
|
299
|
+
function be(e) {
|
|
300
|
+
let t = P(e);
|
|
20
301
|
if (!t) throw Error("effectId is required.");
|
|
21
302
|
if (t.length > 512 || /[\p{Cc}\p{Cf}]/u.test(t)) throw Error("effectId is invalid.");
|
|
22
303
|
return t;
|
|
23
304
|
}
|
|
24
|
-
function
|
|
305
|
+
function xe(e) {
|
|
25
306
|
return JSON.stringify({
|
|
26
|
-
scopeId:
|
|
27
|
-
deviceId:
|
|
28
|
-
role:
|
|
307
|
+
scopeId: P(e.scopeId),
|
|
308
|
+
deviceId: P(e.deviceId),
|
|
309
|
+
role: P(e.role),
|
|
29
310
|
membershipEpoch: e.membershipEpoch ?? null,
|
|
30
|
-
coordinatorId:
|
|
31
|
-
groupId:
|
|
32
|
-
manifestIssuerDeviceId:
|
|
33
|
-
manifestHash:
|
|
34
|
-
signedManifestJson:
|
|
35
|
-
actorType:
|
|
36
|
-
actorId:
|
|
311
|
+
coordinatorId: P(e.coordinatorId),
|
|
312
|
+
groupId: P(e.groupId),
|
|
313
|
+
manifestIssuerDeviceId: P(e.manifestIssuerDeviceId),
|
|
314
|
+
manifestHash: P(e.manifestHash),
|
|
315
|
+
signedManifestJson: P(e.signedManifestJson),
|
|
316
|
+
actorType: P(e.actorType),
|
|
317
|
+
actorId: P(e.actorId)
|
|
37
318
|
});
|
|
38
319
|
}
|
|
39
|
-
function
|
|
320
|
+
function Se(e) {
|
|
40
321
|
return JSON.stringify({
|
|
41
|
-
scopeId:
|
|
42
|
-
deviceId:
|
|
43
|
-
groupId:
|
|
322
|
+
scopeId: P(e.scopeId),
|
|
323
|
+
deviceId: P(e.deviceId),
|
|
324
|
+
groupId: P(e.groupId),
|
|
44
325
|
membershipEpoch: e.membershipEpoch ?? null,
|
|
45
|
-
manifestHash:
|
|
46
|
-
signedManifestJson:
|
|
47
|
-
actorType:
|
|
48
|
-
actorId:
|
|
326
|
+
manifestHash: P(e.manifestHash),
|
|
327
|
+
signedManifestJson: P(e.signedManifestJson),
|
|
328
|
+
actorType: P(e.actorType),
|
|
329
|
+
actorId: P(e.actorId)
|
|
49
330
|
});
|
|
50
331
|
}
|
|
51
|
-
function
|
|
52
|
-
if (e.action !== t || e.request_json !==
|
|
332
|
+
function Ce(e, t, n) {
|
|
333
|
+
if (e.action !== t || e.request_json !== n) throw Error(ve);
|
|
53
334
|
}
|
|
54
|
-
function
|
|
335
|
+
function we(e) {
|
|
55
336
|
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");
|
|
56
337
|
return {
|
|
57
338
|
scope_id: e.scope_id,
|
|
@@ -69,242 +350,242 @@ function u(e) {
|
|
|
69
350
|
}
|
|
70
351
|
//#endregion
|
|
71
352
|
//#region src/coordinator-store-contract.ts
|
|
72
|
-
function
|
|
353
|
+
function Te(e) {
|
|
73
354
|
let t = e.trim(), n = new Date(t);
|
|
74
355
|
if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
|
|
75
356
|
return n.toISOString();
|
|
76
357
|
}
|
|
77
|
-
var
|
|
78
|
-
function
|
|
79
|
-
return typeof e == "string" && e === e.trim() &&
|
|
358
|
+
var Ee = /^identity:[A-Za-z0-9_-]{18,24}$/u;
|
|
359
|
+
function De(e) {
|
|
360
|
+
return typeof e == "string" && e === e.trim() && Ee.test(e);
|
|
80
361
|
}
|
|
81
|
-
function
|
|
362
|
+
function Oe(e) {
|
|
82
363
|
return String(e.kind === "team_member" ? e.assigned_identity_id ?? "" : e.target_identity_id ?? "").trim();
|
|
83
364
|
}
|
|
84
|
-
var
|
|
85
|
-
code =
|
|
365
|
+
var ke = "reciprocal_approval_request_changed", Ae = class extends Error {
|
|
366
|
+
code = ke;
|
|
86
367
|
constructor() {
|
|
87
|
-
super(
|
|
368
|
+
super(ke), this.name = "CoordinatorReciprocalApprovalRequestChangedError";
|
|
88
369
|
}
|
|
89
|
-
},
|
|
90
|
-
function
|
|
370
|
+
}, je = 120, Me = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/iu, Ne = /^(?:actor|device|identity|local):\S+$/iu, Pe = /^(?:actor|device|identity)[_-][a-z0-9][a-z0-9._:-]{4,}$/iu, Fe = /^pending[_-]\S+$/iu, Ie = /^[a-f0-9]{12,64}$/iu;
|
|
371
|
+
function F(e, t) {
|
|
91
372
|
if ([...e].some((e) => /[\p{Cc}\p{Cf}]/u.test(e))) throw Error(`${t}_invalid`);
|
|
92
373
|
let n = e.replace(/\s+/gu, " ").trim();
|
|
93
374
|
if (!n) throw Error(`${t}_required`);
|
|
94
|
-
if ([...n].length >
|
|
375
|
+
if ([...n].length > je) throw Error(`${t}_too_long`);
|
|
95
376
|
return n;
|
|
96
377
|
}
|
|
97
|
-
function
|
|
378
|
+
function Le(e) {
|
|
98
379
|
if (typeof e != "string") return !1;
|
|
99
380
|
let t;
|
|
100
381
|
try {
|
|
101
|
-
t =
|
|
382
|
+
t = F(e, "display_name");
|
|
102
383
|
} catch {
|
|
103
384
|
return !1;
|
|
104
385
|
}
|
|
105
386
|
return ![
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
387
|
+
Me,
|
|
388
|
+
Ne,
|
|
389
|
+
Pe,
|
|
390
|
+
Fe,
|
|
391
|
+
Ie
|
|
111
392
|
].some((e) => e.test(t));
|
|
112
393
|
}
|
|
113
|
-
function
|
|
114
|
-
let n =
|
|
115
|
-
if (!
|
|
394
|
+
function I(e, t) {
|
|
395
|
+
let n = F(e, t);
|
|
396
|
+
if (!Le(n)) throw Error(`${t}_invalid`);
|
|
116
397
|
return n;
|
|
117
398
|
}
|
|
118
|
-
function
|
|
399
|
+
function Re(e) {
|
|
119
400
|
let t = String(e ?? "").replace(/\.local$/iu, "");
|
|
120
|
-
return t.trim() ?
|
|
401
|
+
return t.trim() ? F(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
|
|
121
402
|
}
|
|
122
|
-
function
|
|
403
|
+
function ze(e) {
|
|
123
404
|
for (let t of [
|
|
124
405
|
e.explicitName,
|
|
125
406
|
e.osName,
|
|
126
407
|
e.coordinatorName
|
|
127
408
|
]) {
|
|
128
409
|
let e = String(t ?? "").replace(/\.local$/iu, "").trim();
|
|
129
|
-
if (!(!e || !
|
|
130
|
-
let e =
|
|
131
|
-
if (e &&
|
|
410
|
+
if (!(!e || !Le(e))) try {
|
|
411
|
+
let e = Re(t);
|
|
412
|
+
if (e && Le(e)) return e;
|
|
132
413
|
} catch {}
|
|
133
414
|
}
|
|
134
415
|
let t = String(e.fallbackSeed ?? "").replace(/[^a-z0-9]/giu, "").slice(0, 6);
|
|
135
416
|
return t ? `Codemem device ${t}` : "Codemem device";
|
|
136
417
|
}
|
|
137
|
-
function
|
|
418
|
+
function Be(e) {
|
|
138
419
|
if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("project_summaries_invalid");
|
|
139
420
|
return e.map((e) => {
|
|
140
421
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_summaries_invalid");
|
|
141
422
|
let t = e;
|
|
142
423
|
if (!Number.isSafeInteger(t.existing_memory_count) || Number(t.existing_memory_count) < 0) throw Error("project_summaries_invalid");
|
|
143
424
|
return {
|
|
144
|
-
display_name:
|
|
425
|
+
display_name: F(String(t.display_name ?? ""), "project_name"),
|
|
145
426
|
existing_memory_count: Number(t.existing_memory_count)
|
|
146
427
|
};
|
|
147
428
|
});
|
|
148
429
|
}
|
|
149
430
|
//#endregion
|
|
150
431
|
//#region src/recipient-reviewed-intent.ts
|
|
151
|
-
var
|
|
432
|
+
var Ve = 1, L = class extends Error {
|
|
152
433
|
code;
|
|
153
434
|
constructor(e) {
|
|
154
435
|
super(e), this.name = "RecipientReviewedIntentError", this.code = e;
|
|
155
436
|
}
|
|
156
|
-
},
|
|
157
|
-
function
|
|
158
|
-
throw new
|
|
437
|
+
}, He = /[\p{Cc}\p{Cf}]/u, Ue = 100, We = 65536;
|
|
438
|
+
function R() {
|
|
439
|
+
throw new L("recipient_reviewed_intent_invalid");
|
|
159
440
|
}
|
|
160
|
-
function
|
|
161
|
-
return (!e || typeof e != "object" || Array.isArray(e)) &&
|
|
441
|
+
function z(e) {
|
|
442
|
+
return (!e || typeof e != "object" || Array.isArray(e)) && R(), e;
|
|
162
443
|
}
|
|
163
|
-
function
|
|
164
|
-
Object.keys(e).some((e) => !t.includes(e)) &&
|
|
444
|
+
function B(e, t) {
|
|
445
|
+
Object.keys(e).some((e) => !t.includes(e)) && R();
|
|
165
446
|
}
|
|
166
|
-
function
|
|
167
|
-
return (typeof e != "string" || !e || e !== e.trim() || e.length > t ||
|
|
447
|
+
function V(e, t) {
|
|
448
|
+
return (typeof e != "string" || !e || e !== e.trim() || e.length > t || He.test(e)) && R(), e;
|
|
168
449
|
}
|
|
169
|
-
function
|
|
170
|
-
(typeof e != "string" ||
|
|
450
|
+
function Ge(e) {
|
|
451
|
+
(typeof e != "string" || He.test(e)) && R();
|
|
171
452
|
let t = e.trim().replace(/\s+/gu, " ");
|
|
172
|
-
return (!t || t.length > 256) &&
|
|
453
|
+
return (!t || t.length > 256) && R(), t;
|
|
173
454
|
}
|
|
174
|
-
function
|
|
175
|
-
typeof e != "string" &&
|
|
455
|
+
function Ke(e) {
|
|
456
|
+
typeof e != "string" && R();
|
|
176
457
|
try {
|
|
177
|
-
return
|
|
458
|
+
return F(e, "identity_display_name");
|
|
178
459
|
} catch {
|
|
179
|
-
return
|
|
460
|
+
return R();
|
|
180
461
|
}
|
|
181
462
|
}
|
|
182
|
-
function
|
|
183
|
-
return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) &&
|
|
463
|
+
function qe(e) {
|
|
464
|
+
return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && R(), e;
|
|
184
465
|
}
|
|
185
|
-
function
|
|
466
|
+
function Je(e, t) {
|
|
186
467
|
return e < t ? -1 : +(e > t);
|
|
187
468
|
}
|
|
188
|
-
function
|
|
469
|
+
function Ye(e) {
|
|
189
470
|
return e.kind === "direct" ? "direct" : `team\u0000${e.teamId}`;
|
|
190
471
|
}
|
|
191
|
-
function
|
|
192
|
-
let t =
|
|
193
|
-
return t.kind === "direct" ? (
|
|
472
|
+
function Xe(e) {
|
|
473
|
+
let t = z(e);
|
|
474
|
+
return t.kind === "direct" ? (B(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && R(), B(t, [
|
|
194
475
|
"kind",
|
|
195
476
|
"teamId",
|
|
196
477
|
"displayName"
|
|
197
478
|
]), {
|
|
198
479
|
kind: "team",
|
|
199
|
-
teamId:
|
|
200
|
-
displayName:
|
|
480
|
+
teamId: V(t.teamId, 256),
|
|
481
|
+
displayName: Ge(t.displayName)
|
|
201
482
|
});
|
|
202
483
|
}
|
|
203
|
-
function
|
|
204
|
-
let t =
|
|
205
|
-
|
|
484
|
+
function Ze(e) {
|
|
485
|
+
let t = z(e);
|
|
486
|
+
B(t, [
|
|
206
487
|
"canonicalProjectIdentity",
|
|
207
488
|
"displayName",
|
|
208
489
|
"existingMemoryCount",
|
|
209
490
|
"futureMemoriesShared",
|
|
210
491
|
"sources"
|
|
211
|
-
]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) &&
|
|
212
|
-
let n = t.sources.map(
|
|
213
|
-
return new Set(n.map(
|
|
214
|
-
canonicalProjectIdentity:
|
|
215
|
-
displayName:
|
|
216
|
-
existingMemoryCount:
|
|
492
|
+
]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && R();
|
|
493
|
+
let n = t.sources.map(Xe).toSorted((e, t) => Je(Ye(e), Ye(t)));
|
|
494
|
+
return new Set(n.map(Ye)).size !== n.length && R(), {
|
|
495
|
+
canonicalProjectIdentity: V(t.canonicalProjectIdentity, 512),
|
|
496
|
+
displayName: Ge(t.displayName),
|
|
497
|
+
existingMemoryCount: qe(t.existingMemoryCount),
|
|
217
498
|
futureMemoriesShared: !0,
|
|
218
499
|
sources: n
|
|
219
500
|
};
|
|
220
501
|
}
|
|
221
|
-
function
|
|
222
|
-
let t =
|
|
223
|
-
return
|
|
502
|
+
function Qe(e) {
|
|
503
|
+
let t = z(e);
|
|
504
|
+
return B(t, [
|
|
224
505
|
"canonicalProjectIdentity",
|
|
225
506
|
"displayName",
|
|
226
507
|
"existingMemoryCount"
|
|
227
508
|
]), {
|
|
228
|
-
canonicalProjectIdentity:
|
|
229
|
-
displayName:
|
|
230
|
-
existingMemoryCount:
|
|
509
|
+
canonicalProjectIdentity: V(t.canonicalProjectIdentity, 512),
|
|
510
|
+
displayName: Ge(t.displayName),
|
|
511
|
+
existingMemoryCount: qe(t.existingMemoryCount)
|
|
231
512
|
};
|
|
232
513
|
}
|
|
233
|
-
function
|
|
234
|
-
(!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length >
|
|
235
|
-
let t = e.projects.map(
|
|
236
|
-
return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) &&
|
|
514
|
+
function $e(e) {
|
|
515
|
+
(!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > Ue) && R();
|
|
516
|
+
let t = e.projects.map(Ze).toSorted((e, t) => Je(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(Qe).toSorted((e, t) => Je(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
|
|
517
|
+
return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && R(), {
|
|
237
518
|
projects: t,
|
|
238
519
|
excludedProjects: n
|
|
239
520
|
};
|
|
240
521
|
}
|
|
241
|
-
function
|
|
242
|
-
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
|
|
522
|
+
function et(e, t) {
|
|
523
|
+
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 L("recipient_invite_intent_mismatch");
|
|
243
524
|
}
|
|
244
|
-
function
|
|
245
|
-
let n =
|
|
246
|
-
n.version !== 1 &&
|
|
247
|
-
let r =
|
|
525
|
+
function tt(e, t) {
|
|
526
|
+
let n = z(e);
|
|
527
|
+
n.version !== 1 && R();
|
|
528
|
+
let r = $e(n), i;
|
|
248
529
|
if (n.journey === "team") {
|
|
249
|
-
|
|
530
|
+
B(n, [
|
|
250
531
|
"version",
|
|
251
532
|
"journey",
|
|
252
533
|
"team",
|
|
253
534
|
"projects",
|
|
254
535
|
"excludedProjects"
|
|
255
536
|
]);
|
|
256
|
-
let e =
|
|
257
|
-
|
|
537
|
+
let e = z(n.team);
|
|
538
|
+
B(e, [
|
|
258
539
|
"teamId",
|
|
259
540
|
"displayName",
|
|
260
541
|
"futureProjectsInherit"
|
|
261
|
-
]), e.futureProjectsInherit !== !0 &&
|
|
542
|
+
]), e.futureProjectsInherit !== !0 && R(), i = {
|
|
262
543
|
version: 1,
|
|
263
544
|
journey: "team",
|
|
264
545
|
team: {
|
|
265
|
-
teamId:
|
|
266
|
-
displayName:
|
|
546
|
+
teamId: V(e.teamId, 256),
|
|
547
|
+
displayName: Ge(e.displayName),
|
|
267
548
|
futureProjectsInherit: !0
|
|
268
549
|
},
|
|
269
550
|
...r
|
|
270
551
|
};
|
|
271
552
|
} else if (n.journey === "add_device") {
|
|
272
|
-
|
|
553
|
+
B(n, [
|
|
273
554
|
"version",
|
|
274
555
|
"journey",
|
|
275
556
|
"targetIdentity",
|
|
276
557
|
"projects",
|
|
277
558
|
"excludedProjects"
|
|
278
559
|
]);
|
|
279
|
-
let e =
|
|
280
|
-
|
|
560
|
+
let e = z(n.targetIdentity);
|
|
561
|
+
B(e, ["identityId", "displayName"]), i = {
|
|
281
562
|
version: 1,
|
|
282
563
|
journey: "add_device",
|
|
283
564
|
targetIdentity: {
|
|
284
|
-
identityId:
|
|
285
|
-
displayName:
|
|
565
|
+
identityId: V(e.identityId, 256),
|
|
566
|
+
displayName: Ke(e.displayName)
|
|
286
567
|
},
|
|
287
568
|
...r
|
|
288
569
|
};
|
|
289
|
-
} else
|
|
290
|
-
return t &&
|
|
570
|
+
} else R();
|
|
571
|
+
return t && et(i, t), new TextEncoder().encode(H(i)).byteLength > We && R(), i;
|
|
291
572
|
}
|
|
292
|
-
function
|
|
293
|
-
return Array.isArray(e) ? `[${e.map(
|
|
573
|
+
function H(e) {
|
|
574
|
+
return Array.isArray(e) ? `[${e.map(H).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => Je(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${H(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
294
575
|
}
|
|
295
|
-
function
|
|
296
|
-
return
|
|
576
|
+
function nt(e, t) {
|
|
577
|
+
return H(tt(e, t));
|
|
297
578
|
}
|
|
298
|
-
async function
|
|
299
|
-
let n =
|
|
579
|
+
async function rt(e, t) {
|
|
580
|
+
let n = nt(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
|
|
300
581
|
return Array.from(new Uint8Array(i), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
301
582
|
}
|
|
302
|
-
async function
|
|
303
|
-
let n =
|
|
304
|
-
if (await
|
|
583
|
+
async function it(e, t) {
|
|
584
|
+
let n = tt(e, t.target);
|
|
585
|
+
if (await rt(n) !== t.digest) throw new L("recipient_invite_intent_mismatch");
|
|
305
586
|
return n;
|
|
306
587
|
}
|
|
307
|
-
async function
|
|
588
|
+
async function at(e, t) {
|
|
308
589
|
if (!e) throw Error("recipient_invite_review_unavailable");
|
|
309
590
|
let n;
|
|
310
591
|
try {
|
|
@@ -313,21 +594,21 @@ async function _e(e, t) {
|
|
|
313
594
|
throw Error("recipient_invite_review_unavailable");
|
|
314
595
|
}
|
|
315
596
|
try {
|
|
316
|
-
let r =
|
|
317
|
-
if (
|
|
318
|
-
return await
|
|
597
|
+
let r = tt(n, t.target);
|
|
598
|
+
if (H(r) !== e) throw Error("recipient_invite_review_unavailable");
|
|
599
|
+
return await it(r, t);
|
|
319
600
|
} catch (e) {
|
|
320
|
-
throw e instanceof
|
|
601
|
+
throw e instanceof L && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
|
|
321
602
|
}
|
|
322
603
|
}
|
|
323
604
|
//#endregion
|
|
324
605
|
//#region src/sync-fingerprint.ts
|
|
325
|
-
function
|
|
606
|
+
function ot(e) {
|
|
326
607
|
return t("sha256").update(e, "utf-8").digest("hex");
|
|
327
608
|
}
|
|
328
609
|
//#endregion
|
|
329
|
-
//#region ../../node_modules/.pnpm/hono@4.
|
|
330
|
-
var
|
|
610
|
+
//#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/compose.js
|
|
611
|
+
var st = (e, t, n) => (r, i) => {
|
|
331
612
|
let a = -1;
|
|
332
613
|
return o(0);
|
|
333
614
|
async function o(s) {
|
|
@@ -343,40 +624,45 @@ var ye = (e, t, n) => (r, i) => {
|
|
|
343
624
|
else r.finalized === !1 && n && (c = await n(r));
|
|
344
625
|
return c && (r.finalized === !1 || l) && (r.res = c), r;
|
|
345
626
|
}
|
|
346
|
-
},
|
|
347
|
-
let { all: n = !1, dot: r = !1 } = t, i = (e
|
|
348
|
-
return i
|
|
627
|
+
}, ct = /* @__PURE__ */ Symbol(), lt = (e, t) => new Response(e, { headers: { "Content-Type": t.replace(/^[^;]+/, (e) => e.toLowerCase()) } }).formData(), ut = 32, dt = 1e4, ft = (e) => "headers" in e, pt = async (e, t = /* @__PURE__ */ Object.create(null)) => {
|
|
628
|
+
let { all: n = !1, dot: r = !1 } = t, i = (ft(e) ? e.headers : e.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
629
|
+
return i === "multipart/form-data" || i === "application/x-www-form-urlencoded" ? mt(e, {
|
|
349
630
|
all: n,
|
|
350
631
|
dot: r
|
|
351
632
|
}) : {};
|
|
352
633
|
};
|
|
353
|
-
async function
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
634
|
+
async function mt(e, t) {
|
|
635
|
+
if (!ft(e) && e.bodyCache.formData) return ht(await e.bodyCache.formData, t);
|
|
636
|
+
let n = ft(e) ? e.headers : e.raw.headers, r = lt(await e.arrayBuffer(), n.get("Content-Type") || "");
|
|
637
|
+
ft(e) || (e.bodyCache.formData = r);
|
|
638
|
+
let i = await r;
|
|
639
|
+
return i ? ht(i, t) : {};
|
|
640
|
+
}
|
|
641
|
+
function ht(e, t) {
|
|
642
|
+
let n = /* @__PURE__ */ Object.create(null), r = { count: 0 };
|
|
359
643
|
return e.forEach((e, r) => {
|
|
360
|
-
t.all || r.endsWith("[]") ?
|
|
644
|
+
t.all || r.endsWith("[]") ? gt(n, r, e) : n[r] = e;
|
|
361
645
|
}), t.dot && Object.entries(n).forEach(([e, t]) => {
|
|
362
|
-
e.includes(".") && (
|
|
646
|
+
e.includes(".") && (_t(n, e, t, r), delete n[e]);
|
|
363
647
|
}), n;
|
|
364
648
|
}
|
|
365
|
-
var
|
|
366
|
-
e[t] === void 0 ? t.endsWith("[]") ?
|
|
367
|
-
},
|
|
649
|
+
var gt = (e, t, n) => {
|
|
650
|
+
e[t] === void 0 ? e[t] = t.endsWith("[]") ? [n] : n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
|
|
651
|
+
}, _t = (e, t, n, r) => {
|
|
368
652
|
if (/(?:^|\.)__proto__\./.test(t)) return;
|
|
369
|
-
let
|
|
370
|
-
|
|
371
|
-
t ===
|
|
653
|
+
let i = e, a = t.split(".", ut + 2);
|
|
654
|
+
a.length > ut + 1 && vt(), a.forEach((e, t) => {
|
|
655
|
+
t === a.length - 1 ? i[e] = n : ((!i[e] || typeof i[e] != "object" || Array.isArray(i[e]) || i[e] instanceof File) && (r.count++ >= dt && vt(), i[e] = /* @__PURE__ */ Object.create(null)), i = i[e]);
|
|
372
656
|
});
|
|
373
|
-
},
|
|
657
|
+
}, vt = () => {
|
|
658
|
+
throw Error("Nesting limit exceeded");
|
|
659
|
+
}, yt = (e) => {
|
|
374
660
|
let t = e.split("/");
|
|
375
661
|
return t[0] === "" && t.shift(), t;
|
|
376
|
-
},
|
|
377
|
-
let { groups: t, path: n } =
|
|
378
|
-
return
|
|
379
|
-
},
|
|
662
|
+
}, bt = (e) => {
|
|
663
|
+
let { groups: t, path: n } = xt(e);
|
|
664
|
+
return St(yt(n), t);
|
|
665
|
+
}, xt = (e) => {
|
|
380
666
|
let t = [];
|
|
381
667
|
return e = e.replace(/\{[^}]+\}/g, (e, n) => {
|
|
382
668
|
let r = `@${n}`;
|
|
@@ -385,7 +671,7 @@ var we = (e, t, n) => {
|
|
|
385
671
|
groups: t,
|
|
386
672
|
path: e
|
|
387
673
|
};
|
|
388
|
-
},
|
|
674
|
+
}, St = (e, t) => {
|
|
389
675
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
390
676
|
let [r] = t[n];
|
|
391
677
|
for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
|
|
@@ -394,12 +680,12 @@ var we = (e, t, n) => {
|
|
|
394
680
|
}
|
|
395
681
|
}
|
|
396
682
|
return e;
|
|
397
|
-
},
|
|
683
|
+
}, Ct = {}, wt = (e, t) => {
|
|
398
684
|
if (e === "*") return "*";
|
|
399
685
|
let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
400
686
|
if (n) {
|
|
401
687
|
let r = `${e}#${t}`;
|
|
402
|
-
return
|
|
688
|
+
return Ct[r] || (Ct[r] = n[2] ? t && t[0] !== ":" && t[0] !== "*" ? [
|
|
403
689
|
r,
|
|
404
690
|
n[1],
|
|
405
691
|
RegExp(`^${n[2]}(?=/${t})`)
|
|
@@ -407,14 +693,14 @@ var we = (e, t, n) => {
|
|
|
407
693
|
e,
|
|
408
694
|
n[1],
|
|
409
695
|
RegExp(`^${n[2]}$`)
|
|
410
|
-
] :
|
|
696
|
+
] : [
|
|
411
697
|
e,
|
|
412
698
|
n[1],
|
|
413
699
|
!0
|
|
414
|
-
]),
|
|
700
|
+
]), Ct[r];
|
|
415
701
|
}
|
|
416
702
|
return null;
|
|
417
|
-
},
|
|
703
|
+
}, Tt = (e, t) => {
|
|
418
704
|
try {
|
|
419
705
|
return t(e);
|
|
420
706
|
} catch {
|
|
@@ -426,58 +712,64 @@ var we = (e, t, n) => {
|
|
|
426
712
|
}
|
|
427
713
|
});
|
|
428
714
|
}
|
|
429
|
-
},
|
|
715
|
+
}, Et = (e) => Tt(e, decodeURI), Dt = (e) => {
|
|
430
716
|
let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
|
|
431
717
|
for (; r < t.length; r++) {
|
|
432
718
|
let e = t.charCodeAt(r);
|
|
433
719
|
if (e === 37) {
|
|
434
720
|
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);
|
|
435
|
-
return
|
|
436
|
-
}
|
|
721
|
+
return Et(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
|
|
722
|
+
}
|
|
723
|
+
if (e === 63 || e === 35) break;
|
|
437
724
|
}
|
|
438
725
|
return t.slice(n, r);
|
|
439
|
-
},
|
|
440
|
-
let t =
|
|
726
|
+
}, Ot = (e) => {
|
|
727
|
+
let t = Dt(e);
|
|
441
728
|
return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
|
|
442
|
-
},
|
|
729
|
+
}, U = (e, t, ...n) => (n.length && (t = U(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), kt = (e) => {
|
|
443
730
|
if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
|
|
444
731
|
let t = e.split("/"), n = [], r = "";
|
|
445
732
|
return t.forEach((e) => {
|
|
446
733
|
if (e !== "" && !/\:/.test(e)) r += "/" + e;
|
|
447
|
-
else if (/\:/.test(e))
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
734
|
+
else if (/\:/.test(e)) {
|
|
735
|
+
if (e.charCodeAt(e.length - 1) === 63) {
|
|
736
|
+
n.length === 0 && r === "" ? n.push("/") : n.push(r);
|
|
737
|
+
let t = e.slice(0, -1);
|
|
738
|
+
r += "/" + t, n.push(r);
|
|
739
|
+
} else r += "/" + e;
|
|
740
|
+
}
|
|
452
741
|
}), n.filter((e, t, n) => n.indexOf(e) === t);
|
|
453
|
-
},
|
|
454
|
-
let r;
|
|
455
|
-
|
|
742
|
+
}, At = (e) => e.indexOf("%") === -1 ? e : Tt(e, Ft), jt = (e) => (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), At(e)), Mt = (e, t, n) => {
|
|
743
|
+
let r = e.indexOf("#", 8);
|
|
744
|
+
r !== -1 && (e = e.slice(0, r));
|
|
745
|
+
let i;
|
|
746
|
+
if (!n && t && t.indexOf("%") === -1 && t.indexOf("+") === -1) {
|
|
456
747
|
let n = e.indexOf("?", 8);
|
|
457
748
|
if (n === -1) return;
|
|
458
749
|
for (e.startsWith(t, n + 1) || (n = e.indexOf(`&${t}`, n + 1)); n !== -1;) {
|
|
459
750
|
let r = e.charCodeAt(n + t.length + 1);
|
|
460
751
|
if (r === 61) {
|
|
461
752
|
let r = n + t.length + 2, i = e.indexOf("&", r);
|
|
462
|
-
return
|
|
463
|
-
}
|
|
753
|
+
return jt(e.slice(r, i === -1 ? void 0 : i));
|
|
754
|
+
}
|
|
755
|
+
if (r == 38 || isNaN(r)) return "";
|
|
464
756
|
n = e.indexOf(`&${t}`, n + 1);
|
|
465
757
|
}
|
|
466
|
-
if (
|
|
758
|
+
if (i = /[%+]/.test(e), !i) return;
|
|
467
759
|
}
|
|
468
|
-
let
|
|
469
|
-
|
|
470
|
-
let
|
|
471
|
-
for (;
|
|
472
|
-
let t = e.indexOf("&",
|
|
473
|
-
|
|
474
|
-
let s = e.slice(
|
|
475
|
-
if (
|
|
760
|
+
let a = /* @__PURE__ */ Object.create(null);
|
|
761
|
+
i ??= /[%+]/.test(e);
|
|
762
|
+
let o = e.indexOf("?", 8);
|
|
763
|
+
for (; o !== -1;) {
|
|
764
|
+
let t = e.indexOf("&", o + 1), r = e.indexOf("=", o);
|
|
765
|
+
r > t && t !== -1 && (r = -1);
|
|
766
|
+
let s = e.slice(o + 1, r === -1 ? t === -1 ? void 0 : t : r);
|
|
767
|
+
if (i && (s = jt(s)), o = t, s === "") continue;
|
|
476
768
|
let c;
|
|
477
|
-
|
|
769
|
+
r === -1 ? c = "" : (c = e.slice(r + 1, t === -1 ? void 0 : t), i && (c = jt(c))), n ? (a[s] && Array.isArray(a[s]) || (a[s] = []), a[s].push(c)) : a[s] ??= c;
|
|
478
770
|
}
|
|
479
|
-
return t ?
|
|
480
|
-
},
|
|
771
|
+
return t ? a[t] : a;
|
|
772
|
+
}, Nt = Mt, Pt = (e, t) => Mt(e, t, !0), Ft = decodeURIComponent, It = class {
|
|
481
773
|
raw;
|
|
482
774
|
#e;
|
|
483
775
|
#t;
|
|
@@ -485,20 +777,20 @@ var we = (e, t, n) => {
|
|
|
485
777
|
path;
|
|
486
778
|
bodyCache = {};
|
|
487
779
|
constructor(e, t = "/", n = [[]]) {
|
|
488
|
-
this.raw = e, this.path = t, this.#t = n
|
|
780
|
+
this.raw = e, this.path = t, this.#t = n;
|
|
489
781
|
}
|
|
490
782
|
param(e) {
|
|
491
783
|
return e ? this.#n(e) : this.#r();
|
|
492
784
|
}
|
|
493
785
|
#n(e) {
|
|
494
|
-
let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
|
|
495
|
-
return n &&
|
|
786
|
+
let t = this.#t[0][this.routeIndex]?.[1][e], n = this.#i(t);
|
|
787
|
+
return n && At(n);
|
|
496
788
|
}
|
|
497
789
|
#r() {
|
|
498
|
-
let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
|
|
790
|
+
let e = {}, t = Object.keys(this.#t[0][this.routeIndex]?.[1] ?? {});
|
|
499
791
|
for (let n of t) {
|
|
500
792
|
let t = this.#i(this.#t[0][this.routeIndex][1][n]);
|
|
501
|
-
t !== void 0 && (e[n] =
|
|
793
|
+
t !== void 0 && (e[n] = At(t));
|
|
502
794
|
}
|
|
503
795
|
return e;
|
|
504
796
|
}
|
|
@@ -506,26 +798,26 @@ var we = (e, t, n) => {
|
|
|
506
798
|
return this.#t[1] ? this.#t[1][e] : e;
|
|
507
799
|
}
|
|
508
800
|
query(e) {
|
|
509
|
-
return
|
|
801
|
+
return Nt(this.url, e);
|
|
510
802
|
}
|
|
511
803
|
queries(e) {
|
|
512
|
-
return
|
|
804
|
+
return Pt(this.url, e);
|
|
513
805
|
}
|
|
514
806
|
header(e) {
|
|
515
807
|
if (e) return this.raw.headers.get(e) ?? void 0;
|
|
516
|
-
let t =
|
|
808
|
+
let t = /* @__PURE__ */ Object.create(null);
|
|
517
809
|
return this.raw.headers.forEach((e, n) => {
|
|
518
810
|
t[n] = e;
|
|
519
811
|
}), t;
|
|
520
812
|
}
|
|
521
813
|
async parseBody(e) {
|
|
522
|
-
return
|
|
814
|
+
return pt(this, e);
|
|
523
815
|
}
|
|
524
816
|
#a = (e) => {
|
|
525
817
|
let { bodyCache: t, raw: n } = this, r = t[e];
|
|
526
818
|
if (r) return r;
|
|
527
|
-
let
|
|
528
|
-
return
|
|
819
|
+
for (let n in t) return t[n].then((t) => (n === "json" && (t = JSON.stringify(t)), new Response(t)[e]()));
|
|
820
|
+
return t[e] = n[e]();
|
|
529
821
|
};
|
|
530
822
|
json() {
|
|
531
823
|
return this.#a("text").then((e) => JSON.parse(e));
|
|
@@ -546,10 +838,10 @@ var we = (e, t, n) => {
|
|
|
546
838
|
return this.#a("formData");
|
|
547
839
|
}
|
|
548
840
|
addValidatedData(e, t) {
|
|
549
|
-
this.#e[e] = t;
|
|
841
|
+
(this.#e ??= {})[e] = t;
|
|
550
842
|
}
|
|
551
843
|
valid(e) {
|
|
552
|
-
return this.#e[e];
|
|
844
|
+
return this.#e?.[e];
|
|
553
845
|
}
|
|
554
846
|
get url() {
|
|
555
847
|
return this.raw.url;
|
|
@@ -557,7 +849,7 @@ var we = (e, t, n) => {
|
|
|
557
849
|
get method() {
|
|
558
850
|
return this.raw.method;
|
|
559
851
|
}
|
|
560
|
-
get [
|
|
852
|
+
get [ct]() {
|
|
561
853
|
return this.#t;
|
|
562
854
|
}
|
|
563
855
|
get matchedRoutes() {
|
|
@@ -566,14 +858,14 @@ var we = (e, t, n) => {
|
|
|
566
858
|
get routePath() {
|
|
567
859
|
return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
|
|
568
860
|
}
|
|
569
|
-
},
|
|
861
|
+
}, Lt = {
|
|
570
862
|
Stringify: 1,
|
|
571
863
|
BeforeStream: 2,
|
|
572
864
|
Stream: 3
|
|
573
|
-
},
|
|
865
|
+
}, Rt = (e, t) => {
|
|
574
866
|
let n = new String(e);
|
|
575
867
|
return n.isEscaped = !0, n.callbacks = t, n;
|
|
576
|
-
},
|
|
868
|
+
}, zt = async (e, t, n, r, i) => {
|
|
577
869
|
typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
|
|
578
870
|
let a = e.callbacks;
|
|
579
871
|
if (!a?.length) return Promise.resolve(e);
|
|
@@ -582,12 +874,12 @@ var we = (e, t, n) => {
|
|
|
582
874
|
phase: t,
|
|
583
875
|
buffer: i,
|
|
584
876
|
context: r
|
|
585
|
-
}))).then((e) => Promise.all(e.filter(Boolean).map((e) =>
|
|
586
|
-
return n ?
|
|
587
|
-
},
|
|
877
|
+
}))).then((e) => Promise.all(e.filter(Boolean).map((e) => zt(e, t, !1, r, i))).then(() => i[0]));
|
|
878
|
+
return n ? Rt(await o, a) : o;
|
|
879
|
+
}, Bt = "text/plain; charset=UTF-8", Vt = (e, t) => ({
|
|
588
880
|
"Content-Type": e,
|
|
589
881
|
...t
|
|
590
|
-
}),
|
|
882
|
+
}), W = (e, t) => new Response(e, t), Ht = class {
|
|
591
883
|
#e;
|
|
592
884
|
#t;
|
|
593
885
|
env = {};
|
|
@@ -607,7 +899,7 @@ var we = (e, t, n) => {
|
|
|
607
899
|
this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
|
|
608
900
|
}
|
|
609
901
|
get req() {
|
|
610
|
-
return this.#t ??= new
|
|
902
|
+
return this.#t ??= new It(this.#e, this.#d, this.#u), this.#t;
|
|
611
903
|
}
|
|
612
904
|
get event() {
|
|
613
905
|
if (this.#i && "respondWith" in this.#i) return this.#i;
|
|
@@ -618,16 +910,18 @@ var we = (e, t, n) => {
|
|
|
618
910
|
throw Error("This context has no ExecutionContext");
|
|
619
911
|
}
|
|
620
912
|
get res() {
|
|
621
|
-
return this.#a ||=
|
|
913
|
+
return this.#a ||= W(null, { headers: this.#l ??= new Headers() });
|
|
622
914
|
}
|
|
623
915
|
set res(e) {
|
|
624
916
|
if (this.#a && e) {
|
|
625
|
-
e =
|
|
626
|
-
for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type")
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
917
|
+
e = W(e.body, e);
|
|
918
|
+
for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") {
|
|
919
|
+
if (t === "set-cookie") {
|
|
920
|
+
let t = this.#a.headers.getSetCookie();
|
|
921
|
+
e.headers.delete("set-cookie");
|
|
922
|
+
for (let n of t) e.headers.append("set-cookie", n);
|
|
923
|
+
} else e.headers.set(t, n);
|
|
924
|
+
}
|
|
631
925
|
}
|
|
632
926
|
this.#a = e, this.finalized = !0;
|
|
633
927
|
}
|
|
@@ -638,7 +932,7 @@ var we = (e, t, n) => {
|
|
|
638
932
|
this.#s = e;
|
|
639
933
|
};
|
|
640
934
|
header = (e, t, n) => {
|
|
641
|
-
this.finalized && (this.#a =
|
|
935
|
+
this.finalized && (this.#a = W(this.#a.body, this.#a));
|
|
642
936
|
let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
|
|
643
937
|
t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
|
|
644
938
|
};
|
|
@@ -653,54 +947,68 @@ var we = (e, t, n) => {
|
|
|
653
947
|
return this.#n ? Object.fromEntries(this.#n) : {};
|
|
654
948
|
}
|
|
655
949
|
#f(e, t, n) {
|
|
656
|
-
let r = this.#a ? new Headers(this.#a.headers) : this.#l
|
|
657
|
-
if (typeof t == "object" &&
|
|
658
|
-
|
|
659
|
-
for (let [
|
|
660
|
-
}
|
|
661
|
-
if (n)
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
950
|
+
let r = this.#a ? new Headers(this.#a.headers) : this.#l;
|
|
951
|
+
if (typeof t == "object" && t.headers) {
|
|
952
|
+
r ??= new Headers();
|
|
953
|
+
for (let [e, n] of new Headers(t.headers)) e === "set-cookie" ? r.append(e, n) : r.set(e, n);
|
|
954
|
+
}
|
|
955
|
+
if (n) {
|
|
956
|
+
if (!r) {
|
|
957
|
+
let e = 0;
|
|
958
|
+
for (let t in n) if (++e > 1 || typeof n[t] != "string") {
|
|
959
|
+
r = new Headers();
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (r) for (let e in n) {
|
|
964
|
+
let t = n[e];
|
|
965
|
+
if (typeof t == "string") r.set(e, t);
|
|
966
|
+
else {
|
|
967
|
+
r.delete(e);
|
|
968
|
+
for (let n of t) r.append(e, n);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
665
971
|
}
|
|
666
|
-
return
|
|
972
|
+
return W(e, {
|
|
667
973
|
status: typeof t == "number" ? t : t?.status ?? this.#r,
|
|
668
|
-
headers: r
|
|
974
|
+
headers: r ?? n
|
|
669
975
|
});
|
|
670
976
|
}
|
|
671
977
|
newResponse = (...e) => this.#f(...e);
|
|
672
978
|
body = (e, t, n) => this.#f(e, t, n);
|
|
673
|
-
text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t,
|
|
674
|
-
json = (e, t, n) => this.#f(JSON.stringify(e), t,
|
|
979
|
+
text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, Vt(Bt, n));
|
|
980
|
+
json = (e, t, n) => this.#f(JSON.stringify(e), t, Vt("application/json", n));
|
|
675
981
|
html = (e, t, n) => {
|
|
676
|
-
let r = (e) => this.#f(e, t,
|
|
677
|
-
return typeof e == "object" ?
|
|
982
|
+
let r = (e) => this.#f(e, t, Vt("text/html; charset=UTF-8", n));
|
|
983
|
+
return typeof e == "object" ? zt(e, Lt.Stringify, !1, {}).then(r) : r(e);
|
|
678
984
|
};
|
|
679
985
|
redirect = (e, t) => {
|
|
680
986
|
let n = String(e);
|
|
681
987
|
return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
|
|
682
988
|
};
|
|
683
|
-
notFound = () => (this.#c ??= () =>
|
|
684
|
-
},
|
|
989
|
+
notFound = () => (this.#c ??= () => W(), this.#c(this));
|
|
990
|
+
}, Ut = [
|
|
685
991
|
"get",
|
|
686
992
|
"post",
|
|
687
993
|
"put",
|
|
688
994
|
"delete",
|
|
689
995
|
"options",
|
|
690
|
-
"patch"
|
|
691
|
-
|
|
996
|
+
"patch",
|
|
997
|
+
"query"
|
|
998
|
+
], Wt = "Can not add a route since the matcher is already built.", Gt = class extends Error {}, Kt = "__COMPOSED_HANDLER", qt = (e) => e.text("404 Not Found", 404), Jt = (e, t) => {
|
|
692
999
|
if ("getResponse" in e) {
|
|
693
1000
|
let n = e.getResponse();
|
|
694
1001
|
return t.newResponse(n.body, n);
|
|
695
1002
|
}
|
|
696
1003
|
return console.error(e), t.text("Internal Server Error", 500);
|
|
697
|
-
},
|
|
1004
|
+
}, Yt = class e {
|
|
698
1005
|
get;
|
|
699
1006
|
post;
|
|
700
1007
|
put;
|
|
701
1008
|
delete;
|
|
702
1009
|
options;
|
|
703
1010
|
patch;
|
|
1011
|
+
query;
|
|
704
1012
|
all;
|
|
705
1013
|
on;
|
|
706
1014
|
use;
|
|
@@ -710,7 +1018,7 @@ var we = (e, t, n) => {
|
|
|
710
1018
|
#e = "/";
|
|
711
1019
|
routes = [];
|
|
712
1020
|
constructor(e = {}) {
|
|
713
|
-
[...
|
|
1021
|
+
[...Ut, "all"].forEach((e) => {
|
|
714
1022
|
this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
|
|
715
1023
|
this.#r(e, this.#e, t);
|
|
716
1024
|
}), this);
|
|
@@ -726,7 +1034,7 @@ var we = (e, t, n) => {
|
|
|
726
1034
|
this.#r("ALL", this.#e, e);
|
|
727
1035
|
}), this);
|
|
728
1036
|
let { strict: t, ...n } = e;
|
|
729
|
-
Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ??
|
|
1037
|
+
Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Dt : Ot;
|
|
730
1038
|
}
|
|
731
1039
|
#t() {
|
|
732
1040
|
let t = new e({
|
|
@@ -735,18 +1043,18 @@ var we = (e, t, n) => {
|
|
|
735
1043
|
});
|
|
736
1044
|
return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
|
|
737
1045
|
}
|
|
738
|
-
#n =
|
|
739
|
-
errorHandler =
|
|
1046
|
+
#n = qt;
|
|
1047
|
+
errorHandler = Jt;
|
|
740
1048
|
route(e, t) {
|
|
741
1049
|
let n = this.basePath(e);
|
|
742
1050
|
return t.routes.map((e) => {
|
|
743
1051
|
let r;
|
|
744
|
-
t.errorHandler ===
|
|
1052
|
+
t.errorHandler === Jt ? r = e.handler : (r = async (n, r) => (await st([], t.errorHandler)(n, () => e.handler(n, r))).res, r[Kt] = e.handler), n.#r(e.method, e.path, r, e.basePath);
|
|
745
1053
|
}), this;
|
|
746
1054
|
}
|
|
747
1055
|
basePath(e) {
|
|
748
1056
|
let t = this.#t();
|
|
749
|
-
return t._basePath =
|
|
1057
|
+
return t._basePath = U(this._basePath, e), t;
|
|
750
1058
|
}
|
|
751
1059
|
onError = (e) => (this.errorHandler = e, this);
|
|
752
1060
|
notFound = (e) => (this.#n = e, this);
|
|
@@ -764,21 +1072,21 @@ var we = (e, t, n) => {
|
|
|
764
1072
|
return [e.env, t];
|
|
765
1073
|
};
|
|
766
1074
|
return r ||= (() => {
|
|
767
|
-
let t =
|
|
1075
|
+
let t = U(this._basePath, e), n = t === "/" ? 0 : t.length;
|
|
768
1076
|
return (e) => {
|
|
769
1077
|
let t = new URL(e.url);
|
|
770
1078
|
return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
|
|
771
1079
|
};
|
|
772
|
-
})(), this.#r("ALL",
|
|
1080
|
+
})(), this.#r("ALL", U(e, "*"), async (e, n) => {
|
|
773
1081
|
let i = await t(r(e.req.raw), ...a(e));
|
|
774
1082
|
if (i) return i;
|
|
775
1083
|
await n();
|
|
776
1084
|
}), this;
|
|
777
1085
|
}
|
|
778
1086
|
#r(e, t, n, r) {
|
|
779
|
-
e = e.toUpperCase(), t =
|
|
1087
|
+
e = e.toUpperCase(), t = U(this._basePath, t);
|
|
780
1088
|
let i = {
|
|
781
|
-
basePath: r === void 0 ? this._basePath :
|
|
1089
|
+
basePath: r === void 0 ? this._basePath : U(this._basePath, r),
|
|
782
1090
|
path: t,
|
|
783
1091
|
method: e,
|
|
784
1092
|
handler: n
|
|
@@ -791,7 +1099,7 @@ var we = (e, t, n) => {
|
|
|
791
1099
|
}
|
|
792
1100
|
#a(e, t, n, r) {
|
|
793
1101
|
if (r === "HEAD") return (async () => new Response(null, await this.#a(e, t, n, "GET")))();
|
|
794
|
-
let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new
|
|
1102
|
+
let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Ht(e, {
|
|
795
1103
|
path: i,
|
|
796
1104
|
matchResult: a,
|
|
797
1105
|
env: n,
|
|
@@ -809,7 +1117,7 @@ var we = (e, t, n) => {
|
|
|
809
1117
|
}
|
|
810
1118
|
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);
|
|
811
1119
|
}
|
|
812
|
-
let s =
|
|
1120
|
+
let s = st(a[0], this.errorHandler, this.#n);
|
|
813
1121
|
return (async () => {
|
|
814
1122
|
try {
|
|
815
1123
|
let e = await s(o);
|
|
@@ -821,98 +1129,103 @@ var we = (e, t, n) => {
|
|
|
821
1129
|
})();
|
|
822
1130
|
}
|
|
823
1131
|
fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
|
|
824
|
-
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${
|
|
1132
|
+
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${U("/", e)}`, t), n, r));
|
|
825
1133
|
fire = () => {
|
|
826
1134
|
addEventListener("fetch", (e) => {
|
|
827
1135
|
e.respondWith(this.#a(e.request, e, void 0, e.request.method));
|
|
828
1136
|
});
|
|
829
1137
|
};
|
|
830
|
-
},
|
|
831
|
-
function
|
|
1138
|
+
}, G = () => /* @__PURE__ */ Object.create(null), Xt = [];
|
|
1139
|
+
function Zt(e, t) {
|
|
832
1140
|
let n = this.buildAllMatchers(), r = ((e, t) => {
|
|
833
1141
|
let r = n[e] || n.ALL, i = r[2][t];
|
|
834
1142
|
if (i) return i;
|
|
835
1143
|
let a = t.match(r[0]);
|
|
836
|
-
if (!a) return [[],
|
|
1144
|
+
if (!a) return [[], Xt];
|
|
837
1145
|
let o = a.indexOf("", 1);
|
|
838
1146
|
return [r[1][o], a];
|
|
839
1147
|
});
|
|
840
1148
|
return this.match = r, r(e, t);
|
|
841
1149
|
}
|
|
842
1150
|
//#endregion
|
|
843
|
-
//#region ../../node_modules/.pnpm/hono@4.
|
|
844
|
-
var
|
|
845
|
-
function
|
|
846
|
-
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1
|
|
1151
|
+
//#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
1152
|
+
var Qt = "[^/]+", $t = "(?:|/.*)", K = /* @__PURE__ */ Symbol(), en = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
1153
|
+
function tn(e, t) {
|
|
1154
|
+
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 ? 1 : e === ".*" || e === "(?:|/.*)" ? t === "(?:|/.*)" ? -1 : 1 : t === ".*" || t === "(?:|/.*)" ? -1 : e === "[^/]+" ? 1 : t === "[^/]+" ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
|
|
847
1155
|
}
|
|
848
|
-
var
|
|
1156
|
+
var nn = class e {
|
|
849
1157
|
#e;
|
|
850
1158
|
#t;
|
|
851
|
-
#n =
|
|
1159
|
+
#n = G();
|
|
852
1160
|
insert(t, n, r, i, a) {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1161
|
+
let o = this;
|
|
1162
|
+
for (let n = 0, a = t.length; n < a; n++) {
|
|
1163
|
+
let s = t[n], c = s.length === 1 ? s === "*" ? n === a - 1 ? [
|
|
1164
|
+
"",
|
|
1165
|
+
"",
|
|
1166
|
+
".*"
|
|
1167
|
+
] : [
|
|
1168
|
+
"",
|
|
1169
|
+
"",
|
|
1170
|
+
Qt
|
|
1171
|
+
] : null : s === "/*" ? [
|
|
1172
|
+
"",
|
|
1173
|
+
"",
|
|
1174
|
+
$t
|
|
1175
|
+
] : s.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
|
|
1176
|
+
if (c) {
|
|
1177
|
+
let t = c[1], n = c[2] || "[^/]+";
|
|
1178
|
+
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)) || n.length === 1 && en.has(n))) throw K;
|
|
1179
|
+
if (l = o.#n[n], !l) {
|
|
1180
|
+
if (n !== ".*" && n !== "(?:|/.*)") {
|
|
1181
|
+
for (let e in o.#n) if ((n.length > 1 || e.length > 1) && e !== ".*" && e !== "(?:|/.*)") throw K;
|
|
1182
|
+
}
|
|
1183
|
+
l = o.#n[n] = new e();
|
|
1184
|
+
}
|
|
1185
|
+
t !== "" && (l.#t ??= i.varIndex++, r.push([t, l.#t]));
|
|
1186
|
+
} else if (l = o.#n[s], !l) {
|
|
1187
|
+
for (let e in o.#n) if (e.length > 1 && e !== ".*" && e !== "(?:|/.*)") throw K;
|
|
1188
|
+
l = o.#n[s] = new e();
|
|
879
1189
|
}
|
|
880
|
-
|
|
881
|
-
} else if (l = this.#n[o], !l) {
|
|
882
|
-
if (Object.keys(this.#n).some((e) => e.length > 1 && e !== B && e !== V)) throw H;
|
|
883
|
-
if (a) return;
|
|
884
|
-
l = this.#n[o] = new e();
|
|
1190
|
+
o = l;
|
|
885
1191
|
}
|
|
886
|
-
|
|
1192
|
+
if (o.#e !== void 0) throw K;
|
|
1193
|
+
o.#e = a ? -1 : n;
|
|
887
1194
|
}
|
|
888
1195
|
buildRegExpStr() {
|
|
889
|
-
let e = Object.keys(this.#n).sort(
|
|
890
|
-
let t = this.#n[e];
|
|
891
|
-
return (typeof t.#t == "number" ? `(${e})@${t.#t}` :
|
|
892
|
-
});
|
|
893
|
-
return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
|
|
1196
|
+
let e = Object.keys(this.#n).sort(tn).map((e) => {
|
|
1197
|
+
let t = this.#n[e], n = t.buildRegExpStr();
|
|
1198
|
+
return n === "" ? "" : (typeof t.#t == "number" ? `(${e})@${t.#t}` : en.has(e) ? `\\${e}` : e) + n;
|
|
1199
|
+
}).filter(Boolean);
|
|
1200
|
+
return typeof this.#e == "number" && this.#e !== -1 && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
|
|
894
1201
|
}
|
|
895
|
-
},
|
|
1202
|
+
}, rn = class {
|
|
896
1203
|
#e = { varIndex: 0 };
|
|
897
|
-
#t = new
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1204
|
+
#t = new nn();
|
|
1205
|
+
#n = 0;
|
|
1206
|
+
paths = G();
|
|
1207
|
+
insert(e, t) {
|
|
1208
|
+
if (t) {
|
|
1209
|
+
this.#t.insert(e.split(""), 0, [], this.#e, !0);
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
let n = [], r = [], i = e;
|
|
1213
|
+
for (let e = 0;;) {
|
|
1214
|
+
let t = !1;
|
|
1215
|
+
if (i = i.replace(/\{[^}]+\}/g, (n) => {
|
|
1216
|
+
let i = `@\\${e}`;
|
|
1217
|
+
return r[e] = [i, n], e++, t = !0, i;
|
|
1218
|
+
}), !t) break;
|
|
1219
|
+
}
|
|
1220
|
+
let a = i.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1221
|
+
for (let e = r.length - 1; e >= 0; e--) {
|
|
1222
|
+
let [t] = r[e];
|
|
910
1223
|
for (let n = a.length - 1; n >= 0; n--) if (a[n].indexOf(t) !== -1) {
|
|
911
|
-
a[n] = a[n].replace(t,
|
|
1224
|
+
a[n] = a[n].replace(t, r[e][1]);
|
|
912
1225
|
break;
|
|
913
1226
|
}
|
|
914
1227
|
}
|
|
915
|
-
|
|
1228
|
+
this.#t.insert(a, this.#n, n, this.#e, !1), this.paths[e] = [this.#n++, n];
|
|
916
1229
|
}
|
|
917
1230
|
buildRegExp() {
|
|
918
1231
|
let e = this.#t.buildRegExpStr();
|
|
@@ -928,111 +1241,72 @@ var ot = class e {
|
|
|
928
1241
|
r
|
|
929
1242
|
];
|
|
930
1243
|
}
|
|
931
|
-
},
|
|
932
|
-
|
|
933
|
-
[],
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
function dt() {
|
|
940
|
-
lt = /* @__PURE__ */ Object.create(null);
|
|
941
|
-
}
|
|
942
|
-
function ft(e) {
|
|
943
|
-
let t = new st(), n = [];
|
|
944
|
-
if (e.length === 0) return ct;
|
|
945
|
-
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);
|
|
946
|
-
for (let e = 0, a = -1, o = r.length; e < o; e++) {
|
|
947
|
-
let [o, s, c] = r[e];
|
|
948
|
-
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), nt] : a++;
|
|
949
|
-
let l;
|
|
950
|
-
try {
|
|
951
|
-
l = t.insert(s, a, o);
|
|
952
|
-
} catch (e) {
|
|
953
|
-
throw e === H ? new Ze(s) : e;
|
|
954
|
-
}
|
|
955
|
-
o || (n[a] = c.map(([e, t]) => {
|
|
956
|
-
let n = /* @__PURE__ */ Object.create(null);
|
|
957
|
-
for (--t; t >= 0; t--) {
|
|
958
|
-
let [e, r] = l[t];
|
|
959
|
-
n[e] = r;
|
|
960
|
-
}
|
|
961
|
-
return [e, n];
|
|
962
|
-
}));
|
|
963
|
-
}
|
|
964
|
-
let [a, o, s] = t.buildRegExp();
|
|
965
|
-
for (let e = 0, t = n.length; e < t; e++) for (let t = 0, r = n[e].length; t < r; t++) {
|
|
966
|
-
let r = n[e][t]?.[1];
|
|
967
|
-
if (!r) continue;
|
|
968
|
-
let i = Object.keys(r);
|
|
969
|
-
for (let e = 0, t = i.length; e < t; e++) r[i[e]] = s[r[i[e]]];
|
|
970
|
-
}
|
|
971
|
-
let c = [];
|
|
972
|
-
for (let e in o) c[e] = n[o[e]];
|
|
973
|
-
return [
|
|
974
|
-
a,
|
|
975
|
-
c,
|
|
976
|
-
i
|
|
977
|
-
];
|
|
978
|
-
}
|
|
979
|
-
function U(e, t) {
|
|
980
|
-
if (e) {
|
|
981
|
-
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (ut(n).test(t)) return [...e[n]];
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
var pt = class {
|
|
1244
|
+
}, an = G();
|
|
1245
|
+
function on(e) {
|
|
1246
|
+
return an[e] ??= RegExp(`^${e.replace(/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g, (e, t) => t ? `\\${t}` : e === "/*" ? $t : e === "*" ? ".*" : `/:${Qt}`)}$`);
|
|
1247
|
+
}
|
|
1248
|
+
function sn(e, t) {
|
|
1249
|
+
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (on(n).test(t)) return [...e[n]];
|
|
1250
|
+
}
|
|
1251
|
+
var cn = class {
|
|
985
1252
|
name = "RegExpRouter";
|
|
986
1253
|
#e;
|
|
987
1254
|
#t;
|
|
1255
|
+
#n;
|
|
988
1256
|
constructor() {
|
|
989
|
-
this.#e = { ALL:
|
|
1257
|
+
this.#e = { ALL: G() }, this.#t = { ALL: G() }, this.#n = { ALL: new rn() };
|
|
1258
|
+
}
|
|
1259
|
+
#r(e, t) {
|
|
1260
|
+
try {
|
|
1261
|
+
this.#n[e].insert(t, !/\*|\/:/.test(t));
|
|
1262
|
+
} catch (e) {
|
|
1263
|
+
throw e === K ? new Gt(t) : e;
|
|
1264
|
+
}
|
|
990
1265
|
}
|
|
991
1266
|
add(e, t, n) {
|
|
992
1267
|
let r = this.#e, i = this.#t;
|
|
993
|
-
if (!r
|
|
994
|
-
r[e]
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1268
|
+
if (!r) throw Error(Wt);
|
|
1269
|
+
if (!r[e]) {
|
|
1270
|
+
this.#n[e] = new rn();
|
|
1271
|
+
for (let t of [r, i]) {
|
|
1272
|
+
t[e] = G();
|
|
1273
|
+
for (let n in t.ALL) t[e][n] = [...t.ALL[n]], this.#r(e, n);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
t === "/*" && (t = "*");
|
|
1277
|
+
let a = e === "ALL" ? Object.keys(r) : [e];
|
|
1000
1278
|
if (/\*$/.test(t)) {
|
|
1001
|
-
let
|
|
1002
|
-
e
|
|
1003
|
-
|
|
1004
|
-
}) : r[e][t] ||= U(r[e], t) || U(r.ALL, t) || [], Object.keys(r).forEach((t) => {
|
|
1005
|
-
(e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
|
|
1006
|
-
o.test(e) && r[t][e].push([n, a]);
|
|
1007
|
-
});
|
|
1008
|
-
}), Object.keys(i).forEach((t) => {
|
|
1009
|
-
(e === "ALL" || e === t) && Object.keys(i[t]).forEach((e) => o.test(e) && i[t][e].push([n, a]));
|
|
1010
|
-
});
|
|
1279
|
+
let e = on(t);
|
|
1280
|
+
for (let e of a) r[e][t] || (this.#r(e, t), r[e][t] = sn(r[e], t) || sn(r.ALL, t) || []);
|
|
1281
|
+
for (let o of [r, i]) for (let r of a) for (let i in o[r]) e.test(i) && o[r][i].push([n, t]);
|
|
1011
1282
|
return;
|
|
1012
1283
|
}
|
|
1013
|
-
let o =
|
|
1014
|
-
for (let t
|
|
1015
|
-
let c = o[t];
|
|
1016
|
-
Object.keys(i).forEach((o) => {
|
|
1017
|
-
(e === "ALL" || e === o) && (i[o][c] ||= [...U(r[o], c) || U(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1284
|
+
let o = kt(t) || [t];
|
|
1285
|
+
for (let e of o) for (let t of a) i[t][e] || (this.#r(t, e), i[t][e] = sn(r[t], e) || sn(r.ALL, e) || []), i[t][e].push([n, e]);
|
|
1020
1286
|
}
|
|
1021
|
-
match =
|
|
1287
|
+
match = Zt;
|
|
1022
1288
|
buildAllMatchers() {
|
|
1023
|
-
let e =
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
}), this.#e = this.#t = void 0, dt(), e;
|
|
1289
|
+
let e = G();
|
|
1290
|
+
for (let t of Object.keys(this.#t)) e[t] = this.#i(t);
|
|
1291
|
+
return this.#e = this.#t = this.#n = void 0, an = G(), e;
|
|
1027
1292
|
}
|
|
1028
|
-
#
|
|
1029
|
-
let t = [], n = e
|
|
1030
|
-
|
|
1031
|
-
let
|
|
1032
|
-
|
|
1033
|
-
|
|
1293
|
+
#i(e) {
|
|
1294
|
+
let t = this.#e[e], n = this.#t[e], r = this.#n[e], i = G(), a = [], [o, s, c] = r.buildRegExp();
|
|
1295
|
+
for (let e of [t, n]) for (let t in e) {
|
|
1296
|
+
let n = e[t], o = r.paths[t];
|
|
1297
|
+
if (!o) {
|
|
1298
|
+
i[t] = [n.map(([e]) => [e, G()]), Xt];
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
a[o[0]] = n.map(([e, t]) => [e, r.paths[t][1].reduceRight((e, [t], n) => (e[t] = c[o[1][n][1]], e), G())]);
|
|
1302
|
+
}
|
|
1303
|
+
return [
|
|
1304
|
+
o,
|
|
1305
|
+
s.map((e) => a[e]),
|
|
1306
|
+
i
|
|
1307
|
+
];
|
|
1034
1308
|
}
|
|
1035
|
-
},
|
|
1309
|
+
}, ln = class {
|
|
1036
1310
|
name = "SmartRouter";
|
|
1037
1311
|
#e = [];
|
|
1038
1312
|
#t = [];
|
|
@@ -1040,7 +1314,7 @@ var pt = class {
|
|
|
1040
1314
|
this.#e = e.routers;
|
|
1041
1315
|
}
|
|
1042
1316
|
add(e, t, n) {
|
|
1043
|
-
if (!this.#t) throw Error(
|
|
1317
|
+
if (!this.#t) throw Error(Wt);
|
|
1044
1318
|
this.#t.push([
|
|
1045
1319
|
e,
|
|
1046
1320
|
t,
|
|
@@ -1056,7 +1330,7 @@ var pt = class {
|
|
|
1056
1330
|
for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
|
|
1057
1331
|
o = i.match(e, t);
|
|
1058
1332
|
} catch (e) {
|
|
1059
|
-
if (e instanceof
|
|
1333
|
+
if (e instanceof Gt) continue;
|
|
1060
1334
|
throw e;
|
|
1061
1335
|
}
|
|
1062
1336
|
this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
|
|
@@ -1069,149 +1343,126 @@ var pt = class {
|
|
|
1069
1343
|
if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
|
|
1070
1344
|
return this.#e[0];
|
|
1071
1345
|
}
|
|
1072
|
-
},
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
#
|
|
1077
|
-
#
|
|
1078
|
-
#n;
|
|
1079
|
-
#r = 0;
|
|
1080
|
-
#i = W;
|
|
1081
|
-
constructor(e, t, n) {
|
|
1082
|
-
if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
|
|
1083
|
-
let n = /* @__PURE__ */ Object.create(null);
|
|
1084
|
-
n[e] = {
|
|
1085
|
-
handler: t,
|
|
1086
|
-
possibleKeys: [],
|
|
1087
|
-
score: 0
|
|
1088
|
-
}, this.#e = [n];
|
|
1089
|
-
}
|
|
1090
|
-
this.#n = [];
|
|
1091
|
-
}
|
|
1346
|
+
}, un = G(), dn = 0, fn = class e {
|
|
1347
|
+
#e = [];
|
|
1348
|
+
#t = G();
|
|
1349
|
+
#n = [];
|
|
1350
|
+
#r;
|
|
1351
|
+
#i = un;
|
|
1092
1352
|
insert(t, n, r) {
|
|
1093
|
-
this
|
|
1094
|
-
let
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
if (c in i.#t) {
|
|
1098
|
-
i = i.#t[c], s && o.push(s[1]);
|
|
1099
|
-
continue;
|
|
1100
|
-
}
|
|
1101
|
-
i.#t[c] = new e(), s && (i.#n.push(s), o.push(s[1])), i = i.#t[c];
|
|
1353
|
+
let i = this, a = bt(n), o = /* @__PURE__ */ new Set(), s = 0;
|
|
1354
|
+
for (let t of a) {
|
|
1355
|
+
let n = a[++s], r = wt(t, n) || (n === void 0 && t && t.indexOf("*") === t.length - 1 ? t : null), c = Array.isArray(r), l = c ? r[0] : r || t, u = i.#t[l] ||= new e();
|
|
1356
|
+
r && !u.#r && (u.#r = r, i.#n.push(u)), i = u, c && o.add(r[1]);
|
|
1102
1357
|
}
|
|
1103
|
-
|
|
1358
|
+
i.#e.push({ [t]: {
|
|
1104
1359
|
handler: r,
|
|
1105
|
-
possibleKeys: o
|
|
1106
|
-
score:
|
|
1107
|
-
} })
|
|
1360
|
+
possibleKeys: [...o],
|
|
1361
|
+
score: ++dn
|
|
1362
|
+
} });
|
|
1108
1363
|
}
|
|
1109
1364
|
#a(e, t, n, r, i) {
|
|
1110
1365
|
for (let a = 0, o = t.#e.length; a < o; a++) {
|
|
1111
|
-
let o = t.#e[a], s = o[n] || o.ALL
|
|
1112
|
-
if (s
|
|
1113
|
-
|
|
1114
|
-
|
|
1366
|
+
let o = t.#e[a], s = o[n] || o.ALL;
|
|
1367
|
+
if (s) {
|
|
1368
|
+
s.params = G(), e.push(s);
|
|
1369
|
+
for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
|
|
1370
|
+
let t = s.possibleKeys[e];
|
|
1371
|
+
s.params[t] = i?.[t] && !e ? i[t] : r[t] ?? i?.[t];
|
|
1372
|
+
}
|
|
1115
1373
|
}
|
|
1116
1374
|
}
|
|
1117
1375
|
}
|
|
1118
1376
|
search(e, t) {
|
|
1119
1377
|
let n = [];
|
|
1120
|
-
this.#i =
|
|
1121
|
-
let r = [this], i =
|
|
1378
|
+
this.#i = un;
|
|
1379
|
+
let r = [this], i = yt(t), a = [], o = i.length, s = null;
|
|
1122
1380
|
for (let c = 0; c < o; c++) {
|
|
1123
1381
|
let l = i[c], u = c === o - 1, d = [];
|
|
1124
1382
|
for (let f = 0, p = r.length; f < p; f++) {
|
|
1125
1383
|
let p = r[f], m = p.#t[l];
|
|
1126
1384
|
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));
|
|
1127
|
-
for (let r
|
|
1128
|
-
let f =
|
|
1129
|
-
if (f
|
|
1130
|
-
|
|
1131
|
-
t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
|
|
1385
|
+
for (let r of p.#n) {
|
|
1386
|
+
let f = r.#r, m = p.#i === un ? {} : { ...p.#i };
|
|
1387
|
+
if (typeof f == "string") {
|
|
1388
|
+
(f === "*" || l.startsWith(f.slice(0, -1))) && (this.#a(n, r, e, p.#i), f === "*" && (r.#i = m, d.push(r)));
|
|
1132
1389
|
continue;
|
|
1133
1390
|
}
|
|
1134
|
-
let [h, g
|
|
1135
|
-
if (!l &&
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1391
|
+
let [, h, g] = f;
|
|
1392
|
+
if (!(!l && g === !0)) {
|
|
1393
|
+
if (g !== !0) {
|
|
1394
|
+
if (!s) {
|
|
1395
|
+
s = [];
|
|
1396
|
+
let e = +(t[0] === "/");
|
|
1397
|
+
for (let t = 0; t < o; t++) s[t] = e, e += i[t].length + 1;
|
|
1398
|
+
}
|
|
1399
|
+
let l = t.slice(s[c]), u = g.exec(l);
|
|
1400
|
+
if (u) {
|
|
1401
|
+
m[h] = u[0], this.#a(n, r, e, p.#i, m), u[0].length === l.length && r.#t["*"] && this.#a(n, r.#t["*"], e, p.#i, m);
|
|
1402
|
+
for (let e in r.#t) {
|
|
1403
|
+
r.#i = m;
|
|
1404
|
+
let e = u[0].match(/\//g)?.length ?? 0;
|
|
1405
|
+
(a[e] ||= []).push(r);
|
|
1406
|
+
break;
|
|
1407
|
+
}
|
|
1408
|
+
continue;
|
|
1149
1409
|
}
|
|
1150
|
-
continue;
|
|
1151
1410
|
}
|
|
1411
|
+
(g === !0 || g.test(l)) && (m[h] = l, u ? (this.#a(n, r, e, m, p.#i), r.#t["*"] && this.#a(n, r.#t["*"], e, m, p.#i)) : (r.#i = m, d.push(r)));
|
|
1152
1412
|
}
|
|
1153
|
-
(_ === !0 || _.test(l)) && (m[g] = l, u ? (this.#a(n, v, e, m, p.#i), v.#t["*"] && this.#a(n, v.#t["*"], e, m, p.#i)) : (v.#i = m, d.push(v)));
|
|
1154
1413
|
}
|
|
1155
1414
|
}
|
|
1156
1415
|
let f = a.shift();
|
|
1157
1416
|
r = f ? d.concat(f) : d;
|
|
1158
1417
|
}
|
|
1159
|
-
return n
|
|
1418
|
+
return n[1] && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
|
|
1160
1419
|
}
|
|
1161
|
-
},
|
|
1420
|
+
}, pn = class {
|
|
1162
1421
|
name = "TrieRouter";
|
|
1163
|
-
#e;
|
|
1164
|
-
constructor() {
|
|
1165
|
-
this.#e = new gt();
|
|
1166
|
-
}
|
|
1422
|
+
#e = new fn();
|
|
1167
1423
|
add(e, t, n) {
|
|
1168
|
-
let r
|
|
1169
|
-
if (r) {
|
|
1170
|
-
for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
|
|
1171
|
-
return;
|
|
1172
|
-
}
|
|
1173
|
-
this.#e.insert(e, t, n);
|
|
1424
|
+
for (let r of kt(t) || [t]) this.#e.insert(e, r, n);
|
|
1174
1425
|
}
|
|
1175
1426
|
match(e, t) {
|
|
1176
1427
|
return this.#e.search(e, t);
|
|
1177
1428
|
}
|
|
1178
|
-
},
|
|
1429
|
+
}, mn = class extends Yt {
|
|
1179
1430
|
constructor(e = {}) {
|
|
1180
|
-
super(e), this.router = e.router ?? new
|
|
1431
|
+
super(e), this.router = e.router ?? new ln({ routers: [new cn(), new pn()] });
|
|
1181
1432
|
}
|
|
1182
1433
|
};
|
|
1183
1434
|
//#endregion
|
|
1184
1435
|
//#region src/coordinator-invites.ts
|
|
1185
|
-
function
|
|
1436
|
+
function hn(e) {
|
|
1186
1437
|
let t = "";
|
|
1187
1438
|
for (let n of e) t += String.fromCharCode(n);
|
|
1188
1439
|
return btoa(t);
|
|
1189
1440
|
}
|
|
1190
|
-
function
|
|
1441
|
+
function gn(e) {
|
|
1191
1442
|
let t = atob(e), n = new Uint8Array(t.length);
|
|
1192
1443
|
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
1193
1444
|
return n;
|
|
1194
1445
|
}
|
|
1195
|
-
function
|
|
1446
|
+
function _n(e) {
|
|
1196
1447
|
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1197
1448
|
}
|
|
1198
|
-
function
|
|
1449
|
+
function vn(e) {
|
|
1199
1450
|
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
1200
1451
|
return t + "=".repeat((4 - t.length % 4) % 4);
|
|
1201
1452
|
}
|
|
1202
|
-
function
|
|
1453
|
+
function yn(e) {
|
|
1203
1454
|
let t = JSON.stringify(e);
|
|
1204
|
-
return
|
|
1455
|
+
return _n(hn(new TextEncoder().encode(t)));
|
|
1205
1456
|
}
|
|
1206
|
-
function
|
|
1207
|
-
let t = new TextDecoder().decode(
|
|
1457
|
+
function bn(e) {
|
|
1458
|
+
let t = new TextDecoder().decode(gn(vn(e))), n = JSON.parse(t);
|
|
1208
1459
|
if (typeof n != "object" || !n) throw Error("invalid invite payload");
|
|
1209
1460
|
return n;
|
|
1210
1461
|
}
|
|
1211
|
-
function
|
|
1462
|
+
function xn(e) {
|
|
1212
1463
|
return `codemem://join?invite=${encodeURIComponent(e)}`;
|
|
1213
1464
|
}
|
|
1214
|
-
function
|
|
1465
|
+
function Sn(e) {
|
|
1215
1466
|
let t = e.trim();
|
|
1216
1467
|
if (t.startsWith("codemem://")) {
|
|
1217
1468
|
let e = new URL(t).searchParams.get("invite") ?? "";
|
|
@@ -1222,44 +1473,62 @@ function wt(e) {
|
|
|
1222
1473
|
}
|
|
1223
1474
|
//#endregion
|
|
1224
1475
|
//#region src/project-invite-acceptance.ts
|
|
1225
|
-
var
|
|
1226
|
-
code =
|
|
1227
|
-
detail =
|
|
1476
|
+
var Cn = "pending_setup", wn = "project_sync_enablement_failed", Tn = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", En = class extends Error {
|
|
1477
|
+
code = wn;
|
|
1478
|
+
detail = Tn;
|
|
1228
1479
|
constructor(e) {
|
|
1229
|
-
super(
|
|
1480
|
+
super(Tn, e), this.name = "ProjectSyncEnablementError";
|
|
1230
1481
|
}
|
|
1231
1482
|
};
|
|
1232
|
-
function
|
|
1483
|
+
function Dn(e) {
|
|
1233
1484
|
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.";
|
|
1234
1485
|
}
|
|
1235
1486
|
//#endregion
|
|
1236
|
-
//#region src/
|
|
1237
|
-
var
|
|
1487
|
+
//#region src/project-identity.ts
|
|
1488
|
+
var On = /^(?:command failed(?:\s|:)|error:\s|fatal:\s|git:\s)/iu, kn = /^(?:giterror|git error|git command failed):[^\r\n]*(?:not a git repository|unknown revision or path|no such remote)\b/iu;
|
|
1489
|
+
function An(e) {
|
|
1490
|
+
if (typeof e != "string") return !1;
|
|
1491
|
+
let t = e.trim();
|
|
1492
|
+
return t ? t.includes("\n") || t.includes("\r") ? !0 : On.test(t) || kn.test(t) : !1;
|
|
1493
|
+
}
|
|
1238
1494
|
function q(e) {
|
|
1239
|
-
|
|
1495
|
+
let t = e?.trim();
|
|
1496
|
+
return !t || An(t) ? null : t;
|
|
1240
1497
|
}
|
|
1498
|
+
//#endregion
|
|
1499
|
+
//#region src/scope-resolution.ts
|
|
1500
|
+
var jn = "local-default", Mn = "legacy-shared-review";
|
|
1241
1501
|
function J(e) {
|
|
1502
|
+
return e?.trim() || null;
|
|
1503
|
+
}
|
|
1504
|
+
function Y(e) {
|
|
1242
1505
|
return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
|
|
1243
1506
|
}
|
|
1244
|
-
function
|
|
1245
|
-
return
|
|
1507
|
+
function Nn(t) {
|
|
1508
|
+
return Y(e(t));
|
|
1246
1509
|
}
|
|
1247
|
-
function
|
|
1248
|
-
let t =
|
|
1249
|
-
return t ?
|
|
1510
|
+
function Pn(e) {
|
|
1511
|
+
let t = J(e);
|
|
1512
|
+
return t ? Y(t) : null;
|
|
1250
1513
|
}
|
|
1251
|
-
function
|
|
1514
|
+
function Fn(e) {
|
|
1252
1515
|
let n = [
|
|
1253
1516
|
e.cwd,
|
|
1254
1517
|
e.project,
|
|
1255
1518
|
e.workspaceId
|
|
1256
|
-
].map((e) => q(e)).find((e) => e
|
|
1257
|
-
|
|
1519
|
+
].map((e) => q(e)).find((e) => e !== null), r = [
|
|
1520
|
+
e.gitRemote,
|
|
1521
|
+
e.gitBranch,
|
|
1522
|
+
e.cwd,
|
|
1523
|
+
e.project,
|
|
1524
|
+
e.workspaceId
|
|
1525
|
+
].map((e) => typeof e == "string" ? e.trim() : null), i = n ?? "unknown";
|
|
1526
|
+
return !n && r.some(An) && (i = JSON.stringify(r)), `unmapped:${t("sha256").update(i, "utf8").digest("hex")}`;
|
|
1258
1527
|
}
|
|
1259
|
-
function
|
|
1528
|
+
function In(e) {
|
|
1260
1529
|
let t = q(e.gitRemote), n = q(e.gitBranch), r = q(e.cwd), i = q(e.workspaceId), a = q(e.project);
|
|
1261
1530
|
if (t) {
|
|
1262
|
-
let r =
|
|
1531
|
+
let r = Y(t);
|
|
1263
1532
|
return e.branchScoped && n ? {
|
|
1264
1533
|
value: `${r}:${n}`,
|
|
1265
1534
|
source: "git_remote_branch",
|
|
@@ -1271,49 +1540,49 @@ function Ft(e) {
|
|
|
1271
1540
|
};
|
|
1272
1541
|
}
|
|
1273
1542
|
return r ? {
|
|
1274
|
-
value:
|
|
1543
|
+
value: Nn(r),
|
|
1275
1544
|
source: "cwd",
|
|
1276
1545
|
displayProject: a
|
|
1277
1546
|
} : i ? {
|
|
1278
|
-
value:
|
|
1547
|
+
value: Y(i),
|
|
1279
1548
|
source: "workspace_id",
|
|
1280
1549
|
displayProject: a
|
|
1281
1550
|
} : {
|
|
1282
|
-
value:
|
|
1551
|
+
value: Fn(e),
|
|
1283
1552
|
source: "unmapped",
|
|
1284
1553
|
displayProject: a
|
|
1285
1554
|
};
|
|
1286
1555
|
}
|
|
1287
|
-
function
|
|
1556
|
+
function Ln(e) {
|
|
1288
1557
|
return !/[\\/:]/.test(e);
|
|
1289
1558
|
}
|
|
1290
|
-
function
|
|
1559
|
+
function Rn(e) {
|
|
1291
1560
|
return e.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
|
|
1292
1561
|
}
|
|
1293
|
-
function
|
|
1562
|
+
function zn(e) {
|
|
1294
1563
|
return e.replace(/[*?]/g, "").length;
|
|
1295
1564
|
}
|
|
1296
|
-
function
|
|
1297
|
-
let n =
|
|
1298
|
-
return !n ||
|
|
1565
|
+
function Bn(e, t) {
|
|
1566
|
+
let n = Y(t);
|
|
1567
|
+
return !n || Ln(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${Rn(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
|
|
1299
1568
|
}
|
|
1300
|
-
function
|
|
1569
|
+
function Vn(e) {
|
|
1301
1570
|
return e.mapping.priority ?? 0;
|
|
1302
1571
|
}
|
|
1303
|
-
function
|
|
1304
|
-
let t =
|
|
1572
|
+
function Hn(e) {
|
|
1573
|
+
let t = J(e.mapping.updated_at);
|
|
1305
1574
|
if (!t) return 0;
|
|
1306
1575
|
let n = Date.parse(t);
|
|
1307
1576
|
return Number.isFinite(n) ? n : 0;
|
|
1308
1577
|
}
|
|
1309
|
-
function
|
|
1310
|
-
return
|
|
1578
|
+
function Un(e, t) {
|
|
1579
|
+
return Vn(t) - Vn(e) || t.specificity - e.specificity || Hn(t) - Hn(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
|
|
1311
1580
|
}
|
|
1312
|
-
function
|
|
1313
|
-
return e.toSorted(
|
|
1581
|
+
function Wn(e) {
|
|
1582
|
+
return e.toSorted(Un)[0] ?? null;
|
|
1314
1583
|
}
|
|
1315
|
-
function
|
|
1316
|
-
let t =
|
|
1584
|
+
function Gn(e) {
|
|
1585
|
+
let t = In(e), n = J(e.explicitScopeId);
|
|
1317
1586
|
if (n) return {
|
|
1318
1587
|
scopeId: n,
|
|
1319
1588
|
reason: "explicit_override",
|
|
@@ -1328,7 +1597,7 @@ function Wt(e) {
|
|
|
1328
1597
|
mapping: null,
|
|
1329
1598
|
matchedPattern: null
|
|
1330
1599
|
};
|
|
1331
|
-
let r = e.mappings ?? [], i =
|
|
1600
|
+
let r = e.mappings ?? [], i = Wn(r.filter((e) => Pn(e.workspace_identity) === t.value).map((e) => ({
|
|
1332
1601
|
mapping: e,
|
|
1333
1602
|
matchedPattern: null,
|
|
1334
1603
|
specificity: t.value.length
|
|
@@ -1340,13 +1609,13 @@ function Wt(e) {
|
|
|
1340
1609
|
mapping: i.mapping,
|
|
1341
1610
|
matchedPattern: null
|
|
1342
1611
|
};
|
|
1343
|
-
let a =
|
|
1344
|
-
if (
|
|
1345
|
-
let n =
|
|
1346
|
-
return !n || !
|
|
1612
|
+
let a = Wn(r.flatMap((e) => {
|
|
1613
|
+
if (J(e.workspace_identity)) return [];
|
|
1614
|
+
let n = J(e.project_pattern);
|
|
1615
|
+
return !n || !Bn(t.value, n) ? [] : [{
|
|
1347
1616
|
mapping: e,
|
|
1348
|
-
matchedPattern:
|
|
1349
|
-
specificity:
|
|
1617
|
+
matchedPattern: Y(n),
|
|
1618
|
+
specificity: zn(n)
|
|
1350
1619
|
}];
|
|
1351
1620
|
}));
|
|
1352
1621
|
return a ? {
|
|
@@ -1363,11 +1632,11 @@ function Wt(e) {
|
|
|
1363
1632
|
matchedPattern: null
|
|
1364
1633
|
};
|
|
1365
1634
|
}
|
|
1366
|
-
function
|
|
1367
|
-
let n = new Set([
|
|
1635
|
+
function Kn(e, t) {
|
|
1636
|
+
let n = /* @__PURE__ */ new Set([
|
|
1368
1637
|
"",
|
|
1369
|
-
|
|
1370
|
-
|
|
1638
|
+
jn,
|
|
1639
|
+
Mn
|
|
1371
1640
|
]), r = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
|
|
1372
1641
|
for (let e of r) e.scope_id != null && n.add(e.scope_id);
|
|
1373
1642
|
let i = e.prepare("SELECT sm.scope_id AS scope_id\n FROM scope_memberships sm\n JOIN replication_scopes rs ON rs.scope_id = sm.scope_id\n WHERE sm.device_id = ?\n AND sm.status = 'active'\n AND rs.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch").all(t);
|
|
@@ -1376,29 +1645,29 @@ function Gt(e, t) {
|
|
|
1376
1645
|
}
|
|
1377
1646
|
//#endregion
|
|
1378
1647
|
//#region src/project-share-intent.ts
|
|
1379
|
-
var
|
|
1380
|
-
function
|
|
1648
|
+
var qn = "existing_and_future";
|
|
1649
|
+
function Jn(e) {
|
|
1381
1650
|
return t("sha256").update(JSON.stringify(e)).digest("hex");
|
|
1382
1651
|
}
|
|
1383
|
-
function
|
|
1384
|
-
return
|
|
1652
|
+
function Yn(e) {
|
|
1653
|
+
return Jn({
|
|
1385
1654
|
v: 1,
|
|
1386
|
-
historyPolicy:
|
|
1655
|
+
historyPolicy: qn,
|
|
1387
1656
|
projects: e.map((e) => ({
|
|
1388
1657
|
canonicalIdentity: e.canonicalIdentity,
|
|
1389
1658
|
existingMemoryCount: e.existingMemoryCount
|
|
1390
1659
|
})).toSorted((e, t) => e.canonicalIdentity.localeCompare(t.canonicalIdentity))
|
|
1391
1660
|
});
|
|
1392
1661
|
}
|
|
1393
|
-
function
|
|
1394
|
-
return
|
|
1662
|
+
function Xn(e) {
|
|
1663
|
+
return Yn(e.map((e) => ({
|
|
1395
1664
|
canonicalIdentity: e.canonical_identity,
|
|
1396
1665
|
displayName: e.display_name,
|
|
1397
1666
|
identitySource: "coordinator_acceptance",
|
|
1398
1667
|
existingMemoryCount: e.existing_memory_count
|
|
1399
1668
|
})));
|
|
1400
1669
|
}
|
|
1401
|
-
function
|
|
1670
|
+
function Zn(e) {
|
|
1402
1671
|
if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("operation_intent_invalid");
|
|
1403
1672
|
let t = e.map((e) => {
|
|
1404
1673
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
|
|
@@ -1406,11 +1675,11 @@ function Xt(e) {
|
|
|
1406
1675
|
if (typeof t.canonical_identity != "string" || typeof t.display_name != "string") throw Error("operation_intent_invalid");
|
|
1407
1676
|
let n = t.canonical_identity, r = n.trim(), i = t.display_name, a;
|
|
1408
1677
|
try {
|
|
1409
|
-
a =
|
|
1678
|
+
a = F(i, "project_name");
|
|
1410
1679
|
} catch {
|
|
1411
1680
|
throw Error("operation_intent_invalid");
|
|
1412
1681
|
}
|
|
1413
|
-
let o = t.existing_memory_count, s =
|
|
1682
|
+
let o = t.existing_memory_count, s = In({ gitRemote: r }).value;
|
|
1414
1683
|
if (!r || r !== n || r.length > 2048 || r.startsWith("unmapped:") || s !== r || a !== i || !Number.isSafeInteger(o) || Number(o) < 0 || /[\p{Cc}\p{Cf}]/u.test(r) || /[\p{Cc}\p{Cf}]/u.test(a)) throw Error("operation_intent_invalid");
|
|
1415
1684
|
return {
|
|
1416
1685
|
canonical_identity: r,
|
|
@@ -1423,20 +1692,20 @@ function Xt(e) {
|
|
|
1423
1692
|
}
|
|
1424
1693
|
//#endregion
|
|
1425
1694
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
|
|
1426
|
-
function
|
|
1695
|
+
function Qn(e) {
|
|
1427
1696
|
let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
|
|
1428
1697
|
return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
|
|
1429
1698
|
}
|
|
1430
|
-
function
|
|
1431
|
-
let [e, t] =
|
|
1699
|
+
function $n() {
|
|
1700
|
+
let [e, t] = Qn();
|
|
1432
1701
|
return e * 1e3 + Math.floor(t / 1e6);
|
|
1433
1702
|
}
|
|
1434
|
-
function
|
|
1703
|
+
function er(e) {
|
|
1435
1704
|
return new Promise((t) => setTimeout(t, e));
|
|
1436
1705
|
}
|
|
1437
1706
|
//#endregion
|
|
1438
1707
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
|
|
1439
|
-
var
|
|
1708
|
+
var tr = class {
|
|
1440
1709
|
bucketSize;
|
|
1441
1710
|
tokensPerInterval;
|
|
1442
1711
|
interval;
|
|
@@ -1451,30 +1720,31 @@ var $t = class {
|
|
|
1451
1720
|
break;
|
|
1452
1721
|
case "min":
|
|
1453
1722
|
case "minute":
|
|
1454
|
-
this.interval =
|
|
1723
|
+
this.interval = 6e4;
|
|
1455
1724
|
break;
|
|
1456
1725
|
case "hr":
|
|
1457
1726
|
case "hour":
|
|
1458
|
-
this.interval =
|
|
1727
|
+
this.interval = 36e5;
|
|
1459
1728
|
break;
|
|
1460
1729
|
case "day":
|
|
1461
|
-
this.interval =
|
|
1730
|
+
this.interval = 864e5;
|
|
1462
1731
|
break;
|
|
1463
1732
|
default: throw Error("Invalid interval " + n);
|
|
1464
1733
|
}
|
|
1465
1734
|
else this.interval = n;
|
|
1466
|
-
this.parentBucket = r, this.content = 0, this.lastDrip =
|
|
1735
|
+
this.parentBucket = r, this.content = 0, this.lastDrip = $n();
|
|
1467
1736
|
}
|
|
1468
1737
|
async removeTokens(e) {
|
|
1469
1738
|
if (this.bucketSize === 0) return Infinity;
|
|
1470
1739
|
if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
|
|
1471
1740
|
this.drip();
|
|
1472
|
-
let t = async () => (await
|
|
1741
|
+
let t = async () => (await er(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
|
|
1473
1742
|
if (e > this.content) return t();
|
|
1474
1743
|
if (this.parentBucket != null) {
|
|
1475
1744
|
let n = await this.parentBucket.removeTokens(e);
|
|
1476
1745
|
return e > this.content ? t() : (this.content -= e, Math.min(n, this.content));
|
|
1477
|
-
}
|
|
1746
|
+
}
|
|
1747
|
+
return this.content -= e, this.content;
|
|
1478
1748
|
}
|
|
1479
1749
|
tryRemoveTokens(e) {
|
|
1480
1750
|
return this.bucketSize ? e > this.bucketSize || (this.drip(), e > this.content) || this.parentBucket && !this.parentBucket.tryRemoveTokens(e) ? !1 : (this.content -= e, !0) : !0;
|
|
@@ -1484,30 +1754,30 @@ var $t = class {
|
|
|
1484
1754
|
let e = this.content;
|
|
1485
1755
|
return this.content = this.bucketSize, this.content > e;
|
|
1486
1756
|
}
|
|
1487
|
-
let e =
|
|
1757
|
+
let e = $n(), t = Math.max(e - this.lastDrip, 0);
|
|
1488
1758
|
this.lastDrip = e;
|
|
1489
1759
|
let n = t * (this.tokensPerInterval / this.interval), r = this.content;
|
|
1490
1760
|
return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
|
|
1491
1761
|
}
|
|
1492
|
-
},
|
|
1762
|
+
}, nr = class {
|
|
1493
1763
|
tokenBucket;
|
|
1494
1764
|
curIntervalStart;
|
|
1495
1765
|
tokensThisInterval;
|
|
1496
1766
|
fireImmediately;
|
|
1497
1767
|
constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
|
|
1498
|
-
this.tokenBucket = new
|
|
1768
|
+
this.tokenBucket = new tr({
|
|
1499
1769
|
bucketSize: e,
|
|
1500
1770
|
tokensPerInterval: e,
|
|
1501
1771
|
interval: t
|
|
1502
|
-
}), this.tokenBucket.content = e, this.curIntervalStart =
|
|
1772
|
+
}), this.tokenBucket.content = e, this.curIntervalStart = $n(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
|
|
1503
1773
|
}
|
|
1504
1774
|
async removeTokens(e) {
|
|
1505
1775
|
if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
|
|
1506
|
-
let t =
|
|
1776
|
+
let t = $n();
|
|
1507
1777
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
|
|
1508
1778
|
if (this.fireImmediately) return -1;
|
|
1509
1779
|
{
|
|
1510
|
-
await
|
|
1780
|
+
await er(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
|
|
1511
1781
|
let n = await this.tokenBucket.removeTokens(e);
|
|
1512
1782
|
return this.tokensThisInterval += e, n;
|
|
1513
1783
|
}
|
|
@@ -1517,7 +1787,7 @@ var $t = class {
|
|
|
1517
1787
|
}
|
|
1518
1788
|
tryRemoveTokens(e) {
|
|
1519
1789
|
if (e > this.tokenBucket.bucketSize) return !1;
|
|
1520
|
-
let t =
|
|
1790
|
+
let t = $n();
|
|
1521
1791
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
|
|
1522
1792
|
let n = this.tokenBucket.tryRemoveTokens(e);
|
|
1523
1793
|
return n && (this.tokensThisInterval += e), n;
|
|
@@ -1528,7 +1798,7 @@ var $t = class {
|
|
|
1528
1798
|
};
|
|
1529
1799
|
//#endregion
|
|
1530
1800
|
//#region src/request-rate-limit.ts
|
|
1531
|
-
function
|
|
1801
|
+
function rr(e = {}) {
|
|
1532
1802
|
let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
|
|
1533
1803
|
function a(e) {
|
|
1534
1804
|
return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
|
|
@@ -1545,7 +1815,7 @@ function tn(e = {}) {
|
|
|
1545
1815
|
o(l);
|
|
1546
1816
|
let u = `${c}:${e}`, d = r.get(u);
|
|
1547
1817
|
return d || (d = {
|
|
1548
|
-
limiter: new
|
|
1818
|
+
limiter: new nr({
|
|
1549
1819
|
tokensPerInterval: c,
|
|
1550
1820
|
interval: t,
|
|
1551
1821
|
fireImmediately: !0
|
|
@@ -1562,8 +1832,8 @@ function tn(e = {}) {
|
|
|
1562
1832
|
}
|
|
1563
1833
|
//#endregion
|
|
1564
1834
|
//#region src/scope-membership-semantics.ts
|
|
1565
|
-
var
|
|
1566
|
-
function
|
|
1835
|
+
var ir = "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.";
|
|
1836
|
+
function ar(e) {
|
|
1567
1837
|
let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
|
|
1568
1838
|
return t == null || n == null ? {
|
|
1569
1839
|
membership_epoch: t,
|
|
@@ -1577,19 +1847,19 @@ function rn(e) {
|
|
|
1577
1847
|
reason: t < n ? "stale_epoch" : "current"
|
|
1578
1848
|
};
|
|
1579
1849
|
}
|
|
1580
|
-
function
|
|
1850
|
+
function or(e) {
|
|
1581
1851
|
return {
|
|
1582
1852
|
scope_id: e.scopeId,
|
|
1583
1853
|
device_id: e.deviceId,
|
|
1584
1854
|
membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
|
|
1585
1855
|
prevents_future_sync: !0,
|
|
1586
1856
|
deletes_already_copied_data: !1,
|
|
1587
|
-
message:
|
|
1857
|
+
message: ir
|
|
1588
1858
|
};
|
|
1589
1859
|
}
|
|
1590
1860
|
//#endregion
|
|
1591
1861
|
//#region src/sync-auth-constants.ts
|
|
1592
|
-
var
|
|
1862
|
+
var sr = 300, cr = 65536, lr = E + 1024, X = "X-Codemem-Coordinator-Admin", ur = "X-Codemem-Coordinator-Admin-Actor", dr = 120, fr = 30;
|
|
1593
1863
|
function Z(e, t) {
|
|
1594
1864
|
let n = t.adminSecret();
|
|
1595
1865
|
if (!n) return {
|
|
@@ -1608,14 +1878,14 @@ function Z(e, t) {
|
|
|
1608
1878
|
error: "missing_admin_header"
|
|
1609
1879
|
};
|
|
1610
1880
|
}
|
|
1611
|
-
function
|
|
1881
|
+
function pr(e) {
|
|
1612
1882
|
let t = new URL(e);
|
|
1613
1883
|
return t.search ? `${t.pathname}${t.search}` : t.pathname;
|
|
1614
1884
|
}
|
|
1615
|
-
async function
|
|
1885
|
+
async function mr(e, t, n, r) {
|
|
1616
1886
|
return await e.recordNonce(t, n, r);
|
|
1617
1887
|
}
|
|
1618
|
-
async function
|
|
1888
|
+
async function hr(e, t) {
|
|
1619
1889
|
await e.cleanupNonces(t);
|
|
1620
1890
|
}
|
|
1621
1891
|
async function Q(e, t, n, r) {
|
|
@@ -1651,7 +1921,7 @@ async function Q(e, t, n, r) {
|
|
|
1651
1921
|
try {
|
|
1652
1922
|
u = await n({
|
|
1653
1923
|
method: r.method,
|
|
1654
|
-
pathWithQuery:
|
|
1924
|
+
pathWithQuery: pr(r.url),
|
|
1655
1925
|
bodyBytes: r.body,
|
|
1656
1926
|
timestamp: o,
|
|
1657
1927
|
nonce: s,
|
|
@@ -1672,7 +1942,7 @@ async function Q(e, t, n, r) {
|
|
|
1672
1942
|
enrollment: null
|
|
1673
1943
|
};
|
|
1674
1944
|
let d = t.now();
|
|
1675
|
-
return await
|
|
1945
|
+
return await mr(e, i, s, d) ? (await hr(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 6e5)).toISOString()), {
|
|
1676
1946
|
ok: !0,
|
|
1677
1947
|
error: "ok",
|
|
1678
1948
|
enrollment: c
|
|
@@ -1685,54 +1955,54 @@ async function Q(e, t, n, r) {
|
|
|
1685
1955
|
function $(e) {
|
|
1686
1956
|
return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
|
|
1687
1957
|
}
|
|
1688
|
-
function
|
|
1958
|
+
function gr(e) {
|
|
1689
1959
|
if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
|
|
1690
|
-
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier,
|
|
1691
|
-
function
|
|
1692
|
-
let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i =
|
|
1960
|
+
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? rr(), o = Math.max(1, Math.trunc(i.readLimit ?? dr)), s = Math.max(1, Math.trunc(i.mutationLimit ?? fr)), c = Math.max(1, Math.trunc(i.unauthenticatedReadLimit ?? Math.min(20, o))), l = Math.max(1, Math.trunc(i.unauthenticatedMutationLimit ?? Math.min(10, s))), u = new mn(), d = new TextDecoder();
|
|
1961
|
+
function f(e, t, n) {
|
|
1962
|
+
let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = a.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? o : s : r ? c : l);
|
|
1693
1963
|
return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
|
|
1694
1964
|
error: "rate_limited",
|
|
1695
1965
|
retry_after_s: i.retryAfterS
|
|
1696
1966
|
}, 429));
|
|
1697
1967
|
}
|
|
1698
|
-
async function
|
|
1699
|
-
let
|
|
1700
|
-
if (Number.isFinite(
|
|
1701
|
-
let
|
|
1702
|
-
if (!
|
|
1703
|
-
let
|
|
1968
|
+
async function p(e, t = cr) {
|
|
1969
|
+
let n = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1970
|
+
if (Number.isFinite(n) && n > t) return null;
|
|
1971
|
+
let r = e.req.raw.body;
|
|
1972
|
+
if (!r) return /* @__PURE__ */ new Uint8Array();
|
|
1973
|
+
let i = r.getReader(), a = [], o = 0;
|
|
1704
1974
|
try {
|
|
1705
1975
|
for (;;) {
|
|
1706
|
-
let { done: e, value:
|
|
1976
|
+
let { done: e, value: n } = await i.read();
|
|
1707
1977
|
if (e) break;
|
|
1708
|
-
if (
|
|
1709
|
-
if (
|
|
1710
|
-
|
|
1978
|
+
if (n) {
|
|
1979
|
+
if (o += n.byteLength, o > t) return await i.cancel(), null;
|
|
1980
|
+
a.push(n);
|
|
1711
1981
|
}
|
|
1712
1982
|
}
|
|
1713
1983
|
} finally {
|
|
1714
|
-
|
|
1984
|
+
i.releaseLock();
|
|
1715
1985
|
}
|
|
1716
|
-
let
|
|
1717
|
-
for (let e of
|
|
1718
|
-
return
|
|
1986
|
+
let s = new Uint8Array(o), c = 0;
|
|
1987
|
+
for (let e of a) s.set(e, c), c += e.byteLength;
|
|
1988
|
+
return s;
|
|
1719
1989
|
}
|
|
1720
|
-
function
|
|
1990
|
+
function m(e) {
|
|
1721
1991
|
try {
|
|
1722
|
-
let t = JSON.parse(
|
|
1992
|
+
let t = JSON.parse(d.decode(e));
|
|
1723
1993
|
return typeof t != "object" || !t || Array.isArray(t) ? null : t;
|
|
1724
1994
|
} catch {
|
|
1725
1995
|
return null;
|
|
1726
1996
|
}
|
|
1727
1997
|
}
|
|
1728
|
-
function
|
|
1998
|
+
function h(e, t) {
|
|
1729
1999
|
let n = e[t];
|
|
1730
2000
|
return n == null ? null : String(n).trim() || null;
|
|
1731
2001
|
}
|
|
1732
|
-
function
|
|
2002
|
+
function g(e) {
|
|
1733
2003
|
return e?.trim() || null;
|
|
1734
2004
|
}
|
|
1735
|
-
function
|
|
2005
|
+
function _(e, t) {
|
|
1736
2006
|
let n = e[t];
|
|
1737
2007
|
if (n == null || n === "") return null;
|
|
1738
2008
|
if (typeof n != "number" && typeof n != "string") return NaN;
|
|
@@ -1745,45 +2015,45 @@ function mn(e) {
|
|
|
1745
2015
|
let r = n;
|
|
1746
2016
|
return Number.isFinite(r) ? Math.trunc(r) : NaN;
|
|
1747
2017
|
}
|
|
1748
|
-
function
|
|
2018
|
+
function v(e) {
|
|
1749
2019
|
return [
|
|
1750
2020
|
"1",
|
|
1751
2021
|
"true",
|
|
1752
2022
|
"yes"
|
|
1753
2023
|
].includes(String(e ?? "").trim().toLowerCase());
|
|
1754
2024
|
}
|
|
1755
|
-
function
|
|
2025
|
+
function y(e) {
|
|
1756
2026
|
try {
|
|
1757
|
-
return
|
|
2027
|
+
return Zn(JSON.parse(e ?? ""));
|
|
1758
2028
|
} catch {
|
|
1759
2029
|
throw Error("operation_intent_invalid");
|
|
1760
2030
|
}
|
|
1761
2031
|
}
|
|
1762
|
-
function
|
|
2032
|
+
function ee(e) {
|
|
1763
2033
|
let t = String(e.operation_id ?? "").trim(), n = String(e.reviewed_project_set_digest ?? "").trim();
|
|
1764
2034
|
if (!/^share_[a-f0-9]{40}$/u.test(t) || !/^[a-f0-9]{64}$/u.test(n)) throw Error("operation_intent_invalid");
|
|
1765
|
-
let r =
|
|
1766
|
-
if (
|
|
2035
|
+
let r = y(e.project_intent_json);
|
|
2036
|
+
if (Xn(r) !== n) throw Error("operation_intent_invalid");
|
|
1767
2037
|
return {
|
|
1768
2038
|
operation_id: t,
|
|
1769
2039
|
reviewed_project_set_digest: n,
|
|
1770
2040
|
projects: r
|
|
1771
2041
|
};
|
|
1772
2042
|
}
|
|
1773
|
-
function
|
|
2043
|
+
function b(e) {
|
|
1774
2044
|
try {
|
|
1775
|
-
return
|
|
2045
|
+
return Be(JSON.parse(e ?? ""));
|
|
1776
2046
|
} catch {
|
|
1777
2047
|
throw Error("operation_intent_invalid");
|
|
1778
2048
|
}
|
|
1779
2049
|
}
|
|
1780
|
-
async function
|
|
2050
|
+
async function x(e, t, n) {
|
|
1781
2051
|
if (!t) return n.json({ error: "group_id_required" }, 400);
|
|
1782
2052
|
let r = await e.getGroup(t);
|
|
1783
2053
|
return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
|
|
1784
2054
|
}
|
|
1785
|
-
async function
|
|
1786
|
-
let i = await
|
|
2055
|
+
async function S(e, t, n, r) {
|
|
2056
|
+
let i = await x(e, t, r);
|
|
1787
2057
|
if (i) return {
|
|
1788
2058
|
scope: null,
|
|
1789
2059
|
response: i
|
|
@@ -1804,12 +2074,12 @@ function mn(e) {
|
|
|
1804
2074
|
response: r.json({ error: "scope_not_found" }, 404)
|
|
1805
2075
|
};
|
|
1806
2076
|
}
|
|
1807
|
-
async function
|
|
2077
|
+
async function te(e, n, i) {
|
|
1808
2078
|
let a = await Q(e, t, r, {
|
|
1809
2079
|
method: i.req.method,
|
|
1810
2080
|
url: i.req.url,
|
|
1811
2081
|
groupId: n,
|
|
1812
|
-
body: new Uint8Array(),
|
|
2082
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1813
2083
|
deviceId: i.req.header("X-Opencode-Device") ?? null,
|
|
1814
2084
|
signature: i.req.header("X-Opencode-Signature") ?? null,
|
|
1815
2085
|
timestamp: i.req.header("X-Opencode-Timestamp") ?? null,
|
|
@@ -1817,22 +2087,19 @@ function mn(e) {
|
|
|
1817
2087
|
});
|
|
1818
2088
|
return !a.ok || !a.enrollment ? {
|
|
1819
2089
|
auth: a,
|
|
1820
|
-
response:
|
|
2090
|
+
response: f(i, i.req.path, !1) ?? i.json({ error: a.error }, $(a.error))
|
|
1821
2091
|
} : {
|
|
1822
2092
|
auth: a,
|
|
1823
|
-
response:
|
|
2093
|
+
response: f(i, String(a.enrollment.device_id), !0)
|
|
1824
2094
|
};
|
|
1825
2095
|
}
|
|
1826
|
-
function
|
|
2096
|
+
function C(e, t) {
|
|
1827
2097
|
return e.status === "active" && e.membership_epoch >= t.membership_epoch;
|
|
1828
2098
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
}
|
|
1832
|
-
return d.post("/v1/presence", async (e) => {
|
|
1833
|
-
let i = await m(e);
|
|
2099
|
+
return u.post("/v1/presence", async (e) => {
|
|
2100
|
+
let i = await p(e);
|
|
1834
2101
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1835
|
-
let a =
|
|
2102
|
+
let a = m(i);
|
|
1836
2103
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1837
2104
|
let o = String(a.group_id ?? "").trim();
|
|
1838
2105
|
if (!o) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1848,8 +2115,8 @@ function mn(e) {
|
|
|
1848
2115
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1849
2116
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1850
2117
|
});
|
|
1851
|
-
if (!n.ok || !n.enrollment) return
|
|
1852
|
-
let c =
|
|
2118
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
2119
|
+
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1853
2120
|
if (c) return c;
|
|
1854
2121
|
if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
|
|
1855
2122
|
let l = a.addresses ?? [];
|
|
@@ -1874,7 +2141,7 @@ function mn(e) {
|
|
|
1874
2141
|
} finally {
|
|
1875
2142
|
await s.close();
|
|
1876
2143
|
}
|
|
1877
|
-
}),
|
|
2144
|
+
}), u.get("/v1/peers", async (e) => {
|
|
1878
2145
|
let i = (e.req.query("group_id") ?? "").trim();
|
|
1879
2146
|
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1880
2147
|
let a = n();
|
|
@@ -1883,44 +2150,47 @@ function mn(e) {
|
|
|
1883
2150
|
method: e.req.method,
|
|
1884
2151
|
url: e.req.url,
|
|
1885
2152
|
groupId: i,
|
|
1886
|
-
body: new Uint8Array(),
|
|
2153
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1887
2154
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1888
2155
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1889
2156
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1890
2157
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1891
2158
|
});
|
|
1892
|
-
if (!n.ok || !n.enrollment) return
|
|
1893
|
-
let o =
|
|
2159
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
2160
|
+
let o = f(e, String(n.enrollment.device_id), !0);
|
|
1894
2161
|
if (o) return o;
|
|
1895
2162
|
let s = await a.listGroupPeers(i, String(n.enrollment.device_id));
|
|
1896
2163
|
return e.json({ items: s });
|
|
1897
2164
|
} finally {
|
|
1898
2165
|
await a.close();
|
|
1899
2166
|
}
|
|
1900
|
-
}),
|
|
2167
|
+
}), u.get("/v1/scopes", async (e) => {
|
|
1901
2168
|
let t = (e.req.query("group_id") ?? "").trim();
|
|
1902
2169
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1903
2170
|
let r = n();
|
|
1904
2171
|
try {
|
|
1905
|
-
let { auth: n, response: i } = await
|
|
2172
|
+
let { auth: n, response: i } = await te(r, t, e);
|
|
1906
2173
|
if (i) return i;
|
|
1907
2174
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1908
2175
|
let a = await r.listScopes({
|
|
1909
2176
|
groupId: t,
|
|
1910
2177
|
includeInactive: !1
|
|
1911
|
-
}), o = []
|
|
1912
|
-
|
|
1913
|
-
|
|
2178
|
+
}), o = await r.listDeviceScopeMemberships(String(n.enrollment.device_id), !1), s = new Map(o.map((e) => [e.scope_id, e])), c = a.filter((e) => {
|
|
2179
|
+
if (e.status !== "active") return !1;
|
|
2180
|
+
let t = s.get(e.scope_id);
|
|
2181
|
+
return !!(t && C(t, e));
|
|
2182
|
+
});
|
|
2183
|
+
return e.json({ items: c });
|
|
1914
2184
|
} finally {
|
|
1915
2185
|
await r.close();
|
|
1916
2186
|
}
|
|
1917
|
-
}),
|
|
2187
|
+
}), u.get("/v1/scopes/:scope_id/members", async (e) => {
|
|
1918
2188
|
let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
|
|
1919
2189
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1920
2190
|
if (!r) return e.json({ error: "scope_id_required" }, 400);
|
|
1921
2191
|
let i = n();
|
|
1922
2192
|
try {
|
|
1923
|
-
let { auth: n, response: a } = await
|
|
2193
|
+
let { auth: n, response: a } = await te(i, t, e);
|
|
1924
2194
|
if (a) return a;
|
|
1925
2195
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1926
2196
|
let o = (await i.listScopes({
|
|
@@ -1929,11 +2199,11 @@ function mn(e) {
|
|
|
1929
2199
|
})).find((e) => e.scope_id === r) ?? null;
|
|
1930
2200
|
if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
|
|
1931
2201
|
let s = await i.listScopeMemberships(r, !1);
|
|
1932
|
-
return s.some((e) => e.device_id === String(n.enrollment?.device_id) &&
|
|
2202
|
+
return s.some((e) => e.device_id === String(n.enrollment?.device_id) && C(e, o)) ? e.json({ items: s.filter((e) => C(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
|
|
1933
2203
|
} finally {
|
|
1934
2204
|
await i.close();
|
|
1935
2205
|
}
|
|
1936
|
-
}),
|
|
2206
|
+
}), u.get("/v1/reciprocal-approvals", async (e) => {
|
|
1937
2207
|
let i = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
|
|
1938
2208
|
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1939
2209
|
if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
|
|
@@ -1943,14 +2213,14 @@ function mn(e) {
|
|
|
1943
2213
|
method: e.req.method,
|
|
1944
2214
|
url: e.req.url,
|
|
1945
2215
|
groupId: i,
|
|
1946
|
-
body: new Uint8Array(),
|
|
2216
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1947
2217
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1948
2218
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1949
2219
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1950
2220
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1951
2221
|
});
|
|
1952
|
-
if (!n.ok || !n.enrollment) return
|
|
1953
|
-
let c =
|
|
2222
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2223
|
+
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1954
2224
|
if (c) return c;
|
|
1955
2225
|
let l = await s.listReciprocalApprovals({
|
|
1956
2226
|
groupId: i,
|
|
@@ -1962,10 +2232,10 @@ function mn(e) {
|
|
|
1962
2232
|
} finally {
|
|
1963
2233
|
await s.close();
|
|
1964
2234
|
}
|
|
1965
|
-
}),
|
|
1966
|
-
let i = await
|
|
2235
|
+
}), u.post("/v1/reciprocal-approvals", async (e) => {
|
|
2236
|
+
let i = await p(e);
|
|
1967
2237
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1968
|
-
let a =
|
|
2238
|
+
let a = m(i);
|
|
1969
2239
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1970
2240
|
let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim(), c = Object.hasOwn(a, "expected_incoming_request_id") ? String(a.expected_incoming_request_id ?? "").trim() : void 0;
|
|
1971
2241
|
if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
|
|
@@ -1981,8 +2251,8 @@ function mn(e) {
|
|
|
1981
2251
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1982
2252
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1983
2253
|
});
|
|
1984
|
-
if (!n.ok || !n.enrollment) return
|
|
1985
|
-
let a =
|
|
2254
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2255
|
+
let a = f(e, String(n.enrollment.device_id), !0);
|
|
1986
2256
|
if (a) return a;
|
|
1987
2257
|
if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
|
|
1988
2258
|
if (!await l.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
|
|
@@ -1998,18 +2268,18 @@ function mn(e) {
|
|
|
1998
2268
|
request: t
|
|
1999
2269
|
});
|
|
2000
2270
|
} catch (t) {
|
|
2001
|
-
if (t instanceof
|
|
2271
|
+
if (t instanceof Ae) return e.json({ error: t.code }, 409);
|
|
2002
2272
|
throw t;
|
|
2003
2273
|
}
|
|
2004
2274
|
} finally {
|
|
2005
2275
|
await l.close();
|
|
2006
2276
|
}
|
|
2007
|
-
}),
|
|
2008
|
-
let i = await
|
|
2277
|
+
}), u.post("/v1/invites/add-device", async (e) => {
|
|
2278
|
+
let i = await p(e);
|
|
2009
2279
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
2010
|
-
let a =
|
|
2280
|
+
let a = m(i);
|
|
2011
2281
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
2012
|
-
let o = new Set([
|
|
2282
|
+
let o = /* @__PURE__ */ new Set([
|
|
2013
2283
|
"group_id",
|
|
2014
2284
|
"expires_at",
|
|
2015
2285
|
"reviewed_preview_digest",
|
|
@@ -2033,14 +2303,14 @@ function mn(e) {
|
|
|
2033
2303
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
2034
2304
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
2035
2305
|
});
|
|
2036
|
-
if (!n.ok || !n.enrollment) return
|
|
2037
|
-
let o =
|
|
2306
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2307
|
+
let o = f(e, String(n.enrollment.device_id), !0);
|
|
2038
2308
|
if (o) return o;
|
|
2039
2309
|
let d = n.enrollment.identity_id;
|
|
2040
2310
|
if (!d || d !== d.trim() || d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "identity_binding_required" }, 403);
|
|
2041
|
-
let
|
|
2311
|
+
let p;
|
|
2042
2312
|
try {
|
|
2043
|
-
|
|
2313
|
+
p = await it(a.reviewed_intent, {
|
|
2044
2314
|
target: {
|
|
2045
2315
|
kind: "add_device",
|
|
2046
2316
|
targetIdentityId: d
|
|
@@ -2048,7 +2318,7 @@ function mn(e) {
|
|
|
2048
2318
|
digest: l
|
|
2049
2319
|
});
|
|
2050
2320
|
} catch (t) {
|
|
2051
|
-
return t instanceof
|
|
2321
|
+
return t instanceof L && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2052
2322
|
}
|
|
2053
2323
|
let m = await u.createInvite({
|
|
2054
2324
|
groupId: s,
|
|
@@ -2059,7 +2329,7 @@ function mn(e) {
|
|
|
2059
2329
|
inviteKind: "add_device",
|
|
2060
2330
|
targetIdentityId: d,
|
|
2061
2331
|
reviewedPreviewDigest: l,
|
|
2062
|
-
reviewedIntent:
|
|
2332
|
+
reviewedIntent: p
|
|
2063
2333
|
}), h = {
|
|
2064
2334
|
v: 1,
|
|
2065
2335
|
kind: "add_device",
|
|
@@ -2072,45 +2342,45 @@ function mn(e) {
|
|
|
2072
2342
|
target_identity_id: m.target_identity_id ?? void 0,
|
|
2073
2343
|
inviter_device_id: m.inviter_device_id ?? void 0,
|
|
2074
2344
|
reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
|
|
2075
|
-
}, g =
|
|
2345
|
+
}, g = yn(h), { token: _, ...v } = m;
|
|
2076
2346
|
return e.json({
|
|
2077
2347
|
ok: !0,
|
|
2078
2348
|
invite: v,
|
|
2079
2349
|
payload: h,
|
|
2080
2350
|
encoded: g,
|
|
2081
|
-
link:
|
|
2351
|
+
link: xn(g)
|
|
2082
2352
|
});
|
|
2083
2353
|
} finally {
|
|
2084
2354
|
await u.close();
|
|
2085
2355
|
}
|
|
2086
|
-
}),
|
|
2356
|
+
}), u.post("/v1/admin/devices", async (e) => {
|
|
2087
2357
|
let r = Z(e.req.header(X), t);
|
|
2088
|
-
if (!r.ok) return
|
|
2089
|
-
let i =
|
|
2358
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2359
|
+
let i = f(e, "admin", !0);
|
|
2090
2360
|
if (i) return i;
|
|
2091
|
-
let a = await
|
|
2361
|
+
let a = await p(e);
|
|
2092
2362
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2093
|
-
let o =
|
|
2363
|
+
let o = m(a);
|
|
2094
2364
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2095
2365
|
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;
|
|
2096
2366
|
if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
|
|
2097
|
-
if (
|
|
2098
|
-
let
|
|
2367
|
+
if (ot(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
2368
|
+
let h = n();
|
|
2099
2369
|
try {
|
|
2100
|
-
await
|
|
2370
|
+
await h.createGroup(s), await h.enrollDevice(s, {
|
|
2101
2371
|
deviceId: c,
|
|
2102
2372
|
fingerprint: l,
|
|
2103
2373
|
publicKey: u,
|
|
2104
2374
|
displayName: d
|
|
2105
2375
|
});
|
|
2106
2376
|
} finally {
|
|
2107
|
-
await
|
|
2377
|
+
await h.close();
|
|
2108
2378
|
}
|
|
2109
2379
|
return e.json({ ok: !0 });
|
|
2110
|
-
}),
|
|
2380
|
+
}), u.get("/v1/admin/groups", async (e) => {
|
|
2111
2381
|
let r = Z(e.req.header(X), t);
|
|
2112
|
-
if (!r.ok) return
|
|
2113
|
-
let i =
|
|
2382
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2383
|
+
let i = f(e, "admin", !0);
|
|
2114
2384
|
if (i) return i;
|
|
2115
2385
|
let a = [
|
|
2116
2386
|
"1",
|
|
@@ -2122,14 +2392,14 @@ function mn(e) {
|
|
|
2122
2392
|
} finally {
|
|
2123
2393
|
await o.close();
|
|
2124
2394
|
}
|
|
2125
|
-
}),
|
|
2395
|
+
}), u.post("/v1/admin/groups", async (e) => {
|
|
2126
2396
|
let r = Z(e.req.header(X), t);
|
|
2127
|
-
if (!r.ok) return
|
|
2128
|
-
let i =
|
|
2397
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2398
|
+
let i = f(e, "admin", !0);
|
|
2129
2399
|
if (i) return i;
|
|
2130
|
-
let a = await
|
|
2400
|
+
let a = await p(e);
|
|
2131
2401
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2132
|
-
let o =
|
|
2402
|
+
let o = m(a);
|
|
2133
2403
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2134
2404
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
|
|
2135
2405
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2142,14 +2412,14 @@ function mn(e) {
|
|
|
2142
2412
|
} finally {
|
|
2143
2413
|
await l.close();
|
|
2144
2414
|
}
|
|
2145
|
-
}),
|
|
2415
|
+
}), u.post("/v1/admin/groups/rename", async (e) => {
|
|
2146
2416
|
let r = Z(e.req.header(X), t);
|
|
2147
|
-
if (!r.ok) return
|
|
2148
|
-
let i =
|
|
2417
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2418
|
+
let i = f(e, "admin", !0);
|
|
2149
2419
|
if (i) return i;
|
|
2150
|
-
let a = await
|
|
2420
|
+
let a = await p(e);
|
|
2151
2421
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2152
|
-
let o =
|
|
2422
|
+
let o = m(a);
|
|
2153
2423
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2154
2424
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
|
|
2155
2425
|
if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
|
|
@@ -2162,14 +2432,14 @@ function mn(e) {
|
|
|
2162
2432
|
} finally {
|
|
2163
2433
|
await l.close();
|
|
2164
2434
|
}
|
|
2165
|
-
}),
|
|
2435
|
+
}), u.post("/v1/admin/groups/archive", async (e) => {
|
|
2166
2436
|
let r = Z(e.req.header(X), t);
|
|
2167
|
-
if (!r.ok) return
|
|
2168
|
-
let i =
|
|
2437
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2438
|
+
let i = f(e, "admin", !0);
|
|
2169
2439
|
if (i) return i;
|
|
2170
|
-
let a = await
|
|
2440
|
+
let a = await p(e);
|
|
2171
2441
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2172
|
-
let o =
|
|
2442
|
+
let o = m(a);
|
|
2173
2443
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2174
2444
|
let s = String(o.group_id ?? "").trim();
|
|
2175
2445
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2182,14 +2452,14 @@ function mn(e) {
|
|
|
2182
2452
|
} finally {
|
|
2183
2453
|
await c.close();
|
|
2184
2454
|
}
|
|
2185
|
-
}),
|
|
2455
|
+
}), u.post("/v1/admin/groups/unarchive", async (e) => {
|
|
2186
2456
|
let r = Z(e.req.header(X), t);
|
|
2187
|
-
if (!r.ok) return
|
|
2188
|
-
let i =
|
|
2457
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2458
|
+
let i = f(e, "admin", !0);
|
|
2189
2459
|
if (i) return i;
|
|
2190
|
-
let a = await
|
|
2460
|
+
let a = await p(e);
|
|
2191
2461
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2192
|
-
let o =
|
|
2462
|
+
let o = m(a);
|
|
2193
2463
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2194
2464
|
let s = String(o.group_id ?? "").trim();
|
|
2195
2465
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2202,16 +2472,16 @@ function mn(e) {
|
|
|
2202
2472
|
} finally {
|
|
2203
2473
|
await c.close();
|
|
2204
2474
|
}
|
|
2205
|
-
}),
|
|
2475
|
+
}), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
2206
2476
|
let r = Z(e.req.header(X), t);
|
|
2207
|
-
if (!r.ok) return
|
|
2208
|
-
let i =
|
|
2477
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2478
|
+
let i = f(e, "admin", !0);
|
|
2209
2479
|
if (i) return i;
|
|
2210
2480
|
let a = String(e.req.param("group_id") ?? "").trim(), o = n();
|
|
2211
2481
|
try {
|
|
2212
|
-
let t = await
|
|
2482
|
+
let t = await x(o, a, e);
|
|
2213
2483
|
if (t) return t;
|
|
2214
|
-
let n =
|
|
2484
|
+
let n = v(e.req.query("include_inactive"));
|
|
2215
2485
|
return e.json({ items: await o.listScopes({
|
|
2216
2486
|
groupId: a,
|
|
2217
2487
|
includeInactive: n
|
|
@@ -2219,33 +2489,33 @@ function mn(e) {
|
|
|
2219
2489
|
} finally {
|
|
2220
2490
|
await o.close();
|
|
2221
2491
|
}
|
|
2222
|
-
}),
|
|
2492
|
+
}), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
2223
2493
|
let r = Z(e.req.header(X), t);
|
|
2224
|
-
if (!r.ok) return
|
|
2225
|
-
let i =
|
|
2494
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2495
|
+
let i = f(e, "admin", !0);
|
|
2226
2496
|
if (i) return i;
|
|
2227
|
-
let a = await
|
|
2497
|
+
let a = await p(e);
|
|
2228
2498
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2229
|
-
let o =
|
|
2499
|
+
let o = m(a);
|
|
2230
2500
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2231
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c =
|
|
2501
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
|
|
2232
2502
|
if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
|
|
2233
2503
|
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2234
2504
|
let d = n();
|
|
2235
2505
|
try {
|
|
2236
|
-
let t = await
|
|
2506
|
+
let t = await x(d, s, e);
|
|
2237
2507
|
if (t) return t;
|
|
2238
2508
|
let n = await d.createScope({
|
|
2239
2509
|
scopeId: c,
|
|
2240
2510
|
label: l,
|
|
2241
|
-
kind:
|
|
2242
|
-
authorityType:
|
|
2243
|
-
coordinatorId:
|
|
2511
|
+
kind: h(o, "kind"),
|
|
2512
|
+
authorityType: h(o, "authority_type"),
|
|
2513
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
2244
2514
|
groupId: s,
|
|
2245
|
-
manifestIssuerDeviceId:
|
|
2515
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
2246
2516
|
membershipEpoch: u,
|
|
2247
|
-
manifestHash:
|
|
2248
|
-
status:
|
|
2517
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2518
|
+
status: h(o, "status")
|
|
2249
2519
|
});
|
|
2250
2520
|
return e.json({
|
|
2251
2521
|
ok: !0,
|
|
@@ -2256,33 +2526,33 @@ function mn(e) {
|
|
|
2256
2526
|
} finally {
|
|
2257
2527
|
await d.close();
|
|
2258
2528
|
}
|
|
2259
|
-
}),
|
|
2529
|
+
}), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
|
|
2260
2530
|
let r = Z(e.req.header(X), t);
|
|
2261
|
-
if (!r.ok) return
|
|
2262
|
-
let i =
|
|
2531
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2532
|
+
let i = f(e, "admin", !0);
|
|
2263
2533
|
if (i) return i;
|
|
2264
|
-
let a = await
|
|
2534
|
+
let a = await p(e);
|
|
2265
2535
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2266
|
-
let o =
|
|
2536
|
+
let o = m(a);
|
|
2267
2537
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2268
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l =
|
|
2538
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
|
|
2269
2539
|
if (!c) return e.json({ error: "scope_id_required" }, 400);
|
|
2270
2540
|
if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2271
2541
|
let u = n();
|
|
2272
2542
|
try {
|
|
2273
|
-
let t = await
|
|
2543
|
+
let t = await S(u, s, c, e);
|
|
2274
2544
|
if (t.response) return t.response;
|
|
2275
2545
|
let n = await u.updateScope({
|
|
2276
2546
|
scopeId: c,
|
|
2277
|
-
label: o.label === void 0 ? void 0 :
|
|
2278
|
-
kind: o.kind === void 0 ? void 0 :
|
|
2279
|
-
authorityType: o.authority_type === void 0 ? void 0 :
|
|
2280
|
-
coordinatorId: o.coordinator_id === void 0 ? void 0 :
|
|
2547
|
+
label: o.label === void 0 ? void 0 : h(o, "label"),
|
|
2548
|
+
kind: o.kind === void 0 ? void 0 : h(o, "kind"),
|
|
2549
|
+
authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
|
|
2550
|
+
coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
|
|
2281
2551
|
groupId: s,
|
|
2282
|
-
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 :
|
|
2552
|
+
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
|
|
2283
2553
|
membershipEpoch: l,
|
|
2284
|
-
manifestHash: o.manifest_hash === void 0 ? void 0 :
|
|
2285
|
-
status: o.status === void 0 ? void 0 :
|
|
2554
|
+
manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
|
|
2555
|
+
status: o.status === void 0 ? void 0 : h(o, "status")
|
|
2286
2556
|
});
|
|
2287
2557
|
return n ? e.json({
|
|
2288
2558
|
ok: !0,
|
|
@@ -2293,48 +2563,48 @@ function mn(e) {
|
|
|
2293
2563
|
} finally {
|
|
2294
2564
|
await u.close();
|
|
2295
2565
|
}
|
|
2296
|
-
}),
|
|
2566
|
+
}), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2297
2567
|
let r = Z(e.req.header(X), t);
|
|
2298
|
-
if (!r.ok) return
|
|
2299
|
-
let i =
|
|
2568
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2569
|
+
let i = f(e, "admin", !0);
|
|
2300
2570
|
if (i) return i;
|
|
2301
2571
|
let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
|
|
2302
2572
|
try {
|
|
2303
|
-
let t = await
|
|
2304
|
-
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o,
|
|
2573
|
+
let t = await S(s, a, o, e);
|
|
2574
|
+
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
|
|
2305
2575
|
} finally {
|
|
2306
2576
|
await s.close();
|
|
2307
2577
|
}
|
|
2308
|
-
}),
|
|
2578
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2309
2579
|
let r = Z(e.req.header(X), t);
|
|
2310
|
-
if (!r.ok) return
|
|
2311
|
-
let
|
|
2312
|
-
if (
|
|
2313
|
-
let
|
|
2314
|
-
if (
|
|
2315
|
-
let
|
|
2316
|
-
if (!
|
|
2317
|
-
let
|
|
2318
|
-
if (!
|
|
2319
|
-
if (!
|
|
2320
|
-
if (Number.isNaN(
|
|
2321
|
-
let
|
|
2580
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2581
|
+
let i = f(e, "admin", !0);
|
|
2582
|
+
if (i) return i;
|
|
2583
|
+
let a = await p(e);
|
|
2584
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2585
|
+
let o = m(a);
|
|
2586
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2587
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = h(o, "effect_id"), u = h(o, "device_id"), d = _(o, "membership_epoch");
|
|
2588
|
+
if (!l) return e.json({ error: "effect_id_required" }, 400);
|
|
2589
|
+
if (!u) return e.json({ error: "device_id_required" }, 400);
|
|
2590
|
+
if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2591
|
+
let v = n();
|
|
2322
2592
|
try {
|
|
2323
|
-
let t = await
|
|
2593
|
+
let t = await S(v, s, c, e);
|
|
2324
2594
|
if (t.response) return t.response;
|
|
2325
|
-
let n = await
|
|
2326
|
-
effectId:
|
|
2327
|
-
scopeId:
|
|
2328
|
-
deviceId:
|
|
2329
|
-
role:
|
|
2330
|
-
membershipEpoch:
|
|
2331
|
-
coordinatorId:
|
|
2332
|
-
groupId:
|
|
2333
|
-
manifestIssuerDeviceId:
|
|
2334
|
-
manifestHash:
|
|
2335
|
-
signedManifestJson:
|
|
2595
|
+
let n = await v.grantScopeMembership({
|
|
2596
|
+
effectId: l,
|
|
2597
|
+
scopeId: c,
|
|
2598
|
+
deviceId: u,
|
|
2599
|
+
role: h(o, "role"),
|
|
2600
|
+
membershipEpoch: d,
|
|
2601
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
2602
|
+
groupId: s,
|
|
2603
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
2604
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2605
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
2336
2606
|
actorType: "admin",
|
|
2337
|
-
actorId:
|
|
2607
|
+
actorId: g(e.req.header(ur))
|
|
2338
2608
|
});
|
|
2339
2609
|
return e.json({
|
|
2340
2610
|
ok: !0,
|
|
@@ -2342,67 +2612,67 @@ function mn(e) {
|
|
|
2342
2612
|
}, 201);
|
|
2343
2613
|
} catch (t) {
|
|
2344
2614
|
let n = t instanceof Error ? t.message : String(t);
|
|
2345
|
-
if (t instanceof
|
|
2346
|
-
if (t instanceof
|
|
2347
|
-
let r = t instanceof
|
|
2615
|
+
if (t instanceof N && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
|
|
2616
|
+
if (t instanceof N && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
|
|
2617
|
+
let r = t instanceof N && t.code === "scope_inactive";
|
|
2348
2618
|
return e.json({ error: r ? "scope_not_active" : n }, n === "scope_membership_effect_conflict" || r ? 409 : 400);
|
|
2349
2619
|
} finally {
|
|
2350
|
-
await
|
|
2620
|
+
await v.close();
|
|
2351
2621
|
}
|
|
2352
|
-
}),
|
|
2622
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
|
|
2353
2623
|
let r = Z(e.req.header(X), t);
|
|
2354
|
-
if (!r.ok) return
|
|
2355
|
-
let
|
|
2356
|
-
if (
|
|
2357
|
-
let
|
|
2358
|
-
if (
|
|
2359
|
-
let
|
|
2360
|
-
if (!
|
|
2361
|
-
let
|
|
2362
|
-
if (!
|
|
2363
|
-
if (!
|
|
2364
|
-
if (Number.isNaN(
|
|
2365
|
-
let
|
|
2624
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2625
|
+
let i = f(e, "admin", !0);
|
|
2626
|
+
if (i) return i;
|
|
2627
|
+
let a = await p(e);
|
|
2628
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2629
|
+
let o = a.byteLength > 0 ? m(a) : {};
|
|
2630
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2631
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = String(e.req.param("device_id") ?? "").trim(), u = h(o, "effect_id"), d = _(o, "membership_epoch");
|
|
2632
|
+
if (!u) return e.json({ error: "effect_id_required" }, 400);
|
|
2633
|
+
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
2634
|
+
if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2635
|
+
let v = n();
|
|
2366
2636
|
try {
|
|
2367
|
-
let t = await
|
|
2637
|
+
let t = await S(v, s, c, e);
|
|
2368
2638
|
if (t.response) return t.response;
|
|
2369
|
-
if (!await
|
|
2370
|
-
effectId:
|
|
2371
|
-
scopeId:
|
|
2372
|
-
deviceId:
|
|
2373
|
-
groupId:
|
|
2374
|
-
membershipEpoch:
|
|
2375
|
-
manifestHash:
|
|
2376
|
-
signedManifestJson:
|
|
2639
|
+
if (!await v.revokeScopeMembership({
|
|
2640
|
+
effectId: u,
|
|
2641
|
+
scopeId: c,
|
|
2642
|
+
deviceId: l,
|
|
2643
|
+
groupId: s,
|
|
2644
|
+
membershipEpoch: d,
|
|
2645
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2646
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
2377
2647
|
actorType: "admin",
|
|
2378
|
-
actorId:
|
|
2648
|
+
actorId: g(e.req.header(ur))
|
|
2379
2649
|
})) return e.json({ error: "membership_not_found" }, 404);
|
|
2380
2650
|
let n;
|
|
2381
2651
|
try {
|
|
2382
|
-
n = (await
|
|
2652
|
+
n = (await v.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
|
|
2383
2653
|
} catch {
|
|
2384
2654
|
n = void 0;
|
|
2385
2655
|
}
|
|
2386
2656
|
return e.json({
|
|
2387
2657
|
ok: !0,
|
|
2388
|
-
scope_id:
|
|
2389
|
-
device_id:
|
|
2390
|
-
revocation:
|
|
2391
|
-
scopeId:
|
|
2392
|
-
deviceId:
|
|
2393
|
-
membershipEpoch: n?.membership_epoch ??
|
|
2658
|
+
scope_id: c,
|
|
2659
|
+
device_id: l,
|
|
2660
|
+
revocation: or({
|
|
2661
|
+
scopeId: c,
|
|
2662
|
+
deviceId: l,
|
|
2663
|
+
membershipEpoch: n?.membership_epoch ?? d
|
|
2394
2664
|
})
|
|
2395
2665
|
});
|
|
2396
2666
|
} catch (t) {
|
|
2397
2667
|
let n = t instanceof Error ? t.message : String(t);
|
|
2398
|
-
return t instanceof
|
|
2668
|
+
return t instanceof N && t.code === "scope_group_mismatch" ? e.json({ error: "scope_not_found" }, 404) : e.json({ error: n }, n === "scope_membership_effect_conflict" ? 409 : 400);
|
|
2399
2669
|
} finally {
|
|
2400
|
-
await
|
|
2670
|
+
await v.close();
|
|
2401
2671
|
}
|
|
2402
|
-
}),
|
|
2672
|
+
}), u.get("/v1/admin/devices", async (e) => {
|
|
2403
2673
|
let r = Z(e.req.header(X), t);
|
|
2404
|
-
if (!r.ok) return
|
|
2405
|
-
let i =
|
|
2674
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2675
|
+
let i = f(e, "admin", !0);
|
|
2406
2676
|
if (i) return i;
|
|
2407
2677
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2408
2678
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2416,21 +2686,21 @@ function mn(e) {
|
|
|
2416
2686
|
} finally {
|
|
2417
2687
|
await s.close();
|
|
2418
2688
|
}
|
|
2419
|
-
}),
|
|
2689
|
+
}), u.post("/v1/admin/devices/rename", async (e) => {
|
|
2420
2690
|
let r = Z(e.req.header(X), t);
|
|
2421
|
-
if (!r.ok) return
|
|
2422
|
-
let i =
|
|
2691
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2692
|
+
let i = f(e, "admin", !0);
|
|
2423
2693
|
if (i) return i;
|
|
2424
|
-
let a = await
|
|
2694
|
+
let a = await p(e);
|
|
2425
2695
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2426
|
-
let o =
|
|
2696
|
+
let o = m(a);
|
|
2427
2697
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2428
2698
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
|
|
2429
2699
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
2430
2700
|
if (!l) return e.json({ error: "display_name_required" }, 400);
|
|
2431
2701
|
let u;
|
|
2432
2702
|
try {
|
|
2433
|
-
u =
|
|
2703
|
+
u = I(l, "display_name");
|
|
2434
2704
|
} catch (t) {
|
|
2435
2705
|
return e.json({ error: t instanceof Error ? t.message : "display_name_invalid" }, 400);
|
|
2436
2706
|
}
|
|
@@ -2445,14 +2715,14 @@ function mn(e) {
|
|
|
2445
2715
|
} finally {
|
|
2446
2716
|
await d.close();
|
|
2447
2717
|
}
|
|
2448
|
-
}),
|
|
2718
|
+
}), u.post("/v1/admin/devices/disable", async (e) => {
|
|
2449
2719
|
let r = Z(e.req.header(X), t);
|
|
2450
|
-
if (!r.ok) return
|
|
2451
|
-
let i =
|
|
2720
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2721
|
+
let i = f(e, "admin", !0);
|
|
2452
2722
|
if (i) return i;
|
|
2453
|
-
let a = await
|
|
2723
|
+
let a = await p(e);
|
|
2454
2724
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2455
|
-
let o =
|
|
2725
|
+
let o = m(a);
|
|
2456
2726
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2457
2727
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2458
2728
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2462,14 +2732,14 @@ function mn(e) {
|
|
|
2462
2732
|
} finally {
|
|
2463
2733
|
await l.close();
|
|
2464
2734
|
}
|
|
2465
|
-
}),
|
|
2735
|
+
}), u.post("/v1/admin/devices/enable", async (e) => {
|
|
2466
2736
|
let r = Z(e.req.header(X), t);
|
|
2467
|
-
if (!r.ok) return
|
|
2468
|
-
let i =
|
|
2737
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2738
|
+
let i = f(e, "admin", !0);
|
|
2469
2739
|
if (i) return i;
|
|
2470
|
-
let a = await
|
|
2740
|
+
let a = await p(e);
|
|
2471
2741
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2472
|
-
let o =
|
|
2742
|
+
let o = m(a);
|
|
2473
2743
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2474
2744
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2475
2745
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2479,14 +2749,14 @@ function mn(e) {
|
|
|
2479
2749
|
} finally {
|
|
2480
2750
|
await l.close();
|
|
2481
2751
|
}
|
|
2482
|
-
}),
|
|
2752
|
+
}), u.post("/v1/admin/devices/remove", async (e) => {
|
|
2483
2753
|
let r = Z(e.req.header(X), t);
|
|
2484
|
-
if (!r.ok) return
|
|
2485
|
-
let i =
|
|
2754
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2755
|
+
let i = f(e, "admin", !0);
|
|
2486
2756
|
if (i) return i;
|
|
2487
|
-
let a = await
|
|
2757
|
+
let a = await p(e);
|
|
2488
2758
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2489
|
-
let o =
|
|
2759
|
+
let o = m(a);
|
|
2490
2760
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2491
2761
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2492
2762
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2496,49 +2766,127 @@ function mn(e) {
|
|
|
2496
2766
|
} finally {
|
|
2497
2767
|
await l.close();
|
|
2498
2768
|
}
|
|
2499
|
-
}),
|
|
2769
|
+
}), u.post("/v1/admin/legacy-team-completions", async (e) => {
|
|
2770
|
+
let r = Z(e.req.header(X), t);
|
|
2771
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2772
|
+
let i = f(e, "admin", !0);
|
|
2773
|
+
if (i) return i;
|
|
2774
|
+
let a = await p(e, lr);
|
|
2775
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2776
|
+
let o = m(a);
|
|
2777
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2778
|
+
if (Object.keys(o).some((e) => e !== "group_id" && e !== "manifest")) return e.json({ error: "completion_manifest_invalid" }, 400);
|
|
2779
|
+
let s, c;
|
|
2780
|
+
try {
|
|
2781
|
+
let e = de([o.group_id])[0];
|
|
2782
|
+
if (!e) throw Error("completion_manifest_invalid");
|
|
2783
|
+
s = e, c = pe(o.manifest), he(c);
|
|
2784
|
+
} catch {
|
|
2785
|
+
return e.json({ error: "completion_manifest_invalid" }, 400);
|
|
2786
|
+
}
|
|
2787
|
+
let l = n();
|
|
2788
|
+
try {
|
|
2789
|
+
let t = await l.createLegacyTeamCompletion(s, c);
|
|
2790
|
+
return e.json({
|
|
2791
|
+
ok: !0,
|
|
2792
|
+
...t
|
|
2793
|
+
}, t.status === "created" ? 201 : 200);
|
|
2794
|
+
} catch (t) {
|
|
2795
|
+
if (t instanceof oe) return e.json({ error: t.code }, 409);
|
|
2796
|
+
let n = t instanceof Error ? t.message : "completion_manifest_invalid";
|
|
2797
|
+
if (n === "group_not_found") return e.json({ error: n }, 404);
|
|
2798
|
+
if (n === "group_archived" || n === "completion_manifest_unavailable") return e.json({ error: n }, 409);
|
|
2799
|
+
if (n === "completion_manifest_invalid") return e.json({ error: n }, 400);
|
|
2800
|
+
throw t;
|
|
2801
|
+
} finally {
|
|
2802
|
+
await l.close();
|
|
2803
|
+
}
|
|
2804
|
+
}), u.get("/v1/admin/legacy-team-completions", async (e) => {
|
|
2805
|
+
let r = Z(e.req.header(X), t);
|
|
2806
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2807
|
+
let i = f(e, "admin", !0);
|
|
2808
|
+
if (i) return i;
|
|
2809
|
+
let a = String(e.req.query("group_id") ?? "").trim(), o;
|
|
2810
|
+
try {
|
|
2811
|
+
if (de([a]).length !== 1) throw Error("completion_manifest_invalid");
|
|
2812
|
+
o = fe(e.req.query("candidate_ref"));
|
|
2813
|
+
} catch {
|
|
2814
|
+
return e.json({ error: "group_id_and_candidate_ref_required" }, 400);
|
|
2815
|
+
}
|
|
2816
|
+
let s = n();
|
|
2817
|
+
try {
|
|
2818
|
+
let t = await s.getLegacyTeamCompletion(a, o);
|
|
2819
|
+
return t ? e.json({ manifest: t }) : e.json({ error: "completion_not_found" }, 404);
|
|
2820
|
+
} finally {
|
|
2821
|
+
await s.close();
|
|
2822
|
+
}
|
|
2823
|
+
}), u.post("/v1/admin/legacy-team-completions/query", async (e) => {
|
|
2824
|
+
let r = Z(e.req.header(X), t);
|
|
2825
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2826
|
+
let i = f(e, "admin", !0);
|
|
2827
|
+
if (i) return i;
|
|
2828
|
+
let a = await p(e);
|
|
2829
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2830
|
+
let o = m(a);
|
|
2831
|
+
if (!o || Object.keys(o).some((e) => e !== "group_ids")) return e.json({ error: "completion_query_invalid" }, 400);
|
|
2832
|
+
let s;
|
|
2833
|
+
try {
|
|
2834
|
+
if (s = de(o.group_ids), s.length === 0) throw Error("completion_query_invalid");
|
|
2835
|
+
} catch {
|
|
2836
|
+
return e.json({ error: "completion_query_invalid" }, 400);
|
|
2837
|
+
}
|
|
2838
|
+
let c = n();
|
|
2839
|
+
try {
|
|
2840
|
+
return e.json({ items: await c.listLegacyTeamCompletions(s) });
|
|
2841
|
+
} catch (t) {
|
|
2842
|
+
if (t instanceof Error && t.message === "completion_results_too_large") return e.json({ error: t.message }, 413);
|
|
2843
|
+
throw t;
|
|
2844
|
+
} finally {
|
|
2845
|
+
await c.close();
|
|
2846
|
+
}
|
|
2847
|
+
}), u.post("/v1/admin/invites", async (e) => {
|
|
2500
2848
|
let r = Z(e.req.header(X), t);
|
|
2501
|
-
if (!r.ok) return
|
|
2502
|
-
let i =
|
|
2849
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2850
|
+
let i = f(e, "admin", !0);
|
|
2503
2851
|
if (i) return i;
|
|
2504
|
-
let a = await
|
|
2852
|
+
let a = await p(e);
|
|
2505
2853
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2506
|
-
let o =
|
|
2854
|
+
let o = m(a);
|
|
2507
2855
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2508
|
-
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,
|
|
2856
|
+
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, h = String(o.reviewed_project_set_digest ?? "").trim() || null, g = String(o.inviter_actor_id ?? "").trim() || null, _ = String(o.inviter_display_name ?? "").trim() || null, v = String(o.inviter_device_id ?? "").trim() || null, y = String(o.pending_person_id ?? "").trim() || null, ee = String(o.invite_kind ?? o.kind ?? "").trim(), b = String(o.policy_team_id ?? "").trim() || null, x = String(o.target_identity_id ?? "").trim() || null, S = String(o.reviewed_preview_digest ?? "").trim() || null, te, C = null, w = null;
|
|
2509
2857
|
if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
|
|
2510
2858
|
if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
|
|
2511
2859
|
if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
|
|
2512
|
-
if (!!d != !!
|
|
2513
|
-
let
|
|
2860
|
+
if (!!d != !!h) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
|
|
2861
|
+
let T = ee || (d ? "project_share" : "legacy_enrollment");
|
|
2514
2862
|
if (![
|
|
2515
2863
|
"legacy_enrollment",
|
|
2516
2864
|
"project_share",
|
|
2517
2865
|
"team_member",
|
|
2518
2866
|
"add_device"
|
|
2519
|
-
].includes(
|
|
2520
|
-
if (
|
|
2521
|
-
if (
|
|
2522
|
-
if (
|
|
2523
|
-
if ([
|
|
2524
|
-
if (
|
|
2867
|
+
].includes(T)) return e.json({ error: "invite_kind_invalid" }, 400);
|
|
2868
|
+
if (T === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
|
|
2869
|
+
if (S && !/^[a-f0-9]{64}$/u.test(S)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
|
|
2870
|
+
if (T === "team_member" && (!b || !S || x) || T === "add_device" && (!x || !S || b) || !["team_member", "add_device"].includes(T) && (b || x || S)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
|
|
2871
|
+
if ([b, x].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
|
|
2872
|
+
if (T === "team_member" || T === "add_device") {
|
|
2525
2873
|
if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2526
2874
|
try {
|
|
2527
|
-
|
|
2528
|
-
target:
|
|
2875
|
+
te = await it(o.reviewed_intent, {
|
|
2876
|
+
target: T === "team_member" ? {
|
|
2529
2877
|
kind: "team_member",
|
|
2530
|
-
policyTeamId: String(
|
|
2878
|
+
policyTeamId: String(b)
|
|
2531
2879
|
} : {
|
|
2532
2880
|
kind: "add_device",
|
|
2533
|
-
targetIdentityId: String(
|
|
2881
|
+
targetIdentityId: String(x)
|
|
2534
2882
|
},
|
|
2535
|
-
digest: String(
|
|
2883
|
+
digest: String(S)
|
|
2536
2884
|
});
|
|
2537
2885
|
} catch (t) {
|
|
2538
|
-
return t instanceof
|
|
2886
|
+
return t instanceof L && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2539
2887
|
}
|
|
2540
2888
|
} else if (o.reviewed_intent != null) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
|
|
2541
|
-
if (d && !/^share_[a-f0-9]{40}$/u.test(d) ||
|
|
2889
|
+
if (d && !/^share_[a-f0-9]{40}$/u.test(d) || h && !/^[a-f0-9]{64}$/u.test(h)) return e.json({ error: "operation_intent_reference_invalid" }, 400);
|
|
2542
2890
|
if (d) {
|
|
2543
2891
|
if (!g || !_ || !v || !y) return e.json({ error: "project_invite_identity_context_required" }, 400);
|
|
2544
2892
|
if ([
|
|
@@ -2547,44 +2895,44 @@ function mn(e) {
|
|
|
2547
2895
|
y
|
|
2548
2896
|
].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
|
|
2549
2897
|
try {
|
|
2550
|
-
if (
|
|
2898
|
+
if (I(_, "inviter_display_name"), C = Be(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== C.length || (w = o.project_intent.map((e, t) => {
|
|
2551
2899
|
let n;
|
|
2552
2900
|
try {
|
|
2553
|
-
n =
|
|
2901
|
+
n = Zn([e])[0];
|
|
2554
2902
|
} catch {
|
|
2555
2903
|
throw Error("project_intent_invalid");
|
|
2556
2904
|
}
|
|
2557
|
-
let r =
|
|
2905
|
+
let r = C?.[t];
|
|
2558
2906
|
if (!n || !r || n.display_name !== r.display_name || n.existing_memory_count !== r.existing_memory_count) throw Error("project_intent_invalid");
|
|
2559
2907
|
return n;
|
|
2560
|
-
}), new Set(
|
|
2908
|
+
}), new Set(w.map((e) => e.canonical_identity)).size !== w.length)) throw Error("project_intent_invalid");
|
|
2561
2909
|
} catch (t) {
|
|
2562
2910
|
return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
|
|
2563
2911
|
}
|
|
2564
2912
|
}
|
|
2565
|
-
let
|
|
2913
|
+
let E = n();
|
|
2566
2914
|
try {
|
|
2567
|
-
let t = await
|
|
2915
|
+
let t = await E.getGroup(s);
|
|
2568
2916
|
if (!t) return e.json({ error: "group_not_found" }, 404);
|
|
2569
2917
|
if (t.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
2570
|
-
let n = await
|
|
2918
|
+
let n = await E.createInvite({
|
|
2571
2919
|
groupId: s,
|
|
2572
2920
|
policy: c,
|
|
2573
2921
|
expiresAt: l,
|
|
2574
2922
|
createdBy: u,
|
|
2575
2923
|
operationId: d,
|
|
2576
|
-
reviewedProjectSetDigest:
|
|
2924
|
+
reviewedProjectSetDigest: h,
|
|
2577
2925
|
inviterActorId: g,
|
|
2578
2926
|
inviterDisplayName: _,
|
|
2579
2927
|
inviterDeviceId: v,
|
|
2580
2928
|
pendingPersonId: y,
|
|
2581
|
-
projectSummaries:
|
|
2582
|
-
projectIntent:
|
|
2583
|
-
inviteKind:
|
|
2584
|
-
policyTeamId:
|
|
2585
|
-
targetIdentityId:
|
|
2586
|
-
reviewedPreviewDigest:
|
|
2587
|
-
reviewedIntent:
|
|
2929
|
+
projectSummaries: C,
|
|
2930
|
+
projectIntent: w,
|
|
2931
|
+
inviteKind: T,
|
|
2932
|
+
policyTeamId: b,
|
|
2933
|
+
targetIdentityId: x,
|
|
2934
|
+
reviewedPreviewDigest: S,
|
|
2935
|
+
reviewedIntent: te
|
|
2588
2936
|
}), r = {
|
|
2589
2937
|
v: 1,
|
|
2590
2938
|
kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
|
|
@@ -2597,7 +2945,7 @@ function mn(e) {
|
|
|
2597
2945
|
...n.operation_id ? {
|
|
2598
2946
|
operation_id: n.operation_id,
|
|
2599
2947
|
inviter_name: n.inviter_display_name ?? null,
|
|
2600
|
-
project_summaries:
|
|
2948
|
+
project_summaries: C ?? []
|
|
2601
2949
|
} : {},
|
|
2602
2950
|
...n.invite_kind === "team_member" ? {
|
|
2603
2951
|
policy_team_id: n.policy_team_id ?? void 0,
|
|
@@ -2609,25 +2957,25 @@ function mn(e) {
|
|
|
2609
2957
|
inviter_device_id: n.inviter_device_id ?? void 0,
|
|
2610
2958
|
reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
|
|
2611
2959
|
} : {}
|
|
2612
|
-
}, i =
|
|
2960
|
+
}, i = yn(r), { token: a, ...f } = n;
|
|
2613
2961
|
return e.json({
|
|
2614
2962
|
ok: !0,
|
|
2615
|
-
invite:
|
|
2963
|
+
invite: f,
|
|
2616
2964
|
payload: r,
|
|
2617
2965
|
encoded: i,
|
|
2618
|
-
link:
|
|
2966
|
+
link: xn(i)
|
|
2619
2967
|
});
|
|
2620
2968
|
} catch (t) {
|
|
2621
2969
|
if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
|
|
2622
2970
|
if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
|
|
2623
2971
|
throw t;
|
|
2624
2972
|
} finally {
|
|
2625
|
-
await
|
|
2973
|
+
await E.close();
|
|
2626
2974
|
}
|
|
2627
|
-
}),
|
|
2628
|
-
let r = await
|
|
2975
|
+
}), u.post("/v1/invites/inspect", async (e) => {
|
|
2976
|
+
let r = await p(e);
|
|
2629
2977
|
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
2630
|
-
let i =
|
|
2978
|
+
let i = m(r);
|
|
2631
2979
|
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
2632
2980
|
let a = String(i.token ?? "").trim();
|
|
2633
2981
|
if (!a) return e.json({ error: "invite_invalid" }, 404);
|
|
@@ -2667,7 +3015,7 @@ function mn(e) {
|
|
|
2667
3015
|
if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
|
|
2668
3016
|
let i;
|
|
2669
3017
|
try {
|
|
2670
|
-
i =
|
|
3018
|
+
i = b(n.project_summaries_json);
|
|
2671
3019
|
} catch {
|
|
2672
3020
|
return e.json({ error: "invite_invalid" }, 409);
|
|
2673
3021
|
}
|
|
@@ -2682,10 +3030,10 @@ function mn(e) {
|
|
|
2682
3030
|
} finally {
|
|
2683
3031
|
await o.close();
|
|
2684
3032
|
}
|
|
2685
|
-
}),
|
|
3033
|
+
}), u.get("/v1/admin/invites", async (e) => {
|
|
2686
3034
|
let r = Z(e.req.header(X), t);
|
|
2687
|
-
if (!r.ok) return
|
|
2688
|
-
let i =
|
|
3035
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3036
|
+
let i = f(e, "admin", !0);
|
|
2689
3037
|
if (i) return i;
|
|
2690
3038
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2691
3039
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2696,7 +3044,7 @@ function mn(e) {
|
|
|
2696
3044
|
} finally {
|
|
2697
3045
|
await o.close();
|
|
2698
3046
|
}
|
|
2699
|
-
}),
|
|
3047
|
+
}), u.get("/v1/admin/project-invites/:operationId", async (e) => {
|
|
2700
3048
|
let r = Z(e.req.header(X), t);
|
|
2701
3049
|
if (!r.ok) return e.json({ error: r.error }, 401);
|
|
2702
3050
|
let i = String(e.req.param("operationId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
|
|
@@ -2707,7 +3055,7 @@ function mn(e) {
|
|
|
2707
3055
|
if (!n) return e.json({ error: "operation_not_found" }, 404);
|
|
2708
3056
|
let r;
|
|
2709
3057
|
try {
|
|
2710
|
-
r =
|
|
3058
|
+
r = y(n.project_intent_json);
|
|
2711
3059
|
} catch {
|
|
2712
3060
|
return e.json({ error: "operation_intent_invalid" }, 409);
|
|
2713
3061
|
}
|
|
@@ -2717,7 +3065,7 @@ function mn(e) {
|
|
|
2717
3065
|
display_name: String(e.display_name ?? ""),
|
|
2718
3066
|
existing_memory_count: Number(e.existing_memory_count ?? 0)
|
|
2719
3067
|
}));
|
|
2720
|
-
s =
|
|
3068
|
+
s = xn(yn({
|
|
2721
3069
|
v: 1,
|
|
2722
3070
|
kind: "coordinator_team_invite",
|
|
2723
3071
|
coordinator_url: new URL(e.req.url).origin,
|
|
@@ -2752,10 +3100,10 @@ function mn(e) {
|
|
|
2752
3100
|
} finally {
|
|
2753
3101
|
await o.close();
|
|
2754
3102
|
}
|
|
2755
|
-
}),
|
|
3103
|
+
}), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
|
|
2756
3104
|
let r = Z(e.req.header(X), t);
|
|
2757
|
-
if (!r.ok) return
|
|
2758
|
-
let i =
|
|
3105
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3106
|
+
let i = f(e, "admin", !0);
|
|
2759
3107
|
if (i) return i;
|
|
2760
3108
|
let a = String(e.req.param("grantId") ?? "").trim();
|
|
2761
3109
|
if (!a) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -2773,7 +3121,7 @@ function mn(e) {
|
|
|
2773
3121
|
} finally {
|
|
2774
3122
|
await o.close();
|
|
2775
3123
|
}
|
|
2776
|
-
}),
|
|
3124
|
+
}), u.get("/v1/bootstrap-grants/:grantId", async (e) => {
|
|
2777
3125
|
let i = String(e.req.param("grantId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
|
|
2778
3126
|
if (!i || !a) return e.json({ error: "grant_id_and_group_id_required" }, 400);
|
|
2779
3127
|
let o = n();
|
|
@@ -2782,14 +3130,14 @@ function mn(e) {
|
|
|
2782
3130
|
method: e.req.method,
|
|
2783
3131
|
url: e.req.url,
|
|
2784
3132
|
groupId: a,
|
|
2785
|
-
body: new Uint8Array(),
|
|
3133
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
2786
3134
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
2787
3135
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
2788
3136
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
2789
3137
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
2790
3138
|
});
|
|
2791
|
-
if (!n.ok || !n.enrollment) return
|
|
2792
|
-
let s =
|
|
3139
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
3140
|
+
let s = f(e, String(n.enrollment.device_id), !0);
|
|
2793
3141
|
if (s) return s;
|
|
2794
3142
|
let c = await o.getBootstrapGrant(i);
|
|
2795
3143
|
if (!c || c.group_id !== a || c.seed_device_id !== String(n.enrollment.device_id)) return e.json({ error: "grant_not_found" }, 404);
|
|
@@ -2801,10 +3149,10 @@ function mn(e) {
|
|
|
2801
3149
|
} finally {
|
|
2802
3150
|
await o.close();
|
|
2803
3151
|
}
|
|
2804
|
-
}),
|
|
3152
|
+
}), u.get("/v1/admin/bootstrap-grants", async (e) => {
|
|
2805
3153
|
let r = Z(e.req.header(X), t);
|
|
2806
|
-
if (!r.ok) return
|
|
2807
|
-
let i =
|
|
3154
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3155
|
+
let i = f(e, "admin", !0);
|
|
2808
3156
|
if (i) return i;
|
|
2809
3157
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2810
3158
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2814,14 +3162,14 @@ function mn(e) {
|
|
|
2814
3162
|
} finally {
|
|
2815
3163
|
await o.close();
|
|
2816
3164
|
}
|
|
2817
|
-
}),
|
|
3165
|
+
}), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
|
|
2818
3166
|
let r = Z(e.req.header(X), t);
|
|
2819
|
-
if (!r.ok) return
|
|
2820
|
-
let i =
|
|
3167
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3168
|
+
let i = f(e, "admin", !0);
|
|
2821
3169
|
if (i) return i;
|
|
2822
|
-
let a = await
|
|
3170
|
+
let a = await p(e);
|
|
2823
3171
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2824
|
-
let o =
|
|
3172
|
+
let o = m(a);
|
|
2825
3173
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2826
3174
|
let s = String(o.grant_id ?? "").trim();
|
|
2827
3175
|
if (!s) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -2834,18 +3182,18 @@ function mn(e) {
|
|
|
2834
3182
|
} finally {
|
|
2835
3183
|
await c.close();
|
|
2836
3184
|
}
|
|
2837
|
-
}),
|
|
3185
|
+
}), u.post("/v1/admin/join-requests/approve", async (e) => _r(e, !0, {
|
|
2838
3186
|
createStore: n,
|
|
2839
3187
|
runtime: t,
|
|
2840
|
-
rateLimitedResponse:
|
|
2841
|
-
})),
|
|
3188
|
+
rateLimitedResponse: f
|
|
3189
|
+
})), u.post("/v1/admin/join-requests/deny", async (e) => _r(e, !1, {
|
|
2842
3190
|
createStore: n,
|
|
2843
3191
|
runtime: t,
|
|
2844
|
-
rateLimitedResponse:
|
|
2845
|
-
})),
|
|
3192
|
+
rateLimitedResponse: f
|
|
3193
|
+
})), u.get("/v1/admin/join-requests", async (e) => {
|
|
2846
3194
|
let r = Z(e.req.header(X), t);
|
|
2847
|
-
if (!r.ok) return
|
|
2848
|
-
let i =
|
|
3195
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3196
|
+
let i = f(e, "admin", !0);
|
|
2849
3197
|
if (i) return i;
|
|
2850
3198
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2851
3199
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2855,23 +3203,23 @@ function mn(e) {
|
|
|
2855
3203
|
} finally {
|
|
2856
3204
|
await o.close();
|
|
2857
3205
|
}
|
|
2858
|
-
}),
|
|
2859
|
-
let r = await
|
|
3206
|
+
}), u.post("/v1/join", async (e) => {
|
|
3207
|
+
let r = await p(e);
|
|
2860
3208
|
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
2861
|
-
let i =
|
|
3209
|
+
let i = m(r);
|
|
2862
3210
|
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
2863
|
-
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(),
|
|
3211
|
+
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(), h = String(i.device_display_name ?? "").trim();
|
|
2864
3212
|
if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
|
|
2865
|
-
if (
|
|
3213
|
+
if (ot(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
2866
3214
|
let g = n();
|
|
2867
3215
|
try {
|
|
2868
3216
|
let n = await g.getInviteByTokenForInspection(a);
|
|
2869
3217
|
if (!n) return e.json({ error: "invite_invalid" }, 404);
|
|
2870
|
-
let r = !!(n.operation_id || n.reviewed_project_set_digest),
|
|
2871
|
-
if (n.revoked_at) return e.json({ error: r ||
|
|
2872
|
-
if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r ||
|
|
2873
|
-
if (
|
|
2874
|
-
let r = new Set([
|
|
3218
|
+
let r = !!(n.operation_id || n.reviewed_project_set_digest), p = n.invite_kind === "team_member" || n.invite_kind === "add_device";
|
|
3219
|
+
if (n.revoked_at) return e.json({ error: r || p ? "invite_invalid" : "revoked_token" }, 400);
|
|
3220
|
+
if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || p ? "invite_expired" : "expired_token" }, 410);
|
|
3221
|
+
if (p) {
|
|
3222
|
+
let r = /* @__PURE__ */ new Set([
|
|
2875
3223
|
"token",
|
|
2876
3224
|
"invite_kind",
|
|
2877
3225
|
"kind",
|
|
@@ -2890,11 +3238,11 @@ function mn(e) {
|
|
|
2890
3238
|
try {
|
|
2891
3239
|
if (i.recipient_display_name != null) {
|
|
2892
3240
|
if (typeof i.recipient_display_name != "string") throw Error("recipient_display_name_invalid");
|
|
2893
|
-
d =
|
|
3241
|
+
d = I(i.recipient_display_name, "recipient_display_name");
|
|
2894
3242
|
}
|
|
2895
3243
|
if (i.device_display_name != null) {
|
|
2896
3244
|
if (typeof i.device_display_name != "string") throw Error("device_display_name_invalid");
|
|
2897
|
-
f =
|
|
3245
|
+
f = I(i.device_display_name, "device_display_name");
|
|
2898
3246
|
}
|
|
2899
3247
|
} catch (t) {
|
|
2900
3248
|
return e.json({ error: t instanceof Error ? t.message : "recipient_invite_identity_invalid" }, 400);
|
|
@@ -2932,7 +3280,7 @@ function mn(e) {
|
|
|
2932
3280
|
}
|
|
2933
3281
|
}
|
|
2934
3282
|
if (n.operation_id || n.reviewed_project_set_digest) {
|
|
2935
|
-
let r = new Set([
|
|
3283
|
+
let r = /* @__PURE__ */ new Set([
|
|
2936
3284
|
"token",
|
|
2937
3285
|
"operation_id",
|
|
2938
3286
|
"device_id",
|
|
@@ -2944,18 +3292,18 @@ function mn(e) {
|
|
|
2944
3292
|
"device_display_name"
|
|
2945
3293
|
]);
|
|
2946
3294
|
if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
2947
|
-
if (!u || !d || !f || !
|
|
3295
|
+
if (!u || !d || !f || !h) return e.json({ error: "project_invite_identity_required" }, 400);
|
|
2948
3296
|
if (String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "project_invite_self_acceptance_forbidden" }, 409);
|
|
2949
3297
|
if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
|
|
2950
|
-
let l,
|
|
3298
|
+
let l, p;
|
|
2951
3299
|
try {
|
|
2952
|
-
l =
|
|
3300
|
+
l = I(f, "recipient_display_name"), p = I(h, "device_display_name");
|
|
2953
3301
|
} catch (t) {
|
|
2954
3302
|
return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
|
|
2955
3303
|
}
|
|
2956
|
-
let
|
|
3304
|
+
let m;
|
|
2957
3305
|
try {
|
|
2958
|
-
|
|
3306
|
+
m = ee(n);
|
|
2959
3307
|
} catch {
|
|
2960
3308
|
return e.json({ error: "operation_intent_invalid" }, 409);
|
|
2961
3309
|
}
|
|
@@ -2968,12 +3316,12 @@ function mn(e) {
|
|
|
2968
3316
|
fingerprint: s,
|
|
2969
3317
|
recipientActorId: d,
|
|
2970
3318
|
recipientDisplayName: l,
|
|
2971
|
-
deviceDisplayName:
|
|
3319
|
+
deviceDisplayName: p,
|
|
2972
3320
|
now: t.now()
|
|
2973
3321
|
});
|
|
2974
3322
|
return e.json({
|
|
2975
3323
|
ok: !0,
|
|
2976
|
-
status:
|
|
3324
|
+
status: Cn,
|
|
2977
3325
|
group_id: n.invite.group_id,
|
|
2978
3326
|
operation_id: n.invite.operation_id,
|
|
2979
3327
|
trust_state: n.invite.trust_state,
|
|
@@ -2984,7 +3332,7 @@ function mn(e) {
|
|
|
2984
3332
|
fingerprint: n.seed_enrollment.fingerprint,
|
|
2985
3333
|
display_name: n.seed_enrollment.display_name
|
|
2986
3334
|
} : null,
|
|
2987
|
-
accepted_project_intent:
|
|
3335
|
+
accepted_project_intent: m
|
|
2988
3336
|
});
|
|
2989
3337
|
} catch (t) {
|
|
2990
3338
|
let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
|
|
@@ -2997,9 +3345,9 @@ function mn(e) {
|
|
|
2997
3345
|
"recipient_display_name",
|
|
2998
3346
|
"device_display_name"
|
|
2999
3347
|
].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
3000
|
-
let
|
|
3001
|
-
if (!
|
|
3002
|
-
if (
|
|
3348
|
+
let m = await g.getGroup(String(n.group_id));
|
|
3349
|
+
if (!m) return e.json({ error: "group_not_found" }, 404);
|
|
3350
|
+
if (m.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
3003
3351
|
let _ = String(n.group_id);
|
|
3004
3352
|
if (await g.getEnrollment(_, o)) return e.json({
|
|
3005
3353
|
ok: !0,
|
|
@@ -3040,25 +3388,25 @@ function mn(e) {
|
|
|
3040
3388
|
} finally {
|
|
3041
3389
|
await g.close();
|
|
3042
3390
|
}
|
|
3043
|
-
}),
|
|
3391
|
+
}), u;
|
|
3044
3392
|
}
|
|
3045
|
-
async function
|
|
3393
|
+
async function _r(e, t, n) {
|
|
3046
3394
|
let r = Z(e.req.header(X), n.runtime);
|
|
3047
3395
|
if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3048
3396
|
let i = n.rateLimitedResponse(e, "admin", !0);
|
|
3049
3397
|
if (i) return i;
|
|
3050
3398
|
let a = await (async () => {
|
|
3051
3399
|
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
3052
|
-
if (Number.isFinite(t) && t >
|
|
3400
|
+
if (Number.isFinite(t) && t > cr) return null;
|
|
3053
3401
|
let n = e.req.raw.body;
|
|
3054
|
-
if (!n) return new Uint8Array();
|
|
3402
|
+
if (!n) return /* @__PURE__ */ new Uint8Array();
|
|
3055
3403
|
let r = n.getReader(), i = [], a = 0;
|
|
3056
3404
|
try {
|
|
3057
3405
|
for (;;) {
|
|
3058
3406
|
let { done: e, value: t } = await r.read();
|
|
3059
3407
|
if (e) break;
|
|
3060
3408
|
if (t) {
|
|
3061
|
-
if (a += t.byteLength, a >
|
|
3409
|
+
if (a += t.byteLength, a > cr) return await r.cancel(), null;
|
|
3062
3410
|
i.push(t);
|
|
3063
3411
|
}
|
|
3064
3412
|
}
|
|
@@ -3106,6 +3454,6 @@ async function hn(e, t, n) {
|
|
|
3106
3454
|
}
|
|
3107
3455
|
}
|
|
3108
3456
|
//#endregion
|
|
3109
|
-
export {
|
|
3457
|
+
export { E as $, at as A, ke as B, Sn as C, g as Ct, L as D, n as Dt, Ve as E, i as Et, Re as F, Ce as G, Te as H, I, be as J, xe as K, F as L, it as M, ze as N, nt as O, Le as P, ie as Q, Be as R, yn as S, te as St, ot as T, a as Tt, Oe as U, De as V, N as W, ae as X, Se as Y, ne as Z, wn as _, _ as _t, ar as a, fe as at, Dn as b, x as bt, Zn as c, ge as ct, jn as d, v as dt, w as et, In as f, h as ft, Cn as g, u as gt, q as h, l as ht, or as i, me as it, rt as j, tt as k, Yn as l, _e as lt, Kn as m, S as mt, sr as n, C as nt, qn as o, de as ot, Gn as p, o as pt, we as q, ir as r, oe as rt, Xn as s, pe as st, gr as t, T as tt, Mn as u, he as ut, Tn as v, y as vt, xn as w, r as wt, bn as x, ee as xt, En as y, b as yt, Ae as z };
|
|
3110
3458
|
|
|
3111
|
-
//# sourceMappingURL=coordinator-api-
|
|
3459
|
+
//# sourceMappingURL=coordinator-api-BAufmPEa.js.map
|