Skip to content

Commit 978b3c3

Browse files
authored
fix: use staging url for extensions on staging (#6140)
* fix: use staging url for extensions on staging * fix: implement some feedback * fix: let production be fallback for extension api
1 parent 84b3c54 commit 978b3c3

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

packages/config/src/api/integrations.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@ import fetch from 'node-fetch'
22

33
import { TestOptions } from '../types/options.js'
44

5-
type AvailableIntegration = {
6-
slug: string
7-
hostSiteUrl: string
8-
hasBuild?: boolean
9-
}
5+
type AvailableIntegration = { slug: string; hostSiteUrl: string; hasBuild?: boolean }
106

11-
type GetAvailableIntegrationsOpts = {
12-
testOpts: TestOptions
13-
offline: boolean
14-
}
7+
type GetAvailableIntegrationsOpts = { testOpts: TestOptions; offline: boolean; extensionApiBaseUrl: string }
158

169
export const getAvailableIntegrations = async function ({
1710
testOpts,
1811
offline,
12+
extensionApiBaseUrl,
1913
}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
2014
if (offline) {
2115
return []
2216
}
2317
const { host } = testOpts
24-
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
18+
const baseUrl = new URL(host ? `http://${host}/` : extensionApiBaseUrl)
2519

2620
try {
2721
const response = await fetch(`${baseUrl}integrations`)

packages/config/src/api/site_info.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type GetSiteInfoOpts = {
1919
testOpts?: TestOptions
2020
siteFeatureFlagPrefix: string
2121
token: string
22+
extensionApiBaseUrl: string
2223
}
2324
/**
2425
* Retrieve Netlify Site information, if available.
@@ -40,6 +41,7 @@ export const getSiteInfo = async function ({
4041
siteFeatureFlagPrefix,
4142
token,
4243
featureFlags = {},
44+
extensionApiBaseUrl,
4345
}: GetSiteInfoOpts) {
4446
const { env: testEnv = false } = testOpts
4547

@@ -51,7 +53,7 @@ export const getSiteInfo = async function ({
5153

5254
const integrations =
5355
mode === 'buildbot' && !offline
54-
? await getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags })
56+
? await getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl })
5557
: []
5658

5759
return { siteInfo, accounts: [], addons: [], integrations }
@@ -61,7 +63,7 @@ export const getSiteInfo = async function ({
6163
getSite(api, siteId, siteFeatureFlagPrefix),
6264
getAccounts(api),
6365
getAddons(api, siteId),
64-
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags }),
66+
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl }),
6567
]
6668

6769
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
@@ -117,6 +119,7 @@ type GetIntegrationsOpts = {
117119
offline: boolean
118120
token?: string
119121
featureFlags?: Record<string, boolean>
122+
extensionApiBaseUrl: string
120123
}
121124

122125
const getIntegrations = async function ({
@@ -126,14 +129,14 @@ const getIntegrations = async function ({
126129
offline,
127130
token,
128131
featureFlags,
132+
extensionApiBaseUrl,
129133
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
130134
if (!siteId || offline) {
131135
return []
132136
}
133137
const sendBuildBotTokenToJigsaw = featureFlags?.send_build_bot_token_to_jigsaw
134138
const { host } = testOpts
135-
136-
const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)
139+
const baseUrl = new URL(host ? `http://${host}` : extensionApiBaseUrl)
137140

138141
// if accountId isn't present, use safe v1 endpoint
139142
const url = accountId

packages/config/src/integrations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type MergeIntegrationsOpts = {
99
context: string
1010
testOpts?: TestOptions
1111
offline: boolean
12+
extensionApiBaseUrl: string
1213
}
1314

1415
export const mergeIntegrations = async function ({
@@ -17,8 +18,9 @@ export const mergeIntegrations = async function ({
1718
context,
1819
testOpts = {},
1920
offline,
21+
extensionApiBaseUrl,
2022
}: MergeIntegrationsOpts): Promise<Integration[]> {
21-
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline })
23+
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline, extensionApiBaseUrl })
2224

2325
// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
2426
const resolvedApiIntegrations = apiIntegrations.filter(

packages/config/src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const resolveConfig = async function (opts) {
4949
return parsedCachedConfig
5050
}
5151

52+
// TODO(kh): remove this mapping and get the extensionApiHost from the opts
53+
const extensionApiBaseUrl =
54+
host === 'api-staging.netlify.com' ? 'https://api-staging.netlifysdk.com' : 'https://api.netlifysdk.com'
55+
5256
const {
5357
config: configOpt,
5458
defaultConfig,
@@ -81,6 +85,7 @@ export const resolveConfig = async function (opts) {
8185
featureFlags,
8286
testOpts,
8387
token,
88+
extensionApiBaseUrl,
8489
})
8590

8691
const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
@@ -131,6 +136,7 @@ export const resolveConfig = async function (opts) {
131136
context: context,
132137
testOpts,
133138
offline,
139+
extensionApiBaseUrl,
134140
})
135141

136142
const result = {

0 commit comments

Comments
 (0)