@adobe/aio-commerce-lib-app 0.3.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +1 -4
- package/bin/cli.mjs +24 -0
- package/dist/cjs/actions/app-config.cjs +27 -0
- package/dist/cjs/actions/app-config.d.cts +15 -0
- package/dist/cjs/actions/config.cjs +79 -0
- package/dist/cjs/actions/config.d.cts +15 -0
- package/dist/cjs/actions/installation.cjs +424 -0
- package/dist/cjs/actions/{index.d.cts → installation.d.cts} +4 -3
- package/dist/cjs/actions/scope-tree.cjs +97 -0
- package/dist/cjs/actions/scope-tree.d.cts +8 -0
- package/dist/cjs/{app-Dx0ca6oL.d.cts → app-PTKvEBea.d.cts} +6 -6
- package/dist/cjs/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
- package/dist/cjs/commands/generate/actions/templates/app-management/installation.js.template +1 -1
- package/dist/cjs/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
- package/dist/cjs/commands/index.cjs +105 -113
- package/dist/cjs/config/index.cjs +21 -19
- package/dist/cjs/config/index.d.cts +32 -332
- package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
- package/dist/cjs/installation-nwF2RC7F.cjs +241 -0
- package/dist/cjs/{logging-DYwr5WQk.cjs → logging-IDRQG0as.cjs} +2 -2
- package/dist/cjs/management/index.cjs +9 -8
- package/dist/cjs/management/index.d.cts +2 -2
- package/dist/cjs/parser-DIchX9SL.cjs +267 -0
- package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
- package/dist/cjs/{management-Dm5h0E6l.cjs → runner-CUJ8RHzY.cjs} +24 -30
- package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-Ds2m27Q4.d.cts} +49 -95
- package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
- package/dist/cjs/validate-BegMfe-i.cjs +235 -0
- package/dist/es/actions/app-config.d.mts +15 -0
- package/dist/es/actions/app-config.mjs +25 -0
- package/dist/es/actions/config.d.mts +15 -0
- package/dist/es/actions/config.mjs +77 -0
- package/dist/es/actions/{index.d.mts → installation.d.mts} +4 -3
- package/dist/es/actions/{index.mjs → installation.mjs} +27 -427
- package/dist/es/actions/scope-tree.d.mts +8 -0
- package/dist/es/actions/scope-tree.mjs +95 -0
- package/dist/es/{app-Cx1-6dn0.d.mts → app-vKXaAr6f.d.mts} +6 -6
- package/dist/es/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
- package/dist/es/commands/generate/actions/templates/app-management/installation.js.template +1 -1
- package/dist/es/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
- package/dist/es/commands/index.mjs +82 -91
- package/dist/es/config/index.d.mts +32 -332
- package/dist/es/config/index.mjs +3 -2
- package/dist/es/error-CMV3IjBz.mjs +18 -0
- package/dist/es/{error-P7JgUTds.mjs → installation-SWIwhpKT.mjs} +72 -124
- package/dist/es/management/index.d.mts +2 -3
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/parser-CKQyrTB7.mjs +201 -0
- package/dist/es/router-CJ4VWoCt.mjs +404 -0
- package/dist/es/{management-Y7pwEbNI.mjs → runner-DB2tDBQS.mjs} +17 -24
- package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-Uk7263hG.d.mts} +49 -95
- package/dist/es/schemas-B8yIv0_b.mjs +41 -0
- package/dist/es/validate-DXI6gwZ2.mjs +187 -0
- package/package.json +39 -25
- package/dist/cjs/actions/index.cjs +0 -824
- package/dist/cjs/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
- package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
- package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
- package/dist/cjs/config-JQ_n-5Nk.cjs +0 -565
- package/dist/cjs/error-Byj1DVHZ.cjs +0 -344
- package/dist/es/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
- package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
- package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
- package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
- package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
- package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
- package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
- package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
- package/dist/es/config-BSGerqCG.mjs +0 -457
- /package/dist/es/{logging-VgerMhp6.mjs → logging-CzmXDzxI.mjs} +0 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
const require_schemas = require('./schemas-CZ6c8Id9.cjs');
|
|
2
|
+
let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
|
|
3
|
+
let _adobe_aio_lib_core_logging = require("@adobe/aio-lib-core-logging");
|
|
4
|
+
_adobe_aio_lib_core_logging = require_schemas.__toESM(_adobe_aio_lib_core_logging);
|
|
5
|
+
let regexparam = require("regexparam");
|
|
6
|
+
|
|
7
|
+
//#region ../../packages-private/common-utils/source/actions/http/middleware/logger.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates a logger middleware that adds logging capabilities to the context.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* router.use(logger({ level: "debug", name: () => "my-logger-name" }));
|
|
14
|
+
*
|
|
15
|
+
* router.get("/test", {
|
|
16
|
+
* handler: (req, ctx) => {
|
|
17
|
+
* ctx.logger.info("Hello world");
|
|
18
|
+
* return ok({ body: {} });
|
|
19
|
+
* },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function logger({ name, ...restOptions } = {}) {
|
|
24
|
+
return (ctx) => {
|
|
25
|
+
const params = ctx.rawParams;
|
|
26
|
+
return { logger: (0, _adobe_aio_lib_core_logging.default)(`${params.__ow_method}-${name?.(ctx) ?? process.env.__OW_ACTION_NAME}`, {
|
|
27
|
+
level: `${params.LOG_LEVEL ?? "info"}`,
|
|
28
|
+
...restOptions
|
|
29
|
+
}) };
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../../packages-private/common-utils/source/actions/http/utils.ts
|
|
35
|
+
/**
|
|
36
|
+
* Validates input against a Standard Schema and returns a result.
|
|
37
|
+
*
|
|
38
|
+
* @template TInput - The input type expected by the schema
|
|
39
|
+
* @template TOutput - The output type produced by the schema
|
|
40
|
+
* @param schema - A Standard Schema v1 compliant schema
|
|
41
|
+
* @param input - The input data to validate
|
|
42
|
+
* @returns A promise resolving to either success with validated data or failure with issues
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const result = await validateSchema(mySchema, userInput);
|
|
47
|
+
* if (result.success) {
|
|
48
|
+
* console.log(result.data); // Typed as TOutput
|
|
49
|
+
* } else {
|
|
50
|
+
* console.error(result.issues); // Validation errors
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
async function validateSchema(schema, input) {
|
|
55
|
+
const result = await schema["~standard"].validate(input);
|
|
56
|
+
if (result.issues) return {
|
|
57
|
+
success: false,
|
|
58
|
+
issues: result.issues.map((issue) => ({
|
|
59
|
+
message: issue.message,
|
|
60
|
+
path: issue.path?.map((segment) => typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment)
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
data: result.value
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses a request body from OpenWhisk/Runtime.
|
|
70
|
+
* Handles multiple formats:
|
|
71
|
+
* - Base64-encoded strings (__ow_body)
|
|
72
|
+
* - Already-parsed objects
|
|
73
|
+
* - Body properties mixed into args (web actions with JSON content-type)
|
|
74
|
+
*
|
|
75
|
+
* @param owBody - Body from __ow_body (base64 string, JSON string, or object)
|
|
76
|
+
* @param args - Full args object to extract body from if __ow_body is not present
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const body = parseRequestBody(params.__ow_body, params);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function parseRequestBody(owBody, args) {
|
|
84
|
+
if (owBody) {
|
|
85
|
+
if (typeof owBody === "object") return owBody;
|
|
86
|
+
if (typeof owBody === "string") {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(owBody);
|
|
89
|
+
} catch {}
|
|
90
|
+
try {
|
|
91
|
+
const decoded = Buffer.from(owBody, "base64").toString();
|
|
92
|
+
return JSON.parse(decoded);
|
|
93
|
+
} catch {}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (args && typeof args === "object") {
|
|
97
|
+
const body = {};
|
|
98
|
+
for (const [key, value] of Object.entries(args)) if (!key.startsWith("__ow_")) body[key] = value;
|
|
99
|
+
return body;
|
|
100
|
+
}
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Parses query parameters from OpenWhisk/Runtime format.
|
|
105
|
+
*
|
|
106
|
+
* @param queryString - Query string from __ow_query
|
|
107
|
+
* @param fallbackParams - Fallback params object (used when __ow_query is not present)
|
|
108
|
+
* @returns Parsed query parameters as a record
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const query = parseQueryParams(params.__ow_query, params);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function parseQueryParams(queryString, fallbackParams) {
|
|
116
|
+
if (queryString) return Object.fromEntries(new URLSearchParams(queryString));
|
|
117
|
+
if (fallbackParams) {
|
|
118
|
+
const { __ow_method, __ow_path, __ow_headers, __ow_body, __ow_query, ...rest } = fallbackParams;
|
|
119
|
+
return rest;
|
|
120
|
+
}
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region ../../packages-private/common-utils/source/actions/http/router.ts
|
|
126
|
+
/**
|
|
127
|
+
* HTTP router for Adobe I/O Runtime actions.
|
|
128
|
+
* Provides type-safe routing with schema validation and OpenWhisk integration.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const router = new HttpActionRouter();
|
|
133
|
+
*
|
|
134
|
+
* router.get("/users/:id", {
|
|
135
|
+
* handler: (req) => ok({ id: req.params.id, context: req.context })
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* // Add context builders
|
|
139
|
+
* router.use(async (base) => ({
|
|
140
|
+
* user: await getUser(base.rawParams.__ow_headers?.authorization),
|
|
141
|
+
* }));
|
|
142
|
+
*
|
|
143
|
+
* export const main = router.handler();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
var HttpActionRouter = class {
|
|
147
|
+
constructor() {
|
|
148
|
+
this.routes = [];
|
|
149
|
+
this.contextBuilders = [];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Internal method to add a route to the router.
|
|
153
|
+
*/
|
|
154
|
+
addRoute(method, path, config) {
|
|
155
|
+
const { pattern, keys } = (0, regexparam.parse)(path);
|
|
156
|
+
this.routes.push({
|
|
157
|
+
method,
|
|
158
|
+
pattern,
|
|
159
|
+
keys,
|
|
160
|
+
params: config.params,
|
|
161
|
+
body: config.body,
|
|
162
|
+
query: config.query,
|
|
163
|
+
handler: config.handler
|
|
164
|
+
});
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Register a GET route.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* router.get("/users/:id", {
|
|
173
|
+
* handler: (req) => ok({ id: req.params.id })
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
get(path, config) {
|
|
178
|
+
return this.addRoute("GET", path, config);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Register a POST route.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* router.post("/users", {
|
|
186
|
+
* body: userSchema,
|
|
187
|
+
* handler: (req) => created(req.body)
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
post(path, config) {
|
|
192
|
+
return this.addRoute("POST", path, config);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Register a PUT route.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* router.put("/users/:id", {
|
|
200
|
+
* body: userSchema,
|
|
201
|
+
* handler: (req) => ok(req.body)
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
put(path, config) {
|
|
206
|
+
return this.addRoute("PUT", path, config);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Register a PATCH route.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* router.patch("/users/:id", {
|
|
214
|
+
* body: partialUserSchema,
|
|
215
|
+
* handler: (req) => ok(req.body)
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
patch(path, config) {
|
|
220
|
+
return this.addRoute("PATCH", path, config);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Register a DELETE route.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* router.delete("/users/:id", {
|
|
228
|
+
* handler: (req) => noContent()
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
delete(path, config) {
|
|
233
|
+
return this.addRoute("DELETE", path, config);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Register a context builder that runs before route handlers.
|
|
237
|
+
* Context builders can add properties to the request context.
|
|
238
|
+
* Multiple builders are executed in order and their results are merged.
|
|
239
|
+
*
|
|
240
|
+
* The returned router has an updated context type that includes the new properties,
|
|
241
|
+
* enabling type-safe access in route handlers.
|
|
242
|
+
*
|
|
243
|
+
* @param builder - Function that receives base context and returns additional context
|
|
244
|
+
* @returns The router instance with updated context type for chaining
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const router = new HttpActionRouter()
|
|
249
|
+
* .use(logger()) // HttpActionRouter<BaseContext & { logger: Logger }>
|
|
250
|
+
* .use(auth()); // HttpActionRouter<BaseContext & { logger: Logger } & { user: User }>
|
|
251
|
+
*
|
|
252
|
+
* router.get("/me", {
|
|
253
|
+
* handler: (req, ctx) => {
|
|
254
|
+
* ctx.logger.info("Hello"); // ✅ typed
|
|
255
|
+
* return ok({ body: ctx.user }); // ✅ typed
|
|
256
|
+
* },
|
|
257
|
+
* });
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
use(builder) {
|
|
261
|
+
this.contextBuilders.push(builder);
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Builds the full context by running all context builders.
|
|
266
|
+
*/
|
|
267
|
+
async buildContext(args) {
|
|
268
|
+
let context = { rawParams: args };
|
|
269
|
+
for (const builder of this.contextBuilders) {
|
|
270
|
+
const result = await builder(context);
|
|
271
|
+
if (result) context = {
|
|
272
|
+
...context,
|
|
273
|
+
...result
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return context;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Validates and extracts route parameters.
|
|
280
|
+
*/
|
|
281
|
+
async validateParams(route, params) {
|
|
282
|
+
if (!route.params) return {
|
|
283
|
+
success: true,
|
|
284
|
+
data: params
|
|
285
|
+
};
|
|
286
|
+
const result = await validateSchema(route.params, params);
|
|
287
|
+
if (!result.success) return {
|
|
288
|
+
success: false,
|
|
289
|
+
issues: result.issues
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
success: true,
|
|
293
|
+
data: result.data
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Validates request body.
|
|
298
|
+
*/
|
|
299
|
+
async validateBody(route, body) {
|
|
300
|
+
if (!route.body) return {
|
|
301
|
+
success: true,
|
|
302
|
+
data: body
|
|
303
|
+
};
|
|
304
|
+
const result = await validateSchema(route.body, body);
|
|
305
|
+
if (!result.success) return {
|
|
306
|
+
success: false,
|
|
307
|
+
issues: result.issues
|
|
308
|
+
};
|
|
309
|
+
return {
|
|
310
|
+
success: true,
|
|
311
|
+
data: result.data
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Validates query parameters.
|
|
316
|
+
*/
|
|
317
|
+
async validateQuery(route, query) {
|
|
318
|
+
if (!route.query) return {
|
|
319
|
+
success: true,
|
|
320
|
+
data: query
|
|
321
|
+
};
|
|
322
|
+
const result = await validateSchema(route.query, query);
|
|
323
|
+
if (!result.success) return {
|
|
324
|
+
success: false,
|
|
325
|
+
issues: result.issues
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
success: true,
|
|
329
|
+
data: result.data
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/** Handles a matched route by validating inputs and calling the handler. */
|
|
333
|
+
async handleRoute(route, match, body, query, headers, method, path, context) {
|
|
334
|
+
const params = {};
|
|
335
|
+
route.keys.forEach((key, i) => {
|
|
336
|
+
params[key] = decodeURIComponent(match[i + 1] || "");
|
|
337
|
+
});
|
|
338
|
+
const paramsResult = await this.validateParams(route, params);
|
|
339
|
+
if (!paramsResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
|
|
340
|
+
message: "Invalid route parameters",
|
|
341
|
+
issues: paramsResult.issues
|
|
342
|
+
} });
|
|
343
|
+
const bodyResult = await this.validateBody(route, body);
|
|
344
|
+
if (!bodyResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
|
|
345
|
+
message: "Invalid request body",
|
|
346
|
+
issues: bodyResult.issues
|
|
347
|
+
} });
|
|
348
|
+
const queryResult = await this.validateQuery(route, query);
|
|
349
|
+
if (!queryResult.success) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)({ body: {
|
|
350
|
+
message: "Invalid query parameters",
|
|
351
|
+
issues: queryResult.issues
|
|
352
|
+
} });
|
|
353
|
+
try {
|
|
354
|
+
return await route.handler({
|
|
355
|
+
params: paramsResult.data,
|
|
356
|
+
body: bodyResult.data,
|
|
357
|
+
query: queryResult.data,
|
|
358
|
+
headers,
|
|
359
|
+
method,
|
|
360
|
+
path
|
|
361
|
+
}, context);
|
|
362
|
+
} catch (err) {
|
|
363
|
+
console.error("Handler error:", err);
|
|
364
|
+
return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
|
|
365
|
+
message: "Internal server error",
|
|
366
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
367
|
+
} });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Creates an OpenWhisk/Runtime action handler from the registered routes.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* const router = new HttpActionRouter();
|
|
376
|
+
* router.get("/hello", { handler: () => ok({ message: "Hello!" }) });
|
|
377
|
+
*
|
|
378
|
+
* export const main = router.handler();
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
handler() {
|
|
382
|
+
return async (args) => {
|
|
383
|
+
const method = (args.__ow_method ?? "get").toUpperCase();
|
|
384
|
+
const rawPath = args.__ow_path ?? "/";
|
|
385
|
+
const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
|
|
386
|
+
const headers = args.__ow_headers ?? {};
|
|
387
|
+
const body = parseRequestBody(args.__ow_body, args);
|
|
388
|
+
const query = parseQueryParams(args.__ow_query, args);
|
|
389
|
+
const context = await this.buildContext(args);
|
|
390
|
+
const matchedMethods = [];
|
|
391
|
+
for (const route of this.routes) {
|
|
392
|
+
const match = route.pattern.exec(path);
|
|
393
|
+
if (!match) continue;
|
|
394
|
+
matchedMethods.push(route.method);
|
|
395
|
+
if (route.method !== method) continue;
|
|
396
|
+
const response = await this.handleRoute(route, match, body, query, headers, method, path, context);
|
|
397
|
+
if (response) return response;
|
|
398
|
+
}
|
|
399
|
+
if (matchedMethods.length > 0) return (0, _adobe_aio_commerce_lib_core_responses.methodNotAllowed)(`Method ${method} not allowed`);
|
|
400
|
+
return (0, _adobe_aio_commerce_lib_core_responses.notFound)(`No route matches ${path}`);
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
//#endregion
|
|
406
|
+
Object.defineProperty(exports, 'HttpActionRouter', {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
get: function () {
|
|
409
|
+
return HttpActionRouter;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
Object.defineProperty(exports, 'logger', {
|
|
413
|
+
enumerable: true,
|
|
414
|
+
get: function () {
|
|
415
|
+
return logger;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_schemas = require('./schemas-CZ6c8Id9.cjs');
|
|
2
|
+
const require_installation = require('./installation-nwF2RC7F.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 =
|
|
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 (!
|
|
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:
|
|
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
|
|
564
|
+
const actualMetadata = (_embedded?.eventmetadata ?? []).map(({ _embedded, _links, ...meta }) => ({
|
|
563
565
|
...meta,
|
|
564
|
-
sample: _embedded
|
|
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.
|
|
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 {
|
|
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
|
-
|
|
784
|
-
|
|
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
|
-
|
|
823
|
+
provider_id: provider.id,
|
|
825
824
|
destination: event.config.destination,
|
|
826
|
-
|
|
827
|
-
|
|
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:
|
|
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
|
|
982
|
+
events: eventsData.map(({ config, data }, index) => {
|
|
989
983
|
return {
|
|
990
|
-
config
|
|
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:
|
|
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:
|
|
1098
|
+
when: require_installation.hasEventing,
|
|
1105
1099
|
context: createEventsStepContext,
|
|
1106
1100
|
children: [commerceEventsStep, externalEventsStep]
|
|
1107
1101
|
});
|