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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/dist/cjs/actions/app-config/index.cjs +205 -0
  3. package/dist/cjs/actions/{app-config.d.cts → app-config/index.d.cts} +10 -7
  4. package/dist/cjs/actions/association/index.cjs +85 -0
  5. package/dist/cjs/actions/association/index.d.cts +28 -0
  6. package/dist/cjs/actions/{config.cjs → config/index.cjs} +70 -53
  7. package/dist/{es/actions/config.d.mts → cjs/actions/config/index.d.cts} +10 -7
  8. package/dist/cjs/actions/{installation.cjs → installation/index.cjs} +106 -72
  9. package/dist/{es/actions/installation.d.mts → cjs/actions/installation/index.d.cts} +10 -8
  10. package/dist/cjs/actions/{scope-tree.cjs → scope-tree/index.cjs} +60 -22
  11. package/dist/cjs/actions/{scope-tree.d.cts → scope-tree/index.d.cts} +1 -1
  12. package/dist/cjs/app-D3P-Z6uY.d.cts +1679 -0
  13. package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
  14. package/dist/cjs/commands/index.cjs +517 -309
  15. package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
  16. package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
  17. package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
  18. package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  19. package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  20. package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  21. package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  22. package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
  23. package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
  24. package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
  25. package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
  26. package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
  27. package/dist/cjs/config/index.browser.cjs +18 -0
  28. package/dist/cjs/config/index.browser.d.cts +16 -0
  29. package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
  30. package/dist/cjs/config/index.node.d.cts +1603 -0
  31. package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
  32. package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
  33. package/dist/cjs/environment-B7EnozSg.cjs +135 -0
  34. package/dist/cjs/index-BXm8UbK7.d.cts +16 -0
  35. package/dist/cjs/{index-Dw2NvVOY.d.cts → index-CzReNwbF.d.cts} +177 -3
  36. package/dist/cjs/index.cjs +250 -0
  37. package/dist/cjs/index.d.cts +217 -0
  38. package/dist/cjs/{config-FNMclIFO.cjs → index.node-Dz4lV4qe.cjs} +119 -35
  39. package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
  40. package/dist/cjs/management/index.cjs +1 -1
  41. package/dist/cjs/management/index.d.cts +1 -2
  42. package/dist/cjs/{management-Cvsz4VMf.cjs → management-B9ItB80R.cjs} +432 -591
  43. package/dist/cjs/openapi-CwytYdWl.cjs +2948 -0
  44. package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
  45. package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
  46. package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
  47. package/dist/cjs/{validate-DydOAZha.cjs → validate-BfxhZ5Wv.cjs} +63 -31
  48. package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
  49. package/dist/es/actions/{app-config.d.mts → app-config/index.d.mts} +10 -7
  50. package/dist/es/actions/app-config/index.mjs +202 -0
  51. package/dist/es/actions/association/index.d.mts +28 -0
  52. package/dist/es/actions/association/index.mjs +82 -0
  53. package/dist/{cjs/actions/config.d.cts → es/actions/config/index.d.mts} +10 -7
  54. package/dist/es/actions/{config.mjs → config/index.mjs} +67 -50
  55. package/dist/{cjs/actions/installation.d.cts → es/actions/installation/index.d.mts} +10 -8
  56. package/dist/es/actions/{installation.mjs → installation/index.mjs} +104 -71
  57. package/dist/es/actions/{scope-tree.d.mts → scope-tree/index.d.mts} +1 -1
  58. package/dist/es/actions/{scope-tree.mjs → scope-tree/index.mjs} +58 -20
  59. package/dist/es/app-D3P-Z6uY.d.mts +1679 -0
  60. package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
  61. package/dist/es/commands/index.mjs +550 -340
  62. package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
  63. package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
  64. package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
  65. package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  66. package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  67. package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  68. package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  69. package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
  70. package/dist/es/commands/templates/app-management/association.js.template +6 -0
  71. package/dist/es/commands/templates/app-management/installation.js.template +1 -13
  72. package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
  73. package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
  74. package/dist/es/config/index.browser.d.mts +16 -0
  75. package/dist/es/config/index.browser.mjs +17 -0
  76. package/dist/es/config/index.node.d.mts +1604 -0
  77. package/dist/es/config/index.node.mjs +20 -0
  78. package/dist/es/define-EoYRZbpe.d.mts +34 -0
  79. package/dist/es/define-Z_Glf1-_.mjs +35 -0
  80. package/dist/es/environment-C84BPRJZ.mjs +104 -0
  81. package/dist/es/index-B0XqHwY5.d.mts +16 -0
  82. package/dist/es/{index-Bo0tQsVq.d.mts → index-D52xglhZ.d.mts} +177 -3
  83. package/dist/es/index.d.mts +217 -0
  84. package/dist/es/index.mjs +242 -0
  85. package/dist/es/{config-CcE0EBG7.mjs → index.node-CDH5gwJE.mjs} +94 -30
  86. package/dist/es/management/index.d.mts +1 -2
  87. package/dist/es/management/index.mjs +1 -1
  88. package/dist/es/{management-BZ4Y6lVp.mjs → management-B89ApQVY.mjs} +402 -562
  89. package/dist/es/openapi-CXonvevE.mjs +2900 -0
  90. package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
  91. package/dist/es/utils-_gj8L6eN.mjs +289 -0
  92. package/dist/es/{validate-Du3LhCre.mjs → validate-9cRZWGrA.mjs} +49 -29
  93. package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
  94. package/package.json +52 -22
  95. package/dist/cjs/actions/app-config.cjs +0 -54
  96. package/dist/cjs/actions/registration.cjs +0 -40
  97. package/dist/cjs/actions/registration.d.cts +0 -32
  98. package/dist/cjs/admin-ui-sdk-DZZJCrdT.d.cts +0 -665
  99. package/dist/cjs/app-CakwxQvs.d.cts +0 -673
  100. package/dist/cjs/config/index.d.cts +0 -1975
  101. package/dist/cjs/step-CKVE0aJi.d.cts +0 -187
  102. package/dist/es/actions/app-config.mjs +0 -53
  103. package/dist/es/actions/registration.d.mts +0 -32
  104. package/dist/es/actions/registration.mjs +0 -39
  105. package/dist/es/admin-ui-sdk-hu6iWr0A.d.mts +0 -667
  106. package/dist/es/app-CakwxQvs.d.mts +0 -673
  107. package/dist/es/config/index.d.mts +0 -1975
  108. package/dist/es/config/index.mjs +0 -19
  109. package/dist/es/step-D64mMPrt.d.mts +0 -187
  110. /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
@@ -12,10 +12,10 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-Cozy-1ZF.cjs');
15
+ const require_rolldown_runtime = require('./rolldown-runtime-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
- _adobe_aio_lib_core_logging = require_chunk.__toESM(_adobe_aio_lib_core_logging, 1);
18
+ _adobe_aio_lib_core_logging = require_rolldown_runtime.__toESM(_adobe_aio_lib_core_logging, 1);
19
19
  let regexparam = require("regexparam");
20
20
 
21
21
  //#region ../../packages-private/common-utils/source/actions/http/middleware/logger.ts
@@ -68,15 +68,15 @@ function logger({ name, ...restOptions } = {}) {
68
68
  async function validateSchema(schema, input) {
69
69
  const result = await schema["~standard"].validate(input);
70
70
  if (result.issues) return {
71
- success: false,
72
71
  issues: result.issues.map((issue) => ({
73
72
  message: issue.message,
74
73
  path: issue.path?.map((segment) => typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment)
75
- }))
74
+ })),
75
+ success: false
76
76
  };
77
77
  return {
78
- success: true,
79
- data: result.value
78
+ data: result.value,
79
+ success: true
80
80
  };
81
81
  }
82
82
  /**
@@ -158,23 +158,21 @@ function parseQueryParams(queryString, fallbackParams) {
158
158
  * ```
159
159
  */
160
160
  var HttpActionRouter = class {
161
- constructor() {
162
- this.routes = [];
163
- this.contextBuilders = [];
164
- }
161
+ routes = [];
162
+ contextBuilders = [];
165
163
  /**
166
164
  * Internal method to add a route to the router.
167
165
  */
168
166
  addRoute(method, path, config) {
169
167
  const { pattern, keys } = (0, regexparam.parse)(path);
170
168
  this.routes.push({
171
- method,
172
- pattern,
169
+ body: config.body,
170
+ handler: config.handler,
173
171
  keys,
172
+ method,
174
173
  params: config.params,
175
- body: config.body,
176
- query: config.query,
177
- handler: config.handler
174
+ pattern,
175
+ query: config.query
178
176
  });
179
177
  return this;
180
178
  }
@@ -294,17 +292,17 @@ var HttpActionRouter = class {
294
292
  */
295
293
  async validateParams(route, params) {
296
294
  if (!route.params) return {
297
- success: true,
298
- data: params
295
+ data: params,
296
+ success: true
299
297
  };
300
298
  const result = await validateSchema(route.params, params);
301
299
  if (!result.success) return {
302
- success: false,
303
- issues: result.issues
300
+ issues: result.issues,
301
+ success: false
304
302
  };
305
303
  return {
306
- success: true,
307
- data: result.data
304
+ data: result.data,
305
+ success: true
308
306
  };
309
307
  }
310
308
  /**
@@ -312,17 +310,17 @@ var HttpActionRouter = class {
312
310
  */
313
311
  async validateBody(route, body) {
314
312
  if (!route.body) return {
315
- success: true,
316
- data: body
313
+ data: body,
314
+ success: true
317
315
  };
318
316
  const result = await validateSchema(route.body, body);
319
317
  if (!result.success) return {
320
- success: false,
321
- issues: result.issues
318
+ issues: result.issues,
319
+ success: false
322
320
  };
323
321
  return {
324
- success: true,
325
- data: result.data
322
+ data: result.data,
323
+ success: true
326
324
  };
327
325
  }
328
326
  /**
@@ -330,17 +328,17 @@ var HttpActionRouter = class {
330
328
  */
331
329
  async validateQuery(route, query) {
332
330
  if (!route.query) return {
333
- success: true,
334
- data: query
331
+ data: query,
332
+ success: true
335
333
  };
336
334
  const result = await validateSchema(route.query, query);
337
335
  if (!result.success) return {
338
- success: false,
339
- issues: result.issues
336
+ issues: result.issues,
337
+ success: false
340
338
  };
341
339
  return {
342
- success: true,
343
- data: result.data
340
+ data: result.data,
341
+ success: true
344
342
  };
345
343
  }
346
344
  /** Handles a matched route by validating inputs and calling the handler. */
@@ -351,33 +349,33 @@ var HttpActionRouter = class {
351
349
  });
352
350
  const paramsResult = await this.validateParams(route, params);
353
351
  if (!paramsResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
354
- message: "Invalid route parameters",
355
- issues: paramsResult.issues
352
+ issues: paramsResult.issues,
353
+ message: "Invalid route parameters"
356
354
  } });
357
355
  const bodyResult = await this.validateBody(route, body);
358
356
  if (!bodyResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
359
- message: "Invalid request body",
360
- issues: bodyResult.issues
357
+ issues: bodyResult.issues,
358
+ message: "Invalid request body"
361
359
  } });
362
360
  const queryResult = await this.validateQuery(route, query);
363
361
  if (!queryResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
364
- message: "Invalid query parameters",
365
- issues: queryResult.issues
362
+ issues: queryResult.issues,
363
+ message: "Invalid query parameters"
366
364
  } });
367
365
  try {
368
366
  return await route.handler({
369
- params: paramsResult.data,
370
367
  body: bodyResult.data,
371
- query: queryResult.data,
372
368
  headers,
373
369
  method,
374
- path
370
+ params: paramsResult.data,
371
+ path,
372
+ query: queryResult.data
375
373
  }, context);
376
374
  } catch (err) {
377
375
  console.error("Handler error:", err);
378
376
  return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
379
- message: "Internal server error",
380
- error: err instanceof Error ? err.message : "Unknown error"
377
+ error: err instanceof Error ? err.message : "Unknown error",
378
+ message: "Internal server error"
381
379
  } });
382
380
  }
383
381
  }
@@ -12,9 +12,9 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const require_chunk = require('./chunk-Cozy-1ZF.cjs');
15
+ const require_rolldown_runtime = require('./rolldown-runtime-Cozy-1ZF.cjs');
16
16
  let valibot = require("valibot");
17
- valibot = require_chunk.__toESM(valibot, 1);
17
+ valibot = require_rolldown_runtime.__toESM(valibot, 1);
18
18
 
19
19
  //#region ../../packages-private/common-utils/source/valibot/schemas.ts
20
20
  const ALPHANUMERIC_OR_HYPHEN_REGEX = {
@@ -0,0 +1,408 @@
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
+ let _adobe_aio_commerce_lib_auth = require("@adobe/aio-commerce-lib-auth");
16
+
17
+ //#region source/management/installation/events/utils.ts
18
+ const COMMERCE_PROVIDER_TYPE = "dx_commerce_events";
19
+ const EXTERNAL_PROVIDER_TYPE = "3rd_party_custom_events";
20
+ const PROVIDER_TYPE_TO_LABEL = {
21
+ [COMMERCE_PROVIDER_TYPE]: "Commerce",
22
+ [EXTERNAL_PROVIDER_TYPE]: "External"
23
+ };
24
+ /** Max characters taken from `metadata.id` in the I/O Events provider `instance_id`. */
25
+ const METADATA_ID_MAX_LENGTH_FOR_INSTANCE_ID = 100;
26
+ /** Storage key used for the events installation data in system config. */
27
+ const EVENTS_STORAGE_KEY = "events";
28
+ /**
29
+ * Generates a unique instance ID for I/O Events for this app deployment.
30
+ * Uses `{metadata.id (first 100 chars)}-{providerKeyOrSlug}-{workspaceId}` (lowercased).
31
+ *
32
+ * @param metadata - The metadata of the application
33
+ * @param provider - The event provider (optional `key`, else label is slugified)
34
+ * @param workspaceId - Adobe I/O Developer Console workspace ID for this deployment
35
+ */
36
+ function generateInstanceId(metadata, provider, workspaceId) {
37
+ return `${metadata.id.slice(0, METADATA_ID_MAX_LENGTH_FOR_INSTANCE_ID)}-${provider.key ?? provider.label.toLowerCase().replace(/\s+/g, "-")}-${workspaceId}`.toLowerCase();
38
+ }
39
+ /**
40
+ * Old version of instanceId generator which can be not unique within the same ORG.
41
+ *
42
+ * @param metadata - The metadata of the application
43
+ * @param provider - The event provider for which to generate the instance ID
44
+ * @deprecated use {@link generateInstanceId} instead
45
+ */
46
+ function generateInstanceIdDeprecated(metadata, provider) {
47
+ const slugLabel = provider.label.toLowerCase().replace(/\s+/g, "-");
48
+ return `${metadata.id}-${provider.key ?? slugLabel}`.toLowerCase();
49
+ }
50
+ /**
51
+ * Find an existing event provider by its instance ID.
52
+ * @param allProviders - The list of all existing event providers.
53
+ * @param instanceId - The instance ID to search for.
54
+ */
55
+ function findExistingProvider(allProviders, instanceId) {
56
+ return allProviders.find((provider) => provider.instance_id === instanceId) ?? null;
57
+ }
58
+ /**
59
+ * Find existing event metadata by its event name.
60
+ * @param allMetadata - The list of all existing event metadata.
61
+ * @param eventName - The event name to search for.
62
+ */
63
+ function findExistingProviderMetadata(allMetadata, eventName) {
64
+ return allMetadata.find((meta) => meta.event_code === eventName) ?? null;
65
+ }
66
+ /**
67
+ * Find existing event registrations by client ID and name.
68
+ * @param allRegistrations - The list of all existing event registrations.
69
+ * @param clientId - The client ID of the workspace where the registration was created.
70
+ * @param name - The name of the registration to search for.
71
+ */
72
+ function findExistingRegistrations(allRegistrations, clientId, name) {
73
+ return allRegistrations.find((reg) => reg.client_id === clientId && reg.name === name);
74
+ }
75
+ /**
76
+ * Generates a namespaced event name by combining the application ID with the event name.
77
+ *
78
+ * The application ID is sanitized to comply with the Commerce Eventing API's event code
79
+ * format requirement (`[a-zA-Z0-9_.]`): any character outside that set is replaced with `_`.
80
+ *
81
+ * @param metadata
82
+ * @param name
83
+ */
84
+ function getNamespacedEvent(metadata, name) {
85
+ return `${metadata.id.toLowerCase().replace(/[^a-z0-9_]/g, "_")}.${name}`.toLowerCase();
86
+ }
87
+ /**
88
+ * Get the fully qualified name of an event for I/O Events based on the provider type.
89
+ * @param name - The name of the event.
90
+ * @param providerType - The type of the event provider.
91
+ */
92
+ function getIoEventCode(name, providerType) {
93
+ return providerType === "dx_commerce_events" ? `com.adobe.commerce.${name}` : name;
94
+ }
95
+ /** Maps a provider's metadata type to its human-readable label ("Commerce" or "External"). */
96
+ function getProviderTypeLabel(provider) {
97
+ return PROVIDER_TYPE_TO_LABEL[provider.provider_metadata];
98
+ }
99
+ /**
100
+ * Generates a registration name based on the provider type, provider label, and runtime action.
101
+ *
102
+ * Prefixes with the provider type label ("Commerce" or "External") for readability, then the
103
+ * provider's own label to ensure uniqueness when multiple providers of the same type route
104
+ * events to the same runtime action.
105
+ *
106
+ * @param provider - The provider this registration is associated to.
107
+ * @param runtimeAction - The runtime action this registration points to.
108
+ */
109
+ function getRegistrationName(provider, runtimeAction) {
110
+ const [packageName, actionName] = runtimeAction.split("/").map(kebabToTitleCase);
111
+ return `${getProviderTypeLabel(provider)} Event Registration: ${provider.label} - ${actionName} (${packageName})`;
112
+ }
113
+ /**
114
+ * Returns the registration name in the legacy format used by SDK versions that built
115
+ * the name from the generic provider type label ("Commerce" / "External") rather than
116
+ * the provider's own label. Used during uninstall to match registrations that were
117
+ * created before the naming change.
118
+ *
119
+ * @param provider - The provider this registration is associated to.
120
+ * @param runtimeAction - The runtime action this registration points to.
121
+ * @deprecated Use {@link getRegistrationName} for all new registrations.
122
+ */
123
+ function getLegacyRegistrationName(provider, runtimeAction) {
124
+ const [packageName, actionName] = runtimeAction.split("/").map(kebabToTitleCase);
125
+ return `${getProviderTypeLabel(provider)} Event Registration: ${actionName} (${packageName})`;
126
+ }
127
+ /**
128
+ * Generates a registration name and description based on the provider, events, and runtime action.
129
+ * @param provider - The provider this registration is associated to.
130
+ * @param events - The events routed by this registration.
131
+ * @param runtimeAction - The runtime action this registration points to.
132
+ */
133
+ function getRegistrationDescription(provider, events, runtimeAction) {
134
+ return [
135
+ "This registration was automatically created by @adobe/aio-commerce-lib-app. ",
136
+ `It belongs to the provider "${provider.label}" (instance ID: ${provider.instance_id}). `,
137
+ `It routes ${events.length} event(s) to the runtime action "${runtimeAction}".`
138
+ ].join("\n");
139
+ }
140
+ /**
141
+ * Converts a kebab-case string to Title Case.
142
+ * @param str - The kebab-case string to convert.
143
+ */
144
+ function kebabToTitleCase(str) {
145
+ return str.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
146
+ }
147
+ /**
148
+ * Groups events by their runtime actions. Since each event can have multiple
149
+ * runtime actions, this function creates a mapping where each unique runtime
150
+ * action points to all events that target it.
151
+ *
152
+ * @param events - The events to group by runtime actions.
153
+ */
154
+ function groupEventsByRuntimeActions(events) {
155
+ const actionEventsMap = /* @__PURE__ */ new Map();
156
+ for (const event of events) for (const runtimeAction of event.runtimeActions) {
157
+ const existingEvents = actionEventsMap.get(runtimeAction) ?? [];
158
+ actionEventsMap.set(runtimeAction, [...existingEvents, event]);
159
+ }
160
+ return actionEventsMap;
161
+ }
162
+ function findExistingSubscription(allSubscriptions, eventName) {
163
+ return allSubscriptions.get(eventName) ?? null;
164
+ }
165
+ /**
166
+ * Builds the payload to send to Commerce when configuring Eventing.
167
+ * Returns `null` when no update call is needed.
168
+ *
169
+ * @param initialParams - Initial Commerce Eventing configuration parameters.
170
+ * @param existingData - Existing Commerce Eventing state from the API.
171
+ */
172
+ function getCommerceEventingConfigurationUpdateParams(initialParams, existingData) {
173
+ const { isDefaultProviderConfigured, isDefaultWorkspaceConfigurationEmpty } = existingData;
174
+ if (isDefaultProviderConfigured && !isDefaultWorkspaceConfigurationEmpty) return null;
175
+ const { workspace_configuration, ...configWithoutWorkspace } = initialParams;
176
+ let updateParams = { enabled: true };
177
+ if (isDefaultWorkspaceConfigurationEmpty) {
178
+ if (!workspace_configuration) throw new Error("Workspace configuration is required to enable Commerce Eventing when there is not an existing one.");
179
+ updateParams.workspace_configuration = workspace_configuration;
180
+ }
181
+ if (!isDefaultProviderConfigured) updateParams = {
182
+ ...updateParams,
183
+ ...configWithoutWorkspace
184
+ };
185
+ return updateParams;
186
+ }
187
+ /**
188
+ * Sanitizes a Commerce Eventing identifier.
189
+ * Preserves underscores, converts spaces to underscores, lowercases, and strips the rest.
190
+ *
191
+ * @param value - The raw identifier value to normalize.
192
+ */
193
+ function sanitizeEventingIdentifier(value) {
194
+ return value.toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "");
195
+ }
196
+ /**
197
+ * Creates a partially filled workspace configuration object based on the app credentials and parameters.
198
+ * This configuration is used when creating an event provider in Commerce.
199
+ *
200
+ * @param context - The execution context containing app credentials and parameters.
201
+ */
202
+ function makeWorkspaceConfig(context) {
203
+ const { appData, params } = context;
204
+ const { consumerOrgId, orgName, projectId, projectName, projectTitle, workspaceId, workspaceName, workspaceTitle } = appData;
205
+ const authParams = (0, _adobe_aio_commerce_lib_auth.resolveAuthParams)(params);
206
+ if (authParams.strategy !== "ims") throw new Error("Failed to resolve IMS authentication parameters from the runtime action inputs.");
207
+ const { clientId, clientSecrets, technicalAccountEmail, technicalAccountId, imsOrgId, scopes } = authParams;
208
+ return { project: {
209
+ id: projectId,
210
+ name: projectName,
211
+ org: {
212
+ id: consumerOrgId,
213
+ ims_org_id: imsOrgId,
214
+ name: orgName
215
+ },
216
+ title: projectTitle,
217
+ workspace: {
218
+ action_url: `https://${process.env.__OW_NAMESPACE}.adobeioruntime.net`,
219
+ app_url: `https://${process.env.__OW_NAMESPACE}.adobeio-static.net`,
220
+ details: { credentials: [{
221
+ id: "000000",
222
+ integration_type: "oauth_server_to_server",
223
+ name: `aio-${workspaceId}`,
224
+ oauth_server_to_server: {
225
+ client_id: clientId,
226
+ client_secrets: clientSecrets,
227
+ scopes: scopes.map((scope) => scope.trim()),
228
+ technical_account_email: technicalAccountEmail,
229
+ technical_account_id: technicalAccountId
230
+ }
231
+ }] },
232
+ id: workspaceId,
233
+ name: workspaceName,
234
+ title: workspaceTitle
235
+ }
236
+ } };
237
+ }
238
+ /**
239
+ * Retrieves the current existing data and returns it in a normalized way.
240
+ * @param context The execution context.
241
+ */
242
+ async function getIoEventsExistingData(context) {
243
+ const { ioEventsClient, appData } = context;
244
+ const appCredentials = {
245
+ consumerOrgId: appData.consumerOrgId,
246
+ projectId: appData.projectId,
247
+ workspaceId: appData.workspaceId
248
+ };
249
+ const { _embedded: { providers: existingProviders } } = await ioEventsClient.getAllEventProviders({
250
+ consumerOrgId: appData.consumerOrgId,
251
+ withEventMetadata: true
252
+ });
253
+ const providersWithMetadata = existingProviders.map((providerHal) => {
254
+ const { _embedded, _links, ...providerData } = providerHal;
255
+ const actualMetadata = (_embedded?.eventmetadata ?? []).map(({ _embedded: metadataEmbedded, _links: _metadataLinks, ...meta }) => ({
256
+ ...meta,
257
+ sample: metadataEmbedded?.sample_event ?? null
258
+ }));
259
+ return {
260
+ ...providerData,
261
+ metadata: actualMetadata
262
+ };
263
+ });
264
+ const { _embedded: { registrations: registrationsHal } } = await ioEventsClient.getAllRegistrations(appCredentials);
265
+ return {
266
+ providersWithMetadata,
267
+ registrations: registrationsHal.map(({ _links, ...reg }) => reg)
268
+ };
269
+ }
270
+ /**
271
+ * Retrieves the current existing Commerce eventing data and returns it in a normalized way.
272
+ * @param context - The execution context.
273
+ */
274
+ async function getCommerceEventingExistingData(context) {
275
+ const { commerceEventsClient } = context;
276
+ const existingProviders = await commerceEventsClient.getAllEventProviders();
277
+ const existingSubscriptions = await commerceEventsClient.getAllEventSubscriptions();
278
+ const defaultProvider = existingProviders.find((provider) => !("id" in provider)) ?? null;
279
+ const isDefaultProviderConfigured = defaultProvider !== null;
280
+ return {
281
+ isDefaultProviderConfigured,
282
+ isDefaultWorkspaceConfigurationEmpty: isDefaultProviderConfigured ? !defaultProvider.workspace_configuration?.trim() : true,
283
+ providers: existingProviders,
284
+ subscriptions: new Map(existingSubscriptions.map((subscription) => [subscription.name, subscription]))
285
+ };
286
+ }
287
+
288
+ //#endregion
289
+ Object.defineProperty(exports, 'COMMERCE_PROVIDER_TYPE', {
290
+ enumerable: true,
291
+ get: function () {
292
+ return COMMERCE_PROVIDER_TYPE;
293
+ }
294
+ });
295
+ Object.defineProperty(exports, 'EVENTS_STORAGE_KEY', {
296
+ enumerable: true,
297
+ get: function () {
298
+ return EVENTS_STORAGE_KEY;
299
+ }
300
+ });
301
+ Object.defineProperty(exports, 'EXTERNAL_PROVIDER_TYPE', {
302
+ enumerable: true,
303
+ get: function () {
304
+ return EXTERNAL_PROVIDER_TYPE;
305
+ }
306
+ });
307
+ Object.defineProperty(exports, 'findExistingProvider', {
308
+ enumerable: true,
309
+ get: function () {
310
+ return findExistingProvider;
311
+ }
312
+ });
313
+ Object.defineProperty(exports, 'findExistingProviderMetadata', {
314
+ enumerable: true,
315
+ get: function () {
316
+ return findExistingProviderMetadata;
317
+ }
318
+ });
319
+ Object.defineProperty(exports, 'findExistingRegistrations', {
320
+ enumerable: true,
321
+ get: function () {
322
+ return findExistingRegistrations;
323
+ }
324
+ });
325
+ Object.defineProperty(exports, 'findExistingSubscription', {
326
+ enumerable: true,
327
+ get: function () {
328
+ return findExistingSubscription;
329
+ }
330
+ });
331
+ Object.defineProperty(exports, 'generateInstanceId', {
332
+ enumerable: true,
333
+ get: function () {
334
+ return generateInstanceId;
335
+ }
336
+ });
337
+ Object.defineProperty(exports, 'generateInstanceIdDeprecated', {
338
+ enumerable: true,
339
+ get: function () {
340
+ return generateInstanceIdDeprecated;
341
+ }
342
+ });
343
+ Object.defineProperty(exports, 'getCommerceEventingConfigurationUpdateParams', {
344
+ enumerable: true,
345
+ get: function () {
346
+ return getCommerceEventingConfigurationUpdateParams;
347
+ }
348
+ });
349
+ Object.defineProperty(exports, 'getCommerceEventingExistingData', {
350
+ enumerable: true,
351
+ get: function () {
352
+ return getCommerceEventingExistingData;
353
+ }
354
+ });
355
+ Object.defineProperty(exports, 'getIoEventCode', {
356
+ enumerable: true,
357
+ get: function () {
358
+ return getIoEventCode;
359
+ }
360
+ });
361
+ Object.defineProperty(exports, 'getIoEventsExistingData', {
362
+ enumerable: true,
363
+ get: function () {
364
+ return getIoEventsExistingData;
365
+ }
366
+ });
367
+ Object.defineProperty(exports, 'getLegacyRegistrationName', {
368
+ enumerable: true,
369
+ get: function () {
370
+ return getLegacyRegistrationName;
371
+ }
372
+ });
373
+ Object.defineProperty(exports, 'getNamespacedEvent', {
374
+ enumerable: true,
375
+ get: function () {
376
+ return getNamespacedEvent;
377
+ }
378
+ });
379
+ Object.defineProperty(exports, 'getRegistrationDescription', {
380
+ enumerable: true,
381
+ get: function () {
382
+ return getRegistrationDescription;
383
+ }
384
+ });
385
+ Object.defineProperty(exports, 'getRegistrationName', {
386
+ enumerable: true,
387
+ get: function () {
388
+ return getRegistrationName;
389
+ }
390
+ });
391
+ Object.defineProperty(exports, 'groupEventsByRuntimeActions', {
392
+ enumerable: true,
393
+ get: function () {
394
+ return groupEventsByRuntimeActions;
395
+ }
396
+ });
397
+ Object.defineProperty(exports, 'makeWorkspaceConfig', {
398
+ enumerable: true,
399
+ get: function () {
400
+ return makeWorkspaceConfig;
401
+ }
402
+ });
403
+ Object.defineProperty(exports, 'sanitizeEventingIdentifier', {
404
+ enumerable: true,
405
+ get: function () {
406
+ return sanitizeEventingIdentifier;
407
+ }
408
+ });