@netlify/config 20.5.1 → 20.6.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/lib/api/site_info.js +28 -7
- package/lib/edge_functions.js +47 -3
- package/lib/main.js +9 -1
- package/package.json +5 -4
package/lib/api/site_info.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
1
2
|
import { getEnvelope } from '../env/envelope.js';
|
|
2
3
|
import { throwUserError } from '../error.js';
|
|
3
4
|
import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
|
|
@@ -8,21 +9,22 @@ import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
|
|
|
8
9
|
// Requires knowing the `siteId` and having the access `token`.
|
|
9
10
|
// Silently ignore API errors. For example the network connection might be down,
|
|
10
11
|
// but local builds should still work regardless.
|
|
11
|
-
export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, testOpts: { env: testEnv = true } = {}, }) {
|
|
12
|
+
export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, featureFlags = {}, testOpts: { env: testEnv = true } = {}, }) {
|
|
12
13
|
if (api === undefined || mode === 'buildbot' || !testEnv) {
|
|
13
14
|
const siteInfo = siteId === undefined ? {} : { id: siteId };
|
|
14
15
|
return { siteInfo, accounts: [], addons: [] };
|
|
15
16
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const fetchIntegrations = featureFlags.buildbot_fetch_integrations;
|
|
18
|
+
const promises = [getSite(api, siteId, siteFeatureFlagPrefix), getAccounts(api), getAddons(api, siteId)];
|
|
19
|
+
if (fetchIntegrations) {
|
|
20
|
+
promises.push(getIntegrations({ api, ownerType: 'site', ownerId: siteId }));
|
|
21
|
+
}
|
|
22
|
+
const [siteInfo, accounts, addons, integrations = []] = await Promise.all(promises);
|
|
21
23
|
if (siteInfo.use_envelope) {
|
|
22
24
|
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId });
|
|
23
25
|
siteInfo.build_settings.env = envelope;
|
|
24
26
|
}
|
|
25
|
-
return { siteInfo, accounts, addons };
|
|
27
|
+
return { siteInfo, accounts, addons, integrations: integrations ?? [] };
|
|
26
28
|
};
|
|
27
29
|
const getSite = async function (api, siteId, siteFeatureFlagPrefix = null) {
|
|
28
30
|
if (siteId === undefined) {
|
|
@@ -57,3 +59,22 @@ const getAddons = async function (api, siteId) {
|
|
|
57
59
|
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
|
|
58
60
|
}
|
|
59
61
|
};
|
|
62
|
+
const getIntegrations = async function ({ api, ownerType, ownerId }) {
|
|
63
|
+
if (ownerId === undefined) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const token = api.accessToken();
|
|
68
|
+
const response = await fetch(`https://api.netlifysdk.com/${ownerType}/${ownerId}/integrations`, {
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: `Bearer ${token}`,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const integrations = await response.json();
|
|
74
|
+
return Array.isArray(integrations) ? integrations : [];
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// for now, we'll just ignore errors, as this is early days
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
};
|
package/lib/edge_functions.js
CHANGED
|
@@ -3,13 +3,19 @@ const cacheValues = ['manual', 'off'];
|
|
|
3
3
|
export const validations = [
|
|
4
4
|
{
|
|
5
5
|
property: 'edge_functions.*',
|
|
6
|
-
...validProperties(['path', 'function', 'cache'], []),
|
|
6
|
+
...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache'], []),
|
|
7
7
|
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
property: 'edge_functions.*',
|
|
11
|
-
check: (edgeFunction) => edgeFunction.path !== undefined,
|
|
12
|
-
message: '"path"
|
|
11
|
+
check: (edgeFunction) => edgeFunction.path !== undefined || edgeFunction.pattern !== undefined,
|
|
12
|
+
message: 'either "path" or "pattern" is required.',
|
|
13
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
property: 'edge_functions.*',
|
|
17
|
+
check: (edgeFunction) => !(edgeFunction.path !== undefined && edgeFunction.pattern !== undefined),
|
|
18
|
+
message: '"path" and "pattern" are mutually exclusive.',
|
|
13
19
|
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
14
20
|
},
|
|
15
21
|
{
|
|
@@ -24,6 +30,44 @@ export const validations = [
|
|
|
24
30
|
message: 'must be a string.',
|
|
25
31
|
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
26
32
|
},
|
|
33
|
+
{
|
|
34
|
+
property: 'edge_functions.*.excludedPath',
|
|
35
|
+
check: (value) => isString(value) || (Array.isArray(value) && value.every(isString)),
|
|
36
|
+
message: 'must be a string or array of strings.',
|
|
37
|
+
example: () => ({
|
|
38
|
+
edge_functions: [{ path: '/products/*', excludedPath: ['/products/*.jpg'], function: 'customise' }],
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
property: 'edge_functions.*',
|
|
43
|
+
check: (value) => value.excludedPath === undefined || value.path !== undefined,
|
|
44
|
+
message: '"excludedPath" can only be specified together with "path".',
|
|
45
|
+
example: () => ({
|
|
46
|
+
edge_functions: [{ path: '/products/*', excludedPath: ['/products/*.jpg'], function: 'customise' }],
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
property: 'edge_functions.*.pattern',
|
|
51
|
+
check: isString,
|
|
52
|
+
message: 'must be a string.',
|
|
53
|
+
example: () => ({ edge_functions: [{ pattern: '/hello/(.*)', function: 'hello' }] }),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
property: 'edge_functions.*.excludedPattern',
|
|
57
|
+
check: (value) => isString(value) || (Array.isArray(value) && value.every(isString)),
|
|
58
|
+
message: 'must be a string or array of strings.',
|
|
59
|
+
example: () => ({
|
|
60
|
+
edge_functions: [{ path: '/products/(.*)', excludedPath: ['/products/(.*)\\.jpg'], function: 'customise' }],
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
property: 'edge_functions.*.excludedPattern',
|
|
65
|
+
check: (value) => value.excludedPattern === undefined || value.pattern !== undefined,
|
|
66
|
+
message: '"excludedPattern" can only be specified together with "pattern".',
|
|
67
|
+
example: () => ({
|
|
68
|
+
edge_functions: [{ path: '/products/(.*)', excludedPath: ['/products/(.*)\\.jpg'], function: 'customise' }],
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
27
71
|
{
|
|
28
72
|
property: 'edge_functions.*.function',
|
|
29
73
|
check: isString,
|
package/lib/main.js
CHANGED
|
@@ -29,7 +29,14 @@ export const resolveConfig = async function (opts) {
|
|
|
29
29
|
return parsedCachedConfig;
|
|
30
30
|
}
|
|
31
31
|
const { config: configOpt, defaultConfig, inlineConfig, configMutations, cwd, context, repositoryRoot, base, branch, siteId, deployId, buildId, baseRelDir, mode, debug, logs, featureFlags, } = await normalizeOpts(optsA);
|
|
32
|
-
const { siteInfo, accounts, addons } = await getSiteInfo({
|
|
32
|
+
const { siteInfo, accounts, addons, integrations } = await getSiteInfo({
|
|
33
|
+
api,
|
|
34
|
+
siteId,
|
|
35
|
+
mode,
|
|
36
|
+
testOpts,
|
|
37
|
+
siteFeatureFlagPrefix,
|
|
38
|
+
featureFlags,
|
|
39
|
+
});
|
|
33
40
|
const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
|
|
34
41
|
defaultConfig,
|
|
35
42
|
base,
|
|
@@ -68,6 +75,7 @@ export const resolveConfig = async function (opts) {
|
|
|
68
75
|
const configA = addLegacyFunctionsDirectory(config);
|
|
69
76
|
const result = {
|
|
70
77
|
siteInfo,
|
|
78
|
+
integrations,
|
|
71
79
|
accounts,
|
|
72
80
|
addons,
|
|
73
81
|
env,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.6.0",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -70,9 +70,10 @@
|
|
|
70
70
|
"is-plain-obj": "^4.0.0",
|
|
71
71
|
"js-yaml": "^4.0.0",
|
|
72
72
|
"map-obj": "^5.0.0",
|
|
73
|
-
"netlify": "^13.1.
|
|
73
|
+
"netlify": "^13.1.10",
|
|
74
74
|
"netlify-headers-parser": "^7.1.2",
|
|
75
75
|
"netlify-redirect-parser": "^14.1.3",
|
|
76
|
+
"node-fetch": "^3.3.1",
|
|
76
77
|
"omit.js": "^2.0.2",
|
|
77
78
|
"p-locate": "^6.0.0",
|
|
78
79
|
"path-type": "^5.0.0",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
"yargs": "^17.6.0"
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
|
-
"@types/node": "^18.
|
|
86
|
+
"@types/node": "^14.18.53",
|
|
86
87
|
"ava": "^4.0.0",
|
|
87
88
|
"c8": "^7.12.0",
|
|
88
89
|
"has-ansi": "^5.0.0",
|
|
@@ -93,5 +94,5 @@
|
|
|
93
94
|
"engines": {
|
|
94
95
|
"node": "^14.16.0 || >=16.0.0"
|
|
95
96
|
},
|
|
96
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "34f833bce745039add76a082f8dcfd682f9f7de0"
|
|
97
98
|
}
|