fix: share authz catalog across package instances
This commit is contained in:
@@ -257,7 +257,7 @@
|
||||
},
|
||||
"packages/authz": {
|
||||
"name": "@wrnexus/authz",
|
||||
"version": "0.8.13",
|
||||
"version": "0.8.14",
|
||||
"dependencies": {
|
||||
"@wrnexus/core": "workspace:*",
|
||||
"@wrnexus/db": "workspace:*",
|
||||
@@ -357,7 +357,7 @@
|
||||
},
|
||||
"packages/dev-server": {
|
||||
"name": "@wrnexus/dev-server",
|
||||
"version": "0.8.45",
|
||||
"version": "0.8.46",
|
||||
"dependencies": {
|
||||
"@wrnexus/authz": "workspace:*",
|
||||
"@wrnexus/cache": "workspace:*",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/authz",
|
||||
"version": "0.8.13",
|
||||
"version": "0.8.14",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/dev-server",
|
||||
"version": "0.8.45",
|
||||
"version": "0.8.46",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
Reference in New Issue
Block a user