@authhero/proxy 0.10.4 → 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/dist/proxy.d.ts CHANGED
@@ -183,6 +183,7 @@ declare const forwardedHeadersHandler: HandlerDefinition<{
183
183
  client_ip_header: string;
184
184
  set_x_real_ip: boolean;
185
185
  set_x_original_url: boolean;
186
+ skip_cloudflare_client_ip: boolean;
186
187
  }>;
187
188
 
188
189
  declare const rewriteCookiesHandler: HandlerDefinition<{
@@ -236,6 +237,33 @@ interface ProxyHostContext {
236
237
  domain: string;
237
238
  }
238
239
 
240
+ declare const FORWARDED_HEADERS_HANDLER_TYPE = "forwarded_headers";
241
+ /**
242
+ * Minimal shape shared by stored route handlers (`HandlerConfig`) and the
243
+ * catch-all specs passed to the data plane (`ProxyRouteHandlerSpec`).
244
+ */
245
+ interface HandlerSpecLike {
246
+ type: string;
247
+ options?: unknown;
248
+ }
249
+ /**
250
+ * Guarantee a `forwarded_headers` handler at the head of a chain. Stored route
251
+ * tables (KV / control plane) predate the handler and routinely omit it, which
252
+ * silently drops the visitor IP: nothing else in the chain stamps
253
+ * X-Forwarded-For / X-Real-IP, so upstreams see only the proxy hop's own
254
+ * source address. Chains that already declare it — anywhere in the list — are
255
+ * returned untouched so their configured options win and nothing is stamped
256
+ * twice. Prefer `withForwardedHeadersFor`, which also checks that the registry
257
+ * knows the handler.
258
+ */
259
+ declare function withForwardedHeaders(handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
260
+ /**
261
+ * `withForwardedHeaders`, but a no-op unless `registry` knows the handler — a
262
+ * consumer with a bespoke registry that never registered it would otherwise
263
+ * get a build-time throw on every route. Every chain the data plane compiles
264
+ * (per-host routes and the `defaultHandlers` catch-all) goes through here.
265
+ */
266
+ declare function withForwardedHeadersFor(registry: HandlerRegistry, handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
239
267
  /**
240
268
  * Build a Hono app whose route table mirrors the configured proxy routes for
241
269
  * a single host. Compiled once per host (and cached alongside the resolved
@@ -245,12 +273,23 @@ interface ProxyHostContext {
245
273
  * `handlers/util.ts`). Handlers that template against those values
246
274
  * (`dispatch_namespace`) depend on this wiring.
247
275
  *
276
+ * Every route's handler chain is normalized through
277
+ * `withForwardedHeadersFor`, so a stored route table that omits
278
+ * `forwarded_headers` still forwards the visitor IP.
279
+ *
248
280
  * `defaultHandlers` is a prebuilt middleware chain installed as the catch-all
249
281
  * when no per-host route matches. Pass `undefined` to keep the legacy 404
250
- * "No matching route" behavior.
282
+ * "No matching route" behavior. It is built by the caller (`router.ts`), which
283
+ * applies `withForwardedHeadersFor` to it as well.
251
284
  */
252
285
  declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext, defaultHandlers?: MiddlewareHandler[]): Hono;
253
286
 
287
+ /**
288
+ * True when `ip` falls inside a Cloudflare-published range. Unparseable input
289
+ * returns false — callers treat "not recognizably Cloudflare" as a client IP.
290
+ */
291
+ declare function isCloudflareIp(ip: string): boolean;
292
+
254
293
  declare function sortRoutes(routes: ProxyRoute[]): ProxyRoute[];
255
294
  /**
256
295
  * Match a configured host pattern against a request's `Host`. Supports
@@ -394,5 +433,5 @@ declare function createKvProxyAdapter(options: KvProxyAdapterOptions): ProxyData
394
433
  */
395
434
  declare const PROXY_RESOLVE_HOST_SCOPE = "proxy:resolve_host";
396
435
 
397
- export { DEFAULT_KV_HOST_KEY_PREFIX, HandlerRegistry, PROXY_RESOLVE_HOST_SCOPE, basicAuthHandler, buildCacheAdapterKey, buildCacheApiKey, buildKvHostKey, buildMatchFilter, cacheHandler, compileHostApp, corsHandler, createCacheAdapterHostCache, createCacheApiHostCache, createHttpProxyAdapter, createInMemoryHostCache, createKvProxyAdapter, createProxyApp, createProxyDataPlaneHandler, createProxyDataPlaneRouter, createServiceBindingFetch, createStaticProxyAdapter, defineHandler, dispatchNamespaceHandler, forwardedHeadersHandler, headersHandler, httpHandler, httpRoute, matchesAnyHost, matchesHost, redirectHandler, registerBuiltinHandlers, rewriteCookiesHandler, rewriteLocationHandler, serviceBindingHandler, sortRoutes, staticHandler };
398
- export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, KvNamespaceReader, KvNamespaceWriter, KvProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ProxyRouteHandlerSpec, ResolvedHost, ServiceBindingFetcher, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };
436
+ export { DEFAULT_KV_HOST_KEY_PREFIX, FORWARDED_HEADERS_HANDLER_TYPE, HandlerRegistry, PROXY_RESOLVE_HOST_SCOPE, basicAuthHandler, buildCacheAdapterKey, buildCacheApiKey, buildKvHostKey, buildMatchFilter, cacheHandler, compileHostApp, corsHandler, createCacheAdapterHostCache, createCacheApiHostCache, createHttpProxyAdapter, createInMemoryHostCache, createKvProxyAdapter, createProxyApp, createProxyDataPlaneHandler, createProxyDataPlaneRouter, createServiceBindingFetch, createStaticProxyAdapter, defineHandler, dispatchNamespaceHandler, forwardedHeadersHandler, headersHandler, httpHandler, httpRoute, isCloudflareIp, matchesAnyHost, matchesHost, redirectHandler, registerBuiltinHandlers, rewriteCookiesHandler, rewriteLocationHandler, serviceBindingHandler, sortRoutes, staticHandler, withForwardedHeaders, withForwardedHeadersFor };
437
+ export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HandlerSpecLike, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, KvNamespaceReader, KvNamespaceWriter, KvProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ProxyRouteHandlerSpec, ResolvedHost, ServiceBindingFetcher, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };