@upstash/workflow 0.2.22 → 0.2.23

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/tanstack.js CHANGED
@@ -199,8 +199,8 @@ var NANOID_LENGTH = 21;
199
199
  function getRandomInt() {
200
200
  return Math.floor(Math.random() * NANOID_CHARS.length);
201
201
  }
202
- function nanoid() {
203
- return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
202
+ function nanoid(length = NANOID_LENGTH) {
203
+ return Array.from({ length }).map(() => NANOID_CHARS[getRandomInt()]).join("");
204
204
  }
205
205
  function getWorkflowRunId(id) {
206
206
  return `wfr_${id ?? nanoid()}`;
@@ -217,6 +217,37 @@ function decodeBase64(base64) {
217
217
  return binString;
218
218
  }
219
219
  }
220
+ function getUserIdFromToken(qstashClient) {
221
+ try {
222
+ const token = qstashClient.token;
223
+ const decodedToken = decodeBase64(token);
224
+ const tokenPayload = JSON.parse(decodedToken);
225
+ const userId = tokenPayload.UserID;
226
+ if (!userId) {
227
+ throw new WorkflowError("QStash token payload does not contain userId");
228
+ }
229
+ return userId;
230
+ } catch (error) {
231
+ throw new WorkflowError(
232
+ `Failed to decode QStash token while running create webhook step: ${error.message}`
233
+ );
234
+ }
235
+ }
236
+ function getQStashUrl(qstashClient) {
237
+ try {
238
+ const requester = qstashClient.http;
239
+ const baseUrl = requester.baseUrl;
240
+ if (!baseUrl) {
241
+ throw new WorkflowError("QStash client does not have a baseUrl");
242
+ }
243
+ return baseUrl;
244
+ } catch (error) {
245
+ throw new WorkflowError(`Failed to get QStash URL from client: ${error.message}`);
246
+ }
247
+ }
248
+ function getEventId() {
249
+ return `evt_${nanoid(15)}`;
250
+ }
220
251
 
221
252
  // node_modules/neverthrow/dist/index.es.js
222
253
  var defaultErrorConfig = {
@@ -642,7 +673,9 @@ var StepTypes = [
642
673
  "Call",
643
674
  "Wait",
644
675
  "Notify",
645
- "Invoke"
676
+ "Invoke",
677
+ "CreateWebhook",
678
+ "WaitForWebhook"
646
679
  ];
647
680
 
648
681
  // src/workflow-requests.ts
@@ -954,7 +987,9 @@ If you want to disable QStash Verification, you should clear env variables QSTAS
954
987
  // src/context/steps.ts
955
988
  var BaseLazyStep = class _BaseLazyStep {
956
989
  stepName;
957
- constructor(stepName) {
990
+ context;
991
+ constructor(context, stepName) {
992
+ this.context = context;
958
993
  if (!stepName) {
959
994
  throw new WorkflowError(
960
995
  "A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
@@ -972,13 +1007,14 @@ var BaseLazyStep = class _BaseLazyStep {
972
1007
  *
973
1008
  * will be called when returning the steps to the context from auto executor
974
1009
  *
975
- * @param out field of the step
1010
+ * @param step step
976
1011
  * @returns parsed out field
977
1012
  */
978
- parseOut(out) {
1013
+ parseOut(step) {
1014
+ const out = step.out;
979
1015
  if (out === void 0) {
980
1016
  if (this.allowUndefinedOut) {
981
- return void 0;
1017
+ return this.handleUndefinedOut(step);
982
1018
  } else {
983
1019
  throw new WorkflowError(
984
1020
  `Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
@@ -986,27 +1022,26 @@ var BaseLazyStep = class _BaseLazyStep {
986
1022
  }
987
1023
  }
988
1024
  if (typeof out === "object") {
989
- if (this.stepType !== "Wait") {
990
- console.warn(
991
- `Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
992
- );
993
- return out;
994
- }
995
- return {
996
- ...out,
997
- eventData: _BaseLazyStep.tryParsing(out.eventData)
998
- };
1025
+ console.warn(
1026
+ `Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
1027
+ );
1028
+ return out;
999
1029
  }
1000
1030
  if (typeof out !== "string") {
1001
1031
  throw new WorkflowError(
1002
1032
  `Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
1003
1033
  );
1004
1034
  }
1005
- return this.safeParseOut(out);
1035
+ return this.safeParseOut(out, step);
1006
1036
  }
1007
- safeParseOut(out) {
1037
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1038
+ safeParseOut(out, step) {
1008
1039
  return _BaseLazyStep.tryParsing(out);
1009
1040
  }
1041
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1042
+ handleUndefinedOut(step) {
1043
+ return void 0;
1044
+ }
1010
1045
  static tryParsing(stepOut) {
1011
1046
  try {
1012
1047
  return JSON.parse(stepOut);
@@ -1057,8 +1092,8 @@ var LazyFunctionStep = class extends BaseLazyStep {
1057
1092
  stepFunction;
1058
1093
  stepType = "Run";
1059
1094
  allowUndefinedOut = true;
1060
- constructor(stepName, stepFunction) {
1061
- super(stepName);
1095
+ constructor(context, stepName, stepFunction) {
1096
+ super(context, stepName);
1062
1097
  this.stepFunction = stepFunction;
1063
1098
  }
1064
1099
  getPlanStep(concurrent, targetStep) {
@@ -1088,8 +1123,8 @@ var LazySleepStep = class extends BaseLazyStep {
1088
1123
  sleep;
1089
1124
  stepType = "SleepFor";
1090
1125
  allowUndefinedOut = true;
1091
- constructor(stepName, sleep) {
1092
- super(stepName);
1126
+ constructor(context, stepName, sleep) {
1127
+ super(context, stepName);
1093
1128
  this.sleep = sleep;
1094
1129
  }
1095
1130
  getPlanStep(concurrent, targetStep) {
@@ -1130,8 +1165,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
1130
1165
  sleepUntil;
1131
1166
  stepType = "SleepUntil";
1132
1167
  allowUndefinedOut = true;
1133
- constructor(stepName, sleepUntil) {
1134
- super(stepName);
1168
+ constructor(context, stepName, sleepUntil) {
1169
+ super(context, stepName);
1135
1170
  this.sleepUntil = sleepUntil;
1136
1171
  }
1137
1172
  getPlanStep(concurrent, targetStep) {
@@ -1183,8 +1218,8 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1183
1218
  stringifyBody;
1184
1219
  stepType = "Call";
1185
1220
  allowUndefinedOut = false;
1186
- constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl, stringifyBody) {
1187
- super(stepName);
1221
+ constructor(context, stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl, stringifyBody) {
1222
+ super(context, stepName);
1188
1223
  this.url = url;
1189
1224
  this.method = method;
1190
1225
  this.body = body;
@@ -1328,13 +1363,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
1328
1363
  ]);
1329
1364
  }
1330
1365
  };
1331
- var LazyWaitForEventStep = class extends BaseLazyStep {
1366
+ var LazyWaitEventStep = class extends BaseLazyStep {
1332
1367
  eventId;
1333
1368
  timeout;
1334
- stepType = "Wait";
1335
1369
  allowUndefinedOut = false;
1336
- constructor(stepName, eventId, timeout) {
1337
- super(stepName);
1370
+ constructor(context, stepName, eventId, timeout) {
1371
+ super(context, stepName);
1338
1372
  this.eventId = eventId;
1339
1373
  this.timeout = timeout;
1340
1374
  }
@@ -1359,13 +1393,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
1359
1393
  concurrent
1360
1394
  });
1361
1395
  }
1362
- safeParseOut(out) {
1363
- const result = JSON.parse(out);
1364
- return {
1365
- ...result,
1366
- eventData: BaseLazyStep.tryParsing(result.eventData)
1367
- };
1368
- }
1369
1396
  getHeaders({ context, telemetry: telemetry2, invokeCount, step }) {
1370
1397
  const headers = super.getHeaders({ context, telemetry: telemetry2, invokeCount, step });
1371
1398
  headers.headers["Upstash-Workflow-CallType"] = "step";
@@ -1399,7 +1426,7 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
1399
1426
  timeoutHeaders,
1400
1427
  step: {
1401
1428
  stepId: step.stepId,
1402
- stepType: "Wait",
1429
+ stepType: this.stepType,
1403
1430
  stepName: step.stepName,
1404
1431
  concurrent: step.concurrent,
1405
1432
  targetStep: step.targetStep
@@ -1420,8 +1447,8 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
1420
1447
  };
1421
1448
  var LazyNotifyStep = class extends LazyFunctionStep {
1422
1449
  stepType = "Notify";
1423
- constructor(stepName, eventId, eventData, requester) {
1424
- super(stepName, async () => {
1450
+ constructor(context, stepName, eventId, eventData, requester) {
1451
+ super(context, stepName, async () => {
1425
1452
  const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
1426
1453
  return {
1427
1454
  eventId,
@@ -1446,7 +1473,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1446
1473
  * workflow id of the invoked workflow
1447
1474
  */
1448
1475
  workflowId;
1449
- constructor(stepName, {
1476
+ constructor(context, stepName, {
1450
1477
  workflow,
1451
1478
  body,
1452
1479
  headers = {},
@@ -1456,7 +1483,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
1456
1483
  flowControl,
1457
1484
  stringifyBody = true
1458
1485
  }) {
1459
- super(stepName);
1486
+ super(context, stepName);
1460
1487
  this.params = {
1461
1488
  workflow,
1462
1489
  body,
@@ -1517,6 +1544,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
1517
1544
  userHeaders: context.headers,
1518
1545
  invokeCount
1519
1546
  });
1547
+ context.qstashClient.http.headers?.forEach((value, key) => {
1548
+ invokerHeaders[key] = value;
1549
+ });
1520
1550
  invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
1521
1551
  let invokeBody;
1522
1552
  if (this.params.stringifyBody) {
@@ -1588,6 +1618,88 @@ var LazyInvokeStep = class extends BaseLazyStep {
1588
1618
  return [result];
1589
1619
  }
1590
1620
  };
1621
+ var LazyCreateWebhookStep = class extends BaseLazyStep {
1622
+ stepType = "CreateWebhook";
1623
+ allowUndefinedOut = false;
1624
+ getPlanStep(concurrent, targetStep) {
1625
+ return {
1626
+ stepId: 0,
1627
+ stepName: this.stepName,
1628
+ stepType: this.stepType,
1629
+ concurrent,
1630
+ targetStep
1631
+ };
1632
+ }
1633
+ async getResultStep(concurrent, stepId) {
1634
+ return {
1635
+ stepId,
1636
+ stepName: this.stepName,
1637
+ stepType: this.stepType,
1638
+ out: void 0,
1639
+ concurrent
1640
+ };
1641
+ }
1642
+ getBody({ step, context }) {
1643
+ const userId = getUserIdFromToken(context.qstashClient);
1644
+ const workflowRunId = context.workflowRunId;
1645
+ const eventId = getEventId();
1646
+ const qstashUrl = getQStashUrl(this.context.qstashClient);
1647
+ return JSON.stringify({
1648
+ ...step,
1649
+ out: JSON.stringify({
1650
+ webhookUrl: `${qstashUrl}/v2/workflows/hooks/${userId}/${workflowRunId}/${eventId}`,
1651
+ eventId
1652
+ })
1653
+ });
1654
+ }
1655
+ };
1656
+ var LazyWaitForWebhookStep = class extends LazyWaitEventStep {
1657
+ stepType = "WaitForWebhook";
1658
+ allowUndefinedOut = true;
1659
+ constructor(context, stepName, webhook, timeout) {
1660
+ super(context, stepName, webhook.eventId, timeout);
1661
+ }
1662
+ safeParseOut(out) {
1663
+ const eventData = decodeBase64(out);
1664
+ const parsedEventData = BaseLazyStep.tryParsing(eventData);
1665
+ const body = parsedEventData.body;
1666
+ const parsedBody = typeof body === "string" ? decodeBase64(body) : void 0;
1667
+ const request = new Request(
1668
+ `${parsedEventData.proto}://${parsedEventData.host}${parsedEventData.url}`,
1669
+ {
1670
+ method: parsedEventData.method,
1671
+ headers: parsedEventData.header,
1672
+ body: parsedBody
1673
+ }
1674
+ );
1675
+ return {
1676
+ request,
1677
+ timeout: false
1678
+ };
1679
+ }
1680
+ handleUndefinedOut() {
1681
+ return {
1682
+ timeout: true,
1683
+ request: void 0
1684
+ };
1685
+ }
1686
+ };
1687
+ var LazyWaitForEventStep = class extends LazyWaitEventStep {
1688
+ stepType = "Wait";
1689
+ allowUndefinedOut = true;
1690
+ parseWaitForEventOut(out, waitTimeout) {
1691
+ return {
1692
+ eventData: out ? BaseLazyStep.tryParsing(decodeBase64(out)) : void 0,
1693
+ timeout: waitTimeout ?? false
1694
+ };
1695
+ }
1696
+ safeParseOut(out, step) {
1697
+ return this.parseWaitForEventOut(out, step.waitTimeout);
1698
+ }
1699
+ handleUndefinedOut(step) {
1700
+ return this.parseWaitForEventOut(void 0, step.waitTimeout);
1701
+ }
1702
+ };
1591
1703
 
1592
1704
  // src/agents/constants.ts
1593
1705
  var AGENT_NAME_HEADER = "upstash-agent-name";
@@ -1992,7 +2104,7 @@ var AutoExecutor = class _AutoExecutor {
1992
2104
  step,
1993
2105
  stepCount: this.stepCount
1994
2106
  });
1995
- return lazyStep.parseOut(step.out);
2107
+ return lazyStep.parseOut(step);
1996
2108
  }
1997
2109
  const resultStep = await submitSingleStep({
1998
2110
  context: this.context,
@@ -2079,7 +2191,7 @@ var AutoExecutor = class _AutoExecutor {
2079
2191
  const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
2080
2192
  validateParallelSteps(parallelSteps, parallelResultSteps);
2081
2193
  return parallelResultSteps.map(
2082
- (step, index) => parallelSteps[index].parseOut(step.out)
2194
+ (step, index) => parallelSteps[index].parseOut(step)
2083
2195
  );
2084
2196
  }
2085
2197
  }
@@ -2135,7 +2247,6 @@ var AutoExecutor = class _AutoExecutor {
2135
2247
  * @param index index of the current step
2136
2248
  * @returns result[index] if lazyStepList > 1, otherwise result
2137
2249
  */
2138
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
2139
2250
  static getResult(lazyStepList, result, index) {
2140
2251
  if (lazyStepList.length === 1) {
2141
2252
  return result;
@@ -2927,7 +3038,7 @@ var WorkflowContext = class {
2927
3038
  */
2928
3039
  async run(stepName, stepFunction) {
2929
3040
  const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2930
- return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
3041
+ return await this.addStep(new LazyFunctionStep(this, stepName, wrappedStepFunction));
2931
3042
  }
2932
3043
  /**
2933
3044
  * Stops the execution for the duration provided.
@@ -2941,7 +3052,7 @@ var WorkflowContext = class {
2941
3052
  * @returns undefined
2942
3053
  */
2943
3054
  async sleep(stepName, duration) {
2944
- await this.addStep(new LazySleepStep(stepName, duration));
3055
+ await this.addStep(new LazySleepStep(this, stepName, duration));
2945
3056
  }
2946
3057
  /**
2947
3058
  * Stops the execution until the date time provided.
@@ -2963,13 +3074,14 @@ var WorkflowContext = class {
2963
3074
  datetime = typeof datetime === "string" ? new Date(datetime) : datetime;
2964
3075
  time = Math.round(datetime.getTime() / 1e3);
2965
3076
  }
2966
- await this.addStep(new LazySleepUntilStep(stepName, time));
3077
+ await this.addStep(new LazySleepUntilStep(this, stepName, time));
2967
3078
  }
2968
3079
  async call(stepName, settings) {
2969
3080
  let callStep;
2970
3081
  if ("workflow" in settings) {
2971
3082
  const url = getNewUrlFromWorkflowId(this.url, settings.workflow.workflowId);
2972
3083
  callStep = new LazyCallStep(
3084
+ this,
2973
3085
  stepName,
2974
3086
  url,
2975
3087
  "POST",
@@ -2994,6 +3106,7 @@ var WorkflowContext = class {
2994
3106
  stringifyBody = true
2995
3107
  } = settings;
2996
3108
  callStep = new LazyCallStep(
3109
+ this,
2997
3110
  stepName,
2998
3111
  url,
2999
3112
  method,
@@ -3045,7 +3158,9 @@ var WorkflowContext = class {
3045
3158
  async waitForEvent(stepName, eventId, options = {}) {
3046
3159
  const { timeout = "7d" } = options;
3047
3160
  const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
3048
- return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
3161
+ return await this.addStep(
3162
+ new LazyWaitForEventStep(this, stepName, eventId, timeoutStr)
3163
+ );
3049
3164
  }
3050
3165
  /**
3051
3166
  * Notify workflow runs waiting for an event
@@ -3070,11 +3185,19 @@ var WorkflowContext = class {
3070
3185
  */
3071
3186
  async notify(stepName, eventId, eventData) {
3072
3187
  return await this.addStep(
3073
- new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
3188
+ new LazyNotifyStep(this, stepName, eventId, eventData, this.qstashClient.http)
3074
3189
  );
3075
3190
  }
3076
3191
  async invoke(stepName, settings) {
3077
- return await this.addStep(new LazyInvokeStep(stepName, settings));
3192
+ return await this.addStep(
3193
+ new LazyInvokeStep(this, stepName, settings)
3194
+ );
3195
+ }
3196
+ async createWebhook(stepName) {
3197
+ return await this.addStep(new LazyCreateWebhookStep(this, stepName));
3198
+ }
3199
+ async waitForWebhook(stepName, webhook, timeout) {
3200
+ return await this.addStep(new LazyWaitForWebhookStep(this, stepName, webhook, timeout));
3078
3201
  }
3079
3202
  /**
3080
3203
  * Cancel the current workflow run
@@ -3238,13 +3361,6 @@ var processRawSteps = (rawSteps) => {
3238
3361
  const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
3239
3362
  const otherSteps = stepsToDecode.map((rawStep) => {
3240
3363
  const step = JSON.parse(decodeBase64(rawStep.body));
3241
- if (step.waitEventId) {
3242
- const newOut = {
3243
- eventData: step.out ? decodeBase64(step.out) : void 0,
3244
- timeout: step.waitTimeout ?? false
3245
- };
3246
- step.out = newOut;
3247
- }
3248
3364
  return step;
3249
3365
  });
3250
3366
  const steps = [initialStep, ...otherSteps];
package/tanstack.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-BON2RKOR.mjs";
5
+ } from "./chunk-GZRDB6Z5.mjs";
6
6
 
7
7
  // platforms/tanstack.ts
8
8
  var telemetry = {
@@ -97,7 +97,8 @@ declare abstract class BaseLazyStep<TResult = unknown> {
97
97
  readonly stepName: string;
98
98
  abstract readonly stepType: StepType;
99
99
  protected abstract readonly allowUndefinedOut: boolean;
100
- constructor(stepName: string);
100
+ protected readonly context: WorkflowContext;
101
+ constructor(context: WorkflowContext, stepName: string);
101
102
  /**
102
103
  * plan step to submit when step will run parallel with other
103
104
  * steps (parallel call state `first`)
@@ -120,11 +121,12 @@ declare abstract class BaseLazyStep<TResult = unknown> {
120
121
  *
121
122
  * will be called when returning the steps to the context from auto executor
122
123
  *
123
- * @param out field of the step
124
+ * @param step step
124
125
  * @returns parsed out field
125
126
  */
126
- parseOut(out: unknown): TResult;
127
- protected safeParseOut(out: string): TResult;
127
+ parseOut(step: Step): TResult;
128
+ protected safeParseOut(out: string, step: Step): TResult;
129
+ protected handleUndefinedOut(step: Step): TResult;
128
130
  protected static tryParsing(stepOut: unknown): any;
129
131
  getBody({ step }: GetBodyParams): string;
130
132
  getHeaders({ context, telemetry, invokeCount, step }: GetHeaderParams): HeadersResponse;
@@ -132,6 +134,17 @@ declare abstract class BaseLazyStep<TResult = unknown> {
132
134
  messageId: string;
133
135
  }[]>;
134
136
  }
137
+ type Webhook = {
138
+ webhookUrl: string;
139
+ eventId: string;
140
+ };
141
+ type WaitForWebhookResponse = {
142
+ timeout: false;
143
+ request: Request;
144
+ } | {
145
+ timeout: true;
146
+ request: undefined;
147
+ };
135
148
 
136
149
  declare class AutoExecutor {
137
150
  private context;
@@ -1104,6 +1117,8 @@ declare class WorkflowContext<TInitialPayload = unknown> {
1104
1117
  */
1105
1118
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
1106
1119
  invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
1120
+ createWebhook(stepName: string): Promise<Webhook>;
1121
+ waitForWebhook(stepName: string, webhook: Webhook, timeout: Duration): Promise<WaitForWebhookResponse>;
1107
1122
  /**
1108
1123
  * Cancel the current workflow run
1109
1124
  *
@@ -1140,7 +1155,7 @@ type WorkflowClient = {
1140
1155
  type WorkflowReceiver = {
1141
1156
  verify: InstanceType<typeof Receiver>["verify"];
1142
1157
  };
1143
- declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke"];
1158
+ declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke", "CreateWebhook", "WaitForWebhook"];
1144
1159
  type StepType = (typeof StepTypes)[number];
1145
1160
  type ThirdPartyCallFields<TBody = unknown> = {
1146
1161
  /**
@@ -97,7 +97,8 @@ declare abstract class BaseLazyStep<TResult = unknown> {
97
97
  readonly stepName: string;
98
98
  abstract readonly stepType: StepType;
99
99
  protected abstract readonly allowUndefinedOut: boolean;
100
- constructor(stepName: string);
100
+ protected readonly context: WorkflowContext;
101
+ constructor(context: WorkflowContext, stepName: string);
101
102
  /**
102
103
  * plan step to submit when step will run parallel with other
103
104
  * steps (parallel call state `first`)
@@ -120,11 +121,12 @@ declare abstract class BaseLazyStep<TResult = unknown> {
120
121
  *
121
122
  * will be called when returning the steps to the context from auto executor
122
123
  *
123
- * @param out field of the step
124
+ * @param step step
124
125
  * @returns parsed out field
125
126
  */
126
- parseOut(out: unknown): TResult;
127
- protected safeParseOut(out: string): TResult;
127
+ parseOut(step: Step): TResult;
128
+ protected safeParseOut(out: string, step: Step): TResult;
129
+ protected handleUndefinedOut(step: Step): TResult;
128
130
  protected static tryParsing(stepOut: unknown): any;
129
131
  getBody({ step }: GetBodyParams): string;
130
132
  getHeaders({ context, telemetry, invokeCount, step }: GetHeaderParams): HeadersResponse;
@@ -132,6 +134,17 @@ declare abstract class BaseLazyStep<TResult = unknown> {
132
134
  messageId: string;
133
135
  }[]>;
134
136
  }
137
+ type Webhook = {
138
+ webhookUrl: string;
139
+ eventId: string;
140
+ };
141
+ type WaitForWebhookResponse = {
142
+ timeout: false;
143
+ request: Request;
144
+ } | {
145
+ timeout: true;
146
+ request: undefined;
147
+ };
135
148
 
136
149
  declare class AutoExecutor {
137
150
  private context;
@@ -1104,6 +1117,8 @@ declare class WorkflowContext<TInitialPayload = unknown> {
1104
1117
  */
1105
1118
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
1106
1119
  invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
1120
+ createWebhook(stepName: string): Promise<Webhook>;
1121
+ waitForWebhook(stepName: string, webhook: Webhook, timeout: Duration): Promise<WaitForWebhookResponse>;
1107
1122
  /**
1108
1123
  * Cancel the current workflow run
1109
1124
  *
@@ -1140,7 +1155,7 @@ type WorkflowClient = {
1140
1155
  type WorkflowReceiver = {
1141
1156
  verify: InstanceType<typeof Receiver>["verify"];
1142
1157
  };
1143
- declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke"];
1158
+ declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke", "CreateWebhook", "WaitForWebhook"];
1144
1159
  type StepType = (typeof StepTypes)[number];
1145
1160
  type ThirdPartyCallFields<TBody = unknown> = {
1146
1161
  /**