@authhero/proxy 0.3.3 → 0.4.1

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.mjs CHANGED
@@ -362,7 +362,7 @@ var _e = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", ve
362
362
  "oag"
363
363
  ]).default("regular_web").optional().openapi({ description: "The type of application this client represents" }),
364
364
  logo_uri: e.string().url().optional().openapi({ description: "URL of the logo to display for this client. Recommended size is 150x150 pixels." }),
365
- is_first_party: e.boolean().default(!1).openapi({ description: "Whether this client a first party client (true) or not (false)." }),
365
+ is_first_party: e.boolean().default(!0).openapi({ description: "Whether this client is a first party client (true) or not (false). First-party clients skip the consent screen; third-party clients require explicit user consent for non-basic scopes." }),
366
366
  oidc_conformant: e.boolean().default(!0).openapi({ description: "Whether this client conforms to strict OIDC specifications (true) or uses legacy features (false)." }),
367
367
  auth0_conformant: e.boolean().default(!0).openapi({ description: "Whether this client follows Auth0-compatible behavior (true) or strict OIDC behavior (false). When true, profile/email claims are included in the ID token when scopes are requested. When false, these claims are only available from the userinfo endpoint (strict OIDC 5.4 compliance)." }),
368
368
  callbacks: e.array(e.string()).default([]).optional().openapi({ description: "Comma-separated list of URLs whitelisted for Auth0 to use as a callback to the client after authentication." }),
@@ -1419,7 +1419,7 @@ e.object({ keys: e.array(Wt) }), e.object({
1419
1419
  client_id_metadata_document_supported: e.boolean().optional()
1420
1420
  });
1421
1421
  var Gt = /* @__PURE__ */ function(e) {
1422
- return e.PENDING = "pending", e.AUTHENTICATED = "authenticated", e.AWAITING_EMAIL_VERIFICATION = "awaiting_email_verification", e.AWAITING_MFA = "awaiting_mfa", e.AWAITING_HOOK = "awaiting_hook", e.AWAITING_CONTINUATION = "awaiting_continuation", e.COMPLETED = "completed", e.FAILED = "failed", e.EXPIRED = "expired", e;
1422
+ return e.PENDING = "pending", e.AUTHENTICATED = "authenticated", e.AWAITING_EMAIL_VERIFICATION = "awaiting_email_verification", e.AWAITING_MFA = "awaiting_mfa", e.AWAITING_HOOK = "awaiting_hook", e.AWAITING_CONTINUATION = "awaiting_continuation", e.AWAITING_CONSENT = "awaiting_consent", e.COMPLETED = "completed", e.FAILED = "failed", e.EXPIRED = "expired", e;
1423
1423
  }({}), Kt = e.nativeEnum(Gt), qt = e.object({
1424
1424
  strategy: e.string(),
1425
1425
  strategy_type: e.string()
@@ -2035,6 +2035,7 @@ var N = e.object({
2035
2035
  type: e.string(),
2036
2036
  options: e.record(e.string(), e.unknown()).default({})
2037
2037
  }), F = e.object({
2038
+ id: e.string().optional(),
2038
2039
  custom_domain_id: e.string(),
2039
2040
  priority: e.number().int().default(100),
2040
2041
  match: N,
@@ -2044,7 +2045,10 @@ var N = e.object({
2044
2045
  tenant_id: e.string(),
2045
2046
  created_at: e.string(),
2046
2047
  updated_at: e.string()
2047
- }), hn = F.partial().omit({ custom_domain_id: !0 });
2048
+ }), hn = F.partial().omit({
2049
+ id: !0,
2050
+ custom_domain_id: !0
2051
+ });
2048
2052
  e.object({
2049
2053
  name: e.string(),
2050
2054
  enabled: e.boolean().optional().default(!0),
@@ -2141,7 +2145,12 @@ var bn = e.object({
2141
2145
  resource_server_identifier: e.string(),
2142
2146
  permission_name: e.string()
2143
2147
  }).extend({ created_at: e.string() });
2144
- e.array(bn);
2148
+ e.array(bn), e.object({
2149
+ user_id: e.string().openapi({ description: "The id of the user that granted the consent" }),
2150
+ clientID: e.string().openapi({ description: "The id of the client the grant was issued to" }),
2151
+ audience: e.string().optional().openapi({ description: "The audience the grant applies to" }),
2152
+ scope: e.array(e.string()).default([]).openapi({ description: "The list of OAuth scopes the user has consented to" })
2153
+ }).extend({ id: e.string() });
2145
2154
  var xn = e.object({
2146
2155
  user_id: e.string(),
2147
2156
  resource_server_identifier: e.string(),
@@ -2517,21 +2526,33 @@ function B(e) {
2517
2526
  }
2518
2527
  //#endregion
2519
2528
  //#region src/data-plane/handlers/util.ts
2520
- var V = "__authhero_proxy_request__", Fn = "x-authhero-proxy-mutability-probe";
2521
- function In(e, t) {
2529
+ 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";
2530
+ function Fn(e, t) {
2522
2531
  e.set(V, t);
2523
2532
  }
2524
- function H(e) {
2533
+ function K(e) {
2525
2534
  return e.get(V) ?? e.req.raw;
2526
2535
  }
2527
- function U(e, t) {
2528
- let n = H(e), r = new Headers(n.headers);
2529
- t(r), In(e, new Request(n, { headers: r }));
2536
+ function In(e, t) {
2537
+ e.set(H, t.tenant_id), e.set(U, t.custom_domain_id), e.set(W, t.domain);
2538
+ }
2539
+ function Ln(e) {
2540
+ return e.get(H);
2541
+ }
2542
+ function Rn(e) {
2543
+ return e.get(U);
2544
+ }
2545
+ function zn(e) {
2546
+ return e.get(W);
2547
+ }
2548
+ function q(e, t) {
2549
+ let n = K(e), r = new Headers(n.headers);
2550
+ t(r), Fn(e, new Request(n, { headers: r }));
2530
2551
  }
2531
- function W(e) {
2552
+ function J(e) {
2532
2553
  let t = e.res;
2533
2554
  try {
2534
- t.headers.append(Fn, "1"), t.headers.delete(Fn);
2555
+ t.headers.append(G, "1"), t.headers.delete(G);
2535
2556
  return;
2536
2557
  } catch {
2537
2558
  e.res = new Response(t.body, {
@@ -2543,7 +2564,7 @@ function W(e) {
2543
2564
  }
2544
2565
  //#endregion
2545
2566
  //#region src/data-plane/handlers/cors.ts
2546
- var Ln = e.object({
2567
+ var Bn = e.object({
2547
2568
  origins: e.array(e.string()).optional(),
2548
2569
  allow_credentials: e.boolean().optional(),
2549
2570
  allow_headers: e.array(e.string()).optional(),
@@ -2551,44 +2572,44 @@ var Ln = e.object({
2551
2572
  expose_headers: e.array(e.string()).optional(),
2552
2573
  max_age: e.number().int().optional()
2553
2574
  }).refine((e) => !(e.allow_credentials && e.origins?.includes("*")), { message: "Cannot use wildcard origin (*) with allow_credentials" });
2554
- function G(e, t) {
2575
+ function Y(e, t) {
2555
2576
  let n = new Headers(), r = e.origins ?? ["*"], i = r.includes("*");
2556
2577
  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
2578
  }
2558
- var K = B({
2579
+ var Vn = B({
2559
2580
  type: "cors",
2560
- optionsSchema: Ln,
2581
+ optionsSchema: Bn,
2561
2582
  build(e) {
2562
2583
  return async (t, n) => {
2563
2584
  let r = t.req.header("origin") ?? null;
2564
2585
  if (t.req.method === "OPTIONS" && r !== null && t.req.header("access-control-request-method") !== void 0) {
2565
- let t = G(e, r);
2586
+ let t = Y(e, r);
2566
2587
  return new Response(null, {
2567
2588
  status: 204,
2568
2589
  headers: t
2569
2590
  });
2570
2591
  }
2571
2592
  await n();
2572
- let i = G(e, r);
2573
- W(t), i.forEach((e, n) => {
2593
+ let i = Y(e, r);
2594
+ J(t), i.forEach((e, n) => {
2574
2595
  n.toLowerCase() === "vary" ? t.res.headers.append(n, e) : t.res.headers.set(n, e);
2575
2596
  });
2576
2597
  };
2577
2598
  }
2578
- }), Rn = e.object({
2599
+ }), Hn = e.object({
2579
2600
  username: e.string(),
2580
2601
  password: e.string(),
2581
2602
  realm: e.string().optional()
2582
2603
  });
2583
- function zn(e, t) {
2604
+ function Un(e, t) {
2584
2605
  let n = `${e}:${t}`;
2585
2606
  return typeof btoa == "function" ? btoa(n) : Buffer.from(n, "utf-8").toString("base64");
2586
2607
  }
2587
- var q = B({
2608
+ var Wn = B({
2588
2609
  type: "basic_auth",
2589
- optionsSchema: Rn,
2610
+ optionsSchema: Hn,
2590
2611
  build(e) {
2591
- let t = zn(e.username, e.password), n = (e.realm ?? "Restricted").replace(/["\\\r\n]/g, "");
2612
+ let t = Un(e.username, e.password), n = (e.realm ?? "Restricted").replace(/["\\\r\n]/g, "");
2592
2613
  return async (e, r) => {
2593
2614
  let i = e.req.header("authorization");
2594
2615
  if (i) {
@@ -2604,7 +2625,7 @@ var q = B({
2604
2625
  });
2605
2626
  };
2606
2627
  }
2607
- }), J = B({
2628
+ }), Gn = B({
2608
2629
  type: "headers",
2609
2630
  optionsSchema: e.object({
2610
2631
  request: e.record(e.string(), e.string()).optional(),
@@ -2614,23 +2635,23 @@ var q = B({
2614
2635
  }),
2615
2636
  build(e) {
2616
2637
  return async (t, n) => {
2617
- if ((e.request || e.remove_request) && U(t, (t) => {
2638
+ if ((e.request || e.remove_request) && q(t, (t) => {
2618
2639
  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) && (W(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);
2640
+ }), 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
2641
  };
2621
2642
  }
2622
- }), Y = B({
2643
+ }), Kn = B({
2623
2644
  type: "cache",
2624
2645
  optionsSchema: e.object({ ttl_seconds: e.number().int().positive() }),
2625
2646
  build(e) {
2626
2647
  return async (t, n) => {
2627
2648
  if (await n(), !t.res.headers.has("Cache-Control")) {
2628
2649
  let n = t.res.headers.has("set-cookie") ? "private" : "public";
2629
- W(t), t.res.headers.set("Cache-Control", `${n}, max-age=${e.ttl_seconds}`);
2650
+ J(t), t.res.headers.set("Cache-Control", `${n}, max-age=${e.ttl_seconds}`);
2630
2651
  }
2631
2652
  };
2632
2653
  }
2633
- }), Bn = B({
2654
+ }), qn = B({
2634
2655
  type: "forwarded_headers",
2635
2656
  optionsSchema: e.object({
2636
2657
  client_ip_header: e.string().default("cf-connecting-ip"),
@@ -2640,40 +2661,40 @@ var q = B({
2640
2661
  build(e) {
2641
2662
  return async (t, n) => {
2642
2663
  let r = new URL(t.req.url);
2643
- U(t, (n) => {
2664
+ q(t, (n) => {
2644
2665
  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
2666
  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
2667
  n.set("x-forwarded-for", c), e.set_x_real_ip && n.set("x-real-ip", o);
2647
2668
  }), await n();
2648
2669
  };
2649
2670
  }
2650
- }), Vn = e.object({ upstream_host: e.string().optional() });
2651
- function Hn(e) {
2671
+ }), Jn = e.object({ upstream_host: e.string().optional() });
2672
+ function Yn(e) {
2652
2673
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2653
2674
  }
2654
- function Un(e) {
2675
+ function Xn(e) {
2655
2676
  if (typeof e.getSetCookie == "function") return e.getSetCookie();
2656
2677
  let t = [];
2657
2678
  return e.forEach((e, n) => {
2658
2679
  n.toLowerCase() === "set-cookie" && t.push(e);
2659
2680
  }), t;
2660
2681
  }
2661
- var Wn = B({
2682
+ var Zn = B({
2662
2683
  type: "rewrite_cookies",
2663
- optionsSchema: Vn,
2684
+ optionsSchema: Jn,
2664
2685
  build(e) {
2665
2686
  return async (t, n) => {
2666
2687
  await n();
2667
2688
  let r = new URL(t.req.url).hostname, i = e.upstream_host ?? t.get("__proxy_upstream_host__");
2668
2689
  if (!i) return;
2669
- let a = Un(t.res.headers);
2690
+ let a = Xn(t.res.headers);
2670
2691
  if (a.length === 0) return;
2671
- let o = Hn(i), s = RegExp(`(?:^|;\\s*)Domain=\\.?${o}(?=;|$)`, "i");
2672
- W(t), t.res.headers.delete("set-cookie");
2692
+ let o = Yn(i), s = RegExp(`(?:^|;\\s*)Domain=\\.?${o}(?=;|$)`, "i");
2693
+ J(t), t.res.headers.delete("set-cookie");
2673
2694
  for (let e of a) t.res.headers.append("set-cookie", e.replace(s, `Domain=${r}`));
2674
2695
  };
2675
2696
  }
2676
- }), Gn = B({
2697
+ }), Qn = B({
2677
2698
  type: "rewrite_location",
2678
2699
  optionsSchema: e.object({ upstream_origin: e.string().optional() }),
2679
2700
  build(e) {
@@ -2693,10 +2714,10 @@ var Wn = B({
2693
2714
  }
2694
2715
  if (o.origin !== a) return;
2695
2716
  let s = new URL(t.req.url), c = `${`${s.protocol}//${s.host}`}${o.pathname}${o.search}${o.hash}`;
2696
- W(t), t.res.headers.set("location", c);
2717
+ J(t), t.res.headers.set("location", c);
2697
2718
  };
2698
2719
  }
2699
- }), Kn = new Set([
2720
+ }), $n = new Set([
2700
2721
  "connection",
2701
2722
  "keep-alive",
2702
2723
  "proxy-authenticate",
@@ -2705,24 +2726,24 @@ var Wn = B({
2705
2726
  "trailers",
2706
2727
  "transfer-encoding",
2707
2728
  "upgrade"
2708
- ]), qn = 3e4, Jn = e.object({
2729
+ ]), er = 3e4, tr = e.object({
2709
2730
  upstream_url: e.string(),
2710
2731
  preserve_host: e.boolean().default(!1),
2711
2732
  timeout_ms: e.number().int().positive().optional()
2712
2733
  });
2713
- function Yn(e, t) {
2734
+ function nr(e, t) {
2714
2735
  return e === "" || e === "/" ? t : `${e.endsWith("/") ? e.slice(0, -1) : e}${t.startsWith("/") ? t : `/${t}`}`;
2715
2736
  }
2716
- function Xn(e) {
2737
+ function rr(e) {
2717
2738
  return e !== "GET" && e !== "HEAD";
2718
2739
  }
2719
- function Zn(e, t) {
2740
+ function ir(e, t) {
2720
2741
  let n = new URL(t.url), r = new URL(e.upstream_url);
2721
- r.pathname = Yn(r.pathname, n.pathname), r.search = n.search;
2742
+ r.pathname = nr(r.pathname, n.pathname), r.search = n.search;
2722
2743
  let i = new Headers(t.headers);
2723
- for (let e of Kn) i.delete(e);
2744
+ for (let e of $n) i.delete(e);
2724
2745
  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 = Xn(t.method) ? t.body : void 0, o = {
2746
+ let a = rr(t.method) ? t.body : void 0, o = {
2726
2747
  method: t.method,
2727
2748
  headers: i,
2728
2749
  body: a,
@@ -2733,13 +2754,13 @@ function Zn(e, t) {
2733
2754
  init: o
2734
2755
  };
2735
2756
  }
2736
- var Qn = B({
2757
+ var ar = B({
2737
2758
  type: "http",
2738
- optionsSchema: Jn,
2759
+ optionsSchema: tr,
2739
2760
  build(e) {
2740
- let t = e.timeout_ms ?? qn;
2761
+ let t = e.timeout_ms ?? er;
2741
2762
  return async (n) => {
2742
- let { target: r, init: i } = Zn(e, H(n));
2763
+ let { target: r, init: i } = ir(e, K(n));
2743
2764
  n.set("__proxy_upstream_host__", r.hostname), n.set("__proxy_upstream_origin__", `${r.protocol}//${r.host}`);
2744
2765
  let a = new AbortController(), o = setTimeout(() => a.abort(), t);
2745
2766
  try {
@@ -2755,30 +2776,71 @@ var Qn = B({
2755
2776
  }
2756
2777
  };
2757
2778
  }
2758
- }), $n = e.object({
2779
+ }), or = e.object({
2759
2780
  binding: e.string(),
2760
2781
  upstream_url: e.string().optional(),
2761
2782
  preserve_host: e.boolean().default(!0)
2762
2783
  });
2763
- function er(e) {
2784
+ function sr(e) {
2764
2785
  return typeof e == "object" && !!e && typeof e.fetch == "function";
2765
2786
  }
2766
- var tr = B({
2787
+ var cr = B({
2767
2788
  type: "service_binding",
2768
- optionsSchema: $n,
2789
+ optionsSchema: or,
2769
2790
  build(e, t) {
2770
2791
  let n = t.bindings[e.binding];
2771
- if (!er(n)) throw Error(`Service binding "${e.binding}" is not configured or is not a Fetcher`);
2792
+ if (!sr(n)) throw Error(`Service binding "${e.binding}" is not configured or is not a Fetcher`);
2772
2793
  let r = e.upstream_url ?? `https://${e.binding}.binding.invalid/`;
2773
2794
  return async (t) => {
2774
- let i = H(t), { target: a, init: o } = Zn({
2795
+ let i = K(t), { target: a, init: o } = ir({
2775
2796
  upstream_url: r,
2776
2797
  preserve_host: e.preserve_host
2777
2798
  }, i);
2778
2799
  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
2800
  };
2780
2801
  }
2781
- }), nr = B({
2802
+ }), lr = e.object({
2803
+ binding: e.string(),
2804
+ script_name: e.string(),
2805
+ cpu_ms: e.number().int().positive().optional(),
2806
+ subrequests: e.number().int().positive().optional()
2807
+ });
2808
+ function ur(e) {
2809
+ return typeof e == "object" && !!e && typeof e.get == "function";
2810
+ }
2811
+ var X = /\{(tenant_id|custom_domain_id|domain|host)\}/g;
2812
+ function dr(e) {
2813
+ return X.lastIndex = 0, X.test(e);
2814
+ }
2815
+ var fr = B({
2816
+ type: "dispatch_namespace",
2817
+ optionsSchema: lr,
2818
+ build(e, t) {
2819
+ let n = t.bindings[e.binding];
2820
+ if (!ur(n)) throw Error(`Dispatch namespace binding "${e.binding}" is not configured or does not expose .get()`);
2821
+ let r = dr(e.script_name), i = e.cpu_ms || e.subrequests ? { limits: {
2822
+ ...e.cpu_ms ? { cpuMs: e.cpu_ms } : {},
2823
+ ...e.subrequests ? { subrequests: e.subrequests } : {}
2824
+ } } : void 0;
2825
+ return async (t) => {
2826
+ let a = e.script_name;
2827
+ if (r) {
2828
+ let n = Ln(t), r = Rn(t), i = zn(t), o = t.req.header("host") ?? t.req.header("x-forwarded-host") ?? "";
2829
+ if (a = a.replace(X, (e, t) => {
2830
+ switch (t) {
2831
+ case "tenant_id": return n ?? "";
2832
+ case "custom_domain_id": return r ?? "";
2833
+ case "domain": return i ?? "";
2834
+ case "host": return o;
2835
+ default: return "";
2836
+ }
2837
+ }), a.includes("{") || a === "") return t.text(`dispatch_namespace: could not resolve script name from template "${e.script_name}"`, 500);
2838
+ }
2839
+ let o = n.get(a, void 0, i), s = K(t);
2840
+ return o.fetch(s);
2841
+ };
2842
+ }
2843
+ }), pr = B({
2782
2844
  type: "redirect",
2783
2845
  optionsSchema: e.object({
2784
2846
  upstream_url: e.string().refine((e) => {
@@ -2807,7 +2869,7 @@ var tr = B({
2807
2869
  });
2808
2870
  };
2809
2871
  }
2810
- }), rr = B({
2872
+ }), mr = B({
2811
2873
  type: "static",
2812
2874
  optionsSchema: e.object({
2813
2875
  status: e.number().int().default(200),
@@ -2827,15 +2889,15 @@ var tr = B({
2827
2889
  });
2828
2890
  //#endregion
2829
2891
  //#region src/data-plane/handlers/index.ts
2830
- function X(e) {
2831
- e.add(K).add(q).add(J).add(Y).add(Bn).add(Wn).add(Gn).add(Qn).add(tr).add(nr).add(rr);
2892
+ function hr(e) {
2893
+ 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
2894
  }
2833
2895
  //#endregion
2834
2896
  //#region src/data-plane/matcher.ts
2835
- function ir(e) {
2897
+ function gr(e) {
2836
2898
  return [...e].sort((e, t) => e.priority === t.priority ? e.created_at.localeCompare(t.created_at) : e.priority - t.priority);
2837
2899
  }
2838
- function ar(e, t) {
2900
+ function _r(e, t) {
2839
2901
  let n = e.toLowerCase(), r = t.toLowerCase();
2840
2902
  if (n === r) return !0;
2841
2903
  if (n.startsWith("*.")) {
@@ -2844,13 +2906,13 @@ function ar(e, t) {
2844
2906
  }
2845
2907
  return !1;
2846
2908
  }
2847
- function or(e, t) {
2848
- return !e || e.length === 0 ? !0 : e.some((e) => ar(e, t));
2909
+ function vr(e, t) {
2910
+ return !e || e.length === 0 ? !0 : e.some((e) => _r(e, t));
2849
2911
  }
2850
- function sr(e) {
2912
+ function yr(e) {
2851
2913
  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
2914
  return async (e, i) => {
2853
- if (r && !or(r, e.req.header("host") ?? "")) return new Response("No matching route", { status: 404 });
2915
+ if (r && !vr(r, e.req.header("host") ?? "")) return new Response("No matching route", { status: 404 });
2854
2916
  for (let [n, r] of t) {
2855
2917
  let t = e.req.header(n);
2856
2918
  if (t === void 0 || !r.test(t)) return new Response("No matching route", { status: 404 });
@@ -2867,7 +2929,7 @@ function sr(e) {
2867
2929
  }
2868
2930
  //#endregion
2869
2931
  //#region src/data-plane/compile.ts
2870
- var cr = [
2932
+ var br = [
2871
2933
  "GET",
2872
2934
  "POST",
2873
2935
  "PUT",
@@ -2876,45 +2938,53 @@ var cr = [
2876
2938
  "OPTIONS",
2877
2939
  "HEAD"
2878
2940
  ];
2879
- function lr(e, n) {
2880
- let r = new t(), i = ir(e);
2881
- for (let e of i) {
2941
+ function xr(e, n, r) {
2942
+ let i = new t();
2943
+ r && i.use("*", async (e, t) => {
2944
+ In(e, r), await t();
2945
+ });
2946
+ let a = gr(e);
2947
+ for (let e of a) {
2882
2948
  let t = [];
2883
- t.push(sr(e.match));
2949
+ t.push(yr(e.match));
2884
2950
  for (let r of e.handlers) t.push(n.build(r.type, r.options));
2885
- let i = e.match.methods?.length ? e.match.methods.map((e) => e.toUpperCase()) : cr, a = e.match.path || "/*";
2886
- r.on(i, [a], ...t);
2951
+ let r = e.match.methods?.length ? e.match.methods.map((e) => e.toUpperCase()) : br, a = e.match.path || "/*";
2952
+ i.on(r, [a], ...t);
2887
2953
  }
2888
- return r.all("*", (e) => e.text("No matching route", 404)), r;
2954
+ return i.all("*", (e) => e.text("No matching route", 404)), i;
2889
2955
  }
2890
2956
  //#endregion
2891
2957
  //#region src/data-plane/router.ts
2892
- function ur(e) {
2958
+ function Sr(e) {
2893
2959
  return e.resolver ? e.resolver : e.cache ? R(e.data, e.cache) : R(e.data, e.cacheTtlMs ?? 3e4);
2894
2960
  }
2895
- function dr(e) {
2961
+ function Cr(e) {
2896
2962
  if (e.registry) return e.registry;
2897
2963
  let t = new z(e.bindings ?? {});
2898
- return X(t), t;
2964
+ return hr(t), t;
2899
2965
  }
2900
2966
  function Z(e) {
2901
- let t = ur(e), n = dr(e), r = /* @__PURE__ */ new WeakMap();
2967
+ let t = Sr(e), n = Cr(e), r = /* @__PURE__ */ new WeakMap();
2902
2968
  return async (e) => {
2903
2969
  let i = e.req.header("host") ?? e.req.header("x-forwarded-host");
2904
2970
  if (!i) return e.text("Missing host", 400);
2905
2971
  let a = await t.resolveHost(i);
2906
2972
  if (!a) return e.text("Unknown host", 404);
2907
2973
  let o = r.get(a);
2908
- return o || (o = lr(a.routes, n), r.set(a, o)), o.fetch(e.req.raw);
2974
+ return o || (o = xr(a.routes, n, {
2975
+ tenant_id: a.tenant_id,
2976
+ custom_domain_id: a.custom_domain_id,
2977
+ domain: a.domain
2978
+ }), r.set(a, o)), o.fetch(e.req.raw);
2909
2979
  };
2910
2980
  }
2911
- function fr(e) {
2981
+ function wr(e) {
2912
2982
  let n = new t();
2913
2983
  return n.all("*", Z(e)), n;
2914
2984
  }
2915
2985
  //#endregion
2916
2986
  //#region src/app.ts
2917
- function pr(e) {
2987
+ function Tr(e) {
2918
2988
  let n = new t();
2919
2989
  return n.all("*", Z({
2920
2990
  data: e.data,
@@ -2929,11 +2999,11 @@ function pr(e) {
2929
2999
  function Q(e, t) {
2930
3000
  return new Request(`https://proxy-cache.internal/${encodeURIComponent(e)}/hosts/${encodeURIComponent(t.toLowerCase())}`, { method: "GET" });
2931
3001
  }
2932
- function mr() {
3002
+ function Er() {
2933
3003
  return globalThis.caches?.default;
2934
3004
  }
2935
- function hr(e) {
2936
- let t = e.cache ?? mr();
3005
+ function Dr(e) {
3006
+ let t = e.cache ?? Er();
2937
3007
  if (!t) return e.upstream;
2938
3008
  let n = e.namespace ?? "authhero-proxy", r = e.cacheTtlSeconds ?? 60, i = e.negativeCacheTtlSeconds ?? 10, a = e.waitUntil;
2939
3009
  return { async resolveHost(o) {
@@ -2948,7 +3018,7 @@ function hr(e) {
2948
3018
  return a ? a(f) : await f.catch(() => void 0), l;
2949
3019
  } };
2950
3020
  }
2951
- function gr(e, t) {
3021
+ function Or(e, t) {
2952
3022
  return Q(e, t);
2953
3023
  }
2954
3024
  //#endregion
@@ -2956,7 +3026,7 @@ function gr(e, t) {
2956
3026
  function $() {
2957
3027
  throw Error("Static proxy adapter is read-only; configure routes at init time");
2958
3028
  }
2959
- function _r(e, t, n, r, i, a) {
3029
+ function kr(e, t, n, r, i, a) {
2960
3030
  return {
2961
3031
  id: e.id ?? `${n}:${t}`,
2962
3032
  tenant_id: r,
@@ -2971,10 +3041,10 @@ function _r(e, t, n, r, i, a) {
2971
3041
  updated_at: e.updated_at ?? a
2972
3042
  };
2973
3043
  }
2974
- function vr(e) {
3044
+ function Ar(e) {
2975
3045
  let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.defaultTenantId ?? "static", r = /* @__PURE__ */ new Map();
2976
3046
  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) => _r(n, r, e, s, c, t)).sort((e, t) => e.priority - t.priority);
3047
+ 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
3048
  r.set(e, {
2979
3049
  tenant_id: s,
2980
3050
  custom_domain_id: c,
@@ -3018,7 +3088,7 @@ function vr(e) {
3018
3088
  }
3019
3089
  };
3020
3090
  }
3021
- function yr(e, t = {}) {
3091
+ function jr(e, t = {}) {
3022
3092
  return {
3023
3093
  priority: t.priority,
3024
3094
  match: { path: t.path ?? "/*" },
@@ -3033,7 +3103,7 @@ function yr(e, t = {}) {
3033
3103
  }
3034
3104
  //#endregion
3035
3105
  //#region src/http-adapter/index.ts
3036
- function br() {
3106
+ function Mr() {
3037
3107
  let e = () => {
3038
3108
  throw Error("HTTP proxy adapter does not expose write access to proxy_routes; mutate via the control-plane management API");
3039
3109
  };
@@ -3055,7 +3125,7 @@ function br() {
3055
3125
  }
3056
3126
  };
3057
3127
  }
3058
- function xr(e) {
3128
+ function Nr(e) {
3059
3129
  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
3130
  function s(e) {
3061
3131
  let t = new AbortController(), n = setTimeout(() => t.abort(), o);
@@ -3087,7 +3157,7 @@ function xr(e) {
3087
3157
  }), l);
3088
3158
  }
3089
3159
  return {
3090
- proxyRoutes: br(),
3160
+ proxyRoutes: Mr(),
3091
3161
  async resolveHost(e) {
3092
3162
  let i = await d(), a = `${n}${r}${encodeURIComponent(e.toLowerCase())}`, o = await s((e) => t(a, {
3093
3163
  headers: { authorization: `Bearer ${i}` },
@@ -3100,4 +3170,4 @@ function xr(e) {
3100
3170
  };
3101
3171
  }
3102
3172
  //#endregion
3103
- export { z as HandlerRegistry, q as basicAuthHandler, gr as buildCacheApiKey, sr as buildMatchFilter, Y as cacheHandler, lr as compileHostApp, K as corsHandler, hr as createCacheApiHostCache, xr as createHttpProxyAdapter, R as createInMemoryHostCache, pr as createProxyApp, Z as createProxyDataPlaneHandler, fr as createProxyDataPlaneRouter, vr as createStaticProxyAdapter, B as defineHandler, Bn as forwardedHeadersHandler, P as handlerConfigSchema, J as headersHandler, Qn as httpHandler, yr as httpRoute, N as matchSchema, or as matchesAnyHost, ar as matchesHost, F as proxyRouteInsertSchema, mn as proxyRouteSchema, hn as proxyRouteUpdateSchema, nr as redirectHandler, X as registerBuiltinHandlers, Wn as rewriteCookiesHandler, Gn as rewriteLocationHandler, tr as serviceBindingHandler, ir as sortRoutes, rr as staticHandler };
3173
+ 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 };