@codemem/core 0.39.1 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-types.d.ts +35 -1
- package/dist/api-types.d.ts.map +1 -1
- package/dist/attribution-assessment.d.ts +78 -0
- package/dist/attribution-assessment.d.ts.map +1 -0
- package/dist/attribution-diagnostics.d.ts +53 -0
- package/dist/attribution-diagnostics.d.ts.map +1 -0
- package/dist/better-sqlite-coordinator-store.d.ts +6 -2
- package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
- package/dist/coordinator-actions.d.ts +81 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/coordinator-api-DJVH2jw5.js +21107 -0
- package/dist/coordinator-api-DJVH2jw5.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/coordinator-enrollment-reconciler.d.ts +24 -0
- package/dist/coordinator-enrollment-reconciler.d.ts.map +1 -0
- package/dist/coordinator-enrollment-reconciliation-issues.d.ts +34 -0
- package/dist/coordinator-enrollment-reconciliation-issues.d.ts.map +1 -0
- package/dist/coordinator-invites.d.ts +14 -1
- package/dist/coordinator-invites.d.ts.map +1 -1
- package/dist/coordinator-membership-effects.d.ts +31 -0
- package/dist/coordinator-membership-effects.d.ts.map +1 -0
- package/dist/coordinator-runtime.d.ts +14 -0
- package/dist/coordinator-runtime.d.ts.map +1 -1
- package/dist/coordinator-store-contract.d.ts +134 -1
- package/dist/coordinator-store-contract.d.ts.map +1 -1
- package/dist/coordinator-store-test-harness.d.ts +4 -0
- package/dist/coordinator-store-test-harness.d.ts.map +1 -1
- package/dist/coordinator-store.d.ts +1 -1
- package/dist/coordinator-store.d.ts.map +1 -1
- package/dist/d1-coordinator-store.d.ts +6 -2
- package/dist/d1-coordinator-store.d.ts.map +1 -1
- package/dist/db.d.ts +2 -19
- package/dist/db.d.ts.map +1 -1
- package/dist/embeddings.d.ts +2 -0
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/extraction-benchmark-scoring.d.ts +99 -0
- package/dist/extraction-benchmark-scoring.d.ts.map +1 -0
- package/dist/extraction-benchmarks.d.ts +29 -0
- package/dist/extraction-benchmarks.d.ts.map +1 -1
- package/dist/extraction-eval.d.ts +5 -0
- package/dist/extraction-eval.d.ts.map +1 -1
- package/dist/extraction-model-pricing.d.ts +21 -0
- package/dist/extraction-model-pricing.d.ts.map +1 -0
- package/dist/extraction-replay.d.ts +30 -3
- package/dist/extraction-replay.d.ts.map +1 -1
- package/dist/extraction-tier-routing.d.ts.map +1 -1
- package/dist/index.d.ts +65 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10684 -18254
- package/dist/index.js.map +1 -1
- package/dist/ingest-pipeline.d.ts.map +1 -1
- package/dist/ingest-prompts.d.ts +5 -0
- package/dist/ingest-prompts.d.ts.map +1 -1
- package/dist/ingest-xml-parser.d.ts +21 -0
- package/dist/ingest-xml-parser.d.ts.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +528 -213
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/legacy-recipient-policy-projection.d.ts +122 -0
- package/dist/legacy-recipient-policy-projection.d.ts.map +1 -0
- package/dist/maintenance/relink.d.ts +1 -1
- package/dist/maintenance/relink.d.ts.map +1 -1
- package/dist/observer-client.d.ts +15 -6
- package/dist/observer-client.d.ts.map +1 -1
- package/dist/observer-config.d.ts +2 -0
- package/dist/observer-config.d.ts.map +1 -1
- package/dist/outcome-evidence.d.ts +193 -0
- package/dist/outcome-evidence.d.ts.map +1 -0
- package/dist/pack.d.ts +8 -0
- package/dist/pack.d.ts.map +1 -1
- package/dist/project-invite-acceptance.d.ts +10 -0
- package/dist/project-invite-acceptance.d.ts.map +1 -0
- package/dist/project-invite-identity.d.ts +14 -0
- package/dist/project-invite-identity.d.ts.map +1 -0
- package/dist/project-scope-settings.d.ts.map +1 -1
- package/dist/prompt-pack-ledger.d.ts +21 -0
- package/dist/prompt-pack-ledger.d.ts.map +1 -0
- package/dist/raw-event-flush.d.ts.map +1 -1
- package/dist/recipient-policy-contract.d.ts +153 -0
- package/dist/recipient-policy-contract.d.ts.map +1 -0
- package/dist/recipient-policy-edges.d.ts +85 -0
- package/dist/recipient-policy-edges.d.ts.map +1 -0
- package/dist/recipient-policy-intent.d.ts +12 -0
- package/dist/recipient-policy-intent.d.ts.map +1 -0
- package/dist/recipient-policy-migration.d.ts +22 -0
- package/dist/recipient-policy-migration.d.ts.map +1 -0
- package/dist/recipient-policy-onboarding.d.ts +111 -0
- package/dist/recipient-policy-onboarding.d.ts.map +1 -0
- package/dist/recipient-policy-reconciler.d.ts +83 -0
- package/dist/recipient-policy-reconciler.d.ts.map +1 -0
- package/dist/recipient-policy-reconciliation.d.ts +221 -0
- package/dist/recipient-policy-reconciliation.d.ts.map +1 -0
- package/dist/recipient-policy-review.d.ts +47 -0
- package/dist/recipient-policy-review.d.ts.map +1 -0
- package/dist/recipient-reviewed-intent.d.ts +63 -0
- package/dist/recipient-reviewed-intent.d.ts.map +1 -0
- package/dist/retrieval-ledger.d.ts +216 -0
- package/dist/retrieval-ledger.d.ts.map +1 -0
- package/dist/retrieval-surface-ledger.d.ts +17 -0
- package/dist/retrieval-surface-ledger.d.ts.map +1 -0
- package/dist/schema-bootstrap.d.ts +2 -0
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +11830 -3158
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-membership-cache.d.ts +1 -1
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/share-operation-lifecycle.d.ts +46 -0
- package/dist/share-operation-lifecycle.d.ts.map +1 -0
- package/dist/share-operation.d.ts +87 -0
- package/dist/share-operation.d.ts.map +1 -0
- package/dist/share-provisioning.d.ts +57 -0
- package/dist/share-provisioning.d.ts.map +1 -0
- package/dist/store.d.ts +9 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-bootstrap.d.ts +3 -2
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-capability.d.ts +7 -0
- package/dist/sync-capability.d.ts.map +1 -1
- package/dist/sync-daemon.d.ts +14 -1
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +1 -0
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts +24 -0
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-scope-protocol.d.ts.map +1 -1
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/coordinator-api-hZ1RVJUN.js +0 -2111
- package/dist/coordinator-api-hZ1RVJUN.js.map +0 -1
|
@@ -1,2111 +0,0 @@
|
|
|
1
|
-
import { createHash as e } from "node:crypto";
|
|
2
|
-
//#region src/coordinator-store-contract.ts
|
|
3
|
-
function t(e) {
|
|
4
|
-
let t = e.trim(), n = new Date(t);
|
|
5
|
-
if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
|
|
6
|
-
return n.toISOString();
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/compose.js
|
|
10
|
-
var n = (e, t, n) => (r, i) => {
|
|
11
|
-
let a = -1;
|
|
12
|
-
return o(0);
|
|
13
|
-
async function o(s) {
|
|
14
|
-
if (s <= a) throw Error("next() called multiple times");
|
|
15
|
-
a = s;
|
|
16
|
-
let c, l = !1, u;
|
|
17
|
-
if (e[s] ? (u = e[s][0][0], r.req.routeIndex = s) : u = s === e.length && i || void 0, u) try {
|
|
18
|
-
c = await u(r, () => o(s + 1));
|
|
19
|
-
} catch (e) {
|
|
20
|
-
if (e instanceof Error && t) r.error = e, c = await t(e, r), l = !0;
|
|
21
|
-
else throw e;
|
|
22
|
-
}
|
|
23
|
-
else r.finalized === !1 && n && (c = await n(r));
|
|
24
|
-
return c && (r.finalized === !1 || l) && (r.res = c), r;
|
|
25
|
-
}
|
|
26
|
-
}, r = /* @__PURE__ */ Symbol(), i = async (e, t = /* @__PURE__ */ Object.create(null)) => {
|
|
27
|
-
let { all: n = !1, dot: r = !1 } = t, i = (e instanceof E ? e.raw.headers : e.headers).get("Content-Type");
|
|
28
|
-
return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ? a(e, {
|
|
29
|
-
all: n,
|
|
30
|
-
dot: r
|
|
31
|
-
}) : {};
|
|
32
|
-
};
|
|
33
|
-
async function a(e, t) {
|
|
34
|
-
let n = await e.formData();
|
|
35
|
-
return n ? o(n, t) : {};
|
|
36
|
-
}
|
|
37
|
-
function o(e, t) {
|
|
38
|
-
let n = /* @__PURE__ */ Object.create(null);
|
|
39
|
-
return e.forEach((e, r) => {
|
|
40
|
-
t.all || r.endsWith("[]") ? s(n, r, e) : n[r] = e;
|
|
41
|
-
}), t.dot && Object.entries(n).forEach(([e, t]) => {
|
|
42
|
-
e.includes(".") && (c(n, e, t), delete n[e]);
|
|
43
|
-
}), n;
|
|
44
|
-
}
|
|
45
|
-
var s = (e, t, n) => {
|
|
46
|
-
e[t] === void 0 ? t.endsWith("[]") ? e[t] = [n] : e[t] = n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
|
|
47
|
-
}, c = (e, t, n) => {
|
|
48
|
-
if (/(?:^|\.)__proto__\./.test(t)) return;
|
|
49
|
-
let r = e, i = t.split(".");
|
|
50
|
-
i.forEach((e, t) => {
|
|
51
|
-
t === i.length - 1 ? r[e] = n : ((!r[e] || typeof r[e] != "object" || Array.isArray(r[e]) || r[e] instanceof File) && (r[e] = /* @__PURE__ */ Object.create(null)), r = r[e]);
|
|
52
|
-
});
|
|
53
|
-
}, l = (e) => {
|
|
54
|
-
let t = e.split("/");
|
|
55
|
-
return t[0] === "" && t.shift(), t;
|
|
56
|
-
}, u = (e) => {
|
|
57
|
-
let { groups: t, path: n } = d(e);
|
|
58
|
-
return f(l(n), t);
|
|
59
|
-
}, d = (e) => {
|
|
60
|
-
let t = [];
|
|
61
|
-
return e = e.replace(/\{[^}]+\}/g, (e, n) => {
|
|
62
|
-
let r = `@${n}`;
|
|
63
|
-
return t.push([r, e]), r;
|
|
64
|
-
}), {
|
|
65
|
-
groups: t,
|
|
66
|
-
path: e
|
|
67
|
-
};
|
|
68
|
-
}, f = (e, t) => {
|
|
69
|
-
for (let n = t.length - 1; n >= 0; n--) {
|
|
70
|
-
let [r] = t[n];
|
|
71
|
-
for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
|
|
72
|
-
e[i] = e[i].replace(r, t[n][1]);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return e;
|
|
77
|
-
}, p = {}, m = (e, t) => {
|
|
78
|
-
if (e === "*") return "*";
|
|
79
|
-
let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
80
|
-
if (n) {
|
|
81
|
-
let r = `${e}#${t}`;
|
|
82
|
-
return p[r] || (n[2] ? p[r] = t && t[0] !== ":" && t[0] !== "*" ? [
|
|
83
|
-
r,
|
|
84
|
-
n[1],
|
|
85
|
-
RegExp(`^${n[2]}(?=/${t})`)
|
|
86
|
-
] : [
|
|
87
|
-
e,
|
|
88
|
-
n[1],
|
|
89
|
-
RegExp(`^${n[2]}$`)
|
|
90
|
-
] : p[r] = [
|
|
91
|
-
e,
|
|
92
|
-
n[1],
|
|
93
|
-
!0
|
|
94
|
-
]), p[r];
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
}, h = (e, t) => {
|
|
98
|
-
try {
|
|
99
|
-
return t(e);
|
|
100
|
-
} catch {
|
|
101
|
-
return e.replace(/(?:%[0-9A-Fa-f]{2})+/g, (e) => {
|
|
102
|
-
try {
|
|
103
|
-
return t(e);
|
|
104
|
-
} catch {
|
|
105
|
-
return e;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}, g = (e) => h(e, decodeURI), _ = (e) => {
|
|
110
|
-
let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
|
|
111
|
-
for (; r < t.length; r++) {
|
|
112
|
-
let e = t.charCodeAt(r);
|
|
113
|
-
if (e === 37) {
|
|
114
|
-
let e = t.indexOf("?", r), i = t.indexOf("#", r), a = e === -1 ? i === -1 ? void 0 : i : i === -1 ? e : Math.min(e, i), o = t.slice(n, a);
|
|
115
|
-
return g(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
|
|
116
|
-
} else if (e === 63 || e === 35) break;
|
|
117
|
-
}
|
|
118
|
-
return t.slice(n, r);
|
|
119
|
-
}, v = (e) => {
|
|
120
|
-
let t = _(e);
|
|
121
|
-
return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
|
|
122
|
-
}, y = (e, t, ...n) => (n.length && (t = y(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), b = (e) => {
|
|
123
|
-
if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
|
|
124
|
-
let t = e.split("/"), n = [], r = "";
|
|
125
|
-
return t.forEach((e) => {
|
|
126
|
-
if (e !== "" && !/\:/.test(e)) r += "/" + e;
|
|
127
|
-
else if (/\:/.test(e)) if (/\?/.test(e)) {
|
|
128
|
-
n.length === 0 && r === "" ? n.push("/") : n.push(r);
|
|
129
|
-
let t = e.replace("?", "");
|
|
130
|
-
r += "/" + t, n.push(r);
|
|
131
|
-
} else r += "/" + e;
|
|
132
|
-
}), n.filter((e, t, n) => n.indexOf(e) === t);
|
|
133
|
-
}, x = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : h(e, w)) : e, S = (e, t, n) => {
|
|
134
|
-
let r;
|
|
135
|
-
if (!n && t && !/[%+]/.test(t)) {
|
|
136
|
-
let n = e.indexOf("?", 8);
|
|
137
|
-
if (n === -1) return;
|
|
138
|
-
for (e.startsWith(t, n + 1) || (n = e.indexOf(`&${t}`, n + 1)); n !== -1;) {
|
|
139
|
-
let r = e.charCodeAt(n + t.length + 1);
|
|
140
|
-
if (r === 61) {
|
|
141
|
-
let r = n + t.length + 2, i = e.indexOf("&", r);
|
|
142
|
-
return x(e.slice(r, i === -1 ? void 0 : i));
|
|
143
|
-
} else if (r == 38 || isNaN(r)) return "";
|
|
144
|
-
n = e.indexOf(`&${t}`, n + 1);
|
|
145
|
-
}
|
|
146
|
-
if (r = /[%+]/.test(e), !r) return;
|
|
147
|
-
}
|
|
148
|
-
let i = {};
|
|
149
|
-
r ??= /[%+]/.test(e);
|
|
150
|
-
let a = e.indexOf("?", 8);
|
|
151
|
-
for (; a !== -1;) {
|
|
152
|
-
let t = e.indexOf("&", a + 1), o = e.indexOf("=", a);
|
|
153
|
-
o > t && t !== -1 && (o = -1);
|
|
154
|
-
let s = e.slice(a + 1, o === -1 ? t === -1 ? void 0 : t : o);
|
|
155
|
-
if (r && (s = x(s)), a = t, s === "") continue;
|
|
156
|
-
let c;
|
|
157
|
-
o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = x(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
|
|
158
|
-
}
|
|
159
|
-
return t ? i[t] : i;
|
|
160
|
-
}, C = S, ee = (e, t) => S(e, t, !0), w = decodeURIComponent, T = (e) => h(e, w), E = class {
|
|
161
|
-
raw;
|
|
162
|
-
#e;
|
|
163
|
-
#t;
|
|
164
|
-
routeIndex = 0;
|
|
165
|
-
path;
|
|
166
|
-
bodyCache = {};
|
|
167
|
-
constructor(e, t = "/", n = [[]]) {
|
|
168
|
-
this.raw = e, this.path = t, this.#t = n, this.#e = {};
|
|
169
|
-
}
|
|
170
|
-
param(e) {
|
|
171
|
-
return e ? this.#n(e) : this.#r();
|
|
172
|
-
}
|
|
173
|
-
#n(e) {
|
|
174
|
-
let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
|
|
175
|
-
return n && /\%/.test(n) ? T(n) : n;
|
|
176
|
-
}
|
|
177
|
-
#r() {
|
|
178
|
-
let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
|
|
179
|
-
for (let n of t) {
|
|
180
|
-
let t = this.#i(this.#t[0][this.routeIndex][1][n]);
|
|
181
|
-
t !== void 0 && (e[n] = /\%/.test(t) ? T(t) : t);
|
|
182
|
-
}
|
|
183
|
-
return e;
|
|
184
|
-
}
|
|
185
|
-
#i(e) {
|
|
186
|
-
return this.#t[1] ? this.#t[1][e] : e;
|
|
187
|
-
}
|
|
188
|
-
query(e) {
|
|
189
|
-
return C(this.url, e);
|
|
190
|
-
}
|
|
191
|
-
queries(e) {
|
|
192
|
-
return ee(this.url, e);
|
|
193
|
-
}
|
|
194
|
-
header(e) {
|
|
195
|
-
if (e) return this.raw.headers.get(e) ?? void 0;
|
|
196
|
-
let t = {};
|
|
197
|
-
return this.raw.headers.forEach((e, n) => {
|
|
198
|
-
t[n] = e;
|
|
199
|
-
}), t;
|
|
200
|
-
}
|
|
201
|
-
async parseBody(e) {
|
|
202
|
-
return i(this, e);
|
|
203
|
-
}
|
|
204
|
-
#a = (e) => {
|
|
205
|
-
let { bodyCache: t, raw: n } = this, r = t[e];
|
|
206
|
-
if (r) return r;
|
|
207
|
-
let i = Object.keys(t)[0];
|
|
208
|
-
return i ? t[i].then((t) => (i === "json" && (t = JSON.stringify(t)), new Response(t)[e]())) : t[e] = n[e]();
|
|
209
|
-
};
|
|
210
|
-
json() {
|
|
211
|
-
return this.#a("text").then((e) => JSON.parse(e));
|
|
212
|
-
}
|
|
213
|
-
text() {
|
|
214
|
-
return this.#a("text");
|
|
215
|
-
}
|
|
216
|
-
arrayBuffer() {
|
|
217
|
-
return this.#a("arrayBuffer");
|
|
218
|
-
}
|
|
219
|
-
bytes() {
|
|
220
|
-
return this.#a("arrayBuffer").then((e) => new Uint8Array(e));
|
|
221
|
-
}
|
|
222
|
-
blob() {
|
|
223
|
-
return this.#a("blob");
|
|
224
|
-
}
|
|
225
|
-
formData() {
|
|
226
|
-
return this.#a("formData");
|
|
227
|
-
}
|
|
228
|
-
addValidatedData(e, t) {
|
|
229
|
-
this.#e[e] = t;
|
|
230
|
-
}
|
|
231
|
-
valid(e) {
|
|
232
|
-
return this.#e[e];
|
|
233
|
-
}
|
|
234
|
-
get url() {
|
|
235
|
-
return this.raw.url;
|
|
236
|
-
}
|
|
237
|
-
get method() {
|
|
238
|
-
return this.raw.method;
|
|
239
|
-
}
|
|
240
|
-
get [r]() {
|
|
241
|
-
return this.#t;
|
|
242
|
-
}
|
|
243
|
-
get matchedRoutes() {
|
|
244
|
-
return this.#t[0].map(([[, e]]) => e);
|
|
245
|
-
}
|
|
246
|
-
get routePath() {
|
|
247
|
-
return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
|
|
248
|
-
}
|
|
249
|
-
}, te = {
|
|
250
|
-
Stringify: 1,
|
|
251
|
-
BeforeStream: 2,
|
|
252
|
-
Stream: 3
|
|
253
|
-
}, ne = (e, t) => {
|
|
254
|
-
let n = new String(e);
|
|
255
|
-
return n.isEscaped = !0, n.callbacks = t, n;
|
|
256
|
-
}, D = async (e, t, n, r, i) => {
|
|
257
|
-
typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
|
|
258
|
-
let a = e.callbacks;
|
|
259
|
-
if (!a?.length) return Promise.resolve(e);
|
|
260
|
-
i ? i[0] += e : i = [e];
|
|
261
|
-
let o = Promise.all(a.map((e) => e({
|
|
262
|
-
phase: t,
|
|
263
|
-
buffer: i,
|
|
264
|
-
context: r
|
|
265
|
-
}))).then((e) => Promise.all(e.filter(Boolean).map((e) => D(e, t, !1, r, i))).then(() => i[0]));
|
|
266
|
-
return n ? ne(await o, a) : o;
|
|
267
|
-
}, re = "text/plain; charset=UTF-8", O = (e, t) => ({
|
|
268
|
-
"Content-Type": e,
|
|
269
|
-
...t
|
|
270
|
-
}), k = (e, t) => new Response(e, t), ie = class {
|
|
271
|
-
#e;
|
|
272
|
-
#t;
|
|
273
|
-
env = {};
|
|
274
|
-
#n;
|
|
275
|
-
finalized = !1;
|
|
276
|
-
error;
|
|
277
|
-
#r;
|
|
278
|
-
#i;
|
|
279
|
-
#a;
|
|
280
|
-
#o;
|
|
281
|
-
#s;
|
|
282
|
-
#c;
|
|
283
|
-
#l;
|
|
284
|
-
#u;
|
|
285
|
-
#d;
|
|
286
|
-
constructor(e, t) {
|
|
287
|
-
this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
|
|
288
|
-
}
|
|
289
|
-
get req() {
|
|
290
|
-
return this.#t ??= new E(this.#e, this.#d, this.#u), this.#t;
|
|
291
|
-
}
|
|
292
|
-
get event() {
|
|
293
|
-
if (this.#i && "respondWith" in this.#i) return this.#i;
|
|
294
|
-
throw Error("This context has no FetchEvent");
|
|
295
|
-
}
|
|
296
|
-
get executionCtx() {
|
|
297
|
-
if (this.#i) return this.#i;
|
|
298
|
-
throw Error("This context has no ExecutionContext");
|
|
299
|
-
}
|
|
300
|
-
get res() {
|
|
301
|
-
return this.#a ||= k(null, { headers: this.#l ??= new Headers() });
|
|
302
|
-
}
|
|
303
|
-
set res(e) {
|
|
304
|
-
if (this.#a && e) {
|
|
305
|
-
e = k(e.body, e);
|
|
306
|
-
for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") if (t === "set-cookie") {
|
|
307
|
-
let t = this.#a.headers.getSetCookie();
|
|
308
|
-
e.headers.delete("set-cookie");
|
|
309
|
-
for (let n of t) e.headers.append("set-cookie", n);
|
|
310
|
-
} else e.headers.set(t, n);
|
|
311
|
-
}
|
|
312
|
-
this.#a = e, this.finalized = !0;
|
|
313
|
-
}
|
|
314
|
-
render = (...e) => (this.#s ??= (e) => this.html(e), this.#s(...e));
|
|
315
|
-
setLayout = (e) => this.#o = e;
|
|
316
|
-
getLayout = () => this.#o;
|
|
317
|
-
setRenderer = (e) => {
|
|
318
|
-
this.#s = e;
|
|
319
|
-
};
|
|
320
|
-
header = (e, t, n) => {
|
|
321
|
-
this.finalized && (this.#a = k(this.#a.body, this.#a));
|
|
322
|
-
let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
|
|
323
|
-
t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
|
|
324
|
-
};
|
|
325
|
-
status = (e) => {
|
|
326
|
-
this.#r = e;
|
|
327
|
-
};
|
|
328
|
-
set = (e, t) => {
|
|
329
|
-
this.#n ??= /* @__PURE__ */ new Map(), this.#n.set(e, t);
|
|
330
|
-
};
|
|
331
|
-
get = (e) => this.#n ? this.#n.get(e) : void 0;
|
|
332
|
-
get var() {
|
|
333
|
-
return this.#n ? Object.fromEntries(this.#n) : {};
|
|
334
|
-
}
|
|
335
|
-
#f(e, t, n) {
|
|
336
|
-
let r = this.#a ? new Headers(this.#a.headers) : this.#l ?? new Headers();
|
|
337
|
-
if (typeof t == "object" && "headers" in t) {
|
|
338
|
-
let e = t.headers instanceof Headers ? t.headers : new Headers(t.headers);
|
|
339
|
-
for (let [t, n] of e) t.toLowerCase() === "set-cookie" ? r.append(t, n) : r.set(t, n);
|
|
340
|
-
}
|
|
341
|
-
if (n) for (let [e, t] of Object.entries(n)) if (typeof t == "string") r.set(e, t);
|
|
342
|
-
else {
|
|
343
|
-
r.delete(e);
|
|
344
|
-
for (let n of t) r.append(e, n);
|
|
345
|
-
}
|
|
346
|
-
return k(e, {
|
|
347
|
-
status: typeof t == "number" ? t : t?.status ?? this.#r,
|
|
348
|
-
headers: r
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
newResponse = (...e) => this.#f(...e);
|
|
352
|
-
body = (e, t, n) => this.#f(e, t, n);
|
|
353
|
-
text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, O(re, n));
|
|
354
|
-
json = (e, t, n) => this.#f(JSON.stringify(e), t, O("application/json", n));
|
|
355
|
-
html = (e, t, n) => {
|
|
356
|
-
let r = (e) => this.#f(e, t, O("text/html; charset=UTF-8", n));
|
|
357
|
-
return typeof e == "object" ? D(e, te.Stringify, !1, {}).then(r) : r(e);
|
|
358
|
-
};
|
|
359
|
-
redirect = (e, t) => {
|
|
360
|
-
let n = String(e);
|
|
361
|
-
return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
|
|
362
|
-
};
|
|
363
|
-
notFound = () => (this.#c ??= () => k(), this.#c(this));
|
|
364
|
-
}, ae = [
|
|
365
|
-
"get",
|
|
366
|
-
"post",
|
|
367
|
-
"put",
|
|
368
|
-
"delete",
|
|
369
|
-
"options",
|
|
370
|
-
"patch"
|
|
371
|
-
], A = "Can not add a route since the matcher is already built.", j = class extends Error {}, oe = "__COMPOSED_HANDLER", se = (e) => e.text("404 Not Found", 404), M = (e, t) => {
|
|
372
|
-
if ("getResponse" in e) {
|
|
373
|
-
let n = e.getResponse();
|
|
374
|
-
return t.newResponse(n.body, n);
|
|
375
|
-
}
|
|
376
|
-
return console.error(e), t.text("Internal Server Error", 500);
|
|
377
|
-
}, ce = class e {
|
|
378
|
-
get;
|
|
379
|
-
post;
|
|
380
|
-
put;
|
|
381
|
-
delete;
|
|
382
|
-
options;
|
|
383
|
-
patch;
|
|
384
|
-
all;
|
|
385
|
-
on;
|
|
386
|
-
use;
|
|
387
|
-
router;
|
|
388
|
-
getPath;
|
|
389
|
-
_basePath = "/";
|
|
390
|
-
#e = "/";
|
|
391
|
-
routes = [];
|
|
392
|
-
constructor(e = {}) {
|
|
393
|
-
[...ae, "all"].forEach((e) => {
|
|
394
|
-
this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
|
|
395
|
-
this.#r(e, this.#e, t);
|
|
396
|
-
}), this);
|
|
397
|
-
}), this.on = (e, t, ...n) => {
|
|
398
|
-
for (let r of [t].flat()) {
|
|
399
|
-
this.#e = r;
|
|
400
|
-
for (let t of [e].flat()) n.map((e) => {
|
|
401
|
-
this.#r(t.toUpperCase(), this.#e, e);
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
return this;
|
|
405
|
-
}, this.use = (e, ...t) => (typeof e == "string" ? this.#e = e : (this.#e = "*", t.unshift(e)), t.forEach((e) => {
|
|
406
|
-
this.#r("ALL", this.#e, e);
|
|
407
|
-
}), this);
|
|
408
|
-
let { strict: t, ...n } = e;
|
|
409
|
-
Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? _ : v;
|
|
410
|
-
}
|
|
411
|
-
#t() {
|
|
412
|
-
let t = new e({
|
|
413
|
-
router: this.router,
|
|
414
|
-
getPath: this.getPath
|
|
415
|
-
});
|
|
416
|
-
return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
|
|
417
|
-
}
|
|
418
|
-
#n = se;
|
|
419
|
-
errorHandler = M;
|
|
420
|
-
route(e, t) {
|
|
421
|
-
let r = this.basePath(e);
|
|
422
|
-
return t.routes.map((e) => {
|
|
423
|
-
let i;
|
|
424
|
-
t.errorHandler === M ? i = e.handler : (i = async (r, i) => (await n([], t.errorHandler)(r, () => e.handler(r, i))).res, i[oe] = e.handler), r.#r(e.method, e.path, i, e.basePath);
|
|
425
|
-
}), this;
|
|
426
|
-
}
|
|
427
|
-
basePath(e) {
|
|
428
|
-
let t = this.#t();
|
|
429
|
-
return t._basePath = y(this._basePath, e), t;
|
|
430
|
-
}
|
|
431
|
-
onError = (e) => (this.errorHandler = e, this);
|
|
432
|
-
notFound = (e) => (this.#n = e, this);
|
|
433
|
-
mount(e, t, n) {
|
|
434
|
-
let r, i;
|
|
435
|
-
n && (typeof n == "function" ? i = n : (i = n.optionHandler, r = n.replaceRequest === !1 ? (e) => e : n.replaceRequest));
|
|
436
|
-
let a = i ? (e) => {
|
|
437
|
-
let t = i(e);
|
|
438
|
-
return Array.isArray(t) ? t : [t];
|
|
439
|
-
} : (e) => {
|
|
440
|
-
let t;
|
|
441
|
-
try {
|
|
442
|
-
t = e.executionCtx;
|
|
443
|
-
} catch {}
|
|
444
|
-
return [e.env, t];
|
|
445
|
-
};
|
|
446
|
-
return r ||= (() => {
|
|
447
|
-
let t = y(this._basePath, e), n = t === "/" ? 0 : t.length;
|
|
448
|
-
return (e) => {
|
|
449
|
-
let t = new URL(e.url);
|
|
450
|
-
return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
|
|
451
|
-
};
|
|
452
|
-
})(), this.#r("ALL", y(e, "*"), async (e, n) => {
|
|
453
|
-
let i = await t(r(e.req.raw), ...a(e));
|
|
454
|
-
if (i) return i;
|
|
455
|
-
await n();
|
|
456
|
-
}), this;
|
|
457
|
-
}
|
|
458
|
-
#r(e, t, n, r) {
|
|
459
|
-
e = e.toUpperCase(), t = y(this._basePath, t);
|
|
460
|
-
let i = {
|
|
461
|
-
basePath: r === void 0 ? this._basePath : y(this._basePath, r),
|
|
462
|
-
path: t,
|
|
463
|
-
method: e,
|
|
464
|
-
handler: n
|
|
465
|
-
};
|
|
466
|
-
this.router.add(e, t, [n, i]), this.routes.push(i);
|
|
467
|
-
}
|
|
468
|
-
#i(e, t) {
|
|
469
|
-
if (e instanceof Error) return this.errorHandler(e, t);
|
|
470
|
-
throw e;
|
|
471
|
-
}
|
|
472
|
-
#a(e, t, r, i) {
|
|
473
|
-
if (i === "HEAD") return (async () => new Response(null, await this.#a(e, t, r, "GET")))();
|
|
474
|
-
let a = this.getPath(e, { env: r }), o = this.router.match(i, a), s = new ie(e, {
|
|
475
|
-
path: a,
|
|
476
|
-
matchResult: o,
|
|
477
|
-
env: r,
|
|
478
|
-
executionCtx: t,
|
|
479
|
-
notFoundHandler: this.#n
|
|
480
|
-
});
|
|
481
|
-
if (o[0].length === 1) {
|
|
482
|
-
let e;
|
|
483
|
-
try {
|
|
484
|
-
e = o[0][0][0][0](s, async () => {
|
|
485
|
-
s.res = await this.#n(s);
|
|
486
|
-
});
|
|
487
|
-
} catch (e) {
|
|
488
|
-
return this.#i(e, s);
|
|
489
|
-
}
|
|
490
|
-
return e instanceof Promise ? e.then((e) => e || (s.finalized ? s.res : this.#n(s))).catch((e) => this.#i(e, s)) : e ?? this.#n(s);
|
|
491
|
-
}
|
|
492
|
-
let c = n(o[0], this.errorHandler, this.#n);
|
|
493
|
-
return (async () => {
|
|
494
|
-
try {
|
|
495
|
-
let e = await c(s);
|
|
496
|
-
if (!e.finalized) throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
497
|
-
return e.res;
|
|
498
|
-
} catch (e) {
|
|
499
|
-
return this.#i(e, s);
|
|
500
|
-
}
|
|
501
|
-
})();
|
|
502
|
-
}
|
|
503
|
-
fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
|
|
504
|
-
request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${y("/", e)}`, t), n, r));
|
|
505
|
-
fire = () => {
|
|
506
|
-
addEventListener("fetch", (e) => {
|
|
507
|
-
e.respondWith(this.#a(e.request, e, void 0, e.request.method));
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
}, N = [];
|
|
511
|
-
function le(e, t) {
|
|
512
|
-
let n = this.buildAllMatchers(), r = ((e, t) => {
|
|
513
|
-
let r = n[e] || n.ALL, i = r[2][t];
|
|
514
|
-
if (i) return i;
|
|
515
|
-
let a = t.match(r[0]);
|
|
516
|
-
if (!a) return [[], N];
|
|
517
|
-
let o = a.indexOf("", 1);
|
|
518
|
-
return [r[1][o], a];
|
|
519
|
-
});
|
|
520
|
-
return this.match = r, r(e, t);
|
|
521
|
-
}
|
|
522
|
-
//#endregion
|
|
523
|
-
//#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
524
|
-
var P = "[^/]+", F = ".*", I = "(?:|/.*)", L = /* @__PURE__ */ Symbol(), ue = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
525
|
-
function de(e, t) {
|
|
526
|
-
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === F || e === I ? 1 : t === F || t === I ? -1 : e === P ? 1 : t === P ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
|
|
527
|
-
}
|
|
528
|
-
var fe = class e {
|
|
529
|
-
#e;
|
|
530
|
-
#t;
|
|
531
|
-
#n = /* @__PURE__ */ Object.create(null);
|
|
532
|
-
insert(t, n, r, i, a) {
|
|
533
|
-
if (t.length === 0) {
|
|
534
|
-
if (this.#e !== void 0) throw L;
|
|
535
|
-
if (a) return;
|
|
536
|
-
this.#e = n;
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
|
|
540
|
-
"",
|
|
541
|
-
"",
|
|
542
|
-
F
|
|
543
|
-
] : [
|
|
544
|
-
"",
|
|
545
|
-
"",
|
|
546
|
-
P
|
|
547
|
-
] : o === "/*" ? [
|
|
548
|
-
"",
|
|
549
|
-
"",
|
|
550
|
-
I
|
|
551
|
-
] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
|
|
552
|
-
if (c) {
|
|
553
|
-
let t = c[1], n = c[2] || P;
|
|
554
|
-
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw L;
|
|
555
|
-
if (l = this.#n[n], !l) {
|
|
556
|
-
if (Object.keys(this.#n).some((e) => e !== F && e !== I)) throw L;
|
|
557
|
-
if (a) return;
|
|
558
|
-
l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
|
|
559
|
-
}
|
|
560
|
-
!a && t !== "" && r.push([t, l.#t]);
|
|
561
|
-
} else if (l = this.#n[o], !l) {
|
|
562
|
-
if (Object.keys(this.#n).some((e) => e.length > 1 && e !== F && e !== I)) throw L;
|
|
563
|
-
if (a) return;
|
|
564
|
-
l = this.#n[o] = new e();
|
|
565
|
-
}
|
|
566
|
-
l.insert(s, n, r, i, a);
|
|
567
|
-
}
|
|
568
|
-
buildRegExpStr() {
|
|
569
|
-
let e = Object.keys(this.#n).sort(de).map((e) => {
|
|
570
|
-
let t = this.#n[e];
|
|
571
|
-
return (typeof t.#t == "number" ? `(${e})@${t.#t}` : ue.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
|
|
572
|
-
});
|
|
573
|
-
return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
|
|
574
|
-
}
|
|
575
|
-
}, pe = class {
|
|
576
|
-
#e = { varIndex: 0 };
|
|
577
|
-
#t = new fe();
|
|
578
|
-
insert(e, t, n) {
|
|
579
|
-
let r = [], i = [];
|
|
580
|
-
for (let t = 0;;) {
|
|
581
|
-
let n = !1;
|
|
582
|
-
if (e = e.replace(/\{[^}]+\}/g, (e) => {
|
|
583
|
-
let r = `@\\${t}`;
|
|
584
|
-
return i[t] = [r, e], t++, n = !0, r;
|
|
585
|
-
}), !n) break;
|
|
586
|
-
}
|
|
587
|
-
let a = e.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
588
|
-
for (let e = i.length - 1; e >= 0; e--) {
|
|
589
|
-
let [t] = i[e];
|
|
590
|
-
for (let n = a.length - 1; n >= 0; n--) if (a[n].indexOf(t) !== -1) {
|
|
591
|
-
a[n] = a[n].replace(t, i[e][1]);
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return this.#t.insert(a, t, r, this.#e, n), r;
|
|
596
|
-
}
|
|
597
|
-
buildRegExp() {
|
|
598
|
-
let e = this.#t.buildRegExpStr();
|
|
599
|
-
if (e === "") return [
|
|
600
|
-
/^$/,
|
|
601
|
-
[],
|
|
602
|
-
[]
|
|
603
|
-
];
|
|
604
|
-
let t = 0, n = [], r = [];
|
|
605
|
-
return e = e.replace(/#(\d+)|@(\d+)|\.\*\$/g, (e, i, a) => i === void 0 ? (a === void 0 || (r[Number(a)] = ++t), "") : (n[++t] = Number(i), "$()")), [
|
|
606
|
-
RegExp(`^${e}`),
|
|
607
|
-
n,
|
|
608
|
-
r
|
|
609
|
-
];
|
|
610
|
-
}
|
|
611
|
-
}, me = [
|
|
612
|
-
/^$/,
|
|
613
|
-
[],
|
|
614
|
-
/* @__PURE__ */ Object.create(null)
|
|
615
|
-
], R = /* @__PURE__ */ Object.create(null);
|
|
616
|
-
function z(e) {
|
|
617
|
-
return R[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
|
|
618
|
-
}
|
|
619
|
-
function he() {
|
|
620
|
-
R = /* @__PURE__ */ Object.create(null);
|
|
621
|
-
}
|
|
622
|
-
function ge(e) {
|
|
623
|
-
let t = new pe(), n = [];
|
|
624
|
-
if (e.length === 0) return me;
|
|
625
|
-
let r = e.map((e) => [!/\*|\/:/.test(e[0]), ...e]).sort(([e, t], [n, r]) => e ? 1 : n ? -1 : t.length - r.length), i = /* @__PURE__ */ Object.create(null);
|
|
626
|
-
for (let e = 0, a = -1, o = r.length; e < o; e++) {
|
|
627
|
-
let [o, s, c] = r[e];
|
|
628
|
-
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), N] : a++;
|
|
629
|
-
let l;
|
|
630
|
-
try {
|
|
631
|
-
l = t.insert(s, a, o);
|
|
632
|
-
} catch (e) {
|
|
633
|
-
throw e === L ? new j(s) : e;
|
|
634
|
-
}
|
|
635
|
-
o || (n[a] = c.map(([e, t]) => {
|
|
636
|
-
let n = /* @__PURE__ */ Object.create(null);
|
|
637
|
-
for (--t; t >= 0; t--) {
|
|
638
|
-
let [e, r] = l[t];
|
|
639
|
-
n[e] = r;
|
|
640
|
-
}
|
|
641
|
-
return [e, n];
|
|
642
|
-
}));
|
|
643
|
-
}
|
|
644
|
-
let [a, o, s] = t.buildRegExp();
|
|
645
|
-
for (let e = 0, t = n.length; e < t; e++) for (let t = 0, r = n[e].length; t < r; t++) {
|
|
646
|
-
let r = n[e][t]?.[1];
|
|
647
|
-
if (!r) continue;
|
|
648
|
-
let i = Object.keys(r);
|
|
649
|
-
for (let e = 0, t = i.length; e < t; e++) r[i[e]] = s[r[i[e]]];
|
|
650
|
-
}
|
|
651
|
-
let c = [];
|
|
652
|
-
for (let e in o) c[e] = n[o[e]];
|
|
653
|
-
return [
|
|
654
|
-
a,
|
|
655
|
-
c,
|
|
656
|
-
i
|
|
657
|
-
];
|
|
658
|
-
}
|
|
659
|
-
function B(e, t) {
|
|
660
|
-
if (e) {
|
|
661
|
-
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (z(n).test(t)) return [...e[n]];
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
var _e = class {
|
|
665
|
-
name = "RegExpRouter";
|
|
666
|
-
#e;
|
|
667
|
-
#t;
|
|
668
|
-
constructor() {
|
|
669
|
-
this.#e = { ALL: /* @__PURE__ */ Object.create(null) }, this.#t = { ALL: /* @__PURE__ */ Object.create(null) };
|
|
670
|
-
}
|
|
671
|
-
add(e, t, n) {
|
|
672
|
-
let r = this.#e, i = this.#t;
|
|
673
|
-
if (!r || !i) throw Error(A);
|
|
674
|
-
r[e] || [r, i].forEach((t) => {
|
|
675
|
-
t[e] = /* @__PURE__ */ Object.create(null), Object.keys(t.ALL).forEach((n) => {
|
|
676
|
-
t[e][n] = [...t.ALL[n]];
|
|
677
|
-
});
|
|
678
|
-
}), t === "/*" && (t = "*");
|
|
679
|
-
let a = (t.match(/\/:/g) || []).length;
|
|
680
|
-
if (/\*$/.test(t)) {
|
|
681
|
-
let o = z(t);
|
|
682
|
-
e === "ALL" ? Object.keys(r).forEach((e) => {
|
|
683
|
-
r[e][t] ||= B(r[e], t) || B(r.ALL, t) || [];
|
|
684
|
-
}) : r[e][t] ||= B(r[e], t) || B(r.ALL, t) || [], Object.keys(r).forEach((t) => {
|
|
685
|
-
(e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
|
|
686
|
-
o.test(e) && r[t][e].push([n, a]);
|
|
687
|
-
});
|
|
688
|
-
}), Object.keys(i).forEach((t) => {
|
|
689
|
-
(e === "ALL" || e === t) && Object.keys(i[t]).forEach((e) => o.test(e) && i[t][e].push([n, a]));
|
|
690
|
-
});
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
let o = b(t) || [t];
|
|
694
|
-
for (let t = 0, s = o.length; t < s; t++) {
|
|
695
|
-
let c = o[t];
|
|
696
|
-
Object.keys(i).forEach((o) => {
|
|
697
|
-
(e === "ALL" || e === o) && (i[o][c] ||= [...B(r[o], c) || B(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
match = le;
|
|
702
|
-
buildAllMatchers() {
|
|
703
|
-
let e = /* @__PURE__ */ Object.create(null);
|
|
704
|
-
return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
|
|
705
|
-
e[t] ||= this.#n(t);
|
|
706
|
-
}), this.#e = this.#t = void 0, he(), e;
|
|
707
|
-
}
|
|
708
|
-
#n(e) {
|
|
709
|
-
let t = [], n = e === "ALL";
|
|
710
|
-
return [this.#e, this.#t].forEach((r) => {
|
|
711
|
-
let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
|
|
712
|
-
i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
|
|
713
|
-
}), n ? ge(t) : null;
|
|
714
|
-
}
|
|
715
|
-
}, ve = class {
|
|
716
|
-
name = "SmartRouter";
|
|
717
|
-
#e = [];
|
|
718
|
-
#t = [];
|
|
719
|
-
constructor(e) {
|
|
720
|
-
this.#e = e.routers;
|
|
721
|
-
}
|
|
722
|
-
add(e, t, n) {
|
|
723
|
-
if (!this.#t) throw Error(A);
|
|
724
|
-
this.#t.push([
|
|
725
|
-
e,
|
|
726
|
-
t,
|
|
727
|
-
n
|
|
728
|
-
]);
|
|
729
|
-
}
|
|
730
|
-
match(e, t) {
|
|
731
|
-
if (!this.#t) throw Error("Fatal error");
|
|
732
|
-
let n = this.#e, r = this.#t, i = n.length, a = 0, o;
|
|
733
|
-
for (; a < i; a++) {
|
|
734
|
-
let i = n[a];
|
|
735
|
-
try {
|
|
736
|
-
for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
|
|
737
|
-
o = i.match(e, t);
|
|
738
|
-
} catch (e) {
|
|
739
|
-
if (e instanceof j) continue;
|
|
740
|
-
throw e;
|
|
741
|
-
}
|
|
742
|
-
this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
if (a === i) throw Error("Fatal error");
|
|
746
|
-
return this.name = `SmartRouter + ${this.activeRouter.name}`, o;
|
|
747
|
-
}
|
|
748
|
-
get activeRouter() {
|
|
749
|
-
if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
|
|
750
|
-
return this.#e[0];
|
|
751
|
-
}
|
|
752
|
-
}, V = /* @__PURE__ */ Object.create(null), ye = (e) => {
|
|
753
|
-
for (let t in e) return !0;
|
|
754
|
-
return !1;
|
|
755
|
-
}, be = class e {
|
|
756
|
-
#e;
|
|
757
|
-
#t;
|
|
758
|
-
#n;
|
|
759
|
-
#r = 0;
|
|
760
|
-
#i = V;
|
|
761
|
-
constructor(e, t, n) {
|
|
762
|
-
if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
|
|
763
|
-
let n = /* @__PURE__ */ Object.create(null);
|
|
764
|
-
n[e] = {
|
|
765
|
-
handler: t,
|
|
766
|
-
possibleKeys: [],
|
|
767
|
-
score: 0
|
|
768
|
-
}, this.#e = [n];
|
|
769
|
-
}
|
|
770
|
-
this.#n = [];
|
|
771
|
-
}
|
|
772
|
-
insert(t, n, r) {
|
|
773
|
-
this.#r = ++this.#r;
|
|
774
|
-
let i = this, a = u(n), o = [];
|
|
775
|
-
for (let t = 0, n = a.length; t < n; t++) {
|
|
776
|
-
let n = a[t], r = a[t + 1], s = m(n, r), c = Array.isArray(s) ? s[0] : n;
|
|
777
|
-
if (c in i.#t) {
|
|
778
|
-
i = i.#t[c], s && o.push(s[1]);
|
|
779
|
-
continue;
|
|
780
|
-
}
|
|
781
|
-
i.#t[c] = new e(), s && (i.#n.push(s), o.push(s[1])), i = i.#t[c];
|
|
782
|
-
}
|
|
783
|
-
return i.#e.push({ [t]: {
|
|
784
|
-
handler: r,
|
|
785
|
-
possibleKeys: o.filter((e, t, n) => n.indexOf(e) === t),
|
|
786
|
-
score: this.#r
|
|
787
|
-
} }), i;
|
|
788
|
-
}
|
|
789
|
-
#a(e, t, n, r, i) {
|
|
790
|
-
for (let a = 0, o = t.#e.length; a < o; a++) {
|
|
791
|
-
let o = t.#e[a], s = o[n] || o.ALL, c = {};
|
|
792
|
-
if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== V || i && i !== V)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
|
|
793
|
-
let t = s.possibleKeys[e], n = c[s.score];
|
|
794
|
-
s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
search(e, t) {
|
|
799
|
-
let n = [];
|
|
800
|
-
this.#i = V;
|
|
801
|
-
let r = [this], i = l(t), a = [], o = i.length, s = null;
|
|
802
|
-
for (let c = 0; c < o; c++) {
|
|
803
|
-
let l = i[c], u = c === o - 1, d = [];
|
|
804
|
-
for (let f = 0, p = r.length; f < p; f++) {
|
|
805
|
-
let p = r[f], m = p.#t[l];
|
|
806
|
-
m && (m.#i = p.#i, u ? (m.#t["*"] && this.#a(n, m.#t["*"], e, p.#i), this.#a(n, m, e, p.#i)) : d.push(m));
|
|
807
|
-
for (let r = 0, f = p.#n.length; r < f; r++) {
|
|
808
|
-
let f = p.#n[r], m = p.#i === V ? {} : { ...p.#i };
|
|
809
|
-
if (f === "*") {
|
|
810
|
-
let t = p.#t["*"];
|
|
811
|
-
t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
|
|
812
|
-
continue;
|
|
813
|
-
}
|
|
814
|
-
let [h, g, _] = f;
|
|
815
|
-
if (!l && !(_ instanceof RegExp)) continue;
|
|
816
|
-
let v = p.#t[h];
|
|
817
|
-
if (_ instanceof RegExp) {
|
|
818
|
-
if (s === null) {
|
|
819
|
-
s = Array(o);
|
|
820
|
-
let e = +(t[0] === "/");
|
|
821
|
-
for (let t = 0; t < o; t++) s[t] = e, e += i[t].length + 1;
|
|
822
|
-
}
|
|
823
|
-
let r = t.substring(s[c]), l = _.exec(r);
|
|
824
|
-
if (l) {
|
|
825
|
-
if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ye(v.#t)) {
|
|
826
|
-
v.#i = m;
|
|
827
|
-
let e = l[0].match(/\//)?.length ?? 0;
|
|
828
|
-
(a[e] ||= []).push(v);
|
|
829
|
-
}
|
|
830
|
-
continue;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
(_ === !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)));
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
let f = a.shift();
|
|
837
|
-
r = f ? d.concat(f) : d;
|
|
838
|
-
}
|
|
839
|
-
return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
|
|
840
|
-
}
|
|
841
|
-
}, xe = class {
|
|
842
|
-
name = "TrieRouter";
|
|
843
|
-
#e;
|
|
844
|
-
constructor() {
|
|
845
|
-
this.#e = new be();
|
|
846
|
-
}
|
|
847
|
-
add(e, t, n) {
|
|
848
|
-
let r = b(t);
|
|
849
|
-
if (r) {
|
|
850
|
-
for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
this.#e.insert(e, t, n);
|
|
854
|
-
}
|
|
855
|
-
match(e, t) {
|
|
856
|
-
return this.#e.search(e, t);
|
|
857
|
-
}
|
|
858
|
-
}, Se = class extends ce {
|
|
859
|
-
constructor(e = {}) {
|
|
860
|
-
super(e), this.router = e.router ?? new ve({ routers: [new _e(), new xe()] });
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
//#endregion
|
|
864
|
-
//#region src/coordinator-invites.ts
|
|
865
|
-
function Ce(e) {
|
|
866
|
-
let t = "";
|
|
867
|
-
for (let n of e) t += String.fromCharCode(n);
|
|
868
|
-
return btoa(t);
|
|
869
|
-
}
|
|
870
|
-
function we(e) {
|
|
871
|
-
let t = atob(e), n = new Uint8Array(t.length);
|
|
872
|
-
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
873
|
-
return n;
|
|
874
|
-
}
|
|
875
|
-
function Te(e) {
|
|
876
|
-
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
877
|
-
}
|
|
878
|
-
function Ee(e) {
|
|
879
|
-
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
880
|
-
return t + "=".repeat((4 - t.length % 4) % 4);
|
|
881
|
-
}
|
|
882
|
-
function H(e) {
|
|
883
|
-
let t = JSON.stringify(e);
|
|
884
|
-
return Te(Ce(new TextEncoder().encode(t)));
|
|
885
|
-
}
|
|
886
|
-
function De(e) {
|
|
887
|
-
let t = new TextDecoder().decode(we(Ee(e))), n = JSON.parse(t);
|
|
888
|
-
if (typeof n != "object" || !n) throw Error("invalid invite payload");
|
|
889
|
-
return n;
|
|
890
|
-
}
|
|
891
|
-
function U(e) {
|
|
892
|
-
return `codemem://join?invite=${encodeURIComponent(e)}`;
|
|
893
|
-
}
|
|
894
|
-
function Oe(e) {
|
|
895
|
-
let t = e.trim();
|
|
896
|
-
if (t.startsWith("codemem://")) {
|
|
897
|
-
let e = new URL(t).searchParams.get("invite") ?? "";
|
|
898
|
-
if (!e) throw Error("invite payload missing from link");
|
|
899
|
-
return e;
|
|
900
|
-
}
|
|
901
|
-
return t;
|
|
902
|
-
}
|
|
903
|
-
//#endregion
|
|
904
|
-
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
|
|
905
|
-
function ke(e) {
|
|
906
|
-
let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
|
|
907
|
-
return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
|
|
908
|
-
}
|
|
909
|
-
function W() {
|
|
910
|
-
let [e, t] = ke();
|
|
911
|
-
return e * 1e3 + Math.floor(t / 1e6);
|
|
912
|
-
}
|
|
913
|
-
function G(e) {
|
|
914
|
-
return new Promise((t) => setTimeout(t, e));
|
|
915
|
-
}
|
|
916
|
-
//#endregion
|
|
917
|
-
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
|
|
918
|
-
var Ae = class {
|
|
919
|
-
bucketSize;
|
|
920
|
-
tokensPerInterval;
|
|
921
|
-
interval;
|
|
922
|
-
parentBucket;
|
|
923
|
-
content;
|
|
924
|
-
lastDrip;
|
|
925
|
-
constructor({ bucketSize: e, tokensPerInterval: t, interval: n, parentBucket: r }) {
|
|
926
|
-
if (this.bucketSize = e, this.tokensPerInterval = t, typeof n == "string") switch (n) {
|
|
927
|
-
case "sec":
|
|
928
|
-
case "second":
|
|
929
|
-
this.interval = 1e3;
|
|
930
|
-
break;
|
|
931
|
-
case "min":
|
|
932
|
-
case "minute":
|
|
933
|
-
this.interval = 1e3 * 60;
|
|
934
|
-
break;
|
|
935
|
-
case "hr":
|
|
936
|
-
case "hour":
|
|
937
|
-
this.interval = 1e3 * 60 * 60;
|
|
938
|
-
break;
|
|
939
|
-
case "day":
|
|
940
|
-
this.interval = 1e3 * 60 * 60 * 24;
|
|
941
|
-
break;
|
|
942
|
-
default: throw Error("Invalid interval " + n);
|
|
943
|
-
}
|
|
944
|
-
else this.interval = n;
|
|
945
|
-
this.parentBucket = r, this.content = 0, this.lastDrip = W();
|
|
946
|
-
}
|
|
947
|
-
async removeTokens(e) {
|
|
948
|
-
if (this.bucketSize === 0) return Infinity;
|
|
949
|
-
if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
|
|
950
|
-
this.drip();
|
|
951
|
-
let t = async () => (await G(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
|
|
952
|
-
if (e > this.content) return t();
|
|
953
|
-
if (this.parentBucket != null) {
|
|
954
|
-
let n = await this.parentBucket.removeTokens(e);
|
|
955
|
-
return e > this.content ? t() : (this.content -= e, Math.min(n, this.content));
|
|
956
|
-
} else return this.content -= e, this.content;
|
|
957
|
-
}
|
|
958
|
-
tryRemoveTokens(e) {
|
|
959
|
-
return this.bucketSize ? e > this.bucketSize || (this.drip(), e > this.content) || this.parentBucket && !this.parentBucket.tryRemoveTokens(e) ? !1 : (this.content -= e, !0) : !0;
|
|
960
|
-
}
|
|
961
|
-
drip() {
|
|
962
|
-
if (this.tokensPerInterval === 0) {
|
|
963
|
-
let e = this.content;
|
|
964
|
-
return this.content = this.bucketSize, this.content > e;
|
|
965
|
-
}
|
|
966
|
-
let e = W(), t = Math.max(e - this.lastDrip, 0);
|
|
967
|
-
this.lastDrip = e;
|
|
968
|
-
let n = t * (this.tokensPerInterval / this.interval), r = this.content;
|
|
969
|
-
return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
|
|
970
|
-
}
|
|
971
|
-
}, je = class {
|
|
972
|
-
tokenBucket;
|
|
973
|
-
curIntervalStart;
|
|
974
|
-
tokensThisInterval;
|
|
975
|
-
fireImmediately;
|
|
976
|
-
constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
|
|
977
|
-
this.tokenBucket = new Ae({
|
|
978
|
-
bucketSize: e,
|
|
979
|
-
tokensPerInterval: e,
|
|
980
|
-
interval: t
|
|
981
|
-
}), this.tokenBucket.content = e, this.curIntervalStart = W(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
|
|
982
|
-
}
|
|
983
|
-
async removeTokens(e) {
|
|
984
|
-
if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
|
|
985
|
-
let t = W();
|
|
986
|
-
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
|
|
987
|
-
if (this.fireImmediately) return -1;
|
|
988
|
-
{
|
|
989
|
-
await G(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
|
|
990
|
-
let n = await this.tokenBucket.removeTokens(e);
|
|
991
|
-
return this.tokensThisInterval += e, n;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
let n = await this.tokenBucket.removeTokens(e);
|
|
995
|
-
return this.tokensThisInterval += e, n;
|
|
996
|
-
}
|
|
997
|
-
tryRemoveTokens(e) {
|
|
998
|
-
if (e > this.tokenBucket.bucketSize) return !1;
|
|
999
|
-
let t = W();
|
|
1000
|
-
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
|
|
1001
|
-
let n = this.tokenBucket.tryRemoveTokens(e);
|
|
1002
|
-
return n && (this.tokensThisInterval += e), n;
|
|
1003
|
-
}
|
|
1004
|
-
getTokensRemaining() {
|
|
1005
|
-
return this.tokenBucket.drip(), this.tokenBucket.content;
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
//#endregion
|
|
1009
|
-
//#region src/request-rate-limit.ts
|
|
1010
|
-
function Me(e = {}) {
|
|
1011
|
-
let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
|
|
1012
|
-
function a(e) {
|
|
1013
|
-
return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
|
|
1014
|
-
}
|
|
1015
|
-
function o(e) {
|
|
1016
|
-
if (r.size < 64 || i % 64 != 0) return;
|
|
1017
|
-
let n = e - t * 10;
|
|
1018
|
-
for (let [e, t] of r) t.lastUsedAt < n && r.delete(e);
|
|
1019
|
-
}
|
|
1020
|
-
return { check(e, s) {
|
|
1021
|
-
let c = Math.max(1, Math.trunc(s));
|
|
1022
|
-
i += 1;
|
|
1023
|
-
let l = n();
|
|
1024
|
-
o(l);
|
|
1025
|
-
let u = `${c}:${e}`, d = r.get(u);
|
|
1026
|
-
return d || (d = {
|
|
1027
|
-
limiter: new je({
|
|
1028
|
-
tokensPerInterval: c,
|
|
1029
|
-
interval: t,
|
|
1030
|
-
fireImmediately: !0
|
|
1031
|
-
}),
|
|
1032
|
-
lastUsedAt: l
|
|
1033
|
-
}, r.set(u, d)), d.lastUsedAt = l, d.limiter.tryRemoveTokens(1) ? {
|
|
1034
|
-
allowed: !0,
|
|
1035
|
-
retryAfterS: 0
|
|
1036
|
-
} : {
|
|
1037
|
-
allowed: !1,
|
|
1038
|
-
retryAfterS: a(c)
|
|
1039
|
-
};
|
|
1040
|
-
} };
|
|
1041
|
-
}
|
|
1042
|
-
//#endregion
|
|
1043
|
-
//#region src/scope-membership-semantics.ts
|
|
1044
|
-
var K = "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.";
|
|
1045
|
-
function Ne(e) {
|
|
1046
|
-
let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
|
|
1047
|
-
return t == null || n == null ? {
|
|
1048
|
-
membership_epoch: t,
|
|
1049
|
-
required_epoch: n,
|
|
1050
|
-
stale: !1,
|
|
1051
|
-
reason: "unknown_epoch"
|
|
1052
|
-
} : {
|
|
1053
|
-
membership_epoch: t,
|
|
1054
|
-
required_epoch: n,
|
|
1055
|
-
stale: t < n,
|
|
1056
|
-
reason: t < n ? "stale_epoch" : "current"
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
function q(e) {
|
|
1060
|
-
return {
|
|
1061
|
-
scope_id: e.scopeId,
|
|
1062
|
-
device_id: e.deviceId,
|
|
1063
|
-
membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
|
|
1064
|
-
prevents_future_sync: !0,
|
|
1065
|
-
deletes_already_copied_data: !1,
|
|
1066
|
-
message: K
|
|
1067
|
-
};
|
|
1068
|
-
}
|
|
1069
|
-
//#endregion
|
|
1070
|
-
//#region src/sync-auth-constants.ts
|
|
1071
|
-
var Pe = 300;
|
|
1072
|
-
//#endregion
|
|
1073
|
-
//#region src/sync-fingerprint.ts
|
|
1074
|
-
function J(t) {
|
|
1075
|
-
return e("sha256").update(t, "utf-8").digest("hex");
|
|
1076
|
-
}
|
|
1077
|
-
//#endregion
|
|
1078
|
-
//#region src/coordinator-api.ts
|
|
1079
|
-
var Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Z = "X-Codemem-Coordinator-Admin-Actor", Fe = 120, Ie = 30;
|
|
1080
|
-
function Q(e, t) {
|
|
1081
|
-
let n = t.adminSecret();
|
|
1082
|
-
if (!n) return {
|
|
1083
|
-
ok: !1,
|
|
1084
|
-
error: "admin_not_configured"
|
|
1085
|
-
};
|
|
1086
|
-
let r = (e ?? "").trim();
|
|
1087
|
-
return r ? r === n ? {
|
|
1088
|
-
ok: !0,
|
|
1089
|
-
error: "ok"
|
|
1090
|
-
} : {
|
|
1091
|
-
ok: !1,
|
|
1092
|
-
error: "invalid_admin_secret"
|
|
1093
|
-
} : {
|
|
1094
|
-
ok: !1,
|
|
1095
|
-
error: "missing_admin_header"
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
function Le(e) {
|
|
1099
|
-
let t = new URL(e);
|
|
1100
|
-
return t.search ? `${t.pathname}${t.search}` : t.pathname;
|
|
1101
|
-
}
|
|
1102
|
-
async function Re(e, t, n, r) {
|
|
1103
|
-
return await e.recordNonce(t, n, r);
|
|
1104
|
-
}
|
|
1105
|
-
async function ze(e, t) {
|
|
1106
|
-
await e.cleanupNonces(t);
|
|
1107
|
-
}
|
|
1108
|
-
async function $(e, t, n, r) {
|
|
1109
|
-
let { deviceId: i, signature: a, timestamp: o, nonce: s } = r;
|
|
1110
|
-
if (!i || !a || !o || !s) return {
|
|
1111
|
-
ok: !1,
|
|
1112
|
-
error: "missing_headers",
|
|
1113
|
-
enrollment: null
|
|
1114
|
-
};
|
|
1115
|
-
let c = await e.getEnrollment(r.groupId, i);
|
|
1116
|
-
if (!c) return {
|
|
1117
|
-
ok: !1,
|
|
1118
|
-
error: "unknown_device",
|
|
1119
|
-
enrollment: null
|
|
1120
|
-
};
|
|
1121
|
-
let l = await e.getGroup(r.groupId);
|
|
1122
|
-
if (!l) return {
|
|
1123
|
-
ok: !1,
|
|
1124
|
-
error: "group_not_found",
|
|
1125
|
-
enrollment: null
|
|
1126
|
-
};
|
|
1127
|
-
if (l.archived_at) return {
|
|
1128
|
-
ok: !1,
|
|
1129
|
-
error: "group_archived",
|
|
1130
|
-
enrollment: null
|
|
1131
|
-
};
|
|
1132
|
-
let u;
|
|
1133
|
-
try {
|
|
1134
|
-
u = await n({
|
|
1135
|
-
method: r.method,
|
|
1136
|
-
pathWithQuery: Le(r.url),
|
|
1137
|
-
bodyBytes: r.body,
|
|
1138
|
-
timestamp: o,
|
|
1139
|
-
nonce: s,
|
|
1140
|
-
signature: a,
|
|
1141
|
-
publicKey: String(c.public_key),
|
|
1142
|
-
deviceId: i
|
|
1143
|
-
});
|
|
1144
|
-
} catch {
|
|
1145
|
-
return {
|
|
1146
|
-
ok: !1,
|
|
1147
|
-
error: "signature_verification_error",
|
|
1148
|
-
enrollment: null
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
if (!u) return {
|
|
1152
|
-
ok: !1,
|
|
1153
|
-
error: "invalid_signature",
|
|
1154
|
-
enrollment: null
|
|
1155
|
-
};
|
|
1156
|
-
let d = t.now();
|
|
1157
|
-
return await Re(e, i, s, d) ? (await ze(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
|
|
1158
|
-
ok: !0,
|
|
1159
|
-
error: "ok",
|
|
1160
|
-
enrollment: c
|
|
1161
|
-
}) : {
|
|
1162
|
-
ok: !1,
|
|
1163
|
-
error: "nonce_replay",
|
|
1164
|
-
enrollment: null
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
function Be(e) {
|
|
1168
|
-
if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
|
|
1169
|
-
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? Me(), o = Math.max(1, Math.trunc(i.readLimit ?? Fe)), s = Math.max(1, Math.trunc(i.mutationLimit ?? Ie)), 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 Se(), d = new TextDecoder();
|
|
1170
|
-
function f(e, t, n) {
|
|
1171
|
-
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);
|
|
1172
|
-
return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
|
|
1173
|
-
error: "rate_limited",
|
|
1174
|
-
retry_after_s: i.retryAfterS
|
|
1175
|
-
}, 429));
|
|
1176
|
-
}
|
|
1177
|
-
async function p(e) {
|
|
1178
|
-
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1179
|
-
if (Number.isFinite(t) && t > Y) return null;
|
|
1180
|
-
let n = e.req.raw.body;
|
|
1181
|
-
if (!n) return new Uint8Array();
|
|
1182
|
-
let r = n.getReader(), i = [], a = 0;
|
|
1183
|
-
try {
|
|
1184
|
-
for (;;) {
|
|
1185
|
-
let { done: e, value: t } = await r.read();
|
|
1186
|
-
if (e) break;
|
|
1187
|
-
if (t) {
|
|
1188
|
-
if (a += t.byteLength, a > Y) return await r.cancel(), null;
|
|
1189
|
-
i.push(t);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
} finally {
|
|
1193
|
-
r.releaseLock();
|
|
1194
|
-
}
|
|
1195
|
-
let o = new Uint8Array(a), s = 0;
|
|
1196
|
-
for (let e of i) o.set(e, s), s += e.byteLength;
|
|
1197
|
-
return o;
|
|
1198
|
-
}
|
|
1199
|
-
function m(e) {
|
|
1200
|
-
try {
|
|
1201
|
-
let t = JSON.parse(d.decode(e));
|
|
1202
|
-
return typeof t != "object" || !t || Array.isArray(t) ? null : t;
|
|
1203
|
-
} catch {
|
|
1204
|
-
return null;
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
function h(e, t) {
|
|
1208
|
-
let n = e[t];
|
|
1209
|
-
return n == null ? null : String(n).trim() || null;
|
|
1210
|
-
}
|
|
1211
|
-
function g(e) {
|
|
1212
|
-
return e?.trim() || null;
|
|
1213
|
-
}
|
|
1214
|
-
function _(e, t) {
|
|
1215
|
-
let n = e[t];
|
|
1216
|
-
if (n == null || n === "") return null;
|
|
1217
|
-
if (typeof n != "number" && typeof n != "string") return NaN;
|
|
1218
|
-
if (typeof n == "string") {
|
|
1219
|
-
let e = n.trim();
|
|
1220
|
-
if (!e) return NaN;
|
|
1221
|
-
let t = Number(e);
|
|
1222
|
-
return Number.isFinite(t) ? Math.trunc(t) : NaN;
|
|
1223
|
-
}
|
|
1224
|
-
let r = n;
|
|
1225
|
-
return Number.isFinite(r) ? Math.trunc(r) : NaN;
|
|
1226
|
-
}
|
|
1227
|
-
function v(e) {
|
|
1228
|
-
return [
|
|
1229
|
-
"1",
|
|
1230
|
-
"true",
|
|
1231
|
-
"yes"
|
|
1232
|
-
].includes(String(e ?? "").trim().toLowerCase());
|
|
1233
|
-
}
|
|
1234
|
-
async function y(e, t, n) {
|
|
1235
|
-
if (!t) return n.json({ error: "group_id_required" }, 400);
|
|
1236
|
-
let r = await e.getGroup(t);
|
|
1237
|
-
return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
|
|
1238
|
-
}
|
|
1239
|
-
async function b(e, t, n, r) {
|
|
1240
|
-
let i = await y(e, t, r);
|
|
1241
|
-
if (i) return {
|
|
1242
|
-
scope: null,
|
|
1243
|
-
response: i
|
|
1244
|
-
};
|
|
1245
|
-
if (!n) return {
|
|
1246
|
-
scope: null,
|
|
1247
|
-
response: r.json({ error: "scope_id_required" }, 400)
|
|
1248
|
-
};
|
|
1249
|
-
let a = (await e.listScopes({
|
|
1250
|
-
groupId: t,
|
|
1251
|
-
includeInactive: !0
|
|
1252
|
-
})).find((e) => e.scope_id === n) ?? null;
|
|
1253
|
-
return a ? {
|
|
1254
|
-
scope: a,
|
|
1255
|
-
response: null
|
|
1256
|
-
} : {
|
|
1257
|
-
scope: null,
|
|
1258
|
-
response: r.json({ error: "scope_not_found" }, 404)
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
async function x(e, n, i) {
|
|
1262
|
-
let a = await $(e, t, r, {
|
|
1263
|
-
method: i.req.method,
|
|
1264
|
-
url: i.req.url,
|
|
1265
|
-
groupId: n,
|
|
1266
|
-
body: new Uint8Array(),
|
|
1267
|
-
deviceId: i.req.header("X-Opencode-Device") ?? null,
|
|
1268
|
-
signature: i.req.header("X-Opencode-Signature") ?? null,
|
|
1269
|
-
timestamp: i.req.header("X-Opencode-Timestamp") ?? null,
|
|
1270
|
-
nonce: i.req.header("X-Opencode-Nonce") ?? null
|
|
1271
|
-
});
|
|
1272
|
-
return !a.ok || !a.enrollment ? {
|
|
1273
|
-
auth: a,
|
|
1274
|
-
response: f(i, i.req.path, !1) ?? i.json({ error: a.error }, a.error === "group_archived" ? 409 : 401)
|
|
1275
|
-
} : {
|
|
1276
|
-
auth: a,
|
|
1277
|
-
response: f(i, String(a.enrollment.device_id), !0)
|
|
1278
|
-
};
|
|
1279
|
-
}
|
|
1280
|
-
function S(e, t) {
|
|
1281
|
-
return e.status === "active" && e.membership_epoch >= t.membership_epoch;
|
|
1282
|
-
}
|
|
1283
|
-
async function C(e, t, n) {
|
|
1284
|
-
return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n && S(e, t));
|
|
1285
|
-
}
|
|
1286
|
-
return u.post("/v1/presence", async (e) => {
|
|
1287
|
-
let i = await p(e);
|
|
1288
|
-
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1289
|
-
let a = m(i);
|
|
1290
|
-
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1291
|
-
let o = String(a.group_id ?? "").trim();
|
|
1292
|
-
if (!o) return e.json({ error: "group_id_required" }, 400);
|
|
1293
|
-
let s = n();
|
|
1294
|
-
try {
|
|
1295
|
-
let n = await $(s, t, r, {
|
|
1296
|
-
method: e.req.method,
|
|
1297
|
-
url: e.req.url,
|
|
1298
|
-
groupId: o,
|
|
1299
|
-
body: i,
|
|
1300
|
-
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1301
|
-
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1302
|
-
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1303
|
-
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1304
|
-
});
|
|
1305
|
-
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, n.error === "group_archived" ? 409 : 401);
|
|
1306
|
-
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1307
|
-
if (c) return c;
|
|
1308
|
-
if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
|
|
1309
|
-
let l = a.addresses ?? [];
|
|
1310
|
-
if (!Array.isArray(l) || !l.every((e) => typeof e == "string")) return e.json({ error: "addresses_must_be_list_of_strings" }, 400);
|
|
1311
|
-
let u;
|
|
1312
|
-
try {
|
|
1313
|
-
if (u = Math.max(1, Number.parseInt(String(a.ttl_s ?? 180), 10)), Number.isNaN(u)) return e.json({ error: "ttl_s_must_be_int" }, 400);
|
|
1314
|
-
} catch {
|
|
1315
|
-
return e.json({ error: "ttl_s_must_be_int" }, 400);
|
|
1316
|
-
}
|
|
1317
|
-
let d = await s.upsertPresence({
|
|
1318
|
-
groupId: o,
|
|
1319
|
-
deviceId: String(n.enrollment.device_id),
|
|
1320
|
-
addresses: l,
|
|
1321
|
-
ttlS: u,
|
|
1322
|
-
capabilities: typeof a.capabilities == "object" && a.capabilities !== null && !Array.isArray(a.capabilities) ? a.capabilities : void 0
|
|
1323
|
-
});
|
|
1324
|
-
return e.json({
|
|
1325
|
-
ok: !0,
|
|
1326
|
-
...d
|
|
1327
|
-
});
|
|
1328
|
-
} finally {
|
|
1329
|
-
await s.close();
|
|
1330
|
-
}
|
|
1331
|
-
}), u.get("/v1/peers", async (e) => {
|
|
1332
|
-
let i = (e.req.query("group_id") ?? "").trim();
|
|
1333
|
-
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1334
|
-
let a = n();
|
|
1335
|
-
try {
|
|
1336
|
-
let n = await $(a, t, r, {
|
|
1337
|
-
method: e.req.method,
|
|
1338
|
-
url: e.req.url,
|
|
1339
|
-
groupId: i,
|
|
1340
|
-
body: new Uint8Array(),
|
|
1341
|
-
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1342
|
-
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1343
|
-
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1344
|
-
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1345
|
-
});
|
|
1346
|
-
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, n.error === "group_archived" ? 409 : 401);
|
|
1347
|
-
let o = f(e, String(n.enrollment.device_id), !0);
|
|
1348
|
-
if (o) return o;
|
|
1349
|
-
let s = await a.listGroupPeers(i, String(n.enrollment.device_id));
|
|
1350
|
-
return e.json({ items: s });
|
|
1351
|
-
} finally {
|
|
1352
|
-
await a.close();
|
|
1353
|
-
}
|
|
1354
|
-
}), u.get("/v1/scopes", async (e) => {
|
|
1355
|
-
let t = (e.req.query("group_id") ?? "").trim();
|
|
1356
|
-
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1357
|
-
let r = n();
|
|
1358
|
-
try {
|
|
1359
|
-
let { auth: n, response: i } = await x(r, t, e);
|
|
1360
|
-
if (i) return i;
|
|
1361
|
-
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1362
|
-
let a = await r.listScopes({
|
|
1363
|
-
groupId: t,
|
|
1364
|
-
includeInactive: !1
|
|
1365
|
-
}), o = [];
|
|
1366
|
-
for (let e of a) e.status === "active" && await C(r, e, String(n.enrollment.device_id)) && o.push(e);
|
|
1367
|
-
return e.json({ items: o });
|
|
1368
|
-
} finally {
|
|
1369
|
-
await r.close();
|
|
1370
|
-
}
|
|
1371
|
-
}), u.get("/v1/scopes/:scope_id/members", async (e) => {
|
|
1372
|
-
let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
|
|
1373
|
-
if (!t) return e.json({ error: "group_id_required" }, 400);
|
|
1374
|
-
if (!r) return e.json({ error: "scope_id_required" }, 400);
|
|
1375
|
-
let i = n();
|
|
1376
|
-
try {
|
|
1377
|
-
let { auth: n, response: a } = await x(i, t, e);
|
|
1378
|
-
if (a) return a;
|
|
1379
|
-
if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
|
|
1380
|
-
let o = (await i.listScopes({
|
|
1381
|
-
groupId: t,
|
|
1382
|
-
includeInactive: !1
|
|
1383
|
-
})).find((e) => e.scope_id === r) ?? null;
|
|
1384
|
-
if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
|
|
1385
|
-
let s = await i.listScopeMemberships(r, !1);
|
|
1386
|
-
return s.some((e) => e.device_id === String(n.enrollment?.device_id) && S(e, o)) ? e.json({ items: s.filter((e) => S(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
|
|
1387
|
-
} finally {
|
|
1388
|
-
await i.close();
|
|
1389
|
-
}
|
|
1390
|
-
}), u.get("/v1/reciprocal-approvals", async (e) => {
|
|
1391
|
-
let i = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
|
|
1392
|
-
if (!i) return e.json({ error: "group_id_required" }, 400);
|
|
1393
|
-
if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
|
|
1394
|
-
let s = n();
|
|
1395
|
-
try {
|
|
1396
|
-
let n = await $(s, t, r, {
|
|
1397
|
-
method: e.req.method,
|
|
1398
|
-
url: e.req.url,
|
|
1399
|
-
groupId: i,
|
|
1400
|
-
body: new Uint8Array(),
|
|
1401
|
-
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1402
|
-
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1403
|
-
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1404
|
-
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1405
|
-
});
|
|
1406
|
-
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, 401);
|
|
1407
|
-
let c = f(e, String(n.enrollment.device_id), !0);
|
|
1408
|
-
if (c) return c;
|
|
1409
|
-
let l = await s.listReciprocalApprovals({
|
|
1410
|
-
groupId: i,
|
|
1411
|
-
deviceId: String(n.enrollment.device_id),
|
|
1412
|
-
direction: a,
|
|
1413
|
-
status: o
|
|
1414
|
-
});
|
|
1415
|
-
return e.json({ items: l });
|
|
1416
|
-
} finally {
|
|
1417
|
-
await s.close();
|
|
1418
|
-
}
|
|
1419
|
-
}), u.post("/v1/reciprocal-approvals", async (e) => {
|
|
1420
|
-
let i = await p(e);
|
|
1421
|
-
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
1422
|
-
let a = m(i);
|
|
1423
|
-
if (!a) return e.json({ error: "invalid_json" }, 400);
|
|
1424
|
-
let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim();
|
|
1425
|
-
if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
|
|
1426
|
-
let c = n();
|
|
1427
|
-
try {
|
|
1428
|
-
let n = await $(c, t, r, {
|
|
1429
|
-
method: e.req.method,
|
|
1430
|
-
url: e.req.url,
|
|
1431
|
-
groupId: o,
|
|
1432
|
-
body: i,
|
|
1433
|
-
deviceId: e.req.header("X-Opencode-Device") ?? null,
|
|
1434
|
-
signature: e.req.header("X-Opencode-Signature") ?? null,
|
|
1435
|
-
timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
|
|
1436
|
-
nonce: e.req.header("X-Opencode-Nonce") ?? null
|
|
1437
|
-
});
|
|
1438
|
-
if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, 401);
|
|
1439
|
-
let a = f(e, String(n.enrollment.device_id), !0);
|
|
1440
|
-
if (a) return a;
|
|
1441
|
-
if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
|
|
1442
|
-
if (!await c.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
|
|
1443
|
-
let l = await c.createReciprocalApproval({
|
|
1444
|
-
groupId: o,
|
|
1445
|
-
requestingDeviceId: String(n.enrollment.device_id),
|
|
1446
|
-
requestedDeviceId: s
|
|
1447
|
-
});
|
|
1448
|
-
return e.json({
|
|
1449
|
-
ok: !0,
|
|
1450
|
-
request: l
|
|
1451
|
-
});
|
|
1452
|
-
} finally {
|
|
1453
|
-
await c.close();
|
|
1454
|
-
}
|
|
1455
|
-
}), u.post("/v1/admin/devices", async (e) => {
|
|
1456
|
-
let r = Q(e.req.header(X), t);
|
|
1457
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1458
|
-
let i = f(e, "admin", !0);
|
|
1459
|
-
if (i) return i;
|
|
1460
|
-
let a = await p(e);
|
|
1461
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1462
|
-
let o = m(a);
|
|
1463
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1464
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.fingerprint ?? "").trim(), u = String(o.public_key ?? "").trim(), d = String(o.display_name ?? "").trim() || null;
|
|
1465
|
-
if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
|
|
1466
|
-
if (J(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
1467
|
-
let h = n();
|
|
1468
|
-
try {
|
|
1469
|
-
await h.createGroup(s), await h.enrollDevice(s, {
|
|
1470
|
-
deviceId: c,
|
|
1471
|
-
fingerprint: l,
|
|
1472
|
-
publicKey: u,
|
|
1473
|
-
displayName: d
|
|
1474
|
-
});
|
|
1475
|
-
} finally {
|
|
1476
|
-
await h.close();
|
|
1477
|
-
}
|
|
1478
|
-
return e.json({ ok: !0 });
|
|
1479
|
-
}), u.get("/v1/admin/groups", async (e) => {
|
|
1480
|
-
let r = Q(e.req.header(X), t);
|
|
1481
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1482
|
-
let i = f(e, "admin", !0);
|
|
1483
|
-
if (i) return i;
|
|
1484
|
-
let a = [
|
|
1485
|
-
"1",
|
|
1486
|
-
"true",
|
|
1487
|
-
"yes"
|
|
1488
|
-
].includes((e.req.query("include_archived") ?? "0").trim().toLowerCase()), o = n();
|
|
1489
|
-
try {
|
|
1490
|
-
return e.json({ items: await o.listGroups(a) });
|
|
1491
|
-
} finally {
|
|
1492
|
-
await o.close();
|
|
1493
|
-
}
|
|
1494
|
-
}), u.post("/v1/admin/groups", async (e) => {
|
|
1495
|
-
let r = Q(e.req.header(X), t);
|
|
1496
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1497
|
-
let i = f(e, "admin", !0);
|
|
1498
|
-
if (i) return i;
|
|
1499
|
-
let a = await p(e);
|
|
1500
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1501
|
-
let o = m(a);
|
|
1502
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1503
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
|
|
1504
|
-
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
1505
|
-
let l = n();
|
|
1506
|
-
try {
|
|
1507
|
-
return await l.createGroup(s, c), e.json({
|
|
1508
|
-
ok: !0,
|
|
1509
|
-
group: await l.getGroup(s)
|
|
1510
|
-
});
|
|
1511
|
-
} finally {
|
|
1512
|
-
await l.close();
|
|
1513
|
-
}
|
|
1514
|
-
}), u.post("/v1/admin/groups/rename", async (e) => {
|
|
1515
|
-
let r = Q(e.req.header(X), t);
|
|
1516
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1517
|
-
let i = f(e, "admin", !0);
|
|
1518
|
-
if (i) return i;
|
|
1519
|
-
let a = await p(e);
|
|
1520
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1521
|
-
let o = m(a);
|
|
1522
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1523
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
|
|
1524
|
-
if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
|
|
1525
|
-
let l = n();
|
|
1526
|
-
try {
|
|
1527
|
-
return await l.renameGroup(s, c) ? e.json({
|
|
1528
|
-
ok: !0,
|
|
1529
|
-
group: await l.getGroup(s)
|
|
1530
|
-
}) : e.json({ error: "group_not_found" }, 404);
|
|
1531
|
-
} finally {
|
|
1532
|
-
await l.close();
|
|
1533
|
-
}
|
|
1534
|
-
}), u.post("/v1/admin/groups/archive", async (e) => {
|
|
1535
|
-
let r = Q(e.req.header(X), t);
|
|
1536
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1537
|
-
let i = f(e, "admin", !0);
|
|
1538
|
-
if (i) return i;
|
|
1539
|
-
let a = await p(e);
|
|
1540
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1541
|
-
let o = m(a);
|
|
1542
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1543
|
-
let s = String(o.group_id ?? "").trim();
|
|
1544
|
-
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
1545
|
-
let c = n();
|
|
1546
|
-
try {
|
|
1547
|
-
return await c.archiveGroup(s, t.now()) ? e.json({
|
|
1548
|
-
ok: !0,
|
|
1549
|
-
group: await c.getGroup(s)
|
|
1550
|
-
}) : e.json({ error: "group_not_found_or_already_archived" }, 404);
|
|
1551
|
-
} finally {
|
|
1552
|
-
await c.close();
|
|
1553
|
-
}
|
|
1554
|
-
}), u.post("/v1/admin/groups/unarchive", async (e) => {
|
|
1555
|
-
let r = Q(e.req.header(X), t);
|
|
1556
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1557
|
-
let i = f(e, "admin", !0);
|
|
1558
|
-
if (i) return i;
|
|
1559
|
-
let a = await p(e);
|
|
1560
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1561
|
-
let o = m(a);
|
|
1562
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1563
|
-
let s = String(o.group_id ?? "").trim();
|
|
1564
|
-
if (!s) return e.json({ error: "group_id_required" }, 400);
|
|
1565
|
-
let c = n();
|
|
1566
|
-
try {
|
|
1567
|
-
return await c.unarchiveGroup(s) ? e.json({
|
|
1568
|
-
ok: !0,
|
|
1569
|
-
group: await c.getGroup(s)
|
|
1570
|
-
}) : e.json({ error: "group_not_found_or_not_archived" }, 404);
|
|
1571
|
-
} finally {
|
|
1572
|
-
await c.close();
|
|
1573
|
-
}
|
|
1574
|
-
}), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1575
|
-
let r = Q(e.req.header(X), t);
|
|
1576
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1577
|
-
let i = f(e, "admin", !0);
|
|
1578
|
-
if (i) return i;
|
|
1579
|
-
let a = String(e.req.param("group_id") ?? "").trim(), o = n();
|
|
1580
|
-
try {
|
|
1581
|
-
let t = await y(o, a, e);
|
|
1582
|
-
if (t) return t;
|
|
1583
|
-
let n = v(e.req.query("include_inactive"));
|
|
1584
|
-
return e.json({ items: await o.listScopes({
|
|
1585
|
-
groupId: a,
|
|
1586
|
-
includeInactive: n
|
|
1587
|
-
}) });
|
|
1588
|
-
} finally {
|
|
1589
|
-
await o.close();
|
|
1590
|
-
}
|
|
1591
|
-
}), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1592
|
-
let r = Q(e.req.header(X), t);
|
|
1593
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1594
|
-
let i = f(e, "admin", !0);
|
|
1595
|
-
if (i) return i;
|
|
1596
|
-
let a = await p(e);
|
|
1597
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1598
|
-
let o = m(a);
|
|
1599
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1600
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
|
|
1601
|
-
if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
|
|
1602
|
-
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1603
|
-
let d = n();
|
|
1604
|
-
try {
|
|
1605
|
-
let t = await y(d, s, e);
|
|
1606
|
-
if (t) return t;
|
|
1607
|
-
let n = await d.createScope({
|
|
1608
|
-
scopeId: c,
|
|
1609
|
-
label: l,
|
|
1610
|
-
kind: h(o, "kind"),
|
|
1611
|
-
authorityType: h(o, "authority_type"),
|
|
1612
|
-
coordinatorId: h(o, "coordinator_id"),
|
|
1613
|
-
groupId: s,
|
|
1614
|
-
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
1615
|
-
membershipEpoch: u,
|
|
1616
|
-
manifestHash: h(o, "manifest_hash"),
|
|
1617
|
-
status: h(o, "status")
|
|
1618
|
-
});
|
|
1619
|
-
return e.json({
|
|
1620
|
-
ok: !0,
|
|
1621
|
-
scope: n
|
|
1622
|
-
}, 201);
|
|
1623
|
-
} catch (t) {
|
|
1624
|
-
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1625
|
-
} finally {
|
|
1626
|
-
await d.close();
|
|
1627
|
-
}
|
|
1628
|
-
}), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
|
|
1629
|
-
let r = Q(e.req.header(X), t);
|
|
1630
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1631
|
-
let i = f(e, "admin", !0);
|
|
1632
|
-
if (i) return i;
|
|
1633
|
-
let a = await p(e);
|
|
1634
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1635
|
-
let o = m(a);
|
|
1636
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1637
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
|
|
1638
|
-
if (!c) return e.json({ error: "scope_id_required" }, 400);
|
|
1639
|
-
if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1640
|
-
let u = n();
|
|
1641
|
-
try {
|
|
1642
|
-
let t = await b(u, s, c, e);
|
|
1643
|
-
if (t.response) return t.response;
|
|
1644
|
-
let n = await u.updateScope({
|
|
1645
|
-
scopeId: c,
|
|
1646
|
-
label: o.label === void 0 ? void 0 : h(o, "label"),
|
|
1647
|
-
kind: o.kind === void 0 ? void 0 : h(o, "kind"),
|
|
1648
|
-
authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
|
|
1649
|
-
coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
|
|
1650
|
-
groupId: s,
|
|
1651
|
-
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
|
|
1652
|
-
membershipEpoch: l,
|
|
1653
|
-
manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
|
|
1654
|
-
status: o.status === void 0 ? void 0 : h(o, "status")
|
|
1655
|
-
});
|
|
1656
|
-
return n ? e.json({
|
|
1657
|
-
ok: !0,
|
|
1658
|
-
scope: n
|
|
1659
|
-
}) : e.json({ error: "scope_not_found" }, 404);
|
|
1660
|
-
} catch (t) {
|
|
1661
|
-
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1662
|
-
} finally {
|
|
1663
|
-
await u.close();
|
|
1664
|
-
}
|
|
1665
|
-
}), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
1666
|
-
let r = Q(e.req.header(X), t);
|
|
1667
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1668
|
-
let i = f(e, "admin", !0);
|
|
1669
|
-
if (i) return i;
|
|
1670
|
-
let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
|
|
1671
|
-
try {
|
|
1672
|
-
let t = await b(s, a, o, e);
|
|
1673
|
-
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
|
|
1674
|
-
} finally {
|
|
1675
|
-
await s.close();
|
|
1676
|
-
}
|
|
1677
|
-
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
1678
|
-
let r = Q(e.req.header(X), t);
|
|
1679
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1680
|
-
let i = f(e, "admin", !0);
|
|
1681
|
-
if (i) return i;
|
|
1682
|
-
let a = await p(e);
|
|
1683
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1684
|
-
let o = m(a);
|
|
1685
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1686
|
-
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = h(o, "device_id"), u = _(o, "membership_epoch");
|
|
1687
|
-
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
1688
|
-
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1689
|
-
let d = n();
|
|
1690
|
-
try {
|
|
1691
|
-
let t = await b(d, s, c, e);
|
|
1692
|
-
if (t.response) return t.response;
|
|
1693
|
-
if (t.scope?.status !== "active") return e.json({ error: "scope_not_active" }, 409);
|
|
1694
|
-
if (!await d.getEnrollment(s, l)) return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
|
|
1695
|
-
let n = await d.grantScopeMembership({
|
|
1696
|
-
scopeId: c,
|
|
1697
|
-
deviceId: l,
|
|
1698
|
-
role: h(o, "role"),
|
|
1699
|
-
membershipEpoch: u,
|
|
1700
|
-
coordinatorId: h(o, "coordinator_id"),
|
|
1701
|
-
groupId: s,
|
|
1702
|
-
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
1703
|
-
manifestHash: h(o, "manifest_hash"),
|
|
1704
|
-
signedManifestJson: h(o, "signed_manifest_json"),
|
|
1705
|
-
actorType: "admin",
|
|
1706
|
-
actorId: g(e.req.header(Z))
|
|
1707
|
-
});
|
|
1708
|
-
return e.json({
|
|
1709
|
-
ok: !0,
|
|
1710
|
-
membership: n
|
|
1711
|
-
}, 201);
|
|
1712
|
-
} catch (t) {
|
|
1713
|
-
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1714
|
-
} finally {
|
|
1715
|
-
await d.close();
|
|
1716
|
-
}
|
|
1717
|
-
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
|
|
1718
|
-
let r = Q(e.req.header(X), t);
|
|
1719
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1720
|
-
let i = f(e, "admin", !0);
|
|
1721
|
-
if (i) return i;
|
|
1722
|
-
let a = await p(e);
|
|
1723
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1724
|
-
let o = a.byteLength > 0 ? m(a) : {};
|
|
1725
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1726
|
-
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 = _(o, "membership_epoch");
|
|
1727
|
-
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
1728
|
-
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1729
|
-
let d = n();
|
|
1730
|
-
try {
|
|
1731
|
-
let t = await b(d, s, c, e);
|
|
1732
|
-
if (t.response) return t.response;
|
|
1733
|
-
if (!await d.revokeScopeMembership({
|
|
1734
|
-
scopeId: c,
|
|
1735
|
-
deviceId: l,
|
|
1736
|
-
membershipEpoch: u,
|
|
1737
|
-
manifestHash: h(o, "manifest_hash"),
|
|
1738
|
-
signedManifestJson: h(o, "signed_manifest_json"),
|
|
1739
|
-
actorType: "admin",
|
|
1740
|
-
actorId: g(e.req.header(Z))
|
|
1741
|
-
})) return e.json({ error: "membership_not_found" }, 404);
|
|
1742
|
-
let n;
|
|
1743
|
-
try {
|
|
1744
|
-
n = (await d.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
|
|
1745
|
-
} catch {
|
|
1746
|
-
n = void 0;
|
|
1747
|
-
}
|
|
1748
|
-
return e.json({
|
|
1749
|
-
ok: !0,
|
|
1750
|
-
scope_id: c,
|
|
1751
|
-
device_id: l,
|
|
1752
|
-
revocation: q({
|
|
1753
|
-
scopeId: c,
|
|
1754
|
-
deviceId: l,
|
|
1755
|
-
membershipEpoch: n?.membership_epoch ?? u
|
|
1756
|
-
})
|
|
1757
|
-
});
|
|
1758
|
-
} catch (t) {
|
|
1759
|
-
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1760
|
-
} finally {
|
|
1761
|
-
await d.close();
|
|
1762
|
-
}
|
|
1763
|
-
}), u.get("/v1/admin/devices", async (e) => {
|
|
1764
|
-
let r = Q(e.req.header(X), t);
|
|
1765
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1766
|
-
let i = f(e, "admin", !0);
|
|
1767
|
-
if (i) return i;
|
|
1768
|
-
let a = (e.req.query("group_id") ?? "").trim();
|
|
1769
|
-
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
1770
|
-
let o = [
|
|
1771
|
-
"1",
|
|
1772
|
-
"true",
|
|
1773
|
-
"yes"
|
|
1774
|
-
].includes((e.req.query("include_disabled") ?? "0").trim().toLowerCase()), s = n();
|
|
1775
|
-
try {
|
|
1776
|
-
return e.json({ items: await s.listEnrolledDevices(a, o) });
|
|
1777
|
-
} finally {
|
|
1778
|
-
await s.close();
|
|
1779
|
-
}
|
|
1780
|
-
}), u.post("/v1/admin/devices/rename", async (e) => {
|
|
1781
|
-
let r = Q(e.req.header(X), t);
|
|
1782
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1783
|
-
let i = f(e, "admin", !0);
|
|
1784
|
-
if (i) return i;
|
|
1785
|
-
let a = await p(e);
|
|
1786
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1787
|
-
let o = m(a);
|
|
1788
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1789
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
|
|
1790
|
-
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
1791
|
-
if (!l) return e.json({ error: "display_name_required" }, 400);
|
|
1792
|
-
let u = n();
|
|
1793
|
-
try {
|
|
1794
|
-
if (!await u.renameDevice(s, c, l)) return e.json({ error: "device_not_found" }, 404);
|
|
1795
|
-
let t = await u.getEnrollment(s, c);
|
|
1796
|
-
return e.json({
|
|
1797
|
-
ok: !0,
|
|
1798
|
-
device: t
|
|
1799
|
-
});
|
|
1800
|
-
} finally {
|
|
1801
|
-
await u.close();
|
|
1802
|
-
}
|
|
1803
|
-
}), u.post("/v1/admin/devices/disable", async (e) => {
|
|
1804
|
-
let r = Q(e.req.header(X), t);
|
|
1805
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1806
|
-
let i = f(e, "admin", !0);
|
|
1807
|
-
if (i) return i;
|
|
1808
|
-
let a = await p(e);
|
|
1809
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1810
|
-
let o = m(a);
|
|
1811
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1812
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1813
|
-
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
1814
|
-
let l = n();
|
|
1815
|
-
try {
|
|
1816
|
-
return await l.setDeviceEnabled(s, c, !1) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
|
|
1817
|
-
} finally {
|
|
1818
|
-
await l.close();
|
|
1819
|
-
}
|
|
1820
|
-
}), u.post("/v1/admin/devices/enable", async (e) => {
|
|
1821
|
-
let r = Q(e.req.header(X), t);
|
|
1822
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1823
|
-
let i = f(e, "admin", !0);
|
|
1824
|
-
if (i) return i;
|
|
1825
|
-
let a = await p(e);
|
|
1826
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1827
|
-
let o = m(a);
|
|
1828
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1829
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1830
|
-
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
1831
|
-
let l = n();
|
|
1832
|
-
try {
|
|
1833
|
-
return await l.setDeviceEnabled(s, c, !0) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
|
|
1834
|
-
} finally {
|
|
1835
|
-
await l.close();
|
|
1836
|
-
}
|
|
1837
|
-
}), u.post("/v1/admin/devices/remove", async (e) => {
|
|
1838
|
-
let r = Q(e.req.header(X), t);
|
|
1839
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1840
|
-
let i = f(e, "admin", !0);
|
|
1841
|
-
if (i) return i;
|
|
1842
|
-
let a = await p(e);
|
|
1843
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1844
|
-
let o = m(a);
|
|
1845
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1846
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
|
|
1847
|
-
if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
|
|
1848
|
-
let l = n();
|
|
1849
|
-
try {
|
|
1850
|
-
return await l.removeDevice(s, c) ? e.json({ ok: !0 }) : e.json({ error: "device_not_found" }, 404);
|
|
1851
|
-
} finally {
|
|
1852
|
-
await l.close();
|
|
1853
|
-
}
|
|
1854
|
-
}), u.post("/v1/admin/invites", async (e) => {
|
|
1855
|
-
let r = Q(e.req.header(X), t);
|
|
1856
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1857
|
-
let i = f(e, "admin", !0);
|
|
1858
|
-
if (i) return i;
|
|
1859
|
-
let a = await p(e);
|
|
1860
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1861
|
-
let o = m(a);
|
|
1862
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1863
|
-
let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null;
|
|
1864
|
-
if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
|
|
1865
|
-
if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
|
|
1866
|
-
let d = n();
|
|
1867
|
-
try {
|
|
1868
|
-
let t = await d.getGroup(s);
|
|
1869
|
-
if (!t) return e.json({ error: "group_not_found" }, 404);
|
|
1870
|
-
if (t.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
1871
|
-
let n = await d.createInvite({
|
|
1872
|
-
groupId: s,
|
|
1873
|
-
policy: c,
|
|
1874
|
-
expiresAt: l,
|
|
1875
|
-
createdBy: u
|
|
1876
|
-
}), r = {
|
|
1877
|
-
v: 1,
|
|
1878
|
-
kind: "coordinator_team_invite",
|
|
1879
|
-
coordinator_url: String(o.coordinator_url ?? "").trim(),
|
|
1880
|
-
group_id: s,
|
|
1881
|
-
policy: c,
|
|
1882
|
-
token: String(n.token ?? ""),
|
|
1883
|
-
expires_at: l,
|
|
1884
|
-
team_name: n.team_name_snapshot ?? null
|
|
1885
|
-
}, i = H(r), { token: a, ...f } = n;
|
|
1886
|
-
return e.json({
|
|
1887
|
-
ok: !0,
|
|
1888
|
-
invite: f,
|
|
1889
|
-
payload: r,
|
|
1890
|
-
encoded: i,
|
|
1891
|
-
link: U(i)
|
|
1892
|
-
});
|
|
1893
|
-
} finally {
|
|
1894
|
-
await d.close();
|
|
1895
|
-
}
|
|
1896
|
-
}), u.get("/v1/admin/invites", async (e) => {
|
|
1897
|
-
let r = Q(e.req.header(X), t);
|
|
1898
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1899
|
-
let i = f(e, "admin", !0);
|
|
1900
|
-
if (i) return i;
|
|
1901
|
-
let a = (e.req.query("group_id") ?? "").trim();
|
|
1902
|
-
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
1903
|
-
let o = n();
|
|
1904
|
-
try {
|
|
1905
|
-
let t = (await o.listInvites(a)).map(({ token: e, ...t }) => t);
|
|
1906
|
-
return e.json({ items: t });
|
|
1907
|
-
} finally {
|
|
1908
|
-
await o.close();
|
|
1909
|
-
}
|
|
1910
|
-
}), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
|
|
1911
|
-
let r = Q(e.req.header(X), t);
|
|
1912
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1913
|
-
let i = f(e, "admin", !0);
|
|
1914
|
-
if (i) return i;
|
|
1915
|
-
let a = String(e.req.param("grantId") ?? "").trim();
|
|
1916
|
-
if (!a) return e.json({ error: "grant_id_required" }, 400);
|
|
1917
|
-
let o = n();
|
|
1918
|
-
try {
|
|
1919
|
-
let t = await o.getBootstrapGrant(a);
|
|
1920
|
-
if (!t) return e.json({ error: "grant_not_found" }, 404);
|
|
1921
|
-
let n = await o.getEnrollment(t.group_id, t.worker_device_id);
|
|
1922
|
-
if (!n) return e.json({ error: "worker_enrollment_not_found" }, 404);
|
|
1923
|
-
let r = {
|
|
1924
|
-
grant: t,
|
|
1925
|
-
worker_enrollment: n
|
|
1926
|
-
};
|
|
1927
|
-
return e.json(r);
|
|
1928
|
-
} finally {
|
|
1929
|
-
await o.close();
|
|
1930
|
-
}
|
|
1931
|
-
}), u.get("/v1/admin/bootstrap-grants", async (e) => {
|
|
1932
|
-
let r = Q(e.req.header(X), t);
|
|
1933
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1934
|
-
let i = f(e, "admin", !0);
|
|
1935
|
-
if (i) return i;
|
|
1936
|
-
let a = (e.req.query("group_id") ?? "").trim();
|
|
1937
|
-
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
1938
|
-
let o = n();
|
|
1939
|
-
try {
|
|
1940
|
-
return e.json({ items: await o.listBootstrapGrants(a) });
|
|
1941
|
-
} finally {
|
|
1942
|
-
await o.close();
|
|
1943
|
-
}
|
|
1944
|
-
}), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
|
|
1945
|
-
let r = Q(e.req.header(X), t);
|
|
1946
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1947
|
-
let i = f(e, "admin", !0);
|
|
1948
|
-
if (i) return i;
|
|
1949
|
-
let a = await p(e);
|
|
1950
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1951
|
-
let o = m(a);
|
|
1952
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1953
|
-
let s = String(o.grant_id ?? "").trim();
|
|
1954
|
-
if (!s) return e.json({ error: "grant_id_required" }, 400);
|
|
1955
|
-
let c = n();
|
|
1956
|
-
try {
|
|
1957
|
-
return await c.revokeBootstrapGrant(s, t.now()) ? e.json({
|
|
1958
|
-
ok: !0,
|
|
1959
|
-
grant_id: s
|
|
1960
|
-
}) : e.json({ error: "grant_not_found" }, 404);
|
|
1961
|
-
} finally {
|
|
1962
|
-
await c.close();
|
|
1963
|
-
}
|
|
1964
|
-
}), u.post("/v1/admin/join-requests/approve", async (e) => Ve(e, !0, {
|
|
1965
|
-
createStore: n,
|
|
1966
|
-
runtime: t,
|
|
1967
|
-
rateLimitedResponse: f
|
|
1968
|
-
})), u.post("/v1/admin/join-requests/deny", async (e) => Ve(e, !1, {
|
|
1969
|
-
createStore: n,
|
|
1970
|
-
runtime: t,
|
|
1971
|
-
rateLimitedResponse: f
|
|
1972
|
-
})), u.get("/v1/admin/join-requests", async (e) => {
|
|
1973
|
-
let r = Q(e.req.header(X), t);
|
|
1974
|
-
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1975
|
-
let i = f(e, "admin", !0);
|
|
1976
|
-
if (i) return i;
|
|
1977
|
-
let a = (e.req.query("group_id") ?? "").trim();
|
|
1978
|
-
if (!a) return e.json({ error: "group_id_required" }, 400);
|
|
1979
|
-
let o = n();
|
|
1980
|
-
try {
|
|
1981
|
-
return e.json({ items: await o.listJoinRequests(a) });
|
|
1982
|
-
} finally {
|
|
1983
|
-
await o.close();
|
|
1984
|
-
}
|
|
1985
|
-
}), u.post("/v1/join", async (e) => {
|
|
1986
|
-
let r = await p(e);
|
|
1987
|
-
if (r == null) return e.json({ error: "body_too_large" }, 413);
|
|
1988
|
-
let i = m(r);
|
|
1989
|
-
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
1990
|
-
let a = String(i.token ?? "").trim(), o = String(i.device_id ?? "").trim(), s = String(i.fingerprint ?? "").trim(), c = String(i.public_key ?? "").trim(), l = String(i.display_name ?? "").trim() || null;
|
|
1991
|
-
if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
|
|
1992
|
-
if (J(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
1993
|
-
let u = n();
|
|
1994
|
-
try {
|
|
1995
|
-
let n = await u.getInviteByToken(a);
|
|
1996
|
-
if (!n) return e.json({ error: "invalid_token" }, 404);
|
|
1997
|
-
let r = await u.getGroup(String(n.group_id));
|
|
1998
|
-
if (!r) return e.json({ error: "group_not_found" }, 404);
|
|
1999
|
-
if (r.archived_at) return e.json({ error: "group_archived" }, 409);
|
|
2000
|
-
if (n.revoked_at) return e.json({ error: "revoked_token" }, 400);
|
|
2001
|
-
let i = String(n.expires_at ?? "");
|
|
2002
|
-
if (i && new Date(i.replace("Z", "+00:00")) <= new Date(t.now())) return e.json({ error: "expired_token" }, 400);
|
|
2003
|
-
let d = String(n.group_id);
|
|
2004
|
-
if (await u.getEnrollment(d, o)) return e.json({
|
|
2005
|
-
ok: !0,
|
|
2006
|
-
status: "already_enrolled",
|
|
2007
|
-
group_id: n.group_id,
|
|
2008
|
-
policy: n.policy
|
|
2009
|
-
});
|
|
2010
|
-
let f = String(n.policy);
|
|
2011
|
-
if (!["auto_admit", "approval_required"].includes(f)) return e.json({ error: `unknown invite policy: ${f}` }, 400);
|
|
2012
|
-
if (f === "approval_required") {
|
|
2013
|
-
let t = await u.createJoinRequest({
|
|
2014
|
-
groupId: d,
|
|
2015
|
-
deviceId: o,
|
|
2016
|
-
publicKey: c,
|
|
2017
|
-
fingerprint: s,
|
|
2018
|
-
displayName: l,
|
|
2019
|
-
token: a
|
|
2020
|
-
});
|
|
2021
|
-
return e.json({
|
|
2022
|
-
ok: !0,
|
|
2023
|
-
status: "pending",
|
|
2024
|
-
group_id: n.group_id,
|
|
2025
|
-
policy: n.policy,
|
|
2026
|
-
request_id: t.request_id
|
|
2027
|
-
});
|
|
2028
|
-
}
|
|
2029
|
-
return await u.enrollDevice(d, {
|
|
2030
|
-
deviceId: o,
|
|
2031
|
-
fingerprint: s,
|
|
2032
|
-
publicKey: c,
|
|
2033
|
-
displayName: l
|
|
2034
|
-
}), e.json({
|
|
2035
|
-
ok: !0,
|
|
2036
|
-
status: "enrolled",
|
|
2037
|
-
group_id: n.group_id,
|
|
2038
|
-
policy: n.policy
|
|
2039
|
-
});
|
|
2040
|
-
} finally {
|
|
2041
|
-
await u.close();
|
|
2042
|
-
}
|
|
2043
|
-
}), u;
|
|
2044
|
-
}
|
|
2045
|
-
async function Ve(e, t, n) {
|
|
2046
|
-
let r = Q(e.req.header(X), n.runtime);
|
|
2047
|
-
if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
2048
|
-
let i = n.rateLimitedResponse(e, "admin", !0);
|
|
2049
|
-
if (i) return i;
|
|
2050
|
-
let a = await (async () => {
|
|
2051
|
-
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
2052
|
-
if (Number.isFinite(t) && t > Y) return null;
|
|
2053
|
-
let n = e.req.raw.body;
|
|
2054
|
-
if (!n) return new Uint8Array();
|
|
2055
|
-
let r = n.getReader(), i = [], a = 0;
|
|
2056
|
-
try {
|
|
2057
|
-
for (;;) {
|
|
2058
|
-
let { done: e, value: t } = await r.read();
|
|
2059
|
-
if (e) break;
|
|
2060
|
-
if (t) {
|
|
2061
|
-
if (a += t.byteLength, a > Y) return await r.cancel(), null;
|
|
2062
|
-
i.push(t);
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
} finally {
|
|
2066
|
-
r.releaseLock();
|
|
2067
|
-
}
|
|
2068
|
-
let o = new Uint8Array(a), s = 0;
|
|
2069
|
-
for (let e of i) o.set(e, s), s += e.byteLength;
|
|
2070
|
-
return o;
|
|
2071
|
-
})();
|
|
2072
|
-
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
2073
|
-
let o;
|
|
2074
|
-
try {
|
|
2075
|
-
let e = new TextDecoder(), t = JSON.parse(e.decode(a));
|
|
2076
|
-
o = typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
2077
|
-
} catch {
|
|
2078
|
-
o = null;
|
|
2079
|
-
}
|
|
2080
|
-
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
2081
|
-
let s = String(o.request_id ?? "").trim(), c = String(o.reviewed_by ?? "").trim() || null, l = String(o.bootstrap_grant_seed_device_id ?? "").trim(), u = String(o.bootstrap_grant_expires_at ?? "").trim();
|
|
2082
|
-
if (!s) return e.json({ error: "request_id_required" }, 400);
|
|
2083
|
-
let d = [l, u].filter(Boolean).length;
|
|
2084
|
-
if (d > 0 && d < 2) return e.json({ error: "bootstrap_grant_seed_device_id_and_expires_at_required_together" }, 400);
|
|
2085
|
-
let f = n.createStore();
|
|
2086
|
-
try {
|
|
2087
|
-
let n = await f.reviewJoinRequest({
|
|
2088
|
-
requestId: s,
|
|
2089
|
-
approved: t,
|
|
2090
|
-
reviewedBy: c,
|
|
2091
|
-
bootstrapGrant: t && l && u ? {
|
|
2092
|
-
seedDeviceId: l,
|
|
2093
|
-
expiresAt: u,
|
|
2094
|
-
createdBy: c
|
|
2095
|
-
} : null
|
|
2096
|
-
});
|
|
2097
|
-
return n ? n._no_transition ? e.json({
|
|
2098
|
-
error: "request_not_pending",
|
|
2099
|
-
status: n.status
|
|
2100
|
-
}, 409) : e.json({
|
|
2101
|
-
ok: !0,
|
|
2102
|
-
request: n
|
|
2103
|
-
}) : e.json({ error: "request_not_found" }, 404);
|
|
2104
|
-
} finally {
|
|
2105
|
-
await f.close();
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
//#endregion
|
|
2109
|
-
export { q as a, H as c, t as d, K as i, Oe as l, J as n, Ne as o, Pe as r, De as s, Be as t, U as u };
|
|
2110
|
-
|
|
2111
|
-
//# sourceMappingURL=coordinator-api-hZ1RVJUN.js.map
|