fix: share authz catalog across package instances
Quality / quality (ubuntu-latest) (push) Failing after 9m49s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-22 23:30:01 +05:30
parent 7c5069b5b5
commit 37439188ca
4 changed files with 17 additions and 7 deletions
+13 -3
View File
@@ -32,16 +32,26 @@
import type { AuthzCatalog } from "./types.ts";
let catalog: AuthzCatalog | undefined;
interface AuthzCatalogState {
catalog?: AuthzCatalog;
}
const catalogKey = Symbol.for("@wrnexus/authz:catalog:v1");
function state(): AuthzCatalogState {
const global = globalThis as Record<PropertyKey, unknown>;
return (global[catalogKey] ??= {}) as AuthzCatalogState;
}
/** Set the process-wide authorization catalog (called by the framework at boot). */
export function setAuthzCatalog(next: AuthzCatalog): AuthzCatalog {
catalog = next;
state().catalog = next;
return next;
}
/** The process-wide authorization catalog. Throws if it hasn't been set. */
export function getAuthzCatalog(): AuthzCatalog {
const catalog = state().catalog;
if (!catalog) {
throw new Error(
"WRN-AUTHZ-SETUP: no authorization catalog is configured. The dev server and " +
@@ -59,5 +69,5 @@ export function getAuthzCatalog(): AuthzCatalog {
/** Whether the process-wide authorization catalog has been set. */
export function hasAuthzCatalog(): boolean {
return catalog !== undefined;
return state().catalog !== undefined;
}