netlify-cli 6.14.16 → 6.14.21

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,5 +1,6 @@
1
1
  const { Readable } = require('stream')
2
2
 
3
+ const fromEntries = require('@ungap/from-entries')
3
4
  const { parse: parseContentType } = require('content-type')
4
5
  const multiparty = require('multiparty')
5
6
  const getRawBody = require('raw-body')
@@ -38,7 +39,7 @@ const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
38
39
  encoding: ct.parameters.charset,
39
40
  })
40
41
 
41
- fields = getObjectFromParams(new URLSearchParams(bodyData.toString()))
42
+ fields = fromEntries(new URLSearchParams(bodyData.toString()))
42
43
  } else if (ct.type === 'multipart/form-data') {
43
44
  try {
44
45
  ;[fields, files] = await new Promise((resolve, reject) => {
@@ -126,17 +127,6 @@ const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
126
127
  }
127
128
  }
128
129
 
129
- /**
130
- * Converts URLSearchParams to an object
131
- * @deprecated can be replaced with `Object.fromEntries` once the support for older Node.js Versions than `12.0.0` is dropped.
132
- * @param {URLSearchParams} urlParams
133
- * @returns {Record<string, any>}
134
- */
135
- const getObjectFromParams = (urlParams) => {
136
- const entries = [...urlParams]
137
- return entries.reduce((prev, [key, value]) => ({ ...prev, [key]: value }), {})
138
- }
139
-
140
130
  const getFormHandler = function ({ functionsRegistry }) {
141
131
  const handlers = ['submission-created', `submission-created${BACKGROUND}`]
142
132
  .map((name) => functionsRegistry.get(name))
@@ -12,9 +12,10 @@ const runtimes = require('./runtimes')
12
12
  const { watchDebounced } = require('./watcher')
13
13
 
14
14
  class FunctionsRegistry {
15
- constructor({ capabilities, config, projectRoot, timeouts }) {
15
+ constructor({ capabilities, config, isConnected = false, projectRoot, timeouts }) {
16
16
  this.capabilities = capabilities
17
17
  this.config = config
18
+ this.isConnected = isConnected
18
19
  this.projectRoot = projectRoot
19
20
  this.timeouts = timeouts
20
21
 
@@ -128,7 +129,7 @@ class FunctionsRegistry {
128
129
  return
129
130
  }
130
131
 
131
- if (func.isBackground && !this.capabilities.backgroundFunctions) {
132
+ if (func.isBackground && this.isConnected && !this.capabilities.backgroundFunctions) {
132
133
  warn(getLogMessage('functions.backgroundNotSupported'))
133
134
  }
134
135
 
@@ -178,6 +178,7 @@ const startFunctionsServer = async ({
178
178
  const functionsRegistry = new FunctionsRegistry({
179
179
  capabilities,
180
180
  config,
181
+ isConnected: Boolean(siteUrl),
181
182
  projectRoot: site.root,
182
183
  timeouts,
183
184
  })
@@ -11,7 +11,7 @@ const { getAgent } = require('../lib/http-agent')
11
11
 
12
12
  const { argv, chalk, error, exit, getCwd, getToken, log, normalizeConfig, pollForToken } = require('./command-helpers')
13
13
  const getGlobalConfig = require('./get-global-config')
14
- const openBrowser = require('./open-browser')
14
+ const { openBrowser } = require('./open-browser')
15
15
  const StateConfig = require('./state-config')
16
16
  const { identify, track } = require('./telemetry')
17
17
  const { TrackedCommand } = require('./telemetry/tracked-command')
@@ -3,12 +3,13 @@ const http = require('http')
3
3
  const process = require('process')
4
4
 
5
5
  const { Octokit } = require('@octokit/rest')
6
+ const fromEntries = require('@ungap/from-entries')
6
7
  const getPort = require('get-port')
7
8
  const inquirer = require('inquirer')
8
9
 
9
10
  const { log } = require('./command-helpers')
10
11
  const { createDeferred } = require('./deferred')
11
- const openBrowser = require('./open-browser')
12
+ const { openBrowser } = require('./open-browser')
12
13
 
13
14
  const SERVER_PORT = 3000
14
15
 
@@ -31,6 +32,17 @@ const promptForAuthMethod = async () => {
31
32
  return authMethod === authChoiceNetlify
32
33
  }
33
34
 
35
+ /**
36
+ * Authenticate with the netlify app
37
+ * @returns {Promise<Record<string,string>} Returns a Promise with an object of the following shape
38
+ * ```
39
+ * {
40
+ * user: 'spongebob,
41
+ * token: 'gho_some-token',
42
+ * provider: 'github'
43
+ * }
44
+ * ```
45
+ */
34
46
  const authWithNetlify = async () => {
35
47
  const port = await getPort({ port: SERVER_PORT })
36
48
  const { promise: deferredPromise, reject: deferredReject, resolve: deferredResolve } = createDeferred()
@@ -38,7 +50,7 @@ const authWithNetlify = async () => {
38
50
  const server = http.createServer(function onRequest(req, res) {
39
51
  const parameters = new URLSearchParams(req.url.slice(req.url.indexOf('?') + 1))
40
52
  if (parameters.get('token')) {
41
- deferredResolve(parameters)
53
+ deferredResolve(fromEntries(parameters))
42
54
  res.end(
43
55
  `${
44
56
  "<html><head><script>if(history.replaceState){history.replaceState({},'','/')}</script><style>html{font-family:sans-serif;background:#0e1e25}body{overflow:hidden;position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;width:100vw;}h3{margin:0}.card{position:relative;display:flex;flex-direction:column;width:75%;max-width:364px;padding:24px;background:white;color:rgb(14,30,37);border-radius:8px;box-shadow:0 2px 4px 0 rgba(14,30,37,.16);}</style></head>" +
@@ -96,7 +108,7 @@ const authWithToken = async () => {
96
108
  throw error
97
109
  }
98
110
 
99
- module.exports = async function getGitHubToken() {
111
+ const getGitHubToken = async () => {
100
112
  log('')
101
113
 
102
114
  const withNetlify = await promptForAuthMethod()
@@ -106,3 +118,5 @@ module.exports = async function getGitHubToken() {
106
118
 
107
119
  return await authWithToken()
108
120
  }
121
+
122
+ module.exports = { getGitHubToken, authWithNetlify }
@@ -2,7 +2,7 @@ const { Octokit } = require('@octokit/rest')
2
2
  const chalk = require('chalk')
3
3
 
4
4
  const { error: failAndExit, log } = require('../command-helpers')
5
- const ghauth = require('../gh-auth')
5
+ const { getGitHubToken: ghauth } = require('../gh-auth')
6
6
 
7
7
  const { createDeployKey, formatErrorMessage, getBuildSettings, saveNetlifyToml, setupSite } = require('./utils')
8
8
 
@@ -33,4 +33,4 @@ const openBrowser = async function ({ silentBrowserNoneError, url }) {
33
33
  }
34
34
  }
35
35
 
36
- module.exports = openBrowser
36
+ module.exports = { openBrowser }