@authhero/proxy 0.5.1 → 0.7.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/dist/proxy.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ProxyRoute, ProxyRoutesAdapter, CacheAdapter, RouteMatch, HandlerConfig } from '@authhero/adapter-interfaces';
2
2
  export { HandlerConfig, ListProxyRoutesParams, ListProxyRoutesResult, ProxyRoute, ProxyRouteInsert, ProxyRouteUpdate, ProxyRoutesAdapter, RouteMatch, handlerConfigSchema, matchSchema, proxyRouteInsertSchema, proxyRouteSchema, proxyRouteUpdateSchema } from '@authhero/adapter-interfaces';
3
- import { MiddlewareHandler, Hono, Context } from 'hono';
3
+ import { MiddlewareHandler, Context, Hono } from 'hono';
4
4
  import { z } from '@hono/zod-openapi';
5
5
 
6
6
  interface ResolvedHost {
@@ -28,6 +28,7 @@ interface HostResolverCache {
28
28
  interface HostCacheOptions {
29
29
  freshTtlMs: number;
30
30
  staleTtlMs?: number;
31
+ staleIfErrorTtlMs?: number;
31
32
  negativeTtlMs?: number;
32
33
  maxEntries?: number;
33
34
  waitUntil?: (promise: Promise<unknown>) => void;
@@ -53,26 +54,34 @@ declare class HandlerRegistry {
53
54
  }
54
55
  declare function defineHandler<TOptions>(def: HandlerDefinition<TOptions>): HandlerDefinition<TOptions>;
55
56
 
56
- interface ProxyAppOptions {
57
+ interface ProxyRouteHandlerSpec {
58
+ type: string;
59
+ options?: unknown;
60
+ }
61
+ interface ProxyDataPlaneOptions {
57
62
  data: ProxyDataAdapter;
58
63
  cacheTtlMs?: number;
59
64
  cache?: HostCacheOptions;
60
65
  resolver?: HostResolverCache;
61
66
  registry?: HandlerRegistry;
62
67
  bindings?: Record<string, unknown>;
68
+ resolveHostTimeoutMs?: number;
69
+ defaultHandlers?: ProxyRouteHandlerSpec[];
63
70
  }
64
- declare function createProxyApp(options: ProxyAppOptions): Hono;
71
+ declare function createProxyDataPlaneHandler(options: ProxyDataPlaneOptions): (c: Context) => Promise<Response>;
72
+ declare function createProxyDataPlaneRouter(options: ProxyDataPlaneOptions): Hono;
65
73
 
66
- interface ProxyDataPlaneOptions {
74
+ interface ProxyAppOptions {
67
75
  data: ProxyDataAdapter;
68
76
  cacheTtlMs?: number;
69
77
  cache?: HostCacheOptions;
70
78
  resolver?: HostResolverCache;
71
79
  registry?: HandlerRegistry;
72
80
  bindings?: Record<string, unknown>;
81
+ resolveHostTimeoutMs?: number;
82
+ defaultHandlers?: ProxyRouteHandlerSpec[];
73
83
  }
74
- declare function createProxyDataPlaneHandler(options: ProxyDataPlaneOptions): (c: Context) => Promise<Response>;
75
- declare function createProxyDataPlaneRouter(options: ProxyDataPlaneOptions): Hono;
84
+ declare function createProxyApp(options: ProxyAppOptions): Hono;
76
85
 
77
86
  interface CacheApiHostCacheOptions {
78
87
  upstream: HostResolverCache;
@@ -81,6 +90,8 @@ interface CacheApiHostCacheOptions {
81
90
  namespace?: string;
82
91
  cache?: Cache;
83
92
  waitUntil?: (promise: Promise<unknown>) => void;
93
+ cacheReadTimeoutMs?: number;
94
+ cacheWriteTimeoutMs?: number;
84
95
  }
85
96
  /**
86
97
  * Wraps an upstream `HostResolverCache` with a Cloudflare Cache-API layer.
@@ -93,8 +104,8 @@ interface CacheApiHostCacheOptions {
93
104
  *
94
105
  * @deprecated Prefer `createCacheAdapterHostCache` with `createCloudflareCache`
95
106
  * from `@authhero/cloudflare-adapter`. The adapter-based wrapper supports
96
- * stale-while-revalidate and works with any `CacheAdapter` (Cloudflare,
97
- * Redis, in-memory, …).
107
+ * stale-while-revalidate, stale-if-error, and works with any `CacheAdapter`
108
+ * (Cloudflare, Redis, in-memory, …).
98
109
  */
99
110
  declare function createCacheApiHostCache(options: CacheApiHostCacheOptions): HostResolverCache;
100
111
  declare function buildCacheApiKey(namespace: string, host: string): Request;
@@ -104,15 +115,19 @@ interface CacheAdapterHostCacheOptions {
104
115
  cache: CacheAdapter;
105
116
  freshTtlMs: number;
106
117
  staleTtlMs?: number;
118
+ staleIfErrorTtlMs?: number;
107
119
  negativeTtlMs?: number;
108
120
  keyPrefix?: string;
109
121
  waitUntil?: (promise: Promise<unknown>) => void;
122
+ cacheReadTimeoutMs?: number;
123
+ cacheWriteTimeoutMs?: number;
110
124
  }
111
125
  /**
112
126
  * Wraps an upstream `HostResolverCache` with a generic `CacheAdapter` layer.
113
- * Adds stale-while-revalidate semantics on top of any cache implementation
114
- * — Cloudflare Cache API (via `CloudflareCache` from `@authhero/cloudflare-adapter`),
115
- * Redis, in-memory, or anything else satisfying the `CacheAdapter` interface.
127
+ * Adds stale-while-revalidate and stale-if-error semantics on top of any
128
+ * cache implementation — Cloudflare Cache API (via `CloudflareCache` from
129
+ * `@authhero/cloudflare-adapter`), Redis, in-memory, or anything else
130
+ * satisfying the `CacheAdapter` interface.
116
131
  *
117
132
  * Typical use on Cloudflare Workers:
118
133
  *
@@ -126,6 +141,7 @@ interface CacheAdapterHostCacheOptions {
126
141
  * cache,
127
142
  * freshTtlMs: 60 * 60_000, // 1 hour fresh
128
143
  * staleTtlMs: 23 * 60 * 60_000, // SWR for 23 more hours (24h total)
144
+ * staleIfErrorTtlMs: 24 * 60 * 60_000, // serve last-known-good for one more day on upstream errors
129
145
  * waitUntil: (p) => ctx.waitUntil(p),
130
146
  * });
131
147
  * ```
@@ -187,6 +203,7 @@ declare const serviceBindingHandler: HandlerDefinition<{
187
203
  binding: string;
188
204
  preserve_host: boolean;
189
205
  upstream_url?: string | undefined;
206
+ timeout_ms?: number | undefined;
190
207
  }>;
191
208
 
192
209
  declare const dispatchNamespaceHandler: HandlerDefinition<{
@@ -194,6 +211,7 @@ declare const dispatchNamespaceHandler: HandlerDefinition<{
194
211
  script_name: string;
195
212
  cpu_ms?: number | undefined;
196
213
  subrequests?: number | undefined;
214
+ timeout_ms?: number | undefined;
197
215
  }>;
198
216
 
199
217
  declare const redirectHandler: HandlerDefinition<{
@@ -226,8 +244,12 @@ interface ProxyHostContext {
226
244
  * `domain` set in its Hono context (read with `getProxy*` helpers from
227
245
  * `handlers/util.ts`). Handlers that template against those values
228
246
  * (`dispatch_namespace`) depend on this wiring.
247
+ *
248
+ * `defaultHandlers` is a prebuilt middleware chain installed as the catch-all
249
+ * when no per-host route matches. Pass `undefined` to keep the legacy 404
250
+ * "No matching route" behavior.
229
251
  */
230
- declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext): Hono;
252
+ declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext, defaultHandlers?: MiddlewareHandler[]): Hono;
231
253
 
232
254
  declare function sortRoutes(routes: ProxyRoute[]): ProxyRoute[];
233
255
  /**
@@ -303,4 +325,4 @@ declare function createHttpProxyAdapter(options: HttpProxyAdapterOptions): Proxy
303
325
  declare const PROXY_RESOLVE_HOST_SCOPE = "proxy:resolve_host";
304
326
 
305
327
  export { HandlerRegistry, PROXY_RESOLVE_HOST_SCOPE, basicAuthHandler, buildCacheAdapterKey, buildCacheApiKey, buildMatchFilter, cacheHandler, compileHostApp, corsHandler, createCacheAdapterHostCache, createCacheApiHostCache, createHttpProxyAdapter, createInMemoryHostCache, createProxyApp, createProxyDataPlaneHandler, createProxyDataPlaneRouter, createStaticProxyAdapter, defineHandler, dispatchNamespaceHandler, forwardedHeadersHandler, headersHandler, httpHandler, httpRoute, matchesAnyHost, matchesHost, redirectHandler, registerBuiltinHandlers, rewriteCookiesHandler, rewriteLocationHandler, serviceBindingHandler, sortRoutes, staticHandler };
306
- export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ResolvedHost, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };
328
+ export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ProxyRouteHandlerSpec, ResolvedHost, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };