@authhero/proxy 0.4.5 → 0.5.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/README.md +20 -10
- package/dist/proxy.cjs +1 -1
- package/dist/proxy.d.ts +56 -3
- package/dist/proxy.mjs +265 -214
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/app.d.ts +2 -1
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/data-plane/cache-adapter-cache.d.ts +39 -0
- package/dist/types/data-plane/cache-api-cache.d.ts +5 -0
- package/dist/types/http-adapter/index.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +2 -2
package/dist/proxy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProxyRoute, ProxyRoutesAdapter, RouteMatch, HandlerConfig } from '@authhero/adapter-interfaces';
|
|
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
3
|
import { MiddlewareHandler, Hono, Context } from 'hono';
|
|
4
4
|
import { z } from '@hono/zod-openapi';
|
|
@@ -57,6 +57,7 @@ interface ProxyAppOptions {
|
|
|
57
57
|
data: ProxyDataAdapter;
|
|
58
58
|
cacheTtlMs?: number;
|
|
59
59
|
cache?: HostCacheOptions;
|
|
60
|
+
resolver?: HostResolverCache;
|
|
60
61
|
registry?: HandlerRegistry;
|
|
61
62
|
bindings?: Record<string, unknown>;
|
|
62
63
|
}
|
|
@@ -89,10 +90,53 @@ interface CacheApiHostCacheOptions {
|
|
|
89
90
|
* Invalidation is the caller's responsibility — typically the control plane
|
|
90
91
|
* issues `cache.delete(syntheticKey(...))` on every proxy_route mutation,
|
|
91
92
|
* and each colo's cache expires on its own TTL otherwise.
|
|
93
|
+
*
|
|
94
|
+
* @deprecated Prefer `createCacheAdapterHostCache` with `createCloudflareCache`
|
|
95
|
+
* from `@authhero/cloudflare-adapter`. The adapter-based wrapper supports
|
|
96
|
+
* stale-while-revalidate and works with any `CacheAdapter` (Cloudflare,
|
|
97
|
+
* Redis, in-memory, …).
|
|
92
98
|
*/
|
|
93
99
|
declare function createCacheApiHostCache(options: CacheApiHostCacheOptions): HostResolverCache;
|
|
94
100
|
declare function buildCacheApiKey(namespace: string, host: string): Request;
|
|
95
101
|
|
|
102
|
+
interface CacheAdapterHostCacheOptions {
|
|
103
|
+
upstream: HostResolverCache;
|
|
104
|
+
cache: CacheAdapter;
|
|
105
|
+
freshTtlMs: number;
|
|
106
|
+
staleTtlMs?: number;
|
|
107
|
+
negativeTtlMs?: number;
|
|
108
|
+
keyPrefix?: string;
|
|
109
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 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.
|
|
116
|
+
*
|
|
117
|
+
* Typical use on Cloudflare Workers:
|
|
118
|
+
*
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { createCloudflareCache } from "@authhero/cloudflare-adapter";
|
|
121
|
+
* import { createCacheAdapterHostCache, createInMemoryHostCache } from "@authhero/proxy";
|
|
122
|
+
*
|
|
123
|
+
* const cache = createCloudflareCache({ cacheName: "authhero-proxy-hosts" });
|
|
124
|
+
* const resolver = createCacheAdapterHostCache({
|
|
125
|
+
* upstream: createInMemoryHostCache(data, { freshTtlMs: 60_000 }),
|
|
126
|
+
* cache,
|
|
127
|
+
* freshTtlMs: 60 * 60_000, // 1 hour fresh
|
|
128
|
+
* staleTtlMs: 23 * 60 * 60_000, // SWR for 23 more hours (24h total)
|
|
129
|
+
* waitUntil: (p) => ctx.waitUntil(p),
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* Invalidation is the caller's responsibility — when a host's routes change,
|
|
134
|
+
* call `cache.delete(buildCacheAdapterKey(keyPrefix, host))` from the control
|
|
135
|
+
* plane. Otherwise entries expire on their own TTL.
|
|
136
|
+
*/
|
|
137
|
+
declare function createCacheAdapterHostCache(options: CacheAdapterHostCacheOptions): HostResolverCache;
|
|
138
|
+
declare function buildCacheAdapterKey(keyPrefix: string, host: string): string;
|
|
139
|
+
|
|
96
140
|
declare const corsHandler: HandlerDefinition<{
|
|
97
141
|
origins?: string[] | undefined;
|
|
98
142
|
allow_credentials?: boolean | undefined;
|
|
@@ -232,6 +276,7 @@ interface HttpProxyAdapterOptions {
|
|
|
232
276
|
clientId: string;
|
|
233
277
|
clientSecret: string;
|
|
234
278
|
audience?: string;
|
|
279
|
+
scope?: string;
|
|
235
280
|
resolveHostPath?: string;
|
|
236
281
|
tokenRefreshSkewSeconds?: number;
|
|
237
282
|
timeoutMs?: number;
|
|
@@ -249,5 +294,13 @@ interface HttpProxyAdapterOptions {
|
|
|
249
294
|
*/
|
|
250
295
|
declare function createHttpProxyAdapter(options: HttpProxyAdapterOptions): ProxyDataAdapter;
|
|
251
296
|
|
|
252
|
-
|
|
253
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Scope a control-plane bearer token must carry to call
|
|
299
|
+
* `GET /api/v2/proxy/control-plane/hosts/:host` or `POST /sync`. The data
|
|
300
|
+
* plane requests it when minting tokens; the control plane requires it when
|
|
301
|
+
* verifying them.
|
|
302
|
+
*/
|
|
303
|
+
declare const PROXY_RESOLVE_HOST_SCOPE = "proxy:resolve_host";
|
|
304
|
+
|
|
305
|
+
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 };
|