@adobe/aio-commerce-lib-app 2.1.0 → 2.2.0-alpha-20261110171457

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 (56) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/actions/app-config/index.cjs +5 -5
  3. package/dist/cjs/actions/app-config/index.d.cts +2 -2
  4. package/dist/cjs/actions/association/index.cjs +2 -2
  5. package/dist/cjs/actions/config/index.cjs +2 -2
  6. package/dist/cjs/actions/config/index.d.cts +2 -2
  7. package/dist/cjs/actions/installation/index.cjs +61 -21
  8. package/dist/cjs/actions/installation/index.d.cts +4 -3
  9. package/dist/cjs/actions/scope-tree/index.cjs +2 -2
  10. package/dist/cjs/{app-Ch19CR6g.d.cts → app-DREvtzyX.d.cts} +330 -4
  11. package/dist/cjs/commands/index.cjs +27 -12
  12. package/dist/cjs/config/index.browser.d.cts +2 -1
  13. package/dist/cjs/config/index.node.cjs +3 -3
  14. package/dist/cjs/config/index.node.d.cts +96 -8
  15. package/dist/{es/define-C95h_wa0.d.mts → cjs/define-DW6Vzfku.d.cts} +1 -1
  16. package/dist/cjs/{index-D-Qn-irL.d.cts → index-B9MUZY-U.d.cts} +316 -316
  17. package/dist/cjs/{index-DWEigxhy.d.cts → index-vAue-u_y.d.cts} +1 -4
  18. package/dist/cjs/index.d.cts +8 -8
  19. package/dist/cjs/{index.node-CxdwPrOg.cjs → index.node-CcH8PCzC.cjs} +1 -1
  20. package/dist/cjs/management/index.cjs +1 -1
  21. package/dist/cjs/management/index.d.cts +6 -1
  22. package/dist/cjs/{management-C_JQpgVB.cjs → management-DeRZYcjS.cjs} +17 -5
  23. package/dist/cjs/{openapi-DFoMdZzI.cjs → openapi-CFqaMxUV.cjs} +426 -45
  24. package/dist/cjs/types-DslZGym8.d.cts +23 -0
  25. package/dist/cjs/{validate-B0rOILvG.cjs → validate-DAw7Pxp3.cjs} +1 -1
  26. package/dist/cjs/{router-DpB8wpR2.cjs → version-BACmFGD2.cjs} +77 -19
  27. package/dist/{es/webhooks-C9vMZZDZ.d.mts → cjs/webhooks-BMSr1l7c.d.cts} +268 -12
  28. package/dist/cjs/{webhooks-TvDm57xt.cjs → webhooks-EVlO8rxi.cjs} +53 -12
  29. package/dist/es/actions/app-config/index.d.mts +2 -2
  30. package/dist/es/actions/app-config/index.mjs +5 -5
  31. package/dist/es/actions/association/index.mjs +2 -2
  32. package/dist/es/actions/config/index.d.mts +1 -1
  33. package/dist/es/actions/config/index.mjs +2 -2
  34. package/dist/es/actions/installation/index.d.mts +4 -3
  35. package/dist/es/actions/installation/index.mjs +62 -22
  36. package/dist/es/actions/scope-tree/index.mjs +2 -2
  37. package/dist/es/{app-Ch19CR6g.d.mts → app-DREvtzyX.d.mts} +330 -4
  38. package/dist/es/commands/index.mjs +27 -12
  39. package/dist/es/config/index.browser.d.mts +2 -1
  40. package/dist/es/config/index.node.d.mts +95 -6
  41. package/dist/es/config/index.node.mjs +3 -3
  42. package/dist/{cjs/define-C12IwNNN.d.cts → es/define-B6cjhz1J.d.mts} +1 -1
  43. package/dist/es/{index-CgsSXApi.d.mts → index-DUJtT78x.d.mts} +2 -2
  44. package/dist/es/{index-VgCNSlLP.d.mts → index-zgc3l2nj.d.mts} +2 -2
  45. package/dist/es/index.d.mts +8 -8
  46. package/dist/es/{index.node-C8EXBW94.mjs → index.node-ClvSfs5w.mjs} +1 -1
  47. package/dist/es/management/index.d.mts +6 -1
  48. package/dist/es/management/index.mjs +1 -1
  49. package/dist/es/{management-DKDR7-fX.mjs → management-CG_4z2Ck.mjs} +17 -5
  50. package/dist/es/{openapi-E_1RFhAr.mjs → openapi-BUIws500.mjs} +426 -45
  51. package/dist/es/types-DslZGym8.d.mts +23 -0
  52. package/dist/es/{validate-CiJIjyOr.mjs → validate-BszbuhiE.mjs} +1 -1
  53. package/dist/es/{router-C23GIyGQ.mjs → version-CabzC7R9.mjs} +71 -20
  54. package/dist/{cjs/webhooks-Buu1d7AB.d.cts → es/webhooks-BLgKadnn.d.mts} +268 -12
  55. package/dist/es/{webhooks-CfrYeMy_.mjs → webhooks-DRPXVMMo.mjs} +48 -13
  56. package/package.json +4 -4
@@ -12,120 +12,11 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { r as CommerceAppConfigOutputModel } from "./app-Ch19CR6g.cjs";
16
- import { k as AdminUiComponentConfig, n as WebhookEntry, p as AppEvent, u as CustomInstallationStep } from "./webhooks-Buu1d7AB.cjs";
15
+ import { r as CommerceAppConfigOutputModel } from "./app-DREvtzyX.cjs";
16
+ import { k as AdminUiComponentConfig, n as WebhookEntry, p as AppEvent, u as CustomInstallationStep } from "./webhooks-BMSr1l7c.cjs";
17
+ import * as v from "valibot";
17
18
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
18
19
  import AioLogger from "@adobe/aio-lib-core-logging";
19
- import * as v from "valibot";
20
- /** Schema for validating the Adobe I/O app credentials used across lifecycle workflows. */
21
- declare const AppDataSchema: v.ObjectSchema<{
22
- readonly consumerOrgId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
23
- readonly orgName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
24
- readonly projectId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
25
- readonly projectName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
26
- readonly projectTitle: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
27
- readonly workspaceId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
28
- readonly workspaceName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
29
- readonly workspaceTitle: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
30
- }, undefined>;
31
- /** Type for Adobe I/O app credentials. */
32
- type AppData = v.InferOutput<typeof AppDataSchema>;
33
- /** Status of a step execution. */
34
- type ExecutionStatus = "pending" | "in-progress" | "succeeded" | "failed";
35
- /** A structured error with path to the failing step. */
36
- type WorkflowError<TPayload = unknown> = {
37
- /** Path to the step that failed (e.g., ["eventing", "commerce", "providers"]). */
38
- path: string[];
39
- /** Error key for easy identification. */
40
- key: string;
41
- /** Human-readable error message. */
42
- message?: string;
43
- /** Additional error payload. */
44
- payload?: TPayload;
45
- };
46
- /** Status of a step in the workflow tree. */
47
- type StepStatus = {
48
- /** Step name (unique among siblings). */
49
- name: string;
50
- /** Unique step identifier (e.g., UUID). */
51
- id: string;
52
- /** Full path from root to this step. */
53
- path: string[];
54
- /** Step metadata (for display purposes). */
55
- meta: StepMetaInfo;
56
- /** Current execution status. */
57
- status: ExecutionStatus;
58
- /** ISO timestamp when the step started executing. */
59
- startedAt?: string;
60
- /** ISO timestamp when the step succeeded or failed. */
61
- completedAt?: string;
62
- /** Child step statuses (empty for leaf steps). */
63
- children: StepStatus[];
64
- };
65
- /** Data collected during a workflow run as a nested structure following step paths. */
66
- type WorkflowData = {
67
- [key: string]: unknown | WorkflowData;
68
- };
69
- /** Base properties shared by all workflow run states. */
70
- type WorkflowRunStateBase = {
71
- /** Unique workflow run identifier. */
72
- id: string;
73
- /** Root step status. */
74
- step: StepStatus;
75
- /** Results from executed leaf steps, keyed by path. */
76
- data: WorkflowData | null;
77
- /**
78
- * The validated app configuration that drove this workflow. May be
79
- * undefined on states persisted before this field was introduced.
80
- */
81
- config?: CommerceAppConfigOutputModel;
82
- };
83
- /** Workflow run state when in progress. */
84
- type InProgressWorkflowState = WorkflowRunStateBase & {
85
- status: "in-progress";
86
- /** ISO timestamp when the workflow started. */
87
- startedAt: string;
88
- };
89
- /** Per-run state metadata captured alongside a workflow run's outcome. */
90
- type WorkflowStateMetadata = {
91
- /** True when the workflow was attempted more than once. */
92
- isRetry: boolean;
93
- };
94
- /** Workflow run state when completed successfully. */
95
- type SucceededWorkflowState = WorkflowRunStateBase & {
96
- status: "succeeded";
97
- /** ISO timestamp when the workflow started. */
98
- startedAt: string;
99
- /** ISO timestamp when the workflow completed. */
100
- completedAt: string;
101
- /** Per-run state metadata, present when a retry was attempted. */
102
- metadata?: WorkflowStateMetadata;
103
- };
104
- /** Workflow run state when failed. */
105
- type FailedWorkflowState = WorkflowRunStateBase & {
106
- status: "failed";
107
- /** ISO timestamp when the workflow started. */
108
- startedAt: string;
109
- /** ISO timestamp when the workflow failed. */
110
- completedAt: string;
111
- /** Error information about the failure. */
112
- error: WorkflowError;
113
- /** Per-run state metadata, present when a retry was attempted. */
114
- metadata?: WorkflowStateMetadata;
115
- };
116
- /**
117
- * The full workflow run state (persisted and returned by status endpoints).
118
- * Discriminated union by `status` field.
119
- */
120
- type WorkflowRunState = InProgressWorkflowState | SucceededWorkflowState | FailedWorkflowState;
121
- /** Type guard for in-progress workflow run state. */
122
- declare function isInProgressState(state: WorkflowRunState): state is InProgressWorkflowState;
123
- /** Type guard for succeeded workflow run state. */
124
- declare function isSucceededState(state: WorkflowRunState): state is SucceededWorkflowState;
125
- /** Type guard for failed workflow run state. */
126
- declare function isFailedState(state: WorkflowRunState): state is FailedWorkflowState;
127
- /** Type guard for completed workflow run state (succeeded or failed). */
128
- declare function isCompletedState(state: WorkflowRunState): state is SucceededWorkflowState | FailedWorkflowState;
129
20
  /** Severity level of a validation issue. */
130
21
  type ValidationIssueSeverity = "error" | "warning" | "info";
131
22
  /** A single validation issue reported by a step's validation. */
@@ -173,6 +64,180 @@ type ValidationResult = {
173
64
  /** Flat summary of issue counts for quick frontend decisions. */
174
65
  summary: ValidationSummary;
175
66
  };
67
+ /** A problem found while planning. Blocking issues prevent the plan from running. */
68
+ type PlanningIssue = {
69
+ /** The domain that raised the issue. */
70
+ domain: string;
71
+ /** Machine-readable code identifying the issue type. */
72
+ code: string;
73
+ /** Human-readable description of the issue. */
74
+ message: string;
75
+ /** Whether the issue prevents the plan from running. */
76
+ blocking: boolean;
77
+ /** Severity of the issue. Defaults to `error` when absent. */
78
+ severity?: ValidationIssueSeverity;
79
+ /** Full workflow path of the step that raised the issue. */
80
+ path?: string[];
81
+ /** Additional context about the issue. */
82
+ details?: Record<string, unknown>;
83
+ };
84
+ /** The config of a plan item, as declared in the app config. */
85
+ type ItemConfig = AdminUiComponentConfig | AppEvent | CustomInstallationStep | WebhookEntry;
86
+ /**
87
+ * A reference to a user-visible item an operation changes. Within a domain plan, operations with
88
+ * the same `key` are parts of one change to one item, for example the metadata and the subscription
89
+ * of one event.
90
+ */
91
+ type ItemRef = {
92
+ /** Identifies the item within its domain plan. */
93
+ key: string;
94
+ /**
95
+ * The item's config as declared: the target config item for an add or update,
96
+ * the baseline one for a remove. Absent for an item with no config, such as a live-only resource.
97
+ * Its `label` and `description` are the item's text. A custom installation step has a `name`
98
+ * instead of a `label`.
99
+ */
100
+ config?: ItemConfig;
101
+ };
102
+ /**
103
+ * A single change a domain proposes to apply to a resource, discriminated by
104
+ * `kind`: `add` creates a resource, `update` mutates one, `remove` deletes one.
105
+ */
106
+ type ResourceOperation<TBefore, TAfter = TBefore> = {
107
+ /** Stable identifier of the operation within its plan. */
108
+ id: string;
109
+ /** Human-readable label for display. */
110
+ label: string;
111
+ /**
112
+ * The user-visible items the operation changes, usually one. Empty when the operation is internal
113
+ * to its domain. The config comes from the target config item, else the baseline one.
114
+ */
115
+ itemRefs: ItemRef[];
116
+ /**
117
+ * Why the operation exists: `change` when the target config differs from the baseline,
118
+ * `drift` when the target matches the baseline but deployed state does not.
119
+ */
120
+ reason: "change" | "drift";
121
+ } & ({
122
+ kind: "add";
123
+ after: TAfter;
124
+ } | {
125
+ kind: "update";
126
+ before: TBefore;
127
+ after: TAfter;
128
+ } | {
129
+ kind: "remove";
130
+ before: TBefore;
131
+ });
132
+ /**
133
+ * A difference between the installed config (the baseline) and the target config, for one item,
134
+ * classified as the planner classifies an operation with reason `change`. It does not depend on
135
+ * the live state, so an item that is already live still has its change.
136
+ */
137
+ type ResourceChange = {
138
+ /** Identifies the item within its domain plan. Equals `itemRef.key`. */
139
+ key: string;
140
+ /** `add` when only the target declares the item, `remove` when only the baseline does, `update` when both do and the planner would update it. */
141
+ kind: "add" | "update" | "remove";
142
+ /** The item, with the same key and config as the operations that change it. */
143
+ itemRef: ItemRef;
144
+ };
145
+ /** A domain's proposed set of resource operations. */
146
+ type DomainPlan<TBefore = unknown, TAfter = TBefore> = {
147
+ /** Full workflow path of the step this plan belongs to. */
148
+ path: string[];
149
+ /** The operations the domain proposes to apply. */
150
+ operations: ResourceOperation<TBefore, TAfter>[];
151
+ /**
152
+ * The config differences between the baseline and the target, whatever the live state is.
153
+ * Absent in plans stored by older versions.
154
+ */
155
+ changes?: ResourceChange[];
156
+ };
157
+ /** The execution context passed to a step's `apply` handler. */
158
+ type ApplyContext<TStepCtx extends Record<string, unknown> = Record<string, unknown>, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TSnapshotData = unknown> = ExecutionContext<TStepCtx> & {
159
+ /** Identifier of the lifecycle attempt currently executing. */
160
+ attemptId: string;
161
+ /**
162
+ * The last successful state for this domain, or `null` when the domain was
163
+ * absent from the baseline. Mirrors {@link PlanningInput.baseline} so `apply`
164
+ * can converge deployed state without re-deriving it onto the plan.
165
+ */
166
+ baseline: {
167
+ config: TConfig;
168
+ data: TSnapshotData;
169
+ } | null;
170
+ /** The target configuration to converge to, or `null` when none is available. */
171
+ targetConfig: TConfig | null;
172
+ };
173
+ /** Inputs a domain needs to plan its changes: the prior baseline and the target. */
174
+ type PlanningInput<TConfig, TSnapshotData> = {
175
+ /** Full workflow path of the step being planned. */
176
+ path: string[];
177
+ /** The last successful state for this domain, or `null` when the domain was absent. */
178
+ baseline: {
179
+ config: TConfig;
180
+ data: TSnapshotData;
181
+ } | null;
182
+ /** The target configuration to converge to, or `null` when none is available. */
183
+ targetConfig: TConfig | null;
184
+ /**
185
+ * The latest attempt, when it failed after the baseline was saved: its target configuration
186
+ * (`null` when the domain was absent from it) and this domain's plan in it. Absent otherwise.
187
+ */
188
+ failedAttempt?: {
189
+ targetConfig: TConfig | null;
190
+ plan: DomainPlan | null;
191
+ };
192
+ };
193
+ /** The outcome a domain reports after applying its plan. */
194
+ type ApplyResult<TSnapshotData> = {
195
+ /** The snapshot data describing the resulting state, or `null` if none. */
196
+ snapshotData: TSnapshotData | null;
197
+ };
198
+ /** An issue that prevents the plan from running. */
199
+ type BlockingPlanningIssue = PlanningIssue & {
200
+ blocking: true;
201
+ };
202
+ /** An issue reported with a plan that still runs. */
203
+ type NonBlockingPlanningIssue = PlanningIssue & {
204
+ blocking: false;
205
+ };
206
+ /**
207
+ * The outcome of a domain's planning pass, discriminated by `kind`: `planned`
208
+ * carries the executable plan and any issues that do not block it, `blocked`
209
+ * carries the issues preventing one.
210
+ */
211
+ type PlanningResult<TPlan extends DomainPlan = DomainPlan> = {
212
+ kind: "planned";
213
+ plan: TPlan;
214
+ issues?: NonBlockingPlanningIssue[];
215
+ } | {
216
+ kind: "blocked";
217
+ issues: BlockingPlanningIssue[];
218
+ };
219
+ /**
220
+ * The resource-reconciliation behavior a step contributes: planning proposes a
221
+ * domain plan (or reports blocking issues) using a side-effect-free context, and
222
+ * applying executes the plan under an attempt-scoped context.
223
+ */
224
+ type ResourceCapability<TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown>, TPlan extends DomainPlan, TSnapshotData> = {
225
+ plan: (input: PlanningInput<TConfig, TSnapshotData>, context: ValidationExecutionContext<TStepCtx>) => Promise<PlanningResult<TPlan>>;
226
+ apply: (plan: TPlan, context: ApplyContext<TStepCtx, TConfig, TSnapshotData>) => Promise<ApplyResult<TSnapshotData>>;
227
+ };
228
+ /** Schema for validating the Adobe I/O app credentials used across lifecycle workflows. */
229
+ declare const AppDataSchema: v.ObjectSchema<{
230
+ readonly consumerOrgId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
231
+ readonly orgName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
232
+ readonly projectId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
233
+ readonly projectName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
234
+ readonly projectTitle: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
235
+ readonly workspaceId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
236
+ readonly workspaceName: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
237
+ readonly workspaceTitle: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
238
+ }, undefined>;
239
+ /** Type for Adobe I/O app credentials. */
240
+ type AppData = v.InferOutput<typeof AppDataSchema>;
176
241
  /** Shared context available to all steps during a lifecycle workflow. */
177
242
  type LifecycleContext = {
178
243
  /** The `metadata.id` of the app being managed. */
@@ -349,224 +414,118 @@ declare function defineLeafStep<TName extends string, TConfig extends CommerceAp
349
414
  * meta: { install: { label: "Eventing", description: "Sets up I/O Events" } },
350
415
  * isConfigured: hasEventing,
351
416
  * context: async (ctx) => ({ eventsClient: await createEventsClient(ctx) }),
352
- * children: [commerceEventsStep, externalEventsStep],
353
- * });
354
- * ```
355
- */
356
- declare function defineBranchStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, const TChildren extends AnyStep[] = AnyStep[]>(options: BranchStepOptions<TName, TConfig, TStepCtx, TChildren>): {
357
- children: TChildren;
358
- context: StepContextFactory<TStepCtx> | undefined;
359
- isConfigured: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
360
- meta: StepMeta;
361
- name: TName;
362
- type: "branch";
363
- validate: ((config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>) | undefined;
364
- when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
365
- };
366
- /** Infer the output type from a leaf step. */
367
- type InferStepOutput<TStep> = TStep extends LeafStep<infer _TName, infer _TConfig, infer _TStepCtx, infer TOutput> ? Awaited<TOutput> : never;
368
- /** A problem found while planning. Blocking issues prevent the plan from running. */
369
- type PlanningIssue = {
370
- /** The domain that raised the issue. */
371
- domain: string;
372
- /** Machine-readable code identifying the issue type. */
373
- code: string;
374
- /** Human-readable description of the issue. */
375
- message: string;
376
- /** Whether the issue prevents the plan from running. */
377
- blocking: boolean;
378
- /** Severity of the issue. Defaults to `error` when absent. */
379
- severity?: ValidationIssueSeverity;
380
- /** Full workflow path of the step that raised the issue. */
381
- path?: string[];
382
- /** Additional context about the issue. */
383
- details?: Record<string, unknown>;
384
- };
385
- /** The config of a plan item, as declared in the app config. */
386
- type ItemConfig = AdminUiComponentConfig | AppEvent | CustomInstallationStep | WebhookEntry;
387
- /**
388
- * A reference to a user-visible item an operation changes. Within a domain plan, operations with
389
- * the same `key` are parts of one change to one item, for example the metadata and the subscription
390
- * of one event.
391
- */
392
- type ItemRef = {
393
- /** Identifies the item within its domain plan. */
394
- key: string;
395
- /**
396
- * The item's config as declared: the target config item for an add or update,
397
- * the baseline one for a remove. Absent for an item with no config, such as a live-only resource.
398
- * Its `label` and `description` are the item's text. A custom installation step has a `name`
399
- * instead of a `label`.
400
- */
401
- config?: ItemConfig;
402
- };
403
- /**
404
- * A single change a domain proposes to apply to a resource, discriminated by
405
- * `kind`: `add` creates a resource, `update` mutates one, `remove` deletes one.
406
- */
407
- type ResourceOperation<TBefore, TAfter = TBefore> = {
408
- /** Stable identifier of the operation within its plan. */
409
- id: string;
410
- /** Human-readable label for display. */
411
- label: string;
412
- /**
413
- * The user-visible items the operation changes, usually one. Empty when the operation is internal
414
- * to its domain. The config comes from the target config item, else the baseline one.
415
- */
416
- itemRefs: ItemRef[];
417
- /**
418
- * Why the operation exists: `change` when the target config differs from the baseline,
419
- * `drift` when the target matches the baseline but deployed state does not.
420
- */
421
- reason: "change" | "drift";
422
- } & ({
423
- kind: "add";
424
- after: TAfter;
425
- } | {
426
- kind: "update";
427
- before: TBefore;
428
- after: TAfter;
429
- } | {
430
- kind: "remove";
431
- before: TBefore;
432
- });
433
- /**
434
- * A difference between the installed config (the baseline) and the target config, for one item,
435
- * classified as the planner classifies an operation with reason `change`. It does not depend on
436
- * the live state, so an item that is already live still has its change.
417
+ * children: [commerceEventsStep, externalEventsStep],
418
+ * });
419
+ * ```
437
420
  */
438
- type ResourceChange = {
439
- /** Identifies the item within its domain plan. Equals `itemRef.key`. */
421
+ declare function defineBranchStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, const TChildren extends AnyStep[] = AnyStep[]>(options: BranchStepOptions<TName, TConfig, TStepCtx, TChildren>): {
422
+ children: TChildren;
423
+ context: StepContextFactory<TStepCtx> | undefined;
424
+ isConfigured: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
425
+ meta: StepMeta;
426
+ name: TName;
427
+ type: "branch";
428
+ validate: ((config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>) | undefined;
429
+ when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
430
+ };
431
+ /** Infer the output type from a leaf step. */
432
+ type InferStepOutput<TStep> = TStep extends LeafStep<infer _TName, infer _TConfig, infer _TStepCtx, infer TOutput> ? Awaited<TOutput> : never;
433
+ /** Status of a step execution. */
434
+ type ExecutionStatus = "pending" | "in-progress" | "succeeded" | "failed";
435
+ /** A structured error with path to the failing step. */
436
+ type WorkflowError<TPayload = unknown> = {
437
+ /** Path to the step that failed (e.g., ["eventing", "commerce", "providers"]). */
438
+ path: string[];
439
+ /** Error key for easy identification. */
440
440
  key: string;
441
- /** `add` when only the target declares the item, `remove` when only the baseline does, `update` when both do and the planner would update it. */
442
- kind: "add" | "update" | "remove";
443
- /** The item, with the same key and config as the operations that change it. */
444
- itemRef: ItemRef;
441
+ /** Human-readable error message. */
442
+ message?: string;
443
+ /** Additional error payload. */
444
+ payload?: TPayload;
445
445
  };
446
- /** A domain's proposed set of resource operations. */
447
- type DomainPlan<TBefore = unknown, TAfter = TBefore> = {
448
- /** Full workflow path of the step this plan belongs to. */
446
+ /** Status of a step in the workflow tree. */
447
+ type StepStatus = {
448
+ /** Step name (unique among siblings). */
449
+ name: string;
450
+ /** Unique step identifier (e.g., UUID). */
451
+ id: string;
452
+ /** Full path from root to this step. */
449
453
  path: string[];
450
- /** The operations the domain proposes to apply. */
451
- operations: ResourceOperation<TBefore, TAfter>[];
452
- /**
453
- * The config differences between the baseline and the target, whatever the live state is.
454
- * Absent in plans stored by older versions.
455
- */
456
- changes?: ResourceChange[];
454
+ /** Step metadata (for display purposes). */
455
+ meta: StepMetaInfo;
456
+ /** Current execution status. */
457
+ status: ExecutionStatus;
458
+ /** ISO timestamp when the step started executing. */
459
+ startedAt?: string;
460
+ /** ISO timestamp when the step succeeded or failed. */
461
+ completedAt?: string;
462
+ /** Child step statuses (empty for leaf steps). */
463
+ children: StepStatus[];
457
464
  };
458
- /** The execution context passed to a step's `apply` handler. */
459
- type ApplyContext<TStepCtx extends Record<string, unknown> = Record<string, unknown>, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TSnapshotData = unknown> = ExecutionContext<TStepCtx> & {
460
- /** Identifier of the lifecycle attempt currently executing. */
461
- attemptId: string;
462
- /**
463
- * The last successful state for this domain, or `null` when the domain was
464
- * absent from the baseline. Mirrors {@link PlanningInput.baseline} so `apply`
465
- * can converge deployed state without re-deriving it onto the plan.
466
- */
467
- baseline: {
468
- config: TConfig;
469
- data: TSnapshotData;
470
- } | null;
471
- /** The target configuration to converge to, or `null` when none is available. */
472
- targetConfig: TConfig | null;
465
+ /** Data collected during a workflow run as a nested structure following step paths. */
466
+ type WorkflowData = {
467
+ [key: string]: unknown | WorkflowData;
473
468
  };
474
- /** Inputs a domain needs to plan its changes: the prior baseline and the target. */
475
- type PlanningInput<TConfig, TSnapshotData> = {
476
- /** Full workflow path of the step being planned. */
477
- path: string[];
478
- /** The last successful state for this domain, or `null` when the domain was absent. */
479
- baseline: {
480
- config: TConfig;
481
- data: TSnapshotData;
482
- } | null;
483
- /** The target configuration to converge to, or `null` when none is available. */
484
- targetConfig: TConfig | null;
469
+ /** Base properties shared by all workflow run states. */
470
+ type WorkflowRunStateBase = {
471
+ /** Unique workflow run identifier. */
472
+ id: string;
473
+ /** Root step status. */
474
+ step: StepStatus;
475
+ /** Results from executed leaf steps, keyed by path. */
476
+ data: WorkflowData | null;
485
477
  /**
486
- * The latest attempt, when it failed after the baseline was saved: its target configuration
487
- * (`null` when the domain was absent from it) and this domain's plan in it. Absent otherwise.
478
+ * The validated app configuration that drove this workflow. May be
479
+ * undefined on states persisted before this field was introduced.
488
480
  */
489
- failedAttempt?: {
490
- targetConfig: TConfig | null;
491
- plan: DomainPlan | null;
492
- };
481
+ config?: CommerceAppConfigOutputModel;
493
482
  };
494
- /** The outcome a domain reports after applying its plan. */
495
- type ApplyResult<TSnapshotData> = {
496
- /** The snapshot data describing the resulting state, or `null` if none. */
497
- snapshotData: TSnapshotData | null;
483
+ /** Workflow run state when in progress. */
484
+ type InProgressWorkflowState = WorkflowRunStateBase & {
485
+ status: "in-progress";
486
+ /** ISO timestamp when the workflow started. */
487
+ startedAt: string;
498
488
  };
499
- /** An issue that prevents the plan from running. */
500
- type BlockingPlanningIssue = PlanningIssue & {
501
- blocking: true;
489
+ /** Per-run state metadata captured alongside a workflow run's outcome. */
490
+ type WorkflowStateMetadata = {
491
+ /** True when the workflow was attempted more than once. */
492
+ isRetry: boolean;
502
493
  };
503
- /** An issue reported with a plan that still runs. */
504
- type NonBlockingPlanningIssue = PlanningIssue & {
505
- blocking: false;
494
+ /** Workflow run state when completed successfully. */
495
+ type SucceededWorkflowState = WorkflowRunStateBase & {
496
+ status: "succeeded";
497
+ /** ISO timestamp when the workflow started. */
498
+ startedAt: string;
499
+ /** ISO timestamp when the workflow completed. */
500
+ completedAt: string;
501
+ /** Per-run state metadata, present when a retry was attempted. */
502
+ metadata?: WorkflowStateMetadata;
506
503
  };
507
- /**
508
- * The outcome of a domain's planning pass, discriminated by `kind`: `planned`
509
- * carries the executable plan and any issues that do not block it, `blocked`
510
- * carries the issues preventing one.
511
- */
512
- type PlanningResult<TPlan extends DomainPlan = DomainPlan> = {
513
- kind: "planned";
514
- plan: TPlan;
515
- issues?: NonBlockingPlanningIssue[];
516
- } | {
517
- kind: "blocked";
518
- issues: BlockingPlanningIssue[];
504
+ /** Workflow run state when failed. */
505
+ type FailedWorkflowState = WorkflowRunStateBase & {
506
+ status: "failed";
507
+ /** ISO timestamp when the workflow started. */
508
+ startedAt: string;
509
+ /** ISO timestamp when the workflow failed. */
510
+ completedAt: string;
511
+ /** Error information about the failure. */
512
+ error: WorkflowError;
513
+ /** Per-run state metadata, present when a retry was attempted. */
514
+ metadata?: WorkflowStateMetadata;
519
515
  };
520
516
  /**
521
- * The resource-reconciliation behavior a step contributes: planning proposes a
522
- * domain plan (or reports blocking issues) using a side-effect-free context, and
523
- * applying executes the plan under an attempt-scoped context.
517
+ * The full workflow run state (persisted and returned by status endpoints).
518
+ * Discriminated union by `status` field.
524
519
  */
525
- type ResourceCapability<TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown>, TPlan extends DomainPlan, TSnapshotData> = {
526
- plan: (input: PlanningInput<TConfig, TSnapshotData>, context: ValidationExecutionContext<TStepCtx>) => Promise<PlanningResult<TPlan>>;
527
- apply: (plan: TPlan, context: ApplyContext<TStepCtx, TConfig, TSnapshotData>) => Promise<ApplyResult<TSnapshotData>>;
528
- };
529
- /** The kind of lifecycle operation an orchestration run performs. */
530
- type LifecycleOperation = "install" | "upgrade" | "uninstall";
531
- /** A persisted plan spanning every participating domain. */
532
- type LifecyclePlan = {
533
- /** Unique plan identifier. */
534
- id: string;
535
- /** The lifecycle operation this plan performs. */
536
- operation: LifecycleOperation;
537
- /** Version of the action that produced the plan. */
538
- actionVersion: string;
539
- /** The state the plan transitions from, or `null` when nothing is installed. */
540
- source: {
541
- /**
542
- * Identifier of the baseline snapshot, or `null` when the app was installed with only business
543
- * configuration and has no baseline yet. Starting the plan writes one.
544
- */
545
- snapshotId: string | null;
546
- /** App version of the baseline. */
547
- appVersion: string;
548
- } | null;
549
- /** The state the plan transitions to, or `null` when the app ends up with nothing installed. */
550
- target: {
551
- /** App version being transitioned to. */
552
- appVersion: string;
553
- /** Validated configuration used to produce and execute the plan. */
554
- config: CommerceAppConfigOutputModel;
555
- } | null;
556
- /** Per-domain plans that compose the operation. */
557
- domains: DomainPlan[];
558
- /** Issues reported while planning or validating the plan. Blocking ones prevent it from running. */
559
- issues: PlanningIssue[];
560
- /** Identifier of the pending plan this plan replaced, or `null` when none was pending. */
561
- previousPlanId: string | null;
562
- };
563
- /** A captured snapshot of app state: its configuration and collected workflow data. */
564
- type AppStateSnapshot = {
565
- /** ISO timestamp when the captured state became authoritative. */
566
- createdAt: string;
567
- /** Identifier of the attempt that produced the snapshot, or `null` when no attempt did. */
568
- attemptId: string | null;
569
- } & Required<Pick<SucceededWorkflowState, "id" | "config" | "data">>;
520
+ type WorkflowRunState = InProgressWorkflowState | SucceededWorkflowState | FailedWorkflowState;
521
+ /** Type guard for in-progress workflow run state. */
522
+ declare function isInProgressState(state: WorkflowRunState): state is InProgressWorkflowState;
523
+ /** Type guard for succeeded workflow run state. */
524
+ declare function isSucceededState(state: WorkflowRunState): state is SucceededWorkflowState;
525
+ /** Type guard for failed workflow run state. */
526
+ declare function isFailedState(state: WorkflowRunState): state is FailedWorkflowState;
527
+ /** Type guard for completed workflow run state (succeeded or failed). */
528
+ declare function isCompletedState(state: WorkflowRunState): state is SucceededWorkflowState | FailedWorkflowState;
570
529
  /** Hook function that receives an event and the current state. */
571
530
  type HookFunction<TEvent> = (event: TEvent, state: WorkflowRunState) => void | Promise<void>;
572
531
  /** Hook function that only receives the current state. */
@@ -661,6 +620,47 @@ type ValidateStepTreeOptions = {
661
620
  * - Never throws; all errors from validate handlers are caught and reported as issues
662
621
  */
663
622
  declare function validateStepTree(options: ValidateStepTreeOptions): Promise<ValidationResult>;
623
+ /** The kind of lifecycle operation an orchestration run performs. */
624
+ type LifecycleOperation = "install" | "upgrade" | "uninstall";
625
+ /** A persisted plan spanning every participating domain. */
626
+ type LifecyclePlan = {
627
+ /** Unique plan identifier. */
628
+ id: string;
629
+ /** The lifecycle operation this plan performs. */
630
+ operation: LifecycleOperation;
631
+ /** Version of the action that produced the plan. */
632
+ actionVersion: string;
633
+ /** The state the plan transitions from, or `null` when nothing is installed. */
634
+ source: {
635
+ /**
636
+ * Identifier of the baseline snapshot, or `null` when the app was installed with only business
637
+ * configuration and has no baseline yet. Starting the plan writes one.
638
+ */
639
+ snapshotId: string | null;
640
+ /** App version of the baseline. */
641
+ appVersion: string;
642
+ } | null;
643
+ /** The state the plan transitions to, or `null` when the app ends up with nothing installed. */
644
+ target: {
645
+ /** App version being transitioned to. */
646
+ appVersion: string;
647
+ /** Validated configuration used to produce and execute the plan. */
648
+ config: CommerceAppConfigOutputModel;
649
+ } | null;
650
+ /** Per-domain plans that compose the operation. */
651
+ domains: DomainPlan[];
652
+ /** Issues reported while planning or validating the plan. Blocking ones prevent it from running. */
653
+ issues: PlanningIssue[];
654
+ /** Identifier of the pending plan this plan replaced, or `null` when none was pending. */
655
+ previousPlanId: string | null;
656
+ };
657
+ /** A captured snapshot of app state: its configuration and collected workflow data. */
658
+ type AppStateSnapshot = {
659
+ /** ISO timestamp when the captured state became authoritative. */
660
+ createdAt: string;
661
+ /** Identifier of the attempt that produced the snapshot, or `null` when no attempt did. */
662
+ attemptId: string | null;
663
+ } & Required<Pick<SucceededWorkflowState, "id" | "config" | "data">>;
664
664
  /** Options for creating the initial execution state for a lifecycle plan. */
665
665
  type CreateInitialPlanExecutionStateOptions = {
666
666
  rootStep: BranchStep;
@@ -932,4 +932,4 @@ type SucceededInstallationState = SucceededWorkflowState;
932
932
  type FailedInstallationState = FailedWorkflowState;
933
933
  /** @deprecated Use `WorkflowStateMetadata` from `@adobe/aio-commerce-lib-app/management`. */
934
934
  type InstallationRetryMetadata = WorkflowStateMetadata;
935
- export { defineLeafStep as $, createInitialState as A, BranchStepOptions as B, defineCustomInstallationStep as C, executePlannedWorkflow as D, createInitialPlanExecutionState as E, StepStartedEvent as F, LifecycleContext as G, InferStepOutput as H, StepSucceededEvent as I, StepMeta as J, Step as K, WorkflowHooks as L, executeWorkflow as M, StepEvent as N, ValidateStepTreeOptions as O, StepFailedEvent as P, defineBranchStep as Q, AnyStep as R, CustomInstallationStepHandler as S, planWorkflow as T, LeafStep as U, ExecutionContext as V, LeafStepOptions as W, ValidationContext as X, StepMetaInfo as Y, ValidationExecutionContext as Z, createInitialUninstallationState as _, isFailedState as _t, InstallationError as a, ValidationResult as at, runValidation as b, InstallationStatus as c, FailedWorkflowState as ct, CreateInitialUninstallationStateOptions as d, SucceededWorkflowState as dt, isBranchStep as et, InstallationHooks as f, WorkflowData as ft, createInitialInstallationState as g, isCompletedState as gt, RunValidationOptions as h, WorkflowStateMetadata as ht, InstallationData as i, ValidationIssueSeverity as it, executeUninstallWorkflow as j, validateStepTree as k, SucceededInstallationState as l, InProgressWorkflowState as lt, RunUninstallationOptions as m, WorkflowRunState as mt, InProgressInstallationState as n, StepValidationResult as nt, InstallationRetryMetadata as o, ValidationSummary as ot, RunInstallationOptions as p, WorkflowError as pt, StepContextFactory as q, InstallationContext as r, ValidationIssue as rt, InstallationState as s, ExecutionStatus as st, FailedInstallationState as t, isLeafStep as tt, CreateInitialInstallationStateOptions as u, StepStatus as ut, runInstallation as v, isInProgressState as vt, createRetryState as w, CustomInstallationStepDefinition as x, runUninstallation as y, isSucceededState as yt, BranchStep as z };
935
+ export { BranchStepOptions as $, createInitialState as A, InProgressWorkflowState as B, defineCustomInstallationStep as C, executePlannedWorkflow as D, createInitialPlanExecutionState as E, StepStartedEvent as F, WorkflowRunState as G, SucceededWorkflowState as H, StepSucceededEvent as I, isFailedState as J, WorkflowStateMetadata as K, WorkflowHooks as L, executeWorkflow as M, StepEvent as N, ValidateStepTreeOptions as O, StepFailedEvent as P, BranchStep as Q, ExecutionStatus as R, CustomInstallationStepHandler as S, planWorkflow as T, WorkflowData as U, StepStatus as V, WorkflowError as W, isSucceededState as X, isInProgressState as Y, AnyStep as Z, createInitialUninstallationState as _, ValidationIssueSeverity as _t, InstallationError as a, Step as at, runValidation as b, InstallationStatus as c, StepMetaInfo as ct, CreateInitialUninstallationStateOptions as d, defineBranchStep as dt, ExecutionContext as et, InstallationHooks as f, defineLeafStep as ft, createInitialInstallationState as g, ValidationIssue as gt, RunValidationOptions as h, StepValidationResult as ht, InstallationData as i, LifecycleContext as it, executeUninstallWorkflow as j, validateStepTree as k, SucceededInstallationState as l, ValidationContext as lt, RunUninstallationOptions as m, isLeafStep as mt, InProgressInstallationState as n, LeafStep as nt, InstallationRetryMetadata as o, StepContextFactory as ot, RunInstallationOptions as p, isBranchStep as pt, isCompletedState as q, InstallationContext as r, LeafStepOptions as rt, InstallationState as s, StepMeta as st, FailedInstallationState as t, InferStepOutput as tt, CreateInitialInstallationStateOptions as u, ValidationExecutionContext as ut, runInstallation as v, ValidationResult as vt, createRetryState as w, CustomInstallationStepDefinition as x, runUninstallation as y, ValidationSummary as yt, FailedWorkflowState as z };