@aifabrix/builder 2.44.5 → 2.44.6

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 (207) hide show
  1. package/.cursor/rules/cli-layout.mdc +1 -1
  2. package/.cursor/rules/project-rules.mdc +1 -1
  3. package/.npmrc.token +1 -1
  4. package/README.md +15 -23
  5. package/integration/hubspot-test/README.md +2 -0
  6. package/integration/hubspot-test/test.js +5 -3
  7. package/jest.projects.js +48 -2
  8. package/lib/api/controller-health.api.js +49 -0
  9. package/lib/api/dimension-values.api.js +82 -0
  10. package/lib/api/dimensions.api.js +114 -0
  11. package/lib/api/external-systems.api.js +1 -0
  12. package/lib/api/integration-clients.api.js +168 -0
  13. package/lib/api/types/dimension-values.types.js +28 -0
  14. package/lib/api/types/dimensions.types.js +31 -0
  15. package/lib/api/types/integration-clients.types.js +45 -0
  16. package/lib/api/validation-runner.js +46 -25
  17. package/lib/app/deploy-config.js +11 -1
  18. package/lib/app/deploy-status-display.js +3 -3
  19. package/lib/app/deploy.js +36 -14
  20. package/lib/app/display.js +15 -11
  21. package/lib/app/push.js +46 -23
  22. package/lib/app/register.js +1 -1
  23. package/lib/app/restart-display.js +95 -0
  24. package/lib/app/rotate-secret.js +1 -1
  25. package/lib/app/run-container-start.js +12 -6
  26. package/lib/app/run-env-compose.js +30 -1
  27. package/lib/app/run-helpers.js +44 -12
  28. package/lib/app/run-reload-sync.js +148 -0
  29. package/lib/app/run-resolve-image.js +51 -1
  30. package/lib/app/run.js +99 -73
  31. package/lib/build/index.js +75 -45
  32. package/lib/cli/doctor-check.js +117 -0
  33. package/lib/cli/index.js +8 -2
  34. package/lib/cli/infra-guided.js +445 -0
  35. package/lib/cli/setup-app.js +20 -2
  36. package/lib/cli/setup-auth.js +26 -0
  37. package/lib/cli/setup-dev-path-commands.js +50 -3
  38. package/lib/cli/setup-infra.js +134 -61
  39. package/lib/cli/setup-integration-client.js +182 -0
  40. package/lib/cli/setup-parameters.js +21 -2
  41. package/lib/cli/setup-platform.js +102 -0
  42. package/lib/cli/setup-secrets.js +18 -6
  43. package/lib/cli/setup-utility.js +78 -33
  44. package/lib/commands/datasource-capability-dimension-cli.js +128 -0
  45. package/lib/commands/datasource-capability-output.js +29 -0
  46. package/lib/commands/datasource-capability-relate-cli.js +140 -0
  47. package/lib/commands/datasource-capability.js +411 -0
  48. package/lib/commands/datasource-unified-test-cli.options.js +1 -1
  49. package/lib/commands/datasource.js +53 -13
  50. package/lib/commands/dev-down.js +3 -3
  51. package/lib/commands/dev-infra-gate.js +32 -0
  52. package/lib/commands/dev-init.js +13 -7
  53. package/lib/commands/dimension-value.js +179 -0
  54. package/lib/commands/dimension.js +330 -0
  55. package/lib/commands/integration-client.js +430 -0
  56. package/lib/commands/login-device.js +65 -30
  57. package/lib/commands/login.js +21 -10
  58. package/lib/commands/parameters-validate.js +78 -13
  59. package/lib/commands/repair-datasource-auto-rbac.js +166 -0
  60. package/lib/commands/repair-datasource-keys.js +10 -5
  61. package/lib/commands/repair-datasource.js +19 -7
  62. package/lib/commands/repair-env-template.js +4 -1
  63. package/lib/commands/repair-openapi-sync.js +172 -0
  64. package/lib/commands/repair-persist.js +102 -0
  65. package/lib/commands/repair-rbac-extract.js +27 -0
  66. package/lib/commands/repair-rbac-migrate.js +186 -0
  67. package/lib/commands/repair-rbac.js +214 -31
  68. package/lib/commands/repair-system-alignment.js +246 -0
  69. package/lib/commands/repair-system-permissions.js +168 -0
  70. package/lib/commands/repair.js +120 -338
  71. package/lib/commands/secure.js +1 -1
  72. package/lib/commands/setup-modes.js +455 -0
  73. package/lib/commands/setup-prompts.js +388 -0
  74. package/lib/commands/setup.js +149 -0
  75. package/lib/commands/teardown.js +228 -0
  76. package/lib/commands/up-common.js +79 -19
  77. package/lib/commands/up-dataplane.js +33 -11
  78. package/lib/commands/up-miso.js +7 -11
  79. package/lib/commands/upload.js +109 -23
  80. package/lib/commands/wizard-core-helpers.js +14 -11
  81. package/lib/commands/wizard-core.js +6 -5
  82. package/lib/commands/wizard-dataplane.js +2 -2
  83. package/lib/commands/wizard-entity-selection.js +4 -3
  84. package/lib/commands/wizard-headless.js +2 -1
  85. package/lib/commands/wizard.js +2 -1
  86. package/lib/constants/infra-compose-service-names.js +40 -0
  87. package/lib/core/env-reader.js +16 -3
  88. package/lib/core/secrets-admin-env.js +101 -0
  89. package/lib/core/secrets-ensure-infra.js +34 -1
  90. package/lib/core/secrets-ensure.js +88 -66
  91. package/lib/core/secrets-env-content.js +432 -0
  92. package/lib/core/secrets-env-write.js +27 -1
  93. package/lib/core/secrets-load.js +248 -0
  94. package/lib/core/secrets-names.js +32 -0
  95. package/lib/core/secrets.js +17 -757
  96. package/lib/datasource/capability/basic-exposure.js +76 -0
  97. package/lib/datasource/capability/capability-diff-slice.js +41 -0
  98. package/lib/datasource/capability/capability-key.js +34 -0
  99. package/lib/datasource/capability/capability-resolve.js +172 -0
  100. package/lib/datasource/capability/capability-storage-keys.js +22 -0
  101. package/lib/datasource/capability/copy-operations.js +348 -0
  102. package/lib/datasource/capability/copy-test-payload.js +139 -0
  103. package/lib/datasource/capability/create-operations.js +235 -0
  104. package/lib/datasource/capability/dimension-operations.js +151 -0
  105. package/lib/datasource/capability/dimension-validate.js +219 -0
  106. package/lib/datasource/capability/json-pointer.js +31 -0
  107. package/lib/datasource/capability/reference-rewrite.js +51 -0
  108. package/lib/datasource/capability/relate-operations.js +325 -0
  109. package/lib/datasource/capability/relate-validate.js +219 -0
  110. package/lib/datasource/capability/remove-operations.js +275 -0
  111. package/lib/datasource/capability/run-capability-copy.js +152 -0
  112. package/lib/datasource/capability/run-capability-diff.js +135 -0
  113. package/lib/datasource/capability/run-capability-dimension.js +291 -0
  114. package/lib/datasource/capability/run-capability-edit.js +377 -0
  115. package/lib/datasource/capability/run-capability-relate.js +193 -0
  116. package/lib/datasource/capability/run-capability-remove.js +105 -0
  117. package/lib/datasource/capability/templates/minimal-fetch.json +18 -0
  118. package/lib/datasource/capability/validate-capability-slice.js +35 -0
  119. package/lib/datasource/list.js +136 -23
  120. package/lib/datasource/log-viewer.js +2 -4
  121. package/lib/datasource/unified-validation-run.js +51 -16
  122. package/lib/datasource/validate.js +53 -1
  123. package/lib/deployment/deploy-poll-ui.js +60 -0
  124. package/lib/deployment/deployer-status.js +29 -3
  125. package/lib/deployment/deployer.js +48 -30
  126. package/lib/deployment/environment.js +7 -2
  127. package/lib/deployment/poll-interval.js +72 -0
  128. package/lib/deployment/push.js +11 -9
  129. package/lib/external-system/deploy.js +4 -1
  130. package/lib/external-system/download.js +61 -32
  131. package/lib/external-system/sync-deploy-manifest.js +33 -0
  132. package/lib/infrastructure/index.js +49 -19
  133. package/lib/infrastructure/orphan-infra-docker-teardown.js +177 -0
  134. package/lib/parameters/infra-kv-discovery.js +29 -4
  135. package/lib/parameters/infra-parameter-catalog.js +6 -3
  136. package/lib/parameters/infra-parameter-validate.js +67 -19
  137. package/lib/resolvers/datasource-resolver.js +53 -0
  138. package/lib/resolvers/dimension-file.js +52 -0
  139. package/lib/resolvers/manifest-resolver.js +133 -0
  140. package/lib/schema/external-datasource.schema.json +183 -53
  141. package/lib/schema/external-system.schema.json +23 -10
  142. package/lib/schema/infra.parameter.yaml +26 -11
  143. package/lib/schema/wizard-config.schema.json +1 -1
  144. package/lib/utils/aifabrix-config-dir-walk.js +40 -0
  145. package/lib/utils/aifabrix-runtime-config-dir.js +26 -3
  146. package/lib/utils/app-run-containers.js +2 -2
  147. package/lib/utils/bash-secret-env.js +59 -0
  148. package/lib/utils/cli-secrets-error-format.js +78 -0
  149. package/lib/utils/cli-test-layout-chalk.js +31 -9
  150. package/lib/utils/cli-utils.js +4 -36
  151. package/lib/utils/datasource-test-run-display.js +8 -0
  152. package/lib/utils/dev-hosts-helper.js +3 -2
  153. package/lib/utils/dev-init-ssh-merge.js +2 -1
  154. package/lib/utils/docker-build.js +17 -9
  155. package/lib/utils/docker-reload-mount.js +127 -0
  156. package/lib/utils/external-readme.js +71 -2
  157. package/lib/utils/external-system-local-test-tty.js +3 -2
  158. package/lib/utils/external-system-readiness-core.js +45 -12
  159. package/lib/utils/external-system-readiness-deploy-display.js +3 -3
  160. package/lib/utils/external-system-readiness-display-internals.js +33 -3
  161. package/lib/utils/external-system-readiness-display.js +10 -1
  162. package/lib/utils/file-upload.js +40 -3
  163. package/lib/utils/health-check-db-init.js +107 -0
  164. package/lib/utils/health-check-public-warn.js +69 -0
  165. package/lib/utils/health-check-url.js +19 -4
  166. package/lib/utils/health-check.js +135 -105
  167. package/lib/utils/help-builder.js +5 -1
  168. package/lib/utils/image-name.js +34 -7
  169. package/lib/utils/integration-file-backup.js +74 -0
  170. package/lib/utils/mutagen-install.js +30 -3
  171. package/lib/utils/paths.js +108 -25
  172. package/lib/utils/postgres-wipe.js +212 -0
  173. package/lib/utils/register-aifabrix-shell-env.js +15 -0
  174. package/lib/utils/remote-dev-auth.js +21 -5
  175. package/lib/utils/remote-docker-env.js +9 -1
  176. package/lib/utils/remote-secrets-loader.js +42 -3
  177. package/lib/utils/resolve-docker-image-ref.js +9 -3
  178. package/lib/utils/secrets-ancestor-paths.js +47 -0
  179. package/lib/utils/secrets-helpers.js +17 -10
  180. package/lib/utils/secrets-kv-refs.js +42 -0
  181. package/lib/utils/secrets-kv-scope.js +19 -2
  182. package/lib/utils/secrets-materialize-local.js +134 -0
  183. package/lib/utils/secrets-path.js +24 -10
  184. package/lib/utils/secrets-utils.js +2 -2
  185. package/lib/utils/system-builder-root.js +34 -0
  186. package/lib/utils/url-declarative-resolve-build.js +6 -1
  187. package/lib/utils/url-declarative-runtime-base-path.js +32 -0
  188. package/lib/utils/url-declarative-vdir-inactive-env.js +2 -1
  189. package/lib/utils/urls-local-registry.js +23 -12
  190. package/lib/utils/validation-poll-ui.js +81 -0
  191. package/lib/utils/validation-run-poll.js +29 -5
  192. package/lib/utils/with-muted-logger.js +53 -0
  193. package/package.json +1 -1
  194. package/templates/applications/dataplane/application.yaml +1 -1
  195. package/templates/applications/dataplane/rbac.yaml +10 -10
  196. package/templates/applications/keycloak/env.template +8 -6
  197. package/templates/applications/miso-controller/application.yaml +7 -0
  198. package/templates/applications/miso-controller/env.template +1 -1
  199. package/templates/applications/miso-controller/rbac.yaml +9 -9
  200. package/templates/external-system/README.md.hbs +83 -123
  201. package/.nyc_output/55e9d034-ddab-4579-a706-e02a91d75c91.json +0 -1
  202. package/.nyc_output/processinfo/55e9d034-ddab-4579-a706-e02a91d75c91.json +0 -1
  203. package/.nyc_output/processinfo/index.json +0 -1
  204. package/lib/api/service-users.api.js +0 -150
  205. package/lib/api/types/service-users.types.js +0 -65
  206. package/lib/cli/setup-service-user.js +0 -187
  207. package/lib/commands/service-user.js +0 -429
@@ -1,6 +1,14 @@
1
- const { formatSuccessLine } = require('../utils/cli-test-layout-chalk');
1
+ const {
2
+ formatSuccessLine,
3
+ formatWarningLine,
4
+ formatProgress,
5
+ sectionTitle,
6
+ headerKeyValue,
7
+ metadata
8
+ } = require('../utils/cli-test-layout-chalk');
2
9
  /**
3
- * Upload external system to dataplane (single pipeline upload: validate → publish → controller register).
10
+ * Upload external system to dataplane (sync local `integration/<systemKey>/openapi/*.json` when present,
11
+ * then single pipeline upload: validate → publish → controller register).
4
12
  *
5
13
  * @fileoverview Upload command handler for aifabrix upload <systemKey>
6
14
  * @author AI Fabrix Team
@@ -10,6 +18,8 @@ const { formatSuccessLine } = require('../utils/cli-test-layout-chalk');
10
18
  const path = require('path');
11
19
  const chalk = require('chalk');
12
20
  const logger = require('../utils/logger');
21
+
22
+ const SEP = chalk.gray('────────────────────────────────────────');
13
23
  const { resolveControllerUrl } = require('../utils/controller-url');
14
24
  const { getDeploymentAuth, requireBearerForDataplanePipeline } = require('../utils/token-manager');
15
25
  const { resolveDataplaneUrl } = require('../utils/dataplane-resolver');
@@ -38,6 +48,7 @@ const {
38
48
  } = require('../utils/external-system-readiness-display');
39
49
  const { maybeSyncSystemCertificationFromDataplane } = require('../certification/sync-system-certification');
40
50
  const { cliOptsSkipCertSync } = require('../certification/cli-cert-sync-skip');
51
+ const { maybeSyncOpenApiFilesForMcp } = require('./repair-openapi-sync');
41
52
 
42
53
  /**
43
54
  * Validates system-key format (same as download).
@@ -86,7 +97,7 @@ async function resolveDataplaneAndAuth(systemKey, opts = {}) {
86
97
  }
87
98
 
88
99
  if (!silent) {
89
- logger.log(chalk.gray('Resolving dataplane URL...'));
100
+ logger.log(metadata('Resolving dataplane URL...'));
90
101
  }
91
102
  const dataplaneUrl = await resolveDataplaneUrl(controllerUrl, environment, authConfig, { silent });
92
103
  return { dataplaneUrl, authConfig, environment };
@@ -168,7 +179,9 @@ async function pushAndLogCredentialSecrets(dataplaneUrl, authConfig, systemKey,
168
179
  });
169
180
  if (pushResult.pushed > 0) {
170
181
  const keyList = pushResult.keys?.length ? ` (${pushResult.keys.join(', ')})` : '';
171
- logger.log(chalk.green(`Pushed ${pushResult.pushed} credential secret(s) to dataplane${keyList}.`));
182
+ logger.log(
183
+ formatSuccessLine(`Pushed ${pushResult.pushed} credential secret(s) to dataplane${keyList}.`)
184
+ );
172
185
  } else {
173
186
  logger.log(chalk.yellow('Secret push skipped'));
174
187
  }
@@ -223,7 +236,10 @@ const UPLOAD_PROBE_TEST_DATA = {};
223
236
  * @param {number|undefined} probeTimeoutMs
224
237
  */
225
238
  async function maybeRunUploadProbe(dataplaneUrl, systemKey, authConfig, probeTimeoutMs) {
226
- logger.log(chalk.blue('\nRunning runtime checks (--probe)...'));
239
+ logger.log('');
240
+ logger.log(sectionTitle('Runtime checks (--probe)'));
241
+ logger.log(SEP);
242
+ logger.log(formatProgress('Running runtime checks...'));
227
243
  const timeoutMs = probeTimeoutMs === undefined || probeTimeoutMs === null ? 120000 : probeTimeoutMs;
228
244
  try {
229
245
  const pr = await testSystemViaPipeline(
@@ -246,10 +262,13 @@ async function maybeRunUploadProbe(dataplaneUrl, systemKey, authConfig, probeTim
246
262
 
247
263
  /**
248
264
  * Local validation, manifest, payload, and configuration resolution.
265
+ * Does not write *-deploy.json; run `aifabrix json <systemKey>` to regenerate the deployment manifest from sources.
266
+ *
249
267
  * @param {string} systemKey
268
+ * @param {{ dryRun?: boolean }} [_opts] - Reserved for callers (e.g. dry-run); manifest is always built from current disk files
250
269
  * @returns {Promise<{ manifest: Object, payload: Object }>}
251
270
  */
252
- async function buildValidatedUploadManifestPayload(systemKey) {
271
+ async function buildValidatedUploadManifestPayload(systemKey, _opts = {}) {
253
272
  const validationResult = await validateExternalSystemComplete(systemKey, { type: 'external' });
254
273
  throwIfValidationFailed(validationResult);
255
274
  logger.log(formatSuccessLine('Local validation passed'));
@@ -260,24 +279,52 @@ async function buildValidatedUploadManifestPayload(systemKey) {
260
279
  }
261
280
 
262
281
  /**
263
- * Upload path after dry-run check.
282
+ * Upload local `integration/<systemKey>/openapi/*.json` specs when present so pipeline can resolve
283
+ * each datasource `openapi.documentKey` (same behavior as repair --api OpenAPI sync).
284
+ *
264
285
  * @param {string} systemKey
265
- * @param {Object} options
266
286
  * @param {Object} manifest
267
- * @param {Object} payload
287
+ * @returns {Promise<void>}
268
288
  */
269
- async function runUploadPublishAndSummary(systemKey, options, manifest, payload) {
270
- const { dataplaneUrl, authConfig, environment } = await resolveDataplaneAndAuth(systemKey);
271
- requireBearerForDataplanePipeline(authConfig);
272
- logger.log(chalk.gray('Target:'));
273
- logger.log(chalk.gray(`Environment: ${environment}`));
274
- logger.log(chalk.gray(`Dataplane: ${dataplaneUrl}`));
275
- logDataplanePipelineWarning();
276
- if (options.verbose) {
277
- await maybeRunVerboseServerValidation(dataplaneUrl, authConfig, payload);
289
+ async function logAndSyncLocalOpenApiForUpload(systemKey, manifest) {
290
+ const appPath = getIntegrationPath(systemKey);
291
+ const ei = manifest && manifest.externalIntegration;
292
+ const datasourceFiles = ei && Array.isArray(ei.dataSources) ? ei.dataSources : [];
293
+ const openapiSyncLines = await maybeSyncOpenApiFilesForMcp({
294
+ enabled: true,
295
+ dryRun: false,
296
+ appPath,
297
+ systemKey,
298
+ datasourceFiles
299
+ });
300
+ for (const line of openapiSyncLines) {
301
+ logger.log(line.startsWith('Skipped') ? formatWarningLine(line) : formatSuccessLine(line));
278
302
  }
279
- await pushAndLogCredentialSecrets(dataplaneUrl, authConfig, systemKey, payload);
280
- const rawRes = await runUploadValidatePublish(dataplaneUrl, authConfig, payload);
303
+ }
304
+
305
+ /**
306
+ * @param {Object} ctx
307
+ * @param {string} ctx.systemKey
308
+ * @param {Object} ctx.options
309
+ * @param {Object} ctx.manifest
310
+ * @param {Object} ctx.payload
311
+ * @param {string} ctx.environment
312
+ * @param {string} ctx.dataplaneUrl
313
+ * @param {Object} ctx.authConfig
314
+ * @param {Object} ctx.rawRes
315
+ * @returns {Promise<void>}
316
+ */
317
+ async function handlePublicationAndFollowups(ctx) {
318
+ const {
319
+ systemKey,
320
+ options,
321
+ manifest,
322
+ payload,
323
+ environment,
324
+ dataplaneUrl,
325
+ authConfig,
326
+ rawRes
327
+ } = ctx;
281
328
  const publication = unwrapPublicationResult(rawRes);
282
329
  if (!publication) {
283
330
  throw new Error(
@@ -296,7 +343,6 @@ async function runUploadPublishAndSummary(systemKey, options, manifest, payload)
296
343
  if (options.probe) {
297
344
  await maybeRunUploadProbe(dataplaneUrl, systemKey, authConfig, options.probeTimeout);
298
345
  }
299
-
300
346
  const dsKeys = (payload.dataSources || []).map((ds) => ds && ds.key).filter(Boolean);
301
347
  await maybeSyncSystemCertificationFromDataplane({
302
348
  label: 'upload',
@@ -308,6 +354,41 @@ async function runUploadPublishAndSummary(systemKey, options, manifest, payload)
308
354
  });
309
355
  }
310
356
 
357
+ /**
358
+ * Upload path after dry-run check.
359
+ * @param {string} systemKey
360
+ * @param {Object} options
361
+ * @param {Object} manifest
362
+ * @param {Object} payload
363
+ */
364
+ async function runUploadPublishAndSummary(systemKey, options, manifest, payload) {
365
+ const { dataplaneUrl, authConfig, environment } = await resolveDataplaneAndAuth(systemKey);
366
+ requireBearerForDataplanePipeline(authConfig);
367
+ logger.log('');
368
+ logger.log(sectionTitle('Target'));
369
+ logger.log(SEP);
370
+ logger.log(headerKeyValue('Environment:', environment));
371
+ logger.log(headerKeyValue('Dataplane:', dataplaneUrl));
372
+ logDataplanePipelineWarning();
373
+ if (options.verbose) {
374
+ await maybeRunVerboseServerValidation(dataplaneUrl, authConfig, payload);
375
+ }
376
+ await pushAndLogCredentialSecrets(dataplaneUrl, authConfig, systemKey, payload);
377
+ await logAndSyncLocalOpenApiForUpload(systemKey, manifest);
378
+
379
+ const rawRes = await runUploadValidatePublish(dataplaneUrl, authConfig, payload);
380
+ await handlePublicationAndFollowups({
381
+ systemKey,
382
+ options,
383
+ manifest,
384
+ payload,
385
+ environment,
386
+ dataplaneUrl,
387
+ authConfig,
388
+ rawRes
389
+ });
390
+ }
391
+
311
392
  /**
312
393
  * Uploads external system: publishes to dataplane and registers with controller (draft).
313
394
  * @param {string} systemKey - External system key (integration/<systemKey>/)
@@ -322,8 +403,13 @@ async function runUploadPublishAndSummary(systemKey, options, manifest, payload)
322
403
  */
323
404
  async function uploadExternalSystem(systemKey, options = {}) {
324
405
  validateSystemKeyFormat(systemKey);
325
- logger.log(chalk.blue(`\nUploading external system: ${chalk.bold(systemKey)}`));
326
- const { manifest, payload } = await buildValidatedUploadManifestPayload(systemKey);
406
+ logger.log('');
407
+ logger.log(sectionTitle('Upload external system'));
408
+ logger.log(SEP);
409
+ logger.log(headerKeyValue('System:', systemKey));
410
+ const { manifest, payload } = await buildValidatedUploadManifestPayload(systemKey, {
411
+ dryRun: !!options.dryRun
412
+ });
327
413
  if (options.dryRun) {
328
414
  logger.log(chalk.yellow('Dry run: would upload payload (no API calls).'));
329
415
  logger.log(
@@ -15,6 +15,7 @@ const { getIntegrationPath } = require('../utils/paths');
15
15
  const { parseOpenApi, testMcpConnection, credentialSelection } = require('../api/wizard.api');
16
16
  const { listCredentials } = require('../api/credentials.api');
17
17
  const { listExternalSystems, getExternalSystem } = require('../api/external-systems.api');
18
+ const { formatSuccessLine } = require('../utils/cli-layout-chalk');
18
19
 
19
20
  /**
20
21
  * Parse OpenAPI file or URL
@@ -35,7 +36,7 @@ async function parseOpenApiSource(dataplaneUrl, authConfig, sourceType, sourceDa
35
36
  if (!parseResponse.success) {
36
37
  throw new Error(`OpenAPI parsing failed: ${parseResponse.error || parseResponse.formattedError}`);
37
38
  }
38
- logger.log(chalk.green(`\u2713 OpenAPI ${isUrl ? 'URL' : 'file'} parsed successfully`));
39
+ logger.log(formatSuccessLine(`OpenAPI ${isUrl ? 'URL' : 'file'} parsed successfully`));
39
40
  return parseResponse.data?.spec;
40
41
  } catch (error) {
41
42
  spinner.stop();
@@ -61,7 +62,7 @@ async function testMcpServerConnection(dataplaneUrl, authConfig, sourceData) {
61
62
  if (!testResponse.success || !testResponse.data?.connected) {
62
63
  throw new Error(`MCP connection failed: ${testResponse.data?.error || 'Unable to connect'}`);
63
64
  }
64
- logger.log(chalk.green('\u2713 MCP server connection successful'));
65
+ logger.log(formatSuccessLine('MCP server connection successful'));
65
66
  } catch (error) {
66
67
  spinner.stop();
67
68
  throw error;
@@ -145,7 +146,7 @@ async function runCredentialSelectionLoop(dataplaneUrl, authConfig, selectionDat
145
146
  }
146
147
  if (response.success) {
147
148
  const actionText = selectionData.action === 'create' ? 'created' : 'selected';
148
- logger.log(chalk.green(`\u2713 Credential ${actionText}`));
149
+ logger.log(formatSuccessLine(`Credential ${actionText}`));
149
150
  return response.data?.credentialIdOrKey || null;
150
151
  }
151
152
  const errorMsg = response.error || response.formattedError || response.message || 'Unknown error';
@@ -308,18 +309,19 @@ function throwConfigGenerationError(generateResponse, options = {}) {
308
309
  }
309
310
 
310
311
  /**
311
- * Write debug log to integration/<systemKey>/debug.log
312
+ * Write debug log to integration/<systemKey>/logs/debug.log
312
313
  * @async
313
314
  * @param {string} appName - Application name
314
315
  * @param {string} content - Debug log content
315
316
  */
316
317
  async function writeDebugLog(appName, content) {
317
318
  try {
318
- const dir = getIntegrationPath(appName);
319
+ const appDir = getIntegrationPath(appName);
320
+ const dir = path.join(appDir, 'logs');
319
321
  await fs.mkdir(dir, { recursive: true });
320
322
  const debugPath = path.join(dir, 'debug.log');
321
323
  await fs.writeFile(debugPath, content, 'utf8');
322
- logger.log(chalk.gray(` Debug log saved to integration/${appName}/debug.log`));
324
+ logger.log(chalk.gray(` Debug log saved to integration/${appName}/logs/debug.log`));
323
325
  } catch (e) {
324
326
  logger.warn(`Could not save debug.log: ${e.message}`);
325
327
  }
@@ -336,13 +338,14 @@ async function writeDebugLog(appName, content) {
336
338
  async function writeDebugManifest(appName, systemConfig, datasourceConfig) {
337
339
  const saved = [];
338
340
  try {
339
- const dir = getIntegrationPath(appName);
341
+ const appDir = getIntegrationPath(appName);
342
+ const dir = path.join(appDir, 'logs');
340
343
  await fs.mkdir(dir, { recursive: true });
341
344
  if (systemConfig && typeof systemConfig === 'object') {
342
345
  const systemPath = path.join(dir, 'debug-system.yaml');
343
346
  await fs.writeFile(systemPath, yaml.dump(systemConfig, { lineWidth: -1 }), 'utf8');
344
347
  saved.push('debug-system.yaml');
345
- logger.log(chalk.gray(` Debug manifest saved to integration/${appName}/debug-system.yaml`));
348
+ logger.log(chalk.gray(` Debug manifest saved to integration/${appName}/logs/debug-system.yaml`));
346
349
  }
347
350
  if (datasourceConfig !== undefined && datasourceConfig !== null) {
348
351
  const configs = Array.isArray(datasourceConfig) ? datasourceConfig : [datasourceConfig];
@@ -351,7 +354,7 @@ async function writeDebugManifest(appName, systemConfig, datasourceConfig) {
351
354
  const toWrite = configs.length === 1 ? configs[0] : configs;
352
355
  await fs.writeFile(datasourcePath, yaml.dump(toWrite, { lineWidth: -1 }), 'utf8');
353
356
  saved.push('debug-datasource.yaml');
354
- logger.log(chalk.gray(` Debug manifest saved to integration/${appName}/debug-datasource.yaml`));
357
+ logger.log(chalk.gray(` Debug manifest saved to integration/${appName}/logs/debug-datasource.yaml`));
355
358
  }
356
359
  }
357
360
  } catch (e) {
@@ -381,7 +384,7 @@ async function saveDebugManifestOnErrorAndThrow(generateResponse, opts) {
381
384
  const savedManifest = await writeDebugManifest(appName, systemConfig, datasourceConfig);
382
385
  if (debugLog || savedManifest.length > 0) {
383
386
  const files = [debugLog && 'debug.log', ...savedManifest].filter(Boolean).join(', ');
384
- debugManifestHint = `Debug manifest saved to integration/${appName}/ (${files}). Review the log and fix the manifest manually, then run: aifabrix wizard ${appName}`;
387
+ debugManifestHint = `Debug manifest saved to integration/${appName}/logs/ (${files}). Review the log and fix the manifest manually, then run: aifabrix wizard ${appName}`;
385
388
  }
386
389
  }
387
390
  throwConfigGenerationError(generateResponse, { debugManifestHint });
@@ -398,7 +401,7 @@ async function throwValidationFailureWithDebug(validateResponse, systemConfig, c
398
401
  );
399
402
  if (!debugLog && savedManifest.length === 0) throw new Error(`Configuration validation failed: ${errorMsg}`);
400
403
  const files = [debugLog && 'debug.log', ...savedManifest].filter(Boolean).join(', ');
401
- throw new Error(`Configuration validation failed: ${errorMsg}\n\nDebug manifest saved to integration/${options.appName}/ (${files}). Review the log and fix the manifest manually, then run: aifabrix wizard ${options.appName}`);
404
+ throw new Error(`Configuration validation failed: ${errorMsg}\n\nDebug manifest saved to integration/${options.appName}/logs/ (${files}). Review the log and fix the manifest manually, then run: aifabrix wizard ${options.appName}`);
402
405
  }
403
406
 
404
407
  /**
@@ -13,6 +13,7 @@ const logger = require('../utils/logger');
13
13
  const { getDeploymentAuth, requireBearerForDataplanePipeline } = require('../utils/token-manager');
14
14
  const { resolveControllerUrl } = require('../utils/controller-url');
15
15
  const { normalizeWizardConfigs } = require('./wizard-config-normalizer');
16
+ const { formatSuccessLine, formatSuccessParagraph } = require('../utils/cli-layout-chalk');
16
17
  const {
17
18
  createWizardSession,
18
19
  updateWizardSession,
@@ -143,7 +144,7 @@ async function handleModeSelection(dataplaneUrl, authConfig, configMode = null,
143
144
  throw new Error(fullMsg);
144
145
  }
145
146
  const sessionId = extractSessionId(sessionResponse.data);
146
- logger.log(chalk.green(`\u2713 Session created: ${sessionId}`));
147
+ logger.log(formatSuccessLine(`Session created: ${sessionId}`));
147
148
  return { mode, sessionId };
148
149
  }
149
150
 
@@ -250,7 +251,7 @@ async function handleTypeDetection(dataplaneUrl, authConfig, openapiSpec) {
250
251
  if (detectResponse.success && detectResponse.data) {
251
252
  const detectedType = detectResponse.data;
252
253
  const recommendedType = detectedType.recommendedType || detectedType.apiType || 'unknown';
253
- logger.log(chalk.green(`\u2713 API type detected: ${recommendedType}`));
254
+ logger.log(formatSuccessLine(`API type detected: ${recommendedType}`));
254
255
  return detectedType;
255
256
  }
256
257
  } catch (error) {
@@ -329,7 +330,7 @@ async function handleConfigurationGeneration(dataplaneUrl, authConfig, options)
329
330
  await writeDebugLog(options.appName, debugLog);
330
331
  }
331
332
  }
332
- logger.log(chalk.green('\u2713 Configuration generated successfully'));
333
+ logger.log(formatSuccessLine('Configuration generated successfully'));
333
334
  return { systemConfig: normalized.systemConfig, datasourceConfigs: normalized.datasourceConfigs, systemKey: result.systemKey };
334
335
  } catch (error) {
335
336
  spinner.stop();
@@ -368,7 +369,7 @@ async function validateWizardConfiguration(dataplaneUrl, authConfig, systemConfi
368
369
  if (validateResponse.data?.warnings?.length > 0) warnings.push(...validateResponse.data.warnings);
369
370
  }
370
371
  spinner.stop();
371
- logger.log(chalk.green('\u2713 Configuration validated successfully'));
372
+ logger.log(formatSuccessLine('Configuration validated successfully'));
372
373
  if (warnings.length > 0) logger.log(chalk.yellow('\n\u26A0 Warnings:\n' + warnings.map(w => ` - ${w.message || w}`).join('\n')));
373
374
  } catch (error) {
374
375
  spinner.stop();
@@ -423,7 +424,7 @@ async function tryUpdateReadmeFromDeploymentDocs(appPath, appName, dataplaneUrl,
423
424
  * @param {string} format - Project format: yaml | json
424
425
  */
425
426
  function logWizardFileSaveFooter(appName, generatedFiles) {
426
- logger.log(chalk.green('\n\u2713 Wizard completed successfully!'));
427
+ logger.log(formatSuccessParagraph('Wizard completed successfully!'));
427
428
  logger.log(chalk.green(`\nFiles created in: ${generatedFiles.appPath}`));
428
429
  logger.log(chalk.blue('\nNext steps:'));
429
430
  logger.log(chalk.gray(` 1. Review the generated files in integration/${appName}/`));
@@ -6,7 +6,7 @@
6
6
 
7
7
  const chalk = require('chalk');
8
8
  const logger = require('../utils/logger');
9
- const { infoLine, formatSuccessLine } = require('../utils/cli-test-layout-chalk');
9
+ const { formatProgress, formatSuccessLine } = require('../utils/cli-test-layout-chalk');
10
10
  const { getDataplaneUrl } = require('../datasource/deploy');
11
11
  const { listEnvironmentApplications } = require('../api/environments.api');
12
12
 
@@ -102,7 +102,7 @@ async function tryFallbackDataplaneUrl(controllerUrl, environment, authConfig, s
102
102
  async function discoverDataplaneUrl(controllerUrl, environment, authConfig, opts = {}) {
103
103
  const silent = opts.silent === true;
104
104
  if (!silent) {
105
- logger.log(infoLine('🌐 Getting dataplane URL from controller...'));
105
+ logger.log(formatProgress('Getting dataplane URL from controller...'));
106
106
  }
107
107
  try {
108
108
  const dataplaneAppKey = await findDataplaneServiceAppKey(controllerUrl, environment, authConfig);
@@ -9,6 +9,7 @@ const logger = require('../utils/logger');
9
9
  const { discoverEntities } = require('../api/wizard.api');
10
10
  const { validateEntityNameForOpenApi } = require('../validation/wizard-datasource-validation');
11
11
  const { promptForEntitySelection } = require('../generator/wizard-prompts');
12
+ const { formatSuccessLine } = require('../utils/cli-layout-chalk');
12
13
 
13
14
  /**
14
15
  * If wizard.yaml entity name matches discover-entities list, use it; else warn.
@@ -22,7 +23,7 @@ function resolvePrefillEntityName(trimmed, entities) {
22
23
  logger.log(chalk.gray(
23
24
  `Using entity from wizard.yaml (${trimmed}). Skipping entity prompts.`
24
25
  ));
25
- logger.log(chalk.green(`\u2713 Selected entity: ${trimmed}`));
26
+ logger.log(formatSuccessLine(`Selected entity: ${trimmed}`));
26
27
  return trimmed;
27
28
  }
28
29
  logger.log(chalk.yellow(
@@ -42,7 +43,7 @@ async function promptForValidatedEntity(entities) {
42
43
  if (!validation.valid) {
43
44
  throw new Error(`Invalid entity '${entityName}'. Available: ${entities.map(e => e.name).join(', ')}`);
44
45
  }
45
- logger.log(chalk.green(`\u2713 Selected entity: ${entityName}`));
46
+ logger.log(formatSuccessLine(`Selected entity: ${entityName}`));
46
47
  return entityName;
47
48
  }
48
49
 
@@ -63,7 +64,7 @@ async function discoverAndSelectEntity(dataplaneUrl, authConfig, openapiSpec, pr
63
64
 
64
65
  if (entities.length === 1) {
65
66
  const only = entities[0].name;
66
- logger.log(chalk.green(`\u2713 Only one entity discovered; using: ${only}`));
67
+ logger.log(formatSuccessLine(`Only one entity discovered; using: ${only}`));
67
68
  return only;
68
69
  }
69
70
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  const chalk = require('chalk');
8
8
  const logger = require('../utils/logger');
9
+ const { formatSuccessLine } = require('../utils/cli-layout-chalk');
9
10
  const {
10
11
  validateWizardConfig: validateWizardConfigFile,
11
12
  displayValidationResults
@@ -141,7 +142,7 @@ async function handleWizardHeadless(options) {
141
142
  displayValidationResults(validationResult);
142
143
  throw new Error('Wizard configuration validation failed');
143
144
  }
144
- logger.log(chalk.green('\u2713 Configuration file validated'));
145
+ logger.log(formatSuccessLine('Configuration file validated'));
145
146
 
146
147
  const wizardConfig = validationResult.config;
147
148
  const appName = wizardConfig.appName;
@@ -50,6 +50,7 @@ const {
50
50
  ensureIntegrationDir
51
51
  } = require('./wizard-helpers');
52
52
  const { humanizeAppKey } = require('../generator/wizard-prompts-secondary');
53
+ const { formatSuccessLine } = require('../utils/cli-layout-chalk');
53
54
 
54
55
  /**
55
56
  * Map resolved source type/data onto wizard state.source.
@@ -455,7 +456,7 @@ async function executeWizardFlow(appKey, dataplaneUrl, authConfig, flowOpts = {}
455
456
  }
456
457
  logger.log(chalk.blue('\n\uD83D\uDCCB Step 1: Create Session'));
457
458
  const sessionId = await createSessionFromParams(dataplaneUrl, authConfig, mode, systemIdOrKey, appKey);
458
- logger.log(chalk.green('\u2713 Session created'));
459
+ logger.log(formatSuccessLine('Session created'));
459
460
 
460
461
  const platforms = mode === 'add-datasource' ? [] : await getWizardPlatforms(dataplaneUrl, authConfig);
461
462
  const state = await runWizardStepsAfterSession(appKey, dataplaneUrl, authConfig, sessionId, {
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Infra compose service names accepted by `aifabrix restart` and {@link restartService}.
3
+ *
4
+ * @fileoverview Single source of truth for CLI help + validation
5
+ * @author AI Fabrix Team
6
+ * @version 2.0.0
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ /** @type {ReadonlyArray<{ name: string, description: string }>} */
12
+ const RESTARTABLE_INFRA_SERVICES = Object.freeze([
13
+ { name: 'postgres', description: 'PostgreSQL database' },
14
+ { name: 'redis', description: 'Redis' },
15
+ { name: 'pgadmin', description: 'pgAdmin 4 web UI (only if enabled when you ran up-infra)' },
16
+ { name: 'redis-commander', description: 'Redis Commander web UI (only if enabled when you ran up-infra)' },
17
+ { name: 'traefik', description: 'Traefik reverse proxy (only if enabled when you ran up-infra)' }
18
+ ]);
19
+
20
+ /**
21
+ * @returns {string[]} service names in compose order
22
+ */
23
+ function getRestartableInfraServiceNames() {
24
+ return RESTARTABLE_INFRA_SERVICES.map((s) => s.name);
25
+ }
26
+
27
+ /**
28
+ * Aligned lines for Commander `addHelpText('after', …)`.
29
+ * @returns {string}
30
+ */
31
+ function buildRestartInfraHelpLines() {
32
+ const col = 22;
33
+ return RESTARTABLE_INFRA_SERVICES.map((s) => ` ${s.name.padEnd(col)}${s.description}`).join('\n');
34
+ }
35
+
36
+ module.exports = {
37
+ RESTARTABLE_INFRA_SERVICES,
38
+ getRestartableInfraServiceNames,
39
+ buildRestartInfraHelpLines
40
+ };
@@ -115,6 +115,19 @@ function detectSensitiveValue(key, value) {
115
115
  return false;
116
116
  }
117
117
 
118
+ /**
119
+ * Path segment after `kv://` for sensitive env vars; must match infra.parameter.yaml keys.
120
+ * API_KEY uses the shared miso-controller/dataplane catalog entry (not a flat `api-key` slug).
121
+ * @param {string} key - Environment variable name
122
+ * @returns {string}
123
+ */
124
+ function sensitiveKvPathSegmentFromEnvKey(key) {
125
+ if (key === 'API_KEY') {
126
+ return 'miso-controller-secrets-apiKeyVault';
127
+ }
128
+ return key.toLowerCase().replace(/[^a-z0-9]/g, '-');
129
+ }
130
+
118
131
  /**
119
132
  * Convert existing .env variables to env.template format
120
133
  * @param {Object} existingEnv - Existing environment variables
@@ -128,7 +141,7 @@ function convertToEnvTemplate(existingEnv, requiredVars) {
128
141
  Object.entries(existingEnv).forEach(([key, value]) => {
129
142
  if (detectSensitiveValue(key, value)) {
130
143
  // Convert sensitive values to kv:// references
131
- convertedEnv[key] = `kv://${key.toLowerCase().replace(/[^a-z0-9]/g, '-')}`;
144
+ convertedEnv[key] = `kv://${sensitiveKvPathSegmentFromEnvKey(key)}`;
132
145
  } else {
133
146
  // Keep non-sensitive values as-is
134
147
  convertedEnv[key] = value;
@@ -148,8 +161,8 @@ function generateSecretsFromEnv(envVars) {
148
161
 
149
162
  Object.entries(envVars).forEach(([key, value]) => {
150
163
  if (detectSensitiveValue(key, value)) {
151
- // Use centralized resolver for canonical secret names
152
- const secretName = getCanonicalSecretName(key);
164
+ const secretName =
165
+ key === 'API_KEY' ? sensitiveKvPathSegmentFromEnvKey(key) : getCanonicalSecretName(key);
153
166
  secrets[secretName] = value;
154
167
  }
155
168
  });
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Infrastructure admin-secrets.env generation (PG/Redis Commander defaults).
3
+ *
4
+ * @fileoverview Split from secrets.js for module size limits
5
+ * @author AI Fabrix Team
6
+ * @version 1.0.0
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const logger = require('../utils/logger');
14
+ const config = require('./config');
15
+ const {
16
+ mergeInfraParameterDefaultsForCli,
17
+ getInfraParameterCatalog,
18
+ readRelaxedCatalogDefaults
19
+ } = require('../parameters/infra-parameter-catalog');
20
+ const { createDefaultSecrets } = require('../utils/secrets-generator');
21
+ const pathsUtil = require('../utils/paths');
22
+ const { loadSecrets } = require('./secrets-load');
23
+
24
+ /**
25
+ * Writes admin env key-value pairs to content; encrypts values when encryption key is set.
26
+ * @async
27
+ * @param {Object.<string, string>} adminObj - Key-value object (e.g. POSTGRES_PASSWORD, ...)
28
+ * @returns {Promise<string>} .env-style content (plaintext or secure:// for secrets)
29
+ */
30
+ async function formatAdminSecretsContent(adminObj) {
31
+ const encryptionKey = await config.getSecretsEncryptionKey();
32
+ const { encryptSecret } = require('../utils/secrets-encryption');
33
+ const lines = ['# Infrastructure Admin Credentials'];
34
+ for (const [k, v] of Object.entries(adminObj)) {
35
+ const value = (v === null || v === undefined) ? '' : String(v).replace(/\n/g, ' ').trim();
36
+ const valueToWrite = encryptionKey ? encryptSecret(value, encryptionKey) : value;
37
+ lines.push(`${k}=${valueToWrite}`);
38
+ }
39
+ return lines.join('\n');
40
+ }
41
+
42
+ async function loadSecretsOrBootstrapForAdmin(secretsPath) {
43
+ try {
44
+ return await loadSecrets(secretsPath);
45
+ } catch (error) {
46
+ const defaultSecretsPath = secretsPath || path.join(pathsUtil.getAifabrixHome(), 'secrets.yaml');
47
+ if (!fs.existsSync(defaultSecretsPath)) {
48
+ logger.log('Creating default secrets file...');
49
+ await createDefaultSecrets(defaultSecretsPath);
50
+ return await loadSecrets(secretsPath);
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+
56
+ function getInfraDefaultsMergedForAdmin() {
57
+ try {
58
+ return mergeInfraParameterDefaultsForCli(getInfraParameterCatalog().data, {});
59
+ } catch {
60
+ return {};
61
+ }
62
+ }
63
+
64
+ function buildLocalAdminSecretsObject(secrets, infraDefaults) {
65
+ const raw = secrets['postgres-passwordKeyVault'];
66
+ const relaxed = readRelaxedCatalogDefaults();
67
+ const postgresPassword =
68
+ (raw && String(raw).trim()) ||
69
+ infraDefaults.adminPassword ||
70
+ relaxed.adminPassword ||
71
+ '';
72
+ const pgAdminEmail = infraDefaults.adminEmail || relaxed.adminEmail || '';
73
+ return {
74
+ POSTGRES_PASSWORD: postgresPassword,
75
+ PGADMIN_DEFAULT_EMAIL: pgAdminEmail,
76
+ PGADMIN_DEFAULT_PASSWORD: postgresPassword,
77
+ REDIS_HOST: 'local:redis:6379:0:',
78
+ REDIS_COMMANDER_USER: 'admin',
79
+ REDIS_COMMANDER_PASSWORD: postgresPassword
80
+ };
81
+ }
82
+
83
+ /** Generates admin secrets for infrastructure (beside config.yaml, typically ~/.aifabrix/admin-secrets.env). Defaults from infra.parameter.yaml `defaults`. */
84
+ async function generateAdminSecretsEnv(secretsPath) {
85
+ const secrets = await loadSecretsOrBootstrapForAdmin(secretsPath);
86
+ const infraDefaults = getInfraDefaultsMergedForAdmin();
87
+ const adminObj = buildLocalAdminSecretsObject(secrets, infraDefaults);
88
+ const aifabrixDir = pathsUtil.getAifabrixSystemDir();
89
+ const adminEnvPath = path.join(aifabrixDir, 'admin-secrets.env');
90
+ if (!fs.existsSync(aifabrixDir)) {
91
+ fs.mkdirSync(aifabrixDir, { recursive: true, mode: 0o700 });
92
+ }
93
+ const adminSecrets = await formatAdminSecretsContent(adminObj);
94
+ fs.writeFileSync(adminEnvPath, adminSecrets, { mode: 0o600 });
95
+ return adminEnvPath;
96
+ }
97
+
98
+ module.exports = {
99
+ formatAdminSecretsContent,
100
+ generateAdminSecretsEnv
101
+ };