@netlify/config
Advanced tools
Comparing version 20.21.7 to 20.22.0
@@ -13,2 +13,3 @@ import { NetlifyAPI } from 'netlify'; | ||
siteFeatureFlagPrefix: string; | ||
token: string; | ||
}; | ||
@@ -24,3 +25,3 @@ /** | ||
*/ | ||
export declare const getSiteInfo: ({ api, siteId, accountId, mode, context, offline, testOpts, siteFeatureFlagPrefix, featureFlags, }: GetSiteInfoOpts) => Promise<{ | ||
export declare const getSiteInfo: ({ api, siteId, accountId, mode, context, offline, testOpts, siteFeatureFlagPrefix, token, featureFlags, }: GetSiteInfoOpts) => Promise<{ | ||
siteInfo: any; | ||
@@ -27,0 +28,0 @@ accounts: any; |
@@ -14,5 +14,4 @@ import fetch from 'node-fetch'; | ||
*/ | ||
export const getSiteInfo = async function ({ api, siteId, accountId, mode, context, offline = false, testOpts = {}, siteFeatureFlagPrefix, featureFlags = {}, }) { | ||
export const getSiteInfo = async function ({ api, siteId, accountId, mode, context, offline = false, testOpts = {}, siteFeatureFlagPrefix, token, featureFlags = {}, }) { | ||
const { env: testEnv = false } = testOpts; | ||
const errorOnExtensionFetchFail = featureFlags.error_builds_on_extension_fetch_fail; | ||
if (api === undefined || mode === 'buildbot' || testEnv) { | ||
@@ -25,3 +24,3 @@ const siteInfo = {}; | ||
const integrations = mode === 'buildbot' && !offline | ||
? await getIntegrations({ siteId, testOpts, offline, accountId, errorOnExtensionFetchFail }) | ||
? await getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags }) | ||
: []; | ||
@@ -34,3 +33,3 @@ return { siteInfo, accounts: [], addons: [], integrations }; | ||
getAddons(api, siteId), | ||
getIntegrations({ siteId, testOpts, offline, accountId, errorOnExtensionFetchFail }), | ||
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags }), | ||
]; | ||
@@ -77,6 +76,7 @@ const [siteInfo, accounts, addons, integrations] = await Promise.all(promises); | ||
}; | ||
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, errorOnExtensionFetchFail, }) { | ||
const getIntegrations = async function ({ siteId, accountId, testOpts, offline, token, featureFlags, }) { | ||
if (!siteId || offline) { | ||
return []; | ||
} | ||
const sendBuildBotTokenToJigsaw = featureFlags?.send_build_bot_token_to_jigsaw; | ||
const { host } = testOpts; | ||
@@ -88,27 +88,23 @@ const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`); | ||
: `${baseUrl}site/${siteId}/integrations/safe`; | ||
if (errorOnExtensionFetchFail) { | ||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Unexpected status code ${response.status} from fetching extensions`); | ||
} | ||
const bodyText = await response.text(); | ||
if (bodyText === '') { | ||
return []; | ||
} | ||
const integrations = await JSON.parse(bodyText); | ||
return Array.isArray(integrations) ? integrations : []; | ||
try { | ||
const requestOptions = {}; | ||
if (sendBuildBotTokenToJigsaw && token) { | ||
requestOptions.headers = { | ||
'netlify-sdk-build-bot-token': token, | ||
}; | ||
} | ||
catch (error) { | ||
return throwUserError(`Failed retrieving extensions for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`); | ||
const response = await fetch(url, requestOptions); | ||
if (!response.ok) { | ||
throw new Error(`Unexpected status code ${response.status} from fetching extensions`); | ||
} | ||
} | ||
try { | ||
const response = await fetch(url); | ||
const integrations = await response.json(); | ||
const bodyText = await response.text(); | ||
if (bodyText === '') { | ||
return []; | ||
} | ||
const integrations = await JSON.parse(bodyText); | ||
return Array.isArray(integrations) ? integrations : []; | ||
} | ||
catch { | ||
return []; | ||
catch (error) { | ||
return throwUserError(`Failed retrieving extensions for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`); | ||
} | ||
}; |
@@ -48,2 +48,3 @@ import { getApiClient } from './api/client.js'; | ||
testOpts, | ||
token, | ||
}); | ||
@@ -50,0 +51,0 @@ const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({ |
{ | ||
"name": "@netlify/config", | ||
"version": "20.21.7", | ||
"version": "20.22.0", | ||
"description": "Netlify config module", | ||
@@ -98,3 +98,3 @@ "type": "module", | ||
}, | ||
"gitHead": "09e899aeb71775da157dd9c02f41ceadeeb9f401" | ||
"gitHead": "b1de419113daee962ab37b1e75bcfc0d32f778e7" | ||
} |
3
166990
4021