@upstash/qstash 2.9.1-rc.1 → 2.9.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/index.js CHANGED
@@ -32,6 +32,7 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  Chat: () => Chat,
34
34
  Client: () => Client,
35
+ FlowControlApi: () => FlowControlApi,
35
36
  Messages: () => Messages,
36
37
  QStashWorkflowAbort: () => QStashWorkflowAbort,
37
38
  QStashWorkflowError: () => QStashWorkflowError,
@@ -423,43 +424,6 @@ function decodeBase64(base64) {
423
424
  }
424
425
  }
425
426
  }
426
- function buildBulkActionFilterPayload(request, options) {
427
- const hasDlqIds = "dlqIds" in request && request.dlqIds !== void 0;
428
- const hasAll = "all" in request && Boolean(request.all);
429
- const filterKeys = Object.keys(request).filter((k) => k !== "dlqIds" && k !== "all");
430
- const hasFilters = filterKeys.length > 0;
431
- if (hasDlqIds && hasAll) {
432
- throw new QstashError("dlqIds and all: true are mutually exclusive.");
433
- }
434
- if (hasDlqIds && hasFilters) {
435
- throw new QstashError(
436
- `dlqIds cannot be combined with filter fields: ${filterKeys.join(", ")}.`
437
- );
438
- }
439
- if (hasAll && hasFilters) {
440
- throw new QstashError(
441
- `all: true cannot be combined with filter fields: ${filterKeys.join(", ")}.`
442
- );
443
- }
444
- if (hasAll)
445
- return {};
446
- const { urlGroup, callerIp, ...rest } = request;
447
- const payload = {
448
- ...rest,
449
- ...urlGroup === void 0 || typeof urlGroup !== "string" ? {} : { topicName: urlGroup },
450
- ...callerIp === void 0 || typeof callerIp !== "string" ? {} : options?.callerIpCasing ? { callerIP: callerIp } : { callerIp }
451
- };
452
- if (Object.keys(payload).length === 0) {
453
- throw new QstashError(
454
- "No filters provided. Pass { all: true } to explicitly target all messages."
455
- );
456
- }
457
- return payload;
458
- }
459
- function normalizeCursor(response) {
460
- const cursor = response.cursor;
461
- return { ...response, cursor: cursor || void 0 };
462
- }
463
427
  function getRuntime() {
464
428
  if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
465
429
  return `bun@${process.versions.bun}`;
@@ -689,20 +653,17 @@ var DLQ = class {
689
653
  /**
690
654
  * List messages in the dlq
691
655
  */
692
- async listMessages(options = {}) {
693
- const { urlGroup, ...restFilter } = options.filter ?? {};
656
+ async listMessages(options) {
694
657
  const filterPayload = {
695
- ...restFilter,
696
- ...urlGroup === void 0 ? {} : { topicName: urlGroup }
658
+ ...options?.filter,
659
+ topicName: options?.filter?.urlGroup
697
660
  };
698
661
  const messagesPayload = await this.http.request({
699
662
  method: "GET",
700
663
  path: ["v2", "dlq"],
701
664
  query: {
702
- cursor: options.cursor,
703
- count: options.count,
704
- order: options.order,
705
- trimBody: options.trimBody,
665
+ cursor: options?.cursor,
666
+ count: options?.count,
706
667
  ...filterPayload
707
668
  }
708
669
  });
@@ -718,70 +679,127 @@ var DLQ = class {
718
679
  };
719
680
  }
720
681
  /**
721
- * Remove messages from the dlq.
722
- *
723
- * Can be called with:
724
- * - A single dlqId: `delete("id")`
725
- * - An array of dlqIds: `delete(["id1", "id2"])`
726
- * - An object with dlqIds: `delete({ dlqIds: ["id1", "id2"] })`
727
- * - A filter object: `delete({ url: "https://example.com", label: "label" })`
728
- * - All messages: `delete({ all: true })`
729
- *
730
- * Note: passing an empty array returns `{ deleted: 0 }` without making a request.
682
+ * Remove a message from the dlq using it's `dlqId`
731
683
  */
732
- async delete(request) {
733
- if (typeof request === "string") {
734
- await this.http.request({
735
- method: "DELETE",
736
- path: ["v2", "dlq", request],
737
- parseResponseAsJson: false
738
- });
739
- return { deleted: 1 };
740
- }
741
- if (Array.isArray(request) && request.length === 0)
742
- return { deleted: 0 };
743
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
744
- return normalizeCursor(
745
- await this.http.request({
746
- method: "DELETE",
747
- path: ["v2", "dlq"],
748
- query: buildBulkActionFilterPayload(filters)
749
- })
750
- );
684
+ async delete(dlqMessageId) {
685
+ return await this.http.request({
686
+ method: "DELETE",
687
+ path: ["v2", "dlq", dlqMessageId],
688
+ parseResponseAsJson: false
689
+ // there is no response
690
+ });
751
691
  }
752
692
  /**
753
693
  * Remove multiple messages from the dlq using their `dlqId`s
754
- *
755
- * @deprecated Use `delete` instead
756
694
  */
757
695
  async deleteMany(request) {
758
- return await this.delete(request);
696
+ return await this.http.request({
697
+ method: "DELETE",
698
+ path: ["v2", "dlq"],
699
+ headers: { "Content-Type": "application/json" },
700
+ body: JSON.stringify({ dlqIds: request.dlqIds })
701
+ });
702
+ }
703
+ };
704
+
705
+ // src/client/flow-control.ts
706
+ var FlowControlApi = class {
707
+ http;
708
+ constructor(http) {
709
+ this.http = http;
759
710
  }
760
711
  /**
761
- * Retry messages from the dlq.
712
+ * Get a single flow control by key.
713
+ */
714
+ async get(flowControlKey) {
715
+ return await this.http.request({
716
+ method: "GET",
717
+ path: ["v2", "flowControl", flowControlKey]
718
+ });
719
+ }
720
+ /**
721
+ * Get the global parallelism info.
722
+ */
723
+ async getGlobalParallelism() {
724
+ const response = await this.http.request({
725
+ method: "GET",
726
+ path: ["v2", "globalParallelism"]
727
+ });
728
+ return {
729
+ parallelismMax: response.parallelismMax ?? 0,
730
+ parallelismCount: response.parallelismCount ?? 0
731
+ };
732
+ }
733
+ /**
734
+ * Pause message delivery for a flow-control key.
762
735
  *
763
- * Can be called with:
764
- * - A single dlqId: `retry("id")`
765
- * - An array of dlqIds: `retry(["id1", "id2"])`
766
- * - An object with dlqIds: `retry({ dlqIds: ["id1", "id2"] })`
767
- * - A filter object: `retry({ url: "https://example.com", label: "label" })`
768
- * - All messages: `retry({ all: true })`
736
+ * Messages already in the waitlist will remain there.
737
+ * New incoming messages will be added directly to the waitlist.
738
+ */
739
+ async pause(flowControlKey) {
740
+ await this.http.request({
741
+ method: "POST",
742
+ path: ["v2", "flowControl", flowControlKey, "pause"],
743
+ parseResponseAsJson: false
744
+ });
745
+ }
746
+ /**
747
+ * Resume message delivery for a flow-control key.
748
+ */
749
+ async resume(flowControlKey) {
750
+ await this.http.request({
751
+ method: "POST",
752
+ path: ["v2", "flowControl", flowControlKey, "resume"],
753
+ parseResponseAsJson: false
754
+ });
755
+ }
756
+ /**
757
+ * Pin a processing configuration for a flow-control key.
769
758
  *
770
- * Note: passing an empty array returns `{ responses: [] }` without making a request.
759
+ * While pinned, the system ignores configurations provided by incoming
760
+ * messages and uses the pinned configuration instead.
771
761
  */
772
- async retry(request) {
773
- if (typeof request === "string")
774
- request = [request];
775
- if (Array.isArray(request) && request.length === 0)
776
- return { responses: [] };
777
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
778
- return normalizeCursor(
779
- await this.http.request({
780
- method: "POST",
781
- path: ["v2", "dlq", "retry"],
782
- query: buildBulkActionFilterPayload(filters)
783
- })
784
- );
762
+ async pin(flowControlKey, options) {
763
+ await this.http.request({
764
+ method: "POST",
765
+ path: ["v2", "flowControl", flowControlKey, "pin"],
766
+ query: {
767
+ parallelism: options.parallelism,
768
+ rate: options.rate,
769
+ period: options.period
770
+ },
771
+ parseResponseAsJson: false
772
+ });
773
+ }
774
+ /**
775
+ * Remove the pinned configuration for a flow-control key.
776
+ *
777
+ * After unpinning, the system resumes updating the configuration
778
+ * based on incoming messages.
779
+ */
780
+ async unpin(flowControlKey, options) {
781
+ await this.http.request({
782
+ method: "POST",
783
+ path: ["v2", "flowControl", flowControlKey, "unpin"],
784
+ query: {
785
+ parallelism: options.parallelism,
786
+ rate: options.rate
787
+ },
788
+ parseResponseAsJson: false
789
+ });
790
+ }
791
+ /**
792
+ * Reset the rate configuration state for a flow-control key.
793
+ *
794
+ * Clears the current rate count and immediately ends the current period.
795
+ * The current timestamp becomes the start of the new rate period.
796
+ */
797
+ async resetRate(flowControlKey) {
798
+ await this.http.request({
799
+ method: "POST",
800
+ path: ["v2", "flowControl", flowControlKey, "resetRate"],
801
+ parseResponseAsJson: false
802
+ });
785
803
  }
786
804
  };
787
805
 
@@ -882,15 +900,7 @@ var HttpClient = class {
882
900
  const url = new URL([request.baseUrl ?? this.baseUrl, ...request.path].join("/"));
883
901
  if (request.query) {
884
902
  for (const [key, value] of Object.entries(request.query)) {
885
- if (value === void 0)
886
- continue;
887
- if (Array.isArray(value)) {
888
- for (const item of value) {
889
- url.searchParams.append(key, item);
890
- }
891
- } else if (value instanceof Date) {
892
- url.searchParams.set(key, value.getTime().toString());
893
- } else {
903
+ if (value !== void 0) {
894
904
  url.searchParams.set(key, value.toString());
895
905
  }
896
906
  }
@@ -1121,57 +1131,29 @@ var Messages = class {
1121
1131
  return message;
1122
1132
  }
1123
1133
  /**
1124
- * Cancel messages.
1125
- *
1126
- * Can be called with:
1127
- * - A single messageId: `cancel("id")`
1128
- * - An array of messageIds: `cancel(["id1", "id2"])`
1129
- * - A filter object: `cancel({ flowControlKey: "key", label: "label" })`
1130
- * - All messages: `cancel({ all: true })`
1131
- */
1132
- async cancel(request) {
1133
- if (typeof request === "string") {
1134
- return await this.http.request({
1135
- method: "DELETE",
1136
- path: ["v2", "messages", request]
1137
- });
1138
- }
1139
- if (Array.isArray(request) && request.length === 0)
1140
- return { cancelled: 0 };
1141
- const filters = Array.isArray(request) ? { messageIds: request } : request;
1142
- return await this.http.request({
1143
- method: "DELETE",
1144
- path: ["v2", "messages"],
1145
- query: buildBulkActionFilterPayload(filters, { callerIpCasing: true })
1146
- });
1147
- }
1148
- /**
1149
- * Delete a message.
1150
- *
1151
- * @deprecated Use `cancel(messageId: string)` instead
1134
+ * Cancel a message
1152
1135
  */
1153
1136
  async delete(messageId) {
1154
- await this.http.request({
1137
+ return await this.http.request({
1155
1138
  method: "DELETE",
1156
1139
  path: ["v2", "messages", messageId],
1157
1140
  parseResponseAsJson: false
1158
1141
  });
1159
1142
  }
1160
- /**
1161
- * Cancel multiple messages by their messageIds.
1162
- *
1163
- * @deprecated Use `cancel(messageIds: string[])` instead
1164
- */
1165
1143
  async deleteMany(messageIds) {
1166
- const result = await this.cancel(messageIds);
1144
+ const result = await this.http.request({
1145
+ method: "DELETE",
1146
+ path: ["v2", "messages"],
1147
+ headers: { "Content-Type": "application/json" },
1148
+ body: JSON.stringify({ messageIds })
1149
+ });
1167
1150
  return result.cancelled;
1168
1151
  }
1169
- /**
1170
- * Cancel all messages
1171
- * @deprecated Use `cancel({all: true})` to cancel all
1172
- */
1173
1152
  async deleteAll() {
1174
- const result = await this.cancel({ all: true });
1153
+ const result = await this.http.request({
1154
+ method: "DELETE",
1155
+ path: ["v2", "messages"]
1156
+ });
1175
1157
  return result.cancelled;
1176
1158
  }
1177
1159
  };
@@ -1536,7 +1518,7 @@ var Workflow = class {
1536
1518
  };
1537
1519
 
1538
1520
  // version.ts
1539
- var VERSION = "v2.9.1-rc.1";
1521
+ var VERSION = "v2.9.1";
1540
1522
 
1541
1523
  // src/client/client.ts
1542
1524
  var Client = class {
@@ -1607,6 +1589,14 @@ var Client = class {
1607
1589
  get schedules() {
1608
1590
  return new Schedules(this.http);
1609
1591
  }
1592
+ /**
1593
+ * Access the flow control API.
1594
+ *
1595
+ * List, get, or reset flow controls.
1596
+ */
1597
+ get flowControl() {
1598
+ return new FlowControlApi(this.http);
1599
+ }
1610
1600
  /**
1611
1601
  * Access the workflow API.
1612
1602
  *
@@ -1731,47 +1721,39 @@ var Client = class {
1731
1721
  * }
1732
1722
  * ```
1733
1723
  */
1734
- async logs(request = {}) {
1735
- const {
1736
- urlGroup,
1737
- // eslint-disable-next-line @typescript-eslint/no-deprecated
1738
- topicName,
1739
- fromDate,
1740
- toDate,
1741
- callerIp,
1742
- messageIds,
1743
- // eslint-disable-next-line @typescript-eslint/no-deprecated
1744
- count: filterCount,
1745
- ...restFilter
1746
- } = request.filter ?? {};
1747
- const filterPayload = {
1748
- ...restFilter,
1749
- topicName: urlGroup ?? topicName,
1750
- fromDate,
1751
- toDate,
1752
- callerIp
1753
- };
1754
- let cursorString;
1755
- if (typeof request.cursor === "number" && request.cursor > 0) {
1756
- cursorString = request.cursor.toString();
1757
- } else if (typeof request.cursor === "string" && request.cursor !== "") {
1758
- cursorString = request.cursor;
1724
+ async logs(request) {
1725
+ const query = {};
1726
+ if (typeof request?.cursor === "number" && request.cursor > 0) {
1727
+ query.cursor = request.cursor.toString();
1728
+ } else if (typeof request?.cursor === "string" && request.cursor !== "") {
1729
+ query.cursor = request.cursor;
1730
+ }
1731
+ for (const [key, value] of Object.entries(request?.filter ?? {})) {
1732
+ if (typeof value === "number" && value < 0) {
1733
+ continue;
1734
+ }
1735
+ if (key === "urlGroup") {
1736
+ query.topicName = value.toString();
1737
+ } else if (typeof value !== "undefined") {
1738
+ query[key] = value.toString();
1739
+ }
1759
1740
  }
1760
- const query = {
1761
- cursor: cursorString,
1762
- count: request.count ?? filterCount,
1763
- order: request.order,
1764
- trimBody: request.trimBody,
1765
- messageIds,
1766
- ...filterPayload
1767
- };
1768
1741
  const responsePayload = await this.http.request({
1769
1742
  path: ["v2", "events"],
1770
1743
  method: "GET",
1771
1744
  query
1772
1745
  });
1773
- const logs = responsePayload.events.map((event) => ({ ...event, urlGroup: event.topicName }));
1774
- return { cursor: responsePayload.cursor, logs, events: logs };
1746
+ const logs = responsePayload.events.map((event) => {
1747
+ return {
1748
+ ...event,
1749
+ urlGroup: event.topicName
1750
+ };
1751
+ });
1752
+ return {
1753
+ cursor: responsePayload.cursor,
1754
+ logs,
1755
+ events: logs
1756
+ };
1775
1757
  }
1776
1758
  /**
1777
1759
  * @deprecated Will be removed in the next major release. Use the `logs` method instead.
@@ -1830,6 +1812,7 @@ var resend = ({
1830
1812
  0 && (module.exports = {
1831
1813
  Chat,
1832
1814
  Client,
1815
+ FlowControlApi,
1833
1816
  Messages,
1834
1817
  QStashWorkflowAbort,
1835
1818
  QStashWorkflowError,
package/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  resend
3
- } from "./chunk-SN6OPGRS.mjs";
3
+ } from "./chunk-KDHOB7B5.mjs";
4
4
  import {
5
5
  Chat,
6
6
  Client,
7
+ FlowControlApi,
7
8
  Messages,
8
9
  QStashWorkflowAbort,
9
10
  QStashWorkflowError,
@@ -22,10 +23,11 @@ import {
22
23
  openai,
23
24
  setupAnalytics,
24
25
  upstash
25
- } from "./chunk-RUCOF5QZ.mjs";
26
+ } from "./chunk-DT2X63FB.mjs";
26
27
  export {
27
28
  Chat,
28
29
  Client,
30
+ FlowControlApi,
29
31
  Messages,
30
32
  QStashWorkflowAbort,
31
33
  QStashWorkflowError,
package/nextjs.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler } from 'next';
2
2
  import { NextRequest, NextFetchEvent } from 'next/server';
3
- import { aa as RouteFunction, ab as WorkflowServeOptions } from './client-Gv4WRTxB.mjs';
3
+ import { ae as RouteFunction, af as WorkflowServeOptions } from './client-jh_SomWB.mjs';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {
package/nextjs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler } from 'next';
2
2
  import { NextRequest, NextFetchEvent } from 'next/server';
3
- import { aa as RouteFunction, ab as WorkflowServeOptions } from './client-Gv4WRTxB.js';
3
+ import { ae as RouteFunction, af as WorkflowServeOptions } from './client-jh_SomWB.js';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {