netlify-cli 12.2.6 → 12.2.8

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.
Files changed (112) hide show
  1. package/bin/run.mjs +2 -3
  2. package/npm-shrinkwrap.json +249 -126
  3. package/package.json +4 -4
  4. package/scripts/postinstall.mjs +2 -2
  5. package/src/commands/base-command.mjs +8 -12
  6. package/src/commands/build/build.mjs +2 -2
  7. package/src/commands/completion/completion.mjs +3 -3
  8. package/src/commands/deploy/deploy.mjs +4 -5
  9. package/src/commands/dev/{dev-exec.cjs → dev-exec.mjs} +5 -5
  10. package/src/commands/dev/{dev.cjs → dev.mjs} +32 -32
  11. package/src/commands/dev/index.mjs +1 -0
  12. package/src/commands/env/{env-clone.cjs → env-clone.mjs} +7 -16
  13. package/src/commands/env/{env-get.cjs → env-get.mjs} +5 -13
  14. package/src/commands/env/{env-import.cjs → env-import.mjs} +8 -15
  15. package/src/commands/env/{env-list.cjs → env-list.mjs} +13 -25
  16. package/src/commands/env/{env-set.cjs → env-set.mjs} +5 -5
  17. package/src/commands/env/{env-unset.cjs → env-unset.mjs} +4 -12
  18. package/src/commands/env/{env.cjs → env.mjs} +7 -9
  19. package/src/commands/env/index.mjs +1 -0
  20. package/src/commands/functions/functions-build.mjs +2 -1
  21. package/src/commands/functions/functions-create.mjs +2 -12
  22. package/src/commands/functions/functions-invoke.mjs +2 -1
  23. package/src/commands/functions/functions-list.mjs +2 -1
  24. package/src/commands/functions/functions-serve.mjs +3 -2
  25. package/src/commands/graph/{graph-config-write.cjs → graph-config-write.mjs} +8 -8
  26. package/src/commands/graph/{graph-edit.cjs → graph-edit.mjs} +9 -14
  27. package/src/commands/graph/{graph-handler.cjs → graph-handler.mjs} +6 -6
  28. package/src/commands/graph/{graph-init.cjs → graph-init.mjs} +12 -20
  29. package/src/commands/graph/{graph-library.cjs → graph-library.mjs} +8 -8
  30. package/src/commands/graph/{graph-operations.cjs → graph-operations.mjs} +7 -7
  31. package/src/commands/graph/{graph-pull.cjs → graph-pull.mjs} +8 -12
  32. package/src/commands/graph/{graph.cjs → graph.mjs} +8 -10
  33. package/src/commands/graph/index.mjs +1 -0
  34. package/src/commands/init/init.mjs +5 -2
  35. package/src/commands/link/index.mjs +1 -0
  36. package/src/commands/link/{link.cjs → link.mjs} +15 -13
  37. package/src/commands/lm/index.mjs +1 -0
  38. package/src/commands/lm/{lm-info.cjs → lm-info.mjs} +4 -6
  39. package/src/commands/lm/{lm-install.cjs → lm-install.mjs} +3 -5
  40. package/src/commands/lm/{lm-setup.cjs → lm-setup.mjs} +8 -8
  41. package/src/commands/lm/{lm-uninstall.cjs → lm-uninstall.mjs} +2 -4
  42. package/src/commands/lm/{lm.cjs → lm.mjs} +5 -7
  43. package/src/commands/logout/logout.mjs +2 -1
  44. package/src/commands/main.mjs +10 -12
  45. package/src/commands/recipes/common.mjs +36 -0
  46. package/src/commands/recipes/index.mjs +1 -0
  47. package/src/commands/recipes/{recipes-list.cjs → recipes-list.mjs} +3 -5
  48. package/src/commands/recipes/{recipes.cjs → recipes.mjs} +12 -10
  49. package/src/commands/sites/sites-create-template.mjs +3 -1
  50. package/src/commands/sites/sites-create.mjs +4 -2
  51. package/src/commands/sites/sites-list.mjs +1 -1
  52. package/src/commands/unlink/unlink.mjs +2 -1
  53. package/src/functions-templates/go/hello-world/go.mod +1 -1
  54. package/src/functions-templates/javascript/stripe-charge/package-lock.json +6 -6
  55. package/src/functions-templates/javascript/stripe-subscription/package-lock.json +6 -6
  56. package/src/functions-templates/javascript/token-hider/package-lock.json +6 -6
  57. package/src/functions-templates/rust/hello-world/Cargo.toml +1 -1
  58. package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
  59. package/src/lib/account.cjs +0 -3
  60. package/src/lib/{api.cjs → api.mjs} +3 -5
  61. package/src/lib/{build.cjs → build.mjs} +9 -9
  62. package/src/lib/completion/constants.mjs +4 -0
  63. package/src/lib/completion/{generate-autocompletion.cjs → generate-autocompletion.mjs} +6 -6
  64. package/src/lib/completion/{script.cjs → get-autocompletion.mjs} +1 -25
  65. package/src/lib/completion/index.mjs +1 -0
  66. package/src/lib/completion/script.mjs +35 -0
  67. package/src/lib/edge-functions/{editor-helper.cjs → editor-helper.mjs} +4 -6
  68. package/src/lib/edge-functions/index.cjs +1 -2
  69. package/src/lib/exec-fetcher.cjs +0 -2
  70. package/src/lib/functions/{form-submissions-handler.cjs → form-submissions-handler.mjs} +26 -28
  71. package/src/lib/functions/{scheduled.cjs → scheduled.mjs} +6 -8
  72. package/src/lib/functions/{server.cjs → server.mjs} +20 -29
  73. package/src/lib/geo-location.cjs +1 -1
  74. package/src/lib/{http-agent.cjs → http-agent.mjs} +7 -8
  75. package/src/lib/one-graph/{cli-client.cjs → cli-client.mjs} +46 -74
  76. package/src/lib/one-graph/{cli-netlify-graph.cjs → cli-netlify-graph.mjs} +35 -43
  77. package/src/recipes/vscode/{index.cjs → index.mjs} +7 -9
  78. package/src/recipes/vscode/{settings.cjs → settings.mjs} +10 -12
  79. package/src/utils/{create-stream-promise.cjs → create-stream-promise.mjs} +2 -2
  80. package/src/utils/{detect-server-settings.cjs → detect-server-settings.mjs} +14 -20
  81. package/src/utils/functions/constants.mjs +1 -0
  82. package/src/utils/functions/{functions.cjs → functions.mjs} +6 -8
  83. package/src/utils/functions/{get-functions.cjs → get-functions.mjs} +4 -25
  84. package/src/utils/functions/index.mjs +3 -0
  85. package/src/utils/get-package-json.mjs +16 -0
  86. package/src/utils/{get-repo-data.cjs → get-repo-data.mjs} +15 -12
  87. package/src/utils/{gitignore.cjs → gitignore.mjs} +6 -8
  88. package/src/utils/index.cjs +0 -20
  89. package/src/utils/{live-tunnel.cjs → live-tunnel.mjs} +8 -10
  90. package/src/utils/lm/{install.cjs → install.mjs} +26 -25
  91. package/src/utils/lm/{requirements.cjs → requirements.mjs} +6 -13
  92. package/src/utils/lm/{steps.cjs → steps.mjs} +6 -8
  93. package/src/utils/lm/{ui.cjs → ui.mjs} +5 -7
  94. package/src/utils/{proxy.cjs → proxy.mjs} +31 -34
  95. package/src/utils/{read-repo-url.cjs → read-repo-url.mjs} +6 -11
  96. package/src/utils/{state-config.cjs → state-config.mjs} +8 -10
  97. package/src/utils/telemetry/index.mjs +1 -0
  98. package/src/utils/telemetry/{request.cjs → request.mjs} +5 -3
  99. package/src/utils/telemetry/{telemetry.cjs → telemetry.mjs} +12 -14
  100. package/src/utils/telemetry/{validation.cjs → validation.mjs} +2 -2
  101. package/src/commands/dev/index.cjs +0 -5
  102. package/src/commands/env/index.cjs +0 -5
  103. package/src/commands/graph/index.cjs +0 -5
  104. package/src/commands/link/index.cjs +0 -6
  105. package/src/commands/lm/index.cjs +0 -5
  106. package/src/commands/recipes/common.cjs +0 -33
  107. package/src/commands/recipes/index.cjs +0 -8
  108. package/src/lib/completion/constants.cjs +0 -6
  109. package/src/lib/completion/index.cjs +0 -5
  110. package/src/utils/functions/constants.cjs +0 -5
  111. package/src/utils/functions/index.cjs +0 -12
  112. package/src/utils/telemetry/index.cjs +0 -5
@@ -1,15 +1,33 @@
1
1
  // @ts-check
2
- const { Readable } = require('stream')
2
+ import { Readable } from 'stream'
3
3
 
4
- const { parse: parseContentType } = require('content-type')
5
- const multiparty = require('multiparty')
6
- const getRawBody = require('raw-body')
4
+ import { parse as parseContentType } from 'content-type'
5
+ import multiparty from 'multiparty'
6
+ import getRawBody from 'raw-body'
7
7
 
8
- const { warn } = require('../../utils/command-helpers.cjs')
9
- const { BACKGROUND } = require('../../utils/index.cjs')
10
- const { capitalize } = require('../string.cjs')
8
+ import { warn } from '../../utils/command-helpers.cjs'
9
+ import { BACKGROUND } from '../../utils/functions/index.mjs'
10
+ import { capitalize } from '../string.cjs'
11
11
 
12
- const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
12
+ const getFormHandler = function ({ functionsRegistry }) {
13
+ const handlers = ['submission-created', `submission-created${BACKGROUND}`]
14
+ .map((name) => functionsRegistry.get(name))
15
+ .filter(Boolean)
16
+ .map(({ name }) => name)
17
+
18
+ if (handlers.length === 0) {
19
+ warn(`Missing form submission function handler`)
20
+ return
21
+ }
22
+
23
+ if (handlers.length === 2) {
24
+ warn(`Detected both '${handlers[0]}' and '${handlers[1]}' form submission functions handlers, using ${handlers[0]}`)
25
+ }
26
+
27
+ return handlers[0]
28
+ }
29
+
30
+ export const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
13
31
  return async function formSubmissionHandler(req, res, next) {
14
32
  if (req.url.startsWith('/.netlify/') || req.method !== 'POST') return next()
15
33
 
@@ -126,23 +144,3 @@ const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
126
144
  next()
127
145
  }
128
146
  }
129
-
130
- const getFormHandler = function ({ functionsRegistry }) {
131
- const handlers = ['submission-created', `submission-created${BACKGROUND}`]
132
- .map((name) => functionsRegistry.get(name))
133
- .filter(Boolean)
134
- .map(({ name }) => name)
135
-
136
- if (handlers.length === 0) {
137
- warn(`Missing form submission function handler`)
138
- return
139
- }
140
-
141
- if (handlers.length === 2) {
142
- warn(`Detected both '${handlers[0]}' and '${handlers[1]}' form submission functions handlers, using ${handlers[0]}`)
143
- }
144
-
145
- return handlers[0]
146
- }
147
-
148
- module.exports = { createFormSubmissionHandler }
@@ -1,12 +1,12 @@
1
- const AnsiToHtml = require('ansi-to-html')
1
+ import AnsiToHtml from 'ansi-to-html'
2
2
 
3
- const ansiToHtml = new AnsiToHtml()
3
+ import { CLOCKWORK_USERAGENT } from '../../utils/functions/index.mjs'
4
4
 
5
- const { CLOCKWORK_USERAGENT } = require('../../utils/index.cjs')
5
+ import { formatLambdaError } from './utils.cjs'
6
6
 
7
- const { formatLambdaError } = require('./utils.cjs')
7
+ const ansiToHtml = new AnsiToHtml()
8
8
 
9
- const buildHelpResponse = ({ error, headers, path, result }) => {
9
+ export const buildHelpResponse = ({ error, headers, path, result }) => {
10
10
  const acceptsHtml = headers.accept && headers.accept.includes('text/html')
11
11
 
12
12
  const paragraph = (text) => {
@@ -84,7 +84,7 @@ At the moment, Netlify does nothing about that. In the future, there might be a
84
84
  }
85
85
  }
86
86
 
87
- const handleScheduledFunction = ({ error, request, response, result }) => {
87
+ export const handleScheduledFunction = ({ error, request, response, result }) => {
88
88
  const { contentType, message, statusCode } = buildHelpResponse({
89
89
  error,
90
90
  headers: request.headers,
@@ -96,5 +96,3 @@ const handleScheduledFunction = ({ error, request, response, result }) => {
96
96
  response.set('Content-Type', contentType)
97
97
  response.send(message)
98
98
  }
99
-
100
- module.exports = { handleScheduledFunction, buildHelpResponse }
@@ -1,23 +1,18 @@
1
1
  // @ts-check
2
- const { get } = require('dot-prop')
3
- const jwtDecode = require('jwt-decode')
4
-
5
- const {
6
- CLOCKWORK_USERAGENT,
7
- NETLIFYDEVERR,
8
- NETLIFYDEVLOG,
9
- error: errorExit,
10
- generateNetlifyGraphJWT,
11
- getInternalFunctionsDir,
12
- log,
13
- } = require('../../utils/index.cjs')
14
-
15
- const { handleBackgroundFunction, handleBackgroundFunctionResult } = require('./background.cjs')
16
- const { createFormSubmissionHandler } = require('./form-submissions-handler.cjs')
17
- const { FunctionsRegistry } = require('./registry.cjs')
18
- const { handleScheduledFunction } = require('./scheduled.cjs')
19
- const { handleSynchronousFunction } = require('./synchronous.cjs')
20
- const { shouldBase64Encode } = require('./utils.cjs')
2
+ import { get } from 'dot-prop'
3
+ import jwtDecode from 'jwt-decode'
4
+
5
+ import { CLOCKWORK_USERAGENT, getInternalFunctionsDir } from '../../utils/functions/index.mjs'
6
+ import utils from '../../utils/index.cjs'
7
+
8
+ import { handleBackgroundFunction, handleBackgroundFunctionResult } from './background.cjs'
9
+ import { createFormSubmissionHandler } from './form-submissions-handler.mjs'
10
+ import { FunctionsRegistry } from './registry.cjs'
11
+ import { handleScheduledFunction } from './scheduled.mjs'
12
+ import { handleSynchronousFunction } from './synchronous.cjs'
13
+ import { shouldBase64Encode } from './utils.cjs'
14
+
15
+ const { NETLIFYDEVERR, NETLIFYDEVLOG, error: errorExit, generateNetlifyGraphJWT, log } = utils
21
16
 
22
17
  const buildClientContext = function (headers) {
23
18
  // inject a client context based on auth header, ported over from netlify-lambda (https://github.com/netlify/netlify-lambda/pull/57)
@@ -46,7 +41,7 @@ const buildClientContext = function (headers) {
46
41
  }
47
42
  }
48
43
 
49
- const createHandler = function (options) {
44
+ export const createHandler = function (options) {
50
45
  const { config, functionsRegistry } = options
51
46
 
52
47
  return async function handler(request, response) {
@@ -168,13 +163,11 @@ const createHandler = function (options) {
168
163
  }
169
164
  }
170
165
 
171
- const getFunctionsServer = function (options) {
166
+ const getFunctionsServer = async function (options) {
172
167
  const { buildersPrefix = '', functionsPrefix = '', functionsRegistry, siteUrl } = options
173
168
  // performance optimization, load express on demand
174
- // eslint-disable-next-line n/global-require
175
- const express = require('express')
176
- // eslint-disable-next-line n/global-require
177
- const expressLogging = require('express-logging')
169
+ const { default: express } = await import('express')
170
+ const { default: expressLogging } = await import('express-logging')
178
171
  const app = express()
179
172
  const functionHandler = createHandler(options)
180
173
 
@@ -204,7 +197,7 @@ const getFunctionsServer = function (options) {
204
197
  return app
205
198
  }
206
199
 
207
- const startFunctionsServer = async (options) => {
200
+ export const startFunctionsServer = async (options) => {
208
201
  const { capabilities, config, settings, site, siteUrl, timeouts } = options
209
202
  const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root })
210
203
 
@@ -224,7 +217,7 @@ const startFunctionsServer = async (options) => {
224
217
 
225
218
  await functionsRegistry.scan(functionsDirectories)
226
219
 
227
- const server = getFunctionsServer(Object.assign(options, { functionsRegistry }))
220
+ const server = await getFunctionsServer(Object.assign(options, { functionsRegistry }))
228
221
 
229
222
  await startWebServer({ server, settings })
230
223
  }
@@ -242,5 +235,3 @@ const startWebServer = async ({ server, settings }) => {
242
235
  })
243
236
  })
244
237
  }
245
-
246
- module.exports = { startFunctionsServer, createHandler }
@@ -41,7 +41,7 @@ const mockLocation = {
41
41
  * @param {"cache"|"update"|"mock"} params.mode
42
42
  * @param {string} params.geoCountry
43
43
  * @param {boolean} params.offline
44
- * @param {import('../utils/state-config').StateConfig} params.state
44
+ * @param {import('../utils/state-config.mjs').default} params.state
45
45
  * @returns {Promise<GeoLocation>}
46
46
  */
47
47
  const getGeoLocation = async ({ geoCountry, mode, offline, state }) => {
@@ -1,12 +1,13 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
2
+ import { readFile } from 'fs/promises'
3
3
 
4
- const { HttpsProxyAgent } = require('https-proxy-agent')
5
- const waitPort = require('wait-port')
4
+ import HttpsProxyAgent from 'https-proxy-agent'
5
+ import waitPort from 'wait-port'
6
6
 
7
- const { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } = require('../utils/index.cjs')
7
+ import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.cjs'
8
8
 
9
9
  // https://github.com/TooTallNate/node-https-proxy-agent/issues/89
10
+ // Maybe replace with https://github.com/delvedor/hpagent
10
11
  class HttpsProxyAgentWithCA extends HttpsProxyAgent {
11
12
  constructor(opts) {
12
13
  super(opts)
@@ -26,7 +27,7 @@ const DEFAULT_HTTPS_PORT = 443
26
27
  // 50 seconds
27
28
  const AGENT_PORT_TIMEOUT = 50
28
29
 
29
- const tryGetAgent = async ({ certificateFile, httpProxy }) => {
30
+ export const tryGetAgent = async ({ certificateFile, httpProxy }) => {
30
31
  if (!httpProxy) {
31
32
  return {}
32
33
  }
@@ -85,7 +86,7 @@ const tryGetAgent = async ({ certificateFile, httpProxy }) => {
85
86
  return response
86
87
  }
87
88
 
88
- const getAgent = async ({ certificateFile, httpProxy }) => {
89
+ export const getAgent = async ({ certificateFile, httpProxy }) => {
89
90
  const { agent, error, message, warning } = await tryGetAgent({ httpProxy, certificateFile })
90
91
  if (error) {
91
92
  log(NETLIFYDEVERR, error, message || '')
@@ -96,5 +97,3 @@ const getAgent = async ({ certificateFile, httpProxy }) => {
96
97
  }
97
98
  return agent
98
99
  }
99
-
100
- module.exports = { getAgent, tryGetAgent }
@@ -2,33 +2,21 @@
2
2
  /* eslint-disable eslint-comments/disable-enable-pair */
3
3
  /* eslint-disable fp/no-loops */
4
4
  /* eslint-disable no-underscore-dangle */
5
- const crypto = require('crypto')
6
- const { readFileSync, writeFileSync } = require('fs')
7
- const os = require('os')
8
- const path = require('path')
9
- const process = require('process')
10
-
11
- const gitRepoInfo = require('git-repo-info')
12
- const WSL = require('is-wsl')
13
- const {
14
- // eslint-disable-next-line no-unused-vars
15
- CliEventHelper,
16
- // eslint-disable-next-line no-unused-vars
17
- CodegenHelpers,
18
- GraphQL,
19
- InternalConsole,
20
- NetlifyGraph,
21
- NetlifyGraphLockfile,
22
- OneGraphClient,
23
- } = require('netlify-onegraph-internal')
24
-
25
- const frameworkInfoPromise = import('@netlify/framework-info')
26
-
27
- const { version } = require('../../../package.json')
28
- // eslint-disable-next-line no-unused-vars
29
- const { StateConfig, USER_AGENT, chalk, error, execa, log, warn, watchDebounced } = require('../../utils/index.cjs')
30
-
31
- const {
5
+ import crypto from 'crypto'
6
+ import { readFileSync, writeFileSync } from 'fs'
7
+ import os from 'os'
8
+ import path from 'path'
9
+ import process from 'process'
10
+
11
+ import { listFrameworks } from '@netlify/framework-info'
12
+ import gitRepoInfo from 'git-repo-info'
13
+ import WSL from 'is-wsl'
14
+ import { GraphQL, InternalConsole, NetlifyGraph, NetlifyGraphLockfile, OneGraphClient } from 'netlify-onegraph-internal'
15
+
16
+ import getPackageJson from '../../utils/get-package-json.mjs'
17
+ import utils from '../../utils/index.cjs'
18
+
19
+ import {
32
20
  generateFunctionsFile,
33
21
  generateHandlerByOperationId,
34
22
  getCodegenFunctionById,
@@ -38,11 +26,14 @@ const {
38
26
  setNetlifyTomlCodeGeneratorModule,
39
27
  writeGraphQLOperationsSourceFile,
40
28
  writeGraphQLSchemaFile,
41
- } = require('./cli-netlify-graph.cjs')
29
+ } from './cli-netlify-graph.mjs'
42
30
 
31
+ const { chalk, error, execa, log, warn, watchDebounced } = utils
43
32
  const { parse } = GraphQL
44
33
  const { defaultExampleOperationsDoc, extractFunctionsFromOperationDoc } = NetlifyGraph
45
34
 
35
+ const { version } = await getPackageJson()
36
+
46
37
  const internalConsole = {
47
38
  log,
48
39
  warn,
@@ -51,6 +42,7 @@ const internalConsole = {
51
42
  }
52
43
 
53
44
  /** @type {string | null} */
45
+ // eslint-disable-next-line import/no-mutable-exports
54
46
  let currentPersistedDocId = null
55
47
 
56
48
  /**
@@ -72,11 +64,11 @@ InternalConsole.registerConsole(internalConsole)
72
64
  * @param {function} input.onEvents A function to call when CLI events are received and need to be processed
73
65
  * @param {function} input.onSchemaIdChange A function to call when the CLI schemaId has changed
74
66
  * @param {string} input.sessionId The session id to monitor CLI events for
75
- * @param {StateConfig} input.state A function to call to set/get the current state of the local Netlify project
67
+ * @param {import('../../utils/state-config.mjs').default} input.state A function to call to set/get the current state of the local Netlify project
76
68
  * @param {any} input.site The site object
77
69
  * @returns
78
70
  */
79
- const monitorCLISessionEvents = (input) => {
71
+ export const monitorCLISessionEvents = (input) => {
80
72
  const { appId, config, netlifyGraphConfig, netlifyToken, onClose, onError, onEvents, site, state } = input
81
73
  const currentSessionId = input.sessionId
82
74
  // TODO (sg): Track changing schemaId for a session
@@ -239,7 +231,7 @@ const monitorOperationFile = async ({ netlifyGraphConfig, onAdd, onChange, onUnl
239
231
  * @param {string} input.jwt The Graph JWT
240
232
  * @param {string} input.sessionId The session ID for the current session
241
233
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
242
- * @param {StateConfig} input.state A function to call to set/get the current state of the local Netlify project
234
+ * @param {import('../../utils/state-config.mjs').default} input.state A function to call to set/get the current state of the local Netlify project
243
235
  * @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
244
236
  * @returns {Promise<Record<string, unknown> | undefined>}
245
237
  */
@@ -276,11 +268,11 @@ const fetchCliSessionSchema = async (input) => {
276
268
  * @param {string} input.sessionId The session ID for the current session
277
269
  * @param {string} input.schemaId The schemaId for the current session
278
270
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
279
- * @param {StateConfig} input.state A function to call to set/get the current state of the local Netlify project
271
+ * @param {import('../../utils/state-config.mjs').default} input.state A function to call to set/get the current state of the local Netlify project
280
272
  * @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
281
273
  * @returns {Promise<void>}
282
274
  */
283
- const refetchAndGenerateFromOneGraph = async (input) => {
275
+ export const refetchAndGenerateFromOneGraph = async (input) => {
284
276
  const { config, jwt, logger, netlifyGraphConfig, schemaId, siteId, state } = input
285
277
 
286
278
  await OneGraphClient.ensureAppForSite(jwt, siteId)
@@ -378,7 +370,7 @@ const regenerateFunctionsFileFromOperationsFile = (input) => {
378
370
  * @param {string} input.siteRoot The GraphQL schema to use when generating code
379
371
  * @return {NetlifyGraphLockfile.V0_format | undefined}
380
372
  */
381
- const readLockfile = ({ siteRoot }) => {
373
+ export const readLockfile = ({ siteRoot }) => {
382
374
  try {
383
375
  const buf = readFileSync(path.join(siteRoot, NetlifyGraphLockfile.defaultLockFileName))
384
376
  return JSON.parse(buf.toString('utf8'))
@@ -431,7 +423,7 @@ const mergeLockfile = ({ operationsHash, schemaId, siteRoot }) => {
431
423
  * @param {string} input.siteRoot The GraphQL schema to use when generating code
432
424
  * @return {string | undefined}
433
425
  */
434
- const readSchemaIdFromLockfile = ({ siteRoot }) => {
426
+ export const readSchemaIdFromLockfile = ({ siteRoot }) => {
435
427
  try {
436
428
  const lockfile = readLockfile({ siteRoot })
437
429
  return lockfile && lockfile.locked.schemaId
@@ -544,7 +536,7 @@ const handleOperationsLibraryPersistedEvent = async (input) => {
544
536
  *
545
537
  * @param {object} input
546
538
  * @param {any} input.site The site object
547
- * @param {CliEventHelper.CliEvent} input.event
539
+ * @param {import('netlify-onegraph-internal').CliEventHelper.CliEvent} input.event
548
540
  * @param {GraphQL.GraphQLSchema} input.schema The GraphQL schema to use when generating code
549
541
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
550
542
  * @param {object} input.config The parsed netlify.toml config file
@@ -556,7 +548,7 @@ const handleOperationsLibraryPersistedEvent = async (input) => {
556
548
  * @param {string} input.siteRoot Path to the root of the project
557
549
  * @returns {Promise<void>}
558
550
  */
559
- const handleCliSessionEvent = async ({
551
+ export const handleCliSessionEvent = async ({
560
552
  config,
561
553
  docId,
562
554
  event,
@@ -634,7 +626,7 @@ ${JSON.stringify(payload, null, 2)}`)
634
626
 
635
627
  const editor = process.env.EDITOR || null
636
628
 
637
- /** @type {CliEventHelper.OneGraphNetlifyCliSessionFilesWrittenEvent} */
629
+ /** @type {import('netlify-onegraph-internal').CliEventHelper.OneGraphNetlifyCliSessionFilesWrittenEvent} */
638
630
  const filesWrittenEvent = {
639
631
  id: crypto.randomUUID(),
640
632
  createdAt: new Date().toString(),
@@ -780,12 +772,9 @@ const getCLISessionMetadata = async ({ jwt, oneGraphSessionId, siteId }) => {
780
772
  * Look at the current project, filesystem, etc. and determine relevant metadata for a cli session
781
773
  * @param {object} input
782
774
  * @param {string} input.siteRoot The root file path for the site
783
- * @returns {Promise<CliEventHelper.DetectedLocalCLISessionMetadata>} Any locally detected facts that are relevant to include in the cli session metadata
775
+ * @returns {Promise<import('netlify-onegraph-internal').CliEventHelper.DetectedLocalCLISessionMetadata>} Any locally detected facts that are relevant to include in the cli session metadata
784
776
  */
785
777
  const detectLocalCLISessionMetadata = async ({ siteRoot }) => {
786
- // @ts-ignore
787
- const { listFrameworks } = await frameworkInfoPromise
788
-
789
778
  /** @type {string | null} */
790
779
  let framework = null
791
780
 
@@ -835,7 +824,7 @@ const detectLocalCLISessionMetadata = async ({ siteRoot }) => {
835
824
  const publishCliSessionMetadataPublishEvent = async ({ config, docId, jwt, schemaId, sessionId, siteRoot }) => {
836
825
  const detectedMetadata = await detectLocalCLISessionMetadata({ siteRoot })
837
826
 
838
- /** @type {CodegenHelpers.CodegenModuleMeta | null} */
827
+ /** @type {import('netlify-onegraph-internal').CodegenHelpers.CodegenModuleMeta | null} */
839
828
  let codegen = null
840
829
 
841
830
  const codegenModule = await getCodegenModule({ config })
@@ -854,7 +843,7 @@ const publishCliSessionMetadataPublishEvent = async ({ config, docId, jwt, schem
854
843
  }
855
844
  }
856
845
 
857
- /** @type {CliEventHelper.OneGraphNetlifyCliSessionMetadataPublishEvent} */
846
+ /** @type {import('netlify-onegraph-internal').CliEventHelper.OneGraphNetlifyCliSessionMetadataPublishEvent} */
858
847
  const event = {
859
848
  __typename: 'OneGraphNetlifyCliSessionMetadataPublishEvent',
860
849
  audience: 'UI',
@@ -900,7 +889,7 @@ const publishCliSessionMetadataPublishEvent = async ({ config, docId, jwt, schem
900
889
  * @param {object} input.newMetadata The metadata to merge into (with priority) the existing metadata
901
890
  * @returns {Promise<object>}
902
891
  */
903
- const upsertMergeCLISessionMetadata = async ({ jwt, newMetadata, oneGraphSessionId, siteId, siteRoot }) => {
892
+ export const upsertMergeCLISessionMetadata = async ({ jwt, newMetadata, oneGraphSessionId, siteId, siteRoot }) => {
904
893
  const { errors, metadata } = await getCLISessionMetadata({ jwt, oneGraphSessionId, siteId })
905
894
  if (errors) {
906
895
  warn(`Error fetching cli session metadata: ${JSON.stringify(errors, null, 2)}`)
@@ -916,7 +905,7 @@ const upsertMergeCLISessionMetadata = async ({ jwt, newMetadata, oneGraphSession
916
905
  return result
917
906
  }
918
907
 
919
- const persistNewOperationsDocForSession = async ({
908
+ export const persistNewOperationsDocForSession = async ({
920
909
  config,
921
910
  netlifyGraphConfig,
922
911
  netlifyToken,
@@ -1011,7 +1000,7 @@ const persistNewOperationsDocForSession = async ({
1011
1000
  }
1012
1001
  }
1013
1002
 
1014
- const createCLISession = async ({ metadata, netlifyToken, sessionName, siteId }) => {
1003
+ export const createCLISession = async ({ metadata, netlifyToken, sessionName, siteId }) => {
1015
1004
  const { jwt } = await OneGraphClient.getGraphJwtForSite({ siteId, nfToken: netlifyToken })
1016
1005
  const result = OneGraphClient.createCLISession(jwt, siteId, sessionName, metadata)
1017
1006
  return result
@@ -1019,10 +1008,10 @@ const createCLISession = async ({ metadata, netlifyToken, sessionName, siteId })
1019
1008
 
1020
1009
  /**
1021
1010
  * Load the CLI session id from the local state
1022
- * @param {StateConfig} state
1011
+ * @param {import('../../utils/state-config.mjs').default} state
1023
1012
  * @returns
1024
1013
  */
1025
- const loadCLISession = (state) => state.get('oneGraphSessionId')
1014
+ export const loadCLISession = (state) => state.get('oneGraphSessionId')
1026
1015
 
1027
1016
  /**
1028
1017
  * Idemponentially save the CLI session id to the local state and start monitoring for CLI events, upstream schema changes, and local operation file changes
@@ -1031,10 +1020,10 @@ const loadCLISession = (state) => state.get('oneGraphSessionId')
1031
1020
  * @param {string} input.netlifyToken The (typically netlify) access token that is used for authentication, if any
1032
1021
  * @param {string | undefined} input.oneGraphSessionId The session ID to use for this CLI session (default: read from state)
1033
1022
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
1034
- * @param {StateConfig} input.state A function to call to set/get the current state of the local Netlify project
1023
+ * @param {import('../../utils/state-config.mjs').default} input.state A function to call to set/get the current state of the local Netlify project
1035
1024
  * @param {any} input.site The site object
1036
1025
  */
1037
- const startOneGraphCLISession = async (input) => {
1026
+ export const startOneGraphCLISession = async (input) => {
1038
1027
  const { config, netlifyGraphConfig, netlifyToken, site, state } = input
1039
1028
  const getJwt = async () => {
1040
1029
  const accessToken = await OneGraphClient.getGraphJwtForSite({ siteId: site.id, nfToken: netlifyToken })
@@ -1222,7 +1211,7 @@ ${JSON.stringify(error_, null, 2)}`)
1222
1211
  * @param {string} input.siteId A function to call to set/get the current state of the local Netlify project
1223
1212
  * @param {string} input.sessionId The session id to monitor CLI events for
1224
1213
  */
1225
- const markCliSessionInactive = async ({ netlifyToken, sessionId, siteId }) => {
1214
+ export const markCliSessionInactive = async ({ netlifyToken, sessionId, siteId }) => {
1226
1215
  const { jwt } = await OneGraphClient.getGraphJwtForSite({ siteId, nfToken: netlifyToken })
1227
1216
  const result = await OneGraphClient.executeMarkCliSessionInactive(jwt, siteId, sessionId)
1228
1217
  if (!result || result.errors) {
@@ -1234,7 +1223,7 @@ const markCliSessionInactive = async ({ netlifyToken, sessionId, siteId }) => {
1234
1223
  * Generate a session name that can be identified as belonging to the current checkout
1235
1224
  * @returns {string} The name of the session to create
1236
1225
  */
1237
- const generateSessionName = () => {
1226
+ export const generateSessionName = () => {
1238
1227
  const userInfo = os.userInfo({ encoding: 'utf-8' })
1239
1228
  const sessionName = `${userInfo.username}-${Date.now()}`
1240
1229
  log(`Generated Netlify Graph session name: ${sessionName}`)
@@ -1273,11 +1262,11 @@ const idempotentlyUpdateSessionSchemaIdFromLockfile = async (input) => {
1273
1262
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig A standalone config object that contains all the information necessary for Netlify Graph to process events
1274
1263
  * @param {object} input.metadata
1275
1264
  * @param {string} input.netlifyToken
1276
- * @param {StateConfig} input.state
1265
+ * @param {import('../../utils/state-config.mjs').default} input.state
1277
1266
  * @param {string} [input.oneGraphSessionId]
1278
1267
  * @param {any} input.site The site object
1279
1268
  */
1280
- const ensureCLISession = async (input) => {
1269
+ export const ensureCLISession = async (input) => {
1281
1270
  const { config, metadata, netlifyGraphConfig, netlifyToken, site, state } = input
1282
1271
  let oneGraphSessionId = input.oneGraphSessionId ? input.oneGraphSessionId : loadCLISession(state)
1283
1272
  let parentCliSessionId = null
@@ -1389,7 +1378,7 @@ const ensureCLISession = async (input) => {
1389
1378
  return oneGraphSessionId
1390
1379
  }
1391
1380
 
1392
- const OneGraphCliClient = {
1381
+ export const OneGraphCliClient = {
1393
1382
  ackCLISessionEvents: OneGraphClient.ackCLISessionEvents,
1394
1383
  executeCreatePersistedQueryMutation: OneGraphClient.executeCreatePersistedQueryMutation,
1395
1384
  executeCreateApiTokenMutation: OneGraphClient.executeCreateApiTokenMutation,
@@ -1400,21 +1389,4 @@ const OneGraphCliClient = {
1400
1389
  getGraphJwtForSite: OneGraphClient.getGraphJwtForSite,
1401
1390
  }
1402
1391
 
1403
- module.exports = {
1404
- OneGraphCliClient,
1405
- createCLISession,
1406
- currentPersistedDocId,
1407
- ensureCLISession,
1408
- extractFunctionsFromOperationDoc,
1409
- handleCliSessionEvent,
1410
- generateSessionName,
1411
- loadCLISession,
1412
- markCliSessionInactive,
1413
- monitorCLISessionEvents,
1414
- persistNewOperationsDocForSession,
1415
- readSchemaIdFromLockfile,
1416
- refetchAndGenerateFromOneGraph,
1417
- startOneGraphCLISession,
1418
- upsertMergeCLISessionMetadata,
1419
- readLockfile,
1420
- }
1392
+ export { currentPersistedDocId, extractFunctionsFromOperationDoc }