@adobe/aio-commerce-lib-app 1.7.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 (93) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/cjs/actions/app-config/index.cjs +41 -38
  3. package/dist/cjs/actions/app-config/index.d.cts +1 -1
  4. package/dist/cjs/actions/association/index.cjs +85 -0
  5. package/dist/cjs/actions/{registration → association}/index.d.cts +9 -13
  6. package/dist/cjs/actions/config/index.cjs +21 -32
  7. package/dist/cjs/actions/installation/index.cjs +72 -51
  8. package/dist/cjs/actions/installation/index.d.cts +2 -2
  9. package/dist/cjs/actions/scope-tree/index.cjs +18 -17
  10. package/dist/{es/app-DrYHK-z1.d.mts → cjs/app-D3P-Z6uY.d.cts} +1085 -1035
  11. package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
  12. package/dist/cjs/commands/index.cjs +512 -298
  13. package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
  14. package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
  15. package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
  16. package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  17. package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  18. package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  19. package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  20. package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
  21. package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
  22. package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
  23. package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
  24. package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
  25. package/dist/cjs/config/index.browser.cjs +18 -0
  26. package/dist/cjs/config/index.browser.d.cts +16 -0
  27. package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
  28. package/dist/cjs/config/{index.d.cts → index.node.d.cts} +954 -386
  29. package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
  30. package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
  31. package/dist/cjs/environment-B7EnozSg.cjs +135 -0
  32. package/dist/cjs/{index-B5gJ-q4U.d.cts → index-CzReNwbF.d.cts} +17 -12
  33. package/dist/cjs/index.cjs +250 -0
  34. package/dist/cjs/index.d.cts +217 -0
  35. package/dist/cjs/{config-D-s0GSep.cjs → index.node-Dz4lV4qe.cjs} +119 -35
  36. package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
  37. package/dist/cjs/management/index.cjs +1 -1
  38. package/dist/cjs/management/index.d.cts +1 -1
  39. package/dist/cjs/{management-Dehz9qSJ.cjs → management-B9ItB80R.cjs} +385 -582
  40. package/dist/cjs/{openapi-Cux6K4ZD.cjs → openapi-CwytYdWl.cjs} +476 -600
  41. package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
  42. package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
  43. package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
  44. package/dist/cjs/{validate-oAOpyFyb.cjs → validate-BfxhZ5Wv.cjs} +20 -20
  45. package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
  46. package/dist/es/actions/app-config/index.d.mts +1 -1
  47. package/dist/es/actions/app-config/index.mjs +39 -36
  48. package/dist/es/actions/{registration → association}/index.d.mts +9 -13
  49. package/dist/es/actions/association/index.mjs +82 -0
  50. package/dist/es/actions/config/index.mjs +17 -28
  51. package/dist/es/actions/installation/index.d.mts +2 -2
  52. package/dist/es/actions/installation/index.mjs +69 -48
  53. package/dist/es/actions/scope-tree/index.mjs +14 -13
  54. package/dist/{cjs/app-DrYHK-z1.d.cts → es/app-D3P-Z6uY.d.mts} +1085 -1035
  55. package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
  56. package/dist/es/commands/index.mjs +544 -328
  57. package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
  58. package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
  59. package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
  60. package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  61. package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  62. package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  63. package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  64. package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
  65. package/dist/es/commands/templates/app-management/association.js.template +6 -0
  66. package/dist/es/commands/templates/app-management/installation.js.template +1 -13
  67. package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
  68. package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
  69. package/dist/es/config/index.browser.d.mts +16 -0
  70. package/dist/es/config/index.browser.mjs +17 -0
  71. package/dist/es/config/{index.d.mts → index.node.d.mts} +954 -386
  72. package/dist/es/config/{index.mjs → index.node.mjs} +5 -4
  73. package/dist/es/define-EoYRZbpe.d.mts +34 -0
  74. package/dist/es/define-Z_Glf1-_.mjs +35 -0
  75. package/dist/es/environment-C84BPRJZ.mjs +104 -0
  76. package/dist/es/{index-DLMbTtKS.d.mts → index-D52xglhZ.d.mts} +17 -12
  77. package/dist/es/index.d.mts +217 -0
  78. package/dist/es/index.mjs +242 -0
  79. package/dist/es/{config-3I4eLyyR.mjs → index.node-CDH5gwJE.mjs} +94 -30
  80. package/dist/es/management/index.d.mts +1 -1
  81. package/dist/es/management/index.mjs +1 -1
  82. package/dist/es/{management-BUX-w2Ji.mjs → management-B89ApQVY.mjs} +353 -550
  83. package/dist/es/{openapi-B6uP0SRn.mjs → openapi-CXonvevE.mjs} +476 -600
  84. package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
  85. package/dist/es/utils-_gj8L6eN.mjs +289 -0
  86. package/dist/es/{validate-Dfajrp99.mjs → validate-9cRZWGrA.mjs} +17 -17
  87. package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
  88. package/package.json +40 -17
  89. package/dist/cjs/actions/registration/index.cjs +0 -50
  90. package/dist/cjs/admin-ui-sdk-EU915zlR.d.cts +0 -664
  91. package/dist/es/actions/registration/index.mjs +0 -49
  92. package/dist/es/admin-ui-sdk-BwnD0xjK.d.mts +0 -664
  93. /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
@@ -12,10 +12,12 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { i as requiresInstallationFromDomains, o as getConfigDomains, t as validateCommerceAppConfig, u as hasBusinessConfigSchema } from "../../validate-Dfajrp99.mjs";
16
- import { n as logger, t as HttpActionRouter } from "../../router-D58JJHHA.mjs";
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-9cRZWGrA.mjs";
17
+ import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
17
18
  import { resolveBusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
18
19
  import * as v from "valibot";
20
+ import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
19
21
  import { internalServerError, ok } from "@adobe/aio-commerce-lib-core/responses";
20
22
  import { createHash } from "crypto";
21
23
 
@@ -24,7 +26,7 @@ import { createHash } from "crypto";
24
26
  * Loads the committed OpenAPI spec via dynamic import so it
25
27
  * lands in its own chunk and is not parsed on every cold start.
26
28
  */
27
- const importOpenApi = () => import("../../openapi-B6uP0SRn.mjs");
29
+ const importOpenApi = () => import("../../openapi-CXonvevE.mjs");
28
30
  /** Matches component schema `$ref` strings, capturing the schema name. */
29
31
  const SCHEMA_REF_PATTERN = /"#\/components\/schemas\/(\w+)"/g;
30
32
  /**
@@ -65,7 +67,7 @@ function pruneUnusedSchemas(spec) {
65
67
  function pruneUnusedTags(spec) {
66
68
  const usedTags = /* @__PURE__ */ new Set();
67
69
  for (const pathItem of Object.values(spec.paths)) for (const operation of Object.values(pathItem)) for (const tag of operation.tags ?? []) usedTags.add(tag);
68
- for (let i = spec.tags.length - 1; i >= 0; i--) if (!usedTags.has(spec.tags[i].name)) spec.tags.splice(i, 1);
70
+ for (let i = spec.tags.length - 1; i >= 0; i -= 1) if (!usedTags.has(spec.tags[i].name)) spec.tags.splice(i, 1);
69
71
  }
70
72
  /**
71
73
  * Computes a short hash identifying the spec served for the given config domains.
@@ -75,7 +77,7 @@ function pruneUnusedTags(spec) {
75
77
  * @param domains - The active config domains.
76
78
  */
77
79
  function getOpenApiCacheKey(domains) {
78
- const input = `1.7.0:${[...domains].sort().join(",")}:1.0.0`;
80
+ const input = `1.8.0-beta-20260714082406:${[...domains].sort().join(",")}:2.0.0`;
79
81
  return createHash("sha256").update(input).digest("hex").slice(0, 8);
80
82
  }
81
83
  /** Returns the server URL to be set in the OpenAPI spec, based on the current namespace. */
@@ -108,10 +110,6 @@ async function buildOpenApiSpec(domains, logger) {
108
110
  stripPath("/scope-tree");
109
111
  stripPath("/scope-tree/commerce");
110
112
  }
111
- if (!domains.has("adminUiSdk")) {
112
- logger.debug("Application doesn't define Admin UI SDK registration, stripping references...");
113
- stripPath("/registration");
114
- }
115
113
  if (!requiresInstallationFromDomains(domains)) {
116
114
  logger.debug("Application doesn't require installation, stripping references...");
117
115
  stripPath("/installation");
@@ -135,37 +133,41 @@ async function buildOpenApiSpec(domains, logger) {
135
133
  */
136
134
  const router = new HttpActionRouter().use(logger({ name: () => "app-config" }));
137
135
  /** GET / - Get app config */
138
- router.get("/", { handler: async (_req, { logger, rawParams }) => {
139
- const rawAppConfig = rawParams.appConfig;
140
- if (!rawAppConfig) return internalServerError("The app config is missing. Does the action receive it as a parameter?");
141
- let appConfig = rawAppConfig;
142
- if (hasBusinessConfigSchema(rawAppConfig)) {
143
- logger.debug("Resolving business config schema...");
144
- const schema = await resolveBusinessConfigSchema(rawAppConfig.businessConfig.schema, rawParams);
145
- appConfig = {
146
- ...rawAppConfig,
147
- businessConfig: {
148
- ...rawAppConfig.businessConfig,
149
- schema
150
- }
151
- };
152
- }
153
- logger.debug("Validating app config...");
154
- const config = validateCommerceAppConfig(appConfig);
155
- logger.debug("Successfully validated the app config");
156
- const domains = getConfigDomains(rawParams.appConfig);
157
- const openApiSpecUrl = `${getServerUrl()}/app-config/openapi.json?ck=${getOpenApiCacheKey(domains)}`;
158
- return ok({ body: {
159
- ...config,
160
- openApiSpecUrl
161
- } });
162
- } });
136
+ router.get("/", {
137
+ handler: async (req, { logger, rawParams }) => {
138
+ const rawAppConfig = rawParams.appConfig;
139
+ if (!rawAppConfig) return internalServerError("The app config is missing. Does the action receive it as a parameter?");
140
+ let appConfig = rawAppConfig;
141
+ if (hasBusinessConfigSchema(rawAppConfig)) {
142
+ logger.debug("Resolving business config schema...");
143
+ const schema = await resolveBusinessConfigSchema(rawAppConfig.businessConfig.schema, rawParams);
144
+ appConfig = {
145
+ ...rawAppConfig,
146
+ businessConfig: {
147
+ ...rawAppConfig.businessConfig,
148
+ schema
149
+ }
150
+ };
151
+ }
152
+ logger.debug("Validating app config...");
153
+ const validatedConfig = validateCommerceAppConfig(appConfig);
154
+ logger.debug("Successfully validated the app config");
155
+ const { commerceEnv } = req.query;
156
+ const config = commerceEnv ? filterAppConfigByEnv(validatedConfig, commerceEnv) : validatedConfig;
157
+ const domains = getConfigDomains(rawParams.appConfig);
158
+ const openApiSpecUrl = `${getServerUrl()}/app-config/openapi.json?ck=${getOpenApiCacheKey(domains)}`;
159
+ return ok({ body: {
160
+ ...config,
161
+ openApiSpecUrl
162
+ } });
163
+ },
164
+ query: v.object({ commerceEnv: v.optional(CommerceEnvSchema) })
165
+ });
163
166
  /**
164
167
  * GET /openapi.json - Returns the OpenAPI spec for all SDK actions
165
168
  * @internal - Do not add to OpenAPI Spec.
166
169
  */
167
170
  router.get("/openapi.json", {
168
- query: v.object({ ck: v.optional(v.string()) }),
169
171
  handler: async (req, { logger, rawParams }) => {
170
172
  const { ck } = req.query;
171
173
  const domains = getConfigDomains(rawParams.appConfig);
@@ -177,7 +179,8 @@ router.get("/openapi.json", {
177
179
  });
178
180
  }
179
181
  return ok({ body: await buildOpenApiSpec(domains, logger) });
180
- }
182
+ },
183
+ query: v.object({ ck: v.optional(v.string()) })
181
184
  });
182
185
 
183
186
  //#endregion
@@ -12,21 +12,17 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as AdminUiSdkRegistration } from "../../admin-ui-sdk-BwnD0xjK.mjs";
16
15
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
17
16
 
18
- //#region source/actions/registration/router.d.ts
19
- /** The arguments required to create the runtime action for the registration action. */
20
- type RuntimeActionFactoryArgs = {
21
- registration: AdminUiSdkRegistration;
22
- };
23
- //#endregion
24
- //#region source/actions/registration/index.d.ts
17
+ //#region source/actions/association/index.d.ts
25
18
  /**
26
- * Factory to create the route handler for the `registration` action.
27
- * @param args - The arguments required to create the runtime action.
28
- * @experimental
19
+ * Factory to create the route handler for the `association` action.
20
+ *
21
+ * The `association` action manages the lifecycle of the Commerce instance the
22
+ * app is associated with — `POST /` stores the data when the app is associated,
23
+ * and `DELETE /` clears it on unassociation. Runtime actions consume the data
24
+ * via `getCommerceInstance` / `getCommerceClient` from the root entrypoint.
29
25
  */
30
- declare const registrationRuntimeAction: (args: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
26
+ declare const associationRuntimeAction: () => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
31
27
  //#endregion
32
- export { registrationRuntimeAction };
28
+ export { associationRuntimeAction };
@@ -0,0 +1,82 @@
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 { r as setAssociationData, t as clearAssociationData } from "../../association-repository-BbQv9WCl.mjs";
16
+ import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
17
+ import * as v from "valibot";
18
+ import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
19
+ import { noContent } from "@adobe/aio-commerce-lib-core/responses";
20
+
21
+ //#region source/actions/association/schema.ts
22
+ /** Request body for POST / — store association data. */
23
+ const AssociationRequestBodySchema = v.object({
24
+ commerceBaseUrl: v.pipe(v.string(), v.url("The 'commerceBaseUrl' field must be a valid absolute URL (e.g., 'https://my-store.example.com')")),
25
+ commerceEnv: CommerceEnvSchema
26
+ });
27
+
28
+ //#endregion
29
+ //#region source/actions/association/router.ts
30
+ /**
31
+ * Association action router.
32
+ *
33
+ * Routes:
34
+ * - POST / Store Commerce instance details (`baseUrl`, `env`)
35
+ * - DELETE / Clear stored Commerce instance details
36
+ */
37
+ const router = new HttpActionRouter().use(logger({ name: () => "association" }));
38
+ /**
39
+ * POST / - Store association data.
40
+ *
41
+ * Persists the Commerce instance the app is associated with so runtime actions
42
+ * can later retrieve it via `getCommerceInstance` / `getCommerceClient`.
43
+ */
44
+ router.post("/", {
45
+ body: AssociationRequestBodySchema,
46
+ handler: async (req, { logger }) => {
47
+ const { commerceBaseUrl, commerceEnv } = req.body;
48
+ logger.debug(`Storing association data (baseUrl: "${commerceBaseUrl}", env: "${commerceEnv}")`);
49
+ await setAssociationData({
50
+ baseUrl: commerceBaseUrl,
51
+ env: commerceEnv
52
+ });
53
+ return noContent();
54
+ }
55
+ });
56
+ /**
57
+ * DELETE / - Clear association data.
58
+ *
59
+ * Called when the app is unassociated.
60
+ */
61
+ router.delete("/", { handler: async (_req, { logger }) => {
62
+ logger.debug("Clearing association data");
63
+ await clearAssociationData();
64
+ return noContent();
65
+ } });
66
+
67
+ //#endregion
68
+ //#region source/actions/association/index.ts
69
+ /**
70
+ * Factory to create the route handler for the `association` action.
71
+ *
72
+ * The `association` action manages the lifecycle of the Commerce instance the
73
+ * app is associated with — `POST /` stores the data when the app is associated,
74
+ * and `DELETE /` clears it on unassociation. Runtime actions consume the data
75
+ * via `getCommerceInstance` / `getCommerceClient` from the root entrypoint.
76
+ */
77
+ const associationRuntimeAction = () => async (params) => {
78
+ return await router.handler()({ ...params });
79
+ };
80
+
81
+ //#endregion
82
+ export { associationRuntimeAction };
@@ -13,9 +13,11 @@
13
13
  */
14
14
 
15
15
  import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
16
- import { n as logger, t as HttpActionRouter } from "../../router-D58JJHHA.mjs";
16
+ import { r as filterSchemaByEnv } from "../../environment-C84BPRJZ.mjs";
17
+ import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
17
18
  import { byScopeId, getConfiguration, initialize, setConfiguration } from "@adobe/aio-commerce-lib-config";
18
19
  import * as v from "valibot";
20
+ import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
19
21
  import { ok } from "@adobe/aio-commerce-lib-core/responses";
20
22
 
21
23
  //#region source/actions/config/schema.ts
@@ -24,45 +26,32 @@ const AcceptedConfigurationValuesSchema = v.union([
24
26
  v.string(),
25
27
  v.array(v.string())
26
28
  ]);
27
- /** The set of valid Commerce environments a configuration field can be scoped to. */
28
- const COMMERCE_ENVS = ["paas", "saas"];
29
29
  /** Query parameters for GET / */
30
30
  const GetConfigurationQuerySchema = v.object({
31
- scopeId: nonEmptyStringValueSchema("scopeId"),
32
- commerceEnv: v.optional(v.picklist(COMMERCE_ENVS))
31
+ commerceEnv: v.optional(CommerceEnvSchema),
32
+ scopeId: nonEmptyStringValueSchema("scopeId")
33
33
  });
34
34
  /** Request body for PUT / */
35
35
  const PutConfigBodySchema = v.object({
36
- scopeId: nonEmptyStringValueSchema("scopeId"),
37
36
  config: v.array(v.object({
38
37
  name: nonEmptyStringValueSchema("config[i].name"),
39
38
  value: v.union([v.string(), v.array(v.string())])
40
- }))
39
+ })),
40
+ scopeId: nonEmptyStringValueSchema("scopeId")
41
41
  });
42
42
  /** Request body for PATCH / */
43
43
  const PatchConfigBodySchema = v.object({
44
- scopeId: nonEmptyStringValueSchema("scopeId"),
45
44
  config: v.array(v.object({
46
45
  name: nonEmptyStringValueSchema("config[i].name"),
47
46
  value: v.nullable(AcceptedConfigurationValuesSchema)
48
- }))
47
+ })),
48
+ scopeId: nonEmptyStringValueSchema("scopeId")
49
49
  });
50
50
 
51
51
  //#endregion
52
52
  //#region source/actions/config/router.ts
53
53
  const MASKED_PASSWORD_VALUE = "*****";
54
54
  /**
55
- * Filters a business configuration schema to the fields applicable to the
56
- * given Commerce environment. Fields without an `env` property apply to all
57
- * environments and are always included.
58
- *
59
- * @param schema - The business configuration schema to filter.
60
- * @param env - The Commerce environment to filter by.
61
- */
62
- function filterSchemaByEnv(schema, env) {
63
- return schema.filter((field) => field.env === void 0 || field.env.includes(env));
64
- }
65
- /**
66
55
  * Filters password fields from the configuration values.
67
56
  *
68
57
  * @param schema - The schema to use to filter the values.
@@ -88,7 +77,6 @@ function filterPasswordFields(schema, values) {
88
77
  const router = new HttpActionRouter().use(logger({ name: () => "config" }));
89
78
  /** GET / - Retrieve configuration */
90
79
  router.get("/", {
91
- query: GetConfigurationQuerySchema,
92
80
  handler: async (req, ctx) => {
93
81
  const { logger, rawParams } = ctx;
94
82
  const { configSchema: rawConfigSchema } = rawParams;
@@ -96,8 +84,8 @@ router.get("/", {
96
84
  const envFilteredSchema = env ? filterSchemaByEnv(rawConfigSchema, env) : rawConfigSchema;
97
85
  logger.debug("Initializing configuration");
98
86
  const { configSchema } = await initialize({
99
- schema: envFilteredSchema,
100
- params: rawParams
87
+ params: rawParams,
88
+ schema: envFilteredSchema
101
89
  });
102
90
  const { scopeId } = req.query;
103
91
  logger.debug(`Retrieving configuration with scope id: ${scopeId}`);
@@ -108,7 +96,8 @@ router.get("/", {
108
96
  schema: configSchema,
109
97
  values: appConfiguration
110
98
  } });
111
- }
99
+ },
100
+ query: GetConfigurationQuerySchema
112
101
  });
113
102
  /**
114
103
  * PUT / - Set configuration (deprecated)
@@ -123,8 +112,8 @@ router.put("/", {
123
112
  logger.debug(`Setting configuration with scope id: ${req.body.scopeId}`);
124
113
  const { scopeId, config } = req.body;
125
114
  const { configSchema } = await initialize({
126
- schema: rawParams.configSchema,
127
- params: rawParams
115
+ params: rawParams,
116
+ schema: rawParams.configSchema
128
117
  });
129
118
  const result = await setConfiguration({ config: config.filter((item) => item.value !== MASKED_PASSWORD_VALUE) }, byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
130
119
  result.config = filterPasswordFields(configSchema, result.config);
@@ -145,8 +134,8 @@ router.patch("/", {
145
134
  logger.debug(`Patching configuration with scope id: ${req.body.scopeId}`);
146
135
  const { scopeId, config } = req.body;
147
136
  const { configSchema } = await initialize({
148
- schema: rawParams.configSchema,
149
- params: rawParams
137
+ params: rawParams,
138
+ schema: rawParams.configSchema
150
139
  });
151
140
  const result = await setConfiguration({ config }, byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
152
141
  result.config = filterPasswordFields(configSchema, result.config);
@@ -12,8 +12,8 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as CommerceAppConfig, r as CommerceAppConfigOutputModel } from "../../app-DrYHK-z1.mjs";
16
- import { Y as InstallationContext } from "../../index-DLMbTtKS.mjs";
15
+ import { n as CommerceAppConfig, r as CommerceAppConfigOutputModel } from "../../app-D3P-Z6uY.mjs";
16
+ import { Y as InstallationContext } from "../../index-D52xglhZ.mjs";
17
17
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
18
18
 
19
19
  //#region source/actions/installation/router.d.ts
@@ -13,13 +13,14 @@
13
13
  */
14
14
 
15
15
  import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
16
- import { a as runValidation, c as isFailedState, i as runUninstallation, l as isInProgressState, n as createInitialUninstallationState, r as runInstallation, s as isCompletedState, t as createInitialInstallationState, u as isSucceededState } from "../../management-BUX-w2Ji.mjs";
17
- import { t as validateCommerceAppConfig } from "../../validate-Dfajrp99.mjs";
18
- import { n as logger, t as HttpActionRouter } from "../../router-D58JJHHA.mjs";
16
+ import { t as validateCommerceAppConfig } from "../../validate-9cRZWGrA.mjs";
17
+ import { a as runValidation, c as isFailedState, i as runUninstallation, l as isInProgressState, n as createInitialUninstallationState, r as runInstallation, s as isCompletedState, t as createInitialInstallationState, u as isSucceededState } from "../../management-B89ApQVY.mjs";
18
+ import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
19
+ import { init } from "@adobe/aio-lib-state";
19
20
  import * as v from "valibot";
21
+ import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
20
22
  import { accepted, badRequest, conflict, internalServerError, noContent, ok } from "@adobe/aio-commerce-lib-core/responses";
21
- import { init } from "@adobe/aio-lib-files";
22
- import { init as init$1 } from "@adobe/aio-lib-state";
23
+ import { init as init$1 } from "@adobe/aio-lib-files";
23
24
  import openwhisk from "openwhisk";
24
25
 
25
26
  //#region ../../packages-private/common-utils/source/storage/files-store.ts
@@ -51,12 +52,15 @@ const DEFAULT_DIR_PREFIX = "store";
51
52
  */
52
53
  async function createFilesStore(options = {}) {
53
54
  const { dirPrefix = DEFAULT_DIR_PREFIX } = options;
54
- return new FilesStore(await init(), dirPrefix);
55
+ const files = await init$1();
56
+ return new FilesStore(files, dirPrefix);
55
57
  }
56
58
  /**
57
59
  * Key-value store implementation using @adobe/aio-lib-files.
58
60
  */
59
61
  var FilesStore = class {
62
+ files;
63
+ dirPrefix;
60
64
  constructor(files, dirPrefix) {
61
65
  this.files = files;
62
66
  this.dirPrefix = dirPrefix;
@@ -121,12 +125,16 @@ const DEFAULT_KEY_PREFIX = "store";
121
125
  */
122
126
  async function createStateStore(options = {}) {
123
127
  const { keyPrefix = DEFAULT_KEY_PREFIX, ttlSeconds = DEFAULT_TTL_SECONDS } = options;
124
- return new StateStore(await init$1(), keyPrefix, ttlSeconds);
128
+ const state = await init();
129
+ return new StateStore(state, keyPrefix, ttlSeconds);
125
130
  }
126
131
  /**
127
132
  * Key-value store implementation using @adobe/aio-lib-state.
128
133
  */
129
134
  var StateStore = class {
135
+ state;
136
+ keyPrefix;
137
+ ttlSeconds;
130
138
  constructor(state, keyPrefix, ttlSeconds) {
131
139
  this.state = state;
132
140
  this.keyPrefix = keyPrefix;
@@ -216,6 +224,9 @@ async function createCombinedStore(options = {}) {
216
224
  * Uses lib-state for cache and lib-files for persistence.
217
225
  */
218
226
  var CombinedStore = class {
227
+ cache;
228
+ persistent;
229
+ shouldPersist;
219
230
  constructor(cache, persistent, shouldPersist) {
220
231
  this.cache = cache;
221
232
  this.persistent = persistent;
@@ -236,7 +247,7 @@ var CombinedStore = class {
236
247
  if (!this.shouldPersist || this.shouldPersist(data)) await this.persistent.put(key, data);
237
248
  }
238
249
  async delete(key) {
239
- const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete?.(key) ?? Promise.resolve(false), this.persistent.delete?.(key) ?? Promise.resolve(false)]);
250
+ const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete(key), this.persistent.delete(key)]);
240
251
  return cacheDeleted || persistentDeleted;
241
252
  }
242
253
  };
@@ -261,9 +272,9 @@ const AppDataSchema = v.object({
261
272
  const InstallationRequestBodySchema = v.object({
262
273
  appData: AppDataSchema,
263
274
  commerceBaseUrl: v.string(),
264
- commerceEnv: v.string(),
265
- ioEventsUrl: v.string(),
266
- ioEventsEnv: v.string()
275
+ commerceEnv: CommerceEnvSchema,
276
+ ioEventsEnv: v.string(),
277
+ ioEventsUrl: v.string()
267
278
  });
268
279
 
269
280
  //#endregion
@@ -298,11 +309,11 @@ function getStorageKey() {
298
309
  function buildWorkflowParams(body, rawParams) {
299
310
  return {
300
311
  ...rawParams,
301
- appData: body.appData,
302
- AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
303
- AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
304
312
  AIO_COMMERCE_API_BASE_URL: body.commerceBaseUrl,
305
- AIO_COMMERCE_API_FLAVOR: body.commerceEnv
313
+ AIO_COMMERCE_API_FLAVOR: body.commerceEnv,
314
+ AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
315
+ AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
316
+ appData: body.appData
306
317
  };
307
318
  }
308
319
  /**
@@ -312,9 +323,9 @@ function buildWorkflowParams(body, rawParams) {
312
323
  function buildInstallationContext(params, appConfig, logFn) {
313
324
  return {
314
325
  appData: params.appData,
315
- params,
326
+ customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {},
316
327
  logger: logFn,
317
- customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {}
328
+ params
318
329
  };
319
330
  }
320
331
  /**
@@ -339,12 +350,12 @@ function createInstallationHooks(store, logFn) {
339
350
  await store.put(getStorageKey(), data);
340
351
  };
341
352
  return {
342
- onInstallationStart: (state) => logAndSave("Installation started", state),
343
353
  onInstallationFailure: (state) => logAndSave("Installation failed", state),
354
+ onInstallationStart: (state) => logAndSave("Installation started", state),
344
355
  onInstallationSuccess: (state) => logAndSave(state.status === "succeeded" && state.metadata?.isRetry ? "Installation succeeded on retry" : "Installation succeeded", state),
356
+ onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state),
345
357
  onStepStart: (event, state) => logAndSave(`Step started: ${event.stepName}`, state),
346
- onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state),
347
- onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state)
358
+ onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state)
348
359
  };
349
360
  }
350
361
  /**
@@ -408,21 +419,21 @@ router.post("/", {
408
419
  const ow = openwhisk();
409
420
  const mergedParams = buildWorkflowParams(req.body, rawParams);
410
421
  const activation = await ow.actions.invoke({
411
- name: DEFAULT_ACTION_NAME,
412
422
  blocking: false,
413
- result: false,
423
+ name: DEFAULT_ACTION_NAME,
414
424
  params: {
415
425
  ...mergedParams,
416
- initialState,
417
- appConfig,
426
+ __ow_method: "post",
418
427
  __ow_path: "/execution",
419
- __ow_method: "post"
420
- }
428
+ appConfig,
429
+ initialState
430
+ },
431
+ result: false
421
432
  });
422
433
  logger.debug(`Async execution started: ${activation.activationId}`);
423
434
  return accepted({ body: {
424
- message: "Installation started",
425
435
  activationId: activation.activationId,
436
+ message: "Installation started",
426
437
  ...initialState
427
438
  } });
428
439
  }
@@ -445,16 +456,16 @@ router.post("/execution", { handler: async (_req, { logger, rawParams }) => {
445
456
  const installationContext = buildInstallationContext(params, appConfig, logger);
446
457
  logger.debug(`Executing installation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
447
458
  const result = await runInstallation({
448
- installationContext,
449
459
  config: appConfig,
460
+ hooks,
450
461
  initialState,
451
- hooks
462
+ installationContext
452
463
  });
453
464
  await store.put(getStorageKey(), result);
454
465
  logger.debug(`Installation completed: ${result.status}`);
455
466
  if (isFailedState(result)) return internalServerError({ body: {
456
- message: "Installation failed",
457
467
  error: result.error,
468
+ message: "Installation failed",
458
469
  state: result
459
470
  } });
460
471
  return ok({ body: result });
@@ -480,12 +491,12 @@ router.post("/validation", {
480
491
  const appConfig = validateCommerceAppConfig(rawAppConfig);
481
492
  const { appData, ...params } = buildWorkflowParams(req.body, rawParams);
482
493
  const result = await runValidation({
494
+ config: appConfig,
483
495
  validationContext: {
484
496
  appData,
485
- params,
486
- logger
487
- },
488
- config: appConfig
497
+ logger,
498
+ params
499
+ }
489
500
  });
490
501
  logger.debug(`Validation complete — valid: ${result.valid}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}`);
491
502
  return ok({ body: result });
@@ -515,35 +526,36 @@ router.post("/uninstallation", {
515
526
  handler: async (req, { logger, rawParams }) => {
516
527
  const { appData, commerceBaseUrl } = req.body;
517
528
  logger.debug(`Starting uninstallation for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${commerceBaseUrl}")`);
518
- const rawAppConfig = rawParams.appConfig;
519
- if (!rawAppConfig) return internalServerError("The app config is missing. Does the action receive it as a parameter?");
520
- const appConfig = validateCommerceAppConfig(rawAppConfig);
521
529
  const store = await createUninstallationStore();
522
530
  const existingState = await store.get(getStorageKey());
523
531
  if (existingState && isInProgressState(existingState)) {
524
532
  logger.debug(`Uninstallation already in progress: ${existingState.status}`);
525
533
  return conflict("Uninstallation is already in progress. Wait for it to complete.");
526
534
  }
527
- const initialState = createInitialUninstallationState({ config: appConfig });
535
+ const installAppConfig = (await getInstallationSnapshot())?.config;
536
+ const uninstallConfig = installAppConfig ?? rawParams.appConfig;
537
+ if (!uninstallConfig) return internalServerError("Cannot determine what to uninstall: no recorded installation snapshot and no app config was provided.");
538
+ logger.debug(installAppConfig ? "Sourcing uninstallation from recorded install snapshot" : "No recorded install config found; falling back to request config");
539
+ const initialState = createInitialUninstallationState({ config: validateCommerceAppConfig(uninstallConfig) });
528
540
  logger.debug(`Created initial uninstall state: ${initialState.id}`);
529
541
  await store.put(getStorageKey(), initialState);
530
542
  const workflowParams = buildWorkflowParams(req.body, rawParams);
531
543
  const activation = await openwhisk().actions.invoke({
532
- name: DEFAULT_ACTION_NAME,
533
544
  blocking: false,
534
- result: false,
545
+ name: DEFAULT_ACTION_NAME,
535
546
  params: {
536
547
  ...workflowParams,
537
- initialState,
538
- appConfig,
548
+ __ow_method: "post",
539
549
  __ow_path: "/uninstallation/execution",
540
- __ow_method: "post"
541
- }
550
+ appConfig: uninstallConfig,
551
+ initialState
552
+ },
553
+ result: false
542
554
  });
543
555
  logger.debug(`Async uninstallation started: ${activation.activationId}`);
544
556
  return accepted({ body: {
545
- message: "Uninstallation started",
546
557
  activationId: activation.activationId,
558
+ message: "Uninstallation started",
547
559
  ...initialState
548
560
  } });
549
561
  }
@@ -570,10 +582,10 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
570
582
  const installationContext = buildInstallationContext(params, appConfig, logger);
571
583
  logger.debug(`Executing uninstallation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
572
584
  const result = await runUninstallation({
573
- installationContext,
574
585
  config: appConfig,
586
+ hooks,
575
587
  initialState,
576
- hooks
588
+ installationContext
577
589
  });
578
590
  await store.put(getStorageKey(), result);
579
591
  logger.debug(`Uninstallation completed: ${result.status}`);
@@ -582,8 +594,8 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
582
594
  logger.debug("Cleared installation state after successful uninstallation");
583
595
  }
584
596
  if (isFailedState(result)) return internalServerError({ body: {
585
- message: "Uninstallation failed",
586
597
  error: result.error,
598
+ message: "Uninstallation failed",
587
599
  state: result
588
600
  } });
589
601
  return ok({ body: result });
@@ -599,6 +611,15 @@ router.delete("/uninstallation", { handler: async (_req, { logger }) => {
599
611
  logger.debug("Uninstallation state cleared");
600
612
  return noContent();
601
613
  } });
614
+ /**
615
+ * Returns the completed installation snapshot that recorded its config, or null
616
+ * when none is authoritative (no install, an in-progress install, or a legacy
617
+ * record persisted before the config was recorded).
618
+ */
619
+ async function getInstallationSnapshot() {
620
+ const installSnapshot = await (await createInstallationStore()).get(getStorageKey());
621
+ return installSnapshot && isCompletedState(installSnapshot) && installSnapshot.config ? installSnapshot : null;
622
+ }
602
623
 
603
624
  //#endregion
604
625
  //#region source/actions/installation/index.ts