release: WRNexusJS 0.2.29
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/helpers",
|
||||
"version": "0.2.28",
|
||||
"version": "0.2.29",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Safe convenience helpers for WrNexus request contexts and common application flows.",
|
||||
|
||||
@@ -136,3 +136,11 @@ export function redirectToLogin(
|
||||
target.searchParams.set(options.returnToParam ?? "returnTo", original.href);
|
||||
return Response.redirect(target, options.status ?? 302);
|
||||
}
|
||||
|
||||
export {
|
||||
appOrigin,
|
||||
appUrl,
|
||||
currentAppName,
|
||||
currentAppOrigin,
|
||||
workspaceAppOrigins,
|
||||
} from "./workspace.ts";
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
function workspaceOrigins(): Record<string, string> {
|
||||
const value = process.env.WRNEXUS_WORKSPACE_ORIGINS;
|
||||
|
||||
if (!value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return parsed as Record<string, string>;
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function normalizePath(path: string): string {
|
||||
if (!path) return "/";
|
||||
|
||||
return path.startsWith("/") ? path : `/${path}`;
|
||||
}
|
||||
|
||||
export function appOrigin(appName: string): string {
|
||||
const origins = workspaceOrigins();
|
||||
const origin = origins[appName];
|
||||
|
||||
if (!origin) {
|
||||
throw new Error(
|
||||
`Unknown workspace app "${appName}". Available apps: ${
|
||||
Object.keys(origins).join(", ") || "none"
|
||||
}.`,
|
||||
);
|
||||
}
|
||||
|
||||
return new URL(origin).origin;
|
||||
}
|
||||
|
||||
export function appUrl(appName: string, path = "/"): string {
|
||||
return new URL(normalizePath(path), `${appOrigin(appName)}/`).href;
|
||||
}
|
||||
|
||||
export function currentAppName(): string | undefined {
|
||||
return process.env.WRNEXUS_APP_NAME;
|
||||
}
|
||||
|
||||
export function currentAppOrigin(): string | undefined {
|
||||
const value = process.env.WRNEXUS_APP_ORIGIN;
|
||||
|
||||
return value ? new URL(value).origin : undefined;
|
||||
}
|
||||
|
||||
export function workspaceAppOrigins(): Readonly<Record<string, string>> {
|
||||
return Object.freeze({ ...workspaceOrigins() });
|
||||
}
|
||||
Reference in New Issue
Block a user