@adobe/aio-commerce-lib-app 0.3.2 → 1.0.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +33 -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/cjs/{app-Dx0ca6oL.d.cts → app-PTKvEBea.d.cts} +6 -6
  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 +32 -332
  20. package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
  21. package/dist/cjs/installation-nwF2RC7F.cjs +241 -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-DIchX9SL.cjs +267 -0
  26. package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
  27. package/dist/cjs/{management-Dm5h0E6l.cjs → runner-CUJ8RHzY.cjs} +24 -30
  28. package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-Ds2m27Q4.d.cts} +49 -95
  29. package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
  30. package/dist/cjs/validate-BegMfe-i.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/es/{app-Cx1-6dn0.d.mts → app-vKXaAr6f.d.mts} +6 -6
  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 +32 -332
  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-SWIwhpKT.mjs} +72 -124
  49. package/dist/es/management/index.d.mts +2 -3
  50. package/dist/es/management/index.mjs +1 -1
  51. package/dist/es/parser-CKQyrTB7.mjs +201 -0
  52. package/dist/es/router-CJ4VWoCt.mjs +404 -0
  53. package/dist/es/{management-Y7pwEbNI.mjs → runner-DB2tDBQS.mjs} +17 -24
  54. package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-Uk7263hG.d.mts} +49 -95
  55. package/dist/es/schemas-B8yIv0_b.mjs +41 -0
  56. package/dist/es/validate-DXI6gwZ2.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
@@ -1,457 +0,0 @@
1
- import { a as hasExternalEvents, c as hasCustomInstallationSteps, l as alphaNumericOrHyphenSchema, n as EventingSchema, o as InstallationSchema, r as hasCommerceEvents, s as hasCustomInstallation, t as stringifyError } from "./error-P7JgUTds.mjs";
2
- import * as v from "valibot";
3
- import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
4
- import { dirname, join, parse } from "path";
5
- import { existsSync } from "fs";
6
- import { access, mkdir, readFile } from "fs/promises";
7
- import { createJiti } from "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 } = parse(cwd);
44
- const stopAt = options.stopAt || root;
45
- let currentDir = cwd;
46
- while (true) {
47
- for (const fileName of names) {
48
- const filePath = join(currentDir, fileName);
49
- try {
50
- await access(filePath);
51
- return filePath;
52
- } catch {}
53
- }
54
- if (currentDir === stopAt || currentDir === root) return;
55
- currentDir = 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 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 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 = join(await getProjectRootDirectory(), fileOrFolder);
100
- if (!existsSync(outputDir)) await 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) => existsSync(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/schema/business-configuration.ts
128
- /** Base schema for configuration field options with name, optional label, and optional description */
129
- const BaseOptionSchema = v.object({
130
- name: v.pipe(v.string("Expected a string for the field name"), v.nonEmpty("The field name must not be empty")),
131
- label: v.optional(v.string("Expected a string for the field label")),
132
- description: v.optional(v.string("Expected a string for the field description"))
133
- });
134
- /** Schema for a single option in a list field, containing a display label and a value */
135
- const ListOptionSchema = v.object({
136
- label: v.string("Expected a string for the option label"),
137
- value: v.string("Expected a string for the option value")
138
- });
139
- /** Schema for a list field that allows single selection from a list of options */
140
- const SingleListSchema = v.object({
141
- ...BaseOptionSchema.entries,
142
- type: v.literal("list", "Expected the type to be 'list'"),
143
- selectionMode: v.literal("single", "Expected the selectionMode to be 'single'"),
144
- options: v.array(ListOptionSchema, "Expected an array of list options"),
145
- default: v.pipe(v.string("Expected a string for the default value"), v.nonEmpty("The default value must not be empty"))
146
- });
147
- /** Schema for a list field that allows multiple selections from a list of options */
148
- const MultipleListSchema = v.object({
149
- ...BaseOptionSchema.entries,
150
- type: v.literal("list", "Expected the type to be 'list'"),
151
- selectionMode: v.literal("multiple", "Expected the selectionMode to be 'multiple'"),
152
- options: v.array(ListOptionSchema, "Expected an array of list options"),
153
- default: v.optional(v.array(v.pipe(v.string("Expected a string for each default value"), v.nonEmpty("Each default value must not be empty")), "Expected an array of default values"), [])
154
- });
155
- /** Schema for list fields supporting either single or multiple selection modes */
156
- const ListSchema = v.variant("selectionMode", [SingleListSchema, MultipleListSchema]);
157
- /** Schema for a text input field that accepts string values */
158
- const TextSchema = v.object({
159
- ...BaseOptionSchema.entries,
160
- type: v.literal("text", "Expected the type to be 'text'"),
161
- default: v.optional(v.string("Expected a string for the default value"))
162
- });
163
- /** Schema for a password input field that accepts string values (typically masked in UI) */
164
- const PasswordSchema = v.object({
165
- ...BaseOptionSchema.entries,
166
- type: v.literal("password", "Expected the type to be 'password'"),
167
- default: v.optional(v.string("Expected a string for the default value"))
168
- });
169
- /** Schema for a boolean field that accepts true or false values */
170
- /** Schema for a number input field that accepts numeric values */
171
- /** Schema for a date input field that accepts date values */
172
- /** Schema for an email input field that accepts and validates email addresses */
173
- const EmailSchema = v.object({
174
- ...BaseOptionSchema.entries,
175
- type: v.literal("email", "Expected the type to be 'email'"),
176
- default: v.optional(v.pipe(v.string("Expected a string for the default email value"), v.email("The email must be a valid email address")))
177
- });
178
- /** Schema for a URL input field that accepts and validates URL strings */
179
- const UrlSchema = v.object({
180
- ...BaseOptionSchema.entries,
181
- type: v.literal("url", "Expected the type to be 'url'"),
182
- default: v.optional(v.pipe(v.string("Expected a string for the default URL value"), v.url("The URL must be a valid URL")))
183
- });
184
- /** Schema for a phone number input field that accepts and validates telephone numbers */
185
- const PhoneSchema = v.object({
186
- ...BaseOptionSchema.entries,
187
- type: v.literal("tel", "Expected the type to be 'tel'"),
188
- default: v.optional(v.pipe(v.string("Expected a string for the default phone number value"), v.regex(/^\+?[0-9\s\-()]+$/, "The phone number must contain only numbers and/or country codes")))
189
- });
190
- /** Schema for a configuration field that can be one of various field types (list, text, password, email, url, or phone) */
191
- const FieldSchema = v.variant("type", [
192
- ListSchema,
193
- TextSchema,
194
- PasswordSchema,
195
- EmailSchema,
196
- UrlSchema,
197
- PhoneSchema
198
- ]);
199
- /** Schema for the schema of the business configuration, which is an array of configuration fields with at least one field required */
200
- const SchemaBusinessConfigSchema = v.pipe(v.array(FieldSchema, "Expected an array of configuration fields"), v.minLength(1, "At least one configuration parameter is required"));
201
- /** The schema used to validate the `businessConfig` settings in the app config file. */
202
- const SchemaBusinessConfig = v.object({ schema: v.optional(SchemaBusinessConfigSchema, []) });
203
- /**
204
- * Check if config has business config.
205
- * @param config - The configuration to check.
206
- */
207
- function hasBusinessConfig(config) {
208
- return config.businessConfig !== void 0;
209
- }
210
- /**
211
- * Check if config has business config schema.
212
- * @param config - The configuration to check.
213
- */
214
- function hasBusinessConfigSchema(config) {
215
- return config.businessConfig?.schema !== void 0 && config.businessConfig.schema.length > 0;
216
- }
217
-
218
- //#endregion
219
- //#region source/config/schema/metadata.ts
220
- const MAX_DESCRIPTION_LENGTH = 255;
221
- const MAX_DISPLAY_NAME_LENGTH = 50;
222
- const NUMERIC_IDENTIFIER = "(0|[1-9]\\d*)";
223
- const SEMVER_REGEX = /* @__PURE__ */ new RegExp(`^${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}$`);
224
- function nonEmptyString(fieldName) {
225
- return v.pipe(v.string(`Expected a string for the ${fieldName}`), v.nonEmpty(`The ${fieldName} must not be empty`));
226
- }
227
- /** The schema for the metadata of the application. */
228
- const MetadataSchema = v.object({
229
- id: alphaNumericOrHyphenSchema("application id (metadata.id)"),
230
- displayName: v.pipe(nonEmptyString("application display name"), v.maxLength(MAX_DISPLAY_NAME_LENGTH, `The application display name must not be longer than ${MAX_DISPLAY_NAME_LENGTH} characters`)),
231
- description: v.pipe(nonEmptyString("metadata description"), v.maxLength(MAX_DESCRIPTION_LENGTH, `The metadata description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
232
- version: v.pipe(nonEmptyString("version"), v.regex(SEMVER_REGEX, "The version must follow semantic versioning (semver) format"))
233
- });
234
- /**
235
- * Check if config has metadata.
236
- * @param config - The configuration to check.
237
- */
238
- function hasMetadata(config) {
239
- return config.metadata !== void 0;
240
- }
241
-
242
- //#endregion
243
- //#region source/config/schema/app.ts
244
- /** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
245
- /** The schema used to validate the commerce app config file. */
246
- const CommerceAppConfigSchema = v.looseObject({
247
- metadata: MetadataSchema,
248
- businessConfig: v.optional(SchemaBusinessConfig),
249
- eventing: v.optional(EventingSchema),
250
- installation: v.optional(InstallationSchema)
251
- });
252
-
253
- //#endregion
254
- //#region source/config/schema/domains.ts
255
- /** The individual validatable domains of the app config. */
256
- const CommerceAppConfigSchemas = {
257
- metadata: MetadataSchema,
258
- businessConfig: SchemaBusinessConfig,
259
- eventing: EventingSchema,
260
- installation: InstallationSchema,
261
- "businessConfig.schema": v.unwrap(SchemaBusinessConfig.entries.schema),
262
- "eventing.commerce": v.unwrap(EventingSchema.entries.commerce),
263
- "eventing.external": v.unwrap(EventingSchema.entries.external),
264
- "installation.customInstallationSteps": v.unwrap(InstallationSchema.entries.customInstallationSteps)
265
- };
266
- /**
267
- * Get the config domains that are present in the config.
268
- * @param config - The configuration to check.
269
- */
270
- function getConfigDomains(config) {
271
- const withCommerceEvents = hasCommerceEvents(config);
272
- const withExternalEvents = hasExternalEvents(config);
273
- const domains = {
274
- metadata: hasMetadata(config),
275
- businessConfig: hasBusinessConfig(config),
276
- eventing: withCommerceEvents || withExternalEvents,
277
- installation: hasCustomInstallation(config),
278
- "businessConfig.schema": hasBusinessConfigSchema(config),
279
- "eventing.commerce": withCommerceEvents,
280
- "eventing.external": withExternalEvents,
281
- "installation.customInstallationSteps": hasCustomInstallationSteps(config)
282
- };
283
- const domainsList = Object.entries(domains).filter(([_, value]) => value).map(([key]) => key);
284
- return new Set(domainsList);
285
- }
286
- /**
287
- * Check if the config has a specific domain.
288
- * @param config - The configuration to check.
289
- * @param domain - The domain to check.
290
- */
291
- function hasConfigDomain(config, domain) {
292
- return getConfigDomains(config).has(domain);
293
- }
294
-
295
- //#endregion
296
- //#region source/config/lib/validate.ts
297
- const commerceAppConfigDomainsSchema = v.picklist(Object.keys(CommerceAppConfigSchemas));
298
- /**
299
- * Validates a complete commerce app configuration object against the schema.
300
- *
301
- * @param config - The configuration object to validate.
302
- * @returns The validated and typed configuration output model.
303
- *
304
- * @throws {CommerceSdkValidationError} If the configuration is invalid, with
305
- * detailed validation issues included.
306
- *
307
- * @example
308
- * ```typescript
309
- * const config = {
310
- * businessConfiguration: {
311
- * // ... configuration data
312
- * }
313
- * };
314
- *
315
- * try {
316
- * const validatedConfig = validateCommerceAppConfig(config);
317
- * // Use validatedConfig safely
318
- * } catch (error) {
319
- * if (error instanceof CommerceSdkValidationError) {
320
- * console.error('Validation failed:', error.display());
321
- * }
322
- * }
323
- * ```
324
- */
325
- function validateCommerceAppConfig(config) {
326
- const validatedConfig = v.safeParse(CommerceAppConfigSchema, config);
327
- if (!validatedConfig.success) throw new CommerceSdkValidationError("Invalid commerce app config", { issues: validatedConfig.issues });
328
- return validatedConfig.output;
329
- }
330
- /**
331
- * Validates a specific domain configuration within the commerce app config.
332
- *
333
- * This function validates only a specific domain's configuration rather than
334
- * the entire commerce app configuration object. It first validates that the
335
- * domain name is valid, then validates the configuration data against the
336
- * schema for that specific domain.
337
- *
338
- * @template T - The type of the domain, constrained to valid domain names.
339
- *
340
- * @param config - The domain configuration object to validate.
341
- * @param domain - The name of the domain to validate (e.g., 'businessConfiguration').
342
- * @returns The validated and typed configuration for the specified domain.
343
- *
344
- * @throws {CommerceSdkValidationError} If the domain name is invalid or if the
345
- * configuration doesn't match the domain's schema.
346
- *
347
- * @example
348
- * ```typescript
349
- * const businessConfig = {
350
- * fields: [
351
- * {
352
- * name: 'category',
353
- * type: 'dropdown',
354
- * // ... field configuration
355
- * }
356
- * ]
357
- * };
358
- *
359
- * try {
360
- * const validatedConfig = validateCommerceAppConfigDomain(
361
- * businessConfig,
362
- * 'businessConfig'
363
- * );
364
- * // Use validatedConfig safely
365
- * } catch (error) {
366
- * if (error instanceof CommerceSdkValidationError) {
367
- * console.error('Domain validation failed:', error.issues);
368
- * }
369
- * }
370
- * ```
371
- */
372
- function validateCommerceAppConfigDomain(config, domain) {
373
- const domainSchema = v.safeParse(commerceAppConfigDomainsSchema, domain);
374
- if (!domainSchema.success) throw new CommerceSdkValidationError("Invalid commerce app config domain", { issues: domainSchema.issues });
375
- const domainConfigSchema = CommerceAppConfigSchemas[domain];
376
- const validatedConfig = v.safeParse(domainConfigSchema, config);
377
- if (!validatedConfig.success) throw new CommerceSdkValidationError(`Invalid commerce app config: ${domain}`, { issues: validatedConfig.issues });
378
- return validatedConfig.output;
379
- }
380
-
381
- //#endregion
382
- //#region source/config/lib/parser.ts
383
- const jiti = createJiti(import.meta.url);
384
- const configPaths = Object.freeze([
385
- "app.commerce.config.js",
386
- "app.commerce.config.ts",
387
- "app.commerce.config.cjs",
388
- "app.commerce.config.mjs",
389
- "app.commerce.config.mts",
390
- "app.commerce.config.cts"
391
- ]);
392
- /**
393
- * Try to find (up to the nearest package.json file) the app config file.
394
- *
395
- * Searches for config files in the following order of priority:
396
- * 1. `app.commerce.config.js` - JavaScript (CommonJS or ESM)
397
- * 2. `app.commerce.config.ts` - TypeScript
398
- * 3. `app.commerce.config.cjs` - CommonJS
399
- * 4. `app.commerce.config.mjs` - ES Module
400
- * 5. `app.commerce.config.mts` - ES Module TypeScript
401
- * 6. `app.commerce.config.cts` - CommonJS TypeScript
402
- *
403
- * @param cwd The current working directory
404
- * @returns The path to the config file, or null if not found
405
- */
406
- async function resolveCommerceAppConfig(cwd = process.cwd()) {
407
- const packageJsonPath = await findNearestPackageJson(cwd);
408
- if (!packageJsonPath) return null;
409
- const rootDirectory = dirname(packageJsonPath);
410
- for (const configPath of configPaths) {
411
- const configFilePath = await findUp(configPath, {
412
- cwd,
413
- stopAt: rootDirectory
414
- });
415
- if (configFilePath) return configFilePath;
416
- }
417
- return null;
418
- }
419
- /**
420
- * Read the commerce app config file as-is, without validating it.
421
- *
422
- * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
423
- * The config file must export a default export with the configuration object.
424
- *
425
- * @param cwd The current working directory
426
- * @returns The raw config object from the file
427
- * @throws {Error} If no config file is found or if the file doesn't export a default export
428
- */
429
- async function readCommerceAppConfig(cwd = process.cwd()) {
430
- const configFilePath = await resolveCommerceAppConfig(cwd);
431
- if (!configFilePath) throw new Error("Could not find a commerce app config file in the current working directory or its parents.");
432
- let config = null;
433
- try {
434
- config = await jiti.import(configFilePath);
435
- } catch (error) {
436
- const message = stringifyError(error);
437
- throw new Error(`Failed to read commerce app config file at ${configFilePath}: ${message}`, { cause: error });
438
- }
439
- 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 */ }`");
440
- return config.default;
441
- }
442
- /**
443
- * Read the commerce app config file and parse its contents into its schema.
444
- *
445
- * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
446
- * The config file must export a default export with the configuration object.
447
- *
448
- * @param cwd The current working directory
449
- * @returns The validated and parsed config object
450
- * @throws {Error} If no config file is found, if the file doesn't export a default export, or if validation fails
451
- */
452
- async function parseCommerceAppConfig(cwd = process.cwd()) {
453
- return validateCommerceAppConfig(await readCommerceAppConfig(cwd));
454
- }
455
-
456
- //#endregion
457
- export { readPackageJson as _, validateCommerceAppConfigDomain as a, hasConfigDomain as c, hasBusinessConfigSchema as d, detectPackageManager as f, makeOutputDirFor as g, isESM as h, validateCommerceAppConfig as i, hasMetadata as l, getProjectRootDirectory as m, readCommerceAppConfig as n, CommerceAppConfigSchemas as o, getExecCommand as p, resolveCommerceAppConfig as r, getConfigDomains as s, parseCommerceAppConfig as t, hasBusinessConfig as u, defineConfig as v };