@adobe/aio-commerce-lib-app 0.3.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -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/{es/app-Cx1-6dn0.d.mts → cjs/app-DWX5-Hsf.d.cts} +14 -14
- 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 +91 -106
- package/dist/cjs/config/index.cjs +21 -19
- package/dist/cjs/config/index.d.cts +52 -352
- package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
- package/dist/cjs/installation-CLbceU9F.cjs +243 -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-BPpg_9QB.cjs +267 -0
- package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
- package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-DemKouFJ.d.cts} +49 -95
- package/dist/cjs/{management-Dm5h0E6l.cjs → runner-NHMvoMO2.cjs} +24 -30
- package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
- package/dist/cjs/validate-Btzn9ilZ.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/{cjs/app-Dx0ca6oL.d.cts → es/app-BAiyvNo2.d.mts} +14 -14
- 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 +68 -84
- package/dist/es/config/index.d.mts +52 -352
- package/dist/es/config/index.mjs +3 -2
- package/dist/es/error-CMV3IjBz.mjs +18 -0
- package/dist/es/{error-P7JgUTds.mjs → installation-BTL9X7iv.mjs} +78 -128
- package/dist/es/management/index.d.mts +2 -3
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/parser-CQZTVG6i.mjs +201 -0
- package/dist/es/router-CJ4VWoCt.mjs +404 -0
- package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-BD-lItnK.d.mts} +49 -95
- package/dist/es/{management-Y7pwEbNI.mjs → runner-vwAhjD5r.mjs} +17 -24
- package/dist/es/schemas-B8yIv0_b.mjs +41 -0
- package/dist/es/validate-DKnju9-R.mjs +187 -0
- package/package.json +38 -24
- 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,404 @@
|
|
|
1
|
+
import { badRequest, internalServerError, methodNotAllowed, notFound } from "@adobe/aio-commerce-lib-core/responses";
|
|
2
|
+
import AioLogger from "@adobe/aio-lib-core-logging";
|
|
3
|
+
import { parse } from "regexparam";
|
|
4
|
+
|
|
5
|
+
//#region ../../packages-private/common-utils/source/actions/http/middleware/logger.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a logger middleware that adds logging capabilities to the context.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* router.use(logger({ level: "debug", name: () => "my-logger-name" }));
|
|
12
|
+
*
|
|
13
|
+
* router.get("/test", {
|
|
14
|
+
* handler: (req, ctx) => {
|
|
15
|
+
* ctx.logger.info("Hello world");
|
|
16
|
+
* return ok({ body: {} });
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function logger({ name, ...restOptions } = {}) {
|
|
22
|
+
return (ctx) => {
|
|
23
|
+
const params = ctx.rawParams;
|
|
24
|
+
return { logger: AioLogger(`${params.__ow_method}-${name?.(ctx) ?? process.env.__OW_ACTION_NAME}`, {
|
|
25
|
+
level: `${params.LOG_LEVEL ?? "info"}`,
|
|
26
|
+
...restOptions
|
|
27
|
+
}) };
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../../packages-private/common-utils/source/actions/http/utils.ts
|
|
33
|
+
/**
|
|
34
|
+
* Validates input against a Standard Schema and returns a result.
|
|
35
|
+
*
|
|
36
|
+
* @template TInput - The input type expected by the schema
|
|
37
|
+
* @template TOutput - The output type produced by the schema
|
|
38
|
+
* @param schema - A Standard Schema v1 compliant schema
|
|
39
|
+
* @param input - The input data to validate
|
|
40
|
+
* @returns A promise resolving to either success with validated data or failure with issues
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const result = await validateSchema(mySchema, userInput);
|
|
45
|
+
* if (result.success) {
|
|
46
|
+
* console.log(result.data); // Typed as TOutput
|
|
47
|
+
* } else {
|
|
48
|
+
* console.error(result.issues); // Validation errors
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
async function validateSchema(schema, input) {
|
|
53
|
+
const result = await schema["~standard"].validate(input);
|
|
54
|
+
if (result.issues) return {
|
|
55
|
+
success: false,
|
|
56
|
+
issues: result.issues.map((issue) => ({
|
|
57
|
+
message: issue.message,
|
|
58
|
+
path: issue.path?.map((segment) => typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment)
|
|
59
|
+
}))
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
data: result.value
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parses a request body from OpenWhisk/Runtime.
|
|
68
|
+
* Handles multiple formats:
|
|
69
|
+
* - Base64-encoded strings (__ow_body)
|
|
70
|
+
* - Already-parsed objects
|
|
71
|
+
* - Body properties mixed into args (web actions with JSON content-type)
|
|
72
|
+
*
|
|
73
|
+
* @param owBody - Body from __ow_body (base64 string, JSON string, or object)
|
|
74
|
+
* @param args - Full args object to extract body from if __ow_body is not present
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const body = parseRequestBody(params.__ow_body, params);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function parseRequestBody(owBody, args) {
|
|
82
|
+
if (owBody) {
|
|
83
|
+
if (typeof owBody === "object") return owBody;
|
|
84
|
+
if (typeof owBody === "string") {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(owBody);
|
|
87
|
+
} catch {}
|
|
88
|
+
try {
|
|
89
|
+
const decoded = Buffer.from(owBody, "base64").toString();
|
|
90
|
+
return JSON.parse(decoded);
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (args && typeof args === "object") {
|
|
95
|
+
const body = {};
|
|
96
|
+
for (const [key, value] of Object.entries(args)) if (!key.startsWith("__ow_")) body[key] = value;
|
|
97
|
+
return body;
|
|
98
|
+
}
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Parses query parameters from OpenWhisk/Runtime format.
|
|
103
|
+
*
|
|
104
|
+
* @param queryString - Query string from __ow_query
|
|
105
|
+
* @param fallbackParams - Fallback params object (used when __ow_query is not present)
|
|
106
|
+
* @returns Parsed query parameters as a record
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const query = parseQueryParams(params.__ow_query, params);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function parseQueryParams(queryString, fallbackParams) {
|
|
114
|
+
if (queryString) return Object.fromEntries(new URLSearchParams(queryString));
|
|
115
|
+
if (fallbackParams) {
|
|
116
|
+
const { __ow_method, __ow_path, __ow_headers, __ow_body, __ow_query, ...rest } = fallbackParams;
|
|
117
|
+
return rest;
|
|
118
|
+
}
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region ../../packages-private/common-utils/source/actions/http/router.ts
|
|
124
|
+
/**
|
|
125
|
+
* HTTP router for Adobe I/O Runtime actions.
|
|
126
|
+
* Provides type-safe routing with schema validation and OpenWhisk integration.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const router = new HttpActionRouter();
|
|
131
|
+
*
|
|
132
|
+
* router.get("/users/:id", {
|
|
133
|
+
* handler: (req) => ok({ id: req.params.id, context: req.context })
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Add context builders
|
|
137
|
+
* router.use(async (base) => ({
|
|
138
|
+
* user: await getUser(base.rawParams.__ow_headers?.authorization),
|
|
139
|
+
* }));
|
|
140
|
+
*
|
|
141
|
+
* export const main = router.handler();
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
var HttpActionRouter = class {
|
|
145
|
+
constructor() {
|
|
146
|
+
this.routes = [];
|
|
147
|
+
this.contextBuilders = [];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Internal method to add a route to the router.
|
|
151
|
+
*/
|
|
152
|
+
addRoute(method, path, config) {
|
|
153
|
+
const { pattern, keys } = parse(path);
|
|
154
|
+
this.routes.push({
|
|
155
|
+
method,
|
|
156
|
+
pattern,
|
|
157
|
+
keys,
|
|
158
|
+
params: config.params,
|
|
159
|
+
body: config.body,
|
|
160
|
+
query: config.query,
|
|
161
|
+
handler: config.handler
|
|
162
|
+
});
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Register a GET route.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* router.get("/users/:id", {
|
|
171
|
+
* handler: (req) => ok({ id: req.params.id })
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
get(path, config) {
|
|
176
|
+
return this.addRoute("GET", path, config);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Register a POST route.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* router.post("/users", {
|
|
184
|
+
* body: userSchema,
|
|
185
|
+
* handler: (req) => created(req.body)
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
post(path, config) {
|
|
190
|
+
return this.addRoute("POST", path, config);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Register a PUT route.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* router.put("/users/:id", {
|
|
198
|
+
* body: userSchema,
|
|
199
|
+
* handler: (req) => ok(req.body)
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
put(path, config) {
|
|
204
|
+
return this.addRoute("PUT", path, config);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Register a PATCH route.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* router.patch("/users/:id", {
|
|
212
|
+
* body: partialUserSchema,
|
|
213
|
+
* handler: (req) => ok(req.body)
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
patch(path, config) {
|
|
218
|
+
return this.addRoute("PATCH", path, config);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Register a DELETE route.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* router.delete("/users/:id", {
|
|
226
|
+
* handler: (req) => noContent()
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
delete(path, config) {
|
|
231
|
+
return this.addRoute("DELETE", path, config);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Register a context builder that runs before route handlers.
|
|
235
|
+
* Context builders can add properties to the request context.
|
|
236
|
+
* Multiple builders are executed in order and their results are merged.
|
|
237
|
+
*
|
|
238
|
+
* The returned router has an updated context type that includes the new properties,
|
|
239
|
+
* enabling type-safe access in route handlers.
|
|
240
|
+
*
|
|
241
|
+
* @param builder - Function that receives base context and returns additional context
|
|
242
|
+
* @returns The router instance with updated context type for chaining
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const router = new HttpActionRouter()
|
|
247
|
+
* .use(logger()) // HttpActionRouter<BaseContext & { logger: Logger }>
|
|
248
|
+
* .use(auth()); // HttpActionRouter<BaseContext & { logger: Logger } & { user: User }>
|
|
249
|
+
*
|
|
250
|
+
* router.get("/me", {
|
|
251
|
+
* handler: (req, ctx) => {
|
|
252
|
+
* ctx.logger.info("Hello"); // ✅ typed
|
|
253
|
+
* return ok({ body: ctx.user }); // ✅ typed
|
|
254
|
+
* },
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
use(builder) {
|
|
259
|
+
this.contextBuilders.push(builder);
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Builds the full context by running all context builders.
|
|
264
|
+
*/
|
|
265
|
+
async buildContext(args) {
|
|
266
|
+
let context = { rawParams: args };
|
|
267
|
+
for (const builder of this.contextBuilders) {
|
|
268
|
+
const result = await builder(context);
|
|
269
|
+
if (result) context = {
|
|
270
|
+
...context,
|
|
271
|
+
...result
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return context;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Validates and extracts route parameters.
|
|
278
|
+
*/
|
|
279
|
+
async validateParams(route, params) {
|
|
280
|
+
if (!route.params) return {
|
|
281
|
+
success: true,
|
|
282
|
+
data: params
|
|
283
|
+
};
|
|
284
|
+
const result = await validateSchema(route.params, params);
|
|
285
|
+
if (!result.success) return {
|
|
286
|
+
success: false,
|
|
287
|
+
issues: result.issues
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
success: true,
|
|
291
|
+
data: result.data
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Validates request body.
|
|
296
|
+
*/
|
|
297
|
+
async validateBody(route, body) {
|
|
298
|
+
if (!route.body) return {
|
|
299
|
+
success: true,
|
|
300
|
+
data: body
|
|
301
|
+
};
|
|
302
|
+
const result = await validateSchema(route.body, body);
|
|
303
|
+
if (!result.success) return {
|
|
304
|
+
success: false,
|
|
305
|
+
issues: result.issues
|
|
306
|
+
};
|
|
307
|
+
return {
|
|
308
|
+
success: true,
|
|
309
|
+
data: result.data
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Validates query parameters.
|
|
314
|
+
*/
|
|
315
|
+
async validateQuery(route, query) {
|
|
316
|
+
if (!route.query) return {
|
|
317
|
+
success: true,
|
|
318
|
+
data: query
|
|
319
|
+
};
|
|
320
|
+
const result = await validateSchema(route.query, query);
|
|
321
|
+
if (!result.success) return {
|
|
322
|
+
success: false,
|
|
323
|
+
issues: result.issues
|
|
324
|
+
};
|
|
325
|
+
return {
|
|
326
|
+
success: true,
|
|
327
|
+
data: result.data
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** Handles a matched route by validating inputs and calling the handler. */
|
|
331
|
+
async handleRoute(route, match, body, query, headers, method, path, context) {
|
|
332
|
+
const params = {};
|
|
333
|
+
route.keys.forEach((key, i) => {
|
|
334
|
+
params[key] = decodeURIComponent(match[i + 1] || "");
|
|
335
|
+
});
|
|
336
|
+
const paramsResult = await this.validateParams(route, params);
|
|
337
|
+
if (!paramsResult.success) return badRequest({ body: {
|
|
338
|
+
message: "Invalid route parameters",
|
|
339
|
+
issues: paramsResult.issues
|
|
340
|
+
} });
|
|
341
|
+
const bodyResult = await this.validateBody(route, body);
|
|
342
|
+
if (!bodyResult.success) return badRequest({ body: {
|
|
343
|
+
message: "Invalid request body",
|
|
344
|
+
issues: bodyResult.issues
|
|
345
|
+
} });
|
|
346
|
+
const queryResult = await this.validateQuery(route, query);
|
|
347
|
+
if (!queryResult.success) return badRequest({ body: {
|
|
348
|
+
message: "Invalid query parameters",
|
|
349
|
+
issues: queryResult.issues
|
|
350
|
+
} });
|
|
351
|
+
try {
|
|
352
|
+
return await route.handler({
|
|
353
|
+
params: paramsResult.data,
|
|
354
|
+
body: bodyResult.data,
|
|
355
|
+
query: queryResult.data,
|
|
356
|
+
headers,
|
|
357
|
+
method,
|
|
358
|
+
path
|
|
359
|
+
}, context);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.error("Handler error:", err);
|
|
362
|
+
return internalServerError({ body: {
|
|
363
|
+
message: "Internal server error",
|
|
364
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
365
|
+
} });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Creates an OpenWhisk/Runtime action handler from the registered routes.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* const router = new HttpActionRouter();
|
|
374
|
+
* router.get("/hello", { handler: () => ok({ message: "Hello!" }) });
|
|
375
|
+
*
|
|
376
|
+
* export const main = router.handler();
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
handler() {
|
|
380
|
+
return async (args) => {
|
|
381
|
+
const method = (args.__ow_method ?? "get").toUpperCase();
|
|
382
|
+
const rawPath = args.__ow_path ?? "/";
|
|
383
|
+
const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
|
|
384
|
+
const headers = args.__ow_headers ?? {};
|
|
385
|
+
const body = parseRequestBody(args.__ow_body, args);
|
|
386
|
+
const query = parseQueryParams(args.__ow_query, args);
|
|
387
|
+
const context = await this.buildContext(args);
|
|
388
|
+
const matchedMethods = [];
|
|
389
|
+
for (const route of this.routes) {
|
|
390
|
+
const match = route.pattern.exec(path);
|
|
391
|
+
if (!match) continue;
|
|
392
|
+
matchedMethods.push(route.method);
|
|
393
|
+
if (route.method !== method) continue;
|
|
394
|
+
const response = await this.handleRoute(route, match, body, query, headers, method, path, context);
|
|
395
|
+
if (response) return response;
|
|
396
|
+
}
|
|
397
|
+
if (matchedMethods.length > 0) return methodNotAllowed(`Method ${method} not allowed`);
|
|
398
|
+
return notFound(`No route matches ${path}`);
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
export { logger as n, HttpActionRouter as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as CommerceAppConfigOutputModel } from "./app-
|
|
2
|
-
import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
|
|
3
|
-
import * as v from "valibot";
|
|
1
|
+
import { n as CommerceAppConfigOutputModel } from "./app-BAiyvNo2.mjs";
|
|
4
2
|
import AioLogger from "@adobe/aio-lib-core-logging";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
|
|
5
5
|
|
|
6
6
|
//#region source/management/installation/schema.d.ts
|
|
7
7
|
/** Schema for validating Adobe I/O app credentials required for installation. */
|
|
@@ -21,9 +21,7 @@ type AppData = v.InferOutput<typeof AppDataSchema>;
|
|
|
21
21
|
//#region source/management/installation/workflow/step.d.ts
|
|
22
22
|
/** Shared context available to all steps during installation. */
|
|
23
23
|
type InstallationContext = {
|
|
24
|
-
/** The credentials of the app being installed */
|
|
25
|
-
appData: AppData;
|
|
26
|
-
/** The raw action parameters from the App Builder runtime action. */
|
|
24
|
+
/** The credentials of the app being installed */appData: AppData; /** The raw action parameters from the App Builder runtime action. */
|
|
27
25
|
params: RuntimeActionParams & {
|
|
28
26
|
AIO_COMMERCE_AUTH_IMS_CLIENT_ID: string;
|
|
29
27
|
AIO_COMMERCE_AUTH_IMS_CLIENT_SECRETS: string | string[];
|
|
@@ -31,10 +29,8 @@ type InstallationContext = {
|
|
|
31
29
|
AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_EMAIL: string;
|
|
32
30
|
AIO_COMMERCE_AUTH_IMS_ORG_ID: string;
|
|
33
31
|
AIO_COMMERCE_AUTH_IMS_SCOPES: string | string[];
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
logger: ReturnType<typeof AioLogger>;
|
|
37
|
-
/** Custom scripts defined in the configuration (if any). */
|
|
32
|
+
}; /** Logger instance for installation logging. */
|
|
33
|
+
logger: ReturnType<typeof AioLogger>; /** Custom scripts defined in the configuration (if any). */
|
|
38
34
|
customScripts?: Record<string, unknown>;
|
|
39
35
|
};
|
|
40
36
|
/** Factory function type for creating step-specific context. */
|
|
@@ -48,45 +44,39 @@ type StepMeta = {
|
|
|
48
44
|
};
|
|
49
45
|
/** Defines the base properties of a step. */
|
|
50
46
|
type StepBase<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel> = {
|
|
51
|
-
/** The name of this step. */
|
|
52
|
-
|
|
53
|
-
/** Metadata associated with the step. */
|
|
54
|
-
meta: StepMeta;
|
|
55
|
-
/** Whether the step should be taken into consideration. */
|
|
47
|
+
/** The name of this step. */name: TName; /** Metadata associated with the step. */
|
|
48
|
+
meta: StepMeta; /** Whether the step should be taken into consideration. */
|
|
56
49
|
when?: (config: CommerceAppConfigOutputModel) => config is TConfig;
|
|
57
50
|
};
|
|
58
51
|
/** A leaf step that executes work (no children). */
|
|
59
|
-
type LeafStep<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput
|
|
60
|
-
type: "leaf";
|
|
61
|
-
|
|
62
|
-
run: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput$1 | Promise<TOutput$1>;
|
|
52
|
+
type LeafStep<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> = StepBase<TName, TConfig> & {
|
|
53
|
+
type: "leaf"; /** The execution handler for the step. */
|
|
54
|
+
run: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
|
|
63
55
|
};
|
|
64
56
|
/** A branch step that contains children (no execution). */
|
|
65
57
|
type BranchStep<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>> = StepBase<TName, TConfig> & {
|
|
66
|
-
type: "branch";
|
|
67
|
-
|
|
68
|
-
context?: StepContextFactory<TStepCtx>;
|
|
69
|
-
/** The children steps of this branch. */
|
|
58
|
+
type: "branch"; /** An optional factory function to setup shared context for the children steps. */
|
|
59
|
+
context?: StepContextFactory<TStepCtx>; /** The children steps of this branch. */
|
|
70
60
|
children: AnyStep[];
|
|
71
61
|
};
|
|
72
62
|
/** A step in the installation tree (discriminated union by `type`). */
|
|
73
|
-
type Step<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput
|
|
63
|
+
type Step<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> = LeafStep<TName, TConfig, TStepCtx, TOutput> | BranchStep<TName, TConfig, TStepCtx>;
|
|
74
64
|
/** Loosely-typed step for use in non type-safe contexts. */
|
|
75
65
|
interface AnyStep {
|
|
76
|
-
type: "leaf" | "branch";
|
|
77
|
-
name: string;
|
|
78
|
-
meta: StepMeta;
|
|
79
|
-
when?: (config: CommerceAppConfigOutputModel) => boolean;
|
|
80
66
|
children?: AnyStep[];
|
|
81
67
|
context?: (context: InstallationContext) => any;
|
|
68
|
+
meta: StepMeta;
|
|
69
|
+
name: string;
|
|
82
70
|
run?: (config: any, context: any) => unknown | Promise<unknown>;
|
|
71
|
+
type: "leaf" | "branch";
|
|
72
|
+
when?: (config: CommerceAppConfigOutputModel) => boolean;
|
|
83
73
|
}
|
|
84
74
|
/** Check if a step is a leaf step. */
|
|
85
75
|
declare function isLeafStep(step: AnyStep): step is LeafStep;
|
|
86
76
|
/** Check if a step is a branch step. */
|
|
87
77
|
declare function isBranchStep(step: AnyStep): step is BranchStep;
|
|
88
78
|
/** Options for defining a leaf step. */
|
|
89
|
-
type LeafStepOptions<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput
|
|
79
|
+
type LeafStepOptions<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> = Omit<LeafStep<TName, TConfig, TStepCtx, TOutput>, "type">;
|
|
90
80
|
/** Options for defining a branch step. */
|
|
91
81
|
type BranchStepOptions<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>> = Omit<BranchStep<TName, TConfig, TStepCtx>, "type">;
|
|
92
82
|
/**
|
|
@@ -104,7 +94,7 @@ type BranchStepOptions<TName extends string, TConfig extends CommerceAppConfigOu
|
|
|
104
94
|
* });
|
|
105
95
|
* ```
|
|
106
96
|
*/
|
|
107
|
-
declare function defineLeafStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput
|
|
97
|
+
declare function defineLeafStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown>(options: LeafStepOptions<TName, TConfig, TStepCtx, TOutput>): LeafStep<TName, TConfig, TStepCtx, TOutput>;
|
|
108
98
|
/**
|
|
109
99
|
* Define a branch step (container with children, no runner).
|
|
110
100
|
*
|
|
@@ -130,28 +120,18 @@ type ExecutionStatus = "pending" | "in-progress" | "succeeded" | "failed";
|
|
|
130
120
|
type InstallationStatus = "pending" | "in-progress" | "succeeded" | "failed";
|
|
131
121
|
/** A structured error with path to the failing step. */
|
|
132
122
|
type InstallationError<TPayload = unknown> = {
|
|
133
|
-
/** Path to the step that failed (e.g., ["eventing", "commerce", "providers"]). */
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
key: string;
|
|
137
|
-
/** Human-readable error message. */
|
|
138
|
-
message?: string;
|
|
139
|
-
/** Additional error payload. */
|
|
123
|
+
/** Path to the step that failed (e.g., ["eventing", "commerce", "providers"]). */path: string[]; /** Error key for easy identification. */
|
|
124
|
+
key: string; /** Human-readable error message. */
|
|
125
|
+
message?: string; /** Additional error payload. */
|
|
140
126
|
payload?: TPayload;
|
|
141
127
|
};
|
|
142
128
|
/** Status of a step in the installation tree. */
|
|
143
129
|
type StepStatus = {
|
|
144
|
-
/** Step name (unique among siblings). */
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
path: string[];
|
|
150
|
-
/** Step metadata (for display purposes). */
|
|
151
|
-
meta: StepMeta;
|
|
152
|
-
/** Current execution status. */
|
|
153
|
-
status: ExecutionStatus;
|
|
154
|
-
/** Child step statuses (empty for leaf steps). */
|
|
130
|
+
/** Step name (unique among siblings). */name: string; /** Unique step identifier (e.g., UUID). */
|
|
131
|
+
id: string; /** Full path from root to this step. */
|
|
132
|
+
path: string[]; /** Step metadata (for display purposes). */
|
|
133
|
+
meta: StepMeta; /** Current execution status. */
|
|
134
|
+
status: ExecutionStatus; /** Child step statuses (empty for leaf steps). */
|
|
155
135
|
children: StepStatus[];
|
|
156
136
|
};
|
|
157
137
|
/** Data collected during installation as a nested structure following step paths. */
|
|
@@ -160,35 +140,26 @@ type InstallationData = {
|
|
|
160
140
|
};
|
|
161
141
|
/** Base properties shared by all installation states. */
|
|
162
142
|
type InstallationStateBase = {
|
|
163
|
-
/** Unique installation identifier. */
|
|
164
|
-
|
|
165
|
-
/** Root step status. */
|
|
166
|
-
step: StepStatus;
|
|
167
|
-
/** Results from executed leaf steps, keyed by path. */
|
|
143
|
+
/** Unique installation identifier. */id: string; /** Root step status. */
|
|
144
|
+
step: StepStatus; /** Results from executed leaf steps, keyed by path. */
|
|
168
145
|
data: InstallationData | null;
|
|
169
146
|
};
|
|
170
147
|
/** Installation state when in progress. */
|
|
171
148
|
type InProgressInstallationState = InstallationStateBase & {
|
|
172
|
-
status: "in-progress";
|
|
173
|
-
/** ISO timestamp when installation started. */
|
|
149
|
+
status: "in-progress"; /** ISO timestamp when installation started. */
|
|
174
150
|
startedAt: string;
|
|
175
151
|
};
|
|
176
152
|
/** Installation state when completed successfully. */
|
|
177
153
|
type SucceededInstallationState = InstallationStateBase & {
|
|
178
|
-
status: "succeeded";
|
|
179
|
-
/** ISO timestamp when installation
|
|
180
|
-
startedAt: string;
|
|
181
|
-
/** ISO timestamp when installation completed. */
|
|
154
|
+
status: "succeeded"; /** ISO timestamp when installation started. */
|
|
155
|
+
startedAt: string; /** ISO timestamp when installation completed. */
|
|
182
156
|
completedAt: string;
|
|
183
157
|
};
|
|
184
158
|
/** Installation state when failed. */
|
|
185
159
|
type FailedInstallationState = InstallationStateBase & {
|
|
186
|
-
status: "failed";
|
|
187
|
-
/** ISO timestamp when installation
|
|
188
|
-
|
|
189
|
-
/** ISO timestamp when installation failed. */
|
|
190
|
-
completedAt: string;
|
|
191
|
-
/** Error information about the failure. */
|
|
160
|
+
status: "failed"; /** ISO timestamp when installation started. */
|
|
161
|
+
startedAt: string; /** ISO timestamp when installation failed. */
|
|
162
|
+
completedAt: string; /** Error information about the failure. */
|
|
192
163
|
error: InstallationError;
|
|
193
164
|
};
|
|
194
165
|
/**
|
|
@@ -213,24 +184,19 @@ type HookFunction<TEvent> = (event: TEvent, state: InstallationState) => void |
|
|
|
213
184
|
type InstallationHook = (state: InstallationState) => void | Promise<void>;
|
|
214
185
|
/** Base event payload for step events. */
|
|
215
186
|
type StepEvent = {
|
|
216
|
-
/** Full path to the step (e.g., ["eventing", "commerce", "providers"]). */
|
|
217
|
-
|
|
218
|
-
/** Step name (last element of path, for convenience). */
|
|
219
|
-
stepName: string;
|
|
220
|
-
/** Whether this is a leaf step (executable) or branch step (container). */
|
|
187
|
+
/** Full path to the step (e.g., ["eventing", "commerce", "providers"]). */path: string[]; /** Step name (last element of path, for convenience). */
|
|
188
|
+
stepName: string; /** Whether this is a leaf step (executable) or branch step (container). */
|
|
221
189
|
isLeaf: boolean;
|
|
222
190
|
};
|
|
223
191
|
/** Event payload when a step starts execution. */
|
|
224
192
|
type StepStartedEvent = StepEvent;
|
|
225
193
|
/** Event payload when a step succeeds. */
|
|
226
194
|
type StepSucceededEvent = StepEvent & {
|
|
227
|
-
/** Result returned by the step (only for leaf steps). */
|
|
228
|
-
result: unknown;
|
|
195
|
+
/** Result returned by the step (only for leaf steps). */result: unknown;
|
|
229
196
|
};
|
|
230
197
|
/** Event payload when a step fails. */
|
|
231
198
|
type StepFailedEvent = StepEvent & {
|
|
232
|
-
/** Error information. */
|
|
233
|
-
error: InstallationError;
|
|
199
|
+
/** Error information. */error: InstallationError;
|
|
234
200
|
};
|
|
235
201
|
/** Lifecycle hooks for installation execution. */
|
|
236
202
|
type InstallationHooks = {
|
|
@@ -245,22 +211,15 @@ type InstallationHooks = {
|
|
|
245
211
|
//#region source/management/installation/workflow/runner.d.ts
|
|
246
212
|
/** Options for creating an initial installation state. */
|
|
247
213
|
type CreateInitialStateOptions = {
|
|
248
|
-
/** The root branch step to build the state from. */
|
|
249
|
-
rootStep: BranchStep;
|
|
250
|
-
/** The app configuration used to determine applicable steps. */
|
|
214
|
+
/** The root branch step to build the state from. */rootStep: BranchStep; /** The app configuration used to determine applicable steps. */
|
|
251
215
|
config: CommerceAppConfigOutputModel;
|
|
252
216
|
};
|
|
253
217
|
/** Options for executing a workflow. */
|
|
254
218
|
type ExecuteWorkflowOptions = {
|
|
255
|
-
/** The root branch step to execute. */
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
|
|
259
|
-
/** The app configuration. */
|
|
260
|
-
config: CommerceAppConfigOutputModel;
|
|
261
|
-
/** The initial installation state (with all steps pending). */
|
|
262
|
-
initialState: InProgressInstallationState;
|
|
263
|
-
/** Lifecycle hooks for status change notifications. */
|
|
219
|
+
/** The root branch step to execute. */rootStep: BranchStep; /** Shared installation context (params, logger, etc.). */
|
|
220
|
+
installationContext: InstallationContext; /** The app configuration. */
|
|
221
|
+
config: CommerceAppConfigOutputModel; /** The initial installation state (with all steps pending). */
|
|
222
|
+
initialState: InProgressInstallationState; /** Lifecycle hooks for status change notifications. */
|
|
264
223
|
hooks?: InstallationHooks;
|
|
265
224
|
};
|
|
266
225
|
/**
|
|
@@ -317,18 +276,13 @@ declare function defineCustomInstallationStep<TResult = unknown>(handler: Custom
|
|
|
317
276
|
//#region source/management/installation/runner.d.ts
|
|
318
277
|
/** Options for creating an initial installation state. */
|
|
319
278
|
type CreateInitialInstallationStateOptions = {
|
|
320
|
-
/** The app configuration used to determine applicable steps. */
|
|
321
|
-
config: CommerceAppConfigOutputModel;
|
|
279
|
+
/** The app configuration used to determine applicable steps. */config: CommerceAppConfigOutputModel;
|
|
322
280
|
};
|
|
323
281
|
/** Options for running an installation. */
|
|
324
282
|
type RunInstallationOptions = {
|
|
325
|
-
/** Shared installation context (params, logger, etc.). */
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
config: CommerceAppConfigOutputModel;
|
|
329
|
-
/** The initial installation state (with all steps pending). */
|
|
330
|
-
initialState: InProgressInstallationState;
|
|
331
|
-
/** Lifecycle hooks for status change notifications. */
|
|
283
|
+
/** Shared installation context (params, logger, etc.). */installationContext: InstallationContext; /** The app configuration. */
|
|
284
|
+
config: CommerceAppConfigOutputModel; /** The initial installation state (with all steps pending). */
|
|
285
|
+
initialState: InProgressInstallationState; /** Lifecycle hooks for status change notifications. */
|
|
332
286
|
hooks?: InstallationHooks;
|
|
333
287
|
};
|
|
334
288
|
/**
|