@adobe/aio-commerce-lib-app 1.7.0 → 1.8.0-beta-20260714082406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/dist/cjs/actions/app-config/index.cjs +41 -38
- package/dist/cjs/actions/app-config/index.d.cts +1 -1
- package/dist/cjs/actions/association/index.cjs +85 -0
- package/dist/cjs/actions/{registration → association}/index.d.cts +9 -13
- package/dist/cjs/actions/config/index.cjs +21 -32
- package/dist/cjs/actions/installation/index.cjs +72 -51
- package/dist/cjs/actions/installation/index.d.cts +2 -2
- package/dist/cjs/actions/scope-tree/index.cjs +18 -17
- package/dist/{es/app-DrYHK-z1.d.mts → cjs/app-D3P-Z6uY.d.cts} +1085 -1035
- package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
- package/dist/cjs/commands/index.cjs +512 -298
- package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
- package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
- package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/cjs/config/index.browser.cjs +18 -0
- package/dist/cjs/config/index.browser.d.cts +16 -0
- package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
- package/dist/cjs/config/{index.d.cts → index.node.d.cts} +954 -386
- package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
- package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
- package/dist/cjs/environment-B7EnozSg.cjs +135 -0
- package/dist/cjs/{index-B5gJ-q4U.d.cts → index-CzReNwbF.d.cts} +17 -12
- package/dist/cjs/index.cjs +250 -0
- package/dist/cjs/index.d.cts +217 -0
- package/dist/cjs/{config-D-s0GSep.cjs → index.node-Dz4lV4qe.cjs} +119 -35
- package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
- package/dist/cjs/management/index.cjs +1 -1
- package/dist/cjs/management/index.d.cts +1 -1
- package/dist/cjs/{management-Dehz9qSJ.cjs → management-B9ItB80R.cjs} +385 -582
- package/dist/cjs/{openapi-Cux6K4ZD.cjs → openapi-CwytYdWl.cjs} +476 -600
- package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
- package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
- package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
- package/dist/cjs/{validate-oAOpyFyb.cjs → validate-BfxhZ5Wv.cjs} +20 -20
- package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
- package/dist/es/actions/app-config/index.d.mts +1 -1
- package/dist/es/actions/app-config/index.mjs +39 -36
- package/dist/es/actions/{registration → association}/index.d.mts +9 -13
- package/dist/es/actions/association/index.mjs +82 -0
- package/dist/es/actions/config/index.mjs +17 -28
- package/dist/es/actions/installation/index.d.mts +2 -2
- package/dist/es/actions/installation/index.mjs +69 -48
- package/dist/es/actions/scope-tree/index.mjs +14 -13
- package/dist/{cjs/app-DrYHK-z1.d.cts → es/app-D3P-Z6uY.d.mts} +1085 -1035
- package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
- package/dist/es/commands/index.mjs +544 -328
- package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/es/commands/templates/app-management/association.js.template +6 -0
- package/dist/es/commands/templates/app-management/installation.js.template +1 -13
- package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/es/config/index.browser.d.mts +16 -0
- package/dist/es/config/index.browser.mjs +17 -0
- package/dist/es/config/{index.d.mts → index.node.d.mts} +954 -386
- package/dist/es/config/{index.mjs → index.node.mjs} +5 -4
- package/dist/es/define-EoYRZbpe.d.mts +34 -0
- package/dist/es/define-Z_Glf1-_.mjs +35 -0
- package/dist/es/environment-C84BPRJZ.mjs +104 -0
- package/dist/es/{index-DLMbTtKS.d.mts → index-D52xglhZ.d.mts} +17 -12
- package/dist/es/index.d.mts +217 -0
- package/dist/es/index.mjs +242 -0
- package/dist/es/{config-3I4eLyyR.mjs → index.node-CDH5gwJE.mjs} +94 -30
- package/dist/es/management/index.d.mts +1 -1
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/{management-BUX-w2Ji.mjs → management-B89ApQVY.mjs} +353 -550
- package/dist/es/{openapi-B6uP0SRn.mjs → openapi-CXonvevE.mjs} +476 -600
- package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
- package/dist/es/utils-_gj8L6eN.mjs +289 -0
- package/dist/es/{validate-Dfajrp99.mjs → validate-9cRZWGrA.mjs} +17 -17
- package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
- package/package.json +40 -17
- package/dist/cjs/actions/registration/index.cjs +0 -50
- package/dist/cjs/admin-ui-sdk-EU915zlR.d.cts +0 -664
- package/dist/es/actions/registration/index.mjs +0 -49
- package/dist/es/admin-ui-sdk-BwnD0xjK.d.mts +0 -664
- /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
|
@@ -66,15 +66,15 @@ function logger({ name, ...restOptions } = {}) {
|
|
|
66
66
|
async function validateSchema(schema, input) {
|
|
67
67
|
const result = await schema["~standard"].validate(input);
|
|
68
68
|
if (result.issues) return {
|
|
69
|
-
success: false,
|
|
70
69
|
issues: result.issues.map((issue) => ({
|
|
71
70
|
message: issue.message,
|
|
72
71
|
path: issue.path?.map((segment) => typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment)
|
|
73
|
-
}))
|
|
72
|
+
})),
|
|
73
|
+
success: false
|
|
74
74
|
};
|
|
75
75
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
data: result.value,
|
|
77
|
+
success: true
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -156,23 +156,21 @@ function parseQueryParams(queryString, fallbackParams) {
|
|
|
156
156
|
* ```
|
|
157
157
|
*/
|
|
158
158
|
var HttpActionRouter = class {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.contextBuilders = [];
|
|
162
|
-
}
|
|
159
|
+
routes = [];
|
|
160
|
+
contextBuilders = [];
|
|
163
161
|
/**
|
|
164
162
|
* Internal method to add a route to the router.
|
|
165
163
|
*/
|
|
166
164
|
addRoute(method, path, config) {
|
|
167
165
|
const { pattern, keys } = parse(path);
|
|
168
166
|
this.routes.push({
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
body: config.body,
|
|
168
|
+
handler: config.handler,
|
|
171
169
|
keys,
|
|
170
|
+
method,
|
|
172
171
|
params: config.params,
|
|
173
|
-
|
|
174
|
-
query: config.query
|
|
175
|
-
handler: config.handler
|
|
172
|
+
pattern,
|
|
173
|
+
query: config.query
|
|
176
174
|
});
|
|
177
175
|
return this;
|
|
178
176
|
}
|
|
@@ -292,17 +290,17 @@ var HttpActionRouter = class {
|
|
|
292
290
|
*/
|
|
293
291
|
async validateParams(route, params) {
|
|
294
292
|
if (!route.params) return {
|
|
295
|
-
|
|
296
|
-
|
|
293
|
+
data: params,
|
|
294
|
+
success: true
|
|
297
295
|
};
|
|
298
296
|
const result = await validateSchema(route.params, params);
|
|
299
297
|
if (!result.success) return {
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
issues: result.issues,
|
|
299
|
+
success: false
|
|
302
300
|
};
|
|
303
301
|
return {
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
data: result.data,
|
|
303
|
+
success: true
|
|
306
304
|
};
|
|
307
305
|
}
|
|
308
306
|
/**
|
|
@@ -310,17 +308,17 @@ var HttpActionRouter = class {
|
|
|
310
308
|
*/
|
|
311
309
|
async validateBody(route, body) {
|
|
312
310
|
if (!route.body) return {
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
data: body,
|
|
312
|
+
success: true
|
|
315
313
|
};
|
|
316
314
|
const result = await validateSchema(route.body, body);
|
|
317
315
|
if (!result.success) return {
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
issues: result.issues,
|
|
317
|
+
success: false
|
|
320
318
|
};
|
|
321
319
|
return {
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
data: result.data,
|
|
321
|
+
success: true
|
|
324
322
|
};
|
|
325
323
|
}
|
|
326
324
|
/**
|
|
@@ -328,17 +326,17 @@ var HttpActionRouter = class {
|
|
|
328
326
|
*/
|
|
329
327
|
async validateQuery(route, query) {
|
|
330
328
|
if (!route.query) return {
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
data: query,
|
|
330
|
+
success: true
|
|
333
331
|
};
|
|
334
332
|
const result = await validateSchema(route.query, query);
|
|
335
333
|
if (!result.success) return {
|
|
336
|
-
|
|
337
|
-
|
|
334
|
+
issues: result.issues,
|
|
335
|
+
success: false
|
|
338
336
|
};
|
|
339
337
|
return {
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
data: result.data,
|
|
339
|
+
success: true
|
|
342
340
|
};
|
|
343
341
|
}
|
|
344
342
|
/** Handles a matched route by validating inputs and calling the handler. */
|
|
@@ -349,33 +347,33 @@ var HttpActionRouter = class {
|
|
|
349
347
|
});
|
|
350
348
|
const paramsResult = await this.validateParams(route, params);
|
|
351
349
|
if (!paramsResult.success) return badRequest({ body: {
|
|
352
|
-
|
|
353
|
-
|
|
350
|
+
issues: paramsResult.issues,
|
|
351
|
+
message: "Invalid route parameters"
|
|
354
352
|
} });
|
|
355
353
|
const bodyResult = await this.validateBody(route, body);
|
|
356
354
|
if (!bodyResult.success) return badRequest({ body: {
|
|
357
|
-
|
|
358
|
-
|
|
355
|
+
issues: bodyResult.issues,
|
|
356
|
+
message: "Invalid request body"
|
|
359
357
|
} });
|
|
360
358
|
const queryResult = await this.validateQuery(route, query);
|
|
361
359
|
if (!queryResult.success) return badRequest({ body: {
|
|
362
|
-
|
|
363
|
-
|
|
360
|
+
issues: queryResult.issues,
|
|
361
|
+
message: "Invalid query parameters"
|
|
364
362
|
} });
|
|
365
363
|
try {
|
|
366
364
|
return await route.handler({
|
|
367
|
-
params: paramsResult.data,
|
|
368
365
|
body: bodyResult.data,
|
|
369
|
-
query: queryResult.data,
|
|
370
366
|
headers,
|
|
371
367
|
method,
|
|
372
|
-
|
|
368
|
+
params: paramsResult.data,
|
|
369
|
+
path,
|
|
370
|
+
query: queryResult.data
|
|
373
371
|
}, context);
|
|
374
372
|
} catch (err) {
|
|
375
373
|
console.error("Handler error:", err);
|
|
376
374
|
return internalServerError({ body: {
|
|
377
|
-
message: "
|
|
378
|
-
|
|
375
|
+
error: err instanceof Error ? err.message : "Unknown error",
|
|
376
|
+
message: "Internal server error"
|
|
379
377
|
} });
|
|
380
378
|
}
|
|
381
379
|
}
|
|
@@ -0,0 +1,289 @@
|
|
|
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 { resolveAuthParams } from "@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 = 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
|
+
export { getRegistrationName as _, findExistingProviderMetadata as a, sanitizeEventingIdentifier as b, generateInstanceId as c, getCommerceEventingExistingData as d, getIoEventCode as f, getRegistrationDescription as g, getNamespacedEvent as h, findExistingProvider as i, generateInstanceIdDeprecated as l, getLegacyRegistrationName as m, EVENTS_STORAGE_KEY as n, findExistingRegistrations as o, getIoEventsExistingData as p, EXTERNAL_PROVIDER_TYPE as r, findExistingSubscription as s, COMMERCE_PROVIDER_TYPE as t, getCommerceEventingConfigurationUpdateParams as u, groupEventsByRuntimeActions as v, makeWorkspaceConfig as y };
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { t as alphaNumericOrHyphenSchema } from "./schemas-hRovglBF.mjs";
|
|
16
|
-
import { a as hasCustomInstallationSteps, d as
|
|
16
|
+
import { a as hasCustomInstallationSteps, d as hasAdminUi, i as hasCustomInstallation, l as hasExternalEvents, n as hasWebhooks, o as EventingSchema, r as InstallationSchema, s as hasCommerceEvents, t as WebhooksSchema, u as AdminUiSchema } from "./webhooks-BBPbY2mb.mjs";
|
|
17
17
|
import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
|
|
18
18
|
import { SchemaBusinessConfig } from "@adobe/aio-commerce-lib-config";
|
|
19
19
|
import * as v from "valibot";
|
|
@@ -46,9 +46,9 @@ function nonEmptyString(fieldName) {
|
|
|
46
46
|
}
|
|
47
47
|
/** The schema for the metadata of the application. */
|
|
48
48
|
const MetadataSchema = v.object({
|
|
49
|
-
id: v.pipe(alphaNumericOrHyphenSchema("application id (metadata.id)"), v.maxLength(MAX_ID_LENGTH, `The application id must not be longer than ${MAX_ID_LENGTH} characters`)),
|
|
50
|
-
displayName: v.pipe(nonEmptyString("application display name"), v.maxLength(MAX_DISPLAY_NAME_LENGTH, `The application display name must not be longer than ${MAX_DISPLAY_NAME_LENGTH} characters`)),
|
|
51
49
|
description: v.pipe(nonEmptyString("metadata description"), v.maxLength(MAX_DESCRIPTION_LENGTH, `The metadata description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
|
|
50
|
+
displayName: v.pipe(nonEmptyString("application display name"), v.maxLength(MAX_DISPLAY_NAME_LENGTH, `The application display name must not be longer than ${MAX_DISPLAY_NAME_LENGTH} characters`)),
|
|
51
|
+
id: v.pipe(alphaNumericOrHyphenSchema("application id (metadata.id)"), v.maxLength(MAX_ID_LENGTH, `The application id must not be longer than ${MAX_ID_LENGTH} characters`)),
|
|
52
52
|
version: v.pipe(nonEmptyString("version"), v.regex(SEMVER_REGEX, "The version must follow semantic versioning (semver) format: Major.Minor.Patch (e.g., '1.0.0', '2.3.1')"))
|
|
53
53
|
});
|
|
54
54
|
/**
|
|
@@ -63,16 +63,16 @@ function hasMetadata(config) {
|
|
|
63
63
|
//#region source/config/schema/domains.ts
|
|
64
64
|
/** The individual validatable domains of the app config. */
|
|
65
65
|
const CommerceAppConfigSchemas = {
|
|
66
|
-
|
|
66
|
+
adminUi: AdminUiSchema,
|
|
67
67
|
businessConfig: SchemaBusinessConfig,
|
|
68
|
-
eventing: EventingSchema,
|
|
69
|
-
installation: InstallationSchema,
|
|
70
|
-
webhooks: WebhooksSchema,
|
|
71
68
|
"businessConfig.schema": v.unwrap(SchemaBusinessConfig.entries.schema),
|
|
69
|
+
eventing: EventingSchema,
|
|
72
70
|
"eventing.commerce": v.unwrap(EventingSchema.entries.commerce),
|
|
73
71
|
"eventing.external": v.unwrap(EventingSchema.entries.external),
|
|
72
|
+
installation: InstallationSchema,
|
|
74
73
|
"installation.customInstallationSteps": v.unwrap(InstallationSchema.entries.customInstallationSteps),
|
|
75
|
-
|
|
74
|
+
metadata: MetadataSchema,
|
|
75
|
+
webhooks: WebhooksSchema
|
|
76
76
|
};
|
|
77
77
|
/**
|
|
78
78
|
* Get the config domains that are present in the config.
|
|
@@ -82,16 +82,16 @@ function getConfigDomains(config) {
|
|
|
82
82
|
const withCommerceEvents = hasCommerceEvents(config);
|
|
83
83
|
const withExternalEvents = hasExternalEvents(config);
|
|
84
84
|
const domains = {
|
|
85
|
-
|
|
85
|
+
adminUi: hasAdminUi(config),
|
|
86
86
|
businessConfig: hasBusinessConfig(config),
|
|
87
|
-
eventing: withCommerceEvents || withExternalEvents,
|
|
88
|
-
installation: hasCustomInstallation(config),
|
|
89
|
-
webhooks: hasWebhooks(config),
|
|
90
|
-
adminUiSdk: hasAdminUiSdk(config),
|
|
91
87
|
"businessConfig.schema": hasBusinessConfigSchema(config),
|
|
88
|
+
eventing: withCommerceEvents || withExternalEvents,
|
|
92
89
|
"eventing.commerce": withCommerceEvents,
|
|
93
90
|
"eventing.external": withExternalEvents,
|
|
94
|
-
|
|
91
|
+
installation: hasCustomInstallation(config),
|
|
92
|
+
"installation.customInstallationSteps": hasCustomInstallationSteps(config),
|
|
93
|
+
metadata: hasMetadata(config),
|
|
94
|
+
webhooks: hasWebhooks(config)
|
|
95
95
|
};
|
|
96
96
|
const domainsList = Object.entries(domains).filter(([_, value]) => value).map(([key]) => key);
|
|
97
97
|
return new Set(domainsList);
|
|
@@ -110,11 +110,11 @@ function hasConfigDomain(config, domain) {
|
|
|
110
110
|
/** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
|
|
111
111
|
/** The schema used to validate the commerce app config file. */
|
|
112
112
|
const CommerceAppConfigSchema = v.looseObject({
|
|
113
|
-
|
|
113
|
+
adminUi: v.optional(AdminUiSchema),
|
|
114
114
|
businessConfig: v.optional(SchemaBusinessConfig),
|
|
115
115
|
eventing: v.optional(EventingSchema),
|
|
116
|
-
adminUiSdk: v.optional(AdminUiSdkSchema),
|
|
117
116
|
installation: v.optional(InstallationSchema),
|
|
117
|
+
metadata: MetadataSchema,
|
|
118
118
|
webhooks: v.optional(WebhooksSchema)
|
|
119
119
|
});
|
|
120
120
|
/**
|
|
@@ -127,7 +127,7 @@ function requiresInstallationFromDomains(domains) {
|
|
|
127
127
|
"eventing.commerce",
|
|
128
128
|
"eventing.external",
|
|
129
129
|
"webhooks",
|
|
130
|
-
"
|
|
130
|
+
"adminUi"
|
|
131
131
|
].some((feature) => domains.has(feature));
|
|
132
132
|
}
|
|
133
133
|
/**
|