@upstash/workflow 0.2.18 → 0.2.20

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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _sveltejs_kit from '@sveltejs/kit';
2
2
  import { RequestHandler } from '@sveltejs/kit';
3
- import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.mjs';
4
- import { s as serveManyBase } from './serve-many-CEUYWQvV.mjs';
3
+ import { R as RouteFunction, n as PublicServeOptions, y as InvokableWorkflow } from './types-Q3dM0UlR.mjs';
4
+ import { s as serveManyBase } from './serve-many-BNusWYgt.mjs';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';
package/svelte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _sveltejs_kit from '@sveltejs/kit';
2
2
  import { RequestHandler } from '@sveltejs/kit';
3
- import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.js';
4
- import { s as serveManyBase } from './serve-many-BObe3pdI.js';
3
+ import { R as RouteFunction, n as PublicServeOptions, y as InvokableWorkflow } from './types-Q3dM0UlR.js';
4
+ import { s as serveManyBase } from './serve-many-CXqQP3RI.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';
package/svelte.js CHANGED
@@ -92,7 +92,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
92
92
  var DEFAULT_CONTENT_TYPE = "application/json";
93
93
  var NO_CONCURRENCY = 1;
94
94
  var DEFAULT_RETRIES = 3;
95
- var VERSION = "v0.2.18";
95
+ var VERSION = "v0.2.20";
96
96
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
97
97
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
98
98
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -143,7 +143,8 @@ var WorkflowNonRetryableError = class extends WorkflowAbort {
143
143
  var formatWorkflowError = (error) => {
144
144
  return error instanceof Error ? {
145
145
  error: error.name,
146
- message: error.message
146
+ message: error.message,
147
+ stack: error.stack
147
148
  } : {
148
149
  error: "Error",
149
150
  message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
@@ -614,7 +615,7 @@ var triggerFirstInvocation = async (params) => {
614
615
  const firstInvocationParams = Array.isArray(params) ? params : [params];
615
616
  const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
616
617
  const invocationBatch = firstInvocationParams.map(
617
- ({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
618
+ ({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay, notBefore }) => {
618
619
  const { headers } = getHeaders({
619
620
  initHeaderValue: "true",
620
621
  workflowConfig: {
@@ -645,7 +646,8 @@ var triggerFirstInvocation = async (params) => {
645
646
  method: "POST",
646
647
  body,
647
648
  url: workflowContext.url,
648
- delay
649
+ delay,
650
+ notBefore
649
651
  };
650
652
  }
651
653
  );
@@ -1133,9 +1135,10 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1133
1135
  retryDelay;
1134
1136
  timeout;
1135
1137
  flowControl;
1138
+ stringifyBody;
1136
1139
  stepType = "Call";
1137
1140
  allowUndefinedOut = false;
1138
- constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl) {
1141
+ constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl, stringifyBody) {
1139
1142
  super(stepName);
1140
1143
  this.url = url;
1141
1144
  this.method = method;
@@ -1145,6 +1148,7 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1145
1148
  this.retryDelay = retryDelay;
1146
1149
  this.timeout = timeout;
1147
1150
  this.flowControl = flowControl;
1151
+ this.stringifyBody = stringifyBody;
1148
1152
  }
1149
1153
  getPlanStep(concurrent, targetStep) {
1150
1154
  return {
@@ -1254,10 +1258,22 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1254
1258
  };
1255
1259
  }
1256
1260
  async submitStep({ context, headers }) {
1261
+ let callBody;
1262
+ if (this.stringifyBody) {
1263
+ callBody = JSON.stringify(this.body);
1264
+ } else {
1265
+ if (typeof this.body === "string") {
1266
+ callBody = this.body;
1267
+ } else {
1268
+ throw new WorkflowError(
1269
+ "When stringifyBody is false, body must be a string. Please check the body type of your call step."
1270
+ );
1271
+ }
1272
+ }
1257
1273
  return await context.qstashClient.batch([
1258
1274
  {
1259
1275
  headers,
1260
- body: JSON.stringify(this.body),
1276
+ body: callBody,
1261
1277
  method: this.method,
1262
1278
  url: this.url,
1263
1279
  retries: DEFAULT_RETRIES === this.retries ? void 0 : this.retries,
@@ -1392,7 +1408,8 @@ var LazyInvokeStep = class extends BaseLazyStep {
1392
1408
  workflowRunId,
1393
1409
  retries,
1394
1410
  retryDelay,
1395
- flowControl
1411
+ flowControl,
1412
+ stringifyBody = true
1396
1413
  }) {
1397
1414
  super(stepName);
1398
1415
  this.params = {
@@ -1402,7 +1419,8 @@ var LazyInvokeStep = class extends BaseLazyStep {
1402
1419
  workflowRunId: getWorkflowRunId(workflowRunId),
1403
1420
  retries,
1404
1421
  retryDelay,
1405
- flowControl
1422
+ flowControl,
1423
+ stringifyBody
1406
1424
  };
1407
1425
  const { workflowId } = workflow;
1408
1426
  if (!workflowId) {
@@ -1455,8 +1473,20 @@ var LazyInvokeStep = class extends BaseLazyStep {
1455
1473
  invokeCount
1456
1474
  });
1457
1475
  invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
1476
+ let invokeBody;
1477
+ if (this.params.stringifyBody) {
1478
+ invokeBody = JSON.stringify(this.params.body);
1479
+ } else {
1480
+ if (typeof this.params.body === "string") {
1481
+ invokeBody = this.params.body;
1482
+ } else {
1483
+ throw new WorkflowError(
1484
+ "When stringifyBody is false, body must be a string. Please check the body type of your invoke step."
1485
+ );
1486
+ }
1487
+ }
1458
1488
  const request = {
1459
- body: JSON.stringify(this.params.body),
1489
+ body: invokeBody,
1460
1490
  headers: Object.fromEntries(
1461
1491
  Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
1462
1492
  ),
@@ -2900,7 +2930,8 @@ var WorkflowContext = class {
2900
2930
  settings.retries || 0,
2901
2931
  settings.retryDelay,
2902
2932
  settings.timeout,
2903
- settings.flowControl ?? settings.workflow.options.flowControl
2933
+ settings.flowControl ?? settings.workflow.options.flowControl,
2934
+ settings.stringifyBody ?? true
2904
2935
  );
2905
2936
  } else {
2906
2937
  const {
@@ -2911,7 +2942,8 @@ var WorkflowContext = class {
2911
2942
  retries = 0,
2912
2943
  retryDelay,
2913
2944
  timeout,
2914
- flowControl
2945
+ flowControl,
2946
+ stringifyBody = true
2915
2947
  } = settings;
2916
2948
  callStep = new LazyCallStep(
2917
2949
  stepName,
@@ -2922,7 +2954,8 @@ var WorkflowContext = class {
2922
2954
  retries,
2923
2955
  retryDelay,
2924
2956
  timeout,
2925
- flowControl
2957
+ flowControl,
2958
+ stringifyBody
2926
2959
  );
2927
2960
  }
2928
2961
  return await this.addStep(callStep);
@@ -3286,11 +3319,15 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3286
3319
  const { status, header, body, url, sourceBody, workflowRunId } = JSON.parse(requestPayload);
3287
3320
  const decodedBody = body ? decodeBase64(body) : "{}";
3288
3321
  let errorMessage = "";
3322
+ let failStack = "";
3289
3323
  try {
3290
3324
  const errorPayload = JSON.parse(decodedBody);
3291
3325
  if (errorPayload.message) {
3292
3326
  errorMessage = errorPayload.message;
3293
3327
  }
3328
+ if (errorPayload.stack) {
3329
+ failStack = errorPayload.stack;
3330
+ }
3294
3331
  } catch {
3295
3332
  }
3296
3333
  if (!errorMessage) {
@@ -3328,7 +3365,8 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3328
3365
  context: workflowContext,
3329
3366
  failStatus: status,
3330
3367
  failResponse: errorMessage,
3331
- failHeaders: header
3368
+ failHeaders: header,
3369
+ failStack
3332
3370
  });
3333
3371
  return ok({ result: "is-failure-callback", response: failureResponse });
3334
3372
  } catch (error) {
@@ -3345,7 +3383,7 @@ var processOptions = (options) => {
3345
3383
  environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
3346
3384
  );
3347
3385
  return {
3348
- qstashClient: new import_qstash11.Client({
3386
+ qstashClient: options?.qstashClient ?? new import_qstash11.Client({
3349
3387
  baseUrl: environment.QSTASH_URL,
3350
3388
  token: environment.QSTASH_TOKEN
3351
3389
  }),
package/svelte.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-EHL7SSJF.mjs";
5
+ } from "./chunk-LZGX3WMF.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var telemetry = {
@@ -1286,6 +1286,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1286
1286
  failStatus: number;
1287
1287
  failResponse: string;
1288
1288
  failHeaders: Record<string, string[]>;
1289
+ failStack: string;
1289
1290
  }) => Promise<void | string> | void | string;
1290
1291
  /**
1291
1292
  * Base Url of the workflow endpoint
@@ -1403,6 +1404,10 @@ type FailureFunctionPayload = {
1403
1404
  * error message
1404
1405
  */
1405
1406
  message: string;
1407
+ /**
1408
+ * error stack trace if available
1409
+ */
1410
+ stack?: string;
1406
1411
  };
1407
1412
  /**
1408
1413
  * Makes all fields except the ones selected required
@@ -1476,15 +1481,29 @@ interface WaitEventOptions {
1476
1481
  */
1477
1482
  timeout?: number | Duration;
1478
1483
  }
1484
+ type StringifyBody<TBody = unknown> = TBody extends string ? boolean : true;
1479
1485
  type CallSettings<TBody = unknown> = {
1480
1486
  url: string;
1481
1487
  method?: HTTPMethods$1;
1488
+ /**
1489
+ * Request body.
1490
+ *
1491
+ * By default, the body is stringified with `JSON.stringify`. If you want
1492
+ * to send a string body without stringifying it, you need to set
1493
+ * `stringifyBody` to false.
1494
+ */
1482
1495
  body?: TBody;
1483
1496
  headers?: Record<string, string>;
1484
1497
  retries?: number;
1485
1498
  retryDelay?: string;
1486
1499
  timeout?: Duration | number;
1487
1500
  flowControl?: FlowControl;
1501
+ /**
1502
+ * Whether the body field should be stringified when making the request.
1503
+ *
1504
+ * @default true
1505
+ */
1506
+ stringifyBody?: StringifyBody<TBody>;
1488
1507
  };
1489
1508
  type HeaderParams = {
1490
1509
  /**
@@ -1597,7 +1616,7 @@ type LazyInvokeStepParams<TInitiaPayload, TResult> = {
1597
1616
  workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult>, "routeFunction" | "workflowId" | "options">;
1598
1617
  body: TInitiaPayload;
1599
1618
  workflowRunId?: string;
1600
- } & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay">;
1619
+ } & Pick<CallSettings<TInitiaPayload>, "retries" | "headers" | "flowControl" | "retryDelay" | "stringifyBody">;
1601
1620
  type InvokeStepResponse<TBody> = {
1602
1621
  body: TBody;
1603
1622
  isCanceled?: boolean;
@@ -1609,4 +1628,4 @@ type InvokableWorkflow<TInitialPayload, TResult> = {
1609
1628
  workflowId?: string;
1610
1629
  };
1611
1630
 
1612
- export { type AsyncStepFunction as A, WorkflowLogger as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type Duration as t, type WaitEventOptions as u, type CallSettings as v, type InvokeStepResponse as w, type InvokableWorkflow as x, type LogLevel as y, type WorkflowLoggerOptions as z };
1631
+ export { type AsyncStepFunction as A, type WorkflowLoggerOptions as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, WorkflowLogger as G, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type Duration as t, type WaitEventOptions as u, type StringifyBody as v, type CallSettings as w, type InvokeStepResponse as x, type InvokableWorkflow as y, type LogLevel as z };
@@ -1286,6 +1286,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
1286
1286
  failStatus: number;
1287
1287
  failResponse: string;
1288
1288
  failHeaders: Record<string, string[]>;
1289
+ failStack: string;
1289
1290
  }) => Promise<void | string> | void | string;
1290
1291
  /**
1291
1292
  * Base Url of the workflow endpoint
@@ -1403,6 +1404,10 @@ type FailureFunctionPayload = {
1403
1404
  * error message
1404
1405
  */
1405
1406
  message: string;
1407
+ /**
1408
+ * error stack trace if available
1409
+ */
1410
+ stack?: string;
1406
1411
  };
1407
1412
  /**
1408
1413
  * Makes all fields except the ones selected required
@@ -1476,15 +1481,29 @@ interface WaitEventOptions {
1476
1481
  */
1477
1482
  timeout?: number | Duration;
1478
1483
  }
1484
+ type StringifyBody<TBody = unknown> = TBody extends string ? boolean : true;
1479
1485
  type CallSettings<TBody = unknown> = {
1480
1486
  url: string;
1481
1487
  method?: HTTPMethods$1;
1488
+ /**
1489
+ * Request body.
1490
+ *
1491
+ * By default, the body is stringified with `JSON.stringify`. If you want
1492
+ * to send a string body without stringifying it, you need to set
1493
+ * `stringifyBody` to false.
1494
+ */
1482
1495
  body?: TBody;
1483
1496
  headers?: Record<string, string>;
1484
1497
  retries?: number;
1485
1498
  retryDelay?: string;
1486
1499
  timeout?: Duration | number;
1487
1500
  flowControl?: FlowControl;
1501
+ /**
1502
+ * Whether the body field should be stringified when making the request.
1503
+ *
1504
+ * @default true
1505
+ */
1506
+ stringifyBody?: StringifyBody<TBody>;
1488
1507
  };
1489
1508
  type HeaderParams = {
1490
1509
  /**
@@ -1597,7 +1616,7 @@ type LazyInvokeStepParams<TInitiaPayload, TResult> = {
1597
1616
  workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult>, "routeFunction" | "workflowId" | "options">;
1598
1617
  body: TInitiaPayload;
1599
1618
  workflowRunId?: string;
1600
- } & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay">;
1619
+ } & Pick<CallSettings<TInitiaPayload>, "retries" | "headers" | "flowControl" | "retryDelay" | "stringifyBody">;
1601
1620
  type InvokeStepResponse<TBody> = {
1602
1621
  body: TBody;
1603
1622
  isCanceled?: boolean;
@@ -1609,4 +1628,4 @@ type InvokableWorkflow<TInitialPayload, TResult> = {
1609
1628
  workflowId?: string;
1610
1629
  };
1611
1630
 
1612
- export { type AsyncStepFunction as A, WorkflowLogger as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type Duration as t, type WaitEventOptions as u, type CallSettings as v, type InvokeStepResponse as w, type InvokableWorkflow as x, type LogLevel as y, type WorkflowLoggerOptions as z };
1631
+ export { type AsyncStepFunction as A, type WorkflowLoggerOptions as B, type CallResponse as C, type DetailedFinishCondition as D, type ExclusiveValidationOptions as E, type FinishCondition as F, WorkflowLogger as G, type HeaderParams as H, type InvokeWorkflowRequest as I, type LazyInvokeStepParams as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type StepType as S, type Telemetry as T, type WorkflowServeOptions as W, type RawStep as a, type Waiter as b, WorkflowError as c, WorkflowAbort as d, WorkflowNonRetryableError as e, WorkflowTool as f, WorkflowContext as g, type WorkflowClient as h, type WorkflowReceiver as i, StepTypes as j, type Step as k, type SyncStepFunction as l, type StepFunction as m, type PublicServeOptions as n, type FailureFunctionPayload as o, type RequiredExceptFields as p, type WaitRequest as q, type WaitStepResponse as r, type NotifyStepResponse as s, type Duration as t, type WaitEventOptions as u, type StringifyBody as v, type CallSettings as w, type InvokeStepResponse as x, type InvokableWorkflow as y, type LogLevel as z };