@contentful/app-scripts 1.17.0 → 1.19.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.
@@ -10,12 +10,16 @@ const validate_bundle_1 = require("./validate-bundle");
10
10
  const utils_1 = require("../utils");
11
11
  const contentful_management_1 = require("contentful-management");
12
12
  async function createAppBundleFromFile(orgId, token, zip, host = '') {
13
- const client = (0, contentful_management_1.createClient)({ accessToken: token, host, hostUpload: host.replace(/^api/i, 'upload') });
13
+ const client = (0, contentful_management_1.createClient)({
14
+ accessToken: token,
15
+ host,
16
+ hostUpload: host.replace(/^api/i, 'upload'),
17
+ });
14
18
  const org = await client.getOrganization(orgId);
15
19
  return await org.createAppUpload(zip);
16
20
  }
17
21
  async function createAppUpload(settings) {
18
- (0, validate_bundle_1.validateBundle)(settings.bundleDirectory || '.');
22
+ (0, validate_bundle_1.validateBundle)(settings.bundleDirectory || '.', settings);
19
23
  let appUpload = null;
20
24
  const zipFileSpinner = (0, ora_1.default)('Preparing your files for upload...').start();
21
25
  const zipFile = await (0, create_zip_from_directory_1.createZipFileFromDirectory)(settings.bundleDirectory || '../types');
@@ -1 +1,2 @@
1
- export declare const validateBundle: (path: string) => void;
1
+ import { UploadSettings } from '../types';
2
+ export declare const validateBundle: (path: string, { functions, actions }: Pick<UploadSettings, 'functions' | 'actions'>) => void;
@@ -8,14 +8,14 @@ const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
10
  const ACCEPTED_ENTRY_FILES = ['index.html'];
11
- const getEntryFile = (files) => files.find(file => ACCEPTED_ENTRY_FILES.includes(file));
11
+ const getEntryFile = (files) => files.find((file) => ACCEPTED_ENTRY_FILES.includes(file));
12
12
  const ABSOLUTE_PATH_REG_EXP = /(src|href)="\/([^/])([^"]*)+"/g;
13
13
  const fileContainsAbsolutePath = (fileContent) => {
14
14
  return [...fileContent.matchAll(ABSOLUTE_PATH_REG_EXP)].length > 0;
15
15
  };
16
- const validateBundle = (path) => {
16
+ const validateBundle = (path, { functions, actions }) => {
17
17
  const buildFolder = path_1.default.join('./', path);
18
- const files = fs_1.default.readdirSync(buildFolder);
18
+ const files = fs_1.default.readdirSync(buildFolder, { recursive: true, encoding: 'utf-8' });
19
19
  const entry = getEntryFile(files);
20
20
  if (!entry) {
21
21
  throw new Error('Make sure your bundle includes a valid index.html file in its root folder.');
@@ -26,5 +26,17 @@ const validateBundle = (path) => {
26
26
  console.warn(`${chalk_1.default.red('Warning:')} This bundle uses absolute paths. Please use relative paths instead for correct rendering. See more details here https://www.contentful.com/developers/docs/extensibility/app-framework/app-bundle/#limitations`);
27
27
  console.log('----------------------------');
28
28
  }
29
+ if (functions) {
30
+ const functionWithoutEntryFile = functions.find(({ path }) => !files.includes(path));
31
+ if (functionWithoutEntryFile) {
32
+ throw new Error(`Function "${functionWithoutEntryFile.id}" is missing its entry file at "${path_1.default.join(buildFolder, functionWithoutEntryFile.path)}".`);
33
+ }
34
+ }
35
+ if (actions) {
36
+ const actionWithoutEntryFile = actions.find(({ path }) => !files.includes(path));
37
+ if (actionWithoutEntryFile) {
38
+ throw new Error(`Action "${actionWithoutEntryFile.id}" is missing its entry file at "${path_1.default.join(buildFolder, actionWithoutEntryFile.path)}".`);
39
+ }
40
+ }
29
41
  };
30
42
  exports.validateBundle = validateBundle;
package/lib/utils.js CHANGED
@@ -9,6 +9,15 @@ const chalk_1 = __importDefault(require("chalk"));
9
9
  const inquirer_1 = __importDefault(require("inquirer"));
10
10
  const cache_credential_1 = require("./cache-credential");
11
11
  const DEFAULT_MANIFEST_PATH = './contentful-app-manifest.json';
12
+ const graphQLEvents = {
13
+ fieldMappingEvent: 'graphql.field.mapping',
14
+ queryEvent: 'graphql.query',
15
+ };
16
+ const appEvents = {
17
+ appEventFilter: 'appevent.filter',
18
+ appEventHandler: 'appevent.handler',
19
+ appEventTransformation: 'appevent.transformation',
20
+ };
12
21
  const throwValidationException = (subject, message, details) => {
13
22
  console.log(`${chalk_1.default.red('Validation Error:')} Missing or invalid ${subject}.`);
14
23
  message && console.log(message);
@@ -87,15 +96,12 @@ function getEntityFromManifest(type) {
87
96
  return;
88
97
  }
89
98
  logProgress(`${type === 'actions' ? 'App Actions' : 'functions'} found in ${chalk_1.default.bold(DEFAULT_MANIFEST_PATH)}.`);
90
- const fieldMappingEvent = "graphql.field.mapping";
91
- const queryEvent = "graphql.query";
92
- const appEventFilter = 'appevent.filter';
93
99
  const items = manifest[type].map((item) => {
94
100
  const allowNetworks = Array.isArray(item.allowNetworks)
95
101
  ? item.allowNetworks.map(exports.stripProtocol)
96
102
  : [];
97
103
  const accepts = 'accepts' in item && Array.isArray(item.accepts) ? item.accepts : undefined;
98
- const hasInvalidEvent = accepts?.some((event) => ![fieldMappingEvent, queryEvent, appEventFilter].includes(event));
104
+ const hasInvalidEvent = accepts?.some((event) => ![...Object.values(graphQLEvents), ...Object.values(appEvents)].includes(event));
99
105
  const hasInvalidNetwork = allowNetworks.find((netWork) => !(0, exports.isValidNetwork)(netWork));
100
106
  if (hasInvalidNetwork) {
101
107
  console.log(`${chalk_1.default.red('Error:')} Invalid IP address ${hasInvalidNetwork} found in the allowNetworks array for ${type} "${item.name}".`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/app-scripts",
3
- "version": "1.17.0",
3
+ "version": "1.19.0",
4
4
  "description": "A collection of scripts for building Contentful Apps",
5
5
  "author": "Contentful GmbH",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "bottleneck": "2.19.5",
53
53
  "chalk": "4.1.2",
54
54
  "commander": "12.0.0",
55
- "contentful-management": "11.23.0",
55
+ "contentful-management": "11.24.5",
56
56
  "dotenv": "16.4.5",
57
57
  "ignore": "5.3.1",
58
58
  "inquirer": "8.2.6",
@@ -60,9 +60,9 @@
60
60
  "open": "8.4.2",
61
61
  "ora": "5.4.1"
62
62
  },
63
- "gitHead": "7576b84daf5069f42177cd8d43117f5f3c7056be",
63
+ "gitHead": "42e054adc754dae0657882b09f1ab7adcc9adecf",
64
64
  "devDependencies": {
65
- "@tsconfig/node18": "18.2.2",
65
+ "@tsconfig/node18": "18.2.4",
66
66
  "@types/adm-zip": "0.5.5",
67
67
  "@types/analytics-node": "3.1.14",
68
68
  "@types/inquirer": "8.2.1",