@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,565 +0,0 @@
1
- const require_error = require('./error-Byj1DVHZ.cjs');
2
- let valibot = require("valibot");
3
- valibot = require_error.__toESM(valibot);
4
- let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
5
- let path = require("path");
6
- let fs = require("fs");
7
- let fs_promises = require("fs/promises");
8
- let jiti = require("jiti");
9
-
10
- //#region source/config/lib/define.ts
11
- /**
12
- * Helper to type-safely define the app config.
13
- * @param config - The app config to define.
14
- *
15
- * @example
16
- * ```typescript
17
- * import { defineConfig } from "@adobe/aio-commerce-lib-app";
18
- *
19
- * // In app.commerce.config.js
20
- * export default defineConfig({
21
- * // You get autocompletion and type-safety for the config object.
22
- * businessConfig: { ... }
23
- * });
24
- */
25
- function defineConfig(config) {
26
- return config;
27
- }
28
-
29
- //#endregion
30
- //#region ../../packages-private/scripting-utils/source/project.ts
31
- /**
32
- * This module exports shared project utilities for the AIO Commerce SDK.
33
- * @packageDocumentation
34
- */
35
- /**
36
- * Find a file by walking up parent directories
37
- * @param name - The file name to search for (or array of file names)
38
- * @param options - Search options
39
- * @returns The path to the file, or undefined if not found
40
- */
41
- async function findUp(name, options = {}) {
42
- const names = Array.isArray(name) ? name : [name];
43
- const cwd = options.cwd || process.cwd();
44
- const { root } = (0, path.parse)(cwd);
45
- const stopAt = options.stopAt || root;
46
- let currentDir = cwd;
47
- while (true) {
48
- for (const fileName of names) {
49
- const filePath = (0, path.join)(currentDir, fileName);
50
- try {
51
- await (0, fs_promises.access)(filePath);
52
- return filePath;
53
- } catch {}
54
- }
55
- if (currentDir === stopAt || currentDir === root) return;
56
- currentDir = (0, path.dirname)(currentDir);
57
- }
58
- }
59
- /**
60
- * Find the nearest package.json file in the current working directory or its parents
61
- * @param cwd The current working directory
62
- */
63
- async function findNearestPackageJson(cwd = process.cwd()) {
64
- const packageJsonPath = await findUp("package.json", { cwd });
65
- if (!packageJsonPath) return null;
66
- return packageJsonPath;
67
- }
68
- /**
69
- * Read the package.json file
70
- * @param cwd The current working directory
71
- */
72
- async function readPackageJson(cwd = process.cwd()) {
73
- const packageJsonPath = await findNearestPackageJson(cwd);
74
- if (!packageJsonPath) return null;
75
- return JSON.parse(await (0, fs_promises.readFile)(packageJsonPath, "utf-8"));
76
- }
77
- /**
78
- * Check if the current working directory is an ESM project.
79
- * @param cwd The current working directory
80
- */
81
- async function isESM(cwd = process.cwd()) {
82
- const packageJson = await readPackageJson(cwd);
83
- if (!packageJson) throw new Error("Could not find a `package.json` file in the current working directory or its parents.");
84
- return packageJson.type === "module";
85
- }
86
- /**
87
- * Get the root directory of the project
88
- * @param cwd The current working directory
89
- */
90
- async function getProjectRootDirectory(cwd = process.cwd()) {
91
- const packageJsonPath = await findNearestPackageJson(cwd);
92
- if (!packageJsonPath) throw new Error("Could not find a the root directory of the project. `package.json` file not found.");
93
- return (0, path.dirname)(packageJsonPath);
94
- }
95
- /**
96
- * Create the output directory for the given file or folder (relative to the project root)
97
- * @param fileOrFolder - The file or folder to create
98
- */
99
- async function makeOutputDirFor(fileOrFolder) {
100
- const outputDir = (0, path.join)(await getProjectRootDirectory(), fileOrFolder);
101
- if (!(0, fs.existsSync)(outputDir)) await (0, fs_promises.mkdir)(outputDir, { recursive: true });
102
- return outputDir;
103
- }
104
- /** Detect the package manager by checking for lock files */
105
- async function detectPackageManager(cwd = process.cwd()) {
106
- const rootDirectory = await getProjectRootDirectory(cwd);
107
- const lockFileMap = {
108
- "bun.lockb": "bun",
109
- "pnpm-lock.yaml": "pnpm",
110
- "yarn.lock": "yarn",
111
- "package-lock.json": "npm"
112
- };
113
- const lockFileName = Object.keys(lockFileMap).find((name) => (0, fs.existsSync)((0, path.join)(rootDirectory, name)));
114
- if (!lockFileName) return "npm";
115
- return lockFileMap[lockFileName];
116
- }
117
- /** Get the appropriate exec command based on package manager */
118
- function getExecCommand(packageManager) {
119
- return {
120
- pnpm: "pnpx",
121
- yarn: "yarn dlx",
122
- bun: "bunx",
123
- npm: "npx"
124
- }[packageManager];
125
- }
126
-
127
- //#endregion
128
- //#region source/config/schema/business-configuration.ts
129
- /** Base schema for configuration field options with name, optional label, and optional description */
130
- const BaseOptionSchema = valibot.object({
131
- name: valibot.pipe(valibot.string("Expected a string for the field name"), valibot.nonEmpty("The field name must not be empty")),
132
- label: valibot.optional(valibot.string("Expected a string for the field label")),
133
- description: valibot.optional(valibot.string("Expected a string for the field description"))
134
- });
135
- /** Schema for a single option in a list field, containing a display label and a value */
136
- const ListOptionSchema = valibot.object({
137
- label: valibot.string("Expected a string for the option label"),
138
- value: valibot.string("Expected a string for the option value")
139
- });
140
- /** Schema for a list field that allows single selection from a list of options */
141
- const SingleListSchema = valibot.object({
142
- ...BaseOptionSchema.entries,
143
- type: valibot.literal("list", "Expected the type to be 'list'"),
144
- selectionMode: valibot.literal("single", "Expected the selectionMode to be 'single'"),
145
- options: valibot.array(ListOptionSchema, "Expected an array of list options"),
146
- default: valibot.pipe(valibot.string("Expected a string for the default value"), valibot.nonEmpty("The default value must not be empty"))
147
- });
148
- /** Schema for a list field that allows multiple selections from a list of options */
149
- const MultipleListSchema = valibot.object({
150
- ...BaseOptionSchema.entries,
151
- type: valibot.literal("list", "Expected the type to be 'list'"),
152
- selectionMode: valibot.literal("multiple", "Expected the selectionMode to be 'multiple'"),
153
- options: valibot.array(ListOptionSchema, "Expected an array of list options"),
154
- default: valibot.optional(valibot.array(valibot.pipe(valibot.string("Expected a string for each default value"), valibot.nonEmpty("Each default value must not be empty")), "Expected an array of default values"), [])
155
- });
156
- /** Schema for list fields supporting either single or multiple selection modes */
157
- const ListSchema = valibot.variant("selectionMode", [SingleListSchema, MultipleListSchema]);
158
- /** Schema for a text input field that accepts string values */
159
- const TextSchema = valibot.object({
160
- ...BaseOptionSchema.entries,
161
- type: valibot.literal("text", "Expected the type to be 'text'"),
162
- default: valibot.optional(valibot.string("Expected a string for the default value"))
163
- });
164
- /** Schema for a password input field that accepts string values (typically masked in UI) */
165
- const PasswordSchema = valibot.object({
166
- ...BaseOptionSchema.entries,
167
- type: valibot.literal("password", "Expected the type to be 'password'"),
168
- default: valibot.optional(valibot.string("Expected a string for the default value"))
169
- });
170
- /** Schema for a boolean field that accepts true or false values */
171
- /** Schema for a number input field that accepts numeric values */
172
- /** Schema for a date input field that accepts date values */
173
- /** Schema for an email input field that accepts and validates email addresses */
174
- const EmailSchema = valibot.object({
175
- ...BaseOptionSchema.entries,
176
- type: valibot.literal("email", "Expected the type to be 'email'"),
177
- default: valibot.optional(valibot.pipe(valibot.string("Expected a string for the default email value"), valibot.email("The email must be a valid email address")))
178
- });
179
- /** Schema for a URL input field that accepts and validates URL strings */
180
- const UrlSchema = valibot.object({
181
- ...BaseOptionSchema.entries,
182
- type: valibot.literal("url", "Expected the type to be 'url'"),
183
- default: valibot.optional(valibot.pipe(valibot.string("Expected a string for the default URL value"), valibot.url("The URL must be a valid URL")))
184
- });
185
- /** Schema for a phone number input field that accepts and validates telephone numbers */
186
- const PhoneSchema = valibot.object({
187
- ...BaseOptionSchema.entries,
188
- type: valibot.literal("tel", "Expected the type to be 'tel'"),
189
- default: valibot.optional(valibot.pipe(valibot.string("Expected a string for the default phone number value"), valibot.regex(/^\+?[0-9\s\-()]+$/, "The phone number must contain only numbers and/or country codes")))
190
- });
191
- /** Schema for a configuration field that can be one of various field types (list, text, password, email, url, or phone) */
192
- const FieldSchema = valibot.variant("type", [
193
- ListSchema,
194
- TextSchema,
195
- PasswordSchema,
196
- EmailSchema,
197
- UrlSchema,
198
- PhoneSchema
199
- ]);
200
- /** Schema for the schema of the business configuration, which is an array of configuration fields with at least one field required */
201
- const SchemaBusinessConfigSchema = valibot.pipe(valibot.array(FieldSchema, "Expected an array of configuration fields"), valibot.minLength(1, "At least one configuration parameter is required"));
202
- /** The schema used to validate the `businessConfig` settings in the app config file. */
203
- const SchemaBusinessConfig = valibot.object({ schema: valibot.optional(SchemaBusinessConfigSchema, []) });
204
- /**
205
- * Check if config has business config.
206
- * @param config - The configuration to check.
207
- */
208
- function hasBusinessConfig(config) {
209
- return config.businessConfig !== void 0;
210
- }
211
- /**
212
- * Check if config has business config schema.
213
- * @param config - The configuration to check.
214
- */
215
- function hasBusinessConfigSchema(config) {
216
- return config.businessConfig?.schema !== void 0 && config.businessConfig.schema.length > 0;
217
- }
218
-
219
- //#endregion
220
- //#region source/config/schema/metadata.ts
221
- const MAX_DESCRIPTION_LENGTH = 255;
222
- const MAX_DISPLAY_NAME_LENGTH = 50;
223
- const NUMERIC_IDENTIFIER = "(0|[1-9]\\d*)";
224
- const SEMVER_REGEX = /* @__PURE__ */ new RegExp(`^${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}$`);
225
- function nonEmptyString(fieldName) {
226
- return valibot.pipe(valibot.string(`Expected a string for the ${fieldName}`), valibot.nonEmpty(`The ${fieldName} must not be empty`));
227
- }
228
- /** The schema for the metadata of the application. */
229
- const MetadataSchema = valibot.object({
230
- id: require_error.alphaNumericOrHyphenSchema("application id (metadata.id)"),
231
- displayName: valibot.pipe(nonEmptyString("application display name"), valibot.maxLength(MAX_DISPLAY_NAME_LENGTH, `The application display name must not be longer than ${MAX_DISPLAY_NAME_LENGTH} characters`)),
232
- description: valibot.pipe(nonEmptyString("metadata description"), valibot.maxLength(MAX_DESCRIPTION_LENGTH, `The metadata description must not be longer than ${MAX_DESCRIPTION_LENGTH} characters`)),
233
- version: valibot.pipe(nonEmptyString("version"), valibot.regex(SEMVER_REGEX, "The version must follow semantic versioning (semver) format"))
234
- });
235
- /**
236
- * Check if config has metadata.
237
- * @param config - The configuration to check.
238
- */
239
- function hasMetadata(config) {
240
- return config.metadata !== void 0;
241
- }
242
-
243
- //#endregion
244
- //#region source/config/schema/app.ts
245
- /** biome-ignore-all lint/performance/noBarrelFile: We want to have all the schema exports in one file. */
246
- /** The schema used to validate the commerce app config file. */
247
- const CommerceAppConfigSchema = valibot.looseObject({
248
- metadata: MetadataSchema,
249
- businessConfig: valibot.optional(SchemaBusinessConfig),
250
- eventing: valibot.optional(require_error.EventingSchema),
251
- installation: valibot.optional(require_error.InstallationSchema)
252
- });
253
-
254
- //#endregion
255
- //#region source/config/schema/domains.ts
256
- /** The individual validatable domains of the app config. */
257
- const CommerceAppConfigSchemas = {
258
- metadata: MetadataSchema,
259
- businessConfig: SchemaBusinessConfig,
260
- eventing: require_error.EventingSchema,
261
- installation: require_error.InstallationSchema,
262
- "businessConfig.schema": valibot.unwrap(SchemaBusinessConfig.entries.schema),
263
- "eventing.commerce": valibot.unwrap(require_error.EventingSchema.entries.commerce),
264
- "eventing.external": valibot.unwrap(require_error.EventingSchema.entries.external),
265
- "installation.customInstallationSteps": valibot.unwrap(require_error.InstallationSchema.entries.customInstallationSteps)
266
- };
267
- /**
268
- * Get the config domains that are present in the config.
269
- * @param config - The configuration to check.
270
- */
271
- function getConfigDomains(config) {
272
- const withCommerceEvents = require_error.hasCommerceEvents(config);
273
- const withExternalEvents = require_error.hasExternalEvents(config);
274
- const domains = {
275
- metadata: hasMetadata(config),
276
- businessConfig: hasBusinessConfig(config),
277
- eventing: withCommerceEvents || withExternalEvents,
278
- installation: require_error.hasCustomInstallation(config),
279
- "businessConfig.schema": hasBusinessConfigSchema(config),
280
- "eventing.commerce": withCommerceEvents,
281
- "eventing.external": withExternalEvents,
282
- "installation.customInstallationSteps": require_error.hasCustomInstallationSteps(config)
283
- };
284
- const domainsList = Object.entries(domains).filter(([_, value]) => value).map(([key]) => key);
285
- return new Set(domainsList);
286
- }
287
- /**
288
- * Check if the config has a specific domain.
289
- * @param config - The configuration to check.
290
- * @param domain - The domain to check.
291
- */
292
- function hasConfigDomain(config, domain) {
293
- return getConfigDomains(config).has(domain);
294
- }
295
-
296
- //#endregion
297
- //#region source/config/lib/validate.ts
298
- const commerceAppConfigDomainsSchema = valibot.picklist(Object.keys(CommerceAppConfigSchemas));
299
- /**
300
- * Validates a complete commerce app configuration object against the schema.
301
- *
302
- * @param config - The configuration object to validate.
303
- * @returns The validated and typed configuration output model.
304
- *
305
- * @throws {CommerceSdkValidationError} If the configuration is invalid, with
306
- * detailed validation issues included.
307
- *
308
- * @example
309
- * ```typescript
310
- * const config = {
311
- * businessConfiguration: {
312
- * // ... configuration data
313
- * }
314
- * };
315
- *
316
- * try {
317
- * const validatedConfig = validateCommerceAppConfig(config);
318
- * // Use validatedConfig safely
319
- * } catch (error) {
320
- * if (error instanceof CommerceSdkValidationError) {
321
- * console.error('Validation failed:', error.display());
322
- * }
323
- * }
324
- * ```
325
- */
326
- function validateCommerceAppConfig(config) {
327
- const validatedConfig = valibot.safeParse(CommerceAppConfigSchema, config);
328
- if (!validatedConfig.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid commerce app config", { issues: validatedConfig.issues });
329
- return validatedConfig.output;
330
- }
331
- /**
332
- * Validates a specific domain configuration within the commerce app config.
333
- *
334
- * This function validates only a specific domain's configuration rather than
335
- * the entire commerce app configuration object. It first validates that the
336
- * domain name is valid, then validates the configuration data against the
337
- * schema for that specific domain.
338
- *
339
- * @template T - The type of the domain, constrained to valid domain names.
340
- *
341
- * @param config - The domain configuration object to validate.
342
- * @param domain - The name of the domain to validate (e.g., 'businessConfiguration').
343
- * @returns The validated and typed configuration for the specified domain.
344
- *
345
- * @throws {CommerceSdkValidationError} If the domain name is invalid or if the
346
- * configuration doesn't match the domain's schema.
347
- *
348
- * @example
349
- * ```typescript
350
- * const businessConfig = {
351
- * fields: [
352
- * {
353
- * name: 'category',
354
- * type: 'dropdown',
355
- * // ... field configuration
356
- * }
357
- * ]
358
- * };
359
- *
360
- * try {
361
- * const validatedConfig = validateCommerceAppConfigDomain(
362
- * businessConfig,
363
- * 'businessConfig'
364
- * );
365
- * // Use validatedConfig safely
366
- * } catch (error) {
367
- * if (error instanceof CommerceSdkValidationError) {
368
- * console.error('Domain validation failed:', error.issues);
369
- * }
370
- * }
371
- * ```
372
- */
373
- function validateCommerceAppConfigDomain(config, domain) {
374
- const domainSchema = valibot.safeParse(commerceAppConfigDomainsSchema, domain);
375
- if (!domainSchema.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid commerce app config domain", { issues: domainSchema.issues });
376
- const domainConfigSchema = CommerceAppConfigSchemas[domain];
377
- const validatedConfig = valibot.safeParse(domainConfigSchema, config);
378
- if (!validatedConfig.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError(`Invalid commerce app config: ${domain}`, { issues: validatedConfig.issues });
379
- return validatedConfig.output;
380
- }
381
-
382
- //#endregion
383
- //#region source/config/lib/parser.ts
384
- const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href);
385
- const configPaths = Object.freeze([
386
- "app.commerce.config.js",
387
- "app.commerce.config.ts",
388
- "app.commerce.config.cjs",
389
- "app.commerce.config.mjs",
390
- "app.commerce.config.mts",
391
- "app.commerce.config.cts"
392
- ]);
393
- /**
394
- * Try to find (up to the nearest package.json file) the app config file.
395
- *
396
- * Searches for config files in the following order of priority:
397
- * 1. `app.commerce.config.js` - JavaScript (CommonJS or ESM)
398
- * 2. `app.commerce.config.ts` - TypeScript
399
- * 3. `app.commerce.config.cjs` - CommonJS
400
- * 4. `app.commerce.config.mjs` - ES Module
401
- * 5. `app.commerce.config.mts` - ES Module TypeScript
402
- * 6. `app.commerce.config.cts` - CommonJS TypeScript
403
- *
404
- * @param cwd The current working directory
405
- * @returns The path to the config file, or null if not found
406
- */
407
- async function resolveCommerceAppConfig(cwd = process.cwd()) {
408
- const packageJsonPath = await findNearestPackageJson(cwd);
409
- if (!packageJsonPath) return null;
410
- const rootDirectory = (0, path.dirname)(packageJsonPath);
411
- for (const configPath of configPaths) {
412
- const configFilePath = await findUp(configPath, {
413
- cwd,
414
- stopAt: rootDirectory
415
- });
416
- if (configFilePath) return configFilePath;
417
- }
418
- return null;
419
- }
420
- /**
421
- * Read the commerce app config file as-is, without validating it.
422
- *
423
- * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
424
- * The config file must export a default export with the configuration object.
425
- *
426
- * @param cwd The current working directory
427
- * @returns The raw config object from the file
428
- * @throws {Error} If no config file is found or if the file doesn't export a default export
429
- */
430
- async function readCommerceAppConfig(cwd = process.cwd()) {
431
- const configFilePath = await resolveCommerceAppConfig(cwd);
432
- if (!configFilePath) throw new Error("Could not find a commerce app config file in the current working directory or its parents.");
433
- let config = null;
434
- try {
435
- config = await jiti$1.import(configFilePath);
436
- } catch (error) {
437
- const message = require_error.stringifyError(error);
438
- throw new Error(`Failed to read commerce app config file at ${configFilePath}: ${message}`, { cause: error });
439
- }
440
- 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 */ }`");
441
- return config.default;
442
- }
443
- /**
444
- * Read the commerce app config file and parse its contents into its schema.
445
- *
446
- * Supports multiple config file formats (see {@link resolveCommerceAppConfig} for the list).
447
- * The config file must export a default export with the configuration object.
448
- *
449
- * @param cwd The current working directory
450
- * @returns The validated and parsed config object
451
- * @throws {Error} If no config file is found, if the file doesn't export a default export, or if validation fails
452
- */
453
- async function parseCommerceAppConfig(cwd = process.cwd()) {
454
- return validateCommerceAppConfig(await readCommerceAppConfig(cwd));
455
- }
456
-
457
- //#endregion
458
- Object.defineProperty(exports, 'CommerceAppConfigSchemas', {
459
- enumerable: true,
460
- get: function () {
461
- return CommerceAppConfigSchemas;
462
- }
463
- });
464
- Object.defineProperty(exports, 'defineConfig', {
465
- enumerable: true,
466
- get: function () {
467
- return defineConfig;
468
- }
469
- });
470
- Object.defineProperty(exports, 'detectPackageManager', {
471
- enumerable: true,
472
- get: function () {
473
- return detectPackageManager;
474
- }
475
- });
476
- Object.defineProperty(exports, 'getConfigDomains', {
477
- enumerable: true,
478
- get: function () {
479
- return getConfigDomains;
480
- }
481
- });
482
- Object.defineProperty(exports, 'getExecCommand', {
483
- enumerable: true,
484
- get: function () {
485
- return getExecCommand;
486
- }
487
- });
488
- Object.defineProperty(exports, 'getProjectRootDirectory', {
489
- enumerable: true,
490
- get: function () {
491
- return getProjectRootDirectory;
492
- }
493
- });
494
- Object.defineProperty(exports, 'hasBusinessConfig', {
495
- enumerable: true,
496
- get: function () {
497
- return hasBusinessConfig;
498
- }
499
- });
500
- Object.defineProperty(exports, 'hasBusinessConfigSchema', {
501
- enumerable: true,
502
- get: function () {
503
- return hasBusinessConfigSchema;
504
- }
505
- });
506
- Object.defineProperty(exports, 'hasConfigDomain', {
507
- enumerable: true,
508
- get: function () {
509
- return hasConfigDomain;
510
- }
511
- });
512
- Object.defineProperty(exports, 'hasMetadata', {
513
- enumerable: true,
514
- get: function () {
515
- return hasMetadata;
516
- }
517
- });
518
- Object.defineProperty(exports, 'isESM', {
519
- enumerable: true,
520
- get: function () {
521
- return isESM;
522
- }
523
- });
524
- Object.defineProperty(exports, 'makeOutputDirFor', {
525
- enumerable: true,
526
- get: function () {
527
- return makeOutputDirFor;
528
- }
529
- });
530
- Object.defineProperty(exports, 'parseCommerceAppConfig', {
531
- enumerable: true,
532
- get: function () {
533
- return parseCommerceAppConfig;
534
- }
535
- });
536
- Object.defineProperty(exports, 'readCommerceAppConfig', {
537
- enumerable: true,
538
- get: function () {
539
- return readCommerceAppConfig;
540
- }
541
- });
542
- Object.defineProperty(exports, 'readPackageJson', {
543
- enumerable: true,
544
- get: function () {
545
- return readPackageJson;
546
- }
547
- });
548
- Object.defineProperty(exports, 'resolveCommerceAppConfig', {
549
- enumerable: true,
550
- get: function () {
551
- return resolveCommerceAppConfig;
552
- }
553
- });
554
- Object.defineProperty(exports, 'validateCommerceAppConfig', {
555
- enumerable: true,
556
- get: function () {
557
- return validateCommerceAppConfig;
558
- }
559
- });
560
- Object.defineProperty(exports, 'validateCommerceAppConfigDomain', {
561
- enumerable: true,
562
- get: function () {
563
- return validateCommerceAppConfigDomain;
564
- }
565
- });