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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cjs/actions/app-config/index.cjs +202 -0
  3. package/dist/cjs/actions/{app-config.d.cts → app-config/index.d.cts} +11 -9
  4. package/dist/cjs/actions/{config.cjs → config/index.cjs} +79 -46
  5. package/dist/{es/actions/config.d.mts → cjs/actions/config/index.d.cts} +10 -8
  6. package/dist/cjs/actions/{installation.cjs → installation/index.cjs} +55 -36
  7. package/dist/{es/actions/installation.d.mts → cjs/actions/installation/index.d.cts} +11 -10
  8. package/dist/cjs/actions/{registration.cjs → registration/index.cjs} +16 -7
  9. package/dist/cjs/actions/{registration.d.cts → registration/index.d.cts} +8 -9
  10. package/dist/cjs/actions/{scope-tree.cjs → scope-tree/index.cjs} +52 -15
  11. package/dist/{es/actions/scope-tree.d.mts → cjs/actions/scope-tree/index.d.cts} +2 -5
  12. package/dist/cjs/{admin-ui-sdk-BiSopnKI.d.cts → admin-ui-sdk-EU915zlR.d.cts} +7 -8
  13. package/dist/cjs/app-DrYHK-z1.d.cts +1629 -0
  14. package/dist/cjs/commands/index.cjs +241 -56
  15. package/dist/cjs/commands/templates/app-management/app-config.js.template +2 -2
  16. package/dist/cjs/config/index.cjs +3 -3
  17. package/dist/cjs/config/index.d.cts +181 -1158
  18. package/dist/cjs/{config-ct-qMOGj.cjs → config-D-s0GSep.cjs} +4 -6
  19. package/dist/cjs/{error-C5LNOZ4f.cjs → error-D-N0PKSl.cjs} +0 -1
  20. package/dist/cjs/{index-B5WKJ3hJ.d.cts → index-B5gJ-q4U.d.cts} +172 -3
  21. package/dist/cjs/index-BXm8UbK7.d.cts +16 -0
  22. package/dist/cjs/{logging-BTevALnL.cjs → logging-BVz3weoC.cjs} +1 -1
  23. package/dist/cjs/management/index.cjs +1 -1
  24. package/dist/cjs/management/index.d.cts +2 -3
  25. package/dist/cjs/{management-D1QXg4YU.cjs → management-Dehz9qSJ.cjs} +114 -51
  26. package/dist/cjs/openapi-Cux6K4ZD.cjs +3072 -0
  27. package/dist/cjs/{router-CFErodHU.cjs → router-BOR7T6qR.cjs} +1 -1
  28. package/dist/cjs/{schemas-CukVpc19.cjs → schemas-FngDuIeo.cjs} +1 -1
  29. package/dist/cjs/{validate-b_bI4mDb.cjs → validate-oAOpyFyb.cjs} +49 -17
  30. package/dist/cjs/{webhooks-DS1BtgED.cjs → webhooks-tbZy9G3p.cjs} +4 -4
  31. package/dist/es/actions/{app-config.d.mts → app-config/index.d.mts} +11 -9
  32. package/dist/es/actions/app-config/index.mjs +199 -0
  33. package/dist/{cjs/actions/config.d.cts → es/actions/config/index.d.mts} +10 -8
  34. package/dist/es/actions/{config.mjs → config/index.mjs} +78 -45
  35. package/dist/{cjs/actions/installation.d.cts → es/actions/installation/index.d.mts} +11 -10
  36. package/dist/es/actions/{installation.mjs → installation/index.mjs} +54 -36
  37. package/dist/es/actions/{registration.d.mts → registration/index.d.mts} +8 -9
  38. package/dist/es/actions/{registration.mjs → registration/index.mjs} +16 -6
  39. package/dist/{cjs/actions/scope-tree.d.cts → es/actions/scope-tree/index.d.mts} +2 -5
  40. package/dist/es/actions/{scope-tree.mjs → scope-tree/index.mjs} +51 -14
  41. package/dist/es/{admin-ui-sdk-CCo2SWiL.d.mts → admin-ui-sdk-BwnD0xjK.d.mts} +6 -9
  42. package/dist/es/app-DrYHK-z1.d.mts +1629 -0
  43. package/dist/es/commands/index.mjs +223 -38
  44. package/dist/es/commands/templates/app-management/app-config.js.template +2 -2
  45. package/dist/es/config/index.d.mts +181 -1157
  46. package/dist/es/config/index.mjs +3 -3
  47. package/dist/es/{config-DGPFTk6w.mjs → config-3I4eLyyR.mjs} +4 -5
  48. package/dist/es/index-B0XqHwY5.d.mts +16 -0
  49. package/dist/es/{index-CCov0odd.d.mts → index-DLMbTtKS.d.mts} +172 -3
  50. package/dist/es/management/index.d.mts +2 -3
  51. package/dist/es/management/index.mjs +1 -1
  52. package/dist/es/{management-CCsOfniv.mjs → management-BUX-w2Ji.mjs} +113 -51
  53. package/dist/es/openapi-B6uP0SRn.mjs +3024 -0
  54. package/dist/es/{validate-Dn3lLTGj.mjs → validate-Dfajrp99.mjs} +37 -17
  55. package/dist/es/{webhooks-Dhrkkip7.mjs → webhooks-B5oq9ULL.mjs} +3 -3
  56. package/package.json +29 -17
  57. package/dist/cjs/actions/app-config.cjs +0 -41
  58. package/dist/cjs/app-C6kImBl7.d.cts +0 -564
  59. package/dist/cjs/step-CWYnKbga.d.cts +0 -187
  60. package/dist/es/actions/app-config.mjs +0 -39
  61. package/dist/es/app-DcY6dJiQ.d.mts +0 -564
  62. package/dist/es/step-0eI2x4C9.d.mts +0 -187
  63. /package/dist/cjs/{chunk-DS2yp5vX.cjs → chunk-Cozy-1ZF.cjs} +0 -0
  64. /package/dist/es/{error-DHlYzkbb.mjs → error-_RMwtrUA.mjs} +0 -0
  65. /package/dist/es/{logging-XIUXDK5T.mjs → logging-DbJHXSKh.mjs} +0 -0
  66. /package/dist/es/{router-BxaxEEu3.mjs → router-D58JJHHA.mjs} +0 -0
  67. /package/dist/es/{schemas-DOcnD16x.mjs → schemas-hRovglBF.mjs} +0 -0
@@ -12,7 +12,7 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-DS2yp5vX.cjs');
15
+ const require_chunk = require('./chunk-Cozy-1ZF.cjs');
16
16
  let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
17
17
  let _adobe_aio_lib_core_logging = require("@adobe/aio-lib-core-logging");
18
18
  _adobe_aio_lib_core_logging = require_chunk.__toESM(_adobe_aio_lib_core_logging, 1);
@@ -12,7 +12,7 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-DS2yp5vX.cjs');
15
+ const require_chunk = require('./chunk-Cozy-1ZF.cjs');
16
16
  let valibot = require("valibot");
17
17
  valibot = require_chunk.__toESM(valibot, 1);
18
18
 
@@ -12,13 +12,13 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-DS2yp5vX.cjs');
16
- const require_schemas = require('./schemas-CukVpc19.cjs');
17
- const require_webhooks = require('./webhooks-DS1BtgED.cjs');
15
+ const require_chunk = require('./chunk-Cozy-1ZF.cjs');
16
+ const require_schemas = require('./schemas-FngDuIeo.cjs');
17
+ const require_webhooks = require('./webhooks-tbZy9G3p.cjs');
18
18
  let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
19
+ let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
19
20
  let valibot = require("valibot");
20
21
  valibot = require_chunk.__toESM(valibot, 1);
21
- let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
22
22
 
23
23
  //#region source/config/schema/business-configuration.ts
24
24
  /**
@@ -61,19 +61,6 @@ function hasMetadata(config) {
61
61
  return config.metadata !== void 0;
62
62
  }
63
63
 
64
- //#endregion
65
- //#region source/config/schema/app.ts
66
- /** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
67
- /** The schema used to validate the commerce app config file. */
68
- const CommerceAppConfigSchema = valibot.looseObject({
69
- metadata: MetadataSchema,
70
- businessConfig: valibot.optional(_adobe_aio_commerce_lib_config.SchemaBusinessConfig),
71
- eventing: valibot.optional(require_webhooks.EventingSchema),
72
- adminUiSdk: valibot.optional(require_webhooks.AdminUiSdkSchema),
73
- installation: valibot.optional(require_webhooks.InstallationSchema),
74
- webhooks: valibot.optional(require_webhooks.WebhooksSchema)
75
- });
76
-
77
64
  //#endregion
78
65
  //#region source/config/schema/domains.ts
79
66
  /** The individual validatable domains of the app config. */
@@ -120,6 +107,39 @@ function hasConfigDomain(config, domain) {
120
107
  return getConfigDomains(config).has(domain);
121
108
  }
122
109
 
110
+ //#endregion
111
+ //#region source/config/schema/app.ts
112
+ /** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
113
+ /** The schema used to validate the commerce app config file. */
114
+ const CommerceAppConfigSchema = valibot.looseObject({
115
+ metadata: MetadataSchema,
116
+ businessConfig: valibot.optional(_adobe_aio_commerce_lib_config.SchemaBusinessConfig),
117
+ eventing: valibot.optional(require_webhooks.EventingSchema),
118
+ adminUiSdk: valibot.optional(require_webhooks.AdminUiSdkSchema),
119
+ installation: valibot.optional(require_webhooks.InstallationSchema),
120
+ webhooks: valibot.optional(require_webhooks.WebhooksSchema)
121
+ });
122
+ /**
123
+ * Returns true if the given config domains require installation, false otherwise.
124
+ * @param domains - The config domains to check.
125
+ */
126
+ function requiresInstallationFromDomains(domains) {
127
+ return [
128
+ "installation.customInstallationSteps",
129
+ "eventing.commerce",
130
+ "eventing.external",
131
+ "webhooks",
132
+ "adminUiSdk"
133
+ ].some((feature) => domains.has(feature));
134
+ }
135
+ /**
136
+ * Returns true if the given config requires installation, false otherwise.
137
+ * @param config - The commerce app config to check.
138
+ */
139
+ function requiresInstallation(config) {
140
+ return requiresInstallationFromDomains(getConfigDomains(config));
141
+ }
142
+
123
143
  //#endregion
124
144
  //#region source/config/lib/validate.ts
125
145
  const commerceAppConfigDomainsSchema = valibot.picklist(Object.keys(CommerceAppConfigSchemas));
@@ -243,6 +263,18 @@ Object.defineProperty(exports, 'hasMetadata', {
243
263
  return hasMetadata;
244
264
  }
245
265
  });
266
+ Object.defineProperty(exports, 'requiresInstallation', {
267
+ enumerable: true,
268
+ get: function () {
269
+ return requiresInstallation;
270
+ }
271
+ });
272
+ Object.defineProperty(exports, 'requiresInstallationFromDomains', {
273
+ enumerable: true,
274
+ get: function () {
275
+ return requiresInstallationFromDomains;
276
+ }
277
+ });
246
278
  Object.defineProperty(exports, 'validateCommerceAppConfig', {
247
279
  enumerable: true,
248
280
  get: function () {
@@ -12,8 +12,8 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-DS2yp5vX.cjs');
16
- const require_schemas = require('./schemas-CukVpc19.cjs');
15
+ const require_chunk = require('./chunk-Cozy-1ZF.cjs');
16
+ const require_schemas = require('./schemas-FngDuIeo.cjs');
17
17
  let valibot = require("valibot");
18
18
  valibot = require_chunk.__toESM(valibot, 1);
19
19
 
@@ -294,8 +294,8 @@ const ExternalEventSourceSchema = valibot.object({
294
294
  });
295
295
  /** Schema for eventing configuration with separate commerce and external arrays */
296
296
  const EventingSchema = valibot.object({
297
- commerce: valibot.optional(valibot.array(CommerceEventSourceSchema, "Expected an array of Commerce event sources")),
298
- external: valibot.optional(valibot.array(ExternalEventSourceSchema, "Expected an array of external event sources"))
297
+ commerce: valibot.optional(valibot.pipe(valibot.array(CommerceEventSourceSchema, "Expected an array of Commerce event sources"), valibot.check((sources) => new Set(sources.map((s) => s.provider.label)).size === sources.length, "Commerce provider labels must be unique"))),
298
+ external: valibot.optional(valibot.pipe(valibot.array(ExternalEventSourceSchema, "Expected an array of external event sources"), valibot.check((sources) => new Set(sources.map((s) => s.provider.label)).size === sources.length, "External provider labels must be unique")))
299
299
  });
300
300
  /**
301
301
  * Check if config has commerce event sources.
@@ -12,18 +12,20 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as CommerceAppConfigOutputModel } from "../app-DcY6dJiQ.mjs";
16
- import * as _$_adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
15
+ import { n as CommerceAppConfig } from "../../app-DrYHK-z1.mjs";
17
16
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
18
17
 
19
- //#region source/actions/app-config.d.ts
20
- /** Arguments for the runtime action factory. */
18
+ //#region source/actions/app-config/router.d.ts
19
+ /** The arguments required to create the runtime action for the app-config action. */
21
20
  type RuntimeActionFactoryArgs = {
22
- appConfig: CommerceAppConfigOutputModel;
21
+ appConfig: CommerceAppConfig;
23
22
  };
24
- /** Factory to create the route handler for the `app-config` action. */
25
- declare const appConfigRuntimeAction: ({
26
- appConfig
27
- }: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<_$_adobe_aio_commerce_lib_core_responses0.ActionResponse>;
23
+ //#endregion
24
+ //#region source/actions/app-config/index.d.ts
25
+ /**
26
+ * Factory to create the route handler for the `app-config` action.
27
+ * @param args - The arguments required to create the runtime action.
28
+ */
29
+ declare const appConfigRuntimeAction: (args: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
28
30
  //#endregion
29
31
  export { appConfigRuntimeAction };
@@ -0,0 +1,199 @@
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 { 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";
17
+ import { resolveBusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
18
+ import * as v from "valibot";
19
+ import { internalServerError, ok } from "@adobe/aio-commerce-lib-core/responses";
20
+ import { createHash } from "crypto";
21
+
22
+ //#region source/actions/app-config/openapi.ts
23
+ /**
24
+ * Loads the committed OpenAPI spec via dynamic import so it
25
+ * lands in its own chunk and is not parsed on every cold start.
26
+ */
27
+ const importOpenApi = () => import("../../openapi-B6uP0SRn.mjs");
28
+ /** Matches component schema `$ref` strings, capturing the schema name. */
29
+ const SCHEMA_REF_PATTERN = /"#\/components\/schemas\/(\w+)"/g;
30
+ /**
31
+ * Collects the names of every component schema referenced via `$ref` in a value
32
+ * Scans the serialized JSON, so it catches refs at any depth.
33
+ *
34
+ * @param value - Any part of the spec to scan.
35
+ */
36
+ function collectSchemaRefs(value) {
37
+ return [...(JSON.stringify(value) ?? "").matchAll(SCHEMA_REF_PATTERN)].map((match) => match[1]);
38
+ }
39
+ /**
40
+ * Deletes component schemas not reachable from the remaining paths, in place.
41
+ *
42
+ * Follows `$ref`s transitively from `spec.paths`; the visited set handles
43
+ * recursive schemas (e.g. `ScopeNode`).
44
+ *
45
+ * @param spec - The spec to prune, after paths have been stripped.
46
+ */
47
+ function pruneUnusedSchemas(spec) {
48
+ const schemas = spec.components.schemas;
49
+ const reachable = new Set(collectSchemaRefs(spec.paths));
50
+ const pending = [...reachable];
51
+ while (pending.length > 0) {
52
+ const name = pending.pop();
53
+ if (name === void 0) continue;
54
+ for (const ref of collectSchemaRefs(schemas[name])) if (!reachable.has(ref)) {
55
+ reachable.add(ref);
56
+ pending.push(ref);
57
+ }
58
+ }
59
+ for (const name of Object.keys(schemas)) if (!reachable.has(name)) delete schemas[name];
60
+ }
61
+ /**
62
+ * Removes top-level tags no longer referenced by any remaining path operation, in place.
63
+ * @param spec - The spec to prune, after paths have been stripped.
64
+ */
65
+ function pruneUnusedTags(spec) {
66
+ const usedTags = /* @__PURE__ */ new Set();
67
+ 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);
69
+ }
70
+ /**
71
+ * Computes a short hash identifying the spec served for the given config domains.
72
+ * Changes whenever the served spec would: with the OpenAPI spec version (`info.version`),
73
+ * the package version, or the domains that drive pruning.
74
+ *
75
+ * @param domains - The active config domains.
76
+ */
77
+ function getOpenApiCacheKey(domains) {
78
+ const input = `1.7.0:${[...domains].sort().join(",")}:1.0.0`;
79
+ return createHash("sha256").update(input).digest("hex").slice(0, 8);
80
+ }
81
+ /** Returns the server URL to be set in the OpenAPI spec, based on the current namespace. */
82
+ function getServerUrl() {
83
+ return `https://${process.env.__OW_NAMESPACE}.adobeioruntime.net/api/v1/web/app-management`;
84
+ }
85
+ /**
86
+ * Builds the OpenAPI spec served by `GET /openapi.json`, tailored to the app's
87
+ * capabilities: unused paths are stripped, along with the schemas they leave
88
+ * unreferenced.
89
+ *
90
+ * Works on a fresh copy so the shared module import is never mutated. The
91
+ * committed `docs/openapi.json` always describes the full surface.
92
+ *
93
+ * @param domains - The active config domains that drive path trimming.
94
+ * @param logger - Logger used to report which paths get stripped.
95
+ */
96
+ async function buildOpenApiSpec(domains, logger) {
97
+ const { default: openAPISpec } = await importOpenApi();
98
+ const spec = structuredClone(openAPISpec);
99
+ const stripPath = (path) => {
100
+ if (spec.paths[path]) {
101
+ logger.debug(`Stripping OpenAPI spec path: ${path}`);
102
+ delete spec.paths[path];
103
+ }
104
+ };
105
+ if (!domains.has("businessConfig.schema")) {
106
+ logger.debug("Application doesn't define business configuration, stripping references...");
107
+ stripPath("/config");
108
+ stripPath("/scope-tree");
109
+ stripPath("/scope-tree/commerce");
110
+ }
111
+ if (!domains.has("adminUiSdk")) {
112
+ logger.debug("Application doesn't define Admin UI SDK registration, stripping references...");
113
+ stripPath("/registration");
114
+ }
115
+ if (!requiresInstallationFromDomains(domains)) {
116
+ logger.debug("Application doesn't require installation, stripping references...");
117
+ stripPath("/installation");
118
+ stripPath("/installation/validation");
119
+ stripPath("/installation/uninstallation");
120
+ }
121
+ pruneUnusedSchemas(spec);
122
+ pruneUnusedTags(spec);
123
+ spec.servers[0].url = getServerUrl();
124
+ return spec;
125
+ }
126
+
127
+ //#endregion
128
+ //#region source/actions/app-config/router.ts
129
+ /**
130
+ * App Config action router.
131
+ *
132
+ * Routes:
133
+ * - GET / Retrieve the Commerce App configuration.
134
+ * - GET /openapi.json Returns the OpenAPI spec for all SDK actions
135
+ */
136
+ const router = new HttpActionRouter().use(logger({ name: () => "app-config" }));
137
+ /** 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
+ } });
163
+ /**
164
+ * GET /openapi.json - Returns the OpenAPI spec for all SDK actions
165
+ * @internal - Do not add to OpenAPI Spec.
166
+ */
167
+ router.get("/openapi.json", {
168
+ query: v.object({ ck: v.optional(v.string()) }),
169
+ handler: async (req, { logger, rawParams }) => {
170
+ const { ck } = req.query;
171
+ const domains = getConfigDomains(rawParams.appConfig);
172
+ if (ck && getOpenApiCacheKey(domains) === ck) {
173
+ logger.debug(`Received request for OpenAPI spec with cache key query param: ${ck}`);
174
+ return ok({
175
+ body: await buildOpenApiSpec(domains, logger),
176
+ headers: { "Cache-Control": "public, max-age=31536000, immutable" }
177
+ });
178
+ }
179
+ return ok({ body: await buildOpenApiSpec(domains, logger) });
180
+ }
181
+ });
182
+
183
+ //#endregion
184
+ //#region source/actions/app-config/index.ts
185
+ /**
186
+ * Factory to create the route handler for the `app-config` action.
187
+ * @param args - The arguments required to create the runtime action.
188
+ */
189
+ const appConfigRuntimeAction = (args) => async (params) => {
190
+ const handler = router.handler();
191
+ const { appConfig } = args;
192
+ return await handler({
193
+ ...params,
194
+ appConfig
195
+ });
196
+ };
197
+
198
+ //#endregion
199
+ export { appConfigRuntimeAction };
@@ -12,18 +12,20 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import * as _$_adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
16
- import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
17
15
  import { BusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
16
+ import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
18
17
 
19
- //#region source/actions/config.d.ts
20
- /** 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. */
21
20
  type ConfigActionFactoryArgs = {
22
21
  configSchema: BusinessConfigSchema;
23
22
  };
24
- /** Factory to create the route handler for the `config` action. */
25
- declare const configRuntimeAction: ({
26
- configSchema
27
- }: ConfigActionFactoryArgs) => (params: RuntimeActionParams) => Promise<_$_adobe_aio_commerce_lib_core_responses0.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>;
28
30
  //#endregion
29
31
  export { configRuntimeAction };
@@ -12,21 +12,50 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as logger, t as HttpActionRouter } from "../router-BxaxEEu3.mjs";
16
- import { r as nonEmptyStringValueSchema } from "../schemas-DOcnD16x.mjs";
17
- import { n as validateCommerceAppConfigDomain } from "../validate-Dn3lLTGj.mjs";
18
- import { ok } from "@adobe/aio-commerce-lib-core/responses";
19
- import * as v from "valibot";
15
+ import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
16
+ import { n as logger, t as HttpActionRouter } from "../../router-D58JJHHA.mjs";
20
17
  import { byScopeId, getConfiguration, initialize, setConfiguration } from "@adobe/aio-commerce-lib-config";
18
+ import * as v from "valibot";
19
+ import { ok } from "@adobe/aio-commerce-lib-core/responses";
21
20
 
22
- //#region source/actions/config.ts
23
- const MASKED_PASSWORD_VALUE = "*****";
21
+ //#region source/actions/config/schema.ts
22
+ const AcceptedConfigurationValuesSchema = v.union([
23
+ v.boolean(),
24
+ v.string(),
25
+ v.array(v.string())
26
+ ]);
24
27
  /** The set of valid Commerce environments a configuration field can be scoped to. */
25
28
  const COMMERCE_ENVS = ["paas", "saas"];
29
+ /** Query parameters for GET / */
30
+ const GetConfigurationQuerySchema = v.object({
31
+ scopeId: nonEmptyStringValueSchema("scopeId"),
32
+ commerceEnv: v.optional(v.picklist(COMMERCE_ENVS))
33
+ });
34
+ /** Request body for PUT / */
35
+ const PutConfigBodySchema = v.object({
36
+ scopeId: nonEmptyStringValueSchema("scopeId"),
37
+ config: v.array(v.object({
38
+ name: nonEmptyStringValueSchema("config[i].name"),
39
+ value: v.union([v.string(), v.array(v.string())])
40
+ }))
41
+ });
42
+ /** Request body for PATCH / */
43
+ const PatchConfigBodySchema = v.object({
44
+ scopeId: nonEmptyStringValueSchema("scopeId"),
45
+ config: v.array(v.object({
46
+ name: nonEmptyStringValueSchema("config[i].name"),
47
+ value: v.nullable(AcceptedConfigurationValuesSchema)
48
+ }))
49
+ });
50
+
51
+ //#endregion
52
+ //#region source/actions/config/router.ts
53
+ const MASKED_PASSWORD_VALUE = "*****";
26
54
  /**
27
55
  * Filters a business configuration schema to the fields applicable to the
28
56
  * given Commerce environment. Fields without an `env` property apply to all
29
57
  * environments and are always included.
58
+ *
30
59
  * @param schema - The business configuration schema to filter.
31
60
  * @param env - The Commerce environment to filter by.
32
61
  */
@@ -35,9 +64,9 @@ function filterSchemaByEnv(schema, env) {
35
64
  }
36
65
  /**
37
66
  * Filters password fields from the configuration values.
67
+ *
38
68
  * @param schema - The schema to use to filter the values.
39
69
  * @param values - The values to filter.
40
- * @returns The filtered values.
41
70
  */
42
71
  function filterPasswordFields(schema, values) {
43
72
  return values.map((item) => {
@@ -48,51 +77,55 @@ function filterPasswordFields(schema, values) {
48
77
  return item;
49
78
  });
50
79
  }
51
- const router = new HttpActionRouter().use(logger());
80
+ /**
81
+ * Config action router.
82
+ *
83
+ * Routes:
84
+ * - GET / Get current configuration values for a given scope
85
+ * - POST / Set configuration (overrides all values for the scope) (deprecated)
86
+ * - PATCH / Partially update configuration (only updates provided fields, allows unsetting)
87
+ */
88
+ const router = new HttpActionRouter().use(logger({ name: () => "config" }));
52
89
  /** GET / - Retrieve configuration */
53
90
  router.get("/", {
54
- query: v.object({
55
- scopeId: nonEmptyStringValueSchema("scopeId"),
56
- commerceEnv: v.optional(v.picklist(COMMERCE_ENVS))
57
- }),
91
+ query: GetConfigurationQuerySchema,
58
92
  handler: async (req, ctx) => {
59
93
  const { logger, rawParams } = ctx;
60
- const configSchema = rawParams.configSchema;
61
- logger.debug("Validating configuration schema...");
62
- const validatedSchema = validateCommerceAppConfigDomain(configSchema, "businessConfig.schema");
94
+ const { configSchema: rawConfigSchema } = rawParams;
63
95
  const env = req.query.commerceEnv;
64
- const filteredSchema = env ? filterSchemaByEnv(validatedSchema, env) : validatedSchema;
65
- initialize({ schema: filteredSchema });
96
+ const envFilteredSchema = env ? filterSchemaByEnv(rawConfigSchema, env) : rawConfigSchema;
97
+ logger.debug("Initializing configuration");
98
+ const { configSchema } = await initialize({
99
+ schema: envFilteredSchema,
100
+ params: rawParams
101
+ });
66
102
  const { scopeId } = req.query;
67
103
  logger.debug(`Retrieving configuration with scope id: ${scopeId}`);
68
104
  const appConfiguration = await getConfiguration(byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
69
105
  logger.debug("Masking password values...");
70
- appConfiguration.config = filterPasswordFields(filteredSchema, appConfiguration.config);
106
+ appConfiguration.config = filterPasswordFields(configSchema, appConfiguration.config);
71
107
  return ok({ body: {
72
- schema: filteredSchema,
108
+ schema: configSchema,
73
109
  values: appConfiguration
74
110
  } });
75
111
  }
76
112
  });
77
113
  /**
78
114
  * PUT / - Set configuration (deprecated)
115
+ *
79
116
  * @deprecated Use PATCH instead. This endpoint overwrites all values for the scope
80
117
  * and does not support partial updates or unset semantics.
81
118
  */
82
119
  router.put("/", {
83
- body: v.object({
84
- scopeId: nonEmptyStringValueSchema("scopeId"),
85
- config: v.array(v.object({
86
- name: nonEmptyStringValueSchema("config.name"),
87
- value: v.union([v.string(), v.array(v.string())])
88
- }))
89
- }),
120
+ body: PutConfigBodySchema,
90
121
  handler: async (req, ctx) => {
91
122
  const { logger, rawParams } = ctx;
92
- const { configSchema } = rawParams;
93
123
  logger.debug(`Setting configuration with scope id: ${req.body.scopeId}`);
94
124
  const { scopeId, config } = req.body;
95
- initialize({ schema: validateCommerceAppConfigDomain(configSchema, "businessConfig.schema") });
125
+ const { configSchema } = await initialize({
126
+ schema: rawParams.configSchema,
127
+ params: rawParams
128
+ });
96
129
  const result = await setConfiguration({ config: config.filter((item) => item.value !== MASKED_PASSWORD_VALUE) }, byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
97
130
  result.config = filterPasswordFields(configSchema, result.config);
98
131
  return ok({
@@ -106,23 +139,15 @@ router.put("/", {
106
139
  });
107
140
  /** PATCH / - Partially update configuration */
108
141
  router.patch("/", {
109
- body: v.object({
110
- scopeId: nonEmptyStringValueSchema("scopeId"),
111
- config: v.array(v.object({
112
- name: nonEmptyStringValueSchema("config.name"),
113
- value: v.nullable(v.union([
114
- v.boolean(),
115
- v.string(),
116
- v.array(v.string())
117
- ]))
118
- }))
119
- }),
142
+ body: PatchConfigBodySchema,
120
143
  handler: async (req, ctx) => {
121
144
  const { logger, rawParams } = ctx;
122
- const { configSchema } = rawParams;
123
145
  logger.debug(`Patching configuration with scope id: ${req.body.scopeId}`);
124
146
  const { scopeId, config } = req.body;
125
- initialize({ schema: validateCommerceAppConfigDomain(configSchema, "businessConfig.schema") });
147
+ const { configSchema } = await initialize({
148
+ schema: rawParams.configSchema,
149
+ params: rawParams
150
+ });
126
151
  const result = await setConfiguration({ config }, byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
127
152
  result.config = filterPasswordFields(configSchema, result.config);
128
153
  return ok({
@@ -131,9 +156,17 @@ router.patch("/", {
131
156
  });
132
157
  }
133
158
  });
134
- /** Factory to create the route handler for the `config` action. */
135
- const configRuntimeAction = ({ configSchema }) => async (params) => {
136
- return await router.handler()({
159
+
160
+ //#endregion
161
+ //#region source/actions/config/index.ts
162
+ /**
163
+ * Factory to create the route handler for the `config` action.
164
+ * @param args - The arguments required to create the runtime action.
165
+ */
166
+ const configRuntimeAction = (args) => async (params) => {
167
+ const handler = router.handler();
168
+ const { configSchema } = args;
169
+ return await handler({
137
170
  ...params,
138
171
  configSchema
139
172
  });
@@ -12,22 +12,23 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { n as CommerceAppConfigOutputModel } from "../app-C6kImBl7.cjs";
16
- import { o as InstallationContext } from "../step-CWYnKbga.cjs";
17
- import * as _$_adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
15
+ import { n as CommerceAppConfig, r as CommerceAppConfigOutputModel } from "../../app-DrYHK-z1.mjs";
16
+ import { Y as InstallationContext } from "../../index-DLMbTtKS.mjs";
18
17
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
19
18
 
20
- //#region source/actions/installation.d.ts
19
+ //#region source/actions/installation/router.d.ts
21
20
  type CustomScriptsLoader = (config: CommerceAppConfigOutputModel, logger: InstallationContext["logger"]) => Record<string, unknown>;
22
21
  /** Arguments for the runtime action factory. */
23
22
  type RuntimeActionFactoryArgs = {
24
- appConfig: CommerceAppConfigOutputModel;
23
+ appConfig: CommerceAppConfig;
25
24
  customScriptsLoader?: CustomScriptsLoader;
26
25
  };
27
- /** Factory to create the route handler for the `installation` action. */
28
- declare const installationRuntimeAction: ({
29
- appConfig,
30
- customScriptsLoader
31
- }: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<_$_adobe_aio_commerce_lib_core_responses0.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>;
32
33
  //#endregion
33
34
  export { installationRuntimeAction };