@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/svelte.js CHANGED
@@ -393,43 +393,6 @@ function decodeBase64(base64) {
393
393
  }
394
394
  }
395
395
  }
396
- function buildBulkActionFilterPayload(request, options) {
397
- const hasDlqIds = "dlqIds" in request && request.dlqIds !== void 0;
398
- const hasAll = "all" in request && Boolean(request.all);
399
- const filterKeys = Object.keys(request).filter((k) => k !== "dlqIds" && k !== "all");
400
- const hasFilters = filterKeys.length > 0;
401
- if (hasDlqIds && hasAll) {
402
- throw new QstashError("dlqIds and all: true are mutually exclusive.");
403
- }
404
- if (hasDlqIds && hasFilters) {
405
- throw new QstashError(
406
- `dlqIds cannot be combined with filter fields: ${filterKeys.join(", ")}.`
407
- );
408
- }
409
- if (hasAll && hasFilters) {
410
- throw new QstashError(
411
- `all: true cannot be combined with filter fields: ${filterKeys.join(", ")}.`
412
- );
413
- }
414
- if (hasAll)
415
- return {};
416
- const { urlGroup, callerIp, ...rest } = request;
417
- const payload = {
418
- ...rest,
419
- ...urlGroup === void 0 || typeof urlGroup !== "string" ? {} : { topicName: urlGroup },
420
- ...callerIp === void 0 || typeof callerIp !== "string" ? {} : options?.callerIpCasing ? { callerIP: callerIp } : { callerIp }
421
- };
422
- if (Object.keys(payload).length === 0) {
423
- throw new QstashError(
424
- "No filters provided. Pass { all: true } to explicitly target all messages."
425
- );
426
- }
427
- return payload;
428
- }
429
- function normalizeCursor(response) {
430
- const cursor = response.cursor;
431
- return { ...response, cursor: cursor || void 0 };
432
- }
433
396
  function getRuntime() {
434
397
  if (typeof process === "object" && typeof process.versions == "object" && process.versions.bun)
435
398
  return `bun@${process.versions.bun}`;
@@ -659,20 +622,17 @@ var DLQ = class {
659
622
  /**
660
623
  * List messages in the dlq
661
624
  */
662
- async listMessages(options = {}) {
663
- const { urlGroup, ...restFilter } = options.filter ?? {};
625
+ async listMessages(options) {
664
626
  const filterPayload = {
665
- ...restFilter,
666
- ...urlGroup === void 0 ? {} : { topicName: urlGroup }
627
+ ...options?.filter,
628
+ topicName: options?.filter?.urlGroup
667
629
  };
668
630
  const messagesPayload = await this.http.request({
669
631
  method: "GET",
670
632
  path: ["v2", "dlq"],
671
633
  query: {
672
- cursor: options.cursor,
673
- count: options.count,
674
- order: options.order,
675
- trimBody: options.trimBody,
634
+ cursor: options?.cursor,
635
+ count: options?.count,
676
636
  ...filterPayload
677
637
  }
678
638
  });
@@ -688,70 +648,127 @@ var DLQ = class {
688
648
  };
689
649
  }
690
650
  /**
691
- * Remove messages from the dlq.
692
- *
693
- * Can be called with:
694
- * - A single dlqId: `delete("id")`
695
- * - An array of dlqIds: `delete(["id1", "id2"])`
696
- * - An object with dlqIds: `delete({ dlqIds: ["id1", "id2"] })`
697
- * - A filter object: `delete({ url: "https://example.com", label: "label" })`
698
- * - All messages: `delete({ all: true })`
699
- *
700
- * Note: passing an empty array returns `{ deleted: 0 }` without making a request.
651
+ * Remove a message from the dlq using it's `dlqId`
701
652
  */
702
- async delete(request) {
703
- if (typeof request === "string") {
704
- await this.http.request({
705
- method: "DELETE",
706
- path: ["v2", "dlq", request],
707
- parseResponseAsJson: false
708
- });
709
- return { deleted: 1 };
710
- }
711
- if (Array.isArray(request) && request.length === 0)
712
- return { deleted: 0 };
713
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
714
- return normalizeCursor(
715
- await this.http.request({
716
- method: "DELETE",
717
- path: ["v2", "dlq"],
718
- query: buildBulkActionFilterPayload(filters)
719
- })
720
- );
653
+ async delete(dlqMessageId) {
654
+ return await this.http.request({
655
+ method: "DELETE",
656
+ path: ["v2", "dlq", dlqMessageId],
657
+ parseResponseAsJson: false
658
+ // there is no response
659
+ });
721
660
  }
722
661
  /**
723
662
  * Remove multiple messages from the dlq using their `dlqId`s
724
- *
725
- * @deprecated Use `delete` instead
726
663
  */
727
664
  async deleteMany(request) {
728
- return await this.delete(request);
665
+ return await this.http.request({
666
+ method: "DELETE",
667
+ path: ["v2", "dlq"],
668
+ headers: { "Content-Type": "application/json" },
669
+ body: JSON.stringify({ dlqIds: request.dlqIds })
670
+ });
671
+ }
672
+ };
673
+
674
+ // src/client/flow-control.ts
675
+ var FlowControlApi = class {
676
+ http;
677
+ constructor(http) {
678
+ this.http = http;
729
679
  }
730
680
  /**
731
- * Retry messages from the dlq.
681
+ * Get a single flow control by key.
682
+ */
683
+ async get(flowControlKey) {
684
+ return await this.http.request({
685
+ method: "GET",
686
+ path: ["v2", "flowControl", flowControlKey]
687
+ });
688
+ }
689
+ /**
690
+ * Get the global parallelism info.
691
+ */
692
+ async getGlobalParallelism() {
693
+ const response = await this.http.request({
694
+ method: "GET",
695
+ path: ["v2", "globalParallelism"]
696
+ });
697
+ return {
698
+ parallelismMax: response.parallelismMax ?? 0,
699
+ parallelismCount: response.parallelismCount ?? 0
700
+ };
701
+ }
702
+ /**
703
+ * Pause message delivery for a flow-control key.
732
704
  *
733
- * Can be called with:
734
- * - A single dlqId: `retry("id")`
735
- * - An array of dlqIds: `retry(["id1", "id2"])`
736
- * - An object with dlqIds: `retry({ dlqIds: ["id1", "id2"] })`
737
- * - A filter object: `retry({ url: "https://example.com", label: "label" })`
738
- * - All messages: `retry({ all: true })`
705
+ * Messages already in the waitlist will remain there.
706
+ * New incoming messages will be added directly to the waitlist.
707
+ */
708
+ async pause(flowControlKey) {
709
+ await this.http.request({
710
+ method: "POST",
711
+ path: ["v2", "flowControl", flowControlKey, "pause"],
712
+ parseResponseAsJson: false
713
+ });
714
+ }
715
+ /**
716
+ * Resume message delivery for a flow-control key.
717
+ */
718
+ async resume(flowControlKey) {
719
+ await this.http.request({
720
+ method: "POST",
721
+ path: ["v2", "flowControl", flowControlKey, "resume"],
722
+ parseResponseAsJson: false
723
+ });
724
+ }
725
+ /**
726
+ * Pin a processing configuration for a flow-control key.
739
727
  *
740
- * Note: passing an empty array returns `{ responses: [] }` without making a request.
728
+ * While pinned, the system ignores configurations provided by incoming
729
+ * messages and uses the pinned configuration instead.
741
730
  */
742
- async retry(request) {
743
- if (typeof request === "string")
744
- request = [request];
745
- if (Array.isArray(request) && request.length === 0)
746
- return { responses: [] };
747
- const filters = Array.isArray(request) ? { dlqIds: request } : request;
748
- return normalizeCursor(
749
- await this.http.request({
750
- method: "POST",
751
- path: ["v2", "dlq", "retry"],
752
- query: buildBulkActionFilterPayload(filters)
753
- })
754
- );
731
+ async pin(flowControlKey, options) {
732
+ await this.http.request({
733
+ method: "POST",
734
+ path: ["v2", "flowControl", flowControlKey, "pin"],
735
+ query: {
736
+ parallelism: options.parallelism,
737
+ rate: options.rate,
738
+ period: options.period
739
+ },
740
+ parseResponseAsJson: false
741
+ });
742
+ }
743
+ /**
744
+ * Remove the pinned configuration for a flow-control key.
745
+ *
746
+ * After unpinning, the system resumes updating the configuration
747
+ * based on incoming messages.
748
+ */
749
+ async unpin(flowControlKey, options) {
750
+ await this.http.request({
751
+ method: "POST",
752
+ path: ["v2", "flowControl", flowControlKey, "unpin"],
753
+ query: {
754
+ parallelism: options.parallelism,
755
+ rate: options.rate
756
+ },
757
+ parseResponseAsJson: false
758
+ });
759
+ }
760
+ /**
761
+ * Reset the rate configuration state for a flow-control key.
762
+ *
763
+ * Clears the current rate count and immediately ends the current period.
764
+ * The current timestamp becomes the start of the new rate period.
765
+ */
766
+ async resetRate(flowControlKey) {
767
+ await this.http.request({
768
+ method: "POST",
769
+ path: ["v2", "flowControl", flowControlKey, "resetRate"],
770
+ parseResponseAsJson: false
771
+ });
755
772
  }
756
773
  };
757
774
 
@@ -852,15 +869,7 @@ var HttpClient = class {
852
869
  const url = new URL([request.baseUrl ?? this.baseUrl, ...request.path].join("/"));
853
870
  if (request.query) {
854
871
  for (const [key, value] of Object.entries(request.query)) {
855
- if (value === void 0)
856
- continue;
857
- if (Array.isArray(value)) {
858
- for (const item of value) {
859
- url.searchParams.append(key, item);
860
- }
861
- } else if (value instanceof Date) {
862
- url.searchParams.set(key, value.getTime().toString());
863
- } else {
872
+ if (value !== void 0) {
864
873
  url.searchParams.set(key, value.toString());
865
874
  }
866
875
  }
@@ -1091,57 +1100,29 @@ var Messages = class {
1091
1100
  return message;
1092
1101
  }
1093
1102
  /**
1094
- * Cancel messages.
1095
- *
1096
- * Can be called with:
1097
- * - A single messageId: `cancel("id")`
1098
- * - An array of messageIds: `cancel(["id1", "id2"])`
1099
- * - A filter object: `cancel({ flowControlKey: "key", label: "label" })`
1100
- * - All messages: `cancel({ all: true })`
1101
- */
1102
- async cancel(request) {
1103
- if (typeof request === "string") {
1104
- return await this.http.request({
1105
- method: "DELETE",
1106
- path: ["v2", "messages", request]
1107
- });
1108
- }
1109
- if (Array.isArray(request) && request.length === 0)
1110
- return { cancelled: 0 };
1111
- const filters = Array.isArray(request) ? { messageIds: request } : request;
1112
- return await this.http.request({
1113
- method: "DELETE",
1114
- path: ["v2", "messages"],
1115
- query: buildBulkActionFilterPayload(filters, { callerIpCasing: true })
1116
- });
1117
- }
1118
- /**
1119
- * Delete a message.
1120
- *
1121
- * @deprecated Use `cancel(messageId: string)` instead
1103
+ * Cancel a message
1122
1104
  */
1123
1105
  async delete(messageId) {
1124
- await this.http.request({
1106
+ return await this.http.request({
1125
1107
  method: "DELETE",
1126
1108
  path: ["v2", "messages", messageId],
1127
1109
  parseResponseAsJson: false
1128
1110
  });
1129
1111
  }
1130
- /**
1131
- * Cancel multiple messages by their messageIds.
1132
- *
1133
- * @deprecated Use `cancel(messageIds: string[])` instead
1134
- */
1135
1112
  async deleteMany(messageIds) {
1136
- const result = await this.cancel(messageIds);
1113
+ const result = await this.http.request({
1114
+ method: "DELETE",
1115
+ path: ["v2", "messages"],
1116
+ headers: { "Content-Type": "application/json" },
1117
+ body: JSON.stringify({ messageIds })
1118
+ });
1137
1119
  return result.cancelled;
1138
1120
  }
1139
- /**
1140
- * Cancel all messages
1141
- * @deprecated Use `cancel({all: true})` to cancel all
1142
- */
1143
1121
  async deleteAll() {
1144
- const result = await this.cancel({ all: true });
1122
+ const result = await this.http.request({
1123
+ method: "DELETE",
1124
+ path: ["v2", "messages"]
1125
+ });
1145
1126
  return result.cancelled;
1146
1127
  }
1147
1128
  };
@@ -2861,7 +2842,7 @@ var Workflow = class {
2861
2842
  };
2862
2843
 
2863
2844
  // version.ts
2864
- var VERSION = "v2.9.1-rc.1";
2845
+ var VERSION = "v2.9.1";
2865
2846
 
2866
2847
  // src/client/client.ts
2867
2848
  var Client = class {
@@ -2932,6 +2913,14 @@ var Client = class {
2932
2913
  get schedules() {
2933
2914
  return new Schedules(this.http);
2934
2915
  }
2916
+ /**
2917
+ * Access the flow control API.
2918
+ *
2919
+ * List, get, or reset flow controls.
2920
+ */
2921
+ get flowControl() {
2922
+ return new FlowControlApi(this.http);
2923
+ }
2935
2924
  /**
2936
2925
  * Access the workflow API.
2937
2926
  *
@@ -3056,47 +3045,39 @@ var Client = class {
3056
3045
  * }
3057
3046
  * ```
3058
3047
  */
3059
- async logs(request = {}) {
3060
- const {
3061
- urlGroup,
3062
- // eslint-disable-next-line @typescript-eslint/no-deprecated
3063
- topicName,
3064
- fromDate,
3065
- toDate,
3066
- callerIp,
3067
- messageIds,
3068
- // eslint-disable-next-line @typescript-eslint/no-deprecated
3069
- count: filterCount,
3070
- ...restFilter
3071
- } = request.filter ?? {};
3072
- const filterPayload = {
3073
- ...restFilter,
3074
- topicName: urlGroup ?? topicName,
3075
- fromDate,
3076
- toDate,
3077
- callerIp
3078
- };
3079
- let cursorString;
3080
- if (typeof request.cursor === "number" && request.cursor > 0) {
3081
- cursorString = request.cursor.toString();
3082
- } else if (typeof request.cursor === "string" && request.cursor !== "") {
3083
- cursorString = request.cursor;
3084
- }
3085
- const query = {
3086
- cursor: cursorString,
3087
- count: request.count ?? filterCount,
3088
- order: request.order,
3089
- trimBody: request.trimBody,
3090
- messageIds,
3091
- ...filterPayload
3092
- };
3048
+ async logs(request) {
3049
+ const query = {};
3050
+ if (typeof request?.cursor === "number" && request.cursor > 0) {
3051
+ query.cursor = request.cursor.toString();
3052
+ } else if (typeof request?.cursor === "string" && request.cursor !== "") {
3053
+ query.cursor = request.cursor;
3054
+ }
3055
+ for (const [key, value] of Object.entries(request?.filter ?? {})) {
3056
+ if (typeof value === "number" && value < 0) {
3057
+ continue;
3058
+ }
3059
+ if (key === "urlGroup") {
3060
+ query.topicName = value.toString();
3061
+ } else if (typeof value !== "undefined") {
3062
+ query[key] = value.toString();
3063
+ }
3064
+ }
3093
3065
  const responsePayload = await this.http.request({
3094
3066
  path: ["v2", "events"],
3095
3067
  method: "GET",
3096
3068
  query
3097
3069
  });
3098
- const logs = responsePayload.events.map((event) => ({ ...event, urlGroup: event.topicName }));
3099
- return { cursor: responsePayload.cursor, logs, events: logs };
3070
+ const logs = responsePayload.events.map((event) => {
3071
+ return {
3072
+ ...event,
3073
+ urlGroup: event.topicName
3074
+ };
3075
+ });
3076
+ return {
3077
+ cursor: responsePayload.cursor,
3078
+ logs,
3079
+ events: logs
3080
+ };
3100
3081
  }
3101
3082
  /**
3102
3083
  * @deprecated Will be removed in the next major release. Use the `logs` method instead.
package/svelte.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import "./chunk-SN6OPGRS.mjs";
1
+ import "./chunk-KDHOB7B5.mjs";
2
2
  import {
3
3
  Receiver,
4
4
  serve
5
- } from "./chunk-RUCOF5QZ.mjs";
5
+ } from "./chunk-DT2X63FB.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var verifySignatureSvelte = (handler, config) => {
package/workflow.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export { an as AsyncStepFunction, ag as DisabledWorkflowContext, F as FailureFunctionPayload, aq as FinishCondition, as as LogLevel, ap as ParallelCallState, al as RawStep, ar as RequiredExceptFields, aa as RouteFunction, S as Step, ao as StepFunction, ak as StepType, aj as StepTypes, am as SyncStepFunction, ac as Workflow, ah as WorkflowClient, af as WorkflowContext, au as WorkflowLogger, at as WorkflowLoggerOptions, ai as WorkflowReceiver, ab as WorkflowServeOptions, ad as processOptions, ae as serve } from './client-Gv4WRTxB.mjs';
1
+ export { ar as AsyncStepFunction, ak as DisabledWorkflowContext, F as FailureFunctionPayload, au as FinishCondition, aw as LogLevel, at as ParallelCallState, ap as RawStep, av as RequiredExceptFields, ae as RouteFunction, S as Step, as as StepFunction, ao as StepType, an as StepTypes, aq as SyncStepFunction, ag as Workflow, al as WorkflowClient, aj as WorkflowContext, ay as WorkflowLogger, ax as WorkflowLoggerOptions, am as WorkflowReceiver, af as WorkflowServeOptions, ah as processOptions, ai as serve } from './client-jh_SomWB.mjs';
2
2
  import 'neverthrow';
package/workflow.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { an as AsyncStepFunction, ag as DisabledWorkflowContext, F as FailureFunctionPayload, aq as FinishCondition, as as LogLevel, ap as ParallelCallState, al as RawStep, ar as RequiredExceptFields, aa as RouteFunction, S as Step, ao as StepFunction, ak as StepType, aj as StepTypes, am as SyncStepFunction, ac as Workflow, ah as WorkflowClient, af as WorkflowContext, au as WorkflowLogger, at as WorkflowLoggerOptions, ai as WorkflowReceiver, ab as WorkflowServeOptions, ad as processOptions, ae as serve } from './client-Gv4WRTxB.js';
1
+ export { ar as AsyncStepFunction, ak as DisabledWorkflowContext, F as FailureFunctionPayload, au as FinishCondition, aw as LogLevel, at as ParallelCallState, ap as RawStep, av as RequiredExceptFields, ae as RouteFunction, S as Step, as as StepFunction, ao as StepType, an as StepTypes, aq as SyncStepFunction, ag as Workflow, al as WorkflowClient, aj as WorkflowContext, ay as WorkflowLogger, ax as WorkflowLoggerOptions, am as WorkflowReceiver, af as WorkflowServeOptions, ah as processOptions, ai as serve } from './client-jh_SomWB.js';
2
2
  import 'neverthrow';