@netlify/config 21.0.5 → 22.0.0-rc
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 +1 -0
- package/lib/integrations.js +1 -0
- package/lib/main.d.ts +20 -1
- package/lib/main.js +3 -1
- package/package.json +4 -5
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
|
@@ -2,6 +2,7 @@ import { IntegrationResponse } from './types/api.js';
|
|
|
2
2
|
import { Integration } from './types/integrations.js';
|
|
3
3
|
import { TestOptions } from './types/options.js';
|
|
4
4
|
export declare const NETLIFY_API_STAGING_BASE_URL = "api-staging.netlify.com";
|
|
5
|
+
export declare const NETLIFY_API_BASE_URL = "api.netlify.com";
|
|
5
6
|
export declare const EXTENSION_API_BASE_URL = "https://api.netlifysdk.com";
|
|
6
7
|
export declare const EXTENSION_API_STAGING_BASE_URL = "https://api-staging.netlifysdk.com";
|
|
7
8
|
type MergeIntegrationsOpts = {
|
package/lib/integrations.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getAvailableIntegrations } from './api/integrations.js';
|
|
2
2
|
export const NETLIFY_API_STAGING_BASE_URL = 'api-staging.netlify.com';
|
|
3
|
+
export const NETLIFY_API_BASE_URL = 'api.netlify.com';
|
|
3
4
|
export const EXTENSION_API_BASE_URL = 'https://api.netlifysdk.com';
|
|
4
5
|
export const EXTENSION_API_STAGING_BASE_URL = 'https://api-staging.netlifysdk.com';
|
|
5
6
|
export const mergeIntegrations = async function ({ configIntegrations = [], apiIntegrations, context, testOpts = {}, offline, extensionApiBaseUrl, }) {
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0-rc",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -59,8 +59,6 @@
|
|
|
59
59
|
"license": "MIT",
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@iarna/toml": "^2.2.5",
|
|
62
|
-
"@netlify/headers-parser": "^8.0.0",
|
|
63
|
-
"@netlify/redirect-parser": "^14.5.1",
|
|
64
62
|
"chalk": "^5.0.0",
|
|
65
63
|
"cron-parser": "^4.1.0",
|
|
66
64
|
"deepmerge": "^4.2.2",
|
|
@@ -75,6 +73,8 @@
|
|
|
75
73
|
"js-yaml": "^4.0.0",
|
|
76
74
|
"map-obj": "^5.0.0",
|
|
77
75
|
"netlify": "^13.3.4",
|
|
76
|
+
"@netlify/headers-parser": "^8.0.0",
|
|
77
|
+
"@netlify/redirect-parser": "^14.5.1",
|
|
78
78
|
"node-fetch": "^3.3.1",
|
|
79
79
|
"omit.js": "^2.0.2",
|
|
80
80
|
"p-locate": "^6.0.0",
|
|
@@ -94,6 +94,5 @@
|
|
|
94
94
|
},
|
|
95
95
|
"engines": {
|
|
96
96
|
"node": "^14.16.0 || >=16.0.0"
|
|
97
|
-
}
|
|
98
|
-
"gitHead": "0e4628f57a0a7d02594b5070074445a4ff69b809"
|
|
97
|
+
}
|
|
99
98
|
}
|