netlify-cli 17.3.2 → 17.4.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.
Files changed (210) hide show
  1. package/README.md +2 -138
  2. package/npm-shrinkwrap.json +76 -76
  3. package/package.json +16 -15
  4. package/src/commands/addons/addons-auth.mjs +27 -30
  5. package/src/commands/addons/addons-config.mjs +145 -154
  6. package/src/commands/addons/addons-create.mjs +94 -108
  7. package/src/commands/addons/addons-delete.mjs +36 -41
  8. package/src/commands/addons/addons-list.mjs +38 -42
  9. package/src/commands/addons/addons.mjs +26 -28
  10. package/src/commands/addons/index.mjs +1 -1
  11. package/src/commands/api/api.mjs +45 -53
  12. package/src/commands/api/index.mjs +1 -1
  13. package/src/commands/base-command.mjs +597 -684
  14. package/src/commands/blobs/blobs-delete.mjs +35 -0
  15. package/src/commands/blobs/blobs-get.mjs +44 -0
  16. package/src/commands/blobs/blobs-list.mjs +48 -0
  17. package/src/commands/blobs/blobs-set.mjs +54 -0
  18. package/src/commands/blobs/blobs.mjs +32 -0
  19. package/src/commands/blobs/index.mjs +1 -0
  20. package/src/commands/build/build.mjs +55 -67
  21. package/src/commands/build/index.mjs +1 -1
  22. package/src/commands/completion/completion.mjs +41 -46
  23. package/src/commands/completion/index.mjs +1 -1
  24. package/src/commands/deploy/deploy.mjs +675 -710
  25. package/src/commands/deploy/index.mjs +1 -1
  26. package/src/commands/dev/dev-exec.mjs +20 -32
  27. package/src/commands/dev/dev.mjs +217 -302
  28. package/src/commands/dev/index.mjs +1 -1
  29. package/src/commands/dev/types.d.ts +30 -0
  30. package/src/commands/env/env-clone.mjs +157 -184
  31. package/src/commands/env/env-get.mjs +49 -68
  32. package/src/commands/env/env-import.mjs +100 -119
  33. package/src/commands/env/env-list.mjs +104 -129
  34. package/src/commands/env/env-set.mjs +160 -185
  35. package/src/commands/env/env-unset.mjs +104 -122
  36. package/src/commands/env/env.mjs +28 -30
  37. package/src/commands/env/index.mjs +1 -1
  38. package/src/commands/functions/functions-build.mjs +29 -41
  39. package/src/commands/functions/functions-create.mjs +533 -601
  40. package/src/commands/functions/functions-invoke.mjs +193 -216
  41. package/src/commands/functions/functions-list.mjs +45 -55
  42. package/src/commands/functions/functions-serve.mjs +51 -61
  43. package/src/commands/functions/functions.mjs +26 -32
  44. package/src/commands/functions/index.mjs +1 -1
  45. package/src/commands/index.mjs +2 -2
  46. package/src/commands/init/index.mjs +1 -1
  47. package/src/commands/init/init.mjs +138 -167
  48. package/src/commands/integration/deploy.mjs +337 -399
  49. package/src/commands/integration/index.mjs +12 -13
  50. package/src/commands/link/index.mjs +1 -1
  51. package/src/commands/link/link.mjs +298 -317
  52. package/src/commands/lm/index.mjs +1 -1
  53. package/src/commands/lm/lm-info.mjs +23 -31
  54. package/src/commands/lm/lm-install.mjs +13 -17
  55. package/src/commands/lm/lm-setup.mjs +80 -84
  56. package/src/commands/lm/lm-uninstall.mjs +7 -12
  57. package/src/commands/lm/lm.mjs +18 -22
  58. package/src/commands/login/index.mjs +1 -1
  59. package/src/commands/login/login.mjs +35 -41
  60. package/src/commands/logout/index.mjs +1 -1
  61. package/src/commands/logout/logout.mjs +25 -31
  62. package/src/commands/main.mjs +166 -201
  63. package/src/commands/open/index.mjs +1 -1
  64. package/src/commands/open/open-admin.mjs +15 -18
  65. package/src/commands/open/open-site.mjs +16 -19
  66. package/src/commands/open/open.mjs +24 -27
  67. package/src/commands/recipes/common.mjs +23 -34
  68. package/src/commands/recipes/index.mjs +1 -1
  69. package/src/commands/recipes/recipes-list.mjs +13 -20
  70. package/src/commands/recipes/recipes.mjs +59 -72
  71. package/src/commands/serve/index.mjs +1 -1
  72. package/src/commands/serve/serve.mjs +142 -189
  73. package/src/commands/sites/index.mjs +2 -2
  74. package/src/commands/sites/sites-create-template.mjs +214 -236
  75. package/src/commands/sites/sites-create.mjs +145 -157
  76. package/src/commands/sites/sites-delete.mjs +75 -81
  77. package/src/commands/sites/sites-list.mjs +63 -66
  78. package/src/commands/sites/sites.mjs +18 -20
  79. package/src/commands/status/index.mjs +1 -1
  80. package/src/commands/status/status-hooks.mjs +32 -34
  81. package/src/commands/status/status.mjs +99 -106
  82. package/src/commands/switch/index.mjs +1 -1
  83. package/src/commands/switch/switch.mjs +32 -37
  84. package/src/commands/types.d.ts +31 -0
  85. package/src/commands/unlink/index.mjs +1 -1
  86. package/src/commands/unlink/unlink.mjs +23 -29
  87. package/src/commands/watch/index.mjs +1 -1
  88. package/src/commands/watch/watch.mjs +91 -105
  89. package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
  90. package/src/lib/account.mjs +4 -5
  91. package/src/lib/api.mjs +22 -20
  92. package/src/lib/blobs/blobs.mjs +36 -45
  93. package/src/lib/build.mjs +82 -85
  94. package/src/lib/completion/constants.mjs +2 -4
  95. package/src/lib/completion/generate-autocompletion.mjs +33 -36
  96. package/src/lib/completion/get-autocompletion.mjs +31 -35
  97. package/src/lib/completion/index.mjs +1 -1
  98. package/src/lib/completion/script.mjs +12 -19
  99. package/src/lib/edge-functions/bootstrap.mjs +3 -5
  100. package/src/lib/edge-functions/consts.mjs +9 -10
  101. package/src/lib/edge-functions/deploy.mjs +28 -34
  102. package/src/lib/edge-functions/editor-helper.mjs +29 -42
  103. package/src/lib/edge-functions/headers.mjs +24 -26
  104. package/src/lib/edge-functions/internal.mjs +38 -44
  105. package/src/lib/edge-functions/proxy.mjs +229 -228
  106. package/src/lib/edge-functions/registry.mjs +473 -574
  107. package/src/lib/exec-fetcher.mjs +115 -122
  108. package/src/lib/fs.mjs +28 -27
  109. package/src/lib/functions/background.mjs +16 -20
  110. package/src/lib/functions/config.mjs +12 -9
  111. package/src/lib/functions/form-submissions-handler.mjs +143 -149
  112. package/src/lib/functions/local-proxy.mjs +40 -44
  113. package/src/lib/functions/memoized-build.mjs +19 -21
  114. package/src/lib/functions/netlify-function.mjs +269 -249
  115. package/src/lib/functions/registry.mjs +509 -568
  116. package/src/lib/functions/runtimes/go/index.mjs +62 -71
  117. package/src/lib/functions/runtimes/index.mjs +8 -15
  118. package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
  119. package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
  120. package/src/lib/functions/runtimes/js/constants.mjs +1 -1
  121. package/src/lib/functions/runtimes/js/index.mjs +92 -109
  122. package/src/lib/functions/runtimes/js/worker.mjs +43 -45
  123. package/src/lib/functions/runtimes/rust/index.mjs +64 -73
  124. package/src/lib/functions/scheduled.mjs +70 -88
  125. package/src/lib/functions/server.mjs +269 -327
  126. package/src/lib/functions/synchronous.mjs +118 -147
  127. package/src/lib/functions/utils.mjs +38 -46
  128. package/src/lib/geo-location.mjs +69 -81
  129. package/src/lib/http-agent.mjs +87 -90
  130. package/src/lib/images/proxy.mjs +97 -99
  131. package/src/lib/log.mjs +6 -9
  132. package/src/lib/path.mjs +2 -1
  133. package/src/lib/render-error-template.mjs +19 -20
  134. package/src/lib/settings.mjs +17 -19
  135. package/src/lib/spinner.mjs +21 -23
  136. package/src/lib/string.mjs +4 -2
  137. package/src/recipes/vscode/index.mjs +69 -85
  138. package/src/recipes/vscode/settings.mjs +53 -58
  139. package/src/utils/addons/compare.mjs +31 -32
  140. package/src/utils/addons/diffs/index.mjs +16 -17
  141. package/src/utils/addons/diffs/options.mjs +99 -101
  142. package/src/utils/addons/prepare.mjs +100 -97
  143. package/src/utils/addons/prompts.mjs +73 -76
  144. package/src/utils/addons/render.mjs +33 -36
  145. package/src/utils/addons/validation.mjs +19 -15
  146. package/src/utils/banner.mjs +11 -16
  147. package/src/utils/build-info.mjs +65 -66
  148. package/src/utils/command-helpers.mjs +185 -199
  149. package/src/utils/create-deferred.mjs +9 -12
  150. package/src/utils/create-stream-promise.mjs +54 -47
  151. package/src/utils/deploy/constants.mjs +9 -11
  152. package/src/utils/deploy/deploy-site.mjs +162 -182
  153. package/src/utils/deploy/hash-config.mjs +21 -21
  154. package/src/utils/deploy/hash-files.mjs +34 -38
  155. package/src/utils/deploy/hash-fns.mjs +149 -154
  156. package/src/utils/deploy/hasher-segments.mjs +58 -52
  157. package/src/utils/deploy/upload-files.mjs +99 -113
  158. package/src/utils/deploy/util.mjs +85 -91
  159. package/src/utils/detect-server-settings.mjs +236 -268
  160. package/src/utils/dev.mjs +163 -178
  161. package/src/utils/dot-env.mjs +37 -42
  162. package/src/utils/env/index.mjs +148 -148
  163. package/src/utils/execa.mjs +9 -13
  164. package/src/utils/feature-flags.mjs +6 -5
  165. package/src/utils/framework-server.mjs +43 -52
  166. package/src/utils/functions/constants.mjs +1 -1
  167. package/src/utils/functions/functions.mjs +30 -40
  168. package/src/utils/functions/get-functions.mjs +28 -29
  169. package/src/utils/functions/index.mjs +3 -3
  170. package/src/utils/get-global-config.mjs +33 -36
  171. package/src/utils/get-package-json.mjs +14 -15
  172. package/src/utils/get-repo-data.mjs +54 -64
  173. package/src/utils/get-site.mjs +14 -14
  174. package/src/utils/gh-auth.mjs +79 -100
  175. package/src/utils/gitignore.mjs +37 -40
  176. package/src/utils/headers.mjs +33 -35
  177. package/src/utils/hooks/requires-site-info.mjs +26 -22
  178. package/src/utils/init/config-github.mjs +207 -219
  179. package/src/utils/init/config-manual.mjs +83 -100
  180. package/src/utils/init/config.mjs +25 -26
  181. package/src/utils/init/node-version.mjs +23 -30
  182. package/src/utils/init/plugins.mjs +12 -8
  183. package/src/utils/init/utils.mjs +152 -172
  184. package/src/utils/live-tunnel.mjs +118 -141
  185. package/src/utils/lm/install.mjs +220 -259
  186. package/src/utils/lm/requirements.mjs +54 -63
  187. package/src/utils/lm/steps.mjs +31 -31
  188. package/src/utils/lm/ui.mjs +13 -20
  189. package/src/utils/open-browser.mjs +31 -32
  190. package/src/utils/parse-raw-flags.mjs +39 -35
  191. package/src/utils/proxy-server.mjs +84 -71
  192. package/src/utils/proxy.mjs +696 -750
  193. package/src/utils/read-repo-url.mjs +48 -47
  194. package/src/utils/redirects.mjs +49 -49
  195. package/src/utils/request-id.mjs +2 -4
  196. package/src/utils/rules-proxy.mjs +96 -100
  197. package/src/utils/run-build.mjs +109 -132
  198. package/src/utils/shell.mjs +99 -106
  199. package/src/utils/sign-redirect.mjs +14 -14
  200. package/src/utils/sites/utils.mjs +48 -55
  201. package/src/utils/state-config.mjs +101 -101
  202. package/src/utils/static-server.mjs +28 -34
  203. package/src/utils/telemetry/index.mjs +2 -2
  204. package/src/utils/telemetry/report-error.mjs +45 -49
  205. package/src/utils/telemetry/request.mjs +36 -43
  206. package/src/utils/telemetry/telemetry.mjs +90 -105
  207. package/src/utils/telemetry/utils.mjs +5 -6
  208. package/src/utils/telemetry/validation.mjs +55 -53
  209. package/src/utils/types.d.ts +46 -0
  210. package/src/utils/validation.mjs +10 -13
@@ -1,152 +1,146 @@
1
- // @ts-check
2
- import { Readable } from 'stream'
3
-
4
- import { parse as parseContentType } from 'content-type'
5
- import multiparty from 'multiparty'
6
- import getRawBody from 'raw-body'
7
-
8
- import { warn } from '../../utils/command-helpers.mjs'
9
- import { BACKGROUND } from '../../utils/functions/index.mjs'
10
- import { capitalize } from '../string.mjs'
11
-
1
+ import { Readable } from 'stream';
2
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'cont... Remove this comment to see the full error message
3
+ import { parse as parseContentType } from 'content-type';
4
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'mult... Remove this comment to see the full error message
5
+ import multiparty from 'multiparty';
6
+ import getRawBody from 'raw-body';
7
+ import { warn } from '../../utils/command-helpers.mjs';
8
+ import { BACKGROUND } from '../../utils/functions/index.mjs';
9
+ import { capitalize } from '../string.mjs';
10
+ // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
12
11
  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 }) {
31
- return async function formSubmissionHandler(req, res, next) {
32
- if (
33
- req.url.startsWith('/.netlify/') ||
34
- req.method !== 'POST' ||
35
- (await functionsRegistry.getFunctionForURLPath(req.url, req.method))
36
- )
37
- return next()
38
-
39
- const fakeRequest = new Readable({
40
- read() {
41
- this.push(req.body)
42
- this.push(null)
43
- },
44
- })
45
- fakeRequest.headers = req.headers
46
-
47
- const handlerName = getFormHandler({ functionsRegistry })
48
- if (!handlerName) {
49
- return next()
50
- }
51
-
52
- const originalUrl = new URL(req.url, 'http://localhost')
53
- req.url = `/.netlify/functions/${handlerName}${originalUrl.search}`
54
-
55
- const ct = parseContentType(req)
56
- let fields = {}
57
- let files = {}
58
- if (ct.type.endsWith('/x-www-form-urlencoded')) {
59
- const bodyData = await getRawBody(fakeRequest, {
60
- length: req.headers['content-length'],
61
- limit: '10mb',
62
- encoding: ct.parameters.charset,
63
- })
64
-
65
- fields = Object.fromEntries(new URLSearchParams(bodyData.toString()))
66
- } else if (ct.type === 'multipart/form-data') {
67
- try {
68
- ;[fields, files] = await new Promise((resolve, reject) => {
69
- const form = new multiparty.Form({ encoding: ct.parameters.charset || 'utf8' })
70
- form.parse(fakeRequest, (err, Fields, Files) => {
71
- if (err) return reject(err)
72
- Files = Object.entries(Files).reduce(
73
- (prev, [name, values]) => ({
74
- ...prev,
75
- [name]: values.map((value) => ({
76
- filename: value.originalFilename,
77
- size: value.size,
78
- type: value.headers && value.headers['content-type'],
79
- url: value.path,
80
- })),
81
- }),
82
- {},
83
- )
84
- return resolve([
85
- Object.entries(Fields).reduce(
86
- (prev, [name, values]) => ({ ...prev, [name]: values.length > 1 ? values : values[0] }),
87
- {},
88
- ),
89
- Object.entries(Files).reduce(
90
- (prev, [name, values]) => ({ ...prev, [name]: values.length > 1 ? values : values[0] }),
91
- {},
92
- ),
93
- ])
94
- })
95
- })
96
- } catch (error) {
97
- warn(error)
98
- return next()
99
- }
100
- } else {
101
- warn('Invalid Content-Type for Netlify Dev forms request')
102
- return next()
12
+ const handlers = ['submission-created', `submission-created${BACKGROUND}`]
13
+ .map((name) => functionsRegistry.get(name))
14
+ .filter(Boolean)
15
+ .map(({ name }) => name);
16
+ if (handlers.length === 0) {
17
+ warn(`Missing form submission function handler`);
18
+ return;
103
19
  }
104
- const data = JSON.stringify({
105
- payload: {
106
- company:
107
- fields[Object.keys(fields).find((name) => ['company', 'business', 'employer'].includes(name.toLowerCase()))],
108
- last_name:
109
- fields[Object.keys(fields).find((name) => ['lastname', 'surname', 'byname'].includes(name.toLowerCase()))],
110
- first_name:
111
- fields[
112
- Object.keys(fields).find((name) => ['firstname', 'givenname', 'forename'].includes(name.toLowerCase()))
113
- ],
114
- name: fields[Object.keys(fields).find((name) => ['name', 'fullname'].includes(name.toLowerCase()))],
115
- email:
116
- fields[
117
- Object.keys(fields).find((name) =>
118
- ['email', 'mail', 'from', 'twitter', 'sender'].includes(name.toLowerCase()),
119
- )
120
- ],
121
- title: fields[Object.keys(fields).find((name) => ['title', 'subject'].includes(name.toLowerCase()))],
122
- data: {
123
- ...fields,
124
- ...files,
125
- ip: req.connection.remoteAddress,
126
- user_agent: req.headers['user-agent'],
127
- referrer: req.headers.referer,
128
- },
129
- created_at: new Date().toISOString(),
130
- human_fields: Object.entries({
131
- ...fields,
132
- ...Object.entries(files).reduce((prev, [name, { url }]) => ({ ...prev, [name]: url }), {}),
133
- }).reduce((prev, [key, val]) => ({ ...prev, [capitalize(key)]: val }), {}),
134
- ordered_human_fields: Object.entries({
135
- ...fields,
136
- ...Object.entries(files).reduce((prev, [name, { url }]) => ({ ...prev, [name]: url }), {}),
137
- }).map(([key, val]) => ({ title: capitalize(key), name: key, value: val })),
138
- site_url: siteUrl,
139
- },
140
- })
141
- req.body = data
142
- req.headers = {
143
- ...req.headers,
144
- 'content-length': data.length,
145
- 'content-type': 'application/json',
146
- 'x-netlify-original-pathname': originalUrl.pathname,
147
- 'x-netlify-original-search': originalUrl.search,
20
+ if (handlers.length === 2) {
21
+ warn(`Detected both '${handlers[0]}' and '${handlers[1]}' form submission functions handlers, using ${handlers[0]}`);
148
22
  }
149
-
150
- next()
151
- }
152
- }
23
+ return handlers[0];
24
+ };
25
+ // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
26
+ export const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
27
+ // @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
28
+ return async function formSubmissionHandler(req, res, next) {
29
+ if (req.url.startsWith('/.netlify/') ||
30
+ req.method !== 'POST' ||
31
+ (await functionsRegistry.getFunctionForURLPath(req.url, req.method)))
32
+ return next();
33
+ const fakeRequest = new Readable({
34
+ read() {
35
+ this.push(req.body);
36
+ this.push(null);
37
+ },
38
+ });
39
+ // @ts-expect-error TS(2339) FIXME: Property 'headers' does not exist on type 'Readabl... Remove this comment to see the full error message
40
+ fakeRequest.headers = req.headers;
41
+ const handlerName = getFormHandler({ functionsRegistry });
42
+ if (!handlerName) {
43
+ return next();
44
+ }
45
+ const originalUrl = new URL(req.url, 'http://localhost');
46
+ req.url = `/.netlify/functions/${handlerName}${originalUrl.search}`;
47
+ const ct = parseContentType(req);
48
+ let fields = {};
49
+ let files = {};
50
+ if (ct.type.endsWith('/x-www-form-urlencoded')) {
51
+ const bodyData = await getRawBody(fakeRequest, {
52
+ length: req.headers['content-length'],
53
+ limit: '10mb',
54
+ encoding: ct.parameters.charset,
55
+ });
56
+ fields = Object.fromEntries(new URLSearchParams(bodyData.toString()));
57
+ }
58
+ else if (ct.type === 'multipart/form-data') {
59
+ try {
60
+ [fields, files] = await new Promise((resolve, reject) => {
61
+ const form = new multiparty.Form({ encoding: ct.parameters.charset || 'utf8' });
62
+ // @ts-expect-error TS(7006) FIXME: Parameter 'err' implicitly has an 'any' type.
63
+ form.parse(fakeRequest, (err, Fields, Files) => {
64
+ if (err)
65
+ return reject(err);
66
+ Files = Object.entries(Files).reduce((prev, [name, values]) => ({
67
+ ...prev,
68
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
69
+ [name]: values.map((value) => ({
70
+ filename: value.originalFilename,
71
+ size: value.size,
72
+ type: value.headers && value.headers['content-type'],
73
+ url: value.path,
74
+ })),
75
+ }), {});
76
+ return resolve([
77
+ Object.entries(Fields).reduce(
78
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
79
+ (prev, [name, values]) => ({ ...prev, [name]: values.length > 1 ? values : values[0] }), {}),
80
+ Object.entries(Files).reduce(
81
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
82
+ (prev, [name, values]) => ({ ...prev, [name]: values.length > 1 ? values : values[0] }), {}),
83
+ ]);
84
+ });
85
+ });
86
+ }
87
+ catch (error) {
88
+ // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
89
+ warn(error);
90
+ return next();
91
+ }
92
+ }
93
+ else {
94
+ warn('Invalid Content-Type for Netlify Dev forms request');
95
+ return next();
96
+ }
97
+ const data = JSON.stringify({
98
+ payload: {
99
+ company:
100
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
101
+ fields[Object.keys(fields).find((name) => ['company', 'business', 'employer'].includes(name.toLowerCase()))],
102
+ last_name:
103
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
104
+ fields[Object.keys(fields).find((name) => ['lastname', 'surname', 'byname'].includes(name.toLowerCase()))],
105
+ first_name: fields[
106
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
107
+ Object.keys(fields).find((name) => ['firstname', 'givenname', 'forename'].includes(name.toLowerCase()))],
108
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
109
+ name: fields[Object.keys(fields).find((name) => ['name', 'fullname'].includes(name.toLowerCase()))],
110
+ email: fields[
111
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
112
+ Object.keys(fields).find((name) => ['email', 'mail', 'from', 'twitter', 'sender'].includes(name.toLowerCase()))],
113
+ // @ts-expect-error TS(2538) FIXME: Type 'undefined' cannot be used as an index type.
114
+ title: fields[Object.keys(fields).find((name) => ['title', 'subject'].includes(name.toLowerCase()))],
115
+ data: {
116
+ ...fields,
117
+ ...files,
118
+ ip: req.connection.remoteAddress,
119
+ user_agent: req.headers['user-agent'],
120
+ referrer: req.headers.referer,
121
+ },
122
+ created_at: new Date().toISOString(),
123
+ human_fields: Object.entries({
124
+ ...fields,
125
+ // @ts-expect-error TS(2339) FIXME: Property 'url' does not exist on type 'unknown'.
126
+ ...Object.entries(files).reduce((prev, [name, { url }]) => ({ ...prev, [name]: url }), {}),
127
+ }).reduce((prev, [key, val]) => ({ ...prev, [capitalize(key)]: val }), {}),
128
+ ordered_human_fields: Object.entries({
129
+ ...fields,
130
+ // @ts-expect-error TS(2339) FIXME: Property 'url' does not exist on type 'unknown'.
131
+ ...Object.entries(files).reduce((prev, [name, { url }]) => ({ ...prev, [name]: url }), {}),
132
+ }).map(([key, val]) => ({ title: capitalize(key), name: key, value: val })),
133
+ site_url: siteUrl,
134
+ },
135
+ });
136
+ req.body = data;
137
+ req.headers = {
138
+ ...req.headers,
139
+ 'content-length': data.length,
140
+ 'content-type': 'application/json',
141
+ 'x-netlify-original-pathname': originalUrl.pathname,
142
+ 'x-netlify-original-search': originalUrl.search,
143
+ };
144
+ next();
145
+ };
146
+ };
@@ -1,45 +1,41 @@
1
- // @ts-check
2
- import { stdout } from 'process'
3
-
4
- import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy'
5
-
6
- import execa from '../../utils/execa.mjs'
7
-
1
+ import { stdout } from 'process';
2
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module '@net... Remove this comment to see the full error message
3
+ import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy';
4
+ // @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
5
+ import execa from '../../utils/execa.mjs';
6
+ // @ts-expect-error TS(7031) FIXME: Binding element 'binaryPath' implicitly has an 'an... Remove this comment to see the full error message
8
7
  export const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
9
- const functionsProxyPath = getFunctionsProxyPath()
10
- const requestData = {
11
- resource: '',
12
- ...event,
13
- headers: {
14
- ...event.headers,
15
- 'X-Amzn-Trace-Id': '1a2b3c4d5e6f',
16
- },
17
- requestContext: {
18
- ...context,
19
- httpMethod: event.httpMethod || 'GET',
20
- requestTimeEpoch: 0,
21
- },
22
- }
23
-
24
- if (functionsProxyPath === null) {
25
- throw new Error('Host machine does not support local functions proxy server')
26
- }
27
-
28
- const parameters = [
29
- '--event',
30
- JSON.stringify(requestData),
31
- '--command',
32
- binaryPath,
33
- '--working-dir',
34
- directory,
35
- '--name',
36
- name,
37
- '--timeout',
38
- `${timeout}s`,
39
- ]
40
- const proxyProcess = execa(functionsProxyPath, parameters)
41
-
42
- proxyProcess.stderr.pipe(stdout)
43
-
44
- return proxyProcess
45
- }
8
+ const functionsProxyPath = getFunctionsProxyPath();
9
+ const requestData = {
10
+ resource: '',
11
+ ...event,
12
+ headers: {
13
+ ...event.headers,
14
+ 'X-Amzn-Trace-Id': '1a2b3c4d5e6f',
15
+ },
16
+ requestContext: {
17
+ ...context,
18
+ httpMethod: event.httpMethod || 'GET',
19
+ requestTimeEpoch: 0,
20
+ },
21
+ };
22
+ if (functionsProxyPath === null) {
23
+ throw new Error('Host machine does not support local functions proxy server');
24
+ }
25
+ const parameters = [
26
+ '--event',
27
+ JSON.stringify(requestData),
28
+ '--command',
29
+ binaryPath,
30
+ '--working-dir',
31
+ directory,
32
+ '--name',
33
+ name,
34
+ '--timeout',
35
+ `${timeout}s`,
36
+ ];
37
+ // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type.
38
+ const proxyProcess = execa(functionsProxyPath, parameters);
39
+ proxyProcess.stderr.pipe(stdout);
40
+ return proxyProcess;
41
+ };
@@ -1,5 +1,4 @@
1
- const DEBOUNCE_INTERVAL = 300
2
-
1
+ const DEBOUNCE_INTERVAL = 300;
3
2
  // `memoizedBuild` will avoid running the same build command multiple times
4
3
  // until the previous operation has been completed. If another call is made
5
4
  // within that period, it will be:
@@ -8,24 +7,23 @@ const DEBOUNCE_INTERVAL = 300
8
7
  // This allows us to discard any duplicate filesystem events, while ensuring
9
8
  // that actual updates happening during the zip operation will be executed
10
9
  // after it finishes (only the last update will run).
10
+ // @ts-expect-error TS(7031) FIXME: Binding element 'cache' implicitly has an 'any' ty... Remove this comment to see the full error message
11
11
  export const memoizedBuild = ({ cache, cacheKey, command }) => {
12
- if (cache[cacheKey] === undefined) {
13
- cache[cacheKey] = {
14
- // eslint-disable-next-line promise/prefer-await-to-then
15
- task: command().finally(() => {
16
- const entry = cache[cacheKey]
17
-
18
- cache[cacheKey] = undefined
19
-
20
- if (entry.enqueued !== undefined) {
21
- memoizedBuild({ cacheKey, command, cache })
22
- }
23
- }),
24
- timestamp: Date.now(),
12
+ if (cache[cacheKey] === undefined) {
13
+ cache[cacheKey] = {
14
+ // eslint-disable-next-line promise/prefer-await-to-then
15
+ task: command().finally(() => {
16
+ const entry = cache[cacheKey];
17
+ cache[cacheKey] = undefined;
18
+ if (entry.enqueued !== undefined) {
19
+ memoizedBuild({ cacheKey, command, cache });
20
+ }
21
+ }),
22
+ timestamp: Date.now(),
23
+ };
25
24
  }
26
- } else if (Date.now() > cache[cacheKey].timestamp + DEBOUNCE_INTERVAL) {
27
- cache[cacheKey].enqueued = true
28
- }
29
-
30
- return cache[cacheKey].task
31
- }
25
+ else if (Date.now() > cache[cacheKey].timestamp + DEBOUNCE_INTERVAL) {
26
+ cache[cacheKey].enqueued = true;
27
+ }
28
+ return cache[cacheKey].task;
29
+ };