Skip to content

fix: use staging url for extensions on staging #6140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/config/src/api/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import fetch from 'node-fetch'

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

type AvailableIntegration = {
slug: string
hostSiteUrl: string
hasBuild?: boolean
}
type AvailableIntegration = { slug: string; hostSiteUrl: string; hasBuild?: boolean }

type GetAvailableIntegrationsOpts = {
testOpts: TestOptions
offline: boolean
}
type GetAvailableIntegrationsOpts = { testOpts: TestOptions; offline: boolean; extensionApiBaseUrl: string }

export const getAvailableIntegrations = async function ({
testOpts,
offline,
extensionApiBaseUrl,
}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
if (offline) {
return []
}
const { host } = testOpts
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
const baseUrl = new URL(host ? `http://${host}/` : extensionApiBaseUrl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever want to connect to the API over HTTP?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same thing, but I think the assumption here is that the passed in testOpts.host is a local server for testing, so it uses http.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean because of the http://${host}/?


try {
const response = await fetch(`${baseUrl}integrations`)
Expand Down
11 changes: 7 additions & 4 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type GetSiteInfoOpts = {
testOpts?: TestOptions
siteFeatureFlagPrefix: string
token: string
extensionApiBaseUrl: string
}
/**
* Retrieve Netlify Site information, if available.
Expand All @@ -40,6 +41,7 @@ export const getSiteInfo = async function ({
siteFeatureFlagPrefix,
token,
featureFlags = {},
extensionApiBaseUrl,
}: GetSiteInfoOpts) {
const { env: testEnv = false } = testOpts

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

const integrations =
mode === 'buildbot' && !offline
? await getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags })
? await getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl })
: []

return { siteInfo, accounts: [], addons: [], integrations }
Expand All @@ -61,7 +63,7 @@ export const getSiteInfo = async function ({
getSite(api, siteId, siteFeatureFlagPrefix),
getAccounts(api),
getAddons(api, siteId),
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags }),
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl }),
]

const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
Expand Down Expand Up @@ -117,6 +119,7 @@ type GetIntegrationsOpts = {
offline: boolean
token?: string
featureFlags?: Record<string, boolean>
extensionApiBaseUrl: string
}

const getIntegrations = async function ({
Expand All @@ -126,14 +129,14 @@ const getIntegrations = async function ({
offline,
token,
featureFlags,
extensionApiBaseUrl,
}: GetIntegrationsOpts): Promise<IntegrationResponse[]> {
if (!siteId || offline) {
return []
}
const sendBuildBotTokenToJigsaw = featureFlags?.send_build_bot_token_to_jigsaw
const { host } = testOpts

const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)
const baseUrl = new URL(host ? `http://${host}` : extensionApiBaseUrl)

// if accountId isn't present, use safe v1 endpoint
const url = accountId
Expand Down
4 changes: 3 additions & 1 deletion packages/config/src/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type MergeIntegrationsOpts = {
context: string
testOpts?: TestOptions
offline: boolean
extensionApiBaseUrl: string
}

export const mergeIntegrations = async function ({
Expand All @@ -17,8 +18,9 @@ export const mergeIntegrations = async function ({
context,
testOpts = {},
offline,
extensionApiBaseUrl,
}: MergeIntegrationsOpts): Promise<Integration[]> {
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline })
const availableIntegrations = await getAvailableIntegrations({ testOpts, offline, extensionApiBaseUrl })

// Include all API integrations, unless they have a `dev` property and we are in the `dev` context
const resolvedApiIntegrations = apiIntegrations.filter(
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const resolveConfig = async function (opts) {
return parsedCachedConfig
}

// TODO(kh): remove this mapping and get the extensionApiHost from the opts
const extensionApiBaseUrl =
host === 'api-staging.netlify.com' ? 'https://api-staging.netlifysdk.com' : 'https://api.netlifysdk.com'

const {
config: configOpt,
defaultConfig,
Expand Down Expand Up @@ -81,6 +85,7 @@ export const resolveConfig = async function (opts) {
featureFlags,
testOpts,
token,
extensionApiBaseUrl,
})

const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
Expand Down Expand Up @@ -131,6 +136,7 @@ export const resolveConfig = async function (opts) {
context: context,
testOpts,
offline,
extensionApiBaseUrl,
})

const result = {
Expand Down
Loading