@upstash/workflow 0.2.17 → 0.2.19

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/solidjs.js CHANGED
@@ -84,12 +84,13 @@ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
84
84
  var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
85
85
  var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
86
86
  var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
87
+ var WORKFLOW_LABEL_HEADER = "Upstash-Label";
87
88
  var WORKFLOW_PROTOCOL_VERSION = "1";
88
89
  var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
89
90
  var DEFAULT_CONTENT_TYPE = "application/json";
90
91
  var NO_CONCURRENCY = 1;
91
92
  var DEFAULT_RETRIES = 3;
92
- var VERSION = "v0.2.17";
93
+ var VERSION = "v0.2.18";
93
94
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
94
95
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
95
96
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -611,7 +612,7 @@ var triggerFirstInvocation = async (params) => {
611
612
  const firstInvocationParams = Array.isArray(params) ? params : [params];
612
613
  const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
613
614
  const invocationBatch = firstInvocationParams.map(
614
- ({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
615
+ ({ workflowContext, useJSONContent, telemetry, invokeCount, delay, notBefore }) => {
615
616
  const { headers } = getHeaders({
616
617
  initHeaderValue: "true",
617
618
  workflowConfig: {
@@ -633,13 +634,17 @@ var triggerFirstInvocation = async (params) => {
633
634
  if (useJSONContent) {
634
635
  headers["content-type"] = "application/json";
635
636
  }
637
+ if (workflowContext.label) {
638
+ headers[WORKFLOW_LABEL_HEADER] = workflowContext.label;
639
+ }
636
640
  const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
637
641
  return {
638
642
  headers,
639
643
  method: "POST",
640
644
  body,
641
645
  url: workflowContext.url,
642
- delay
646
+ delay,
647
+ notBefore
643
648
  };
644
649
  }
645
650
  );
@@ -733,10 +738,11 @@ var recreateUserHeaders = (headers) => {
733
738
  const pairs = headers.entries();
734
739
  for (const [header, value] of pairs) {
735
740
  const headerLowerCase = header.toLowerCase();
736
- if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
741
+ const isUserHeader = !headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
737
742
  !headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
738
743
  headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
739
- headerLowerCase !== "render-proxy-ttl") {
744
+ headerLowerCase !== "render-proxy-ttl" || headerLowerCase === WORKFLOW_LABEL_HEADER.toLocaleLowerCase();
745
+ if (isUserHeader) {
740
746
  filteredHeaders.append(header, value);
741
747
  }
742
748
  }
@@ -2699,6 +2705,22 @@ var WorkflowContext = class {
2699
2705
  * and number of requests per second with the same key.
2700
2706
  */
2701
2707
  flowControl;
2708
+ /**
2709
+ * Label to apply to the workflow run.
2710
+ *
2711
+ * Can be used to filter the workflow run logs.
2712
+ *
2713
+ * Can be set by passing a `label` parameter when triggering the workflow
2714
+ * with `client.trigger`:
2715
+ *
2716
+ * ```ts
2717
+ * await client.trigger({
2718
+ * url: "https://workflow-endpoint.com",
2719
+ * label: "my-label"
2720
+ * });
2721
+ * ```
2722
+ */
2723
+ label;
2702
2724
  constructor({
2703
2725
  qstashClient,
2704
2726
  workflowRunId,
@@ -2713,7 +2735,8 @@ var WorkflowContext = class {
2713
2735
  retryDelay,
2714
2736
  telemetry,
2715
2737
  invokeCount,
2716
- flowControl
2738
+ flowControl,
2739
+ label
2717
2740
  }) {
2718
2741
  this.qstashClient = qstashClient;
2719
2742
  this.workflowRunId = workflowRunId;
@@ -2726,6 +2749,7 @@ var WorkflowContext = class {
2726
2749
  this.retries = retries ?? DEFAULT_RETRIES;
2727
2750
  this.retryDelay = retryDelay;
2728
2751
  this.flowControl = flowControl;
2752
+ this.label = label;
2729
2753
  this.executor = new AutoExecutor(this, this.steps, telemetry, invokeCount, debug);
2730
2754
  }
2731
2755
  /**
@@ -3026,7 +3050,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
3026
3050
  env: context.env,
3027
3051
  retries: context.retries,
3028
3052
  retryDelay: context.retryDelay,
3029
- flowControl: context.flowControl
3053
+ flowControl: context.flowControl,
3054
+ label: context.label
3030
3055
  });
3031
3056
  try {
3032
3057
  await routeFunction(disabledContext);
@@ -3203,11 +3228,12 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3203
3228
  if (!errorMessage) {
3204
3229
  errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
3205
3230
  }
3231
+ const userHeaders = recreateUserHeaders(request.headers);
3206
3232
  const workflowContext = new WorkflowContext({
3207
3233
  qstashClient,
3208
3234
  workflowRunId,
3209
3235
  initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
3210
- headers: recreateUserHeaders(request.headers),
3236
+ headers: userHeaders,
3211
3237
  steps: [],
3212
3238
  url,
3213
3239
  failureUrl: url,
@@ -3216,8 +3242,9 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3216
3242
  retries,
3217
3243
  retryDelay,
3218
3244
  flowControl,
3219
- telemetry: void 0
3245
+ telemetry: void 0,
3220
3246
  // not going to make requests in authentication check
3247
+ label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0
3221
3248
  });
3222
3249
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3223
3250
  routeFunction,
@@ -3250,7 +3277,7 @@ var processOptions = (options) => {
3250
3277
  environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
3251
3278
  );
3252
3279
  return {
3253
- qstashClient: new import_qstash11.Client({
3280
+ qstashClient: options?.qstashClient ?? new import_qstash11.Client({
3254
3281
  baseUrl: environment.QSTASH_URL,
3255
3282
  token: environment.QSTASH_TOKEN
3256
3283
  }),
@@ -3426,6 +3453,7 @@ var serveBase = (routeFunction, telemetry, options) => {
3426
3453
  });
3427
3454
  }
3428
3455
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
3456
+ const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
3429
3457
  const workflowContext = new WorkflowContext({
3430
3458
  qstashClient,
3431
3459
  workflowRunId,
@@ -3440,7 +3468,8 @@ var serveBase = (routeFunction, telemetry, options) => {
3440
3468
  retryDelay,
3441
3469
  telemetry,
3442
3470
  invokeCount,
3443
- flowControl
3471
+ flowControl,
3472
+ label
3444
3473
  });
3445
3474
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3446
3475
  routeFunction,
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-RP7G4UD5.mjs";
4
+ } from "./chunk-37XOXDLZ.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
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--R_3XZXz.mjs';
4
- import { s as serveManyBase } from './serve-many-DgDSOvQs.mjs';
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';
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--R_3XZXz.js';
4
- import { s as serveManyBase } from './serve-many-B3DfoTFt.js';
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';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';
package/svelte.js CHANGED
@@ -86,12 +86,13 @@ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
86
86
  var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
87
87
  var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
88
88
  var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
89
+ var WORKFLOW_LABEL_HEADER = "Upstash-Label";
89
90
  var WORKFLOW_PROTOCOL_VERSION = "1";
90
91
  var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
91
92
  var DEFAULT_CONTENT_TYPE = "application/json";
92
93
  var NO_CONCURRENCY = 1;
93
94
  var DEFAULT_RETRIES = 3;
94
- var VERSION = "v0.2.17";
95
+ var VERSION = "v0.2.18";
95
96
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
96
97
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
97
98
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
@@ -613,7 +614,7 @@ var triggerFirstInvocation = async (params) => {
613
614
  const firstInvocationParams = Array.isArray(params) ? params : [params];
614
615
  const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
615
616
  const invocationBatch = firstInvocationParams.map(
616
- ({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay }) => {
617
+ ({ workflowContext, useJSONContent, telemetry: telemetry2, invokeCount, delay, notBefore }) => {
617
618
  const { headers } = getHeaders({
618
619
  initHeaderValue: "true",
619
620
  workflowConfig: {
@@ -635,13 +636,17 @@ var triggerFirstInvocation = async (params) => {
635
636
  if (useJSONContent) {
636
637
  headers["content-type"] = "application/json";
637
638
  }
639
+ if (workflowContext.label) {
640
+ headers[WORKFLOW_LABEL_HEADER] = workflowContext.label;
641
+ }
638
642
  const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
639
643
  return {
640
644
  headers,
641
645
  method: "POST",
642
646
  body,
643
647
  url: workflowContext.url,
644
- delay
648
+ delay,
649
+ notBefore
645
650
  };
646
651
  }
647
652
  );
@@ -735,10 +740,11 @@ var recreateUserHeaders = (headers) => {
735
740
  const pairs = headers.entries();
736
741
  for (const [header, value] of pairs) {
737
742
  const headerLowerCase = header.toLowerCase();
738
- if (!headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
743
+ const isUserHeader = !headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
739
744
  !headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
740
745
  headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
741
- headerLowerCase !== "render-proxy-ttl") {
746
+ headerLowerCase !== "render-proxy-ttl" || headerLowerCase === WORKFLOW_LABEL_HEADER.toLocaleLowerCase();
747
+ if (isUserHeader) {
742
748
  filteredHeaders.append(header, value);
743
749
  }
744
750
  }
@@ -2768,6 +2774,22 @@ var WorkflowContext = class {
2768
2774
  * and number of requests per second with the same key.
2769
2775
  */
2770
2776
  flowControl;
2777
+ /**
2778
+ * Label to apply to the workflow run.
2779
+ *
2780
+ * Can be used to filter the workflow run logs.
2781
+ *
2782
+ * Can be set by passing a `label` parameter when triggering the workflow
2783
+ * with `client.trigger`:
2784
+ *
2785
+ * ```ts
2786
+ * await client.trigger({
2787
+ * url: "https://workflow-endpoint.com",
2788
+ * label: "my-label"
2789
+ * });
2790
+ * ```
2791
+ */
2792
+ label;
2771
2793
  constructor({
2772
2794
  qstashClient,
2773
2795
  workflowRunId,
@@ -2782,7 +2804,8 @@ var WorkflowContext = class {
2782
2804
  retryDelay,
2783
2805
  telemetry: telemetry2,
2784
2806
  invokeCount,
2785
- flowControl
2807
+ flowControl,
2808
+ label
2786
2809
  }) {
2787
2810
  this.qstashClient = qstashClient;
2788
2811
  this.workflowRunId = workflowRunId;
@@ -2795,6 +2818,7 @@ var WorkflowContext = class {
2795
2818
  this.retries = retries ?? DEFAULT_RETRIES;
2796
2819
  this.retryDelay = retryDelay;
2797
2820
  this.flowControl = flowControl;
2821
+ this.label = label;
2798
2822
  this.executor = new AutoExecutor(this, this.steps, telemetry2, invokeCount, debug);
2799
2823
  }
2800
2824
  /**
@@ -3095,7 +3119,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
3095
3119
  env: context.env,
3096
3120
  retries: context.retries,
3097
3121
  retryDelay: context.retryDelay,
3098
- flowControl: context.flowControl
3122
+ flowControl: context.flowControl,
3123
+ label: context.label
3099
3124
  });
3100
3125
  try {
3101
3126
  await routeFunction(disabledContext);
@@ -3272,11 +3297,12 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3272
3297
  if (!errorMessage) {
3273
3298
  errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
3274
3299
  }
3300
+ const userHeaders = recreateUserHeaders(request.headers);
3275
3301
  const workflowContext = new WorkflowContext({
3276
3302
  qstashClient,
3277
3303
  workflowRunId,
3278
3304
  initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
3279
- headers: recreateUserHeaders(request.headers),
3305
+ headers: userHeaders,
3280
3306
  steps: [],
3281
3307
  url,
3282
3308
  failureUrl: url,
@@ -3285,8 +3311,9 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
3285
3311
  retries,
3286
3312
  retryDelay,
3287
3313
  flowControl,
3288
- telemetry: void 0
3314
+ telemetry: void 0,
3289
3315
  // not going to make requests in authentication check
3316
+ label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0
3290
3317
  });
3291
3318
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3292
3319
  routeFunction,
@@ -3319,7 +3346,7 @@ var processOptions = (options) => {
3319
3346
  environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
3320
3347
  );
3321
3348
  return {
3322
- qstashClient: new import_qstash11.Client({
3349
+ qstashClient: options?.qstashClient ?? new import_qstash11.Client({
3323
3350
  baseUrl: environment.QSTASH_URL,
3324
3351
  token: environment.QSTASH_TOKEN
3325
3352
  }),
@@ -3495,6 +3522,7 @@ var serveBase = (routeFunction, telemetry2, options) => {
3495
3522
  });
3496
3523
  }
3497
3524
  const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
3525
+ const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
3498
3526
  const workflowContext = new WorkflowContext({
3499
3527
  qstashClient,
3500
3528
  workflowRunId,
@@ -3509,7 +3537,8 @@ var serveBase = (routeFunction, telemetry2, options) => {
3509
3537
  retryDelay,
3510
3538
  telemetry: telemetry2,
3511
3539
  invokeCount,
3512
- flowControl
3540
+ flowControl,
3541
+ label
3513
3542
  });
3514
3543
  const authCheck = await DisabledWorkflowContext.tryAuthentication(
3515
3544
  routeFunction,
package/svelte.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-RP7G4UD5.mjs";
5
+ } from "./chunk-37XOXDLZ.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var telemetry = {
@@ -913,7 +913,23 @@ declare class WorkflowContext<TInitialPayload = unknown> {
913
913
  * and number of requests per second with the same key.
914
914
  */
915
915
  readonly flowControl?: FlowControl;
916
- constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, retryDelay, telemetry, invokeCount, flowControl, }: {
916
+ /**
917
+ * Label to apply to the workflow run.
918
+ *
919
+ * Can be used to filter the workflow run logs.
920
+ *
921
+ * Can be set by passing a `label` parameter when triggering the workflow
922
+ * with `client.trigger`:
923
+ *
924
+ * ```ts
925
+ * await client.trigger({
926
+ * url: "https://workflow-endpoint.com",
927
+ * label: "my-label"
928
+ * });
929
+ * ```
930
+ */
931
+ readonly label?: string;
932
+ constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, retryDelay, telemetry, invokeCount, flowControl, label, }: {
917
933
  qstashClient: WorkflowClient;
918
934
  workflowRunId: string;
919
935
  headers: Headers;
@@ -928,6 +944,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
928
944
  telemetry?: Telemetry;
929
945
  invokeCount?: number;
930
946
  flowControl?: FlowControl;
947
+ label?: string;
931
948
  });
932
949
  /**
933
950
  * Executes a workflow step
@@ -913,7 +913,23 @@ declare class WorkflowContext<TInitialPayload = unknown> {
913
913
  * and number of requests per second with the same key.
914
914
  */
915
915
  readonly flowControl?: FlowControl;
916
- constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, retryDelay, telemetry, invokeCount, flowControl, }: {
916
+ /**
917
+ * Label to apply to the workflow run.
918
+ *
919
+ * Can be used to filter the workflow run logs.
920
+ *
921
+ * Can be set by passing a `label` parameter when triggering the workflow
922
+ * with `client.trigger`:
923
+ *
924
+ * ```ts
925
+ * await client.trigger({
926
+ * url: "https://workflow-endpoint.com",
927
+ * label: "my-label"
928
+ * });
929
+ * ```
930
+ */
931
+ readonly label?: string;
932
+ constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, retryDelay, telemetry, invokeCount, flowControl, label, }: {
917
933
  qstashClient: WorkflowClient;
918
934
  workflowRunId: string;
919
935
  headers: Headers;
@@ -928,6 +944,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
928
944
  telemetry?: Telemetry;
929
945
  invokeCount?: number;
930
946
  flowControl?: FlowControl;
947
+ label?: string;
931
948
  });
932
949
  /**
933
950
  * Executes a workflow step