@adobe/aio-commerce-lib-app 0.3.2 → 1.0.1

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 (78) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +1 -4
  3. package/bin/cli.mjs +24 -0
  4. package/dist/cjs/actions/app-config.cjs +27 -0
  5. package/dist/cjs/actions/app-config.d.cts +15 -0
  6. package/dist/cjs/actions/config.cjs +79 -0
  7. package/dist/cjs/actions/config.d.cts +15 -0
  8. package/dist/cjs/actions/installation.cjs +424 -0
  9. package/dist/cjs/actions/{index.d.cts → installation.d.cts} +4 -3
  10. package/dist/cjs/actions/scope-tree.cjs +97 -0
  11. package/dist/cjs/actions/scope-tree.d.cts +8 -0
  12. package/dist/{es/app-Cx1-6dn0.d.mts → cjs/app-DWX5-Hsf.d.cts} +14 -14
  13. package/dist/cjs/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  14. package/dist/cjs/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  15. package/dist/cjs/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  16. package/dist/cjs/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  17. package/dist/cjs/commands/index.cjs +91 -106
  18. package/dist/cjs/config/index.cjs +21 -19
  19. package/dist/cjs/config/index.d.cts +52 -352
  20. package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
  21. package/dist/cjs/installation-CLbceU9F.cjs +243 -0
  22. package/dist/cjs/{logging-DYwr5WQk.cjs → logging-IDRQG0as.cjs} +2 -2
  23. package/dist/cjs/management/index.cjs +9 -8
  24. package/dist/cjs/management/index.d.cts +2 -2
  25. package/dist/cjs/parser-BPpg_9QB.cjs +267 -0
  26. package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
  27. package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-DemKouFJ.d.cts} +49 -95
  28. package/dist/cjs/{management-Dm5h0E6l.cjs → runner-NHMvoMO2.cjs} +24 -30
  29. package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
  30. package/dist/cjs/validate-Btzn9ilZ.cjs +235 -0
  31. package/dist/es/actions/app-config.d.mts +15 -0
  32. package/dist/es/actions/app-config.mjs +25 -0
  33. package/dist/es/actions/config.d.mts +15 -0
  34. package/dist/es/actions/config.mjs +77 -0
  35. package/dist/es/actions/{index.d.mts → installation.d.mts} +4 -3
  36. package/dist/es/actions/{index.mjs → installation.mjs} +27 -427
  37. package/dist/es/actions/scope-tree.d.mts +8 -0
  38. package/dist/es/actions/scope-tree.mjs +95 -0
  39. package/dist/{cjs/app-Dx0ca6oL.d.cts → es/app-BAiyvNo2.d.mts} +14 -14
  40. package/dist/es/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  41. package/dist/es/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  42. package/dist/es/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  43. package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  44. package/dist/es/commands/index.mjs +68 -84
  45. package/dist/es/config/index.d.mts +52 -352
  46. package/dist/es/config/index.mjs +3 -2
  47. package/dist/es/error-CMV3IjBz.mjs +18 -0
  48. package/dist/es/{error-P7JgUTds.mjs → installation-BTL9X7iv.mjs} +78 -128
  49. package/dist/es/management/index.d.mts +2 -3
  50. package/dist/es/management/index.mjs +1 -1
  51. package/dist/es/parser-CQZTVG6i.mjs +201 -0
  52. package/dist/es/router-CJ4VWoCt.mjs +404 -0
  53. package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-BD-lItnK.d.mts} +49 -95
  54. package/dist/es/{management-Y7pwEbNI.mjs → runner-vwAhjD5r.mjs} +17 -24
  55. package/dist/es/schemas-B8yIv0_b.mjs +41 -0
  56. package/dist/es/validate-DKnju9-R.mjs +187 -0
  57. package/package.json +38 -24
  58. package/dist/cjs/actions/index.cjs +0 -824
  59. package/dist/cjs/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  60. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  61. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  62. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  63. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  64. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  65. package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  66. package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  67. package/dist/cjs/config-JQ_n-5Nk.cjs +0 -565
  68. package/dist/cjs/error-Byj1DVHZ.cjs +0 -344
  69. package/dist/es/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  70. package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  71. package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  72. package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  73. package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  74. package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  75. package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  76. package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  77. package/dist/es/config-BSGerqCG.mjs +0 -457
  78. /package/dist/es/{logging-VgerMhp6.mjs → logging-CzmXDzxI.mjs} +0 -0
@@ -1,7 +1,9 @@
1
- const require_error = require('./error-Byj1DVHZ.cjs');
2
- const require_logging = require('./logging-DYwr5WQk.cjs');
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
+ const require_installation = require('./installation-CLbceU9F.cjs');
3
+ const require_error = require('./error-DJ2UAPH2.cjs');
4
+ const require_logging = require('./logging-IDRQG0as.cjs');
3
5
  let camelcase = require("camelcase");
4
- camelcase = require_error.__toESM(camelcase);
6
+ camelcase = require_schemas.__toESM(camelcase);
5
7
  let _adobe_aio_commerce_lib_auth = require("@adobe/aio-commerce-lib-auth");
6
8
  let _adobe_aio_commerce_lib_api = require("@adobe/aio-commerce-lib-api");
7
9
  let _adobe_aio_commerce_lib_events_commerce = require("@adobe/aio-commerce-lib-events/commerce");
@@ -330,7 +332,7 @@ function createCustomScriptStep(scriptConfig) {
330
332
  * defined in the configuration. Each script becomes a separate leaf step.
331
333
  */
332
334
  function createCustomScriptSteps(config) {
333
- if (!require_error.hasCustomInstallationSteps(config)) return [];
335
+ if (!require_installation.hasCustomInstallationSteps(config)) return [];
334
336
  const steps = config.installation.customInstallationSteps;
335
337
  if (new Set(steps.map((step) => step.name)).size !== steps.length) throw new Error("Duplicate step names detected in custom installation steps. Each step must have a unique name.");
336
338
  return steps.map((scriptConfig) => createCustomScriptStep(scriptConfig));
@@ -345,7 +347,7 @@ const customInstallationStepBase = defineBranchStep({
345
347
  label: "Custom Installation Steps",
346
348
  description: "Executes custom installation scripts defined in the application configuration"
347
349
  },
348
- when: require_error.hasCustomInstallationSteps,
350
+ when: require_installation.hasCustomInstallationSteps,
349
351
  children: []
350
352
  });
351
353
  /**
@@ -559,9 +561,9 @@ async function getIoEventsExistingData(context) {
559
561
  });
560
562
  const providersWithMetadata = existingProviders.map((providerHal) => {
561
563
  const { _embedded, _links, ...providerData } = providerHal;
562
- const actualMetadata = (_embedded?.eventmetadata ?? []).map(({ _embedded: _embedded$1, _links: _links$1, ...meta }) => ({
564
+ const actualMetadata = (_embedded?.eventmetadata ?? []).map(({ _embedded, _links, ...meta }) => ({
563
565
  ...meta,
564
- sample: _embedded$1?.sample_event ?? null
566
+ sample: _embedded?.sample_event ?? null
565
567
  }));
566
568
  return {
567
569
  ...providerData,
@@ -750,13 +752,13 @@ async function configureCommerceEventing(params, existingData) {
750
752
  enabled: true
751
753
  };
752
754
  if (existingData.isDefaultWorkspaceConfigurationEmpty) {
753
- if (!config.workspaceConfiguration) {
755
+ if (!config.workspace_configuration) {
754
756
  const message = "Workspace configuration is required to enable Commerce Eventing when there is not an existing one.";
755
757
  logger.error(message);
756
758
  throw new Error(message);
757
759
  }
758
760
  logger.info("Default provider workspace configuration already present, it will not be overriden");
759
- const { workspaceConfiguration, ...rest } = updateParams;
761
+ const { workspace_configuration, ...rest } = updateParams;
760
762
  updateParams = rest;
761
763
  }
762
764
  logger.info("Updating Commerce Eventing configuration with provided workspace configuration.");
@@ -780,11 +782,8 @@ async function createCommerceProvider(params) {
780
782
  const { commerceEventsClient, logger } = context;
781
783
  logger.info(`Creating Commerce provider "${provider.label}" with instance ID "${provider.instance_id}"`);
782
784
  return commerceEventsClient.createEventProvider({
783
- providerId: provider.id,
784
- instanceId: provider.instance_id,
785
- label: provider.label,
786
- description: provider.description,
787
- associatedWorkspaceConfiguration: provider.workspaceConfiguration
785
+ ...provider,
786
+ provider_id: provider.id
788
787
  }).then((res) => {
789
788
  logger.info(`Commerce provider "${provider.label}" created with ID '${res.provider_id}'`);
790
789
  return res;
@@ -821,10 +820,10 @@ async function createCommerceEventSubscription(params) {
821
820
  name: eventName,
822
821
  parent: event.config.name,
823
822
  fields: event.config.fields,
824
- providerId: provider.id,
823
+ provider_id: provider.id,
825
824
  destination: event.config.destination,
826
- hipaaAuditRequired: event.config.hipaaAuditRequired,
827
- prioritary: event.config.prioritary,
825
+ hipaa_audit_required: event.config.hipaa_audit_required,
826
+ priority: event.config.priority,
828
827
  force: event.config.force
829
828
  };
830
829
  logger.debug(`Event subscription specification for event "${event.config.name}": ${require_logging.inspect(eventSpec)}`);
@@ -847,12 +846,7 @@ async function createOrGetCommerceEventSubscription(params, existingData) {
847
846
  const existing = findExistingSubscription(existingData, getNamespacedEvent(metadata, event.config.name));
848
847
  if (existing) {
849
848
  logger.info(`Subscription for event "${event.config.name}" already exists, skipping creation.`);
850
- return {
851
- name: existing.name,
852
- parent: existing.parent,
853
- fields: existing.fields,
854
- providerId: existing.provider_id
855
- };
849
+ return existing;
856
850
  }
857
851
  return createCommerceEventSubscription(params);
858
852
  }
@@ -921,7 +915,7 @@ async function onboardCommerceEventing(params, existingData) {
921
915
  const subscriptions = [];
922
916
  await configureCommerceEventing({
923
917
  context,
924
- config: { workspaceConfiguration }
918
+ config: { workspace_configuration: workspaceConfiguration }
925
919
  }, existingData);
926
920
  const { workspace_configuration: _, ...commerceProviderData } = await createOrGetCommerceProvider({
927
921
  context,
@@ -930,7 +924,7 @@ async function onboardCommerceEventing(params, existingData) {
930
924
  instance_id: instanceId,
931
925
  label: provider.label,
932
926
  description: provider.description,
933
- workspaceConfiguration
927
+ workspace_configuration: workspaceConfiguration
934
928
  }
935
929
  }, existingData.providers);
936
930
  for (const event of events) subscriptions.push(await createOrGetCommerceEventSubscription({
@@ -954,7 +948,7 @@ const commerceEventsStep = defineLeafStep({
954
948
  label: "Configure Commerce Events",
955
949
  description: "Sets up I/O Events for Adobe Commerce event sources"
956
950
  },
957
- when: require_error.hasCommerceEvents,
951
+ when: require_installation.hasCommerceEvents,
958
952
  run: async (config, context) => {
959
953
  const { logger } = context;
960
954
  logger.debug("Starting installation of Commerce Events with config:", config);
@@ -985,9 +979,9 @@ const commerceEventsStep = defineLeafStep({
985
979
  data: {
986
980
  ioEvents: providerData,
987
981
  commerce: commerceProvider,
988
- events: eventsData.map(({ config: config$1, data }, index) => {
982
+ events: eventsData.map(({ config, data }, index) => {
989
983
  return {
990
- config: config$1,
984
+ config,
991
985
  data: {
992
986
  ...data,
993
987
  subscription: subscriptions[index]
@@ -1062,7 +1056,7 @@ const externalEventsStep = defineLeafStep({
1062
1056
  label: "Configure External Events",
1063
1057
  description: "Sets up I/O Events for external event sources"
1064
1058
  },
1065
- when: require_error.hasExternalEvents,
1059
+ when: require_installation.hasExternalEvents,
1066
1060
  run: async (config, context) => {
1067
1061
  const { logger } = context;
1068
1062
  logger.debug("Starting installation of External Events with config:", config);
@@ -1101,7 +1095,7 @@ const eventingStep = defineBranchStep({
1101
1095
  label: "Eventing",
1102
1096
  description: "Sets up the I/O Events and the Commerce events required by the application"
1103
1097
  },
1104
- when: require_error.hasEventing,
1098
+ when: require_installation.hasEventing,
1105
1099
  context: createEventsStepContext,
1106
1100
  children: [commerceEventsStep, externalEventsStep]
1107
1101
  });
@@ -0,0 +1,98 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let valibot = require("valibot");
29
+ valibot = __toESM(valibot);
30
+
31
+ //#region ../../packages-private/common-utils/source/valibot/schemas.ts
32
+ const ALPHANUMERIC_OR_HYPHEN_REGEX = {
33
+ any: /^[a-zA-Z0-9-]+$/,
34
+ lowercase: /^[a-z0-9-]+$/,
35
+ uppercase: /^[A-Z0-9-]+$/
36
+ };
37
+ /**
38
+ * A schema for a string value.
39
+ * @param name The name of the field this schema refers to.
40
+ */
41
+ function stringValueSchema(name) {
42
+ return valibot.string(`Expected a string value for '${name}'`);
43
+ }
44
+ /**
45
+ * A schema for a non-empty string value.
46
+ * @param name The name of the field this schema refers to.
47
+ */
48
+ function nonEmptyStringValueSchema(name) {
49
+ return valibot.pipe(stringValueSchema(name), valibot.nonEmpty(`The value of "${name}" must not be empty`));
50
+ }
51
+ /**
52
+ * A schema for a boolean value.
53
+ * @param name The name of the field this schema refers to.
54
+ */
55
+ function booleanValueSchema(name) {
56
+ return valibot.boolean(`Expected a boolean value for '${name}'`);
57
+ }
58
+ /**
59
+ * A schema for a string that only contains alphanumeric characters and hyphens.
60
+ * @param name The name of the field this schema refers to.
61
+ * @param casing The allowed casing for the string (default: "any").
62
+ */
63
+ function alphaNumericOrHyphenSchema(name, casing = "any") {
64
+ const casingLabel = casing === "any" ? "" : ` (${casing} only)`;
65
+ return valibot.pipe(stringValueSchema(name), valibot.regex(ALPHANUMERIC_OR_HYPHEN_REGEX[casing], `Only alphanumeric characters and hyphens are allowed in string value of "${name}"${casingLabel}`));
66
+ }
67
+
68
+ //#endregion
69
+ Object.defineProperty(exports, '__toESM', {
70
+ enumerable: true,
71
+ get: function () {
72
+ return __toESM;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, 'alphaNumericOrHyphenSchema', {
76
+ enumerable: true,
77
+ get: function () {
78
+ return alphaNumericOrHyphenSchema;
79
+ }
80
+ });
81
+ Object.defineProperty(exports, 'booleanValueSchema', {
82
+ enumerable: true,
83
+ get: function () {
84
+ return booleanValueSchema;
85
+ }
86
+ });
87
+ Object.defineProperty(exports, 'nonEmptyStringValueSchema', {
88
+ enumerable: true,
89
+ get: function () {
90
+ return nonEmptyStringValueSchema;
91
+ }
92
+ });
93
+ Object.defineProperty(exports, 'stringValueSchema', {
94
+ enumerable: true,
95
+ get: function () {
96
+ return stringValueSchema;
97
+ }
98
+ });
@@ -0,0 +1,235 @@
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
+ const require_installation = require('./installation-CLbceU9F.cjs');
3
+ let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
4
+ let valibot = require("valibot");
5
+ valibot = require_schemas.__toESM(valibot);
6
+ let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
7
+
8
+ //#region source/config/schema/business-configuration.ts
9
+ /**
10
+ * Check if config has business config.
11
+ * @param config - The configuration to check.
12
+ */
13
+ function hasBusinessConfig(config) {
14
+ return config.businessConfig !== void 0;
15
+ }
16
+ /**
17
+ * Check if config has business config schema.
18
+ * @param config - The configuration to check.
19
+ */
20
+ function hasBusinessConfigSchema(config) {
21
+ return config.businessConfig?.schema !== void 0 && config.businessConfig.schema.length > 0;
22
+ }
23
+
24
+ //#endregion
25
+ //#region source/config/schema/metadata.ts
26
+ const MAX_DESCRIPTION_LENGTH = 255;
27
+ const MAX_DISPLAY_NAME_LENGTH = 50;
28
+ const NUMERIC_IDENTIFIER = "(0|[1-9]\\d*)";
29
+ const SEMVER_REGEX = new RegExp(`^${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}$`);
30
+ function nonEmptyString(fieldName) {
31
+ return valibot.pipe(valibot.string(`Expected a string for the ${fieldName}`), valibot.nonEmpty(`The ${fieldName} must not be empty`));
32
+ }
33
+ /** The schema for the metadata of the application. */
34
+ const MetadataSchema = valibot.object({
35
+ id: require_schemas.alphaNumericOrHyphenSchema("application id (metadata.id)"),
36
+ displayName: valibot.pipe(nonEmptyString("application display name"), valibot.maxLength(MAX_DISPLAY_NAME_LENGTH, `The application display name must not be longer than ${MAX_DISPLAY_NAME_LENGTH} characters`)),
37
+ description: valibot.pipe(nonEmptyString("metadata description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The metadata description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
38
+ version: valibot.pipe(nonEmptyString("version"), valibot.regex(SEMVER_REGEX, "The version must follow semantic versioning (semver) format"))
39
+ });
40
+ /**
41
+ * Check if config has metadata.
42
+ * @param config - The configuration to check.
43
+ */
44
+ function hasMetadata(config) {
45
+ return config.metadata !== void 0;
46
+ }
47
+
48
+ //#endregion
49
+ //#region source/config/schema/app.ts
50
+ /** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
51
+ /** The schema used to validate the commerce app config file. */
52
+ const CommerceAppConfigSchema = valibot.looseObject({
53
+ metadata: MetadataSchema,
54
+ businessConfig: valibot.optional(_adobe_aio_commerce_lib_config.SchemaBusinessConfig),
55
+ eventing: valibot.optional(require_installation.EventingSchema),
56
+ installation: valibot.optional(require_installation.InstallationSchema)
57
+ });
58
+
59
+ //#endregion
60
+ //#region source/config/schema/domains.ts
61
+ /** The individual validatable domains of the app config. */
62
+ const CommerceAppConfigSchemas = {
63
+ metadata: MetadataSchema,
64
+ businessConfig: _adobe_aio_commerce_lib_config.SchemaBusinessConfig,
65
+ eventing: require_installation.EventingSchema,
66
+ installation: require_installation.InstallationSchema,
67
+ "businessConfig.schema": valibot.unwrap(_adobe_aio_commerce_lib_config.SchemaBusinessConfig.entries.schema),
68
+ "eventing.commerce": valibot.unwrap(require_installation.EventingSchema.entries.commerce),
69
+ "eventing.external": valibot.unwrap(require_installation.EventingSchema.entries.external),
70
+ "installation.customInstallationSteps": valibot.unwrap(require_installation.InstallationSchema.entries.customInstallationSteps)
71
+ };
72
+ /**
73
+ * Get the config domains that are present in the config.
74
+ * @param config - The configuration to check.
75
+ */
76
+ function getConfigDomains(config) {
77
+ const withCommerceEvents = require_installation.hasCommerceEvents(config);
78
+ const withExternalEvents = require_installation.hasExternalEvents(config);
79
+ const domains = {
80
+ metadata: hasMetadata(config),
81
+ businessConfig: hasBusinessConfig(config),
82
+ eventing: withCommerceEvents || withExternalEvents,
83
+ installation: require_installation.hasCustomInstallation(config),
84
+ "businessConfig.schema": hasBusinessConfigSchema(config),
85
+ "eventing.commerce": withCommerceEvents,
86
+ "eventing.external": withExternalEvents,
87
+ "installation.customInstallationSteps": require_installation.hasCustomInstallationSteps(config)
88
+ };
89
+ const domainsList = Object.entries(domains).filter(([_, value]) => value).map(([key]) => key);
90
+ return new Set(domainsList);
91
+ }
92
+ /**
93
+ * Check if the config has a specific domain.
94
+ * @param config - The configuration to check.
95
+ * @param domain - The domain to check.
96
+ */
97
+ function hasConfigDomain(config, domain) {
98
+ return getConfigDomains(config).has(domain);
99
+ }
100
+
101
+ //#endregion
102
+ //#region source/config/lib/validate.ts
103
+ const commerceAppConfigDomainsSchema = valibot.picklist(Object.keys(CommerceAppConfigSchemas));
104
+ /**
105
+ * Validates a complete commerce app configuration object against the schema.
106
+ *
107
+ * @param config - The configuration object to validate.
108
+ * @returns The validated and typed configuration output model.
109
+ *
110
+ * @throws {CommerceSdkValidationError} If the configuration is invalid, with
111
+ * detailed validation issues included.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const config = {
116
+ * businessConfiguration: {
117
+ * // ... configuration data
118
+ * }
119
+ * };
120
+ *
121
+ * try {
122
+ * const validatedConfig = validateCommerceAppConfig(config);
123
+ * // Use validatedConfig safely
124
+ * } catch (error) {
125
+ * if (error instanceof CommerceSdkValidationError) {
126
+ * console.error('Validation failed:', error.display());
127
+ * }
128
+ * }
129
+ * ```
130
+ */
131
+ function validateCommerceAppConfig(config) {
132
+ const validatedConfig = valibot.safeParse(CommerceAppConfigSchema, config);
133
+ if (!validatedConfig.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid commerce app config", { issues: validatedConfig.issues });
134
+ return validatedConfig.output;
135
+ }
136
+ /**
137
+ * Validates a specific domain configuration within the commerce app config.
138
+ *
139
+ * This function validates only a specific domain's configuration rather than
140
+ * the entire commerce app configuration object. It first validates that the
141
+ * domain name is valid, then validates the configuration data against the
142
+ * schema for that specific domain.
143
+ *
144
+ * @template T - The type of the domain, constrained to valid domain names.
145
+ *
146
+ * @param config - The domain configuration object to validate.
147
+ * @param domain - The name of the domain to validate (e.g., 'businessConfiguration').
148
+ * @returns The validated and typed configuration for the specified domain.
149
+ *
150
+ * @throws {CommerceSdkValidationError} If the domain name is invalid or if the
151
+ * configuration doesn't match the domain's schema.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const businessConfig = {
156
+ * fields: [
157
+ * {
158
+ * name: 'category',
159
+ * type: 'dropdown',
160
+ * // ... field configuration
161
+ * }
162
+ * ]
163
+ * };
164
+ *
165
+ * try {
166
+ * const validatedConfig = validateCommerceAppConfigDomain(
167
+ * businessConfig,
168
+ * 'businessConfig'
169
+ * );
170
+ * // Use validatedConfig safely
171
+ * } catch (error) {
172
+ * if (error instanceof CommerceSdkValidationError) {
173
+ * console.error('Domain validation failed:', error.issues);
174
+ * }
175
+ * }
176
+ * ```
177
+ */
178
+ function validateCommerceAppConfigDomain(config, domain) {
179
+ const domainSchema = valibot.safeParse(commerceAppConfigDomainsSchema, domain);
180
+ if (!domainSchema.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid commerce app config domain", { issues: domainSchema.issues });
181
+ const domainConfigSchema = CommerceAppConfigSchemas[domain];
182
+ const validatedConfig = valibot.safeParse(domainConfigSchema, config);
183
+ if (!validatedConfig.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError(`Invalid commerce app config: ${domain}`, { issues: validatedConfig.issues });
184
+ return validatedConfig.output;
185
+ }
186
+
187
+ //#endregion
188
+ Object.defineProperty(exports, 'CommerceAppConfigSchemas', {
189
+ enumerable: true,
190
+ get: function () {
191
+ return CommerceAppConfigSchemas;
192
+ }
193
+ });
194
+ Object.defineProperty(exports, 'getConfigDomains', {
195
+ enumerable: true,
196
+ get: function () {
197
+ return getConfigDomains;
198
+ }
199
+ });
200
+ Object.defineProperty(exports, 'hasBusinessConfig', {
201
+ enumerable: true,
202
+ get: function () {
203
+ return hasBusinessConfig;
204
+ }
205
+ });
206
+ Object.defineProperty(exports, 'hasBusinessConfigSchema', {
207
+ enumerable: true,
208
+ get: function () {
209
+ return hasBusinessConfigSchema;
210
+ }
211
+ });
212
+ Object.defineProperty(exports, 'hasConfigDomain', {
213
+ enumerable: true,
214
+ get: function () {
215
+ return hasConfigDomain;
216
+ }
217
+ });
218
+ Object.defineProperty(exports, 'hasMetadata', {
219
+ enumerable: true,
220
+ get: function () {
221
+ return hasMetadata;
222
+ }
223
+ });
224
+ Object.defineProperty(exports, 'validateCommerceAppConfig', {
225
+ enumerable: true,
226
+ get: function () {
227
+ return validateCommerceAppConfig;
228
+ }
229
+ });
230
+ Object.defineProperty(exports, 'validateCommerceAppConfigDomain', {
231
+ enumerable: true,
232
+ get: function () {
233
+ return validateCommerceAppConfigDomain;
234
+ }
235
+ });
@@ -0,0 +1,15 @@
1
+ import { n as CommerceAppConfigOutputModel } from "../app-BAiyvNo2.mjs";
2
+ import * as _adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
3
+ import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
4
+
5
+ //#region source/actions/app-config.d.ts
6
+ /** Arguments for the runtime action factory. */
7
+ type RuntimeActionFactoryArgs = {
8
+ appConfig: CommerceAppConfigOutputModel;
9
+ };
10
+ /** Factory to create the route handler for the `app-config` action. */
11
+ declare const appConfigRuntimeAction: ({
12
+ appConfig
13
+ }: RuntimeActionFactoryArgs) => (params: RuntimeActionParams) => Promise<_adobe_aio_commerce_lib_core_responses0.ActionResponse>;
14
+ //#endregion
15
+ export { appConfigRuntimeAction };
@@ -0,0 +1,25 @@
1
+ import { n as logger, t as HttpActionRouter } from "../router-CJ4VWoCt.mjs";
2
+ import { t as validateCommerceAppConfig } from "../validate-DKnju9-R.mjs";
3
+ import { ok } from "@adobe/aio-commerce-lib-core/responses";
4
+
5
+ //#region source/actions/app-config.ts
6
+ /** Router for the app config actions. */
7
+ const router = new HttpActionRouter().use(logger({ name: () => "get-app-config" }));
8
+ /** GET / - Get app config */
9
+ router.get("/", { handler: async (_req, { logger, rawParams }) => {
10
+ logger.debug("Validating app config...");
11
+ const { appConfig } = rawParams;
12
+ const config = validateCommerceAppConfig(appConfig);
13
+ logger.debug("Successfully validated the app config");
14
+ return ok({ body: config });
15
+ } });
16
+ /** Factory to create the route handler for the `app-config` action. */
17
+ const appConfigRuntimeAction = ({ appConfig }) => async (params) => {
18
+ return await router.handler()({
19
+ ...params,
20
+ appConfig
21
+ });
22
+ };
23
+
24
+ //#endregion
25
+ export { appConfigRuntimeAction };
@@ -0,0 +1,15 @@
1
+ import * as _adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
2
+ import { BusinessConfigSchema } from "@adobe/aio-commerce-lib-config";
3
+ import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
4
+
5
+ //#region source/actions/config.d.ts
6
+ /** The arguments for the config action factory. */
7
+ type ConfigActionFactoryArgs = {
8
+ configSchema: BusinessConfigSchema;
9
+ };
10
+ /** Factory to create the route handler for the `config` action. */
11
+ declare const configRuntimeAction: ({
12
+ configSchema
13
+ }: ConfigActionFactoryArgs) => (params: RuntimeActionParams) => Promise<_adobe_aio_commerce_lib_core_responses0.ActionResponse>;
14
+ //#endregion
15
+ export { configRuntimeAction };
@@ -0,0 +1,77 @@
1
+ import { n as logger, t as HttpActionRouter } from "../router-CJ4VWoCt.mjs";
2
+ import { n as validateCommerceAppConfigDomain } from "../validate-DKnju9-R.mjs";
3
+ import { r as nonEmptyStringValueSchema } from "../schemas-B8yIv0_b.mjs";
4
+ import { ok } from "@adobe/aio-commerce-lib-core/responses";
5
+ import * as v from "valibot";
6
+ import { byScopeId, getConfiguration, initialize, setConfiguration } from "@adobe/aio-commerce-lib-config";
7
+
8
+ //#region source/actions/config.ts
9
+ const MASKED_PASSWORD_VALUE = "*****";
10
+ /**
11
+ * Filters password fields from the configuration values.
12
+ * @param schema - The schema to use to filter the values.
13
+ * @param values - The values to filter.
14
+ * @returns The filtered values.
15
+ */
16
+ function filterPasswordFields(schema, values) {
17
+ return values.map((item) => {
18
+ if (schema.find((field) => field.name === item.name)?.type === "password") return {
19
+ ...item,
20
+ value: MASKED_PASSWORD_VALUE
21
+ };
22
+ return item;
23
+ });
24
+ }
25
+ const router = new HttpActionRouter().use(logger());
26
+ /** GET / - Retrieve configuration */
27
+ router.get("/", {
28
+ query: v.object({ scopeId: nonEmptyStringValueSchema("scopeId") }),
29
+ handler: async (req, ctx) => {
30
+ const { logger, rawParams } = ctx;
31
+ const configSchema = rawParams.configSchema;
32
+ logger.debug("Validating configuration schema...");
33
+ const validatedSchema = validateCommerceAppConfigDomain(configSchema, "businessConfig.schema");
34
+ initialize({ schema: validatedSchema });
35
+ const { scopeId } = req.query;
36
+ logger.debug(`Retrieving configuration with scope id: ${scopeId}`);
37
+ const appConfiguration = await getConfiguration(byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
38
+ logger.debug("Masking password values...");
39
+ appConfiguration.config = filterPasswordFields(configSchema, appConfiguration.config);
40
+ return ok({ body: {
41
+ schema: validatedSchema,
42
+ values: appConfiguration
43
+ } });
44
+ }
45
+ });
46
+ /** POST / - Set configuration */
47
+ router.put("/", {
48
+ body: v.object({
49
+ scopeId: nonEmptyStringValueSchema("scopeId"),
50
+ config: v.array(v.object({
51
+ name: nonEmptyStringValueSchema("config.name"),
52
+ value: v.union([v.string(), v.array(v.string())])
53
+ }))
54
+ }),
55
+ handler: async (req, ctx) => {
56
+ const { logger, rawParams } = ctx;
57
+ const { configSchema } = rawParams;
58
+ logger.debug(`Setting configuration with scope id: ${req.body.scopeId}`);
59
+ const { scopeId, config } = req.body;
60
+ const result = await setConfiguration({ config: config.filter((item) => item.value !== MASKED_PASSWORD_VALUE) }, byScopeId(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
61
+ result.config = filterPasswordFields(configSchema, result.config);
62
+ return ok({
63
+ body: result,
64
+ headers: { "Cache-Control": "no-store" }
65
+ });
66
+ }
67
+ });
68
+ /** Factory to create the route handler for the `config` action. */
69
+ const configRuntimeAction = ({ configSchema }) => async (params) => {
70
+ return await router.handler()({
71
+ ...params,
72
+ configSchema
73
+ });
74
+ };
75
+
76
+ //#endregion
77
+ export { configRuntimeAction };
@@ -1,15 +1,16 @@
1
- import { n as CommerceAppConfigOutputModel } from "../app-Cx1-6dn0.mjs";
2
- import { P as InstallationContext } from "../index-Bxr3zvCT.mjs";
1
+ import { n as CommerceAppConfigOutputModel } from "../app-BAiyvNo2.mjs";
2
+ import { P as InstallationContext } from "../runner-BD-lItnK.mjs";
3
3
  import * as _adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
4
4
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
5
5
 
6
6
  //#region source/actions/installation.d.ts
7
7
  type CustomScriptsLoader = (config: CommerceAppConfigOutputModel, logger: InstallationContext["logger"]) => Record<string, unknown>;
8
+ /** Arguments for the runtime action factory. */
8
9
  type RuntimeActionFactoryArgs = {
9
10
  appConfig: CommerceAppConfigOutputModel;
10
11
  customScriptsLoader?: CustomScriptsLoader;
11
12
  };
12
- /** The route handler for the runtime action. */
13
+ /** Factory to create the route handler for the `installation` action. */
13
14
  declare const installationRuntimeAction: ({
14
15
  appConfig,
15
16
  customScriptsLoader