@upstash/workflow 1.2.0 → 1.3.0

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.
Files changed (51) hide show
  1. package/README.md +10 -0
  2. package/astro.d.mts +2 -2
  3. package/astro.d.ts +2 -2
  4. package/astro.js +31 -5
  5. package/astro.mjs +1 -1
  6. package/{chunk-V5ZUHMAF.mjs → chunk-G24J5PCC.mjs} +93 -5
  7. package/cloudflare.d.mts +2 -2
  8. package/cloudflare.d.ts +2 -2
  9. package/cloudflare.js +31 -5
  10. package/cloudflare.mjs +1 -1
  11. package/express.d.mts +2 -2
  12. package/express.d.ts +2 -2
  13. package/express.js +31 -5
  14. package/express.mjs +1 -1
  15. package/h3.d.mts +2 -2
  16. package/h3.d.ts +2 -2
  17. package/h3.js +31 -5
  18. package/h3.mjs +1 -1
  19. package/hono.d.mts +2 -2
  20. package/hono.d.ts +2 -2
  21. package/hono.js +31 -5
  22. package/hono.mjs +1 -1
  23. package/index.d.mts +201 -128
  24. package/index.d.ts +201 -128
  25. package/index.js +212 -160
  26. package/index.mjs +124 -156
  27. package/nextjs.d.mts +2 -2
  28. package/nextjs.d.ts +2 -2
  29. package/nextjs.js +31 -5
  30. package/nextjs.mjs +1 -1
  31. package/package.json +1 -1
  32. package/react-router.d.mts +2 -2
  33. package/react-router.d.ts +2 -2
  34. package/react-router.js +31 -5
  35. package/react-router.mjs +1 -1
  36. package/{serve-many-C6sa_DxN.d.mts → serve-many-D3D9uE4u.d.mts} +1 -1
  37. package/{serve-many-B-fe7bh7.d.ts → serve-many-kPOasiyb.d.ts} +1 -1
  38. package/solidjs.d.mts +1 -1
  39. package/solidjs.d.ts +1 -1
  40. package/solidjs.js +31 -5
  41. package/solidjs.mjs +1 -1
  42. package/svelte.d.mts +2 -2
  43. package/svelte.d.ts +2 -2
  44. package/svelte.js +31 -5
  45. package/svelte.mjs +1 -1
  46. package/tanstack.d.mts +2 -2
  47. package/tanstack.d.ts +2 -2
  48. package/tanstack.js +31 -5
  49. package/tanstack.mjs +1 -1
  50. package/{types-B2S08hRU.d.ts → types-B_E1VAK6.d.mts} +9 -1
  51. package/{types-B2S08hRU.d.mts → types-B_E1VAK6.d.ts} +9 -1
package/index.js CHANGED
@@ -196,6 +196,66 @@ var getSteps = async (requester, workflowRunId, messageId, dispatchDebug) => {
196
196
  }
197
197
  }
198
198
  };
199
+ function normalizeCursor(response) {
200
+ const cursor = response.cursor;
201
+ return { ...response, cursor: cursor || void 0 };
202
+ }
203
+ var DEFAULT_BULK_COUNT = 100;
204
+ function buildBulkActionQueryParameters(request, options) {
205
+ const cursor = "cursor" in request ? request.cursor : void 0;
206
+ if ("all" in request) {
207
+ return { count: request.count ?? DEFAULT_BULK_COUNT, cursor };
208
+ }
209
+ if ("dlqIds" in request) {
210
+ const ids = request.dlqIds;
211
+ if (Array.isArray(ids) && ids.length === 0) {
212
+ throw new import_qstash2.QstashError(
213
+ "Empty dlqIds array provided. If you intend to target all DLQ messages, use { all: true } explicitly."
214
+ );
215
+ }
216
+ return { dlqIds: ids, cursor };
217
+ }
218
+ if ("workflowRunIds" in request && request.workflowRunIds) {
219
+ if (request.workflowRunIds.length === 0) {
220
+ throw new import_qstash2.QstashError(
221
+ "Empty workflowRunIds array provided. If you intend to target all workflow runs, use { all: true } explicitly."
222
+ );
223
+ }
224
+ return { workflowRunIds: request.workflowRunIds };
225
+ }
226
+ const filter = request.filter;
227
+ if (!filter) {
228
+ throw new import_qstash2.QstashError(
229
+ "No filter provided. Use { filter: { ... } } with at least one filter field, or { all: true }."
230
+ );
231
+ }
232
+ if (options?.translateWorkflowUrl) {
233
+ const { workflowUrlStartingWith, workflowUrl, ...rest } = filter;
234
+ if (workflowUrlStartingWith && workflowUrl) {
235
+ throw new import_qstash2.QstashError(
236
+ "workflowUrl and workflowUrlStartingWith are mutually exclusive. Use workflowUrl for exact match or workflowUrlStartingWith for prefix match."
237
+ );
238
+ }
239
+ const urlParams = {};
240
+ if (workflowUrlStartingWith) {
241
+ urlParams.workflowUrl = workflowUrlStartingWith;
242
+ } else if (workflowUrl) {
243
+ urlParams.workflowUrl = workflowUrl;
244
+ urlParams.workflowUrlExactMatch = true;
245
+ }
246
+ return {
247
+ ...rest,
248
+ ...urlParams,
249
+ count: request.count ?? DEFAULT_BULK_COUNT,
250
+ cursor
251
+ };
252
+ }
253
+ return {
254
+ ...filter,
255
+ count: request.count ?? DEFAULT_BULK_COUNT,
256
+ cursor
257
+ };
258
+ }
199
259
 
200
260
  // src/constants.ts
201
261
  var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
@@ -206,6 +266,7 @@ var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
206
266
  var WORKFLOW_FAILURE_CALLBACK_HEADER = "Upstash-Workflow-Failure-Callback";
207
267
  var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
208
268
  var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
269
+ var WORKFLOW_RETRIED_HEADER = "Upstash-Retried";
209
270
  var WORKFLOW_LABEL_HEADER = "Upstash-Label";
210
271
  var WORKFLOW_UNKOWN_SDK_VERSION_HEADER = "Upstash-Workflow-Unknown-Sdk";
211
272
  var WORKFLOW_UNKOWN_SDK_TRIGGER_HEADER = "upstash-workflow-trigger-by-sdk";
@@ -214,7 +275,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
214
275
  var DEFAULT_CONTENT_TYPE = "application/json";
215
276
  var NO_CONCURRENCY = 1;
216
277
  var DEFAULT_RETRIES = 3;
217
- var VERSION = "v1.0.0";
278
+ var VERSION = "v1.2.1";
218
279
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
219
280
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
220
281
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -869,6 +930,9 @@ var recreateUserHeaders = (headers) => {
869
930
  }
870
931
  return filteredHeaders;
871
932
  };
933
+ var isThirdPartyCallResult = (request) => {
934
+ return request.headers.get("Upstash-Workflow-Callback") !== null;
935
+ };
872
936
  var handleThirdPartyCallResult = async ({
873
937
  request,
874
938
  requestPayload,
@@ -878,7 +942,7 @@ var handleThirdPartyCallResult = async ({
878
942
  middlewareManager
879
943
  }) => {
880
944
  try {
881
- if (request.headers.get("Upstash-Workflow-Callback")) {
945
+ if (isThirdPartyCallResult(request)) {
882
946
  let callbackPayload;
883
947
  if (requestPayload) {
884
948
  callbackPayload = requestPayload;
@@ -2654,6 +2718,13 @@ var WorkflowContext = class {
2654
2718
  * ```
2655
2719
  */
2656
2720
  label;
2721
+ /**
2722
+ * Number of times QStash has retried delivering the current request.
2723
+ *
2724
+ * Sourced from the `Upstash-Retried` header. `0` on the first delivery,
2725
+ * `1` on the first retry, `2` on the second, and so on.
2726
+ */
2727
+ retried;
2657
2728
  constructor({
2658
2729
  qstashClient,
2659
2730
  workflowRunId,
@@ -2666,6 +2737,7 @@ var WorkflowContext = class {
2666
2737
  telemetry,
2667
2738
  invokeCount,
2668
2739
  label,
2740
+ retried,
2669
2741
  middlewareManager
2670
2742
  }) {
2671
2743
  this.qstashClient = qstashClient;
@@ -2677,6 +2749,7 @@ var WorkflowContext = class {
2677
2749
  this.requestPayload = initialPayload;
2678
2750
  this.env = env ?? {};
2679
2751
  this.label = label;
2752
+ this.retried = retried ?? 0;
2680
2753
  const middlewareManagerInstance = middlewareManager ?? new MiddlewareManager([]);
2681
2754
  middlewareManagerInstance.assignContext(this);
2682
2755
  this.executor = new AutoExecutor(
@@ -2940,7 +3013,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2940
3013
  const disabledContext = new _DisabledWorkflowContext({
2941
3014
  qstashClient: new import_qstash10.Client({
2942
3015
  baseUrl: "disabled-client",
2943
- token: "disabled-client"
3016
+ token: "disabled-client",
3017
+ devMode: false
2944
3018
  }),
2945
3019
  workflowRunId: context.workflowRunId,
2946
3020
  workflowRunCreatedAt: context.workflowRunCreatedAt,
@@ -2949,7 +3023,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2949
3023
  url: context.url,
2950
3024
  initialPayload: context.requestPayload,
2951
3025
  env: context.env,
2952
- label: context.label
3026
+ label: context.label,
3027
+ retried: context.retried
2953
3028
  });
2954
3029
  try {
2955
3030
  await routeFunction(disabledContext);
@@ -3165,6 +3240,7 @@ var handleFailure = async ({
3165
3240
  errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
3166
3241
  }
3167
3242
  const userHeaders = recreateUserHeaders(request.headers);
3243
+ const retried = Number(request.headers.get(WORKFLOW_RETRIED_HEADER) ?? "0");
3168
3244
  const workflowContext = new WorkflowContext({
3169
3245
  qstashClient,
3170
3246
  workflowRunId,
@@ -3176,6 +3252,7 @@ var handleFailure = async ({
3176
3252
  telemetry: void 0,
3177
3253
  // not going to make requests in authentication check
3178
3254
  label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0,
3255
+ retried,
3179
3256
  workflowRunCreatedAt: workflowCreatedAt,
3180
3257
  middlewareManager: void 0
3181
3258
  });
@@ -3335,6 +3412,9 @@ var getReceiver = (environment, receiverConfig, region) => {
3335
3412
  if (receiverConfig === "set-to-undefined") {
3336
3413
  return void 0;
3337
3414
  }
3415
+ if (isQStashDevModeEnabled(environment)) {
3416
+ return new import_qstash11.Receiver({ devMode: true });
3417
+ }
3338
3418
  const receiverEnv = readReceiverEnvironmentVariables(environment, region);
3339
3419
  return receiverEnv.QSTASH_CURRENT_SIGNING_KEY && receiverEnv.QSTASH_NEXT_SIGNING_KEY ? new import_qstash11.Receiver({
3340
3420
  currentSigningKey: receiverEnv.QSTASH_CURRENT_SIGNING_KEY,
@@ -3344,6 +3424,10 @@ var getReceiver = (environment, receiverConfig, region) => {
3344
3424
  return receiverConfig;
3345
3425
  }
3346
3426
  };
3427
+ var isQStashDevModeEnabled = (env) => {
3428
+ const value = env.QSTASH_DEV;
3429
+ return value === "true" || value === "1";
3430
+ };
3347
3431
  var getQStashHandlerOptions = (...params) => {
3348
3432
  const handlers = getQStashHandlers(...params);
3349
3433
  return {
@@ -3653,12 +3737,13 @@ var serveBase = (routeFunction, telemetry, options, internalOptions) => {
3653
3737
  );
3654
3738
  }
3655
3739
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
3740
+ const retried = Number(request.headers.get(WORKFLOW_RETRIED_HEADER) ?? "0");
3656
3741
  const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
3657
3742
  const workflowRunCreatedAt = request.headers.get(WORKFLOW_CREATED_AT_HEADER);
3658
3743
  const workflowContext = new WorkflowContext({
3659
3744
  qstashClient: regionalClient,
3660
3745
  workflowRunId,
3661
- initialPayload: initialPayloadParser(rawInitialPayload),
3746
+ initialPayload: isThirdPartyCallResult(request) ? JSON.parse(rawInitialPayload) : initialPayloadParser(rawInitialPayload),
3662
3747
  headers: recreateUserHeaders(request.headers),
3663
3748
  steps,
3664
3749
  url: workflowUrl,
@@ -3666,6 +3751,7 @@ var serveBase = (routeFunction, telemetry, options, internalOptions) => {
3666
3751
  telemetry,
3667
3752
  invokeCount,
3668
3753
  label,
3754
+ retried,
3669
3755
  workflowRunCreatedAt: Number(workflowRunCreatedAt),
3670
3756
  middlewareManager
3671
3757
  });
@@ -3800,7 +3886,19 @@ var serve = (routeFunction, options) => {
3800
3886
  var import_qstash12 = require("@upstash/qstash");
3801
3887
 
3802
3888
  // src/client/dlq.ts
3803
- var DLQ = class _DLQ {
3889
+ function buildResumeRestartHeaders(options) {
3890
+ const headers = {};
3891
+ if (options?.flowControl) {
3892
+ const { flowControlKey, flowControlValue } = prepareFlowControl(options.flowControl);
3893
+ headers["Upstash-Flow-Control-Key"] = flowControlKey;
3894
+ headers["Upstash-Flow-Control-Value"] = flowControlValue;
3895
+ }
3896
+ if (options?.retries !== void 0) {
3897
+ headers["Upstash-Retries"] = options.retries.toString();
3898
+ }
3899
+ return headers;
3900
+ }
3901
+ var DLQ = class {
3804
3902
  constructor(client) {
3805
3903
  this.client = client;
3806
3904
  }
@@ -3823,40 +3921,66 @@ var DLQ = class _DLQ {
3823
3921
  */
3824
3922
  async list(parameters) {
3825
3923
  const { cursor, count, filter } = parameters || {};
3826
- return await this.client.http.request({
3827
- path: ["v2", "dlq"],
3828
- method: "GET",
3829
- query: {
3830
- cursor,
3831
- count,
3832
- ...filter,
3833
- source: "workflow"
3834
- }
3835
- });
3924
+ return normalizeCursor(
3925
+ await this.client.http.request({
3926
+ path: ["v2", "dlq"],
3927
+ method: "GET",
3928
+ query: {
3929
+ cursor,
3930
+ count,
3931
+ ...filter,
3932
+ source: "workflow"
3933
+ }
3934
+ })
3935
+ );
3836
3936
  }
3837
- async resume(parameters) {
3838
- const { headers, queryParams } = _DLQ.handleDLQOptions(parameters);
3839
- const { workflowRuns } = await this.client.http.request({
3840
- path: ["v2", "workflows", "dlq", `resume?${queryParams}`],
3841
- headers,
3842
- method: "POST"
3843
- });
3844
- if (Array.isArray(parameters.dlqId)) {
3845
- return workflowRuns;
3937
+ async resume(request, options) {
3938
+ if (typeof request === "object" && !Array.isArray(request) && "dlqId" in request) {
3939
+ const { dlqId, flowControl, retries } = request;
3940
+ const dlqIds = Array.isArray(dlqId) ? dlqId : [dlqId];
3941
+ const { workflowRuns } = await this.client.http.request({
3942
+ path: ["v2", "workflows", "dlq", "resume"],
3943
+ query: { dlqIds },
3944
+ method: "POST",
3945
+ headers: buildResumeRestartHeaders({ flowControl, retries })
3946
+ });
3947
+ return Array.isArray(dlqId) ? workflowRuns : workflowRuns[0];
3846
3948
  }
3847
- return workflowRuns[0];
3949
+ if (typeof request === "string") request = [request];
3950
+ if (Array.isArray(request) && request.length === 0) return { workflowRuns: [] };
3951
+ const filters = Array.isArray(request) ? { dlqIds: request } : request;
3952
+ return normalizeCursor(
3953
+ await this.client.http.request({
3954
+ path: ["v2", "workflows", "dlq", "resume"],
3955
+ query: buildBulkActionQueryParameters(filters),
3956
+ method: "POST",
3957
+ headers: buildResumeRestartHeaders(options)
3958
+ })
3959
+ );
3848
3960
  }
3849
- async restart(parameters) {
3850
- const { headers, queryParams } = _DLQ.handleDLQOptions(parameters);
3851
- const { workflowRuns } = await this.client.http.request({
3852
- path: ["v2", "workflows", "dlq", `restart?${queryParams}`],
3853
- headers,
3854
- method: "POST"
3855
- });
3856
- if (Array.isArray(parameters.dlqId)) {
3857
- return workflowRuns;
3961
+ async restart(request, options) {
3962
+ if (typeof request === "object" && !Array.isArray(request) && "dlqId" in request) {
3963
+ const { dlqId, flowControl, retries } = request;
3964
+ const dlqIds = Array.isArray(dlqId) ? dlqId : [dlqId];
3965
+ const { workflowRuns } = await this.client.http.request({
3966
+ path: ["v2", "workflows", "dlq", "restart"],
3967
+ query: { dlqIds },
3968
+ method: "POST",
3969
+ headers: buildResumeRestartHeaders({ flowControl, retries })
3970
+ });
3971
+ return Array.isArray(dlqId) ? workflowRuns : workflowRuns[0];
3858
3972
  }
3859
- return workflowRuns[0];
3973
+ if (typeof request === "string") request = [request];
3974
+ if (Array.isArray(request) && request.length === 0) return { workflowRuns: [] };
3975
+ const filters = Array.isArray(request) ? { dlqIds: request } : request;
3976
+ return normalizeCursor(
3977
+ await this.client.http.request({
3978
+ path: ["v2", "workflows", "dlq", "restart"],
3979
+ query: buildBulkActionQueryParameters(filters),
3980
+ method: "POST",
3981
+ headers: buildResumeRestartHeaders(options)
3982
+ })
3983
+ );
3860
3984
  }
3861
3985
  /**
3862
3986
  * Retry the failure callback of a workflow run whose failureUrl/failureFunction
@@ -3873,35 +3997,36 @@ var DLQ = class _DLQ {
3873
3997
  return response;
3874
3998
  }
3875
3999
  /**
3876
- * Handles DLQ options and prepares headers and query parameters.
4000
+ * Delete DLQ messages.
3877
4001
  *
3878
- * @param options - DLQ resume/restart options
3879
- */
3880
- static handleDLQOptions(options) {
3881
- const { dlqId, flowControl, retries } = options;
3882
- const headers = {};
3883
- if (flowControl) {
3884
- const { flowControlKey, flowControlValue } = prepareFlowControl(flowControl);
3885
- headers["Upstash-Flow-Control-Key"] = flowControlKey;
3886
- headers["Upstash-Flow-Control-Value"] = flowControlValue;
3887
- }
3888
- if (retries !== void 0) {
3889
- headers["Upstash-Retries"] = retries.toString();
3890
- }
3891
- return {
3892
- queryParams: _DLQ.getDlqIdQueryParameter(dlqId),
3893
- headers
3894
- };
3895
- }
3896
- /**
3897
- * Converts DLQ ID(s) to query parameter string.
4002
+ * Can be called with:
4003
+ * - A single dlqId: `delete("id")`
4004
+ * - An array of dlqIds: `delete(["id1", "id2"])`
4005
+ * - A filter object: `delete({ filter: { label: "my-label", fromDate: 1640995200000 } })`
4006
+ * - To target all entries: `delete({ all: true })`
4007
+ *
4008
+ * Processes up to `count` messages per call (defaults to 100).
4009
+ * Call in a loop until cursor is undefined to process all:
3898
4010
  *
3899
- * @param dlqId - Single DLQ ID or array of DLQ IDs
4011
+ * ```ts
4012
+ * let cursor: string | undefined;
4013
+ * do {
4014
+ * const result = await client.dlq.delete({ all: true, count: 100, cursor });
4015
+ * cursor = result.cursor;
4016
+ * } while (cursor);
4017
+ * ```
3900
4018
  */
3901
- static getDlqIdQueryParameter(dlqId) {
3902
- const dlqIds = Array.isArray(dlqId) ? dlqId : [dlqId];
3903
- const paramsArray = dlqIds.map((id) => ["dlqIds", id]);
3904
- return new URLSearchParams(paramsArray).toString();
4019
+ async delete(request) {
4020
+ if (typeof request === "string") request = [request];
4021
+ if (Array.isArray(request) && request.length === 0) return { deleted: 0 };
4022
+ const filters = Array.isArray(request) ? { dlqIds: request } : request;
4023
+ return normalizeCursor(
4024
+ await this.client.http.request({
4025
+ path: ["v2", "workflows", "dlq"],
4026
+ method: "DELETE",
4027
+ query: buildBulkActionQueryParameters(filters)
4028
+ })
4029
+ );
3905
4030
  }
3906
4031
  };
3907
4032
 
@@ -3911,82 +4036,25 @@ var Client4 = class {
3911
4036
  constructor(clientConfig) {
3912
4037
  this.client = new import_qstash12.Client(clientConfig);
3913
4038
  }
3914
- /**
3915
- * Cancel an ongoing workflow
3916
- *
3917
- * Returns true if workflow is canceled succesfully. Otherwise, throws error.
3918
- *
3919
- * There are multiple ways you can cancel workflows:
3920
- * - pass one or more workflow run ids to cancel them
3921
- * - pass a workflow url to cancel all runs starting with this url
3922
- * - cancel all pending or active workflow runs
3923
- *
3924
- * ### Cancel a set of workflow runs
3925
- *
3926
- * ```ts
3927
- * // cancel a single workflow
3928
- * await client.cancel({ ids: "<WORKFLOW_RUN_ID>" })
3929
- *
3930
- * // cancel a set of workflow runs
3931
- * await client.cancel({ ids: [
3932
- * "<WORKFLOW_RUN_ID_1>",
3933
- * "<WORKFLOW_RUN_ID_2>",
3934
- * ]})
3935
- * ```
3936
- *
3937
- * ### Cancel workflows starting with a url
3938
- *
3939
- * If you have an endpoint called `https://your-endpoint.com` and you
3940
- * want to cancel all workflow runs on it, you can use `urlStartingWith`.
3941
- *
3942
- * Note that this will cancel workflows in all endpoints under
3943
- * `https://your-endpoint.com`.
3944
- *
3945
- * ```ts
3946
- * await client.cancel({ urlStartingWith: "https://your-endpoint.com" })
3947
- * ```
3948
- *
3949
- * ### Cancel *all* workflows
3950
- *
3951
- * To cancel all pending and currently running workflows, you can
3952
- * do it like this:
3953
- *
3954
- * ```ts
3955
- * await client.cancel({ all: true })
3956
- * ```
3957
- *
3958
- * @param ids run id of the workflow to delete
3959
- * @param urlStartingWith cancel workflows starting with this url. Will be ignored
3960
- * if `ids` parameter is set.
3961
- * @param all set to true in order to cancel all workflows. Will be ignored
3962
- * if `ids` or `urlStartingWith` parameters are set.
3963
- * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
3964
- */
3965
- async cancel({
3966
- ids,
3967
- urlStartingWith,
3968
- all
3969
- }) {
3970
- let body;
3971
- if (ids) {
3972
- const runIdArray = typeof ids === "string" ? [ids] : ids;
3973
- body = JSON.stringify({ workflowRunIds: runIdArray });
3974
- } else if (urlStartingWith) {
3975
- body = JSON.stringify({ workflowUrl: urlStartingWith });
3976
- } else if (all) {
3977
- body = "{}";
3978
- } else {
3979
- throw new TypeError("The `cancel` method cannot be called without any options.");
4039
+ async cancel(request) {
4040
+ if (typeof request === "object" && !Array.isArray(request) && ("ids" in request || "urlStartingWith" in request)) {
4041
+ const legacy = request;
4042
+ if (legacy.ids) {
4043
+ const ids = typeof legacy.ids === "string" ? [legacy.ids] : legacy.ids;
4044
+ return this.cancel(ids);
4045
+ }
4046
+ if (legacy.urlStartingWith) {
4047
+ return this.cancel({ filter: { workflowUrlStartingWith: legacy.urlStartingWith } });
4048
+ }
3980
4049
  }
3981
- const result = await this.client.http.request({
4050
+ if (typeof request === "string") request = [request];
4051
+ if (Array.isArray(request) && request.length === 0) return { cancelled: 0 };
4052
+ const filters = Array.isArray(request) ? { workflowRunIds: request } : request;
4053
+ return await this.client.http.request({
3982
4054
  path: ["v2", "workflows", "runs"],
3983
4055
  method: "DELETE",
3984
- body,
3985
- headers: {
3986
- "Content-Type": "application/json"
3987
- }
4056
+ query: buildBulkActionQueryParameters(filters, { translateWorkflowUrl: true })
3988
4057
  });
3989
- return result;
3990
4058
  }
3991
4059
  /**
3992
4060
  * Notify a workflow run waiting for an event
@@ -4110,33 +4178,17 @@ var Client4 = class {
4110
4178
  * ```
4111
4179
  */
4112
4180
  async logs(params) {
4113
- const { workflowRunId, cursor, count, state, workflowUrl, workflowCreatedAt } = params ?? {};
4114
- const urlParams = new URLSearchParams({ groupBy: "workflowRunId" });
4115
- if (workflowRunId) {
4116
- urlParams.append("workflowRunId", workflowRunId);
4117
- }
4118
- if (cursor) {
4119
- urlParams.append("cursor", cursor);
4120
- }
4121
- if (count) {
4122
- urlParams.append("count", count.toString());
4123
- }
4124
- if (state) {
4125
- urlParams.append("state", state);
4126
- }
4127
- if (workflowUrl) {
4128
- urlParams.append("workflowUrl", workflowUrl);
4129
- }
4130
- if (workflowCreatedAt) {
4131
- urlParams.append("workflowCreatedAt", workflowCreatedAt.toString());
4132
- }
4133
- if (params?.label) {
4134
- urlParams.append("label", params.label);
4135
- }
4136
- const result = await this.client.http.request({
4137
- path: ["v2", "workflows", `events?${urlParams.toString()}`]
4181
+ const { cursor, count, filter, ...legacyFilter } = params ?? {};
4182
+ return await this.client.http.request({
4183
+ path: ["v2", "workflows", "events"],
4184
+ query: {
4185
+ groupBy: "workflowRunId",
4186
+ ...legacyFilter,
4187
+ cursor,
4188
+ count,
4189
+ ...filter
4190
+ }
4138
4191
  });
4139
- return result;
4140
4192
  }
4141
4193
  get dlq() {
4142
4194
  return new DLQ(this.client);