@authhero/cloudflare-adapter 3.4.0 → 4.1.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/cloudflare-adapter.cjs +27 -26
- package/dist/cloudflare-adapter.d.ts +47 -9
- package/dist/cloudflare-adapter.mjs +277 -217
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/action-code-generator.d.ts +20 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/wfp-provisioner/index.d.ts +1 -1
- package/dist/types/wfp-provisioner/wfp-forward.d.ts +24 -6
- package/package.json +4 -4
|
@@ -142,7 +142,7 @@ async function ae(e, t, n) {
|
|
|
142
142
|
let a = i.data.result.find((e) => e.hostname.toLowerCase() === n.toLowerCase());
|
|
143
143
|
return !a || e.enterprise && a.custom_metadata?.tenant_id !== t ? null : a;
|
|
144
144
|
}
|
|
145
|
-
async function
|
|
145
|
+
async function oe(e, t, n, r) {
|
|
146
146
|
let i = n.custom_domain_id, a;
|
|
147
147
|
try {
|
|
148
148
|
a = C({
|
|
@@ -175,7 +175,7 @@ async function w(e, t, n, r) {
|
|
|
175
175
|
outcome: "updated"
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function se(e) {
|
|
179
179
|
return {
|
|
180
180
|
create: async (t, n) => {
|
|
181
181
|
let { sslOverrides: r, rest: i } = S(n.domain_metadata);
|
|
@@ -232,7 +232,7 @@ function oe(e) {
|
|
|
232
232
|
}), r;
|
|
233
233
|
let { result: o } = a.data;
|
|
234
234
|
if (e.enterprise && o.custom_metadata?.tenant_id !== t) throw new d(404);
|
|
235
|
-
let { domain: s } = await
|
|
235
|
+
let { domain: s } = await oe(e, t, r, o);
|
|
236
236
|
return s;
|
|
237
237
|
},
|
|
238
238
|
getByDomain: async (t) => e.customDomainAdapter.getByDomain(t),
|
|
@@ -292,7 +292,7 @@ function oe(e) {
|
|
|
292
292
|
}
|
|
293
293
|
//#endregion
|
|
294
294
|
//#region src/cache/index.ts
|
|
295
|
-
var
|
|
295
|
+
var ce = class {
|
|
296
296
|
config;
|
|
297
297
|
cache = null;
|
|
298
298
|
constructor(e) {
|
|
@@ -366,8 +366,8 @@ var se = class {
|
|
|
366
366
|
console.warn("CloudflareCache.clear() is not implemented - Cloudflare Cache API does not support clearing all entries");
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
|
-
function
|
|
370
|
-
return new
|
|
369
|
+
function le(e = {}) {
|
|
370
|
+
return new ce({
|
|
371
371
|
defaultTtlSeconds: 300,
|
|
372
372
|
keyPrefix: "authhero",
|
|
373
373
|
getTimeoutMs: 200,
|
|
@@ -376,14 +376,14 @@ function ce(e = {}) {
|
|
|
376
376
|
}
|
|
377
377
|
//#endregion
|
|
378
378
|
//#region ../../node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js
|
|
379
|
-
var
|
|
379
|
+
var ue = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", w = (e = 21) => {
|
|
380
380
|
let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
|
|
381
|
-
for (; e--;) t +=
|
|
381
|
+
for (; e--;) t += ue[n[e] & 63];
|
|
382
382
|
return t;
|
|
383
383
|
};
|
|
384
384
|
//#endregion
|
|
385
385
|
//#region src/r2-sql-logs/query.ts
|
|
386
|
-
async function
|
|
386
|
+
async function T(e, t) {
|
|
387
387
|
let n = e.timeout || 3e4, r = new AbortController(), i = setTimeout(() => r.abort(), n);
|
|
388
388
|
try {
|
|
389
389
|
let n = `https://api.sql.cloudflarestorage.com/api/v1/accounts/${e.accountId}/r2-sql/query/${e.warehouseName}`, i = await fetch(n, {
|
|
@@ -403,15 +403,15 @@ async function E(e, t) {
|
|
|
403
403
|
clearTimeout(i);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
|
-
function
|
|
406
|
+
function E(e) {
|
|
407
407
|
return `'${e.replace(/'/g, "''")}'`;
|
|
408
408
|
}
|
|
409
|
-
function
|
|
409
|
+
function D(e) {
|
|
410
410
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
411
411
|
}
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/r2-sql-logs/logs.ts
|
|
414
|
-
function
|
|
414
|
+
function O(e) {
|
|
415
415
|
let t = (e) => {
|
|
416
416
|
if (!e) return "";
|
|
417
417
|
try {
|
|
@@ -451,16 +451,16 @@ function k(e) {
|
|
|
451
451
|
} : void 0
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
|
-
function
|
|
454
|
+
function de(e) {
|
|
455
455
|
return async (t, n) => {
|
|
456
|
-
let r = n.log_id ||
|
|
456
|
+
let r = n.log_id || w(), i = {
|
|
457
457
|
...n,
|
|
458
458
|
log_id: r
|
|
459
459
|
};
|
|
460
|
-
return await
|
|
460
|
+
return await fe(e, t, i), i;
|
|
461
461
|
};
|
|
462
462
|
}
|
|
463
|
-
async function
|
|
463
|
+
async function fe(e, t, n) {
|
|
464
464
|
let r = (e) => e ? JSON.stringify(e) : void 0, i = {
|
|
465
465
|
id: n.log_id,
|
|
466
466
|
tenant_id: t,
|
|
@@ -511,22 +511,22 @@ async function de(e, t, n) {
|
|
|
511
511
|
throw console.error("Failed to send log to Pipeline:", e), e;
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
function
|
|
514
|
+
function pe(e) {
|
|
515
515
|
return async (t, n) => {
|
|
516
|
-
let r = e.namespace || "default", i = e.tableName || "logs", a = await
|
|
517
|
-
SELECT * FROM ${
|
|
518
|
-
WHERE tenant_id = ${
|
|
519
|
-
AND id = ${
|
|
516
|
+
let r = e.namespace || "default", i = e.tableName || "logs", a = await T(e, `
|
|
517
|
+
SELECT * FROM ${D(r)}.${D(i)}
|
|
518
|
+
WHERE tenant_id = ${E(t)}
|
|
519
|
+
AND id = ${E(n)}
|
|
520
520
|
LIMIT 1
|
|
521
521
|
`);
|
|
522
522
|
if (a.length === 0) return null;
|
|
523
523
|
let o = a[0];
|
|
524
|
-
return o ?
|
|
524
|
+
return o ? O(o) : null;
|
|
525
525
|
};
|
|
526
526
|
}
|
|
527
527
|
//#endregion
|
|
528
528
|
//#region src/r2-sql-logs/list.ts
|
|
529
|
-
function
|
|
529
|
+
function me(e) {
|
|
530
530
|
let t = {}, n = /(\w+):(?:"([^"]*)"|(\S+))/g, r;
|
|
531
531
|
for (; (r = n.exec(e)) !== null;) {
|
|
532
532
|
let e = r[1], n = r[2] === void 0 ? r[3] : r[2];
|
|
@@ -534,40 +534,40 @@ function pe(e) {
|
|
|
534
534
|
}
|
|
535
535
|
return t;
|
|
536
536
|
}
|
|
537
|
-
function
|
|
537
|
+
function he(e) {
|
|
538
538
|
let t = [];
|
|
539
539
|
for (let [n, r] of Object.entries(e)) {
|
|
540
540
|
let e = n.replace(/[^a-zA-Z0-9_]/g, "");
|
|
541
|
-
e && r && t.push(`${
|
|
541
|
+
e && r && t.push(`${D(e)} = ${E(r)}`);
|
|
542
542
|
}
|
|
543
543
|
return t;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function ge(e) {
|
|
546
546
|
return async (t, n = {}) => {
|
|
547
|
-
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n, c = e.namespace || "default", l = e.tableName || "logs", u = [`tenant_id = ${
|
|
547
|
+
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n, c = e.namespace || "default", l = e.tableName || "logs", u = [`tenant_id = ${E(t)}`];
|
|
548
548
|
if (s) {
|
|
549
|
-
let e =
|
|
550
|
-
u.push(...
|
|
549
|
+
let e = me(s);
|
|
550
|
+
u.push(...he(e));
|
|
551
551
|
}
|
|
552
552
|
let d = u.join(" AND "), f = "ORDER BY date DESC";
|
|
553
553
|
if (o && o.sort_by) {
|
|
554
554
|
let e = o.sort_by.replace(/[^a-zA-Z0-9_]/g, ""), t = o.sort_order === "asc" ? "ASC" : "DESC";
|
|
555
|
-
f = `ORDER BY ${
|
|
555
|
+
f = `ORDER BY ${D(e)} ${t}`;
|
|
556
556
|
}
|
|
557
|
-
let p = r * i, m = `LIMIT ${i} OFFSET ${p}`, h = (await
|
|
558
|
-
SELECT * FROM ${
|
|
557
|
+
let p = r * i, m = `LIMIT ${i} OFFSET ${p}`, h = (await T(e, `
|
|
558
|
+
SELECT * FROM ${D(c)}.${D(l)}
|
|
559
559
|
WHERE ${d}
|
|
560
560
|
${f}
|
|
561
561
|
${m}
|
|
562
|
-
`)).map(
|
|
562
|
+
`)).map(O);
|
|
563
563
|
if (!a) return {
|
|
564
564
|
logs: h,
|
|
565
565
|
start: 0,
|
|
566
566
|
limit: 0,
|
|
567
567
|
length: 0
|
|
568
568
|
};
|
|
569
|
-
let g = (await
|
|
570
|
-
SELECT COUNT(*) as count FROM ${
|
|
569
|
+
let g = (await T(e, `
|
|
570
|
+
SELECT COUNT(*) as count FROM ${D(c)}.${D(l)}
|
|
571
571
|
WHERE ${d}
|
|
572
572
|
`))[0]?.count || 0;
|
|
573
573
|
return {
|
|
@@ -580,7 +580,7 @@ function he(e) {
|
|
|
580
580
|
}
|
|
581
581
|
//#endregion
|
|
582
582
|
//#region src/r2-sql-logs/stats.ts
|
|
583
|
-
function
|
|
583
|
+
function _e() {
|
|
584
584
|
return {
|
|
585
585
|
async getDaily() {
|
|
586
586
|
throw Error("Stats queries are not supported by R2 SQL logs adapter. Use Analytics Engine or Kysely adapter instead.");
|
|
@@ -592,20 +592,20 @@ function ge() {
|
|
|
592
592
|
}
|
|
593
593
|
//#endregion
|
|
594
594
|
//#region src/r2-sql-logs/index.ts
|
|
595
|
-
function
|
|
595
|
+
function k(e) {
|
|
596
596
|
let t = !!e.pipelineEndpoint, n = !!e.pipelineBinding;
|
|
597
597
|
if (!t && !n) throw Error("R2 SQL logs adapter requires one of: \"pipelineEndpoint\" or \"pipelineBinding\"");
|
|
598
598
|
if (!e.authToken) throw Error("R2 SQL logs adapter requires \"authToken\" configuration");
|
|
599
599
|
if (!e.warehouseName) throw Error("R2 SQL logs adapter requires \"warehouseName\" configuration");
|
|
600
600
|
return {
|
|
601
|
-
create:
|
|
602
|
-
list:
|
|
603
|
-
get:
|
|
601
|
+
create: de(e),
|
|
602
|
+
list: ge(e),
|
|
603
|
+
get: pe(e)
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
606
|
//#endregion
|
|
607
607
|
//#region src/analytics-engine-logs/query.ts
|
|
608
|
-
async function
|
|
608
|
+
async function A(e, t) {
|
|
609
609
|
let n = e.timeout || 3e4, r = new AbortController(), i = setTimeout(() => r.abort(), n);
|
|
610
610
|
try {
|
|
611
611
|
let n = `https://api.cloudflare.com/client/v4/accounts/${e.accountId}/analytics_engine/sql`, i = await fetch(n, {
|
|
@@ -628,15 +628,15 @@ async function j(e, t) {
|
|
|
628
628
|
clearTimeout(i);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
-
function
|
|
631
|
+
function j(e) {
|
|
632
632
|
return `'${e.replace(/'/g, "''").replace(/\\/g, "\\\\")}'`;
|
|
633
633
|
}
|
|
634
|
-
function
|
|
634
|
+
function M(e) {
|
|
635
635
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
636
636
|
}
|
|
637
637
|
//#endregion
|
|
638
638
|
//#region src/analytics-engine-logs/logs.ts
|
|
639
|
-
function
|
|
639
|
+
function N(e) {
|
|
640
640
|
let t = (e) => {
|
|
641
641
|
if (e) try {
|
|
642
642
|
return JSON.parse(e);
|
|
@@ -668,16 +668,16 @@ function P(e) {
|
|
|
668
668
|
isMobile: e.double1 === 1
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
|
-
function
|
|
671
|
+
function ve(e) {
|
|
672
672
|
return async (t, n) => {
|
|
673
|
-
let r = n.log_id ||
|
|
673
|
+
let r = n.log_id || w(), i = {
|
|
674
674
|
...n,
|
|
675
675
|
log_id: r
|
|
676
676
|
};
|
|
677
|
-
return
|
|
677
|
+
return ye(e, t, i), i;
|
|
678
678
|
};
|
|
679
679
|
}
|
|
680
|
-
function
|
|
680
|
+
function ye(e, t, n) {
|
|
681
681
|
if (!e.analyticsEngineBinding) {
|
|
682
682
|
console.error("Analytics Engine binding not configured");
|
|
683
683
|
return;
|
|
@@ -714,34 +714,34 @@ function ve(e, t, n) {
|
|
|
714
714
|
console.error("Failed to write log to Analytics Engine:", e);
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
|
-
function
|
|
717
|
+
function be(e) {
|
|
718
718
|
return async (t, n) => {
|
|
719
|
-
let r = await
|
|
719
|
+
let r = await A(e, `
|
|
720
720
|
SELECT *
|
|
721
|
-
FROM ${
|
|
722
|
-
WHERE index1 = ${
|
|
723
|
-
AND blob1 = ${
|
|
721
|
+
FROM ${M(e.dataset || "authhero_logs")}
|
|
722
|
+
WHERE index1 = ${j(t)}
|
|
723
|
+
AND blob1 = ${j(n)}
|
|
724
724
|
LIMIT 1
|
|
725
725
|
`);
|
|
726
|
-
return r.length === 0 || !r[0] ? null :
|
|
726
|
+
return r.length === 0 || !r[0] ? null : N(r[0]);
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
729
|
//#endregion
|
|
730
730
|
//#region src/analytics-engine-logs/list.ts
|
|
731
|
-
function
|
|
731
|
+
function P(e) {
|
|
732
732
|
let t = e;
|
|
733
733
|
return t.startsWith("\"") && t.endsWith("\"") && t.length > 1 && (t = t.slice(1, -1)), c(t);
|
|
734
734
|
}
|
|
735
|
-
function
|
|
735
|
+
function xe(e) {
|
|
736
736
|
let t = {}, n = [];
|
|
737
737
|
for (let r of s(e)) {
|
|
738
738
|
if (r === "OR" || r === "AND") continue;
|
|
739
739
|
let e = r.match(/^(\w+):([\s\S]*)$/);
|
|
740
740
|
if (e) {
|
|
741
|
-
let n = e[1], r =
|
|
741
|
+
let n = e[1], r = P(e[2]);
|
|
742
742
|
t[n] || (t[n] = []), t[n].push(r);
|
|
743
743
|
} else {
|
|
744
|
-
let e =
|
|
744
|
+
let e = P(r);
|
|
745
745
|
e && n.push(e);
|
|
746
746
|
}
|
|
747
747
|
}
|
|
@@ -750,7 +750,7 @@ function be(e) {
|
|
|
750
750
|
terms: n
|
|
751
751
|
};
|
|
752
752
|
}
|
|
753
|
-
function
|
|
753
|
+
function F(e) {
|
|
754
754
|
return {
|
|
755
755
|
log_id: "blob1",
|
|
756
756
|
tenant_id: "blob2",
|
|
@@ -771,7 +771,7 @@ function I(e) {
|
|
|
771
771
|
hostname: "blob17"
|
|
772
772
|
}[e] || null;
|
|
773
773
|
}
|
|
774
|
-
function
|
|
774
|
+
function Se(e) {
|
|
775
775
|
let t = [];
|
|
776
776
|
for (let [n, r] of Object.entries(e)) {
|
|
777
777
|
let e = r.filter((e) => e !== "");
|
|
@@ -782,41 +782,41 @@ function xe(e) {
|
|
|
782
782
|
n.length > 0 && t.push(`(${n.join(" OR ")})`);
|
|
783
783
|
continue;
|
|
784
784
|
}
|
|
785
|
-
let i =
|
|
786
|
-
if (i) if (e.length === 1) t.push(`${i} = ${
|
|
785
|
+
let i = F(n);
|
|
786
|
+
if (i) if (e.length === 1) t.push(`${i} = ${j(e[0])}`);
|
|
787
787
|
else {
|
|
788
|
-
let n = e.map((e) =>
|
|
788
|
+
let n = e.map((e) => j(e)).join(", ");
|
|
789
789
|
t.push(`${i} IN (${n})`);
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
792
|
return t;
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function Ce(e) {
|
|
795
795
|
return e.filter((e) => e !== "").map((e) => {
|
|
796
|
-
let t =
|
|
796
|
+
let t = j(e), n = j(`%${e}%`);
|
|
797
797
|
return `(blob7 = ${t} OR blob5 LIKE ${n} OR blob4 LIKE ${n})`;
|
|
798
798
|
});
|
|
799
799
|
}
|
|
800
|
-
function Ce(e) {
|
|
801
|
-
return e === "date" ? "double2" : I(e) || "timestamp";
|
|
802
|
-
}
|
|
803
800
|
function we(e) {
|
|
801
|
+
return e === "date" ? "double2" : F(e) || "timestamp";
|
|
802
|
+
}
|
|
803
|
+
function Te(e) {
|
|
804
804
|
return async (t, n = {}) => {
|
|
805
|
-
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s, from_date: c, to_date: l } = n, u = e.dataset || "authhero_logs", d = [`index1 = ${
|
|
805
|
+
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s, from_date: c, to_date: l } = n, u = e.dataset || "authhero_logs", d = [`index1 = ${j(t)}`];
|
|
806
806
|
if (s) {
|
|
807
|
-
let { fields: e, terms: t } =
|
|
808
|
-
d.push(...
|
|
807
|
+
let { fields: e, terms: t } = xe(s);
|
|
808
|
+
d.push(...Se(e)), d.push(...Ce(t));
|
|
809
809
|
}
|
|
810
810
|
typeof c == "number" && Number.isFinite(c) && d.push(`double2 >= ${Math.floor(c) * 1e3}`), typeof l == "number" && Number.isFinite(l) && d.push(`double2 <= ${Math.floor(l) * 1e3}`);
|
|
811
811
|
let f = d.join(" AND "), p = "ORDER BY timestamp DESC";
|
|
812
|
-
o && o.sort_by && (p = `ORDER BY ${
|
|
813
|
-
let m = r * i, h = `LIMIT ${i} OFFSET ${m}`, g = (await
|
|
812
|
+
o && o.sort_by && (p = `ORDER BY ${we(o.sort_by)} ${o.sort_order === "asc" ? "ASC" : "DESC"}`);
|
|
813
|
+
let m = r * i, h = `LIMIT ${i} OFFSET ${m}`, g = (await A(e, `
|
|
814
814
|
SELECT *
|
|
815
|
-
FROM ${
|
|
815
|
+
FROM ${M(u)}
|
|
816
816
|
WHERE ${f}
|
|
817
817
|
${p}
|
|
818
818
|
${h}
|
|
819
|
-
`)).map(
|
|
819
|
+
`)).map(N);
|
|
820
820
|
if (!a) return {
|
|
821
821
|
logs: g,
|
|
822
822
|
start: 0,
|
|
@@ -825,11 +825,11 @@ function we(e) {
|
|
|
825
825
|
};
|
|
826
826
|
let _ = `
|
|
827
827
|
SELECT count() as count
|
|
828
|
-
FROM ${
|
|
828
|
+
FROM ${M(u)}
|
|
829
829
|
WHERE ${f}
|
|
830
830
|
`;
|
|
831
831
|
try {
|
|
832
|
-
let t = (await
|
|
832
|
+
let t = (await A(e, _))[0]?.count || 0;
|
|
833
833
|
return {
|
|
834
834
|
logs: g,
|
|
835
835
|
start: m,
|
|
@@ -848,14 +848,14 @@ function we(e) {
|
|
|
848
848
|
}
|
|
849
849
|
//#endregion
|
|
850
850
|
//#region src/analytics-engine-logs/stats.ts
|
|
851
|
-
var
|
|
852
|
-
function
|
|
851
|
+
var I = ["s"], Ee = ["pwd_leak"];
|
|
852
|
+
function L(e) {
|
|
853
853
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
854
854
|
}
|
|
855
|
-
function
|
|
855
|
+
function R(e) {
|
|
856
856
|
return e.toISOString().split("T")[0];
|
|
857
857
|
}
|
|
858
|
-
function
|
|
858
|
+
function z(e, t) {
|
|
859
859
|
let n = (/* @__PURE__ */ new Date(`${e}T${t === "end" ? "23:59:59.999" : "00:00:00.000"}Z`)).getTime();
|
|
860
860
|
if (Number.isNaN(n)) return NaN;
|
|
861
861
|
let r = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
@@ -863,24 +863,24 @@ function B(e, t) {
|
|
|
863
863
|
let i = new Date(n);
|
|
864
864
|
return i.getUTCFullYear() !== Number(r[1]) || i.getUTCMonth() + 1 !== Number(r[2]) || i.getUTCDate() !== Number(r[3]) ? NaN : n;
|
|
865
865
|
}
|
|
866
|
-
function
|
|
866
|
+
function B(e) {
|
|
867
867
|
let t = e.dataset || "authhero_logs";
|
|
868
868
|
return {
|
|
869
869
|
async getDaily(n, r = {}) {
|
|
870
870
|
let { from: i, to: a } = r, o = /* @__PURE__ */ new Date(), s = new Date(o);
|
|
871
871
|
s.setDate(s.getDate() - 30);
|
|
872
|
-
let c = i ?
|
|
872
|
+
let c = i ? L(i) : R(s), l = a ? L(a) : R(o), u = z(c, "start"), d = z(l, "end");
|
|
873
873
|
if (Number.isNaN(u) || Number.isNaN(d)) throw Error(`Invalid stats date range: from='${c}' to='${l}'`);
|
|
874
|
-
return (await
|
|
874
|
+
return (await A(e, `
|
|
875
875
|
SELECT
|
|
876
876
|
toDate(toDateTime(double2 / 1000)) AS date,
|
|
877
|
-
SUM(CASE WHEN blob3 IN (${
|
|
877
|
+
SUM(CASE WHEN blob3 IN (${I.map((e) => j(e)).join(", ")}) THEN 1 ELSE 0 END) AS logins,
|
|
878
878
|
SUM(CASE WHEN blob3 = 'ss' THEN 1 ELSE 0 END) AS signups,
|
|
879
|
-
SUM(CASE WHEN blob3 IN (${
|
|
879
|
+
SUM(CASE WHEN blob3 IN (${Ee.map((e) => j(e)).join(", ")}) THEN 1 ELSE 0 END) AS leaked_passwords,
|
|
880
880
|
MIN(double2) AS first_event,
|
|
881
881
|
MAX(double2) AS last_event
|
|
882
882
|
FROM "${t}"
|
|
883
|
-
WHERE index1 = ${
|
|
883
|
+
WHERE index1 = ${j(n)}
|
|
884
884
|
AND double2 >= ${u}
|
|
885
885
|
AND double2 <= ${d}
|
|
886
886
|
GROUP BY date
|
|
@@ -897,10 +897,10 @@ function V(e) {
|
|
|
897
897
|
async getActiveUsers(n) {
|
|
898
898
|
let r = /* @__PURE__ */ new Date();
|
|
899
899
|
r.setDate(r.getDate() - 30);
|
|
900
|
-
let i = r.getTime(), a =
|
|
900
|
+
let i = r.getTime(), a = I.map((e) => j(e)).join(", "), o = (await A(e, `
|
|
901
901
|
SELECT COUNT(DISTINCT blob7) AS count
|
|
902
902
|
FROM "${t}"
|
|
903
|
-
WHERE index1 = ${
|
|
903
|
+
WHERE index1 = ${j(n)}
|
|
904
904
|
AND double2 >= ${i}
|
|
905
905
|
AND blob3 IN (${a})
|
|
906
906
|
AND blob7 IS NOT NULL
|
|
@@ -912,7 +912,7 @@ function V(e) {
|
|
|
912
912
|
}
|
|
913
913
|
//#endregion
|
|
914
914
|
//#region src/analytics-engine-logs/analytics.ts
|
|
915
|
-
var
|
|
915
|
+
var De = {
|
|
916
916
|
"active-users": ["s", "seacft"],
|
|
917
917
|
logins: [
|
|
918
918
|
"s",
|
|
@@ -942,17 +942,17 @@ var Ee = {
|
|
|
942
942
|
"fvr"
|
|
943
943
|
],
|
|
944
944
|
"codes-sent": ["cls", "cs"]
|
|
945
|
-
},
|
|
945
|
+
}, Oe = {
|
|
946
946
|
connection: "blob9",
|
|
947
947
|
client_id: "blob11",
|
|
948
948
|
user_type: "blob16",
|
|
949
949
|
event: "blob3"
|
|
950
|
-
},
|
|
950
|
+
}, ke = {
|
|
951
951
|
connection: "blob9",
|
|
952
952
|
client_id: "blob11",
|
|
953
953
|
user_type: "blob16",
|
|
954
954
|
user_id: "blob7"
|
|
955
|
-
},
|
|
955
|
+
}, Ae = {
|
|
956
956
|
"active-users": {
|
|
957
957
|
expr: "count(DISTINCT blob7)",
|
|
958
958
|
alias: "active_users",
|
|
@@ -1009,8 +1009,8 @@ var Ee = {
|
|
|
1009
1009
|
type: "UInt64"
|
|
1010
1010
|
}
|
|
1011
1011
|
};
|
|
1012
|
-
function
|
|
1013
|
-
let n = `toDateTime(intDiv(double2, 1000), ${
|
|
1012
|
+
function je(e, t) {
|
|
1013
|
+
let n = `toDateTime(intDiv(double2, 1000), ${j(t)})`;
|
|
1014
1014
|
switch (e) {
|
|
1015
1015
|
case "hour": return `toStartOfHour(${n})`;
|
|
1016
1016
|
case "week": return `toStartOfWeek(${n})`;
|
|
@@ -1018,45 +1018,45 @@ function Ae(e, t) {
|
|
|
1018
1018
|
default: return `toStartOfDay(${n})`;
|
|
1019
1019
|
}
|
|
1020
1020
|
}
|
|
1021
|
-
function
|
|
1021
|
+
function Me(e) {
|
|
1022
1022
|
return e === "hour" ? "DateTime" : "Date";
|
|
1023
1023
|
}
|
|
1024
|
-
function
|
|
1025
|
-
let r = new Date(e.from).getTime(), i = new Date(e.to).getTime(), a = n.map((e) =>
|
|
1026
|
-
`index1 = ${
|
|
1024
|
+
function Ne(e, t, n) {
|
|
1025
|
+
let r = new Date(e.from).getTime(), i = new Date(e.to).getTime(), a = n.map((e) => j(e)).join(", "), o = [
|
|
1026
|
+
`index1 = ${j(t)}`,
|
|
1027
1027
|
`double2 >= ${r}`,
|
|
1028
1028
|
`double2 < ${i}`,
|
|
1029
1029
|
`blob3 IN (${a})`
|
|
1030
1030
|
];
|
|
1031
|
-
for (let [t, n] of Object.entries(
|
|
1031
|
+
for (let [t, n] of Object.entries(ke)) {
|
|
1032
1032
|
let r = e.filters[t];
|
|
1033
1033
|
if (r && r.length > 0) {
|
|
1034
|
-
let e = r.map((e) =>
|
|
1034
|
+
let e = r.map((e) => j(e)).join(", ");
|
|
1035
1035
|
o.push(`${n} IN (${e})`);
|
|
1036
1036
|
}
|
|
1037
1037
|
}
|
|
1038
1038
|
return o.join(" AND ");
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1040
|
+
function Pe(e, t, n) {
|
|
1041
1041
|
if (e.order_by) {
|
|
1042
1042
|
let t = e.order_by.startsWith("-");
|
|
1043
|
-
return `${
|
|
1043
|
+
return `${M(t ? e.order_by.slice(1) : e.order_by)} ${t ? "DESC" : "ASC"}`;
|
|
1044
1044
|
}
|
|
1045
|
-
return t.length > 0 && t[0] === "time" ? `${
|
|
1045
|
+
return t.length > 0 && t[0] === "time" ? `${M("time")} ASC` : `${M(n)} DESC`;
|
|
1046
1046
|
}
|
|
1047
|
-
function
|
|
1047
|
+
function V(e) {
|
|
1048
1048
|
let t = e.dataset || "authhero_logs";
|
|
1049
1049
|
return { async query(n, r, i) {
|
|
1050
|
-
let a =
|
|
1050
|
+
let a = De[r], o = Ae[r], s = [], c = [];
|
|
1051
1051
|
for (let e of i.group_by) if (e === "time") {
|
|
1052
|
-
let e =
|
|
1053
|
-
s.push(`${e} AS ${
|
|
1052
|
+
let e = je(i.interval, i.tz);
|
|
1053
|
+
s.push(`${e} AS ${M("time")}`), c.push({
|
|
1054
1054
|
name: "time",
|
|
1055
|
-
type:
|
|
1055
|
+
type: Me(i.interval)
|
|
1056
1056
|
});
|
|
1057
1057
|
} else {
|
|
1058
|
-
let t =
|
|
1059
|
-
s.push(`${t} AS ${
|
|
1058
|
+
let t = Oe[e];
|
|
1059
|
+
s.push(`${t} AS ${M(e)}`), c.push({
|
|
1060
1060
|
name: e,
|
|
1061
1061
|
type: "String"
|
|
1062
1062
|
});
|
|
@@ -1065,10 +1065,10 @@ function H(e) {
|
|
|
1065
1065
|
name: o.alias,
|
|
1066
1066
|
type: o.type
|
|
1067
1067
|
});
|
|
1068
|
-
let l = [...s, `${o.expr} AS ${
|
|
1068
|
+
let l = [...s, `${o.expr} AS ${M(o.alias)}`], u = i.group_by.length ? `GROUP BY ${i.group_by.map((e) => M(e === "time" ? "time" : e)).join(", ")}` : "", d = Pe(i, i.group_by.map((e) => e === "time" ? "time" : e), o.alias), f = `
|
|
1069
1069
|
SELECT ${l.join(", ")}
|
|
1070
|
-
FROM ${
|
|
1071
|
-
WHERE ${
|
|
1070
|
+
FROM ${M(t)}
|
|
1071
|
+
WHERE ${Ne(i, n, a)}
|
|
1072
1072
|
${u}
|
|
1073
1073
|
ORDER BY ${d}
|
|
1074
1074
|
LIMIT ${Math.max(0, i.limit)} OFFSET ${Math.max(0, i.offset)}
|
|
@@ -1105,47 +1105,47 @@ function H(e) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
//#endregion
|
|
1107
1107
|
//#region src/analytics-engine-logs/index.ts
|
|
1108
|
-
function
|
|
1108
|
+
function H(e) {
|
|
1109
1109
|
return e.analyticsEngineBinding || console.warn("Analytics Engine: No binding configured. Logs will not be written to Analytics Engine."), (!e.accountId || !e.apiToken) && console.warn("Analytics Engine: accountId and apiToken are required for querying logs via SQL API."), {
|
|
1110
|
-
create:
|
|
1111
|
-
list:
|
|
1112
|
-
get:
|
|
1110
|
+
create: ve(e),
|
|
1111
|
+
list: Te(e),
|
|
1112
|
+
get: be(e)
|
|
1113
1113
|
};
|
|
1114
1114
|
}
|
|
1115
1115
|
//#endregion
|
|
1116
1116
|
//#region src/analytics-engine-action-executions/actionExecutions.ts
|
|
1117
|
-
var
|
|
1118
|
-
function
|
|
1117
|
+
var Fe = "authhero_action_executions", Ie = 1024, Le = "[truncated]";
|
|
1118
|
+
function U(e) {
|
|
1119
1119
|
if (!(typeof e != "string" || e.length === 0)) try {
|
|
1120
1120
|
return JSON.parse(e);
|
|
1121
1121
|
} catch {
|
|
1122
1122
|
return;
|
|
1123
1123
|
}
|
|
1124
1124
|
}
|
|
1125
|
-
function
|
|
1125
|
+
function Re(e) {
|
|
1126
1126
|
let t = o.safeParse(e);
|
|
1127
1127
|
return t.success ? t.data : "unspecified";
|
|
1128
1128
|
}
|
|
1129
|
-
function
|
|
1130
|
-
return e.length <= t ? e : `${e.substring(0, t - 11)}${
|
|
1129
|
+
function W(e, t = Ie) {
|
|
1130
|
+
return e.length <= t ? e : `${e.substring(0, t - 11)}${Le}`;
|
|
1131
1131
|
}
|
|
1132
|
-
function
|
|
1132
|
+
function G(e) {
|
|
1133
1133
|
return e == null ? "" : JSON.stringify(e);
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1135
|
+
function ze(e) {
|
|
1136
1136
|
let t = typeof e.blob6 == "string" && e.blob6.length > 0 ? e.blob6 : typeof e.double1 == "number" ? new Date(e.double1).toISOString() : "", n = typeof e.blob7 == "string" && e.blob7.length > 0 ? e.blob7 : t;
|
|
1137
1137
|
return {
|
|
1138
1138
|
id: typeof e.blob1 == "string" ? e.blob1 : "",
|
|
1139
1139
|
tenant_id: typeof e.index1 == "string" ? e.index1 : "",
|
|
1140
1140
|
trigger_id: typeof e.blob2 == "string" ? e.blob2 : "",
|
|
1141
|
-
status:
|
|
1142
|
-
results:
|
|
1143
|
-
logs:
|
|
1141
|
+
status: Re(e.blob3),
|
|
1142
|
+
results: U(e.blob4) ?? [],
|
|
1143
|
+
logs: U(e.blob5),
|
|
1144
1144
|
created_at: t,
|
|
1145
1145
|
updated_at: n
|
|
1146
1146
|
};
|
|
1147
1147
|
}
|
|
1148
|
-
function
|
|
1148
|
+
function Be(e) {
|
|
1149
1149
|
return async (t, n) => {
|
|
1150
1150
|
let r = Date.now(), i = new Date(r).toISOString(), a = {
|
|
1151
1151
|
id: n.id,
|
|
@@ -1157,10 +1157,10 @@ function ze(e) {
|
|
|
1157
1157
|
created_at: i,
|
|
1158
1158
|
updated_at: i
|
|
1159
1159
|
};
|
|
1160
|
-
return
|
|
1160
|
+
return Ve(e, t, a, r), a;
|
|
1161
1161
|
};
|
|
1162
1162
|
}
|
|
1163
|
-
function
|
|
1163
|
+
function Ve(e, t, n, r) {
|
|
1164
1164
|
if (!e.analyticsEngineBinding) {
|
|
1165
1165
|
console.error("Analytics Engine action_executions binding not configured; skipping write");
|
|
1166
1166
|
return;
|
|
@@ -1168,13 +1168,13 @@ function Be(e, t, n, r) {
|
|
|
1168
1168
|
try {
|
|
1169
1169
|
e.analyticsEngineBinding.writeDataPoint({
|
|
1170
1170
|
blobs: [
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
G(
|
|
1175
|
-
G(
|
|
1176
|
-
|
|
1177
|
-
|
|
1171
|
+
W(n.id),
|
|
1172
|
+
W(n.trigger_id),
|
|
1173
|
+
W(n.status),
|
|
1174
|
+
W(G(n.results)),
|
|
1175
|
+
W(G(n.logs)),
|
|
1176
|
+
W(n.created_at),
|
|
1177
|
+
W(n.updated_at)
|
|
1178
1178
|
],
|
|
1179
1179
|
doubles: [r],
|
|
1180
1180
|
indexes: [t.substring(0, 96)]
|
|
@@ -1183,29 +1183,29 @@ function Be(e, t, n, r) {
|
|
|
1183
1183
|
console.error("Failed to write action_execution to Analytics Engine:", e);
|
|
1184
1184
|
}
|
|
1185
1185
|
}
|
|
1186
|
-
function
|
|
1186
|
+
function He(e) {
|
|
1187
1187
|
return async (t, n) => {
|
|
1188
|
-
let r = await
|
|
1188
|
+
let r = await A(e, `
|
|
1189
1189
|
SELECT *
|
|
1190
|
-
FROM ${
|
|
1191
|
-
WHERE index1 = ${
|
|
1192
|
-
AND blob1 = ${
|
|
1190
|
+
FROM ${M(e.dataset || Fe)}
|
|
1191
|
+
WHERE index1 = ${j(t)}
|
|
1192
|
+
AND blob1 = ${j(n)}
|
|
1193
1193
|
LIMIT 1
|
|
1194
1194
|
`);
|
|
1195
|
-
return r.length === 0 || !r[0] ? null :
|
|
1195
|
+
return r.length === 0 || !r[0] ? null : ze(r[0]);
|
|
1196
1196
|
};
|
|
1197
1197
|
}
|
|
1198
1198
|
//#endregion
|
|
1199
1199
|
//#region src/analytics-engine-action-executions/index.ts
|
|
1200
|
-
function
|
|
1200
|
+
function K(e) {
|
|
1201
1201
|
return e.analyticsEngineBinding || console.warn("Analytics Engine: No action_executions binding configured. Executions will not be written."), (!e.accountId || !e.apiToken) && console.warn("Analytics Engine: accountId and apiToken are required to read action_executions via the SQL API."), {
|
|
1202
|
-
create:
|
|
1203
|
-
get:
|
|
1202
|
+
create: Be(e),
|
|
1203
|
+
get: He(e)
|
|
1204
1204
|
};
|
|
1205
1205
|
}
|
|
1206
1206
|
//#endregion
|
|
1207
1207
|
//#region src/geo/index.ts
|
|
1208
|
-
function
|
|
1208
|
+
function Ue() {
|
|
1209
1209
|
return { async getGeoInfo(e) {
|
|
1210
1210
|
try {
|
|
1211
1211
|
let t = e["cf-ipcountry"], n = e["cf-ipcity"], r = e["cf-iplatitude"], i = e["cf-iplongitude"], a = e["cf-timezone"], o = e["cf-ipcontinent"];
|
|
@@ -1224,7 +1224,7 @@ function He() {
|
|
|
1224
1224
|
}
|
|
1225
1225
|
//#endregion
|
|
1226
1226
|
//#region src/rate-limit/index.ts
|
|
1227
|
-
var
|
|
1227
|
+
var We = class {
|
|
1228
1228
|
bindings;
|
|
1229
1229
|
constructor(e) {
|
|
1230
1230
|
this.bindings = e;
|
|
@@ -1240,14 +1240,72 @@ var Ue = class {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
}
|
|
1242
1242
|
};
|
|
1243
|
-
function
|
|
1244
|
-
if (e && Object.keys(e).some((t) => e[t])) return new
|
|
1243
|
+
function q(e) {
|
|
1244
|
+
if (e && Object.keys(e).some((t) => e[t])) return new We(e);
|
|
1245
1245
|
}
|
|
1246
1246
|
//#endregion
|
|
1247
|
-
//#region src/
|
|
1248
|
-
var
|
|
1249
|
-
|
|
1250
|
-
|
|
1247
|
+
//#region src/action-code-generator.ts
|
|
1248
|
+
var Ge = class {
|
|
1249
|
+
config;
|
|
1250
|
+
models = [
|
|
1251
|
+
"glm",
|
|
1252
|
+
"deepseek",
|
|
1253
|
+
"qwen"
|
|
1254
|
+
];
|
|
1255
|
+
constructor(e) {
|
|
1256
|
+
this.config = e;
|
|
1257
|
+
}
|
|
1258
|
+
async generate(e) {
|
|
1259
|
+
let t = e.triggerId === "post-login" ? "post-user-login" : e.triggerId, n = Object.hasOwn(a, t) ? a[t] : void 0;
|
|
1260
|
+
if (!n) throw Error("Unsupported action trigger");
|
|
1261
|
+
let r = {
|
|
1262
|
+
glm: "@cf/zai-org/glm-4.7-flash",
|
|
1263
|
+
deepseek: "@cf/deepseek-ai/deepseek-v4-flash-0731",
|
|
1264
|
+
qwen: "@cf/qwen/qwen3.8-27b",
|
|
1265
|
+
...this.config.models
|
|
1266
|
+
}, o = await (this.config.fetch ?? globalThis.fetch)(`https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(this.config.accountId)}/ai/v1/chat/completions`, {
|
|
1267
|
+
method: "POST",
|
|
1268
|
+
headers: {
|
|
1269
|
+
Authorization: `Bearer ${this.config.apiToken}`,
|
|
1270
|
+
"content-type": "application/json",
|
|
1271
|
+
"cf-aig-gateway-id": this.config.gatewayId,
|
|
1272
|
+
"cf-aig-collect-log": "false",
|
|
1273
|
+
"cf-aig-skip-cache": "true"
|
|
1274
|
+
},
|
|
1275
|
+
signal: AbortSignal.timeout(this.config.timeoutMs ?? 6e4),
|
|
1276
|
+
body: JSON.stringify({
|
|
1277
|
+
model: r[e.model],
|
|
1278
|
+
max_tokens: 8192,
|
|
1279
|
+
stream: !1,
|
|
1280
|
+
messages: [{
|
|
1281
|
+
role: "system",
|
|
1282
|
+
content: [
|
|
1283
|
+
"Generate an AuthHero Action as plain JavaScript source only. No Markdown, prose, or reasoning.",
|
|
1284
|
+
`Define exports.${n} = async (event, api) => { ... }; at the top level.`,
|
|
1285
|
+
`The only available api namespaces and methods are: ${JSON.stringify(i[t])}. Do not invent APIs.`,
|
|
1286
|
+
"Use the following TypeScript API declarations as reference for parameter types, optional arguments, and return values. The handler's api parameter has type ActionAPI. Output JavaScript only; do not copy type declarations or type annotations into the action.",
|
|
1287
|
+
e.apiTypes,
|
|
1288
|
+
"This runs in a Web Worker. Use fetch and Web Crypto; no require, imports, npm modules, process, filesystem, or Node APIs.",
|
|
1289
|
+
"Read credentials and configurable endpoint URLs from event.secrets. Never embed credentials. Comment with the secret names needed.",
|
|
1290
|
+
"Treat event data as untrusted. Validate tokens before using their claims. Handle fetch failures and use bounded timeouts.",
|
|
1291
|
+
t === "custom-token-exchange" ? "Validate event.transaction.subject_token before calling exactly one api.authentication.setUserById or setUserByConnection, or reject with api.access.rejectInvalidSubjectToken." : ""
|
|
1292
|
+
].filter(Boolean).join("\n")
|
|
1293
|
+
}, {
|
|
1294
|
+
role: "user",
|
|
1295
|
+
content: e.prompt
|
|
1296
|
+
}]
|
|
1297
|
+
})
|
|
1298
|
+
});
|
|
1299
|
+
if (!o.ok) throw Error(`AI Gateway request failed (${o.status})`);
|
|
1300
|
+
let s = (await o.json()).choices?.[0];
|
|
1301
|
+
if (s?.finish_reason !== "stop" || typeof s.message?.content != "string") throw Error("AI Gateway did not return a complete action");
|
|
1302
|
+
let c = s.message.content.trim().replace(/^```(?:javascript|js)?\s*\n([\s\S]*?)\n```$/, "$1").trim();
|
|
1303
|
+
if (!c || c.length > 1e5) throw Error("AI Gateway returned invalid action source");
|
|
1304
|
+
return { code: c };
|
|
1305
|
+
}
|
|
1306
|
+
}, Ke = 5, qe = 1e3, J = 50;
|
|
1307
|
+
async function Je(e, t = {}) {
|
|
1308
|
+
let n = Math.trunc(t.perPage ?? J), r = Number.isFinite(n) ? Math.min(qe, Math.max(Ke, n)) : J, i = t.maxPages ?? 200, a = {
|
|
1251
1309
|
scanned: 0,
|
|
1252
1310
|
matched: 0,
|
|
1253
1311
|
updated: 0,
|
|
@@ -1282,7 +1340,7 @@ async function Ke(e, t = {}) {
|
|
|
1282
1340
|
continue;
|
|
1283
1341
|
}
|
|
1284
1342
|
a.matched++;
|
|
1285
|
-
let { outcome: r } = await
|
|
1343
|
+
let { outcome: r } = await oe(e, n.tenant_id, n, t);
|
|
1286
1344
|
r === "updated" ? a.updated++ : r === "failed" && a.errors++;
|
|
1287
1345
|
} catch (e) {
|
|
1288
1346
|
console.warn(`[custom-domains] sync failed for ${t.hostname}:`, e instanceof Error ? e.message : e), a.errors++;
|
|
@@ -1294,7 +1352,7 @@ async function Ke(e, t = {}) {
|
|
|
1294
1352
|
}
|
|
1295
1353
|
//#endregion
|
|
1296
1354
|
//#region src/code-executor/worker-template.ts
|
|
1297
|
-
function
|
|
1355
|
+
function Y(e) {
|
|
1298
1356
|
return `// Auto-generated AuthHero code hook worker
|
|
1299
1357
|
|
|
1300
1358
|
const fnNames = ${JSON.stringify(a)};
|
|
@@ -1381,7 +1439,7 @@ export default {
|
|
|
1381
1439
|
}
|
|
1382
1440
|
//#endregion
|
|
1383
1441
|
//#region src/code-executor/index.ts
|
|
1384
|
-
var
|
|
1442
|
+
var X = class {
|
|
1385
1443
|
config;
|
|
1386
1444
|
constructor(e) {
|
|
1387
1445
|
this.config = e;
|
|
@@ -1442,7 +1500,7 @@ var qe = class {
|
|
|
1442
1500
|
}
|
|
1443
1501
|
}
|
|
1444
1502
|
async deploy(e, t) {
|
|
1445
|
-
let n = `hook-${e}`, r =
|
|
1503
|
+
let n = `hook-${e}`, r = Y(t), i = `https://api.cloudflare.com/client/v4/accounts/${this.config.accountId}/workers/dispatch/namespaces/${this.config.dispatchNamespace}/scripts/${n}`, a = JSON.stringify({
|
|
1446
1504
|
main_module: "index.js",
|
|
1447
1505
|
compatibility_date: this.config.compatibilityDate ?? "2024-11-20"
|
|
1448
1506
|
}), o = new FormData();
|
|
@@ -1467,16 +1525,16 @@ var qe = class {
|
|
|
1467
1525
|
throw Error(`Failed to remove hook worker ${t}: ${r.status} ${e}`);
|
|
1468
1526
|
}
|
|
1469
1527
|
}
|
|
1470
|
-
},
|
|
1471
|
-
async function
|
|
1528
|
+
}, Ye = X, Xe = a, Ze = i;
|
|
1529
|
+
async function Qe(e) {
|
|
1472
1530
|
let t = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", t), r = new Uint8Array(n), i = "";
|
|
1473
1531
|
for (let e of r) i += e.toString(16).padStart(2, "0");
|
|
1474
1532
|
return i;
|
|
1475
1533
|
}
|
|
1476
|
-
function
|
|
1534
|
+
function $e(e) {
|
|
1477
1535
|
return `
|
|
1478
|
-
const TRIGGER_FN_NAMES = ${JSON.stringify(
|
|
1479
|
-
const API_SHAPES = ${JSON.stringify(
|
|
1536
|
+
const TRIGGER_FN_NAMES = ${JSON.stringify(Xe)};
|
|
1537
|
+
const API_SHAPES = ${JSON.stringify(Ze)};
|
|
1480
1538
|
const MAX_LOG_ENTRIES = 50;
|
|
1481
1539
|
const MAX_LOG_LENGTH = 500;
|
|
1482
1540
|
|
|
@@ -1576,7 +1634,7 @@ export default {
|
|
|
1576
1634
|
};
|
|
1577
1635
|
`;
|
|
1578
1636
|
}
|
|
1579
|
-
var
|
|
1637
|
+
var et = class {
|
|
1580
1638
|
loader;
|
|
1581
1639
|
compatibilityDate;
|
|
1582
1640
|
constructor(e) {
|
|
@@ -1585,11 +1643,11 @@ var $e = class {
|
|
|
1585
1643
|
async execute(e) {
|
|
1586
1644
|
let t = Date.now();
|
|
1587
1645
|
try {
|
|
1588
|
-
let t =
|
|
1646
|
+
let t = $e(e.code), n = {
|
|
1589
1647
|
compatibilityDate: this.compatibilityDate,
|
|
1590
1648
|
mainModule: "hook.js",
|
|
1591
1649
|
modules: { "hook.js": t }
|
|
1592
|
-
}, r = e.hookCodeId ? `${e.hookCodeId}-${await
|
|
1650
|
+
}, r = e.hookCodeId ? `${e.hookCodeId}-${await Qe(e.code)}` : null;
|
|
1593
1651
|
return await (await (r ? this.loader.get(r, async () => n) : this.loader.load(n)).getEntrypoint().fetch(new Request("https://hook/execute", {
|
|
1594
1652
|
method: "POST",
|
|
1595
1653
|
headers: { "Content-Type": "application/json" },
|
|
@@ -1607,37 +1665,37 @@ var $e = class {
|
|
|
1607
1665
|
};
|
|
1608
1666
|
}
|
|
1609
1667
|
}
|
|
1610
|
-
},
|
|
1611
|
-
function
|
|
1612
|
-
if (
|
|
1668
|
+
}, tt = new TextEncoder();
|
|
1669
|
+
function nt(e, t) {
|
|
1670
|
+
if (tt.encode(e).length <= t) return e;
|
|
1613
1671
|
let n = 0, r = "";
|
|
1614
1672
|
for (let i of e) {
|
|
1615
|
-
let e =
|
|
1673
|
+
let e = tt.encode(i).length;
|
|
1616
1674
|
if (n + e > t) break;
|
|
1617
1675
|
n += e, r += i;
|
|
1618
1676
|
}
|
|
1619
1677
|
return r;
|
|
1620
1678
|
}
|
|
1621
|
-
var
|
|
1622
|
-
function
|
|
1679
|
+
var Z = (e, t = 1024) => nt(e, t);
|
|
1680
|
+
function rt(e) {
|
|
1623
1681
|
let t = e.analyticsEngineBinding;
|
|
1624
1682
|
return (e) => {
|
|
1625
1683
|
if (t) try {
|
|
1626
1684
|
t.writeDataPoint({
|
|
1627
1685
|
blobs: [
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1686
|
+
Z(e.name),
|
|
1687
|
+
Z(e.tenantId),
|
|
1688
|
+
Z(e.eventType),
|
|
1689
|
+
Z(e.source),
|
|
1690
|
+
Z(e.destination ?? ""),
|
|
1691
|
+
Z(e.error ?? "")
|
|
1634
1692
|
],
|
|
1635
1693
|
doubles: [
|
|
1636
1694
|
e.value,
|
|
1637
1695
|
e.retryCount ?? 0,
|
|
1638
1696
|
Date.now()
|
|
1639
1697
|
],
|
|
1640
|
-
indexes: [
|
|
1698
|
+
indexes: [nt(e.tenantId, 96)]
|
|
1641
1699
|
});
|
|
1642
1700
|
} catch (e) {
|
|
1643
1701
|
console.error("Failed to write outbox metric to Analytics Engine:", e);
|
|
@@ -1646,7 +1704,7 @@ function tt(e) {
|
|
|
1646
1704
|
}
|
|
1647
1705
|
//#endregion
|
|
1648
1706
|
//#region src/wfp-provisioner/provisioner.ts
|
|
1649
|
-
function
|
|
1707
|
+
function it(e) {
|
|
1650
1708
|
let t = n(e);
|
|
1651
1709
|
return {
|
|
1652
1710
|
async onProvision(e) {
|
|
@@ -1667,11 +1725,11 @@ function nt(e) {
|
|
|
1667
1725
|
}
|
|
1668
1726
|
//#endregion
|
|
1669
1727
|
//#region src/wfp-provisioner/tenant-hook.ts
|
|
1670
|
-
function
|
|
1728
|
+
function at(e) {
|
|
1671
1729
|
return e.deployment_type === "wfp";
|
|
1672
1730
|
}
|
|
1673
|
-
var
|
|
1674
|
-
function
|
|
1731
|
+
var ot = 2048;
|
|
1732
|
+
function Q(e) {
|
|
1675
1733
|
let t;
|
|
1676
1734
|
if (e instanceof Error) t = e.message;
|
|
1677
1735
|
else try {
|
|
@@ -1679,15 +1737,15 @@ function $(e) {
|
|
|
1679
1737
|
} catch {
|
|
1680
1738
|
t = Object.prototype.toString.call(e);
|
|
1681
1739
|
}
|
|
1682
|
-
return t.slice(0,
|
|
1740
|
+
return t.slice(0, ot);
|
|
1683
1741
|
}
|
|
1684
|
-
function
|
|
1685
|
-
let { provisioner: t, tenants: n, syncDefaults: i } = e, a = e.shouldProvision ??
|
|
1742
|
+
function st(e) {
|
|
1743
|
+
let { provisioner: t, tenants: n, syncDefaults: i } = e, a = e.shouldProvision ?? at, o = e.logger;
|
|
1686
1744
|
async function s(e, t) {
|
|
1687
1745
|
try {
|
|
1688
1746
|
await n.update(e, {
|
|
1689
1747
|
provisioning_state: "failed",
|
|
1690
|
-
provisioning_error:
|
|
1748
|
+
provisioning_error: Q(t),
|
|
1691
1749
|
provisioning_state_changed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1692
1750
|
});
|
|
1693
1751
|
} catch (t) {
|
|
@@ -1707,7 +1765,7 @@ function at(e) {
|
|
|
1707
1765
|
try {
|
|
1708
1766
|
l = await t.onProvision(e);
|
|
1709
1767
|
} catch (t) {
|
|
1710
|
-
throw await c("provision-resources", "failed", { message:
|
|
1768
|
+
throw await c("provision-resources", "failed", { message: Q(t) }), await s(e, t), t;
|
|
1711
1769
|
}
|
|
1712
1770
|
let u = {
|
|
1713
1771
|
d1_database_id: l.d1DatabaseId,
|
|
@@ -1725,7 +1783,7 @@ function at(e) {
|
|
|
1725
1783
|
if (t.length > 0) throw Error(`sync-defaults seed reported ${t.length} error(s): ${t.join("; ")}`);
|
|
1726
1784
|
await c("seed-defaults", "succeeded");
|
|
1727
1785
|
} catch (e) {
|
|
1728
|
-
throw await c("seed-defaults", "failed", { message:
|
|
1786
|
+
throw await c("seed-defaults", "failed", { message: Q(e) }), e;
|
|
1729
1787
|
}
|
|
1730
1788
|
}
|
|
1731
1789
|
await n.update(e, {
|
|
@@ -1739,7 +1797,7 @@ function at(e) {
|
|
|
1739
1797
|
await n.update(e, {
|
|
1740
1798
|
...u,
|
|
1741
1799
|
provisioning_state: "failed",
|
|
1742
|
-
provisioning_error:
|
|
1800
|
+
provisioning_error: Q(t),
|
|
1743
1801
|
provisioning_state_changed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1744
1802
|
});
|
|
1745
1803
|
} catch (t) {
|
|
@@ -1776,62 +1834,64 @@ function at(e) {
|
|
|
1776
1834
|
}
|
|
1777
1835
|
//#endregion
|
|
1778
1836
|
//#region src/wfp-provisioner/wfp-forward.ts
|
|
1779
|
-
var
|
|
1780
|
-
function
|
|
1837
|
+
var ct = "DISPATCHER", lt = "tenant-{tenant_id}-auth", $ = ["/u/widget/"];
|
|
1838
|
+
function ut(e) {
|
|
1781
1839
|
return typeof e == "object" && !!e && "get" in e && typeof Reflect.get(e, "get") == "function";
|
|
1782
1840
|
}
|
|
1783
|
-
function
|
|
1841
|
+
function dt(e, t) {
|
|
1784
1842
|
return e.replace(/\{tenant_id\}/g, t);
|
|
1785
1843
|
}
|
|
1786
|
-
function
|
|
1787
|
-
let { tenants: t, controlPlaneTenantId: n, dispatcherBinding: r =
|
|
1788
|
-
|
|
1789
|
-
|
|
1844
|
+
function ft(e) {
|
|
1845
|
+
let { tenants: t, controlPlaneTenantId: n, dispatcherBinding: r = ct, scriptNameTemplate: i = lt, resolveTenantId: a = (e) => e.req.header("tenant-id"), localPaths: o = [], includeDefaultLocalPaths: s = !0 } = e;
|
|
1846
|
+
e.localPaths?.length === 0 && e.includeDefaultLocalPaths === void 0 && console.warn("[authhero] createWfpForwardMiddleware: `localPaths: []` no longer turns off DEFAULT_LOCAL_PATHS; pass `includeDefaultLocalPaths: false` to dispatch them.");
|
|
1847
|
+
let c = [...s ? $ : [], ...o];
|
|
1848
|
+
return async (e, o) => {
|
|
1849
|
+
if (c.length > 0) {
|
|
1790
1850
|
let t = e.req.path;
|
|
1791
|
-
if (
|
|
1851
|
+
if (c.some((e) => t.startsWith(e))) return o();
|
|
1792
1852
|
}
|
|
1793
|
-
let
|
|
1794
|
-
if (!
|
|
1795
|
-
let l = await t.get(
|
|
1796
|
-
if (!l || l.deployment_type !== "wfp" || l.provisioning_state && l.provisioning_state !== "ready") return
|
|
1853
|
+
let s = await a(e);
|
|
1854
|
+
if (!s || s === n) return o();
|
|
1855
|
+
let l = await t.get(s);
|
|
1856
|
+
if (!l || l.deployment_type !== "wfp" || l.provisioning_state && l.provisioning_state !== "ready") return o();
|
|
1797
1857
|
let u = Reflect.get(e.env ?? {}, r);
|
|
1798
|
-
if (!
|
|
1799
|
-
let d =
|
|
1858
|
+
if (!ut(u)) return o();
|
|
1859
|
+
let d = dt(i, s), f;
|
|
1800
1860
|
try {
|
|
1801
1861
|
f = await u.get(d).fetch(e.req.raw);
|
|
1802
1862
|
} catch (t) {
|
|
1803
1863
|
let n = t instanceof Error ? t.message : String(t), r = /not\s*found|no\s*such|does not exist/i.test(n), i = r ? "wfp_worker_not_found" : "wfp_dispatch_failed";
|
|
1804
|
-
return console.error(`[wfp-forward] ${i} tenant=${
|
|
1864
|
+
return console.error(`[wfp-forward] ${i} tenant=${s} script=${d}: ${n}`), e.header("X-Authhero-Error", i), e.header("X-Wfp-Tenant", s), e.json({
|
|
1805
1865
|
error: i,
|
|
1806
|
-
detail: r ? `Tenant '${
|
|
1807
|
-
tenant_id:
|
|
1866
|
+
detail: r ? `Tenant '${s}' is marked ready but its worker '${d}' is not deployed in the dispatch namespace.` : `The worker for tenant '${s}' could not be reached.`,
|
|
1867
|
+
tenant_id: s
|
|
1808
1868
|
}, r ? 503 : 502);
|
|
1809
1869
|
}
|
|
1810
1870
|
if (f.status >= 500) {
|
|
1811
1871
|
let e = f.headers.get("X-Authhero-Error");
|
|
1812
|
-
console.error(`[wfp-forward] tenant worker ${f.status}${e ? ` (${e})` : ""} tenant=${
|
|
1872
|
+
console.error(`[wfp-forward] tenant worker ${f.status}${e ? ` (${e})` : ""} tenant=${s} script=${d}`);
|
|
1813
1873
|
}
|
|
1814
1874
|
let p = Reflect.get(f, "webSocket");
|
|
1815
1875
|
if (f.status === 101 || p != null) return f;
|
|
1816
1876
|
let m = new Response(f.body, f);
|
|
1817
|
-
return m.headers.set("X-Wfp-Tenant",
|
|
1877
|
+
return m.headers.set("X-Wfp-Tenant", s), m;
|
|
1818
1878
|
};
|
|
1819
1879
|
}
|
|
1820
1880
|
//#endregion
|
|
1821
1881
|
//#region src/index.ts
|
|
1822
|
-
function
|
|
1882
|
+
function pt(e) {
|
|
1823
1883
|
let t = {
|
|
1824
|
-
customDomains:
|
|
1825
|
-
cache:
|
|
1884
|
+
customDomains: se(e),
|
|
1885
|
+
cache: le({
|
|
1826
1886
|
...e.cacheName && { cacheName: e.cacheName },
|
|
1827
1887
|
...e.defaultTtlSeconds !== void 0 && { defaultTtlSeconds: e.defaultTtlSeconds },
|
|
1828
1888
|
...e.keyPrefix && { keyPrefix: e.keyPrefix }
|
|
1829
1889
|
}),
|
|
1830
|
-
geo:
|
|
1890
|
+
geo: Ue()
|
|
1831
1891
|
};
|
|
1832
|
-
e.r2SqlLogs ? t.logs =
|
|
1833
|
-
let n =
|
|
1892
|
+
e.r2SqlLogs ? t.logs = k(e.r2SqlLogs) : e.analyticsEngineLogs && (t.logs = H(e.analyticsEngineLogs)), e.analyticsEngineLogs && (t.analytics = V(e.analyticsEngineLogs), t.stats = B(e.analyticsEngineLogs)), e.analyticsEngineActionExecutions && (t.actionExecutions = K(e.analyticsEngineActionExecutions));
|
|
1893
|
+
let n = q(e.rateLimitBindings);
|
|
1834
1894
|
return n && (t.rateLimit = n), t;
|
|
1835
1895
|
}
|
|
1836
1896
|
//#endregion
|
|
1837
|
-
export { t as CloudflareApiClient, e as CloudflareApiError,
|
|
1897
|
+
export { Ge as CloudflareActionCodeGenerator, t as CloudflareApiClient, e as CloudflareApiError, Ye as CloudflareCodeExecutor, $ as DEFAULT_LOCAL_PATHS, X as DispatchNamespaceCodeExecutor, et as WorkerLoaderCodeExecutor, K as createAnalyticsEngineActionExecutionsAdapter, V as createAnalyticsEngineAnalyticsAdapter, H as createAnalyticsEngineLogsAdapter, rt as createAnalyticsEngineOutboxMetricsSink, B as createAnalyticsEngineStatsAdapter, q as createCloudflareRateLimitAdapter, it as createCloudflareWfpD1Provisioner, k as createR2SQLLogsAdapter, _e as createR2SQLStatsAdapter, ft as createWfpForwardMiddleware, n as createWfpProvisionerSteps, st as createWfpTenantProvisioningHook, pt as default, Y as generateWorkerScript, Je as syncCustomDomains };
|