@decohere/scaffold 0.0.1-dev.18 → 0.0.1-dev.20261105.54
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/LICENSE +15 -0
- package/commonjs/src/add-api.action.js +37 -0
- package/commonjs/src/add-api.command.js +39 -0
- package/commonjs/src/add.command.js +22 -0
- package/commonjs/src/add.module.js +24 -0
- package/commonjs/src/auth0-configure.action.js +28 -0
- package/commonjs/src/auth0-configure.command.js +24 -0
- package/commonjs/src/auth0-login.action.js +28 -0
- package/commonjs/src/auth0-login.command.js +23 -0
- package/commonjs/src/auth0.command.js +22 -0
- package/commonjs/src/auth0.module.js +28 -0
- package/commonjs/src/cli.js +8 -0
- package/commonjs/src/create.command.js +22 -0
- package/commonjs/src/create.module.js +24 -0
- package/commonjs/src/domain/prompt.js +62 -0
- package/commonjs/src/index.js +48 -0
- package/commonjs/src/models/compose.model.js +258 -0
- package/commonjs/src/models/config-yaml.model.js +86 -0
- package/commonjs/src/models/const.js +30 -0
- package/commonjs/src/models/dev-container.model.js +172 -0
- package/commonjs/src/models/docker-image.model.js +277 -0
- package/commonjs/src/models/env-file.model.js +48 -0
- package/commonjs/src/models/gitignore.model.js +48 -0
- package/commonjs/src/models/launch-json.model.js +70 -0
- package/commonjs/src/models/package-json.model.js +157 -0
- package/commonjs/src/models/project.model.js +132 -0
- package/commonjs/src/models/source-file.js +4 -0
- package/commonjs/src/models/tsconfig.model.js +32 -0
- package/commonjs/src/models/vitest-config.model.js +33 -0
- package/commonjs/src/models/vscode-settings.model.js +29 -0
- package/commonjs/src/program.js +64 -0
- package/commonjs/src/resolve-target-dir.js +17 -0
- package/commonjs/src/services/scaffold.service.js +60 -0
- package/commonjs/src/version.js +55 -0
- package/commonjs/src/webapi/api-name.js +93 -0
- package/commonjs/src/webapi/auth0-commands.js +250 -0
- package/commonjs/src/webapi/authorize-scopes.js +79 -0
- package/commonjs/src/webapi/cli-options.js +99 -0
- package/commonjs/src/webapi/const.js +54 -0
- package/commonjs/src/webapi/create-api.js +275 -0
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +164 -0
- package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/commonjs/src/webapi/devcontainer/host-scripts.js +50 -0
- package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/commonjs/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/commonjs/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/commonjs/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/commonjs/src/webapi/features/auth.feature.js +408 -0
- package/commonjs/src/webapi/features/auth0-cli.js +472 -0
- package/commonjs/src/webapi/features/biome-format.js +47 -0
- package/commonjs/src/webapi/features/database.feature.js +433 -0
- package/commonjs/src/webapi/features/finalize.feature.js +93 -0
- package/commonjs/src/webapi/features/postman.feature.js +322 -0
- package/commonjs/src/webapi/models/api-package-json.model.js +58 -0
- package/commonjs/src/webapi/models/auth-config.model.js +24 -0
- package/commonjs/src/webapi/models/controller-source-file.model.js +190 -0
- package/commonjs/src/webapi/models/github-ci.model.js +193 -0
- package/commonjs/src/webapi/models/main-source-file.model.js +165 -0
- package/commonjs/src/webapi/models/production-dockerfile.model.js +75 -0
- package/commonjs/src/webapi/models/sample-files.model.js +58 -0
- package/commonjs/src/webapi/models/webapi-image.model.js +25 -0
- package/commonjs/src/webapi/postman/hello-openapi.js +173 -0
- package/commonjs/src/webapi/postman/local-view.js +182 -0
- package/commonjs/src/webapi/postman/openapi-to-postman.js +238 -0
- package/commonjs/src/webapi/workspace-readme.js +109 -0
- package/commonjs/src/webapi.action.js +28 -0
- package/commonjs/src/webapi.command.js +43 -0
- package/es6/src/add-api.action.js +27 -0
- package/es6/src/add-api.command.js +29 -0
- package/es6/src/add.command.js +12 -0
- package/es6/src/add.module.js +14 -0
- package/es6/src/auth0-configure.action.js +18 -0
- package/es6/src/auth0-configure.command.js +14 -0
- package/es6/src/auth0-login.action.js +18 -0
- package/es6/src/auth0-login.command.js +13 -0
- package/es6/src/auth0.command.js +12 -0
- package/es6/src/auth0.module.js +18 -0
- package/es6/src/cli.js +4 -0
- package/es6/src/create.command.js +12 -0
- package/es6/src/create.module.js +14 -0
- package/es6/src/domain/prompt.js +41 -0
- package/es6/src/index.js +9 -0
- package/es6/src/models/compose.model.js +254 -0
- package/es6/src/models/config-yaml.model.js +74 -0
- package/es6/src/models/const.js +20 -0
- package/es6/src/models/dev-container.model.js +162 -0
- package/es6/src/models/docker-image.model.js +235 -0
- package/es6/src/models/env-file.model.js +44 -0
- package/es6/src/models/gitignore.model.js +38 -0
- package/es6/src/models/launch-json.model.js +60 -0
- package/es6/src/models/package-json.model.js +142 -0
- package/es6/src/models/project.model.js +117 -0
- package/es6/src/models/source-file.js +1 -0
- package/es6/src/models/tsconfig.model.js +22 -0
- package/es6/src/models/vitest-config.model.js +23 -0
- package/es6/src/models/vscode-settings.model.js +19 -0
- package/es6/src/program.js +50 -0
- package/es6/src/resolve-target-dir.js +7 -0
- package/es6/src/services/scaffold.service.js +50 -0
- package/es6/src/version.js +34 -0
- package/es6/src/webapi/api-name.js +57 -0
- package/es6/src/webapi/auth0-commands.js +185 -0
- package/es6/src/webapi/authorize-scopes.js +55 -0
- package/es6/src/webapi/cli-options.js +34 -0
- package/es6/src/webapi/const.js +21 -0
- package/es6/src/webapi/create-api.js +255 -0
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +154 -0
- package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/es6/src/webapi/devcontainer/host-scripts.js +29 -0
- package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/es6/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/es6/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/es6/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/es6/src/webapi/features/auth.feature.js +357 -0
- package/es6/src/webapi/features/auth0-cli.js +406 -0
- package/es6/src/webapi/features/biome-format.js +40 -0
- package/es6/src/webapi/features/database.feature.js +423 -0
- package/es6/src/webapi/features/finalize.feature.js +83 -0
- package/es6/src/webapi/features/postman.feature.js +256 -0
- package/es6/src/webapi/models/api-package-json.model.js +53 -0
- package/es6/src/webapi/models/auth-config.model.js +20 -0
- package/es6/src/webapi/models/controller-source-file.model.js +181 -0
- package/{src/webapi/models/github-ci.model.ts → es6/src/webapi/models/github-ci.model.js} +27 -29
- package/es6/src/webapi/models/main-source-file.model.js +161 -0
- package/es6/src/webapi/models/production-dockerfile.model.js +66 -0
- package/es6/src/webapi/models/sample-files.model.js +40 -0
- package/es6/src/webapi/models/webapi-image.model.js +18 -0
- package/es6/src/webapi/postman/hello-openapi.js +166 -0
- package/es6/src/webapi/postman/local-view.js +167 -0
- package/es6/src/webapi/postman/openapi-to-postman.js +179 -0
- package/es6/src/webapi/workspace-readme.js +88 -0
- package/es6/src/webapi.action.js +18 -0
- package/es6/src/webapi.command.js +33 -0
- package/package.json +19 -9
- package/types/src/add-api.action.d.ts +13 -0
- package/types/src/add-api.command.d.ts +7 -0
- package/types/src/add.command.d.ts +6 -0
- package/types/src/add.module.d.ts +14 -0
- package/types/src/auth0-configure.action.d.ts +7 -0
- package/types/src/auth0-configure.command.d.ts +6 -0
- package/types/src/auth0-login.action.d.ts +4 -0
- package/types/src/auth0-login.command.d.ts +6 -0
- package/types/src/auth0.command.d.ts +6 -0
- package/types/src/auth0.module.d.ts +18 -0
- package/types/src/cli.d.ts +2 -0
- package/types/src/create.command.d.ts +6 -0
- package/types/src/create.module.d.ts +14 -0
- package/types/src/domain/prompt.d.ts +4 -0
- package/{src/index.ts → types/src/index.d.ts} +4 -0
- package/types/src/models/compose.model.d.ts +73 -0
- package/types/src/models/config-yaml.model.d.ts +27 -0
- package/types/src/models/const.d.ts +20 -0
- package/types/src/models/dev-container.model.d.ts +49 -0
- package/types/src/models/docker-image.model.d.ts +90 -0
- package/types/src/models/env-file.model.d.ts +16 -0
- package/types/src/models/gitignore.model.d.ts +9 -0
- package/types/src/models/launch-json.model.d.ts +7 -0
- package/types/src/models/package-json.model.d.ts +36 -0
- package/types/src/models/project.model.d.ts +60 -0
- package/{src/models/source-file.ts → types/src/models/source-file.d.ts} +4 -6
- package/types/src/models/tsconfig.model.d.ts +5 -0
- package/types/src/models/vitest-config.model.d.ts +5 -0
- package/types/src/models/vscode-settings.model.d.ts +7 -0
- package/types/src/program.d.ts +8 -0
- package/{src/resolve-target-dir.ts → types/src/resolve-target-dir.d.ts} +1 -4
- package/types/src/services/scaffold.service.d.ts +22 -0
- package/types/src/version.d.ts +6 -0
- package/types/src/webapi/api-name.d.ts +14 -0
- package/types/src/webapi/auth0-commands.d.ts +11 -0
- package/types/src/webapi/authorize-scopes.d.ts +7 -0
- package/types/src/webapi/cli-options.d.ts +6 -0
- package/{src/webapi/const.ts → types/src/webapi/const.d.ts} +9 -21
- package/types/src/webapi/create-api.d.ts +15 -0
- package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +32 -0
- package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +182 -0
- package/types/src/webapi/devcontainer/host-scripts.d.ts +7 -0
- package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +3 -0
- package/types/src/webapi/devcontainer/templates/initialize.sh +169 -0
- package/types/src/webapi/devcontainer/templates/post-create.sh +35 -0
- package/types/src/webapi/devcontainer/templates/post-start.sh +65 -0
- package/types/src/webapi/devcontainer/templates/tty-prompt.sh +38 -0
- package/types/src/webapi/features/auth.feature.d.ts +10 -0
- package/types/src/webapi/features/auth0-cli.d.ts +84 -0
- package/types/src/webapi/features/biome-format.d.ts +5 -0
- package/types/src/webapi/features/database.feature.d.ts +7 -0
- package/types/src/webapi/features/finalize.feature.d.ts +2 -0
- package/types/src/webapi/features/postman.feature.d.ts +16 -0
- package/types/src/webapi/models/api-package-json.model.d.ts +18 -0
- package/types/src/webapi/models/auth-config.model.d.ts +26 -0
- package/types/src/webapi/models/controller-source-file.model.d.ts +46 -0
- package/types/src/webapi/models/github-ci.model.d.ts +9 -0
- package/types/src/webapi/models/main-source-file.model.d.ts +54 -0
- package/types/src/webapi/models/production-dockerfile.model.d.ts +18 -0
- package/types/src/webapi/models/sample-files.model.d.ts +7 -0
- package/types/src/webapi/models/webapi-image.model.d.ts +12 -0
- package/types/src/webapi/postman/hello-openapi.d.ts +19 -0
- package/types/src/webapi/postman/local-view.d.ts +17 -0
- package/types/src/webapi/postman/openapi-to-postman.d.ts +62 -0
- package/types/src/webapi/workspace-readme.d.ts +18 -0
- package/types/src/webapi.action.d.ts +14 -0
- package/types/src/webapi.command.d.ts +11 -0
- package/src/add-api.action.ts +0 -25
- package/src/add-api.command.ts +0 -31
- package/src/add.command.ts +0 -20
- package/src/add.module.ts +0 -11
- package/src/cli.ts +0 -4
- package/src/create.command.ts +0 -20
- package/src/create.module.ts +0 -11
- package/src/domain/prompt.ts +0 -50
- package/src/models/compose.model.ts +0 -205
- package/src/models/config-yaml.model.ts +0 -83
- package/src/models/const.ts +0 -20
- package/src/models/dev-container.model.ts +0 -136
- package/src/models/docker-image.model.ts +0 -343
- package/src/models/env-file.model.ts +0 -45
- package/src/models/gitignore.model.ts +0 -35
- package/src/models/launch-json.model.ts +0 -60
- package/src/models/package-json.model.ts +0 -169
- package/src/models/project.model.ts +0 -141
- package/src/models/tsconfig.model.ts +0 -29
- package/src/models/vitest-config.model.ts +0 -26
- package/src/models/vscode-settings.model.ts +0 -24
- package/src/program.ts +0 -63
- package/src/services/scaffold.service.ts +0 -89
- package/src/version.ts +0 -56
- package/src/webapi/api-name.ts +0 -73
- package/src/webapi/cli-options.ts +0 -56
- package/src/webapi/create-api.ts +0 -275
- package/src/webapi/devcontainer/host-scripts.ts +0 -35
- package/src/webapi/features/auth.feature.ts +0 -454
- package/src/webapi/features/auth0-cli.ts +0 -421
- package/src/webapi/features/biome-format.ts +0 -34
- package/src/webapi/features/database.feature.ts +0 -522
- package/src/webapi/features/finalize.feature.ts +0 -112
- package/src/webapi/features/postman.feature.ts +0 -287
- package/src/webapi/models/api-package-json.model.ts +0 -60
- package/src/webapi/models/auth-config.model.ts +0 -36
- package/src/webapi/models/controller-source-file.model.ts +0 -232
- package/src/webapi/models/main-source-file.model.ts +0 -208
- package/src/webapi/models/production-dockerfile.model.ts +0 -162
- package/src/webapi/models/sample-files.model.ts +0 -45
- package/src/webapi/models/webapi-image.model.ts +0 -21
- package/src/webapi/postman/hello-openapi.ts +0 -92
- package/src/webapi/postman/local-view.ts +0 -195
- package/src/webapi/postman/openapi-to-postman.ts +0 -208
- package/src/webapi/workspace-readme.ts +0 -192
- package/src/webapi.action.ts +0 -22
- package/src/webapi.command.ts +0 -41
- package/tests/auth-postman.wiring.spec.ts +0 -263
- package/tests/auth0-cli.spec.ts +0 -232
- package/tests/biome-format.spec.ts +0 -49
- package/tests/cli.integration.spec.ts +0 -658
- package/tests/compose.model.spec.ts +0 -51
- package/tests/container-image.model.spec.ts +0 -162
- package/tests/dev-container.model.spec.ts +0 -29
- package/tests/devcontainer-base-image.spec.ts +0 -32
- package/tests/hello-di-inject.scaffold.spec.ts +0 -18
- package/tests/hello-route.contract.spec.ts +0 -94
- package/tests/package-json.order.spec.ts +0 -59
- package/tests/postman-from-openapi.spec.ts +0 -197
- package/tests/seed-devcontainer-templates.ts +0 -40
- package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +0 -96
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get AUTH0_CLI_INSTALL_MESSAGE () {
|
|
13
|
+
return AUTH0_CLI_INSTALL_MESSAGE;
|
|
14
|
+
},
|
|
15
|
+
get ensureLoggedIn () {
|
|
16
|
+
return ensureLoggedIn;
|
|
17
|
+
},
|
|
18
|
+
get requireInstalled () {
|
|
19
|
+
return requireInstalled;
|
|
20
|
+
},
|
|
21
|
+
get runAuth0Configure () {
|
|
22
|
+
return runAuth0Configure;
|
|
23
|
+
},
|
|
24
|
+
get runAuth0Login () {
|
|
25
|
+
return runAuth0Login;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _nodefs = require("node:fs");
|
|
29
|
+
const _nodepath = require("node:path");
|
|
30
|
+
const _apiname = require("./api-name.js");
|
|
31
|
+
const _authorizescopes = require("./authorize-scopes.js");
|
|
32
|
+
const _auth0cli = /*#__PURE__*/ _interop_require_wildcard(require("./features/auth0-cli.js"));
|
|
33
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
34
|
+
if (typeof WeakMap !== "function") return null;
|
|
35
|
+
var cacheBabelInterop = new WeakMap();
|
|
36
|
+
var cacheNodeInterop = new WeakMap();
|
|
37
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
38
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
39
|
+
})(nodeInterop);
|
|
40
|
+
}
|
|
41
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
42
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
46
|
+
return {
|
|
47
|
+
default: obj
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
51
|
+
if (cache && cache.has(obj)) {
|
|
52
|
+
return cache.get(obj);
|
|
53
|
+
}
|
|
54
|
+
var newObj = {
|
|
55
|
+
__proto__: null
|
|
56
|
+
};
|
|
57
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
58
|
+
for(var key in obj){
|
|
59
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
60
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
61
|
+
if (desc && (desc.get || desc.set)) {
|
|
62
|
+
Object.defineProperty(newObj, key, desc);
|
|
63
|
+
} else {
|
|
64
|
+
newObj[key] = obj[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
newObj.default = obj;
|
|
69
|
+
if (cache) {
|
|
70
|
+
cache.set(obj, newObj);
|
|
71
|
+
}
|
|
72
|
+
return newObj;
|
|
73
|
+
}
|
|
74
|
+
/** Same Postman OAuth callbacks as `PostmanFeature`. */ const POSTMAN_CALLBACKS = [
|
|
75
|
+
"https://oauth.pstmn.io/v1/callback",
|
|
76
|
+
"https://oauth.pstmn.io/v1/browser-callback"
|
|
77
|
+
];
|
|
78
|
+
const SPA_SUFFIX = " Postman";
|
|
79
|
+
const AUTH0_CLI_INSTALL_MESSAGE = "The Auth0 CLI is required.\n" + " It is bundled in the Decohere create image (`npx @decohere/create auth0 login`).\n" + " Host install: brew install auth0/auth0-cli/auth0\n" + " Or visit: https://github.com/auth0/auth0-cli";
|
|
80
|
+
function fail(message) {
|
|
81
|
+
throw new _apiname.CreateCliError(message);
|
|
82
|
+
}
|
|
83
|
+
function requireInstalled() {
|
|
84
|
+
if (_auth0cli.isInstalled()) return;
|
|
85
|
+
fail(AUTH0_CLI_INSTALL_MESSAGE);
|
|
86
|
+
}
|
|
87
|
+
function ensureLoggedIn() {
|
|
88
|
+
requireInstalled();
|
|
89
|
+
process.stdout.write("\n Checking Auth0 credentials...");
|
|
90
|
+
let tenants = _auth0cli.listTenants();
|
|
91
|
+
if (tenants.length === 0) {
|
|
92
|
+
process.stdout.write(" not logged in.\n");
|
|
93
|
+
console.log(" Logging in to Auth0 (open the URL in your browser)...");
|
|
94
|
+
if (!_auth0cli.login()) fail("Auth0 login failed.");
|
|
95
|
+
tenants = _auth0cli.listTenants();
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
_auth0cli.listApis();
|
|
99
|
+
process.stdout.write(" ok.\n");
|
|
100
|
+
} catch (err) {
|
|
101
|
+
if (err instanceof _auth0cli.Auth0AuthError) {
|
|
102
|
+
process.stdout.write(" token expired.\n");
|
|
103
|
+
console.log(" Re-authenticating (open the URL in your browser)...");
|
|
104
|
+
if (!_auth0cli.login()) fail("Auth0 login failed.");
|
|
105
|
+
tenants = _auth0cli.listTenants();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const active = tenants.find((t)=>t.active) ?? tenants[0];
|
|
109
|
+
if (active == null) fail("No Auth0 tenant after login.");
|
|
110
|
+
return active;
|
|
111
|
+
}
|
|
112
|
+
function runAuth0Login() {
|
|
113
|
+
requireInstalled();
|
|
114
|
+
console.log(" Logging in to Auth0 (open the URL in your browser)...");
|
|
115
|
+
if (!_auth0cli.login()) fail("Auth0 login failed.");
|
|
116
|
+
const tenants = _auth0cli.listTenants();
|
|
117
|
+
const active = tenants.find((t)=>t.active) ?? tenants[0];
|
|
118
|
+
if (active == null) fail("No Auth0 tenant after login.");
|
|
119
|
+
console.log(`\n ✓ Auth0 tenant: https://${active.name}`);
|
|
120
|
+
console.log(" Tokens are stored in ~/.config/auth0 (mounted into the create image).");
|
|
121
|
+
console.log(" Next: npx @decohere/create auth0 configure");
|
|
122
|
+
}
|
|
123
|
+
function runAuth0Configure(directory = ".") {
|
|
124
|
+
const targetDir = (0, _nodepath.resolve)(directory);
|
|
125
|
+
if (!(0, _apiname.isDecohereWorkspace)(targetDir)) {
|
|
126
|
+
throw new _apiname.CreateCliError(`Not a Decohere workspace: ${targetDir}. Scaffold one first with \`npx @decohere/create webapi\`.`);
|
|
127
|
+
}
|
|
128
|
+
const active = ensureLoggedIn();
|
|
129
|
+
const issuerBaseUrl = `https://${active.name}`;
|
|
130
|
+
const projectName = process.env.DECOHERE_PROJECT_NAME?.trim() || (0, _nodepath.basename)(targetDir);
|
|
131
|
+
const envPath = (0, _nodepath.join)(targetDir, ".env");
|
|
132
|
+
const existing = readEnvFile(envPath);
|
|
133
|
+
const existingAudience = existing.AUTH0_AUDIENCE?.trim();
|
|
134
|
+
const discovered = (0, _authorizescopes.discoverAuthorizeScopes)(targetDir);
|
|
135
|
+
let existingScopes = [];
|
|
136
|
+
if (existingAudience) {
|
|
137
|
+
try {
|
|
138
|
+
existingScopes = _auth0cli.listApiScopes(existingAudience);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err instanceof _auth0cli.Auth0AuthError) throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const apiScopes = resolveApiScopes(discovered, existingScopes);
|
|
144
|
+
console.log(discovered.length > 0 ? ` ✓ Scanned @Authorize — ${discovered.length} scope(s) from controllers` : " ✓ No @Authorize in projects/*/src — keeping existing / Hello scopes");
|
|
145
|
+
let audience = existingAudience;
|
|
146
|
+
if (audience) {
|
|
147
|
+
try {
|
|
148
|
+
_auth0cli.updateApiScopes(audience, apiScopes);
|
|
149
|
+
console.log(` ✓ API scopes ensured (${apiScopes.join(", ")})`);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
console.error(` ✗ Failed to update API scopes: ${err instanceof Error ? err.message : err}`);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
const identifier = `https://api.${projectName}`;
|
|
155
|
+
console.log(`\n Creating Auth0 API ${identifier}...`);
|
|
156
|
+
audience = _auth0cli.createApi(`${projectName} API`, identifier, apiScopes).identifier;
|
|
157
|
+
console.log(` ✓ API created: ${audience}`);
|
|
158
|
+
}
|
|
159
|
+
const appName = `${projectName}${SPA_SUFFIX}`;
|
|
160
|
+
const app = _auth0cli.ensureSpaApp(appName, [
|
|
161
|
+
...POSTMAN_CALLBACKS
|
|
162
|
+
]);
|
|
163
|
+
console.log(app.reused ? ` ✓ Reusing Auth0 SPA app (${app.client_id})` : ` ✓ Auth0 SPA app created (${app.client_id})`);
|
|
164
|
+
try {
|
|
165
|
+
_auth0cli.enableConnectionForClient(_auth0cli.DB_CONNECTION_NAME, app.client_id);
|
|
166
|
+
console.log(` ✓ Enabled ${_auth0cli.DB_CONNECTION_NAME} on SPA`);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
console.error(` ✗ Failed to enable DB connection on SPA: ${err instanceof Error ? err.message : err}`);
|
|
169
|
+
}
|
|
170
|
+
upsertEnv(envPath, {
|
|
171
|
+
AUTH0_ISSUER_BASE_URL: issuerBaseUrl,
|
|
172
|
+
AUTH0_AUDIENCE: audience
|
|
173
|
+
});
|
|
174
|
+
console.log(` ✓ Wrote AUTH0_ISSUER_BASE_URL and AUTH0_AUDIENCE to .env`);
|
|
175
|
+
const adminSub = existing.AUTH0_ADMIN_USER_SUB?.trim();
|
|
176
|
+
if (adminSub) {
|
|
177
|
+
try {
|
|
178
|
+
_auth0cli.assignUserPermissions(adminSub, audience, apiScopes);
|
|
179
|
+
console.log(` ✓ Assigned ${apiScopes.length} API permission(s) to admin user`);
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.error(` ✗ Failed to assign admin permissions: ${err instanceof Error ? err.message : err}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const domain = issuerBaseUrl.replace(/^https?:\/\//, "");
|
|
185
|
+
patchPostmanAuth(targetDir, projectName, {
|
|
186
|
+
domain,
|
|
187
|
+
audience,
|
|
188
|
+
clientId: app.client_id,
|
|
189
|
+
scopes: (0, _authorizescopes.postmanRequestedScopes)(apiScopes)
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function readEnvFile(path) {
|
|
193
|
+
if (!(0, _nodefs.existsSync)(path)) return {};
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const line of (0, _nodefs.readFileSync)(path, "utf8").split("\n")){
|
|
196
|
+
const trimmed = line.trim();
|
|
197
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
198
|
+
const eq = line.indexOf("=");
|
|
199
|
+
if (eq <= 0) continue;
|
|
200
|
+
out[line.slice(0, eq).trim()] = line.slice(eq + 1);
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
function resolveApiScopes(discovered, existing) {
|
|
205
|
+
const merged = (0, _authorizescopes.mergeApiScopes)(discovered, existing);
|
|
206
|
+
return merged.length > 0 ? merged : [
|
|
207
|
+
..._auth0cli.HELLO_API_SCOPES
|
|
208
|
+
].sort();
|
|
209
|
+
}
|
|
210
|
+
function upsertEnv(path, entries) {
|
|
211
|
+
let text = (0, _nodefs.existsSync)(path) ? (0, _nodefs.readFileSync)(path, "utf8") : "";
|
|
212
|
+
for (const [key, value] of Object.entries(entries)){
|
|
213
|
+
const re = new RegExp(`^${key}=.*$`, "m");
|
|
214
|
+
if (re.test(text)) {
|
|
215
|
+
text = text.replace(re, `${key}=${value}`);
|
|
216
|
+
} else {
|
|
217
|
+
text = `${text}${text === "" || text.endsWith("\n") ? "" : "\n"}${key}=${value}\n`;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (text !== "" && !text.endsWith("\n")) text = `${text}\n`;
|
|
221
|
+
(0, _nodefs.writeFileSync)(path, text);
|
|
222
|
+
}
|
|
223
|
+
function patchPostmanAuth(targetDir, projectName, auth) {
|
|
224
|
+
const envYaml = (0, _nodepath.join)(targetDir, "postman/environments", `${projectName}-Local.environment.yaml`);
|
|
225
|
+
if ((0, _nodefs.existsSync)(envYaml)) {
|
|
226
|
+
let yaml = (0, _nodefs.readFileSync)(envYaml, "utf8");
|
|
227
|
+
yaml = replaceYamlKeyedValue(yaml, "auth0Domain", auth.domain);
|
|
228
|
+
yaml = replaceYamlKeyedValue(yaml, "auth0Audience", auth.audience);
|
|
229
|
+
yaml = replaceYamlKeyedValue(yaml, "auth0ClientId", auth.clientId);
|
|
230
|
+
yaml = replaceYamlKeyedValue(yaml, "authUrl", `https://${auth.domain}/authorize?audience=${auth.audience}`);
|
|
231
|
+
yaml = replaceYamlKeyedValue(yaml, "accessTokenUrl", `https://${auth.domain}/oauth/token`);
|
|
232
|
+
yaml = replaceYamlKeyedValue(yaml, "scope", auth.scopes);
|
|
233
|
+
(0, _nodefs.writeFileSync)(envYaml, yaml);
|
|
234
|
+
console.log(` ✓ Updated Postman environment auth0ClientId (${auth.clientId})`);
|
|
235
|
+
console.log(` ✓ Updated Postman token scopes`);
|
|
236
|
+
}
|
|
237
|
+
const collectionDef = (0, _nodepath.join)(targetDir, "postman/collections", `${projectName} WebAPI`, ".resources/definition.yaml");
|
|
238
|
+
if ((0, _nodefs.existsSync)(collectionDef)) {
|
|
239
|
+
let yaml = (0, _nodefs.readFileSync)(collectionDef, "utf8");
|
|
240
|
+
yaml = yaml.replace(/^(\s*clientId:\s*).+$/m, `$1${JSON.stringify(auth.clientId)}`);
|
|
241
|
+
yaml = yaml.replace(/^(\s*scope:\s*).+$/m, `$1${JSON.stringify(auth.scopes)}`);
|
|
242
|
+
(0, _nodefs.writeFileSync)(collectionDef, yaml);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** Replace `key: <name>` / `value: …` pairs in Postman Local View environment YAML. */ function replaceYamlKeyedValue(yaml, key, value) {
|
|
246
|
+
const quoted = JSON.stringify(value);
|
|
247
|
+
const re = new RegExp(`(key:\\s*${key}\\s*\\n\\s*value:\\s*)[^\\n]+`, "m");
|
|
248
|
+
if (!re.test(yaml)) return yaml;
|
|
249
|
+
return yaml.replace(re, `$1${quoted}`);
|
|
250
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get OIDC_SCOPES () {
|
|
13
|
+
return OIDC_SCOPES;
|
|
14
|
+
},
|
|
15
|
+
get discoverAuthorizeScopes () {
|
|
16
|
+
return discoverAuthorizeScopes;
|
|
17
|
+
},
|
|
18
|
+
get mergeApiScopes () {
|
|
19
|
+
return mergeApiScopes;
|
|
20
|
+
},
|
|
21
|
+
get postmanRequestedScopes () {
|
|
22
|
+
return postmanRequestedScopes;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _nodefs = require("node:fs");
|
|
26
|
+
const _nodepath = require("node:path");
|
|
27
|
+
const _apiname = require("./api-name.js");
|
|
28
|
+
const OIDC_SCOPES = [
|
|
29
|
+
"openid",
|
|
30
|
+
"profile",
|
|
31
|
+
"email"
|
|
32
|
+
];
|
|
33
|
+
const AUTHORIZE_RE = /@Authorize\(\s*(["'])([^"']+)\1(?:\s*,\s*(["'])([^"']+)\3)?\s*\)/g;
|
|
34
|
+
function isAppSource(fileName) {
|
|
35
|
+
return fileName.endsWith(".ts") && !fileName.endsWith(".spec.ts") && !fileName.endsWith(".test.ts") && !fileName.endsWith(".d.ts");
|
|
36
|
+
}
|
|
37
|
+
function discoverAuthorizeScopes(rootDir) {
|
|
38
|
+
const scopes = new Set();
|
|
39
|
+
for (const apiName of (0, _apiname.listExistingApiNames)(rootDir)){
|
|
40
|
+
collectFromDir((0, _nodepath.join)(rootDir, "projects", apiName, "src"), scopes);
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
...scopes
|
|
44
|
+
].sort();
|
|
45
|
+
}
|
|
46
|
+
function collectFromDir(dir, scopes) {
|
|
47
|
+
if (!(0, _nodefs.existsSync)(dir)) return;
|
|
48
|
+
for (const entry of (0, _nodefs.readdirSync)(dir, {
|
|
49
|
+
withFileTypes: true
|
|
50
|
+
})){
|
|
51
|
+
const path = (0, _nodepath.join)(dir, entry.name);
|
|
52
|
+
if (entry.isDirectory()) {
|
|
53
|
+
collectFromDir(path, scopes);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!entry.isFile() || !isAppSource(entry.name)) continue;
|
|
57
|
+
const text = (0, _nodefs.readFileSync)(path, "utf8");
|
|
58
|
+
for (const match of text.matchAll(AUTHORIZE_RE)){
|
|
59
|
+
const action = match[2];
|
|
60
|
+
if (action == null || action === "") continue;
|
|
61
|
+
const subject = match[4] ?? "all";
|
|
62
|
+
scopes.add(`${action}:${subject}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function mergeApiScopes(discovered, existing) {
|
|
67
|
+
return [
|
|
68
|
+
...new Set([
|
|
69
|
+
...existing,
|
|
70
|
+
...discovered
|
|
71
|
+
])
|
|
72
|
+
].sort();
|
|
73
|
+
}
|
|
74
|
+
function postmanRequestedScopes(apiScopes) {
|
|
75
|
+
return [
|
|
76
|
+
...OIDC_SCOPES,
|
|
77
|
+
...apiScopes
|
|
78
|
+
].join(" ");
|
|
79
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get addWebapiFeatureOptions () {
|
|
13
|
+
return addWebapiFeatureOptions;
|
|
14
|
+
},
|
|
15
|
+
get collectName () {
|
|
16
|
+
return collectName;
|
|
17
|
+
},
|
|
18
|
+
get runScaffoldApi () {
|
|
19
|
+
return runScaffoldApi;
|
|
20
|
+
},
|
|
21
|
+
get toApiOptions () {
|
|
22
|
+
return toApiOptions;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _resolvetargetdir = require("../resolve-target-dir.js");
|
|
26
|
+
const _apiname = require("./api-name.js");
|
|
27
|
+
const _createapi = require("./create-api.js");
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
29
|
+
if (typeof WeakMap !== "function") return null;
|
|
30
|
+
var cacheBabelInterop = new WeakMap();
|
|
31
|
+
var cacheNodeInterop = new WeakMap();
|
|
32
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
33
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
34
|
+
})(nodeInterop);
|
|
35
|
+
}
|
|
36
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
37
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
41
|
+
return {
|
|
42
|
+
default: obj
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
46
|
+
if (cache && cache.has(obj)) {
|
|
47
|
+
return cache.get(obj);
|
|
48
|
+
}
|
|
49
|
+
var newObj = {
|
|
50
|
+
__proto__: null
|
|
51
|
+
};
|
|
52
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
53
|
+
for(var key in obj){
|
|
54
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
55
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
56
|
+
if (desc && (desc.get || desc.set)) {
|
|
57
|
+
Object.defineProperty(newObj, key, desc);
|
|
58
|
+
} else {
|
|
59
|
+
newObj[key] = obj[key];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
newObj.default = obj;
|
|
64
|
+
if (cache) {
|
|
65
|
+
cache.set(obj, newObj);
|
|
66
|
+
}
|
|
67
|
+
return newObj;
|
|
68
|
+
}
|
|
69
|
+
function collectName(value, previous) {
|
|
70
|
+
previous.push(value);
|
|
71
|
+
return previous;
|
|
72
|
+
}
|
|
73
|
+
function addWebapiFeatureOptions(cmd) {
|
|
74
|
+
return cmd.option("--database <provider>", "Database provider: none | postgres/typeorm").option("--auth <provider>", "Auth provider: none | auth0").option("--postman <provider>", "Postman provider: none | local | api").option("-y, --yes", "Install dependencies without prompting").option("--install <mode>", "Dependency install mode: ask | yes | no", "ask");
|
|
75
|
+
}
|
|
76
|
+
function toApiOptions(directory, opts, extra = {}) {
|
|
77
|
+
const installMode = String(opts.install ?? "ask").toLowerCase();
|
|
78
|
+
const names = Array.isArray(opts.name) ? opts.name : typeof opts.name === "string" ? [
|
|
79
|
+
opts.name
|
|
80
|
+
] : extra.names;
|
|
81
|
+
return {
|
|
82
|
+
d: (0, _resolvetargetdir.resolveTargetDir)(directory, typeof opts.d === "string" ? opts.d : undefined),
|
|
83
|
+
databaseProvider: opts.database,
|
|
84
|
+
authProvider: opts.auth,
|
|
85
|
+
postmanProvider: opts.postman,
|
|
86
|
+
installDependencies: opts.yes === true ? "yes" : installMode === "yes" || installMode === "no" ? installMode : undefined,
|
|
87
|
+
names,
|
|
88
|
+
...extra
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function runScaffoldApi(normalized) {
|
|
92
|
+
(0, _apiname.parseApiNames)(normalized.names);
|
|
93
|
+
const { closePrompt } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../domain/prompt.js")));
|
|
94
|
+
try {
|
|
95
|
+
await (0, _createapi.scaffoldApi)(normalized);
|
|
96
|
+
} finally{
|
|
97
|
+
closePrompt();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Default API project slug when `--name` is omitted. */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get DEFAULT_WEBAPI_NAME () {
|
|
13
|
+
return DEFAULT_WEBAPI_NAME;
|
|
14
|
+
},
|
|
15
|
+
get WEBAPI_PROJECT_DIR () {
|
|
16
|
+
return WEBAPI_PROJECT_DIR;
|
|
17
|
+
},
|
|
18
|
+
get WEBAPI_RELEASE_ENTRY () {
|
|
19
|
+
return WEBAPI_RELEASE_ENTRY;
|
|
20
|
+
},
|
|
21
|
+
get webapiPackageName () {
|
|
22
|
+
return webapiPackageName;
|
|
23
|
+
},
|
|
24
|
+
get webapiPackagedEntry () {
|
|
25
|
+
return webapiPackagedEntry;
|
|
26
|
+
},
|
|
27
|
+
get webapiPort () {
|
|
28
|
+
return webapiPort;
|
|
29
|
+
},
|
|
30
|
+
get webapiProjectDir () {
|
|
31
|
+
return webapiProjectDir;
|
|
32
|
+
},
|
|
33
|
+
get webapiReleaseEntry () {
|
|
34
|
+
return webapiReleaseEntry;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const DEFAULT_WEBAPI_NAME = "api";
|
|
38
|
+
function webapiProjectDir(name) {
|
|
39
|
+
return `projects/${name}`;
|
|
40
|
+
}
|
|
41
|
+
function webapiReleaseEntry(name) {
|
|
42
|
+
return `dist/release/${webapiProjectDir(name)}/${webapiPackagedEntry()}`;
|
|
43
|
+
}
|
|
44
|
+
function webapiPackagedEntry() {
|
|
45
|
+
return "es6/src/main.js";
|
|
46
|
+
}
|
|
47
|
+
function webapiPackageName(workspaceName, apiName) {
|
|
48
|
+
return `@${workspaceName}/${apiName}`;
|
|
49
|
+
}
|
|
50
|
+
function webapiPort(index) {
|
|
51
|
+
return 3000 + index;
|
|
52
|
+
}
|
|
53
|
+
const WEBAPI_PROJECT_DIR = webapiProjectDir(DEFAULT_WEBAPI_NAME);
|
|
54
|
+
const WEBAPI_RELEASE_ENTRY = webapiReleaseEntry(DEFAULT_WEBAPI_NAME);
|