-
Notifications
You must be signed in to change notification settings - Fork 78
feat: retrieve integration meta data from new endpoint #5647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
d596237
12cdb9d
8d0ec67
ebeebdd
f271f78
a39c459
876602b
9e5dec2
16e8eae
18cc081
2db6580
7fa8c19
4dd7b86
3fae809
2e34fa7
f510e19
7bf6d8f
d56db4a
3f8f4e1
83b6ead
1f4992f
5606943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ type GetSiteInfoOpts = { | |
offline?: boolean | ||
api?: NetlifyAPI | ||
context?: string | ||
featureFlags?: Record<string, boolean> | ||
testOpts?: TestOptions | ||
} | ||
/** | ||
|
@@ -37,30 +36,58 @@ export const getSiteInfo = async function ({ | |
}: GetSiteInfoOpts) { | ||
const { env: testEnv = false } = testOpts | ||
|
||
if (api === undefined || mode === 'buildbot' || testEnv) { | ||
if (api === undefined || testEnv || offline) { | ||
const siteInfo = siteId === undefined ? {} : { id: siteId } | ||
|
||
const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : [] | ||
|
||
return { siteInfo, accounts: [], addons: [], integrations } | ||
return { siteInfo, accounts: [], addons: [], integrations: [] } | ||
} | ||
|
||
const promises = [ | ||
getSite(api, siteId, siteFeatureFlagPrefix), | ||
getAccounts(api), | ||
getAddons(api, siteId), | ||
getIntegrations({ siteId, testOpts, offline }), | ||
] | ||
const siteInfo = await getSite(api, siteId, siteFeatureFlagPrefix) | ||
const featureFlags = siteInfo.feature_flags | ||
|
||
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises) | ||
const useV2Endpoint = featureFlags?.cli_integration_installations_meta | ||
|
||
if (siteInfo.use_envelope) { | ||
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context }) | ||
if (useV2Endpoint) { | ||
const promises = [ | ||
getAccounts(api), | ||
getAddons(api, siteId), | ||
getIntegrations({ siteId, testOpts, offline, accountId: siteInfo.account_id, featureFlags }), | ||
] | ||
|
||
siteInfo.build_settings.env = envelope | ||
} | ||
const [accounts, addons, integrations] = await Promise.all(promises) | ||
|
||
if (siteInfo.use_envelope) { | ||
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context }) | ||
|
||
siteInfo.build_settings.env = envelope | ||
} | ||
|
||
return { siteInfo, accounts, addons, integrations } | ||
} else { | ||
lemusthelroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (mode === 'buildbot') { | ||
const siteInfo = siteId === undefined ? {} : { id: siteId } | ||
|
||
const integrations = await getIntegrations({ siteId, testOpts, offline, featureFlags }) | ||
|
||
return { siteInfo, accounts: [], addons: [], integrations } | ||
} | ||
|
||
const promises = [ | ||
getAccounts(api), | ||
getAddons(api, siteId), | ||
getIntegrations({ siteId, testOpts, offline, featureFlags }), | ||
] | ||
|
||
return { siteInfo, accounts, addons, integrations } | ||
const [accounts, addons, integrations] = await Promise.all(promises) | ||
|
||
if (siteInfo.use_envelope) { | ||
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context }) | ||
|
||
siteInfo.build_settings.env = envelope | ||
} | ||
|
||
return { siteInfo, accounts, addons, integrations } | ||
} | ||
} | ||
|
||
const getSite = async function (api: NetlifyAPI, siteId: string, siteFeatureFlagPrefix: string | null = null) { | ||
|
@@ -73,6 +100,8 @@ const getSite = async function (api: NetlifyAPI, siteId: string, siteFeatureFlag | |
return { ...site, id: siteId } | ||
} catch (error) { | ||
throwUserError(`Failed retrieving site data for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`) | ||
// Added to satisfy TypeScript only an object can be returned | ||
return { id: siteId } | ||
lemusthelroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
|
@@ -82,6 +111,8 @@ const getAccounts = async function (api: NetlifyAPI) { | |
return Array.isArray(accounts) ? accounts : [] | ||
} catch (error) { | ||
throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`) | ||
// Added to satisfy TypeScript only an array can be returned | ||
return [] | ||
lemusthelroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
|
@@ -95,19 +126,25 @@ const getAddons = async function (api: NetlifyAPI, siteId: string) { | |
return Array.isArray(addons) ? addons : [] | ||
} catch (error) { | ||
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`) | ||
// Added to satisfy TypeScript only an array can be returned | ||
lemusthelroy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return [] | ||
} | ||
} | ||
|
||
type GetIntegrationsOpts = { | ||
siteId?: string | ||
accountId?: string | ||
testOpts: TestOptions | ||
offline: boolean | ||
featureFlags?: Record<string, boolean> | ||
} | ||
|
||
const getIntegrations = async function ({ | ||
siteId, | ||
accountId, | ||
testOpts, | ||
offline, | ||
featureFlags, | ||
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> { | ||
if (!siteId || offline) { | ||
return [] | ||
|
@@ -117,13 +154,20 @@ const getIntegrations = async function ({ | |
|
||
const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`) | ||
|
||
const useV2Endpoint = featureFlags?.cli_integration_installations_meta | ||
|
||
const url = useV2Endpoint | ||
? `${baseUrl}team/${accountId}/integrations/installations/meta` | ||
: `${baseUrl}site/${siteId}/integrations/safe` | ||
|
||
try { | ||
const response = await fetch(`${baseUrl}site/${siteId}/integrations/safe`) | ||
const response = await fetch(url) | ||
|
||
const integrations = await response.json() | ||
return Array.isArray(integrations) ? integrations : [] | ||
} catch (error) { | ||
// for now, we'll just ignore errors, as this is early days | ||
// Integrations should not block the build if they fail to load | ||
// TODO: We should consider blocking the build as integrations are a critical part of the build process | ||
lemusthelroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return [] | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.