@netlify/config 21.0.4 → 21.0.6
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 +41 -5
- package/lib/integrations.d.ts +4 -0
- package/lib/integrations.js +5 -5
- package/lib/main.js +7 -25
- package/lib/types/options.d.ts +1 -0
- package/package.json +3 -3
package/lib/api/site_info.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import { getEnvelope } from '../env/envelope.js';
|
|
3
3
|
import { throwUserError } from '../error.js';
|
|
4
|
+
import { EXTENSION_API_BASE_URL, EXTENSION_API_STAGING_BASE_URL, NETLIFY_API_BASE_URL, NETLIFY_API_STAGING_BASE_URL, } from '../integrations.js';
|
|
4
5
|
import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
|
|
5
6
|
/**
|
|
6
7
|
* Retrieve Netlify Site information, if available.
|
|
@@ -20,7 +21,16 @@ export const getSiteInfo = async function ({ api, siteId, accountId, mode, conte
|
|
|
20
21
|
if (accountId !== undefined)
|
|
21
22
|
siteInfo.account_id = accountId;
|
|
22
23
|
const integrations = mode === 'buildbot' && !offline
|
|
23
|
-
? await getIntegrations({
|
|
24
|
+
? await getIntegrations({
|
|
25
|
+
siteId,
|
|
26
|
+
testOpts,
|
|
27
|
+
offline,
|
|
28
|
+
accountId,
|
|
29
|
+
token,
|
|
30
|
+
featureFlags,
|
|
31
|
+
extensionApiBaseUrl,
|
|
32
|
+
mode,
|
|
33
|
+
})
|
|
24
34
|
: [];
|
|
25
35
|
return { siteInfo, accounts: [], addons: [], integrations };
|
|
26
36
|
}
|
|
@@ -28,7 +38,7 @@ export const getSiteInfo = async function ({ api, siteId, accountId, mode, conte
|
|
|
28
38
|
getSite(api, siteId, siteFeatureFlagPrefix),
|
|
29
39
|
getAccounts(api),
|
|
30
40
|
getAddons(api, siteId),
|
|
31
|
-
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl }),
|
|
41
|
+
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl, mode }),
|
|
32
42
|
];
|
|
33
43
|
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises);
|
|
34
44
|
if (siteInfo.use_envelope) {
|
|
@@ -70,21 +80,47 @@ const getAddons = async function (api, siteId) {
|
|
|
70
80
|
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
|
|
71
81
|
}
|
|
72
82
|
};
|
|
73
|
-
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, token, featureFlags, extensionApiBaseUrl, }) {
|
|
83
|
+
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, token, featureFlags, extensionApiBaseUrl, mode, }) {
|
|
74
84
|
if (!siteId || offline) {
|
|
75
85
|
return [];
|
|
76
86
|
}
|
|
77
87
|
const sendBuildBotTokenToJigsaw = featureFlags?.send_build_bot_token_to_jigsaw;
|
|
78
|
-
const { host } = testOpts;
|
|
79
|
-
|
|
88
|
+
const { host: originalHost, setBaseUrl } = testOpts;
|
|
89
|
+
// TODO(kh): I am adding this purely for local staging development.
|
|
90
|
+
// We should remove this once we have fixed https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
|
|
91
|
+
let host = originalHost;
|
|
92
|
+
// If there is a host, we use it to fetch the integrations
|
|
93
|
+
// we check if the host is staging or production and set the host accordingly,
|
|
94
|
+
// sadly necessary because of https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
|
|
95
|
+
if (originalHost) {
|
|
96
|
+
if (originalHost?.includes(NETLIFY_API_STAGING_BASE_URL)) {
|
|
97
|
+
host = EXTENSION_API_STAGING_BASE_URL;
|
|
98
|
+
}
|
|
99
|
+
else if (originalHost?.includes(NETLIFY_API_BASE_URL)) {
|
|
100
|
+
host = EXTENSION_API_BASE_URL;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
host = `http://${originalHost}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const baseUrl = new URL(host ?? extensionApiBaseUrl);
|
|
107
|
+
// We only use this for testing
|
|
108
|
+
if (host && setBaseUrl) {
|
|
109
|
+
setBaseUrl(extensionApiBaseUrl);
|
|
110
|
+
}
|
|
80
111
|
// if accountId isn't present, use safe v1 endpoint
|
|
81
112
|
const url = accountId
|
|
82
113
|
? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}`
|
|
83
114
|
: `${baseUrl}site/${siteId}/integrations/safe`;
|
|
84
115
|
try {
|
|
85
116
|
const requestOptions = {};
|
|
117
|
+
// This is used to identify where the request is coming from
|
|
118
|
+
requestOptions.headers = {
|
|
119
|
+
'netlify-config-mode': mode,
|
|
120
|
+
};
|
|
86
121
|
if (sendBuildBotTokenToJigsaw && token) {
|
|
87
122
|
requestOptions.headers = {
|
|
123
|
+
...requestOptions.headers,
|
|
88
124
|
'netlify-sdk-build-bot-token': token,
|
|
89
125
|
};
|
|
90
126
|
}
|
package/lib/integrations.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { IntegrationResponse } from './types/api.js';
|
|
2
2
|
import { Integration } from './types/integrations.js';
|
|
3
3
|
import { TestOptions } from './types/options.js';
|
|
4
|
+
export declare const NETLIFY_API_STAGING_BASE_URL = "api-staging.netlify.com";
|
|
5
|
+
export declare const NETLIFY_API_BASE_URL = "api.netlify.com";
|
|
6
|
+
export declare const EXTENSION_API_BASE_URL = "https://api.netlifysdk.com";
|
|
7
|
+
export declare const EXTENSION_API_STAGING_BASE_URL = "https://api-staging.netlifysdk.com";
|
|
4
8
|
type MergeIntegrationsOpts = {
|
|
5
9
|
configIntegrations?: {
|
|
6
10
|
name: string;
|
package/lib/integrations.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { getAvailableIntegrations } from './api/integrations.js';
|
|
2
|
+
export const NETLIFY_API_STAGING_BASE_URL = 'api-staging.netlify.com';
|
|
3
|
+
export const NETLIFY_API_BASE_URL = 'api.netlify.com';
|
|
4
|
+
export const EXTENSION_API_BASE_URL = 'https://api.netlifysdk.com';
|
|
5
|
+
export const EXTENSION_API_STAGING_BASE_URL = 'https://api-staging.netlifysdk.com';
|
|
2
6
|
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, testOpts = {}, offline, extensionApiBaseUrl, }) {
|
|
3
7
|
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline, extensionApiBaseUrl });
|
|
4
8
|
// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
|
|
@@ -23,11 +27,7 @@ export const mergeIntegrations = async function ({ configIntegrations = [], apiI
|
|
|
23
27
|
if (!integration) {
|
|
24
28
|
return undefined;
|
|
25
29
|
}
|
|
26
|
-
return {
|
|
27
|
-
slug: integration.slug,
|
|
28
|
-
version: integration.hostSiteUrl,
|
|
29
|
-
has_build: !!integration.hasBuild,
|
|
30
|
-
};
|
|
30
|
+
return { slug: integration.slug, version: integration.hostSiteUrl, has_build: !!integration.hasBuild };
|
|
31
31
|
})
|
|
32
32
|
.filter((i) => typeof i !== 'undefined');
|
|
33
33
|
return [...resolvedApiIntegrations, ...resolvedConfigIntegrations];
|
package/lib/main.js
CHANGED
|
@@ -9,7 +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
|
+
import { EXTENSION_API_BASE_URL, EXTENSION_API_STAGING_BASE_URL, mergeIntegrations, NETLIFY_API_STAGING_BASE_URL, } from './integrations.js';
|
|
13
13
|
import { logResult } from './log/main.js';
|
|
14
14
|
import { mergeConfigs } from './merge.js';
|
|
15
15
|
import { normalizeBeforeConfigMerge, normalizeAfterConfigMerge } from './merge_normalize.js';
|
|
@@ -35,7 +35,9 @@ export const resolveConfig = async function (opts) {
|
|
|
35
35
|
return parsedCachedConfig;
|
|
36
36
|
}
|
|
37
37
|
// TODO(kh): remove this mapping and get the extensionApiHost from the opts
|
|
38
|
-
const extensionApiBaseUrl = host
|
|
38
|
+
const extensionApiBaseUrl = host?.includes(NETLIFY_API_STAGING_BASE_URL)
|
|
39
|
+
? EXTENSION_API_STAGING_BASE_URL
|
|
40
|
+
: EXTENSION_API_BASE_URL;
|
|
39
41
|
const { config: configOpt, defaultConfig, inlineConfig, configMutations, cwd, context, repositoryRoot, base, branch, siteId, accountId, deployId, buildId, baseRelDir, mode, debug, logs, featureFlags, } = await normalizeOpts(optsA);
|
|
40
42
|
let { siteInfo, accounts, addons, integrations } = parsedCachedConfig || {};
|
|
41
43
|
// If we have cached site info, we don't need to fetch it again
|
|
@@ -138,13 +140,7 @@ const addLegacyFunctionsDirectory = (config) => {
|
|
|
138
140
|
if (!config.functionsDirectory) {
|
|
139
141
|
return config;
|
|
140
142
|
}
|
|
141
|
-
return {
|
|
142
|
-
...config,
|
|
143
|
-
build: {
|
|
144
|
-
...config.build,
|
|
145
|
-
functions: config.functionsDirectory,
|
|
146
|
-
},
|
|
147
|
-
};
|
|
143
|
+
return { ...config, build: { ...config.build, functions: config.functionsDirectory } };
|
|
148
144
|
};
|
|
149
145
|
/**
|
|
150
146
|
* Try to load the configuration file in two passes.
|
|
@@ -202,24 +198,10 @@ const loadConfig = async function ({ configOpt, cwd, context, repositoryRoot, pa
|
|
|
202
198
|
* Load configuration file and normalize it, merge contexts, etc.
|
|
203
199
|
*/
|
|
204
200
|
const getFullConfig = async function ({ configOpt, cwd, context, repositoryRoot, packagePath, branch, defaultConfig, inlineConfig, baseRelDir, configBase, base, logs, featureFlags, }) {
|
|
205
|
-
const configPath = await getConfigPath({
|
|
206
|
-
configOpt,
|
|
207
|
-
cwd,
|
|
208
|
-
repositoryRoot,
|
|
209
|
-
packagePath,
|
|
210
|
-
configBase,
|
|
211
|
-
});
|
|
201
|
+
const configPath = await getConfigPath({ configOpt, cwd, repositoryRoot, packagePath, configBase });
|
|
212
202
|
try {
|
|
213
203
|
const config = await parseConfig(configPath);
|
|
214
|
-
const configA = mergeAndNormalizeConfig({
|
|
215
|
-
config,
|
|
216
|
-
defaultConfig,
|
|
217
|
-
inlineConfig,
|
|
218
|
-
context,
|
|
219
|
-
branch,
|
|
220
|
-
logs,
|
|
221
|
-
packagePath,
|
|
222
|
-
});
|
|
204
|
+
const configA = mergeAndNormalizeConfig({ config, defaultConfig, inlineConfig, context, branch, logs, packagePath });
|
|
223
205
|
const { config: configB, buildDir, base: baseA, } = await resolveFiles({ packagePath, config: configA, repositoryRoot, base, baseRelDir });
|
|
224
206
|
const headersPath = getHeadersPath(configB);
|
|
225
207
|
const configC = await addHeaders({ config: configB, headersPath, logs });
|
package/lib/types/options.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "21.0.
|
|
3
|
+
"version": "21.0.6",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"is-plain-obj": "^4.0.0",
|
|
75
75
|
"js-yaml": "^4.0.0",
|
|
76
76
|
"map-obj": "^5.0.0",
|
|
77
|
-
"netlify": "^13.3.
|
|
77
|
+
"netlify": "^13.3.4",
|
|
78
78
|
"node-fetch": "^3.3.1",
|
|
79
79
|
"omit.js": "^2.0.2",
|
|
80
80
|
"p-locate": "^6.0.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"engines": {
|
|
96
96
|
"node": "^14.16.0 || >=16.0.0"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "761c1e087c92c4cf579050e686a5869da5b3ce00"
|
|
99
99
|
}
|