@authhero/proxy 0.10.5 → 0.10.6
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 +7 -1
- package/dist/proxy.cjs +1 -1
- package/dist/proxy.d.ts +42 -3
- package/dist/proxy.mjs +395 -278
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/data-plane/cloudflare-ips.d.ts +11 -0
- package/dist/types/data-plane/compile.d.ts +33 -1
- package/dist/types/data-plane/handlers/forwarded-headers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a textual IP address into its bytes: 4 for IPv4, 16 for IPv6.
|
|
3
|
+
* IPv4-mapped IPv6 (`::ffff:1.2.3.4`) collapses to the 4-byte form so it is
|
|
4
|
+
* matched against the IPv4 ranges. Returns null for anything unparseable.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseIpAddress(input: string): number[] | null;
|
|
7
|
+
/**
|
|
8
|
+
* True when `ip` falls inside a Cloudflare-published range. Unparseable input
|
|
9
|
+
* returns false — callers treat "not recognizably Cloudflare" as a client IP.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isCloudflareIp(ip: string): boolean;
|
|
@@ -3,6 +3,33 @@ import type { MiddlewareHandler } from "hono";
|
|
|
3
3
|
import type { ProxyRoute } from "../types";
|
|
4
4
|
import { HandlerRegistry } from "./registry";
|
|
5
5
|
import { type ProxyHostContext } from "./handlers/util";
|
|
6
|
+
export declare const FORWARDED_HEADERS_HANDLER_TYPE = "forwarded_headers";
|
|
7
|
+
/**
|
|
8
|
+
* Minimal shape shared by stored route handlers (`HandlerConfig`) and the
|
|
9
|
+
* catch-all specs passed to the data plane (`ProxyRouteHandlerSpec`).
|
|
10
|
+
*/
|
|
11
|
+
export interface HandlerSpecLike {
|
|
12
|
+
type: string;
|
|
13
|
+
options?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Guarantee a `forwarded_headers` handler at the head of a chain. Stored route
|
|
17
|
+
* tables (KV / control plane) predate the handler and routinely omit it, which
|
|
18
|
+
* silently drops the visitor IP: nothing else in the chain stamps
|
|
19
|
+
* X-Forwarded-For / X-Real-IP, so upstreams see only the proxy hop's own
|
|
20
|
+
* source address. Chains that already declare it — anywhere in the list — are
|
|
21
|
+
* returned untouched so their configured options win and nothing is stamped
|
|
22
|
+
* twice. Prefer `withForwardedHeadersFor`, which also checks that the registry
|
|
23
|
+
* knows the handler.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withForwardedHeaders(handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
|
|
26
|
+
/**
|
|
27
|
+
* `withForwardedHeaders`, but a no-op unless `registry` knows the handler — a
|
|
28
|
+
* consumer with a bespoke registry that never registered it would otherwise
|
|
29
|
+
* get a build-time throw on every route. Every chain the data plane compiles
|
|
30
|
+
* (per-host routes and the `defaultHandlers` catch-all) goes through here.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withForwardedHeadersFor(registry: HandlerRegistry, handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
|
|
6
33
|
/**
|
|
7
34
|
* Build a Hono app whose route table mirrors the configured proxy routes for
|
|
8
35
|
* a single host. Compiled once per host (and cached alongside the resolved
|
|
@@ -12,8 +39,13 @@ import { type ProxyHostContext } from "./handlers/util";
|
|
|
12
39
|
* `handlers/util.ts`). Handlers that template against those values
|
|
13
40
|
* (`dispatch_namespace`) depend on this wiring.
|
|
14
41
|
*
|
|
42
|
+
* Every route's handler chain is normalized through
|
|
43
|
+
* `withForwardedHeadersFor`, so a stored route table that omits
|
|
44
|
+
* `forwarded_headers` still forwards the visitor IP.
|
|
45
|
+
*
|
|
15
46
|
* `defaultHandlers` is a prebuilt middleware chain installed as the catch-all
|
|
16
47
|
* when no per-host route matches. Pass `undefined` to keep the legacy 404
|
|
17
|
-
* "No matching route" behavior.
|
|
48
|
+
* "No matching route" behavior. It is built by the caller (`router.ts`), which
|
|
49
|
+
* applies `withForwardedHeadersFor` to it as well.
|
|
18
50
|
*/
|
|
19
51
|
export declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext, defaultHandlers?: MiddlewareHandler[]): Hono;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export type { CacheAdapterHostCacheOptions } from "./data-plane/cache-adapter-ca
|
|
|
13
13
|
export { HandlerRegistry, defineHandler } from "./data-plane/registry";
|
|
14
14
|
export type { HandlerDefinition, HandlerBuildContext, } from "./data-plane/registry";
|
|
15
15
|
export { registerBuiltinHandlers, corsHandler, basicAuthHandler, headersHandler, cacheHandler, forwardedHeadersHandler, rewriteCookiesHandler, rewriteLocationHandler, httpHandler, serviceBindingHandler, dispatchNamespaceHandler, redirectHandler, staticHandler, } from "./data-plane/handlers";
|
|
16
|
-
export { compileHostApp } from "./data-plane/compile";
|
|
16
|
+
export { compileHostApp, withForwardedHeaders, withForwardedHeadersFor, FORWARDED_HEADERS_HANDLER_TYPE, } from "./data-plane/compile";
|
|
17
|
+
export type { HandlerSpecLike } from "./data-plane/compile";
|
|
18
|
+
export { isCloudflareIp } from "./data-plane/cloudflare-ips";
|
|
17
19
|
export { sortRoutes, matchesHost, matchesAnyHost, buildMatchFilter, } from "./data-plane/matcher";
|
|
18
20
|
export { createStaticProxyAdapter, httpRoute } from "./static";
|
|
19
21
|
export type { StaticProxyAdapterOptions, StaticHostConfig, StaticRouteInput, } from "./static";
|