44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
/* global console */
|
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import process from "node:process";
|
|
|
|
const root = process.cwd();
|
|
const required = [
|
|
"packages/auth/package.json",
|
|
"packages/auth/src/engine.ts",
|
|
"packages/auth/src/plugin.ts",
|
|
"packages/auth/src/routes/api.ts",
|
|
"packages/auth/src/stores/memory.ts",
|
|
"packages/auth/src/stores/sql.ts",
|
|
"packages/auth/assets/client/auth.js",
|
|
"packages/auth/migrations/001_auth.sql",
|
|
"examples/auth-showcase/package.json",
|
|
];
|
|
for (const file of required) {
|
|
if (!existsSync(join(root, file))) throw new Error(`Missing authentication file: ${file}`);
|
|
}
|
|
const manifest = JSON.parse(readFileSync(join(root, "packages/auth/package.json"), "utf8"));
|
|
if (manifest.name !== "@wrnexus/auth") throw new Error("Invalid authentication package name");
|
|
if (manifest.version !== "0.5.0") throw new Error("Invalid authentication package version");
|
|
const components = readdirSync(join(root, "packages/auth/components")).filter((file) =>
|
|
file.endsWith(".wrn"),
|
|
);
|
|
if (components.length < 16)
|
|
throw new Error(`Expected at least 16 auth components, received ${components.length}`);
|
|
const plugin = readFileSync(join(root, "packages/auth/src/plugin.ts"), "utf8");
|
|
for (const expected of [
|
|
"clientRuntimes",
|
|
"routeEntries",
|
|
"middleware",
|
|
"migrations",
|
|
"devToolbarPanels",
|
|
]) {
|
|
if (!plugin.includes(expected)) throw new Error(`Auth plugin is missing ${expected}`);
|
|
}
|
|
const runtime = readFileSync(join(root, "packages/auth/assets/client/auth.js"), "utf8");
|
|
if (!runtime.includes("navigator.credentials")) throw new Error("Passkey runtime is incomplete");
|
|
if (runtime.includes("document.write"))
|
|
throw new Error("Passkey runtime contains unsafe document.write");
|
|
console.log(`@wrnexus/auth structural verification passed (${components.length} components).`);
|