release: WRNexusJS 0.2.29

This commit is contained in:
2026-07-14 17:34:51 +05:30
parent e27c92e3b6
commit e6dbb5b0fc
62 changed files with 513 additions and 292 deletions
+1 -1
View File
@@ -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.",
+8
View File
@@ -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";
+58
View File
@@ -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() });
}