@adobe/aio-commerce-lib-app 2.0.0 → 2.0.1-alpha-20260923160203

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 (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -0
  3. package/dist/cjs/actions/app-config/index.cjs +3 -3
  4. package/dist/cjs/actions/association/index.cjs +1 -1
  5. package/dist/cjs/actions/config/index.cjs +1 -1
  6. package/dist/cjs/actions/installation/index.cjs +4 -4
  7. package/dist/cjs/actions/scope-tree/index.cjs +4 -3
  8. package/dist/cjs/cli/index.cjs +393 -0
  9. package/dist/cjs/cli/index.d.cts +31 -0
  10. package/dist/cjs/commands/index.cjs +73 -1717
  11. package/dist/cjs/{common-VSsQEHDv.cjs → common-B3KrOG-h.cjs} +1 -1
  12. package/dist/cjs/config/index.node.cjs +3 -3
  13. package/dist/{es/logging-CXesop3u.mjs → cjs/constants-tQUzmimN.cjs} +6 -18
  14. package/dist/cjs/{index.node-vcOo1rt0.cjs → index.node-DwuJfAiP.cjs} +1 -1
  15. package/dist/cjs/{logging-Br3xfBNe.cjs → logging-QTsrSwPc.cjs} +0 -16
  16. package/dist/cjs/management/index.cjs +1 -1
  17. package/dist/cjs/{management-Bki3hlxL.cjs → management-DplOGozL.cjs} +11 -10
  18. package/dist/cjs/{validate-CwWYtRsS.cjs → validate-DkmBVWFX.cjs} +1 -1
  19. package/dist/cjs/web-src-CCzvhSf0.cjs +1515 -0
  20. package/dist/cjs/{webhooks-Bcq2Qy7q.cjs → webhooks-zXjrg32x.cjs} +57 -57
  21. package/dist/es/actions/app-config/index.mjs +3 -3
  22. package/dist/es/actions/association/index.mjs +1 -1
  23. package/dist/es/actions/config/index.mjs +1 -1
  24. package/dist/es/actions/installation/index.mjs +4 -4
  25. package/dist/es/actions/scope-tree/index.mjs +3 -2
  26. package/dist/es/cli/index.d.mts +31 -0
  27. package/dist/es/cli/index.mjs +381 -0
  28. package/dist/es/commands/index.mjs +29 -1666
  29. package/dist/es/{common-dy6NrZt8.mjs → common-BWUDGasu.mjs} +1 -1
  30. package/dist/es/config/index.node.mjs +3 -3
  31. package/dist/es/constants-CSQsZaDP.mjs +25 -0
  32. package/dist/es/{index.node-CW46zuxW.mjs → index.node-DPiidKGS.mjs} +1 -1
  33. package/dist/es/logging-DbJHXSKh.mjs +32 -0
  34. package/dist/es/management/index.mjs +1 -1
  35. package/dist/es/{management-DgwAhaaJ.mjs → management-YDkb15SJ.mjs} +6 -5
  36. package/dist/es/{validate-NzW1FQwL.mjs → validate-Pd7RIA_3.mjs} +1 -1
  37. package/dist/es/web-src-CM_09qwk.mjs +1345 -0
  38. package/dist/es/{webhooks-CHZ1SXxw.mjs → webhooks-BMBfTqwi.mjs} +58 -58
  39. package/package.json +11 -1
  40. /package/dist/cjs/{commands/templates → templates}/admin-ui/tsconfig.json +0 -0
  41. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/.babelrc +0 -0
  42. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/index.css +0 -0
  43. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/index.html +0 -0
  44. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/src/app.jsx +0 -0
  45. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/src/components/welcome.jsx +0 -0
  46. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src/src/pages/main-page.jsx +0 -0
  47. /package/dist/cjs/{commands/templates → templates}/admin-ui/web-src-template.d.ts +0 -0
  48. /package/dist/cjs/{commands/templates → templates}/app-management/app-config.js.template +0 -0
  49. /package/dist/cjs/{commands/templates → templates}/app-management/association.js.template +0 -0
  50. /package/dist/cjs/{commands/templates → templates}/app-management/custom-scripts.js.template +0 -0
  51. /package/dist/cjs/{commands/templates → templates}/app-management/installation.js.template +0 -0
  52. /package/dist/cjs/{commands/templates → templates}/business-configuration/config.js.template +0 -0
  53. /package/dist/cjs/{commands/templates → templates}/business-configuration/scope-tree.js.template +0 -0
  54. /package/dist/cjs/{commands/templates → templates}/typescript/webpack-config.cjs +0 -0
  55. /package/dist/es/{commands/templates → templates}/admin-ui/tsconfig.json +0 -0
  56. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/.babelrc +0 -0
  57. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/index.css +0 -0
  58. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/index.html +0 -0
  59. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/src/app.jsx +0 -0
  60. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/src/components/welcome.jsx +0 -0
  61. /package/dist/es/{commands/templates → templates}/admin-ui/web-src/src/pages/main-page.jsx +0 -0
  62. /package/dist/es/{commands/templates → templates}/admin-ui/web-src-template.d.ts +0 -0
  63. /package/dist/es/{commands/templates → templates}/app-management/app-config.js.template +0 -0
  64. /package/dist/es/{commands/templates → templates}/app-management/association.js.template +0 -0
  65. /package/dist/es/{commands/templates → templates}/app-management/custom-scripts.js.template +0 -0
  66. /package/dist/es/{commands/templates → templates}/app-management/installation.js.template +0 -0
  67. /package/dist/es/{commands/templates → templates}/business-configuration/config.js.template +0 -0
  68. /package/dist/es/{commands/templates → templates}/business-configuration/scope-tree.js.template +0 -0
  69. /package/dist/es/{commands/templates → templates}/typescript/webpack-config.cjs +0 -0
@@ -20,6 +20,60 @@ let _adobe_aio_commerce_lib_admin_ui_api = require("@adobe/aio-commerce-lib-admi
20
20
  let _adobe_aio_commerce_lib_admin_ui_menu = require("@adobe/aio-commerce-lib-admin-ui/menu");
21
21
  let _adobe_aio_commerce_lib_core_commerce = require("@adobe/aio-commerce-lib-core/commerce");
22
22
 
23
+ //#region source/config/schema/installation.ts
24
+ const MAX_DESCRIPTION_LENGTH$1 = 255;
25
+ const MAX_NAME_LENGTH = 255;
26
+ const MAX_MESSAGE_LENGTH = 1e3;
27
+ /**
28
+ * Regex for script paths that can be relative or absolute.
29
+ * Must end with a .js or .ts extension
30
+ * Examples:
31
+ * - "./scripts/setup.js"
32
+ * - "./setup.ts"
33
+ * - "../../scripts/setup.js"
34
+ */
35
+ const SCRIPT_PATH_REGEX = /^(?:\.{0,2}\/)*(?:[\w-]+\/)*[\w-]+\.(?:js|ts)$/;
36
+ /**
37
+ * Schema for custom installation step configuration
38
+ */
39
+ const CustomInstallationStepSchema = valibot.object({
40
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH$1, `The step description must not be longer than ${MAX_DESCRIPTION_LENGTH$1} characters`)),
41
+ name: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step name"), valibot.maxLength(MAX_NAME_LENGTH, `The step name must not be longer than ${MAX_NAME_LENGTH} characters`)),
42
+ script: valibot.pipe(require_schemas.nonEmptyStringValueSchema("script path"), valibot.regex(SCRIPT_PATH_REGEX, "Script path must end with .js or .ts (e.g., \"./setup.js\", \"./scripts/setup.ts\", or \"../../scripts/setup.js\")"))
43
+ });
44
+ /**
45
+ * Schema for installation messages configuration
46
+ */
47
+ const MessagesSchema = valibot.object({
48
+ postInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("postInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The postInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`))),
49
+ preInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("preInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The preInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`)))
50
+ });
51
+ /**
52
+ * Schema for installation configuration
53
+ */
54
+ const InstallationSchema = valibot.object({
55
+ customInstallationSteps: valibot.pipe(valibot.optional(valibot.array(CustomInstallationStepSchema, "Expected an array of custom installation steps")), valibot.check((input) => {
56
+ const steps = input || [];
57
+ return new Set(steps.map((step) => step.name)).size === steps.length;
58
+ }, "Duplicate step names detected in custom installation steps. Each step must have a unique name.")),
59
+ messages: valibot.optional(MessagesSchema)
60
+ });
61
+ /**
62
+ * Check if config has custom installation settings.
63
+ * @param config - The configuration to check.
64
+ */
65
+ function hasCustomInstallation(config) {
66
+ return config.installation !== void 0;
67
+ }
68
+ /**
69
+ * Check if config has custom installation steps.
70
+ * @param config - The configuration to check.
71
+ */
72
+ function hasCustomInstallationSteps(config) {
73
+ return Array.isArray(config?.installation?.customInstallationSteps) && config.installation.customInstallationSteps.length > 0;
74
+ }
75
+
76
+ //#endregion
23
77
  //#region source/config/schema/admin-ui.ts
24
78
  /**
25
79
  * Whether the given items have distinct ids once Commerce sanitizes them into resource ids.
@@ -229,7 +283,7 @@ function hasAdminUi(config) {
229
283
 
230
284
  //#endregion
231
285
  //#region source/config/schema/eventing.ts
232
- const MAX_DESCRIPTION_LENGTH$1 = 255;
286
+ const MAX_DESCRIPTION_LENGTH = 255;
233
287
  const MAX_LABEL_LENGTH = 100;
234
288
  const MAX_KEY_LENGTH = 50;
235
289
  const MAX_EVENT_NAME_LENGTH = 180;
@@ -298,13 +352,13 @@ function commerceEventFieldSchema() {
298
352
  }
299
353
  /** Schema for event provider configuration */
300
354
  const ProviderSchema = valibot.object({
301
- description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("provider description"), ioEventsTextSchema("Provider description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH$1, `The provider description must not be longer than ${MAX_DESCRIPTION_LENGTH$1} characters`)),
355
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("provider description"), ioEventsTextSchema("Provider description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The provider description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
302
356
  key: valibot.optional(valibot.pipe(require_schemas.alphaNumericOrHyphenSchema("provider key"), valibot.maxLength(MAX_KEY_LENGTH, `The provider key must not be longer than ${MAX_KEY_LENGTH} characters`))),
303
357
  label: valibot.pipe(require_schemas.nonEmptyStringValueSchema("provider label"), ioEventsTextSchema("Provider label"), valibot.maxLength(MAX_LABEL_LENGTH, `The provider label must not be longer than ${MAX_LABEL_LENGTH} characters`))
304
358
  });
305
359
  /** Schema for base shared properties between event types. */
306
360
  const BaseEventSchema = valibot.object({
307
- description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("event description"), ioEventsTextSchema("Event description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH$1, `The event description must not be longer than ${MAX_DESCRIPTION_LENGTH$1} characters`)),
361
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("event description"), ioEventsTextSchema("Event description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The event description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
308
362
  env: valibot.optional(_adobe_aio_commerce_lib_core_commerce.CommerceEnvArraySchema),
309
363
  label: valibot.pipe(require_schemas.nonEmptyStringValueSchema("event label"), ioEventsTextSchema("Event label"), valibot.maxLength(MAX_LABEL_LENGTH, `The event label must not be longer than ${MAX_LABEL_LENGTH} characters`)),
310
364
  runtimeActions: valibot.array(valibot.pipe(require_schemas.nonEmptyStringValueSchema("runtime action"), valibot.regex(/^[a-z0-9-]+\/[a-z0-9-]+$/i, "Runtime action must be in the format \"<package>/<action>\" (e.g., \"my-package/my-action\")")), "Expected an array of runtime actions in the format <package>/<action>")
@@ -382,60 +436,6 @@ function hasEventing(config) {
382
436
  return config.eventing !== void 0;
383
437
  }
384
438
 
385
- //#endregion
386
- //#region source/config/schema/installation.ts
387
- const MAX_DESCRIPTION_LENGTH = 255;
388
- const MAX_NAME_LENGTH = 255;
389
- const MAX_MESSAGE_LENGTH = 1e3;
390
- /**
391
- * Regex for script paths that can be relative or absolute.
392
- * Must end with a .js or .ts extension
393
- * Examples:
394
- * - "./scripts/setup.js"
395
- * - "./setup.ts"
396
- * - "../../scripts/setup.js"
397
- */
398
- const SCRIPT_PATH_REGEX = /^(?:\.{0,2}\/)*(?:[\w-]+\/)*[\w-]+\.(?:js|ts)$/;
399
- /**
400
- * Schema for custom installation step configuration
401
- */
402
- const CustomInstallationStepSchema = valibot.object({
403
- description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The step description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
404
- name: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step name"), valibot.maxLength(MAX_NAME_LENGTH, `The step name must not be longer than ${MAX_NAME_LENGTH} characters`)),
405
- script: valibot.pipe(require_schemas.nonEmptyStringValueSchema("script path"), valibot.regex(SCRIPT_PATH_REGEX, "Script path must end with .js or .ts (e.g., \"./setup.js\", \"./scripts/setup.ts\", or \"../../scripts/setup.js\")"))
406
- });
407
- /**
408
- * Schema for installation messages configuration
409
- */
410
- const MessagesSchema = valibot.object({
411
- postInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("postInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The postInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`))),
412
- preInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("preInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The preInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`)))
413
- });
414
- /**
415
- * Schema for installation configuration
416
- */
417
- const InstallationSchema = valibot.object({
418
- customInstallationSteps: valibot.pipe(valibot.optional(valibot.array(CustomInstallationStepSchema, "Expected an array of custom installation steps")), valibot.check((input) => {
419
- const steps = input || [];
420
- return new Set(steps.map((step) => step.name)).size === steps.length;
421
- }, "Duplicate step names detected in custom installation steps. Each step must have a unique name.")),
422
- messages: valibot.optional(MessagesSchema)
423
- });
424
- /**
425
- * Check if config has custom installation settings.
426
- * @param config - The configuration to check.
427
- */
428
- function hasCustomInstallation(config) {
429
- return config.installation !== void 0;
430
- }
431
- /**
432
- * Check if config has custom installation steps.
433
- * @param config - The configuration to check.
434
- */
435
- function hasCustomInstallationSteps(config) {
436
- return Array.isArray(config?.installation?.customInstallationSteps) && config.installation.customInstallationSteps.length > 0;
437
- }
438
-
439
439
  //#endregion
440
440
  //#region source/config/schema/webhooks.ts
441
441
  /** Schema for webhook field configuration (name and optional source). */
@@ -13,12 +13,12 @@
13
13
  */
14
14
 
15
15
  import { n as filterAppConfigByEnv } from "../../environment-C84BPRJZ.mjs";
16
- import { i as requiresInstallationFromDomains, o as getConfigDomains, t as validateCommerceAppConfig, u as hasBusinessConfigSchema } from "../../validate-NzW1FQwL.mjs";
16
+ import { i as requiresInstallationFromDomains, o as getConfigDomains, t as validateCommerceAppConfig, u as hasBusinessConfigSchema } from "../../validate-Pd7RIA_3.mjs";
17
17
  import { n as logger, t as HttpActionRouter } from "../../router-BshIPAR1.mjs";
18
18
  import { resolveBusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
19
+ import { internalServerError, ok } from "@adobe/aio-commerce-lib-core/responses";
19
20
  import * as v from "valibot";
20
21
  import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
21
- import { internalServerError, ok } from "@adobe/aio-commerce-lib-core/responses";
22
22
  import { createHash } from "crypto";
23
23
 
24
24
  //#region source/actions/app-config/openapi.ts
@@ -77,7 +77,7 @@ function pruneUnusedTags(spec) {
77
77
  * @param domains - The active config domains.
78
78
  */
79
79
  function getOpenApiCacheKey(domains) {
80
- const input = `2.0.0:${[...domains].sort().join(",")}:3.0.0`;
80
+ const input = `2.0.1-alpha-20260923160203:${[...domains].sort().join(",")}:3.0.0`;
81
81
  return createHash("sha256").update(input).digest("hex").slice(0, 8);
82
82
  }
83
83
  /** Returns the server URL to be set in the OpenAPI spec, based on the current namespace. */
@@ -14,9 +14,9 @@
14
14
 
15
15
  import { r as setAssociationData, t as clearAssociationData } from "../../repository-BGmy0YeZ.mjs";
16
16
  import { n as logger, t as HttpActionRouter } from "../../router-BshIPAR1.mjs";
17
+ import { noContent } from "@adobe/aio-commerce-lib-core/responses";
17
18
  import * as v from "valibot";
18
19
  import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
19
- import { noContent } from "@adobe/aio-commerce-lib-core/responses";
20
20
 
21
21
  //#region source/actions/association/schema.ts
22
22
  /** Request body for POST / — store association data. */
@@ -16,9 +16,9 @@ import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
16
16
  import { r as filterSchemaByEnv } from "../../environment-C84BPRJZ.mjs";
17
17
  import { n as logger, t as HttpActionRouter } from "../../router-BshIPAR1.mjs";
18
18
  import { byScopeId, getConfiguration, initialize, setConfiguration } from "@adobe/aio-commerce-lib-config";
19
+ import { ok } from "@adobe/aio-commerce-lib-core/responses";
19
20
  import * as v from "valibot";
20
21
  import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
21
- import { ok } from "@adobe/aio-commerce-lib-core/responses";
22
22
 
23
23
  //#region source/actions/config/schema.ts
24
24
  const AcceptedConfigurationValuesSchema = v.union([
@@ -13,14 +13,14 @@
13
13
  */
14
14
 
15
15
  import { n as getAssociationData } from "../../repository-BGmy0YeZ.mjs";
16
+ import { _ as CURRENT_STATE_KEY, a as buildWorkflowParams, b as requireCurrentAttempt, c as createLifecyclePersistence, d as getExecutedCustomInstallationSteps, f as getStorageKey, g as getCurrentLifecycleBaseline, h as createOrchestrationStateStore, i as buildLifecycleContext, l as createLifecycleRuntime, m as readStateFromStore, o as createInstallationHooks, p as isPostAppDeployInvocation, s as createInstallationStore, t as DEFAULT_ACTION_NAME, u as createUninstallationStore, v as normalizeExpiredAttempt, x as requireState, y as readOrInitializeState } from "../../common-BWUDGasu.mjs";
17
+ import { C as callHook, S as isLeafStep, _ as isStepConfigured, a as runValidation, b as setAtPath, d as isSucceededState, f as createRetryState, g as getAtPath, h as createWorkflowError, i as runUninstallation, l as isFailedState, m as createSucceededState, n as createInitialUninstallationState, p as createFailedState, r as runInstallation, t as createInitialInstallationState, u as isInProgressState, v as nowIsoString, x as isBranchStep, y as pathsEqual } from "../../management-YDkb15SJ.mjs";
16
18
  import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
17
- import { r as validateRecordedCommerceAppConfig, t as validateCommerceAppConfig } from "../../validate-NzW1FQwL.mjs";
18
- import { _ as CURRENT_STATE_KEY, a as buildWorkflowParams, b as requireCurrentAttempt, c as createLifecyclePersistence, d as getExecutedCustomInstallationSteps, f as getStorageKey, g as getCurrentLifecycleBaseline, h as createOrchestrationStateStore, i as buildLifecycleContext, l as createLifecycleRuntime, m as readStateFromStore, o as createInstallationHooks, p as isPostAppDeployInvocation, s as createInstallationStore, t as DEFAULT_ACTION_NAME, u as createUninstallationStore, v as normalizeExpiredAttempt, x as requireState, y as readOrInitializeState } from "../../common-dy6NrZt8.mjs";
19
- import { C as callHook, S as isLeafStep, _ as isStepConfigured, a as runValidation, b as setAtPath, d as isSucceededState, f as createRetryState, g as getAtPath, h as createWorkflowError, i as runUninstallation, l as isFailedState, m as createSucceededState, n as createInitialUninstallationState, p as createFailedState, r as runInstallation, t as createInitialInstallationState, u as isInProgressState, v as nowIsoString, x as isBranchStep, y as pathsEqual } from "../../management-DgwAhaaJ.mjs";
19
+ import { r as validateRecordedCommerceAppConfig, t as validateCommerceAppConfig } from "../../validate-Pd7RIA_3.mjs";
20
20
  import { n as logger, t as HttpActionRouter } from "../../router-BshIPAR1.mjs";
21
+ import { accepted, badRequest, conflict, internalServerError, noContent, ok } from "@adobe/aio-commerce-lib-core/responses";
21
22
  import * as v from "valibot";
22
23
  import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
23
- import { accepted, badRequest, conflict, internalServerError, noContent, ok } from "@adobe/aio-commerce-lib-core/responses";
24
24
  import openwhisk from "openwhisk";
25
25
 
26
26
  //#region source/management/common/workflow/execute.ts
@@ -13,13 +13,14 @@
13
13
  */
14
14
 
15
15
  import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
16
- import { n as LIFECYCLE_HTTP_CLIENT_TIMEOUT_MS, t as inspect } from "../../logging-CXesop3u.mjs";
16
+ import { t as LIFECYCLE_HTTP_CLIENT_TIMEOUT_MS } from "../../constants-CSQsZaDP.mjs";
17
+ import { t as inspect } from "../../logging-DbJHXSKh.mjs";
17
18
  import { n as logger, t as HttpActionRouter } from "../../router-BshIPAR1.mjs";
18
19
  import { resolveCommerceHttpClientParams } from "@adobe/aio-commerce-lib-api";
19
20
  import { getScopeTree, setCustomScopeTree, syncCommerceScopes, unsyncCommerceScopes } from "@adobe/aio-commerce-lib-config";
21
+ import { badRequest, internalServerError, nonAuthoritativeInformation, ok } from "@adobe/aio-commerce-lib-core/responses";
20
22
  import * as v from "valibot";
21
23
  import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
22
- import { badRequest, internalServerError, nonAuthoritativeInformation, ok } from "@adobe/aio-commerce-lib-core/responses";
23
24
 
24
25
  //#region source/actions/scope-tree/schema.ts
25
26
  const CustomScopeInputSchema = v.object({
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ //#region source/commands/hooks/pre-app-build.d.ts
16
+ /** The extensions that register a `pre-app-build` hook. */
17
+ type Extension = "extensibility/1" | "configuration/1" | "backend-ui/2";
18
+ //#endregion
19
+ //#region source/cli/index.d.ts
20
+ /**
21
+ * Creates the `pre-app-build` hook for the given extension.
22
+ * @param extension - The extension the hook is registered for.
23
+ */
24
+ export declare function preAppBuild(extension: Extension): () => Promise<void>;
25
+ /** Creates the `pre-app-run` hook. */
26
+ export declare function preAppRun(): () => Promise<void>;
27
+ /** Creates the `pre-app-dev` hook. */
28
+ export declare function preAppDev(): () => Promise<void>;
29
+ /** Creates the `post-app-deploy` hook. */
30
+ export declare function postAppDeploy(): () => Promise<void>;
31
+ //#endregion
@@ -0,0 +1,381 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { p as getProjectRootDirectory, r as parseCommerceAppConfig } from "../index.node-DPiidKGS.mjs";
16
+ import { O as TEMPLATES_DIR, S as BACKEND_UI_V2_EXTENSION_POINT_ID, T as EXTENSIBILITY_EXTENSION_POINT_ID, c as run$4, d as readExtConfig, f as updateExtConfig, g as getRuntimeActions, l as generateActionFiles, n as prepareWebSourceImportAlias, o as run$5, t as generateWebSrc, u as prepareRuntimeAppConfigModule, v as loadAppManifest, w as CONFIGURATION_EXTENSION_POINT_ID } from "../web-src-CM_09qwk.mjs";
17
+ import { n as INSTALLATION_INVOCATION_SOURCE_HEADER, r as POST_APP_DEPLOY_INVOCATION_SOURCE } from "../common-BWUDGasu.mjs";
18
+ import { l as hasBackendUiV2Components } from "../webhooks-BMBfTqwi.mjs";
19
+ import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
20
+ import { existsSync, readFileSync, writeFileSync } from "fs";
21
+ import path from "path";
22
+ import consola$1, { consola } from "consola";
23
+ import aioIms from "@adobe/aio-lib-ims";
24
+ import config from "@adobe/aio-lib-core-config";
25
+ import { colors } from "consola/utils";
26
+ import ky, { HTTPError } from "ky";
27
+ import * as v from "valibot";
28
+ import { setTimeout } from "timers/promises";
29
+ import dotenv from "dotenv";
30
+
31
+ //#region ../../packages-private/scripting-utils/source/aio/auth.ts
32
+ const { context: context$1, getToken } = aioIms;
33
+ /** Gets an IMS access token for the current CLI IMS context. */
34
+ async function getUserToken() {
35
+ const contextName = await context$1.getCurrent() ?? "cli";
36
+ return getToken(contextName, {});
37
+ }
38
+
39
+ //#endregion
40
+ //#region ../../packages-private/scripting-utils/source/aio/context.ts
41
+ /**
42
+ * Reads the current App Builder project and Runtime namespace from the local AIO CLI config.
43
+ * @throws If either the project or the runtime namespace is not configured.
44
+ */
45
+ function getAioProjectContext() {
46
+ const project = config.get("project");
47
+ const namespace = config.get("runtime.namespace");
48
+ if (!(project && namespace)) throw new Error("The current App Builder project and Runtime namespace are required");
49
+ return {
50
+ namespace,
51
+ project
52
+ };
53
+ }
54
+ /** Reads the configured AIO CLI environment, defaulting to `"prod"`. */
55
+ function getAioCliEnv() {
56
+ return config.get("cli.env") === "stage" ? "stage" : "prod";
57
+ }
58
+
59
+ //#endregion
60
+ //#region source/commands/hooks/post-app-deploy/polling.ts
61
+ const POLL_INTERVAL_MS = 1e3;
62
+ const UpgradeStateSchema = v.object({
63
+ failure: v.optional(v.object({
64
+ key: v.string(),
65
+ message: v.optional(v.string())
66
+ })),
67
+ id: v.string(),
68
+ status: v.picklist([
69
+ "pending",
70
+ "in-progress",
71
+ "succeeded",
72
+ "failed"
73
+ ])
74
+ });
75
+ /** Reads the latest upgrade state from the installation action. */
76
+ async function getUpgradeState(request) {
77
+ try {
78
+ const response = await ky.get(request.endpoint, { headers: request.headers });
79
+ if (response.status === 204) return null;
80
+ const parsed = v.safeParse(UpgradeStateSchema, await response.json());
81
+ return parsed.success ? parsed.output : null;
82
+ } catch (error) {
83
+ consola.debug("Unable to read upgrade status; stopping upgrade polling.", { error });
84
+ return null;
85
+ }
86
+ }
87
+ /** Waits for an automatic upgrade when its status remains available. */
88
+ async function waitForAutomaticUpgrade(request) {
89
+ const state = await getUpgradeState(request);
90
+ if (!state) return;
91
+ if (state.status === "succeeded") {
92
+ consola.success("App upgrade completed.\n");
93
+ return;
94
+ }
95
+ if (state.status === "failed") {
96
+ const reason = state.failure?.message ?? state.failure?.key ?? "The lifecycle attempt failed";
97
+ throw new Error(`App upgrade failed: ${reason}`);
98
+ }
99
+ consola.start("App upgrade is in progress...");
100
+ await setTimeout(POLL_INTERVAL_MS);
101
+ return waitForAutomaticUpgrade(request);
102
+ }
103
+
104
+ //#endregion
105
+ //#region source/commands/hooks/post-app-deploy/main.ts
106
+ /** Returns true for a no-op reason defined by the upgrade API contract. */
107
+ function isSkippedReason(reason) {
108
+ return reason === "already-current" || reason === "not-associated" || reason === "not-installed";
109
+ }
110
+ /** Returns true if the result indicates that the upgrade was skipped. */
111
+ function isSkippedResult(result) {
112
+ return "skipped" in result;
113
+ }
114
+ /** Invokes the upgrade action. */
115
+ async function createUpgradeRequest() {
116
+ const { project, namespace } = getAioProjectContext();
117
+ const token = await getUserToken();
118
+ const endpoint = `https://${namespace}.adobeioruntime.net/api/v1/web/app-management/installation`;
119
+ const ioEventsEnv = getAioCliEnv();
120
+ const ioEventsUrl = ioEventsEnv === "stage" ? "https://events-stage.adobe.io" : "https://events.adobe.io";
121
+ return {
122
+ body: {
123
+ appData: {
124
+ consumerOrgId: project.org.id,
125
+ orgName: project.org.name,
126
+ projectId: project.id,
127
+ projectName: project.name,
128
+ projectTitle: project.title,
129
+ workspaceId: project.workspace.id,
130
+ workspaceName: project.workspace.name,
131
+ workspaceTitle: project.workspace.title
132
+ },
133
+ ioEventsEnv,
134
+ ioEventsUrl
135
+ },
136
+ endpoint,
137
+ headers: {
138
+ Authorization: `Bearer ${token}`,
139
+ [INSTALLATION_INVOCATION_SOURCE_HEADER]: POST_APP_DEPLOY_INVOCATION_SOURCE,
140
+ "x-gw-ims-org-id": project.org.ims_org_id
141
+ }
142
+ };
143
+ }
144
+ /** Invokes the upgrade action. */
145
+ async function invokeAction(request) {
146
+ consola.debug(`Upgrade endpoint: ${request.endpoint}`);
147
+ try {
148
+ return await ky.post(request.endpoint, {
149
+ headers: request.headers,
150
+ json: request.body
151
+ }).json();
152
+ } catch (error) {
153
+ if (error instanceof HTTPError) {
154
+ const details = await error.response.json();
155
+ if (error.response.status === 409 && isSkippedReason(details.reason)) return {
156
+ reason: details.reason,
157
+ skipped: true
158
+ };
159
+ throw new Error(`Failed to trigger app upgrade (HTTP ${error.response.status}): ${JSON.stringify(details, null, 2)}`, { cause: error });
160
+ }
161
+ throw error;
162
+ }
163
+ }
164
+ /** Invokes the deployed app's upgrade endpoint. */
165
+ async function run$3() {
166
+ const { upgradeMode } = (await parseCommerceAppConfig()).metadata;
167
+ consola.log("");
168
+ consola.start("Checking for app upgrades...");
169
+ const request = await createUpgradeRequest();
170
+ const result = await invokeAction(request);
171
+ if (isSkippedResult(result)) {
172
+ consola.info(`No upgrade was run: ${result.reason}.\n`);
173
+ return result;
174
+ }
175
+ if (upgradeMode === "manual") consola.success(`You have set ${colors.cyan("metadata.upgradeMode")} to ${colors.cyan("manual")}. The upgrade plan has been created but will not be executed.`);
176
+ else consola.success(`You have set ${colors.cyan("metadata.upgradeMode")} to ${colors.cyan("auto")}. The upgrade plan has been created. Execution will begin shortly.`);
177
+ consola.box(["Upgrade plan", JSON.stringify(result.plan, null, 2)].join("\n\n"));
178
+ if (upgradeMode === "auto") await waitForAutomaticUpgrade(request);
179
+ return result;
180
+ }
181
+
182
+ //#endregion
183
+ //#region ../../packages-private/scripting-utils/source/env.ts
184
+ /**
185
+ * This module exports shared environment utilities for the AIO Commerce SDK.
186
+ * @packageDocumentation
187
+ */
188
+ const { context } = aioIms;
189
+ const IMS_KEYS = {
190
+ client_id: "AIO_COMMERCE_AUTH_IMS_CLIENT_ID",
191
+ client_secrets: "AIO_COMMERCE_AUTH_IMS_CLIENT_SECRETS",
192
+ ims_org_id: "AIO_COMMERCE_AUTH_IMS_ORG_ID",
193
+ scopes: "AIO_COMMERCE_AUTH_IMS_SCOPES",
194
+ technical_account_email: "AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_EMAIL",
195
+ technical_account_id: "AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_ID"
196
+ };
197
+ /**
198
+ * Replaces or creates an environment variable in a .env file
199
+ * @param filePath - The path to the .env file
200
+ * @param key - The environment variable key to replace or create
201
+ * @param value - The new value for the environment variable
202
+ */
203
+ function replaceEnvVar(filePath, key, value) {
204
+ const envPath = path.resolve(filePath);
205
+ const envLines = readFileSync(envPath, "utf8").split("\n");
206
+ const formattedValue = value.includes(" ") ? `"${value}"` : value;
207
+ let keyExists = false;
208
+ const updatedLines = envLines.map((line) => {
209
+ if (line.trim().startsWith("#") || !line.includes("=")) return line;
210
+ const [currentKey] = line.split("=");
211
+ if (currentKey === key) {
212
+ keyExists = true;
213
+ return `${key}=${formattedValue}`;
214
+ }
215
+ return line;
216
+ });
217
+ if (!keyExists) updatedLines.push(`${key}=${formattedValue}`);
218
+ writeFileSync(envPath, updatedLines.join("\n"), "utf8");
219
+ }
220
+ /**
221
+ * Sets the `NODE_ENV` environment variable in the current process and in the app
222
+ * `.env` file, so the web bundler (Parcel) ships the matching React build.
223
+ * Creates the `.env` if absent.
224
+ * @param mode - The environment mode to set in `NODE_ENV`.
225
+ * @param projectRoot - Resolved project root containing the `.env` file.
226
+ */
227
+ function setNodeEnv(mode, projectRoot) {
228
+ const envPath = path.join(projectRoot, ".env");
229
+ if (!existsSync(envPath)) writeFileSync(envPath, "", "utf8");
230
+ replaceEnvVar(envPath, "NODE_ENV", mode);
231
+ process.env.NODE_ENV = mode;
232
+ }
233
+ /** Resolves the IMS server to server context from the project workspace credentials. */
234
+ function resolveImsS2SContext() {
235
+ const [credential] = (config.get("project.workspace.details.credentials") ?? []).filter(({ integration_type }) => integration_type === "oauth_server_to_server").map(({ name }) => name);
236
+ if (!credential) return Promise.resolve(null);
237
+ return context.get(credential);
238
+ }
239
+ /**
240
+ * Syncs the IMS credentials environment variables from the configured IMS context in
241
+ * the .env file, in a way that is compatible with `@adobe/aio-commerce-lib-auth`.
242
+ * @param projectRoot - Resolved project root containing the `.env` file.
243
+ */
244
+ async function syncImsCredentials(projectRoot) {
245
+ const envPath = path.join(projectRoot, ".env");
246
+ if (!existsSync(envPath)) return {
247
+ ok: false,
248
+ reason: "missing-env"
249
+ };
250
+ const envVars = dotenv.parse(readFileSync(envPath, "utf8"));
251
+ const imsContext = await resolveImsS2SContext();
252
+ if (!imsContext) return {
253
+ ok: false,
254
+ reason: "no-ims-context"
255
+ };
256
+ const { data } = imsContext;
257
+ for (const [key, value] of Object.entries(data)) {
258
+ const oauthKey = IMS_KEYS[key];
259
+ if (!oauthKey) continue;
260
+ if (!envVars[oauthKey] || envVars[oauthKey] !== value) replaceEnvVar(envPath, oauthKey, value);
261
+ }
262
+ return { ok: true };
263
+ }
264
+
265
+ //#endregion
266
+ //#region source/commands/hooks/pre-app-build.ts
267
+ /**
268
+ * Runs the pre-app-build hook for the given extension.
269
+ * @param extension - The extension to run the hook for.
270
+ * @param projectRoot - Resolved project root containing extension files.
271
+ * @param templatesDir - Directory containing action templates.
272
+ * @param options - Hook options.
273
+ * @param options.isDevSession - Whether the build runs within `aio app run` or `aio app dev`, which keeps `NODE_ENV` untouched.
274
+ */
275
+ async function run$2(extension, projectRoot, templatesDir = TEMPLATES_DIR, { isDevSession = false } = {}) {
276
+ const appManifest = await loadAppManifest(projectRoot);
277
+ await prepareRuntimeAppConfigModule(appManifest, projectRoot);
278
+ if (extension === "extensibility/1") {
279
+ const { doc: extensibilityExtConfig } = await readExtConfig(EXTENSIBILITY_EXTENSION_POINT_ID, projectRoot);
280
+ await run$4(appManifest, projectRoot);
281
+ await generateActionFiles(appManifest, getRuntimeActions(extensibilityExtConfig.toJS(), "app-management"), EXTENSIBILITY_EXTENSION_POINT_ID, templatesDir, projectRoot);
282
+ consola$1.info("Syncing IMS credentials...");
283
+ await syncImsCredentials(projectRoot);
284
+ return;
285
+ }
286
+ if (extension === "configuration/1") {
287
+ const { doc: businessConfigExtConfig } = await readExtConfig(CONFIGURATION_EXTENSION_POINT_ID, projectRoot);
288
+ await run$5(appManifest, projectRoot);
289
+ await generateActionFiles(appManifest, getRuntimeActions(businessConfigExtConfig.toJS(), "business-configuration"), CONFIGURATION_EXTENSION_POINT_ID, templatesDir, projectRoot);
290
+ return;
291
+ }
292
+ if (extension === "backend-ui/2") {
293
+ if (hasBackendUiV2Components(appManifest)) {
294
+ const extConfig = await updateExtConfig(appManifest, BACKEND_UI_V2_EXTENSION_POINT_ID, projectRoot);
295
+ if (extConfig.operations?.view) {
296
+ await prepareWebSourceImportAlias(extConfig, projectRoot);
297
+ await generateWebSrc(extConfig, appManifest.metadata.displayName, projectRoot, templatesDir);
298
+ if (!isDevSession) await setNodeEnv("production", projectRoot);
299
+ }
300
+ }
301
+ return;
302
+ }
303
+ throw new Error(`Unsupported extension: ${extension}`);
304
+ }
305
+
306
+ //#endregion
307
+ //#region source/commands/hooks/pre-app-dev.ts
308
+ /**
309
+ * Resets the web build back to development by setting `NODE_ENV` in the process and the project `.env`.
310
+ * @param projectRoot - Resolved project root containing the `.env` file.
311
+ */
312
+ async function run$1(projectRoot) {
313
+ await setNodeEnv("development", projectRoot);
314
+ }
315
+
316
+ //#endregion
317
+ //#region source/commands/hooks/pre-app-run.ts
318
+ /**
319
+ * Resets the web build back to development by setting `NODE_ENV` in the process and the project `.env`.
320
+ * @param projectRoot - Resolved project root containing the `.env` file.
321
+ */
322
+ async function run(projectRoot) {
323
+ await setNodeEnv("development", projectRoot);
324
+ }
325
+
326
+ //#endregion
327
+ //#region source/cli/index.ts
328
+ /**
329
+ * Internal App Builder hook handlers, loaded by the hook files that
330
+ * `@adobe/aio-commerce-lib-app` generates. Not part of the public API.
331
+ * @packageDocumentation
332
+ */
333
+ let isDevSession = false;
334
+ /**
335
+ * Creates an async App Builder hook that runs the given function, logging any
336
+ * error and exiting the process with code 1.
337
+ *
338
+ * @param fn - The hook implementation.
339
+ */
340
+ function createHook(fn) {
341
+ return async () => {
342
+ try {
343
+ await fn();
344
+ } catch (error) {
345
+ if (error instanceof CommerceSdkValidationError) consola$1.error(error.display());
346
+ else consola$1.error(error);
347
+ process.exit(1);
348
+ }
349
+ };
350
+ }
351
+ /**
352
+ * Creates the `pre-app-build` hook for the given extension.
353
+ * @param extension - The extension the hook is registered for.
354
+ */
355
+ function preAppBuild(extension) {
356
+ return createHook(async () => {
357
+ const projectRoot = await getProjectRootDirectory();
358
+ await run$2(extension, projectRoot, TEMPLATES_DIR, { isDevSession });
359
+ });
360
+ }
361
+ /** Creates the `pre-app-run` hook. */
362
+ function preAppRun() {
363
+ return createHook(async () => {
364
+ isDevSession = true;
365
+ await run(await getProjectRootDirectory());
366
+ });
367
+ }
368
+ /** Creates the `pre-app-dev` hook. */
369
+ function preAppDev() {
370
+ return createHook(async () => {
371
+ isDevSession = true;
372
+ await run$1(await getProjectRootDirectory());
373
+ });
374
+ }
375
+ /** Creates the `post-app-deploy` hook. */
376
+ function postAppDeploy() {
377
+ return createHook(run$3);
378
+ }
379
+
380
+ //#endregion
381
+ export { postAppDeploy, preAppBuild, preAppDev, preAppRun };