@adobe/aio-commerce-lib-app 1.5.0 → 1.7.0

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 (67) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cjs/actions/app-config/index.cjs +202 -0
  3. package/dist/cjs/actions/{app-config.d.cts → app-config/index.d.cts} +11 -9
  4. package/dist/cjs/actions/{config.cjs → config/index.cjs} +79 -46
  5. package/dist/{es/actions/config.d.mts → cjs/actions/config/index.d.cts} +10 -8
  6. package/dist/cjs/actions/{installation.cjs → installation/index.cjs} +55 -36
  7. package/dist/{es/actions/installation.d.mts → cjs/actions/installation/index.d.cts} +11 -10
  8. package/dist/cjs/actions/{registration.cjs → registration/index.cjs} +16 -7
  9. package/dist/cjs/actions/{registration.d.cts → registration/index.d.cts} +8 -9
  10. package/dist/cjs/actions/{scope-tree.cjs → scope-tree/index.cjs} +52 -15
  11. package/dist/{es/actions/scope-tree.d.mts → cjs/actions/scope-tree/index.d.cts} +2 -5
  12. package/dist/cjs/{admin-ui-sdk-BiSopnKI.d.cts → admin-ui-sdk-EU915zlR.d.cts} +7 -8
  13. package/dist/cjs/app-DrYHK-z1.d.cts +1629 -0
  14. package/dist/cjs/commands/index.cjs +241 -56
  15. package/dist/cjs/commands/templates/app-management/app-config.js.template +2 -2
  16. package/dist/cjs/config/index.cjs +3 -3
  17. package/dist/cjs/config/index.d.cts +181 -1158
  18. package/dist/cjs/{config-ct-qMOGj.cjs → config-D-s0GSep.cjs} +4 -6
  19. package/dist/cjs/{error-C5LNOZ4f.cjs → error-D-N0PKSl.cjs} +0 -1
  20. package/dist/cjs/{index-B5WKJ3hJ.d.cts → index-B5gJ-q4U.d.cts} +172 -3
  21. package/dist/cjs/index-BXm8UbK7.d.cts +16 -0
  22. package/dist/cjs/{logging-BTevALnL.cjs → logging-BVz3weoC.cjs} +1 -1
  23. package/dist/cjs/management/index.cjs +1 -1
  24. package/dist/cjs/management/index.d.cts +2 -3
  25. package/dist/cjs/{management-D1QXg4YU.cjs → management-Dehz9qSJ.cjs} +114 -51
  26. package/dist/cjs/openapi-Cux6K4ZD.cjs +3072 -0
  27. package/dist/cjs/{router-CFErodHU.cjs → router-BOR7T6qR.cjs} +1 -1
  28. package/dist/cjs/{schemas-CukVpc19.cjs → schemas-FngDuIeo.cjs} +1 -1
  29. package/dist/cjs/{validate-b_bI4mDb.cjs → validate-oAOpyFyb.cjs} +49 -17
  30. package/dist/cjs/{webhooks-DS1BtgED.cjs → webhooks-tbZy9G3p.cjs} +4 -4
  31. package/dist/es/actions/{app-config.d.mts → app-config/index.d.mts} +11 -9
  32. package/dist/es/actions/app-config/index.mjs +199 -0
  33. package/dist/{cjs/actions/config.d.cts → es/actions/config/index.d.mts} +10 -8
  34. package/dist/es/actions/{config.mjs → config/index.mjs} +78 -45
  35. package/dist/{cjs/actions/installation.d.cts → es/actions/installation/index.d.mts} +11 -10
  36. package/dist/es/actions/{installation.mjs → installation/index.mjs} +54 -36
  37. package/dist/es/actions/{registration.d.mts → registration/index.d.mts} +8 -9
  38. package/dist/es/actions/{registration.mjs → registration/index.mjs} +16 -6
  39. package/dist/{cjs/actions/scope-tree.d.cts → es/actions/scope-tree/index.d.mts} +2 -5
  40. package/dist/es/actions/{scope-tree.mjs → scope-tree/index.mjs} +51 -14
  41. package/dist/es/{admin-ui-sdk-CCo2SWiL.d.mts → admin-ui-sdk-BwnD0xjK.d.mts} +6 -9
  42. package/dist/es/app-DrYHK-z1.d.mts +1629 -0
  43. package/dist/es/commands/index.mjs +223 -38
  44. package/dist/es/commands/templates/app-management/app-config.js.template +2 -2
  45. package/dist/es/config/index.d.mts +181 -1157
  46. package/dist/es/config/index.mjs +3 -3
  47. package/dist/es/{config-DGPFTk6w.mjs → config-3I4eLyyR.mjs} +4 -5
  48. package/dist/es/index-B0XqHwY5.d.mts +16 -0
  49. package/dist/es/{index-CCov0odd.d.mts → index-DLMbTtKS.d.mts} +172 -3
  50. package/dist/es/management/index.d.mts +2 -3
  51. package/dist/es/management/index.mjs +1 -1
  52. package/dist/es/{management-CCsOfniv.mjs → management-BUX-w2Ji.mjs} +113 -51
  53. package/dist/es/openapi-B6uP0SRn.mjs +3024 -0
  54. package/dist/es/{validate-Dn3lLTGj.mjs → validate-Dfajrp99.mjs} +37 -17
  55. package/dist/es/{webhooks-Dhrkkip7.mjs → webhooks-B5oq9ULL.mjs} +3 -3
  56. package/package.json +29 -17
  57. package/dist/cjs/actions/app-config.cjs +0 -41
  58. package/dist/cjs/app-C6kImBl7.d.cts +0 -564
  59. package/dist/cjs/step-CWYnKbga.d.cts +0 -187
  60. package/dist/es/actions/app-config.mjs +0 -39
  61. package/dist/es/app-DcY6dJiQ.d.mts +0 -564
  62. package/dist/es/step-0eI2x4C9.d.mts +0 -187
  63. /package/dist/cjs/{chunk-DS2yp5vX.cjs → chunk-Cozy-1ZF.cjs} +0 -0
  64. /package/dist/es/{error-DHlYzkbb.mjs → error-_RMwtrUA.mjs} +0 -0
  65. /package/dist/es/{logging-XIUXDK5T.mjs → logging-DbJHXSKh.mjs} +0 -0
  66. /package/dist/es/{router-BxaxEEu3.mjs → router-D58JJHHA.mjs} +0 -0
  67. /package/dist/es/{schemas-DOcnD16x.mjs → schemas-hRovglBF.mjs} +0 -0
@@ -13,24 +13,28 @@
13
13
  * governing permissions and limitations under the License.
14
14
  */
15
15
 
16
- const require_chunk = require('../chunk-DS2yp5vX.cjs');
17
- const require_webhooks = require('../webhooks-DS1BtgED.cjs');
18
- const require_validate = require('../validate-b_bI4mDb.cjs');
19
- const require_config = require('../config-ct-qMOGj.cjs');
20
- const require_error = require('../error-C5LNOZ4f.cjs');
21
- const require_logging = require('../logging-BTevALnL.cjs');
16
+ const require_chunk = require('../chunk-Cozy-1ZF.cjs');
17
+ const require_error = require('../error-D-N0PKSl.cjs');
18
+ const require_config = require('../config-D-s0GSep.cjs');
19
+ const require_webhooks = require('../webhooks-tbZy9G3p.cjs');
20
+ const require_validate = require('../validate-oAOpyFyb.cjs');
21
+ const require_logging = require('../logging-BVz3weoC.cjs');
22
22
  let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
23
- let path = require("path");
24
- path = require_chunk.__toESM(path, 1);
25
- let fs = require("fs");
26
- let fs_promises = require("fs/promises");
27
23
  let consola = require("consola");
28
24
  consola = require_chunk.__toESM(consola, 1);
25
+ let path = require("path");
26
+ path = require_chunk.__toESM(path, 1);
27
+ let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
29
28
  let prettier = require("prettier");
30
29
  prettier = require_chunk.__toESM(prettier, 1);
30
+ let fs = require("fs");
31
+ let fs_promises = require("fs/promises");
31
32
  let url = require("url");
32
33
  let yaml = require("yaml");
34
+ let _npmcli_package_json = require("@npmcli/package-json");
35
+ _npmcli_package_json = require_chunk.__toESM(_npmcli_package_json, 1);
33
36
  let consola_utils = require("consola/utils");
37
+ let esbuild = require("esbuild");
34
38
  let safe_stable_stringify = require("safe-stable-stringify");
35
39
  safe_stable_stringify = require_chunk.__toESM(safe_stable_stringify, 1);
36
40
  let child_process = require("child_process");
@@ -40,8 +44,6 @@ let _adobe_aio_lib_ims = require("@adobe/aio-lib-ims");
40
44
  _adobe_aio_lib_ims = require_chunk.__toESM(_adobe_aio_lib_ims, 1);
41
45
  let dotenv = require("dotenv");
42
46
  dotenv = require_chunk.__toESM(dotenv, 1);
43
- let _npmcli_package_json = require("@npmcli/package-json");
44
- _npmcli_package_json = require_chunk.__toESM(_npmcli_package_json, 1);
45
47
 
46
48
  //#region source/commands/constants.ts
47
49
  /** The name of the package containing all the generated runtime actions */
@@ -64,6 +66,10 @@ const ADMIN_UI_SDK_PACKAGE_NAME = "admin-ui-sdk";
64
66
  const ADMIN_UI_SDK_ACTIONS_PATH = `${GENERATED_PATH}/actions/registration`;
65
67
  /** The name of the configuration schema file */
66
68
  const APP_MANIFEST_FILE = "app.commerce.manifest.json";
69
+ /** The name of the generated runtime-safe app config module (dynamic schemas only). */
70
+ const RUNTIME_APP_CONFIG_FILE = "app.commerce.config.js";
71
+ /** Package import alias for the generated runtime-safe app config module. */
72
+ const APP_CONFIG_IMPORT_ALIAS = "#app.commerce.config";
67
73
  /** The name of the commerce app configuration file */
68
74
  const COMMERCE_APP_CONFIG_FILE = "app.commerce.config";
69
75
  /** The name of the configuration schema file */
@@ -103,6 +109,14 @@ async function loadAppManifest() {
103
109
  return appConfig;
104
110
  }
105
111
  /**
112
+ * Whether the app config contains anything that can't be JSON-serialized as-is
113
+ * and therefore requires generating a runtime-safe ESM config module.
114
+ */
115
+ function hasDynamicAppConfig(appConfig) {
116
+ const schema = appConfig.businessConfig?.schema;
117
+ return Array.isArray(schema) && (0, _adobe_aio_commerce_lib_config.hasDynamicSchema)(schema);
118
+ }
119
+ /**
106
120
  * Path to an extension point's `.generated` directory, relative to the project root.
107
121
  * @param extensionPointId - The extension point ID, e.g. "commerce/extensibility/1"
108
122
  */
@@ -145,6 +159,21 @@ function getAdminUiSdkActionsDir(extensionPointId) {
145
159
  function getAdminUiSdkRegistrationActionPath(extensionPointId) {
146
160
  return (0, path.join)(getAdminUiSdkActionsDir(extensionPointId), "index.js");
147
161
  }
162
+ /** Path to the generated app manifest JSON file, relative to the project root. */
163
+ function getManifestPath() {
164
+ return (0, path.join)(getGeneratedDir(EXTENSIBILITY_EXTENSION_POINT_ID), APP_MANIFEST_FILE);
165
+ }
166
+ /**
167
+ * Path to the generated runtime-safe app config ESM module, relative to the
168
+ * project root. Used when the business config schema contains dynamic options.
169
+ */
170
+ function getRuntimeAppConfigPath() {
171
+ return (0, path.join)(getGeneratedDir(EXTENSIBILITY_EXTENSION_POINT_ID), RUNTIME_APP_CONFIG_FILE);
172
+ }
173
+ /** Path to the generated configuration schema file, relative to the project root. */
174
+ function getSchemaPath() {
175
+ return (0, path.join)(getGeneratedDir(CONFIGURATION_EXTENSION_POINT_ID), CONFIG_SCHEMA_FILE_NAME);
176
+ }
148
177
 
149
178
  //#endregion
150
179
  //#region source/commands/generate/actions/config.ts
@@ -173,7 +202,7 @@ function createActionDefinition(actionName, config = {}, options = {}) {
173
202
  ...options,
174
203
  function: `${GENERATED_ACTIONS_PATH}/${actionName}.js`,
175
204
  web: options.web ?? "yes",
176
- runtime: "nodejs:22",
205
+ runtime: "nodejs:24",
177
206
  annotations: {
178
207
  "require-adobe-auth": true,
179
208
  final: true
@@ -200,8 +229,6 @@ function getRuntimeActions(extConfig, dir) {
200
229
  * @param features - The features that are enabled for the app.
201
230
  */
202
231
  function buildAppManagementExtConfig(appConfig) {
203
- const features = require_validate.getConfigDomains(appConfig);
204
- const hasPasswordFieldsInSchema = require_validate.hasBusinessConfigSchema(appConfig) && appConfig.businessConfig.schema.some((field) => field.type === "password");
205
232
  const extConfig = {
206
233
  hooks: { "pre-app-build": "EXTENSION=extensibility/1 $packageExec aio-commerce-lib-app hooks pre-app-build" },
207
234
  operations: { workerProcess: [{
@@ -213,13 +240,9 @@ function buildAppManagementExtConfig(appConfig) {
213
240
  actions: { "app-config": createActionDefinition("app-config") }
214
241
  } } }
215
242
  };
216
- if ([
217
- "installation.customInstallationSteps",
218
- "eventing.commerce",
219
- "eventing.external",
220
- "webhooks",
221
- "adminUiSdk"
222
- ].some((feature) => features.has(feature))) {
243
+ const needsInstallAction = require_validate.requiresInstallation(appConfig);
244
+ const hasPasswordFieldsInSchema = require_validate.hasBusinessConfigSchema(appConfig) && appConfig.businessConfig.schema.some((field) => field.type === "password");
245
+ if (needsInstallAction) {
223
246
  extConfig.operations.workerProcess.push({
224
247
  type: "action",
225
248
  impl: `${PACKAGE_NAME}/installation`
@@ -272,7 +295,7 @@ function buildAdminUiSdkExtConfig() {
272
295
  actions: { registration: {
273
296
  function: `${ADMIN_UI_SDK_ACTIONS_PATH}/index.js`,
274
297
  web: "yes",
275
- runtime: "nodejs:22",
298
+ runtime: "nodejs:24",
276
299
  annotations: {
277
300
  "require-adobe-auth": true,
278
301
  final: true
@@ -288,12 +311,12 @@ function buildAdminUiSdkExtConfig() {
288
311
  * Read a YAML file and return a {@link Document}
289
312
  * @param path - The path to the YAML file
290
313
  */
291
- async function readYamlFile(path$3) {
314
+ async function readYamlFile(path$5) {
292
315
  let doc = new yaml.Document();
293
- if ((0, fs.existsSync)(path$3)) try {
294
- doc = (0, yaml.parseDocument)(await (0, fs_promises.readFile)(path$3, "utf-8"), { keepSourceTokens: true });
316
+ if ((0, fs.existsSync)(path$5)) try {
317
+ doc = (0, yaml.parseDocument)(await (0, fs_promises.readFile)(path$5, "utf-8"), { keepSourceTokens: true });
295
318
  } catch {
296
- const file = (0, path.basename)(path$3);
319
+ const file = (0, path.basename)(path$5);
297
320
  throw new Error(`Failed to parse ${file}`);
298
321
  }
299
322
  if (doc.contents === null) doc.contents = new yaml.YAMLMap();
@@ -307,18 +330,18 @@ async function readYamlFile(path$3) {
307
330
  * @param typeConfig - Configuration for the node type
308
331
  * @returns The existing or newly created node
309
332
  */
310
- function getOrCreateNode(doc, path$4, options, typeConfig) {
311
- const node = doc.getIn(path$4);
333
+ function getOrCreateNode(doc, path$6, options, typeConfig) {
334
+ const node = doc.getIn(path$6);
312
335
  if (node) {
313
- if (!typeConfig.typeGuard(node)) throw new Error(`Expected ${typeConfig.typeName} at path "${path$4.join(".")}".`);
336
+ if (!typeConfig.typeGuard(node)) throw new Error(`Expected ${typeConfig.typeName} at path "${path$6.join(".")}".`);
314
337
  return node;
315
338
  }
316
- if (doc.hasIn(path$4)) doc.deleteIn(path$4);
317
- const pair = doc.createPair(path$4.at(-1), typeConfig.createNode());
339
+ if (doc.hasIn(path$6)) doc.deleteIn(path$6);
340
+ const pair = doc.createPair(path$6.at(-1), typeConfig.createNode());
318
341
  options.onBeforeCreate?.(pair);
319
- if (path$4.length === 1) doc.add(pair);
320
- else doc.addIn(path$4.slice(0, -1), pair);
321
- return doc.getIn(path$4);
342
+ if (path$6.length === 1) doc.add(pair);
343
+ else doc.addIn(path$6.slice(0, -1), pair);
344
+ return doc.getIn(path$6);
322
345
  }
323
346
  /**
324
347
  * Get or create a sequence at the given path
@@ -326,8 +349,8 @@ function getOrCreateNode(doc, path$4, options, typeConfig) {
326
349
  * @param path - The path to the sequence
327
350
  * @param options - The options for the sequence
328
351
  */
329
- function getOrCreateSeq(doc, path$5, options) {
330
- return getOrCreateNode(doc, path$5, options ?? {}, {
352
+ function getOrCreateSeq(doc, path$7, options) {
353
+ return getOrCreateNode(doc, path$7, options ?? {}, {
331
354
  typeGuard: yaml.isSeq,
332
355
  createNode: () => new yaml.YAMLSeq(),
333
356
  typeName: "sequence"
@@ -339,13 +362,40 @@ function getOrCreateSeq(doc, path$5, options) {
339
362
  * @param path - The path to the map
340
363
  * @param options - The options for the map
341
364
  */
342
- function getOrCreateMap(doc, path$6, options) {
343
- return getOrCreateNode(doc, path$6, options ?? {}, {
365
+ function getOrCreateMap(doc, path$8, options) {
366
+ return getOrCreateNode(doc, path$8, options ?? {}, {
344
367
  typeGuard: yaml.isMap,
345
368
  createNode: () => new yaml.YAMLMap(),
346
369
  typeName: "map"
347
370
  });
348
371
  }
372
+ /**
373
+ * Read the `inputs` map from an existing YAML action definition into a plain
374
+ * object. Used by codegen to merge developer-added inputs with the ones the
375
+ * generator manages, so regeneration does not strip user-added entries.
376
+ *
377
+ * @param existingAction - The YAML map representing the existing action.
378
+ */
379
+ function getExistingInputs(existingAction) {
380
+ const inputs = existingAction?.get("inputs");
381
+ if (!(0, yaml.isMap)(inputs)) return {};
382
+ return Object.fromEntries(inputs.items.map((item) => {
383
+ if (!(0, yaml.isPair)(item)) return [];
384
+ return [String(item.key), item.value];
385
+ }));
386
+ }
387
+ /**
388
+ * Read a string field from an existing YAML action definition. Used by codegen
389
+ * to preserve developer-set values (e.g. `runtime`) across regeneration
390
+ * instead of overwriting them.
391
+ *
392
+ * @param key - The field to read.
393
+ * @param existingAction - The YAML map representing the existing action.
394
+ */
395
+ function getExistingString(key, existingAction) {
396
+ const value = existingAction?.get(key);
397
+ return typeof value === "string" ? value : void 0;
398
+ }
349
399
 
350
400
  //#endregion
351
401
  //#region ../../packages-private/scripting-utils/source/yaml/codegen.ts
@@ -374,19 +424,30 @@ function buildWeb(extConfig, web) {
374
424
  if (!extConfig.hasIn(["web"])) extConfig.add(extConfig.createPair("web", web));
375
425
  }
376
426
  /**
377
- * Build the definition for a runtime action
378
- * @param name - The name of the action
379
- * @param path - The path where the action is located
380
- * @param action - The action definition
427
+ * Build the definition for a runtime action.
428
+ *
429
+ * Developer-added `inputs` keys (anything not in the generator-managed set) on
430
+ * `existingAction` are preserved so that hand-written entries for example
431
+ * factory credentials for `dynamicList` fields — survive regeneration.
432
+ *
433
+ * A `runtime` already set on `existingAction` is likewise preserved, so a
434
+ * developer can pin a different Node runtime (e.g. `nodejs:24`) in
435
+ * `ext.config.yaml` once without codegen reverting it on the next run.
436
+ *
437
+ * @param action - The action definition to build.
438
+ * @param existingAction - The action's previous YAML definition, if any.
381
439
  */
382
- function buildActionDefinition(action) {
440
+ function buildActionDefinition(action, existingAction) {
383
441
  const actionDef = new yaml.YAMLMap();
384
- const inputs = { LOG_LEVEL: "$LOG_LEVEL" };
442
+ const existingInputs = getExistingInputs(existingAction);
443
+ const existingRuntime = getExistingString("runtime", existingAction);
444
+ const managedInputs = { LOG_LEVEL: "$LOG_LEVEL" };
385
445
  actionDef.set("function", action.function);
386
446
  actionDef.set("web", action.web ?? "yes");
387
- actionDef.set("runtime", action.runtime ?? "nodejs:22");
447
+ actionDef.set("runtime", existingRuntime ?? action.runtime ?? "nodejs:24");
388
448
  actionDef.set("inputs", {
389
- ...inputs,
449
+ ...existingInputs,
450
+ ...managedInputs,
390
451
  ...action.inputs ?? {}
391
452
  });
392
453
  actionDef.set("annotations", { ...action.annotations ?? {
@@ -461,11 +522,13 @@ function buildRuntimeManifest(extConfig, manifest) {
461
522
  ], { onBeforeCreate: (pair) => {
462
523
  pair.key.commentBefore = " This package definition is auto-generated. Do not remove or manually edit.";
463
524
  } });
525
+ const existingActions = packageDef.get("actions");
464
526
  const actions = new yaml.YAMLMap();
465
527
  packageDef.set("license", pkg.license ?? "Apache-2.0");
466
528
  packageDef.set("actions", actions);
467
529
  for (const [actionName, action] of Object.entries(pkg.actions ?? {})) {
468
- const actionDef = buildActionDefinition(action);
530
+ const existingAction = (0, yaml.isMap)(existingActions) ? existingActions.get(actionName) : void 0;
531
+ const actionDef = buildActionDefinition(action, (0, yaml.isMap)(existingAction) ? existingAction : void 0);
469
532
  actions.set(actionName, actionDef);
470
533
  }
471
534
  }
@@ -508,6 +571,109 @@ async function writeExtConfig(configPath, doc) {
508
571
  const __dirname$1 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
509
572
  /** The path to the action templates directory, sibling to this file. */
510
573
  const TEMPLATES_DIR = (0, path.join)(__dirname$1, "templates");
574
+ const TYPESCRIPT_CONFIG_EXTENSIONS = new Set([
575
+ ".ts",
576
+ ".mts",
577
+ ".cts"
578
+ ]);
579
+ const LEADING_DOT_SLASH_PATTERN = /^\.\//u;
580
+ const DYNAMIC_APP_CONFIG_IMPORT = `import appConfig from "${APP_CONFIG_IMPORT_ALIAS}";`;
581
+ const STATIC_APP_MANIFEST_IMPORT = "import appConfig from \"../../app.commerce.manifest.json\" with { type: \"json\" };";
582
+ const STATIC_CONFIG_SCHEMA_IMPORT = "import configSchema from \"../../configuration-schema.json\" with { type: \"json\" };";
583
+ /** Normalize a path for use as an ESM import specifier. */
584
+ function normalizeImportPath(path$3) {
585
+ const normalizedPath = path$3.split(path.sep).join("/");
586
+ return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
587
+ }
588
+ /** Normalize a generated file path for package.json imports. */
589
+ function normalizePackageJsonPath(path$4) {
590
+ return normalizeImportPath(path$4).replace(LEADING_DOT_SLASH_PATTERN, "./");
591
+ }
592
+ /** Add or update the package import alias used by dynamic generated actions. */
593
+ async function updateAppConfigImportAlias(projectRoot, runtimeConfigPath) {
594
+ const pkg = await _npmcli_package_json.default.load(projectRoot);
595
+ const existingImports = typeof pkg.content.imports === "object" && pkg.content.imports !== null ? pkg.content.imports : {};
596
+ pkg.update({ imports: {
597
+ ...existingImports,
598
+ [APP_CONFIG_IMPORT_ALIAS]: normalizePackageJsonPath(runtimeConfigPath)
599
+ } });
600
+ await pkg.save();
601
+ }
602
+ /** Remove the package import alias used only by dynamic generated actions. */
603
+ async function deleteAppConfigImportAlias(projectRoot) {
604
+ const pkg = await _npmcli_package_json.default.load(projectRoot);
605
+ const existingImports = typeof pkg.content.imports === "object" && pkg.content.imports !== null ? pkg.content.imports : {};
606
+ if (!("#app.commerce.config" in existingImports)) return;
607
+ const imports = { ...existingImports };
608
+ delete imports[APP_CONFIG_IMPORT_ALIAS];
609
+ if (Object.keys(imports).length > 0) pkg.update({ imports });
610
+ else pkg.content.imports = void 0;
611
+ await pkg.save();
612
+ }
613
+ /** Write an ESM passthrough module for JavaScript app config files. */
614
+ async function writeJavaScriptAppConfigModule(configFilePath, outputPath) {
615
+ await (0, fs_promises.writeFile)(outputPath, [
616
+ "// This file has been auto-generated by `@adobe/aio-commerce-lib-app`",
617
+ "// Do not modify this file directly",
618
+ "",
619
+ `import appConfig from "${normalizeImportPath((0, path.relative)((0, path.dirname)(outputPath), configFilePath))}";`,
620
+ "",
621
+ "export default appConfig;",
622
+ ""
623
+ ].join("\n"), "utf-8");
624
+ }
625
+ /** Bundle a TypeScript app config file into runtime-safe ESM. */
626
+ async function bundleTypeScriptAppConfigModule(configFilePath, outputPath) {
627
+ await (0, esbuild.build)({
628
+ entryPoints: [configFilePath],
629
+ outfile: outputPath,
630
+ bundle: true,
631
+ format: "esm",
632
+ platform: "node",
633
+ target: "node22",
634
+ packages: "external",
635
+ logLevel: "silent"
636
+ });
637
+ }
638
+ /** Generate the runtime-safe app config module used by generated runtime actions. */
639
+ async function generateRuntimeAppConfigModule() {
640
+ const projectRoot = await require_config.getProjectRootDirectory();
641
+ const runtimeConfigPath = getRuntimeAppConfigPath();
642
+ await require_config.makeOutputDirFor((0, path.dirname)(runtimeConfigPath));
643
+ const outputPath = (0, path.join)(projectRoot, runtimeConfigPath);
644
+ const configFilePath = await require_config.resolveCommerceAppConfig(projectRoot);
645
+ if (!configFilePath) throw new Error("Dynamic list options require an app.commerce.config.* file so generated actions can import the option factories at runtime.");
646
+ consola.consola.info("Generating JS config module...");
647
+ if (TYPESCRIPT_CONFIG_EXTENSIONS.has((0, path.extname)(configFilePath))) await bundleTypeScriptAppConfigModule(configFilePath, outputPath);
648
+ else await writeJavaScriptAppConfigModule(configFilePath, outputPath);
649
+ await updateAppConfigImportAlias(projectRoot, runtimeConfigPath);
650
+ consola.consola.success(`Generated JS config module: ${(0, path.relative)(process.cwd(), outputPath)}`);
651
+ }
652
+ /** Remove the generated app config module when generated actions use static JSON. */
653
+ async function cleanupRuntimeAppConfigModule() {
654
+ const projectRoot = await require_config.getProjectRootDirectory();
655
+ await (0, fs_promises.rm)((0, path.join)(projectRoot, getRuntimeAppConfigPath()), { force: true });
656
+ await deleteAppConfigImportAlias(projectRoot);
657
+ }
658
+ /**
659
+ * Prepare runtime-side config artifacts consumed by generated actions: the
660
+ * bundled ESM module and its `#app.commerce.config` package import alias.
661
+ *
662
+ * Generates them for dynamic schemas, cleans them up for static ones.
663
+ */
664
+ async function prepareRuntimeAppConfigModule(appManifest) {
665
+ if (hasDynamicAppConfig(appManifest)) {
666
+ await generateRuntimeAppConfigModule();
667
+ return;
668
+ }
669
+ await cleanupRuntimeAppConfigModule();
670
+ }
671
+ /** Switch static JSON imports to the generated runtime config module for dynamic schemas. */
672
+ function applyRuntimeAppConfigImport(template, actionName) {
673
+ if (actionName === "app-config" || actionName === "installation") return template.replace(STATIC_APP_MANIFEST_IMPORT, DYNAMIC_APP_CONFIG_IMPORT);
674
+ if (actionName === "config") return template.replace(STATIC_CONFIG_SCHEMA_IMPORT, DYNAMIC_APP_CONFIG_IMPORT).replace("const args = { configSchema };", "const args = { configSchema: appConfig.businessConfig.schema };");
675
+ return template;
676
+ }
511
677
  /**
512
678
  * Read an extension point's ext.config.yaml file and return it as a JS object.
513
679
  * @param extensionPointId - The extension point ID to read the config for.
@@ -554,8 +720,10 @@ async function generateActionFiles(appManifest, actions, extensionPointId, templ
554
720
  await require_config.makeOutputDirFor(getActionsDir(extensionPointId));
555
721
  const projectRoot = await require_config.getProjectRootDirectory();
556
722
  const outputFiles = [];
723
+ const useDynamicImports = hasDynamicAppConfig(appManifest);
557
724
  for (const action of actions) {
558
725
  let template = await (0, fs_promises.readFile)((0, path.join)(templatesDir, action.templateFile), "utf-8");
726
+ if (useDynamicImports) template = applyRuntimeAppConfigImport(template, action.name);
559
727
  if (action.name === "installation") {
560
728
  const scriptsTemplate = await generateCustomScriptsTemplate(await (0, fs_promises.readFile)((0, path.join)(templatesDir, "app-management", "custom-scripts.js.template"), "utf-8"), appManifest);
561
729
  template = applyCustomScripts(template, scriptsTemplate);
@@ -623,6 +791,7 @@ async function generateRegistrationActionFile(appManifest, extensionPointId, tem
623
791
  * @param templatesDir - The directory to load templates from, for testing purposes. Defaults to the generated actions template root.
624
792
  */
625
793
  async function run$5(appManifest, templatesDir = TEMPLATES_DIR) {
794
+ await prepareRuntimeAppConfigModule(appManifest);
626
795
  await generateActionFiles(appManifest, getRuntimeActions(await updateExtConfig(appManifest, EXTENSIBILITY_EXTENSION_POINT_ID), "app-management"), EXTENSIBILITY_EXTENSION_POINT_ID, templatesDir);
627
796
  if (require_validate.hasBusinessConfigSchema(appManifest)) await generateActionFiles(appManifest, getRuntimeActions(await updateExtConfig(appManifest, CONFIGURATION_EXTENSION_POINT_ID), "business-configuration"), CONFIGURATION_EXTENSION_POINT_ID, templatesDir);
628
797
  if (require_webhooks.hasAdminUiSdk(appManifest)) {
@@ -644,10 +813,18 @@ async function exec$5() {
644
813
  //#endregion
645
814
  //#region source/commands/generate/manifest/main.ts
646
815
  async function run$4(appConfig) {
816
+ if (hasDynamicAppConfig(appConfig)) {
817
+ const stalePath = (0, path.join)(await require_config.getProjectRootDirectory(), getManifestPath());
818
+ if (await (0, fs_promises.access)(stalePath).then(() => true, () => false)) {
819
+ await (0, fs_promises.rm)(stalePath, { force: true });
820
+ consola.consola.success(`Removed stale ${APP_MANIFEST_FILE}`);
821
+ }
822
+ return;
823
+ }
647
824
  consola.consola.info("Generating app manifest...");
648
825
  const contents = (0, safe_stable_stringify.stringify)(appConfig, null, 2);
649
826
  await (0, fs_promises.writeFile)((0, path.join)(await require_config.makeOutputDirFor(getGeneratedDir(EXTENSIBILITY_EXTENSION_POINT_ID)), APP_MANIFEST_FILE), contents, "utf-8");
650
- consola.consola.success(`Generated ${APP_MANIFEST_FILE}`);
827
+ consola.consola.success(`Generated ${APP_MANIFEST_FILE}\n`);
651
828
  }
652
829
  /** Run the generate manifest command */
653
830
  async function exec$4() {
@@ -679,7 +856,6 @@ async function run$3(appConfig) {
679
856
  consola.consola.debug("Business configuration schema not found in application configuration. Nothing to do.");
680
857
  return;
681
858
  }
682
- consola.consola.info("Generating configuration schema...");
683
859
  const projectDir = await require_config.getProjectRootDirectory();
684
860
  const envPath = (0, path.join)(projectDir, ".env");
685
861
  await touch(envPath);
@@ -689,9 +865,19 @@ async function run$3(appConfig) {
689
865
  if ("AIO_COMMERCE_CONFIG_ENCRYPTION_KEY" in process.env && String(process.env.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY).trim().length > 0) (0, child_process.execSync)(`${packageExec} aio-commerce-lib-config encryption validate`);
690
866
  else (0, child_process.execSync)(`${packageExec} aio-commerce-lib-config encryption setup`);
691
867
  }
868
+ if (hasDynamicAppConfig(appConfig)) {
869
+ const stalePath = (0, path.join)(projectDir, getSchemaPath());
870
+ if (await (0, fs_promises.access)(stalePath).then(() => true, () => false)) {
871
+ await (0, fs_promises.rm)(stalePath, { force: true });
872
+ consola.consola.success(`Removed stale ${CONFIG_SCHEMA_FILE_NAME}`);
873
+ }
874
+ return;
875
+ }
876
+ consola.consola.info("Generating configuration schema...");
877
+ const outputDir = await require_config.makeOutputDirFor(getGeneratedDir(CONFIGURATION_EXTENSION_POINT_ID));
692
878
  const contents = (0, safe_stable_stringify.stringify)(appConfig.businessConfig.schema, null, 2);
693
- await (0, fs_promises.writeFile)((0, path.join)(await require_config.makeOutputDirFor(getGeneratedDir(CONFIGURATION_EXTENSION_POINT_ID)), CONFIG_SCHEMA_FILE_NAME), contents, "utf-8");
694
- consola.consola.success(`Generated ${CONFIG_SCHEMA_FILE_NAME}`);
879
+ await (0, fs_promises.writeFile)((0, path.join)(outputDir, CONFIG_SCHEMA_FILE_NAME), contents, "utf-8");
880
+ consola.consola.success(`Generated ${CONFIG_SCHEMA_FILE_NAME}\n`);
695
881
  }
696
882
  /** Run the generate schema command */
697
883
  async function exec$3() {
@@ -806,6 +992,7 @@ async function syncImsCredentials() {
806
992
  */
807
993
  async function run$1(extension, templatesDir = TEMPLATES_DIR) {
808
994
  const appManifest = await loadAppManifest();
995
+ await prepareRuntimeAppConfigModule(appManifest);
809
996
  if (extension === "extensibility/1") {
810
997
  const { doc: extensibilityExtConfig } = await readExtConfig(EXTENSIBILITY_EXTENSION_POINT_ID);
811
998
  await run$4(appManifest);
@@ -1215,7 +1402,7 @@ function runInstall(packageManager, dependencies, cwd = process.cwd()) {
1215
1402
  */
1216
1403
  function installDependencies(packageManager, domains, cwd = process.cwd()) {
1217
1404
  const packages = [];
1218
- if (domains.has("businessConfig.schema")) packages.push(`@adobe/aio-commerce-lib-config@^1.4.0`);
1405
+ if (domains.has("businessConfig.schema")) packages.push(`@adobe/aio-commerce-lib-config@^1.5.1`);
1219
1406
  if (packages.length === 0) {
1220
1407
  consola.consola.info("No additional domain dependencies to install.");
1221
1408
  return;
@@ -1242,7 +1429,7 @@ async function ensureInstallYaml(domains, cwd = process.cwd()) {
1242
1429
 
1243
1430
  //#endregion
1244
1431
  //#region source/commands/init/main.ts
1245
- const REQUIRED_DEPENDENCIES = ["@adobe/aio-commerce-sdk", `@adobe/aio-commerce-lib-app@1.5.0`];
1432
+ const REQUIRED_DEPENDENCIES = ["@adobe/aio-commerce-sdk", `@adobe/aio-commerce-lib-app@1.7.0`];
1246
1433
  /** Initialize the project */
1247
1434
  async function run(flags, extraOptions) {
1248
1435
  consola.consola.start("Initializing app...");
@@ -1307,9 +1494,7 @@ Examples:
1307
1494
  /** Run all generate targets in sequence */
1308
1495
  async function generateAll() {
1309
1496
  await exec$5();
1310
- consola.default.log.raw("");
1311
1497
  await exec$4();
1312
- consola.default.log.raw("");
1313
1498
  await exec$3();
1314
1499
  }
1315
1500
  /** Command handlers registry mapping command names to their subcommand handlers */
@@ -16,7 +16,7 @@
16
16
  import { appConfigRuntimeAction } from "@adobe/aio-commerce-lib-app/actions/app-config";
17
17
 
18
18
  // The manifest is always at this relative constant path from the action.
19
- import commerceAppManifest from "../../app.commerce.manifest.json" with { type: "json" };
19
+ import appConfig from "../../app.commerce.manifest.json" with { type: "json" };
20
20
 
21
- const args = { appConfig: commerceAppManifest };
21
+ const args = { appConfig };
22
22
  export const main = appConfigRuntimeAction(args);
@@ -13,9 +13,9 @@
13
13
  */
14
14
 
15
15
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
- const require_webhooks = require('../webhooks-DS1BtgED.cjs');
17
- const require_validate = require('../validate-b_bI4mDb.cjs');
18
- const require_config = require('../config-ct-qMOGj.cjs');
16
+ const require_config = require('../config-D-s0GSep.cjs');
17
+ const require_webhooks = require('../webhooks-tbZy9G3p.cjs');
18
+ const require_validate = require('../validate-oAOpyFyb.cjs');
19
19
 
20
20
  exports.CommerceAppConfigSchemas = require_validate.CommerceAppConfigSchemas;
21
21
  exports.defineConfig = require_config.defineConfig;