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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +1 -4
  3. package/bin/cli.mjs +24 -0
  4. package/dist/cjs/actions/app-config.cjs +27 -0
  5. package/dist/cjs/actions/app-config.d.cts +15 -0
  6. package/dist/cjs/actions/config.cjs +79 -0
  7. package/dist/cjs/actions/config.d.cts +15 -0
  8. package/dist/cjs/actions/installation.cjs +424 -0
  9. package/dist/cjs/actions/{index.d.cts → installation.d.cts} +4 -3
  10. package/dist/cjs/actions/scope-tree.cjs +97 -0
  11. package/dist/cjs/actions/scope-tree.d.cts +8 -0
  12. package/dist/{es/app-Cx1-6dn0.d.mts → cjs/app-DWX5-Hsf.d.cts} +14 -14
  13. package/dist/cjs/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  14. package/dist/cjs/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  15. package/dist/cjs/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  16. package/dist/cjs/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  17. package/dist/cjs/commands/index.cjs +91 -106
  18. package/dist/cjs/config/index.cjs +21 -19
  19. package/dist/cjs/config/index.d.cts +52 -352
  20. package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
  21. package/dist/cjs/installation-CLbceU9F.cjs +243 -0
  22. package/dist/cjs/{logging-DYwr5WQk.cjs → logging-IDRQG0as.cjs} +2 -2
  23. package/dist/cjs/management/index.cjs +9 -8
  24. package/dist/cjs/management/index.d.cts +2 -2
  25. package/dist/cjs/parser-BPpg_9QB.cjs +267 -0
  26. package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
  27. package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-DemKouFJ.d.cts} +49 -95
  28. package/dist/cjs/{management-Dm5h0E6l.cjs → runner-NHMvoMO2.cjs} +24 -30
  29. package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
  30. package/dist/cjs/validate-Btzn9ilZ.cjs +235 -0
  31. package/dist/es/actions/app-config.d.mts +15 -0
  32. package/dist/es/actions/app-config.mjs +25 -0
  33. package/dist/es/actions/config.d.mts +15 -0
  34. package/dist/es/actions/config.mjs +77 -0
  35. package/dist/es/actions/{index.d.mts → installation.d.mts} +4 -3
  36. package/dist/es/actions/{index.mjs → installation.mjs} +27 -427
  37. package/dist/es/actions/scope-tree.d.mts +8 -0
  38. package/dist/es/actions/scope-tree.mjs +95 -0
  39. package/dist/{cjs/app-Dx0ca6oL.d.cts → es/app-BAiyvNo2.d.mts} +14 -14
  40. package/dist/es/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  41. package/dist/es/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  42. package/dist/es/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  43. package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  44. package/dist/es/commands/index.mjs +68 -84
  45. package/dist/es/config/index.d.mts +52 -352
  46. package/dist/es/config/index.mjs +3 -2
  47. package/dist/es/error-CMV3IjBz.mjs +18 -0
  48. package/dist/es/{error-P7JgUTds.mjs → installation-BTL9X7iv.mjs} +78 -128
  49. package/dist/es/management/index.d.mts +2 -3
  50. package/dist/es/management/index.mjs +1 -1
  51. package/dist/es/parser-CQZTVG6i.mjs +201 -0
  52. package/dist/es/router-CJ4VWoCt.mjs +404 -0
  53. package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-BD-lItnK.d.mts} +49 -95
  54. package/dist/es/{management-Y7pwEbNI.mjs → runner-vwAhjD5r.mjs} +17 -24
  55. package/dist/es/schemas-B8yIv0_b.mjs +41 -0
  56. package/dist/es/validate-DKnju9-R.mjs +187 -0
  57. package/package.json +38 -24
  58. package/dist/cjs/actions/index.cjs +0 -824
  59. package/dist/cjs/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  60. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  61. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  62. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  63. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  64. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  65. package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  66. package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  67. package/dist/cjs/config-JQ_n-5Nk.cjs +0 -565
  68. package/dist/cjs/error-Byj1DVHZ.cjs +0 -344
  69. package/dist/es/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  70. package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  71. package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  72. package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  73. package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  74. package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  75. package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  76. package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  77. package/dist/es/config-BSGerqCG.mjs +0 -457
  78. /package/dist/es/{logging-VgerMhp6.mjs → logging-CzmXDzxI.mjs} +0 -0
@@ -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,7 @@
1
- import { n as CommerceAppConfigOutputModel } from "./app-Cx1-6dn0.mjs";
2
- import AioLogger from "@adobe/aio-lib-core-logging";
3
- import * as v from "valibot";
1
+ import { n as CommerceAppConfigOutputModel } from "./app-DWX5-Hsf.cjs";
4
2
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
3
+ import * as v from "valibot";
4
+ import AioLogger from "@adobe/aio-lib-core-logging";
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
- /** Logger instance for installation logging. */
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
- name: TName;
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$1 = unknown> = StepBase<TName, TConfig> & {
60
- type: "leaf";
61
- /** The execution handler for the step. */
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
- /** An optional factory function to setup shared context for the children steps. */
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$1 = unknown> = LeafStep<TName, TConfig, TStepCtx, TOutput$1> | BranchStep<TName, TConfig, TStepCtx>;
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$1 = unknown> = Omit<LeafStep<TName, TConfig, TStepCtx, TOutput$1>, "type">;
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$1 = unknown>(options: LeafStepOptions<TName, TConfig, TStepCtx, TOutput$1>): LeafStep<TName, TConfig, TStepCtx, TOutput$1>;
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
- path: string[];
135
- /** Error key for easy identification. */
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
- name: string;
146
- /** Unique step identifier (e.g., UUID). */
147
- id: string;
148
- /** Full path from root to this step. */
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
- id: string;
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 started. */
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 started. */
188
- startedAt: string;
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
- path: string[];
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
- rootStep: BranchStep;
257
- /** Shared installation context (params, logger, etc.). */
258
- installationContext: InstallationContext;
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
- installationContext: InstallationContext;
327
- /** The app configuration. */
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
  /**