@netlify/config 20.8.0 → 20.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.
- package/lib/api/integrations.js +16 -0
- package/lib/api/site_info.js +9 -8
- package/lib/edge_functions.js +9 -1
- package/lib/integrations.js +34 -0
- package/lib/main.js +8 -1
- package/lib/path.js +1 -0
- package/lib/types/integrations.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
export const getAvailableIntegrations = async function ({ testOpts, }) {
|
|
3
|
+
const { host } = testOpts;
|
|
4
|
+
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`);
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch(`${baseUrl}integrations`);
|
|
7
|
+
if (response.ok) {
|
|
8
|
+
const integrations = (await response.json());
|
|
9
|
+
return Array.isArray(integrations) ? integrations : [];
|
|
10
|
+
}
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
};
|
package/lib/api/site_info.js
CHANGED
|
@@ -11,19 +11,20 @@ import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
|
|
|
11
11
|
* Silently ignore API errors. For example the network connection might be down,
|
|
12
12
|
* but local builds should still work regardless.
|
|
13
13
|
*/
|
|
14
|
-
export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, offline = false,
|
|
14
|
+
export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, offline = false, testOpts = {}, }) {
|
|
15
15
|
const { env: testEnv = false } = testOpts;
|
|
16
|
-
const fetchIntegrations = featureFlags.buildbot_fetch_integrations;
|
|
17
16
|
if (api === undefined || mode === 'buildbot' || testEnv) {
|
|
18
17
|
const siteInfo = siteId === undefined ? {} : { id: siteId };
|
|
19
|
-
const integrations =
|
|
18
|
+
const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts }) : [];
|
|
20
19
|
return { siteInfo, accounts: [], addons: [], integrations };
|
|
21
20
|
}
|
|
22
|
-
const promises = [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const promises = [
|
|
22
|
+
getSite(api, siteId, siteFeatureFlagPrefix),
|
|
23
|
+
getAccounts(api),
|
|
24
|
+
getAddons(api, siteId),
|
|
25
|
+
getIntegrations({ siteId, testOpts }),
|
|
26
|
+
];
|
|
27
|
+
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises);
|
|
27
28
|
if (siteInfo.use_envelope) {
|
|
28
29
|
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId });
|
|
29
30
|
siteInfo.build_settings.env = envelope;
|
package/lib/edge_functions.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { isString, validProperties } from './validate/helpers.js';
|
|
2
2
|
const cacheValues = ['manual', 'off'];
|
|
3
|
+
const methodValues = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];
|
|
4
|
+
const isMethod = (value) => typeof value === 'string' && methodValues.includes(value.toUpperCase());
|
|
3
5
|
export const validations = [
|
|
4
6
|
{
|
|
5
7
|
property: 'edge_functions.*',
|
|
6
|
-
...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache'], []),
|
|
8
|
+
...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache', 'method'], []),
|
|
7
9
|
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
8
10
|
},
|
|
9
11
|
{
|
|
@@ -76,4 +78,10 @@ export const validations = [
|
|
|
76
78
|
message: `must be one of: ${cacheValues.join(', ')}`,
|
|
77
79
|
example: () => ({ edge_functions: [{ cache: cacheValues[0], path: '/hello', function: 'hello' }] }),
|
|
78
80
|
},
|
|
81
|
+
{
|
|
82
|
+
property: 'edge_functions.*.method',
|
|
83
|
+
check: (value) => isMethod(value) || (Array.isArray(value) && value.length !== 0 && value.every(isMethod)),
|
|
84
|
+
message: `must be one of or array of: ${methodValues.join(', ')}`,
|
|
85
|
+
example: () => ({ edge_functions: [{ method: ['PUT', 'DELETE'], path: '/hello', function: 'hello' }] }),
|
|
86
|
+
},
|
|
79
87
|
];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getAvailableIntegrations } from './api/integrations.js';
|
|
2
|
+
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, testOpts = {}, }) {
|
|
3
|
+
const availableIntegrations = await getAvailableIntegrations({ testOpts });
|
|
4
|
+
// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
|
|
5
|
+
const resolvedApiIntegrations = apiIntegrations.filter((integration) => !configIntegrations.some((configIntegration) => configIntegration.name === integration.slug &&
|
|
6
|
+
typeof configIntegration.dev !== 'undefined' &&
|
|
7
|
+
context === 'dev'));
|
|
8
|
+
// For integrations loaded from the TOML, we will use the local reference in the `dev` context,
|
|
9
|
+
// otherwise we will fetch from the API and match the slug
|
|
10
|
+
const resolvedConfigIntegrations = configIntegrations
|
|
11
|
+
.filter((configIntegration) => apiIntegrations.every((apiIntegration) => apiIntegration.slug !== configIntegration.name) ||
|
|
12
|
+
('dev' in configIntegration && context === 'dev'))
|
|
13
|
+
.map((configIntegration) => {
|
|
14
|
+
if (configIntegration.dev && context === 'dev') {
|
|
15
|
+
const integrationInstance = apiIntegrations.find((apiIntegration) => apiIntegration.slug === configIntegration.name);
|
|
16
|
+
return {
|
|
17
|
+
slug: configIntegration.name,
|
|
18
|
+
dev: configIntegration.dev,
|
|
19
|
+
has_build: integrationInstance?.has_build ?? configIntegration.dev?.force_run_in_build ?? false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const integration = availableIntegrations.find((availableIntegration) => availableIntegration.slug === configIntegration.name);
|
|
23
|
+
if (!integration) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
slug: integration.slug,
|
|
28
|
+
version: integration.hostSiteUrl,
|
|
29
|
+
has_build: !!integration.hasBuild,
|
|
30
|
+
};
|
|
31
|
+
})
|
|
32
|
+
.filter((i) => typeof i !== 'undefined');
|
|
33
|
+
return [...resolvedApiIntegrations, ...resolvedConfigIntegrations];
|
|
34
|
+
};
|
package/lib/main.js
CHANGED
|
@@ -9,6 +9,7 @@ import { getEnv } from './env/main.js';
|
|
|
9
9
|
import { resolveConfigPaths } from './files.js';
|
|
10
10
|
import { getHeadersPath, addHeaders } from './headers.js';
|
|
11
11
|
import { getInlineConfig } from './inline_config.js';
|
|
12
|
+
import { mergeIntegrations } from './integrations.js';
|
|
12
13
|
import { logResult } from './log/main.js';
|
|
13
14
|
import { mergeConfigs } from './merge.js';
|
|
14
15
|
import { normalizeBeforeConfigMerge, normalizeAfterConfigMerge } from './merge_normalize.js';
|
|
@@ -77,9 +78,15 @@ export const resolveConfig = async function (opts) {
|
|
|
77
78
|
});
|
|
78
79
|
// @todo Remove in the next major version.
|
|
79
80
|
const configA = addLegacyFunctionsDirectory(config);
|
|
81
|
+
const mergedIntegrations = await mergeIntegrations({
|
|
82
|
+
apiIntegrations: integrations,
|
|
83
|
+
configIntegrations: configA.integrations,
|
|
84
|
+
context: context,
|
|
85
|
+
testOpts,
|
|
86
|
+
});
|
|
80
87
|
const result = {
|
|
81
88
|
siteInfo,
|
|
82
|
-
integrations,
|
|
89
|
+
integrations: mergedIntegrations,
|
|
83
90
|
accounts,
|
|
84
91
|
addons,
|
|
85
92
|
env,
|
package/lib/path.js
CHANGED
|
@@ -6,6 +6,7 @@ const FILENAME = 'netlify.toml';
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration location can be:
|
|
8
8
|
* - a local path with the --config CLI flag
|
|
9
|
+
* - a `netlify.*` file in the `repositoryRoot/{base}/{packagePath}`
|
|
9
10
|
* - a `netlify.*` file in the `repositoryRoot/{base}`
|
|
10
11
|
* - a `netlify.*` file in the `repositoryRoot`
|
|
11
12
|
* - a `netlify.*` file in the current directory or any parent
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.9.0",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"engines": {
|
|
95
95
|
"node": "^14.16.0 || >=16.0.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "5521b954cc7944141d095434e39cce2af3d3ccaf"
|
|
98
98
|
}
|