@codemem/core 0.43.1 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +24 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-DGTIU3Ri.js → coordinator-api-Dlr65yhR.js} +1234 -904
- package/dist/coordinator-api-Dlr65yhR.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/filters.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 +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10598 -8850
- 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/ingest-xml-parser.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 +391 -305
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/legacy-recipient-policy-projection.d.ts +5 -0
- package/dist/legacy-recipient-policy-projection.d.ts.map +1 -1
- package/dist/legacy-team-attempt-lifecycle.d.ts +16 -0
- package/dist/legacy-team-attempt-lifecycle.d.ts.map +1 -0
- package/dist/legacy-team-candidate.d.ts +3 -13
- package/dist/legacy-team-candidate.d.ts.map +1 -1
- package/dist/legacy-team-project-canonical-preflight.d.ts +3 -1
- package/dist/legacy-team-project-canonical-preflight.d.ts.map +1 -1
- package/dist/legacy-team-project-policy.d.ts +4 -0
- package/dist/legacy-team-project-policy.d.ts.map +1 -0
- package/dist/legacy-team-setup-activation.d.ts +41 -1
- package/dist/legacy-team-setup-activation.d.ts.map +1 -1
- package/dist/legacy-team-setup-completion-manifest.d.ts +53 -0
- package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -0
- package/dist/legacy-team-setup-draft.d.ts +5 -2
- package/dist/legacy-team-setup-draft.d.ts.map +1 -1
- package/dist/legacy-team-setup-errors.d.ts +9 -2
- package/dist/legacy-team-setup-errors.d.ts.map +1 -1
- package/dist/legacy-team-setup-label-policy.d.ts +30 -0
- package/dist/legacy-team-setup-label-policy.d.ts.map +1 -0
- package/dist/legacy-team-setup-limits.d.ts +19 -1
- package/dist/legacy-team-setup-limits.d.ts.map +1 -1
- package/dist/local-project-inventory.d.ts +3 -0
- package/dist/local-project-inventory.d.ts.map +1 -0
- package/dist/memory-kinds.d.ts +24 -0
- package/dist/memory-kinds.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-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.map +1 -1
- package/dist/recipient-policy-contract.d.ts +5 -0
- package/dist/recipient-policy-contract.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-migration.d.ts.map +1 -1
- package/dist/recipient-policy-onboarding.d.ts.map +1 -1
- package/dist/recipient-policy-review.d.ts +1 -13
- package/dist/recipient-policy-review.d.ts.map +1 -1
- package/dist/recipient-policy-team-metadata.d.ts +38 -0
- package/dist/recipient-policy-team-metadata.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +147 -109
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-backfill.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 +3 -0
- 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 +36 -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 C(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 w = 1, T = 50, E = 500, D = 15e5, te = 25 * D, ne = 256, re = 37661024, ie = "completion_conflict", ae = class extends Error {
|
|
110
|
+
code = ie;
|
|
111
|
+
constructor() {
|
|
112
|
+
super(ie), this.name = "CoordinatorLegacyTeamCompletionConflictError";
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function O() {
|
|
116
|
+
throw Error("completion_manifest_invalid");
|
|
117
|
+
}
|
|
118
|
+
function k(e) {
|
|
119
|
+
return (!e || typeof e != "object" || Array.isArray(e)) && O(), e;
|
|
120
|
+
}
|
|
121
|
+
function A(e, t) {
|
|
122
|
+
let n = new Set(t);
|
|
123
|
+
Object.keys(e).some((e) => !n.has(e)) && O();
|
|
124
|
+
}
|
|
125
|
+
function oe(e) {
|
|
126
|
+
return /^(?:[\\/]{2}|\.{1,2}[\\/]|\/|~[\\/]|[a-z]:[\\/]|file:)/iu.test(e);
|
|
127
|
+
}
|
|
128
|
+
function j(e) {
|
|
129
|
+
return (typeof e != "string" || !e || e !== e.trim() || e.length > ne || /[\p{Cc}\p{Cf}]/u.test(e) || oe(e)) && O(), e;
|
|
130
|
+
}
|
|
131
|
+
function M(e) {
|
|
132
|
+
let t = j(e);
|
|
133
|
+
return /^[a-f0-9]{64}$/u.test(t) || O(), t;
|
|
134
|
+
}
|
|
135
|
+
function se(e) {
|
|
136
|
+
typeof e != "string" && O();
|
|
137
|
+
let t = e.normalize("NFC").trim();
|
|
138
|
+
return (!t || [...t].length > 120 || /[\p{Cc}\p{Cf}]/u.test(t) || oe(t)) && O(), t;
|
|
139
|
+
}
|
|
140
|
+
function ce(e) {
|
|
141
|
+
(typeof e != "string" || !e) && O();
|
|
142
|
+
let t = new Date(e);
|
|
143
|
+
return (Number.isNaN(t.getTime()) || t.toISOString() !== e) && O(), e;
|
|
144
|
+
}
|
|
145
|
+
function le(e, t) {
|
|
146
|
+
return (!Array.isArray(e) || e.length > t) && O(), e;
|
|
147
|
+
}
|
|
148
|
+
function ue(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)) && O(), n;
|
|
151
|
+
}
|
|
152
|
+
function de(e) {
|
|
153
|
+
return ue(le(e, 50).map(j), (e) => e);
|
|
154
|
+
}
|
|
155
|
+
function fe(e) {
|
|
156
|
+
let t = j(e);
|
|
157
|
+
return /^legacy-team-candidate:[a-f0-9]{32}$/u.test(t) || O(), t;
|
|
158
|
+
}
|
|
159
|
+
function pe(e) {
|
|
160
|
+
let t = k(e);
|
|
161
|
+
A(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 && O();
|
|
178
|
+
let n = k(t.team);
|
|
179
|
+
A(n, [
|
|
180
|
+
"display_name",
|
|
181
|
+
"policy_revision",
|
|
182
|
+
"device_eligibility_mode"
|
|
183
|
+
]), n.device_eligibility_mode !== "reviewed_allowlist" && O();
|
|
184
|
+
let r = j(t.team_id), i = ue(le(t.memberships, 500).map((e) => {
|
|
185
|
+
let t = k(e);
|
|
186
|
+
return A(t, ["identity_id", "role"]), t.role !== "member" && O(), {
|
|
187
|
+
identity_id: j(t.identity_id),
|
|
188
|
+
role: "member"
|
|
189
|
+
};
|
|
190
|
+
}), (e) => e.identity_id), a = ue(le(t.device_decisions, 500).map((e) => {
|
|
191
|
+
let t = k(e);
|
|
192
|
+
A(t, [
|
|
193
|
+
"device_id",
|
|
194
|
+
"key_fingerprint",
|
|
195
|
+
"enabled",
|
|
196
|
+
"identity_id",
|
|
197
|
+
"decision"
|
|
198
|
+
]), t.decision !== "included" && t.decision !== "excluded" && O(), typeof t.enabled != "boolean" && O();
|
|
199
|
+
let n = t.identity_id == null ? null : j(t.identity_id);
|
|
200
|
+
t.decision === "included" != !!n && O(), t.decision === "included" && !t.enabled && O();
|
|
201
|
+
let r = t.decision;
|
|
202
|
+
return {
|
|
203
|
+
device_id: j(t.device_id),
|
|
204
|
+
key_fingerprint: M(t.key_fingerprint),
|
|
205
|
+
enabled: t.enabled,
|
|
206
|
+
identity_id: n,
|
|
207
|
+
decision: r
|
|
208
|
+
};
|
|
209
|
+
}), (e) => e.device_id);
|
|
210
|
+
a.length === 0 && O();
|
|
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))) && O();
|
|
213
|
+
let l = ue(le(t.project_mappings, 500).map((e) => {
|
|
214
|
+
let t = k(e);
|
|
215
|
+
A(t, [
|
|
216
|
+
"project_ref",
|
|
217
|
+
"resolved_project_ref",
|
|
218
|
+
"scope_id"
|
|
219
|
+
]);
|
|
220
|
+
let n = j(t.project_ref), r = j(t.resolved_project_ref);
|
|
221
|
+
return /^legacy-team-project-ref-v1:[0-9a-f]{64}$/u.test(n) || O(), /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(r) || O(), {
|
|
222
|
+
project_ref: n,
|
|
223
|
+
resolved_project_ref: r,
|
|
224
|
+
scope_id: j(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 && O(), u.set(e.resolved_project_ref, e.scope_id);
|
|
230
|
+
}
|
|
231
|
+
let d = ue(le(t.project_recipients, 500).map((e) => {
|
|
232
|
+
let t = k(e);
|
|
233
|
+
A(t, ["resolved_project_ref", "team_id"]);
|
|
234
|
+
let n = j(t.team_id);
|
|
235
|
+
n !== r && O();
|
|
236
|
+
let i = j(t.resolved_project_ref);
|
|
237
|
+
return /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(i) || O(), {
|
|
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) && O();
|
|
243
|
+
let m = {
|
|
244
|
+
version: 1,
|
|
245
|
+
coordinator_id: j(t.coordinator_id),
|
|
246
|
+
candidate_ref: fe(t.candidate_ref),
|
|
247
|
+
candidate_digest: M(t.candidate_digest),
|
|
248
|
+
team_id: r,
|
|
249
|
+
team_digest: M(t.team_digest),
|
|
250
|
+
source_digest: M(t.source_digest),
|
|
251
|
+
finish_digest: M(t.finish_digest),
|
|
252
|
+
access_delta_digest: M(t.access_delta_digest),
|
|
253
|
+
team: {
|
|
254
|
+
display_name: se(n.display_name),
|
|
255
|
+
policy_revision: M(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: ce(t.completed_at)
|
|
263
|
+
};
|
|
264
|
+
return new TextEncoder().encode(JSON.stringify(m)).byteLength > 15e5 && O(), 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) && O();
|
|
271
|
+
}
|
|
272
|
+
function ge(e, t) {
|
|
273
|
+
y(e.coordinator_id, t) !== e.candidate_ref && O();
|
|
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 && O();
|
|
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) && O();
|
|
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,33 +1473,33 @@ 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
1487
|
//#region src/scope-resolution.ts
|
|
1237
|
-
var
|
|
1488
|
+
var On = "local-default", kn = "legacy-shared-review";
|
|
1238
1489
|
function q(e) {
|
|
1239
1490
|
return e?.trim() || null;
|
|
1240
1491
|
}
|
|
1241
1492
|
function J(e) {
|
|
1242
1493
|
return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
|
|
1243
1494
|
}
|
|
1244
|
-
function
|
|
1495
|
+
function An(t) {
|
|
1245
1496
|
return J(e(t));
|
|
1246
1497
|
}
|
|
1247
|
-
function
|
|
1498
|
+
function jn(e) {
|
|
1248
1499
|
let t = q(e);
|
|
1249
1500
|
return t ? J(t) : null;
|
|
1250
1501
|
}
|
|
1251
|
-
function
|
|
1502
|
+
function Mn(e) {
|
|
1252
1503
|
let n = [
|
|
1253
1504
|
e.cwd,
|
|
1254
1505
|
e.project,
|
|
@@ -1256,7 +1507,7 @@ function Pt(e) {
|
|
|
1256
1507
|
].map((e) => q(e)).find((e) => e != null);
|
|
1257
1508
|
return `unmapped:${t("sha256").update(n ?? "unknown", "utf8").digest("hex")}`;
|
|
1258
1509
|
}
|
|
1259
|
-
function
|
|
1510
|
+
function Nn(e) {
|
|
1260
1511
|
let t = q(e.gitRemote), n = q(e.gitBranch), r = q(e.cwd), i = q(e.workspaceId), a = q(e.project);
|
|
1261
1512
|
if (t) {
|
|
1262
1513
|
let r = J(t);
|
|
@@ -1271,7 +1522,7 @@ function Ft(e) {
|
|
|
1271
1522
|
};
|
|
1272
1523
|
}
|
|
1273
1524
|
return r ? {
|
|
1274
|
-
value:
|
|
1525
|
+
value: An(r),
|
|
1275
1526
|
source: "cwd",
|
|
1276
1527
|
displayProject: a
|
|
1277
1528
|
} : i ? {
|
|
@@ -1279,41 +1530,41 @@ function Ft(e) {
|
|
|
1279
1530
|
source: "workspace_id",
|
|
1280
1531
|
displayProject: a
|
|
1281
1532
|
} : {
|
|
1282
|
-
value:
|
|
1533
|
+
value: Mn(e),
|
|
1283
1534
|
source: "unmapped",
|
|
1284
1535
|
displayProject: a
|
|
1285
1536
|
};
|
|
1286
1537
|
}
|
|
1287
|
-
function
|
|
1538
|
+
function Pn(e) {
|
|
1288
1539
|
return !/[\\/:]/.test(e);
|
|
1289
1540
|
}
|
|
1290
|
-
function
|
|
1541
|
+
function Fn(e) {
|
|
1291
1542
|
return e.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
|
|
1292
1543
|
}
|
|
1293
|
-
function
|
|
1544
|
+
function In(e) {
|
|
1294
1545
|
return e.replace(/[*?]/g, "").length;
|
|
1295
1546
|
}
|
|
1296
|
-
function
|
|
1547
|
+
function Ln(e, t) {
|
|
1297
1548
|
let n = J(t);
|
|
1298
|
-
return !n ||
|
|
1549
|
+
return !n || Pn(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${Fn(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
|
|
1299
1550
|
}
|
|
1300
|
-
function
|
|
1551
|
+
function Rn(e) {
|
|
1301
1552
|
return e.mapping.priority ?? 0;
|
|
1302
1553
|
}
|
|
1303
|
-
function
|
|
1554
|
+
function zn(e) {
|
|
1304
1555
|
let t = q(e.mapping.updated_at);
|
|
1305
1556
|
if (!t) return 0;
|
|
1306
1557
|
let n = Date.parse(t);
|
|
1307
1558
|
return Number.isFinite(n) ? n : 0;
|
|
1308
1559
|
}
|
|
1309
|
-
function
|
|
1310
|
-
return
|
|
1560
|
+
function Bn(e, t) {
|
|
1561
|
+
return Rn(t) - Rn(e) || t.specificity - e.specificity || zn(t) - zn(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
|
|
1311
1562
|
}
|
|
1312
|
-
function
|
|
1313
|
-
return e.toSorted(
|
|
1563
|
+
function Vn(e) {
|
|
1564
|
+
return e.toSorted(Bn)[0] ?? null;
|
|
1314
1565
|
}
|
|
1315
|
-
function
|
|
1316
|
-
let t =
|
|
1566
|
+
function Hn(e) {
|
|
1567
|
+
let t = Nn(e), n = q(e.explicitScopeId);
|
|
1317
1568
|
if (n) return {
|
|
1318
1569
|
scopeId: n,
|
|
1319
1570
|
reason: "explicit_override",
|
|
@@ -1328,7 +1579,7 @@ function Wt(e) {
|
|
|
1328
1579
|
mapping: null,
|
|
1329
1580
|
matchedPattern: null
|
|
1330
1581
|
};
|
|
1331
|
-
let r = e.mappings ?? [], i =
|
|
1582
|
+
let r = e.mappings ?? [], i = Vn(r.filter((e) => jn(e.workspace_identity) === t.value).map((e) => ({
|
|
1332
1583
|
mapping: e,
|
|
1333
1584
|
matchedPattern: null,
|
|
1334
1585
|
specificity: t.value.length
|
|
@@ -1340,13 +1591,13 @@ function Wt(e) {
|
|
|
1340
1591
|
mapping: i.mapping,
|
|
1341
1592
|
matchedPattern: null
|
|
1342
1593
|
};
|
|
1343
|
-
let a =
|
|
1594
|
+
let a = Vn(r.flatMap((e) => {
|
|
1344
1595
|
if (q(e.workspace_identity)) return [];
|
|
1345
1596
|
let n = q(e.project_pattern);
|
|
1346
|
-
return !n || !
|
|
1597
|
+
return !n || !Ln(t.value, n) ? [] : [{
|
|
1347
1598
|
mapping: e,
|
|
1348
1599
|
matchedPattern: J(n),
|
|
1349
|
-
specificity:
|
|
1600
|
+
specificity: In(n)
|
|
1350
1601
|
}];
|
|
1351
1602
|
}));
|
|
1352
1603
|
return a ? {
|
|
@@ -1363,11 +1614,11 @@ function Wt(e) {
|
|
|
1363
1614
|
matchedPattern: null
|
|
1364
1615
|
};
|
|
1365
1616
|
}
|
|
1366
|
-
function
|
|
1367
|
-
let n = new Set([
|
|
1617
|
+
function Un(e, t) {
|
|
1618
|
+
let n = /* @__PURE__ */ new Set([
|
|
1368
1619
|
"",
|
|
1369
|
-
|
|
1370
|
-
|
|
1620
|
+
On,
|
|
1621
|
+
kn
|
|
1371
1622
|
]), r = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
|
|
1372
1623
|
for (let e of r) e.scope_id != null && n.add(e.scope_id);
|
|
1373
1624
|
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 +1627,29 @@ function Gt(e, t) {
|
|
|
1376
1627
|
}
|
|
1377
1628
|
//#endregion
|
|
1378
1629
|
//#region src/project-share-intent.ts
|
|
1379
|
-
var
|
|
1380
|
-
function
|
|
1630
|
+
var Wn = "existing_and_future";
|
|
1631
|
+
function Gn(e) {
|
|
1381
1632
|
return t("sha256").update(JSON.stringify(e)).digest("hex");
|
|
1382
1633
|
}
|
|
1383
|
-
function
|
|
1384
|
-
return
|
|
1634
|
+
function Kn(e) {
|
|
1635
|
+
return Gn({
|
|
1385
1636
|
v: 1,
|
|
1386
|
-
historyPolicy:
|
|
1637
|
+
historyPolicy: Wn,
|
|
1387
1638
|
projects: e.map((e) => ({
|
|
1388
1639
|
canonicalIdentity: e.canonicalIdentity,
|
|
1389
1640
|
existingMemoryCount: e.existingMemoryCount
|
|
1390
1641
|
})).toSorted((e, t) => e.canonicalIdentity.localeCompare(t.canonicalIdentity))
|
|
1391
1642
|
});
|
|
1392
1643
|
}
|
|
1393
|
-
function
|
|
1394
|
-
return
|
|
1644
|
+
function qn(e) {
|
|
1645
|
+
return Kn(e.map((e) => ({
|
|
1395
1646
|
canonicalIdentity: e.canonical_identity,
|
|
1396
1647
|
displayName: e.display_name,
|
|
1397
1648
|
identitySource: "coordinator_acceptance",
|
|
1398
1649
|
existingMemoryCount: e.existing_memory_count
|
|
1399
1650
|
})));
|
|
1400
1651
|
}
|
|
1401
|
-
function
|
|
1652
|
+
function Jn(e) {
|
|
1402
1653
|
if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("operation_intent_invalid");
|
|
1403
1654
|
let t = e.map((e) => {
|
|
1404
1655
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
|
|
@@ -1406,11 +1657,11 @@ function Xt(e) {
|
|
|
1406
1657
|
if (typeof t.canonical_identity != "string" || typeof t.display_name != "string") throw Error("operation_intent_invalid");
|
|
1407
1658
|
let n = t.canonical_identity, r = n.trim(), i = t.display_name, a;
|
|
1408
1659
|
try {
|
|
1409
|
-
a =
|
|
1660
|
+
a = F(i, "project_name");
|
|
1410
1661
|
} catch {
|
|
1411
1662
|
throw Error("operation_intent_invalid");
|
|
1412
1663
|
}
|
|
1413
|
-
let o = t.existing_memory_count, s =
|
|
1664
|
+
let o = t.existing_memory_count, s = Nn({ gitRemote: r }).value;
|
|
1414
1665
|
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
1666
|
return {
|
|
1416
1667
|
canonical_identity: r,
|
|
@@ -1423,20 +1674,20 @@ function Xt(e) {
|
|
|
1423
1674
|
}
|
|
1424
1675
|
//#endregion
|
|
1425
1676
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
|
|
1426
|
-
function
|
|
1677
|
+
function Yn(e) {
|
|
1427
1678
|
let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
|
|
1428
1679
|
return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
|
|
1429
1680
|
}
|
|
1430
1681
|
function Y() {
|
|
1431
|
-
let [e, t] =
|
|
1682
|
+
let [e, t] = Yn();
|
|
1432
1683
|
return e * 1e3 + Math.floor(t / 1e6);
|
|
1433
1684
|
}
|
|
1434
|
-
function
|
|
1685
|
+
function Xn(e) {
|
|
1435
1686
|
return new Promise((t) => setTimeout(t, e));
|
|
1436
1687
|
}
|
|
1437
1688
|
//#endregion
|
|
1438
1689
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
|
|
1439
|
-
var
|
|
1690
|
+
var Zn = class {
|
|
1440
1691
|
bucketSize;
|
|
1441
1692
|
tokensPerInterval;
|
|
1442
1693
|
interval;
|
|
@@ -1451,14 +1702,14 @@ var $t = class {
|
|
|
1451
1702
|
break;
|
|
1452
1703
|
case "min":
|
|
1453
1704
|
case "minute":
|
|
1454
|
-
this.interval =
|
|
1705
|
+
this.interval = 6e4;
|
|
1455
1706
|
break;
|
|
1456
1707
|
case "hr":
|
|
1457
1708
|
case "hour":
|
|
1458
|
-
this.interval =
|
|
1709
|
+
this.interval = 36e5;
|
|
1459
1710
|
break;
|
|
1460
1711
|
case "day":
|
|
1461
|
-
this.interval =
|
|
1712
|
+
this.interval = 864e5;
|
|
1462
1713
|
break;
|
|
1463
1714
|
default: throw Error("Invalid interval " + n);
|
|
1464
1715
|
}
|
|
@@ -1469,12 +1720,13 @@ var $t = class {
|
|
|
1469
1720
|
if (this.bucketSize === 0) return Infinity;
|
|
1470
1721
|
if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
|
|
1471
1722
|
this.drip();
|
|
1472
|
-
let t = async () => (await
|
|
1723
|
+
let t = async () => (await Xn(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
|
|
1473
1724
|
if (e > this.content) return t();
|
|
1474
1725
|
if (this.parentBucket != null) {
|
|
1475
1726
|
let n = await this.parentBucket.removeTokens(e);
|
|
1476
1727
|
return e > this.content ? t() : (this.content -= e, Math.min(n, this.content));
|
|
1477
|
-
}
|
|
1728
|
+
}
|
|
1729
|
+
return this.content -= e, this.content;
|
|
1478
1730
|
}
|
|
1479
1731
|
tryRemoveTokens(e) {
|
|
1480
1732
|
return this.bucketSize ? e > this.bucketSize || (this.drip(), e > this.content) || this.parentBucket && !this.parentBucket.tryRemoveTokens(e) ? !1 : (this.content -= e, !0) : !0;
|
|
@@ -1489,13 +1741,13 @@ var $t = class {
|
|
|
1489
1741
|
let n = t * (this.tokensPerInterval / this.interval), r = this.content;
|
|
1490
1742
|
return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
|
|
1491
1743
|
}
|
|
1492
|
-
},
|
|
1744
|
+
}, Qn = class {
|
|
1493
1745
|
tokenBucket;
|
|
1494
1746
|
curIntervalStart;
|
|
1495
1747
|
tokensThisInterval;
|
|
1496
1748
|
fireImmediately;
|
|
1497
1749
|
constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
|
|
1498
|
-
this.tokenBucket = new
|
|
1750
|
+
this.tokenBucket = new Zn({
|
|
1499
1751
|
bucketSize: e,
|
|
1500
1752
|
tokensPerInterval: e,
|
|
1501
1753
|
interval: t
|
|
@@ -1507,7 +1759,7 @@ var $t = class {
|
|
|
1507
1759
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
|
|
1508
1760
|
if (this.fireImmediately) return -1;
|
|
1509
1761
|
{
|
|
1510
|
-
await
|
|
1762
|
+
await Xn(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
|
|
1511
1763
|
let n = await this.tokenBucket.removeTokens(e);
|
|
1512
1764
|
return this.tokensThisInterval += e, n;
|
|
1513
1765
|
}
|
|
@@ -1528,7 +1780,7 @@ var $t = class {
|
|
|
1528
1780
|
};
|
|
1529
1781
|
//#endregion
|
|
1530
1782
|
//#region src/request-rate-limit.ts
|
|
1531
|
-
function
|
|
1783
|
+
function $n(e = {}) {
|
|
1532
1784
|
let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
|
|
1533
1785
|
function a(e) {
|
|
1534
1786
|
return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
|
|
@@ -1545,7 +1797,7 @@ function tn(e = {}) {
|
|
|
1545
1797
|
o(l);
|
|
1546
1798
|
let u = `${c}:${e}`, d = r.get(u);
|
|
1547
1799
|
return d || (d = {
|
|
1548
|
-
limiter: new
|
|
1800
|
+
limiter: new Qn({
|
|
1549
1801
|
tokensPerInterval: c,
|
|
1550
1802
|
interval: t,
|
|
1551
1803
|
fireImmediately: !0
|
|
@@ -1562,8 +1814,8 @@ function tn(e = {}) {
|
|
|
1562
1814
|
}
|
|
1563
1815
|
//#endregion
|
|
1564
1816
|
//#region src/scope-membership-semantics.ts
|
|
1565
|
-
var
|
|
1566
|
-
function
|
|
1817
|
+
var er = "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.";
|
|
1818
|
+
function tr(e) {
|
|
1567
1819
|
let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
|
|
1568
1820
|
return t == null || n == null ? {
|
|
1569
1821
|
membership_epoch: t,
|
|
@@ -1577,19 +1829,19 @@ function rn(e) {
|
|
|
1577
1829
|
reason: t < n ? "stale_epoch" : "current"
|
|
1578
1830
|
};
|
|
1579
1831
|
}
|
|
1580
|
-
function
|
|
1832
|
+
function nr(e) {
|
|
1581
1833
|
return {
|
|
1582
1834
|
scope_id: e.scopeId,
|
|
1583
1835
|
device_id: e.deviceId,
|
|
1584
1836
|
membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
|
|
1585
1837
|
prevents_future_sync: !0,
|
|
1586
1838
|
deletes_already_copied_data: !1,
|
|
1587
|
-
message:
|
|
1839
|
+
message: er
|
|
1588
1840
|
};
|
|
1589
1841
|
}
|
|
1590
1842
|
//#endregion
|
|
1591
1843
|
//#region src/sync-auth-constants.ts
|
|
1592
|
-
var
|
|
1844
|
+
var rr = 300, ir = 65536, ar = D + 1024, X = "X-Codemem-Coordinator-Admin", or = "X-Codemem-Coordinator-Admin-Actor", sr = 120, cr = 30;
|
|
1593
1845
|
function Z(e, t) {
|
|
1594
1846
|
let n = t.adminSecret();
|
|
1595
1847
|
if (!n) return {
|
|
@@ -1608,14 +1860,14 @@ function Z(e, t) {
|
|
|
1608
1860
|
error: "missing_admin_header"
|
|
1609
1861
|
};
|
|
1610
1862
|
}
|
|
1611
|
-
function
|
|
1863
|
+
function lr(e) {
|
|
1612
1864
|
let t = new URL(e);
|
|
1613
1865
|
return t.search ? `${t.pathname}${t.search}` : t.pathname;
|
|
1614
1866
|
}
|
|
1615
|
-
async function
|
|
1867
|
+
async function ur(e, t, n, r) {
|
|
1616
1868
|
return await e.recordNonce(t, n, r);
|
|
1617
1869
|
}
|
|
1618
|
-
async function
|
|
1870
|
+
async function dr(e, t) {
|
|
1619
1871
|
await e.cleanupNonces(t);
|
|
1620
1872
|
}
|
|
1621
1873
|
async function Q(e, t, n, r) {
|
|
@@ -1651,7 +1903,7 @@ async function Q(e, t, n, r) {
|
|
|
1651
1903
|
try {
|
|
1652
1904
|
u = await n({
|
|
1653
1905
|
method: r.method,
|
|
1654
|
-
pathWithQuery:
|
|
1906
|
+
pathWithQuery: lr(r.url),
|
|
1655
1907
|
bodyBytes: r.body,
|
|
1656
1908
|
timestamp: o,
|
|
1657
1909
|
nonce: s,
|
|
@@ -1672,7 +1924,7 @@ async function Q(e, t, n, r) {
|
|
|
1672
1924
|
enrollment: null
|
|
1673
1925
|
};
|
|
1674
1926
|
let d = t.now();
|
|
1675
|
-
return await
|
|
1927
|
+
return await ur(e, i, s, d) ? (await dr(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 6e5)).toISOString()), {
|
|
1676
1928
|
ok: !0,
|
|
1677
1929
|
error: "ok",
|
|
1678
1930
|
enrollment: c
|
|
@@ -1685,54 +1937,54 @@ async function Q(e, t, n, r) {
|
|
|
1685
1937
|
function $(e) {
|
|
1686
1938
|
return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
|
|
1687
1939
|
}
|
|
1688
|
-
function
|
|
1940
|
+
function fr(e) {
|
|
1689
1941
|
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 =
|
|
1942
|
+
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? $n(), o = Math.max(1, Math.trunc(i.readLimit ?? sr)), s = Math.max(1, Math.trunc(i.mutationLimit ?? cr)), 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();
|
|
1943
|
+
function f(e, t, n) {
|
|
1944
|
+
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
1945
|
return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
|
|
1694
1946
|
error: "rate_limited",
|
|
1695
1947
|
retry_after_s: i.retryAfterS
|
|
1696
1948
|
}, 429));
|
|
1697
1949
|
}
|
|
1698
|
-
async function
|
|
1699
|
-
let
|
|
1700
|
-
if (Number.isFinite(
|
|
1701
|
-
let
|
|
1702
|
-
if (!
|
|
1703
|
-
let
|
|
1950
|
+
async function p(e, t = ir) {
|
|
1951
|
+
let n = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1952
|
+
if (Number.isFinite(n) && n > t) return null;
|
|
1953
|
+
let r = e.req.raw.body;
|
|
1954
|
+
if (!r) return /* @__PURE__ */ new Uint8Array();
|
|
1955
|
+
let i = r.getReader(), a = [], o = 0;
|
|
1704
1956
|
try {
|
|
1705
1957
|
for (;;) {
|
|
1706
|
-
let { done: e, value:
|
|
1958
|
+
let { done: e, value: n } = await i.read();
|
|
1707
1959
|
if (e) break;
|
|
1708
|
-
if (
|
|
1709
|
-
if (
|
|
1710
|
-
|
|
1960
|
+
if (n) {
|
|
1961
|
+
if (o += n.byteLength, o > t) return await i.cancel(), null;
|
|
1962
|
+
a.push(n);
|
|
1711
1963
|
}
|
|
1712
1964
|
}
|
|
1713
1965
|
} finally {
|
|
1714
|
-
|
|
1966
|
+
i.releaseLock();
|
|
1715
1967
|
}
|
|
1716
|
-
let
|
|
1717
|
-
for (let e of
|
|
1718
|
-
return
|
|
1968
|
+
let s = new Uint8Array(o), c = 0;
|
|
1969
|
+
for (let e of a) s.set(e, c), c += e.byteLength;
|
|
1970
|
+
return s;
|
|
1719
1971
|
}
|
|
1720
|
-
function
|
|
1972
|
+
function m(e) {
|
|
1721
1973
|
try {
|
|
1722
|
-
let t = JSON.parse(
|
|
1974
|
+
let t = JSON.parse(d.decode(e));
|
|
1723
1975
|
return typeof t != "object" || !t || Array.isArray(t) ? null : t;
|
|
1724
1976
|
} catch {
|
|
1725
1977
|
return null;
|
|
1726
1978
|
}
|
|
1727
1979
|
}
|
|
1728
|
-
function
|
|
1980
|
+
function h(e, t) {
|
|
1729
1981
|
let n = e[t];
|
|
1730
1982
|
return n == null ? null : String(n).trim() || null;
|
|
1731
1983
|
}
|
|
1732
|
-
function
|
|
1984
|
+
function g(e) {
|
|
1733
1985
|
return e?.trim() || null;
|
|
1734
1986
|
}
|
|
1735
|
-
function
|
|
1987
|
+
function _(e, t) {
|
|
1736
1988
|
let n = e[t];
|
|
1737
1989
|
if (n == null || n === "") return null;
|
|
1738
1990
|
if (typeof n != "number" && typeof n != "string") return NaN;
|
|
@@ -1745,45 +1997,45 @@ function mn(e) {
|
|
|
1745
1997
|
let r = n;
|
|
1746
1998
|
return Number.isFinite(r) ? Math.trunc(r) : NaN;
|
|
1747
1999
|
}
|
|
1748
|
-
function
|
|
2000
|
+
function v(e) {
|
|
1749
2001
|
return [
|
|
1750
2002
|
"1",
|
|
1751
2003
|
"true",
|
|
1752
2004
|
"yes"
|
|
1753
2005
|
].includes(String(e ?? "").trim().toLowerCase());
|
|
1754
2006
|
}
|
|
1755
|
-
function
|
|
2007
|
+
function y(e) {
|
|
1756
2008
|
try {
|
|
1757
|
-
return
|
|
2009
|
+
return Jn(JSON.parse(e ?? ""));
|
|
1758
2010
|
} catch {
|
|
1759
2011
|
throw Error("operation_intent_invalid");
|
|
1760
2012
|
}
|
|
1761
2013
|
}
|
|
1762
|
-
function
|
|
2014
|
+
function ee(e) {
|
|
1763
2015
|
let t = String(e.operation_id ?? "").trim(), n = String(e.reviewed_project_set_digest ?? "").trim();
|
|
1764
2016
|
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 (
|
|
2017
|
+
let r = y(e.project_intent_json);
|
|
2018
|
+
if (qn(r) !== n) throw Error("operation_intent_invalid");
|
|
1767
2019
|
return {
|
|
1768
2020
|
operation_id: t,
|
|
1769
2021
|
reviewed_project_set_digest: n,
|
|
1770
2022
|
projects: r
|
|
1771
2023
|
};
|
|
1772
2024
|
}
|
|
1773
|
-
function
|
|
2025
|
+
function b(e) {
|
|
1774
2026
|
try {
|
|
1775
|
-
return
|
|
2027
|
+
return Be(JSON.parse(e ?? ""));
|
|
1776
2028
|
} catch {
|
|
1777
2029
|
throw Error("operation_intent_invalid");
|
|
1778
2030
|
}
|
|
1779
2031
|
}
|
|
1780
|
-
async function
|
|
2032
|
+
async function x(e, t, n) {
|
|
1781
2033
|
if (!t) return n.json({ error: "group_id_required" }, 400);
|
|
1782
2034
|
let r = await e.getGroup(t);
|
|
1783
2035
|
return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
|
|
1784
2036
|
}
|
|
1785
|
-
async function
|
|
1786
|
-
let i = await
|
|
2037
|
+
async function S(e, t, n, r) {
|
|
2038
|
+
let i = await x(e, t, r);
|
|
1787
2039
|
if (i) return {
|
|
1788
2040
|
scope: null,
|
|
1789
2041
|
response: i
|
|
@@ -1804,12 +2056,12 @@ function mn(e) {
|
|
|
1804
2056
|
response: r.json({ error: "scope_not_found" }, 404)
|
|
1805
2057
|
};
|
|
1806
2058
|
}
|
|
1807
|
-
async function
|
|
2059
|
+
async function C(e, n, i) {
|
|
1808
2060
|
let a = await Q(e, t, r, {
|
|
1809
2061
|
method: i.req.method,
|
|
1810
2062
|
url: i.req.url,
|
|
1811
2063
|
groupId: n,
|
|
1812
|
-
body: new Uint8Array(),
|
|
2064
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1813
2065
|
deviceId: i.req.header("X-Opencode-Device") ?? null,
|
|
1814
2066
|
signature: i.req.header("X-Opencode-Signature") ?? null,
|
|
1815
2067
|
timestamp: i.req.header("X-Opencode-Timestamp") ?? null,
|
|
@@ -1817,22 +2069,19 @@ function mn(e) {
|
|
|
1817
2069
|
});
|
|
1818
2070
|
return !a.ok || !a.enrollment ? {
|
|
1819
2071
|
auth: a,
|
|
1820
|
-
response:
|
|
2072
|
+
response: f(i, i.req.path, !1) ?? i.json({ error: a.error }, $(a.error))
|
|
1821
2073
|
} : {
|
|
1822
2074
|
auth: a,
|
|
1823
|
-
response:
|
|
2075
|
+
response: f(i, String(a.enrollment.device_id), !0)
|
|
1824
2076
|
};
|
|
1825
2077
|
}
|
|
1826
|
-
function
|
|
2078
|
+
function w(e, t) {
|
|
1827
2079
|
return e.status === "active" && e.membership_epoch >= t.membership_epoch;
|
|
1828
2080
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
}
|
|
1832
|
-
return d.post("/v1/presence", async (e) => {
|
|
1833
|
-
let i = await m(e);
|
|
2081
|
+
return u.post("/v1/presence", async (e) => {
|
|
2082
|
+
let i = await p(e);
|
|
1834
2083
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1835
|
-
let a =
|
|
2084
|
+
let a = m(i);
|
|
1836
2085
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1837
2086
|
let o = String(a.group_id ?? "").trim();
|
|
1838
2087
|
if (!o) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -1848,8 +2097,8 @@ function mn(e) {
|
|
|
1848
2097
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1849
2098
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1850
2099
|
});
|
|
1851
|
-
if (!n.ok || !n.enrollment) return
|
|
1852
|
-
let c =
|
|
2100
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
2101
|
+
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1853
2102
|
if (c) return c;
|
|
1854
2103
|
if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
|
|
1855
2104
|
let l = a.addresses ?? [];
|
|
@@ -1874,7 +2123,7 @@ function mn(e) {
|
|
|
1874
2123
|
} finally {
|
|
1875
2124
|
await s.close();
|
|
1876
2125
|
}
|
|
1877
|
-
}),
|
|
2126
|
+
}), u.get("/v1/peers", async (e) => {
|
|
1878
2127
|
let i = (e.req.query("group_id") ?? "").trim();
|
|
1879
2128
|
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1880
2129
|
let a = n();
|
|
@@ -1883,44 +2132,47 @@ function mn(e) {
|
|
|
1883
2132
|
method: e.req.method,
|
|
1884
2133
|
url: e.req.url,
|
|
1885
2134
|
groupId: i,
|
|
1886
|
-
body: new Uint8Array(),
|
|
2135
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1887
2136
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1888
2137
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1889
2138
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1890
2139
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1891
2140
|
});
|
|
1892
|
-
if (!n.ok || !n.enrollment) return
|
|
1893
|
-
let o =
|
|
2141
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
|
|
2142
|
+
let o = f(e, String(n.enrollment.device_id), !0);
|
|
1894
2143
|
if (o) return o;
|
|
1895
2144
|
let s = await a.listGroupPeers(i, String(n.enrollment.device_id));
|
|
1896
2145
|
return e.json({ items: s });
|
|
1897
2146
|
} finally {
|
|
1898
2147
|
await a.close();
|
|
1899
2148
|
}
|
|
1900
|
-
}),
|
|
2149
|
+
}), u.get("/v1/scopes", async (e) => {
|
|
1901
2150
|
let t = (e.req.query("group_id") ?? "").trim();
|
|
1902
2151
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1903
2152
|
let r = n();
|
|
1904
2153
|
try {
|
|
1905
|
-
let { auth: n, response: i } = await
|
|
2154
|
+
let { auth: n, response: i } = await C(r, t, e);
|
|
1906
2155
|
if (i) return i;
|
|
1907
2156
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1908
2157
|
let a = await r.listScopes({
|
|
1909
2158
|
groupId: t,
|
|
1910
2159
|
includeInactive: !1
|
|
1911
|
-
}), o = []
|
|
1912
|
-
|
|
1913
|
-
|
|
2160
|
+
}), o = await r.listDeviceScopeMemberships(String(n.enrollment.device_id), !1), s = new Map(o.map((e) => [e.scope_id, e])), c = a.filter((e) => {
|
|
2161
|
+
if (e.status !== "active") return !1;
|
|
2162
|
+
let t = s.get(e.scope_id);
|
|
2163
|
+
return !!(t && w(t, e));
|
|
2164
|
+
});
|
|
2165
|
+
return e.json({ items: c });
|
|
1914
2166
|
} finally {
|
|
1915
2167
|
await r.close();
|
|
1916
2168
|
}
|
|
1917
|
-
}),
|
|
2169
|
+
}), u.get("/v1/scopes/:scope_id/members", async (e) => {
|
|
1918
2170
|
let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
|
|
1919
2171
|
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1920
2172
|
if (!r) return e.json({ error: "scope_id_required" }, 400);
|
|
1921
2173
|
let i = n();
|
|
1922
2174
|
try {
|
|
1923
|
-
let { auth: n, response: a } = await
|
|
2175
|
+
let { auth: n, response: a } = await C(i, t, e);
|
|
1924
2176
|
if (a) return a;
|
|
1925
2177
|
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1926
2178
|
let o = (await i.listScopes({
|
|
@@ -1929,11 +2181,11 @@ function mn(e) {
|
|
|
1929
2181
|
})).find((e) => e.scope_id === r) ?? null;
|
|
1930
2182
|
if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
|
|
1931
2183
|
let s = await i.listScopeMemberships(r, !1);
|
|
1932
|
-
return s.some((e) => e.device_id === String(n.enrollment?.device_id) &&
|
|
2184
|
+
return s.some((e) => e.device_id === String(n.enrollment?.device_id) && w(e, o)) ? e.json({ items: s.filter((e) => w(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
|
|
1933
2185
|
} finally {
|
|
1934
2186
|
await i.close();
|
|
1935
2187
|
}
|
|
1936
|
-
}),
|
|
2188
|
+
}), u.get("/v1/reciprocal-approvals", async (e) => {
|
|
1937
2189
|
let i = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
|
|
1938
2190
|
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1939
2191
|
if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
|
|
@@ -1943,14 +2195,14 @@ function mn(e) {
|
|
|
1943
2195
|
method: e.req.method,
|
|
1944
2196
|
url: e.req.url,
|
|
1945
2197
|
groupId: i,
|
|
1946
|
-
body: new Uint8Array(),
|
|
2198
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
1947
2199
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1948
2200
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1949
2201
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1950
2202
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1951
2203
|
});
|
|
1952
|
-
if (!n.ok || !n.enrollment) return
|
|
1953
|
-
let c =
|
|
2204
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2205
|
+
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1954
2206
|
if (c) return c;
|
|
1955
2207
|
let l = await s.listReciprocalApprovals({
|
|
1956
2208
|
groupId: i,
|
|
@@ -1962,10 +2214,10 @@ function mn(e) {
|
|
|
1962
2214
|
} finally {
|
|
1963
2215
|
await s.close();
|
|
1964
2216
|
}
|
|
1965
|
-
}),
|
|
1966
|
-
let i = await
|
|
2217
|
+
}), u.post("/v1/reciprocal-approvals", async (e) => {
|
|
2218
|
+
let i = await p(e);
|
|
1967
2219
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1968
|
-
let a =
|
|
2220
|
+
let a = m(i);
|
|
1969
2221
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1970
2222
|
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
2223
|
if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
|
|
@@ -1981,8 +2233,8 @@ function mn(e) {
|
|
|
1981
2233
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1982
2234
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1983
2235
|
});
|
|
1984
|
-
if (!n.ok || !n.enrollment) return
|
|
1985
|
-
let a =
|
|
2236
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2237
|
+
let a = f(e, String(n.enrollment.device_id), !0);
|
|
1986
2238
|
if (a) return a;
|
|
1987
2239
|
if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
|
|
1988
2240
|
if (!await l.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
|
|
@@ -1998,18 +2250,18 @@ function mn(e) {
|
|
|
1998
2250
|
request: t
|
|
1999
2251
|
});
|
|
2000
2252
|
} catch (t) {
|
|
2001
|
-
if (t instanceof
|
|
2253
|
+
if (t instanceof Ae) return e.json({ error: t.code }, 409);
|
|
2002
2254
|
throw t;
|
|
2003
2255
|
}
|
|
2004
2256
|
} finally {
|
|
2005
2257
|
await l.close();
|
|
2006
2258
|
}
|
|
2007
|
-
}),
|
|
2008
|
-
let i = await
|
|
2259
|
+
}), u.post("/v1/invites/add-device", async (e) => {
|
|
2260
|
+
let i = await p(e);
|
|
2009
2261
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
2010
|
-
let a =
|
|
2262
|
+
let a = m(i);
|
|
2011
2263
|
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
2012
|
-
let o = new Set([
|
|
2264
|
+
let o = /* @__PURE__ */ new Set([
|
|
2013
2265
|
"group_id",
|
|
2014
2266
|
"expires_at",
|
|
2015
2267
|
"reviewed_preview_digest",
|
|
@@ -2033,14 +2285,14 @@ function mn(e) {
|
|
|
2033
2285
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
2034
2286
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
2035
2287
|
});
|
|
2036
|
-
if (!n.ok || !n.enrollment) return
|
|
2037
|
-
let o =
|
|
2288
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
2289
|
+
let o = f(e, String(n.enrollment.device_id), !0);
|
|
2038
2290
|
if (o) return o;
|
|
2039
2291
|
let d = n.enrollment.identity_id;
|
|
2040
2292
|
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
|
|
2293
|
+
let p;
|
|
2042
2294
|
try {
|
|
2043
|
-
|
|
2295
|
+
p = await it(a.reviewed_intent, {
|
|
2044
2296
|
target: {
|
|
2045
2297
|
kind: "add_device",
|
|
2046
2298
|
targetIdentityId: d
|
|
@@ -2048,7 +2300,7 @@ function mn(e) {
|
|
|
2048
2300
|
digest: l
|
|
2049
2301
|
});
|
|
2050
2302
|
} catch (t) {
|
|
2051
|
-
return t instanceof
|
|
2303
|
+
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
2304
|
}
|
|
2053
2305
|
let m = await u.createInvite({
|
|
2054
2306
|
groupId: s,
|
|
@@ -2059,7 +2311,7 @@ function mn(e) {
|
|
|
2059
2311
|
inviteKind: "add_device",
|
|
2060
2312
|
targetIdentityId: d,
|
|
2061
2313
|
reviewedPreviewDigest: l,
|
|
2062
|
-
reviewedIntent:
|
|
2314
|
+
reviewedIntent: p
|
|
2063
2315
|
}), h = {
|
|
2064
2316
|
v: 1,
|
|
2065
2317
|
kind: "add_device",
|
|
@@ -2072,45 +2324,45 @@ function mn(e) {
|
|
|
2072
2324
|
target_identity_id: m.target_identity_id ?? void 0,
|
|
2073
2325
|
inviter_device_id: m.inviter_device_id ?? void 0,
|
|
2074
2326
|
reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
|
|
2075
|
-
}, g =
|
|
2327
|
+
}, g = yn(h), { token: _, ...v } = m;
|
|
2076
2328
|
return e.json({
|
|
2077
2329
|
ok: !0,
|
|
2078
2330
|
invite: v,
|
|
2079
2331
|
payload: h,
|
|
2080
2332
|
encoded: g,
|
|
2081
|
-
link:
|
|
2333
|
+
link: xn(g)
|
|
2082
2334
|
});
|
|
2083
2335
|
} finally {
|
|
2084
2336
|
await u.close();
|
|
2085
2337
|
}
|
|
2086
|
-
}),
|
|
2338
|
+
}), u.post("/v1/admin/devices", async (e) => {
|
|
2087
2339
|
let r = Z(e.req.header(X), t);
|
|
2088
|
-
if (!r.ok) return
|
|
2089
|
-
let i =
|
|
2340
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2341
|
+
let i = f(e, "admin", !0);
|
|
2090
2342
|
if (i) return i;
|
|
2091
|
-
let a = await
|
|
2343
|
+
let a = await p(e);
|
|
2092
2344
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2093
|
-
let o =
|
|
2345
|
+
let o = m(a);
|
|
2094
2346
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2095
2347
|
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
2348
|
if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
|
|
2097
|
-
if (
|
|
2098
|
-
let
|
|
2349
|
+
if (ot(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
2350
|
+
let h = n();
|
|
2099
2351
|
try {
|
|
2100
|
-
await
|
|
2352
|
+
await h.createGroup(s), await h.enrollDevice(s, {
|
|
2101
2353
|
deviceId: c,
|
|
2102
2354
|
fingerprint: l,
|
|
2103
2355
|
publicKey: u,
|
|
2104
2356
|
displayName: d
|
|
2105
2357
|
});
|
|
2106
2358
|
} finally {
|
|
2107
|
-
await
|
|
2359
|
+
await h.close();
|
|
2108
2360
|
}
|
|
2109
2361
|
return e.json({ ok: !0 });
|
|
2110
|
-
}),
|
|
2362
|
+
}), u.get("/v1/admin/groups", async (e) => {
|
|
2111
2363
|
let r = Z(e.req.header(X), t);
|
|
2112
|
-
if (!r.ok) return
|
|
2113
|
-
let i =
|
|
2364
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2365
|
+
let i = f(e, "admin", !0);
|
|
2114
2366
|
if (i) return i;
|
|
2115
2367
|
let a = [
|
|
2116
2368
|
"1",
|
|
@@ -2122,14 +2374,14 @@ function mn(e) {
|
|
|
2122
2374
|
} finally {
|
|
2123
2375
|
await o.close();
|
|
2124
2376
|
}
|
|
2125
|
-
}),
|
|
2377
|
+
}), u.post("/v1/admin/groups", async (e) => {
|
|
2126
2378
|
let r = Z(e.req.header(X), t);
|
|
2127
|
-
if (!r.ok) return
|
|
2128
|
-
let i =
|
|
2379
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2380
|
+
let i = f(e, "admin", !0);
|
|
2129
2381
|
if (i) return i;
|
|
2130
|
-
let a = await
|
|
2382
|
+
let a = await p(e);
|
|
2131
2383
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2132
|
-
let o =
|
|
2384
|
+
let o = m(a);
|
|
2133
2385
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2134
2386
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
|
|
2135
2387
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2142,14 +2394,14 @@ function mn(e) {
|
|
|
2142
2394
|
} finally {
|
|
2143
2395
|
await l.close();
|
|
2144
2396
|
}
|
|
2145
|
-
}),
|
|
2397
|
+
}), u.post("/v1/admin/groups/rename", async (e) => {
|
|
2146
2398
|
let r = Z(e.req.header(X), t);
|
|
2147
|
-
if (!r.ok) return
|
|
2148
|
-
let i =
|
|
2399
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2400
|
+
let i = f(e, "admin", !0);
|
|
2149
2401
|
if (i) return i;
|
|
2150
|
-
let a = await
|
|
2402
|
+
let a = await p(e);
|
|
2151
2403
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2152
|
-
let o =
|
|
2404
|
+
let o = m(a);
|
|
2153
2405
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2154
2406
|
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
|
|
2155
2407
|
if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
|
|
@@ -2162,14 +2414,14 @@ function mn(e) {
|
|
|
2162
2414
|
} finally {
|
|
2163
2415
|
await l.close();
|
|
2164
2416
|
}
|
|
2165
|
-
}),
|
|
2417
|
+
}), u.post("/v1/admin/groups/archive", async (e) => {
|
|
2166
2418
|
let r = Z(e.req.header(X), t);
|
|
2167
|
-
if (!r.ok) return
|
|
2168
|
-
let i =
|
|
2419
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2420
|
+
let i = f(e, "admin", !0);
|
|
2169
2421
|
if (i) return i;
|
|
2170
|
-
let a = await
|
|
2422
|
+
let a = await p(e);
|
|
2171
2423
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2172
|
-
let o =
|
|
2424
|
+
let o = m(a);
|
|
2173
2425
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2174
2426
|
let s = String(o.group_id ?? "").trim();
|
|
2175
2427
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2182,14 +2434,14 @@ function mn(e) {
|
|
|
2182
2434
|
} finally {
|
|
2183
2435
|
await c.close();
|
|
2184
2436
|
}
|
|
2185
|
-
}),
|
|
2437
|
+
}), u.post("/v1/admin/groups/unarchive", async (e) => {
|
|
2186
2438
|
let r = Z(e.req.header(X), t);
|
|
2187
|
-
if (!r.ok) return
|
|
2188
|
-
let i =
|
|
2439
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2440
|
+
let i = f(e, "admin", !0);
|
|
2189
2441
|
if (i) return i;
|
|
2190
|
-
let a = await
|
|
2442
|
+
let a = await p(e);
|
|
2191
2443
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2192
|
-
let o =
|
|
2444
|
+
let o = m(a);
|
|
2193
2445
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2194
2446
|
let s = String(o.group_id ?? "").trim();
|
|
2195
2447
|
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2202,16 +2454,16 @@ function mn(e) {
|
|
|
2202
2454
|
} finally {
|
|
2203
2455
|
await c.close();
|
|
2204
2456
|
}
|
|
2205
|
-
}),
|
|
2457
|
+
}), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
2206
2458
|
let r = Z(e.req.header(X), t);
|
|
2207
|
-
if (!r.ok) return
|
|
2208
|
-
let i =
|
|
2459
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2460
|
+
let i = f(e, "admin", !0);
|
|
2209
2461
|
if (i) return i;
|
|
2210
2462
|
let a = String(e.req.param("group_id") ?? "").trim(), o = n();
|
|
2211
2463
|
try {
|
|
2212
|
-
let t = await
|
|
2464
|
+
let t = await x(o, a, e);
|
|
2213
2465
|
if (t) return t;
|
|
2214
|
-
let n =
|
|
2466
|
+
let n = v(e.req.query("include_inactive"));
|
|
2215
2467
|
return e.json({ items: await o.listScopes({
|
|
2216
2468
|
groupId: a,
|
|
2217
2469
|
includeInactive: n
|
|
@@ -2219,33 +2471,33 @@ function mn(e) {
|
|
|
2219
2471
|
} finally {
|
|
2220
2472
|
await o.close();
|
|
2221
2473
|
}
|
|
2222
|
-
}),
|
|
2474
|
+
}), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
2223
2475
|
let r = Z(e.req.header(X), t);
|
|
2224
|
-
if (!r.ok) return
|
|
2225
|
-
let i =
|
|
2476
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2477
|
+
let i = f(e, "admin", !0);
|
|
2226
2478
|
if (i) return i;
|
|
2227
|
-
let a = await
|
|
2479
|
+
let a = await p(e);
|
|
2228
2480
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2229
|
-
let o =
|
|
2481
|
+
let o = m(a);
|
|
2230
2482
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2231
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c =
|
|
2483
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
|
|
2232
2484
|
if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
|
|
2233
2485
|
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2234
2486
|
let d = n();
|
|
2235
2487
|
try {
|
|
2236
|
-
let t = await
|
|
2488
|
+
let t = await x(d, s, e);
|
|
2237
2489
|
if (t) return t;
|
|
2238
2490
|
let n = await d.createScope({
|
|
2239
2491
|
scopeId: c,
|
|
2240
2492
|
label: l,
|
|
2241
|
-
kind:
|
|
2242
|
-
authorityType:
|
|
2243
|
-
coordinatorId:
|
|
2493
|
+
kind: h(o, "kind"),
|
|
2494
|
+
authorityType: h(o, "authority_type"),
|
|
2495
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
2244
2496
|
groupId: s,
|
|
2245
|
-
manifestIssuerDeviceId:
|
|
2497
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
2246
2498
|
membershipEpoch: u,
|
|
2247
|
-
manifestHash:
|
|
2248
|
-
status:
|
|
2499
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2500
|
+
status: h(o, "status")
|
|
2249
2501
|
});
|
|
2250
2502
|
return e.json({
|
|
2251
2503
|
ok: !0,
|
|
@@ -2256,33 +2508,33 @@ function mn(e) {
|
|
|
2256
2508
|
} finally {
|
|
2257
2509
|
await d.close();
|
|
2258
2510
|
}
|
|
2259
|
-
}),
|
|
2511
|
+
}), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
|
|
2260
2512
|
let r = Z(e.req.header(X), t);
|
|
2261
|
-
if (!r.ok) return
|
|
2262
|
-
let i =
|
|
2513
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2514
|
+
let i = f(e, "admin", !0);
|
|
2263
2515
|
if (i) return i;
|
|
2264
|
-
let a = await
|
|
2516
|
+
let a = await p(e);
|
|
2265
2517
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2266
|
-
let o =
|
|
2518
|
+
let o = m(a);
|
|
2267
2519
|
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 =
|
|
2520
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
|
|
2269
2521
|
if (!c) return e.json({ error: "scope_id_required" }, 400);
|
|
2270
2522
|
if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2271
2523
|
let u = n();
|
|
2272
2524
|
try {
|
|
2273
|
-
let t = await
|
|
2525
|
+
let t = await S(u, s, c, e);
|
|
2274
2526
|
if (t.response) return t.response;
|
|
2275
2527
|
let n = await u.updateScope({
|
|
2276
2528
|
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 :
|
|
2529
|
+
label: o.label === void 0 ? void 0 : h(o, "label"),
|
|
2530
|
+
kind: o.kind === void 0 ? void 0 : h(o, "kind"),
|
|
2531
|
+
authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
|
|
2532
|
+
coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
|
|
2281
2533
|
groupId: s,
|
|
2282
|
-
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 :
|
|
2534
|
+
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
|
|
2283
2535
|
membershipEpoch: l,
|
|
2284
|
-
manifestHash: o.manifest_hash === void 0 ? void 0 :
|
|
2285
|
-
status: o.status === void 0 ? void 0 :
|
|
2536
|
+
manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
|
|
2537
|
+
status: o.status === void 0 ? void 0 : h(o, "status")
|
|
2286
2538
|
});
|
|
2287
2539
|
return n ? e.json({
|
|
2288
2540
|
ok: !0,
|
|
@@ -2293,48 +2545,48 @@ function mn(e) {
|
|
|
2293
2545
|
} finally {
|
|
2294
2546
|
await u.close();
|
|
2295
2547
|
}
|
|
2296
|
-
}),
|
|
2548
|
+
}), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2297
2549
|
let r = Z(e.req.header(X), t);
|
|
2298
|
-
if (!r.ok) return
|
|
2299
|
-
let i =
|
|
2550
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2551
|
+
let i = f(e, "admin", !0);
|
|
2300
2552
|
if (i) return i;
|
|
2301
2553
|
let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
|
|
2302
2554
|
try {
|
|
2303
|
-
let t = await
|
|
2304
|
-
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o,
|
|
2555
|
+
let t = await S(s, a, o, e);
|
|
2556
|
+
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
|
|
2305
2557
|
} finally {
|
|
2306
2558
|
await s.close();
|
|
2307
2559
|
}
|
|
2308
|
-
}),
|
|
2560
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
2309
2561
|
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
|
|
2562
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2563
|
+
let i = f(e, "admin", !0);
|
|
2564
|
+
if (i) return i;
|
|
2565
|
+
let a = await p(e);
|
|
2566
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2567
|
+
let o = m(a);
|
|
2568
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2569
|
+
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");
|
|
2570
|
+
if (!l) return e.json({ error: "effect_id_required" }, 400);
|
|
2571
|
+
if (!u) return e.json({ error: "device_id_required" }, 400);
|
|
2572
|
+
if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2573
|
+
let v = n();
|
|
2322
2574
|
try {
|
|
2323
|
-
let t = await
|
|
2575
|
+
let t = await S(v, s, c, e);
|
|
2324
2576
|
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:
|
|
2577
|
+
let n = await v.grantScopeMembership({
|
|
2578
|
+
effectId: l,
|
|
2579
|
+
scopeId: c,
|
|
2580
|
+
deviceId: u,
|
|
2581
|
+
role: h(o, "role"),
|
|
2582
|
+
membershipEpoch: d,
|
|
2583
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
2584
|
+
groupId: s,
|
|
2585
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
2586
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2587
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
2336
2588
|
actorType: "admin",
|
|
2337
|
-
actorId:
|
|
2589
|
+
actorId: g(e.req.header(or))
|
|
2338
2590
|
});
|
|
2339
2591
|
return e.json({
|
|
2340
2592
|
ok: !0,
|
|
@@ -2342,67 +2594,67 @@ function mn(e) {
|
|
|
2342
2594
|
}, 201);
|
|
2343
2595
|
} catch (t) {
|
|
2344
2596
|
let n = t instanceof Error ? t.message : String(t);
|
|
2345
|
-
if (t instanceof
|
|
2346
|
-
if (t instanceof
|
|
2347
|
-
let r = t instanceof
|
|
2597
|
+
if (t instanceof N && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
|
|
2598
|
+
if (t instanceof N && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
|
|
2599
|
+
let r = t instanceof N && t.code === "scope_inactive";
|
|
2348
2600
|
return e.json({ error: r ? "scope_not_active" : n }, n === "scope_membership_effect_conflict" || r ? 409 : 400);
|
|
2349
2601
|
} finally {
|
|
2350
|
-
await
|
|
2602
|
+
await v.close();
|
|
2351
2603
|
}
|
|
2352
|
-
}),
|
|
2604
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
|
|
2353
2605
|
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
|
|
2606
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2607
|
+
let i = f(e, "admin", !0);
|
|
2608
|
+
if (i) return i;
|
|
2609
|
+
let a = await p(e);
|
|
2610
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2611
|
+
let o = a.byteLength > 0 ? m(a) : {};
|
|
2612
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2613
|
+
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");
|
|
2614
|
+
if (!u) return e.json({ error: "effect_id_required" }, 400);
|
|
2615
|
+
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
2616
|
+
if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
2617
|
+
let v = n();
|
|
2366
2618
|
try {
|
|
2367
|
-
let t = await
|
|
2619
|
+
let t = await S(v, s, c, e);
|
|
2368
2620
|
if (t.response) return t.response;
|
|
2369
|
-
if (!await
|
|
2370
|
-
effectId:
|
|
2371
|
-
scopeId:
|
|
2372
|
-
deviceId:
|
|
2373
|
-
groupId:
|
|
2374
|
-
membershipEpoch:
|
|
2375
|
-
manifestHash:
|
|
2376
|
-
signedManifestJson:
|
|
2621
|
+
if (!await v.revokeScopeMembership({
|
|
2622
|
+
effectId: u,
|
|
2623
|
+
scopeId: c,
|
|
2624
|
+
deviceId: l,
|
|
2625
|
+
groupId: s,
|
|
2626
|
+
membershipEpoch: d,
|
|
2627
|
+
manifestHash: h(o, "manifest_hash"),
|
|
2628
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
2377
2629
|
actorType: "admin",
|
|
2378
|
-
actorId:
|
|
2630
|
+
actorId: g(e.req.header(or))
|
|
2379
2631
|
})) return e.json({ error: "membership_not_found" }, 404);
|
|
2380
2632
|
let n;
|
|
2381
2633
|
try {
|
|
2382
|
-
n = (await
|
|
2634
|
+
n = (await v.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
|
|
2383
2635
|
} catch {
|
|
2384
2636
|
n = void 0;
|
|
2385
2637
|
}
|
|
2386
2638
|
return e.json({
|
|
2387
2639
|
ok: !0,
|
|
2388
|
-
scope_id:
|
|
2389
|
-
device_id:
|
|
2390
|
-
revocation:
|
|
2391
|
-
scopeId:
|
|
2392
|
-
deviceId:
|
|
2393
|
-
membershipEpoch: n?.membership_epoch ??
|
|
2640
|
+
scope_id: c,
|
|
2641
|
+
device_id: l,
|
|
2642
|
+
revocation: nr({
|
|
2643
|
+
scopeId: c,
|
|
2644
|
+
deviceId: l,
|
|
2645
|
+
membershipEpoch: n?.membership_epoch ?? d
|
|
2394
2646
|
})
|
|
2395
2647
|
});
|
|
2396
2648
|
} catch (t) {
|
|
2397
2649
|
let n = t instanceof Error ? t.message : String(t);
|
|
2398
|
-
return t instanceof
|
|
2650
|
+
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
2651
|
} finally {
|
|
2400
|
-
await
|
|
2652
|
+
await v.close();
|
|
2401
2653
|
}
|
|
2402
|
-
}),
|
|
2654
|
+
}), u.get("/v1/admin/devices", async (e) => {
|
|
2403
2655
|
let r = Z(e.req.header(X), t);
|
|
2404
|
-
if (!r.ok) return
|
|
2405
|
-
let i =
|
|
2656
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2657
|
+
let i = f(e, "admin", !0);
|
|
2406
2658
|
if (i) return i;
|
|
2407
2659
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2408
2660
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2416,21 +2668,21 @@ function mn(e) {
|
|
|
2416
2668
|
} finally {
|
|
2417
2669
|
await s.close();
|
|
2418
2670
|
}
|
|
2419
|
-
}),
|
|
2671
|
+
}), u.post("/v1/admin/devices/rename", async (e) => {
|
|
2420
2672
|
let r = Z(e.req.header(X), t);
|
|
2421
|
-
if (!r.ok) return
|
|
2422
|
-
let i =
|
|
2673
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2674
|
+
let i = f(e, "admin", !0);
|
|
2423
2675
|
if (i) return i;
|
|
2424
|
-
let a = await
|
|
2676
|
+
let a = await p(e);
|
|
2425
2677
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2426
|
-
let o =
|
|
2678
|
+
let o = m(a);
|
|
2427
2679
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2428
2680
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
|
|
2429
2681
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
2430
2682
|
if (!l) return e.json({ error: "display_name_required" }, 400);
|
|
2431
2683
|
let u;
|
|
2432
2684
|
try {
|
|
2433
|
-
u =
|
|
2685
|
+
u = I(l, "display_name");
|
|
2434
2686
|
} catch (t) {
|
|
2435
2687
|
return e.json({ error: t instanceof Error ? t.message : "display_name_invalid" }, 400);
|
|
2436
2688
|
}
|
|
@@ -2445,14 +2697,14 @@ function mn(e) {
|
|
|
2445
2697
|
} finally {
|
|
2446
2698
|
await d.close();
|
|
2447
2699
|
}
|
|
2448
|
-
}),
|
|
2700
|
+
}), u.post("/v1/admin/devices/disable", async (e) => {
|
|
2449
2701
|
let r = Z(e.req.header(X), t);
|
|
2450
|
-
if (!r.ok) return
|
|
2451
|
-
let i =
|
|
2702
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2703
|
+
let i = f(e, "admin", !0);
|
|
2452
2704
|
if (i) return i;
|
|
2453
|
-
let a = await
|
|
2705
|
+
let a = await p(e);
|
|
2454
2706
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2455
|
-
let o =
|
|
2707
|
+
let o = m(a);
|
|
2456
2708
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2457
2709
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2458
2710
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2462,14 +2714,14 @@ function mn(e) {
|
|
|
2462
2714
|
} finally {
|
|
2463
2715
|
await l.close();
|
|
2464
2716
|
}
|
|
2465
|
-
}),
|
|
2717
|
+
}), u.post("/v1/admin/devices/enable", async (e) => {
|
|
2466
2718
|
let r = Z(e.req.header(X), t);
|
|
2467
|
-
if (!r.ok) return
|
|
2468
|
-
let i =
|
|
2719
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2720
|
+
let i = f(e, "admin", !0);
|
|
2469
2721
|
if (i) return i;
|
|
2470
|
-
let a = await
|
|
2722
|
+
let a = await p(e);
|
|
2471
2723
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2472
|
-
let o =
|
|
2724
|
+
let o = m(a);
|
|
2473
2725
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2474
2726
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2475
2727
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2479,14 +2731,14 @@ function mn(e) {
|
|
|
2479
2731
|
} finally {
|
|
2480
2732
|
await l.close();
|
|
2481
2733
|
}
|
|
2482
|
-
}),
|
|
2734
|
+
}), u.post("/v1/admin/devices/remove", async (e) => {
|
|
2483
2735
|
let r = Z(e.req.header(X), t);
|
|
2484
|
-
if (!r.ok) return
|
|
2485
|
-
let i =
|
|
2736
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2737
|
+
let i = f(e, "admin", !0);
|
|
2486
2738
|
if (i) return i;
|
|
2487
|
-
let a = await
|
|
2739
|
+
let a = await p(e);
|
|
2488
2740
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2489
|
-
let o =
|
|
2741
|
+
let o = m(a);
|
|
2490
2742
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2491
2743
|
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
2492
2744
|
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
@@ -2496,49 +2748,127 @@ function mn(e) {
|
|
|
2496
2748
|
} finally {
|
|
2497
2749
|
await l.close();
|
|
2498
2750
|
}
|
|
2499
|
-
}),
|
|
2751
|
+
}), u.post("/v1/admin/legacy-team-completions", async (e) => {
|
|
2752
|
+
let r = Z(e.req.header(X), t);
|
|
2753
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2754
|
+
let i = f(e, "admin", !0);
|
|
2755
|
+
if (i) return i;
|
|
2756
|
+
let a = await p(e, ar);
|
|
2757
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2758
|
+
let o = m(a);
|
|
2759
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2760
|
+
if (Object.keys(o).some((e) => e !== "group_id" && e !== "manifest")) return e.json({ error: "completion_manifest_invalid" }, 400);
|
|
2761
|
+
let s, c;
|
|
2762
|
+
try {
|
|
2763
|
+
let e = de([o.group_id])[0];
|
|
2764
|
+
if (!e) throw Error("completion_manifest_invalid");
|
|
2765
|
+
s = e, c = pe(o.manifest), he(c);
|
|
2766
|
+
} catch {
|
|
2767
|
+
return e.json({ error: "completion_manifest_invalid" }, 400);
|
|
2768
|
+
}
|
|
2769
|
+
let l = n();
|
|
2770
|
+
try {
|
|
2771
|
+
let t = await l.createLegacyTeamCompletion(s, c);
|
|
2772
|
+
return e.json({
|
|
2773
|
+
ok: !0,
|
|
2774
|
+
...t
|
|
2775
|
+
}, t.status === "created" ? 201 : 200);
|
|
2776
|
+
} catch (t) {
|
|
2777
|
+
if (t instanceof ae) return e.json({ error: t.code }, 409);
|
|
2778
|
+
let n = t instanceof Error ? t.message : "completion_manifest_invalid";
|
|
2779
|
+
if (n === "group_not_found") return e.json({ error: n }, 404);
|
|
2780
|
+
if (n === "group_archived" || n === "completion_manifest_unavailable") return e.json({ error: n }, 409);
|
|
2781
|
+
if (n === "completion_manifest_invalid") return e.json({ error: n }, 400);
|
|
2782
|
+
throw t;
|
|
2783
|
+
} finally {
|
|
2784
|
+
await l.close();
|
|
2785
|
+
}
|
|
2786
|
+
}), u.get("/v1/admin/legacy-team-completions", async (e) => {
|
|
2787
|
+
let r = Z(e.req.header(X), t);
|
|
2788
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2789
|
+
let i = f(e, "admin", !0);
|
|
2790
|
+
if (i) return i;
|
|
2791
|
+
let a = String(e.req.query("group_id") ?? "").trim(), o;
|
|
2792
|
+
try {
|
|
2793
|
+
if (de([a]).length !== 1) throw Error("completion_manifest_invalid");
|
|
2794
|
+
o = fe(e.req.query("candidate_ref"));
|
|
2795
|
+
} catch {
|
|
2796
|
+
return e.json({ error: "group_id_and_candidate_ref_required" }, 400);
|
|
2797
|
+
}
|
|
2798
|
+
let s = n();
|
|
2799
|
+
try {
|
|
2800
|
+
let t = await s.getLegacyTeamCompletion(a, o);
|
|
2801
|
+
return t ? e.json({ manifest: t }) : e.json({ error: "completion_not_found" }, 404);
|
|
2802
|
+
} finally {
|
|
2803
|
+
await s.close();
|
|
2804
|
+
}
|
|
2805
|
+
}), u.post("/v1/admin/legacy-team-completions/query", async (e) => {
|
|
2806
|
+
let r = Z(e.req.header(X), t);
|
|
2807
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2808
|
+
let i = f(e, "admin", !0);
|
|
2809
|
+
if (i) return i;
|
|
2810
|
+
let a = await p(e);
|
|
2811
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2812
|
+
let o = m(a);
|
|
2813
|
+
if (!o || Object.keys(o).some((e) => e !== "group_ids")) return e.json({ error: "completion_query_invalid" }, 400);
|
|
2814
|
+
let s;
|
|
2815
|
+
try {
|
|
2816
|
+
if (s = de(o.group_ids), s.length === 0) throw Error("completion_query_invalid");
|
|
2817
|
+
} catch {
|
|
2818
|
+
return e.json({ error: "completion_query_invalid" }, 400);
|
|
2819
|
+
}
|
|
2820
|
+
let c = n();
|
|
2821
|
+
try {
|
|
2822
|
+
return e.json({ items: await c.listLegacyTeamCompletions(s) });
|
|
2823
|
+
} catch (t) {
|
|
2824
|
+
if (t instanceof Error && t.message === "completion_results_too_large") return e.json({ error: t.message }, 413);
|
|
2825
|
+
throw t;
|
|
2826
|
+
} finally {
|
|
2827
|
+
await c.close();
|
|
2828
|
+
}
|
|
2829
|
+
}), u.post("/v1/admin/invites", async (e) => {
|
|
2500
2830
|
let r = Z(e.req.header(X), t);
|
|
2501
|
-
if (!r.ok) return
|
|
2502
|
-
let i =
|
|
2831
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2832
|
+
let i = f(e, "admin", !0);
|
|
2503
2833
|
if (i) return i;
|
|
2504
|
-
let a = await
|
|
2834
|
+
let a = await p(e);
|
|
2505
2835
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2506
|
-
let o =
|
|
2836
|
+
let o = m(a);
|
|
2507
2837
|
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,
|
|
2838
|
+
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, C, w = null, T = null;
|
|
2509
2839
|
if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
|
|
2510
2840
|
if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
|
|
2511
2841
|
if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
|
|
2512
|
-
if (!!d != !!
|
|
2513
|
-
let
|
|
2842
|
+
if (!!d != !!h) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
|
|
2843
|
+
let E = ee || (d ? "project_share" : "legacy_enrollment");
|
|
2514
2844
|
if (![
|
|
2515
2845
|
"legacy_enrollment",
|
|
2516
2846
|
"project_share",
|
|
2517
2847
|
"team_member",
|
|
2518
2848
|
"add_device"
|
|
2519
|
-
].includes(
|
|
2520
|
-
if (
|
|
2521
|
-
if (
|
|
2522
|
-
if (
|
|
2523
|
-
if ([
|
|
2524
|
-
if (
|
|
2849
|
+
].includes(E)) return e.json({ error: "invite_kind_invalid" }, 400);
|
|
2850
|
+
if (E === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
|
|
2851
|
+
if (S && !/^[a-f0-9]{64}$/u.test(S)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
|
|
2852
|
+
if (E === "team_member" && (!b || !S || x) || E === "add_device" && (!x || !S || b) || !["team_member", "add_device"].includes(E) && (b || x || S)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
|
|
2853
|
+
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);
|
|
2854
|
+
if (E === "team_member" || E === "add_device") {
|
|
2525
2855
|
if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
|
|
2526
2856
|
try {
|
|
2527
|
-
|
|
2528
|
-
target:
|
|
2857
|
+
C = await it(o.reviewed_intent, {
|
|
2858
|
+
target: E === "team_member" ? {
|
|
2529
2859
|
kind: "team_member",
|
|
2530
|
-
policyTeamId: String(
|
|
2860
|
+
policyTeamId: String(b)
|
|
2531
2861
|
} : {
|
|
2532
2862
|
kind: "add_device",
|
|
2533
|
-
targetIdentityId: String(
|
|
2863
|
+
targetIdentityId: String(x)
|
|
2534
2864
|
},
|
|
2535
|
-
digest: String(
|
|
2865
|
+
digest: String(S)
|
|
2536
2866
|
});
|
|
2537
2867
|
} catch (t) {
|
|
2538
|
-
return t instanceof
|
|
2868
|
+
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
2869
|
}
|
|
2540
2870
|
} 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) ||
|
|
2871
|
+
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
2872
|
if (d) {
|
|
2543
2873
|
if (!g || !_ || !v || !y) return e.json({ error: "project_invite_identity_context_required" }, 400);
|
|
2544
2874
|
if ([
|
|
@@ -2547,44 +2877,44 @@ function mn(e) {
|
|
|
2547
2877
|
y
|
|
2548
2878
|
].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
|
|
2549
2879
|
try {
|
|
2550
|
-
if (
|
|
2880
|
+
if (I(_, "inviter_display_name"), w = Be(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== w.length || (T = o.project_intent.map((e, t) => {
|
|
2551
2881
|
let n;
|
|
2552
2882
|
try {
|
|
2553
|
-
n =
|
|
2883
|
+
n = Jn([e])[0];
|
|
2554
2884
|
} catch {
|
|
2555
2885
|
throw Error("project_intent_invalid");
|
|
2556
2886
|
}
|
|
2557
|
-
let r =
|
|
2887
|
+
let r = w?.[t];
|
|
2558
2888
|
if (!n || !r || n.display_name !== r.display_name || n.existing_memory_count !== r.existing_memory_count) throw Error("project_intent_invalid");
|
|
2559
2889
|
return n;
|
|
2560
|
-
}), new Set(
|
|
2890
|
+
}), new Set(T.map((e) => e.canonical_identity)).size !== T.length)) throw Error("project_intent_invalid");
|
|
2561
2891
|
} catch (t) {
|
|
2562
2892
|
return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
|
|
2563
2893
|
}
|
|
2564
2894
|
}
|
|
2565
|
-
let
|
|
2895
|
+
let D = n();
|
|
2566
2896
|
try {
|
|
2567
|
-
let t = await
|
|
2897
|
+
let t = await D.getGroup(s);
|
|
2568
2898
|
if (!t) return e.json({ error: "group_not_found" }, 404);
|
|
2569
2899
|
if (t.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
2570
|
-
let n = await
|
|
2900
|
+
let n = await D.createInvite({
|
|
2571
2901
|
groupId: s,
|
|
2572
2902
|
policy: c,
|
|
2573
2903
|
expiresAt: l,
|
|
2574
2904
|
createdBy: u,
|
|
2575
2905
|
operationId: d,
|
|
2576
|
-
reviewedProjectSetDigest:
|
|
2906
|
+
reviewedProjectSetDigest: h,
|
|
2577
2907
|
inviterActorId: g,
|
|
2578
2908
|
inviterDisplayName: _,
|
|
2579
2909
|
inviterDeviceId: v,
|
|
2580
2910
|
pendingPersonId: y,
|
|
2581
|
-
projectSummaries:
|
|
2582
|
-
projectIntent:
|
|
2583
|
-
inviteKind:
|
|
2584
|
-
policyTeamId:
|
|
2585
|
-
targetIdentityId:
|
|
2586
|
-
reviewedPreviewDigest:
|
|
2587
|
-
reviewedIntent:
|
|
2911
|
+
projectSummaries: w,
|
|
2912
|
+
projectIntent: T,
|
|
2913
|
+
inviteKind: E,
|
|
2914
|
+
policyTeamId: b,
|
|
2915
|
+
targetIdentityId: x,
|
|
2916
|
+
reviewedPreviewDigest: S,
|
|
2917
|
+
reviewedIntent: C
|
|
2588
2918
|
}), r = {
|
|
2589
2919
|
v: 1,
|
|
2590
2920
|
kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
|
|
@@ -2597,7 +2927,7 @@ function mn(e) {
|
|
|
2597
2927
|
...n.operation_id ? {
|
|
2598
2928
|
operation_id: n.operation_id,
|
|
2599
2929
|
inviter_name: n.inviter_display_name ?? null,
|
|
2600
|
-
project_summaries:
|
|
2930
|
+
project_summaries: w ?? []
|
|
2601
2931
|
} : {},
|
|
2602
2932
|
...n.invite_kind === "team_member" ? {
|
|
2603
2933
|
policy_team_id: n.policy_team_id ?? void 0,
|
|
@@ -2609,25 +2939,25 @@ function mn(e) {
|
|
|
2609
2939
|
inviter_device_id: n.inviter_device_id ?? void 0,
|
|
2610
2940
|
reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
|
|
2611
2941
|
} : {}
|
|
2612
|
-
}, i =
|
|
2942
|
+
}, i = yn(r), { token: a, ...f } = n;
|
|
2613
2943
|
return e.json({
|
|
2614
2944
|
ok: !0,
|
|
2615
|
-
invite:
|
|
2945
|
+
invite: f,
|
|
2616
2946
|
payload: r,
|
|
2617
2947
|
encoded: i,
|
|
2618
|
-
link:
|
|
2948
|
+
link: xn(i)
|
|
2619
2949
|
});
|
|
2620
2950
|
} catch (t) {
|
|
2621
2951
|
if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
|
|
2622
2952
|
if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
|
|
2623
2953
|
throw t;
|
|
2624
2954
|
} finally {
|
|
2625
|
-
await
|
|
2955
|
+
await D.close();
|
|
2626
2956
|
}
|
|
2627
|
-
}),
|
|
2628
|
-
let r = await
|
|
2957
|
+
}), u.post("/v1/invites/inspect", async (e) => {
|
|
2958
|
+
let r = await p(e);
|
|
2629
2959
|
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
2630
|
-
let i =
|
|
2960
|
+
let i = m(r);
|
|
2631
2961
|
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
2632
2962
|
let a = String(i.token ?? "").trim();
|
|
2633
2963
|
if (!a) return e.json({ error: "invite_invalid" }, 404);
|
|
@@ -2667,7 +2997,7 @@ function mn(e) {
|
|
|
2667
2997
|
if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
|
|
2668
2998
|
let i;
|
|
2669
2999
|
try {
|
|
2670
|
-
i =
|
|
3000
|
+
i = b(n.project_summaries_json);
|
|
2671
3001
|
} catch {
|
|
2672
3002
|
return e.json({ error: "invite_invalid" }, 409);
|
|
2673
3003
|
}
|
|
@@ -2682,10 +3012,10 @@ function mn(e) {
|
|
|
2682
3012
|
} finally {
|
|
2683
3013
|
await o.close();
|
|
2684
3014
|
}
|
|
2685
|
-
}),
|
|
3015
|
+
}), u.get("/v1/admin/invites", async (e) => {
|
|
2686
3016
|
let r = Z(e.req.header(X), t);
|
|
2687
|
-
if (!r.ok) return
|
|
2688
|
-
let i =
|
|
3017
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3018
|
+
let i = f(e, "admin", !0);
|
|
2689
3019
|
if (i) return i;
|
|
2690
3020
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2691
3021
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2696,7 +3026,7 @@ function mn(e) {
|
|
|
2696
3026
|
} finally {
|
|
2697
3027
|
await o.close();
|
|
2698
3028
|
}
|
|
2699
|
-
}),
|
|
3029
|
+
}), u.get("/v1/admin/project-invites/:operationId", async (e) => {
|
|
2700
3030
|
let r = Z(e.req.header(X), t);
|
|
2701
3031
|
if (!r.ok) return e.json({ error: r.error }, 401);
|
|
2702
3032
|
let i = String(e.req.param("operationId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
|
|
@@ -2707,7 +3037,7 @@ function mn(e) {
|
|
|
2707
3037
|
if (!n) return e.json({ error: "operation_not_found" }, 404);
|
|
2708
3038
|
let r;
|
|
2709
3039
|
try {
|
|
2710
|
-
r =
|
|
3040
|
+
r = y(n.project_intent_json);
|
|
2711
3041
|
} catch {
|
|
2712
3042
|
return e.json({ error: "operation_intent_invalid" }, 409);
|
|
2713
3043
|
}
|
|
@@ -2717,7 +3047,7 @@ function mn(e) {
|
|
|
2717
3047
|
display_name: String(e.display_name ?? ""),
|
|
2718
3048
|
existing_memory_count: Number(e.existing_memory_count ?? 0)
|
|
2719
3049
|
}));
|
|
2720
|
-
s =
|
|
3050
|
+
s = xn(yn({
|
|
2721
3051
|
v: 1,
|
|
2722
3052
|
kind: "coordinator_team_invite",
|
|
2723
3053
|
coordinator_url: new URL(e.req.url).origin,
|
|
@@ -2752,10 +3082,10 @@ function mn(e) {
|
|
|
2752
3082
|
} finally {
|
|
2753
3083
|
await o.close();
|
|
2754
3084
|
}
|
|
2755
|
-
}),
|
|
3085
|
+
}), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
|
|
2756
3086
|
let r = Z(e.req.header(X), t);
|
|
2757
|
-
if (!r.ok) return
|
|
2758
|
-
let i =
|
|
3087
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3088
|
+
let i = f(e, "admin", !0);
|
|
2759
3089
|
if (i) return i;
|
|
2760
3090
|
let a = String(e.req.param("grantId") ?? "").trim();
|
|
2761
3091
|
if (!a) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -2773,7 +3103,7 @@ function mn(e) {
|
|
|
2773
3103
|
} finally {
|
|
2774
3104
|
await o.close();
|
|
2775
3105
|
}
|
|
2776
|
-
}),
|
|
3106
|
+
}), u.get("/v1/bootstrap-grants/:grantId", async (e) => {
|
|
2777
3107
|
let i = String(e.req.param("grantId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
|
|
2778
3108
|
if (!i || !a) return e.json({ error: "grant_id_and_group_id_required" }, 400);
|
|
2779
3109
|
let o = n();
|
|
@@ -2782,14 +3112,14 @@ function mn(e) {
|
|
|
2782
3112
|
method: e.req.method,
|
|
2783
3113
|
url: e.req.url,
|
|
2784
3114
|
groupId: a,
|
|
2785
|
-
body: new Uint8Array(),
|
|
3115
|
+
body: /* @__PURE__ */ new Uint8Array(),
|
|
2786
3116
|
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
2787
3117
|
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
2788
3118
|
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
2789
3119
|
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
2790
3120
|
});
|
|
2791
|
-
if (!n.ok || !n.enrollment) return
|
|
2792
|
-
let s =
|
|
3121
|
+
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
|
|
3122
|
+
let s = f(e, String(n.enrollment.device_id), !0);
|
|
2793
3123
|
if (s) return s;
|
|
2794
3124
|
let c = await o.getBootstrapGrant(i);
|
|
2795
3125
|
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 +3131,10 @@ function mn(e) {
|
|
|
2801
3131
|
} finally {
|
|
2802
3132
|
await o.close();
|
|
2803
3133
|
}
|
|
2804
|
-
}),
|
|
3134
|
+
}), u.get("/v1/admin/bootstrap-grants", async (e) => {
|
|
2805
3135
|
let r = Z(e.req.header(X), t);
|
|
2806
|
-
if (!r.ok) return
|
|
2807
|
-
let i =
|
|
3136
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3137
|
+
let i = f(e, "admin", !0);
|
|
2808
3138
|
if (i) return i;
|
|
2809
3139
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2810
3140
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2814,14 +3144,14 @@ function mn(e) {
|
|
|
2814
3144
|
} finally {
|
|
2815
3145
|
await o.close();
|
|
2816
3146
|
}
|
|
2817
|
-
}),
|
|
3147
|
+
}), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
|
|
2818
3148
|
let r = Z(e.req.header(X), t);
|
|
2819
|
-
if (!r.ok) return
|
|
2820
|
-
let i =
|
|
3149
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3150
|
+
let i = f(e, "admin", !0);
|
|
2821
3151
|
if (i) return i;
|
|
2822
|
-
let a = await
|
|
3152
|
+
let a = await p(e);
|
|
2823
3153
|
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2824
|
-
let o =
|
|
3154
|
+
let o = m(a);
|
|
2825
3155
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2826
3156
|
let s = String(o.grant_id ?? "").trim();
|
|
2827
3157
|
if (!s) return e.json({ error: "grant_id_required" }, 400);
|
|
@@ -2834,18 +3164,18 @@ function mn(e) {
|
|
|
2834
3164
|
} finally {
|
|
2835
3165
|
await c.close();
|
|
2836
3166
|
}
|
|
2837
|
-
}),
|
|
3167
|
+
}), u.post("/v1/admin/join-requests/approve", async (e) => pr(e, !0, {
|
|
2838
3168
|
createStore: n,
|
|
2839
3169
|
runtime: t,
|
|
2840
|
-
rateLimitedResponse:
|
|
2841
|
-
})),
|
|
3170
|
+
rateLimitedResponse: f
|
|
3171
|
+
})), u.post("/v1/admin/join-requests/deny", async (e) => pr(e, !1, {
|
|
2842
3172
|
createStore: n,
|
|
2843
3173
|
runtime: t,
|
|
2844
|
-
rateLimitedResponse:
|
|
2845
|
-
})),
|
|
3174
|
+
rateLimitedResponse: f
|
|
3175
|
+
})), u.get("/v1/admin/join-requests", async (e) => {
|
|
2846
3176
|
let r = Z(e.req.header(X), t);
|
|
2847
|
-
if (!r.ok) return
|
|
2848
|
-
let i =
|
|
3177
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3178
|
+
let i = f(e, "admin", !0);
|
|
2849
3179
|
if (i) return i;
|
|
2850
3180
|
let a = (e.req.query("group_id") ?? "").trim();
|
|
2851
3181
|
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
@@ -2855,23 +3185,23 @@ function mn(e) {
|
|
|
2855
3185
|
} finally {
|
|
2856
3186
|
await o.close();
|
|
2857
3187
|
}
|
|
2858
|
-
}),
|
|
2859
|
-
let r = await
|
|
3188
|
+
}), u.post("/v1/join", async (e) => {
|
|
3189
|
+
let r = await p(e);
|
|
2860
3190
|
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
2861
|
-
let i =
|
|
3191
|
+
let i = m(r);
|
|
2862
3192
|
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(),
|
|
3193
|
+
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
3194
|
if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
|
|
2865
|
-
if (
|
|
3195
|
+
if (ot(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
2866
3196
|
let g = n();
|
|
2867
3197
|
try {
|
|
2868
3198
|
let n = await g.getInviteByTokenForInspection(a);
|
|
2869
3199
|
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([
|
|
3200
|
+
let r = !!(n.operation_id || n.reviewed_project_set_digest), p = n.invite_kind === "team_member" || n.invite_kind === "add_device";
|
|
3201
|
+
if (n.revoked_at) return e.json({ error: r || p ? "invite_invalid" : "revoked_token" }, 400);
|
|
3202
|
+
if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || p ? "invite_expired" : "expired_token" }, 410);
|
|
3203
|
+
if (p) {
|
|
3204
|
+
let r = /* @__PURE__ */ new Set([
|
|
2875
3205
|
"token",
|
|
2876
3206
|
"invite_kind",
|
|
2877
3207
|
"kind",
|
|
@@ -2890,11 +3220,11 @@ function mn(e) {
|
|
|
2890
3220
|
try {
|
|
2891
3221
|
if (i.recipient_display_name != null) {
|
|
2892
3222
|
if (typeof i.recipient_display_name != "string") throw Error("recipient_display_name_invalid");
|
|
2893
|
-
d =
|
|
3223
|
+
d = I(i.recipient_display_name, "recipient_display_name");
|
|
2894
3224
|
}
|
|
2895
3225
|
if (i.device_display_name != null) {
|
|
2896
3226
|
if (typeof i.device_display_name != "string") throw Error("device_display_name_invalid");
|
|
2897
|
-
f =
|
|
3227
|
+
f = I(i.device_display_name, "device_display_name");
|
|
2898
3228
|
}
|
|
2899
3229
|
} catch (t) {
|
|
2900
3230
|
return e.json({ error: t instanceof Error ? t.message : "recipient_invite_identity_invalid" }, 400);
|
|
@@ -2932,7 +3262,7 @@ function mn(e) {
|
|
|
2932
3262
|
}
|
|
2933
3263
|
}
|
|
2934
3264
|
if (n.operation_id || n.reviewed_project_set_digest) {
|
|
2935
|
-
let r = new Set([
|
|
3265
|
+
let r = /* @__PURE__ */ new Set([
|
|
2936
3266
|
"token",
|
|
2937
3267
|
"operation_id",
|
|
2938
3268
|
"device_id",
|
|
@@ -2944,18 +3274,18 @@ function mn(e) {
|
|
|
2944
3274
|
"device_display_name"
|
|
2945
3275
|
]);
|
|
2946
3276
|
if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
2947
|
-
if (!u || !d || !f || !
|
|
3277
|
+
if (!u || !d || !f || !h) return e.json({ error: "project_invite_identity_required" }, 400);
|
|
2948
3278
|
if (String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "project_invite_self_acceptance_forbidden" }, 409);
|
|
2949
3279
|
if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
|
|
2950
|
-
let l,
|
|
3280
|
+
let l, p;
|
|
2951
3281
|
try {
|
|
2952
|
-
l =
|
|
3282
|
+
l = I(f, "recipient_display_name"), p = I(h, "device_display_name");
|
|
2953
3283
|
} catch (t) {
|
|
2954
3284
|
return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
|
|
2955
3285
|
}
|
|
2956
|
-
let
|
|
3286
|
+
let m;
|
|
2957
3287
|
try {
|
|
2958
|
-
|
|
3288
|
+
m = ee(n);
|
|
2959
3289
|
} catch {
|
|
2960
3290
|
return e.json({ error: "operation_intent_invalid" }, 409);
|
|
2961
3291
|
}
|
|
@@ -2968,12 +3298,12 @@ function mn(e) {
|
|
|
2968
3298
|
fingerprint: s,
|
|
2969
3299
|
recipientActorId: d,
|
|
2970
3300
|
recipientDisplayName: l,
|
|
2971
|
-
deviceDisplayName:
|
|
3301
|
+
deviceDisplayName: p,
|
|
2972
3302
|
now: t.now()
|
|
2973
3303
|
});
|
|
2974
3304
|
return e.json({
|
|
2975
3305
|
ok: !0,
|
|
2976
|
-
status:
|
|
3306
|
+
status: Cn,
|
|
2977
3307
|
group_id: n.invite.group_id,
|
|
2978
3308
|
operation_id: n.invite.operation_id,
|
|
2979
3309
|
trust_state: n.invite.trust_state,
|
|
@@ -2984,7 +3314,7 @@ function mn(e) {
|
|
|
2984
3314
|
fingerprint: n.seed_enrollment.fingerprint,
|
|
2985
3315
|
display_name: n.seed_enrollment.display_name
|
|
2986
3316
|
} : null,
|
|
2987
|
-
accepted_project_intent:
|
|
3317
|
+
accepted_project_intent: m
|
|
2988
3318
|
});
|
|
2989
3319
|
} catch (t) {
|
|
2990
3320
|
let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
|
|
@@ -2997,9 +3327,9 @@ function mn(e) {
|
|
|
2997
3327
|
"recipient_display_name",
|
|
2998
3328
|
"device_display_name"
|
|
2999
3329
|
].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
|
|
3000
|
-
let
|
|
3001
|
-
if (!
|
|
3002
|
-
if (
|
|
3330
|
+
let m = await g.getGroup(String(n.group_id));
|
|
3331
|
+
if (!m) return e.json({ error: "group_not_found" }, 404);
|
|
3332
|
+
if (m.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
3003
3333
|
let _ = String(n.group_id);
|
|
3004
3334
|
if (await g.getEnrollment(_, o)) return e.json({
|
|
3005
3335
|
ok: !0,
|
|
@@ -3040,25 +3370,25 @@ function mn(e) {
|
|
|
3040
3370
|
} finally {
|
|
3041
3371
|
await g.close();
|
|
3042
3372
|
}
|
|
3043
|
-
}),
|
|
3373
|
+
}), u;
|
|
3044
3374
|
}
|
|
3045
|
-
async function
|
|
3375
|
+
async function pr(e, t, n) {
|
|
3046
3376
|
let r = Z(e.req.header(X), n.runtime);
|
|
3047
3377
|
if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
3048
3378
|
let i = n.rateLimitedResponse(e, "admin", !0);
|
|
3049
3379
|
if (i) return i;
|
|
3050
3380
|
let a = await (async () => {
|
|
3051
3381
|
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
3052
|
-
if (Number.isFinite(t) && t >
|
|
3382
|
+
if (Number.isFinite(t) && t > ir) return null;
|
|
3053
3383
|
let n = e.req.raw.body;
|
|
3054
|
-
if (!n) return new Uint8Array();
|
|
3384
|
+
if (!n) return /* @__PURE__ */ new Uint8Array();
|
|
3055
3385
|
let r = n.getReader(), i = [], a = 0;
|
|
3056
3386
|
try {
|
|
3057
3387
|
for (;;) {
|
|
3058
3388
|
let { done: e, value: t } = await r.read();
|
|
3059
3389
|
if (e) break;
|
|
3060
3390
|
if (t) {
|
|
3061
|
-
if (a += t.byteLength, a >
|
|
3391
|
+
if (a += t.byteLength, a > ir) return await r.cancel(), null;
|
|
3062
3392
|
i.push(t);
|
|
3063
3393
|
}
|
|
3064
3394
|
}
|
|
@@ -3106,6 +3436,6 @@ async function hn(e, t, n) {
|
|
|
3106
3436
|
}
|
|
3107
3437
|
}
|
|
3108
3438
|
//#endregion
|
|
3109
|
-
export {
|
|
3439
|
+
export { T as $, rt as A, De as B, xn as C, r as Ct, nt as D, L as E, n as Et, I as F, xe as G, Oe as H, F as I, Se as J, we as K, Be as L, ze as M, Le as N, tt as O, Re as P, D as Q, Ae as R, Sn as S, g as St, Ve as T, i as Tt, N as U, Te as V, Ce as W, te as X, ie as Y, re as Z, Tn as _, y as _t, tr as a, de as at, bn as b, ee as bt, Jn as c, _e as ct, On as d, h as dt, E as et, Nn as f, o as ft, wn as g, _ as gt, Cn as h, u as ht, nr as i, fe as it, it as j, at as k, Kn as l, he as lt, Un as m, l as mt, rr as n, ae as nt, Wn as o, pe as ot, Hn as p, S as pt, be as q, er as r, me as rt, qn as s, ge as st, fr as t, w as tt, kn as u, v as ut, En as v, b as vt, ot as w, a as wt, yn as x, C as xt, Dn as y, x as yt, ke as z };
|
|
3110
3440
|
|
|
3111
|
-
//# sourceMappingURL=coordinator-api-
|
|
3441
|
+
//# sourceMappingURL=coordinator-api-Dlr65yhR.js.map
|