@authhero/proxy 0.10.4 → 0.10.5
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/proxy.cjs +1 -1
- package/dist/proxy.mjs +135 -124
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/proxy.mjs
CHANGED
|
@@ -2584,21 +2584,32 @@ e.object({
|
|
|
2584
2584
|
cohorts: e.array(Kn)
|
|
2585
2585
|
});
|
|
2586
2586
|
var qn = e.object({
|
|
2587
|
+
cohort: e.string(),
|
|
2588
|
+
tokens: e.number(),
|
|
2589
|
+
active: e.array(e.number())
|
|
2590
|
+
});
|
|
2591
|
+
e.object({
|
|
2592
|
+
interval: e.literal("week"),
|
|
2593
|
+
from: e.string(),
|
|
2594
|
+
to: e.string(),
|
|
2595
|
+
cohorts: e.array(qn)
|
|
2596
|
+
});
|
|
2597
|
+
var Jn = e.object({
|
|
2587
2598
|
name: e.string(),
|
|
2588
2599
|
type: e.string()
|
|
2589
|
-
}),
|
|
2600
|
+
}), Yn = e.object({
|
|
2590
2601
|
elapsed: e.number(),
|
|
2591
2602
|
rows_read: e.number().optional(),
|
|
2592
2603
|
bytes_read: e.number().optional()
|
|
2593
2604
|
});
|
|
2594
2605
|
e.object({
|
|
2595
|
-
meta: e.array(
|
|
2606
|
+
meta: e.array(Jn),
|
|
2596
2607
|
data: e.array(e.record(e.string(), e.any())),
|
|
2597
2608
|
rows: e.number(),
|
|
2598
2609
|
rows_before_limit_at_least: e.number().optional(),
|
|
2599
|
-
statistics:
|
|
2610
|
+
statistics: Yn.optional()
|
|
2600
2611
|
});
|
|
2601
|
-
var
|
|
2612
|
+
var Xn = e.enum(/* @__PURE__ */ "login.login-id.login-password.signup.signup-id.signup-password.reset-password.consent.mfa.mfa-push.mfa-otp.mfa-voice.mfa-phone.mfa-webauthn.mfa-email.mfa-recovery-code.status.device-flow.email-verification.email-otp-challenge.organizations.invitation.common.passkeys.captcha.custom-form.login-passwordless.mfa-login-options".split(".")), Zn = e.record(e.string(), e.record(e.string(), e.string())).openapi({
|
|
2602
2613
|
type: "object",
|
|
2603
2614
|
additionalProperties: {
|
|
2604
2615
|
type: "object",
|
|
@@ -2606,11 +2617,11 @@ var Yn = e.enum(/* @__PURE__ */ "login.login-id.login-password.signup.signup-id.
|
|
|
2606
2617
|
}
|
|
2607
2618
|
});
|
|
2608
2619
|
e.object({
|
|
2609
|
-
prompt:
|
|
2620
|
+
prompt: Xn,
|
|
2610
2621
|
language: e.string(),
|
|
2611
|
-
custom_text:
|
|
2622
|
+
custom_text: Zn
|
|
2612
2623
|
});
|
|
2613
|
-
var
|
|
2624
|
+
var Qn = e.enum([
|
|
2614
2625
|
"phone",
|
|
2615
2626
|
"totp",
|
|
2616
2627
|
"email",
|
|
@@ -2618,9 +2629,9 @@ var Zn = e.enum([
|
|
|
2618
2629
|
"webauthn-roaming",
|
|
2619
2630
|
"webauthn-platform",
|
|
2620
2631
|
"passkey"
|
|
2621
|
-
]),
|
|
2632
|
+
]), $n = e.object({
|
|
2622
2633
|
user_id: e.string(),
|
|
2623
|
-
type:
|
|
2634
|
+
type: Qn,
|
|
2624
2635
|
phone_number: e.string().optional(),
|
|
2625
2636
|
totp_secret: e.string().optional(),
|
|
2626
2637
|
credential_id: e.string().optional(),
|
|
@@ -2654,7 +2665,7 @@ function F(t, n) {
|
|
|
2654
2665
|
path: ["public_key"]
|
|
2655
2666
|
}));
|
|
2656
2667
|
}
|
|
2657
|
-
|
|
2668
|
+
$n.superRefine(F), $n.extend({
|
|
2658
2669
|
id: e.string(),
|
|
2659
2670
|
created_at: e.string(),
|
|
2660
2671
|
updated_at: e.string()
|
|
@@ -2665,12 +2676,12 @@ Qn.superRefine(F), Qn.extend({
|
|
|
2665
2676
|
});
|
|
2666
2677
|
//#endregion
|
|
2667
2678
|
//#region src/data-plane/cache.ts
|
|
2668
|
-
var
|
|
2679
|
+
var er = 1e4;
|
|
2669
2680
|
function I(e, t, n) {
|
|
2670
2681
|
let r = typeof t == "number" ? {
|
|
2671
2682
|
freshTtlMs: t,
|
|
2672
2683
|
maxEntries: n
|
|
2673
|
-
} : t, i = r.freshTtlMs, a = r.staleTtlMs ?? 0, o = r.staleIfErrorTtlMs ?? 0, s = r.negativeTtlMs ?? i, c = r.maxEntries ??
|
|
2684
|
+
} : t, i = r.freshTtlMs, a = r.staleTtlMs ?? 0, o = r.staleIfErrorTtlMs ?? 0, s = r.negativeTtlMs ?? i, c = r.maxEntries ?? er, l = r.waitUntil, u = /* @__PURE__ */ new Map();
|
|
2674
2685
|
function d(e) {
|
|
2675
2686
|
for (let [t, n] of u) n.stale_if_error_until <= e && n.stale_until <= e && !n.refreshing && u.delete(t);
|
|
2676
2687
|
for (; u.size >= c;) {
|
|
@@ -2753,27 +2764,27 @@ function R(e) {
|
|
|
2753
2764
|
//#endregion
|
|
2754
2765
|
//#region src/data-plane/handlers/util.ts
|
|
2755
2766
|
var z = "__authhero_proxy_request__", B = "__authhero_proxy_tenant_id__", V = "__authhero_proxy_custom_domain_id__", H = "__authhero_proxy_domain__", U = "x-authhero-proxy-mutability-probe";
|
|
2756
|
-
function
|
|
2767
|
+
function tr(e, t) {
|
|
2757
2768
|
e.set(z, t);
|
|
2758
2769
|
}
|
|
2759
2770
|
function W(e) {
|
|
2760
2771
|
return e.get(z) ?? e.req.raw;
|
|
2761
2772
|
}
|
|
2762
|
-
function
|
|
2773
|
+
function nr(e, t) {
|
|
2763
2774
|
e.set(B, t.tenant_id), e.set(V, t.custom_domain_id), e.set(H, t.domain);
|
|
2764
2775
|
}
|
|
2765
|
-
function
|
|
2776
|
+
function rr(e) {
|
|
2766
2777
|
return e.get(B);
|
|
2767
2778
|
}
|
|
2768
|
-
function
|
|
2779
|
+
function ir(e) {
|
|
2769
2780
|
return e.get(V);
|
|
2770
2781
|
}
|
|
2771
|
-
function
|
|
2782
|
+
function ar(e) {
|
|
2772
2783
|
return e.get(H);
|
|
2773
2784
|
}
|
|
2774
|
-
function
|
|
2785
|
+
function or(e, t) {
|
|
2775
2786
|
let n = W(e), r = new Headers(n.headers);
|
|
2776
|
-
t(r),
|
|
2787
|
+
t(r), tr(e, new Request(n, { headers: r }));
|
|
2777
2788
|
}
|
|
2778
2789
|
function G(e) {
|
|
2779
2790
|
let t = e.res;
|
|
@@ -2790,7 +2801,7 @@ function G(e) {
|
|
|
2790
2801
|
}
|
|
2791
2802
|
//#endregion
|
|
2792
2803
|
//#region src/data-plane/handlers/cors.ts
|
|
2793
|
-
var
|
|
2804
|
+
var sr = e.object({
|
|
2794
2805
|
origins: e.array(e.string()).optional(),
|
|
2795
2806
|
allow_credentials: e.boolean().optional(),
|
|
2796
2807
|
allow_headers: e.array(e.string()).optional(),
|
|
@@ -2798,44 +2809,44 @@ var or = e.object({
|
|
|
2798
2809
|
expose_headers: e.array(e.string()).optional(),
|
|
2799
2810
|
max_age: e.number().int().optional()
|
|
2800
2811
|
}).refine((e) => !(e.allow_credentials && e.origins?.includes("*")), { message: "Cannot use wildcard origin (*) with allow_credentials" });
|
|
2801
|
-
function
|
|
2812
|
+
function cr(e, t) {
|
|
2802
2813
|
let n = new Headers(), r = e.origins ?? ["*"], i = r.includes("*");
|
|
2803
2814
|
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;
|
|
2804
2815
|
}
|
|
2805
|
-
var
|
|
2816
|
+
var lr = R({
|
|
2806
2817
|
type: "cors",
|
|
2807
|
-
optionsSchema:
|
|
2818
|
+
optionsSchema: sr,
|
|
2808
2819
|
build(e) {
|
|
2809
2820
|
return async (t, n) => {
|
|
2810
2821
|
let r = t.req.header("origin") ?? null;
|
|
2811
2822
|
if (t.req.method === "OPTIONS" && r !== null && t.req.header("access-control-request-method") !== void 0) {
|
|
2812
|
-
let t =
|
|
2823
|
+
let t = cr(e, r);
|
|
2813
2824
|
return new Response(null, {
|
|
2814
2825
|
status: 204,
|
|
2815
2826
|
headers: t
|
|
2816
2827
|
});
|
|
2817
2828
|
}
|
|
2818
2829
|
await n();
|
|
2819
|
-
let i =
|
|
2830
|
+
let i = cr(e, r);
|
|
2820
2831
|
G(t), i.forEach((e, n) => {
|
|
2821
2832
|
n.toLowerCase() === "vary" ? t.res.headers.append(n, e) : t.res.headers.set(n, e);
|
|
2822
2833
|
});
|
|
2823
2834
|
};
|
|
2824
2835
|
}
|
|
2825
|
-
}),
|
|
2836
|
+
}), ur = e.object({
|
|
2826
2837
|
username: e.string(),
|
|
2827
2838
|
password: e.string(),
|
|
2828
2839
|
realm: e.string().optional()
|
|
2829
2840
|
});
|
|
2830
|
-
function
|
|
2841
|
+
function dr(e, t) {
|
|
2831
2842
|
let n = `${e}:${t}`;
|
|
2832
2843
|
return typeof btoa == "function" ? btoa(n) : Buffer.from(n, "utf-8").toString("base64");
|
|
2833
2844
|
}
|
|
2834
|
-
var
|
|
2845
|
+
var fr = R({
|
|
2835
2846
|
type: "basic_auth",
|
|
2836
|
-
optionsSchema:
|
|
2847
|
+
optionsSchema: ur,
|
|
2837
2848
|
build(e) {
|
|
2838
|
-
let t =
|
|
2849
|
+
let t = dr(e.username, e.password), n = (e.realm ?? "Restricted").replace(/["\\\r\n]/g, "");
|
|
2839
2850
|
return async (e, r) => {
|
|
2840
2851
|
let i = e.req.header("authorization");
|
|
2841
2852
|
if (i) {
|
|
@@ -2851,7 +2862,7 @@ var dr = R({
|
|
|
2851
2862
|
});
|
|
2852
2863
|
};
|
|
2853
2864
|
}
|
|
2854
|
-
}),
|
|
2865
|
+
}), pr = R({
|
|
2855
2866
|
type: "headers",
|
|
2856
2867
|
optionsSchema: e.object({
|
|
2857
2868
|
request: e.record(e.string(), e.string()).optional(),
|
|
@@ -2861,12 +2872,12 @@ var dr = R({
|
|
|
2861
2872
|
}),
|
|
2862
2873
|
build(e) {
|
|
2863
2874
|
return async (t, n) => {
|
|
2864
|
-
if ((e.request || e.remove_request) &&
|
|
2875
|
+
if ((e.request || e.remove_request) && or(t, (t) => {
|
|
2865
2876
|
if (e.remove_request?.forEach((e) => t.delete(e)), e.request) for (let [n, r] of Object.entries(e.request)) t.set(n, r);
|
|
2866
2877
|
}), await n(), (e.response || e.remove_response) && (G(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);
|
|
2867
2878
|
};
|
|
2868
2879
|
}
|
|
2869
|
-
}),
|
|
2880
|
+
}), mr = R({
|
|
2870
2881
|
type: "cache",
|
|
2871
2882
|
optionsSchema: e.object({ ttl_seconds: e.number().int().positive() }),
|
|
2872
2883
|
build(e) {
|
|
@@ -2877,7 +2888,7 @@ var dr = R({
|
|
|
2877
2888
|
}
|
|
2878
2889
|
};
|
|
2879
2890
|
}
|
|
2880
|
-
}),
|
|
2891
|
+
}), hr = R({
|
|
2881
2892
|
type: "forwarded_headers",
|
|
2882
2893
|
optionsSchema: e.object({
|
|
2883
2894
|
client_ip_header: e.string().default("cf-connecting-ip"),
|
|
@@ -2887,40 +2898,40 @@ var dr = R({
|
|
|
2887
2898
|
build(e) {
|
|
2888
2899
|
return async (t, n) => {
|
|
2889
2900
|
let r = new URL(t.req.url);
|
|
2890
|
-
|
|
2901
|
+
or(t, (n) => {
|
|
2891
2902
|
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);
|
|
2892
2903
|
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;
|
|
2893
2904
|
n.set("x-forwarded-for", c), e.set_x_real_ip && n.set("x-real-ip", o);
|
|
2894
2905
|
}), await n();
|
|
2895
2906
|
};
|
|
2896
2907
|
}
|
|
2897
|
-
}),
|
|
2898
|
-
function
|
|
2908
|
+
}), gr = e.object({ upstream_host: e.string().optional() });
|
|
2909
|
+
function _r(e) {
|
|
2899
2910
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2900
2911
|
}
|
|
2901
|
-
function
|
|
2912
|
+
function vr(e) {
|
|
2902
2913
|
if (typeof e.getSetCookie == "function") return e.getSetCookie();
|
|
2903
2914
|
let t = [];
|
|
2904
2915
|
return e.forEach((e, n) => {
|
|
2905
2916
|
n.toLowerCase() === "set-cookie" && t.push(e);
|
|
2906
2917
|
}), t;
|
|
2907
2918
|
}
|
|
2908
|
-
var
|
|
2919
|
+
var yr = R({
|
|
2909
2920
|
type: "rewrite_cookies",
|
|
2910
|
-
optionsSchema:
|
|
2921
|
+
optionsSchema: gr,
|
|
2911
2922
|
build(e) {
|
|
2912
2923
|
return async (t, n) => {
|
|
2913
2924
|
await n();
|
|
2914
2925
|
let r = new URL(t.req.url).hostname, i = e.upstream_host ?? t.get("__proxy_upstream_host__");
|
|
2915
2926
|
if (!i) return;
|
|
2916
|
-
let a =
|
|
2927
|
+
let a = vr(t.res.headers);
|
|
2917
2928
|
if (a.length === 0) return;
|
|
2918
|
-
let o =
|
|
2929
|
+
let o = _r(i), s = RegExp(`(?:^|;\\s*)Domain=\\.?${o}(?=;|$)`, "i");
|
|
2919
2930
|
G(t), t.res.headers.delete("set-cookie");
|
|
2920
2931
|
for (let e of a) t.res.headers.append("set-cookie", e.replace(s, `Domain=${r}`));
|
|
2921
2932
|
};
|
|
2922
2933
|
}
|
|
2923
|
-
}),
|
|
2934
|
+
}), br = R({
|
|
2924
2935
|
type: "rewrite_location",
|
|
2925
2936
|
optionsSchema: e.object({ upstream_origin: e.string().optional() }),
|
|
2926
2937
|
build(e) {
|
|
@@ -2943,14 +2954,14 @@ var vr = R({
|
|
|
2943
2954
|
G(t), t.res.headers.set("location", c);
|
|
2944
2955
|
};
|
|
2945
2956
|
}
|
|
2946
|
-
}),
|
|
2957
|
+
}), xr = class extends Error {
|
|
2947
2958
|
ms;
|
|
2948
2959
|
constructor(e, t) {
|
|
2949
2960
|
super(`${t ?? "Operation"} timed out after ${e}ms`), this.name = "TimeoutError", this.ms = e;
|
|
2950
2961
|
}
|
|
2951
2962
|
};
|
|
2952
2963
|
function K(e) {
|
|
2953
|
-
return e instanceof
|
|
2964
|
+
return e instanceof xr ? !0 : e instanceof Error ? e.name === "AbortError" || e.name === "TimeoutError" : !1;
|
|
2954
2965
|
}
|
|
2955
2966
|
function q(e, t) {
|
|
2956
2967
|
let n = new AbortController(), r = setTimeout(() => n.abort(), e);
|
|
@@ -2958,7 +2969,7 @@ function q(e, t) {
|
|
|
2958
2969
|
}
|
|
2959
2970
|
function J(e, t, n) {
|
|
2960
2971
|
let r, i = new Promise((e, i) => {
|
|
2961
|
-
r = setTimeout(() => i(new
|
|
2972
|
+
r = setTimeout(() => i(new xr(t, n)), t);
|
|
2962
2973
|
});
|
|
2963
2974
|
return Promise.race([e, i]).finally(() => {
|
|
2964
2975
|
r && clearTimeout(r);
|
|
@@ -2966,7 +2977,7 @@ function J(e, t, n) {
|
|
|
2966
2977
|
}
|
|
2967
2978
|
//#endregion
|
|
2968
2979
|
//#region src/data-plane/handlers/http.ts
|
|
2969
|
-
var
|
|
2980
|
+
var Sr = new Set([
|
|
2970
2981
|
"connection",
|
|
2971
2982
|
"keep-alive",
|
|
2972
2983
|
"proxy-authenticate",
|
|
@@ -2975,24 +2986,24 @@ var xr = new Set([
|
|
|
2975
2986
|
"trailers",
|
|
2976
2987
|
"transfer-encoding",
|
|
2977
2988
|
"upgrade"
|
|
2978
|
-
]),
|
|
2989
|
+
]), Cr = 3e4, wr = e.object({
|
|
2979
2990
|
upstream_url: e.string(),
|
|
2980
2991
|
preserve_host: e.boolean().default(!1),
|
|
2981
2992
|
timeout_ms: e.number().int().positive().optional()
|
|
2982
2993
|
});
|
|
2983
|
-
function
|
|
2994
|
+
function Tr(e, t) {
|
|
2984
2995
|
return e === "" || e === "/" ? t : `${e.endsWith("/") ? e.slice(0, -1) : e}${t.startsWith("/") ? t : `/${t}`}`;
|
|
2985
2996
|
}
|
|
2986
|
-
function
|
|
2997
|
+
function Er(e) {
|
|
2987
2998
|
return e !== "GET" && e !== "HEAD";
|
|
2988
2999
|
}
|
|
2989
|
-
function
|
|
3000
|
+
function Dr(e, t) {
|
|
2990
3001
|
let n = new URL(t.url), r = new URL(e.upstream_url);
|
|
2991
|
-
r.pathname =
|
|
3002
|
+
r.pathname = Tr(r.pathname, n.pathname), r.search = n.search;
|
|
2992
3003
|
let i = new Headers(t.headers);
|
|
2993
|
-
for (let e of
|
|
3004
|
+
for (let e of Sr) i.delete(e);
|
|
2994
3005
|
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(":", ""));
|
|
2995
|
-
let a =
|
|
3006
|
+
let a = Er(t.method) ? t.body : void 0, o = {
|
|
2996
3007
|
method: t.method,
|
|
2997
3008
|
headers: i,
|
|
2998
3009
|
body: a,
|
|
@@ -3003,13 +3014,13 @@ function Er(e, t) {
|
|
|
3003
3014
|
init: o
|
|
3004
3015
|
};
|
|
3005
3016
|
}
|
|
3006
|
-
var
|
|
3017
|
+
var Or = R({
|
|
3007
3018
|
type: "http",
|
|
3008
|
-
optionsSchema:
|
|
3019
|
+
optionsSchema: wr,
|
|
3009
3020
|
build(e) {
|
|
3010
|
-
let t = e.timeout_ms ??
|
|
3021
|
+
let t = e.timeout_ms ?? Cr;
|
|
3011
3022
|
return async (n) => {
|
|
3012
|
-
let { target: r, init: i } =
|
|
3023
|
+
let { target: r, init: i } = Dr(e, W(n));
|
|
3013
3024
|
n.set("__proxy_upstream_host__", r.hostname), n.set("__proxy_upstream_origin__", `${r.protocol}//${r.host}`);
|
|
3014
3025
|
try {
|
|
3015
3026
|
return await q(t, (e) => fetch(r.toString(), {
|
|
@@ -3021,24 +3032,24 @@ var Dr = R({
|
|
|
3021
3032
|
}
|
|
3022
3033
|
};
|
|
3023
3034
|
}
|
|
3024
|
-
}),
|
|
3035
|
+
}), kr = 3e4, Ar = e.object({
|
|
3025
3036
|
binding: e.string(),
|
|
3026
3037
|
upstream_url: e.string().optional(),
|
|
3027
3038
|
preserve_host: e.boolean().default(!0),
|
|
3028
3039
|
timeout_ms: e.number().int().positive().optional()
|
|
3029
3040
|
});
|
|
3030
|
-
function
|
|
3041
|
+
function jr(e) {
|
|
3031
3042
|
return typeof e == "object" && !!e && typeof e.fetch == "function";
|
|
3032
3043
|
}
|
|
3033
|
-
var
|
|
3044
|
+
var Mr = R({
|
|
3034
3045
|
type: "service_binding",
|
|
3035
|
-
optionsSchema:
|
|
3046
|
+
optionsSchema: Ar,
|
|
3036
3047
|
build(e, t) {
|
|
3037
3048
|
let n = t.bindings[e.binding];
|
|
3038
|
-
if (!
|
|
3039
|
-
let r = e.upstream_url ?? `https://${e.binding}.binding.invalid/`, i = e.timeout_ms ??
|
|
3049
|
+
if (!jr(n)) throw Error(`Service binding "${e.binding}" is not configured or is not a Fetcher`);
|
|
3050
|
+
let r = e.upstream_url ?? `https://${e.binding}.binding.invalid/`, i = e.timeout_ms ?? kr;
|
|
3040
3051
|
return async (t) => {
|
|
3041
|
-
let a = W(t), { target: o, init: s } =
|
|
3052
|
+
let a = W(t), { target: o, init: s } = Dr({
|
|
3042
3053
|
upstream_url: r,
|
|
3043
3054
|
preserve_host: e.preserve_host
|
|
3044
3055
|
}, a);
|
|
@@ -3053,34 +3064,34 @@ var jr = R({
|
|
|
3053
3064
|
}
|
|
3054
3065
|
};
|
|
3055
3066
|
}
|
|
3056
|
-
}),
|
|
3067
|
+
}), Nr = 3e4, Pr = e.object({
|
|
3057
3068
|
binding: e.string(),
|
|
3058
3069
|
script_name: e.string(),
|
|
3059
3070
|
cpu_ms: e.number().int().positive().optional(),
|
|
3060
3071
|
subrequests: e.number().int().positive().optional(),
|
|
3061
3072
|
timeout_ms: e.number().int().positive().optional()
|
|
3062
3073
|
});
|
|
3063
|
-
function
|
|
3074
|
+
function Fr(e) {
|
|
3064
3075
|
return typeof e == "object" && !!e && typeof e.get == "function";
|
|
3065
3076
|
}
|
|
3066
3077
|
var Y = /\{(tenant_id|custom_domain_id|domain|host)\}/g;
|
|
3067
|
-
function
|
|
3078
|
+
function Ir(e) {
|
|
3068
3079
|
return Y.lastIndex = 0, Y.test(e);
|
|
3069
3080
|
}
|
|
3070
|
-
var
|
|
3081
|
+
var Lr = R({
|
|
3071
3082
|
type: "dispatch_namespace",
|
|
3072
|
-
optionsSchema:
|
|
3083
|
+
optionsSchema: Pr,
|
|
3073
3084
|
build(e, t) {
|
|
3074
3085
|
let n = t.bindings[e.binding];
|
|
3075
|
-
if (!
|
|
3076
|
-
let r =
|
|
3086
|
+
if (!Fr(n)) throw Error(`Dispatch namespace binding "${e.binding}" is not configured or does not expose .get()`);
|
|
3087
|
+
let r = Ir(e.script_name), i = e.timeout_ms ?? Nr, a = e.cpu_ms || e.subrequests ? { limits: {
|
|
3077
3088
|
...e.cpu_ms ? { cpuMs: e.cpu_ms } : {},
|
|
3078
3089
|
...e.subrequests ? { subrequests: e.subrequests } : {}
|
|
3079
3090
|
} } : void 0;
|
|
3080
3091
|
return async (t) => {
|
|
3081
3092
|
let o = e.script_name;
|
|
3082
3093
|
if (r) {
|
|
3083
|
-
let n =
|
|
3094
|
+
let n = rr(t), r = ir(t), i = ar(t), a = t.req.header("host") ?? t.req.header("x-forwarded-host") ?? "";
|
|
3084
3095
|
if (o = o.replace(Y, (e, t) => {
|
|
3085
3096
|
switch (t) {
|
|
3086
3097
|
case "tenant_id": return n ?? "";
|
|
@@ -3103,7 +3114,7 @@ var Ir = R({
|
|
|
3103
3114
|
}
|
|
3104
3115
|
};
|
|
3105
3116
|
}
|
|
3106
|
-
}),
|
|
3117
|
+
}), Rr = R({
|
|
3107
3118
|
type: "redirect",
|
|
3108
3119
|
optionsSchema: e.object({
|
|
3109
3120
|
upstream_url: e.string().refine((e) => {
|
|
@@ -3132,7 +3143,7 @@ var Ir = R({
|
|
|
3132
3143
|
});
|
|
3133
3144
|
};
|
|
3134
3145
|
}
|
|
3135
|
-
}),
|
|
3146
|
+
}), zr = R({
|
|
3136
3147
|
type: "static",
|
|
3137
3148
|
optionsSchema: e.object({
|
|
3138
3149
|
status: e.number().int().default(200),
|
|
@@ -3152,15 +3163,15 @@ var Ir = R({
|
|
|
3152
3163
|
});
|
|
3153
3164
|
//#endregion
|
|
3154
3165
|
//#region src/data-plane/handlers/index.ts
|
|
3155
|
-
function
|
|
3156
|
-
e.add(
|
|
3166
|
+
function Br(e) {
|
|
3167
|
+
e.add(lr).add(fr).add(pr).add(mr).add(hr).add(yr).add(br).add(Or).add(Mr).add(Lr).add(Rr).add(zr);
|
|
3157
3168
|
}
|
|
3158
3169
|
//#endregion
|
|
3159
3170
|
//#region src/data-plane/matcher.ts
|
|
3160
|
-
function
|
|
3171
|
+
function Vr(e) {
|
|
3161
3172
|
return [...e].sort((e, t) => e.priority === t.priority ? e.created_at.localeCompare(t.created_at) : e.priority - t.priority);
|
|
3162
3173
|
}
|
|
3163
|
-
function
|
|
3174
|
+
function Hr(e, t) {
|
|
3164
3175
|
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
3165
3176
|
if (n === r) return !0;
|
|
3166
3177
|
if (n.startsWith("*.")) {
|
|
@@ -3169,13 +3180,13 @@ function Vr(e, t) {
|
|
|
3169
3180
|
}
|
|
3170
3181
|
return !1;
|
|
3171
3182
|
}
|
|
3172
|
-
function
|
|
3173
|
-
return !e || e.length === 0 ? !0 : e.some((e) =>
|
|
3183
|
+
function Ur(e, t) {
|
|
3184
|
+
return !e || e.length === 0 ? !0 : e.some((e) => Hr(e, t));
|
|
3174
3185
|
}
|
|
3175
3186
|
function X(e) {
|
|
3176
3187
|
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;
|
|
3177
3188
|
return async (e, i) => {
|
|
3178
|
-
if (r && !
|
|
3189
|
+
if (r && !Ur(r, e.req.header("host") ?? "")) return new Response("No matching route", { status: 404 });
|
|
3179
3190
|
for (let [n, r] of t) {
|
|
3180
3191
|
let t = e.req.header(n);
|
|
3181
3192
|
if (t === void 0 || !r.test(t)) return new Response("No matching route", { status: 404 });
|
|
@@ -3192,7 +3203,7 @@ function X(e) {
|
|
|
3192
3203
|
}
|
|
3193
3204
|
//#endregion
|
|
3194
3205
|
//#region src/data-plane/compile.ts
|
|
3195
|
-
var
|
|
3206
|
+
var Wr = [
|
|
3196
3207
|
"GET",
|
|
3197
3208
|
"POST",
|
|
3198
3209
|
"PUT",
|
|
@@ -3204,34 +3215,34 @@ var Ur = [
|
|
|
3204
3215
|
function Z(e, n, r, i) {
|
|
3205
3216
|
let a = new t();
|
|
3206
3217
|
r && a.use("*", async (e, t) => {
|
|
3207
|
-
|
|
3218
|
+
nr(e, r), await t();
|
|
3208
3219
|
});
|
|
3209
|
-
let o =
|
|
3220
|
+
let o = Vr(e);
|
|
3210
3221
|
for (let e of o) {
|
|
3211
3222
|
let t = [];
|
|
3212
3223
|
t.push(X(e.match));
|
|
3213
3224
|
for (let r of e.handlers) t.push(n.build(r.type, r.options));
|
|
3214
|
-
let r = e.match.methods?.length ? e.match.methods.map((e) => e.toUpperCase()) :
|
|
3225
|
+
let r = e.match.methods?.length ? e.match.methods.map((e) => e.toUpperCase()) : Wr, i = e.match.path || "/*";
|
|
3215
3226
|
a.on(r, [i], ...t);
|
|
3216
3227
|
}
|
|
3217
|
-
return i && i.length > 0 ? a.on(
|
|
3228
|
+
return i && i.length > 0 ? a.on(Wr, ["*"], ...i) : a.all("*", (e) => e.text("No matching route", 404)), a.onError((e, t) => {
|
|
3218
3229
|
let n = K(e);
|
|
3219
3230
|
return t.text(n ? "Upstream timeout" : "Bad gateway", n ? 504 : 502, { "x-authhero-proxy-error": n ? "handler_timeout" : "handler_failed" });
|
|
3220
3231
|
}), a;
|
|
3221
3232
|
}
|
|
3222
3233
|
//#endregion
|
|
3223
3234
|
//#region src/data-plane/router.ts
|
|
3224
|
-
var
|
|
3225
|
-
function
|
|
3235
|
+
var Gr = 1e4;
|
|
3236
|
+
function Kr(e) {
|
|
3226
3237
|
return e.resolver ? e.resolver : e.cache ? I(e.data, e.cache) : I(e.data, e.cacheTtlMs ?? 3e4);
|
|
3227
3238
|
}
|
|
3228
|
-
function
|
|
3239
|
+
function qr(e) {
|
|
3229
3240
|
if (e.registry) return e.registry;
|
|
3230
3241
|
let t = new L(e.bindings ?? {});
|
|
3231
|
-
return
|
|
3242
|
+
return Br(t), t;
|
|
3232
3243
|
}
|
|
3233
3244
|
function Q(e) {
|
|
3234
|
-
let t =
|
|
3245
|
+
let t = Kr(e), n = qr(e), r = /* @__PURE__ */ new WeakMap(), i = e.resolveHostTimeoutMs ?? Gr, a = e.defaultHandlers && e.defaultHandlers.length > 0 ? e.defaultHandlers.map((e) => n.build(e.type, e.options)) : void 0, o = a ? Z([], n, void 0, a) : void 0;
|
|
3235
3246
|
return async (e) => {
|
|
3236
3247
|
let s = e.req.header("host") ?? e.req.header("x-forwarded-host");
|
|
3237
3248
|
if (!s) return e.text("Missing host", 400);
|
|
@@ -3249,13 +3260,13 @@ function Q(e) {
|
|
|
3249
3260
|
}
|
|
3250
3261
|
};
|
|
3251
3262
|
}
|
|
3252
|
-
function
|
|
3263
|
+
function Jr(e) {
|
|
3253
3264
|
let n = new t();
|
|
3254
3265
|
return n.all("*", Q(e)), n;
|
|
3255
3266
|
}
|
|
3256
3267
|
//#endregion
|
|
3257
3268
|
//#region src/app.ts
|
|
3258
|
-
function
|
|
3269
|
+
function Yr(e) {
|
|
3259
3270
|
let n = new t();
|
|
3260
3271
|
return n.all("*", Q({
|
|
3261
3272
|
data: e.data,
|
|
@@ -3273,17 +3284,17 @@ function Jr(e) {
|
|
|
3273
3284
|
}
|
|
3274
3285
|
//#endregion
|
|
3275
3286
|
//#region src/data-plane/cache-api-cache.ts
|
|
3276
|
-
var
|
|
3277
|
-
function
|
|
3287
|
+
var Xr = 1e3, Zr = 1e3;
|
|
3288
|
+
function Qr(e, t) {
|
|
3278
3289
|
return new Request(`https://proxy-cache.internal/${encodeURIComponent(e)}/hosts/${encodeURIComponent(t.toLowerCase())}`, { method: "GET" });
|
|
3279
3290
|
}
|
|
3280
|
-
function
|
|
3291
|
+
function $r() {
|
|
3281
3292
|
return globalThis.caches?.default;
|
|
3282
3293
|
}
|
|
3283
|
-
function
|
|
3284
|
-
let t = e.cache ??
|
|
3294
|
+
function ei(e) {
|
|
3295
|
+
let t = e.cache ?? $r();
|
|
3285
3296
|
if (!t) return e.upstream;
|
|
3286
|
-
let n = t, r = e.namespace ?? "authhero-proxy", i = e.cacheTtlSeconds ?? 60, a = e.negativeCacheTtlSeconds ?? 10, o = e.waitUntil, s = e.cacheReadTimeoutMs ??
|
|
3297
|
+
let n = t, r = e.namespace ?? "authhero-proxy", i = e.cacheTtlSeconds ?? 60, a = e.negativeCacheTtlSeconds ?? 10, o = e.waitUntil, s = e.cacheReadTimeoutMs ?? Xr, c = e.cacheWriteTimeoutMs ?? Zr;
|
|
3287
3298
|
async function l(e) {
|
|
3288
3299
|
try {
|
|
3289
3300
|
return await J(Promise.resolve(n.match(e)), s, "cache.match");
|
|
@@ -3292,7 +3303,7 @@ function $r(e) {
|
|
|
3292
3303
|
}
|
|
3293
3304
|
}
|
|
3294
3305
|
return { async resolveHost(t) {
|
|
3295
|
-
let s =
|
|
3306
|
+
let s = Qr(r, t), u = await l(s);
|
|
3296
3307
|
if (u) try {
|
|
3297
3308
|
return (await u.json()).value;
|
|
3298
3309
|
} catch {}
|
|
@@ -3303,14 +3314,14 @@ function $r(e) {
|
|
|
3303
3314
|
return o ? o(m) : await m, d;
|
|
3304
3315
|
} };
|
|
3305
3316
|
}
|
|
3306
|
-
function
|
|
3307
|
-
return
|
|
3317
|
+
function ti(e, t) {
|
|
3318
|
+
return Qr(e, t);
|
|
3308
3319
|
}
|
|
3309
3320
|
//#endregion
|
|
3310
3321
|
//#region src/data-plane/cache-adapter-cache.ts
|
|
3311
|
-
var
|
|
3312
|
-
function
|
|
3313
|
-
let { upstream: t, cache: n, freshTtlMs: r, staleTtlMs: i = 0, staleIfErrorTtlMs: a = 0, negativeTtlMs: o = r, keyPrefix: s = "authhero-proxy-host", waitUntil: c, cacheReadTimeoutMs: l =
|
|
3322
|
+
var ni = 1e3, ri = 1e3;
|
|
3323
|
+
function ii(e) {
|
|
3324
|
+
let { upstream: t, cache: n, freshTtlMs: r, staleTtlMs: i = 0, staleIfErrorTtlMs: a = 0, negativeTtlMs: o = r, keyPrefix: s = "authhero-proxy-host", waitUntil: c, cacheReadTimeoutMs: l = ni, cacheWriteTimeoutMs: u = ri } = e, d = /* @__PURE__ */ new Map();
|
|
3314
3325
|
function f(e) {
|
|
3315
3326
|
return `${s}:${e.toLowerCase()}`;
|
|
3316
3327
|
}
|
|
@@ -3363,7 +3374,7 @@ function ri(e) {
|
|
|
3363
3374
|
}
|
|
3364
3375
|
} };
|
|
3365
3376
|
}
|
|
3366
|
-
function
|
|
3377
|
+
function ai(e, t) {
|
|
3367
3378
|
return `${e}:${t.toLowerCase()}`;
|
|
3368
3379
|
}
|
|
3369
3380
|
//#endregion
|
|
@@ -3371,7 +3382,7 @@ function ii(e, t) {
|
|
|
3371
3382
|
function $() {
|
|
3372
3383
|
throw Error("Static proxy adapter is read-only; configure routes at init time");
|
|
3373
3384
|
}
|
|
3374
|
-
function
|
|
3385
|
+
function oi(e, t, n, r, i, a) {
|
|
3375
3386
|
return {
|
|
3376
3387
|
id: e.id ?? `${n}:${t}`,
|
|
3377
3388
|
tenant_id: r,
|
|
@@ -3386,10 +3397,10 @@ function ai(e, t, n, r, i, a) {
|
|
|
3386
3397
|
updated_at: e.updated_at ?? a
|
|
3387
3398
|
};
|
|
3388
3399
|
}
|
|
3389
|
-
function
|
|
3400
|
+
function si(e) {
|
|
3390
3401
|
let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.defaultTenantId ?? "static", r = /* @__PURE__ */ new Map();
|
|
3391
3402
|
for (let [i, a] of Object.entries(e.hosts)) {
|
|
3392
|
-
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) =>
|
|
3403
|
+
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) => oi(n, r, e, s, c, t)).sort((e, t) => e.priority - t.priority);
|
|
3393
3404
|
r.set(e, {
|
|
3394
3405
|
tenant_id: s,
|
|
3395
3406
|
custom_domain_id: c,
|
|
@@ -3433,7 +3444,7 @@ function oi(e) {
|
|
|
3433
3444
|
}
|
|
3434
3445
|
};
|
|
3435
3446
|
}
|
|
3436
|
-
function
|
|
3447
|
+
function ci(e, t = {}) {
|
|
3437
3448
|
return {
|
|
3438
3449
|
priority: t.priority,
|
|
3439
3450
|
match: { path: t.path ?? "/*" },
|
|
@@ -3448,10 +3459,10 @@ function si(e, t = {}) {
|
|
|
3448
3459
|
}
|
|
3449
3460
|
//#endregion
|
|
3450
3461
|
//#region src/constants.ts
|
|
3451
|
-
var
|
|
3462
|
+
var li = "proxy:resolve_host";
|
|
3452
3463
|
//#endregion
|
|
3453
3464
|
//#region src/http-adapter/index.ts
|
|
3454
|
-
function
|
|
3465
|
+
function ui() {
|
|
3455
3466
|
let e = () => {
|
|
3456
3467
|
throw Error("HTTP proxy adapter does not expose write access to proxy_routes; mutate via the control-plane management API");
|
|
3457
3468
|
};
|
|
@@ -3473,7 +3484,7 @@ function li() {
|
|
|
3473
3484
|
}
|
|
3474
3485
|
};
|
|
3475
3486
|
}
|
|
3476
|
-
function
|
|
3487
|
+
function di(e) {
|
|
3477
3488
|
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.scope ?? "proxy:resolve_host", o = e.tokenRefreshSkewSeconds ?? 60, s = e.timeoutMs ?? 2500;
|
|
3478
3489
|
function c(e) {
|
|
3479
3490
|
let t = new AbortController(), n = setTimeout(() => t.abort(), s);
|
|
@@ -3506,7 +3517,7 @@ function ui(e) {
|
|
|
3506
3517
|
}), u);
|
|
3507
3518
|
}
|
|
3508
3519
|
return {
|
|
3509
|
-
proxyRoutes:
|
|
3520
|
+
proxyRoutes: ui(),
|
|
3510
3521
|
async resolveHost(e) {
|
|
3511
3522
|
let i = await f(), a = `${n}${r}${encodeURIComponent(e.toLowerCase())}`, o = await c((e) => t(a, {
|
|
3512
3523
|
headers: { authorization: `Bearer ${i}` },
|
|
@@ -3520,7 +3531,7 @@ function ui(e) {
|
|
|
3520
3531
|
}
|
|
3521
3532
|
//#endregion
|
|
3522
3533
|
//#region src/http-adapter/service-binding-fetch.ts
|
|
3523
|
-
function
|
|
3534
|
+
function fi(e) {
|
|
3524
3535
|
return (t, n) => {
|
|
3525
3536
|
let r = t instanceof Request && n === void 0 ? t : new Request(t, n);
|
|
3526
3537
|
return e.fetch(r);
|
|
@@ -3528,11 +3539,11 @@ function di(e) {
|
|
|
3528
3539
|
}
|
|
3529
3540
|
//#endregion
|
|
3530
3541
|
//#region src/kv-adapter/index.ts
|
|
3531
|
-
var
|
|
3532
|
-
function
|
|
3542
|
+
var pi = "authhero-proxy-host:";
|
|
3543
|
+
function mi(e, t) {
|
|
3533
3544
|
return `${e}${t.toLowerCase()}`;
|
|
3534
3545
|
}
|
|
3535
|
-
function
|
|
3546
|
+
function hi() {
|
|
3536
3547
|
let e = () => {
|
|
3537
3548
|
throw Error("KV proxy adapter does not expose write access to proxy_routes; mutate via the control-plane management API");
|
|
3538
3549
|
};
|
|
@@ -3554,15 +3565,15 @@ function mi() {
|
|
|
3554
3565
|
}
|
|
3555
3566
|
};
|
|
3556
3567
|
}
|
|
3557
|
-
function
|
|
3558
|
-
let { kv: t, keyPrefix: n =
|
|
3568
|
+
function gi(e) {
|
|
3569
|
+
let { kv: t, keyPrefix: n = pi, timeoutMs: r } = e;
|
|
3559
3570
|
return {
|
|
3560
|
-
proxyRoutes:
|
|
3571
|
+
proxyRoutes: hi(),
|
|
3561
3572
|
async resolveHost(e) {
|
|
3562
|
-
let i =
|
|
3573
|
+
let i = mi(n, e), a = t.get(i, "json");
|
|
3563
3574
|
return (r && r > 0 ? await J(a, r, "kv.get") : await a) ?? null;
|
|
3564
3575
|
}
|
|
3565
3576
|
};
|
|
3566
3577
|
}
|
|
3567
3578
|
//#endregion
|
|
3568
|
-
export {
|
|
3579
|
+
export { pi as DEFAULT_KV_HOST_KEY_PREFIX, L as HandlerRegistry, li as PROXY_RESOLVE_HOST_SCOPE, fr as basicAuthHandler, ai as buildCacheAdapterKey, ti as buildCacheApiKey, mi as buildKvHostKey, X as buildMatchFilter, mr as cacheHandler, Z as compileHostApp, lr as corsHandler, ii as createCacheAdapterHostCache, ei as createCacheApiHostCache, di as createHttpProxyAdapter, I as createInMemoryHostCache, gi as createKvProxyAdapter, Yr as createProxyApp, Q as createProxyDataPlaneHandler, Jr as createProxyDataPlaneRouter, fi as createServiceBindingFetch, si as createStaticProxyAdapter, R as defineHandler, Lr as dispatchNamespaceHandler, hr as forwardedHeadersHandler, En as handlerConfigSchema, pr as headersHandler, Or as httpHandler, ci as httpRoute, Tn as matchSchema, Ur as matchesAnyHost, Hr as matchesHost, P as proxyRouteInsertSchema, Dn as proxyRouteSchema, On as proxyRouteUpdateSchema, Rr as redirectHandler, Br as registerBuiltinHandlers, yr as rewriteCookiesHandler, br as rewriteLocationHandler, Mr as serviceBindingHandler, Vr as sortRoutes, zr as staticHandler };
|