@decohere/scaffold 0.0.1-dev.125 → 0.0.1-dev.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -19
- package/src/add-api.action.ts +25 -0
- package/src/add-api.command.ts +31 -0
- package/src/add.command.ts +20 -0
- package/src/add.module.ts +11 -0
- package/src/cli.ts +4 -0
- package/src/create.command.ts +20 -0
- package/src/create.module.ts +11 -0
- package/src/domain/prompt.ts +50 -0
- package/{types/src/index.d.ts → src/index.ts} +0 -4
- package/src/models/compose.model.ts +205 -0
- package/src/models/config-yaml.model.ts +83 -0
- package/src/models/const.ts +20 -0
- package/src/models/dev-container.model.ts +136 -0
- package/src/models/docker-image.model.ts +343 -0
- package/src/models/env-file.model.ts +45 -0
- package/src/models/gitignore.model.ts +35 -0
- package/src/models/launch-json.model.ts +60 -0
- package/src/models/package-json.model.ts +169 -0
- package/src/models/project.model.ts +141 -0
- package/{types/src/models/source-file.d.ts → src/models/source-file.ts} +6 -4
- package/src/models/tsconfig.model.ts +29 -0
- package/src/models/vitest-config.model.ts +26 -0
- package/src/models/vscode-settings.model.ts +24 -0
- package/src/program.ts +63 -0
- package/{types/src/resolve-target-dir.d.ts → src/resolve-target-dir.ts} +4 -1
- package/src/services/scaffold.service.ts +89 -0
- package/src/version.ts +56 -0
- package/src/webapi/api-name.ts +73 -0
- package/src/webapi/cli-options.ts +56 -0
- package/{types/src/webapi/const.d.ts → src/webapi/const.ts} +21 -9
- package/src/webapi/create-api.ts +275 -0
- package/src/webapi/devcontainer/host-scripts.ts +35 -0
- package/src/webapi/features/auth.feature.ts +454 -0
- package/src/webapi/features/auth0-cli.ts +421 -0
- package/src/webapi/features/biome-format.ts +34 -0
- package/src/webapi/features/database.feature.ts +522 -0
- package/src/webapi/features/finalize.feature.ts +112 -0
- package/src/webapi/features/postman.feature.ts +287 -0
- package/src/webapi/models/api-package-json.model.ts +60 -0
- package/src/webapi/models/auth-config.model.ts +36 -0
- package/src/webapi/models/controller-source-file.model.ts +232 -0
- package/{es6/src/webapi/models/github-ci.model.js → src/webapi/models/github-ci.model.ts} +29 -27
- package/src/webapi/models/main-source-file.model.ts +208 -0
- package/src/webapi/models/production-dockerfile.model.ts +162 -0
- package/src/webapi/models/sample-files.model.ts +45 -0
- package/src/webapi/models/webapi-image.model.ts +21 -0
- package/src/webapi/postman/hello-openapi.ts +92 -0
- package/src/webapi/postman/local-view.ts +195 -0
- package/src/webapi/postman/openapi-to-postman.ts +208 -0
- package/src/webapi/workspace-readme.ts +192 -0
- package/src/webapi.action.ts +22 -0
- package/src/webapi.command.ts +41 -0
- package/tests/auth-postman.wiring.spec.ts +263 -0
- package/tests/auth0-cli.spec.ts +232 -0
- package/tests/biome-format.spec.ts +49 -0
- package/tests/cli.integration.spec.ts +658 -0
- package/tests/compose.model.spec.ts +51 -0
- package/tests/container-image.model.spec.ts +162 -0
- package/tests/dev-container.model.spec.ts +29 -0
- package/tests/devcontainer-base-image.spec.ts +32 -0
- package/tests/hello-di-inject.scaffold.spec.ts +18 -0
- package/tests/hello-route.contract.spec.ts +94 -0
- package/tests/package-json.order.spec.ts +59 -0
- package/tests/postman-from-openapi.spec.ts +197 -0
- package/tests/seed-devcontainer-templates.ts +40 -0
- package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +96 -0
- package/LICENSE +0 -15
- package/commonjs/src/add-api.action.js +0 -37
- package/commonjs/src/add-api.command.js +0 -39
- package/commonjs/src/add.command.js +0 -22
- package/commonjs/src/add.module.js +0 -24
- package/commonjs/src/auth0-configure.action.js +0 -28
- package/commonjs/src/auth0-configure.command.js +0 -24
- package/commonjs/src/auth0-login.action.js +0 -28
- package/commonjs/src/auth0-login.command.js +0 -23
- package/commonjs/src/auth0.command.js +0 -22
- package/commonjs/src/auth0.module.js +0 -28
- package/commonjs/src/cli.js +0 -8
- package/commonjs/src/create.command.js +0 -22
- package/commonjs/src/create.module.js +0 -24
- package/commonjs/src/domain/prompt.js +0 -62
- package/commonjs/src/index.js +0 -48
- package/commonjs/src/models/compose.model.js +0 -258
- package/commonjs/src/models/config-yaml.model.js +0 -86
- package/commonjs/src/models/const.js +0 -30
- package/commonjs/src/models/dev-container.model.js +0 -172
- package/commonjs/src/models/docker-image.model.js +0 -277
- package/commonjs/src/models/env-file.model.js +0 -48
- package/commonjs/src/models/gitignore.model.js +0 -48
- package/commonjs/src/models/launch-json.model.js +0 -70
- package/commonjs/src/models/package-json.model.js +0 -156
- package/commonjs/src/models/project.model.js +0 -132
- package/commonjs/src/models/source-file.js +0 -4
- package/commonjs/src/models/tsconfig.model.js +0 -32
- package/commonjs/src/models/vitest-config.model.js +0 -33
- package/commonjs/src/models/vscode-settings.model.js +0 -29
- package/commonjs/src/program.js +0 -64
- package/commonjs/src/resolve-target-dir.js +0 -17
- package/commonjs/src/services/scaffold.service.js +0 -60
- package/commonjs/src/version.js +0 -55
- package/commonjs/src/webapi/api-name.js +0 -93
- package/commonjs/src/webapi/auth0-commands.js +0 -250
- package/commonjs/src/webapi/authorize-scopes.js +0 -79
- package/commonjs/src/webapi/cli-options.js +0 -99
- package/commonjs/src/webapi/const.js +0 -54
- package/commonjs/src/webapi/create-api.js +0 -265
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +0 -164
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
- package/commonjs/src/webapi/devcontainer/host-scripts.js +0 -50
- package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
- package/commonjs/src/webapi/devcontainer/templates/initialize.sh +0 -169
- package/commonjs/src/webapi/devcontainer/templates/post-create.sh +0 -35
- package/commonjs/src/webapi/devcontainer/templates/post-start.sh +0 -65
- package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
- package/commonjs/src/webapi/features/auth.feature.js +0 -408
- package/commonjs/src/webapi/features/auth0-cli.js +0 -472
- package/commonjs/src/webapi/features/biome-format.js +0 -47
- package/commonjs/src/webapi/features/database.feature.js +0 -433
- package/commonjs/src/webapi/features/finalize.feature.js +0 -93
- package/commonjs/src/webapi/features/postman.feature.js +0 -322
- package/commonjs/src/webapi/models/api-package-json.model.js +0 -58
- package/commonjs/src/webapi/models/auth-config.model.js +0 -24
- package/commonjs/src/webapi/models/controller-source-file.model.js +0 -190
- package/commonjs/src/webapi/models/github-ci.model.js +0 -193
- package/commonjs/src/webapi/models/main-source-file.model.js +0 -165
- package/commonjs/src/webapi/models/production-dockerfile.model.js +0 -75
- package/commonjs/src/webapi/models/sample-files.model.js +0 -58
- package/commonjs/src/webapi/models/webapi-image.model.js +0 -25
- package/commonjs/src/webapi/postman/hello-openapi.js +0 -173
- package/commonjs/src/webapi/postman/local-view.js +0 -182
- package/commonjs/src/webapi/postman/openapi-to-postman.js +0 -238
- package/commonjs/src/webapi/workspace-readme.js +0 -109
- package/commonjs/src/webapi.action.js +0 -28
- package/commonjs/src/webapi.command.js +0 -43
- package/es6/src/add-api.action.js +0 -27
- package/es6/src/add-api.command.js +0 -29
- package/es6/src/add.command.js +0 -12
- package/es6/src/add.module.js +0 -14
- package/es6/src/auth0-configure.action.js +0 -18
- package/es6/src/auth0-configure.command.js +0 -14
- package/es6/src/auth0-login.action.js +0 -18
- package/es6/src/auth0-login.command.js +0 -13
- package/es6/src/auth0.command.js +0 -12
- package/es6/src/auth0.module.js +0 -18
- package/es6/src/cli.js +0 -4
- package/es6/src/create.command.js +0 -12
- package/es6/src/create.module.js +0 -14
- package/es6/src/domain/prompt.js +0 -41
- package/es6/src/index.js +0 -9
- package/es6/src/models/compose.model.js +0 -254
- package/es6/src/models/config-yaml.model.js +0 -74
- package/es6/src/models/const.js +0 -20
- package/es6/src/models/dev-container.model.js +0 -162
- package/es6/src/models/docker-image.model.js +0 -235
- package/es6/src/models/env-file.model.js +0 -44
- package/es6/src/models/gitignore.model.js +0 -38
- package/es6/src/models/launch-json.model.js +0 -60
- package/es6/src/models/package-json.model.js +0 -141
- package/es6/src/models/project.model.js +0 -117
- package/es6/src/models/source-file.js +0 -1
- package/es6/src/models/tsconfig.model.js +0 -22
- package/es6/src/models/vitest-config.model.js +0 -23
- package/es6/src/models/vscode-settings.model.js +0 -19
- package/es6/src/program.js +0 -50
- package/es6/src/resolve-target-dir.js +0 -7
- package/es6/src/services/scaffold.service.js +0 -50
- package/es6/src/version.js +0 -34
- package/es6/src/webapi/api-name.js +0 -57
- package/es6/src/webapi/auth0-commands.js +0 -185
- package/es6/src/webapi/authorize-scopes.js +0 -55
- package/es6/src/webapi/cli-options.js +0 -34
- package/es6/src/webapi/const.js +0 -21
- package/es6/src/webapi/create-api.js +0 -245
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +0 -154
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
- package/es6/src/webapi/devcontainer/host-scripts.js +0 -29
- package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
- package/es6/src/webapi/devcontainer/templates/initialize.sh +0 -169
- package/es6/src/webapi/devcontainer/templates/post-create.sh +0 -35
- package/es6/src/webapi/devcontainer/templates/post-start.sh +0 -65
- package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
- package/es6/src/webapi/features/auth.feature.js +0 -357
- package/es6/src/webapi/features/auth0-cli.js +0 -406
- package/es6/src/webapi/features/biome-format.js +0 -40
- package/es6/src/webapi/features/database.feature.js +0 -423
- package/es6/src/webapi/features/finalize.feature.js +0 -83
- package/es6/src/webapi/features/postman.feature.js +0 -256
- package/es6/src/webapi/models/api-package-json.model.js +0 -53
- package/es6/src/webapi/models/auth-config.model.js +0 -20
- package/es6/src/webapi/models/controller-source-file.model.js +0 -181
- package/es6/src/webapi/models/main-source-file.model.js +0 -161
- package/es6/src/webapi/models/production-dockerfile.model.js +0 -66
- package/es6/src/webapi/models/sample-files.model.js +0 -40
- package/es6/src/webapi/models/webapi-image.model.js +0 -18
- package/es6/src/webapi/postman/hello-openapi.js +0 -166
- package/es6/src/webapi/postman/local-view.js +0 -167
- package/es6/src/webapi/postman/openapi-to-postman.js +0 -179
- package/es6/src/webapi/workspace-readme.js +0 -88
- package/es6/src/webapi.action.js +0 -18
- package/es6/src/webapi.command.js +0 -33
- package/types/src/add-api.action.d.ts +0 -13
- package/types/src/add-api.command.d.ts +0 -7
- package/types/src/add.command.d.ts +0 -6
- package/types/src/add.module.d.ts +0 -14
- package/types/src/auth0-configure.action.d.ts +0 -7
- package/types/src/auth0-configure.command.d.ts +0 -6
- package/types/src/auth0-login.action.d.ts +0 -4
- package/types/src/auth0-login.command.d.ts +0 -6
- package/types/src/auth0.command.d.ts +0 -6
- package/types/src/auth0.module.d.ts +0 -18
- package/types/src/cli.d.ts +0 -2
- package/types/src/create.command.d.ts +0 -6
- package/types/src/create.module.d.ts +0 -14
- package/types/src/domain/prompt.d.ts +0 -4
- package/types/src/models/compose.model.d.ts +0 -73
- package/types/src/models/config-yaml.model.d.ts +0 -27
- package/types/src/models/const.d.ts +0 -20
- package/types/src/models/dev-container.model.d.ts +0 -49
- package/types/src/models/docker-image.model.d.ts +0 -90
- package/types/src/models/env-file.model.d.ts +0 -16
- package/types/src/models/gitignore.model.d.ts +0 -9
- package/types/src/models/launch-json.model.d.ts +0 -7
- package/types/src/models/package-json.model.d.ts +0 -36
- package/types/src/models/project.model.d.ts +0 -60
- package/types/src/models/tsconfig.model.d.ts +0 -5
- package/types/src/models/vitest-config.model.d.ts +0 -5
- package/types/src/models/vscode-settings.model.d.ts +0 -7
- package/types/src/program.d.ts +0 -8
- package/types/src/services/scaffold.service.d.ts +0 -22
- package/types/src/version.d.ts +0 -6
- package/types/src/webapi/api-name.d.ts +0 -14
- package/types/src/webapi/auth0-commands.d.ts +0 -11
- package/types/src/webapi/authorize-scopes.d.ts +0 -7
- package/types/src/webapi/cli-options.d.ts +0 -6
- package/types/src/webapi/create-api.d.ts +0 -15
- package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +0 -32
- package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
- package/types/src/webapi/devcontainer/host-scripts.d.ts +0 -7
- package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
- package/types/src/webapi/devcontainer/templates/initialize.sh +0 -169
- package/types/src/webapi/devcontainer/templates/post-create.sh +0 -35
- package/types/src/webapi/devcontainer/templates/post-start.sh +0 -65
- package/types/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
- package/types/src/webapi/features/auth.feature.d.ts +0 -10
- package/types/src/webapi/features/auth0-cli.d.ts +0 -84
- package/types/src/webapi/features/biome-format.d.ts +0 -5
- package/types/src/webapi/features/database.feature.d.ts +0 -7
- package/types/src/webapi/features/finalize.feature.d.ts +0 -2
- package/types/src/webapi/features/postman.feature.d.ts +0 -16
- package/types/src/webapi/models/api-package-json.model.d.ts +0 -18
- package/types/src/webapi/models/auth-config.model.d.ts +0 -26
- package/types/src/webapi/models/controller-source-file.model.d.ts +0 -46
- package/types/src/webapi/models/github-ci.model.d.ts +0 -9
- package/types/src/webapi/models/main-source-file.model.d.ts +0 -54
- package/types/src/webapi/models/production-dockerfile.model.d.ts +0 -18
- package/types/src/webapi/models/sample-files.model.d.ts +0 -7
- package/types/src/webapi/models/webapi-image.model.d.ts +0 -12
- package/types/src/webapi/postman/hello-openapi.d.ts +0 -19
- package/types/src/webapi/postman/local-view.d.ts +0 -17
- package/types/src/webapi/postman/openapi-to-postman.d.ts +0 -62
- package/types/src/webapi/workspace-readme.d.ts +0 -18
- package/types/src/webapi.action.d.ts +0 -14
- package/types/src/webapi.command.d.ts +0 -11
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resetMemfs } from "@decohere/nexus/testing";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { seedDevcontainerTemplates } from "./seed-devcontainer-templates.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Feature-level coverage for Auth0 + Postman wiring.
|
|
9
|
+
*
|
|
10
|
+
* webapi.spec.ts only asserts install behaviour with authProvider:"none" and
|
|
11
|
+
* stubs auth0-cli as isInstalled:false — so missing .env / empty auth0ClientId
|
|
12
|
+
* on re-scaffold never failed the suite.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
mockAsk,
|
|
17
|
+
mockPick,
|
|
18
|
+
mockInstall,
|
|
19
|
+
mockCreateAdminDatabaseUser,
|
|
20
|
+
mockEnsureSpaApp,
|
|
21
|
+
mockEnableConnectionForClient,
|
|
22
|
+
mockIsInstalled,
|
|
23
|
+
} = vi.hoisted(() => ({
|
|
24
|
+
mockAsk: vi.fn((_q: string, fallback = "") => Promise.resolve(fallback)),
|
|
25
|
+
mockPick: vi.fn(
|
|
26
|
+
<T>(_label: string, items: T[], _display: (item: T) => string): Promise<T | null> =>
|
|
27
|
+
Promise.resolve(items[0] ?? null),
|
|
28
|
+
),
|
|
29
|
+
mockInstall: vi.fn().mockResolvedValue({ message: "", data: [] }),
|
|
30
|
+
mockCreateAdminDatabaseUser: vi.fn(),
|
|
31
|
+
mockEnsureSpaApp: vi.fn(),
|
|
32
|
+
mockEnableConnectionForClient: vi.fn(),
|
|
33
|
+
mockIsInstalled: vi.fn(() => true),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const mockPm = {
|
|
37
|
+
name: "pnpm" as const,
|
|
38
|
+
install: mockInstall,
|
|
39
|
+
syncLockFile: vi.fn().mockResolvedValue({ message: "", data: [] }),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
vi.mock("../src/domain/prompt.js", async () => {
|
|
43
|
+
const actual = await import("../src/domain/prompt.js");
|
|
44
|
+
return { ...actual, ask: mockAsk, pick: mockPick };
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
vi.mock(import("../../nexus/src/interop/index.js"), async (importOriginal) => {
|
|
48
|
+
const actual = await importOriginal();
|
|
49
|
+
return {
|
|
50
|
+
...actual,
|
|
51
|
+
detectPackageManager: () => mockPm,
|
|
52
|
+
promptForPackageManager: () => Promise.resolve(mockPm),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
vi.mock(import("../src/webapi/features/auth0-cli.js"), async (importOriginal) => {
|
|
57
|
+
const actual = await importOriginal();
|
|
58
|
+
return {
|
|
59
|
+
...actual,
|
|
60
|
+
isInstalled: mockIsInstalled,
|
|
61
|
+
login: () => true,
|
|
62
|
+
listTenants: () => [{ name: "dev-tenant.us.auth0.com", active: true }],
|
|
63
|
+
listApis: () => [{ name: "webapi API", identifier: "https://api.webapi" }],
|
|
64
|
+
updateApiScopes: vi.fn(),
|
|
65
|
+
createAdminDatabaseUser: mockCreateAdminDatabaseUser,
|
|
66
|
+
ensureSpaApp: mockEnsureSpaApp,
|
|
67
|
+
createSpaApp: vi.fn(() => {
|
|
68
|
+
throw new Error("createSpaApp should not be called — use ensureSpaApp");
|
|
69
|
+
}),
|
|
70
|
+
enableConnectionForClient: mockEnableConnectionForClient,
|
|
71
|
+
generateAdminPassword: () => "Generated1!",
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
vi.mock("../src/webapi/features/biome-format.js", () => ({
|
|
76
|
+
formatScaffoldedFiles: vi.fn(),
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
const { scaffoldApi } = await import("../src/webapi/create-api.js");
|
|
80
|
+
|
|
81
|
+
const TARGET = "/my-api";
|
|
82
|
+
|
|
83
|
+
/** Extra Auth0 fields accepted via the shared options bag (AuthFeature). */
|
|
84
|
+
type ScaffoldOpts = Parameters<typeof scaffoldApi>[0] & {
|
|
85
|
+
issuerBaseUrl?: string;
|
|
86
|
+
audience?: string;
|
|
87
|
+
adminUsername?: string;
|
|
88
|
+
adminPassword?: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function read(rel: string): string {
|
|
92
|
+
return readFileSync(join(TARGET, rel), "utf8");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const baseOpts = (): ScaffoldOpts => ({
|
|
96
|
+
d: TARGET,
|
|
97
|
+
databaseProvider: "postgres/typeorm",
|
|
98
|
+
authProvider: "auth0",
|
|
99
|
+
issuerBaseUrl: "https://dev-tenant.us.auth0.com",
|
|
100
|
+
audience: "https://api.webapi",
|
|
101
|
+
adminUsername: "admin",
|
|
102
|
+
adminPassword: "Generated1!",
|
|
103
|
+
postmanProvider: "local",
|
|
104
|
+
installDependencies: "no",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
vi.spyOn(process, "cwd").mockReturnValue("/");
|
|
109
|
+
process.env.DECOHERE_BUILDER = "1";
|
|
110
|
+
resetMemfs();
|
|
111
|
+
seedDevcontainerTemplates();
|
|
112
|
+
mockInstall.mockClear();
|
|
113
|
+
mockAsk.mockClear();
|
|
114
|
+
mockCreateAdminDatabaseUser.mockReset();
|
|
115
|
+
mockEnsureSpaApp.mockReset();
|
|
116
|
+
mockEnableConnectionForClient.mockReset();
|
|
117
|
+
|
|
118
|
+
mockCreateAdminDatabaseUser.mockReturnValue({
|
|
119
|
+
user_id: "auth0|admin",
|
|
120
|
+
email: "admin@my-api.example.com",
|
|
121
|
+
password: "Generated1!",
|
|
122
|
+
username: "admin",
|
|
123
|
+
});
|
|
124
|
+
mockEnsureSpaApp.mockReturnValue({ client_id: "spa_client_123", reused: false });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
afterEach(() => {
|
|
128
|
+
resetMemfs();
|
|
129
|
+
vi.restoreAllMocks();
|
|
130
|
+
delete process.env.DECOHERE_BUILDER;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("scaffoldApi auth0 + postman wiring", () => {
|
|
134
|
+
it("writes AUTH0_ADMIN_* to .env and auth0ClientId into the Postman environment", async () => {
|
|
135
|
+
await scaffoldApi(baseOpts());
|
|
136
|
+
|
|
137
|
+
const env = read(".env");
|
|
138
|
+
expect(env).toContain("AUTH0_ADMIN_USER_SUB=auth0|admin");
|
|
139
|
+
expect(env).toContain("AUTH0_ADMIN_USER_EMAIL=admin@my-api.example.com");
|
|
140
|
+
expect(env).toContain("AUTH0_ADMIN_USER_PASSWORD=Generated1!");
|
|
141
|
+
expect(env).toContain("AUTH0_ADMIN_USERNAME=admin");
|
|
142
|
+
|
|
143
|
+
const postmanEnv = read("postman/environments/my-api-Local.environment.yaml");
|
|
144
|
+
expect(postmanEnv).toMatch(/key: auth0ClientId\n\s+value: spa_client_123/);
|
|
145
|
+
expect(mockEnsureSpaApp).toHaveBeenCalledWith(
|
|
146
|
+
"my-api Postman",
|
|
147
|
+
expect.arrayContaining(["https://oauth.pstmn.io/v1/callback"]),
|
|
148
|
+
);
|
|
149
|
+
expect(mockCreateAdminDatabaseUser).toHaveBeenCalledOnce();
|
|
150
|
+
|
|
151
|
+
const readme = read("README.md");
|
|
152
|
+
expect(readme).toContain("## Auth0");
|
|
153
|
+
expect(readme).toContain("AUTH0_ISSUER_BASE_URL");
|
|
154
|
+
expect(readme).toContain("## Postman");
|
|
155
|
+
expect(readme).toContain("Local View");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("still writes admin env when Auth0 returns an existing user identity", async () => {
|
|
159
|
+
mockCreateAdminDatabaseUser.mockReturnValue({
|
|
160
|
+
user_id: "auth0|existing",
|
|
161
|
+
email: "admin@my-api.example.com",
|
|
162
|
+
password: "Generated1!",
|
|
163
|
+
username: "admin",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
await scaffoldApi(baseOpts());
|
|
167
|
+
|
|
168
|
+
const env = read(".env");
|
|
169
|
+
expect(env).toContain("AUTH0_ADMIN_USER_SUB=auth0|existing");
|
|
170
|
+
expect(env).toContain("AUTH0_ADMIN_USER_PASSWORD=Generated1!");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("writes a non-empty auth0ClientId when the SPA app is reused", async () => {
|
|
174
|
+
mockEnsureSpaApp.mockReturnValue({ client_id: "spa_reused", reused: true });
|
|
175
|
+
|
|
176
|
+
await scaffoldApi(baseOpts());
|
|
177
|
+
|
|
178
|
+
const postmanEnv = read("postman/environments/my-api-Local.environment.yaml");
|
|
179
|
+
expect(postmanEnv).toMatch(/key: auth0ClientId\n\s+value: spa_reused/);
|
|
180
|
+
expect(postmanEnv).not.toMatch(/key: auth0ClientId\n\s+value: ""/);
|
|
181
|
+
|
|
182
|
+
const collectionAuth = read(
|
|
183
|
+
"postman/collections/my-api WebAPI/.resources/definition.yaml",
|
|
184
|
+
);
|
|
185
|
+
expect(collectionAuth).toMatch(/clientId:\s*spa_reused/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("preserves existing auth0ClientId when ensureSpaApp fails on re-scaffold", async () => {
|
|
189
|
+
await scaffoldApi(baseOpts());
|
|
190
|
+
|
|
191
|
+
mockEnsureSpaApp.mockImplementation(() => {
|
|
192
|
+
throw new Error("auth0 apps create failed: Unauthorized");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await scaffoldApi(baseOpts());
|
|
196
|
+
|
|
197
|
+
const postmanEnv = read("postman/environments/my-api-Local.environment.yaml");
|
|
198
|
+
expect(postmanEnv).toMatch(/key: auth0ClientId\n\s+value: spa_client_123/);
|
|
199
|
+
expect(postmanEnv).not.toMatch(/key: auth0ClientId\n\s+value: ""/);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("fails the scaffold instead of writing an empty auth0ClientId", async () => {
|
|
203
|
+
mockEnsureSpaApp.mockImplementation(() => {
|
|
204
|
+
throw new Error("auth0 apps create failed: Unauthorized");
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await expect(scaffoldApi(baseOpts())).rejects.toThrow(/auth0ClientId would be empty/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("surfaces Auth0 application-limit guidance without writing an empty auth0ClientId", async () => {
|
|
211
|
+
mockEnsureSpaApp.mockImplementation(() => {
|
|
212
|
+
throw new Error(
|
|
213
|
+
[
|
|
214
|
+
'Auth0 refused to create SPA "my-api Postman": tenant application limit reached.',
|
|
215
|
+
"This tenant already has 3 application(s):",
|
|
216
|
+
" - ledger Postman (spa_a)",
|
|
217
|
+
"",
|
|
218
|
+
"Fix: Auth0 Dashboard → Applications → Applications → delete unused apps,",
|
|
219
|
+
'then re-run the scaffold (or choose Postman "none" to skip SPA creation).',
|
|
220
|
+
].join("\n"),
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
let thrown: unknown;
|
|
225
|
+
try {
|
|
226
|
+
await scaffoldApi(baseOpts());
|
|
227
|
+
} catch (err) {
|
|
228
|
+
thrown = err;
|
|
229
|
+
}
|
|
230
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
231
|
+
const message = (thrown as Error).message;
|
|
232
|
+
expect(message).toMatch(/tenant application limit reached/);
|
|
233
|
+
expect(message).toMatch(/delete unused apps/i);
|
|
234
|
+
expect(message).not.toMatch(/auth0ClientId would be empty/);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("scaffolds a thin ability.factory extension point (not CASL infrastructure)", async () => {
|
|
238
|
+
await scaffoldApi(baseOpts());
|
|
239
|
+
|
|
240
|
+
const ability = read("projects/api/src/auth/ability.factory.ts");
|
|
241
|
+
expect(ability).toContain("export function defineAbilitiesFor");
|
|
242
|
+
expect(ability).toContain("export function mapPrincipal");
|
|
243
|
+
expect(ability).toContain("defaultDefineAbilitiesFor");
|
|
244
|
+
expect(ability).toContain("createPrincipalFromPayload");
|
|
245
|
+
expect(ability).toContain("AUTH0_ADMIN_USER_SUB");
|
|
246
|
+
expect(ability).not.toContain("@casl/ability");
|
|
247
|
+
expect(ability).not.toContain("AbilityBuilder");
|
|
248
|
+
expect(ability).not.toContain("createMongoAbility");
|
|
249
|
+
|
|
250
|
+
const main = read("projects/api/src/main.ts");
|
|
251
|
+
expect(main).toContain(".withAuth(defineAbilitiesFor, { principalMapper: mapPrincipal })");
|
|
252
|
+
expect(main).not.toContain("createAbilityFactory");
|
|
253
|
+
|
|
254
|
+
const rootPkg = JSON.parse(read("package.json")) as {
|
|
255
|
+
dependencies?: Record<string, string>;
|
|
256
|
+
};
|
|
257
|
+
const apiPkg = JSON.parse(read("projects/api/package.json")) as {
|
|
258
|
+
dependencies?: Record<string, string>;
|
|
259
|
+
};
|
|
260
|
+
expect(rootPkg.dependencies?.["@casl/ability"]).toBeUndefined();
|
|
261
|
+
expect(apiPkg.dependencies?.["@casl/ability"]).toBeUndefined();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const { mockSpawnSync } = vi.hoisted(() => ({
|
|
4
|
+
mockSpawnSync: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock("node:child_process", () => ({
|
|
8
|
+
execFileSync: vi.fn(),
|
|
9
|
+
spawnSync: mockSpawnSync,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
createAdminDatabaseUser,
|
|
14
|
+
createApi,
|
|
15
|
+
DB_CONNECTION_NAME,
|
|
16
|
+
ensureSpaApp,
|
|
17
|
+
updateApiScopes,
|
|
18
|
+
} = await import("../src/webapi/features/auth0-cli.js");
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mockSpawnSync.mockReset();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("createApi / updateApiScopes RBAC", () => {
|
|
29
|
+
it("creates APIs with --enforce-policies and access_token_authz dialect", () => {
|
|
30
|
+
mockSpawnSync.mockReturnValueOnce({
|
|
31
|
+
status: 0,
|
|
32
|
+
stdout: JSON.stringify({ identifier: "https://api.webapi" }),
|
|
33
|
+
stderr: "",
|
|
34
|
+
error: undefined,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const api = createApi("webapi API", "https://api.webapi");
|
|
38
|
+
expect(api.identifier).toBe("https://api.webapi");
|
|
39
|
+
|
|
40
|
+
const args = mockSpawnSync.mock.calls[0]?.[1] as string[];
|
|
41
|
+
expect(args).toEqual(
|
|
42
|
+
expect.arrayContaining([
|
|
43
|
+
"apis",
|
|
44
|
+
"create",
|
|
45
|
+
"--enforce-policies",
|
|
46
|
+
"--token-dialect",
|
|
47
|
+
"access_token_authz",
|
|
48
|
+
]),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("updates existing APIs with --enforce-policies so re-scaffold is not fail-open", () => {
|
|
53
|
+
mockSpawnSync.mockReturnValueOnce({
|
|
54
|
+
status: 0,
|
|
55
|
+
stdout: "",
|
|
56
|
+
stderr: "",
|
|
57
|
+
error: undefined,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
updateApiScopes("https://api.webapi");
|
|
61
|
+
|
|
62
|
+
const args = mockSpawnSync.mock.calls[0]?.[1] as string[];
|
|
63
|
+
expect(args).toEqual(
|
|
64
|
+
expect.arrayContaining([
|
|
65
|
+
"apis",
|
|
66
|
+
"update",
|
|
67
|
+
"https://api.webapi",
|
|
68
|
+
"--enforce-policies",
|
|
69
|
+
"--token-dialect",
|
|
70
|
+
"access_token_authz",
|
|
71
|
+
]),
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("createAdminDatabaseUser", () => {
|
|
77
|
+
it("returns the created user on success", () => {
|
|
78
|
+
mockSpawnSync.mockReturnValueOnce({
|
|
79
|
+
status: 0,
|
|
80
|
+
stdout: JSON.stringify({ user_id: "auth0|new", email: "admin@demo.example.com" }),
|
|
81
|
+
stderr: "",
|
|
82
|
+
error: undefined,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const admin = createAdminDatabaseUser({
|
|
86
|
+
email: "admin@demo.example.com",
|
|
87
|
+
password: "Secret1!",
|
|
88
|
+
username: "admin",
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(admin).toEqual({
|
|
92
|
+
user_id: "auth0|new",
|
|
93
|
+
email: "admin@demo.example.com",
|
|
94
|
+
password: "Secret1!",
|
|
95
|
+
username: "admin",
|
|
96
|
+
});
|
|
97
|
+
expect(mockSpawnSync).toHaveBeenCalledOnce();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("looks up an existing user, resets password, and still returns credentials", () => {
|
|
101
|
+
mockSpawnSync
|
|
102
|
+
.mockReturnValueOnce({
|
|
103
|
+
status: 1,
|
|
104
|
+
stdout: "",
|
|
105
|
+
stderr: 'The user already exists. {"statusCode":409}',
|
|
106
|
+
error: undefined,
|
|
107
|
+
})
|
|
108
|
+
.mockReturnValueOnce({
|
|
109
|
+
status: 0,
|
|
110
|
+
stdout: JSON.stringify([
|
|
111
|
+
{ user_id: "auth0|existing", email: "admin@demo.example.com" },
|
|
112
|
+
]),
|
|
113
|
+
stderr: "",
|
|
114
|
+
error: undefined,
|
|
115
|
+
})
|
|
116
|
+
.mockReturnValueOnce({
|
|
117
|
+
status: 0,
|
|
118
|
+
stdout: "{}",
|
|
119
|
+
stderr: "",
|
|
120
|
+
error: undefined,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const admin = createAdminDatabaseUser({
|
|
124
|
+
email: "admin@demo.example.com",
|
|
125
|
+
password: "NewSecret1!",
|
|
126
|
+
username: "admin",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(admin).toEqual({
|
|
130
|
+
user_id: "auth0|existing",
|
|
131
|
+
email: "admin@demo.example.com",
|
|
132
|
+
password: "NewSecret1!",
|
|
133
|
+
username: "admin",
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const patchCall = mockSpawnSync.mock.calls[2]?.[1] as string[];
|
|
137
|
+
expect(patchCall).toEqual(
|
|
138
|
+
expect.arrayContaining([
|
|
139
|
+
"api",
|
|
140
|
+
"patch",
|
|
141
|
+
`users/${encodeURIComponent("auth0|existing")}`,
|
|
142
|
+
]),
|
|
143
|
+
);
|
|
144
|
+
const dataIdx = patchCall.indexOf("--data");
|
|
145
|
+
expect(JSON.parse(patchCall[dataIdx + 1] ?? "{}")).toEqual({
|
|
146
|
+
password: "NewSecret1!",
|
|
147
|
+
connection: DB_CONNECTION_NAME,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe("ensureSpaApp", () => {
|
|
153
|
+
it("reuses an existing app by name and refreshes callbacks", () => {
|
|
154
|
+
mockSpawnSync
|
|
155
|
+
.mockReturnValueOnce({
|
|
156
|
+
status: 0,
|
|
157
|
+
stdout: JSON.stringify([
|
|
158
|
+
{ client_id: "spa_existing", name: "webapi Postman" },
|
|
159
|
+
{ client_id: "other", name: "Other App" },
|
|
160
|
+
]),
|
|
161
|
+
stderr: "",
|
|
162
|
+
error: undefined,
|
|
163
|
+
})
|
|
164
|
+
.mockReturnValueOnce({
|
|
165
|
+
status: 0,
|
|
166
|
+
stdout: "",
|
|
167
|
+
stderr: "",
|
|
168
|
+
error: undefined,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const app = ensureSpaApp("webapi Postman", [
|
|
172
|
+
"https://oauth.pstmn.io/v1/callback",
|
|
173
|
+
"https://oauth.pstmn.io/v1/browser-callback",
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
expect(app).toEqual({ client_id: "spa_existing", reused: true });
|
|
177
|
+
const updateArgs = mockSpawnSync.mock.calls[1]?.[1] as string[];
|
|
178
|
+
expect(updateArgs).toEqual(
|
|
179
|
+
expect.arrayContaining([
|
|
180
|
+
"apps",
|
|
181
|
+
"update",
|
|
182
|
+
"spa_existing",
|
|
183
|
+
"--callbacks",
|
|
184
|
+
"https://oauth.pstmn.io/v1/callback,https://oauth.pstmn.io/v1/browser-callback",
|
|
185
|
+
]),
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("creates a SPA when no matching app exists", () => {
|
|
190
|
+
mockSpawnSync
|
|
191
|
+
.mockReturnValueOnce({
|
|
192
|
+
status: 0,
|
|
193
|
+
stdout: JSON.stringify([{ client_id: "other", name: "Other App" }]),
|
|
194
|
+
stderr: "",
|
|
195
|
+
error: undefined,
|
|
196
|
+
})
|
|
197
|
+
.mockReturnValueOnce({
|
|
198
|
+
status: 0,
|
|
199
|
+
stdout: JSON.stringify({ client_id: "spa_new", name: "webapi Postman" }),
|
|
200
|
+
stderr: "",
|
|
201
|
+
error: undefined,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const app = ensureSpaApp("webapi Postman", ["https://oauth.pstmn.io/v1/callback"]);
|
|
205
|
+
expect(app).toEqual({ client_id: "spa_new", reused: false });
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("fails with a delete-apps message when Auth0 hits the application entity limit", () => {
|
|
209
|
+
mockSpawnSync
|
|
210
|
+
.mockReturnValueOnce({
|
|
211
|
+
status: 0,
|
|
212
|
+
stdout: JSON.stringify([
|
|
213
|
+
{ client_id: "spa_a", name: "ledger Postman" },
|
|
214
|
+
{ client_id: "spa_b", name: "workspace Postman" },
|
|
215
|
+
{ client_id: "m2m", name: "Default App" },
|
|
216
|
+
]),
|
|
217
|
+
stderr: "",
|
|
218
|
+
error: undefined,
|
|
219
|
+
})
|
|
220
|
+
.mockReturnValueOnce({
|
|
221
|
+
status: 1,
|
|
222
|
+
stdout: "",
|
|
223
|
+
stderr:
|
|
224
|
+
"Failed to create application: 403 Forbidden: You reached the limit of entities of this type for this tenant.",
|
|
225
|
+
error: undefined,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(() =>
|
|
229
|
+
ensureSpaApp("crypto Postman", ["https://oauth.pstmn.io/v1/callback"]),
|
|
230
|
+
).toThrow(/tenant application limit reached[\s\S]*delete unused apps/i);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const { mockSpawnSync } = vi.hoisted(() => ({
|
|
4
|
+
mockSpawnSync: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock("node:child_process", () => ({
|
|
8
|
+
spawnSync: mockSpawnSync,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const { formatScaffoldedFiles } = await import("../src/webapi/features/biome-format.js");
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockSpawnSync.mockReset();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
vi.clearAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("formatScaffoldedFiles", () => {
|
|
22
|
+
it("runs biome check --write in the target directory", () => {
|
|
23
|
+
mockSpawnSync.mockReturnValue({ status: 0, stdout: "", stderr: "", error: undefined });
|
|
24
|
+
|
|
25
|
+
formatScaffoldedFiles("/tmp/scaffold");
|
|
26
|
+
|
|
27
|
+
expect(mockSpawnSync).toHaveBeenCalledWith(
|
|
28
|
+
"biome",
|
|
29
|
+
["check", "--write", "."],
|
|
30
|
+
expect.objectContaining({ cwd: "/tmp/scaffold" }),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("falls back to npx when biome is not on PATH", () => {
|
|
35
|
+
const enoent = Object.assign(new Error("not found"), { code: "ENOENT" });
|
|
36
|
+
mockSpawnSync
|
|
37
|
+
.mockReturnValueOnce({ status: 1, stdout: "", stderr: "", error: enoent })
|
|
38
|
+
.mockReturnValueOnce({ status: 0, stdout: "", stderr: "", error: undefined });
|
|
39
|
+
|
|
40
|
+
formatScaffoldedFiles("/tmp/scaffold");
|
|
41
|
+
|
|
42
|
+
expect(mockSpawnSync).toHaveBeenNthCalledWith(
|
|
43
|
+
2,
|
|
44
|
+
"npx",
|
|
45
|
+
["--yes", "@biomejs/biome", "check", "--write", "."],
|
|
46
|
+
expect.objectContaining({ cwd: "/tmp/scaffold" }),
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|