@adobe/aio-commerce-lib-app 1.6.0 → 1.8.0-beta-20260714082406

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 (110) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/dist/cjs/actions/app-config/index.cjs +205 -0
  3. package/dist/cjs/actions/{app-config.d.cts → app-config/index.d.cts} +10 -7
  4. package/dist/cjs/actions/association/index.cjs +85 -0
  5. package/dist/cjs/actions/association/index.d.cts +28 -0
  6. package/dist/cjs/actions/{config.cjs → config/index.cjs} +70 -53
  7. package/dist/{es/actions/config.d.mts → cjs/actions/config/index.d.cts} +10 -7
  8. package/dist/cjs/actions/{installation.cjs → installation/index.cjs} +106 -72
  9. package/dist/{es/actions/installation.d.mts → cjs/actions/installation/index.d.cts} +10 -8
  10. package/dist/cjs/actions/{scope-tree.cjs → scope-tree/index.cjs} +60 -22
  11. package/dist/cjs/actions/{scope-tree.d.cts → scope-tree/index.d.cts} +1 -1
  12. package/dist/cjs/app-D3P-Z6uY.d.cts +1679 -0
  13. package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
  14. package/dist/cjs/commands/index.cjs +517 -309
  15. package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
  16. package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
  17. package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
  18. package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  19. package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  20. package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  21. package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  22. package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
  23. package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
  24. package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
  25. package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
  26. package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
  27. package/dist/cjs/config/index.browser.cjs +18 -0
  28. package/dist/cjs/config/index.browser.d.cts +16 -0
  29. package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
  30. package/dist/cjs/config/index.node.d.cts +1603 -0
  31. package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
  32. package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
  33. package/dist/cjs/environment-B7EnozSg.cjs +135 -0
  34. package/dist/cjs/index-BXm8UbK7.d.cts +16 -0
  35. package/dist/cjs/{index-Dw2NvVOY.d.cts → index-CzReNwbF.d.cts} +177 -3
  36. package/dist/cjs/index.cjs +250 -0
  37. package/dist/cjs/index.d.cts +217 -0
  38. package/dist/cjs/{config-FNMclIFO.cjs → index.node-Dz4lV4qe.cjs} +119 -35
  39. package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
  40. package/dist/cjs/management/index.cjs +1 -1
  41. package/dist/cjs/management/index.d.cts +1 -2
  42. package/dist/cjs/{management-Cvsz4VMf.cjs → management-B9ItB80R.cjs} +432 -591
  43. package/dist/cjs/openapi-CwytYdWl.cjs +2948 -0
  44. package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
  45. package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
  46. package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
  47. package/dist/cjs/{validate-DydOAZha.cjs → validate-BfxhZ5Wv.cjs} +63 -31
  48. package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
  49. package/dist/es/actions/{app-config.d.mts → app-config/index.d.mts} +10 -7
  50. package/dist/es/actions/app-config/index.mjs +202 -0
  51. package/dist/es/actions/association/index.d.mts +28 -0
  52. package/dist/es/actions/association/index.mjs +82 -0
  53. package/dist/{cjs/actions/config.d.cts → es/actions/config/index.d.mts} +10 -7
  54. package/dist/es/actions/{config.mjs → config/index.mjs} +67 -50
  55. package/dist/{cjs/actions/installation.d.cts → es/actions/installation/index.d.mts} +10 -8
  56. package/dist/es/actions/{installation.mjs → installation/index.mjs} +104 -71
  57. package/dist/es/actions/{scope-tree.d.mts → scope-tree/index.d.mts} +1 -1
  58. package/dist/es/actions/{scope-tree.mjs → scope-tree/index.mjs} +58 -20
  59. package/dist/es/app-D3P-Z6uY.d.mts +1679 -0
  60. package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
  61. package/dist/es/commands/index.mjs +550 -340
  62. package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
  63. package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
  64. package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
  65. package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  66. package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  67. package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  68. package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  69. package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
  70. package/dist/es/commands/templates/app-management/association.js.template +6 -0
  71. package/dist/es/commands/templates/app-management/installation.js.template +1 -13
  72. package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
  73. package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
  74. package/dist/es/config/index.browser.d.mts +16 -0
  75. package/dist/es/config/index.browser.mjs +17 -0
  76. package/dist/es/config/index.node.d.mts +1604 -0
  77. package/dist/es/config/index.node.mjs +20 -0
  78. package/dist/es/define-EoYRZbpe.d.mts +34 -0
  79. package/dist/es/define-Z_Glf1-_.mjs +35 -0
  80. package/dist/es/environment-C84BPRJZ.mjs +104 -0
  81. package/dist/es/index-B0XqHwY5.d.mts +16 -0
  82. package/dist/es/{index-Bo0tQsVq.d.mts → index-D52xglhZ.d.mts} +177 -3
  83. package/dist/es/index.d.mts +217 -0
  84. package/dist/es/index.mjs +242 -0
  85. package/dist/es/{config-CcE0EBG7.mjs → index.node-CDH5gwJE.mjs} +94 -30
  86. package/dist/es/management/index.d.mts +1 -2
  87. package/dist/es/management/index.mjs +1 -1
  88. package/dist/es/{management-BZ4Y6lVp.mjs → management-B89ApQVY.mjs} +402 -562
  89. package/dist/es/openapi-CXonvevE.mjs +2900 -0
  90. package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
  91. package/dist/es/utils-_gj8L6eN.mjs +289 -0
  92. package/dist/es/{validate-Du3LhCre.mjs → validate-9cRZWGrA.mjs} +49 -29
  93. package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
  94. package/package.json +52 -22
  95. package/dist/cjs/actions/app-config.cjs +0 -54
  96. package/dist/cjs/actions/registration.cjs +0 -40
  97. package/dist/cjs/actions/registration.d.cts +0 -32
  98. package/dist/cjs/admin-ui-sdk-DZZJCrdT.d.cts +0 -665
  99. package/dist/cjs/app-CakwxQvs.d.cts +0 -673
  100. package/dist/cjs/config/index.d.cts +0 -1975
  101. package/dist/cjs/step-CKVE0aJi.d.cts +0 -187
  102. package/dist/es/actions/app-config.mjs +0 -53
  103. package/dist/es/actions/registration.d.mts +0 -32
  104. package/dist/es/actions/registration.mjs +0 -39
  105. package/dist/es/admin-ui-sdk-hu6iWr0A.d.mts +0 -667
  106. package/dist/es/app-CakwxQvs.d.mts +0 -673
  107. package/dist/es/config/index.d.mts +0 -1975
  108. package/dist/es/config/index.mjs +0 -19
  109. package/dist/es/step-D64mMPrt.d.mts +0 -187
  110. /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
@@ -12,17 +12,20 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { BusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
16
15
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
16
+ import { BusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
17
17
 
18
- //#region source/actions/config.d.ts
19
- /** The arguments for the config action factory. */
18
+ //#region source/actions/config/router.d.ts
19
+ /** The arguments required to create the runtime action for the config action. */
20
20
  type ConfigActionFactoryArgs = {
21
21
  configSchema: BusinessConfigSchema;
22
22
  };
23
- /** Factory to create the route handler for the `config` action. */
24
- declare const configRuntimeAction: ({
25
- configSchema
26
- }: ConfigActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
23
+ //#endregion
24
+ //#region source/actions/config/index.d.ts
25
+ /**
26
+ * Factory to create the route handler for the `config` action.
27
+ * @param args - The arguments required to create the runtime action.
28
+ */
29
+ declare const configRuntimeAction: (args: ConfigActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
27
30
  //#endregion
28
31
  export { configRuntimeAction };
@@ -13,18 +13,19 @@
13
13
  */
14
14
 
15
15
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
- const require_chunk = require('../chunk-Cozy-1ZF.cjs');
17
- const require_router = require('../router-BOR7T6qR.cjs');
18
- const require_schemas = require('../schemas-FngDuIeo.cjs');
19
- const require_validate = require('../validate-DydOAZha.cjs');
20
- const require_management = require('../management-Cvsz4VMf.cjs');
21
- let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
16
+ const require_rolldown_runtime = require('../../rolldown-runtime-Cozy-1ZF.cjs');
17
+ const require_schemas = require('../../schemas-mLxMh_ko.cjs');
18
+ const require_validate = require('../../validate-BfxhZ5Wv.cjs');
19
+ const require_management = require('../../management-B9ItB80R.cjs');
20
+ const require_router = require('../../router-hA_Y9gZ1.cjs');
21
+ let _adobe_aio_lib_state = require("@adobe/aio-lib-state");
22
22
  let valibot = require("valibot");
23
- valibot = require_chunk.__toESM(valibot, 1);
23
+ valibot = require_rolldown_runtime.__toESM(valibot, 1);
24
+ let _adobe_aio_commerce_lib_core_commerce = require("@adobe/aio-commerce-lib-core/commerce");
25
+ let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
24
26
  let _adobe_aio_lib_files = require("@adobe/aio-lib-files");
25
- let _adobe_aio_lib_state = require("@adobe/aio-lib-state");
26
27
  let openwhisk = require("openwhisk");
27
- openwhisk = require_chunk.__toESM(openwhisk, 1);
28
+ openwhisk = require_rolldown_runtime.__toESM(openwhisk, 1);
28
29
 
29
30
  //#region ../../packages-private/common-utils/source/storage/files-store.ts
30
31
  /** Default directory prefix. */
@@ -55,12 +56,15 @@ const DEFAULT_DIR_PREFIX = "store";
55
56
  */
56
57
  async function createFilesStore(options = {}) {
57
58
  const { dirPrefix = DEFAULT_DIR_PREFIX } = options;
58
- return new FilesStore(await (0, _adobe_aio_lib_files.init)(), dirPrefix);
59
+ const files = await (0, _adobe_aio_lib_files.init)();
60
+ return new FilesStore(files, dirPrefix);
59
61
  }
60
62
  /**
61
63
  * Key-value store implementation using @adobe/aio-lib-files.
62
64
  */
63
65
  var FilesStore = class {
66
+ files;
67
+ dirPrefix;
64
68
  constructor(files, dirPrefix) {
65
69
  this.files = files;
66
70
  this.dirPrefix = dirPrefix;
@@ -125,12 +129,16 @@ const DEFAULT_KEY_PREFIX = "store";
125
129
  */
126
130
  async function createStateStore(options = {}) {
127
131
  const { keyPrefix = DEFAULT_KEY_PREFIX, ttlSeconds = DEFAULT_TTL_SECONDS } = options;
128
- return new StateStore(await (0, _adobe_aio_lib_state.init)(), keyPrefix, ttlSeconds);
132
+ const state = await (0, _adobe_aio_lib_state.init)();
133
+ return new StateStore(state, keyPrefix, ttlSeconds);
129
134
  }
130
135
  /**
131
136
  * Key-value store implementation using @adobe/aio-lib-state.
132
137
  */
133
138
  var StateStore = class {
139
+ state;
140
+ keyPrefix;
141
+ ttlSeconds;
134
142
  constructor(state, keyPrefix, ttlSeconds) {
135
143
  this.state = state;
136
144
  this.keyPrefix = keyPrefix;
@@ -220,6 +228,9 @@ async function createCombinedStore(options = {}) {
220
228
  * Uses lib-state for cache and lib-files for persistence.
221
229
  */
222
230
  var CombinedStore = class {
231
+ cache;
232
+ persistent;
233
+ shouldPersist;
223
234
  constructor(cache, persistent, shouldPersist) {
224
235
  this.cache = cache;
225
236
  this.persistent = persistent;
@@ -240,7 +251,7 @@ var CombinedStore = class {
240
251
  if (!this.shouldPersist || this.shouldPersist(data)) await this.persistent.put(key, data);
241
252
  }
242
253
  async delete(key) {
243
- const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete?.(key) ?? Promise.resolve(false), this.persistent.delete?.(key) ?? Promise.resolve(false)]);
254
+ const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete(key), this.persistent.delete(key)]);
244
255
  return cacheDeleted || persistentDeleted;
245
256
  }
246
257
  };
@@ -260,16 +271,19 @@ const AppDataSchema = valibot.object({
260
271
  });
261
272
 
262
273
  //#endregion
263
- //#region source/actions/installation.ts
264
- const DEFAULT_ACTION_NAME = "app-management/installation";
265
- /** Request body schema shared by POST / and POST /validation. */
266
- const InstallationRequestBodySchema = (0, valibot.object)({
274
+ //#region source/actions/installation/schema.ts
275
+ /** Request body for POST / and POST /validation (shared shape) */
276
+ const InstallationRequestBodySchema = valibot.object({
267
277
  appData: AppDataSchema,
268
- commerceBaseUrl: (0, valibot.string)(),
269
- commerceEnv: (0, valibot.string)(),
270
- ioEventsUrl: (0, valibot.string)(),
271
- ioEventsEnv: (0, valibot.string)()
278
+ commerceBaseUrl: valibot.string(),
279
+ commerceEnv: _adobe_aio_commerce_lib_core_commerce.CommerceEnvSchema,
280
+ ioEventsEnv: valibot.string(),
281
+ ioEventsUrl: valibot.string()
272
282
  });
283
+
284
+ //#endregion
285
+ //#region source/actions/installation/router.ts
286
+ const DEFAULT_ACTION_NAME = "app-management/installation";
273
287
  /** Creates a workflow state store with the given prefix. */
274
288
  function createWorkflowStore(prefix) {
275
289
  return createCombinedStore({
@@ -299,11 +313,11 @@ function getStorageKey() {
299
313
  function buildWorkflowParams(body, rawParams) {
300
314
  return {
301
315
  ...rawParams,
302
- appData: body.appData,
303
- AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
304
- AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
305
316
  AIO_COMMERCE_API_BASE_URL: body.commerceBaseUrl,
306
- AIO_COMMERCE_API_FLAVOR: body.commerceEnv
317
+ AIO_COMMERCE_API_FLAVOR: body.commerceEnv,
318
+ AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
319
+ AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
320
+ appData: body.appData
307
321
  };
308
322
  }
309
323
  /**
@@ -313,9 +327,9 @@ function buildWorkflowParams(body, rawParams) {
313
327
  function buildInstallationContext(params, appConfig, logFn) {
314
328
  return {
315
329
  appData: params.appData,
316
- params,
330
+ customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {},
317
331
  logger: logFn,
318
- customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {}
332
+ params
319
333
  };
320
334
  }
321
335
  /**
@@ -340,26 +354,26 @@ function createInstallationHooks(store, logFn) {
340
354
  await store.put(getStorageKey(), data);
341
355
  };
342
356
  return {
343
- onInstallationStart: (state) => logAndSave("Installation started", state),
344
357
  onInstallationFailure: (state) => logAndSave("Installation failed", state),
358
+ onInstallationStart: (state) => logAndSave("Installation started", state),
345
359
  onInstallationSuccess: (state) => logAndSave(state.status === "succeeded" && state.metadata?.isRetry ? "Installation succeeded on retry" : "Installation succeeded", state),
360
+ onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state),
346
361
  onStepStart: (event, state) => logAndSave(`Step started: ${event.stepName}`, state),
347
- onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state),
348
- onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state)
362
+ onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state)
349
363
  };
350
364
  }
351
365
  /**
352
366
  * Installation action router.
353
367
  *
354
368
  * Routes:
355
- * - GET /installation - Get current installation status
356
- * - POST /installation - Start installation (creates plan, invokes execution async)
357
- * - POST /installation/execution - Execute installation (internal, called async)
358
- * - POST /installation/validation - Pre-installation validation
359
- * - POST /installation/uninstallation - Start uninstallation (async)
360
- * - GET /installation/uninstallation - Get current uninstallation status
361
- * - POST /installation/uninstallation/execution - Execute uninstallation (internal, called async)
362
- * - DELETE /installation/uninstallation - Clear uninstallation state only (no offboarding)
369
+ * - GET / Get current installation status
370
+ * - POST / Start installation (creates plan, invokes execution async)
371
+ * - POST /execution Execute installation (internal, called async)
372
+ * - POST /validation Pre-installation validation
373
+ * - POST /uninstallation Start uninstallation (creates plan, invokes execution async)
374
+ * - GET /uninstallation Get current uninstallation status
375
+ * - POST /uninstallation/execution Execute uninstallation (internal, called async)
376
+ * - DELETE /uninstallation Clear uninstallation state only (no offboarding)
363
377
  */
364
378
  const router = new require_router.HttpActionRouter().use(require_router.logger({ name: () => "installation" }));
365
379
  /**
@@ -401,7 +415,7 @@ router.post("/", {
401
415
  logger.debug("Previous installation failed, allowing retry");
402
416
  }
403
417
  const rawAppConfig = rawParams.appConfig;
404
- if (!rawAppConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
418
+ if (!rawAppConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("The app config is missing. Does the action receive it as a parameter?");
405
419
  const appConfig = require_validate.validateCommerceAppConfig(rawAppConfig);
406
420
  const initialState = require_management.createInitialInstallationState({ config: appConfig });
407
421
  logger.debug(`Created initial state: ${initialState.id}`);
@@ -409,27 +423,28 @@ router.post("/", {
409
423
  const ow = (0, openwhisk.default)();
410
424
  const mergedParams = buildWorkflowParams(req.body, rawParams);
411
425
  const activation = await ow.actions.invoke({
412
- name: DEFAULT_ACTION_NAME,
413
426
  blocking: false,
414
- result: false,
427
+ name: DEFAULT_ACTION_NAME,
415
428
  params: {
416
429
  ...mergedParams,
417
- initialState,
418
- appConfig,
430
+ __ow_method: "post",
419
431
  __ow_path: "/execution",
420
- __ow_method: "post"
421
- }
432
+ appConfig,
433
+ initialState
434
+ },
435
+ result: false
422
436
  });
423
437
  logger.debug(`Async execution started: ${activation.activationId}`);
424
438
  return (0, _adobe_aio_commerce_lib_core_responses.accepted)({ body: {
425
- message: "Installation started",
426
439
  activationId: activation.activationId,
440
+ message: "Installation started",
427
441
  ...initialState
428
442
  } });
429
443
  }
430
444
  });
431
445
  /**
432
- * POST /installation/execution - Execute installation (internal)
446
+ * POST /installation/execution - Execute installation
447
+ * @internal - Do not add to OpenAPI Spec.
433
448
  *
434
449
  * This endpoint is called asynchronously by POST /installation.
435
450
  * It runs the actual installation workflow and saves state.
@@ -445,16 +460,16 @@ router.post("/execution", { handler: async (_req, { logger, rawParams }) => {
445
460
  const installationContext = buildInstallationContext(params, appConfig, logger);
446
461
  logger.debug(`Executing installation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
447
462
  const result = await require_management.runInstallation({
448
- installationContext,
449
463
  config: appConfig,
464
+ hooks,
450
465
  initialState,
451
- hooks
466
+ installationContext
452
467
  });
453
468
  await store.put(getStorageKey(), result);
454
469
  logger.debug(`Installation completed: ${result.status}`);
455
470
  if (require_management.isFailedState(result)) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
456
- message: "Installation failed",
457
471
  error: result.error,
472
+ message: "Installation failed",
458
473
  state: result
459
474
  } });
460
475
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: result });
@@ -476,16 +491,16 @@ router.post("/validation", {
476
491
  handler: async (req, { logger, rawParams }) => {
477
492
  logger.debug("Running pre-installation validation...");
478
493
  const rawAppConfig = rawParams.appConfig;
479
- if (!rawAppConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
494
+ if (!rawAppConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("The app config is missing. Does the action receive it as a parameter?");
480
495
  const appConfig = require_validate.validateCommerceAppConfig(rawAppConfig);
481
496
  const { appData, ...params } = buildWorkflowParams(req.body, rawParams);
482
497
  const result = await require_management.runValidation({
498
+ config: appConfig,
483
499
  validationContext: {
484
500
  appData,
485
- params,
486
- logger
487
- },
488
- config: appConfig
501
+ logger,
502
+ params
503
+ }
489
504
  });
490
505
  logger.debug(`Validation complete — valid: ${result.valid}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}`);
491
506
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: result });
@@ -515,41 +530,43 @@ router.post("/uninstallation", {
515
530
  handler: async (req, { logger, rawParams }) => {
516
531
  const { appData, commerceBaseUrl } = req.body;
517
532
  logger.debug(`Starting uninstallation for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${commerceBaseUrl}")`);
518
- const rawAppConfig = rawParams.appConfig;
519
- if (!rawAppConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
520
- const appConfig = require_validate.validateCommerceAppConfig(rawAppConfig);
521
533
  const store = await createUninstallationStore();
522
534
  const existingState = await store.get(getStorageKey());
523
535
  if (existingState && require_management.isInProgressState(existingState)) {
524
536
  logger.debug(`Uninstallation already in progress: ${existingState.status}`);
525
537
  return (0, _adobe_aio_commerce_lib_core_responses.conflict)("Uninstallation is already in progress. Wait for it to complete.");
526
538
  }
527
- const initialState = require_management.createInitialUninstallationState({ config: appConfig });
539
+ const installAppConfig = (await getInstallationSnapshot())?.config;
540
+ const uninstallConfig = installAppConfig ?? rawParams.appConfig;
541
+ if (!uninstallConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Cannot determine what to uninstall: no recorded installation snapshot and no app config was provided.");
542
+ logger.debug(installAppConfig ? "Sourcing uninstallation from recorded install snapshot" : "No recorded install config found; falling back to request config");
543
+ const initialState = require_management.createInitialUninstallationState({ config: require_validate.validateCommerceAppConfig(uninstallConfig) });
528
544
  logger.debug(`Created initial uninstall state: ${initialState.id}`);
529
545
  await store.put(getStorageKey(), initialState);
530
546
  const workflowParams = buildWorkflowParams(req.body, rawParams);
531
547
  const activation = await (0, openwhisk.default)().actions.invoke({
532
- name: DEFAULT_ACTION_NAME,
533
548
  blocking: false,
534
- result: false,
549
+ name: DEFAULT_ACTION_NAME,
535
550
  params: {
536
551
  ...workflowParams,
537
- initialState,
538
- appConfig,
552
+ __ow_method: "post",
539
553
  __ow_path: "/uninstallation/execution",
540
- __ow_method: "post"
541
- }
554
+ appConfig: uninstallConfig,
555
+ initialState
556
+ },
557
+ result: false
542
558
  });
543
559
  logger.debug(`Async uninstallation started: ${activation.activationId}`);
544
560
  return (0, _adobe_aio_commerce_lib_core_responses.accepted)({ body: {
545
- message: "Uninstallation started",
546
561
  activationId: activation.activationId,
562
+ message: "Uninstallation started",
547
563
  ...initialState
548
564
  } });
549
565
  }
550
566
  });
551
567
  /**
552
- * POST /uninstallation/execution - Execute uninstallation (internal, called async by POST /uninstallation)
568
+ * POST /uninstallation/execution - Execute uninstallation
569
+ * @internal - Do not add to OpenAPI Spec.
553
570
  *
554
571
  * Flow:
555
572
  * 1. Build InstallationContext from params
@@ -569,10 +586,10 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
569
586
  const installationContext = buildInstallationContext(params, appConfig, logger);
570
587
  logger.debug(`Executing uninstallation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
571
588
  const result = await require_management.runUninstallation({
572
- installationContext,
573
589
  config: appConfig,
590
+ hooks,
574
591
  initialState,
575
- hooks
592
+ installationContext
576
593
  });
577
594
  await store.put(getStorageKey(), result);
578
595
  logger.debug(`Uninstallation completed: ${result.status}`);
@@ -581,8 +598,8 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
581
598
  logger.debug("Cleared installation state after successful uninstallation");
582
599
  }
583
600
  if (require_management.isFailedState(result)) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
584
- message: "Uninstallation failed",
585
601
  error: result.error,
602
+ message: "Uninstallation failed",
586
603
  state: result
587
604
  } });
588
605
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: result });
@@ -598,9 +615,26 @@ router.delete("/uninstallation", { handler: async (_req, { logger }) => {
598
615
  logger.debug("Uninstallation state cleared");
599
616
  return (0, _adobe_aio_commerce_lib_core_responses.noContent)();
600
617
  } });
601
- /** Factory to create the route handler for the `installation` action. */
602
- const installationRuntimeAction = ({ appConfig, customScriptsLoader }) => async (params) => {
603
- return await router.handler()({
618
+ /**
619
+ * Returns the completed installation snapshot that recorded its config, or null
620
+ * when none is authoritative (no install, an in-progress install, or a legacy
621
+ * record persisted before the config was recorded).
622
+ */
623
+ async function getInstallationSnapshot() {
624
+ const installSnapshot = await (await createInstallationStore()).get(getStorageKey());
625
+ return installSnapshot && require_management.isCompletedState(installSnapshot) && installSnapshot.config ? installSnapshot : null;
626
+ }
627
+
628
+ //#endregion
629
+ //#region source/actions/installation/index.ts
630
+ /**
631
+ * Factory to create the route handler for the `installation` action.
632
+ * @param args - The arguments required to create the runtime action.
633
+ */
634
+ const installationRuntimeAction = (args) => async (params) => {
635
+ const handler = router.handler();
636
+ const { appConfig, customScriptsLoader } = args;
637
+ return await handler({
604
638
  ...params,
605
639
  appConfig,
606
640
  customScriptsLoader
@@ -12,21 +12,23 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as CommerceAppConfigOutputModel, t as CommerceAppConfig } from "../app-CakwxQvs.mjs";
16
- import { o as InstallationContext } from "../step-D64mMPrt.mjs";
15
+ import { n as CommerceAppConfig, r as CommerceAppConfigOutputModel } from "../../app-D3P-Z6uY.cjs";
16
+ import { Y as InstallationContext } from "../../index-CzReNwbF.cjs";
17
17
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
18
18
 
19
- //#region source/actions/installation.d.ts
19
+ //#region source/actions/installation/router.d.ts
20
20
  type CustomScriptsLoader = (config: CommerceAppConfigOutputModel, logger: InstallationContext["logger"]) => Record<string, unknown>;
21
21
  /** Arguments for the runtime action factory. */
22
22
  type RuntimeActionFactoryArgs = {
23
23
  appConfig: CommerceAppConfig;
24
24
  customScriptsLoader?: CustomScriptsLoader;
25
25
  };
26
- /** Factory to create the route handler for the `installation` action. */
27
- declare const installationRuntimeAction: ({
28
- appConfig,
29
- customScriptsLoader
30
- }: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
26
+ //#endregion
27
+ //#region source/actions/installation/index.d.ts
28
+ /**
29
+ * Factory to create the route handler for the `installation` action.
30
+ * @param args - The arguments required to create the runtime action.
31
+ */
32
+ declare const installationRuntimeAction: (args: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
31
33
  //#endregion
32
34
  export { installationRuntimeAction };
@@ -13,38 +13,76 @@
13
13
  */
14
14
 
15
15
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
- const require_chunk = require('../chunk-Cozy-1ZF.cjs');
17
- const require_router = require('../router-BOR7T6qR.cjs');
18
- const require_schemas = require('../schemas-FngDuIeo.cjs');
19
- const require_logging = require('../logging-BVz3weoC.cjs');
16
+ const require_rolldown_runtime = require('../../rolldown-runtime-Cozy-1ZF.cjs');
17
+ const require_schemas = require('../../schemas-mLxMh_ko.cjs');
18
+ const require_logging = require('../../logging-udPuAJPt.cjs');
19
+ const require_router = require('../../router-hA_Y9gZ1.cjs');
20
+ let _adobe_aio_commerce_lib_api = require("@adobe/aio-commerce-lib-api");
20
21
  let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
21
- let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
22
22
  let valibot = require("valibot");
23
- valibot = require_chunk.__toESM(valibot, 1);
24
- let _adobe_aio_commerce_lib_api = require("@adobe/aio-commerce-lib-api");
23
+ valibot = require_rolldown_runtime.__toESM(valibot, 1);
24
+ let _adobe_aio_commerce_lib_core_commerce = require("@adobe/aio-commerce-lib-core/commerce");
25
+ let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
26
+
27
+ //#region source/actions/scope-tree/schema.ts
28
+ const CustomScopeInputSchema = valibot.object({
29
+ children: valibot.optional(valibot.array(valibot.lazy(() => CustomScopeInputSchema))),
30
+ code: valibot.string(),
31
+ id: valibot.optional(valibot.string()),
32
+ is_editable: valibot.boolean(),
33
+ is_final: valibot.boolean(),
34
+ label: valibot.string(),
35
+ level: valibot.optional(valibot.string())
36
+ });
37
+ /** Request body for PUT / */
38
+ const SetCustomScopeTreeBodySchema = valibot.object({ scopes: valibot.array(CustomScopeInputSchema) });
39
+ /** Request body for POST /commerce */
40
+ const SyncCommerceScopesBodySchema = valibot.object({
41
+ commerceBaseUrl: require_schemas.nonEmptyStringValueSchema("commerceBaseUrl"),
42
+ commerceEnv: valibot.optional(_adobe_aio_commerce_lib_core_commerce.CommerceEnvSchema)
43
+ });
25
44
 
26
- //#region source/actions/scope-tree.ts
27
- const router = new require_router.HttpActionRouter().use(require_router.logger());
45
+ //#endregion
46
+ //#region source/actions/scope-tree/router.ts
47
+ /**
48
+ * Scope Tree action router.
49
+ *
50
+ * Routes:
51
+ * - GET / Retrieve the scope tree.
52
+ * - PUT / Set custom scope tree.
53
+ * - POST /commerce Sync commerce scopes
54
+ * - DELETE /commerce Unsync commerce scopes
55
+ */
56
+ const router = new require_router.HttpActionRouter().use(require_router.logger({ name: () => "scope-tree" }));
28
57
  /** GET / - Get scope tree */
29
58
  router.get("/", { handler: async (_req, ctx) => {
30
59
  const { logger } = ctx;
31
60
  const result = await (0, _adobe_aio_commerce_lib_config.getScopeTree)();
32
61
  logger.debug(`Successfully retrieved scope tree (cached: ${result.isCachedData}): ${require_logging.inspect(result.scopeTree)}`);
33
62
  if (result.isCachedData) return (0, _adobe_aio_commerce_lib_core_responses.nonAuthoritativeInformation)({
34
- headers: { "x-cache": "hit" },
35
- body: { scopes: result.scopeTree }
63
+ body: { scopes: result.scopeTree },
64
+ headers: { "x-cache": "hit" }
36
65
  });
37
66
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: { scopes: result.scopeTree } });
38
67
  } });
39
- /** POST / - Set custom scope tree */
68
+ /** PUT / - Set custom scope tree */
40
69
  router.put("/", {
41
- body: valibot.object({ scopes: valibot.array(valibot.any()) }),
70
+ body: SetCustomScopeTreeBodySchema,
42
71
  handler: async (req, ctx) => {
43
72
  const { logger } = ctx;
44
73
  logger.debug(`Setting custom scope tree with ${req.body.scopes?.length || 0} scopes`);
45
74
  const request = { scopes: req.body.scopes };
75
+ let result;
46
76
  logger.debug(`Setting custom scope tree: ${require_logging.inspect(request)}`);
47
- const result = await (0, _adobe_aio_commerce_lib_config.setCustomScopeTree)(request);
77
+ try {
78
+ result = await (0, _adobe_aio_commerce_lib_config.setCustomScopeTree)(request);
79
+ } catch (err) {
80
+ if (err instanceof Error && "isValidationError" in err) {
81
+ logger.debug(`Custom scope tree validation failed: ${err.message}`);
82
+ return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: { message: err.message } });
83
+ }
84
+ throw err;
85
+ }
48
86
  logger.debug(`Successfully set custom scope tree: ${require_logging.inspect(result)}`);
49
87
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({
50
88
  body: { result },
@@ -54,10 +92,7 @@ router.put("/", {
54
92
  });
55
93
  /** POST /commerce - Sync commerce scopes */
56
94
  router.post("/commerce", {
57
- body: valibot.object({
58
- commerceBaseUrl: require_schemas.nonEmptyStringValueSchema("commerceBaseUrl"),
59
- commerceEnv: valibot.optional(require_schemas.nonEmptyStringValueSchema("commerceEnv"))
60
- }),
95
+ body: SyncCommerceScopesBodySchema,
61
96
  handler: async (req, ctx) => {
62
97
  const { logger } = ctx;
63
98
  logger.debug("Syncing commerce scopes...");
@@ -70,18 +105,18 @@ router.post("/commerce", {
70
105
  if (result.error) {
71
106
  logger.error(`Error syncing commerce scopes: ${require_logging.inspect(result.error)}`);
72
107
  return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
73
- message: "An internal server error occurred",
74
- error: result.error
108
+ error: result.error,
109
+ message: "An internal server error occurred"
75
110
  } });
76
111
  }
77
112
  if (!result.synced) {
78
113
  logger.debug(`Commerce scopes not synced (cached): ${require_logging.inspect(result.scopeTree)}`);
79
114
  return (0, _adobe_aio_commerce_lib_core_responses.nonAuthoritativeInformation)({
80
- headers: { "x-cache": "hit" },
81
115
  body: {
82
116
  scopes: result.scopeTree,
83
117
  synced: false
84
- }
118
+ },
119
+ headers: { "x-cache": "hit" }
85
120
  });
86
121
  }
87
122
  logger.debug(`Successfully synced commerce scopes: ${require_logging.inspect(result.scopeTree)}`);
@@ -105,6 +140,9 @@ router.delete("/commerce", { handler: async (_req, ctx) => {
105
140
  logger.debug(message);
106
141
  return (0, _adobe_aio_commerce_lib_core_responses.ok)(message);
107
142
  } });
143
+
144
+ //#endregion
145
+ //#region source/actions/scope-tree/index.ts
108
146
  /** The handler method for the `scope-tree` action. */
109
147
  const scopeTreeRuntimeAction = router.handler();
110
148
 
@@ -12,7 +12,7 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- //#region source/actions/scope-tree.d.ts
15
+ //#region source/actions/scope-tree/index.d.ts
16
16
  /** The handler method for the `scope-tree` action. */
17
17
  declare const scopeTreeRuntimeAction: (args: import("@adobe/aio-commerce-lib-core/params").RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
18
18
  //#endregion