Skip to content
Draft
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
23 changes: 14 additions & 9 deletions packages/config/src/api/site_info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetlifyAPI } from '@netlify/api'

import type { operations } from '@netlify/open-api'
import * as z from 'zod'

import { getEnvelope } from '../env/envelope.js'
Expand Down Expand Up @@ -114,6 +114,10 @@ export const getSiteInfo = async function ({
return { siteInfo, accounts, extensions }
}

type GetSiteOpts = operations['getSite']['parameters']['query'] & {
feature_flags?: string
}

const getSite = async function (
api: NetlifyAPI,
siteId: string,
Expand All @@ -124,11 +128,9 @@ const getSite = async function (
}
try {
const site = await api.getSite({
// @ts-expect-error: Internal parameter that instructs the API to include all the site's
// feature flags in the response.
feature_flags: siteFeatureFlagPrefix,
siteId,
})
site_id: siteId,
} as GetSiteOpts)
return { ...site, id: siteId }
} catch (err) {
return throwUserError(`Failed retrieving site data for site ${siteId}: ${err.message}. ${ERROR_CALL_TO_ACTION}`)
Expand All @@ -148,12 +150,15 @@ export type MinimalAccount = {
members_count: number
}

type ListAccountsForUserOpts = operations['listAccountsForUser']['parameters']['query'] & {
minimal?: string
}

const getAccounts = async function (api: NetlifyAPI): Promise<MinimalAccount[]> {
try {
const accounts = (await api.listAccountsForUser(
// @ts-expect-error(ndhoule): This is an unpublished, internal querystring parameter
{ minimal: 'true' },
)) as MinimalAccount[] | null
const accounts = (await api.listAccountsForUser({
minimal: 'true',
} as ListAccountsForUserOpts)) as MinimalAccount[] | null
return Array.isArray(accounts) ? (accounts as MinimalAccount[]) : []
} catch (error) {
return throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
Expand Down
15 changes: 12 additions & 3 deletions packages/config/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { resolvePath } from './files.js'

type Config = {
build: {
base?: string
}
}

/**
* Retrieve the first `base` directory used to load the first config file.
*/
export const getInitialBase = function ({
repositoryRoot,
// @ts-expect-error TODO: enhance the types later on, just moved the file to .ts
defaultConfig: { build: { base: defaultBase } = {} },
inlineConfig: { build: { base: initialBase = defaultBase } = {} },
}: {
repositoryRoot: string
defaultConfig: Config
inlineConfig: Config
}) {
return resolveBase(repositoryRoot, initialBase)
}
Expand All @@ -25,7 +34,7 @@ export const getInitialBase = function ({
* If the second file has a `base` property, it is ignored, i.e. it is not
* recursive.
*/
export const getBase = function (base: string | undefined, repositoryRoot: string, config: $TSFixMe) {
export const getBase = function (base: string | undefined, repositoryRoot: string, config: Config) {
return base === undefined ? resolveBase(repositoryRoot, config.build.base) : base
}

Expand All @@ -36,6 +45,6 @@ const resolveBase = function (repositoryRoot: string, base: string) {
/**
* Also `config.build.base`.
*/
export const addBase = function (config, base) {
export const addBase = function (config: Config, base: string) {
return { ...config, build: { ...config.build, base } }
}
96 changes: 0 additions & 96 deletions packages/config/tests/api/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -184,12 +178,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -324,12 +312,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -461,12 +443,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -604,12 +580,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -747,12 +717,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -921,12 +885,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1064,12 +1022,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1201,12 +1153,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1387,12 +1333,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1569,12 +1509,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1770,12 +1704,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -1955,12 +1883,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -2098,12 +2020,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -2284,12 +2200,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -2402,9 +2312,3 @@ Generated by [AVA](https://avajs.dev).
},␊
"token": "test"␊
}`

## Integrations are not returned if failed to fetch integrations

> Snapshot 1

'Failed retrieving extensions for site test: Unexpected status code 500 from fetching extensions. Double-check your login status with \'netlify status\' or contact support with details of your error.'
Binary file modified packages/config/tests/api/snapshots/tests.js.snap
Binary file not shown.
42 changes: 0 additions & 42 deletions packages/config/tests/base/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -192,12 +186,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -330,12 +318,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -472,12 +454,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -615,12 +591,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -751,12 +721,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down Expand Up @@ -887,12 +851,6 @@ Generated by [AVA](https://avajs.dev).
],␊
"value": "0"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
Expand Down
Binary file modified packages/config/tests/base/snapshots/tests.js.snap
Binary file not shown.
Loading
Loading