diff --git a/.circleci/config.yml b/.circleci/config.yml index e14f6b77d..d571a6bac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -163,7 +163,7 @@ workflows: - vault filters: branches: - only: master + only: main requires: - test-built-app-18 - test-built-app-18-actions-functions diff --git a/packages/contentful--app-scripts/src/utils.ts b/packages/contentful--app-scripts/src/utils.ts index efd8c0fe9..68425c2b1 100644 --- a/packages/contentful--app-scripts/src/utils.ts +++ b/packages/contentful--app-scripts/src/utils.ts @@ -8,6 +8,17 @@ import { ContentfulFunction, FunctionAppAction } from './types'; const DEFAULT_MANIFEST_PATH = './contentful-app-manifest.json'; +const graphQLEvents = { + fieldMappingEvent: 'graphql.field.mapping', + queryEvent: 'graphql.query', +}; + +const appEvents = { + appEventFilter: 'appevent.filter', + appEventHandler: 'appevent.handler', + appEventTransformation: 'appevent.transformation', +}; + export const throwValidationException = (subject: string, message?: string, details?: string) => { console.log(`${chalk.red('Validation Error:')} Missing or invalid ${subject}.`); message && console.log(message); @@ -56,10 +67,10 @@ ${err.message} throw err; }; -export const selectFromList = async ( +export const selectFromList = async ( list: T[], message: string, - cachedOptionEnvVar: string, + cachedOptionEnvVar: string ): Promise => { const cachedEnvVar = process.env[cachedOptionEnvVar]; const cachedElement = list.find((item) => item.value === cachedEnvVar); @@ -86,9 +97,13 @@ export const selectFromList = async ( } }; -type Entities = Type extends 'actions' ? Omit[] : Omit[]; +type Entities = Type extends 'actions' + ? Omit[] + : Omit[]; -export function getEntityFromManifest(type: Type): Entities | undefined { +export function getEntityFromManifest( + type: Type +): Entities | undefined { const isManifestExists = fs.existsSync(DEFAULT_MANIFEST_PATH); if (!isManifestExists) { @@ -104,30 +119,28 @@ export function getEntityFromManifest(type logProgress( `${type === 'actions' ? 'App Actions' : 'functions'} found in ${chalk.bold( - DEFAULT_MANIFEST_PATH, - )}.`, + DEFAULT_MANIFEST_PATH + )}.` ); - const fieldMappingEvent = "graphql.field.mapping"; - const queryEvent = "graphql.query"; - const appEventFilter = 'appevent.filter'; - const items = (manifest[type] as FunctionAppAction[] | ContentfulFunction[]).map((item) => { const allowNetworks = Array.isArray(item.allowNetworks) ? item.allowNetworks.map(stripProtocol) : []; const accepts = 'accepts' in item && Array.isArray(item.accepts) ? item.accepts : undefined; - const hasInvalidEvent = accepts?.some((event) => ![fieldMappingEvent, queryEvent, appEventFilter].includes(event)); + const hasInvalidEvent = accepts?.some( + (event) => ![...Object.values(graphQLEvents), ...Object.values(appEvents)].includes(event) + ); const hasInvalidNetwork = allowNetworks.find((netWork) => !isValidNetwork(netWork)); if (hasInvalidNetwork) { console.log( `${chalk.red( - 'Error:', + 'Error:' )} Invalid IP address ${hasInvalidNetwork} found in the allowNetworks array for ${type} "${ item.name - }".`, + }".` ); // eslint-disable-next-line no-process-exit process.exit(1); @@ -135,10 +148,10 @@ export function getEntityFromManifest(type if (hasInvalidEvent) { console.log( `${chalk.red( - 'Error:', + 'Error:' )} Invalid events ${hasInvalidEvent} found in the accepts array for ${type} "${ item.name - }".`, + }".` ); // eslint-disable-next-line no-process-exit process.exit(1); @@ -159,8 +172,8 @@ export function getEntityFromManifest(type } catch { console.log( `${chalk.red('Error:')} Invalid JSON in manifest file at ${chalk.bold( - DEFAULT_MANIFEST_PATH, - )}.`, + DEFAULT_MANIFEST_PATH + )}.` ); // eslint-disable-next-line no-process-exit process.exit(1); diff --git a/packages/contentful--create-contentful-app/README.md b/packages/contentful--create-contentful-app/README.md index ccd65d0bb..59fd902b0 100644 --- a/packages/contentful--create-contentful-app/README.md +++ b/packages/contentful--create-contentful-app/README.md @@ -17,7 +17,7 @@ To start developing your first app, run: npx create-contentful-app my-first-app ``` -![Screenshot of `npx create-contentful-app my-app`](https://raw.githubusercontent.com/contentful/create-contentful-app/master/packages/contentful--create-contentful-app/docs/screenshot.png) +![Screenshot of `npx create-contentful-app my-app`](https://raw.githubusercontent.com/contentful/create-contentful-app/main/packages/contentful--create-contentful-app/docs/screenshot.png) ## Bootstrap diff --git a/packages/contentful--create-contentful-app/src/includeFunction.ts b/packages/contentful--create-contentful-app/src/includeFunction.ts index 0c87d6825..9930b0459 100644 --- a/packages/contentful--create-contentful-app/src/includeFunction.ts +++ b/packages/contentful--create-contentful-app/src/includeFunction.ts @@ -11,7 +11,12 @@ const addBuildCommand = getAddBuildCommandFn({ command: 'node build-functions.js', }); -const VALID_FUNCTION_TEMPLATES_DIRS = ['templates', 'appevent-filter']; +const VALID_FUNCTION_TEMPLATES_DIRS = [ + 'templates', + 'appevent-filter', + 'appevent-handler', + 'appevent-transformation', +]; function functionTemplateFromName(functionName: string) { let dirName = functionName;