@upstash/workflow 0.2.2 → 0.2.4

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/nextjs.js CHANGED
@@ -78,6 +78,23 @@ var getSteps = async (requester, workflowRunId, messageId, debug) => {
78
78
  }
79
79
  };
80
80
 
81
+ // src/constants.ts
82
+ var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
83
+ var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
84
+ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
85
+ var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
86
+ var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
87
+ var WORKFLOW_PROTOCOL_VERSION = "1";
88
+ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
89
+ var DEFAULT_CONTENT_TYPE = "application/json";
90
+ var NO_CONCURRENCY = 1;
91
+ var DEFAULT_RETRIES = 3;
92
+ var VERSION = "v0.2.3";
93
+ var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
94
+ var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
95
+ var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
96
+ var TELEMETRY_HEADER_RUNTIME = "Upstash-Telemetry-Runtime";
97
+
81
98
  // src/error.ts
82
99
  var import_qstash2 = require("@upstash/qstash");
83
100
  var WorkflowError = class extends import_qstash2.QstashError {
@@ -715,18 +732,6 @@ var Err = class {
715
732
  };
716
733
  var fromThrowable = Result.fromThrowable;
717
734
 
718
- // src/constants.ts
719
- var WORKFLOW_ID_HEADER = "Upstash-Workflow-RunId";
720
- var WORKFLOW_INIT_HEADER = "Upstash-Workflow-Init";
721
- var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
722
- var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
723
- var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
724
- var WORKFLOW_PROTOCOL_VERSION = "1";
725
- var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
726
- var DEFAULT_CONTENT_TYPE = "application/json";
727
- var NO_CONCURRENCY = 1;
728
- var DEFAULT_RETRIES = 3;
729
-
730
735
  // src/types.ts
731
736
  var StepTypes = [
732
737
  "Initial",
@@ -740,16 +745,21 @@ var StepTypes = [
740
745
 
741
746
  // src/workflow-requests.ts
742
747
  var import_qstash3 = require("@upstash/qstash");
743
- var triggerFirstInvocation = async (workflowContext, retries, useJSONContent, debug) => {
744
- const { headers } = getHeaders(
745
- "true",
746
- workflowContext.workflowRunId,
747
- workflowContext.url,
748
- workflowContext.headers,
749
- void 0,
750
- workflowContext.failureUrl,
751
- retries
752
- );
748
+ var triggerFirstInvocation = async ({
749
+ workflowContext,
750
+ useJSONContent,
751
+ telemetry,
752
+ debug
753
+ }) => {
754
+ const { headers } = getHeaders({
755
+ initHeaderValue: "true",
756
+ workflowRunId: workflowContext.workflowRunId,
757
+ workflowUrl: workflowContext.url,
758
+ userHeaders: workflowContext.headers,
759
+ failureUrl: workflowContext.failureUrl,
760
+ retries: workflowContext.retries,
761
+ telemetry
762
+ });
753
763
  if (useJSONContent) {
754
764
  headers["content-type"] = "application/json";
755
765
  }
@@ -855,7 +865,16 @@ var recreateUserHeaders = (headers) => {
855
865
  }
856
866
  return filteredHeaders;
857
867
  };
858
- var handleThirdPartyCallResult = async (request, requestPayload, client, workflowUrl, failureUrl, retries, debug) => {
868
+ var handleThirdPartyCallResult = async ({
869
+ request,
870
+ requestPayload,
871
+ client,
872
+ workflowUrl,
873
+ failureUrl,
874
+ retries,
875
+ telemetry,
876
+ debug
877
+ }) => {
859
878
  try {
860
879
  if (request.headers.get("Upstash-Workflow-Callback")) {
861
880
  let callbackPayload;
@@ -914,15 +933,15 @@ ${atob(callbackMessage.body ?? "")}`
914
933
  );
915
934
  }
916
935
  const userHeaders = recreateUserHeaders(request.headers);
917
- const { headers: requestHeaders } = getHeaders(
918
- "false",
936
+ const { headers: requestHeaders } = getHeaders({
937
+ initHeaderValue: "false",
919
938
  workflowRunId,
920
939
  workflowUrl,
921
940
  userHeaders,
922
- void 0,
923
941
  failureUrl,
924
- retries
925
- );
942
+ retries,
943
+ telemetry
944
+ });
926
945
  const callResponse = {
927
946
  status: callbackMessage.status,
928
947
  body: atob(callbackMessage.body ?? ""),
@@ -960,12 +979,31 @@ ${atob(callbackMessage.body ?? "")}`
960
979
  );
961
980
  }
962
981
  };
963
- var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries, callTimeout) => {
982
+ var getTelemetryHeaders = (telemetry) => {
983
+ return {
984
+ [TELEMETRY_HEADER_SDK]: telemetry.sdk,
985
+ [TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
986
+ [TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
987
+ };
988
+ };
989
+ var getHeaders = ({
990
+ initHeaderValue,
991
+ workflowRunId,
992
+ workflowUrl,
993
+ userHeaders,
994
+ failureUrl,
995
+ retries,
996
+ step,
997
+ callRetries,
998
+ callTimeout,
999
+ telemetry
1000
+ }) => {
964
1001
  const baseHeaders = {
965
1002
  [WORKFLOW_INIT_HEADER]: initHeaderValue,
966
1003
  [WORKFLOW_ID_HEADER]: workflowRunId,
967
1004
  [WORKFLOW_URL_HEADER]: workflowUrl,
968
- [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody"
1005
+ [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
1006
+ ...telemetry ? getTelemetryHeaders(telemetry) : {}
969
1007
  };
970
1008
  if (!step?.callUrl) {
971
1009
  baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
@@ -1039,6 +1077,13 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
1039
1077
  ...Object.fromEntries(
1040
1078
  Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
1041
1079
  ),
1080
+ // to include telemetry headers:
1081
+ ...telemetry ? Object.fromEntries(
1082
+ Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
1083
+ header,
1084
+ [value]
1085
+ ])
1086
+ ) : {},
1042
1087
  // note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
1043
1088
  "Upstash-Workflow-Runid": [workflowRunId],
1044
1089
  [WORKFLOW_INIT_HEADER]: ["false"],
@@ -1077,6 +1122,7 @@ If you want to disable QStash Verification, you should clear env variables QSTAS
1077
1122
  };
1078
1123
 
1079
1124
  // src/context/auto-executor.ts
1125
+ var import_qstash4 = require("@upstash/qstash");
1080
1126
  var AutoExecutor = class _AutoExecutor {
1081
1127
  context;
1082
1128
  promises = /* @__PURE__ */ new WeakMap();
@@ -1085,13 +1131,15 @@ var AutoExecutor = class _AutoExecutor {
1085
1131
  nonPlanStepCount;
1086
1132
  steps;
1087
1133
  indexInCurrentList = 0;
1134
+ telemetry;
1088
1135
  stepCount = 0;
1089
1136
  planStepCount = 0;
1090
1137
  executingStep = false;
1091
- constructor(context, steps, debug) {
1138
+ constructor(context, steps, telemetry, debug) {
1092
1139
  this.context = context;
1093
- this.debug = debug;
1094
1140
  this.steps = steps;
1141
+ this.telemetry = telemetry;
1142
+ this.debug = debug;
1095
1143
  this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
1096
1144
  }
1097
1145
  /**
@@ -1234,7 +1282,7 @@ var AutoExecutor = class _AutoExecutor {
1234
1282
  );
1235
1283
  await this.submitStepsToQStash([resultStep], [parallelStep]);
1236
1284
  } catch (error) {
1237
- if (error instanceof WorkflowAbort) {
1285
+ if (error instanceof WorkflowAbort || error instanceof import_qstash4.QstashError && error.status === 400) {
1238
1286
  throw error;
1239
1287
  }
1240
1288
  throw new WorkflowError(
@@ -1305,15 +1353,16 @@ var AutoExecutor = class _AutoExecutor {
1305
1353
  });
1306
1354
  if (steps[0].waitEventId && steps.length === 1) {
1307
1355
  const waitStep = steps[0];
1308
- const { headers, timeoutHeaders } = getHeaders(
1309
- "false",
1310
- this.context.workflowRunId,
1311
- this.context.url,
1312
- this.context.headers,
1313
- waitStep,
1314
- this.context.failureUrl,
1315
- this.context.retries
1316
- );
1356
+ const { headers, timeoutHeaders } = getHeaders({
1357
+ initHeaderValue: "false",
1358
+ workflowRunId: this.context.workflowRunId,
1359
+ workflowUrl: this.context.url,
1360
+ userHeaders: this.context.headers,
1361
+ step: waitStep,
1362
+ failureUrl: this.context.failureUrl,
1363
+ retries: this.context.retries,
1364
+ telemetry: this.telemetry
1365
+ });
1317
1366
  const waitBody = {
1318
1367
  url: this.context.url,
1319
1368
  timeout: waitStep.timeout,
@@ -1340,17 +1389,18 @@ var AutoExecutor = class _AutoExecutor {
1340
1389
  const result = await this.context.qstashClient.batchJSON(
1341
1390
  steps.map((singleStep, index) => {
1342
1391
  const lazyStep = lazySteps[index];
1343
- const { headers } = getHeaders(
1344
- "false",
1345
- this.context.workflowRunId,
1346
- this.context.url,
1347
- this.context.headers,
1348
- singleStep,
1349
- this.context.failureUrl,
1350
- this.context.retries,
1351
- lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
1352
- lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0
1353
- );
1392
+ const { headers } = getHeaders({
1393
+ initHeaderValue: "false",
1394
+ workflowRunId: this.context.workflowRunId,
1395
+ workflowUrl: this.context.url,
1396
+ userHeaders: this.context.headers,
1397
+ step: singleStep,
1398
+ failureUrl: this.context.failureUrl,
1399
+ retries: this.context.retries,
1400
+ callRetries: lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
1401
+ callTimeout: lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0,
1402
+ telemetry: this.telemetry
1403
+ });
1354
1404
  const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
1355
1405
  singleStep.out = JSON.stringify(singleStep.out);
1356
1406
  return singleStep.callUrl ? (
@@ -1462,6 +1512,127 @@ var sortSteps = (steps) => {
1462
1512
  return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
1463
1513
  };
1464
1514
 
1515
+ // src/context/api/anthropic.ts
1516
+ var import_qstash5 = require("@upstash/qstash");
1517
+
1518
+ // src/context/provider.ts
1519
+ var getProviderInfo = (api) => {
1520
+ if (!api.provider) {
1521
+ throw new WorkflowError("A Provider must be provided.");
1522
+ }
1523
+ if (api.provider.owner === "upstash") {
1524
+ throw new WorkflowError("Upstash provider isn't supported.");
1525
+ }
1526
+ const { name, provider, ...parameters } = api;
1527
+ if (!provider.baseUrl) throw new TypeError("baseUrl cannot be empty or undefined!");
1528
+ if (!provider.token) throw new TypeError("token cannot be empty or undefined!");
1529
+ if (provider.apiKind !== name) {
1530
+ throw new TypeError(`Unexpected api name. Expected '${provider.apiKind}', received ${name}`);
1531
+ }
1532
+ const providerInfo = {
1533
+ url: provider.getUrl(),
1534
+ baseUrl: provider.baseUrl,
1535
+ route: provider.getRoute(),
1536
+ appendHeaders: provider.getHeaders(parameters),
1537
+ owner: provider.owner,
1538
+ method: provider.method
1539
+ };
1540
+ return provider.onFinish(providerInfo, parameters);
1541
+ };
1542
+
1543
+ // src/context/api/base.ts
1544
+ var BaseWorkflowApi = class {
1545
+ context;
1546
+ constructor({ context }) {
1547
+ this.context = context;
1548
+ }
1549
+ /**
1550
+ * context.call which uses a QStash API
1551
+ *
1552
+ * @param stepName
1553
+ * @param settings
1554
+ * @returns
1555
+ */
1556
+ async callApi(stepName, settings) {
1557
+ const { url, appendHeaders, method } = getProviderInfo(settings.api);
1558
+ const { method: userMethod, body, headers = {}, retries = 0, timeout } = settings;
1559
+ return await this.context.call(stepName, {
1560
+ url,
1561
+ method: userMethod ?? method,
1562
+ body,
1563
+ headers: {
1564
+ ...appendHeaders,
1565
+ ...headers
1566
+ },
1567
+ retries,
1568
+ timeout
1569
+ });
1570
+ }
1571
+ };
1572
+
1573
+ // src/context/api/anthropic.ts
1574
+ var AnthropicAPI = class extends BaseWorkflowApi {
1575
+ async call(stepName, settings) {
1576
+ const { token, operation, ...parameters } = settings;
1577
+ return await this.callApi(stepName, {
1578
+ api: {
1579
+ name: "llm",
1580
+ provider: (0, import_qstash5.anthropic)({ token })
1581
+ },
1582
+ ...parameters
1583
+ });
1584
+ }
1585
+ };
1586
+
1587
+ // src/context/api/openai.ts
1588
+ var import_qstash6 = require("@upstash/qstash");
1589
+ var OpenAIAPI = class extends BaseWorkflowApi {
1590
+ async call(stepName, settings) {
1591
+ const { token, organization, operation, ...parameters } = settings;
1592
+ return await this.callApi(stepName, {
1593
+ api: {
1594
+ name: "llm",
1595
+ provider: (0, import_qstash6.openai)({ token, organization })
1596
+ },
1597
+ ...parameters
1598
+ });
1599
+ }
1600
+ };
1601
+
1602
+ // src/context/api/resend.ts
1603
+ var import_qstash7 = require("@upstash/qstash");
1604
+ var ResendAPI = class extends BaseWorkflowApi {
1605
+ async call(stepName, settings) {
1606
+ const { token, batch = false, ...parameters } = settings;
1607
+ return await this.callApi(stepName, {
1608
+ api: {
1609
+ name: "email",
1610
+ provider: (0, import_qstash7.resend)({ token, batch })
1611
+ },
1612
+ ...parameters
1613
+ });
1614
+ }
1615
+ };
1616
+
1617
+ // src/context/api/index.ts
1618
+ var WorkflowApi = class extends BaseWorkflowApi {
1619
+ get openai() {
1620
+ return new OpenAIAPI({
1621
+ context: this.context
1622
+ });
1623
+ }
1624
+ get resend() {
1625
+ return new ResendAPI({
1626
+ context: this.context
1627
+ });
1628
+ }
1629
+ get anthropic() {
1630
+ return new AnthropicAPI({
1631
+ context: this.context
1632
+ });
1633
+ }
1634
+ };
1635
+
1465
1636
  // src/context/context.ts
1466
1637
  var WorkflowContext = class {
1467
1638
  executor;
@@ -1594,7 +1765,8 @@ var WorkflowContext = class {
1594
1765
  debug,
1595
1766
  initialPayload,
1596
1767
  env,
1597
- retries
1768
+ retries,
1769
+ telemetry
1598
1770
  }) {
1599
1771
  this.qstashClient = qstashClient;
1600
1772
  this.workflowRunId = workflowRunId;
@@ -1605,7 +1777,7 @@ var WorkflowContext = class {
1605
1777
  this.requestPayload = initialPayload;
1606
1778
  this.env = env ?? {};
1607
1779
  this.retries = retries ?? DEFAULT_RETRIES;
1608
- this.executor = new AutoExecutor(this, this.steps, debug);
1780
+ this.executor = new AutoExecutor(this, this.steps, telemetry, debug);
1609
1781
  }
1610
1782
  /**
1611
1783
  * Executes a workflow step
@@ -1841,6 +2013,11 @@ var WorkflowContext = class {
1841
2013
  async addStep(step) {
1842
2014
  return await this.executor.addStep(step);
1843
2015
  }
2016
+ get api() {
2017
+ return new WorkflowApi({
2018
+ context: this
2019
+ });
2020
+ }
1844
2021
  };
1845
2022
 
1846
2023
  // src/logger.ts
@@ -1918,7 +2095,7 @@ function decodeBase64(base64) {
1918
2095
  }
1919
2096
 
1920
2097
  // src/serve/authorization.ts
1921
- var import_qstash4 = require("@upstash/qstash");
2098
+ var import_qstash8 = require("@upstash/qstash");
1922
2099
  var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
1923
2100
  static disabledMessage = "disabled-qstash-worklfow-run";
1924
2101
  /**
@@ -1949,7 +2126,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
1949
2126
  */
1950
2127
  static async tryAuthentication(routeFunction, context) {
1951
2128
  const disabledContext = new _DisabledWorkflowContext({
1952
- qstashClient: new import_qstash4.Client({
2129
+ qstashClient: new import_qstash8.Client({
1953
2130
  baseUrl: "disabled-client",
1954
2131
  token: "disabled-client"
1955
2132
  }),
@@ -2113,7 +2290,7 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
2113
2290
  };
2114
2291
  }
2115
2292
  };
2116
- var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, debug) => {
2293
+ var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, routeFunction, failureFunction, env, retries, debug) => {
2117
2294
  if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
2118
2295
  return ok("not-failure-callback");
2119
2296
  }
@@ -2138,7 +2315,11 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
2138
2315
  steps: [],
2139
2316
  url,
2140
2317
  failureUrl: url,
2141
- debug
2318
+ debug,
2319
+ env,
2320
+ retries,
2321
+ telemetry: void 0
2322
+ // not going to make requests in authentication check
2142
2323
  });
2143
2324
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
2144
2325
  routeFunction,
@@ -2163,15 +2344,15 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
2163
2344
  };
2164
2345
 
2165
2346
  // src/serve/options.ts
2166
- var import_qstash5 = require("@upstash/qstash");
2167
- var import_qstash6 = require("@upstash/qstash");
2347
+ var import_qstash9 = require("@upstash/qstash");
2348
+ var import_qstash10 = require("@upstash/qstash");
2168
2349
  var processOptions = (options) => {
2169
2350
  const environment = options?.env ?? (typeof process === "undefined" ? {} : process.env);
2170
2351
  const receiverEnvironmentVariablesSet = Boolean(
2171
2352
  environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
2172
2353
  );
2173
2354
  return {
2174
- qstashClient: new import_qstash6.Client({
2355
+ qstashClient: new import_qstash10.Client({
2175
2356
  baseUrl: environment.QSTASH_URL,
2176
2357
  token: environment.QSTASH_TOKEN
2177
2358
  }),
@@ -2205,7 +2386,7 @@ var processOptions = (options) => {
2205
2386
  throw error;
2206
2387
  }
2207
2388
  },
2208
- receiver: receiverEnvironmentVariablesSet ? new import_qstash5.Receiver({
2389
+ receiver: receiverEnvironmentVariablesSet ? new import_qstash9.Receiver({
2209
2390
  currentSigningKey: environment.QSTASH_CURRENT_SIGNING_KEY,
2210
2391
  nextSigningKey: environment.QSTASH_NEXT_SIGNING_KEY
2211
2392
  }) : void 0,
@@ -2213,6 +2394,7 @@ var processOptions = (options) => {
2213
2394
  env: environment,
2214
2395
  retries: DEFAULT_RETRIES,
2215
2396
  useJSONContent: false,
2397
+ disableTelemetry: false,
2216
2398
  ...options
2217
2399
  };
2218
2400
  };
@@ -2247,7 +2429,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
2247
2429
  var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
2248
2430
 
2249
2431
  // src/serve/index.ts
2250
- var serveBase = (routeFunction, options) => {
2432
+ var serveBase = (routeFunction, telemetry, options) => {
2251
2433
  const {
2252
2434
  qstashClient,
2253
2435
  onStepFinish,
@@ -2260,8 +2442,10 @@ var serveBase = (routeFunction, options) => {
2260
2442
  baseUrl,
2261
2443
  env,
2262
2444
  retries,
2263
- useJSONContent
2445
+ useJSONContent,
2446
+ disableTelemetry
2264
2447
  } = processOptions(options);
2448
+ telemetry = disableTelemetry ? void 0 : telemetry;
2265
2449
  const debug = WorkflowLogger.getLogger(verbose);
2266
2450
  const handler = async (request) => {
2267
2451
  await debug?.log("INFO", "ENDPOINT_START");
@@ -2297,7 +2481,10 @@ var serveBase = (routeFunction, options) => {
2297
2481
  qstashClient,
2298
2482
  initialPayloadParser,
2299
2483
  routeFunction,
2300
- failureFunction
2484
+ failureFunction,
2485
+ env,
2486
+ retries,
2487
+ debug
2301
2488
  );
2302
2489
  if (failureCheck.isErr()) {
2303
2490
  throw failureCheck.error;
@@ -2315,7 +2502,8 @@ var serveBase = (routeFunction, options) => {
2315
2502
  failureUrl: workflowFailureUrl,
2316
2503
  debug,
2317
2504
  env,
2318
- retries
2505
+ retries,
2506
+ telemetry
2319
2507
  });
2320
2508
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
2321
2509
  routeFunction,
@@ -2331,22 +2519,23 @@ var serveBase = (routeFunction, options) => {
2331
2519
  "auth-fail"
2332
2520
  );
2333
2521
  }
2334
- const callReturnCheck = await handleThirdPartyCallResult(
2522
+ const callReturnCheck = await handleThirdPartyCallResult({
2335
2523
  request,
2336
- rawInitialPayload,
2337
- qstashClient,
2524
+ requestPayload: rawInitialPayload,
2525
+ client: qstashClient,
2338
2526
  workflowUrl,
2339
- workflowFailureUrl,
2527
+ failureUrl: workflowFailureUrl,
2340
2528
  retries,
2529
+ telemetry,
2341
2530
  debug
2342
- );
2531
+ });
2343
2532
  if (callReturnCheck.isErr()) {
2344
2533
  await debug?.log("ERROR", "SUBMIT_THIRD_PARTY_RESULT", {
2345
2534
  error: callReturnCheck.error.message
2346
2535
  });
2347
2536
  throw callReturnCheck.error;
2348
2537
  } else if (callReturnCheck.value === "continue-workflow") {
2349
- const result = isFirstInvocation ? await triggerFirstInvocation(workflowContext, retries, useJSONContent, debug) : await triggerRouteFunction({
2538
+ const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
2350
2539
  onStep: async () => routeFunction(workflowContext),
2351
2540
  onCleanup: async () => {
2352
2541
  await triggerWorkflowDelete(workflowContext, debug);
@@ -2385,6 +2574,11 @@ var serveBase = (routeFunction, options) => {
2385
2574
  var serve = (routeFunction, options) => {
2386
2575
  const { handler: serveHandler } = serveBase(
2387
2576
  routeFunction,
2577
+ {
2578
+ sdk: SDK_TELEMETRY,
2579
+ framework: "nextjs",
2580
+ runtime: `node@${process.version}`
2581
+ },
2388
2582
  options
2389
2583
  );
2390
2584
  return {
@@ -2394,7 +2588,15 @@ var serve = (routeFunction, options) => {
2394
2588
  };
2395
2589
  };
2396
2590
  var servePagesRouter = (routeFunction, options) => {
2397
- const { handler: serveHandler } = serveBase(routeFunction, options);
2591
+ const { handler: serveHandler } = serveBase(
2592
+ routeFunction,
2593
+ {
2594
+ sdk: SDK_TELEMETRY,
2595
+ framework: "nextjs-pages",
2596
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
2597
+ },
2598
+ options
2599
+ );
2398
2600
  const handler = async (request_, res) => {
2399
2601
  if (request_.method?.toUpperCase() !== "POST") {
2400
2602
  res.status(405).json("Only POST requests are allowed in worklfows");
package/nextjs.mjs CHANGED
@@ -1,11 +1,17 @@
1
1
  import {
2
+ SDK_TELEMETRY,
2
3
  serveBase
3
- } from "./chunk-Z7WS5XIR.mjs";
4
+ } from "./chunk-ETDFMXER.mjs";
4
5
 
5
6
  // platforms/nextjs.ts
6
7
  var serve = (routeFunction, options) => {
7
8
  const { handler: serveHandler } = serveBase(
8
9
  routeFunction,
10
+ {
11
+ sdk: SDK_TELEMETRY,
12
+ framework: "nextjs",
13
+ runtime: `node@${process.version}`
14
+ },
9
15
  options
10
16
  );
11
17
  return {
@@ -15,7 +21,15 @@ var serve = (routeFunction, options) => {
15
21
  };
16
22
  };
17
23
  var servePagesRouter = (routeFunction, options) => {
18
- const { handler: serveHandler } = serveBase(routeFunction, options);
24
+ const { handler: serveHandler } = serveBase(
25
+ routeFunction,
26
+ {
27
+ sdk: SDK_TELEMETRY,
28
+ framework: "nextjs-pages",
29
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
30
+ },
31
+ options
32
+ );
19
33
  const handler = async (request_, res) => {
20
34
  if (request_.method?.toUpperCase() !== "POST") {
21
35
  res.status(405).json("Only POST requests are allowed in worklfows");
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/workflow","version":"v0.2.2","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsc":"^2.0.4","tsup":"^8.3.0","typescript":"^5.6.3","typescript-eslint":"^8.8.0"},"dependencies":{"@upstash/qstash":"^2.7.17"},"directories":{"example":"examples"}}
1
+ {"name":"@upstash/workflow","version":"v0.2.4","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@upstash/qstash":"^2.7.20"},"directories":{"example":"examples"}}
package/solidjs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-APRap-aV.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Bt4-paRy.mjs';
3
3
  import '@upstash/qstash';
4
4
 
5
5
  /**
package/solidjs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-APRap-aV.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-Bt4-paRy.js';
3
3
  import '@upstash/qstash';
4
4
 
5
5
  /**