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