@adobe/aio-commerce-lib-app 1.2.0 → 1.3.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @adobe/aio-commerce-lib-app
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#369](https://github.com/adobe/aio-commerce-sdk/pull/369) [`d8b0fa9`](https://github.com/adobe/aio-commerce-sdk/commit/d8b0fa9e3370b7abd0fb71b42d0078c375f63fb3) Thanks [@oshmyheliuk](https://github.com/oshmyheliuk)! - Add uninstallation flow for both native steps and custom steps. `defineCustomInstallationStep` now accepts an object with `install` and an optional `uninstall` handler in addition to a plain function, enabling per-step cleanup logic.
8
+
9
+ - [#387](https://github.com/adobe/aio-commerce-sdk/pull/387) [`0803ecb`](https://github.com/adobe/aio-commerce-sdk/commit/0803ecb143ee6a0e6d4113cb380d625e20ee4e2f) Thanks [@obarcelonap](https://github.com/obarcelonap)! - Adding new PATCH endpoint for configuration which allows to partially set configuration values. Deprecating PUT endpoint in favor of PATCH.
10
+
11
+ ### Patch Changes
12
+
13
+ - [#375](https://github.com/adobe/aio-commerce-sdk/pull/375) [`f5ac1a1`](https://github.com/adobe/aio-commerce-sdk/commit/f5ac1a1a400a6e609f296ef8de21ef6b20602120) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Fix an issue where the Commerce Eventing module was constantly being updated for each provider of an app.
14
+
15
+ - Updated dependencies [[`d8b0fa9`](https://github.com/adobe/aio-commerce-sdk/commit/d8b0fa9e3370b7abd0fb71b42d0078c375f63fb3), [`0803ecb`](https://github.com/adobe/aio-commerce-sdk/commit/0803ecb143ee6a0e6d4113cb380d625e20ee4e2f)]:
16
+ - @adobe/aio-commerce-lib-events@1.1.0
17
+ - @adobe/aio-commerce-lib-config@1.2.0
18
+
3
19
  ## 1.2.0
4
20
 
5
21
  ### Minor Changes
@@ -59,7 +59,11 @@ router.get("/", {
59
59
  } });
60
60
  }
61
61
  });
62
- /** POST / - Set configuration */
62
+ /**
63
+ * PUT / - Set configuration (deprecated)
64
+ * @deprecated Use PATCH instead. This endpoint overwrites all values for the scope
65
+ * and does not support partial updates or unset semantics.
66
+ */
63
67
  router.put("/", {
64
68
  body: valibot.object({
65
69
  scopeId: require_schemas.nonEmptyStringValueSchema("scopeId"),
@@ -73,8 +77,35 @@ router.put("/", {
73
77
  const { configSchema } = rawParams;
74
78
  logger.debug(`Setting configuration with scope id: ${req.body.scopeId}`);
75
79
  const { scopeId, config } = req.body;
80
+ (0, _adobe_aio_commerce_lib_config.initialize)({ schema: require_validate.validateCommerceAppConfigDomain(configSchema, "businessConfig.schema") });
76
81
  const result = await (0, _adobe_aio_commerce_lib_config.setConfiguration)({ config: config.filter((item) => item.value !== MASKED_PASSWORD_VALUE) }, (0, _adobe_aio_commerce_lib_config.byScopeId)(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
77
82
  result.config = filterPasswordFields(configSchema, result.config);
83
+ return (0, _adobe_aio_commerce_lib_core_responses.ok)({
84
+ body: result,
85
+ headers: {
86
+ "Cache-Control": "no-store",
87
+ Deprecation: "Wed, 15 Apr 2026 00:00:00 GMT"
88
+ }
89
+ });
90
+ }
91
+ });
92
+ /** PATCH / - Partially update configuration */
93
+ router.patch("/", {
94
+ body: valibot.object({
95
+ scopeId: require_schemas.nonEmptyStringValueSchema("scopeId"),
96
+ config: valibot.array(valibot.object({
97
+ name: require_schemas.nonEmptyStringValueSchema("config.name"),
98
+ value: valibot.nullable(valibot.union([valibot.string(), valibot.array(valibot.string())]))
99
+ }))
100
+ }),
101
+ handler: async (req, ctx) => {
102
+ const { logger, rawParams } = ctx;
103
+ const { configSchema } = rawParams;
104
+ logger.debug(`Patching configuration with scope id: ${req.body.scopeId}`);
105
+ const { scopeId, config } = req.body;
106
+ (0, _adobe_aio_commerce_lib_config.initialize)({ schema: require_validate.validateCommerceAppConfigDomain(configSchema, "businessConfig.schema") });
107
+ const result = await (0, _adobe_aio_commerce_lib_config.setConfiguration)({ config }, (0, _adobe_aio_commerce_lib_config.byScopeId)(scopeId), { encryptionKey: rawParams.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY });
108
+ result.config = filterPasswordFields(configSchema, result.config);
78
109
  return (0, _adobe_aio_commerce_lib_core_responses.ok)({
79
110
  body: result,
80
111
  headers: { "Cache-Control": "no-store" }
@@ -15,7 +15,7 @@
15
15
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
16
  const require_schemas = require('../schemas-nkIxa8sL.cjs');
17
17
  const require_router = require('../router-KeQRduO3.cjs');
18
- const require_management = require('../management-iLQubQ7K.cjs');
18
+ const require_management = require('../management-C6xG5bfl.cjs');
19
19
  let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
20
20
  let valibot = require("valibot");
21
21
  valibot = require_schemas.__toESM(valibot);
@@ -268,21 +268,68 @@ const InstallationRequestBodySchema = (0, valibot.object)({
268
268
  ioEventsUrl: (0, valibot.string)(),
269
269
  ioEventsEnv: (0, valibot.string)()
270
270
  });
271
- /** Creates an installation state store using lib-core combined storage. */
272
- function createInstallationStore() {
271
+ /** Creates a workflow state store with the given prefix. */
272
+ function createWorkflowStore(prefix) {
273
273
  return createCombinedStore({
274
- cache: { keyPrefix: "installation" },
274
+ cache: { keyPrefix: prefix },
275
275
  persistent: {
276
- dirPrefix: "installation",
276
+ dirPrefix: prefix,
277
277
  shouldPersist: require_management.isCompletedState
278
278
  }
279
279
  });
280
280
  }
281
+ /** Creates the installation state store. */
282
+ function createInstallationStore() {
283
+ return createWorkflowStore("installation");
284
+ }
285
+ /** Creates the uninstallation state store. */
286
+ function createUninstallationStore() {
287
+ return createWorkflowStore("uninstallation");
288
+ }
281
289
  /** Returns the storage key used to store the current installation ID. */
282
290
  function getStorageKey() {
283
291
  return "current";
284
292
  }
285
293
  /**
294
+ * Merges rawParams with body fields, overriding API URLs.
295
+ * Shared by POST /, POST /execution, POST /uninstallation, POST /uninstallation/execution.
296
+ */
297
+ function buildWorkflowParams(body, rawParams) {
298
+ return {
299
+ ...rawParams,
300
+ appData: body.appData,
301
+ AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
302
+ AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
303
+ AIO_COMMERCE_API_BASE_URL: body.commerceBaseUrl,
304
+ AIO_COMMERCE_API_FLAVOR: body.commerceEnv
305
+ };
306
+ }
307
+ /**
308
+ * Builds an InstallationContext from merged workflow params.
309
+ * Shared by POST /execution and POST /uninstallation/execution.
310
+ */
311
+ function buildInstallationContext(params, appConfig, logFn) {
312
+ return {
313
+ appData: params.appData,
314
+ params,
315
+ logger: logFn,
316
+ customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {}
317
+ };
318
+ }
319
+ /**
320
+ * Reads state from a store and returns 200 with body or 204.
321
+ * Shared by GET / and GET /uninstallation.
322
+ */
323
+ async function readStateFromStore(store, logFn) {
324
+ const state = await store.get(getStorageKey());
325
+ if (state) {
326
+ logFn(`Found state: ${state.status}`);
327
+ return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: state });
328
+ }
329
+ logFn("No state found");
330
+ return (0, _adobe_aio_commerce_lib_core_responses.noContent)();
331
+ }
332
+ /**
286
333
  * Creates hooks to sync installation state to storage.
287
334
  */
288
335
  function createInstallationHooks(store, logFn) {
@@ -303,9 +350,14 @@ function createInstallationHooks(store, logFn) {
303
350
  * Installation action router.
304
351
  *
305
352
  * Routes:
306
- * - POST /installation - Start installation (creates plan, invokes execution async)
307
- * - GET /installation/execution - Get current execution status
308
- * - POST /installation/execution - Execute installation (internal, called async)
353
+ * - GET /installation - Get current installation status
354
+ * - POST /installation - Start installation (creates plan, invokes execution async)
355
+ * - POST /installation/execution - Execute installation (internal, called async)
356
+ * - POST /installation/validation - Pre-installation validation
357
+ * - POST /installation/uninstallation - Start uninstallation (async)
358
+ * - GET /installation/uninstallation - Get current uninstallation status
359
+ * - POST /installation/uninstallation/execution - Execute uninstallation (internal, called async)
360
+ * - DELETE /installation/uninstallation - Clear uninstallation state only (no offboarding)
309
361
  */
310
362
  const router = new require_router.HttpActionRouter().use(require_router.logger({ name: () => "installation" }));
311
363
  /**
@@ -318,13 +370,7 @@ const router = new require_router.HttpActionRouter().use(require_router.logger({
318
370
  */
319
371
  router.get("/", { handler: async (_req, { logger }) => {
320
372
  logger.debug("Getting installation execution status...");
321
- const state = await (await createInstallationStore()).get(getStorageKey());
322
- if (state) {
323
- logger.debug(`Found execution: ${state.status}`);
324
- return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: state });
325
- }
326
- logger.debug("No execution found");
327
- return (0, _adobe_aio_commerce_lib_core_responses.noContent)();
373
+ return readStateFromStore(await createInstallationStore(), (msg) => logger.debug(msg));
328
374
  } });
329
375
  /**
330
376
  * POST / - Start installation
@@ -356,17 +402,14 @@ router.post("/", {
356
402
  const initialState = require_management.createInitialInstallationState({ config: appConfig });
357
403
  logger.debug(`Created initial state: ${initialState.id}`);
358
404
  await store.put(getStorageKey(), initialState);
359
- const activation = await (0, openwhisk.default)().actions.invoke({
405
+ const ow = (0, openwhisk.default)();
406
+ const mergedParams = buildWorkflowParams(req.body, rawParams);
407
+ const activation = await ow.actions.invoke({
360
408
  name: DEFAULT_ACTION_NAME,
361
409
  blocking: false,
362
410
  result: false,
363
411
  params: {
364
- ...rawParams,
365
- appData: req.body.appData,
366
- AIO_EVENTS_API_BASE_URL: req.body.ioEventsUrl,
367
- AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: req.body.ioEventsEnv,
368
- AIO_COMMERCE_API_BASE_URL: req.body.commerceBaseUrl,
369
- AIO_COMMERCE_API_FLAVOR: req.body.commerceEnv,
412
+ ...mergedParams,
370
413
  initialState,
371
414
  appConfig,
372
415
  __ow_path: "/execution",
@@ -388,18 +431,13 @@ router.post("/", {
388
431
  * It runs the actual installation workflow and saves state.
389
432
  */
390
433
  router.post("/execution", { handler: async (_req, { logger, rawParams }) => {
391
- const { appData, ...params } = rawParams;
434
+ const params = rawParams;
392
435
  const { initialState, appConfig } = params;
393
436
  if (!initialState) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)("initialState is required for execution");
394
437
  if (!appConfig) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)("appConfig is required for execution");
395
438
  const store = await createInstallationStore();
396
439
  const hooks = createInstallationHooks(store, (msg) => logger.debug(msg));
397
- const installationContext = {
398
- appData,
399
- params,
400
- logger,
401
- customScripts: params.customScriptsLoader?.(appConfig, logger) || {}
402
- };
440
+ const installationContext = buildInstallationContext(params, appConfig, logger);
403
441
  logger.debug(`Executing installation: ${initialState.id}`);
404
442
  const result = await require_management.runInstallation({
405
443
  installationContext,
@@ -434,14 +472,7 @@ router.post("/validation", {
434
472
  logger.debug("Running pre-installation validation...");
435
473
  const appConfig = rawParams.appConfig;
436
474
  if (!appConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
437
- const { appData, ...params } = {
438
- ...rawParams,
439
- appData: req.body.appData,
440
- AIO_EVENTS_API_BASE_URL: req.body.ioEventsUrl,
441
- AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: req.body.ioEventsEnv,
442
- AIO_COMMERCE_API_BASE_URL: req.body.commerceBaseUrl,
443
- AIO_COMMERCE_API_FLAVOR: req.body.commerceEnv
444
- };
475
+ const { appData, ...params } = buildWorkflowParams(req.body, rawParams);
445
476
  const result = await require_management.runValidation({
446
477
  validationContext: {
447
478
  appData,
@@ -455,14 +486,107 @@ router.post("/validation", {
455
486
  }
456
487
  });
457
488
  /**
458
- * DELETE / - Clear installation state
489
+ * GET /uninstallation - Get current uninstallation status
490
+ *
491
+ * Returns 200 with state if an uninstallation has been started, 204 otherwise.
492
+ */
493
+ router.get("/uninstallation", { handler: async (_req, { logger }) => {
494
+ logger.debug("Getting uninstallation execution status...");
495
+ return readStateFromStore(await createUninstallationStore(), (msg) => logger.debug(msg));
496
+ } });
497
+ /**
498
+ * POST /uninstallation - Start uninstallation (async)
499
+ *
500
+ * Flow:
501
+ * 1. Check uninstallation store for existing state
502
+ * 2. If in-progress: return 409 Conflict
503
+ * 3. Create initial uninstall state, save to store
504
+ * 4. Invoke POST /uninstallation/execution async via openwhisk
505
+ * 5. Return 202 Accepted with initial state
506
+ */
507
+ router.post("/uninstallation", {
508
+ body: InstallationRequestBodySchema,
509
+ handler: async (req, { logger, rawParams }) => {
510
+ logger.debug("Starting async uninstallation...");
511
+ const appConfig = rawParams.appConfig;
512
+ if (!appConfig) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
513
+ const store = await createUninstallationStore();
514
+ const existingState = await store.get(getStorageKey());
515
+ if (existingState && require_management.isInProgressState(existingState)) {
516
+ logger.debug(`Uninstallation already in progress: ${existingState.status}`);
517
+ return (0, _adobe_aio_commerce_lib_core_responses.conflict)("Uninstallation is already in progress. Wait for it to complete.");
518
+ }
519
+ const initialState = require_management.createInitialUninstallationState({ config: appConfig });
520
+ logger.debug(`Created initial uninstall state: ${initialState.id}`);
521
+ await store.put(getStorageKey(), initialState);
522
+ const workflowParams = buildWorkflowParams(req.body, rawParams);
523
+ const activation = await (0, openwhisk.default)().actions.invoke({
524
+ name: DEFAULT_ACTION_NAME,
525
+ blocking: false,
526
+ result: false,
527
+ params: {
528
+ ...workflowParams,
529
+ initialState,
530
+ appConfig,
531
+ __ow_path: "/uninstallation/execution",
532
+ __ow_method: "post"
533
+ }
534
+ });
535
+ logger.debug(`Async uninstallation started: ${activation.activationId}`);
536
+ return (0, _adobe_aio_commerce_lib_core_responses.accepted)({ body: {
537
+ message: "Uninstallation started",
538
+ activationId: activation.activationId,
539
+ ...initialState
540
+ } });
541
+ }
542
+ });
543
+ /**
544
+ * POST /uninstallation/execution - Execute uninstallation (internal, called async by POST /uninstallation)
545
+ *
546
+ * Flow:
547
+ * 1. Build InstallationContext from params
548
+ * 2. Run uninstallation workflow with hooks (hooks persist state per step)
549
+ * 3. Save final state to uninstallation store
550
+ * 4. On success, clear installation store
551
+ * 5. Return 200 on success, 500 on failure
552
+ */
553
+ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawParams }) => {
554
+ const params = rawParams;
555
+ const { initialState, appConfig } = params;
556
+ if (!initialState) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)("initialState is required for execution");
557
+ if (!appConfig) return (0, _adobe_aio_commerce_lib_core_responses.badRequest)("appConfig is required for execution");
558
+ const store = await createUninstallationStore();
559
+ const hooks = createInstallationHooks(store, (msg) => logger.debug(msg));
560
+ const installationContext = buildInstallationContext(params, appConfig, logger);
561
+ logger.debug(`Executing uninstallation: ${initialState.id}`);
562
+ const result = await require_management.runUninstallation({
563
+ installationContext,
564
+ config: appConfig,
565
+ initialState,
566
+ hooks
567
+ });
568
+ await store.put(getStorageKey(), result);
569
+ logger.debug(`Uninstallation completed: ${result.status}`);
570
+ if (require_management.isSucceededState(result)) {
571
+ await (await createInstallationStore()).delete(getStorageKey());
572
+ logger.debug("Cleared installation state after successful uninstallation");
573
+ }
574
+ if (require_management.isFailedState(result)) return (0, _adobe_aio_commerce_lib_core_responses.internalServerError)({ body: {
575
+ message: "Uninstallation failed",
576
+ error: result.error,
577
+ state: result
578
+ } });
579
+ return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: result });
580
+ } });
581
+ /**
582
+ * DELETE /uninstallation - Clear uninstallation state
459
583
  *
460
- * This endpoint allows clearing the installation state.
584
+ * Removes the stored uninstallation state without triggering any offboarding.
461
585
  */
462
- router.delete("/", { handler: async (_req, { logger }) => {
463
- logger.debug("Clearing installation state...");
464
- await (await createInstallationStore()).delete(getStorageKey());
465
- logger.debug("Installation state cleared");
586
+ router.delete("/uninstallation", { handler: async (_req, { logger }) => {
587
+ logger.debug("Clearing uninstallation state...");
588
+ await (await createUninstallationStore()).delete(getStorageKey());
589
+ logger.debug("Uninstallation state cleared");
466
590
  return (0, _adobe_aio_commerce_lib_core_responses.noContent)();
467
591
  } });
468
592
  /** Factory to create the route handler for the `installation` action. */
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { n as CommerceAppConfigOutputModel } from "../app-DcQMhW2N.cjs";
16
- import { V as InstallationContext } from "../index-DZxladgt.cjs";
16
+ import { q as InstallationContext } from "../index-BVwQk9bx.cjs";
17
17
  import * as _$_adobe_aio_commerce_lib_core_responses0 from "@adobe/aio-commerce-lib-core/responses";
18
18
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
19
19
 
@@ -62,32 +62,43 @@ type StepContextFactory<TStepCtx extends Record<string, unknown> = Record<string
62
62
  type ExecutionContext<TStepCtx extends Record<string, unknown> = Record<string, unknown>> = InstallationContext & TStepCtx;
63
63
  /**
64
64
  * A narrowed context available to step `validate` handlers.
65
- * Excludes `customScripts` — those only apply during installation `run`, not pre-flight validation.
65
+ * Excludes `customScripts` — those only apply during installation, not pre-flight validation.
66
66
  */
67
67
  type ValidationContext = Omit<InstallationContext, "customScripts">;
68
68
  /** The context passed to step `validate` handlers (base validation context merged with step-level context). */
69
69
  type ValidationExecutionContext<TStepCtx extends Record<string, unknown> = Record<string, unknown>> = ValidationContext & TStepCtx;
70
- /** Metadata for a step (used for UI display). */
71
- type StepMeta = {
70
+ /** Metadata info for a step (used for UI display). */
71
+ type StepMetaInfo = {
72
72
  label: string;
73
73
  description?: string;
74
74
  };
75
+ /** Step metadata keyed by execution mode. */
76
+ type StepMeta = {
77
+ install: StepMetaInfo;
78
+ uninstall?: StepMetaInfo;
79
+ };
75
80
  /** Defines the base properties of a step. */
76
81
  type StepBase<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel> = {
77
- /** The name of this step. */name: TName; /** Metadata associated with the step. */
82
+ /** The name of this step. */name: TName; /** Metadata associated with the step, keyed by execution mode. */
78
83
  meta: StepMeta; /** Whether the step should be taken into consideration. */
79
84
  when?: (config: CommerceAppConfigOutputModel) => config is TConfig;
80
85
  };
81
86
  /** A leaf step that executes work (no children). */
82
87
  type LeafStep<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> = StepBase<TName, TConfig> & {
83
88
  type: "leaf"; /** The execution handler for the step. */
84
- run: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
89
+ install: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
85
90
  /**
86
91
  * Optional pre-installation validation handler.
87
92
  * Called before installation begins to surface issues (errors or warnings).
88
93
  * Returning an empty array means the step has no issues.
89
94
  */
90
95
  validate?: (config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>;
96
+ /**
97
+ * Optional uninstall handler for the step.
98
+ * Called during uninstallation to reverse the work done by `install`.
99
+ * If absent, the step is silently skipped during uninstallation.
100
+ */
101
+ uninstall?: (config: TConfig, context: ExecutionContext<TStepCtx>) => void | Promise<void>;
91
102
  };
92
103
  /** A branch step that contains children (no execution). */
93
104
  type BranchStep<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TChildren extends AnyStep[] = AnyStep[]> = StepBase<TName, TConfig> & {
@@ -107,10 +118,11 @@ type Step<TName extends string = string, TConfig extends CommerceAppConfigOutput
107
118
  interface AnyStep {
108
119
  children?: AnyStep[];
109
120
  context?: (context: InstallationContext) => any;
121
+ install?: (config: any, context: any) => unknown | Promise<unknown>;
110
122
  meta: StepMeta;
111
123
  name: string;
112
- run?: (config: any, context: any) => unknown | Promise<unknown>;
113
124
  type: "leaf" | "branch";
125
+ uninstall?: (config: any, context: any) => void | Promise<void>;
114
126
  validate?: (config: any, context: any) => ValidationIssue[] | Promise<ValidationIssue[]>;
115
127
  when?: (config: CommerceAppConfigOutputModel) => boolean;
116
128
  }
@@ -129,8 +141,8 @@ type BranchStepOptions<TName extends string, TConfig extends CommerceAppConfigOu
129
141
  * ```typescript
130
142
  * const createProviders = defineLeafStep({
131
143
  * name: "providers",
132
- * meta: { label: "Create Providers", description: "Creates I/O Events providers" },
133
- * run: async ({ config, stepContext }) => {
144
+ * meta: { install: { label: "Create Providers", description: "Creates I/O Events providers" } },
145
+ * install: async ({ config, stepContext }) => {
134
146
  * const { eventsClient } = stepContext;
135
147
  * return eventsClient.createProvider(config.eventing);
136
148
  * },
@@ -142,7 +154,8 @@ declare function defineLeafStep<TName extends string, TConfig extends CommerceAp
142
154
  name: TName;
143
155
  meta: StepMeta;
144
156
  when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
145
- run: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
157
+ install: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
158
+ uninstall: ((config: TConfig, context: ExecutionContext<TStepCtx>) => void | Promise<void>) | undefined;
146
159
  validate: ((config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>) | undefined;
147
160
  };
148
161
  /**
@@ -152,7 +165,7 @@ declare function defineLeafStep<TName extends string, TConfig extends CommerceAp
152
165
  * ```typescript
153
166
  * const eventing = defineBranchStep({
154
167
  * name: "eventing",
155
- * meta: { label: "Eventing", description: "Sets up I/O Events" },
168
+ * meta: { install: { label: "Eventing", description: "Sets up I/O Events" } },
156
169
  * when: hasEventing,
157
170
  * context: async (ctx) => ({ eventsClient: await createEventsClient(ctx) }),
158
171
  * children: [commerceEventsStep, externalEventsStep],
@@ -188,7 +201,7 @@ type StepStatus = {
188
201
  /** Step name (unique among siblings). */name: string; /** Unique step identifier (e.g., UUID). */
189
202
  id: string; /** Full path from root to this step. */
190
203
  path: string[]; /** Step metadata (for display purposes). */
191
- meta: StepMeta; /** Current execution status. */
204
+ meta: StepMetaInfo; /** Current execution status. */
192
205
  status: ExecutionStatus; /** Child step statuses (empty for leaf steps). */
193
206
  children: StepStatus[];
194
207
  };
@@ -270,7 +283,8 @@ type InstallationHooks = {
270
283
  /** Options for creating an initial installation state. */
271
284
  type CreateInitialStateOptions = {
272
285
  /** The root branch step to build the state from. */rootStep: BranchStep; /** The app configuration used to determine applicable steps. */
273
- config: CommerceAppConfigOutputModel;
286
+ config: CommerceAppConfigOutputModel; /** The execution mode. When "uninstall", steps use `meta.uninstall` if defined; defaults to "install". */
287
+ mode?: ExecutionMode;
274
288
  };
275
289
  /** Options for executing a workflow. */
276
290
  type ExecuteWorkflowOptions = {
@@ -280,6 +294,8 @@ type ExecuteWorkflowOptions = {
280
294
  initialState: InProgressInstallationState; /** Lifecycle hooks for status change notifications. */
281
295
  hooks?: InstallationHooks;
282
296
  };
297
+ /** Execution mode: "install" or "uninstall". */
298
+ type ExecutionMode = "install" | "uninstall";
283
299
  /**
284
300
  * Creates an initial installation state from a root step and config.
285
301
  *
@@ -291,13 +307,18 @@ declare function createInitialState(options: CreateInitialStateOptions): InProgr
291
307
  * Executes a workflow from an initial state. Returns the final state (never throws).
292
308
  */
293
309
  declare function executeWorkflow(options: ExecuteWorkflowOptions): Promise<SucceededInstallationState | FailedInstallationState>;
310
+ /**
311
+ * Executes an uninstall workflow from an initial state. Returns the final state (never throws).
312
+ * Steps with an `uninstall` handler get it called; steps without are silently skipped.
313
+ */
314
+ declare function executeUninstallWorkflow(options: ExecuteWorkflowOptions): Promise<SucceededInstallationState | FailedInstallationState>;
294
315
  //#endregion
295
316
  //#region source/management/installation/workflow/validation.d.ts
296
317
  /** Validation result for a single step, mirroring the step hierarchy. */
297
318
  type StepValidationResult = {
298
319
  /** Step name (unique among siblings). */name: string; /** Full path from root to this step. */
299
320
  path: string[]; /** Step metadata (for display purposes). */
300
- meta: StepMeta; /** Issues found for this specific step (not including children). */
321
+ meta: StepMetaInfo; /** Issues found for this specific step (not including children). */
301
322
  issues: ValidationIssue[]; /** Validation results for child steps (empty for leaf steps). */
302
323
  children: StepValidationResult[];
303
324
  };
@@ -342,35 +363,49 @@ declare function validateStepTree(options: ValidateStepTreeOptions): Promise<Val
342
363
  * @returns The result of the installation step (can be any value or Promise)
343
364
  */
344
365
  type CustomInstallationStepHandler<TResult = unknown> = (config: CommerceAppConfigOutputModel, context: ExecutionContext) => TResult | Promise<TResult>;
366
+ /**
367
+ * Object form for defining a custom installation step with both install and uninstall handlers.
368
+ *
369
+ * @template TResult - The return type of the install handler
370
+ */
371
+ type CustomInstallationStepDefinition<TResult = unknown> = {
372
+ /** The installation handler, called when the app is installed. */install: CustomInstallationStepHandler<TResult>; /** The optional uninstall handler, called when the app is uninstalled. */
373
+ uninstall?: CustomInstallationStepHandler<void>;
374
+ };
345
375
  /**
346
376
  * Define a custom installation step with type-safe parameters.
347
377
  *
348
378
  * This helper provides type safety and IDE autocompletion for custom installation scripts.
349
- * The handler function receives properly typed `config` and `context` parameters.
379
+ * Accepts either a plain function (install only) or an object with `install` and optional
380
+ * `uninstall` handlers.
350
381
  *
351
- * @param handler - The installation step handler function
352
- * @returns The same handler function (for use as default export)
353
- *
354
- * @example
382
+ * @example Plain function (install only):
355
383
  * ```typescript
356
384
  * import { defineCustomInstallationStep } from "@adobe/aio-commerce-lib-app/management";
357
385
  *
358
386
  * export default defineCustomInstallationStep(async (config, context) => {
359
387
  * const { logger, params } = context;
360
- *
361
388
  * logger.info(`Setting up ${config.metadata.displayName}...`);
389
+ * return { status: "success" };
390
+ * });
391
+ * ```
362
392
  *
363
- * // Your installation logic here
364
- * // TypeScript will provide autocompletion for config and context
393
+ * @example Object form with install and uninstall:
394
+ * ```typescript
395
+ * import { defineCustomInstallationStep } from "@adobe/aio-commerce-lib-app/management";
365
396
  *
366
- * return {
367
- * status: "success",
368
- * message: "Setup completed",
369
- * };
397
+ * export default defineCustomInstallationStep({
398
+ * install: async (config, context) => {
399
+ * context.logger.info(`Registering ${config.metadata.displayName}...`);
400
+ * return { status: "success" };
401
+ * },
402
+ * uninstall: async (config, context) => {
403
+ * context.logger.info(`Removing ${config.metadata.displayName}...`);
404
+ * },
370
405
  * });
371
406
  * ```
372
407
  */
373
- declare function defineCustomInstallationStep<TResult = unknown>(handler: CustomInstallationStepHandler<TResult>): CustomInstallationStepHandler<TResult>;
408
+ declare function defineCustomInstallationStep<TResult = unknown>(handlerOrDefinition: CustomInstallationStepHandler<TResult> | CustomInstallationStepDefinition<TResult>): CustomInstallationStepHandler<TResult> | CustomInstallationStepDefinition<TResult>;
374
409
  //#endregion
375
410
  //#region source/management/installation/runner.d.ts
376
411
  /** Options for creating an initial installation state. */
@@ -394,6 +429,25 @@ declare function createInitialInstallationState(options: CreateInitialInstallati
394
429
  * Runs the full installation workflow. Returns the final state (never throws).
395
430
  */
396
431
  declare function runInstallation(options: RunInstallationOptions): Promise<SucceededInstallationState | FailedInstallationState>;
432
+ /** Options for creating an initial uninstallation state. */
433
+ type CreateInitialUninstallationStateOptions = {
434
+ /** The app configuration used to determine applicable steps. */config: CommerceAppConfigOutputModel;
435
+ };
436
+ /** Options for running an uninstallation. */
437
+ type RunUninstallationOptions = {
438
+ /** Shared installation context (params, logger, etc.). */installationContext: InstallationContext; /** The app configuration. */
439
+ config: CommerceAppConfigOutputModel; /** The initial uninstallation state (with all steps pending). */
440
+ initialState: InProgressInstallationState; /** Lifecycle hooks for status change notifications. */
441
+ hooks?: InstallationHooks;
442
+ };
443
+ /**
444
+ * Creates an initial uninstallation state from the config and step definitions.
445
+ */
446
+ declare function createInitialUninstallationState(options: CreateInitialUninstallationStateOptions): InProgressInstallationState;
447
+ /**
448
+ * Runs the full uninstallation workflow. Returns the final state (never throws).
449
+ */
450
+ declare function runUninstallation(options: RunUninstallationOptions): Promise<SucceededInstallationState | FailedInstallationState>;
397
451
  /** Options for running pre-installation validation. */
398
452
  type RunValidationOptions = {
399
453
  /** Validation context (params, logger, appData — no customScripts). */validationContext: ValidationContext; /** The app configuration. */
@@ -409,4 +463,4 @@ type RunValidationOptions = {
409
463
  */
410
464
  declare function runValidation(options: RunValidationOptions): Promise<ValidationResult>;
411
465
  //#endregion
412
- export { isBranchStep as $, StepStatus as A, InferStepOutput as B, ExecutionStatus as C, InstallationError as D, InstallationData as E, isSucceededState as F, StepContextFactory as G, LeafStep as H, AnyStep as I, ValidationExecutionContext as J, StepMeta as K, BranchStep as L, isCompletedState as M, isFailedState as N, InstallationState as O, isInProgressState as P, defineLeafStep as Q, BranchStepOptions as R, StepSucceededEvent as S, InProgressInstallationState as T, LeafStepOptions as U, InstallationContext as V, Step as W, ValidationIssueSeverity as X, ValidationIssue as Y, defineBranchStep as Z, executeWorkflow as _, runInstallation as a, StepFailedEvent as b, defineCustomInstallationStep as c, ValidationResult as d, isLeafStep as et, ValidationSummary as f, createInitialState as g, ExecuteWorkflowOptions as h, createInitialInstallationState as i, SucceededInstallationState as j, InstallationStatus as k, StepValidationResult as l, CreateInitialStateOptions as m, RunInstallationOptions as n, runValidation as o, validateStepTree as p, ValidationContext as q, RunValidationOptions as r, CustomInstallationStepHandler as s, CreateInitialInstallationStateOptions as t, ValidateStepTreeOptions as u, InstallationHooks as v, FailedInstallationState as w, StepStartedEvent as x, StepEvent as y, ExecutionContext as z };
466
+ export { StepMetaInfo as $, FailedInstallationState as A, isInProgressState as B, executeWorkflow as C, StepStartedEvent as D, StepFailedEvent as E, InstallationStatus as F, ExecutionContext as G, AnyStep as H, StepStatus as I, LeafStep as J, InferStepOutput as K, SucceededInstallationState as L, InstallationData as M, InstallationError as N, StepSucceededEvent as O, InstallationState as P, StepMeta as Q, isCompletedState as R, executeUninstallWorkflow as S, StepEvent as T, BranchStep as U, isSucceededState as V, BranchStepOptions as W, Step as X, LeafStepOptions as Y, StepContextFactory as Z, ValidationSummary as _, RunValidationOptions as a, defineLeafStep as at, ExecuteWorkflowOptions as b, runInstallation as c, CustomInstallationStepDefinition as d, ValidationContext as et, CustomInstallationStepHandler as f, ValidationResult as g, ValidateStepTreeOptions as h, RunUninstallationOptions as i, defineBranchStep as it, InProgressInstallationState as j, ExecutionStatus as k, runUninstallation as l, StepValidationResult as m, CreateInitialUninstallationStateOptions as n, ValidationIssue as nt, createInitialInstallationState as o, isBranchStep as ot, defineCustomInstallationStep as p, InstallationContext as q, RunInstallationOptions as r, ValidationIssueSeverity as rt, createInitialUninstallationState as s, isLeafStep as st, CreateInitialInstallationStateOptions as t, ValidationExecutionContext as tt, runValidation as u, validateStepTree as v, InstallationHooks as w, createInitialState as x, CreateInitialStateOptions as y, isFailedState as z };
@@ -13,13 +13,15 @@
13
13
  */
14
14
 
15
15
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
- const require_management = require('../management-iLQubQ7K.cjs');
16
+ const require_management = require('../management-C6xG5bfl.cjs');
17
17
 
18
18
  exports.createInitialInstallationState = require_management.createInitialInstallationState;
19
+ exports.createInitialUninstallationState = require_management.createInitialUninstallationState;
19
20
  exports.defineCustomInstallationStep = require_management.defineCustomInstallationStep;
20
21
  exports.isCompletedState = require_management.isCompletedState;
21
22
  exports.isFailedState = require_management.isFailedState;
22
23
  exports.isInProgressState = require_management.isInProgressState;
23
24
  exports.isSucceededState = require_management.isSucceededState;
24
25
  exports.runInstallation = require_management.runInstallation;
26
+ exports.runUninstallation = require_management.runUninstallation;
25
27
  exports.runValidation = require_management.runValidation;
@@ -12,5 +12,5 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { $ as isBranchStep, A as StepStatus, B as InferStepOutput, C as ExecutionStatus, D as InstallationError, E as InstallationData, F as isSucceededState, G as StepContextFactory, H as LeafStep, I as AnyStep, J as ValidationExecutionContext, K as StepMeta, L as BranchStep, M as isCompletedState, N as isFailedState, O as InstallationState, P as isInProgressState, Q as defineLeafStep, R as BranchStepOptions, S as StepSucceededEvent, T as InProgressInstallationState, U as LeafStepOptions, V as InstallationContext, W as Step, X as ValidationIssueSeverity, Y as ValidationIssue, Z as defineBranchStep, _ as executeWorkflow, a as runInstallation, b as StepFailedEvent, c as defineCustomInstallationStep, d as ValidationResult, et as isLeafStep, f as ValidationSummary, g as createInitialState, h as ExecuteWorkflowOptions, i as createInitialInstallationState, j as SucceededInstallationState, k as InstallationStatus, l as StepValidationResult, m as CreateInitialStateOptions, n as RunInstallationOptions, o as runValidation, p as validateStepTree, q as ValidationContext, r as RunValidationOptions, s as CustomInstallationStepHandler, t as CreateInitialInstallationStateOptions, u as ValidateStepTreeOptions, v as InstallationHooks, w as FailedInstallationState, x as StepStartedEvent, y as StepEvent, z as ExecutionContext } from "../index-DZxladgt.cjs";
16
- export { AnyStep, BranchStep, BranchStepOptions, CreateInitialInstallationStateOptions, CreateInitialStateOptions, CustomInstallationStepHandler, ExecuteWorkflowOptions, ExecutionContext, ExecutionStatus, FailedInstallationState, InProgressInstallationState, InferStepOutput, InstallationContext, InstallationData, InstallationError, InstallationHooks, InstallationState, InstallationStatus, LeafStep, LeafStepOptions, RunInstallationOptions, RunValidationOptions, Step, StepContextFactory, StepEvent, StepFailedEvent, StepMeta, StepStartedEvent, StepStatus, StepSucceededEvent, StepValidationResult, SucceededInstallationState, ValidateStepTreeOptions, ValidationContext, ValidationExecutionContext, ValidationIssue, ValidationIssueSeverity, ValidationResult, ValidationSummary, createInitialInstallationState, createInitialState, defineBranchStep, defineCustomInstallationStep, defineLeafStep, executeWorkflow, isBranchStep, isCompletedState, isFailedState, isInProgressState, isLeafStep, isSucceededState, runInstallation, runValidation, validateStepTree };
15
+ import { $ as StepMetaInfo, A as FailedInstallationState, B as isInProgressState, C as executeWorkflow, D as StepStartedEvent, E as StepFailedEvent, F as InstallationStatus, G as ExecutionContext, H as AnyStep, I as StepStatus, J as LeafStep, K as InferStepOutput, L as SucceededInstallationState, M as InstallationData, N as InstallationError, O as StepSucceededEvent, P as InstallationState, Q as StepMeta, R as isCompletedState, S as executeUninstallWorkflow, T as StepEvent, U as BranchStep, V as isSucceededState, W as BranchStepOptions, X as Step, Y as LeafStepOptions, Z as StepContextFactory, _ as ValidationSummary, a as RunValidationOptions, at as defineLeafStep, b as ExecuteWorkflowOptions, c as runInstallation, d as CustomInstallationStepDefinition, et as ValidationContext, f as CustomInstallationStepHandler, g as ValidationResult, h as ValidateStepTreeOptions, i as RunUninstallationOptions, it as defineBranchStep, j as InProgressInstallationState, k as ExecutionStatus, l as runUninstallation, m as StepValidationResult, n as CreateInitialUninstallationStateOptions, nt as ValidationIssue, o as createInitialInstallationState, ot as isBranchStep, p as defineCustomInstallationStep, q as InstallationContext, r as RunInstallationOptions, rt as ValidationIssueSeverity, s as createInitialUninstallationState, st as isLeafStep, t as CreateInitialInstallationStateOptions, tt as ValidationExecutionContext, u as runValidation, v as validateStepTree, w as InstallationHooks, x as createInitialState, y as CreateInitialStateOptions, z as isFailedState } from "../index-BVwQk9bx.cjs";
16
+ export { AnyStep, BranchStep, BranchStepOptions, CreateInitialInstallationStateOptions, CreateInitialStateOptions, CreateInitialUninstallationStateOptions, CustomInstallationStepDefinition, CustomInstallationStepHandler, ExecuteWorkflowOptions, ExecutionContext, ExecutionStatus, FailedInstallationState, InProgressInstallationState, InferStepOutput, InstallationContext, InstallationData, InstallationError, InstallationHooks, InstallationState, InstallationStatus, LeafStep, LeafStepOptions, RunInstallationOptions, RunUninstallationOptions, RunValidationOptions, Step, StepContextFactory, StepEvent, StepFailedEvent, StepMeta, StepMetaInfo, StepStartedEvent, StepStatus, StepSucceededEvent, StepValidationResult, SucceededInstallationState, ValidateStepTreeOptions, ValidationContext, ValidationExecutionContext, ValidationIssue, ValidationIssueSeverity, ValidationResult, ValidationSummary, createInitialInstallationState, createInitialState, createInitialUninstallationState, defineBranchStep, defineCustomInstallationStep, defineLeafStep, executeUninstallWorkflow, executeWorkflow, isBranchStep, isCompletedState, isFailedState, isInProgressState, isLeafStep, isSucceededState, runInstallation, runUninstallation, runValidation, validateStepTree };