1
1
import { NetlifyAPI } from 'netlify'
2
2
import fetch from 'node-fetch'
3
+ import type { RequestInit } from 'node-fetch'
3
4
4
5
import { getEnvelope } from '../env/envelope.js'
5
6
import { throwUserError } from '../error.js'
@@ -17,6 +18,7 @@ type GetSiteInfoOpts = {
17
18
featureFlags ?: Record < string , boolean >
18
19
testOpts ?: TestOptions
19
20
siteFeatureFlagPrefix : string
21
+ token : string
20
22
}
21
23
/**
22
24
* Retrieve Netlify Site information, if available.
@@ -36,6 +38,8 @@ export const getSiteInfo = async function ({
36
38
offline = false ,
37
39
testOpts = { } ,
38
40
siteFeatureFlagPrefix,
41
+ token,
42
+ featureFlags = { } ,
39
43
} : GetSiteInfoOpts ) {
40
44
const { env : testEnv = false } = testOpts
41
45
@@ -46,7 +50,9 @@ export const getSiteInfo = async function ({
46
50
if ( accountId !== undefined ) siteInfo . account_id = accountId
47
51
48
52
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
+ : [ ]
50
56
51
57
return { siteInfo, accounts : [ ] , addons : [ ] , integrations }
52
58
}
@@ -55,7 +61,7 @@ export const getSiteInfo = async function ({
55
61
getSite ( api , siteId , siteFeatureFlagPrefix ) ,
56
62
getAccounts ( api ) ,
57
63
getAddons ( api , siteId ) ,
58
- getIntegrations ( { siteId, testOpts, offline, accountId } ) ,
64
+ getIntegrations ( { siteId, testOpts, offline, accountId, token , featureFlags } ) ,
59
65
]
60
66
61
67
const [ siteInfo , accounts , addons , integrations ] = await Promise . all ( promises )
@@ -109,18 +115,22 @@ type GetIntegrationsOpts = {
109
115
accountId ?: string
110
116
testOpts : TestOptions
111
117
offline : boolean
118
+ token ?: string
119
+ featureFlags ?: Record < string , boolean >
112
120
}
113
121
114
122
const getIntegrations = async function ( {
115
123
siteId,
116
124
accountId,
117
125
testOpts,
118
126
offline,
127
+ token,
128
+ featureFlags,
119
129
} : GetIntegrationsOpts ) : Promise < IntegrationResponse [ ] > {
120
130
if ( ! siteId || offline ) {
121
131
return [ ]
122
132
}
123
-
133
+ const sendBuildBotTokenToJigsaw = featureFlags ?. send_build_bot_token_to_jigsaw
124
134
const { host } = testOpts
125
135
126
136
const baseUrl = new URL ( host ? `http://${ host } ` : `https://api.netlifysdk.com` )
@@ -131,7 +141,15 @@ const getIntegrations = async function ({
131
141
: `${ baseUrl } site/${ siteId } /integrations/safe`
132
142
133
143
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 )
135
153
if ( ! response . ok ) {
136
154
throw new Error ( `Unexpected status code ${ response . status } from fetching extensions` )
137
155
}
0 commit comments