@adobe/aio-commerce-lib-app 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/actions/index.cjs +815 -170
- package/dist/cjs/actions/index.d.cts +2 -2
- package/dist/cjs/app-Dx0ca6oL.d.cts +181 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +63 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +104 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +69 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +125 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +83 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +113 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +56 -0
- package/dist/cjs/commands/index.cjs +1075 -119
- package/dist/cjs/config/index.cjs +20 -1
- package/dist/cjs/config/index.d.cts +532 -3
- package/dist/cjs/config-JQ_n-5Nk.cjs +565 -0
- package/dist/cjs/error-Byj1DVHZ.cjs +344 -0
- package/dist/cjs/{index-DS3IlISO.d.cts → index-C5SutkJQ.d.cts} +1 -1
- package/dist/cjs/logging-DYwr5WQk.cjs +25 -0
- package/dist/cjs/management/index.cjs +9 -1
- package/dist/cjs/management/index.d.cts +1 -1
- package/dist/cjs/management-Dm5h0E6l.cjs +1246 -0
- package/dist/es/actions/index.d.mts +2 -2
- package/dist/es/actions/index.mjs +813 -170
- package/dist/es/app-Cx1-6dn0.d.mts +181 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +63 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +104 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +69 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +125 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +83 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +113 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +56 -0
- package/dist/es/commands/index.mjs +1070 -119
- package/dist/es/config/index.d.mts +532 -3
- package/dist/es/config/index.mjs +4 -1
- package/dist/es/config-BSGerqCG.mjs +457 -0
- package/dist/es/error-P7JgUTds.mjs +251 -0
- package/dist/es/{index-DQepSWYP.d.mts → index-Bxr3zvCT.d.mts} +2 -2
- package/dist/es/logging-VgerMhp6.mjs +18 -0
- package/dist/es/management/index.d.mts +2 -2
- package/dist/es/management/index.mjs +3 -1
- package/dist/es/management-Y7pwEbNI.mjs +1204 -0
- package/package.json +20 -8
- package/dist/cjs/app-C4HhkXbP.d.cts +0 -451
- package/dist/cjs/error-yAk1zzvx.cjs +0 -1
- package/dist/cjs/management-CE3_DJw4.cjs +0 -2
- package/dist/cjs/parser-Dovux8ce.cjs +0 -1
- package/dist/cjs/schemas-CdaP-Exw.cjs +0 -1
- package/dist/es/app-CMpx3D7Y.d.mts +0 -451
- package/dist/es/chunk-VmiN0kV1.mjs +0 -1
- package/dist/es/error-hBHRgZ9R.mjs +0 -1
- package/dist/es/management-BM2WcbV6.mjs +0 -2
- package/dist/es/parser-DOVfvr9l.mjs +0 -1
- package/dist/es/schemas-eemlD-xS.mjs +0 -1
- /package/dist/cjs/commands/generate/actions/templates/{custom-scripts.js.template → app-management/custom-scripts.js.template} +0 -0
- /package/dist/cjs/commands/generate/actions/templates/{get-app-config.js.template → app-management/get-app-config.js.template} +0 -0
- /package/dist/cjs/commands/generate/actions/templates/{installation.js.template → app-management/installation.js.template} +0 -0
- /package/dist/es/commands/generate/actions/templates/{custom-scripts.js.template → app-management/custom-scripts.js.template} +0 -0
- /package/dist/es/commands/generate/actions/templates/{get-app-config.js.template → app-management/get-app-config.js.template} +0 -0
- /package/dist/es/commands/generate/actions/templates/{installation.js.template → app-management/installation.js.template} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as stringifyError}from"./error-hBHRgZ9R.mjs";import{a as stringValueSchema,i as nonEmptyStringValueSchema,n as alphaNumericOrUnderscoreSchema,o as titleCaseSchema,r as booleanValueSchema,t as alphaNumericOrHyphenSchema}from"./schemas-eemlD-xS.mjs";import{existsSync}from"fs";import{dirname,join,parse}from"path";import*as v from"valibot";import{CommerceSdkValidationError}from"@adobe/aio-commerce-lib-core/error";import{access,mkdir,readFile}from"fs/promises";import{createJiti}from"jiti";async function findUp(name,options={}){let names=Array.isArray(name)?name:[name],cwd=options.cwd||process.cwd(),{root}=parse(cwd),stopAt=options.stopAt||root,currentDir=cwd;for(;;){for(let fileName of names){let filePath=join(currentDir,fileName);try{return await access(filePath),filePath}catch{}}if(currentDir===stopAt||currentDir===root)return;currentDir=dirname(currentDir)}}async function findNearestPackageJson(cwd=process.cwd()){return await findUp(`package.json`,{cwd})||null}async function getProjectRootDirectory(cwd=process.cwd()){let packageJsonPath=await findNearestPackageJson(cwd);if(!packageJsonPath)throw Error("Could not find a the root directory of the project. `package.json` file not found.");return dirname(packageJsonPath)}async function makeOutputDirFor(fileOrFolder){let outputDir=join(await getProjectRootDirectory(),fileOrFolder);return existsSync(outputDir)||await mkdir(outputDir,{recursive:!0}),outputDir}async function detectPackageManager(cwd=process.cwd()){let rootDirectory=await getProjectRootDirectory(cwd),lockFileMap={"bun.lockb":`bun`,"pnpm-lock.yaml":`pnpm`,"yarn.lock":`yarn`,"package-lock.json":`npm`},lockFileName=Object.keys(lockFileMap).find(name=>existsSync(join(rootDirectory,name)));return lockFileName?lockFileMap[lockFileName]:`npm`}function getExecCommand(packageManager){return{pnpm:`pnpx`,yarn:`yarn dlx`,bun:`bunx`,npm:`npx`}[packageManager]}const BaseOptionSchema=v.object({name:v.pipe(v.string(`Expected a string for the field name`),v.nonEmpty(`The field name must not be empty`)),label:v.optional(v.string(`Expected a string for the field label`)),description:v.optional(v.string(`Expected a string for the field description`))}),ListOptionSchema=v.object({label:v.string(`Expected a string for the option label`),value:v.string(`Expected a string for the option value`)}),SingleListSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`list`,`Expected the type to be 'list'`),selectionMode:v.literal(`single`,`Expected the selectionMode to be 'single'`),options:v.array(ListOptionSchema,`Expected an array of list options`),default:v.pipe(v.string(`Expected a string for the default value`),v.nonEmpty(`The default value must not be empty`))}),MultipleListSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`list`,`Expected the type to be 'list'`),selectionMode:v.literal(`multiple`,`Expected the selectionMode to be 'multiple'`),options:v.array(ListOptionSchema,`Expected an array of list options`),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`),[])}),ListSchema=v.variant(`selectionMode`,[SingleListSchema,MultipleListSchema]),TextSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`text`,`Expected the type to be 'text'`),default:v.optional(v.string(`Expected a string for the default value`))}),PasswordSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`password`,`Expected the type to be 'password'`),default:v.optional(v.string(`Expected a string for the default value`))}),EmailSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`email`,`Expected the type to be 'email'`),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`)))}),UrlSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`url`,`Expected the type to be 'url'`),default:v.optional(v.pipe(v.string(`Expected a string for the default URL value`),v.url(`The URL must be a valid URL`)))}),PhoneSchema=v.object({...BaseOptionSchema.entries,type:v.literal(`tel`,`Expected the type to be 'tel'`),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`)))}),FieldSchema=v.variant(`type`,[ListSchema,TextSchema,PasswordSchema,EmailSchema,UrlSchema,PhoneSchema]),SchemaBusinessConfigSchema=v.pipe(v.array(FieldSchema,`Expected an array of configuration fields`),v.minLength(1,`At least one configuration parameter is required`)),SchemaBusinessConfig=v.object({schema:v.optional(SchemaBusinessConfigSchema,[])}),COMMERCE_EVENT_NAME_REGEX=/^(?:plugin|observer)\.[a-z_]+$/,FIELD_NAME_REGEX=/^([a-zA-Z0-9_\-.[\]]+|\*)$/;function commerceEventNameSchema(){return v.pipe(nonEmptyStringValueSchema(`event name`),v.regex(COMMERCE_EVENT_NAME_REGEX,`Event name must start with "plugin." or "observer." followed by lowercase letters and underscores only (e.g., "plugin.order_placed")`))}function fieldNameSchema(){return v.pipe(nonEmptyStringValueSchema(`field name`),v.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 "*"`))}function commerceEventFieldSchema(){return v.object({name:fieldNameSchema(),source:v.optional(stringValueSchema(`field source`))})}const ProviderSchema=v.object({label:v.pipe(titleCaseSchema(`provider label`),v.maxLength(100,`The provider label must not be longer than 100 characters`)),description:v.pipe(nonEmptyStringValueSchema(`provider description`),v.maxLength(255,`The provider description must not be longer than 255 characters`)),key:v.optional(v.pipe(alphaNumericOrHyphenSchema(`provider key`),v.maxLength(50,`The provider key must not be longer than 50 characters`)))}),BaseEventSchema=v.object({label:v.pipe(titleCaseSchema(`event label`),v.maxLength(100,`The event label must not be longer than 100 characters`)),description:v.pipe(nonEmptyStringValueSchema(`event description`),v.maxLength(255,`The event description must not be longer than 255 characters`)),runtimeActions:v.array(v.pipe(nonEmptyStringValueSchema(`runtime action`),v.regex(/^[a-z0-9-]+\/[a-z0-9-]+$/,`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>`)}),OPERATORS=[`greaterThan`,`lessThan`,`equal`,`regex`,`in`,`onChange`],ruleOperatorSchema=v.union(OPERATORS.map(op=>v.literal(op)),`Operator must be one of: ${OPERATORS.join(`, `)}`),CommerceEventRuleSchema=v.object({field:nonEmptyStringValueSchema(`rule field`),operator:ruleOperatorSchema,value:nonEmptyStringValueSchema(`rule value`)}),CommerceEventSchema=v.object({...BaseEventSchema.entries,name:commerceEventNameSchema(),fields:v.array(commerceEventFieldSchema(),`Expected an array of event field objects with a 'name' property`),rules:v.optional(v.array(CommerceEventRuleSchema,`Expected an array of event rules with field, operator, and value`)),destination:v.optional(nonEmptyStringValueSchema(`destination`)),hipaaAuditRequired:v.optional(booleanValueSchema(`hipaaAuditRequired`)),prioritary:v.optional(booleanValueSchema(`prioritary`)),force:v.optional(booleanValueSchema(`force`))}),ExternalEventSchema=v.object({...BaseEventSchema.entries,name:alphaNumericOrUnderscoreSchema(`event name`,`lowercase`)}),CommerceEventSourceSchema=v.object({provider:ProviderSchema,events:v.array(CommerceEventSchema,`Expected an array of Commerce events`)}),ExternalEventSourceSchema=v.object({provider:ProviderSchema,events:v.array(ExternalEventSchema,`Expected an array of external events`)}),EventingSchema=v.object({commerce:v.optional(v.array(CommerceEventSourceSchema,`Expected an array of Commerce event sources`)),external:v.optional(v.array(ExternalEventSourceSchema,`Expected an array of external event sources`))}),MAX_MESSAGE_LENGTH=1e3,CustomInstallationStepSchema=v.object({script:v.pipe(nonEmptyStringValueSchema(`script path`),v.regex(/^(?:\.{0,2}\/)*[\w-/]*[\w-]+\.js$/,`Script path must end with .js (e.g., "./setup.js", "./scripts/setup.js", or "../../scripts/setup.js")`)),name:v.pipe(nonEmptyStringValueSchema(`step name`),v.maxLength(255,`The step name must not be longer than 255 characters`)),description:v.pipe(nonEmptyStringValueSchema(`step description`),v.maxLength(255,`The step description must not be longer than 255 characters`))}),MessagesSchema=v.object({preInstallation:v.optional(v.pipe(nonEmptyStringValueSchema(`preInstallation message`),v.maxLength(MAX_MESSAGE_LENGTH,`The preInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`))),postInstallation:v.optional(v.pipe(nonEmptyStringValueSchema(`postInstallation message`),v.maxLength(MAX_MESSAGE_LENGTH,`The postInstallation message must not be longer than ${MAX_MESSAGE_LENGTH} characters`)))}),InstallationSchema=v.object({messages:v.optional(MessagesSchema),customInstallationSteps:v.optional(v.array(CustomInstallationStepSchema,`Expected an array of custom installation steps`))}),NUMERIC_IDENTIFIER=`(0|[1-9]\\d*)`,SEMVER_REGEX=RegExp(`^${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}\\.${NUMERIC_IDENTIFIER}$`);function nonEmptyString(fieldName){return v.pipe(v.string(`Expected a string for the ${fieldName}`),v.nonEmpty(`The ${fieldName} must not be empty`))}const MetadataSchema=v.object({id:alphaNumericOrHyphenSchema(`application id (metadata.id)`),displayName:v.pipe(nonEmptyString(`application display name`),v.maxLength(50,`The application display name must not be longer than 50 characters`)),description:v.pipe(nonEmptyString(`metadata description`),v.maxLength(255,`The metadata description must not be longer than 255 characters`)),version:v.pipe(nonEmptyString(`version`),v.regex(SEMVER_REGEX,`The version must follow semantic versioning (semver) format`))}),CommerceAppConfigSchemas={metadata:MetadataSchema,businessConfig:SchemaBusinessConfig,"businessConfig.schema":SchemaBusinessConfigSchema,eventing:EventingSchema,installation:InstallationSchema},CommerceAppConfigSchema=v.looseObject({metadata:MetadataSchema,businessConfig:v.optional(SchemaBusinessConfig),eventing:v.optional(EventingSchema),installation:v.optional(InstallationSchema)}),commerceAppConfigDomainsSchema=v.picklist(Object.keys(CommerceAppConfigSchemas));function validateCommerceAppConfig(config){let validatedConfig=v.safeParse(CommerceAppConfigSchema,config);if(!validatedConfig.success)throw new CommerceSdkValidationError(`Invalid commerce app config`,{issues:validatedConfig.issues});return validatedConfig.output}function validateCommerceAppConfigDomain(config,domain){let domainSchema=v.safeParse(commerceAppConfigDomainsSchema,domain);if(!domainSchema.success)throw new CommerceSdkValidationError(`Invalid commerce app config domain`,{issues:domainSchema.issues});let domainConfigSchema=CommerceAppConfigSchemas[domain],validatedConfig=v.safeParse(domainConfigSchema,config);if(!validatedConfig.success)throw new CommerceSdkValidationError(`Invalid commerce app config: ${domain}`,{issues:validatedConfig.issues});return validatedConfig.output}const jiti=createJiti(import.meta.url),configPaths=Object.freeze([`app.commerce.config.js`,`app.commerce.config.ts`,`app.commerce.config.cjs`,`app.commerce.config.mjs`,`app.commerce.config.mts`,`app.commerce.config.cts`]);async function resolveCommerceAppConfig(cwd=process.cwd()){let packageJsonPath=await findNearestPackageJson(cwd);if(!packageJsonPath)return null;let rootDirectory=dirname(packageJsonPath);for(let configPath of configPaths){let configFilePath=await findUp(configPath,{cwd,stopAt:rootDirectory});if(configFilePath)return configFilePath}return null}async function readCommerceAppConfig(cwd=process.cwd()){let configFilePath=await resolveCommerceAppConfig(cwd);if(!configFilePath)throw Error(`Could not find a commerce app config file in the current working directory or its parents.`);let config=null;try{config=await jiti.import(configFilePath)}catch(error){let message=stringifyError(error);throw Error(`Failed to read commerce app config file at ${configFilePath}: ${message}`,{cause:error})}if(!(config&&`default`in config)||config.default===void 0||config.default===null||typeof config.default==`object`&&Object.keys(config.default).length===0)throw Error("Commerce app config file does not export a default export. Make sure you use `export default` or `module.exports = { /* your config */ }`");return config.default}async function parseCommerceAppConfig(cwd=process.cwd()){return validateCommerceAppConfig(await readCommerceAppConfig(cwd))}export{validateCommerceAppConfigDomain as a,getProjectRootDirectory as c,validateCommerceAppConfig as i,makeOutputDirFor as l,readCommerceAppConfig as n,detectPackageManager as o,resolveCommerceAppConfig as r,getExecCommand as s,parseCommerceAppConfig as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import*as v from"valibot";const ALPHANUMERIC_OR_UNDERSCORE_REGEX={any:/^[a-zA-Z0-9_]+$/,lowercase:/^[a-z0-9_]+$/,uppercase:/^[A-Z0-9_]+$/},ALPHANUMERIC_OR_HYPHEN_REGEX={any:/^[a-zA-Z0-9-]+$/,lowercase:/^[a-z0-9-]+$/,uppercase:/^[A-Z0-9-]+$/},TITLE_CASE_REGEX=/^[A-Z][a-z]*(?:\s[A-Z][a-z]*)*$/;function stringValueSchema(name){return v.string(`Expected a string value for '${name}'`)}function nonEmptyStringValueSchema(name){return v.pipe(stringValueSchema(name),v.nonEmpty(`The value of "${name}" must not be empty`))}function booleanValueSchema(name){return v.boolean(`Expected a boolean value for '${name}'`)}function alphaNumericOrUnderscoreSchema(name,casing=`any`){let casingLabel=casing===`any`?``:` (${casing} only)`;return v.pipe(stringValueSchema(name),v.regex(ALPHANUMERIC_OR_UNDERSCORE_REGEX[casing],`Only alphanumeric characters and underscores are allowed in string value of "${name}"${casingLabel}`))}function alphaNumericOrHyphenSchema(name,casing=`any`){let casingLabel=casing===`any`?``:` (${casing} only)`;return v.pipe(stringValueSchema(name),v.regex(ALPHANUMERIC_OR_HYPHEN_REGEX[casing],`Only alphanumeric characters and hyphens are allowed in string value of "${name}"${casingLabel}`))}function titleCaseSchema(name){return v.pipe(nonEmptyStringValueSchema(name),v.regex(TITLE_CASE_REGEX,`The value of "${name}" must be in Title Case, which means, an uppercase letter after each space (e.g., "Some Title Case")`))}export{stringValueSchema as a,nonEmptyStringValueSchema as i,alphaNumericOrUnderscoreSchema as n,titleCaseSchema as o,booleanValueSchema as r,alphaNumericOrHyphenSchema as t};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|