@vercel/queue 0.2.0 → 0.2.1

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.2.1"}`);
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);