@vercel/queue 0.2.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -658,7 +658,13 @@ function parseBinaryHeaders(headers) {
658
658
  `Missing required CloudEvent headers: ${missingFields.join(", ")}`
659
659
  );
660
660
  }
661
- const region = getHeader(headers, "ce-vqsregion") ?? void 0;
661
+ const rawRegion = getHeader(headers, "ce-vqsregion") ?? void 0;
662
+ if (rawRegion !== void 0 && !/^[a-z]{2,5}[0-9]{1,2}$/.test(rawRegion)) {
663
+ throw new Error(
664
+ `Invalid ce-vqsregion header: ${JSON.stringify(rawRegion)}. Region must match /^[a-z]{2,5}[0-9]{1,2}$/ (e.g. "iad1", "lhr1").`
665
+ );
666
+ }
667
+ const region = rawRegion;
662
668
  const base = {
663
669
  queueName,
664
670
  consumerGroup,
@@ -1548,6 +1554,14 @@ function parseQueueHeaders(headers) {
1548
1554
  receiptHandle
1549
1555
  };
1550
1556
  }
1557
+ var REGION_PATTERN = /^[a-z]{2,5}[0-9]{1,2}$/;
1558
+ function validateRegion(region) {
1559
+ if (!REGION_PATTERN.test(region)) {
1560
+ throw new Error(
1561
+ `Invalid region code: ${JSON.stringify(region)}. Region must match the pattern /^[a-z]{2,5}[0-9]{1,2}$/ (e.g. "iad1", "lhr1").`
1562
+ );
1563
+ }
1564
+ }
1551
1565
  var DEFAULT_BASE_URL_RESOLVER = (region) => new URL(`https://${region}.vercel-queue.com`);
1552
1566
  function resolveBaseUrl(region, resolver) {
1553
1567
  return (resolver ?? DEFAULT_BASE_URL_RESOLVER)(region);
@@ -1565,6 +1579,7 @@ var ApiClient = class _ApiClient {
1565
1579
  baseUrlResolver;
1566
1580
  dispatcher;
1567
1581
  constructor(options) {
1582
+ validateRegion(options.region);
1568
1583
  this.region = options.region;
1569
1584
  this.baseUrlResolver = options.resolveBaseUrl;
1570
1585
  this.baseUrl = resolveBaseUrl(this.region, this.baseUrlResolver);
@@ -1679,7 +1694,7 @@ Cause: ${cause}`
1679
1694
  }
1680
1695
  console.debug("[VQS Debug] Request:", JSON.stringify(logData, null, 2));
1681
1696
  }
1682
- init.headers.set("User-Agent", `@vercel/queue/${"0.2.0"}`);
1697
+ init.headers.set("User-Agent", `@vercel/queue/${"0.3.0"}`);
1683
1698
  init.headers.set("Vqs-Client-Ts", (/* @__PURE__ */ new Date()).toISOString());
1684
1699
  const fetchInit = this.dispatcher ? { ...init, dispatcher: this.dispatcher } : init;
1685
1700
  const response = await fetch(url, fetchInit);
@@ -1773,6 +1788,7 @@ Cause: ${cause}`
1773
1788
  );
1774
1789
  }
1775
1790
  if (response.status === 202) {
1791
+ await response.text();
1776
1792
  return { messageId: null };
1777
1793
  }
1778
1794
  const responseData = await response.json();
@@ -1810,6 +1826,7 @@ Cause: ${cause}`
1810
1826
  }
1811
1827
  );
1812
1828
  if (response.status === 204) {
1829
+ await response.text();
1813
1830
  return;
1814
1831
  }
1815
1832
  if (!response.ok) {
@@ -1959,6 +1976,7 @@ Cause: ${cause}`
1959
1976
  "Missing or invalid receipt handle"
1960
1977
  );
1961
1978
  }
1979
+ await response.text();
1962
1980
  return { acknowledged: true };
1963
1981
  }
1964
1982
  async changeVisibility(options) {
@@ -2010,6 +2028,7 @@ Cause: ${cause}`
2010
2028
  "Missing receipt handle or invalid visibility timeout"
2011
2029
  );
2012
2030
  }
2031
+ await response.text();
2013
2032
  return { success: true };
2014
2033
  }
2015
2034
  };