@contentful/app-scripts 1.8.2 → 1.9.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.
@@ -0,0 +1,62 @@
1
+ const assert = require('assert');
2
+
3
+ const { isValidNetwork, stripProtocol } = require('./utils');
4
+
5
+ describe('isValidIpAddress', () => {
6
+ it('returns true for a valid IP address', () => {
7
+ const result = isValidNetwork('192.168.0.1');
8
+ assert.strictEqual(result, true);
9
+ });
10
+
11
+ it('returns true for a valid domain', () => {
12
+ const result = isValidNetwork('google.com');
13
+ assert.strictEqual(result, true);
14
+ });
15
+
16
+ it('returns true for a valid ipv6 address', () => {
17
+ const result = isValidNetwork('2001:0db8:85a3:0000:0000:8a2e:0370:7334');
18
+ assert.strictEqual(result, true);
19
+ });
20
+
21
+ it('returns true for a valid domain with port', () => {
22
+ const result = isValidNetwork('google.com:4000');
23
+ assert.strictEqual(result, true);
24
+ });
25
+
26
+ it('returns true for a valid IP address with port', () => {
27
+ const result = isValidNetwork('192.168.0.1:2000');
28
+ assert.strictEqual(result, true);
29
+ });
30
+
31
+ it('returns false for an invalid IP address', () => {
32
+ const result = isValidNetwork('not an ip address');
33
+ assert.strictEqual(result, false);
34
+ });
35
+
36
+ it('returns true for an valid ipv6 address with port', () => {
37
+ const result = isValidNetwork('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443');
38
+ assert.strictEqual(result, true);
39
+ });
40
+ });
41
+
42
+ describe('removeProtocolFromUrl', () => {
43
+ it('returns the host of a URL without a protocol', () => {
44
+ const result = stripProtocol('http://example.com');
45
+ assert.strictEqual(result, 'example.com');
46
+ });
47
+
48
+ it('returns valid ipv6 address', () => {
49
+ const result = stripProtocol('http://[2001:0db8:85a3:0000:0000:8a2e:0370]:7334');
50
+ assert.strictEqual(result, '[2001:0db8:85a3:0000:0000:8a2e:0370]:7334');
51
+ });
52
+
53
+ it('returns valid domain', () => {
54
+ const result = stripProtocol('example.com');
55
+ assert.strictEqual(result, 'example.com');
56
+ });
57
+
58
+ it('returns valid domain with port', () => {
59
+ const result = stripProtocol('example.com:40');
60
+ assert.strictEqual(result, 'example.com:40');
61
+ });
62
+ });
package/lib/utils.js CHANGED
@@ -13,6 +13,18 @@ const throwValidationException = (subject, message, details) => {
13
13
  throw new TypeError(message);
14
14
  };
15
15
 
16
+ const isValidNetwork = (address) => {
17
+ const addressRegex =
18
+ /^(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}|(?:\d{1,3}\.){3}\d{1,3}|(\[(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\]|(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}))(?::\d{1,5})?$/;
19
+ return addressRegex.test(address);
20
+ };
21
+
22
+ const stripProtocol = (url) => {
23
+ const protocolRemovedUrl = url.replace(/^https?:\/\//, '');
24
+
25
+ return protocolRemovedUrl.split('/')[0];
26
+ };
27
+
16
28
  const showCreationError = (subject, message) => {
17
29
  console.log(`
18
30
  ${chalk.red('Creation error:')}
@@ -81,7 +93,33 @@ function getActionsManifest() {
81
93
  ----------------------------`);
82
94
  console.log('');
83
95
 
84
- return manifest.actions.map((action) => ({ parameters: [], ...action })); // adding required parameters
96
+ const actions = manifest.actions.map((action) => {
97
+ const allowedNetworks = Array.isArray(action.allowedNetworks)
98
+ ? allowedNetworks.map(stripProtocol)
99
+ : [];
100
+
101
+ const hasInvalidNetwork = allowedNetworks.find((netWork) => !isValidNetwork(netWork));
102
+
103
+ if (hasInvalidNetwork) {
104
+ console.log(
105
+ `${chalk.red(
106
+ 'Error:'
107
+ )} Invalid IP address ${hasInvalidNetwork} found in the allowedNetworks array for action "${
108
+ action.name
109
+ }".`
110
+ );
111
+ // eslint-disable-next-line no-process-exit
112
+ process.exit(1);
113
+ }
114
+
115
+ return {
116
+ parameters: [],
117
+ ...action,
118
+ allowedNetworks,
119
+ };
120
+ });
121
+
122
+ return actions;
85
123
  } catch {
86
124
  console.log(
87
125
  `${chalk.red('Error:')} Invalid JSON in manifest file at ${chalk.bold(
@@ -99,4 +137,6 @@ module.exports = {
99
137
  selectFromList,
100
138
  showCreationError,
101
139
  getActionsManifest,
140
+ isValidNetwork,
141
+ stripProtocol,
102
142
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/app-scripts",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "A collection of scripts for building Contentful Apps",
5
5
  "author": "Contentful GmbH",
6
6
  "license": "MIT",
@@ -61,5 +61,5 @@
61
61
  "open": "8.4.2",
62
62
  "ora": "5.4.1"
63
63
  },
64
- "gitHead": "43e318bc4b0ce268d1e40cf91b2116debf48e93f"
64
+ "gitHead": "63817dc3be779cc5bf2258d955618069bbeecbe5"
65
65
  }