@upstash/workflow 0.2.23 → 0.3.0-rc1

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.mjs CHANGED
@@ -5,17 +5,17 @@ import {
5
5
  WorkflowAbort,
6
6
  WorkflowContext,
7
7
  WorkflowError,
8
- WorkflowLogger,
8
+ WorkflowMiddleware,
9
9
  WorkflowNonRetryableError,
10
10
  WorkflowRetryAfterError,
11
- WorkflowTool,
12
11
  getWorkflowRunId,
12
+ loggingMiddleware,
13
13
  makeGetWaitersRequest,
14
14
  makeNotifyRequest,
15
15
  prepareFlowControl,
16
16
  serve,
17
17
  triggerFirstInvocation
18
- } from "./chunk-GZRDB6Z5.mjs";
18
+ } from "./chunk-2Z32SOYM.mjs";
19
19
 
20
20
  // src/client/index.ts
21
21
  import { Client as QStashClient } from "@upstash/qstash";
@@ -28,15 +28,19 @@ var DLQ = class _DLQ {
28
28
  /**
29
29
  * list the items in the DLQ
30
30
  *
31
- * @param cursor - Optional cursor for pagination.
32
- * @param count - Optional number of items to return.
33
- * @param filter - Optional filter options to apply to the DLQ items.
31
+ * @param parameters - Optional parameters object
32
+ * @param parameters.cursor - Optional cursor for pagination
33
+ * @param parameters.count - Optional number of items to return
34
+ * @param parameters.filter - Optional filter options to apply to the DLQ items.
34
35
  * The available filter options are:
35
36
  * - `fromDate`: Filter items which entered the DLQ after this date.
36
37
  * - `toDate`: Filter items which entered the DLQ before this date.
37
38
  * - `url`: Filter items by the URL they were sent to.
38
39
  * - `responseStatus`: Filter items by the response status code.
39
- * @returns
40
+ * - `workflowRunId`: Filter items by workflow run ID.
41
+ * - `workflowCreatedAt`: Filter items by workflow creation time.
42
+ * - `failureFunctionState`: Filter items by failure callback state.
43
+ * - `label`: Filter items by label.
40
44
  */
41
45
  async list(parameters) {
42
46
  const { cursor, count, filter } = parameters || {};
@@ -79,8 +83,8 @@ var DLQ = class _DLQ {
79
83
  * Retry the failure callback of a workflow run whose failureUrl/failureFunction
80
84
  * request has failed.
81
85
  *
82
- * @param dlqId - The ID of the DLQ message to retry.
83
- * @returns
86
+ * @param dlqId - The ID of the DLQ message to retry
87
+ * @returns response with workflow run information
84
88
  */
85
89
  async retryFailureFunction({ dlqId }) {
86
90
  const response = await this.client.http.request({
@@ -89,6 +93,11 @@ var DLQ = class _DLQ {
89
93
  });
90
94
  return response;
91
95
  }
96
+ /**
97
+ * Handles DLQ options and prepares headers and query parameters.
98
+ *
99
+ * @param options - DLQ resume/restart options
100
+ */
92
101
  static handleDLQOptions(options) {
93
102
  const { dlqId, flowControl, retries } = options;
94
103
  const headers = {};
@@ -105,6 +114,11 @@ var DLQ = class _DLQ {
105
114
  headers
106
115
  };
107
116
  }
117
+ /**
118
+ * Converts DLQ ID(s) to query parameter string.
119
+ *
120
+ * @param dlqId - Single DLQ ID or array of DLQ IDs
121
+ */
108
122
  static getDlqIdQueryParameter(dlqId) {
109
123
  const dlqIds = Array.isArray(dlqId) ? dlqId : [dlqId];
110
124
  const paramsArray = dlqIds.map((id) => ["dlqIds", id]);
@@ -116,11 +130,6 @@ var DLQ = class _DLQ {
116
130
  var Client = class {
117
131
  client;
118
132
  constructor(clientConfig) {
119
- if (!clientConfig?.token) {
120
- console.error(
121
- "QStash token is required for Upstash Workflow!\n\nTo fix this:\n1. Get your token from the Upstash Console (https://console.upstash.com/qstash)\n2. Initialize the workflow client with:\n\n const client = new Client({\n token: '<YOUR_QSTASH_TOKEN>'\n });"
122
- );
123
- }
124
133
  this.client = new QStashClient(clientConfig);
125
134
  }
126
135
  /**
@@ -243,11 +252,10 @@ var Client = class {
243
252
  const isBatchInput = Array.isArray(params);
244
253
  const options = isBatchInput ? params : [params];
245
254
  const invocations = options.map((option) => {
246
- const failureUrl = option.useFailureFunction ? option.url : option.failureUrl;
255
+ const failureUrl = option.failureUrl ?? option.url;
247
256
  const finalWorkflowRunId = getWorkflowRunId(option.workflowRunId);
248
257
  const context = new WorkflowContext({
249
258
  qstashClient: this.client,
250
- // @ts-expect-error header type mismatch because of bun
251
259
  headers: new Headers({
252
260
  ...option.headers ?? {},
253
261
  ...option.label ? { [WORKFLOW_LABEL_HEADER]: option.label } : {}
@@ -256,11 +264,7 @@ var Client = class {
256
264
  steps: [],
257
265
  url: option.url,
258
266
  workflowRunId: finalWorkflowRunId,
259
- retries: option.retries,
260
- retryDelay: option.retryDelay,
261
267
  telemetry: option.disableTelemetry ? void 0 : { sdk: SDK_TELEMETRY },
262
- flowControl: option.flowControl,
263
- failureUrl,
264
268
  label: option.label
265
269
  });
266
270
  return {
@@ -268,7 +272,10 @@ var Client = class {
268
272
  telemetry: option.disableTelemetry ? void 0 : { sdk: SDK_TELEMETRY },
269
273
  delay: option.delay,
270
274
  notBefore: option.notBefore,
271
- keepTriggerConfig: option.keepTriggerConfig
275
+ failureUrl,
276
+ retries: option.retries,
277
+ retryDelay: option.retryDelay,
278
+ flowControl: option.flowControl
272
279
  };
273
280
  });
274
281
  const result = await triggerFirstInvocation(invocations);
@@ -347,9 +354,9 @@ export {
347
354
  WorkflowAbort,
348
355
  WorkflowContext,
349
356
  WorkflowError,
350
- WorkflowLogger,
357
+ WorkflowMiddleware,
351
358
  WorkflowNonRetryableError,
352
359
  WorkflowRetryAfterError,
353
- WorkflowTool,
360
+ loggingMiddleware,
354
361
  serve
355
362
  };
package/nextjs.d.mts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
2
- import { R as RouteFunction, o as PublicServeOptions, z as InvokableWorkflow } from './types-BD06btU6.mjs';
3
- import { s as serveManyBase } from './serve-many-B5Vbacm6.mjs';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, x as InvokableWorkflow } from './types-pEje3VEB.mjs';
3
+ import { s as serveManyBase } from './serve-many-DhB8-zPD.mjs';
4
4
  import '@upstash/qstash';
5
5
  import 'zod';
6
- import 'ai';
7
- import '@ai-sdk/openai';
8
6
 
9
7
  /**
10
8
  * Serve method to serve a Upstash Workflow in a Nextjs project
@@ -15,17 +13,17 @@ import '@ai-sdk/openai';
15
13
  * @param options workflow options
16
14
  * @returns
17
15
  */
18
- declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
16
+ declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
19
17
  POST: (request: Request) => Promise<Response>;
20
18
  };
21
- declare const createWorkflow: <TInitialPayload, TResult>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
19
+ declare const createWorkflow: <TInitialPayload, TResult>(...params: Parameters<typeof serve<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
22
20
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
23
21
  POST: (request: Request) => Promise<any>;
24
22
  };
25
- declare const servePagesRouter: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
23
+ declare const servePagesRouter: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
26
24
  handler: NextApiHandler;
27
25
  };
28
- declare const createWorkflowPagesRouter: <TInitialPayload, TResult>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
26
+ declare const createWorkflowPagesRouter: <TInitialPayload, TResult>(...params: Parameters<typeof servePagesRouter<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
29
27
  declare const serveManyPagesRouter: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
30
28
  handler: (req: NextApiRequest, res: NextApiResponse<any>) => Promise<any>;
31
29
  };
package/nextjs.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
2
- import { R as RouteFunction, o as PublicServeOptions, z as InvokableWorkflow } from './types-BD06btU6.js';
3
- import { s as serveManyBase } from './serve-many-BCV7INWe.js';
2
+ import { c as RouteFunction, d as WorkflowServeOptions, x as InvokableWorkflow } from './types-pEje3VEB.js';
3
+ import { s as serveManyBase } from './serve-many-qnfynN1x.js';
4
4
  import '@upstash/qstash';
5
5
  import 'zod';
6
- import 'ai';
7
- import '@ai-sdk/openai';
8
6
 
9
7
  /**
10
8
  * Serve method to serve a Upstash Workflow in a Nextjs project
@@ -15,17 +13,17 @@ import '@ai-sdk/openai';
15
13
  * @param options workflow options
16
14
  * @returns
17
15
  */
18
- declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
16
+ declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
19
17
  POST: (request: Request) => Promise<Response>;
20
18
  };
21
- declare const createWorkflow: <TInitialPayload, TResult>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
19
+ declare const createWorkflow: <TInitialPayload, TResult>(...params: Parameters<typeof serve<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
22
20
  declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
23
21
  POST: (request: Request) => Promise<any>;
24
22
  };
25
- declare const servePagesRouter: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
23
+ declare const servePagesRouter: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: WorkflowServeOptions<TInitialPayload, TResult>) => {
26
24
  handler: NextApiHandler;
27
25
  };
28
- declare const createWorkflowPagesRouter: <TInitialPayload, TResult>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
26
+ declare const createWorkflowPagesRouter: <TInitialPayload, TResult>(...params: Parameters<typeof servePagesRouter<TInitialPayload, TResult>>) => InvokableWorkflow<TInitialPayload, TResult>;
29
27
  declare const serveManyPagesRouter: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => {
30
28
  handler: (req: NextApiRequest, res: NextApiResponse<any>) => Promise<any>;
31
29
  };