@vercel/queue 0.0.0-alpha.35 → 0.0.0-alpha.37

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
@@ -153,18 +153,6 @@ var MessageAlreadyProcessedError = class extends Error {
153
153
  this.name = "MessageAlreadyProcessedError";
154
154
  }
155
155
  };
156
- var ConcurrencyLimitError = class extends Error {
157
- /** Current number of in-flight messages for this consumer group. */
158
- currentInflight;
159
- /** Maximum allowed concurrent messages (as configured). */
160
- maxConcurrency;
161
- constructor(message = "Concurrency limit exceeded", currentInflight, maxConcurrency) {
162
- super(message);
163
- this.name = "ConcurrencyLimitError";
164
- this.currentInflight = currentInflight;
165
- this.maxConcurrency = maxConcurrency;
166
- }
167
- };
168
156
  var DuplicateMessageError = class extends Error {
169
157
  idempotencyKey;
170
158
  constructor(message, idempotencyKey) {
@@ -568,13 +556,30 @@ var QueueClient = class {
568
556
  payload,
569
557
  idempotencyKey,
570
558
  retentionSeconds,
571
- delaySeconds
559
+ delaySeconds,
560
+ headers: optionHeaders
572
561
  } = options;
573
- const headers = new Headers({
574
- Authorization: `Bearer ${await this.getToken()}`,
575
- "Content-Type": transport.contentType,
576
- ...this.customHeaders
577
- });
562
+ const headers = new Headers();
563
+ if (this.customHeaders) {
564
+ for (const [name, value] of Object.entries(this.customHeaders)) {
565
+ headers.append(name, value);
566
+ }
567
+ }
568
+ if (optionHeaders) {
569
+ const protectedHeaderNames = /* @__PURE__ */ new Set(["authorization", "content-type"]);
570
+ const isProtectedHeader = (name) => {
571
+ const lower = name.toLowerCase();
572
+ if (protectedHeaderNames.has(lower)) return true;
573
+ return lower.startsWith("vqs-");
574
+ };
575
+ for (const [name, value] of Object.entries(optionHeaders)) {
576
+ if (!isProtectedHeader(name) && value !== void 0) {
577
+ headers.append(name, value);
578
+ }
579
+ }
580
+ }
581
+ headers.set("Authorization", `Bearer ${await this.getToken()}`);
582
+ headers.set("Content-Type", transport.contentType);
578
583
  const deploymentId = this.getSendDeploymentId();
579
584
  if (deploymentId) {
580
585
  headers.set("Vqs-Deployment-Id", deploymentId);
@@ -632,25 +637,17 @@ var QueueClient = class {
632
637
  * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
633
638
  * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
634
639
  * @param options.limit - Max messages to retrieve (default: 1, min: 1, max: 10)
635
- * @param options.maxConcurrency - Max in-flight messages (default: unlimited, min: 1)
636
640
  * @param transport - Deserializer for message payloads
637
641
  * @yields Message objects with payload, messageId, receiptHandle, etc.
638
642
  * @throws {QueueEmptyError} When no messages available
639
643
  * @throws {InvalidLimitError} When limit is outside 1-10 range
640
- * @throws {ConcurrencyLimitError} When maxConcurrency exceeded
641
644
  * @throws {BadRequestError} When parameters are invalid
642
645
  * @throws {UnauthorizedError} When authentication fails
643
646
  * @throws {ForbiddenError} When access is denied
644
647
  * @throws {InternalServerError} When server encounters an error
645
648
  */
646
649
  async *receiveMessages(options, transport) {
647
- const {
648
- queueName,
649
- consumerGroup,
650
- visibilityTimeoutSeconds,
651
- limit,
652
- maxConcurrency
653
- } = options;
650
+ const { queueName, consumerGroup, visibilityTimeoutSeconds, limit } = options;
654
651
  if (limit !== void 0 && (limit < 1 || limit > 10)) {
655
652
  throw new InvalidLimitError(limit);
656
653
  }
@@ -668,9 +665,6 @@ var QueueClient = class {
668
665
  if (limit !== void 0) {
669
666
  headers.set("Vqs-Max-Messages", limit.toString());
670
667
  }
671
- if (maxConcurrency !== void 0) {
672
- headers.set("Vqs-Max-Concurrency", maxConcurrency.toString());
673
- }
674
668
  const effectiveDeploymentId = this.getConsumeDeploymentId();
675
669
  if (effectiveDeploymentId) {
676
670
  headers.set("Vqs-Deployment-Id", effectiveDeploymentId);
@@ -687,18 +681,6 @@ var QueueClient = class {
687
681
  }
688
682
  if (!response.ok) {
689
683
  const errorText = await response.text();
690
- if (response.status === 429) {
691
- let errorData = {};
692
- try {
693
- errorData = JSON.parse(errorText);
694
- } catch {
695
- }
696
- throw new ConcurrencyLimitError(
697
- errorData.error || "Concurrency limit exceeded or throttled",
698
- errorData.currentInflight,
699
- errorData.maxConcurrency
700
- );
701
- }
702
684
  throwCommonHttpError(
703
685
  response.status,
704
686
  response.statusText,
@@ -736,26 +718,18 @@ var QueueClient = class {
736
718
  * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
737
719
  * @param options.messageId - Message ID to retrieve
738
720
  * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
739
- * @param options.maxConcurrency - Max in-flight messages (default: unlimited, min: 1)
740
721
  * @param transport - Deserializer for the message payload
741
722
  * @returns Promise with the message
742
723
  * @throws {MessageNotFoundError} When message doesn't exist
743
724
  * @throws {MessageNotAvailableError} When message is in wrong state or was a duplicate
744
725
  * @throws {MessageAlreadyProcessedError} When message was already processed
745
- * @throws {ConcurrencyLimitError} When maxConcurrency exceeded
746
726
  * @throws {BadRequestError} When parameters are invalid
747
727
  * @throws {UnauthorizedError} When authentication fails
748
728
  * @throws {ForbiddenError} When access is denied
749
729
  * @throws {InternalServerError} When server encounters an error
750
730
  */
751
731
  async receiveMessageById(options, transport) {
752
- const {
753
- queueName,
754
- consumerGroup,
755
- messageId,
756
- visibilityTimeoutSeconds,
757
- maxConcurrency
758
- } = options;
732
+ const { queueName, consumerGroup, messageId, visibilityTimeoutSeconds } = options;
759
733
  const headers = new Headers({
760
734
  Authorization: `Bearer ${await this.getToken()}`,
761
735
  Accept: "multipart/mixed",
@@ -767,9 +741,6 @@ var QueueClient = class {
767
741
  visibilityTimeoutSeconds.toString()
768
742
  );
769
743
  }
770
- if (maxConcurrency !== void 0) {
771
- headers.set("Vqs-Max-Concurrency", maxConcurrency.toString());
772
- }
773
744
  const effectiveDeploymentId = this.getConsumeDeploymentId();
774
745
  if (effectiveDeploymentId) {
775
746
  headers.set("Vqs-Deployment-Id", effectiveDeploymentId);
@@ -803,18 +774,6 @@ var QueueClient = class {
803
774
  if (response.status === 410) {
804
775
  throw new MessageAlreadyProcessedError(messageId);
805
776
  }
806
- if (response.status === 429) {
807
- let errorData = {};
808
- try {
809
- errorData = JSON.parse(errorText);
810
- } catch {
811
- }
812
- throw new ConcurrencyLimitError(
813
- errorData.error || "Concurrency limit exceeded or throttled",
814
- errorData.currentInflight,
815
- errorData.maxConcurrency
816
- );
817
- }
818
777
  throwCommonHttpError(
819
778
  response.status,
820
779
  response.statusText,
@@ -1221,7 +1180,8 @@ var Topic = class {
1221
1180
  payload,
1222
1181
  idempotencyKey: options?.idempotencyKey,
1223
1182
  retentionSeconds: options?.retentionSeconds,
1224
- delaySeconds: options?.delaySeconds
1183
+ delaySeconds: options?.delaySeconds,
1184
+ headers: options?.headers
1225
1185
  },
1226
1186
  this.transport
1227
1187
  );
@@ -1404,7 +1364,8 @@ async function send(topicName, payload, options) {
1404
1364
  payload,
1405
1365
  idempotencyKey: options?.idempotencyKey,
1406
1366
  retentionSeconds: options?.retentionSeconds,
1407
- delaySeconds: options?.delaySeconds
1367
+ delaySeconds: options?.delaySeconds,
1368
+ headers: options?.headers
1408
1369
  },
1409
1370
  transport
1410
1371
  );
@@ -1493,7 +1454,6 @@ export {
1493
1454
  BadRequestError,
1494
1455
  BufferTransport,
1495
1456
  Client,
1496
- ConcurrencyLimitError,
1497
1457
  ConsumerDiscoveryError,
1498
1458
  ConsumerRegistryNotConfiguredError,
1499
1459
  DuplicateMessageError,