@decohere/scaffold 0.0.1-dev.126 → 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.
Files changed (264) hide show
  1. package/package.json +9 -19
  2. package/src/add-api.action.ts +25 -0
  3. package/src/add-api.command.ts +31 -0
  4. package/src/add.command.ts +20 -0
  5. package/src/add.module.ts +11 -0
  6. package/src/cli.ts +4 -0
  7. package/src/create.command.ts +20 -0
  8. package/src/create.module.ts +11 -0
  9. package/src/domain/prompt.ts +50 -0
  10. package/{types/src/index.d.ts → src/index.ts} +0 -4
  11. package/src/models/compose.model.ts +205 -0
  12. package/src/models/config-yaml.model.ts +83 -0
  13. package/src/models/const.ts +20 -0
  14. package/src/models/dev-container.model.ts +136 -0
  15. package/src/models/docker-image.model.ts +343 -0
  16. package/src/models/env-file.model.ts +45 -0
  17. package/src/models/gitignore.model.ts +35 -0
  18. package/src/models/launch-json.model.ts +60 -0
  19. package/src/models/package-json.model.ts +169 -0
  20. package/src/models/project.model.ts +141 -0
  21. package/{types/src/models/source-file.d.ts → src/models/source-file.ts} +6 -4
  22. package/src/models/tsconfig.model.ts +29 -0
  23. package/src/models/vitest-config.model.ts +26 -0
  24. package/src/models/vscode-settings.model.ts +24 -0
  25. package/src/program.ts +63 -0
  26. package/{types/src/resolve-target-dir.d.ts → src/resolve-target-dir.ts} +4 -1
  27. package/src/services/scaffold.service.ts +89 -0
  28. package/src/version.ts +56 -0
  29. package/src/webapi/api-name.ts +73 -0
  30. package/src/webapi/cli-options.ts +56 -0
  31. package/{types/src/webapi/const.d.ts → src/webapi/const.ts} +21 -9
  32. package/src/webapi/create-api.ts +275 -0
  33. package/src/webapi/devcontainer/host-scripts.ts +35 -0
  34. package/src/webapi/features/auth.feature.ts +454 -0
  35. package/src/webapi/features/auth0-cli.ts +421 -0
  36. package/src/webapi/features/biome-format.ts +34 -0
  37. package/src/webapi/features/database.feature.ts +522 -0
  38. package/src/webapi/features/finalize.feature.ts +112 -0
  39. package/src/webapi/features/postman.feature.ts +287 -0
  40. package/src/webapi/models/api-package-json.model.ts +60 -0
  41. package/src/webapi/models/auth-config.model.ts +36 -0
  42. package/src/webapi/models/controller-source-file.model.ts +232 -0
  43. package/{es6/src/webapi/models/github-ci.model.js → src/webapi/models/github-ci.model.ts} +29 -27
  44. package/src/webapi/models/main-source-file.model.ts +208 -0
  45. package/src/webapi/models/production-dockerfile.model.ts +162 -0
  46. package/src/webapi/models/sample-files.model.ts +45 -0
  47. package/src/webapi/models/webapi-image.model.ts +21 -0
  48. package/src/webapi/postman/hello-openapi.ts +92 -0
  49. package/src/webapi/postman/local-view.ts +195 -0
  50. package/src/webapi/postman/openapi-to-postman.ts +208 -0
  51. package/src/webapi/workspace-readme.ts +192 -0
  52. package/src/webapi.action.ts +22 -0
  53. package/src/webapi.command.ts +41 -0
  54. package/tests/auth-postman.wiring.spec.ts +263 -0
  55. package/tests/auth0-cli.spec.ts +232 -0
  56. package/tests/biome-format.spec.ts +49 -0
  57. package/tests/cli.integration.spec.ts +658 -0
  58. package/tests/compose.model.spec.ts +51 -0
  59. package/tests/container-image.model.spec.ts +162 -0
  60. package/tests/dev-container.model.spec.ts +29 -0
  61. package/tests/devcontainer-base-image.spec.ts +32 -0
  62. package/tests/hello-di-inject.scaffold.spec.ts +18 -0
  63. package/tests/hello-route.contract.spec.ts +94 -0
  64. package/tests/package-json.order.spec.ts +59 -0
  65. package/tests/postman-from-openapi.spec.ts +197 -0
  66. package/tests/seed-devcontainer-templates.ts +40 -0
  67. package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +96 -0
  68. package/LICENSE +0 -15
  69. package/commonjs/src/add-api.action.js +0 -37
  70. package/commonjs/src/add-api.command.js +0 -39
  71. package/commonjs/src/add.command.js +0 -22
  72. package/commonjs/src/add.module.js +0 -24
  73. package/commonjs/src/auth0-configure.action.js +0 -28
  74. package/commonjs/src/auth0-configure.command.js +0 -24
  75. package/commonjs/src/auth0-login.action.js +0 -28
  76. package/commonjs/src/auth0-login.command.js +0 -23
  77. package/commonjs/src/auth0.command.js +0 -22
  78. package/commonjs/src/auth0.module.js +0 -28
  79. package/commonjs/src/cli.js +0 -8
  80. package/commonjs/src/create.command.js +0 -22
  81. package/commonjs/src/create.module.js +0 -24
  82. package/commonjs/src/domain/prompt.js +0 -62
  83. package/commonjs/src/index.js +0 -48
  84. package/commonjs/src/models/compose.model.js +0 -258
  85. package/commonjs/src/models/config-yaml.model.js +0 -86
  86. package/commonjs/src/models/const.js +0 -30
  87. package/commonjs/src/models/dev-container.model.js +0 -172
  88. package/commonjs/src/models/docker-image.model.js +0 -277
  89. package/commonjs/src/models/env-file.model.js +0 -48
  90. package/commonjs/src/models/gitignore.model.js +0 -48
  91. package/commonjs/src/models/launch-json.model.js +0 -70
  92. package/commonjs/src/models/package-json.model.js +0 -156
  93. package/commonjs/src/models/project.model.js +0 -132
  94. package/commonjs/src/models/source-file.js +0 -4
  95. package/commonjs/src/models/tsconfig.model.js +0 -32
  96. package/commonjs/src/models/vitest-config.model.js +0 -33
  97. package/commonjs/src/models/vscode-settings.model.js +0 -29
  98. package/commonjs/src/program.js +0 -64
  99. package/commonjs/src/resolve-target-dir.js +0 -17
  100. package/commonjs/src/services/scaffold.service.js +0 -60
  101. package/commonjs/src/version.js +0 -55
  102. package/commonjs/src/webapi/api-name.js +0 -93
  103. package/commonjs/src/webapi/auth0-commands.js +0 -250
  104. package/commonjs/src/webapi/authorize-scopes.js +0 -79
  105. package/commonjs/src/webapi/cli-options.js +0 -99
  106. package/commonjs/src/webapi/const.js +0 -54
  107. package/commonjs/src/webapi/create-api.js +0 -265
  108. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +0 -164
  109. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  110. package/commonjs/src/webapi/devcontainer/host-scripts.js +0 -50
  111. package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  112. package/commonjs/src/webapi/devcontainer/templates/initialize.sh +0 -169
  113. package/commonjs/src/webapi/devcontainer/templates/post-create.sh +0 -35
  114. package/commonjs/src/webapi/devcontainer/templates/post-start.sh +0 -65
  115. package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  116. package/commonjs/src/webapi/features/auth.feature.js +0 -408
  117. package/commonjs/src/webapi/features/auth0-cli.js +0 -472
  118. package/commonjs/src/webapi/features/biome-format.js +0 -47
  119. package/commonjs/src/webapi/features/database.feature.js +0 -433
  120. package/commonjs/src/webapi/features/finalize.feature.js +0 -93
  121. package/commonjs/src/webapi/features/postman.feature.js +0 -322
  122. package/commonjs/src/webapi/models/api-package-json.model.js +0 -58
  123. package/commonjs/src/webapi/models/auth-config.model.js +0 -24
  124. package/commonjs/src/webapi/models/controller-source-file.model.js +0 -190
  125. package/commonjs/src/webapi/models/github-ci.model.js +0 -193
  126. package/commonjs/src/webapi/models/main-source-file.model.js +0 -165
  127. package/commonjs/src/webapi/models/production-dockerfile.model.js +0 -75
  128. package/commonjs/src/webapi/models/sample-files.model.js +0 -58
  129. package/commonjs/src/webapi/models/webapi-image.model.js +0 -25
  130. package/commonjs/src/webapi/postman/hello-openapi.js +0 -173
  131. package/commonjs/src/webapi/postman/local-view.js +0 -182
  132. package/commonjs/src/webapi/postman/openapi-to-postman.js +0 -238
  133. package/commonjs/src/webapi/workspace-readme.js +0 -109
  134. package/commonjs/src/webapi.action.js +0 -28
  135. package/commonjs/src/webapi.command.js +0 -43
  136. package/es6/src/add-api.action.js +0 -27
  137. package/es6/src/add-api.command.js +0 -29
  138. package/es6/src/add.command.js +0 -12
  139. package/es6/src/add.module.js +0 -14
  140. package/es6/src/auth0-configure.action.js +0 -18
  141. package/es6/src/auth0-configure.command.js +0 -14
  142. package/es6/src/auth0-login.action.js +0 -18
  143. package/es6/src/auth0-login.command.js +0 -13
  144. package/es6/src/auth0.command.js +0 -12
  145. package/es6/src/auth0.module.js +0 -18
  146. package/es6/src/cli.js +0 -4
  147. package/es6/src/create.command.js +0 -12
  148. package/es6/src/create.module.js +0 -14
  149. package/es6/src/domain/prompt.js +0 -41
  150. package/es6/src/index.js +0 -9
  151. package/es6/src/models/compose.model.js +0 -254
  152. package/es6/src/models/config-yaml.model.js +0 -74
  153. package/es6/src/models/const.js +0 -20
  154. package/es6/src/models/dev-container.model.js +0 -162
  155. package/es6/src/models/docker-image.model.js +0 -235
  156. package/es6/src/models/env-file.model.js +0 -44
  157. package/es6/src/models/gitignore.model.js +0 -38
  158. package/es6/src/models/launch-json.model.js +0 -60
  159. package/es6/src/models/package-json.model.js +0 -141
  160. package/es6/src/models/project.model.js +0 -117
  161. package/es6/src/models/source-file.js +0 -1
  162. package/es6/src/models/tsconfig.model.js +0 -22
  163. package/es6/src/models/vitest-config.model.js +0 -23
  164. package/es6/src/models/vscode-settings.model.js +0 -19
  165. package/es6/src/program.js +0 -50
  166. package/es6/src/resolve-target-dir.js +0 -7
  167. package/es6/src/services/scaffold.service.js +0 -50
  168. package/es6/src/version.js +0 -34
  169. package/es6/src/webapi/api-name.js +0 -57
  170. package/es6/src/webapi/auth0-commands.js +0 -185
  171. package/es6/src/webapi/authorize-scopes.js +0 -55
  172. package/es6/src/webapi/cli-options.js +0 -34
  173. package/es6/src/webapi/const.js +0 -21
  174. package/es6/src/webapi/create-api.js +0 -245
  175. package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +0 -154
  176. package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  177. package/es6/src/webapi/devcontainer/host-scripts.js +0 -29
  178. package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  179. package/es6/src/webapi/devcontainer/templates/initialize.sh +0 -169
  180. package/es6/src/webapi/devcontainer/templates/post-create.sh +0 -35
  181. package/es6/src/webapi/devcontainer/templates/post-start.sh +0 -65
  182. package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  183. package/es6/src/webapi/features/auth.feature.js +0 -357
  184. package/es6/src/webapi/features/auth0-cli.js +0 -406
  185. package/es6/src/webapi/features/biome-format.js +0 -40
  186. package/es6/src/webapi/features/database.feature.js +0 -423
  187. package/es6/src/webapi/features/finalize.feature.js +0 -83
  188. package/es6/src/webapi/features/postman.feature.js +0 -256
  189. package/es6/src/webapi/models/api-package-json.model.js +0 -53
  190. package/es6/src/webapi/models/auth-config.model.js +0 -20
  191. package/es6/src/webapi/models/controller-source-file.model.js +0 -181
  192. package/es6/src/webapi/models/main-source-file.model.js +0 -161
  193. package/es6/src/webapi/models/production-dockerfile.model.js +0 -66
  194. package/es6/src/webapi/models/sample-files.model.js +0 -40
  195. package/es6/src/webapi/models/webapi-image.model.js +0 -18
  196. package/es6/src/webapi/postman/hello-openapi.js +0 -166
  197. package/es6/src/webapi/postman/local-view.js +0 -167
  198. package/es6/src/webapi/postman/openapi-to-postman.js +0 -179
  199. package/es6/src/webapi/workspace-readme.js +0 -88
  200. package/es6/src/webapi.action.js +0 -18
  201. package/es6/src/webapi.command.js +0 -33
  202. package/types/src/add-api.action.d.ts +0 -13
  203. package/types/src/add-api.command.d.ts +0 -7
  204. package/types/src/add.command.d.ts +0 -6
  205. package/types/src/add.module.d.ts +0 -14
  206. package/types/src/auth0-configure.action.d.ts +0 -7
  207. package/types/src/auth0-configure.command.d.ts +0 -6
  208. package/types/src/auth0-login.action.d.ts +0 -4
  209. package/types/src/auth0-login.command.d.ts +0 -6
  210. package/types/src/auth0.command.d.ts +0 -6
  211. package/types/src/auth0.module.d.ts +0 -18
  212. package/types/src/cli.d.ts +0 -2
  213. package/types/src/create.command.d.ts +0 -6
  214. package/types/src/create.module.d.ts +0 -14
  215. package/types/src/domain/prompt.d.ts +0 -4
  216. package/types/src/models/compose.model.d.ts +0 -73
  217. package/types/src/models/config-yaml.model.d.ts +0 -27
  218. package/types/src/models/const.d.ts +0 -20
  219. package/types/src/models/dev-container.model.d.ts +0 -49
  220. package/types/src/models/docker-image.model.d.ts +0 -90
  221. package/types/src/models/env-file.model.d.ts +0 -16
  222. package/types/src/models/gitignore.model.d.ts +0 -9
  223. package/types/src/models/launch-json.model.d.ts +0 -7
  224. package/types/src/models/package-json.model.d.ts +0 -36
  225. package/types/src/models/project.model.d.ts +0 -60
  226. package/types/src/models/tsconfig.model.d.ts +0 -5
  227. package/types/src/models/vitest-config.model.d.ts +0 -5
  228. package/types/src/models/vscode-settings.model.d.ts +0 -7
  229. package/types/src/program.d.ts +0 -8
  230. package/types/src/services/scaffold.service.d.ts +0 -22
  231. package/types/src/version.d.ts +0 -6
  232. package/types/src/webapi/api-name.d.ts +0 -14
  233. package/types/src/webapi/auth0-commands.d.ts +0 -11
  234. package/types/src/webapi/authorize-scopes.d.ts +0 -7
  235. package/types/src/webapi/cli-options.d.ts +0 -6
  236. package/types/src/webapi/create-api.d.ts +0 -15
  237. package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +0 -32
  238. package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  239. package/types/src/webapi/devcontainer/host-scripts.d.ts +0 -7
  240. package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  241. package/types/src/webapi/devcontainer/templates/initialize.sh +0 -169
  242. package/types/src/webapi/devcontainer/templates/post-create.sh +0 -35
  243. package/types/src/webapi/devcontainer/templates/post-start.sh +0 -65
  244. package/types/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  245. package/types/src/webapi/features/auth.feature.d.ts +0 -10
  246. package/types/src/webapi/features/auth0-cli.d.ts +0 -84
  247. package/types/src/webapi/features/biome-format.d.ts +0 -5
  248. package/types/src/webapi/features/database.feature.d.ts +0 -7
  249. package/types/src/webapi/features/finalize.feature.d.ts +0 -2
  250. package/types/src/webapi/features/postman.feature.d.ts +0 -16
  251. package/types/src/webapi/models/api-package-json.model.d.ts +0 -18
  252. package/types/src/webapi/models/auth-config.model.d.ts +0 -26
  253. package/types/src/webapi/models/controller-source-file.model.d.ts +0 -46
  254. package/types/src/webapi/models/github-ci.model.d.ts +0 -9
  255. package/types/src/webapi/models/main-source-file.model.d.ts +0 -54
  256. package/types/src/webapi/models/production-dockerfile.model.d.ts +0 -18
  257. package/types/src/webapi/models/sample-files.model.d.ts +0 -7
  258. package/types/src/webapi/models/webapi-image.model.d.ts +0 -12
  259. package/types/src/webapi/postman/hello-openapi.d.ts +0 -19
  260. package/types/src/webapi/postman/local-view.d.ts +0 -17
  261. package/types/src/webapi/postman/openapi-to-postman.d.ts +0 -62
  262. package/types/src/webapi/workspace-readme.d.ts +0 -18
  263. package/types/src/webapi.action.d.ts +0 -14
  264. package/types/src/webapi.command.d.ts +0 -11
@@ -1,256 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { pick } from "../../domain/prompt.js";
5
- import { WELL_KNOWN_FILES } from "../../models/const.js";
6
- import { buildHelloOpenApiDocument } from "../postman/hello-openapi.js";
7
- import { buildEnvironmentYaml, buildLocalViewFilesFromCollection } from "../postman/local-view.js";
8
- import { applyPostmanAuthOverlay, openApiToPostmanCollection } from "../postman/openapi-to-postman.js";
9
- import * as auth0Cli from "./auth0-cli.js";
10
- /** Postman OAuth callback URLs (popup + "Authorize using browser"). */ const POSTMAN_CALLBACKS = [
11
- "https://oauth.pstmn.io/v1/callback",
12
- "https://oauth.pstmn.io/v1/browser-callback"
13
- ];
14
- /** Scopes requested for Auth0 access tokens (OIDC + Hello CASL permissions). */ const POSTMAN_SCOPES = [
15
- "openid",
16
- "profile",
17
- "email",
18
- "read:Hello",
19
- "create:Hello",
20
- "update:Hello",
21
- "delete:Hello"
22
- ].join(" ");
23
- const COLLECTION_DESCRIPTION = "Open the project root in Postman Local View (not the postman/ folder). " + "Select the Local environment, then Authorization → Get New Access Token (PKCE). " + "Routes are generated from OpenAPI; Auth0 overlay is hand-authored.";
24
- async function getOptions(_workspace, cliOptions) {
25
- if (cliOptions.postmanProvider != null) return {};
26
- const choices = [
27
- {
28
- label: "none",
29
- description: "skip"
30
- },
31
- {
32
- label: "local",
33
- description: "Local View / Native Git files (no API key)"
34
- },
35
- {
36
- label: "api",
37
- description: "also upload to Postman.com (needs API key)"
38
- }
39
- ];
40
- const selected = await pick("\n Postman: ", choices, (c)=>`${c.label} — ${c.description}`);
41
- const provider = selected?.label ?? "none";
42
- if (provider === "none") return {
43
- postmanProvider: "none"
44
- };
45
- if (provider === "local") return {
46
- postmanProvider: "local"
47
- };
48
- const apiKey = process.env.POSTMAN_API_KEY ?? await import("../../domain/prompt.js").then((m)=>m.ask("\n Postman API key (app.getpostman.com/settings/me/api-keys): "));
49
- const headers = {
50
- "X-Api-Key": apiKey,
51
- "Content-Type": "application/json"
52
- };
53
- const wsRes = await fetch("https://api.getpostman.com/workspaces", {
54
- headers
55
- });
56
- if (!wsRes.ok) {
57
- console.error("\n Postman API key invalid — falling back to local files.");
58
- return {
59
- postmanProvider: "local"
60
- };
61
- }
62
- const { workspaces } = await wsRes.json();
63
- const wsChoices = [
64
- {
65
- label: "<new workspace>",
66
- id: null
67
- },
68
- ...workspaces.map((w)=>({
69
- label: `${w.name} (${w.type})`,
70
- id: w.id
71
- }))
72
- ];
73
- const wsPicked = await pick("\n Postman workspace: ", wsChoices, (c)=>c.label);
74
- let workspaceId;
75
- if (!wsPicked || wsPicked.id === null) {
76
- const { ask } = await import("../../domain/prompt.js");
77
- const wsName = await ask(` Workspace name: `);
78
- const createRes = await fetch("https://api.getpostman.com/workspaces", {
79
- method: "POST",
80
- headers,
81
- body: JSON.stringify({
82
- workspace: {
83
- name: wsName,
84
- type: "personal"
85
- }
86
- })
87
- });
88
- const { workspace: ws } = await createRes.json();
89
- workspaceId = ws.id;
90
- console.log(` ✓ Workspace created: ${wsName}`);
91
- } else {
92
- workspaceId = wsPicked.id;
93
- }
94
- return {
95
- postmanProvider: "api",
96
- apiKey,
97
- workspaceId
98
- };
99
- }
100
- /** Build Postman collection: OpenAPI routes + Auth0 auth overlay. */ export async function buildHybridPostmanCollection(projectName, auth) {
101
- const openapi = buildHelloOpenApiDocument(projectName);
102
- const base = await openApiToPostmanCollection(openapi);
103
- if (base.info._postman_id == null) {
104
- base.info._postman_id = randomUUID();
105
- }
106
- return applyPostmanAuthOverlay(base, projectName, auth, {
107
- callbacks: POSTMAN_CALLBACKS,
108
- scopes: POSTMAN_SCOPES,
109
- description: COLLECTION_DESCRIPTION
110
- });
111
- }
112
- /** Read a previously scaffolded auth0ClientId so re-scaffold never blanks it. */ function readExistingSpaClientId(targetDir, projectName) {
113
- const envPath = join(targetDir, "postman/environments", `${projectName}-Local.environment.yaml`);
114
- if (!existsSync(envPath)) return undefined;
115
- const text = readFileSync(envPath, "utf8");
116
- const match = text.match(/key:\s*auth0ClientId\s*\n\s*value:\s*["']?([^"'\n]+)/);
117
- const value = match?.[1]?.trim();
118
- return value && value.length > 0 ? value : undefined;
119
- }
120
- /**
121
- * Resolve the Postman SPA client id. Never returns empty — preserves an existing
122
- * env value on Auth0 failure, otherwise throws so we do not write a blank env.
123
- */ function resolveSpaClientId(workspace) {
124
- const appName = `${workspace.name} Postman`;
125
- try {
126
- const app = auth0Cli.ensureSpaApp(appName, [
127
- ...POSTMAN_CALLBACKS
128
- ]);
129
- console.log(app.reused ? ` ✓ Reusing Auth0 SPA app for Postman PKCE (${app.client_id})` : ` ✓ Auth0 SPA app created for Postman PKCE (${app.client_id})`);
130
- try {
131
- auth0Cli.enableConnectionForClient(auth0Cli.DB_CONNECTION_NAME, app.client_id);
132
- console.log(` ✓ Enabled ${auth0Cli.DB_CONNECTION_NAME} on Postman SPA`);
133
- } catch (err) {
134
- console.error(` ✗ Failed to enable DB connection on SPA: ${err instanceof Error ? err.message : err}`);
135
- }
136
- return app.client_id;
137
- } catch (err) {
138
- const existing = readExistingSpaClientId(workspace.targetDir, workspace.name);
139
- if (existing) {
140
- console.error(` ✗ Failed to ensure Auth0 SPA app (${err instanceof Error ? err.message : err})`);
141
- console.log(` ✓ Keeping existing auth0ClientId from Postman environment (${existing})`);
142
- return existing;
143
- }
144
- const detail = err instanceof Error ? err.message : String(err);
145
- // Entity-limit messages are already actionable; avoid burying them.
146
- if (auth0Cli.isAuth0EntityLimitError(err)) {
147
- throw new Error(detail);
148
- }
149
- throw new Error(`Failed to ensure Auth0 SPA app for Postman — auth0ClientId would be empty: ${detail}`);
150
- }
151
- }
152
- async function scaffold(workspace, options) {
153
- if (options.postmanProvider === "none" || options.postmanProvider == null) return;
154
- const authConfigModel = workspace.getModel(WELL_KNOWN_FILES.AUTH_CONFIG);
155
- const authCfg = authConfigModel?.config;
156
- const spaClientId = authCfg?.issuerBaseUrl ? resolveSpaClientId(workspace) : undefined;
157
- const auth0Env = authCfg?.issuerBaseUrl ? {
158
- auth0Domain: authCfg.issuerBaseUrl.replace(/^https?:\/\//, ""),
159
- auth0Audience: authCfg.audience,
160
- auth0ClientId: spaClientId
161
- } : undefined;
162
- const projectName = workspace.name;
163
- const envName = `${projectName} Local`;
164
- const collection = await buildHybridPostmanCollection(projectName, auth0Env);
165
- const localFiles = buildLocalViewFilesFromCollection(collection, projectName, auth0Env, {
166
- callbacks: POSTMAN_CALLBACKS,
167
- scopes: POSTMAN_SCOPES
168
- });
169
- const envYaml = buildEnvironmentYaml(envName, auth0Env, {
170
- callbacks: POSTMAN_CALLBACKS,
171
- scopes: POSTMAN_SCOPES
172
- });
173
- workspace.addFile({
174
- files: ()=>[
175
- {
176
- filePath: ".postman/resources.yaml",
177
- content: [
178
- "# Open this project root in Postman (Files → Open folder), not the postman/ subfolder.",
179
- "# Postman fills workspace.id when you connect Local View.",
180
- "#",
181
- "# All resources under postman/ are registered automatically.",
182
- "# Route requests are generated from OpenAPI; Auth0 overlay is hand-authored.",
183
- ""
184
- ].join("\n")
185
- },
186
- {
187
- filePath: `postman/environments/${projectName}-Local.environment.yaml`,
188
- content: envYaml
189
- },
190
- ...localFiles
191
- ]
192
- });
193
- if (options.postmanProvider === "api" && options.apiKey) {
194
- const headers = {
195
- "X-Api-Key": options.apiKey,
196
- "Content-Type": "application/json"
197
- };
198
- const colRes = await fetch(`https://api.getpostman.com/collections?workspace=${options.workspaceId}`, {
199
- method: "POST",
200
- headers,
201
- body: JSON.stringify({
202
- collection
203
- })
204
- });
205
- if (colRes.ok) {
206
- console.log(" ✓ Postman collection uploaded");
207
- } else {
208
- console.error(" ✗ Failed to upload Postman collection");
209
- }
210
- const envValues = [
211
- {
212
- key: "baseUrl",
213
- value: "http://localhost:3000",
214
- enabled: true
215
- },
216
- ...auth0Env?.auth0Domain ? [
217
- {
218
- key: "auth0Domain",
219
- value: auth0Env.auth0Domain,
220
- enabled: true
221
- },
222
- {
223
- key: "auth0Audience",
224
- value: auth0Env.auth0Audience ?? "",
225
- enabled: true
226
- },
227
- {
228
- key: "auth0ClientId",
229
- value: auth0Env.auth0ClientId ?? "",
230
- enabled: true
231
- }
232
- ] : []
233
- ];
234
- const envRes = await fetch(`https://api.getpostman.com/environments?workspace=${options.workspaceId}`, {
235
- method: "POST",
236
- headers,
237
- body: JSON.stringify({
238
- environment: {
239
- name: envName,
240
- values: envValues
241
- }
242
- })
243
- });
244
- if (envRes.ok) {
245
- console.log(" ✓ Postman environment uploaded");
246
- } else {
247
- console.error(" ✗ Failed to upload Postman environment");
248
- }
249
- }
250
- }
251
- export const PostmanFeature = {
252
- getOptions,
253
- scaffold
254
- };
255
- export { buildHelloOpenApiDocument } from "../postman/hello-openapi.js";
256
- export { POSTMAN_CALLBACKS, POSTMAN_SCOPES };
@@ -1,53 +0,0 @@
1
- import { WELL_KNOWN_FILES } from "../../models/const.js";
2
- import { sortStringMap } from "../../models/package-json.model.js";
3
- import { CREATE_VERSION } from "../../version.js";
4
- /**
5
- * Builder for `projects/<api>/package.json`.
6
- *
7
- * Starts with the core `@decohere/http` + `@decohere/crucible` deps. Features can call
8
- * `addDependency` / `addDevDependency` to extend.
9
- */ export class ApiPackageJson {
10
- workspaceName;
11
- apiName;
12
- key = WELL_KNOWN_FILES.API_PACKAGE_JSON;
13
- _dependencies;
14
- _devDependencies = {};
15
- constructor(workspaceName, apiName = "api"){
16
- this.workspaceName = workspaceName;
17
- this.apiName = apiName;
18
- this._dependencies = {
19
- "@decohere/http": CREATE_VERSION,
20
- "@decohere/crucible": CREATE_VERSION
21
- };
22
- }
23
- addDependency(name, version) {
24
- this._dependencies[name] = version;
25
- return this;
26
- }
27
- addDevDependency(name, version) {
28
- this._devDependencies[name] = version;
29
- return this;
30
- }
31
- files() {
32
- const pkg = {
33
- name: `@${this.workspaceName}/${this.apiName}`,
34
- version: "0.0.1",
35
- private: true,
36
- type: "module",
37
- main: "src/main.ts",
38
- scripts: {
39
- lint: "biome check --write ."
40
- },
41
- dependencies: sortStringMap(this._dependencies)
42
- };
43
- if (Object.keys(this._devDependencies).length > 0) {
44
- pkg.devDependencies = sortStringMap(this._devDependencies);
45
- }
46
- return [
47
- {
48
- filePath: "package.json",
49
- content: JSON.stringify(pkg, null, 2)
50
- }
51
- ];
52
- }
53
- }
@@ -1,20 +0,0 @@
1
- import { WELL_KNOWN_FILES } from "../../models/const.js";
2
- /**
3
- * Data-carrier model for auth configuration.
4
- *
5
- * Registered by AuthFeature when auth0 is configured. Other features (e.g.
6
- * PostmanFeature) retrieve it via workspace.getModel(WELL_KNOWN_FILES.AUTH_CONFIG).
7
- * Produces no files — exists solely so features can communicate auth details.
8
- */ export class AuthConfigModel {
9
- config;
10
- key = WELL_KNOWN_FILES.AUTH_CONFIG;
11
- constructor(config){
12
- this.config = config;
13
- }
14
- setAdminUser(adminUser) {
15
- this.config.adminUser = adminUser;
16
- }
17
- files() {
18
- return [];
19
- }
20
- }
@@ -1,181 +0,0 @@
1
- import { WELL_KNOWN_FILES } from "../../models/const.js";
2
- /** Tracks named imports from a single module path, split into values and types. */ class ImportGroup {
3
- _values = [];
4
- _types = [];
5
- add(name, typeOnly = false) {
6
- if (typeOnly) {
7
- // Value import already present — value wins, skip
8
- if (!this._values.includes(name) && !this._types.includes(name)) {
9
- this._types.push(name);
10
- }
11
- } else {
12
- // Promote: remove from types if it was previously type-only
13
- const typeIdx = this._types.indexOf(name);
14
- if (typeIdx !== -1) this._types.splice(typeIdx, 1);
15
- if (!this._values.includes(name)) this._values.push(name);
16
- }
17
- return this;
18
- }
19
- render(from) {
20
- const values = [
21
- ...this._values
22
- ].sort();
23
- const types = [
24
- ...this._types
25
- ].sort().map((n)=>`type ${n}`);
26
- return `import { ${[
27
- ...values,
28
- ...types
29
- ].join(", ")} } from "${from}";`;
30
- }
31
- }
32
- /**
33
- * A controller method. Features call `addDecorator()` to prepend decorators
34
- * before the HTTP verb decorator (e.g. `@AllowAnonymous` before `@Get()`).
35
- */ export class ControllerMethod {
36
- name;
37
- _httpDecorator;
38
- _params;
39
- _extraDecorators = [];
40
- _body;
41
- _isAsync;
42
- constructor(name, _httpDecorator, _params, isAsync, body){
43
- this.name = name;
44
- this._httpDecorator = _httpDecorator;
45
- this._params = _params;
46
- this._isAsync = isAsync;
47
- this._body = body;
48
- }
49
- addDecorator(decorator) {
50
- this._extraDecorators.push(decorator);
51
- return this;
52
- }
53
- /** Replace the method body lines (used by features that extend generated behaviour). */ setBody(body) {
54
- this._body = body;
55
- return this;
56
- }
57
- setAsync(isAsync = true) {
58
- this._isAsync = isAsync;
59
- return this;
60
- }
61
- render() {
62
- const lines = [];
63
- for (const d of this._extraDecorators){
64
- lines.push(`\t${d}`);
65
- }
66
- lines.push(`\t${this._httpDecorator}`);
67
- const asyncKw = this._isAsync ? "async " : "";
68
- lines.push(`\tpublic ${asyncKw}${this.name}(${this._params}) {`);
69
- for (const line of this._body){
70
- lines.push(`\t\t${line}`);
71
- }
72
- lines.push("\t}");
73
- return lines;
74
- }
75
- }
76
- /**
77
- * Model for `projects/api/src/controllers/hello.controller.ts`.
78
- *
79
- * Pre-initialised with all routes and their HTTP decorators. Features mutate
80
- * the model via `getMethod(name).addDecorator(...)`, `addDecorator(...)` (class
81
- * level), `addCortexImport(...)`, `addImport(...)`, and `addConstructorParam(...)`.
82
- */ export class ControllerSourceFile {
83
- key = WELL_KNOWN_FILES.CONTROLLER_TS;
84
- _cortexImports = new ImportGroup().add("Controller").add("Delete").add("Field").add("Get").add("Param").add("Post").add("Put").add("Query");
85
- _extraImportGroups = new Map([
86
- [
87
- "@decohere/crucible/decorators",
88
- new ImportGroup().add("inject")
89
- ]
90
- ]);
91
- _classDecorators = [];
92
- /** Explicit @inject(SampleService): using the class as a value keeps its import, which SWC can drop when the class is only a type (design:paramtypes then collapses to Object). */ _ctorParams = [
93
- "@inject(SampleService) private readonly sample: SampleService"
94
- ];
95
- _methods = new Map([
96
- [
97
- "getAll",
98
- new ControllerMethod("getAll", "@Get()", '@Query("filter") filter: string', true, [
99
- "const greeting = await this.sample.getGreeting();",
100
- "return { filter, message: greeting };"
101
- ])
102
- ],
103
- [
104
- "getOne",
105
- new ControllerMethod("getOne", '@Get("/:id")', '@Param("id") id: string', false, [
106
- "return { id, message: `Hello ${id}!` };"
107
- ])
108
- ],
109
- [
110
- "create",
111
- new ControllerMethod("create", "@Post()", "body: HelloBody", false, [
112
- "return { message: body.message };"
113
- ])
114
- ],
115
- [
116
- "update",
117
- new ControllerMethod("update", '@Put("/:id")', '@Param("id") id: string, body: HelloBody', false, [
118
- "return { id, message: body.message };"
119
- ])
120
- ],
121
- [
122
- "remove",
123
- new ControllerMethod("remove", '@Delete("/:id")', '@Param("id") id: string', false, [
124
- "return { id, deleted: true };"
125
- ])
126
- ]
127
- ]);
128
- /** Retrieve a method by name to mutate its decorators. */ getMethod(name) {
129
- const m = this._methods.get(name);
130
- if (m == null) throw new Error(`No method '${name}' on ControllerSourceFile`);
131
- return m;
132
- }
133
- /** Add a class-level decorator (e.g. `@Authorize`). */ addDecorator(decorator) {
134
- this._classDecorators.push(decorator);
135
- return this;
136
- }
137
- /** Add a named import from `@decohere/http`. */ addCortexImport(name, typeOnly = false) {
138
- this._cortexImports.add(name, typeOnly);
139
- return this;
140
- }
141
- /** Add a named import from any other module. */ addImport(name, from, typeOnly = false) {
142
- const group = this._extraImportGroups.get(from) ?? new ImportGroup();
143
- group.add(name, typeOnly);
144
- this._extraImportGroups.set(from, group);
145
- return this;
146
- }
147
- /** Add a constructor parameter (e.g. an injected dependency). */ addConstructorParam(param) {
148
- this._ctorParams.push(param);
149
- return this;
150
- }
151
- files() {
152
- const lines = [
153
- this._cortexImports.render("@decohere/http"),
154
- 'import { SampleService } from "../services/sample.service.js";'
155
- ];
156
- for (const [from, group] of this._extraImportGroups){
157
- lines.push(group.render(from));
158
- }
159
- lines.push("", "class HelloBody {", '\t@Field("body", "message")', "\tpublic message!: string;", "}", "");
160
- for (const d of this._classDecorators){
161
- lines.push(d);
162
- }
163
- lines.push('@Controller({ prefix: "/hello" })', "export class HelloController {", "");
164
- lines.push("\tpublic constructor(");
165
- for (const p of this._ctorParams){
166
- lines.push(`\t\t${p},`);
167
- }
168
- lines.push("\t) {}");
169
- lines.push("");
170
- for (const method of this._methods.values()){
171
- lines.push(...method.render(), "");
172
- }
173
- lines.push("}", "");
174
- return [
175
- {
176
- filePath: "src/controllers/hello.controller.ts",
177
- content: lines.join("\n")
178
- }
179
- ];
180
- }
181
- }
@@ -1,161 +0,0 @@
1
- import { WELL_KNOWN_FILES } from "../../models/const.js";
2
- /** Tracks named imports from a single module path, split into values and types. */ class ImportGroup {
3
- _values = [];
4
- _types = [];
5
- add(name, typeOnly = false) {
6
- if (typeOnly) {
7
- // Value import already present — value wins, skip
8
- if (!this._values.includes(name) && !this._types.includes(name)) {
9
- this._types.push(name);
10
- }
11
- } else {
12
- // Promote: remove from types if it was previously type-only
13
- const typeIdx = this._types.indexOf(name);
14
- if (typeIdx !== -1) this._types.splice(typeIdx, 1);
15
- if (!this._values.includes(name)) this._values.push(name);
16
- }
17
- return this;
18
- }
19
- render(from) {
20
- const values = [
21
- ...this._values
22
- ].sort();
23
- const types = [
24
- ...this._types
25
- ].sort().map((n)=>`type ${n}`);
26
- return `import { ${[
27
- ...values,
28
- ...types
29
- ].join(", ")} } from "${from}";`;
30
- }
31
- }
32
- /**
33
- * Model for `projects/api/src/main.ts`.
34
- *
35
- * Starts with the minimal HTTP + YAML config setup. Features mutate the model
36
- * by calling addSideEffectImport / addImport / addBuilderCall / addEntity /
37
- * addRepository. files() renders whatever has been accumulated.
38
- */ export class MainSourceFile {
39
- appName;
40
- key = WELL_KNOWN_FILES.MAIN_TS;
41
- _sideEffectImports = [];
42
- _extraImports = new Map();
43
- _builderCalls = [];
44
- _entities = [];
45
- _repositories = [];
46
- _services = [];
47
- _dataSourceName;
48
- _typeOrmSeed;
49
- constructor(appName){
50
- this.appName = appName;
51
- }
52
- /** Adds a bare side-effect import, e.g. `@decohere/http/auth`. */ addSideEffectImport(path) {
53
- if (!this._sideEffectImports.includes(path)) this._sideEffectImports.push(path);
54
- return this;
55
- }
56
- /** Adds a named import, e.g. `import { Foo } from "bar"`. */ addImport(name, from, typeOnly = false) {
57
- const group = this._extraImports.get(from) ?? new ImportGroup();
58
- group.add(name, typeOnly);
59
- this._extraImports.set(from, group);
60
- return this;
61
- }
62
- /**
63
- * Adds a builder call inserted after `.withConfiguration()` and before
64
- * `.withServices()`. Pass the call without leading dot, e.g. `.withAuth()`.
65
- */ addBuilderCall(call) {
66
- this._builderCalls.push(call);
67
- return this;
68
- }
69
- /** Adds a TypeORM entity — import and entry in `withTypeOrm({ entities })`. */ addEntity(entity) {
70
- this._entities.push(entity);
71
- return this;
72
- }
73
- /** Adds a TypeORM repository — import and entry in `withTypeOrm({ repositories })`. */ addRepository(repo) {
74
- this._repositories.push(repo);
75
- return this;
76
- }
77
- /** Adds a service registered in `.withServices()`. */ addService(service) {
78
- this._services.push(service);
79
- return this;
80
- }
81
- /**
82
- * Datasource name passed to `withTypeOrm({ name })`. Must match
83
- * `database.dataSources[].name` in config.yaml.
84
- */ setDataSourceName(name) {
85
- this._dataSourceName = name;
86
- return this;
87
- }
88
- /**
89
- * Inline seed callback body for `withTypeOrm({ seed })`.
90
- * Receives `dataSource` in scope. Example: `await dataSource.getRepository(User).save(...)`.
91
- */ setTypeOrmSeed(seedBody) {
92
- this._typeOrmSeed = seedBody;
93
- return this;
94
- }
95
- files() {
96
- const imports = [
97
- 'import "@decohere/scribe-pino";',
98
- 'import "@decohere/http/http";'
99
- ];
100
- for (const path of this._sideEffectImports){
101
- imports.push(`import "${path}";`);
102
- }
103
- imports.push('import "@decohere/config";', 'import { YamlDataSource } from "@decohere/config";', 'import { Builder } from "@decohere/http";', 'import { FastifyProvider } from "@decohere/http/providers";', 'import { scribe } from "@decohere/scribe";', 'import { SampleService } from "./services/sample.service.js";');
104
- for (const e of this._entities){
105
- imports.push(`import { ${e.className} } from "${e.importPath}";`);
106
- }
107
- for (const r of this._repositories){
108
- imports.push(`import { ${r.className} } from "${r.importPath}";`);
109
- }
110
- for (const s of this._services){
111
- imports.push(`import { ${s.className} } from "${s.importPath}";`);
112
- }
113
- for (const [from, group] of this._extraImports){
114
- imports.push(group.render(from));
115
- }
116
- imports.push('import { HelloController } from "./controllers/hello.controller.js";');
117
- const serviceRegs = [
118
- "cb.registerSingleton(SampleService);",
119
- ...this._services.map((s)=>s.scope === "request" ? `cb.registerRequestScoped(${s.className});` : `cb.registerSingleton(${s.className});`)
120
- ].join(" ");
121
- const builderCalls = [
122
- `\t.withHttp(FastifyProvider)`,
123
- `\t.withConfiguration(YamlDataSource)`,
124
- `\t.withHealth()`,
125
- `\t.withOpenApi({ info: { title: "${this.appName}", version: "1.0.0" } })`,
126
- ...this._builderCalls.map((c)=>`\t${c}`),
127
- `\t.withServices((cb) => { ${serviceRegs} })`
128
- ];
129
- if (this._entities.length > 0) {
130
- const entities = this._entities.map((e)=>e.className).join(", ");
131
- const repos = this._repositories.map((r)=>r.className).join(", ");
132
- const named = this._dataSourceName != null ? `name: "${this._dataSourceName}", ` : "";
133
- if (this._typeOrmSeed) {
134
- builderCalls.push(`\t.withTypeOrm({ ${named}entities: [${entities}], repositories: [${repos}], seed: async (dataSource) => { ${this._typeOrmSeed} } })`);
135
- } else {
136
- builderCalls.push(`\t.withTypeOrm({ ${named}entities: [${entities}], repositories: [${repos}] })`);
137
- }
138
- }
139
- builderCalls.push(`\t.withControllers(HelloController)`);
140
- const content = [
141
- ...imports,
142
- "",
143
- `scribe.withPinoPretty().and.withPinoRoll({ file: "logs/${this.appName}.log" });`,
144
- "",
145
- `const app = await Builder.create({ applicationName: "${this.appName}" })`,
146
- ...builderCalls,
147
- `\t.build();`,
148
- "",
149
- "await app.start({ port: Number(process.env.PORT ?? 3000) });",
150
- "",
151
- "export default app;",
152
- ""
153
- ].join("\n");
154
- return [
155
- {
156
- filePath: "src/main.ts",
157
- content
158
- }
159
- ];
160
- }
161
- }