@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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CacheAdapter } from "@authhero/adapter-interfaces";
|
|
2
|
+
import type { HostResolverCache } from "./cache";
|
|
3
|
+
export interface CacheAdapterHostCacheOptions {
|
|
4
|
+
upstream: HostResolverCache;
|
|
5
|
+
cache: CacheAdapter;
|
|
6
|
+
freshTtlMs: number;
|
|
7
|
+
staleTtlMs?: number;
|
|
8
|
+
negativeTtlMs?: number;
|
|
9
|
+
keyPrefix?: string;
|
|
10
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Wraps an upstream `HostResolverCache` with a generic `CacheAdapter` layer.
|
|
14
|
+
* Adds stale-while-revalidate semantics on top of any cache implementation
|
|
15
|
+
* — Cloudflare Cache API (via `CloudflareCache` from `@authhero/cloudflare-adapter`),
|
|
16
|
+
* Redis, in-memory, or anything else satisfying the `CacheAdapter` interface.
|
|
17
|
+
*
|
|
18
|
+
* Typical use on Cloudflare Workers:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createCloudflareCache } from "@authhero/cloudflare-adapter";
|
|
22
|
+
* import { createCacheAdapterHostCache, createInMemoryHostCache } from "@authhero/proxy";
|
|
23
|
+
*
|
|
24
|
+
* const cache = createCloudflareCache({ cacheName: "authhero-proxy-hosts" });
|
|
25
|
+
* const resolver = createCacheAdapterHostCache({
|
|
26
|
+
* upstream: createInMemoryHostCache(data, { freshTtlMs: 60_000 }),
|
|
27
|
+
* cache,
|
|
28
|
+
* freshTtlMs: 60 * 60_000, // 1 hour fresh
|
|
29
|
+
* staleTtlMs: 23 * 60 * 60_000, // SWR for 23 more hours (24h total)
|
|
30
|
+
* waitUntil: (p) => ctx.waitUntil(p),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Invalidation is the caller's responsibility — when a host's routes change,
|
|
35
|
+
* call `cache.delete(buildCacheAdapterKey(keyPrefix, host))` from the control
|
|
36
|
+
* plane. Otherwise entries expire on their own TTL.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createCacheAdapterHostCache(options: CacheAdapterHostCacheOptions): HostResolverCache;
|
|
39
|
+
export declare function buildCacheAdapterKey(keyPrefix: string, host: string): string;
|
|
@@ -15,6 +15,11 @@ export interface CacheApiHostCacheOptions {
|
|
|
15
15
|
* Invalidation is the caller's responsibility — typically the control plane
|
|
16
16
|
* issues `cache.delete(syntheticKey(...))` on every proxy_route mutation,
|
|
17
17
|
* and each colo's cache expires on its own TTL otherwise.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Prefer `createCacheAdapterHostCache` with `createCloudflareCache`
|
|
20
|
+
* from `@authhero/cloudflare-adapter`. The adapter-based wrapper supports
|
|
21
|
+
* stale-while-revalidate and works with any `CacheAdapter` (Cloudflare,
|
|
22
|
+
* Redis, in-memory, …).
|
|
18
23
|
*/
|
|
19
24
|
export declare function createCacheApiHostCache(options: CacheApiHostCacheOptions): HostResolverCache;
|
|
20
25
|
export declare function buildCacheApiKey(namespace: string, host: string): Request;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { createInMemoryHostCache } from "./data-plane/cache";
|
|
|
8
8
|
export type { HostCacheOptions, HostResolverCache } from "./data-plane/cache";
|
|
9
9
|
export { createCacheApiHostCache, buildCacheApiKey, } from "./data-plane/cache-api-cache";
|
|
10
10
|
export type { CacheApiHostCacheOptions } from "./data-plane/cache-api-cache";
|
|
11
|
+
export { createCacheAdapterHostCache, buildCacheAdapterKey, } from "./data-plane/cache-adapter-cache";
|
|
12
|
+
export type { CacheAdapterHostCacheOptions } from "./data-plane/cache-adapter-cache";
|
|
11
13
|
export { HandlerRegistry, defineHandler } from "./data-plane/registry";
|
|
12
14
|
export type { HandlerDefinition, HandlerBuildContext, } from "./data-plane/registry";
|
|
13
15
|
export { registerBuiltinHandlers, corsHandler, basicAuthHandler, headersHandler, cacheHandler, forwardedHeadersHandler, rewriteCookiesHandler, rewriteLocationHandler, httpHandler, serviceBindingHandler, dispatchNamespaceHandler, redirectHandler, staticHandler, } from "./data-plane/handlers";
|
|
@@ -17,3 +19,4 @@ export { createStaticProxyAdapter, httpRoute } from "./static";
|
|
|
17
19
|
export type { StaticProxyAdapterOptions, StaticHostConfig, StaticRouteInput, } from "./static";
|
|
18
20
|
export { createHttpProxyAdapter } from "./http-adapter";
|
|
19
21
|
export type { HttpProxyAdapterOptions } from "./http-adapter";
|
|
22
|
+
export { PROXY_RESOLVE_HOST_SCOPE } from "./constants";
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
13
|
},
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.5.1",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"hono": "^4.6.8"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@authhero/adapter-interfaces": "3.
|
|
42
|
+
"@authhero/adapter-interfaces": "3.1.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "vite build && tsc -p tsconfig.types.json && rollup -c rollup.dts.config.mjs",
|