netlify-cli 9.1.1 → 9.2.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
- "version": "9.1.1",
3
+ "version": "9.2.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "netlify-cli",
9
- "version": "9.1.1",
9
+ "version": "9.2.0",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
@@ -15,7 +15,7 @@
15
15
  "@netlify/framework-info": "^9.0.0",
16
16
  "@netlify/local-functions-proxy": "^1.1.1",
17
17
  "@netlify/plugin-edge-handlers": "^3.0.6",
18
- "@netlify/plugins-list": "^6.9.0",
18
+ "@netlify/plugins-list": "^6.10.1",
19
19
  "@netlify/routing-local-proxy": "^0.34.1",
20
20
  "@netlify/zip-it-and-ship-it": "^5.7.4",
21
21
  "@octokit/rest": "^18.0.0",
@@ -82,7 +82,7 @@
82
82
  "multiparty": "^4.2.1",
83
83
  "netlify": "^11.0.0",
84
84
  "netlify-headers-parser": "^6.0.1",
85
- "netlify-onegraph-internal": "0.0.37",
85
+ "netlify-onegraph-internal": "0.0.39",
86
86
  "netlify-redirect-parser": "^13.0.2",
87
87
  "netlify-redirector": "^0.2.1",
88
88
  "node-fetch": "^2.6.0",
@@ -3842,9 +3842,9 @@
3842
3842
  }
3843
3843
  },
3844
3844
  "node_modules/@netlify/plugins-list": {
3845
- "version": "6.9.0",
3846
- "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.9.0.tgz",
3847
- "integrity": "sha512-8UjAqy/9OhnRAW33vo9UexNbNHXpBXO7uqh05Dbzu2i0jVRVHdEjGII8m2YnsCfPU8jPWdJu3XmXRhkPPKUvyA==",
3845
+ "version": "6.10.1",
3846
+ "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.10.1.tgz",
3847
+ "integrity": "sha512-/8P8QXDJUFlkAMBmuZYf2orsdxL0ite75/BQuRaFlZh7HxeYg84rfWsBqyMe9DGt2hnYqQ/zlDFNAyK+fiynNg==",
3848
3848
  "engines": {
3849
3849
  "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
3850
3850
  }
@@ -16484,9 +16484,9 @@
16484
16484
  }
16485
16485
  },
16486
16486
  "node_modules/netlify-onegraph-internal": {
16487
- "version": "0.0.37",
16488
- "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.37.tgz",
16489
- "integrity": "sha512-EjcLO4jafn2mKVval6hns7wdqT28c7rHJyOzYTUa5ViU+L4eF6CweA4jjH36rmsFxNJchQBpzR2zl/KY4auOKg==",
16487
+ "version": "0.0.39",
16488
+ "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.39.tgz",
16489
+ "integrity": "sha512-ekx1INpJGTU2t6TkvlnzFXuaFGrf5PM9we13Oq4mFbynhfuwN3NmnDRSIGl2g6ae9ZpvzTCVSIr13u/HMWjxpA==",
16490
16490
  "dependencies": {
16491
16491
  "graphql": "16.0.0",
16492
16492
  "node-fetch": "^2.6.0",
@@ -26156,9 +26156,9 @@
26156
26156
  }
26157
26157
  },
26158
26158
  "@netlify/plugins-list": {
26159
- "version": "6.9.0",
26160
- "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.9.0.tgz",
26161
- "integrity": "sha512-8UjAqy/9OhnRAW33vo9UexNbNHXpBXO7uqh05Dbzu2i0jVRVHdEjGII8m2YnsCfPU8jPWdJu3XmXRhkPPKUvyA=="
26159
+ "version": "6.10.1",
26160
+ "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.10.1.tgz",
26161
+ "integrity": "sha512-/8P8QXDJUFlkAMBmuZYf2orsdxL0ite75/BQuRaFlZh7HxeYg84rfWsBqyMe9DGt2hnYqQ/zlDFNAyK+fiynNg=="
26162
26162
  },
26163
26163
  "@netlify/routing-local-proxy": {
26164
26164
  "version": "0.34.1",
@@ -35806,9 +35806,9 @@
35806
35806
  }
35807
35807
  },
35808
35808
  "netlify-onegraph-internal": {
35809
- "version": "0.0.37",
35810
- "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.37.tgz",
35811
- "integrity": "sha512-EjcLO4jafn2mKVval6hns7wdqT28c7rHJyOzYTUa5ViU+L4eF6CweA4jjH36rmsFxNJchQBpzR2zl/KY4auOKg==",
35809
+ "version": "0.0.39",
35810
+ "resolved": "https://registry.npmjs.org/netlify-onegraph-internal/-/netlify-onegraph-internal-0.0.39.tgz",
35811
+ "integrity": "sha512-ekx1INpJGTU2t6TkvlnzFXuaFGrf5PM9we13Oq4mFbynhfuwN3NmnDRSIGl2g6ae9ZpvzTCVSIr13u/HMWjxpA==",
35812
35812
  "requires": {
35813
35813
  "graphql": "16.0.0",
35814
35814
  "node-fetch": "^2.6.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
3
  "description": "Netlify command line tool",
4
- "version": "9.1.1",
4
+ "version": "9.2.0",
5
5
  "author": "Netlify Inc.",
6
6
  "contributors": [
7
7
  "Abraham Schilling <AbrahamSchilling@gmail.com> (https://gitlab.com/n4bb12)",
@@ -204,7 +204,7 @@
204
204
  "@netlify/framework-info": "^9.0.0",
205
205
  "@netlify/local-functions-proxy": "^1.1.1",
206
206
  "@netlify/plugin-edge-handlers": "^3.0.6",
207
- "@netlify/plugins-list": "^6.9.0",
207
+ "@netlify/plugins-list": "^6.10.1",
208
208
  "@netlify/routing-local-proxy": "^0.34.1",
209
209
  "@netlify/zip-it-and-ship-it": "^5.7.4",
210
210
  "@octokit/rest": "^18.0.0",
@@ -271,7 +271,7 @@
271
271
  "multiparty": "^4.2.1",
272
272
  "netlify": "^11.0.0",
273
273
  "netlify-headers-parser": "^6.0.1",
274
- "netlify-onegraph-internal": "0.0.37",
274
+ "netlify-onegraph-internal": "0.0.39",
275
275
  "netlify-redirect-parser": "^13.0.2",
276
276
  "netlify-redirector": "^0.2.1",
277
277
  "node-fetch": "^2.6.0",
@@ -32,7 +32,6 @@ const {
32
32
  detectServerSettings,
33
33
  error,
34
34
  exit,
35
- generateAuthlifyJWT,
36
35
  getSiteInformation,
37
36
  injectEnvVariables,
38
37
  log,
@@ -265,27 +264,7 @@ const dev = async (options, command) => {
265
264
  }
266
265
 
267
266
  const startNetlifyGraphWatcher = Boolean(options.graph)
268
- let authlifyJWT
269
-
270
- if (startNetlifyGraphWatcher) {
271
- const netlifyToken = await command.authenticate()
272
- authlifyJWT = generateAuthlifyJWT(netlifyToken, siteInfo.authlify_token_id, site.id)
273
- }
274
-
275
- await injectEnvVariables({
276
- env: Object.assign(
277
- command.netlify.cachedConfig.env,
278
- authlifyJWT == null
279
- ? {}
280
- : {
281
- ONEGRAPH_AUTHLIFY_TOKEN: {
282
- sources: ['general'],
283
- value: authlifyJWT,
284
- },
285
- },
286
- ),
287
- site,
288
- })
267
+ await injectEnvVariables({ env: command.netlify.cachedConfig.env, site })
289
268
 
290
269
  const { addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
291
270
  // inherited from base command --offline
@@ -306,28 +285,14 @@ const dev = async (options, command) => {
306
285
 
307
286
  command.setAnalyticsPayload({ projectType: settings.framework || 'custom', live: options.live })
308
287
 
309
- let configWithAuthlify
310
-
311
- if (siteInfo.authlify_token_id) {
312
- const netlifyToken = command.authenticate()
313
- // Only inject the authlify config if a token ID exists. This prevents
314
- // calling command.authenticate() (which opens a browser window) if the
315
- // user hasn't enabled API Authentication
316
- configWithAuthlify = Object.assign(config, {
317
- authlify: {
318
- netlifyToken,
319
- authlifyTokenId: siteInfo.authlify_token_id,
320
- siteId: site.id,
321
- },
322
- })
323
- } else {
324
- configWithAuthlify = config
325
- }
326
-
327
288
  await startFunctionsServer({
328
- config: configWithAuthlify,
289
+ api,
290
+ command,
291
+ config,
292
+ isGraphEnabled: startNetlifyGraphWatcher,
329
293
  settings,
330
294
  site,
295
+ siteInfo,
331
296
  siteUrl,
332
297
  capabilities,
333
298
  timeouts,
@@ -34,8 +34,10 @@ const functionsServe = async (options, command) => {
34
34
 
35
35
  await startFunctionsServer({
36
36
  config,
37
+ api,
37
38
  settings: { functions: functionsDir, functionsPort },
38
39
  site,
40
+ siteInfo,
39
41
  siteUrl,
40
42
  capabilities,
41
43
  timeouts,
@@ -1,4 +1,6 @@
1
1
  // @ts-check
2
+ const process = require('process')
3
+
2
4
  const jwtDecode = require('jwt-decode')
3
5
 
4
6
  const {
@@ -6,7 +8,7 @@ const {
6
8
  NETLIFYDEVERR,
7
9
  NETLIFYDEVLOG,
8
10
  error: errorExit,
9
- generateAuthlifyJWT,
11
+ generateNetlifyGraphJWT,
10
12
  getInternalFunctionsDir,
11
13
  log,
12
14
  } = require('../../utils')
@@ -45,7 +47,51 @@ const buildClientContext = function (headers) {
45
47
  }
46
48
  }
47
49
 
48
- const createHandler = function ({ config, functionsRegistry }) {
50
+ const startPollingForAPIAuthentication = async function (options) {
51
+ const { api, command, config, site, siteInfo } = options
52
+ const frequency = 5000
53
+
54
+ const helper = async (maybeSiteData) => {
55
+ const siteData = await (maybeSiteData || api.getSite({ siteId: site.id }))
56
+ const authlifyTokenId = siteData && siteData.authlify_token_id
57
+
58
+ const existingAuthlifyTokenId = config && config.netlifyGraphConfig && config.netlifyGraphConfig.authlifyTokenId
59
+ if (authlifyTokenId && authlifyTokenId !== existingAuthlifyTokenId) {
60
+ const netlifyToken = await command.authenticate()
61
+ // Only inject the authlify config if a token ID exists. This prevents
62
+ // calling command.authenticate() (which opens a browser window) if the
63
+ // user hasn't enabled API Authentication
64
+ const netlifyGraphConfig = {
65
+ netlifyToken,
66
+ authlifyTokenId: siteData.authlify_token_id,
67
+ siteId: site.id,
68
+ }
69
+ config.netlifyGraphConfig = netlifyGraphConfig
70
+
71
+ const netlifyGraphJWT = generateNetlifyGraphJWT(netlifyGraphConfig)
72
+
73
+ if (netlifyGraphJWT != null) {
74
+ // XXX(anmonteiro): this name is deprecated. Delete after 3/31/2022
75
+ process.env.ONEGRAPH_AUTHLIFY_TOKEN = netlifyGraphJWT
76
+ process.env.NETLIFY_GRAPH_TOKEN = netlifyGraphJWT
77
+ }
78
+ } else {
79
+ delete config.authlify
80
+ }
81
+
82
+ setTimeout(helper, frequency)
83
+ }
84
+
85
+ await helper(siteInfo)
86
+ }
87
+
88
+ const createHandler = function (options) {
89
+ const { config, functionsRegistry } = options
90
+
91
+ if (options.isGraphEnabled) {
92
+ startPollingForAPIAuthentication(options)
93
+ }
94
+
49
95
  return async function handler(request, response) {
50
96
  // handle proxies without path re-writes (http-servr)
51
97
  const cleanPath = request.path.replace(/^\/.netlify\/(functions|builders)/, '')
@@ -107,8 +153,10 @@ const createHandler = function ({ config, functionsRegistry }) {
107
153
  }
108
154
 
109
155
  if (config && config.authlify && config.authlify.authlifyTokenId != null) {
110
- const { authlifyTokenId, netlifyToken, siteId } = config.authlify
111
- event.authlifyToken = generateAuthlifyJWT(netlifyToken, authlifyTokenId, siteId)
156
+ // XXX(anmonteiro): this name is deprecated. Delete after 3/31/2022
157
+ const jwt = generateNetlifyGraphJWT(config.netlifyGraphConfig)
158
+ event.authlifyToken = jwt
159
+ event.netlifyGraphToken = jwt
112
160
  }
113
161
 
114
162
  const clientContext = buildClientContext(request.headers) || {}
@@ -160,14 +208,15 @@ const createHandler = function ({ config, functionsRegistry }) {
160
208
  }
161
209
  }
162
210
 
163
- const getFunctionsServer = function ({ buildersPrefix, config, functionsPrefix, functionsRegistry, siteUrl }) {
211
+ const getFunctionsServer = function (options) {
212
+ const { buildersPrefix = '', functionsPrefix = '', functionsRegistry, siteUrl } = options
164
213
  // performance optimization, load express on demand
165
214
  // eslint-disable-next-line node/global-require
166
215
  const express = require('express')
167
216
  // eslint-disable-next-line node/global-require
168
217
  const expressLogging = require('express-logging')
169
218
  const app = express()
170
- const functionHandler = createHandler({ config, functionsRegistry })
219
+ const functionHandler = createHandler(options)
171
220
 
172
221
  app.set('query parser', 'simple')
173
222
 
@@ -195,16 +244,8 @@ const getFunctionsServer = function ({ buildersPrefix, config, functionsPrefix,
195
244
  return app
196
245
  }
197
246
 
198
- const startFunctionsServer = async ({
199
- buildersPrefix = '',
200
- capabilities,
201
- config,
202
- functionsPrefix = '',
203
- settings,
204
- site,
205
- siteUrl,
206
- timeouts,
207
- }) => {
247
+ const startFunctionsServer = async (options) => {
248
+ const { capabilities, config, settings, site, siteUrl, timeouts } = options
208
249
  const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root })
209
250
 
210
251
  // The order of the function directories matters. Leftmost directories take
@@ -223,13 +264,7 @@ const startFunctionsServer = async ({
223
264
 
224
265
  await functionsRegistry.scan(functionsDirectories)
225
266
 
226
- const server = getFunctionsServer({
227
- config,
228
- functionsRegistry,
229
- siteUrl,
230
- functionsPrefix,
231
- buildersPrefix,
232
- })
267
+ const server = getFunctionsServer(Object.assign(options, { functionsRegistry }))
233
268
 
234
269
  await startWebServer({ server, settings })
235
270
  }
@@ -478,7 +478,7 @@ const { buildSchema, parse } = GraphQL
478
478
  const getGraphEditUrlBySiteName = ({ oneGraphSessionId, siteName }) => {
479
479
  const host = process.env.NETLIFY_APP_HOST || 'app.netlify.com'
480
480
  // http because app.netlify.com will redirect to https, and localhost will still work for development
481
- const url = `http://${host}/sites/${siteName}/graph/explorer?cliSessionId=${oneGraphSessionId}`
481
+ const url = `http://${host}/sites/app/${siteName}/graph/explorer/${oneGraphSessionId}`
482
482
 
483
483
  return url
484
484
  }
@@ -493,7 +493,7 @@ const getGraphEditUrlBySiteName = ({ oneGraphSessionId, siteName }) => {
493
493
  const getGraphEditUrlBySiteId = ({ oneGraphSessionId, siteId }) => {
494
494
  const host = process.env.NETLIFY_APP_HOST || 'app.netlify.com'
495
495
  // http because app.netlify.com will redirect to https, and localhost will still work for development
496
- const url = `http://${host}/site-redirect/${siteId}/graph/explorer?cliSessionId=${oneGraphSessionId}`
496
+ const url = `http://${host}/site-redirect/${siteId}/graph/explorer/${oneGraphSessionId}`
497
497
 
498
498
  return url
499
499
  }
package/src/utils/dev.js CHANGED
@@ -194,12 +194,12 @@ const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
194
194
  return acquiredPort
195
195
  }
196
196
 
197
- // Generates an Authlify JWT with the following claims:
197
+ // Generates a Netlify Graph JWT with the following claims:
198
198
  // - site_id
199
199
  // - netlify_token -- the bearer token for the Netlify API
200
200
  // - authlify_token_id -- the authlify token ID stored for the site after
201
201
  // enabling API Authentication.
202
- const generateAuthlifyJWT = (netlifyToken, authlifyTokenId, siteId) => {
202
+ const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
203
203
  const claims = {
204
204
  netlify_token: netlifyToken,
205
205
  authlify_token_id: authlifyTokenId,
@@ -219,5 +219,5 @@ module.exports = {
219
219
  getSiteInformation,
220
220
  injectEnvVariables,
221
221
  acquirePort,
222
- generateAuthlifyJWT,
222
+ generateNetlifyGraphJWT,
223
223
  }