@codemem/core 0.29.3 → 0.30.0-alpha.2
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 +27 -1
- package/dist/api-types.d.ts.map +1 -1
- package/dist/better-sqlite-coordinator-store.d.ts +10 -1
- package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
- package/dist/coordinator-actions.d.ts +58 -1
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/{coordinator-api-Dbgsu1O8.js → coordinator-api-D6UhwKON.js} +393 -123
- package/dist/coordinator-api-D6UhwKON.js.map +1 -0
- package/dist/coordinator-api.d.ts.map +1 -1
- package/dist/coordinator-store-contract.d.ts +114 -0
- package/dist/coordinator-store-contract.d.ts.map +1 -1
- package/dist/coordinator-store-test-harness.d.ts.map +1 -1
- package/dist/coordinator-store.d.ts +1 -1
- package/dist/coordinator-store.d.ts.map +1 -1
- package/dist/d1-coordinator-store.d.ts +10 -1
- package/dist/d1-coordinator-store.d.ts.map +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/export-import.d.ts.map +1 -1
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6199 -4306
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +240 -47
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/schema.d.ts +5166 -2662
- package/dist/schema.d.ts.map +1 -1
- package/dist/scope-backfill.d.ts +78 -0
- package/dist/scope-backfill.d.ts.map +1 -0
- package/dist/scope-membership-cache.d.ts +78 -0
- package/dist/scope-membership-cache.d.ts.map +1 -0
- package/dist/scope-membership-semantics.d.ts +25 -0
- package/dist/scope-membership-semantics.d.ts.map +1 -0
- package/dist/scope-resolution.d.ts +40 -0
- package/dist/scope-resolution.d.ts.map +1 -0
- package/dist/scope-stamping.d.ts +10 -0
- package/dist/scope-stamping.d.ts.map +1 -0
- package/dist/search.d.ts +2 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/store.d.ts +19 -15
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-bootstrap.d.ts +6 -4
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-capability.d.ts +14 -0
- package/dist/sync-capability.d.ts.map +1 -0
- package/dist/sync-daemon.d.ts +12 -1
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts +94 -11
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-retention-runner.d.ts +1 -0
- package/dist/sync-retention-runner.d.ts.map +1 -1
- package/dist/sync-scope-protocol.d.ts +32 -0
- package/dist/sync-scope-protocol.d.ts.map +1 -0
- package/dist/test-schema.generated.d.ts +1 -1
- package/dist/test-schema.generated.d.ts.map +1 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vectors.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/coordinator-api-Dbgsu1O8.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash as e } from "node:crypto";
|
|
2
|
-
//#region ../../node_modules/.pnpm/hono@4.12.
|
|
2
|
+
//#region ../../node_modules/.pnpm/hono@4.12.16/node_modules/hono/dist/compose.js
|
|
3
3
|
var t = (e, t, n) => (r, i) => {
|
|
4
4
|
let a = -1;
|
|
5
5
|
return o(0);
|
|
@@ -358,13 +358,13 @@ var o = (e, t, n) => {
|
|
|
358
358
|
"delete",
|
|
359
359
|
"options",
|
|
360
360
|
"patch"
|
|
361
|
-
], O = "Can not add a route since the matcher is already built.", k = class extends Error {}, se = "__COMPOSED_HANDLER",
|
|
361
|
+
], O = "Can not add a route since the matcher is already built.", k = class extends Error {}, se = "__COMPOSED_HANDLER", ce = (e) => e.text("404 Not Found", 404), A = (e, t) => {
|
|
362
362
|
if ("getResponse" in e) {
|
|
363
363
|
let n = e.getResponse();
|
|
364
364
|
return t.newResponse(n.body, n);
|
|
365
365
|
}
|
|
366
366
|
return console.error(e), t.text("Internal Server Error", 500);
|
|
367
|
-
},
|
|
367
|
+
}, le = class e {
|
|
368
368
|
get;
|
|
369
369
|
post;
|
|
370
370
|
put;
|
|
@@ -405,13 +405,13 @@ var o = (e, t, n) => {
|
|
|
405
405
|
});
|
|
406
406
|
return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
|
|
407
407
|
}
|
|
408
|
-
#n =
|
|
409
|
-
errorHandler =
|
|
408
|
+
#n = ce;
|
|
409
|
+
errorHandler = A;
|
|
410
410
|
route(e, n) {
|
|
411
411
|
let r = this.basePath(e);
|
|
412
412
|
return n.routes.map((e) => {
|
|
413
413
|
let i;
|
|
414
|
-
n.errorHandler ===
|
|
414
|
+
n.errorHandler === A ? i = e.handler : (i = async (r, i) => (await t([], n.errorHandler)(r, () => e.handler(r, i))).res, i[se] = e.handler), r.#r(e.method, e.path, i);
|
|
415
415
|
}), this;
|
|
416
416
|
}
|
|
417
417
|
basePath(e) {
|
|
@@ -497,31 +497,31 @@ var o = (e, t, n) => {
|
|
|
497
497
|
e.respondWith(this.#a(e.request, e, void 0, e.request.method));
|
|
498
498
|
});
|
|
499
499
|
};
|
|
500
|
-
},
|
|
501
|
-
function
|
|
500
|
+
}, j = [];
|
|
501
|
+
function ue(e, t) {
|
|
502
502
|
let n = this.buildAllMatchers(), r = ((e, t) => {
|
|
503
503
|
let r = n[e] || n.ALL, i = r[2][t];
|
|
504
504
|
if (i) return i;
|
|
505
505
|
let a = t.match(r[0]);
|
|
506
|
-
if (!a) return [[],
|
|
506
|
+
if (!a) return [[], j];
|
|
507
507
|
let o = a.indexOf("", 1);
|
|
508
508
|
return [r[1][o], a];
|
|
509
509
|
});
|
|
510
510
|
return this.match = r, r(e, t);
|
|
511
511
|
}
|
|
512
512
|
//#endregion
|
|
513
|
-
//#region ../../node_modules/.pnpm/hono@4.12.
|
|
514
|
-
var
|
|
515
|
-
function
|
|
516
|
-
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e ===
|
|
513
|
+
//#region ../../node_modules/.pnpm/hono@4.12.16/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
514
|
+
var M = "[^/]+", N = ".*", P = "(?:|/.*)", F = /* @__PURE__ */ Symbol(), de = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
515
|
+
function fe(e, t) {
|
|
516
|
+
return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === N || e === P ? 1 : t === N || t === P ? -1 : e === M ? 1 : t === M ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
|
|
517
517
|
}
|
|
518
|
-
var
|
|
518
|
+
var pe = class e {
|
|
519
519
|
#e;
|
|
520
520
|
#t;
|
|
521
521
|
#n = /* @__PURE__ */ Object.create(null);
|
|
522
522
|
insert(t, n, r, i, a) {
|
|
523
523
|
if (t.length === 0) {
|
|
524
|
-
if (this.#e !== void 0) throw
|
|
524
|
+
if (this.#e !== void 0) throw F;
|
|
525
525
|
if (a) return;
|
|
526
526
|
this.#e = n;
|
|
527
527
|
return;
|
|
@@ -529,42 +529,42 @@ var de = class e {
|
|
|
529
529
|
let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
|
|
530
530
|
"",
|
|
531
531
|
"",
|
|
532
|
-
|
|
532
|
+
N
|
|
533
533
|
] : [
|
|
534
534
|
"",
|
|
535
535
|
"",
|
|
536
|
-
|
|
536
|
+
M
|
|
537
537
|
] : o === "/*" ? [
|
|
538
538
|
"",
|
|
539
539
|
"",
|
|
540
|
-
|
|
540
|
+
P
|
|
541
541
|
] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
|
|
542
542
|
if (c) {
|
|
543
|
-
let t = c[1], n = c[2] ||
|
|
544
|
-
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw
|
|
543
|
+
let t = c[1], n = c[2] || M;
|
|
544
|
+
if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw F;
|
|
545
545
|
if (l = this.#n[n], !l) {
|
|
546
|
-
if (Object.keys(this.#n).some((e) => e !==
|
|
546
|
+
if (Object.keys(this.#n).some((e) => e !== N && e !== P)) throw F;
|
|
547
547
|
if (a) return;
|
|
548
548
|
l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
|
|
549
549
|
}
|
|
550
550
|
!a && t !== "" && r.push([t, l.#t]);
|
|
551
551
|
} else if (l = this.#n[o], !l) {
|
|
552
|
-
if (Object.keys(this.#n).some((e) => e.length > 1 && e !==
|
|
552
|
+
if (Object.keys(this.#n).some((e) => e.length > 1 && e !== N && e !== P)) throw F;
|
|
553
553
|
if (a) return;
|
|
554
554
|
l = this.#n[o] = new e();
|
|
555
555
|
}
|
|
556
556
|
l.insert(s, n, r, i, a);
|
|
557
557
|
}
|
|
558
558
|
buildRegExpStr() {
|
|
559
|
-
let e = Object.keys(this.#n).sort(
|
|
559
|
+
let e = Object.keys(this.#n).sort(fe).map((e) => {
|
|
560
560
|
let t = this.#n[e];
|
|
561
|
-
return (typeof t.#t == "number" ? `(${e})@${t.#t}` :
|
|
561
|
+
return (typeof t.#t == "number" ? `(${e})@${t.#t}` : de.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
|
|
562
562
|
});
|
|
563
563
|
return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
|
|
564
564
|
}
|
|
565
|
-
},
|
|
565
|
+
}, me = class {
|
|
566
566
|
#e = { varIndex: 0 };
|
|
567
|
-
#t = new
|
|
567
|
+
#t = new pe();
|
|
568
568
|
insert(e, t, n) {
|
|
569
569
|
let r = [], i = [];
|
|
570
570
|
for (let t = 0;;) {
|
|
@@ -598,29 +598,29 @@ var de = class e {
|
|
|
598
598
|
r
|
|
599
599
|
];
|
|
600
600
|
}
|
|
601
|
-
},
|
|
601
|
+
}, he = [
|
|
602
602
|
/^$/,
|
|
603
603
|
[],
|
|
604
604
|
/* @__PURE__ */ Object.create(null)
|
|
605
|
-
],
|
|
606
|
-
function
|
|
607
|
-
return
|
|
605
|
+
], I = /* @__PURE__ */ Object.create(null);
|
|
606
|
+
function L(e) {
|
|
607
|
+
return I[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
|
|
608
608
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
609
|
+
function ge() {
|
|
610
|
+
I = /* @__PURE__ */ Object.create(null);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
let t = new
|
|
614
|
-
if (e.length === 0) return
|
|
612
|
+
function _e(e) {
|
|
613
|
+
let t = new me(), n = [];
|
|
614
|
+
if (e.length === 0) return he;
|
|
615
615
|
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);
|
|
616
616
|
for (let e = 0, a = -1, o = r.length; e < o; e++) {
|
|
617
617
|
let [o, s, c] = r[e];
|
|
618
|
-
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]),
|
|
618
|
+
o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), j] : a++;
|
|
619
619
|
let l;
|
|
620
620
|
try {
|
|
621
621
|
l = t.insert(s, a, o);
|
|
622
622
|
} catch (e) {
|
|
623
|
-
throw e ===
|
|
623
|
+
throw e === F ? new k(s) : e;
|
|
624
624
|
}
|
|
625
625
|
o || (n[a] = c.map(([e, t]) => {
|
|
626
626
|
let n = /* @__PURE__ */ Object.create(null);
|
|
@@ -646,12 +646,12 @@ function me(e) {
|
|
|
646
646
|
i
|
|
647
647
|
];
|
|
648
648
|
}
|
|
649
|
-
function
|
|
649
|
+
function R(e, t) {
|
|
650
650
|
if (e) {
|
|
651
|
-
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (
|
|
651
|
+
for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (L(n).test(t)) return [...e[n]];
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
|
-
var
|
|
654
|
+
var ve = class {
|
|
655
655
|
name = "RegExpRouter";
|
|
656
656
|
#e;
|
|
657
657
|
#t;
|
|
@@ -668,10 +668,10 @@ var he = class {
|
|
|
668
668
|
}), t === "/*" && (t = "*");
|
|
669
669
|
let a = (t.match(/\/:/g) || []).length;
|
|
670
670
|
if (/\*$/.test(t)) {
|
|
671
|
-
let o =
|
|
671
|
+
let o = L(t);
|
|
672
672
|
e === "ALL" ? Object.keys(r).forEach((e) => {
|
|
673
|
-
r[e][t] ||=
|
|
674
|
-
}) : r[e][t] ||=
|
|
673
|
+
r[e][t] ||= R(r[e], t) || R(r.ALL, t) || [];
|
|
674
|
+
}) : r[e][t] ||= R(r[e], t) || R(r.ALL, t) || [], Object.keys(r).forEach((t) => {
|
|
675
675
|
(e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
|
|
676
676
|
o.test(e) && r[t][e].push([n, a]);
|
|
677
677
|
});
|
|
@@ -684,25 +684,25 @@ var he = class {
|
|
|
684
684
|
for (let t = 0, s = o.length; t < s; t++) {
|
|
685
685
|
let c = o[t];
|
|
686
686
|
Object.keys(i).forEach((o) => {
|
|
687
|
-
(e === "ALL" || e === o) && (i[o][c] ||= [...
|
|
687
|
+
(e === "ALL" || e === o) && (i[o][c] ||= [...R(r[o], c) || R(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
|
|
688
688
|
});
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
|
-
match =
|
|
691
|
+
match = ue;
|
|
692
692
|
buildAllMatchers() {
|
|
693
693
|
let e = /* @__PURE__ */ Object.create(null);
|
|
694
694
|
return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
|
|
695
695
|
e[t] ||= this.#n(t);
|
|
696
|
-
}), this.#e = this.#t = void 0,
|
|
696
|
+
}), this.#e = this.#t = void 0, ge(), e;
|
|
697
697
|
}
|
|
698
698
|
#n(e) {
|
|
699
699
|
let t = [], n = e === "ALL";
|
|
700
700
|
return [this.#e, this.#t].forEach((r) => {
|
|
701
701
|
let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
|
|
702
702
|
i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
|
|
703
|
-
}), n ?
|
|
703
|
+
}), n ? _e(t) : null;
|
|
704
704
|
}
|
|
705
|
-
},
|
|
705
|
+
}, ye = class {
|
|
706
706
|
name = "SmartRouter";
|
|
707
707
|
#e = [];
|
|
708
708
|
#t = [];
|
|
@@ -739,15 +739,15 @@ var he = class {
|
|
|
739
739
|
if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
|
|
740
740
|
return this.#e[0];
|
|
741
741
|
}
|
|
742
|
-
},
|
|
742
|
+
}, z = /* @__PURE__ */ Object.create(null), be = (e) => {
|
|
743
743
|
for (let t in e) return !0;
|
|
744
744
|
return !1;
|
|
745
|
-
},
|
|
745
|
+
}, xe = class e {
|
|
746
746
|
#e;
|
|
747
747
|
#t;
|
|
748
748
|
#n;
|
|
749
749
|
#r = 0;
|
|
750
|
-
#i =
|
|
750
|
+
#i = z;
|
|
751
751
|
constructor(e, t, n) {
|
|
752
752
|
if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
|
|
753
753
|
let n = /* @__PURE__ */ Object.create(null);
|
|
@@ -779,7 +779,7 @@ var he = class {
|
|
|
779
779
|
#a(e, t, n, r, i) {
|
|
780
780
|
for (let a = 0, o = t.#e.length; a < o; a++) {
|
|
781
781
|
let o = t.#e[a], s = o[n] || o.ALL, c = {};
|
|
782
|
-
if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !==
|
|
782
|
+
if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== z || i && i !== z)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
|
|
783
783
|
let t = s.possibleKeys[e], n = c[s.score];
|
|
784
784
|
s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
|
|
785
785
|
}
|
|
@@ -787,7 +787,7 @@ var he = class {
|
|
|
787
787
|
}
|
|
788
788
|
search(e, t) {
|
|
789
789
|
let n = [];
|
|
790
|
-
this.#i =
|
|
790
|
+
this.#i = z;
|
|
791
791
|
let r = [this], i = c(t), a = [], o = i.length, s = null;
|
|
792
792
|
for (let c = 0; c < o; c++) {
|
|
793
793
|
let l = i[c], u = c === o - 1, d = [];
|
|
@@ -795,7 +795,7 @@ var he = class {
|
|
|
795
795
|
let p = r[f], m = p.#t[l];
|
|
796
796
|
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));
|
|
797
797
|
for (let r = 0, f = p.#n.length; r < f; r++) {
|
|
798
|
-
let f = p.#n[r], m = p.#i ===
|
|
798
|
+
let f = p.#n[r], m = p.#i === z ? {} : { ...p.#i };
|
|
799
799
|
if (f === "*") {
|
|
800
800
|
let t = p.#t["*"];
|
|
801
801
|
t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
|
|
@@ -812,7 +812,7 @@ var he = class {
|
|
|
812
812
|
}
|
|
813
813
|
let r = t.substring(s[c]), l = _.exec(r);
|
|
814
814
|
if (l) {
|
|
815
|
-
if (m[g] = l[0], this.#a(n, v, e, p.#i, m),
|
|
815
|
+
if (m[g] = l[0], this.#a(n, v, e, p.#i, m), be(v.#t)) {
|
|
816
816
|
v.#i = m;
|
|
817
817
|
let e = l[0].match(/\//)?.length ?? 0;
|
|
818
818
|
(a[e] ||= []).push(v);
|
|
@@ -828,11 +828,11 @@ var he = class {
|
|
|
828
828
|
}
|
|
829
829
|
return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
|
|
830
830
|
}
|
|
831
|
-
},
|
|
831
|
+
}, Se = class {
|
|
832
832
|
name = "TrieRouter";
|
|
833
833
|
#e;
|
|
834
834
|
constructor() {
|
|
835
|
-
this.#e = new
|
|
835
|
+
this.#e = new xe();
|
|
836
836
|
}
|
|
837
837
|
add(e, t, n) {
|
|
838
838
|
let r = y(t);
|
|
@@ -845,43 +845,43 @@ var he = class {
|
|
|
845
845
|
match(e, t) {
|
|
846
846
|
return this.#e.search(e, t);
|
|
847
847
|
}
|
|
848
|
-
},
|
|
848
|
+
}, Ce = class extends le {
|
|
849
849
|
constructor(e = {}) {
|
|
850
|
-
super(e), this.router = e.router ?? new
|
|
850
|
+
super(e), this.router = e.router ?? new ye({ routers: [new ve(), new Se()] });
|
|
851
851
|
}
|
|
852
852
|
};
|
|
853
853
|
//#endregion
|
|
854
854
|
//#region src/coordinator-invites.ts
|
|
855
|
-
function
|
|
855
|
+
function we(e) {
|
|
856
856
|
let t = "";
|
|
857
857
|
for (let n of e) t += String.fromCharCode(n);
|
|
858
858
|
return btoa(t);
|
|
859
859
|
}
|
|
860
|
-
function
|
|
860
|
+
function Te(e) {
|
|
861
861
|
let t = atob(e), n = new Uint8Array(t.length);
|
|
862
862
|
for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
|
|
863
863
|
return n;
|
|
864
864
|
}
|
|
865
|
-
function
|
|
865
|
+
function Ee(e) {
|
|
866
866
|
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
867
867
|
}
|
|
868
|
-
function
|
|
868
|
+
function De(e) {
|
|
869
869
|
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
870
870
|
return t + "=".repeat((4 - t.length % 4) % 4);
|
|
871
871
|
}
|
|
872
|
-
function
|
|
872
|
+
function B(e) {
|
|
873
873
|
let t = JSON.stringify(e);
|
|
874
|
-
return
|
|
874
|
+
return Ee(we(new TextEncoder().encode(t)));
|
|
875
875
|
}
|
|
876
|
-
function
|
|
877
|
-
let t = new TextDecoder().decode(
|
|
876
|
+
function Oe(e) {
|
|
877
|
+
let t = new TextDecoder().decode(Te(De(e))), n = JSON.parse(t);
|
|
878
878
|
if (typeof n != "object" || !n) throw Error("invalid invite payload");
|
|
879
879
|
return n;
|
|
880
880
|
}
|
|
881
|
-
function
|
|
881
|
+
function V(e) {
|
|
882
882
|
return `codemem://join?invite=${encodeURIComponent(e)}`;
|
|
883
883
|
}
|
|
884
|
-
function
|
|
884
|
+
function ke(e) {
|
|
885
885
|
let t = e.trim();
|
|
886
886
|
if (t.startsWith("codemem://")) {
|
|
887
887
|
let e = new URL(t).searchParams.get("invite") ?? "";
|
|
@@ -892,20 +892,20 @@ function Te(e) {
|
|
|
892
892
|
}
|
|
893
893
|
//#endregion
|
|
894
894
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
|
|
895
|
-
function
|
|
895
|
+
function Ae(e) {
|
|
896
896
|
let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
|
|
897
897
|
return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
|
|
898
898
|
}
|
|
899
|
-
function
|
|
900
|
-
let [e, t] =
|
|
899
|
+
function H() {
|
|
900
|
+
let [e, t] = Ae();
|
|
901
901
|
return e * 1e3 + Math.floor(t / 1e6);
|
|
902
902
|
}
|
|
903
|
-
function
|
|
903
|
+
function U(e) {
|
|
904
904
|
return new Promise((t) => setTimeout(t, e));
|
|
905
905
|
}
|
|
906
906
|
//#endregion
|
|
907
907
|
//#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
|
|
908
|
-
var
|
|
908
|
+
var je = class {
|
|
909
909
|
bucketSize;
|
|
910
910
|
tokensPerInterval;
|
|
911
911
|
interval;
|
|
@@ -932,13 +932,13 @@ var De = class {
|
|
|
932
932
|
default: throw Error("Invalid interval " + n);
|
|
933
933
|
}
|
|
934
934
|
else this.interval = n;
|
|
935
|
-
this.parentBucket = r, this.content = 0, this.lastDrip =
|
|
935
|
+
this.parentBucket = r, this.content = 0, this.lastDrip = H();
|
|
936
936
|
}
|
|
937
937
|
async removeTokens(e) {
|
|
938
938
|
if (this.bucketSize === 0) return Infinity;
|
|
939
939
|
if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
|
|
940
940
|
this.drip();
|
|
941
|
-
let t = async () => (await
|
|
941
|
+
let t = async () => (await U(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
|
|
942
942
|
if (e > this.content) return t();
|
|
943
943
|
if (this.parentBucket != null) {
|
|
944
944
|
let n = await this.parentBucket.removeTokens(e);
|
|
@@ -953,30 +953,30 @@ var De = class {
|
|
|
953
953
|
let e = this.content;
|
|
954
954
|
return this.content = this.bucketSize, this.content > e;
|
|
955
955
|
}
|
|
956
|
-
let e =
|
|
956
|
+
let e = H(), t = Math.max(e - this.lastDrip, 0);
|
|
957
957
|
this.lastDrip = e;
|
|
958
958
|
let n = t * (this.tokensPerInterval / this.interval), r = this.content;
|
|
959
959
|
return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
|
|
960
960
|
}
|
|
961
|
-
},
|
|
961
|
+
}, Me = class {
|
|
962
962
|
tokenBucket;
|
|
963
963
|
curIntervalStart;
|
|
964
964
|
tokensThisInterval;
|
|
965
965
|
fireImmediately;
|
|
966
966
|
constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
|
|
967
|
-
this.tokenBucket = new
|
|
967
|
+
this.tokenBucket = new je({
|
|
968
968
|
bucketSize: e,
|
|
969
969
|
tokensPerInterval: e,
|
|
970
970
|
interval: t
|
|
971
|
-
}), this.tokenBucket.content = e, this.curIntervalStart =
|
|
971
|
+
}), this.tokenBucket.content = e, this.curIntervalStart = H(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
|
|
972
972
|
}
|
|
973
973
|
async removeTokens(e) {
|
|
974
974
|
if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
|
|
975
|
-
let t =
|
|
975
|
+
let t = H();
|
|
976
976
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
|
|
977
977
|
if (this.fireImmediately) return -1;
|
|
978
978
|
{
|
|
979
|
-
await
|
|
979
|
+
await U(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
|
|
980
980
|
let n = await this.tokenBucket.removeTokens(e);
|
|
981
981
|
return this.tokensThisInterval += e, n;
|
|
982
982
|
}
|
|
@@ -986,7 +986,7 @@ var De = class {
|
|
|
986
986
|
}
|
|
987
987
|
tryRemoveTokens(e) {
|
|
988
988
|
if (e > this.tokenBucket.bucketSize) return !1;
|
|
989
|
-
let t =
|
|
989
|
+
let t = H();
|
|
990
990
|
if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
|
|
991
991
|
let n = this.tokenBucket.tryRemoveTokens(e);
|
|
992
992
|
return n && (this.tokensThisInterval += e), n;
|
|
@@ -997,7 +997,7 @@ var De = class {
|
|
|
997
997
|
};
|
|
998
998
|
//#endregion
|
|
999
999
|
//#region src/request-rate-limit.ts
|
|
1000
|
-
function
|
|
1000
|
+
function Ne(e = {}) {
|
|
1001
1001
|
let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
|
|
1002
1002
|
function a(e) {
|
|
1003
1003
|
return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
|
|
@@ -1014,7 +1014,7 @@ function ke(e = {}) {
|
|
|
1014
1014
|
o(l);
|
|
1015
1015
|
let u = `${c}:${e}`, d = r.get(u);
|
|
1016
1016
|
return d || (d = {
|
|
1017
|
-
limiter: new
|
|
1017
|
+
limiter: new Me({
|
|
1018
1018
|
tokensPerInterval: c,
|
|
1019
1019
|
interval: t,
|
|
1020
1020
|
fireImmediately: !0
|
|
@@ -1030,16 +1030,43 @@ function ke(e = {}) {
|
|
|
1030
1030
|
} };
|
|
1031
1031
|
}
|
|
1032
1032
|
//#endregion
|
|
1033
|
+
//#region src/scope-membership-semantics.ts
|
|
1034
|
+
var W = "Revocation prevents future sync only; it does not remove data already copied to the revoked device.";
|
|
1035
|
+
function Pe(e) {
|
|
1036
|
+
let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
|
|
1037
|
+
return t == null || n == null ? {
|
|
1038
|
+
membership_epoch: t,
|
|
1039
|
+
required_epoch: n,
|
|
1040
|
+
stale: !1,
|
|
1041
|
+
reason: "unknown_epoch"
|
|
1042
|
+
} : {
|
|
1043
|
+
membership_epoch: t,
|
|
1044
|
+
required_epoch: n,
|
|
1045
|
+
stale: t < n,
|
|
1046
|
+
reason: t < n ? "stale_epoch" : "current"
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function G(e) {
|
|
1050
|
+
return {
|
|
1051
|
+
scope_id: e.scopeId,
|
|
1052
|
+
device_id: e.deviceId,
|
|
1053
|
+
membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
|
|
1054
|
+
prevents_future_sync: !0,
|
|
1055
|
+
deletes_already_copied_data: !1,
|
|
1056
|
+
message: W
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
//#endregion
|
|
1033
1060
|
//#region src/sync-auth-constants.ts
|
|
1034
|
-
var
|
|
1061
|
+
var K = 300;
|
|
1035
1062
|
//#endregion
|
|
1036
1063
|
//#region src/sync-fingerprint.ts
|
|
1037
|
-
function
|
|
1064
|
+
function q(t) {
|
|
1038
1065
|
return e("sha256").update(t, "utf-8").digest("hex");
|
|
1039
1066
|
}
|
|
1040
1067
|
//#endregion
|
|
1041
1068
|
//#region src/coordinator-api.ts
|
|
1042
|
-
var
|
|
1069
|
+
var J = 64 * 1024, Y = "X-Codemem-Coordinator-Admin", X = "X-Codemem-Coordinator-Admin-Actor", Fe = 120, Ie = 30;
|
|
1043
1070
|
function Z(e, t) {
|
|
1044
1071
|
let n = t.adminSecret();
|
|
1045
1072
|
if (!n) return {
|
|
@@ -1058,14 +1085,14 @@ function Z(e, t) {
|
|
|
1058
1085
|
error: "missing_admin_header"
|
|
1059
1086
|
};
|
|
1060
1087
|
}
|
|
1061
|
-
function
|
|
1088
|
+
function Le(e) {
|
|
1062
1089
|
let t = new URL(e);
|
|
1063
1090
|
return t.search ? `${t.pathname}${t.search}` : t.pathname;
|
|
1064
1091
|
}
|
|
1065
|
-
async function
|
|
1092
|
+
async function Re(e, t, n, r) {
|
|
1066
1093
|
return await e.recordNonce(t, n, r);
|
|
1067
1094
|
}
|
|
1068
|
-
async function
|
|
1095
|
+
async function ze(e, t) {
|
|
1069
1096
|
await e.cleanupNonces(t);
|
|
1070
1097
|
}
|
|
1071
1098
|
async function Q(e, t, n, r) {
|
|
@@ -1085,7 +1112,7 @@ async function Q(e, t, n, r) {
|
|
|
1085
1112
|
try {
|
|
1086
1113
|
l = await n({
|
|
1087
1114
|
method: r.method,
|
|
1088
|
-
pathWithQuery:
|
|
1115
|
+
pathWithQuery: Le(r.url),
|
|
1089
1116
|
bodyBytes: r.body,
|
|
1090
1117
|
timestamp: o,
|
|
1091
1118
|
nonce: s,
|
|
@@ -1106,7 +1133,7 @@ async function Q(e, t, n, r) {
|
|
|
1106
1133
|
enrollment: null
|
|
1107
1134
|
};
|
|
1108
1135
|
let u = t.now();
|
|
1109
|
-
return await
|
|
1136
|
+
return await Re(e, i, s, u) ? (await ze(e, (/* @__PURE__ */ new Date(new Date(u).getTime() - 300 * 2 * 1e3)).toISOString()), {
|
|
1110
1137
|
ok: !0,
|
|
1111
1138
|
error: "ok",
|
|
1112
1139
|
enrollment: c
|
|
@@ -1116,9 +1143,9 @@ async function Q(e, t, n, r) {
|
|
|
1116
1143
|
enrollment: null
|
|
1117
1144
|
};
|
|
1118
1145
|
}
|
|
1119
|
-
function
|
|
1146
|
+
function Be(e) {
|
|
1120
1147
|
if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
|
|
1121
|
-
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ??
|
|
1148
|
+
let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? Ne(), 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 Ce(), d = new TextDecoder();
|
|
1122
1149
|
function f(e, t, n) {
|
|
1123
1150
|
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);
|
|
1124
1151
|
return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
|
|
@@ -1128,7 +1155,7 @@ function Ie(e) {
|
|
|
1128
1155
|
}
|
|
1129
1156
|
async function p(e) {
|
|
1130
1157
|
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1131
|
-
if (Number.isFinite(t) && t >
|
|
1158
|
+
if (Number.isFinite(t) && t > J) return null;
|
|
1132
1159
|
let n = e.req.raw.body;
|
|
1133
1160
|
if (!n) return new Uint8Array();
|
|
1134
1161
|
let r = n.getReader(), i = [], a = 0;
|
|
@@ -1137,7 +1164,7 @@ function Ie(e) {
|
|
|
1137
1164
|
let { done: e, value: t } = await r.read();
|
|
1138
1165
|
if (e) break;
|
|
1139
1166
|
if (t) {
|
|
1140
|
-
if (a += t.byteLength, a >
|
|
1167
|
+
if (a += t.byteLength, a > J) return await r.cancel(), null;
|
|
1141
1168
|
i.push(t);
|
|
1142
1169
|
}
|
|
1143
1170
|
}
|
|
@@ -1156,6 +1183,60 @@ function Ie(e) {
|
|
|
1156
1183
|
return null;
|
|
1157
1184
|
}
|
|
1158
1185
|
}
|
|
1186
|
+
function h(e, t) {
|
|
1187
|
+
let n = e[t];
|
|
1188
|
+
return n == null ? null : String(n).trim() || null;
|
|
1189
|
+
}
|
|
1190
|
+
function g(e) {
|
|
1191
|
+
return e?.trim() || null;
|
|
1192
|
+
}
|
|
1193
|
+
function _(e, t) {
|
|
1194
|
+
let n = e[t];
|
|
1195
|
+
if (n == null || n === "") return null;
|
|
1196
|
+
if (typeof n != "number" && typeof n != "string") return NaN;
|
|
1197
|
+
if (typeof n == "string") {
|
|
1198
|
+
let e = n.trim();
|
|
1199
|
+
if (!e) return NaN;
|
|
1200
|
+
let t = Number(e);
|
|
1201
|
+
return Number.isFinite(t) ? Math.trunc(t) : NaN;
|
|
1202
|
+
}
|
|
1203
|
+
let r = n;
|
|
1204
|
+
return Number.isFinite(r) ? Math.trunc(r) : NaN;
|
|
1205
|
+
}
|
|
1206
|
+
function v(e) {
|
|
1207
|
+
return [
|
|
1208
|
+
"1",
|
|
1209
|
+
"true",
|
|
1210
|
+
"yes"
|
|
1211
|
+
].includes(String(e ?? "").trim().toLowerCase());
|
|
1212
|
+
}
|
|
1213
|
+
async function y(e, t, n) {
|
|
1214
|
+
if (!t) return n.json({ error: "group_id_required" }, 400);
|
|
1215
|
+
let r = await e.getGroup(t);
|
|
1216
|
+
return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
|
|
1217
|
+
}
|
|
1218
|
+
async function b(e, t, n, r) {
|
|
1219
|
+
let i = await y(e, t, r);
|
|
1220
|
+
if (i) return {
|
|
1221
|
+
scope: null,
|
|
1222
|
+
response: i
|
|
1223
|
+
};
|
|
1224
|
+
if (!n) return {
|
|
1225
|
+
scope: null,
|
|
1226
|
+
response: r.json({ error: "scope_id_required" }, 400)
|
|
1227
|
+
};
|
|
1228
|
+
let a = (await e.listScopes({
|
|
1229
|
+
groupId: t,
|
|
1230
|
+
includeInactive: !0
|
|
1231
|
+
})).find((e) => e.scope_id === n) ?? null;
|
|
1232
|
+
return a ? {
|
|
1233
|
+
scope: a,
|
|
1234
|
+
response: null
|
|
1235
|
+
} : {
|
|
1236
|
+
scope: null,
|
|
1237
|
+
response: r.json({ error: "scope_not_found" }, 404)
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1159
1240
|
return u.post("/v1/presence", async (e) => {
|
|
1160
1241
|
let i = await p(e);
|
|
1161
1242
|
if (i == null) return e.json({ error: "body_too_large" }, 413);
|
|
@@ -1290,7 +1371,7 @@ function Ie(e) {
|
|
|
1290
1371
|
await c.close();
|
|
1291
1372
|
}
|
|
1292
1373
|
}), u.post("/v1/admin/devices", async (e) => {
|
|
1293
|
-
let r = Z(e.req.header(
|
|
1374
|
+
let r = Z(e.req.header(Y), t);
|
|
1294
1375
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1295
1376
|
let i = f(e, "admin", !0);
|
|
1296
1377
|
if (i) return i;
|
|
@@ -1300,7 +1381,7 @@ function Ie(e) {
|
|
|
1300
1381
|
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1301
1382
|
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;
|
|
1302
1383
|
if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
|
|
1303
|
-
if (
|
|
1384
|
+
if (q(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
1304
1385
|
let h = n();
|
|
1305
1386
|
try {
|
|
1306
1387
|
await h.createGroup(s), await h.enrollDevice(s, {
|
|
@@ -1314,7 +1395,7 @@ function Ie(e) {
|
|
|
1314
1395
|
}
|
|
1315
1396
|
return e.json({ ok: !0 });
|
|
1316
1397
|
}), u.get("/v1/admin/groups", async (e) => {
|
|
1317
|
-
let r = Z(e.req.header(
|
|
1398
|
+
let r = Z(e.req.header(Y), t);
|
|
1318
1399
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1319
1400
|
let i = f(e, "admin", !0);
|
|
1320
1401
|
if (i) return i;
|
|
@@ -1329,7 +1410,7 @@ function Ie(e) {
|
|
|
1329
1410
|
await o.close();
|
|
1330
1411
|
}
|
|
1331
1412
|
}), u.post("/v1/admin/groups", async (e) => {
|
|
1332
|
-
let r = Z(e.req.header(
|
|
1413
|
+
let r = Z(e.req.header(Y), t);
|
|
1333
1414
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1334
1415
|
let i = f(e, "admin", !0);
|
|
1335
1416
|
if (i) return i;
|
|
@@ -1349,7 +1430,7 @@ function Ie(e) {
|
|
|
1349
1430
|
await l.close();
|
|
1350
1431
|
}
|
|
1351
1432
|
}), u.post("/v1/admin/groups/rename", async (e) => {
|
|
1352
|
-
let r = Z(e.req.header(
|
|
1433
|
+
let r = Z(e.req.header(Y), t);
|
|
1353
1434
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1354
1435
|
let i = f(e, "admin", !0);
|
|
1355
1436
|
if (i) return i;
|
|
@@ -1369,7 +1450,7 @@ function Ie(e) {
|
|
|
1369
1450
|
await l.close();
|
|
1370
1451
|
}
|
|
1371
1452
|
}), u.post("/v1/admin/groups/archive", async (e) => {
|
|
1372
|
-
let r = Z(e.req.header(
|
|
1453
|
+
let r = Z(e.req.header(Y), t);
|
|
1373
1454
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1374
1455
|
let i = f(e, "admin", !0);
|
|
1375
1456
|
if (i) return i;
|
|
@@ -1389,7 +1470,7 @@ function Ie(e) {
|
|
|
1389
1470
|
await c.close();
|
|
1390
1471
|
}
|
|
1391
1472
|
}), u.post("/v1/admin/groups/unarchive", async (e) => {
|
|
1392
|
-
let r = Z(e.req.header(
|
|
1473
|
+
let r = Z(e.req.header(Y), t);
|
|
1393
1474
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1394
1475
|
let i = f(e, "admin", !0);
|
|
1395
1476
|
if (i) return i;
|
|
@@ -1408,8 +1489,197 @@ function Ie(e) {
|
|
|
1408
1489
|
} finally {
|
|
1409
1490
|
await c.close();
|
|
1410
1491
|
}
|
|
1492
|
+
}), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1493
|
+
let r = Z(e.req.header(Y), t);
|
|
1494
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1495
|
+
let i = f(e, "admin", !0);
|
|
1496
|
+
if (i) return i;
|
|
1497
|
+
let a = String(e.req.param("group_id") ?? "").trim(), o = n();
|
|
1498
|
+
try {
|
|
1499
|
+
let t = await y(o, a, e);
|
|
1500
|
+
if (t) return t;
|
|
1501
|
+
let n = v(e.req.query("include_inactive"));
|
|
1502
|
+
return e.json({ items: await o.listScopes({
|
|
1503
|
+
groupId: a,
|
|
1504
|
+
includeInactive: n
|
|
1505
|
+
}) });
|
|
1506
|
+
} finally {
|
|
1507
|
+
await o.close();
|
|
1508
|
+
}
|
|
1509
|
+
}), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
|
|
1510
|
+
let r = Z(e.req.header(Y), t);
|
|
1511
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1512
|
+
let i = f(e, "admin", !0);
|
|
1513
|
+
if (i) return i;
|
|
1514
|
+
let a = await p(e);
|
|
1515
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1516
|
+
let o = m(a);
|
|
1517
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1518
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
|
|
1519
|
+
if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
|
|
1520
|
+
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1521
|
+
let d = n();
|
|
1522
|
+
try {
|
|
1523
|
+
let t = await y(d, s, e);
|
|
1524
|
+
if (t) return t;
|
|
1525
|
+
let n = await d.createScope({
|
|
1526
|
+
scopeId: c,
|
|
1527
|
+
label: l,
|
|
1528
|
+
kind: h(o, "kind"),
|
|
1529
|
+
authorityType: h(o, "authority_type"),
|
|
1530
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
1531
|
+
groupId: s,
|
|
1532
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
1533
|
+
membershipEpoch: u,
|
|
1534
|
+
manifestHash: h(o, "manifest_hash"),
|
|
1535
|
+
status: h(o, "status")
|
|
1536
|
+
});
|
|
1537
|
+
return e.json({
|
|
1538
|
+
ok: !0,
|
|
1539
|
+
scope: n
|
|
1540
|
+
}, 201);
|
|
1541
|
+
} catch (t) {
|
|
1542
|
+
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1543
|
+
} finally {
|
|
1544
|
+
await d.close();
|
|
1545
|
+
}
|
|
1546
|
+
}), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
|
|
1547
|
+
let r = Z(e.req.header(Y), t);
|
|
1548
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1549
|
+
let i = f(e, "admin", !0);
|
|
1550
|
+
if (i) return i;
|
|
1551
|
+
let a = await p(e);
|
|
1552
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1553
|
+
let o = m(a);
|
|
1554
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1555
|
+
let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
|
|
1556
|
+
if (!c) return e.json({ error: "scope_id_required" }, 400);
|
|
1557
|
+
if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1558
|
+
let u = n();
|
|
1559
|
+
try {
|
|
1560
|
+
let t = await b(u, s, c, e);
|
|
1561
|
+
if (t.response) return t.response;
|
|
1562
|
+
let n = await u.updateScope({
|
|
1563
|
+
scopeId: c,
|
|
1564
|
+
label: o.label === void 0 ? void 0 : h(o, "label"),
|
|
1565
|
+
kind: o.kind === void 0 ? void 0 : h(o, "kind"),
|
|
1566
|
+
authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
|
|
1567
|
+
coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
|
|
1568
|
+
groupId: s,
|
|
1569
|
+
manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
|
|
1570
|
+
membershipEpoch: l,
|
|
1571
|
+
manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
|
|
1572
|
+
status: o.status === void 0 ? void 0 : h(o, "status")
|
|
1573
|
+
});
|
|
1574
|
+
return n ? e.json({
|
|
1575
|
+
ok: !0,
|
|
1576
|
+
scope: n
|
|
1577
|
+
}) : e.json({ error: "scope_not_found" }, 404);
|
|
1578
|
+
} catch (t) {
|
|
1579
|
+
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1580
|
+
} finally {
|
|
1581
|
+
await u.close();
|
|
1582
|
+
}
|
|
1583
|
+
}), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
1584
|
+
let r = Z(e.req.header(Y), t);
|
|
1585
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1586
|
+
let i = f(e, "admin", !0);
|
|
1587
|
+
if (i) return i;
|
|
1588
|
+
let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
|
|
1589
|
+
try {
|
|
1590
|
+
let t = await b(s, a, o, e);
|
|
1591
|
+
return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
|
|
1592
|
+
} finally {
|
|
1593
|
+
await s.close();
|
|
1594
|
+
}
|
|
1595
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
|
|
1596
|
+
let r = Z(e.req.header(Y), t);
|
|
1597
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1598
|
+
let i = f(e, "admin", !0);
|
|
1599
|
+
if (i) return i;
|
|
1600
|
+
let a = await p(e);
|
|
1601
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1602
|
+
let o = m(a);
|
|
1603
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1604
|
+
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");
|
|
1605
|
+
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
1606
|
+
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1607
|
+
let d = n();
|
|
1608
|
+
try {
|
|
1609
|
+
let t = await b(d, s, c, e);
|
|
1610
|
+
if (t.response) return t.response;
|
|
1611
|
+
if (t.scope?.status !== "active") return e.json({ error: "scope_not_active" }, 409);
|
|
1612
|
+
if (!await d.getEnrollment(s, l)) return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
|
|
1613
|
+
let n = await d.grantScopeMembership({
|
|
1614
|
+
scopeId: c,
|
|
1615
|
+
deviceId: l,
|
|
1616
|
+
role: h(o, "role"),
|
|
1617
|
+
membershipEpoch: u,
|
|
1618
|
+
coordinatorId: h(o, "coordinator_id"),
|
|
1619
|
+
groupId: s,
|
|
1620
|
+
manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
|
|
1621
|
+
manifestHash: h(o, "manifest_hash"),
|
|
1622
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
1623
|
+
actorType: "admin",
|
|
1624
|
+
actorId: g(e.req.header(X))
|
|
1625
|
+
});
|
|
1626
|
+
return e.json({
|
|
1627
|
+
ok: !0,
|
|
1628
|
+
membership: n
|
|
1629
|
+
}, 201);
|
|
1630
|
+
} catch (t) {
|
|
1631
|
+
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1632
|
+
} finally {
|
|
1633
|
+
await d.close();
|
|
1634
|
+
}
|
|
1635
|
+
}), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
|
|
1636
|
+
let r = Z(e.req.header(Y), t);
|
|
1637
|
+
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1638
|
+
let i = f(e, "admin", !0);
|
|
1639
|
+
if (i) return i;
|
|
1640
|
+
let a = await p(e);
|
|
1641
|
+
if (a == null) return e.json({ error: "body_too_large" }, 413);
|
|
1642
|
+
let o = a.byteLength > 0 ? m(a) : {};
|
|
1643
|
+
if (!o) return e.json({ error: "invalid_json" }, 400);
|
|
1644
|
+
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");
|
|
1645
|
+
if (!l) return e.json({ error: "device_id_required" }, 400);
|
|
1646
|
+
if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
|
|
1647
|
+
let d = n();
|
|
1648
|
+
try {
|
|
1649
|
+
let t = await b(d, s, c, e);
|
|
1650
|
+
if (t.response) return t.response;
|
|
1651
|
+
if (!await d.revokeScopeMembership({
|
|
1652
|
+
scopeId: c,
|
|
1653
|
+
deviceId: l,
|
|
1654
|
+
membershipEpoch: u,
|
|
1655
|
+
manifestHash: h(o, "manifest_hash"),
|
|
1656
|
+
signedManifestJson: h(o, "signed_manifest_json"),
|
|
1657
|
+
actorType: "admin",
|
|
1658
|
+
actorId: g(e.req.header(X))
|
|
1659
|
+
})) return e.json({ error: "membership_not_found" }, 404);
|
|
1660
|
+
let n;
|
|
1661
|
+
try {
|
|
1662
|
+
n = (await d.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
|
|
1663
|
+
} catch {
|
|
1664
|
+
n = void 0;
|
|
1665
|
+
}
|
|
1666
|
+
return e.json({
|
|
1667
|
+
ok: !0,
|
|
1668
|
+
scope_id: c,
|
|
1669
|
+
device_id: l,
|
|
1670
|
+
revocation: G({
|
|
1671
|
+
scopeId: c,
|
|
1672
|
+
deviceId: l,
|
|
1673
|
+
membershipEpoch: n?.membership_epoch ?? u
|
|
1674
|
+
})
|
|
1675
|
+
});
|
|
1676
|
+
} catch (t) {
|
|
1677
|
+
return e.json({ error: t instanceof Error ? t.message : String(t) }, 400);
|
|
1678
|
+
} finally {
|
|
1679
|
+
await d.close();
|
|
1680
|
+
}
|
|
1411
1681
|
}), u.get("/v1/admin/devices", async (e) => {
|
|
1412
|
-
let r = Z(e.req.header(
|
|
1682
|
+
let r = Z(e.req.header(Y), t);
|
|
1413
1683
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1414
1684
|
let i = f(e, "admin", !0);
|
|
1415
1685
|
if (i) return i;
|
|
@@ -1426,7 +1696,7 @@ function Ie(e) {
|
|
|
1426
1696
|
await s.close();
|
|
1427
1697
|
}
|
|
1428
1698
|
}), u.post("/v1/admin/devices/rename", async (e) => {
|
|
1429
|
-
let r = Z(e.req.header(
|
|
1699
|
+
let r = Z(e.req.header(Y), t);
|
|
1430
1700
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1431
1701
|
let i = f(e, "admin", !0);
|
|
1432
1702
|
if (i) return i;
|
|
@@ -1449,7 +1719,7 @@ function Ie(e) {
|
|
|
1449
1719
|
await u.close();
|
|
1450
1720
|
}
|
|
1451
1721
|
}), u.post("/v1/admin/devices/disable", async (e) => {
|
|
1452
|
-
let r = Z(e.req.header(
|
|
1722
|
+
let r = Z(e.req.header(Y), t);
|
|
1453
1723
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1454
1724
|
let i = f(e, "admin", !0);
|
|
1455
1725
|
if (i) return i;
|
|
@@ -1466,7 +1736,7 @@ function Ie(e) {
|
|
|
1466
1736
|
await l.close();
|
|
1467
1737
|
}
|
|
1468
1738
|
}), u.post("/v1/admin/devices/enable", async (e) => {
|
|
1469
|
-
let r = Z(e.req.header(
|
|
1739
|
+
let r = Z(e.req.header(Y), t);
|
|
1470
1740
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1471
1741
|
let i = f(e, "admin", !0);
|
|
1472
1742
|
if (i) return i;
|
|
@@ -1483,7 +1753,7 @@ function Ie(e) {
|
|
|
1483
1753
|
await l.close();
|
|
1484
1754
|
}
|
|
1485
1755
|
}), u.post("/v1/admin/devices/remove", async (e) => {
|
|
1486
|
-
let r = Z(e.req.header(
|
|
1756
|
+
let r = Z(e.req.header(Y), t);
|
|
1487
1757
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1488
1758
|
let i = f(e, "admin", !0);
|
|
1489
1759
|
if (i) return i;
|
|
@@ -1500,7 +1770,7 @@ function Ie(e) {
|
|
|
1500
1770
|
await l.close();
|
|
1501
1771
|
}
|
|
1502
1772
|
}), u.post("/v1/admin/invites", async (e) => {
|
|
1503
|
-
let r = Z(e.req.header(
|
|
1773
|
+
let r = Z(e.req.header(Y), t);
|
|
1504
1774
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1505
1775
|
let i = f(e, "admin", !0);
|
|
1506
1776
|
if (i) return i;
|
|
@@ -1529,19 +1799,19 @@ function Ie(e) {
|
|
|
1529
1799
|
token: String(n.token ?? ""),
|
|
1530
1800
|
expires_at: l,
|
|
1531
1801
|
team_name: n.team_name_snapshot ?? null
|
|
1532
|
-
}, i =
|
|
1802
|
+
}, i = B(r), { token: a, ...f } = n;
|
|
1533
1803
|
return e.json({
|
|
1534
1804
|
ok: !0,
|
|
1535
1805
|
invite: f,
|
|
1536
1806
|
payload: r,
|
|
1537
1807
|
encoded: i,
|
|
1538
|
-
link:
|
|
1808
|
+
link: V(i)
|
|
1539
1809
|
});
|
|
1540
1810
|
} finally {
|
|
1541
1811
|
await d.close();
|
|
1542
1812
|
}
|
|
1543
1813
|
}), u.get("/v1/admin/invites", async (e) => {
|
|
1544
|
-
let r = Z(e.req.header(
|
|
1814
|
+
let r = Z(e.req.header(Y), t);
|
|
1545
1815
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1546
1816
|
let i = f(e, "admin", !0);
|
|
1547
1817
|
if (i) return i;
|
|
@@ -1555,7 +1825,7 @@ function Ie(e) {
|
|
|
1555
1825
|
await o.close();
|
|
1556
1826
|
}
|
|
1557
1827
|
}), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
|
|
1558
|
-
let r = Z(e.req.header(
|
|
1828
|
+
let r = Z(e.req.header(Y), t);
|
|
1559
1829
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1560
1830
|
let i = f(e, "admin", !0);
|
|
1561
1831
|
if (i) return i;
|
|
@@ -1576,7 +1846,7 @@ function Ie(e) {
|
|
|
1576
1846
|
await o.close();
|
|
1577
1847
|
}
|
|
1578
1848
|
}), u.get("/v1/admin/bootstrap-grants", async (e) => {
|
|
1579
|
-
let r = Z(e.req.header(
|
|
1849
|
+
let r = Z(e.req.header(Y), t);
|
|
1580
1850
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1581
1851
|
let i = f(e, "admin", !0);
|
|
1582
1852
|
if (i) return i;
|
|
@@ -1589,7 +1859,7 @@ function Ie(e) {
|
|
|
1589
1859
|
await o.close();
|
|
1590
1860
|
}
|
|
1591
1861
|
}), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
|
|
1592
|
-
let r = Z(e.req.header(
|
|
1862
|
+
let r = Z(e.req.header(Y), t);
|
|
1593
1863
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1594
1864
|
let i = f(e, "admin", !0);
|
|
1595
1865
|
if (i) return i;
|
|
@@ -1617,7 +1887,7 @@ function Ie(e) {
|
|
|
1617
1887
|
runtime: t,
|
|
1618
1888
|
rateLimitedResponse: f
|
|
1619
1889
|
})), u.get("/v1/admin/join-requests", async (e) => {
|
|
1620
|
-
let r = Z(e.req.header(
|
|
1890
|
+
let r = Z(e.req.header(Y), t);
|
|
1621
1891
|
if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1622
1892
|
let i = f(e, "admin", !0);
|
|
1623
1893
|
if (i) return i;
|
|
@@ -1636,7 +1906,7 @@ function Ie(e) {
|
|
|
1636
1906
|
if (!i) return e.json({ error: "invalid_json" }, 400);
|
|
1637
1907
|
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;
|
|
1638
1908
|
if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
|
|
1639
|
-
if (
|
|
1909
|
+
if (q(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
|
|
1640
1910
|
let u = n();
|
|
1641
1911
|
try {
|
|
1642
1912
|
let n = await u.getInviteByToken(a);
|
|
@@ -1690,13 +1960,13 @@ function Ie(e) {
|
|
|
1690
1960
|
}), u;
|
|
1691
1961
|
}
|
|
1692
1962
|
async function $(e, t, n) {
|
|
1693
|
-
let r = Z(e.req.header(
|
|
1963
|
+
let r = Z(e.req.header(Y), n.runtime);
|
|
1694
1964
|
if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
|
|
1695
1965
|
let i = n.rateLimitedResponse(e, "admin", !0);
|
|
1696
1966
|
if (i) return i;
|
|
1697
1967
|
let a = await (async () => {
|
|
1698
1968
|
let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
|
|
1699
|
-
if (Number.isFinite(t) && t >
|
|
1969
|
+
if (Number.isFinite(t) && t > J) return null;
|
|
1700
1970
|
let n = e.req.raw.body;
|
|
1701
1971
|
if (!n) return new Uint8Array();
|
|
1702
1972
|
let r = n.getReader(), i = [], a = 0;
|
|
@@ -1705,7 +1975,7 @@ async function $(e, t, n) {
|
|
|
1705
1975
|
let { done: e, value: t } = await r.read();
|
|
1706
1976
|
if (e) break;
|
|
1707
1977
|
if (t) {
|
|
1708
|
-
if (a += t.byteLength, a >
|
|
1978
|
+
if (a += t.byteLength, a > J) return await r.cancel(), null;
|
|
1709
1979
|
i.push(t);
|
|
1710
1980
|
}
|
|
1711
1981
|
}
|
|
@@ -1753,6 +2023,6 @@ async function $(e, t, n) {
|
|
|
1753
2023
|
}
|
|
1754
2024
|
}
|
|
1755
2025
|
//#endregion
|
|
1756
|
-
export {
|
|
2026
|
+
export { G as a, B as c, W as i, ke as l, q as n, Pe as o, K as r, Oe as s, Be as t, V as u };
|
|
1757
2027
|
|
|
1758
|
-
//# sourceMappingURL=coordinator-api-
|
|
2028
|
+
//# sourceMappingURL=coordinator-api-D6UhwKON.js.map
|