@netlify/config 21.0.5 → 21.0.7
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.d.ts +16 -3
- package/lib/api/site_info.js +43 -10
- package/lib/integrations.d.ts +2 -5
- package/lib/integrations.js +8 -8
- package/lib/main.d.ts +20 -1
- package/lib/main.js +3 -4
- package/package.json +2 -2
- package/lib/api/integrations.d.ts +0 -13
- package/lib/api/integrations.js +0 -19
package/lib/api/site_info.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NetlifyAPI } from 'netlify';
|
|
2
|
+
import { IntegrationResponse } from '../types/api.js';
|
|
2
3
|
import { ModeOption, TestOptions } from '../types/options.js';
|
|
3
4
|
type GetSiteInfoOpts = {
|
|
4
5
|
siteId: string;
|
|
@@ -24,8 +25,20 @@ type GetSiteInfoOpts = {
|
|
|
24
25
|
*/
|
|
25
26
|
export declare const getSiteInfo: ({ api, siteId, accountId, mode, context, offline, testOpts, siteFeatureFlagPrefix, token, featureFlags, extensionApiBaseUrl, }: GetSiteInfoOpts) => Promise<{
|
|
26
27
|
siteInfo: any;
|
|
27
|
-
accounts:
|
|
28
|
-
addons: any;
|
|
29
|
-
integrations:
|
|
28
|
+
accounts: MinimalAccount[];
|
|
29
|
+
addons: any[] | undefined;
|
|
30
|
+
integrations: IntegrationResponse[];
|
|
30
31
|
}>;
|
|
32
|
+
export type MinimalAccount = {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
slug: string;
|
|
36
|
+
default: boolean;
|
|
37
|
+
team_logo_url: string | null;
|
|
38
|
+
on_pro_trial: boolean;
|
|
39
|
+
organization_id: string | null;
|
|
40
|
+
type_name: string;
|
|
41
|
+
type_slug: string;
|
|
42
|
+
members_count: number;
|
|
43
|
+
};
|
|
31
44
|
export {};
|
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,17 +21,25 @@ 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
|
}
|
|
27
|
-
const
|
|
37
|
+
const [siteInfo, accounts, addons, integrations] = await Promise.all([
|
|
28
38
|
getSite(api, siteId, siteFeatureFlagPrefix),
|
|
29
39
|
getAccounts(api),
|
|
30
40
|
getAddons(api, siteId),
|
|
31
|
-
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl }),
|
|
32
|
-
];
|
|
33
|
-
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises);
|
|
41
|
+
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl, mode }),
|
|
42
|
+
]);
|
|
34
43
|
if (siteInfo.use_envelope) {
|
|
35
44
|
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context });
|
|
36
45
|
siteInfo.build_settings.env = envelope;
|
|
@@ -51,11 +60,13 @@ const getSite = async function (api, siteId, siteFeatureFlagPrefix) {
|
|
|
51
60
|
};
|
|
52
61
|
const getAccounts = async function (api) {
|
|
53
62
|
try {
|
|
54
|
-
const accounts = await api.listAccountsForUser(
|
|
63
|
+
const accounts = (await api.listAccountsForUser(
|
|
64
|
+
// @ts-expect-error(ndhoule): This is an unpublished, internal querystring parameter
|
|
65
|
+
{ minimal: 'true' }));
|
|
55
66
|
return Array.isArray(accounts) ? accounts : [];
|
|
56
67
|
}
|
|
57
68
|
catch (error) {
|
|
58
|
-
throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
|
|
69
|
+
return throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
|
|
59
70
|
}
|
|
60
71
|
};
|
|
61
72
|
const getAddons = async function (api, siteId) {
|
|
@@ -70,25 +81,47 @@ const getAddons = async function (api, siteId) {
|
|
|
70
81
|
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
|
|
71
82
|
}
|
|
72
83
|
};
|
|
73
|
-
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, token, featureFlags, extensionApiBaseUrl, }) {
|
|
84
|
+
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, token, featureFlags, extensionApiBaseUrl, mode, }) {
|
|
74
85
|
if (!siteId || offline) {
|
|
75
86
|
return [];
|
|
76
87
|
}
|
|
77
88
|
const sendBuildBotTokenToJigsaw = featureFlags?.send_build_bot_token_to_jigsaw;
|
|
78
|
-
const { host, setBaseUrl } = testOpts;
|
|
89
|
+
const { host: originalHost, setBaseUrl } = testOpts;
|
|
90
|
+
// TODO(kh): I am adding this purely for local staging development.
|
|
91
|
+
// We should remove this once we have fixed https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
|
|
92
|
+
let host = originalHost;
|
|
93
|
+
// If there is a host, we use it to fetch the integrations
|
|
94
|
+
// we check if the host is staging or production and set the host accordingly,
|
|
95
|
+
// sadly necessary because of https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
|
|
96
|
+
if (originalHost) {
|
|
97
|
+
if (originalHost?.includes(NETLIFY_API_STAGING_BASE_URL)) {
|
|
98
|
+
host = EXTENSION_API_STAGING_BASE_URL;
|
|
99
|
+
}
|
|
100
|
+
else if (originalHost?.includes(NETLIFY_API_BASE_URL)) {
|
|
101
|
+
host = EXTENSION_API_BASE_URL;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
host = `http://${originalHost}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const baseUrl = new URL(host ?? extensionApiBaseUrl);
|
|
79
108
|
// We only use this for testing
|
|
80
109
|
if (host && setBaseUrl) {
|
|
81
110
|
setBaseUrl(extensionApiBaseUrl);
|
|
82
111
|
}
|
|
83
|
-
const baseUrl = new URL(host ? `http://${host}` : extensionApiBaseUrl);
|
|
84
112
|
// if accountId isn't present, use safe v1 endpoint
|
|
85
113
|
const url = accountId
|
|
86
114
|
? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}`
|
|
87
115
|
: `${baseUrl}site/${siteId}/integrations/safe`;
|
|
88
116
|
try {
|
|
89
117
|
const requestOptions = {};
|
|
118
|
+
// This is used to identify where the request is coming from
|
|
119
|
+
requestOptions.headers = {
|
|
120
|
+
'netlify-config-mode': mode,
|
|
121
|
+
};
|
|
90
122
|
if (sendBuildBotTokenToJigsaw && token) {
|
|
91
123
|
requestOptions.headers = {
|
|
124
|
+
...requestOptions.headers,
|
|
92
125
|
'netlify-sdk-build-bot-token': token,
|
|
93
126
|
};
|
|
94
127
|
}
|
package/lib/integrations.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IntegrationResponse } from './types/api.js';
|
|
2
2
|
import { Integration } from './types/integrations.js';
|
|
3
|
-
import { TestOptions } from './types/options.js';
|
|
4
3
|
export declare const NETLIFY_API_STAGING_BASE_URL = "api-staging.netlify.com";
|
|
4
|
+
export declare const NETLIFY_API_BASE_URL = "api.netlify.com";
|
|
5
5
|
export declare const EXTENSION_API_BASE_URL = "https://api.netlifysdk.com";
|
|
6
6
|
export declare const EXTENSION_API_STAGING_BASE_URL = "https://api-staging.netlifysdk.com";
|
|
7
7
|
type MergeIntegrationsOpts = {
|
|
@@ -14,9 +14,6 @@ type MergeIntegrationsOpts = {
|
|
|
14
14
|
}[];
|
|
15
15
|
apiIntegrations: IntegrationResponse[];
|
|
16
16
|
context: string;
|
|
17
|
-
testOpts?: TestOptions;
|
|
18
|
-
offline: boolean;
|
|
19
|
-
extensionApiBaseUrl: string;
|
|
20
17
|
};
|
|
21
|
-
export declare const mergeIntegrations: ({ configIntegrations, apiIntegrations, context,
|
|
18
|
+
export declare const mergeIntegrations: ({ configIntegrations, apiIntegrations, context, }: MergeIntegrationsOpts) => Promise<Integration[]>;
|
|
22
19
|
export {};
|
package/lib/integrations.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getAvailableIntegrations } from './api/integrations.js';
|
|
2
1
|
export const NETLIFY_API_STAGING_BASE_URL = 'api-staging.netlify.com';
|
|
2
|
+
export const NETLIFY_API_BASE_URL = 'api.netlify.com';
|
|
3
3
|
export const EXTENSION_API_BASE_URL = 'https://api.netlifysdk.com';
|
|
4
4
|
export const EXTENSION_API_STAGING_BASE_URL = 'https://api-staging.netlifysdk.com';
|
|
5
|
-
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context,
|
|
6
|
-
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline, extensionApiBaseUrl });
|
|
5
|
+
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, }) {
|
|
7
6
|
// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
|
|
8
7
|
const resolvedApiIntegrations = apiIntegrations.filter((integration) => !configIntegrations.some((configIntegration) => configIntegration.name === integration.slug &&
|
|
9
8
|
typeof configIntegration.dev !== 'undefined' &&
|
|
@@ -14,19 +13,20 @@ export const mergeIntegrations = async function ({ configIntegrations = [], apiI
|
|
|
14
13
|
.filter((configIntegration) => apiIntegrations.every((apiIntegration) => apiIntegration.slug !== configIntegration.name) ||
|
|
15
14
|
('dev' in configIntegration && context === 'dev'))
|
|
16
15
|
.map((configIntegration) => {
|
|
16
|
+
const apiIntegration = apiIntegrations.find((apiIntegration) => apiIntegration.slug === configIntegration.name);
|
|
17
17
|
if (configIntegration.dev && context === 'dev') {
|
|
18
|
-
const integrationInstance = apiIntegrations.find((apiIntegration) => apiIntegration.slug === configIntegration.name);
|
|
19
18
|
return {
|
|
20
19
|
slug: configIntegration.name,
|
|
21
20
|
dev: configIntegration.dev,
|
|
22
|
-
|
|
21
|
+
// TODO(kh): has_build should become irrelevant soon as we are only returning extensions that have a build event handler.
|
|
22
|
+
has_build: apiIntegration?.has_build ?? configIntegration.dev?.force_run_in_build ?? false,
|
|
23
|
+
...apiIntegration,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
if (!integration) {
|
|
26
|
+
if (!apiIntegration) {
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
|
-
return
|
|
29
|
+
return apiIntegration;
|
|
30
30
|
})
|
|
31
31
|
.filter((i) => typeof i !== 'undefined');
|
|
32
32
|
return [...resolvedApiIntegrations, ...resolvedConfigIntegrations];
|
package/lib/main.d.ts
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import { type MinimalAccount } from './api/site_info.js';
|
|
2
|
+
export type Config = {
|
|
3
|
+
accounts: MinimalAccount[] | undefined;
|
|
4
|
+
addons: any;
|
|
5
|
+
api: any;
|
|
6
|
+
branch: any;
|
|
7
|
+
buildDir: any;
|
|
8
|
+
config: any;
|
|
9
|
+
configPath: any;
|
|
10
|
+
context: any;
|
|
11
|
+
env: any;
|
|
12
|
+
headersPath: any;
|
|
13
|
+
integrations: any;
|
|
14
|
+
logs: any;
|
|
15
|
+
redirectsPath: any;
|
|
16
|
+
repositoryRoot: any;
|
|
17
|
+
siteInfo: any;
|
|
18
|
+
token: any;
|
|
19
|
+
};
|
|
1
20
|
/**
|
|
2
21
|
* Load the configuration file.
|
|
3
22
|
* Takes an optional configuration file path as input and return the resolved
|
|
4
23
|
* `config` together with related properties such as the `configPath`.
|
|
5
24
|
*/
|
|
6
|
-
export declare const resolveConfig: (opts: any) => Promise<
|
|
25
|
+
export declare const resolveConfig: (opts: any) => Promise<Config>;
|
package/lib/main.js
CHANGED
|
@@ -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
|
|
@@ -105,9 +107,6 @@ export const resolveConfig = async function (opts) {
|
|
|
105
107
|
apiIntegrations: integrations,
|
|
106
108
|
configIntegrations: configA.integrations,
|
|
107
109
|
context: context,
|
|
108
|
-
testOpts,
|
|
109
|
-
offline,
|
|
110
|
-
extensionApiBaseUrl,
|
|
111
110
|
});
|
|
112
111
|
const result = {
|
|
113
112
|
siteInfo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "21.0.
|
|
3
|
+
"version": "21.0.7",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"engines": {
|
|
96
96
|
"node": "^14.16.0 || >=16.0.0"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "8d10878db3be9cfefe3162fd155c76595aba045e"
|
|
99
99
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TestOptions } from '../types/options.js';
|
|
2
|
-
type AvailableIntegration = {
|
|
3
|
-
slug: string;
|
|
4
|
-
hostSiteUrl: string;
|
|
5
|
-
hasBuild?: boolean;
|
|
6
|
-
};
|
|
7
|
-
type GetAvailableIntegrationsOpts = {
|
|
8
|
-
testOpts: TestOptions;
|
|
9
|
-
offline: boolean;
|
|
10
|
-
extensionApiBaseUrl: string;
|
|
11
|
-
};
|
|
12
|
-
export declare const getAvailableIntegrations: ({ testOpts, offline, extensionApiBaseUrl, }: GetAvailableIntegrationsOpts) => Promise<AvailableIntegration[]>;
|
|
13
|
-
export {};
|
package/lib/api/integrations.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
|
-
export const getAvailableIntegrations = async function ({ testOpts, offline, extensionApiBaseUrl, }) {
|
|
3
|
-
if (offline) {
|
|
4
|
-
return [];
|
|
5
|
-
}
|
|
6
|
-
const { host } = testOpts;
|
|
7
|
-
const baseUrl = new URL(host ? `http://${host}/` : extensionApiBaseUrl);
|
|
8
|
-
try {
|
|
9
|
-
const response = await fetch(`${baseUrl}integrations`);
|
|
10
|
-
if (response.ok) {
|
|
11
|
-
const integrations = (await response.json());
|
|
12
|
-
return Array.isArray(integrations) ? integrations : [];
|
|
13
|
-
}
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
};
|