@@ -4,6 +4,12 @@ import type { RequestInit } from 'node-fetch'
4
4
5
5
import { getEnvelope } from '../env/envelope.js'
6
6
import { throwUserError } from '../error.js'
7
+ import {
8
+ EXTENSION_API_BASE_URL ,
9
+ EXTENSION_API_STAGING_BASE_URL ,
10
+ NETLIFY_API_BASE_URL ,
11
+ NETLIFY_API_STAGING_BASE_URL ,
12
+ } from '../integrations.js'
7
13
import { ERROR_CALL_TO_ACTION } from '../log/messages.js'
8
14
import { IntegrationResponse } from '../types/api.js'
9
15
import { ModeOption , TestOptions } from '../types/options.js'
@@ -53,7 +59,16 @@ export const getSiteInfo = async function ({
53
59
54
60
const integrations =
55
61
mode === 'buildbot' && ! offline
56
- ? await getIntegrations ( { siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl } )
62
+ ? await getIntegrations ( {
63
+ siteId,
64
+ testOpts,
65
+ offline,
66
+ accountId,
67
+ token,
68
+ featureFlags,
69
+ extensionApiBaseUrl,
70
+ mode,
71
+ } )
57
72
: [ ]
58
73
59
74
return { siteInfo, accounts : [ ] , addons : [ ] , integrations }
@@ -63,7 +78,7 @@ export const getSiteInfo = async function ({
63
78
getSite ( api , siteId , siteFeatureFlagPrefix ) ,
64
79
getAccounts ( api ) ,
65
80
getAddons ( api , siteId ) ,
66
- getIntegrations ( { siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl } ) ,
81
+ getIntegrations ( { siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl, mode } ) ,
67
82
]
68
83
69
84
const [ siteInfo , accounts , addons , integrations ] = await Promise . all ( promises )
@@ -120,6 +135,7 @@ type GetIntegrationsOpts = {
120
135
token ?: string
121
136
featureFlags ?: Record < string , boolean >
122
137
extensionApiBaseUrl : string
138
+ mode : ModeOption
123
139
}
124
140
125
141
const getIntegrations = async function ( {
@@ -130,19 +146,36 @@ const getIntegrations = async function ({
130
146
token,
131
147
featureFlags,
132
148
extensionApiBaseUrl,
149
+ mode,
133
150
} : GetIntegrationsOpts ) : Promise < IntegrationResponse [ ] > {
134
151
if ( ! siteId || offline ) {
135
152
return [ ]
136
153
}
137
154
const sendBuildBotTokenToJigsaw = featureFlags ?. send_build_bot_token_to_jigsaw
138
- const { host, setBaseUrl } = testOpts
155
+ const { host : originalHost , setBaseUrl } = testOpts
156
+
157
+ // TODO(kh): I am adding this purely for local staging development.
158
+ // We should remove this once we have fixed https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
159
+ let host = originalHost
160
+
161
+ // If there is a host, we use it to fetch the integrations
162
+ // we check if the host is staging or production and set the host accordingly,
163
+ // sadly necessary because of https://github.com/netlify/cli/blob/b5a5c7525edd28925c5c2e3e5f0f00c4261eaba5/src/lib/build.ts#L125
164
+ if ( originalHost ) {
165
+ if ( originalHost ?. includes ( NETLIFY_API_STAGING_BASE_URL ) ) {
166
+ host = EXTENSION_API_STAGING_BASE_URL
167
+ } else if ( originalHost ?. includes ( NETLIFY_API_BASE_URL ) ) {
168
+ host = EXTENSION_API_BASE_URL
169
+ } else {
170
+ host = `http://${ originalHost } `
171
+ }
172
+ }
139
173
174
+ const baseUrl = new URL ( host ?? extensionApiBaseUrl )
140
175
// We only use this for testing
141
176
if ( host && setBaseUrl ) {
142
177
setBaseUrl ( extensionApiBaseUrl )
143
178
}
144
-
145
- const baseUrl = new URL ( host ? `http://${ host } ` : extensionApiBaseUrl )
146
179
// if accountId isn't present, use safe v1 endpoint
147
180
const url = accountId
148
181
? `${ baseUrl } team/${ accountId } /integrations/installations/meta/${ siteId } `
@@ -151,8 +184,14 @@ const getIntegrations = async function ({
151
184
try {
152
185
const requestOptions = { } as RequestInit
153
186
187
+ // This is used to identify where the request is coming from
188
+ requestOptions . headers = {
189
+ 'netlify-config-mode' : mode ,
190
+ }
191
+
154
192
if ( sendBuildBotTokenToJigsaw && token ) {
155
193
requestOptions . headers = {
194
+ ...requestOptions . headers ,
156
195
'netlify-sdk-build-bot-token' : token ,
157
196
}
158
197
}
0 commit comments