vercel 54.15.1 → 54.16.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 (54) hide show
  1. package/dist/chunks/{add-BHCMFK52.js → add-ODBKI7EV.js} +5 -5
  2. package/dist/chunks/{chunk-AWD3IGXU.js → chunk-3NR6OYDV.js} +1 -1
  3. package/dist/chunks/{chunk-5X6ILMYI.js → chunk-76QQSALN.js} +3 -3
  4. package/dist/chunks/{chunk-CQ24PL4F.js → chunk-7CTLNKAS.js} +48 -9
  5. package/dist/chunks/{chunk-B5DP7FOH.js → chunk-BGQPLZFA.js} +6 -6
  6. package/dist/chunks/{chunk-4GQBO7KU.js → chunk-BIHRICRM.js} +2 -2
  7. package/dist/chunks/{chunk-4TL5EF3A.js → chunk-FBYYZKN3.js} +4 -1
  8. package/dist/chunks/{chunk-OOGTHUXU.js → chunk-HL5ZRVF2.js} +6 -6
  9. package/dist/chunks/{chunk-OEFNWW5M.js → chunk-HXAMK45D.js} +2 -2
  10. package/dist/chunks/{chunk-MABHXDYV.js → chunk-INFYZRHS.js} +286 -76
  11. package/dist/chunks/{chunk-PMUUPCDL.js → chunk-JFA4NUXP.js} +1 -1
  12. package/dist/chunks/{chunk-UEPXHHDN.js → chunk-KJMSI2CT.js} +1 -1
  13. package/dist/chunks/{chunk-CBMMVXLH.js → chunk-LJXYGWOY.js} +11 -3
  14. package/dist/chunks/{chunk-4OEXX4CB.js → chunk-MSWXRAHA.js} +1 -1
  15. package/dist/chunks/{chunk-D7U6YBVT.js → chunk-NVITPK2U.js} +1 -1
  16. package/dist/chunks/{chunk-RWRYDAUG.js → chunk-O6YJBWWC.js} +1 -1
  17. package/dist/chunks/{chunk-JNVCGTF2.js → chunk-Q4ZRBN2A.js} +1 -1
  18. package/dist/chunks/{chunk-HIYWSGI7.js → chunk-Q77ALSXR.js} +3 -0
  19. package/dist/chunks/{chunk-TDFUNPL7.js → chunk-RCUMYP4L.js} +4 -4
  20. package/dist/chunks/{chunk-UYC2Q5YZ.js → chunk-U2NYO6GP.js} +1 -1
  21. package/dist/chunks/{chunk-TAUAS27Y.js → chunk-UI2T3GI4.js} +2 -2
  22. package/dist/chunks/{chunk-UJZ4RUU6.js → chunk-ULNWA6GY.js} +1 -1
  23. package/dist/chunks/{chunk-AQWK7XXE.js → chunk-VLQBXXOQ.js} +2 -2
  24. package/dist/chunks/{compile-vercel-config-LUMMHFTD.js → compile-vercel-config-7THB6MTJ.js} +2 -2
  25. package/dist/chunks/{delete-X6VOLLCP.js → delete-USWDARFF.js} +3 -3
  26. package/dist/chunks/{disable-LFH5IOCZ.js → disable-K6B26MC2.js} +3 -3
  27. package/dist/chunks/{discard-EVD33PAE.js → discard-2T7HZCGR.js} +3 -3
  28. package/dist/chunks/{edit-FL3SRS2I.js → edit-2CC2WAO4.js} +5 -5
  29. package/dist/chunks/{enable-HTU7LQK5.js → enable-KEZA6F4T.js} +3 -3
  30. package/dist/chunks/{export-R222C6IH.js → export-PE2T4HYP.js} +3 -3
  31. package/dist/chunks/{inspect-YYTAQP3A.js → inspect-TQSHD4MH.js} +4 -4
  32. package/dist/chunks/{list-AOJMWKA7.js → list-AU6URG3E.js} +4 -4
  33. package/dist/chunks/{list-SWJFJSEE.js → list-IDTF5TWY.js} +3 -3
  34. package/dist/chunks/{ls-H7KDHFK6.js → ls-XOAWRTNQ.js} +5 -5
  35. package/dist/chunks/{publish-O5VKBFJ6.js → publish-G42C77TP.js} +3 -3
  36. package/dist/chunks/{query-7UDJEOOR.js → query-YTBD7YLX.js} +3 -3
  37. package/dist/chunks/{reorder-ZPI6Q7DQ.js → reorder-BDOOUURL.js} +3 -3
  38. package/dist/chunks/{restore-7FNMEG4A.js → restore-ENUHC25O.js} +3 -3
  39. package/dist/chunks/{rm-U37YHRNF.js → rm-ALWF3NBL.js} +5 -5
  40. package/dist/chunks/{routes-YEU33SON.js → routes-KUTLDFIF.js} +2 -2
  41. package/dist/chunks/{rule-inspect-CVI3TQHN.js → rule-inspect-BV6MC7PG.js} +5 -5
  42. package/dist/chunks/{rules-ZTL4JCZO.js → rules-IGG7M2AC.js} +6 -6
  43. package/dist/chunks/{schema-LZ6VDRGM.js → schema-ZYJOJIGL.js} +3 -3
  44. package/dist/chunks/{update-O6FSP627.js → update-I3WE3IQJ.js} +5 -5
  45. package/dist/commands/build/index.js +18 -18
  46. package/dist/commands/deploy/index.js +12 -12
  47. package/dist/commands/dev/index.js +623 -95
  48. package/dist/commands/env/index.js +6 -6
  49. package/dist/commands/link/index.js +47 -13
  50. package/dist/commands/list/index.js +5 -5
  51. package/dist/commands-bulk.js +44 -40
  52. package/dist/index.js +46 -42
  53. package/dist/version.mjs +1 -1
  54. package/package.json +20 -19
@@ -9,7 +9,7 @@ import {
9
9
  } from "../../chunks/chunk-2HSQ7YUK.js";
10
10
  import {
11
11
  getUpdateCommand
12
- } from "../../chunks/chunk-OEFNWW5M.js";
12
+ } from "../../chunks/chunk-HXAMK45D.js";
13
13
  import {
14
14
  highlight
15
15
  } from "../../chunks/chunk-V5P25P7F.js";
@@ -26,28 +26,29 @@ import {
26
26
  require_mime_types,
27
27
  require_npa,
28
28
  staticFiles
29
- } from "../../chunks/chunk-CQ24PL4F.js";
29
+ } from "../../chunks/chunk-7CTLNKAS.js";
30
30
  import "../../chunks/chunk-IB5L4LKZ.js";
31
31
  import {
32
32
  pickOverrides
33
- } from "../../chunks/chunk-4OEXX4CB.js";
33
+ } from "../../chunks/chunk-MSWXRAHA.js";
34
34
  import "../../chunks/chunk-YI3JV6GM.js";
35
35
  import {
36
36
  displayDetectedServices,
37
37
  printProjectNotFoundError,
38
38
  readConfig,
39
39
  setupAndLink
40
- } from "../../chunks/chunk-5X6ILMYI.js";
40
+ } from "../../chunks/chunk-76QQSALN.js";
41
41
  import "../../chunks/chunk-QH7WYDEP.js";
42
42
  import {
43
43
  getLocalPathConfig
44
- } from "../../chunks/chunk-UJZ4RUU6.js";
45
- import "../../chunks/chunk-4TL5EF3A.js";
44
+ } from "../../chunks/chunk-ULNWA6GY.js";
45
+ import "../../chunks/chunk-FBYYZKN3.js";
46
46
  import {
47
47
  help
48
- } from "../../chunks/chunk-AWD3IGXU.js";
48
+ } from "../../chunks/chunk-3NR6OYDV.js";
49
49
  import {
50
50
  VERCEL_DIR,
51
+ VERCEL_OIDC_TOKEN,
51
52
  findRepoRoot,
52
53
  getLinkedProject,
53
54
  getVercelDirectory,
@@ -69,10 +70,10 @@ import {
69
70
  resolveProjectCwd,
70
71
  tryDetectServices,
71
72
  validateConfig
72
- } from "../../chunks/chunk-MABHXDYV.js";
73
+ } from "../../chunks/chunk-INFYZRHS.js";
73
74
  import {
74
75
  TelemetryClient
75
- } from "../../chunks/chunk-HIYWSGI7.js";
76
+ } from "../../chunks/chunk-Q77ALSXR.js";
76
77
  import {
77
78
  buildCommandWithYes,
78
79
  outputActionRequired
@@ -4821,7 +4822,7 @@ var require_requires_port = __commonJS({
4821
4822
  var require_common = __commonJS({
4822
4823
  "../../node_modules/.pnpm/http-proxy-node16@1.0.6_debug@3.1.0/node_modules/http-proxy-node16/lib/http-proxy/common.js"(exports2) {
4823
4824
  var common = exports2;
4824
- var url3 = __require("url");
4825
+ var url4 = __require("url");
4825
4826
  var extend = Object.assign;
4826
4827
  var required = require_requires_port();
4827
4828
  var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
@@ -4869,7 +4870,7 @@ var require_common = __commonJS({
4869
4870
  }
4870
4871
  var target = options[forward || "target"];
4871
4872
  var targetPath = target && options.prependPath !== false ? target.path || "" : "";
4872
- var outgoingPath = !options.toProxy ? url3.parse(req.url).path || "" : req.url;
4873
+ var outgoingPath = !options.toProxy ? url4.parse(req.url).path || "" : req.url;
4873
4874
  outgoingPath = !options.ignorePath ? outgoingPath : "";
4874
4875
  outgoing.path = common.urlJoin(targetPath, outgoingPath);
4875
4876
  if (options.changeOrigin) {
@@ -4892,11 +4893,11 @@ var require_common = __commonJS({
4892
4893
  };
4893
4894
  common.urlJoin = function() {
4894
4895
  var args2 = Array.prototype.slice.call(arguments), queryParams = [], queryParamRaw = "", retSegs;
4895
- args2.forEach((url4, index) => {
4896
- var qpStart = url4.indexOf("?");
4896
+ args2.forEach((url5, index) => {
4897
+ var qpStart = url5.indexOf("?");
4897
4898
  if (qpStart !== -1) {
4898
- queryParams.push(url4.substring(qpStart + 1));
4899
- args2[index] = url4.substring(0, qpStart);
4899
+ queryParams.push(url5.substring(qpStart + 1));
4900
+ args2[index] = url5.substring(0, qpStart);
4900
4901
  }
4901
4902
  });
4902
4903
  queryParamRaw = queryParams.filter(Boolean).join("&");
@@ -4934,7 +4935,7 @@ var require_common = __commonJS({
4934
4935
  // ../../node_modules/.pnpm/http-proxy-node16@1.0.6_debug@3.1.0/node_modules/http-proxy-node16/lib/http-proxy/passes/web-outgoing.js
4935
4936
  var require_web_outgoing = __commonJS({
4936
4937
  "../../node_modules/.pnpm/http-proxy-node16@1.0.6_debug@3.1.0/node_modules/http-proxy-node16/lib/http-proxy/passes/web-outgoing.js"(exports2, module2) {
4937
- var url3 = __require("url");
4938
+ var url4 = __require("url");
4938
4939
  var common = require_common();
4939
4940
  var redirectRegex = /^201|30(1|2|7|8)$/;
4940
4941
  module2.exports = {
@@ -4972,8 +4973,8 @@ var require_web_outgoing = __commonJS({
4972
4973
  },
4973
4974
  setRedirectHostRewrite: function setRedirectHostRewrite(req, res, proxyRes, options) {
4974
4975
  if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers["location"] && redirectRegex.test(proxyRes.statusCode)) {
4975
- var target = url3.parse(options.target);
4976
- var u = url3.parse(proxyRes.headers["location"]);
4976
+ var target = url4.parse(options.target);
4977
+ var u = url4.parse(proxyRes.headers["location"]);
4977
4978
  if (target.host != u.host) {
4978
4979
  return;
4979
4980
  }
@@ -5652,8 +5653,8 @@ var require_debug2 = __commonJS({
5652
5653
  // ../../node_modules/.pnpm/follow-redirects@1.16.0_debug@3.1.0/node_modules/follow-redirects/index.js
5653
5654
  var require_follow_redirects = __commonJS({
5654
5655
  "../../node_modules/.pnpm/follow-redirects@1.16.0_debug@3.1.0/node_modules/follow-redirects/index.js"(exports2, module2) {
5655
- var url3 = __require("url");
5656
- var URL2 = url3.URL;
5656
+ var url4 = __require("url");
5657
+ var URL2 = url4.URL;
5657
5658
  var http2 = __require("http");
5658
5659
  var https = __require("https");
5659
5660
  var Writable2 = __require("stream").Writable;
@@ -5914,7 +5915,7 @@ var require_follow_redirects = __commonJS({
5914
5915
  for (var event of events) {
5915
5916
  request.on(event, eventHandlers[event]);
5916
5917
  }
5917
- this._currentUrl = /^\//.test(this._options.path) ? url3.format(this._options) : (
5918
+ this._currentUrl = /^\//.test(this._options.path) ? url4.format(this._options) : (
5918
5919
  // When making a request to a proxy, […]
5919
5920
  // a client MUST send the target URI in absolute-form […].
5920
5921
  this._options.path
@@ -5982,7 +5983,7 @@ var require_follow_redirects = __commonJS({
5982
5983
  var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers);
5983
5984
  var currentUrlParts = parseUrl(this._currentUrl);
5984
5985
  var currentHost = currentHostHeader || currentUrlParts.host;
5985
- var currentUrl = /^\w+:/.test(location) ? this._currentUrl : url3.format(Object.assign(currentUrlParts, { host: currentHost }));
5986
+ var currentUrl = /^\w+:/.test(location) ? this._currentUrl : url4.format(Object.assign(currentUrlParts, { host: currentHost }));
5986
5987
  var redirectUrl = resolveUrl(location, currentUrl);
5987
5988
  debug("redirecting to", redirectUrl.href);
5988
5989
  this._isRedirect = true;
@@ -6060,7 +6061,7 @@ var require_follow_redirects = __commonJS({
6060
6061
  if (useNativeURL) {
6061
6062
  parsed = new URL2(input);
6062
6063
  } else {
6063
- parsed = validateUrl(url3.parse(input));
6064
+ parsed = validateUrl(url4.parse(input));
6064
6065
  if (!isString(parsed.protocol)) {
6065
6066
  throw new InvalidUrlError({ input });
6066
6067
  }
@@ -6068,7 +6069,7 @@ var require_follow_redirects = __commonJS({
6068
6069
  return parsed;
6069
6070
  }
6070
6071
  function resolveUrl(relative3, base) {
6071
- return useNativeURL ? new URL2(relative3, base) : parseUrl(url3.resolve(base, relative3));
6072
+ return useNativeURL ? new URL2(relative3, base) : parseUrl(url4.resolve(base, relative3));
6072
6073
  }
6073
6074
  function validateUrl(input) {
6074
6075
  if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
@@ -6285,16 +6286,16 @@ var require_web_incoming = __commonJS({
6285
6286
  var proxyError = createErrorHandler(proxyReq, options.target);
6286
6287
  req.on("error", proxyError);
6287
6288
  proxyReq.on("error", proxyError);
6288
- function createErrorHandler(proxyReq2, url3) {
6289
+ function createErrorHandler(proxyReq2, url4) {
6289
6290
  return function proxyError2(err) {
6290
6291
  if (req.socket.destroyed && err.code === "ECONNRESET") {
6291
- server.emit("econnreset", err, req, res, url3);
6292
+ server.emit("econnreset", err, req, res, url4);
6292
6293
  return proxyReq2.abort();
6293
6294
  }
6294
6295
  if (clb) {
6295
- clb(err, req, res, url3);
6296
+ clb(err, req, res, url4);
6296
6297
  } else {
6297
- server.emit("error", err, req, res, url3);
6298
+ server.emit("error", err, req, res, url4);
6298
6299
  }
6299
6300
  };
6300
6301
  }
@@ -15783,7 +15784,7 @@ var require_src2 = __commonJS({
15783
15784
  var path6 = __require("path");
15784
15785
  var { createHash } = __require("crypto");
15785
15786
  var { realpath, lstat, createReadStream, readdir } = __require("fs");
15786
- var url3 = require_urlparser();
15787
+ var url4 = require_urlparser();
15787
15788
  var slasher = require_glob_slash();
15788
15789
  var minimatch3 = require_minimatch2();
15789
15790
  var pathToRegExp = require_path_to_regexp();
@@ -15835,7 +15836,7 @@ var require_src2 = __commonJS({
15835
15836
  }
15836
15837
  const { keys, results } = matches;
15837
15838
  const props = {};
15838
- const { protocol } = url3.parse(destination);
15839
+ const { protocol } = url4.parse(destination);
15839
15840
  const normalizedDest = protocol ? destination : slasher(destination);
15840
15841
  const toPath = pathToRegExp.compile(normalizedDest);
15841
15842
  for (let index = 0; index < keys.length; index++) {
@@ -16190,7 +16191,7 @@ var require_src2 = __commonJS({
16190
16191
  acceptsJSON = request.headers.accept.includes("application/json");
16191
16192
  }
16192
16193
  try {
16193
- relativePath = decodeURIComponent(url3.parse(request.url).pathname);
16194
+ relativePath = decodeURIComponent(url4.parse(request.url).pathname);
16194
16195
  } catch (err) {
16195
16196
  return sendError("/", response, acceptsJSON, current, handlers, config, {
16196
16197
  statusCode: 400,
@@ -16771,7 +16772,7 @@ var import_once = __toESM(require_dist7(), 1);
16771
16772
  var import_directory = __toESM(require_directory(), 1);
16772
16773
  var import_get_port2 = __toESM(require_get_port(), 1);
16773
16774
  var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
16774
- import url2, { URL } from "url";
16775
+ import url3, { URL } from "url";
16775
16776
  import http from "http";
16776
16777
  import { randomBytes as randomBytes2 } from "crypto";
16777
16778
  import { watch } from "chokidar";
@@ -16831,7 +16832,7 @@ function relative2(a, b) {
16831
16832
 
16832
16833
  // src/util/dev/router.ts
16833
16834
  var import_pcre_to_regexp = __toESM(require_dist6(), 1);
16834
- import url from "url";
16835
+ import url2 from "url";
16835
16836
 
16836
16837
  // src/util/dev/is-url.ts
16837
16838
  function isURL(str) {
@@ -16885,6 +16886,343 @@ function formatQueryString(query) {
16885
16886
  return s || null;
16886
16887
  }
16887
16888
 
16889
+ // src/util/dev/transforms.ts
16890
+ import url from "url";
16891
+ function resolveTransforms(transforms, ctx) {
16892
+ if (!transforms || transforms.length === 0) {
16893
+ return [];
16894
+ }
16895
+ return transforms.map((transform) => {
16896
+ if (transform.type === "request.path") {
16897
+ return {
16898
+ ...transform,
16899
+ args: resolveString(transform.args, transform, ctx)
16900
+ };
16901
+ }
16902
+ return {
16903
+ ...transform,
16904
+ target: { key: resolveKey(transform.target.key, transform, ctx) },
16905
+ args: resolveArgs(transform.args, transform, ctx)
16906
+ };
16907
+ });
16908
+ }
16909
+ function applyResponseTransforms(headers, transforms) {
16910
+ for (const transform of transforms) {
16911
+ if (transform.type === "response.headers" && "target" in transform) {
16912
+ applyTransform(headers, transform, true);
16913
+ }
16914
+ }
16915
+ }
16916
+ function applyRequestTransforms(req, transforms) {
16917
+ if (transforms.length === 0) {
16918
+ return;
16919
+ }
16920
+ applyRequestHeaderTransforms(req.headers, transforms);
16921
+ const parsed = url.parse(req.url || "/");
16922
+ const query = parseQueryString(parsed.search);
16923
+ applyQueryTransforms(query, transforms);
16924
+ const newPath = getRequestPath(transforms);
16925
+ if (newPath !== void 0) {
16926
+ parsed.pathname = newPath;
16927
+ }
16928
+ parsed.search = formatQueryString(query);
16929
+ req.url = url.format(parsed);
16930
+ }
16931
+ function hasResponseTransforms(transforms) {
16932
+ return transforms.some((t) => t.type === "response.headers");
16933
+ }
16934
+ function resolveKey(key, _transform, ctx) {
16935
+ if (typeof key === "string") {
16936
+ return expandCaptureGroups(key, ctx.match, ctx.keys);
16937
+ }
16938
+ return key;
16939
+ }
16940
+ function resolveArgs(args2, transform, ctx) {
16941
+ if (typeof args2 === "string") {
16942
+ return resolveString(args2, transform, ctx);
16943
+ }
16944
+ if (Array.isArray(args2)) {
16945
+ return args2.map(
16946
+ (a) => typeof a === "string" ? resolveString(a, transform, ctx) : a
16947
+ );
16948
+ }
16949
+ return args2;
16950
+ }
16951
+ function resolveString(value, transform, ctx) {
16952
+ let resolved = expandCaptureGroups(value, ctx.match, ctx.keys);
16953
+ if (transform.env && transform.env.length > 0 && ctx.env) {
16954
+ resolved = expandEnvVars(resolved, transform.env, ctx.env);
16955
+ }
16956
+ return resolved;
16957
+ }
16958
+ function expandCaptureGroups(str, match, keys) {
16959
+ return str.replace(/\$([0-9A-Za-z_]+)/g, (whole, name) => {
16960
+ const namedIdx = keys.indexOf(name);
16961
+ if (namedIdx !== -1) {
16962
+ return match[namedIdx + 1] ?? "";
16963
+ }
16964
+ if (/^[0-9]+$/.test(name)) {
16965
+ const n = parseInt(name, 10);
16966
+ if (n < match.length) {
16967
+ return match[n] ?? "";
16968
+ }
16969
+ }
16970
+ return whole;
16971
+ });
16972
+ }
16973
+ function expandEnvVars(str, allowlist, env) {
16974
+ const allowed = new Set(allowlist);
16975
+ return str.replace(
16976
+ /\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g,
16977
+ (match, braced, bare) => {
16978
+ const name = braced ?? bare;
16979
+ if (!allowed.has(name) || env[name] === void 0) {
16980
+ return match;
16981
+ }
16982
+ return env[name];
16983
+ }
16984
+ );
16985
+ }
16986
+ function applyRequestHeaderTransforms(headers, transforms) {
16987
+ for (const transform of transforms) {
16988
+ if (transform.type === "request.headers" && "target" in transform) {
16989
+ applyTransform(headers, transform, true);
16990
+ }
16991
+ }
16992
+ }
16993
+ function applyQueryTransforms(query, transforms) {
16994
+ for (const transform of transforms) {
16995
+ if (transform.type === "request.query" && "target" in transform) {
16996
+ applyTransform(query, transform, false);
16997
+ }
16998
+ }
16999
+ for (const key of Object.keys(query)) {
17000
+ const value = query[key];
17001
+ if (value === void 0) {
17002
+ delete query[key];
17003
+ } else if (typeof value === "string") {
17004
+ query[key] = [value];
17005
+ }
17006
+ }
17007
+ }
17008
+ var HEADER_NAME_RE = /^[-\w]+$/;
17009
+ var HEADER_VALUE_RE = /^[-\w:;.,/\\"'?!(){}[\]@<>=+*#$&`|~%^ ]+$/;
17010
+ function isValidHeaderName(name) {
17011
+ return name.length > 0 && HEADER_NAME_RE.test(name);
17012
+ }
17013
+ function isValidHeaderValue(value) {
17014
+ return value.length > 0 && HEADER_VALUE_RE.test(value);
17015
+ }
17016
+ function hasValidHeaderArgs(args2) {
17017
+ if (typeof args2 === "string") {
17018
+ return isValidHeaderValue(args2);
17019
+ }
17020
+ if (Array.isArray(args2)) {
17021
+ return args2.every(isValidHeaderValue);
17022
+ }
17023
+ return false;
17024
+ }
17025
+ function applyTransform(data, transform, isHeader) {
17026
+ const keySelector = transform.target?.key;
17027
+ if (keySelector == null) {
17028
+ return;
17029
+ }
17030
+ if (isHeader && (transform.op === "set" || transform.op === "append")) {
17031
+ if (typeof keySelector === "string" && !isValidHeaderName(keySelector)) {
17032
+ return;
17033
+ }
17034
+ if (!hasValidHeaderArgs(transform.args)) {
17035
+ return;
17036
+ }
17037
+ }
17038
+ const matchedKeys = findMatchingKeys(data, keySelector);
17039
+ switch (transform.op) {
17040
+ case "set":
17041
+ opSet(data, matchedKeys, keySelector, transform.args);
17042
+ break;
17043
+ case "append":
17044
+ opAppend(data, matchedKeys, keySelector, transform.args, isHeader);
17045
+ break;
17046
+ case "delete":
17047
+ opDelete(data, matchedKeys, transform.args, isHeader);
17048
+ break;
17049
+ default:
17050
+ break;
17051
+ }
17052
+ }
17053
+ function isValidRequestPath(path6) {
17054
+ if (path6 === "" || path6.length > 2048) {
17055
+ return false;
17056
+ }
17057
+ if (path6[0] !== "/" || path6.startsWith("//")) {
17058
+ return false;
17059
+ }
17060
+ if (/[?#]/.test(path6)) {
17061
+ return false;
17062
+ }
17063
+ for (let i = 0; i < path6.length; i++) {
17064
+ const code = path6.charCodeAt(i);
17065
+ if (code <= 32 || code === 127) {
17066
+ return false;
17067
+ }
17068
+ }
17069
+ return true;
17070
+ }
17071
+ function getRequestPath(transforms) {
17072
+ let path6;
17073
+ for (const transform of transforms) {
17074
+ if (transform.type === "request.path" && transform.op === "set" && typeof transform.args === "string" && isValidRequestPath(transform.args)) {
17075
+ path6 = transform.args;
17076
+ }
17077
+ }
17078
+ return path6;
17079
+ }
17080
+ function findMatchingKeys(data, keyPattern) {
17081
+ const matched = [];
17082
+ for (const key of Object.keys(data)) {
17083
+ if (matchesRule(key, keyPattern)) {
17084
+ matched.push(key);
17085
+ }
17086
+ }
17087
+ return matched;
17088
+ }
17089
+ function matchesRule(candidate, rule) {
17090
+ candidate = candidate.toLowerCase();
17091
+ if (rule == null) {
17092
+ return true;
17093
+ }
17094
+ if (typeof rule === "string") {
17095
+ return candidate === rule.toLowerCase();
17096
+ }
17097
+ const r = rule;
17098
+ for (const [op, val] of Object.entries(r)) {
17099
+ if (val === void 0) {
17100
+ continue;
17101
+ }
17102
+ switch (op) {
17103
+ case "eq":
17104
+ if (candidate !== String(val).toLowerCase())
17105
+ return false;
17106
+ break;
17107
+ case "neq":
17108
+ if (candidate === val.toLowerCase())
17109
+ return false;
17110
+ break;
17111
+ case "inc":
17112
+ if (!val.some((v) => candidate === v.toLowerCase()))
17113
+ return false;
17114
+ break;
17115
+ case "ninc":
17116
+ if (val.some((v) => candidate === v.toLowerCase()))
17117
+ return false;
17118
+ break;
17119
+ case "pre":
17120
+ if (!candidate.startsWith(String(val).toLowerCase()))
17121
+ return false;
17122
+ break;
17123
+ case "suf":
17124
+ if (!candidate.endsWith(String(val).toLowerCase()))
17125
+ return false;
17126
+ break;
17127
+ case "sub":
17128
+ if (!candidate.includes(String(val).toLowerCase()))
17129
+ return false;
17130
+ break;
17131
+ case "gt":
17132
+ if (!(Number(candidate) > val))
17133
+ return false;
17134
+ break;
17135
+ case "gte":
17136
+ if (!(Number(candidate) >= val))
17137
+ return false;
17138
+ break;
17139
+ case "lt":
17140
+ if (!(Number(candidate) < val))
17141
+ return false;
17142
+ break;
17143
+ case "lte":
17144
+ if (!(Number(candidate) <= val))
17145
+ return false;
17146
+ break;
17147
+ default:
17148
+ break;
17149
+ }
17150
+ }
17151
+ return true;
17152
+ }
17153
+ function opSet(data, matchedKeys, keySelector, args2) {
17154
+ for (const key of matchedKeys) {
17155
+ data[key] = args2;
17156
+ }
17157
+ if (matchedKeys.length === 0 && typeof keySelector === "string" && data[keySelector] === void 0 && !isEmptyArgs(args2)) {
17158
+ data[keySelector] = args2;
17159
+ }
17160
+ }
17161
+ function opAppend(data, matchedKeys, keySelector, args2, isHeader) {
17162
+ if (isEmptyArgs(args2)) {
17163
+ return;
17164
+ }
17165
+ const toAppend = typeof args2 === "string" ? [args2] : args2 ?? [];
17166
+ for (const key of matchedKeys) {
17167
+ const next = [...toValueList(data[key], isHeader), ...toAppend];
17168
+ setTransformValue(data, key, fromValueList(next));
17169
+ }
17170
+ if (matchedKeys.length === 0 && typeof keySelector === "string") {
17171
+ setTransformValue(data, keySelector, fromValueList(toAppend));
17172
+ }
17173
+ }
17174
+ function opDelete(data, matchedKeys, args2, isHeader) {
17175
+ if (args2 == null) {
17176
+ for (const key of matchedKeys) {
17177
+ delete data[key];
17178
+ }
17179
+ return;
17180
+ }
17181
+ const patterns = typeof args2 === "string" ? [args2] : args2;
17182
+ for (const key of matchedKeys) {
17183
+ const kept = toValueList(data[key], isHeader).filter(
17184
+ (value) => !patterns.some((pattern) => matchesRule(value, pattern))
17185
+ );
17186
+ setTransformValue(data, key, fromValueList(kept));
17187
+ }
17188
+ }
17189
+ function toValueList(value, isHeader) {
17190
+ if (value === void 0) {
17191
+ return [];
17192
+ }
17193
+ if (Array.isArray(value)) {
17194
+ return value;
17195
+ }
17196
+ const str = String(value);
17197
+ if (isHeader && str.includes(",")) {
17198
+ return str.split(",").map((v) => v.trim()).filter((v) => v !== "");
17199
+ }
17200
+ return [str];
17201
+ }
17202
+ function fromValueList(values) {
17203
+ if (values.length === 0) {
17204
+ return void 0;
17205
+ }
17206
+ if (values.length === 1) {
17207
+ return values[0];
17208
+ }
17209
+ return values;
17210
+ }
17211
+ function setTransformValue(data, key, value) {
17212
+ if (value === void 0) {
17213
+ delete data[key];
17214
+ } else {
17215
+ data[key] = value;
17216
+ }
17217
+ }
17218
+ function isEmptyArgs(args2) {
17219
+ if (args2 == null)
17220
+ return true;
17221
+ if (typeof args2 === "string")
17222
+ return args2 === "";
17223
+ return args2.length === 0;
17224
+ }
17225
+
16888
17226
  // src/util/dev/router.ts
16889
17227
  function resolveRouteParameters(str, match, keys) {
16890
17228
  return str.replace(/\$([1-9a-zA-Z]+)/g, (_, param2) => {
@@ -16916,12 +17254,14 @@ function getRoutesTypes(routes = []) {
16916
17254
  }
16917
17255
  async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfig, previousHeaders, missRoutes, phase) {
16918
17256
  let result;
16919
- let { pathname: reqPathname, search: reqSearch } = url.parse(reqUrl);
17257
+ let { pathname: reqPathname, search: reqSearch } = url2.parse(reqUrl);
16920
17258
  reqPathname = reqPathname || "/";
16921
17259
  const reqQuery = parseQueryString(reqSearch);
16922
17260
  const combinedHeaders = { ...previousHeaders };
16923
17261
  let status;
16924
17262
  let isContinue = false;
17263
+ const requestTransforms = [];
17264
+ let responseTransforms;
16925
17265
  if (routes) {
16926
17266
  let idx = -1;
16927
17267
  for (const routeConfig of routes) {
@@ -16939,6 +17279,15 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
16939
17279
  const matcher = (0, import_pcre_to_regexp.default)(`%${src}%${flags}`, keys);
16940
17280
  const match = matcher.exec(reqPathname) || matcher.exec(reqPathname.substring(1));
16941
17281
  if (match) {
17282
+ const routeTransforms = routeConfig.transforms ? resolveTransforms(routeConfig.transforms, {
17283
+ match,
17284
+ keys,
17285
+ env: devServer?.envConfigs.runEnv
17286
+ }) : [];
17287
+ const isServiceMarker = typeof routeConfig.destination === "object" && routeConfig.destination !== null && routeConfig.destination.type === "service";
17288
+ if (!isServiceMarker && routeTransforms.length > 0) {
17289
+ requestTransforms.push(...routeTransforms);
17290
+ }
16942
17291
  let destPath = reqPathname;
16943
17292
  if (routeConfig.dest) {
16944
17293
  destPath = resolveRouteParameters(routeConfig.dest, match, keys);
@@ -16958,13 +17307,16 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
16958
17307
  if (routeConfig.status) {
16959
17308
  status = routeConfig.status;
16960
17309
  }
17310
+ if (routeTransforms.length > 0) {
17311
+ responseTransforms = routeTransforms;
17312
+ }
16961
17313
  reqPathname = destPath;
16962
17314
  isContinue = true;
16963
17315
  continue;
16964
17316
  }
16965
17317
  const isDestUrl = isURL(destPath);
16966
17318
  if (routeConfig.check && devServer && vercelConfig && phase !== "hit" && !isDestUrl) {
16967
- let { pathname } = url.parse(destPath);
17319
+ let { pathname } = url2.parse(destPath);
16968
17320
  pathname = pathname || "/";
16969
17321
  const hasDestFile = await devServer.hasFilesystem(
16970
17322
  pathname,
@@ -16973,6 +17325,9 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
16973
17325
  if (!hasDestFile) {
16974
17326
  if (routeConfig.status && phase !== "miss") {
16975
17327
  } else if (missRoutes && missRoutes.length > 0) {
17328
+ if (routeTransforms.length > 0) {
17329
+ responseTransforms = routeTransforms;
17330
+ }
16976
17331
  const missResult = await devRouter(
16977
17332
  destPath,
16978
17333
  reqMethod,
@@ -16984,6 +17339,15 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
16984
17339
  "miss"
16985
17340
  );
16986
17341
  if (missResult.found) {
17342
+ if (requestTransforms.length > 0) {
17343
+ missResult.requestTransforms = [
17344
+ ...requestTransforms,
17345
+ ...missResult.requestTransforms ?? []
17346
+ ];
17347
+ }
17348
+ if (!missResult.responseTransforms && responseTransforms) {
17349
+ missResult.responseTransforms = responseTransforms;
17350
+ }
16987
17351
  return missResult;
16988
17352
  } else {
16989
17353
  reqPathname = destPath;
@@ -16993,11 +17357,19 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
16993
17357
  if (routeConfig.status && phase === "miss") {
16994
17358
  status = routeConfig.status;
16995
17359
  }
17360
+ if (routeTransforms.length > 0) {
17361
+ responseTransforms = routeTransforms;
17362
+ }
16996
17363
  reqPathname = destPath;
16997
17364
  continue;
16998
17365
  }
16999
17366
  }
17000
17367
  }
17368
+ const effectiveStatus = routeConfig.status || status;
17369
+ const isRedirectExit = typeof effectiveStatus === "number" && effectiveStatus >= 300 && effectiveStatus < 400;
17370
+ if (!isServiceMarker && !isRedirectExit && routeTransforms.length > 0) {
17371
+ responseTransforms = routeTransforms;
17372
+ }
17001
17373
  if (isDestUrl) {
17002
17374
  result = {
17003
17375
  found: true,
@@ -17010,14 +17382,16 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
17010
17382
  query: reqQuery,
17011
17383
  matched_route: routeConfig,
17012
17384
  matched_route_idx: idx,
17013
- phase
17385
+ phase,
17386
+ requestTransforms,
17387
+ responseTransforms
17014
17388
  };
17015
17389
  break;
17016
17390
  } else {
17017
17391
  if (!destPath.startsWith("/")) {
17018
17392
  destPath = `/${destPath}`;
17019
17393
  }
17020
- let { pathname: destPathname, search: destSearch } = url.parse(destPath);
17394
+ let { pathname: destPathname, search: destSearch } = url2.parse(destPath);
17021
17395
  destPathname = destPathname || "/";
17022
17396
  const destQuery = parseQueryString(destSearch);
17023
17397
  Object.assign(destQuery, reqQuery);
@@ -17032,7 +17406,9 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
17032
17406
  query: destQuery,
17033
17407
  matched_route: routeConfig,
17034
17408
  matched_route_idx: idx,
17035
- phase
17409
+ phase,
17410
+ requestTransforms,
17411
+ responseTransforms
17036
17412
  };
17037
17413
  break;
17038
17414
  }
@@ -17048,7 +17424,9 @@ async function devRouter(reqUrl = "/", reqMethod, routes, devServer, vercelConfi
17048
17424
  isDestUrl: false,
17049
17425
  query: reqQuery,
17050
17426
  headers: combinedHeaders,
17051
- phase
17427
+ phase,
17428
+ requestTransforms,
17429
+ responseTransforms
17052
17430
  };
17053
17431
  }
17054
17432
  return result;
@@ -18568,8 +18946,8 @@ var ServicesOrchestrator = class {
18568
18946
  `Triggering scheduled job ${import_chalk.default.bold(serviceName)} (schedule: ${import_chalk.default.cyan(schedule)})`
18569
18947
  );
18570
18948
  try {
18571
- const url3 = `http://${managed.host}:${managed.port}${cronPath}`;
18572
- const res = await fetch(url3, { method: "POST" });
18949
+ const url4 = `http://${managed.host}:${managed.port}${cronPath}`;
18950
+ const res = await fetch(url4, { method: "POST" });
18573
18951
  output_manager_default.debug(
18574
18952
  `Cron trigger for "${serviceName}" responded with status ${res.status}`
18575
18953
  );
@@ -18606,6 +18984,8 @@ var QueueBroker = class {
18606
18984
  constructor(services, getServiceOrigin) {
18607
18985
  this.getServiceOrigin = getServiceOrigin;
18608
18986
  this.messages = /* @__PURE__ */ new Map();
18987
+ this.idempotencyRecords = /* @__PURE__ */ new Map();
18988
+ this.duplicateMessages = /* @__PURE__ */ new Map();
18609
18989
  this.consumerGroups = [];
18610
18990
  this.deliveryState = /* @__PURE__ */ new Map();
18611
18991
  for (const service of services) {
@@ -18635,6 +19015,30 @@ var QueueBroker = class {
18635
19015
  enqueue(queueName, payload, contentType2, options) {
18636
19016
  const messageId = randomBytes(16).toString("hex");
18637
19017
  const retentionMs = (options?.retentionSeconds ?? 0) > 0 ? options.retentionSeconds * 1e3 : DEFAULT_RETENTION;
19018
+ const idempotencyRecordKey = options?.idempotencyKey ? `${queueName}:${options.idempotencyKey}` : void 0;
19019
+ if (idempotencyRecordKey) {
19020
+ const record = this.idempotencyRecords.get(idempotencyRecordKey);
19021
+ if (record && record.expiresAt > Date.now()) {
19022
+ this.duplicateMessages.set(messageId, {
19023
+ queueName,
19024
+ originalMessageId: record.messageId,
19025
+ expiresAt: Date.now() + retentionMs
19026
+ });
19027
+ output_manager_default.debug(
19028
+ `queues: skipped duplicate message for queue "${queueName}"`
19029
+ );
19030
+ return { messageId };
19031
+ }
19032
+ if (record) {
19033
+ this.idempotencyRecords.delete(idempotencyRecordKey);
19034
+ }
19035
+ }
19036
+ if (idempotencyRecordKey) {
19037
+ this.idempotencyRecords.set(idempotencyRecordKey, {
19038
+ messageId,
19039
+ expiresAt: Date.now() + retentionMs
19040
+ });
19041
+ }
18638
19042
  const message2 = {
18639
19043
  messageId,
18640
19044
  payload,
@@ -18676,6 +19080,17 @@ var QueueBroker = class {
18676
19080
  }
18677
19081
  return { messageId };
18678
19082
  }
19083
+ getOriginalMessageIdForDuplicate(queueName, messageId) {
19084
+ const duplicate = this.duplicateMessages.get(messageId);
19085
+ if (!duplicate || duplicate.queueName !== queueName) {
19086
+ return null;
19087
+ }
19088
+ if (duplicate.expiresAt <= Date.now()) {
19089
+ this.duplicateMessages.delete(messageId);
19090
+ return null;
19091
+ }
19092
+ return duplicate.originalMessageId;
19093
+ }
18679
19094
  receiveById(messageId, consumerGroup) {
18680
19095
  const message2 = this.messages.get(messageId);
18681
19096
  if (!message2)
@@ -18870,6 +19285,16 @@ var QueueBroker = class {
18870
19285
  }
18871
19286
  tick() {
18872
19287
  const now = Date.now();
19288
+ for (const [key, record] of this.idempotencyRecords) {
19289
+ if (record.expiresAt <= now) {
19290
+ this.idempotencyRecords.delete(key);
19291
+ }
19292
+ }
19293
+ for (const [messageId, record] of this.duplicateMessages) {
19294
+ if (record.expiresAt <= now) {
19295
+ this.duplicateMessages.delete(messageId);
19296
+ }
19297
+ }
18873
19298
  for (const group of this.consumerGroups) {
18874
19299
  const groupDeliveries = this.deliveryState.get(group.id);
18875
19300
  if (!groupDeliveries)
@@ -18992,8 +19417,8 @@ function parseListen(str, defaultPort = 3e3) {
18992
19417
  if (!isNaN(port)) {
18993
19418
  return [port];
18994
19419
  }
18995
- const url3 = parse(str);
18996
- switch (url3.protocol) {
19420
+ const url4 = parse(str);
19421
+ switch (url4.protocol) {
18997
19422
  case "pipe:": {
18998
19423
  const cutStr = str.replace(/^pipe:/, "");
18999
19424
  if (cutStr.slice(0, 4) !== "\\\\.\\") {
@@ -19002,25 +19427,25 @@ function parseListen(str, defaultPort = 3e3) {
19002
19427
  return [cutStr];
19003
19428
  }
19004
19429
  case "unix:":
19005
- if (!url3.pathname) {
19430
+ if (!url4.pathname) {
19006
19431
  throw new Error(`Invalid UNIX domain socket endpoint: ${str}`);
19007
19432
  }
19008
- return [url3.pathname];
19433
+ return [url4.pathname];
19009
19434
  case "tcp:":
19010
- url3.port = url3.port || String(defaultPort);
19011
- return [parseInt(url3.port, 10), url3.hostname ?? void 0];
19435
+ url4.port = url4.port || String(defaultPort);
19436
+ return [parseInt(url4.port, 10), url4.hostname ?? void 0];
19012
19437
  default:
19013
- if (!url3.slashes) {
19014
- if (url3.protocol === null) {
19015
- return [defaultPort, url3.pathname ?? void 0];
19438
+ if (!url4.slashes) {
19439
+ if (url4.protocol === null) {
19440
+ return [defaultPort, url4.pathname ?? void 0];
19016
19441
  }
19017
- port = Number(url3.hostname);
19018
- if (url3.protocol && !isNaN(port)) {
19019
- return [port, url3.protocol.substring(0, url3.protocol.length - 1)];
19442
+ port = Number(url4.hostname);
19443
+ if (url4.protocol && !isNaN(port)) {
19444
+ return [port, url4.protocol.substring(0, url4.protocol.length - 1)];
19020
19445
  }
19021
19446
  }
19022
19447
  throw new Error(
19023
- `Unknown \`--listen\` scheme (protocol): ${url3.protocol}`
19448
+ `Unknown \`--listen\` scheme (protocol): ${url4.protocol}`
19024
19449
  );
19025
19450
  }
19026
19451
  }
@@ -19052,6 +19477,7 @@ var DevCommandExitError = class extends Error {
19052
19477
  };
19053
19478
  var DevServer = class {
19054
19479
  constructor(cwd, options) {
19480
+ this.responseTransformsByReq = /* @__PURE__ */ new WeakMap();
19055
19481
  this.clearVercelConfigPromise = () => {
19056
19482
  this.getVercelConfigPromise = null;
19057
19483
  };
@@ -19092,12 +19518,19 @@ var DevServer = class {
19092
19518
  /**
19093
19519
  * This is the equivalent to now-proxy exit_with_status() function.
19094
19520
  */
19095
- this.exitWithStatus = async (match, routeResult, phase, req, res, requestId) => {
19521
+ this.exitWithStatus = async (match, routeResult, phase, req, res, requestId, responseTransforms) => {
19096
19522
  const { status, headers, dest } = routeResult;
19097
19523
  const location = headers["location"] || dest;
19098
19524
  if (status && location && 300 <= status && status <= 399) {
19099
19525
  output_manager_default.debug(`Route found with redirect status code ${status}`);
19100
- await this.sendRedirect(req, res, requestId, location, status);
19526
+ await this.sendRedirect(
19527
+ req,
19528
+ res,
19529
+ requestId,
19530
+ location,
19531
+ status,
19532
+ responseTransforms
19533
+ );
19101
19534
  return true;
19102
19535
  }
19103
19536
  if (!match && status && phase !== "miss") {
@@ -19105,7 +19538,11 @@ var DevServer = class {
19105
19538
  return false;
19106
19539
  }
19107
19540
  output_manager_default.debug(`Route found with with status code ${status}`);
19108
- await this.sendError(req, res, requestId, "", status, headers);
19541
+ const errorHeaders = { ...headers };
19542
+ if (responseTransforms) {
19543
+ applyResponseTransforms(errorHeaders, responseTransforms);
19544
+ }
19545
+ await this.sendError(req, res, requestId, "", status, errorHeaders);
19109
19546
  return true;
19110
19547
  }
19111
19548
  return false;
@@ -19136,11 +19573,12 @@ var DevServer = class {
19136
19573
  const retentionSeconds = retentionHeader && !isNaN(parseInt(retentionHeader, 10)) ? parseInt(retentionHeader, 10) : void 0;
19137
19574
  const delayHeader = req.headers["vqs-delay-seconds"];
19138
19575
  const delaySeconds = delayHeader && !isNaN(parseInt(delayHeader, 10)) ? parseInt(delayHeader, 10) : void 0;
19576
+ const idempotencyKey = req.headers["vqs-idempotency-key"];
19139
19577
  const { messageId } = this.queueBroker.enqueue(
19140
19578
  topic,
19141
19579
  payload,
19142
19580
  contentType2,
19143
- { retentionSeconds, delaySeconds }
19581
+ { retentionSeconds, delaySeconds, idempotencyKey }
19144
19582
  );
19145
19583
  res.writeHead(201, {
19146
19584
  "Content-Type": "application/json",
@@ -19153,7 +19591,18 @@ var DevServer = class {
19153
19591
  /^([A-Za-z0-9_-]+)\/consumer\/([A-Za-z0-9_-]+)\/id\/([^/]+)$/
19154
19592
  );
19155
19593
  if (req.method === "POST" && receiveByIdMatch) {
19156
- const [, , consumer, messageId] = receiveByIdMatch;
19594
+ const [, queueName, consumer, messageId] = receiveByIdMatch;
19595
+ const originalMessageId = this.queueBroker.getOriginalMessageIdForDuplicate(queueName, messageId);
19596
+ if (originalMessageId) {
19597
+ res.writeHead(409, { "Content-Type": "application/json" });
19598
+ res.end(
19599
+ JSON.stringify({
19600
+ error: "This messageId was a duplicate - use originalMessageId instead",
19601
+ originalMessageId
19602
+ })
19603
+ );
19604
+ return;
19605
+ }
19157
19606
  const result = this.queueBroker.receiveById(messageId, consumer);
19158
19607
  if (!result) {
19159
19608
  res.writeHead(404);
@@ -19282,7 +19731,7 @@ ${partHeaders}\r
19282
19731
  */
19283
19732
  this.serveProjectAsNowV2 = async (req, res, requestId, vercelConfig, routes = vercelConfig.routes, callLevel = 0) => {
19284
19733
  const { debug } = output_manager_default;
19285
- const parsed = url2.parse(req.url || "/");
19734
+ const parsed = url3.parse(req.url || "/");
19286
19735
  if (typeof parsed.pathname === "string" && parsed.pathname.includes("//")) {
19287
19736
  let location = parsed.pathname.replace(/\/+/g, "/");
19288
19737
  if (parsed.search) {
@@ -19327,11 +19776,11 @@ ${partHeaders}\r
19327
19776
  const getReqUrl = (rr) => {
19328
19777
  if (rr.dest) {
19329
19778
  if (rr.query) {
19330
- const destParsed = url2.parse(rr.dest);
19779
+ const destParsed = url3.parse(rr.dest);
19331
19780
  const destQuery = parseQueryString(destParsed.search);
19332
19781
  Object.assign(destQuery, rr.query);
19333
19782
  destParsed.search = formatQueryString(destQuery);
19334
- return url2.format(destParsed);
19783
+ return url3.format(destParsed);
19335
19784
  }
19336
19785
  return rr.dest;
19337
19786
  }
@@ -19349,6 +19798,8 @@ ${partHeaders}\r
19349
19798
  let prevUrl = req.url;
19350
19799
  let prevHeaders = {};
19351
19800
  let middlewarePid;
19801
+ const requestTransforms = [];
19802
+ let responseTransforms;
19352
19803
  const middleware = [...this.buildMatches.values()].find(
19353
19804
  (m) => m.config?.middleware === true
19354
19805
  );
@@ -19454,9 +19905,9 @@ ${partHeaders}\r
19454
19905
  return;
19455
19906
  }
19456
19907
  } else {
19457
- const rewriteUrlParsed = url2.parse(beforeRewriteUrl);
19458
- rewriteUrlParsed.search = url2.parse(rewritePath).search;
19459
- req.url = url2.format(rewriteUrlParsed);
19908
+ const rewriteUrlParsed = url3.parse(beforeRewriteUrl);
19909
+ rewriteUrlParsed.search = url3.parse(rewritePath).search;
19910
+ req.url = url3.format(rewriteUrlParsed);
19460
19911
  }
19461
19912
  debug(
19462
19913
  `Rewrote incoming HTTP URL from "${beforeRewriteUrl}" to "${req.url}"`
@@ -19500,6 +19951,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19500
19951
  missRoutes,
19501
19952
  phase
19502
19953
  );
19954
+ if (routeResult.requestTransforms) {
19955
+ requestTransforms.push(...routeResult.requestTransforms);
19956
+ }
19957
+ if (routeResult.responseTransforms) {
19958
+ responseTransforms = routeResult.responseTransforms;
19959
+ }
19503
19960
  if (routeResult.continue) {
19504
19961
  if (routeResult.dest) {
19505
19962
  prevUrl = getReqUrl(routeResult);
@@ -19514,15 +19971,18 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19514
19971
  res,
19515
19972
  requestId,
19516
19973
  routeResult.matched_route,
19517
- vercelConfig
19974
+ vercelConfig,
19975
+ requestTransforms,
19976
+ responseTransforms
19518
19977
  );
19519
19978
  }
19520
19979
  if (routeResult.isDestUrl) {
19521
- const destParsed = url2.parse(routeResult.dest);
19980
+ const destParsed = url3.parse(routeResult.dest);
19522
19981
  const destQuery = parseQueryString(destParsed.search);
19523
19982
  Object.assign(destQuery, routeResult.query);
19524
19983
  destParsed.search = formatQueryString(destQuery);
19525
- const destUrl = url2.format(destParsed);
19984
+ const destUrl = url3.format(destParsed);
19985
+ this.prepareTransforms(req, requestTransforms, responseTransforms);
19526
19986
  debug(`ProxyPass: ${destUrl}`);
19527
19987
  this.setResponseHeaders(res, requestId);
19528
19988
  return proxyPass(req, res, destUrl, this, requestId);
@@ -19540,7 +20000,8 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19540
20000
  phase,
19541
20001
  req,
19542
20002
  res,
19543
- requestId
20003
+ requestId,
20004
+ responseTransforms
19544
20005
  )) {
19545
20006
  return;
19546
20007
  }
@@ -19555,6 +20016,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19555
20016
  [],
19556
20017
  "miss"
19557
20018
  );
20019
+ if (routeResult.requestTransforms) {
20020
+ requestTransforms.push(...routeResult.requestTransforms);
20021
+ }
20022
+ if (routeResult.responseTransforms) {
20023
+ responseTransforms = routeResult.responseTransforms;
20024
+ }
19558
20025
  match = await findBuildMatch(
19559
20026
  this.buildMatches,
19560
20027
  this.files,
@@ -19568,7 +20035,8 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19568
20035
  phase,
19569
20036
  req,
19570
20037
  res,
19571
- requestId
20038
+ requestId,
20039
+ responseTransforms
19572
20040
  )) {
19573
20041
  return;
19574
20042
  }
@@ -19585,6 +20053,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19585
20053
  "hit"
19586
20054
  );
19587
20055
  routeResult.status = prevStatus;
20056
+ if (routeResult.requestTransforms) {
20057
+ requestTransforms.push(...routeResult.requestTransforms);
20058
+ }
20059
+ if (routeResult.responseTransforms) {
20060
+ responseTransforms = routeResult.responseTransforms;
20061
+ }
19588
20062
  }
19589
20063
  statusCode = routeResult.status;
19590
20064
  if (match) {
@@ -19618,6 +20092,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19618
20092
  routeResult = routeResultForError;
19619
20093
  statusCode = routeResultForError.status;
19620
20094
  match = matchForError;
20095
+ if (routeResult.requestTransforms) {
20096
+ requestTransforms.push(...routeResult.requestTransforms);
20097
+ }
20098
+ if (routeResult.responseTransforms) {
20099
+ responseTransforms = routeResult.responseTransforms;
20100
+ }
19621
20101
  } else if (matched_route && matched_route.src && !matched_route.dest) {
19622
20102
  debug(
19623
20103
  "Route without `dest` detected in error phase, attempting to exit early"
@@ -19628,7 +20108,8 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19628
20108
  "error",
19629
20109
  req,
19630
20110
  res,
19631
- requestId
20111
+ requestId,
20112
+ responseTransforms
19632
20113
  )) {
19633
20114
  return;
19634
20115
  }
@@ -19660,12 +20141,13 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19660
20141
  req.headers[name] = value;
19661
20142
  }
19662
20143
  this.setResponseHeaders(res, requestId);
19663
- const origUrl = url2.parse(req.url || "/");
20144
+ const origUrl = url3.parse(req.url || "/");
19664
20145
  const origQuery = parseQueryString(origUrl.search);
19665
20146
  origUrl.pathname = dest;
19666
20147
  Object.assign(origQuery, query);
19667
20148
  origUrl.search = formatQueryString(origQuery);
19668
- req.url = url2.format(origUrl);
20149
+ req.url = url3.format(origUrl);
20150
+ this.prepareTransforms(req, requestTransforms, responseTransforms);
19669
20151
  return proxyPass(req, res, upstream, this, requestId, false);
19670
20152
  }
19671
20153
  if (statusCode === 404 && routeResult.phase === "miss" || !this.renderDirectoryListing(req, res, requestPath, requestId)) {
@@ -19676,12 +20158,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19676
20158
  const buildRequestPath = match.buildResults.has(null) ? null : requestPath;
19677
20159
  const buildResult = match.buildResults.get(buildRequestPath);
19678
20160
  if (buildResult && Array.isArray(buildResult.routes) && buildResult.routes.length > 0) {
19679
- const origUrl = url2.parse(req.url || "/");
20161
+ const origUrl = url3.parse(req.url || "/");
19680
20162
  const origQuery = parseQueryString(origUrl.search);
19681
20163
  origUrl.pathname = dest;
19682
20164
  Object.assign(origQuery, query);
19683
20165
  origUrl.search = formatQueryString(origQuery);
19684
- const newUrl = url2.format(origUrl);
20166
+ const newUrl = url3.format(origUrl);
19685
20167
  debug(
19686
20168
  `Checking build result's ${buildResult.routes.length} \`routes\` to match ${newUrl}`
19687
20169
  );
@@ -19757,11 +20239,11 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19757
20239
  debug(
19758
20240
  `Proxying to "${builderPkg.name}" dev server (port=${port}, pid=${pid})`
19759
20241
  );
19760
- const origUrl = url2.parse(req.url || "/");
20242
+ const origUrl = url3.parse(req.url || "/");
19761
20243
  const origQuery = parseQueryString(origUrl.search);
19762
20244
  Object.assign(origQuery, query);
19763
20245
  origUrl.search = formatQueryString(origQuery);
19764
- req.url = url2.format({
20246
+ req.url = url3.format({
19765
20247
  pathname: origUrl.pathname,
19766
20248
  search: origUrl.search
19767
20249
  });
@@ -19769,6 +20251,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19769
20251
  for (const [name, value] of Object.entries(headers2)) {
19770
20252
  req.headers[name] = value;
19771
20253
  }
20254
+ this.prepareTransforms(req, requestTransforms, responseTransforms);
19772
20255
  this.setResponseHeaders(res, requestId);
19773
20256
  return proxyPass(
19774
20257
  req,
@@ -19793,6 +20276,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19793
20276
  for (const [name, value] of Object.entries(headers2)) {
19794
20277
  req.headers[name] = value;
19795
20278
  }
20279
+ this.prepareTransforms(req, requestTransforms, responseTransforms);
19796
20280
  this.setResponseHeaders(res, requestId);
19797
20281
  return proxyPass(req, res, this.devProcessOrigin, this, requestId, false);
19798
20282
  }
@@ -19807,6 +20291,12 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19807
20291
  switch (asset.type) {
19808
20292
  case "FileFsRef":
19809
20293
  this.setResponseHeaders(res, requestId);
20294
+ const staticResHeaders = {};
20295
+ applyResponseTransforms(staticResHeaders, responseTransforms ?? []);
20296
+ for (const [name, value] of Object.entries(staticResHeaders)) {
20297
+ if (value !== void 0)
20298
+ res.setHeader(name, value);
20299
+ }
19810
20300
  req.url = `/${basename(asset.fsPath)}`;
19811
20301
  return serveStaticFile(req, res, dirname2(asset.fsPath), {
19812
20302
  headers: [
@@ -19826,6 +20316,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19826
20316
  "Content-Length": asset.data.length,
19827
20317
  "Content-Type": asset.contentType || getMimeType(assetKey)
19828
20318
  };
20319
+ applyResponseTransforms(headers2, responseTransforms ?? []);
19829
20320
  this.setResponseHeaders(res, requestId, headers2);
19830
20321
  res.end(asset.data);
19831
20322
  return;
@@ -19840,14 +20331,16 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19840
20331
  return;
19841
20332
  }
19842
20333
  requestId = generateRequestId(this.podId, true);
19843
- const origUrl = url2.parse(req.url || "/");
20334
+ const origUrl = url3.parse(req.url || "/");
19844
20335
  const origQuery = parseQueryString(origUrl.search);
19845
20336
  Object.assign(origQuery, query);
19846
20337
  origUrl.search = formatQueryString(origQuery);
19847
- const path6 = url2.format({
20338
+ req.url = url3.format({
19848
20339
  pathname: origUrl.pathname,
19849
20340
  search: origUrl.search
19850
20341
  });
20342
+ applyRequestTransforms(req, requestTransforms);
20343
+ const path6 = req.url || "/";
19851
20344
  const body = await (0, import_raw_body.default)(req);
19852
20345
  const payload = {
19853
20346
  method: req.method || "GET",
@@ -19881,7 +20374,9 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19881
20374
  if (!statusCode) {
19882
20375
  res.statusCode = result.statusCode;
19883
20376
  }
19884
- this.setResponseHeaders(res, requestId, result.headers);
20377
+ const lambdaHeaders = result.headers ?? {};
20378
+ applyResponseTransforms(lambdaHeaders, responseTransforms ?? []);
20379
+ this.setResponseHeaders(res, requestId, lambdaHeaders);
19885
20380
  let resBody;
19886
20381
  if (result.encoding === "base64" && typeof result.body === "string") {
19887
20382
  resBody = Buffer.from(result.body, "base64");
@@ -19912,8 +20407,13 @@ Please ensure that ${cmd(err.path)} is properly installed`;
19912
20407
  ws: true,
19913
20408
  xfwd: true
19914
20409
  });
19915
- this.proxy.on("proxyRes", (proxyRes) => {
20410
+ this.proxy.on("proxyRes", (proxyRes, req) => {
19916
20411
  proxyRes.headers["server"] = "Vercel";
20412
+ const responseTransforms = this.responseTransformsByReq.get(req);
20413
+ if (responseTransforms) {
20414
+ this.responseTransformsByReq.delete(req);
20415
+ applyResponseTransforms(proxyRes.headers, responseTransforms);
20416
+ }
19917
20417
  });
19918
20418
  this.proxy.on("error", (err, req, res) => {
19919
20419
  output_manager_default.debug(
@@ -20226,7 +20726,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
20226
20726
  return void 0;
20227
20727
  }
20228
20728
  async _getVercelConfig() {
20229
- const { compileVercelConfig } = await import("../../chunks/compile-vercel-config-LUMMHFTD.js");
20729
+ const { compileVercelConfig } = await import("../../chunks/compile-vercel-config-7THB6MTJ.js");
20230
20730
  await compileVercelConfig(this.cwd);
20231
20731
  const configPath = getLocalPathConfig(this.cwd);
20232
20732
  const [
@@ -20249,7 +20749,8 @@ Please ensure that ${cmd(err.path)} is properly installed`;
20249
20749
  await this.exit();
20250
20750
  }
20251
20751
  vercelConfig.routes = maybeRoutes || [];
20252
- if (!vercelConfig.experimentalServices && (!vercelConfig.builds || vercelConfig.builds.length === 0)) {
20752
+ const hasResolvedServices = !!this.services && this.services.length > 0;
20753
+ if (!vercelConfig.experimentalServices && !hasResolvedServices && (!vercelConfig.builds || vercelConfig.builds.length === 0)) {
20253
20754
  const featHandleMiss = true;
20254
20755
  const { projectSettings, cleanUrls, trailingSlash } = vercelConfig;
20255
20756
  const files = (await staticFiles(this.cwd, {})).map(
@@ -20604,7 +21105,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
20604
21105
  this.server.on("upgrade", async (req, socket, head) => {
20605
21106
  await this.startPromise;
20606
21107
  if (this.orchestrator) {
20607
- const pathname2 = url2.parse(req.url || "/").pathname || "/";
21108
+ const pathname2 = url3.parse(req.url || "/").pathname || "/";
20608
21109
  const service = this.orchestrator.getServiceForRoute(pathname2);
20609
21110
  if (service) {
20610
21111
  const target = `http://${service.host}:${service.port}`;
@@ -20626,7 +21127,7 @@ Please ensure that ${cmd(err.path)} is properly installed`;
20626
21127
  this.proxy.ws(req, socket, head, { target });
20627
21128
  return;
20628
21129
  }
20629
- const pathname = url2.parse(req.url || "/").pathname || "/";
21130
+ const pathname = url3.parse(req.url || "/").pathname || "/";
20630
21131
  for (const match of this.buildMatches.values()) {
20631
21132
  const { builder } = match.builderWithPkg;
20632
21133
  if ((builder.version === 3 || builder.version === -1) && typeof builder.startDevServer === "function") {
@@ -20796,10 +21297,14 @@ ${error_code}
20796
21297
  }
20797
21298
  res.end(body);
20798
21299
  }
20799
- async sendRedirect(req, res, requestId, location, statusCode = 302) {
21300
+ async sendRedirect(req, res, requestId, location, statusCode = 302, responseTransforms) {
20800
21301
  output_manager_default.debug(`Redirect ${statusCode}: ${location}`);
20801
21302
  res.statusCode = statusCode;
20802
- this.setResponseHeaders(res, requestId, { location });
21303
+ const redirectHeaders = { location };
21304
+ if (responseTransforms) {
21305
+ applyResponseTransforms(redirectHeaders, responseTransforms);
21306
+ }
21307
+ this.setResponseHeaders(res, requestId, redirectHeaders);
20803
21308
  let body;
20804
21309
  const { accept = "text/plain" } = req.headers;
20805
21310
  if (accept.includes("json")) {
@@ -20838,6 +21343,17 @@ ${error_code}
20838
21343
  res.setHeader(name, value);
20839
21344
  }
20840
21345
  }
21346
+ prepareTransforms(req, requestTransforms, responseTransforms) {
21347
+ if (requestTransforms && requestTransforms.length > 0) {
21348
+ applyRequestTransforms(req, requestTransforms);
21349
+ }
21350
+ if (responseTransforms && hasResponseTransforms(responseTransforms)) {
21351
+ this.responseTransformsByReq.set(req, responseTransforms);
21352
+ }
21353
+ }
21354
+ clearResponseTransforms(req) {
21355
+ this.responseTransformsByReq.delete(req);
21356
+ }
20841
21357
  /**
20842
21358
  * Returns the request `headers` that will be sent to the Lambda.
20843
21359
  */
@@ -20884,7 +21400,7 @@ ${error_code}
20884
21400
  }
20885
21401
  return this.serviceRoutesTable.get(serviceName) || [];
20886
21402
  }
20887
- async delegateToService(req, res, requestId, matchedRoute, vercelConfig) {
21403
+ async delegateToService(req, res, requestId, matchedRoute, vercelConfig, requestTransforms, responseTransforms) {
20888
21404
  const { debug } = output_manager_default;
20889
21405
  const { service: serviceName, path: destPath } = matchedRoute.destination;
20890
21406
  const origin = this.orchestrator?.getServiceOrigin(serviceName);
@@ -20901,7 +21417,7 @@ ${error_code}
20901
21417
  );
20902
21418
  return;
20903
21419
  }
20904
- const parsed = url2.parse(req.url || "/");
21420
+ const parsed = url3.parse(req.url || "/");
20905
21421
  const originalPathname = parsed.pathname || "/";
20906
21422
  let lookupPath = originalPathname;
20907
21423
  if (typeof destPath === "string" && matchedRoute.src) {
@@ -20915,6 +21431,10 @@ ${error_code}
20915
21431
  }
20916
21432
  const serviceRoutes = this.getServiceRouteTable(serviceName);
20917
21433
  const proxyHeaders = this.getProxyHeaders(req, requestId, false);
21434
+ const requestTransformsToApply = [
21435
+ ...requestTransforms ?? []
21436
+ ];
21437
+ let responseTransformsToApply = responseTransforms;
20918
21438
  if (serviceRoutes.length > 0) {
20919
21439
  const serviceResult = await devRouter(
20920
21440
  `${lookupPath}${parsed.search || ""}`,
@@ -20923,6 +21443,12 @@ ${error_code}
20923
21443
  this,
20924
21444
  vercelConfig
20925
21445
  );
21446
+ if (serviceResult.requestTransforms) {
21447
+ requestTransformsToApply.push(...serviceResult.requestTransforms);
21448
+ }
21449
+ if (serviceResult.responseTransforms) {
21450
+ responseTransformsToApply = serviceResult.responseTransforms;
21451
+ }
20926
21452
  const location = serviceResult.headers?.location;
20927
21453
  if (location && typeof serviceResult.status === "number" && serviceResult.status >= 300 && serviceResult.status < 400) {
20928
21454
  await this.sendRedirect(
@@ -20930,7 +21456,8 @@ ${error_code}
20930
21456
  res,
20931
21457
  requestId,
20932
21458
  location,
20933
- serviceResult.status
21459
+ serviceResult.status,
21460
+ responseTransformsToApply
20934
21461
  );
20935
21462
  return;
20936
21463
  }
@@ -20945,6 +21472,11 @@ ${error_code}
20945
21472
  for (const [name, value] of Object.entries(proxyHeaders)) {
20946
21473
  req.headers[name] = value;
20947
21474
  }
21475
+ this.prepareTransforms(
21476
+ req,
21477
+ requestTransformsToApply,
21478
+ responseTransformsToApply
21479
+ );
20948
21480
  this.setResponseHeaders(res, requestId);
20949
21481
  debug(`Delegating to service "${serviceName}": ${origin}`);
20950
21482
  return proxyPass(req, res, origin, this, requestId, false);
@@ -21170,6 +21702,7 @@ function proxyPass(req, res, dest, devServer, requestId, ignorePath = true) {
21170
21702
  res,
21171
21703
  { target: dest, ignorePath },
21172
21704
  (error2) => {
21705
+ devServer.clearResponseTransforms(req);
21173
21706
  output_manager_default.debug(`Failed to complete request to ${req.url}: ${error2}`);
21174
21707
  if (!res.headersSent) {
21175
21708
  devServer.sendError(req, res, requestId, "FUNCTION_INVOCATION_FAILED");
@@ -21361,11 +21894,6 @@ var import_ms5 = __toESM(require_ms(), 1);
21361
21894
  import { setTimeout as setTimeout2 } from "timers/promises";
21362
21895
  import { decodeJwt } from "jose";
21363
21896
  import { performance } from "perf_hooks";
21364
-
21365
- // src/util/env/constants.ts
21366
- var VERCEL_OIDC_TOKEN = "VERCEL_OIDC_TOKEN";
21367
-
21368
- // src/util/env/refresh-oidc-token.ts
21369
21897
  var REFRESH_BEFORE_EXPIRY_MILLIS = getMs(
21370
21898
  (0, import_ms5.default)("15m"),
21371
21899
  process.env.REFRESH_VERCEL_OIDC_TOKEN_BEFORE_EXPIRY_MILLIS