@authhero/proxy 0.3.3 → 0.4.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/README.md +25 -0
- package/dist/proxy.cjs +1 -1
- package/dist/proxy.d.ts +20 -3
- package/dist/proxy.mjs +153 -92
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/data-plane/compile.d.ts +7 -2
- package/dist/types/data-plane/handlers/dispatch-namespace.d.ts +16 -0
- package/dist/types/data-plane/handlers/index.d.ts +1 -0
- package/dist/types/data-plane/handlers/util.d.ts +9 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/proxy.mjs
CHANGED
|
@@ -2517,21 +2517,33 @@ function B(e) {
|
|
|
2517
2517
|
}
|
|
2518
2518
|
//#endregion
|
|
2519
2519
|
//#region src/data-plane/handlers/util.ts
|
|
2520
|
-
var V = "__authhero_proxy_request__",
|
|
2521
|
-
function
|
|
2520
|
+
var V = "__authhero_proxy_request__", H = "__authhero_proxy_tenant_id__", U = "__authhero_proxy_custom_domain_id__", W = "__authhero_proxy_domain__", G = "x-authhero-proxy-mutability-probe";
|
|
2521
|
+
function Fn(e, t) {
|
|
2522
2522
|
e.set(V, t);
|
|
2523
2523
|
}
|
|
2524
|
-
function
|
|
2524
|
+
function K(e) {
|
|
2525
2525
|
return e.get(V) ?? e.req.raw;
|
|
2526
2526
|
}
|
|
2527
|
-
function
|
|
2528
|
-
|
|
2529
|
-
|
|
2527
|
+
function In(e, t) {
|
|
2528
|
+
e.set(H, t.tenant_id), e.set(U, t.custom_domain_id), e.set(W, t.domain);
|
|
2529
|
+
}
|
|
2530
|
+
function Ln(e) {
|
|
2531
|
+
return e.get(H);
|
|
2532
|
+
}
|
|
2533
|
+
function Rn(e) {
|
|
2534
|
+
return e.get(U);
|
|
2535
|
+
}
|
|
2536
|
+
function zn(e) {
|
|
2537
|
+
return e.get(W);
|
|
2530
2538
|
}
|
|
2531
|
-
function
|
|
2539
|
+
function q(e, t) {
|
|
2540
|
+
let n = K(e), r = new Headers(n.headers);
|
|
2541
|
+
t(r), Fn(e, new Request(n, { headers: r }));
|
|
2542
|
+
}
|
|
2543
|
+
function J(e) {
|
|
2532
2544
|
let t = e.res;
|
|
2533
2545
|
try {
|
|
2534
|
-
t.headers.append(
|
|
2546
|
+
t.headers.append(G, "1"), t.headers.delete(G);
|
|
2535
2547
|
return;
|
|
2536
2548
|
} catch {
|
|
2537
2549
|
e.res = new Response(t.body, {
|
|
@@ -2543,7 +2555,7 @@ function W(e) {
|
|
|
2543
2555
|
}
|
|
2544
2556
|
//#endregion
|
|
2545
2557
|
//#region src/data-plane/handlers/cors.ts
|
|
2546
|
-
var
|
|
2558
|
+
var Bn = e.object({
|
|
2547
2559
|
origins: e.array(e.string()).optional(),
|
|
2548
2560
|
allow_credentials: e.boolean().optional(),
|
|
2549
2561
|
allow_headers: e.array(e.string()).optional(),
|
|
@@ -2551,44 +2563,44 @@ var Ln = e.object({
|
|
|
2551
2563
|
expose_headers: e.array(e.string()).optional(),
|
|
2552
2564
|
max_age: e.number().int().optional()
|
|
2553
2565
|
}).refine((e) => !(e.allow_credentials && e.origins?.includes("*")), { message: "Cannot use wildcard origin (*) with allow_credentials" });
|
|
2554
|
-
function
|
|
2566
|
+
function Y(e, t) {
|
|
2555
2567
|
let n = new Headers(), r = e.origins ?? ["*"], i = r.includes("*");
|
|
2556
2568
|
return i && !e.allow_credentials ? n.set("Access-Control-Allow-Origin", "*") : t && (i || r.includes(t)) && (n.set("Access-Control-Allow-Origin", t), n.append("Vary", "Origin")), e.allow_credentials && n.set("Access-Control-Allow-Credentials", "true"), e.allow_methods?.length && n.set("Access-Control-Allow-Methods", e.allow_methods.join(", ")), e.allow_headers?.length && n.set("Access-Control-Allow-Headers", e.allow_headers.join(", ")), e.expose_headers?.length && n.set("Access-Control-Expose-Headers", e.expose_headers.join(", ")), e.max_age !== void 0 && n.set("Access-Control-Max-Age", String(e.max_age)), n;
|
|
2557
2569
|
}
|
|
2558
|
-
var
|
|
2570
|
+
var Vn = B({
|
|
2559
2571
|
type: "cors",
|
|
2560
|
-
optionsSchema:
|
|
2572
|
+
optionsSchema: Bn,
|
|
2561
2573
|
build(e) {
|
|
2562
2574
|
return async (t, n) => {
|
|
2563
2575
|
let r = t.req.header("origin") ?? null;
|
|
2564
2576
|
if (t.req.method === "OPTIONS" && r !== null && t.req.header("access-control-request-method") !== void 0) {
|
|
2565
|
-
let t =
|
|
2577
|
+
let t = Y(e, r);
|
|
2566
2578
|
return new Response(null, {
|
|
2567
2579
|
status: 204,
|
|
2568
2580
|
headers: t
|
|
2569
2581
|
});
|
|
2570
2582
|
}
|
|
2571
2583
|
await n();
|
|
2572
|
-
let i =
|
|
2573
|
-
|
|
2584
|
+
let i = Y(e, r);
|
|
2585
|
+
J(t), i.forEach((e, n) => {
|
|
2574
2586
|
n.toLowerCase() === "vary" ? t.res.headers.append(n, e) : t.res.headers.set(n, e);
|
|
2575
2587
|
});
|
|
2576
2588
|
};
|
|
2577
2589
|
}
|
|
2578
|
-
}),
|
|
2590
|
+
}), Hn = e.object({
|
|
2579
2591
|
username: e.string(),
|
|
2580
2592
|
password: e.string(),
|
|
2581
2593
|
realm: e.string().optional()
|
|
2582
2594
|
});
|
|
2583
|
-
function
|
|
2595
|
+
function Un(e, t) {
|
|
2584
2596
|
let n = `${e}:${t}`;
|
|
2585
2597
|
return typeof btoa == "function" ? btoa(n) : Buffer.from(n, "utf-8").toString("base64");
|
|
2586
2598
|
}
|
|
2587
|
-
var
|
|
2599
|
+
var Wn = B({
|
|
2588
2600
|
type: "basic_auth",
|
|
2589
|
-
optionsSchema:
|
|
2601
|
+
optionsSchema: Hn,
|
|
2590
2602
|
build(e) {
|
|
2591
|
-
let t =
|
|
2603
|
+
let t = Un(e.username, e.password), n = (e.realm ?? "Restricted").replace(/["\\\r\n]/g, "");
|
|
2592
2604
|
return async (e, r) => {
|
|
2593
2605
|
let i = e.req.header("authorization");
|
|
2594
2606
|
if (i) {
|
|
@@ -2604,7 +2616,7 @@ var q = B({
|
|
|
2604
2616
|
});
|
|
2605
2617
|
};
|
|
2606
2618
|
}
|
|
2607
|
-
}),
|
|
2619
|
+
}), Gn = B({
|
|
2608
2620
|
type: "headers",
|
|
2609
2621
|
optionsSchema: e.object({
|
|
2610
2622
|
request: e.record(e.string(), e.string()).optional(),
|
|
@@ -2614,23 +2626,23 @@ var q = B({
|
|
|
2614
2626
|
}),
|
|
2615
2627
|
build(e) {
|
|
2616
2628
|
return async (t, n) => {
|
|
2617
|
-
if ((e.request || e.remove_request) &&
|
|
2629
|
+
if ((e.request || e.remove_request) && q(t, (t) => {
|
|
2618
2630
|
if (e.remove_request?.forEach((e) => t.delete(e)), e.request) for (let [n, r] of Object.entries(e.request)) t.set(n, r);
|
|
2619
|
-
}), await n(), (e.response || e.remove_response) && (
|
|
2631
|
+
}), await n(), (e.response || e.remove_response) && (J(t), e.remove_response?.forEach((e) => t.res.headers.delete(e)), e.response)) for (let [n, r] of Object.entries(e.response)) t.res.headers.set(n, r);
|
|
2620
2632
|
};
|
|
2621
2633
|
}
|
|
2622
|
-
}),
|
|
2634
|
+
}), Kn = B({
|
|
2623
2635
|
type: "cache",
|
|
2624
2636
|
optionsSchema: e.object({ ttl_seconds: e.number().int().positive() }),
|
|
2625
2637
|
build(e) {
|
|
2626
2638
|
return async (t, n) => {
|
|
2627
2639
|
if (await n(), !t.res.headers.has("Cache-Control")) {
|
|
2628
2640
|
let n = t.res.headers.has("set-cookie") ? "private" : "public";
|
|
2629
|
-
|
|
2641
|
+
J(t), t.res.headers.set("Cache-Control", `${n}, max-age=${e.ttl_seconds}`);
|
|
2630
2642
|
}
|
|
2631
2643
|
};
|
|
2632
2644
|
}
|
|
2633
|
-
}),
|
|
2645
|
+
}), qn = B({
|
|
2634
2646
|
type: "forwarded_headers",
|
|
2635
2647
|
optionsSchema: e.object({
|
|
2636
2648
|
client_ip_header: e.string().default("cf-connecting-ip"),
|
|
@@ -2640,40 +2652,40 @@ var q = B({
|
|
|
2640
2652
|
build(e) {
|
|
2641
2653
|
return async (t, n) => {
|
|
2642
2654
|
let r = new URL(t.req.url);
|
|
2643
|
-
|
|
2655
|
+
q(t, (n) => {
|
|
2644
2656
|
n.set("x-forwarded-host", r.host), n.set("x-forwarded-proto", r.protocol.replace(":", "")), e.set_x_original_url && n.set("x-original-url", t.req.url);
|
|
2645
2657
|
let i = n.get(e.client_ip_header), a = (n.get("x-forwarded-for") ?? "").split(",").map((e) => e.trim()).filter(Boolean), o = i ?? a[a.length - 1] ?? "127.0.0.1", s = a.length === 0 || a[a.length - 1] !== o, c = a.length ? s ? `${a.join(", ")}, ${o}` : a.join(", ") : o;
|
|
2646
2658
|
n.set("x-forwarded-for", c), e.set_x_real_ip && n.set("x-real-ip", o);
|
|
2647
2659
|
}), await n();
|
|
2648
2660
|
};
|
|
2649
2661
|
}
|
|
2650
|
-
}),
|
|
2651
|
-
function
|
|
2662
|
+
}), Jn = e.object({ upstream_host: e.string().optional() });
|
|
2663
|
+
function Yn(e) {
|
|
2652
2664
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2653
2665
|
}
|
|
2654
|
-
function
|
|
2666
|
+
function Xn(e) {
|
|
2655
2667
|
if (typeof e.getSetCookie == "function") return e.getSetCookie();
|
|
2656
2668
|
let t = [];
|
|
2657
2669
|
return e.forEach((e, n) => {
|
|
2658
2670
|
n.toLowerCase() === "set-cookie" && t.push(e);
|
|
2659
2671
|
}), t;
|
|
2660
2672
|
}
|
|
2661
|
-
var
|
|
2673
|
+
var Zn = B({
|
|
2662
2674
|
type: "rewrite_cookies",
|
|
2663
|
-
optionsSchema:
|
|
2675
|
+
optionsSchema: Jn,
|
|
2664
2676
|
build(e) {
|
|
2665
2677
|
return async (t, n) => {
|
|
2666
2678
|
await n();
|
|
2667
2679
|
let r = new URL(t.req.url).hostname, i = e.upstream_host ?? t.get("__proxy_upstream_host__");
|
|
2668
2680
|
if (!i) return;
|
|
2669
|
-
let a =
|
|
2681
|
+
let a = Xn(t.res.headers);
|
|
2670
2682
|
if (a.length === 0) return;
|
|
2671
|
-
let o =
|
|
2672
|
-
|
|
2683
|
+
let o = Yn(i), s = RegExp(`(?:^|;\\s*)Domain=\\.?${o}(?=;|$)`, "i");
|
|
2684
|
+
J(t), t.res.headers.delete("set-cookie");
|
|
2673
2685
|
for (let e of a) t.res.headers.append("set-cookie", e.replace(s, `Domain=${r}`));
|
|
2674
2686
|
};
|
|
2675
2687
|
}
|
|
2676
|
-
}),
|
|
2688
|
+
}), Qn = B({
|
|
2677
2689
|
type: "rewrite_location",
|
|
2678
2690
|
optionsSchema: e.object({ upstream_origin: e.string().optional() }),
|
|
2679
2691
|
build(e) {
|
|
@@ -2693,10 +2705,10 @@ var Wn = B({
|
|
|
2693
2705
|
}
|
|
2694
2706
|
if (o.origin !== a) return;
|
|
2695
2707
|
let s = new URL(t.req.url), c = `${`${s.protocol}//${s.host}`}${o.pathname}${o.search}${o.hash}`;
|
|
2696
|
-
|
|
2708
|
+
J(t), t.res.headers.set("location", c);
|
|
2697
2709
|
};
|
|
2698
2710
|
}
|
|
2699
|
-
}),
|
|
2711
|
+
}), $n = new Set([
|
|
2700
2712
|
"connection",
|
|
2701
2713
|
"keep-alive",
|
|
2702
2714
|
"proxy-authenticate",
|
|
@@ -2705,24 +2717,24 @@ var Wn = B({
|
|
|
2705
2717
|
"trailers",
|
|
2706
2718
|
"transfer-encoding",
|
|
2707
2719
|
"upgrade"
|
|
2708
|
-
]),
|
|
2720
|
+
]), er = 3e4, tr = e.object({
|
|
2709
2721
|
upstream_url: e.string(),
|
|
2710
2722
|
preserve_host: e.boolean().default(!1),
|
|
2711
2723
|
timeout_ms: e.number().int().positive().optional()
|
|
2712
2724
|
});
|
|
2713
|
-
function
|
|
2725
|
+
function nr(e, t) {
|
|
2714
2726
|
return e === "" || e === "/" ? t : `${e.endsWith("/") ? e.slice(0, -1) : e}${t.startsWith("/") ? t : `/${t}`}`;
|
|
2715
2727
|
}
|
|
2716
|
-
function
|
|
2728
|
+
function rr(e) {
|
|
2717
2729
|
return e !== "GET" && e !== "HEAD";
|
|
2718
2730
|
}
|
|
2719
|
-
function
|
|
2731
|
+
function ir(e, t) {
|
|
2720
2732
|
let n = new URL(t.url), r = new URL(e.upstream_url);
|
|
2721
|
-
r.pathname =
|
|
2733
|
+
r.pathname = nr(r.pathname, n.pathname), r.search = n.search;
|
|
2722
2734
|
let i = new Headers(t.headers);
|
|
2723
|
-
for (let e of
|
|
2735
|
+
for (let e of $n) i.delete(e);
|
|
2724
2736
|
e.preserve_host || i.set("host", r.host), i.has("x-forwarded-host") || i.set("x-forwarded-host", n.host), i.has("x-forwarded-proto") || i.set("x-forwarded-proto", n.protocol.replace(":", ""));
|
|
2725
|
-
let a =
|
|
2737
|
+
let a = rr(t.method) ? t.body : void 0, o = {
|
|
2726
2738
|
method: t.method,
|
|
2727
2739
|
headers: i,
|
|
2728
2740
|
body: a,
|
|
@@ -2733,13 +2745,13 @@ function Zn(e, t) {
|
|
|
2733
2745
|
init: o
|
|
2734
2746
|
};
|
|
2735
2747
|
}
|
|
2736
|
-
var
|
|
2748
|
+
var ar = B({
|
|
2737
2749
|
type: "http",
|
|
2738
|
-
optionsSchema:
|
|
2750
|
+
optionsSchema: tr,
|
|
2739
2751
|
build(e) {
|
|
2740
|
-
let t = e.timeout_ms ??
|
|
2752
|
+
let t = e.timeout_ms ?? er;
|
|
2741
2753
|
return async (n) => {
|
|
2742
|
-
let { target: r, init: i } =
|
|
2754
|
+
let { target: r, init: i } = ir(e, K(n));
|
|
2743
2755
|
n.set("__proxy_upstream_host__", r.hostname), n.set("__proxy_upstream_origin__", `${r.protocol}//${r.host}`);
|
|
2744
2756
|
let a = new AbortController(), o = setTimeout(() => a.abort(), t);
|
|
2745
2757
|
try {
|
|
@@ -2755,30 +2767,71 @@ var Qn = B({
|
|
|
2755
2767
|
}
|
|
2756
2768
|
};
|
|
2757
2769
|
}
|
|
2758
|
-
}),
|
|
2770
|
+
}), or = e.object({
|
|
2759
2771
|
binding: e.string(),
|
|
2760
2772
|
upstream_url: e.string().optional(),
|
|
2761
2773
|
preserve_host: e.boolean().default(!0)
|
|
2762
2774
|
});
|
|
2763
|
-
function
|
|
2775
|
+
function sr(e) {
|
|
2764
2776
|
return typeof e == "object" && !!e && typeof e.fetch == "function";
|
|
2765
2777
|
}
|
|
2766
|
-
var
|
|
2778
|
+
var cr = B({
|
|
2767
2779
|
type: "service_binding",
|
|
2768
|
-
optionsSchema:
|
|
2780
|
+
optionsSchema: or,
|
|
2769
2781
|
build(e, t) {
|
|
2770
2782
|
let n = t.bindings[e.binding];
|
|
2771
|
-
if (!
|
|
2783
|
+
if (!sr(n)) throw Error(`Service binding "${e.binding}" is not configured or is not a Fetcher`);
|
|
2772
2784
|
let r = e.upstream_url ?? `https://${e.binding}.binding.invalid/`;
|
|
2773
2785
|
return async (t) => {
|
|
2774
|
-
let i =
|
|
2786
|
+
let i = K(t), { target: a, init: o } = ir({
|
|
2775
2787
|
upstream_url: r,
|
|
2776
2788
|
preserve_host: e.preserve_host
|
|
2777
2789
|
}, i);
|
|
2778
2790
|
return t.set("__proxy_upstream_host__", a.hostname), t.set("__proxy_upstream_origin__", `${a.protocol}//${a.host}`), n.fetch(new Request(a.toString(), o));
|
|
2779
2791
|
};
|
|
2780
2792
|
}
|
|
2781
|
-
}),
|
|
2793
|
+
}), lr = e.object({
|
|
2794
|
+
binding: e.string(),
|
|
2795
|
+
script_name: e.string(),
|
|
2796
|
+
cpu_ms: e.number().int().positive().optional(),
|
|
2797
|
+
subrequests: e.number().int().positive().optional()
|
|
2798
|
+
});
|
|
2799
|
+
function ur(e) {
|
|
2800
|
+
return typeof e == "object" && !!e && typeof e.get == "function";
|
|
2801
|
+
}
|
|
2802
|
+
var X = /\{(tenant_id|custom_domain_id|domain|host)\}/g;
|
|
2803
|
+
function dr(e) {
|
|
2804
|
+
return X.lastIndex = 0, X.test(e);
|
|
2805
|
+
}
|
|
2806
|
+
var fr = B({
|
|
2807
|
+
type: "dispatch_namespace",
|
|
2808
|
+
optionsSchema: lr,
|
|
2809
|
+
build(e, t) {
|
|
2810
|
+
let n = t.bindings[e.binding];
|
|
2811
|
+
if (!ur(n)) throw Error(`Dispatch namespace binding "${e.binding}" is not configured or does not expose .get()`);
|
|
2812
|
+
let r = dr(e.script_name), i = e.cpu_ms || e.subrequests ? { limits: {
|
|
2813
|
+
...e.cpu_ms ? { cpuMs: e.cpu_ms } : {},
|
|
2814
|
+
...e.subrequests ? { subrequests: e.subrequests } : {}
|
|
2815
|
+
} } : void 0;
|
|
2816
|
+
return async (t) => {
|
|
2817
|
+
let a = e.script_name;
|
|
2818
|
+
if (r) {
|
|
2819
|
+
let n = Ln(t), r = Rn(t), i = zn(t), o = t.req.header("host") ?? t.req.header("x-forwarded-host") ?? "";
|
|
2820
|
+
if (a = a.replace(X, (e, t) => {
|
|
2821
|
+
switch (t) {
|
|
2822
|
+
case "tenant_id": return n ?? "";
|
|
2823
|
+
case "custom_domain_id": return r ?? "";
|
|
2824
|
+
case "domain": return i ?? "";
|
|
2825
|
+
case "host": return o;
|
|
2826
|
+
default: return "";
|
|
2827
|
+
}
|
|
2828
|
+
}), a.includes("{") || a === "") return t.text(`dispatch_namespace: could not resolve script name from template "${e.script_name}"`, 500);
|
|
2829
|
+
}
|
|
2830
|
+
let o = n.get(a, void 0, i), s = K(t);
|
|
2831
|
+
return o.fetch(s);
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
}), pr = B({
|
|
2782
2835
|
type: "redirect",
|
|
2783
2836
|
optionsSchema: e.object({
|
|
2784
2837
|
upstream_url: e.string().refine((e) => {
|
|
@@ -2807,7 +2860,7 @@ var tr = B({
|
|
|
2807
2860
|
});
|
|
2808
2861
|
};
|
|
2809
2862
|
}
|
|
2810
|
-
}),
|
|
2863
|
+
}), mr = B({
|
|
2811
2864
|
type: "static",
|
|
2812
2865
|
optionsSchema: e.object({
|
|
2813
2866
|
status: e.number().int().default(200),
|
|
@@ -2827,15 +2880,15 @@ var tr = B({
|
|
|
2827
2880
|
});
|
|
2828
2881
|
//#endregion
|
|
2829
2882
|
//#region src/data-plane/handlers/index.ts
|
|
2830
|
-
function
|
|
2831
|
-
e.add(
|
|
2883
|
+
function hr(e) {
|
|
2884
|
+
e.add(Vn).add(Wn).add(Gn).add(Kn).add(qn).add(Zn).add(Qn).add(ar).add(cr).add(fr).add(pr).add(mr);
|
|
2832
2885
|
}
|
|
2833
2886
|
//#endregion
|
|
2834
2887
|
//#region src/data-plane/matcher.ts
|
|
2835
|
-
function
|
|
2888
|
+
function gr(e) {
|
|
2836
2889
|
return [...e].sort((e, t) => e.priority === t.priority ? e.created_at.localeCompare(t.created_at) : e.priority - t.priority);
|
|
2837
2890
|
}
|
|
2838
|
-
function
|
|
2891
|
+
function _r(e, t) {
|
|
2839
2892
|
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
2840
2893
|
if (n === r) return !0;
|
|
2841
2894
|
if (n.startsWith("*.")) {
|
|
@@ -2844,13 +2897,13 @@ function ar(e, t) {
|
|
|
2844
2897
|
}
|
|
2845
2898
|
return !1;
|
|
2846
2899
|
}
|
|
2847
|
-
function
|
|
2848
|
-
return !e || e.length === 0 ? !0 : e.some((e) =>
|
|
2900
|
+
function vr(e, t) {
|
|
2901
|
+
return !e || e.length === 0 ? !0 : e.some((e) => _r(e, t));
|
|
2849
2902
|
}
|
|
2850
|
-
function
|
|
2903
|
+
function yr(e) {
|
|
2851
2904
|
let t = (e.headers ? Object.entries(e.headers) : []).map(([e, t]) => [e.toLowerCase(), new RegExp(t)]), n = (e.query ? Object.entries(e.query) : []).map(([e, t]) => [e, new RegExp(t)]), r = e.hosts;
|
|
2852
2905
|
return async (e, i) => {
|
|
2853
|
-
if (r && !
|
|
2906
|
+
if (r && !vr(r, e.req.header("host") ?? "")) return new Response("No matching route", { status: 404 });
|
|
2854
2907
|
for (let [n, r] of t) {
|
|
2855
2908
|
let t = e.req.header(n);
|
|
2856
2909
|
if (t === void 0 || !r.test(t)) return new Response("No matching route", { status: 404 });
|
|
@@ -2867,7 +2920,7 @@ function sr(e) {
|
|
|
2867
2920
|
}
|
|
2868
2921
|
//#endregion
|
|
2869
2922
|
//#region src/data-plane/compile.ts
|
|
2870
|
-
var
|
|
2923
|
+
var br = [
|
|
2871
2924
|
"GET",
|
|
2872
2925
|
"POST",
|
|
2873
2926
|
"PUT",
|
|
@@ -2876,45 +2929,53 @@ var cr = [
|
|
|
2876
2929
|
"OPTIONS",
|
|
2877
2930
|
"HEAD"
|
|
2878
2931
|
];
|
|
2879
|
-
function
|
|
2880
|
-
let
|
|
2881
|
-
|
|
2932
|
+
function xr(e, n, r) {
|
|
2933
|
+
let i = new t();
|
|
2934
|
+
r && i.use("*", async (e, t) => {
|
|
2935
|
+
In(e, r), await t();
|
|
2936
|
+
});
|
|
2937
|
+
let a = gr(e);
|
|
2938
|
+
for (let e of a) {
|
|
2882
2939
|
let t = [];
|
|
2883
|
-
t.push(
|
|
2940
|
+
t.push(yr(e.match));
|
|
2884
2941
|
for (let r of e.handlers) t.push(n.build(r.type, r.options));
|
|
2885
|
-
let
|
|
2886
|
-
|
|
2942
|
+
let r = e.match.methods?.length ? e.match.methods.map((e) => e.toUpperCase()) : br, a = e.match.path || "/*";
|
|
2943
|
+
i.on(r, [a], ...t);
|
|
2887
2944
|
}
|
|
2888
|
-
return
|
|
2945
|
+
return i.all("*", (e) => e.text("No matching route", 404)), i;
|
|
2889
2946
|
}
|
|
2890
2947
|
//#endregion
|
|
2891
2948
|
//#region src/data-plane/router.ts
|
|
2892
|
-
function
|
|
2949
|
+
function Sr(e) {
|
|
2893
2950
|
return e.resolver ? e.resolver : e.cache ? R(e.data, e.cache) : R(e.data, e.cacheTtlMs ?? 3e4);
|
|
2894
2951
|
}
|
|
2895
|
-
function
|
|
2952
|
+
function Cr(e) {
|
|
2896
2953
|
if (e.registry) return e.registry;
|
|
2897
2954
|
let t = new z(e.bindings ?? {});
|
|
2898
|
-
return
|
|
2955
|
+
return hr(t), t;
|
|
2899
2956
|
}
|
|
2900
2957
|
function Z(e) {
|
|
2901
|
-
let t =
|
|
2958
|
+
let t = Sr(e), n = Cr(e), r = /* @__PURE__ */ new WeakMap();
|
|
2902
2959
|
return async (e) => {
|
|
2903
2960
|
let i = e.req.header("host") ?? e.req.header("x-forwarded-host");
|
|
2904
2961
|
if (!i) return e.text("Missing host", 400);
|
|
2905
2962
|
let a = await t.resolveHost(i);
|
|
2906
2963
|
if (!a) return e.text("Unknown host", 404);
|
|
2907
2964
|
let o = r.get(a);
|
|
2908
|
-
return o || (o =
|
|
2965
|
+
return o || (o = xr(a.routes, n, {
|
|
2966
|
+
tenant_id: a.tenant_id,
|
|
2967
|
+
custom_domain_id: a.custom_domain_id,
|
|
2968
|
+
domain: a.domain
|
|
2969
|
+
}), r.set(a, o)), o.fetch(e.req.raw);
|
|
2909
2970
|
};
|
|
2910
2971
|
}
|
|
2911
|
-
function
|
|
2972
|
+
function wr(e) {
|
|
2912
2973
|
let n = new t();
|
|
2913
2974
|
return n.all("*", Z(e)), n;
|
|
2914
2975
|
}
|
|
2915
2976
|
//#endregion
|
|
2916
2977
|
//#region src/app.ts
|
|
2917
|
-
function
|
|
2978
|
+
function Tr(e) {
|
|
2918
2979
|
let n = new t();
|
|
2919
2980
|
return n.all("*", Z({
|
|
2920
2981
|
data: e.data,
|
|
@@ -2929,11 +2990,11 @@ function pr(e) {
|
|
|
2929
2990
|
function Q(e, t) {
|
|
2930
2991
|
return new Request(`https://proxy-cache.internal/${encodeURIComponent(e)}/hosts/${encodeURIComponent(t.toLowerCase())}`, { method: "GET" });
|
|
2931
2992
|
}
|
|
2932
|
-
function
|
|
2993
|
+
function Er() {
|
|
2933
2994
|
return globalThis.caches?.default;
|
|
2934
2995
|
}
|
|
2935
|
-
function
|
|
2936
|
-
let t = e.cache ??
|
|
2996
|
+
function Dr(e) {
|
|
2997
|
+
let t = e.cache ?? Er();
|
|
2937
2998
|
if (!t) return e.upstream;
|
|
2938
2999
|
let n = e.namespace ?? "authhero-proxy", r = e.cacheTtlSeconds ?? 60, i = e.negativeCacheTtlSeconds ?? 10, a = e.waitUntil;
|
|
2939
3000
|
return { async resolveHost(o) {
|
|
@@ -2948,7 +3009,7 @@ function hr(e) {
|
|
|
2948
3009
|
return a ? a(f) : await f.catch(() => void 0), l;
|
|
2949
3010
|
} };
|
|
2950
3011
|
}
|
|
2951
|
-
function
|
|
3012
|
+
function Or(e, t) {
|
|
2952
3013
|
return Q(e, t);
|
|
2953
3014
|
}
|
|
2954
3015
|
//#endregion
|
|
@@ -2956,7 +3017,7 @@ function gr(e, t) {
|
|
|
2956
3017
|
function $() {
|
|
2957
3018
|
throw Error("Static proxy adapter is read-only; configure routes at init time");
|
|
2958
3019
|
}
|
|
2959
|
-
function
|
|
3020
|
+
function kr(e, t, n, r, i, a) {
|
|
2960
3021
|
return {
|
|
2961
3022
|
id: e.id ?? `${n}:${t}`,
|
|
2962
3023
|
tenant_id: r,
|
|
@@ -2971,10 +3032,10 @@ function _r(e, t, n, r, i, a) {
|
|
|
2971
3032
|
updated_at: e.updated_at ?? a
|
|
2972
3033
|
};
|
|
2973
3034
|
}
|
|
2974
|
-
function
|
|
3035
|
+
function Ar(e) {
|
|
2975
3036
|
let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.defaultTenantId ?? "static", r = /* @__PURE__ */ new Map();
|
|
2976
3037
|
for (let [i, a] of Object.entries(e.hosts)) {
|
|
2977
|
-
let e = i.toLowerCase(), o = Array.isArray(a) ? { routes: a } : a, s = o.tenant_id ?? n, c = o.custom_domain_id ?? e, l = o.routes.map((n, r) =>
|
|
3038
|
+
let e = i.toLowerCase(), o = Array.isArray(a) ? { routes: a } : a, s = o.tenant_id ?? n, c = o.custom_domain_id ?? e, l = o.routes.map((n, r) => kr(n, r, e, s, c, t)).sort((e, t) => e.priority - t.priority);
|
|
2978
3039
|
r.set(e, {
|
|
2979
3040
|
tenant_id: s,
|
|
2980
3041
|
custom_domain_id: c,
|
|
@@ -3018,7 +3079,7 @@ function vr(e) {
|
|
|
3018
3079
|
}
|
|
3019
3080
|
};
|
|
3020
3081
|
}
|
|
3021
|
-
function
|
|
3082
|
+
function jr(e, t = {}) {
|
|
3022
3083
|
return {
|
|
3023
3084
|
priority: t.priority,
|
|
3024
3085
|
match: { path: t.path ?? "/*" },
|
|
@@ -3033,7 +3094,7 @@ function yr(e, t = {}) {
|
|
|
3033
3094
|
}
|
|
3034
3095
|
//#endregion
|
|
3035
3096
|
//#region src/http-adapter/index.ts
|
|
3036
|
-
function
|
|
3097
|
+
function Mr() {
|
|
3037
3098
|
let e = () => {
|
|
3038
3099
|
throw Error("HTTP proxy adapter does not expose write access to proxy_routes; mutate via the control-plane management API");
|
|
3039
3100
|
};
|
|
@@ -3055,7 +3116,7 @@ function br() {
|
|
|
3055
3116
|
}
|
|
3056
3117
|
};
|
|
3057
3118
|
}
|
|
3058
|
-
function
|
|
3119
|
+
function Nr(e) {
|
|
3059
3120
|
let t = e.fetch ?? fetch, n = e.baseUrl.replace(/\/+$/, ""), r = e.resolveHostPath ?? "/api/v2/proxy/control-plane/hosts/", i = e.audience ?? `${n}/api/v2/`, a = e.tokenRefreshSkewSeconds ?? 60, o = e.timeoutMs ?? 5e3;
|
|
3060
3121
|
function s(e) {
|
|
3061
3122
|
let t = new AbortController(), n = setTimeout(() => t.abort(), o);
|
|
@@ -3087,7 +3148,7 @@ function xr(e) {
|
|
|
3087
3148
|
}), l);
|
|
3088
3149
|
}
|
|
3089
3150
|
return {
|
|
3090
|
-
proxyRoutes:
|
|
3151
|
+
proxyRoutes: Mr(),
|
|
3091
3152
|
async resolveHost(e) {
|
|
3092
3153
|
let i = await d(), a = `${n}${r}${encodeURIComponent(e.toLowerCase())}`, o = await s((e) => t(a, {
|
|
3093
3154
|
headers: { authorization: `Bearer ${i}` },
|
|
@@ -3100,4 +3161,4 @@ function xr(e) {
|
|
|
3100
3161
|
};
|
|
3101
3162
|
}
|
|
3102
3163
|
//#endregion
|
|
3103
|
-
export { z as HandlerRegistry,
|
|
3164
|
+
export { z as HandlerRegistry, Wn as basicAuthHandler, Or as buildCacheApiKey, yr as buildMatchFilter, Kn as cacheHandler, xr as compileHostApp, Vn as corsHandler, Dr as createCacheApiHostCache, Nr as createHttpProxyAdapter, R as createInMemoryHostCache, Tr as createProxyApp, Z as createProxyDataPlaneHandler, wr as createProxyDataPlaneRouter, Ar as createStaticProxyAdapter, B as defineHandler, fr as dispatchNamespaceHandler, qn as forwardedHeadersHandler, P as handlerConfigSchema, Gn as headersHandler, ar as httpHandler, jr as httpRoute, N as matchSchema, vr as matchesAnyHost, _r as matchesHost, F as proxyRouteInsertSchema, mn as proxyRouteSchema, hn as proxyRouteUpdateSchema, pr as redirectHandler, hr as registerBuiltinHandlers, Zn as rewriteCookiesHandler, Qn as rewriteLocationHandler, cr as serviceBindingHandler, gr as sortRoutes, mr as staticHandler };
|