@authhero/proxy 0.7.5 → 0.8.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/dist/proxy.d.ts CHANGED
@@ -316,6 +316,46 @@ interface HttpProxyAdapterOptions {
316
316
  */
317
317
  declare function createHttpProxyAdapter(options: HttpProxyAdapterOptions): ProxyDataAdapter;
318
318
 
319
+ /**
320
+ * Minimal structural view of a Cloudflare KV namespace's read surface. Declared
321
+ * locally so `@authhero/proxy` stays free of a hard `@cloudflare/workers-types`
322
+ * dependency — a real `KVNamespace` binding is structurally assignable to this.
323
+ */
324
+ interface KvNamespaceReader {
325
+ get<T = unknown>(key: string, type: "json"): Promise<T | null>;
326
+ }
327
+ /**
328
+ * Minimal structural view of a Cloudflare KV namespace's write surface, consumed
329
+ * by the control-plane publisher. A real `KVNamespace` is assignable to this.
330
+ */
331
+ interface KvNamespaceWriter {
332
+ put(key: string, value: string): Promise<void>;
333
+ delete(key: string): Promise<void>;
334
+ }
335
+ declare const DEFAULT_KV_HOST_KEY_PREFIX = "authhero-proxy-host:";
336
+ /**
337
+ * Build the KV key for a host. Shared by the proxy reader
338
+ * (`createKvProxyAdapter`) and the control-plane publisher so both agree on the
339
+ * exact key format. Hosts are lowercased for case-insensitive lookups.
340
+ */
341
+ declare function buildKvHostKey(keyPrefix: string, host: string): string;
342
+ interface KvProxyAdapterOptions {
343
+ kv: KvNamespaceReader;
344
+ keyPrefix?: string;
345
+ timeoutMs?: number;
346
+ }
347
+ /**
348
+ * Build a `ProxyDataAdapter` that resolves hosts from a Cloudflare KV namespace.
349
+ * The control plane publishes the full `ResolvedHost` blob per host into KV; the
350
+ * proxy reads it with a single, unauthenticated, edge-local `KV.get` — faster
351
+ * and more reliable on cold reads than the two-hop HTTP control-plane adapter.
352
+ *
353
+ * Intended to sit in the `upstream` seam of `createCacheAdapterHostCache` as the
354
+ * durable-edge layer. A null from KV means "not found"; callers can keep the
355
+ * HTTP adapter as a miss / `stale-if-error` fallback during cutover.
356
+ */
357
+ declare function createKvProxyAdapter(options: KvProxyAdapterOptions): ProxyDataAdapter;
358
+
319
359
  /**
320
360
  * Scope a control-plane bearer token must carry to call
321
361
  * `GET /api/v2/proxy/control-plane/hosts/:host` or `POST /sync`. The data
@@ -324,5 +364,5 @@ declare function createHttpProxyAdapter(options: HttpProxyAdapterOptions): Proxy
324
364
  */
325
365
  declare const PROXY_RESOLVE_HOST_SCOPE = "proxy:resolve_host";
326
366
 
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 };
328
- export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ProxyRouteHandlerSpec, ResolvedHost, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };
367
+ 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, createStaticProxyAdapter, defineHandler, dispatchNamespaceHandler, forwardedHeadersHandler, headersHandler, httpHandler, httpRoute, matchesAnyHost, matchesHost, redirectHandler, registerBuiltinHandlers, rewriteCookiesHandler, rewriteLocationHandler, serviceBindingHandler, sortRoutes, staticHandler };
368
+ export type { CacheAdapterHostCacheOptions, CacheApiHostCacheOptions, HandlerBuildContext, HandlerDefinition, HostCacheOptions, HostResolverCache, HttpProxyAdapterOptions, KvNamespaceReader, KvNamespaceWriter, KvProxyAdapterOptions, ProxyAppOptions, ProxyDataAdapter, ProxyDataPlaneOptions, ProxyRouteHandlerSpec, ResolvedHost, StaticHostConfig, StaticProxyAdapterOptions, StaticRouteInput };
package/dist/proxy.mjs CHANGED
@@ -2178,7 +2178,14 @@ e.array(En), e.object({
2178
2178
  clientID: e.string().openapi({ description: "The id of the client the grant was issued to" }),
2179
2179
  audience: e.string().optional().openapi({ description: "The audience the grant applies to" }),
2180
2180
  scope: e.array(e.string()).default([]).openapi({ description: "The list of OAuth scopes the user has consented to" })
2181
- }).extend({ id: e.string() });
2181
+ }).extend({ id: e.string() }), e.object({
2182
+ user_id: e.string(),
2183
+ last_login: e.string().optional(),
2184
+ last_ip: e.string().optional(),
2185
+ login_count: e.number().default(0),
2186
+ failed_logins: e.array(e.string()).optional(),
2187
+ last_password_reset: e.string().optional()
2188
+ });
2182
2189
  var Dn = e.object({
2183
2190
  user_id: e.string(),
2184
2191
  resource_server_identifier: e.string(),
@@ -3335,4 +3342,42 @@ function Yr(e) {
3335
3342
  };
3336
3343
  }
3337
3344
  //#endregion
3338
- export { F as HandlerRegistry, qr as PROXY_RESOLVE_HOST_SCOPE, Xn as basicAuthHandler, Ur as buildCacheAdapterKey, zr as buildCacheApiKey, Dr as buildMatchFilter, Qn as cacheHandler, Z as compileHostApp, qn as corsHandler, Hr as createCacheAdapterHostCache, Rr as createCacheApiHostCache, Yr as createHttpProxyAdapter, P as createInMemoryHostCache, Nr as createProxyApp, Q as createProxyDataPlaneHandler, Mr as createProxyDataPlaneRouter, Gr as createStaticProxyAdapter, I as defineHandler, xr as dispatchNamespaceHandler, $n as forwardedHeadersHandler, yn as handlerConfigSchema, Zn as headersHandler, fr as httpHandler, Kr as httpRoute, vn as matchSchema, Er as matchesAnyHost, Tr as matchesHost, j as proxyRouteInsertSchema, bn as proxyRouteSchema, xn as proxyRouteUpdateSchema, Sr as redirectHandler, wr as registerBuiltinHandlers, rr as rewriteCookiesHandler, ir as rewriteLocationHandler, gr as serviceBindingHandler, X as sortRoutes, Cr as staticHandler };
3345
+ //#region src/kv-adapter/index.ts
3346
+ var Xr = "authhero-proxy-host:";
3347
+ function Zr(e, t) {
3348
+ return `${e}${t.toLowerCase()}`;
3349
+ }
3350
+ function Qr() {
3351
+ let e = () => {
3352
+ throw Error("KV proxy adapter does not expose write access to proxy_routes; mutate via the control-plane management API");
3353
+ };
3354
+ return {
3355
+ async create() {
3356
+ return e();
3357
+ },
3358
+ async update() {
3359
+ return e();
3360
+ },
3361
+ async remove() {
3362
+ return e();
3363
+ },
3364
+ async get() {
3365
+ throw Error("KV proxy adapter does not expose per-route reads; use resolveHost");
3366
+ },
3367
+ async list() {
3368
+ throw Error("KV proxy adapter does not expose per-route reads; use resolveHost");
3369
+ }
3370
+ };
3371
+ }
3372
+ function $r(e) {
3373
+ let { kv: t, keyPrefix: n = Xr, timeoutMs: r } = e;
3374
+ return {
3375
+ proxyRoutes: Qr(),
3376
+ async resolveHost(e) {
3377
+ let i = Zr(n, e), a = t.get(i, "json");
3378
+ return (r && r > 0 ? await J(a, r, "kv.get") : await a) ?? null;
3379
+ }
3380
+ };
3381
+ }
3382
+ //#endregion
3383
+ export { Xr as DEFAULT_KV_HOST_KEY_PREFIX, F as HandlerRegistry, qr as PROXY_RESOLVE_HOST_SCOPE, Xn as basicAuthHandler, Ur as buildCacheAdapterKey, zr as buildCacheApiKey, Zr as buildKvHostKey, Dr as buildMatchFilter, Qn as cacheHandler, Z as compileHostApp, qn as corsHandler, Hr as createCacheAdapterHostCache, Rr as createCacheApiHostCache, Yr as createHttpProxyAdapter, P as createInMemoryHostCache, $r as createKvProxyAdapter, Nr as createProxyApp, Q as createProxyDataPlaneHandler, Mr as createProxyDataPlaneRouter, Gr as createStaticProxyAdapter, I as defineHandler, xr as dispatchNamespaceHandler, $n as forwardedHeadersHandler, yn as handlerConfigSchema, Zn as headersHandler, fr as httpHandler, Kr as httpRoute, vn as matchSchema, Er as matchesAnyHost, Tr as matchesHost, j as proxyRouteInsertSchema, bn as proxyRouteSchema, xn as proxyRouteUpdateSchema, Sr as redirectHandler, wr as registerBuiltinHandlers, rr as rewriteCookiesHandler, ir as rewriteLocationHandler, gr as serviceBindingHandler, X as sortRoutes, Cr as staticHandler };