@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.mjs CHANGED
@@ -597,7 +597,13 @@ function parseBinaryHeaders(headers) {
597
597
  `Missing required CloudEvent headers: ${missingFields.join(", ")}`
598
598
  );
599
599
  }
600
- const region = getHeader(headers, "ce-vqsregion") ?? void 0;
600
+ const rawRegion = getHeader(headers, "ce-vqsregion") ?? void 0;
601
+ if (rawRegion !== void 0 && !/^[a-z]{2,5}[0-9]{1,2}$/.test(rawRegion)) {
602
+ throw new Error(
603
+ `Invalid ce-vqsregion header: ${JSON.stringify(rawRegion)}. Region must match /^[a-z]{2,5}[0-9]{1,2}$/ (e.g. "iad1", "lhr1").`
604
+ );
605
+ }
606
+ const region = rawRegion;
601
607
  const base = {
602
608
  queueName,
603
609
  consumerGroup,
@@ -1486,6 +1492,14 @@ function parseQueueHeaders(headers) {
1486
1492
  receiptHandle
1487
1493
  };
1488
1494
  }
1495
+ var REGION_PATTERN = /^[a-z]{2,5}[0-9]{1,2}$/;
1496
+ function validateRegion(region) {
1497
+ if (!REGION_PATTERN.test(region)) {
1498
+ throw new Error(
1499
+ `Invalid region code: ${JSON.stringify(region)}. Region must match the pattern /^[a-z]{2,5}[0-9]{1,2}$/ (e.g. "iad1", "lhr1").`
1500
+ );
1501
+ }
1502
+ }
1489
1503
  var DEFAULT_BASE_URL_RESOLVER = (region) => new URL(`https://${region}.vercel-queue.com`);
1490
1504
  function resolveBaseUrl(region, resolver) {
1491
1505
  return (resolver ?? DEFAULT_BASE_URL_RESOLVER)(region);
@@ -1503,6 +1517,7 @@ var ApiClient = class _ApiClient {
1503
1517
  baseUrlResolver;
1504
1518
  dispatcher;
1505
1519
  constructor(options) {
1520
+ validateRegion(options.region);
1506
1521
  this.region = options.region;
1507
1522
  this.baseUrlResolver = options.resolveBaseUrl;
1508
1523
  this.baseUrl = resolveBaseUrl(this.region, this.baseUrlResolver);
@@ -1617,7 +1632,7 @@ Cause: ${cause}`
1617
1632
  }
1618
1633
  console.debug("[VQS Debug] Request:", JSON.stringify(logData, null, 2));
1619
1634
  }
1620
- init.headers.set("User-Agent", `@vercel/queue/${"0.2.0"}`);
1635
+ init.headers.set("User-Agent", `@vercel/queue/${"0.3.0"}`);
1621
1636
  init.headers.set("Vqs-Client-Ts", (/* @__PURE__ */ new Date()).toISOString());
1622
1637
  const fetchInit = this.dispatcher ? { ...init, dispatcher: this.dispatcher } : init;
1623
1638
  const response = await fetch(url, fetchInit);
@@ -1711,6 +1726,7 @@ Cause: ${cause}`
1711
1726
  );
1712
1727
  }
1713
1728
  if (response.status === 202) {
1729
+ await response.text();
1714
1730
  return { messageId: null };
1715
1731
  }
1716
1732
  const responseData = await response.json();
@@ -1748,6 +1764,7 @@ Cause: ${cause}`
1748
1764
  }
1749
1765
  );
1750
1766
  if (response.status === 204) {
1767
+ await response.text();
1751
1768
  return;
1752
1769
  }
1753
1770
  if (!response.ok) {
@@ -1897,6 +1914,7 @@ Cause: ${cause}`
1897
1914
  "Missing or invalid receipt handle"
1898
1915
  );
1899
1916
  }
1917
+ await response.text();
1900
1918
  return { acknowledged: true };
1901
1919
  }
1902
1920
  async changeVisibility(options) {
@@ -1948,6 +1966,7 @@ Cause: ${cause}`
1948
1966
  "Missing receipt handle or invalid visibility timeout"
1949
1967
  );
1950
1968
  }
1969
+ await response.text();
1951
1970
  return { success: true };
1952
1971
  }
1953
1972
  };