From 60c4cc8ad19a002e1838df36511460d8b65f14a0 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Thu, 5 Dec 2024 16:59:39 -0500 Subject: [PATCH 1/6] chore: remove released feature flag for future state v2 --- packages/config/src/api/site_info.ts | 50 ++++------------------------ 1 file changed, 6 insertions(+), 44 deletions(-) diff --git a/packages/config/src/api/site_info.ts b/packages/config/src/api/site_info.ts index 699219768d..aa76ab8fa0 100644 --- a/packages/config/src/api/site_info.ts +++ b/packages/config/src/api/site_info.ts @@ -35,53 +35,20 @@ export const getSiteInfo = async function ({ context, offline = false, testOpts = {}, - featureFlags = {}, siteFeatureFlagPrefix, }: GetSiteInfoOpts) { const { env: testEnv = false } = testOpts - const useV2Endpoint = !!accountId && featureFlags.cli_integration_installations_meta - - if (useV2Endpoint) { - if (api === undefined || mode === 'buildbot' || testEnv) { - const siteInfo: { id?: string; account_id?: string } = {} - - if (siteId !== undefined) siteInfo.id = siteId - if (accountId !== undefined) siteInfo.account_id = accountId - - const integrations = - mode === 'buildbot' && !offline - ? await getIntegrations({ siteId, testOpts, offline, useV2Endpoint, accountId }) - : [] - - return { siteInfo, accounts: [], addons: [], integrations } - } - - const promises = [ - getSite(api, siteId, siteFeatureFlagPrefix), - getAccounts(api), - getAddons(api, siteId), - getIntegrations({ siteId, testOpts, offline, useV2Endpoint, accountId }), - ] - - const [siteInfo, accounts, addons, integrations] = await Promise.all(promises) - - if (siteInfo.use_envelope) { - const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context }) - - siteInfo.build_settings.env = envelope - } - - return { siteInfo, accounts, addons, integrations } - } - if (api === undefined || mode === 'buildbot' || testEnv) { const siteInfo: { id?: string; account_id?: string } = {} if (siteId !== undefined) siteInfo.id = siteId if (accountId !== undefined) siteInfo.account_id = accountId - const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : [] + const integrations = + mode === 'buildbot' && !offline + ? await getIntegrations({ siteId, testOpts, offline, accountId }) + : [] return { siteInfo, accounts: [], addons: [], integrations } } @@ -90,7 +57,7 @@ export const getSiteInfo = async function ({ getSite(api, siteId, siteFeatureFlagPrefix), getAccounts(api), getAddons(api, siteId), - getIntegrations({ siteId, testOpts, offline }), + getIntegrations({ siteId, testOpts, offline, accountId }), ] const [siteInfo, accounts, addons, integrations] = await Promise.all(promises) @@ -144,7 +111,6 @@ type GetIntegrationsOpts = { accountId?: string testOpts: TestOptions offline: boolean - useV2Endpoint?: boolean } const getIntegrations = async function ({ @@ -152,7 +118,6 @@ const getIntegrations = async function ({ accountId, testOpts, offline, - useV2Endpoint, }: GetIntegrationsOpts): Promise { if (!siteId || offline) { return [] @@ -162,10 +127,7 @@ const getIntegrations = async function ({ const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`) - // use future state feature flag - const url = useV2Endpoint - ? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}` - : `${baseUrl}site/${siteId}/integrations/safe` + const url = `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}` try { const response = await fetch(url) From 13a610899bca443e55b482ffd59c7d7ebf468412 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Thu, 5 Dec 2024 17:13:48 -0500 Subject: [PATCH 2/6] chore: format --- packages/config/src/api/site_info.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/config/src/api/site_info.ts b/packages/config/src/api/site_info.ts index aa76ab8fa0..4e80ba8e06 100644 --- a/packages/config/src/api/site_info.ts +++ b/packages/config/src/api/site_info.ts @@ -46,9 +46,7 @@ export const getSiteInfo = async function ({ if (accountId !== undefined) siteInfo.account_id = accountId const integrations = - mode === 'buildbot' && !offline - ? await getIntegrations({ siteId, testOpts, offline, accountId }) - : [] + mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline, accountId }) : [] return { siteInfo, accounts: [], addons: [], integrations } } From 4aa5cae4c32fb068a5002f995715ce0b9d85f777 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Thu, 5 Dec 2024 17:22:15 -0500 Subject: [PATCH 3/6] chore: tests --- packages/config/tests/api/tests.js | 48 ------------------------------ 1 file changed, 48 deletions(-) diff --git a/packages/config/tests/api/tests.js b/packages/config/tests/api/tests.js index 8910aea2a8..39e6cb8165 100644 --- a/packages/config/tests/api/tests.js +++ b/packages/config/tests/api/tests.js @@ -383,54 +383,6 @@ test('Integrations are returned if feature flag is false and mode is dev', async t.assert(config.integrations[0].has_build === true) }) -test('Integrations and account id are returned if flag is true for site and mode is buildbot', async (t) => { - const { output } = await new Fixture('./fixtures/base') - .withFlags({ - siteId: 'test', - mode: 'buildbot', - token: 'test', - accountId: 'account1', - featureFlags: { - cli_integration_installations_meta: true, - }, - }) - .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) - - const config = JSON.parse(output) - - t.assert(config.integrations) - t.is(config.integrations.length, 1) - t.is(config.integrations[0].slug, 'test') - t.is(config.integrations[0].version, 'so-cool') - t.is(config.integrations[0].has_build, true) - - // account id is also available - t.assert(config.siteInfo) - t.is(config.siteInfo.account_id, 'account1') -}) - -test('Integrations are returned if flag is true for site and mode is dev', async (t) => { - const { output } = await new Fixture('./fixtures/base') - .withFlags({ - siteId: 'test', - mode: 'dev', - token: 'test', - accountId: 'account1', - featureFlags: { - cli_integration_installations_meta: true, - }, - }) - .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) - - const config = JSON.parse(output) - - t.assert(config.integrations) - t.assert(config.integrations.length === 1) - t.assert(config.integrations[0].slug === 'test') - t.assert(config.integrations[0].version === 'so-cool') - t.assert(config.integrations[0].has_build === true) -}) - test('baseRelDir is true if build.base is overridden', async (t) => { const fixturesDir = normalize(`${fileURLToPath(test.meta.file)}/../fixtures`) From 578bfdeab2e7b63e790e9a01e954bf175775adbf Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 09:58:41 -0500 Subject: [PATCH 4/6] test: modify tests --- packages/config/src/api/site_info.ts | 5 ++- packages/config/tests/api/tests.js | 58 +++++++++++++++++++++------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/packages/config/src/api/site_info.ts b/packages/config/src/api/site_info.ts index 4e80ba8e06..4ac6db793e 100644 --- a/packages/config/src/api/site_info.ts +++ b/packages/config/src/api/site_info.ts @@ -125,7 +125,10 @@ const getIntegrations = async function ({ const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`) - const url = `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}` + // if accountId isn't present, use safe v1 endpoint + const url = accountId + ? `${baseUrl}team/${accountId}/integrations/installations/meta/${siteId}` + : `${baseUrl}site/${siteId}/integrations/safe` try { const response = await fetch(url) diff --git a/packages/config/tests/api/tests.js b/packages/config/tests/api/tests.js index 39e6cb8165..fc1bf3f522 100644 --- a/packages/config/tests/api/tests.js +++ b/packages/config/tests/api/tests.js @@ -20,7 +20,7 @@ const SITE_INTEGRATIONS_RESPONSE = { response: [ { slug: 'test', - version: 'so-cool', + version: 'so-cool-v1', has_build: true, }, ], @@ -31,7 +31,7 @@ const TEAM_INSTALLATIONS_META_RESPONSE = { response: [ { slug: 'test', - version: 'so-cool', + version: 'so-cool-v2', has_build: true, }, ], @@ -42,6 +42,11 @@ const SITE_INTEGRATIONS_EMPTY_RESPONSE = { response: [], } +const TEAM_INSTALLATIONS_META_EMPTY_RESPONSE = { + path: '/team/account1/integrations/installations/meta/test', + response: [], +} + const SITE_INFO_BUILD_SETTINGS = { path: SITE_INFO_PATH, response: { @@ -222,7 +227,7 @@ test('Build settings are not used in CI', async (t) => { t.snapshot(normalizeOutput(output)) }) -test('Integrations are returned if feature flag is true', async (t) => { +test('Integrations are returned from getSiteInfo from v1 safe API when there is not accountID', async (t) => { const { output } = await new Fixture('./fixtures/base') .withFlags({ token: 'test', @@ -235,7 +240,7 @@ test('Integrations are returned if feature flag is true', async (t) => { t.assert(config.integrations) t.assert(config.integrations.length === 1) t.assert(config.integrations[0].slug === 'test') - t.assert(config.integrations[0].version === 'so-cool') + t.assert(config.integrations[0].version === 'so-cool-v1') t.assert(config.integrations[0].has_build === true) }) @@ -244,8 +249,9 @@ test('Integration specified in config is also returned if integration is availab .withFlags({ token: 'test', siteId: 'test', + accountId: 'account1', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_RESPONSE]) const config = JSON.parse(output) @@ -262,8 +268,9 @@ test('Integration specified in config is not returned if integration is not avai .withFlags({ token: 'test', siteId: 'test', + accountId: 'account1', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) @@ -278,8 +285,9 @@ test('In integration dev mode, integration specified in config is returned even token: 'test', siteId: 'test', context: 'dev', + accountId: 'account1', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) @@ -292,6 +300,25 @@ test('In integration dev mode, integration specified in config is returned even }) test('In integration dev mode, integration specified in config is returned even if integration is not enabled on site', async (t) => { + const { output } = await new Fixture('./fixtures/dev_integration') + .withFlags({ + token: 'test', + siteId: 'test', + context: 'dev', + accountId: 'account1', + }) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + + const config = JSON.parse(output) + + t.assert(config.integrations) + t.assert(config.integrations.length === 1) + t.assert(config.integrations[0].slug === 'abc-integration') + t.assert(config.integrations[0].has_build === false) + t.assert(config.integrations[0].version === undefined) +}) + +test('In integration dev mode, integration specified in config is returned even if integration is not enabled on site and accountId not present', async (t) => { const { output } = await new Fixture('./fixtures/dev_integration') .withFlags({ token: 'test', @@ -315,8 +342,9 @@ test('In integration dev mode, integration specified in config is returned and b token: 'test', siteId: 'test', context: 'dev', + accountId: 'account1', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_EMPTY_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) @@ -333,8 +361,9 @@ test('Integrations are not returned if offline', async (t) => { offline: true, siteId: 'test', mode: 'buildbot', + accountId: 'account1', }) - .runConfigServer([SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) @@ -350,14 +379,14 @@ test('Integrations and account id are returned if feature flag is false and mode accountId: 'account1', token: 'test', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) t.assert(config.integrations) t.is(config.integrations.length, 1) t.is(config.integrations[0].slug, 'test') - t.is(config.integrations[0].version, 'so-cool') + t.is(config.integrations[0].version, 'so-cool-v2') t.is(config.integrations[0].has_build, true) // account id is also available @@ -365,21 +394,22 @@ test('Integrations and account id are returned if feature flag is false and mode t.is(config.siteInfo.account_id, 'account1') }) -test('Integrations are returned if feature flag is false and mode is dev', async (t) => { +test('Integrations are returned if accountId is present and mode is dev', async (t) => { const { output } = await new Fixture('./fixtures/base') .withFlags({ siteId: 'test', mode: 'dev', token: 'test', + accountId: 'account1', }) - .runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) + .runConfigServer([SITE_INFO_DATA, TEAM_INSTALLATIONS_META_RESPONSE, FETCH_INTEGRATIONS_EMPTY_RESPONSE]) const config = JSON.parse(output) t.assert(config.integrations) t.assert(config.integrations.length === 1) t.assert(config.integrations[0].slug === 'test') - t.assert(config.integrations[0].version === 'so-cool') + t.assert(config.integrations[0].version === 'so-cool-v2') t.assert(config.integrations[0].has_build === true) }) From 0b011ecdf2d2bbd5a4c1a920776a5c7873d7ec8a Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 18:08:56 -0500 Subject: [PATCH 5/6] fix: convert normalize case file to typescript to make the build not take 4 minutes --- packages/config/src/{case.js => case.ts} | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) rename packages/config/src/{case.js => case.ts} (68%) diff --git a/packages/config/src/case.js b/packages/config/src/case.ts similarity index 68% rename from packages/config/src/case.js rename to packages/config/src/case.ts index e8755ed876..0bbdad2180 100644 --- a/packages/config/src/case.js +++ b/packages/config/src/case.ts @@ -1,10 +1,18 @@ // Some properties can be optionally capitalized. We normalize them to lowercase -export const normalizeConfigCase = function ({ Build, build = Build, ...config }) { +export const normalizeConfigCase = function ({ + Build, + build = Build, + ...config +}: { + Build: Record + build: Record + [key: string]: unknown +}): Record { const buildA = normalizeBuildCase(build) return { ...config, build: buildA } } -const normalizeBuildCase = function ({ +const normalizeBuildCase = ({ Base, base = Base, Command, @@ -22,7 +30,7 @@ const normalizeBuildCase = function ({ Publish, publish = Publish, ...build -} = {}) { +}: Record = {}): Record => { return { ...build, base, From 60cfa21c82b8ad4b6a4fb5517f12eb35cad9d18a Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Fri, 6 Dec 2024 18:16:51 -0500 Subject: [PATCH 6/6] chore: change test name --- packages/config/tests/api/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config/tests/api/tests.js b/packages/config/tests/api/tests.js index fc1bf3f522..897c9cc9ce 100644 --- a/packages/config/tests/api/tests.js +++ b/packages/config/tests/api/tests.js @@ -371,7 +371,7 @@ test('Integrations are not returned if offline', async (t) => { t.assert(config.integrations.length === 0) }) -test('Integrations and account id are returned if feature flag is false and mode is buildbot', async (t) => { +test('Integrations and account id are returned if mode is buildbot', async (t) => { const { output } = await new Fixture('./fixtures/base') .withFlags({ siteId: 'test',