11import { NetlifyAPI } from 'netlify'
22import fetch from 'node-fetch'
3+ import type { RequestInit } from 'node-fetch'
34
45import { getEnvelope } from '../env/envelope.js'
56import { throwUserError } from '../error.js'
@@ -17,6 +18,7 @@ type GetSiteInfoOpts = {
1718 featureFlags ?: Record < string , boolean >
1819 testOpts ?: TestOptions
1920 siteFeatureFlagPrefix : string
21+ token : string
2022}
2123/**
2224 * Retrieve Netlify Site information, if available.
@@ -36,6 +38,8 @@ export const getSiteInfo = async function ({
3638 offline = false ,
3739 testOpts = { } ,
3840 siteFeatureFlagPrefix,
41+ token,
42+ featureFlags = { } ,
3943} : GetSiteInfoOpts ) {
4044 const { env : testEnv = false } = testOpts
4145
@@ -46,7 +50,9 @@ export const getSiteInfo = async function ({
4650 if ( accountId !== undefined ) siteInfo . account_id = accountId
4751
4852 const integrations =
49- mode === 'buildbot' && ! offline ? await getIntegrations ( { siteId, testOpts, offline, accountId } ) : [ ]
53+ mode === 'buildbot' && ! offline
54+ ? await getIntegrations ( { siteId, testOpts, offline, accountId, token, featureFlags } )
55+ : [ ]
5056
5157 return { siteInfo, accounts : [ ] , addons : [ ] , integrations }
5258 }
@@ -55,7 +61,7 @@ export const getSiteInfo = async function ({
5561 getSite ( api , siteId , siteFeatureFlagPrefix ) ,
5662 getAccounts ( api ) ,
5763 getAddons ( api , siteId ) ,
58- getIntegrations ( { siteId, testOpts, offline, accountId } ) ,
64+ getIntegrations ( { siteId, testOpts, offline, accountId, token , featureFlags } ) ,
5965 ]
6066
6167 const [ siteInfo , accounts , addons , integrations ] = await Promise . all ( promises )
@@ -109,18 +115,22 @@ type GetIntegrationsOpts = {
109115 accountId ?: string
110116 testOpts : TestOptions
111117 offline : boolean
118+ token ?: string
119+ featureFlags ?: Record < string , boolean >
112120}
113121
114122const getIntegrations = async function ( {
115123 siteId,
116124 accountId,
117125 testOpts,
118126 offline,
127+ token,
128+ featureFlags,
119129} : GetIntegrationsOpts ) : Promise < IntegrationResponse [ ] > {
120130 if ( ! siteId || offline ) {
121131 return [ ]
122132 }
123-
133+ const sendBuildBotTokenToJigsaw = featureFlags ?. send_build_bot_token_to_jigsaw
124134 const { host } = testOpts
125135
126136 const baseUrl = new URL ( host ? `http://${ host } ` : `https://api.netlifysdk.com` )
@@ -131,7 +141,15 @@ const getIntegrations = async function ({
131141 : `${ baseUrl } site/${ siteId } /integrations/safe`
132142
133143 try {
134- const response = await fetch ( url )
144+ const requestOptions = { } as RequestInit
145+
146+ if ( sendBuildBotTokenToJigsaw && token ) {
147+ requestOptions . headers = {
148+ 'netlify-sdk-build-bot-token' : token ,
149+ }
150+ }
151+
152+ const response = await fetch ( url , requestOptions )
135153 if ( ! response . ok ) {
136154 throw new Error ( `Unexpected status code ${ response . status } from fetching extensions` )
137155 }
0 commit comments