@netlify/config 18.0.0 → 18.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/api/site_info.js +10 -2
- package/src/env/envelope.js +27 -0
- package/src/env/main.js +11 -5
- package/src/log/messages.js +2 -0
- package/src/main.js +1 -0
- package/src/validate/validations.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.0",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/main.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"is-plain-obj": "^4.0.0",
|
|
65
65
|
"js-yaml": "^4.0.0",
|
|
66
66
|
"map-obj": "^5.0.0",
|
|
67
|
-
"netlify": "^11.0.
|
|
67
|
+
"netlify": "^11.0.2",
|
|
68
68
|
"netlify-headers-parser": "^6.0.2",
|
|
69
69
|
"netlify-redirect-parser": "13.0.5",
|
|
70
70
|
"omit.js": "^2.0.2",
|
package/src/api/site_info.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getEnvelope } from '../env/envelope.js'
|
|
1
2
|
import { throwUserError } from '../error.js'
|
|
3
|
+
import { ERROR_CALL_TO_ACTION } from '../log/messages.js'
|
|
2
4
|
|
|
3
5
|
// Retrieve Netlify Site information, if available.
|
|
4
6
|
// Used to retrieve local build environment variables and UI build settings.
|
|
@@ -7,6 +9,7 @@ import { throwUserError } from '../error.js'
|
|
|
7
9
|
// Requires knowing the `siteId` and having the access `token`.
|
|
8
10
|
// Silently ignore API errors. For example the network connection might be down,
|
|
9
11
|
// but local builds should still work regardless.
|
|
12
|
+
// eslint-disable-next-line complexity
|
|
10
13
|
export const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env: testEnv = true } = {} }) {
|
|
11
14
|
if (api === undefined || mode === 'buildbot' || !testEnv) {
|
|
12
15
|
const siteInfo = siteId === undefined ? {} : { id: siteId }
|
|
@@ -18,6 +21,13 @@ export const getSiteInfo = async function ({ api, siteId, mode, testOpts: { env:
|
|
|
18
21
|
getAccounts(api),
|
|
19
22
|
getAddons(api, siteId),
|
|
20
23
|
])
|
|
24
|
+
|
|
25
|
+
if (siteInfo.use_envelope) {
|
|
26
|
+
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId })
|
|
27
|
+
// eslint-disable-next-line fp/no-mutation
|
|
28
|
+
siteInfo.build_settings.env = envelope
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
return { siteInfo, accounts, addons }
|
|
22
32
|
}
|
|
23
33
|
|
|
@@ -55,5 +65,3 @@ const getAddons = async function (api, siteId) {
|
|
|
55
65
|
throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { throwUserError } from '../error.js'
|
|
2
|
+
import { ERROR_CALL_TO_ACTION } from '../log/messages.js'
|
|
3
|
+
|
|
4
|
+
export const getEnvelope = async function ({ api, accountId, siteId }) {
|
|
5
|
+
if (accountId === undefined) {
|
|
6
|
+
return {}
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const environmentVariables = await api.getEnvVars({ accountId, siteId })
|
|
10
|
+
// eslint-disable-next-line fp/no-mutating-methods
|
|
11
|
+
const sortedEnvVarsFromDevContext = environmentVariables
|
|
12
|
+
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
|
|
13
|
+
.reduce((acc, cur) => {
|
|
14
|
+
const envVar = cur.values.find((val) => ['dev', 'all'].includes(val.context))
|
|
15
|
+
if (envVar && envVar.value) {
|
|
16
|
+
return {
|
|
17
|
+
...acc,
|
|
18
|
+
[cur.key]: envVar.value,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return acc
|
|
22
|
+
}, {})
|
|
23
|
+
return sortedEnvVarsFromDevContext
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throwUserError(`Failed retrieving envelope for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/env/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import omit from 'omit.js'
|
|
|
2
2
|
|
|
3
3
|
import { removeFalsy } from '../utils/remove_falsy.js'
|
|
4
4
|
|
|
5
|
+
import { getEnvelope } from './envelope.js'
|
|
5
6
|
import { getGitEnv } from './git.js'
|
|
6
7
|
|
|
7
8
|
// Retrieve this site's environment variable. Also take into account team-wide
|
|
@@ -11,6 +12,7 @@ import { getGitEnv } from './git.js'
|
|
|
11
12
|
// TODO: add `netlify.toml` `build.environment`, after normalization
|
|
12
13
|
// TODO: add `CONTEXT` and others
|
|
13
14
|
export const getEnv = async function ({
|
|
15
|
+
api,
|
|
14
16
|
mode,
|
|
15
17
|
config,
|
|
16
18
|
siteInfo,
|
|
@@ -27,7 +29,7 @@ export const getEnv = async function ({
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context })
|
|
30
|
-
const [accountEnv, addonsEnv, uiEnv, configFileEnv] = getUserEnv({ config, siteInfo, accounts, addons })
|
|
32
|
+
const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, config, siteInfo, accounts, addons })
|
|
31
33
|
|
|
32
34
|
// Sources of environment variables, in descending order of precedence.
|
|
33
35
|
const sources = [
|
|
@@ -115,8 +117,8 @@ const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
|
|
|
115
117
|
const DEFAULT_SITE_NAME = 'site-name'
|
|
116
118
|
|
|
117
119
|
// Environment variables specified by the user
|
|
118
|
-
const getUserEnv = function ({ config, siteInfo, accounts, addons }) {
|
|
119
|
-
const accountEnv = getAccountEnv({ siteInfo, accounts })
|
|
120
|
+
const getUserEnv = async function ({ api, config, siteInfo, accounts, addons }) {
|
|
121
|
+
const accountEnv = await getAccountEnv({ api, siteInfo, accounts })
|
|
120
122
|
const addonsEnv = getAddonsEnv(addons)
|
|
121
123
|
const uiEnv = getUiEnv({ siteInfo })
|
|
122
124
|
const configFileEnv = getConfigFileEnv({ config })
|
|
@@ -124,8 +126,12 @@ const getUserEnv = function ({ config, siteInfo, accounts, addons }) {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// Account-wide environment variables
|
|
127
|
-
const getAccountEnv = function ({ siteInfo
|
|
128
|
-
|
|
129
|
+
const getAccountEnv = async function ({ api, siteInfo, accounts }) {
|
|
130
|
+
if (siteInfo.use_envelope) {
|
|
131
|
+
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug })
|
|
132
|
+
return envelope
|
|
133
|
+
}
|
|
134
|
+
const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {}
|
|
129
135
|
return siteEnv
|
|
130
136
|
}
|
|
131
137
|
|
package/src/log/messages.js
CHANGED
|
@@ -2,6 +2,8 @@ import { throwUserError } from '../error.js'
|
|
|
2
2
|
|
|
3
3
|
import { logWarning } from './logger.js'
|
|
4
4
|
|
|
5
|
+
export const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
|
|
6
|
+
|
|
5
7
|
export const throwOnInvalidTomlSequence = function (invalidSequence) {
|
|
6
8
|
throwUserError(
|
|
7
9
|
`In netlify.toml, the following backslash should be escaped: ${invalidSequence}
|
package/src/main.js
CHANGED
|
@@ -102,6 +102,17 @@ export const PRE_NORMALIZE_VALIDATIONS = [
|
|
|
102
102
|
functions: { ignored_node_modules: ['module-one', 'module-two'] },
|
|
103
103
|
}),
|
|
104
104
|
},
|
|
105
|
+
{
|
|
106
|
+
property: 'edge_functions',
|
|
107
|
+
check: isArrayOfObjects,
|
|
108
|
+
message: 'must be an array of objects.',
|
|
109
|
+
example: () => ({
|
|
110
|
+
edge_functions: [
|
|
111
|
+
{ path: '/hello', function: 'hello' },
|
|
112
|
+
{ path: '/auth', function: 'auth' },
|
|
113
|
+
],
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
105
116
|
]
|
|
106
117
|
|
|
107
118
|
const EXAMPLE_PORT = 80
|
|
@@ -242,5 +253,40 @@ export const POST_NORMALIZE_VALIDATIONS = [
|
|
|
242
253
|
functions: { directory: 'my-functions' },
|
|
243
254
|
}),
|
|
244
255
|
},
|
|
256
|
+
{
|
|
257
|
+
property: 'edge_functions.*',
|
|
258
|
+
...validProperties(['path', 'function'], []),
|
|
259
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
property: 'edge_functions.*',
|
|
263
|
+
check: (edgeFunction) => edgeFunction.path !== undefined,
|
|
264
|
+
message: '"path" property is required.',
|
|
265
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
property: 'edge_functions.*',
|
|
269
|
+
check: (edgeFunction) => edgeFunction.function !== undefined,
|
|
270
|
+
message: '"function" property is required.',
|
|
271
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
property: 'edge_functions.*.path',
|
|
275
|
+
check: isString,
|
|
276
|
+
message: 'must be a string.',
|
|
277
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
property: 'edge_functions.*.function',
|
|
281
|
+
check: isString,
|
|
282
|
+
message: 'must be a string.',
|
|
283
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
property: 'edge_functions.*.path',
|
|
287
|
+
check: (pathName) => pathName.startsWith('/'),
|
|
288
|
+
message: 'must be a valid path.',
|
|
289
|
+
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
|
|
290
|
+
},
|
|
245
291
|
]
|
|
246
292
|
/* eslint-enable max-lines */
|