@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/h3.js CHANGED
@@ -716,43 +716,6 @@ function decodeBase64(base64) {
716
716
  }
717
717
  }
718
718
  }
719
- function buildBulkActionFilterPayload(request, options) {
720
- const hasDlqIds = "dlqIds" in request && request.dlqIds !== void 0;
721
- const hasAll = "all" in request && Boolean(request.all);
722
- const filterKeys = Object.keys(request).filter((k) => k !== "dlqIds" && k !== "all");
723
- const hasFilters = filterKeys.length > 0;
724
- if (hasDlqIds && hasAll) {
725
- throw new QstashError("dlqIds and all: true are mutually exclusive.");
726
- }
727
- if (hasDlqIds && hasFilters) {
728
- throw new QstashError(
729
- `dlqIds cannot be combined with filter fields: ${filterKeys.join(", ")}.`
730
- );
731
- }
732
- if (hasAll && hasFilters) {
733
- throw new QstashError(
734
- `all: true cannot be combined with filter fields: ${filterKeys.join(", ")}.`
735
- );
736
- }
737
- if (hasAll)
738
- return {};
739
- const { urlGroup, callerIp, ...rest } = request;
740
- const payload = {
741
- ...rest,
742
- ...urlGroup === void 0 || typeof urlGroup !== "string" ? {} : { topicName: urlGroup },
743
- ...callerIp === void 0 || typeof callerIp !== "string" ? {} : options?.callerIpCasing ? { callerIP: callerIp } : { callerIp }
744
- };
745
- if (Object.keys(payload).length === 0) {
746
- throw new QstashError(
747
- "No filters provided. Pass { all: true } to explicitly target all messages."
748
- );
749
- }
750
- return payload;
751
- }
752
- function normalizeCursor(response) {
753
- const cursor = response.cursor;
754
- return { ...response, cursor: cursor || void 0 };
755
- }
756
719
  function getRuntime() {
757
720
  if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
758
721
  return `bun@${process.versions.bun}`;
@@ -982,20 +945,17 @@ var DLQ = class {
982
945
  /**
983
946
  * List messages in the dlq
984
947
  */
985
- async listMessages(options = {}) {
986
- const { urlGroup, ...restFilter } = options.filter ?? {};
948
+ async listMessages(options) {
987
949
  const filterPayload = {
988
- ...restFilter,
989
- ...urlGroup === void 0 ? {} : { topicName: urlGroup }
950
+ ...options?.filter,
951
+ topicName: options?.filter?.urlGroup
990
952
  };
991
953
  const messagesPayload = await this.http.request({
992
954
  method: "GET",
993
955
  path: ["v2", "dlq"],
994
956
  query: {
995
- cursor: options.cursor,
996
- count: options.count,
997
- order: options.order,
998
- trimBody: options.trimBody,
957
+ cursor: options?.cursor,
958
+ count: options?.count,
999
959
  ...filterPayload
1000
960
  }
1001
961
  });
@@ -1011,70 +971,127 @@ var DLQ = class {
1011
971
  };
1012
972
  }
1013
973
  /**
1014
- * Remove messages from the dlq.
1015
- *
1016
- * Can be called with:
1017
- * - A single dlqId: `delete("id")`
1018
- * - An array of dlqIds: `delete(["id1", "id2"])`
1019
- * - An object with dlqIds: `delete({ dlqIds: ["id1", "id2"] })`
1020
- * - A filter object: `delete({ url: "https://example.com", label: "label" })`
1021
- * - All messages: `delete({ all: true })`
1022
- *
1023
- * Note: passing an empty array returns `{ deleted: 0 }` without making a request.
974
+ * Remove a message from the dlq using it's `dlqId`
1024
975
  */
1025
- async delete(request) {
1026
- if (typeof request === "string") {
1027
- await this.http.request({
1028
- method: "DELETE",
1029
- path: ["v2", "dlq", request],
1030
- parseResponseAsJson: false
1031
- });
1032
- return { deleted: 1 };
1033
- }
1034
- if (Array.isArray(request) && request.length === 0)
1035
- return { deleted: 0 };
1036
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
1037
- return normalizeCursor(
1038
- await this.http.request({
1039
- method: "DELETE",
1040
- path: ["v2", "dlq"],
1041
- query: buildBulkActionFilterPayload(filters)
1042
- })
1043
- );
976
+ async delete(dlqMessageId) {
977
+ return await this.http.request({
978
+ method: "DELETE",
979
+ path: ["v2", "dlq", dlqMessageId],
980
+ parseResponseAsJson: false
981
+ // there is no response
982
+ });
1044
983
  }
1045
984
  /**
1046
985
  * Remove multiple messages from the dlq using their `dlqId`s
1047
- *
1048
- * @deprecated Use `delete` instead
1049
986
  */
1050
987
  async deleteMany(request) {
1051
- return await this.delete(request);
988
+ return await this.http.request({
989
+ method: "DELETE",
990
+ path: ["v2", "dlq"],
991
+ headers: { "Content-Type": "application/json" },
992
+ body: JSON.stringify({ dlqIds: request.dlqIds })
993
+ });
994
+ }
995
+ };
996
+
997
+ // src/client/flow-control.ts
998
+ var FlowControlApi = class {
999
+ http;
1000
+ constructor(http) {
1001
+ this.http = http;
1052
1002
  }
1053
1003
  /**
1054
- * Retry messages from the dlq.
1004
+ * Get a single flow control by key.
1005
+ */
1006
+ async get(flowControlKey) {
1007
+ return await this.http.request({
1008
+ method: "GET",
1009
+ path: ["v2", "flowControl", flowControlKey]
1010
+ });
1011
+ }
1012
+ /**
1013
+ * Get the global parallelism info.
1014
+ */
1015
+ async getGlobalParallelism() {
1016
+ const response = await this.http.request({
1017
+ method: "GET",
1018
+ path: ["v2", "globalParallelism"]
1019
+ });
1020
+ return {
1021
+ parallelismMax: response.parallelismMax ?? 0,
1022
+ parallelismCount: response.parallelismCount ?? 0
1023
+ };
1024
+ }
1025
+ /**
1026
+ * Pause message delivery for a flow-control key.
1055
1027
  *
1056
- * Can be called with:
1057
- * - A single dlqId: `retry("id")`
1058
- * - An array of dlqIds: `retry(["id1", "id2"])`
1059
- * - An object with dlqIds: `retry({ dlqIds: ["id1", "id2"] })`
1060
- * - A filter object: `retry({ url: "https://example.com", label: "label" })`
1061
- * - All messages: `retry({ all: true })`
1028
+ * Messages already in the waitlist will remain there.
1029
+ * New incoming messages will be added directly to the waitlist.
1030
+ */
1031
+ async pause(flowControlKey) {
1032
+ await this.http.request({
1033
+ method: "POST",
1034
+ path: ["v2", "flowControl", flowControlKey, "pause"],
1035
+ parseResponseAsJson: false
1036
+ });
1037
+ }
1038
+ /**
1039
+ * Resume message delivery for a flow-control key.
1040
+ */
1041
+ async resume(flowControlKey) {
1042
+ await this.http.request({
1043
+ method: "POST",
1044
+ path: ["v2", "flowControl", flowControlKey, "resume"],
1045
+ parseResponseAsJson: false
1046
+ });
1047
+ }
1048
+ /**
1049
+ * Pin a processing configuration for a flow-control key.
1062
1050
  *
1063
- * Note: passing an empty array returns `{ responses: [] }` without making a request.
1051
+ * While pinned, the system ignores configurations provided by incoming
1052
+ * messages and uses the pinned configuration instead.
1064
1053
  */
1065
- async retry(request) {
1066
- if (typeof request === "string")
1067
- request = [request];
1068
- if (Array.isArray(request) && request.length === 0)
1069
- return { responses: [] };
1070
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
1071
- return normalizeCursor(
1072
- await this.http.request({
1073
- method: "POST",
1074
- path: ["v2", "dlq", "retry"],
1075
- query: buildBulkActionFilterPayload(filters)
1076
- })
1077
- );
1054
+ async pin(flowControlKey, options) {
1055
+ await this.http.request({
1056
+ method: "POST",
1057
+ path: ["v2", "flowControl", flowControlKey, "pin"],
1058
+ query: {
1059
+ parallelism: options.parallelism,
1060
+ rate: options.rate,
1061
+ period: options.period
1062
+ },
1063
+ parseResponseAsJson: false
1064
+ });
1065
+ }
1066
+ /**
1067
+ * Remove the pinned configuration for a flow-control key.
1068
+ *
1069
+ * After unpinning, the system resumes updating the configuration
1070
+ * based on incoming messages.
1071
+ */
1072
+ async unpin(flowControlKey, options) {
1073
+ await this.http.request({
1074
+ method: "POST",
1075
+ path: ["v2", "flowControl", flowControlKey, "unpin"],
1076
+ query: {
1077
+ parallelism: options.parallelism,
1078
+ rate: options.rate
1079
+ },
1080
+ parseResponseAsJson: false
1081
+ });
1082
+ }
1083
+ /**
1084
+ * Reset the rate configuration state for a flow-control key.
1085
+ *
1086
+ * Clears the current rate count and immediately ends the current period.
1087
+ * The current timestamp becomes the start of the new rate period.
1088
+ */
1089
+ async resetRate(flowControlKey) {
1090
+ await this.http.request({
1091
+ method: "POST",
1092
+ path: ["v2", "flowControl", flowControlKey, "resetRate"],
1093
+ parseResponseAsJson: false
1094
+ });
1078
1095
  }
1079
1096
  };
1080
1097
 
@@ -1175,15 +1192,7 @@ var HttpClient = class {
1175
1192
  const url = new URL([request.baseUrl ?? this.baseUrl, ...request.path].join("/"));
1176
1193
  if (request.query) {
1177
1194
  for (const [key, value] of Object.entries(request.query)) {
1178
- if (value === void 0)
1179
- continue;
1180
- if (Array.isArray(value)) {
1181
- for (const item of value) {
1182
- url.searchParams.append(key, item);
1183
- }
1184
- } else if (value instanceof Date) {
1185
- url.searchParams.set(key, value.getTime().toString());
1186
- } else {
1195
+ if (value !== void 0) {
1187
1196
  url.searchParams.set(key, value.toString());
1188
1197
  }
1189
1198
  }
@@ -1414,57 +1423,29 @@ var Messages = class {
1414
1423
  return message;
1415
1424
  }
1416
1425
  /**
1417
- * Cancel messages.
1418
- *
1419
- * Can be called with:
1420
- * - A single messageId: `cancel("id")`
1421
- * - An array of messageIds: `cancel(["id1", "id2"])`
1422
- * - A filter object: `cancel({ flowControlKey: "key", label: "label" })`
1423
- * - All messages: `cancel({ all: true })`
1424
- */
1425
- async cancel(request) {
1426
- if (typeof request === "string") {
1427
- return await this.http.request({
1428
- method: "DELETE",
1429
- path: ["v2", "messages", request]
1430
- });
1431
- }
1432
- if (Array.isArray(request) && request.length === 0)
1433
- return { cancelled: 0 };
1434
- const filters = Array.isArray(request) ? { messageIds: request } : request;
1435
- return await this.http.request({
1436
- method: "DELETE",
1437
- path: ["v2", "messages"],
1438
- query: buildBulkActionFilterPayload(filters, { callerIpCasing: true })
1439
- });
1440
- }
1441
- /**
1442
- * Delete a message.
1443
- *
1444
- * @deprecated Use `cancel(messageId: string)` instead
1426
+ * Cancel a message
1445
1427
  */
1446
1428
  async delete(messageId) {
1447
- await this.http.request({
1429
+ return await this.http.request({
1448
1430
  method: "DELETE",
1449
1431
  path: ["v2", "messages", messageId],
1450
1432
  parseResponseAsJson: false
1451
1433
  });
1452
1434
  }
1453
- /**
1454
- * Cancel multiple messages by their messageIds.
1455
- *
1456
- * @deprecated Use `cancel(messageIds: string[])` instead
1457
- */
1458
1435
  async deleteMany(messageIds) {
1459
- const result = await this.cancel(messageIds);
1436
+ const result = await this.http.request({
1437
+ method: "DELETE",
1438
+ path: ["v2", "messages"],
1439
+ headers: { "Content-Type": "application/json" },
1440
+ body: JSON.stringify({ messageIds })
1441
+ });
1460
1442
  return result.cancelled;
1461
1443
  }
1462
- /**
1463
- * Cancel all messages
1464
- * @deprecated Use `cancel({all: true})` to cancel all
1465
- */
1466
1444
  async deleteAll() {
1467
- const result = await this.cancel({ all: true });
1445
+ const result = await this.http.request({
1446
+ method: "DELETE",
1447
+ path: ["v2", "messages"]
1448
+ });
1468
1449
  return result.cancelled;
1469
1450
  }
1470
1451
  };
@@ -3184,7 +3165,7 @@ var Workflow = class {
3184
3165
  };
3185
3166
 
3186
3167
  // version.ts
3187
- var VERSION = "v2.9.1-rc.1";
3168
+ var VERSION = "v2.9.1";
3188
3169
 
3189
3170
  // src/client/client.ts
3190
3171
  var Client = class {
@@ -3255,6 +3236,14 @@ var Client = class {
3255
3236
  get schedules() {
3256
3237
  return new Schedules(this.http);
3257
3238
  }
3239
+ /**
3240
+ * Access the flow control API.
3241
+ *
3242
+ * List, get, or reset flow controls.
3243
+ */
3244
+ get flowControl() {
3245
+ return new FlowControlApi(this.http);
3246
+ }
3258
3247
  /**
3259
3248
  * Access the workflow API.
3260
3249
  *
@@ -3379,47 +3368,39 @@ var Client = class {
3379
3368
  * }
3380
3369
  * ```
3381
3370
  */
3382
- async logs(request = {}) {
3383
- const {
3384
- urlGroup,
3385
- // eslint-disable-next-line @typescript-eslint/no-deprecated
3386
- topicName,
3387
- fromDate,
3388
- toDate,
3389
- callerIp,
3390
- messageIds,
3391
- // eslint-disable-next-line @typescript-eslint/no-deprecated
3392
- count: filterCount,
3393
- ...restFilter
3394
- } = request.filter ?? {};
3395
- const filterPayload = {
3396
- ...restFilter,
3397
- topicName: urlGroup ?? topicName,
3398
- fromDate,
3399
- toDate,
3400
- callerIp
3401
- };
3402
- let cursorString;
3403
- if (typeof request.cursor === "number" && request.cursor > 0) {
3404
- cursorString = request.cursor.toString();
3405
- } else if (typeof request.cursor === "string" && request.cursor !== "") {
3406
- cursorString = request.cursor;
3407
- }
3408
- const query = {
3409
- cursor: cursorString,
3410
- count: request.count ?? filterCount,
3411
- order: request.order,
3412
- trimBody: request.trimBody,
3413
- messageIds,
3414
- ...filterPayload
3415
- };
3371
+ async logs(request) {
3372
+ const query = {};
3373
+ if (typeof request?.cursor === "number" && request.cursor > 0) {
3374
+ query.cursor = request.cursor.toString();
3375
+ } else if (typeof request?.cursor === "string" && request.cursor !== "") {
3376
+ query.cursor = request.cursor;
3377
+ }
3378
+ for (const [key, value] of Object.entries(request?.filter ?? {})) {
3379
+ if (typeof value === "number" && value < 0) {
3380
+ continue;
3381
+ }
3382
+ if (key === "urlGroup") {
3383
+ query.topicName = value.toString();
3384
+ } else if (typeof value !== "undefined") {
3385
+ query[key] = value.toString();
3386
+ }
3387
+ }
3416
3388
  const responsePayload = await this.http.request({
3417
3389
  path: ["v2", "events"],
3418
3390
  method: "GET",
3419
3391
  query
3420
3392
  });
3421
- const logs = responsePayload.events.map((event) => ({ ...event, urlGroup: event.topicName }));
3422
- return { cursor: responsePayload.cursor, logs, events: logs };
3393
+ const logs = responsePayload.events.map((event) => {
3394
+ return {
3395
+ ...event,
3396
+ urlGroup: event.topicName
3397
+ };
3398
+ });
3399
+ return {
3400
+ cursor: responsePayload.cursor,
3401
+ logs,
3402
+ events: logs
3403
+ };
3423
3404
  }
3424
3405
  /**
3425
3406
  * @deprecated Will be removed in the next major release. Use the `logs` method instead.
package/h3.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  serve,
3
3
  verifySignatureH3
4
- } from "./chunk-STWPT5EV.mjs";
5
- import "./chunk-SN6OPGRS.mjs";
6
- import "./chunk-RUCOF5QZ.mjs";
4
+ } from "./chunk-JO26IBSH.mjs";
5
+ import "./chunk-KDHOB7B5.mjs";
6
+ import "./chunk-DT2X63FB.mjs";
7
7
  export {
8
8
  serve,
9
9
  verifySignatureH3
package/hono.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context } from 'hono';
2
- import { aa as RouteFunction, ab as WorkflowServeOptions } from './client-Gv4WRTxB.mjs';
2
+ import { ae as RouteFunction, af as WorkflowServeOptions } from './client-jh_SomWB.mjs';
3
3
  import 'neverthrow';
4
4
 
5
5
  type WorkflowBindings = {
package/hono.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context } from 'hono';
2
- import { aa as RouteFunction, ab as WorkflowServeOptions } from './client-Gv4WRTxB.js';
2
+ import { ae as RouteFunction, af as WorkflowServeOptions } from './client-jh_SomWB.js';
3
3
  import 'neverthrow';
4
4
 
5
5
  type WorkflowBindings = {