@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,24 @@
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
+ let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
3
+
4
+ //#region ../../packages-private/scripting-utils/source/error.ts
5
+ /**
6
+ * This module exports shared error utilities for the AIO Commerce SDK.
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Stringify an error to a human-friendly string.
11
+ * @param error - The error to stringify.
12
+ */
13
+ function stringifyError(error) {
14
+ if (error instanceof _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError) return error.display();
15
+ return error instanceof Error ? error.message : String(error);
16
+ }
17
+
18
+ //#endregion
19
+ Object.defineProperty(exports, 'stringifyError', {
20
+ enumerable: true,
21
+ get: function () {
22
+ return stringifyError;
23
+ }
24
+ });
@@ -0,0 +1,243 @@
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
+ let valibot = require("valibot");
3
+ valibot = require_schemas.__toESM(valibot);
4
+
5
+ //#region source/config/schema/eventing.ts
6
+ const MAX_DESCRIPTION_LENGTH$1 = 255;
7
+ const MAX_LABEL_LENGTH = 100;
8
+ const MAX_KEY_LENGTH = 50;
9
+ const MAX_EVENT_NAME_LENGTH = 180;
10
+ /**
11
+ * Regex for Commerce event names that must start with "plugin." or "observer."
12
+ * followed by one or more dot-separated lowercase segments containing letters
13
+ * and underscores only.
14
+ * Examples: "observer.order_placed", "plugin.sales.api.order_management.place"
15
+ */
16
+ const COMMERCE_EVENT_NAME_REGEX = /^(?:plugin|observer)\.[a-z_]+(?:\.[a-z_]+)*$/;
17
+ /**
18
+ * Regex for external event names.
19
+ * Allows word characters (letters, digits, underscore), hyphens, underscores, and dots.
20
+ * Examples: "external_event", "webhook.received", "my-event_123"
21
+ */
22
+ const EXTERNAL_EVENT_NAME_REGEX = /^[\w\-_.]+$/;
23
+ /**
24
+ * Regex for field names according to XSD fieldName pattern.
25
+ * Field name can either contain only [a-zA-Z0-9_\-\.\[\]] or be set to *.
26
+ */
27
+ const FIELD_NAME_REGEX = /^([a-zA-Z0-9_\-.[\]]+|\*)$/;
28
+ /**
29
+ * Schema for Commerce event names.
30
+ * Validates that the event name starts with "plugin." or "observer."
31
+ * followed by one or more dot-separated lowercase segments containing letters
32
+ * and underscores only.
33
+ */
34
+ function commerceEventNameSchema() {
35
+ return valibot.pipe(require_schemas.nonEmptyStringValueSchema("event name"), valibot.regex(COMMERCE_EVENT_NAME_REGEX, "Event name must start with \"plugin.\" or \"observer.\" followed by one or more dot-separated lowercase segments containing letters and underscores only (e.g., \"observer.order_placed\", \"plugin.sales.api.order_management.place\")"), valibot.maxLength(MAX_EVENT_NAME_LENGTH, `The event name must not be longer than ${MAX_EVENT_NAME_LENGTH} characters`));
36
+ }
37
+ /**
38
+ * Schema for external event names.
39
+ * Validates that the event name contains only word characters (letters, digits, underscore),
40
+ * hyphens, underscores, and dots.
41
+ */
42
+ function externalEventNameSchema() {
43
+ return valibot.pipe(require_schemas.nonEmptyStringValueSchema("event name"), valibot.regex(EXTERNAL_EVENT_NAME_REGEX, "Event name must contain only letters, digits, underscores, hyphens, and dots (e.g., \"external_event\", \"webhook.received\", \"my-event_123\")"), valibot.maxLength(MAX_EVENT_NAME_LENGTH, `The event name must not be longer than ${MAX_EVENT_NAME_LENGTH} characters`));
44
+ }
45
+ /**
46
+ * Schema for field names.
47
+ * Validates that the field name matches the XSD fieldName pattern:
48
+ * can either contain only [a-zA-Z0-9_\-\.\[\]] or be set to *.
49
+ */
50
+ function fieldNameSchema() {
51
+ return valibot.pipe(require_schemas.nonEmptyStringValueSchema("field name"), valibot.regex(FIELD_NAME_REGEX, "Field name must contain only letters (a-z, A-Z), numbers (0-9), underscores (_), dashes (-), dots (.), and square brackets ([, ]), or be exactly \"*\""));
52
+ }
53
+ /**
54
+ * Schema for field objects in Commerce events.
55
+ * Each field has a required name and an optional source.
56
+ */
57
+ function commerceEventFieldSchema() {
58
+ return valibot.object({
59
+ name: fieldNameSchema(),
60
+ source: valibot.optional(require_schemas.stringValueSchema("field source"))
61
+ });
62
+ }
63
+ /** Schema for event provider configuration */
64
+ const ProviderSchema = valibot.object({
65
+ label: valibot.pipe(require_schemas.nonEmptyStringValueSchema("provider label"), valibot.maxLength(MAX_LABEL_LENGTH, `The provider label must not be longer than ${MAX_LABEL_LENGTH} characters`)),
66
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("provider description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH$1, `The provider description must not be longer than ${MAX_DESCRIPTION_LENGTH$1} characters`)),
67
+ key: valibot.optional(valibot.pipe(require_schemas.alphaNumericOrHyphenSchema("provider key"), valibot.maxLength(MAX_KEY_LENGTH, `The provider key must not be longer than ${MAX_KEY_LENGTH} characters`)))
68
+ });
69
+ /** Schema for base shared properties between event types. */
70
+ const BaseEventSchema = valibot.object({
71
+ label: valibot.pipe(require_schemas.nonEmptyStringValueSchema("event label"), valibot.maxLength(MAX_LABEL_LENGTH, `The event label must not be longer than ${MAX_LABEL_LENGTH} characters`)),
72
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("event description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH$1, `The event description must not be longer than ${MAX_DESCRIPTION_LENGTH$1} characters`)),
73
+ runtimeActions: valibot.array(valibot.pipe(require_schemas.nonEmptyStringValueSchema("runtime action"), valibot.regex(/^[a-z0-9-]+\/[a-z0-9-]+$/i, "Runtime action must be in the format \"<package>/<action>\" (e.g., \"my-package/my-action\")")), "Expected an array of runtime actions in the format <package>/<action>")
74
+ });
75
+ /**
76
+ * Schema for rule operator values.
77
+ * Valid operators for Commerce event filtering rules.
78
+ */
79
+ const OPERATORS = [
80
+ "greaterThan",
81
+ "lessThan",
82
+ "equal",
83
+ "regex",
84
+ "in",
85
+ "onChange"
86
+ ];
87
+ const ruleOperatorSchema = valibot.union(OPERATORS.map((op) => valibot.literal(op)), `Operator must be one of: ${OPERATORS.join(", ")}`);
88
+ /** Schema for Commerce event rule configuration */
89
+ const CommerceEventRuleSchema = valibot.object({
90
+ field: require_schemas.nonEmptyStringValueSchema("rule field"),
91
+ operator: ruleOperatorSchema,
92
+ value: require_schemas.nonEmptyStringValueSchema("rule value")
93
+ });
94
+ /** Schema for Commerce event configuration */
95
+ const CommerceEventSchema = valibot.object({
96
+ ...BaseEventSchema.entries,
97
+ name: commerceEventNameSchema(),
98
+ fields: valibot.array(commerceEventFieldSchema(), "Expected an array of event field objects with a 'name' property"),
99
+ rules: valibot.optional(valibot.array(CommerceEventRuleSchema, "Expected an array of event rules with field, operator, and value")),
100
+ destination: valibot.optional(require_schemas.nonEmptyStringValueSchema("destination")),
101
+ hipaa_audit_required: valibot.optional(require_schemas.booleanValueSchema("hipaa_audit_required")),
102
+ priority: valibot.optional(require_schemas.booleanValueSchema("priority")),
103
+ force: valibot.optional(require_schemas.booleanValueSchema("force"))
104
+ });
105
+ /** Schema for external event configuration */
106
+ const ExternalEventSchema = valibot.object({
107
+ ...BaseEventSchema.entries,
108
+ name: externalEventNameSchema()
109
+ });
110
+ /** Schema for Commerce event source configuration */
111
+ const CommerceEventSourceSchema = valibot.object({
112
+ provider: ProviderSchema,
113
+ events: valibot.array(CommerceEventSchema, "Expected an array of Commerce events")
114
+ });
115
+ /** Schema for external event source configuration */
116
+ const ExternalEventSourceSchema = valibot.object({
117
+ provider: ProviderSchema,
118
+ events: valibot.array(ExternalEventSchema, "Expected an array of external events")
119
+ });
120
+ /** Schema for eventing configuration with separate commerce and external arrays */
121
+ const EventingSchema = valibot.object({
122
+ commerce: valibot.optional(valibot.array(CommerceEventSourceSchema, "Expected an array of Commerce event sources")),
123
+ external: valibot.optional(valibot.array(ExternalEventSourceSchema, "Expected an array of external event sources"))
124
+ });
125
+ /**
126
+ * Check if config has commerce event sources.
127
+ * @param config - The configuration to check.
128
+ */
129
+ function hasCommerceEvents(config) {
130
+ return Array.isArray(config?.eventing?.commerce) && config.eventing.commerce.length > 0;
131
+ }
132
+ /**
133
+ * Check if config has external event sources.
134
+ * @param config - The configuration to check.
135
+ */
136
+ function hasExternalEvents(config) {
137
+ return Array.isArray(config?.eventing?.external) && config.eventing.external.length > 0;
138
+ }
139
+ /**
140
+ * Check if config has any eventing configuration.
141
+ * @param config - The configuration to check.
142
+ */
143
+ function hasEventing(config) {
144
+ return config.eventing !== void 0;
145
+ }
146
+
147
+ //#endregion
148
+ //#region source/config/schema/installation.ts
149
+ const MAX_DESCRIPTION_LENGTH = 255;
150
+ const MAX_NAME_LENGTH = 255;
151
+ const MAX_MESSAGE_LENGTH = 1e3;
152
+ /**
153
+ * Regex for script paths that can be relative or absolute.
154
+ * Must end with .js extension
155
+ * Examples:
156
+ * - "./scripts/setup.js"
157
+ * - "./setup.js"
158
+ * - "../../scripts/setup.js"
159
+ */
160
+ const SCRIPT_PATH_REGEX = /^(?:\.{0,2}\/)*[\w-/]*[\w-]+\.js$/;
161
+ /**
162
+ * Schema for custom installation step configuration
163
+ */
164
+ const CustomInstallationStepSchema = valibot.object({
165
+ script: valibot.pipe(require_schemas.nonEmptyStringValueSchema("script path"), valibot.regex(SCRIPT_PATH_REGEX, "Script path must end with .js (e.g., \"./setup.js\", \"./scripts/setup.js\", or \"../../scripts/setup.js\")")),
166
+ name: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step name"), valibot.maxLength(MAX_NAME_LENGTH, `The step name must not be longer than ${MAX_NAME_LENGTH} characters`)),
167
+ description: valibot.pipe(require_schemas.nonEmptyStringValueSchema("step description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The step description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`))
168
+ });
169
+ /**
170
+ * Schema for installation messages configuration
171
+ */
172
+ const MessagesSchema = valibot.object({
173
+ preInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("preInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The preInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`))),
174
+ postInstallation: valibot.optional(valibot.pipe(require_schemas.nonEmptyStringValueSchema("postInstallation message"), valibot.maxLength(MAX_MESSAGE_LENGTH, `The postInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`)))
175
+ });
176
+ /**
177
+ * Schema for installation configuration
178
+ */
179
+ const InstallationSchema = valibot.object({
180
+ messages: valibot.optional(MessagesSchema),
181
+ customInstallationSteps: valibot.pipe(valibot.optional(valibot.array(CustomInstallationStepSchema, "Expected an array of custom installation steps")), valibot.check((input) => {
182
+ const steps = input || [];
183
+ return new Set(steps.map((step) => step.name)).size === steps.length;
184
+ }, "Duplicate step names detected in custom installation steps. Each step must have a unique name."))
185
+ });
186
+ /**
187
+ * Check if config has custom installation settings.
188
+ * @param config - The configuration to check.
189
+ */
190
+ function hasCustomInstallation(config) {
191
+ return config.installation !== void 0;
192
+ }
193
+ /**
194
+ * Check if config has custom installation steps.
195
+ * @param config - The configuration to check.
196
+ */
197
+ function hasCustomInstallationSteps(config) {
198
+ return Array.isArray(config?.installation?.customInstallationSteps) && config.installation.customInstallationSteps.length > 0;
199
+ }
200
+
201
+ //#endregion
202
+ Object.defineProperty(exports, 'EventingSchema', {
203
+ enumerable: true,
204
+ get: function () {
205
+ return EventingSchema;
206
+ }
207
+ });
208
+ Object.defineProperty(exports, 'InstallationSchema', {
209
+ enumerable: true,
210
+ get: function () {
211
+ return InstallationSchema;
212
+ }
213
+ });
214
+ Object.defineProperty(exports, 'hasCommerceEvents', {
215
+ enumerable: true,
216
+ get: function () {
217
+ return hasCommerceEvents;
218
+ }
219
+ });
220
+ Object.defineProperty(exports, 'hasCustomInstallation', {
221
+ enumerable: true,
222
+ get: function () {
223
+ return hasCustomInstallation;
224
+ }
225
+ });
226
+ Object.defineProperty(exports, 'hasCustomInstallationSteps', {
227
+ enumerable: true,
228
+ get: function () {
229
+ return hasCustomInstallationSteps;
230
+ }
231
+ });
232
+ Object.defineProperty(exports, 'hasEventing', {
233
+ enumerable: true,
234
+ get: function () {
235
+ return hasEventing;
236
+ }
237
+ });
238
+ Object.defineProperty(exports, 'hasExternalEvents', {
239
+ enumerable: true,
240
+ get: function () {
241
+ return hasExternalEvents;
242
+ }
243
+ });
@@ -1,6 +1,6 @@
1
- const require_error = require('./error-Byj1DVHZ.cjs');
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
2
  let util = require("util");
3
- util = require_error.__toESM(util);
3
+ util = require_schemas.__toESM(util);
4
4
 
5
5
  //#region ../../packages-private/common-utils/source/logging.ts
6
6
  /**
@@ -1,9 +1,10 @@
1
- const require_management = require('../management-Dm5h0E6l.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runner = require('../runner-NHMvoMO2.cjs');
2
3
 
3
- exports.createInitialInstallationState = require_management.createInitialInstallationState;
4
- exports.defineCustomInstallationStep = require_management.defineCustomInstallationStep;
5
- exports.isCompletedState = require_management.isCompletedState;
6
- exports.isFailedState = require_management.isFailedState;
7
- exports.isInProgressState = require_management.isInProgressState;
8
- exports.isSucceededState = require_management.isSucceededState;
9
- exports.runInstallation = require_management.runInstallation;
4
+ exports.createInitialInstallationState = require_runner.createInitialInstallationState;
5
+ exports.defineCustomInstallationStep = require_runner.defineCustomInstallationStep;
6
+ exports.isCompletedState = require_runner.isCompletedState;
7
+ exports.isFailedState = require_runner.isFailedState;
8
+ exports.isInProgressState = require_runner.isInProgressState;
9
+ exports.isSucceededState = require_runner.isSucceededState;
10
+ exports.runInstallation = require_runner.runInstallation;
@@ -1,2 +1,2 @@
1
- import { A as BranchStep, B as defineBranchStep, C as StepStatus, D as isInProgressState, E as isFailedState, F as LeafStep, H as isBranchStep, I as LeafStepOptions, L as Step, M as ExecutionContext, N as InferStepOutput, O as isSucceededState, P as InstallationContext, R as StepContextFactory, S as InstallationStatus, T as isCompletedState, U as isLeafStep, V as defineLeafStep, _ as FailedInstallationState, a as CustomInstallationStepHandler, b as InstallationError, c as ExecuteWorkflowOptions, d as InstallationHooks, f as StepEvent, g as ExecutionStatus, h as StepSucceededEvent, i as runInstallation, j as BranchStepOptions, k as AnyStep, l as createInitialState, m as StepStartedEvent, n as RunInstallationOptions, o as defineCustomInstallationStep, p as StepFailedEvent, r as createInitialInstallationState, s as CreateInitialStateOptions, t as CreateInitialInstallationStateOptions, u as executeWorkflow, v as InProgressInstallationState, w as SucceededInstallationState, x as InstallationState, y as InstallationData, z as StepMeta } from "../index-C5SutkJQ.cjs";
2
- export { AnyStep, BranchStep, BranchStepOptions, CreateInitialInstallationStateOptions, CreateInitialStateOptions, CustomInstallationStepHandler, ExecuteWorkflowOptions, ExecutionContext, ExecutionStatus, FailedInstallationState, InProgressInstallationState, InferStepOutput, InstallationContext, InstallationData, InstallationError, InstallationHooks, InstallationState, InstallationStatus, LeafStep, LeafStepOptions, RunInstallationOptions, Step, StepContextFactory, StepEvent, StepFailedEvent, StepMeta, StepStartedEvent, StepStatus, StepSucceededEvent, SucceededInstallationState, createInitialInstallationState, createInitialState, defineBranchStep, defineCustomInstallationStep, defineLeafStep, executeWorkflow, isBranchStep, isCompletedState, isFailedState, isInProgressState, isLeafStep, isSucceededState, runInstallation };
1
+ import { A as BranchStep, B as defineBranchStep, C as StepStatus, D as isInProgressState, E as isFailedState, F as LeafStep, H as isBranchStep, I as LeafStepOptions, L as Step, M as ExecutionContext, N as InferStepOutput, O as isSucceededState, P as InstallationContext, R as StepContextFactory, S as InstallationStatus, T as isCompletedState, U as isLeafStep, V as defineLeafStep, _ as FailedInstallationState, a as CustomInstallationStepHandler, b as InstallationError, c as ExecuteWorkflowOptions, d as InstallationHooks, f as StepEvent, g as ExecutionStatus, h as StepSucceededEvent, i as runInstallation, j as BranchStepOptions, k as AnyStep, l as createInitialState, m as StepStartedEvent, n as RunInstallationOptions, o as defineCustomInstallationStep, p as StepFailedEvent, r as createInitialInstallationState, s as CreateInitialStateOptions, t as CreateInitialInstallationStateOptions, u as executeWorkflow, v as InProgressInstallationState, w as SucceededInstallationState, x as InstallationState, y as InstallationData, z as StepMeta } from "../runner-DemKouFJ.cjs";
2
+ export { AnyStep, BranchStep, BranchStepOptions, type CreateInitialInstallationStateOptions, CreateInitialStateOptions, type CustomInstallationStepHandler, ExecuteWorkflowOptions, ExecutionContext, ExecutionStatus, FailedInstallationState, InProgressInstallationState, InferStepOutput, InstallationContext, InstallationData, InstallationError, InstallationHooks, InstallationState, InstallationStatus, LeafStep, LeafStepOptions, type RunInstallationOptions, Step, StepContextFactory, StepEvent, StepFailedEvent, StepMeta, StepStartedEvent, StepStatus, StepSucceededEvent, SucceededInstallationState, createInitialInstallationState, createInitialState, defineBranchStep, defineCustomInstallationStep, defineLeafStep, executeWorkflow, isBranchStep, isCompletedState, isFailedState, isInProgressState, isLeafStep, isSucceededState, runInstallation };
@@ -0,0 +1,267 @@
1
+ const require_schemas = require('./schemas-CZ6c8Id9.cjs');
2
+ const require_validate = require('./validate-Btzn9ilZ.cjs');
3
+ const require_error = require('./error-DJ2UAPH2.cjs');
4
+ let path = require("path");
5
+ let fs = require("fs");
6
+ let fs_promises = require("fs/promises");
7
+ let jiti = require("jiti");
8
+
9
+ //#region source/config/lib/define.ts
10
+ /**
11
+ * Helper to type-safely define the app config.
12
+ * @param config - The app config to define.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { defineConfig } from "@adobe/aio-commerce-lib-app";
17
+ *
18
+ * // In app.commerce.config.js
19
+ * export default defineConfig({
20
+ * // You get autocompletion and type-safety for the config object.
21
+ * businessConfig: { ... }
22
+ * });
23
+ */
24
+ function defineConfig(config) {
25
+ return config;
26
+ }
27
+
28
+ //#endregion
29
+ //#region ../../packages-private/scripting-utils/source/project.ts
30
+ /**
31
+ * This module exports shared project utilities for the AIO Commerce SDK.
32
+ * @packageDocumentation
33
+ */
34
+ /**
35
+ * Find a file by walking up parent directories
36
+ * @param name - The file name to search for (or array of file names)
37
+ * @param options - Search options
38
+ * @returns The path to the file, or undefined if not found
39
+ */
40
+ async function findUp(name, options = {}) {
41
+ const names = Array.isArray(name) ? name : [name];
42
+ const cwd = options.cwd || process.cwd();
43
+ const { root } = (0, path.parse)(cwd);
44
+ const stopAt = options.stopAt || root;
45
+ let currentDir = cwd;
46
+ while (true) {
47
+ for (const fileName of names) {
48
+ const filePath = (0, path.join)(currentDir, fileName);
49
+ try {
50
+ await (0, fs_promises.access)(filePath);
51
+ return filePath;
52
+ } catch {}
53
+ }
54
+ if (currentDir === stopAt || currentDir === root) return;
55
+ currentDir = (0, path.dirname)(currentDir);
56
+ }
57
+ }
58
+ /**
59
+ * Find the nearest package.json file in the current working directory or its parents
60
+ * @param cwd The current working directory
61
+ */
62
+ async function findNearestPackageJson(cwd = process.cwd()) {
63
+ const packageJsonPath = await findUp("package.json", { cwd });
64
+ if (!packageJsonPath) return null;
65
+ return packageJsonPath;
66
+ }
67
+ /**
68
+ * Read the package.json file
69
+ * @param cwd The current working directory
70
+ */
71
+ async function readPackageJson(cwd = process.cwd()) {
72
+ const packageJsonPath = await findNearestPackageJson(cwd);
73
+ if (!packageJsonPath) return null;
74
+ return JSON.parse(await (0, fs_promises.readFile)(packageJsonPath, "utf-8"));
75
+ }
76
+ /**
77
+ * Check if the current working directory is an ESM project.
78
+ * @param cwd The current working directory
79
+ */
80
+ async function isESM(cwd = process.cwd()) {
81
+ const packageJson = await readPackageJson(cwd);
82
+ if (!packageJson) throw new Error("Could not find a `package.json` file in the current working directory or its parents.");
83
+ return packageJson.type === "module";
84
+ }
85
+ /**
86
+ * Get the root directory of the project
87
+ * @param cwd The current working directory
88
+ */
89
+ async function getProjectRootDirectory(cwd = process.cwd()) {
90
+ const packageJsonPath = await findNearestPackageJson(cwd);
91
+ if (!packageJsonPath) throw new Error("Could not find a the root directory of the project. `package.json` file not found.");
92
+ return (0, path.dirname)(packageJsonPath);
93
+ }
94
+ /**
95
+ * Create the output directory for the given file or folder (relative to the project root)
96
+ * @param fileOrFolder - The file or folder to create
97
+ */
98
+ async function makeOutputDirFor(fileOrFolder) {
99
+ const outputDir = (0, path.join)(await getProjectRootDirectory(), fileOrFolder);
100
+ if (!(0, fs.existsSync)(outputDir)) await (0, fs_promises.mkdir)(outputDir, { recursive: true });
101
+ return outputDir;
102
+ }
103
+ /** Detect the package manager by checking for lock files */
104
+ async function detectPackageManager(cwd = process.cwd()) {
105
+ const rootDirectory = await getProjectRootDirectory(cwd);
106
+ const lockFileMap = {
107
+ "bun.lockb": "bun",
108
+ "pnpm-lock.yaml": "pnpm",
109
+ "yarn.lock": "yarn",
110
+ "package-lock.json": "npm"
111
+ };
112
+ const lockFileName = Object.keys(lockFileMap).find((name) => (0, fs.existsSync)((0, path.join)(rootDirectory, name)));
113
+ if (!lockFileName) return "npm";
114
+ return lockFileMap[lockFileName];
115
+ }
116
+ /** Get the appropriate exec command based on package manager */
117
+ function getExecCommand(packageManager) {
118
+ return {
119
+ pnpm: "pnpx",
120
+ yarn: "yarn dlx",
121
+ bun: "bunx",
122
+ npm: "npx"
123
+ }[packageManager];
124
+ }
125
+
126
+ //#endregion
127
+ //#region source/config/lib/parser.ts
128
+ const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href);
129
+ const configPaths = Object.freeze([
130
+ "app.commerce.config.js",
131
+ "app.commerce.config.ts",
132
+ "app.commerce.config.cjs",
133
+ "app.commerce.config.mjs",
134
+ "app.commerce.config.mts",
135
+ "app.commerce.config.cts"
136
+ ]);
137
+ /**
138
+ * Try to find (up to the nearest package.json file) the app config file.
139
+ *
140
+ * Searches for config files in the following order of priority:
141
+ * 1. `app.commerce.config.js` - JavaScript (CommonJS or ESM)
142
+ * 2. `app.commerce.config.ts` - TypeScript
143
+ * 3. `app.commerce.config.cjs` - CommonJS
144
+ * 4. `app.commerce.config.mjs` - ES Module
145
+ * 5. `app.commerce.config.mts` - ES Module TypeScript
146
+ * 6. `app.commerce.config.cts` - CommonJS TypeScript
147
+ *
148
+ * @param cwd The current working directory
149
+ * @returns The path to the config file, or null if not found
150
+ */
151
+ async function resolveCommerceAppConfig(cwd = process.cwd()) {
152
+ const packageJsonPath = await findNearestPackageJson(cwd);
153
+ if (!packageJsonPath) return null;
154
+ const rootDirectory = (0, path.dirname)(packageJsonPath);
155
+ for (const configPath of configPaths) {
156
+ const configFilePath = await findUp(configPath, {
157
+ cwd,
158
+ stopAt: rootDirectory
159
+ });
160
+ if (configFilePath) return configFilePath;
161
+ }
162
+ return null;
163
+ }
164
+ /**
165
+ * Read the commerce app config file as-is, without validating it.
166
+ *
167
+ * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
168
+ * The config file must export a default export with the configuration object.
169
+ *
170
+ * @param cwd The current working directory
171
+ * @returns The raw config object from the file
172
+ * @throws {Error} If no config file is found or if the file doesn't export a default export
173
+ */
174
+ async function readCommerceAppConfig(cwd = process.cwd()) {
175
+ const configFilePath = await resolveCommerceAppConfig(cwd);
176
+ if (!configFilePath) throw new Error("Could not find a commerce app config file in the current working directory or its parents.");
177
+ let config = null;
178
+ try {
179
+ config = await jiti$1.import(configFilePath);
180
+ } catch (error) {
181
+ const message = require_error.stringifyError(error);
182
+ throw new Error(`Failed to read commerce app config file at ${configFilePath}: ${message}`, { cause: error });
183
+ }
184
+ if (!(config && "default" in config) || config.default === void 0 || config.default === null || typeof config.default === "object" && Object.keys(config.default).length === 0) throw new Error("Commerce app config file does not export a default export. Make sure you use `export default` or `module.exports = { /* your config */ }`");
185
+ return config.default;
186
+ }
187
+ /**
188
+ * Read the commerce app config file and parse its contents into its schema.
189
+ *
190
+ * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
191
+ * The config file must export a default export with the configuration object.
192
+ *
193
+ * @param cwd The current working directory
194
+ * @returns The validated and parsed config object
195
+ * @throws {Error} If no config file is found, if the file doesn't export a default export, or if validation fails
196
+ */
197
+ async function parseCommerceAppConfig(cwd = process.cwd()) {
198
+ return require_validate.validateCommerceAppConfig(await readCommerceAppConfig(cwd));
199
+ }
200
+
201
+ //#endregion
202
+ Object.defineProperty(exports, 'defineConfig', {
203
+ enumerable: true,
204
+ get: function () {
205
+ return defineConfig;
206
+ }
207
+ });
208
+ Object.defineProperty(exports, 'detectPackageManager', {
209
+ enumerable: true,
210
+ get: function () {
211
+ return detectPackageManager;
212
+ }
213
+ });
214
+ Object.defineProperty(exports, 'findNearestPackageJson', {
215
+ enumerable: true,
216
+ get: function () {
217
+ return findNearestPackageJson;
218
+ }
219
+ });
220
+ Object.defineProperty(exports, 'getExecCommand', {
221
+ enumerable: true,
222
+ get: function () {
223
+ return getExecCommand;
224
+ }
225
+ });
226
+ Object.defineProperty(exports, 'getProjectRootDirectory', {
227
+ enumerable: true,
228
+ get: function () {
229
+ return getProjectRootDirectory;
230
+ }
231
+ });
232
+ Object.defineProperty(exports, 'isESM', {
233
+ enumerable: true,
234
+ get: function () {
235
+ return isESM;
236
+ }
237
+ });
238
+ Object.defineProperty(exports, 'makeOutputDirFor', {
239
+ enumerable: true,
240
+ get: function () {
241
+ return makeOutputDirFor;
242
+ }
243
+ });
244
+ Object.defineProperty(exports, 'parseCommerceAppConfig', {
245
+ enumerable: true,
246
+ get: function () {
247
+ return parseCommerceAppConfig;
248
+ }
249
+ });
250
+ Object.defineProperty(exports, 'readCommerceAppConfig', {
251
+ enumerable: true,
252
+ get: function () {
253
+ return readCommerceAppConfig;
254
+ }
255
+ });
256
+ Object.defineProperty(exports, 'readPackageJson', {
257
+ enumerable: true,
258
+ get: function () {
259
+ return readPackageJson;
260
+ }
261
+ });
262
+ Object.defineProperty(exports, 'resolveCommerceAppConfig', {
263
+ enumerable: true,
264
+ get: function () {
265
+ return resolveCommerceAppConfig;
266
+ }
267
+ });