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
+2 -2
View File
@@ -257,7 +257,7 @@
}, },
"packages/authz": { "packages/authz": {
"name": "@wrnexus/authz", "name": "@wrnexus/authz",
"version": "0.8.13", "version": "0.8.14",
"dependencies": { "dependencies": {
"@wrnexus/core": "workspace:*", "@wrnexus/core": "workspace:*",
"@wrnexus/db": "workspace:*", "@wrnexus/db": "workspace:*",
@@ -357,7 +357,7 @@
}, },
"packages/dev-server": { "packages/dev-server": {
"name": "@wrnexus/dev-server", "name": "@wrnexus/dev-server",
"version": "0.8.45", "version": "0.8.46",
"dependencies": { "dependencies": {
"@wrnexus/authz": "workspace:*", "@wrnexus/authz": "workspace:*",
"@wrnexus/cache": "workspace:*", "@wrnexus/cache": "workspace:*",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/authz", "name": "@wrnexus/authz",
"version": "0.8.13", "version": "0.8.14",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
+13 -3
View File
@@ -32,16 +32,26 @@
import type { AuthzCatalog } from "./types.ts"; 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). */ /** Set the process-wide authorization catalog (called by the framework at boot). */
export function setAuthzCatalog(next: AuthzCatalog): AuthzCatalog { export function setAuthzCatalog(next: AuthzCatalog): AuthzCatalog {
catalog = next; state().catalog = next;
return next; return next;
} }
/** The process-wide authorization catalog. Throws if it hasn't been set. */ /** The process-wide authorization catalog. Throws if it hasn't been set. */
export function getAuthzCatalog(): AuthzCatalog { export function getAuthzCatalog(): AuthzCatalog {
const catalog = state().catalog;
if (!catalog) { if (!catalog) {
throw new Error( throw new Error(
"WRN-AUTHZ-SETUP: no authorization catalog is configured. The dev server and " + "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. */ /** Whether the process-wide authorization catalog has been set. */
export function hasAuthzCatalog(): boolean { export function hasAuthzCatalog(): boolean {
return catalog !== undefined; return state().catalog !== undefined;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@wrnexus/dev-server", "name": "@wrnexus/dev-server",
"version": "0.8.45", "version": "0.8.46",
"type": "module", "type": "module",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {