@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/astro.d.mts +2 -2
- package/astro.d.ts +2 -2
- package/astro.js +40 -11
- package/astro.mjs +1 -1
- package/{chunk-RP7G4UD5.mjs → chunk-37XOXDLZ.mjs} +41 -11
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +40 -11
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +40 -11
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +40 -11
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +40 -11
- package/hono.mjs +1 -1
- package/index.d.mts +29 -3
- package/index.d.ts +29 -3
- package/index.js +51 -14
- package/index.mjs +13 -4
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +40 -11
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-B3DfoTFt.d.ts → serve-many-BObe3pdI.d.ts} +1 -1
- package/{serve-many-DgDSOvQs.d.mts → serve-many-CEUYWQvV.d.mts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +40 -11
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +40 -11
- package/svelte.mjs +1 -1
- package/{types--R_3XZXz.d.ts → types-B7_5AkKQ.d.mts} +18 -1
- package/{types--R_3XZXz.d.mts → types-B7_5AkKQ.d.ts} +18 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types
|
|
2
|
-
export { A as AsyncStepFunction, C as CallResponse, v as CallSettings, D as DetailedFinishCondition, t as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, x as InvokableWorkflow, w as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, y as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, u as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, B as WorkflowLogger, z as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types
|
|
1
|
+
import { R as RouteFunction, W as WorkflowServeOptions, E as ExclusiveValidationOptions, T as Telemetry, S as StepType, a as RawStep, N as NotifyResponse, b as Waiter } from './types-B7_5AkKQ.js';
|
|
2
|
+
export { A as AsyncStepFunction, C as CallResponse, v as CallSettings, D as DetailedFinishCondition, t as Duration, o as FailureFunctionPayload, F as FinishCondition, H as HeaderParams, x as InvokableWorkflow, w as InvokeStepResponse, I as InvokeWorkflowRequest, L as LazyInvokeStepParams, y as LogLevel, s as NotifyStepResponse, P as ParallelCallState, n as PublicServeOptions, p as RequiredExceptFields, k as Step, m as StepFunction, j as StepTypes, l as SyncStepFunction, u as WaitEventOptions, q as WaitRequest, r as WaitStepResponse, d as WorkflowAbort, h as WorkflowClient, g as WorkflowContext, c as WorkflowError, B as WorkflowLogger, z as WorkflowLoggerOptions, e as WorkflowNonRetryableError, i as WorkflowReceiver, f as WorkflowTool } from './types-B7_5AkKQ.js';
|
|
3
3
|
import { FlowControl, PublishRequest, HTTPMethods, State, Client as Client$1 } from '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
|
@@ -343,6 +343,10 @@ type WorkflowRunLog = {
|
|
|
343
343
|
* If the workflow run has failed, id of the run in DLQ
|
|
344
344
|
*/
|
|
345
345
|
dlqId?: string;
|
|
346
|
+
/**
|
|
347
|
+
* Label of the workflow run
|
|
348
|
+
*/
|
|
349
|
+
label?: string;
|
|
346
350
|
};
|
|
347
351
|
type WorkflowRunLogs = {
|
|
348
352
|
cursor: string;
|
|
@@ -412,6 +416,22 @@ type TriggerOptions = {
|
|
|
412
416
|
* Delay to apply before triggering the workflow.
|
|
413
417
|
*/
|
|
414
418
|
delay?: PublishRequest["delay"];
|
|
419
|
+
/**
|
|
420
|
+
* Optionally set the absolute delay of this message.
|
|
421
|
+
* This will override the delay option.
|
|
422
|
+
* The message will not delivered until the specified time.
|
|
423
|
+
*
|
|
424
|
+
* Unix timestamp in seconds.
|
|
425
|
+
*
|
|
426
|
+
* @default undefined
|
|
427
|
+
*/
|
|
428
|
+
notBefore?: PublishRequest["notBefore"];
|
|
429
|
+
/**
|
|
430
|
+
* Label to apply to the workflow run.
|
|
431
|
+
*
|
|
432
|
+
* Can be used to filter the workflow run logs.
|
|
433
|
+
*/
|
|
434
|
+
label?: string;
|
|
415
435
|
} & ({
|
|
416
436
|
/**
|
|
417
437
|
* URL to call if the first request to the workflow endpoint fails
|
|
@@ -456,6 +476,7 @@ type DLQFilterOptions = Pick<QStashDLQFilterOptions, "fromDate" | "toDate" | "ur
|
|
|
456
476
|
workflowRunId?: string;
|
|
457
477
|
workflowCreatedAt?: string;
|
|
458
478
|
failureFunctionState?: FailureCallbackInfo["state"];
|
|
479
|
+
label?: string;
|
|
459
480
|
};
|
|
460
481
|
type FailureCallbackInfo = {
|
|
461
482
|
state?: "CALLBACK_FAIL" | "CALLBACK_SUCCESS" | "CALLBACK_INPROGRESS";
|
|
@@ -491,8 +512,12 @@ type DLQMessage = {
|
|
|
491
512
|
* status of the failure callback
|
|
492
513
|
*/
|
|
493
514
|
failureCallbackInfo?: FailureCallbackInfo;
|
|
515
|
+
/**
|
|
516
|
+
* label passed when triggering workflow
|
|
517
|
+
*/
|
|
518
|
+
label?: string;
|
|
494
519
|
};
|
|
495
|
-
type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId" | "failureCallback" | "failureCallbackInfo">;
|
|
520
|
+
type PublicDLQMessage = Pick<DLQMessage, "header" | "body" | "maxRetries" | "notBefore" | "createdAt" | "callerIP" | "workflowRunId" | "workflowCreatedAt" | "workflowUrl" | "responseStatus" | "responseHeader" | "responseBody" | "dlqId" | "failureCallback" | "failureCallbackInfo" | "label">;
|
|
496
521
|
declare class DLQ {
|
|
497
522
|
private client;
|
|
498
523
|
constructor(client: Client$1);
|
|
@@ -832,6 +857,7 @@ declare class Client {
|
|
|
832
857
|
state?: WorkflowRunLog["workflowState"];
|
|
833
858
|
workflowUrl?: WorkflowRunLog["workflowUrl"];
|
|
834
859
|
workflowCreatedAt?: WorkflowRunLog["workflowRunCreatedAt"];
|
|
860
|
+
label?: WorkflowRunLog["label"];
|
|
835
861
|
}): Promise<WorkflowRunLogs>;
|
|
836
862
|
get dlq(): DLQ;
|
|
837
863
|
}
|
package/index.js
CHANGED
|
@@ -99,12 +99,13 @@ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
|
99
99
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
100
100
|
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
101
101
|
var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
|
|
102
|
+
var WORKFLOW_LABEL_HEADER = "Upstash-Label";
|
|
102
103
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
103
104
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
104
105
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
105
106
|
var NO_CONCURRENCY = 1;
|
|
106
107
|
var DEFAULT_RETRIES = 3;
|
|
107
|
-
var VERSION = "v0.2.
|
|
108
|
+
var VERSION = "v0.2.18";
|
|
108
109
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
109
110
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
110
111
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -626,7 +627,7 @@ var triggerFirstInvocation = async (params) => {
|
|
|
626
627
|
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
627
628
|
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
628
629
|
const invocationBatch = firstInvocationParams.map(
|
|
629
|
-
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
|
|
630
|
+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay, notBefore }) => {
|
|
630
631
|
const { headers } = getHeaders({
|
|
631
632
|
initHeaderValue: "true",
|
|
632
633
|
workflowConfig: {
|
|
@@ -648,13 +649,17 @@ var triggerFirstInvocation = async (params) => {
|
|
|
648
649
|
if (useJSONContent) {
|
|
649
650
|
headers["content-type"] = "application/json";
|
|
650
651
|
}
|
|
652
|
+
if (workflowContext.label) {
|
|
653
|
+
headers[WORKFLOW_LABEL_HEADER] = workflowContext.label;
|
|
654
|
+
}
|
|
651
655
|
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
652
656
|
return {
|
|
653
657
|
headers,
|
|
654
658
|
method: "POST",
|
|
655
659
|
body,
|
|
656
660
|
url: workflowContext.url,
|
|
657
|
-
delay
|
|
661
|
+
delay,
|
|
662
|
+
notBefore
|
|
658
663
|
};
|
|
659
664
|
}
|
|
660
665
|
);
|
|
@@ -748,10 +753,11 @@ var recreateUserHeaders = (headers) => {
|
|
|
748
753
|
const pairs = headers.entries();
|
|
749
754
|
for (const [header, value] of pairs) {
|
|
750
755
|
const headerLowerCase = header.toLowerCase();
|
|
751
|
-
|
|
756
|
+
const isUserHeader = !headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
|
|
752
757
|
!headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
|
|
753
758
|
headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
|
|
754
|
-
headerLowerCase !== "render-proxy-ttl")
|
|
759
|
+
headerLowerCase !== "render-proxy-ttl" || headerLowerCase === WORKFLOW_LABEL_HEADER.toLocaleLowerCase();
|
|
760
|
+
if (isUserHeader) {
|
|
755
761
|
filteredHeaders.append(header, value);
|
|
756
762
|
}
|
|
757
763
|
}
|
|
@@ -2745,6 +2751,22 @@ var WorkflowContext = class {
|
|
|
2745
2751
|
* and number of requests per second with the same key.
|
|
2746
2752
|
*/
|
|
2747
2753
|
flowControl;
|
|
2754
|
+
/**
|
|
2755
|
+
* Label to apply to the workflow run.
|
|
2756
|
+
*
|
|
2757
|
+
* Can be used to filter the workflow run logs.
|
|
2758
|
+
*
|
|
2759
|
+
* Can be set by passing a `label` parameter when triggering the workflow
|
|
2760
|
+
* with `client.trigger`:
|
|
2761
|
+
*
|
|
2762
|
+
* ```ts
|
|
2763
|
+
* await client.trigger({
|
|
2764
|
+
* url: "https://workflow-endpoint.com",
|
|
2765
|
+
* label: "my-label"
|
|
2766
|
+
* });
|
|
2767
|
+
* ```
|
|
2768
|
+
*/
|
|
2769
|
+
label;
|
|
2748
2770
|
constructor({
|
|
2749
2771
|
qstashClient,
|
|
2750
2772
|
workflowRunId,
|
|
@@ -2759,7 +2781,8 @@ var WorkflowContext = class {
|
|
|
2759
2781
|
retryDelay,
|
|
2760
2782
|
telemetry,
|
|
2761
2783
|
invokeCount,
|
|
2762
|
-
flowControl
|
|
2784
|
+
flowControl,
|
|
2785
|
+
label
|
|
2763
2786
|
}) {
|
|
2764
2787
|
this.qstashClient = qstashClient;
|
|
2765
2788
|
this.workflowRunId = workflowRunId;
|
|
@@ -2772,6 +2795,7 @@ var WorkflowContext = class {
|
|
|
2772
2795
|
this.retries = retries ?? DEFAULT_RETRIES;
|
|
2773
2796
|
this.retryDelay = retryDelay;
|
|
2774
2797
|
this.flowControl = flowControl;
|
|
2798
|
+
this.label = label;
|
|
2775
2799
|
this.executor = new AutoExecutor(this, this.steps, telemetry, invokeCount, debug);
|
|
2776
2800
|
}
|
|
2777
2801
|
/**
|
|
@@ -3072,7 +3096,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
3072
3096
|
env: context.env,
|
|
3073
3097
|
retries: context.retries,
|
|
3074
3098
|
retryDelay: context.retryDelay,
|
|
3075
|
-
flowControl: context.flowControl
|
|
3099
|
+
flowControl: context.flowControl,
|
|
3100
|
+
label: context.label
|
|
3076
3101
|
});
|
|
3077
3102
|
try {
|
|
3078
3103
|
await routeFunction(disabledContext);
|
|
@@ -3249,11 +3274,12 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
3249
3274
|
if (!errorMessage) {
|
|
3250
3275
|
errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
|
|
3251
3276
|
}
|
|
3277
|
+
const userHeaders = recreateUserHeaders(request.headers);
|
|
3252
3278
|
const workflowContext = new WorkflowContext({
|
|
3253
3279
|
qstashClient,
|
|
3254
3280
|
workflowRunId,
|
|
3255
3281
|
initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
|
|
3256
|
-
headers:
|
|
3282
|
+
headers: userHeaders,
|
|
3257
3283
|
steps: [],
|
|
3258
3284
|
url,
|
|
3259
3285
|
failureUrl: url,
|
|
@@ -3262,8 +3288,9 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
3262
3288
|
retries,
|
|
3263
3289
|
retryDelay,
|
|
3264
3290
|
flowControl,
|
|
3265
|
-
telemetry: void 0
|
|
3291
|
+
telemetry: void 0,
|
|
3266
3292
|
// not going to make requests in authentication check
|
|
3293
|
+
label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0
|
|
3267
3294
|
});
|
|
3268
3295
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
3269
3296
|
routeFunction,
|
|
@@ -3296,7 +3323,7 @@ var processOptions = (options) => {
|
|
|
3296
3323
|
environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
|
|
3297
3324
|
);
|
|
3298
3325
|
return {
|
|
3299
|
-
qstashClient: new import_qstash11.Client({
|
|
3326
|
+
qstashClient: options?.qstashClient ?? new import_qstash11.Client({
|
|
3300
3327
|
baseUrl: environment.QSTASH_URL,
|
|
3301
3328
|
token: environment.QSTASH_TOKEN
|
|
3302
3329
|
}),
|
|
@@ -3472,6 +3499,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3472
3499
|
});
|
|
3473
3500
|
}
|
|
3474
3501
|
const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
|
|
3502
|
+
const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
|
|
3475
3503
|
const workflowContext = new WorkflowContext({
|
|
3476
3504
|
qstashClient,
|
|
3477
3505
|
workflowRunId,
|
|
@@ -3486,7 +3514,8 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3486
3514
|
retryDelay,
|
|
3487
3515
|
telemetry,
|
|
3488
3516
|
invokeCount,
|
|
3489
|
-
flowControl
|
|
3517
|
+
flowControl,
|
|
3518
|
+
label
|
|
3490
3519
|
});
|
|
3491
3520
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
3492
3521
|
routeFunction,
|
|
@@ -3832,7 +3861,10 @@ var Client4 = class {
|
|
|
3832
3861
|
const context = new WorkflowContext({
|
|
3833
3862
|
qstashClient: this.client,
|
|
3834
3863
|
// @ts-expect-error header type mismatch because of bun
|
|
3835
|
-
headers: new Headers(
|
|
3864
|
+
headers: new Headers({
|
|
3865
|
+
...option.headers ?? {},
|
|
3866
|
+
...option.label ? { [WORKFLOW_LABEL_HEADER]: option.label } : {}
|
|
3867
|
+
}),
|
|
3836
3868
|
initialPayload: option.body,
|
|
3837
3869
|
steps: [],
|
|
3838
3870
|
url: option.url,
|
|
@@ -3841,12 +3873,14 @@ var Client4 = class {
|
|
|
3841
3873
|
retryDelay: option.retryDelay,
|
|
3842
3874
|
telemetry: { sdk: SDK_TELEMETRY },
|
|
3843
3875
|
flowControl: option.flowControl,
|
|
3844
|
-
failureUrl
|
|
3876
|
+
failureUrl,
|
|
3877
|
+
label: option.label
|
|
3845
3878
|
});
|
|
3846
3879
|
return {
|
|
3847
3880
|
workflowContext: context,
|
|
3848
3881
|
telemetry: { sdk: SDK_TELEMETRY },
|
|
3849
|
-
delay: option.delay
|
|
3882
|
+
delay: option.delay,
|
|
3883
|
+
notBefore: option.notBefore
|
|
3850
3884
|
};
|
|
3851
3885
|
});
|
|
3852
3886
|
const result = await triggerFirstInvocation(invocations);
|
|
@@ -3907,6 +3941,9 @@ var Client4 = class {
|
|
|
3907
3941
|
if (workflowCreatedAt) {
|
|
3908
3942
|
urlParams.append("workflowCreatedAt", workflowCreatedAt.toString());
|
|
3909
3943
|
}
|
|
3944
|
+
if (params?.label) {
|
|
3945
|
+
urlParams.append("label", params.label);
|
|
3946
|
+
}
|
|
3910
3947
|
const result = await this.client.http.request({
|
|
3911
3948
|
path: ["v2", "workflows", `events?${urlParams.toString()}`]
|
|
3912
3949
|
});
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SDK_TELEMETRY,
|
|
3
3
|
StepTypes,
|
|
4
|
+
WORKFLOW_LABEL_HEADER,
|
|
4
5
|
WorkflowAbort,
|
|
5
6
|
WorkflowContext,
|
|
6
7
|
WorkflowError,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
prepareFlowControl,
|
|
14
15
|
serve,
|
|
15
16
|
triggerFirstInvocation
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-37XOXDLZ.mjs";
|
|
17
18
|
|
|
18
19
|
// src/client/index.ts
|
|
19
20
|
import { Client as QStashClient } from "@upstash/qstash";
|
|
@@ -246,7 +247,10 @@ var Client = class {
|
|
|
246
247
|
const context = new WorkflowContext({
|
|
247
248
|
qstashClient: this.client,
|
|
248
249
|
// @ts-expect-error header type mismatch because of bun
|
|
249
|
-
headers: new Headers(
|
|
250
|
+
headers: new Headers({
|
|
251
|
+
...option.headers ?? {},
|
|
252
|
+
...option.label ? { [WORKFLOW_LABEL_HEADER]: option.label } : {}
|
|
253
|
+
}),
|
|
250
254
|
initialPayload: option.body,
|
|
251
255
|
steps: [],
|
|
252
256
|
url: option.url,
|
|
@@ -255,12 +259,14 @@ var Client = class {
|
|
|
255
259
|
retryDelay: option.retryDelay,
|
|
256
260
|
telemetry: { sdk: SDK_TELEMETRY },
|
|
257
261
|
flowControl: option.flowControl,
|
|
258
|
-
failureUrl
|
|
262
|
+
failureUrl,
|
|
263
|
+
label: option.label
|
|
259
264
|
});
|
|
260
265
|
return {
|
|
261
266
|
workflowContext: context,
|
|
262
267
|
telemetry: { sdk: SDK_TELEMETRY },
|
|
263
|
-
delay: option.delay
|
|
268
|
+
delay: option.delay,
|
|
269
|
+
notBefore: option.notBefore
|
|
264
270
|
};
|
|
265
271
|
});
|
|
266
272
|
const result = await triggerFirstInvocation(invocations);
|
|
@@ -321,6 +327,9 @@ var Client = class {
|
|
|
321
327
|
if (workflowCreatedAt) {
|
|
322
328
|
urlParams.append("workflowCreatedAt", workflowCreatedAt.toString());
|
|
323
329
|
}
|
|
330
|
+
if (params?.label) {
|
|
331
|
+
urlParams.append("label", params.label);
|
|
332
|
+
}
|
|
324
333
|
const result = await this.client.http.request({
|
|
325
334
|
path: ["v2", "workflows", `events?${urlParams.toString()}`]
|
|
326
335
|
});
|
package/nextjs.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-CEUYWQvV.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/nextjs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, n as PublicServeOptions, x as InvokableWorkflow } from './types-B7_5AkKQ.js';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-BObe3pdI.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/nextjs.js
CHANGED
|
@@ -89,12 +89,13 @@ var WORKFLOW_URL_HEADER = "Upstash-Workflow-Url";
|
|
|
89
89
|
var WORKFLOW_FAILURE_HEADER = "Upstash-Workflow-Is-Failure";
|
|
90
90
|
var WORKFLOW_FEATURE_HEADER = "Upstash-Feature-Set";
|
|
91
91
|
var WORKFLOW_INVOKE_COUNT_HEADER = "Upstash-Workflow-Invoke-Count";
|
|
92
|
+
var WORKFLOW_LABEL_HEADER = "Upstash-Label";
|
|
92
93
|
var WORKFLOW_PROTOCOL_VERSION = "1";
|
|
93
94
|
var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
94
95
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
95
96
|
var NO_CONCURRENCY = 1;
|
|
96
97
|
var DEFAULT_RETRIES = 3;
|
|
97
|
-
var VERSION = "v0.2.
|
|
98
|
+
var VERSION = "v0.2.18";
|
|
98
99
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
99
100
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
100
101
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -616,7 +617,7 @@ var triggerFirstInvocation = async (params) => {
|
|
|
616
617
|
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
617
618
|
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
618
619
|
const invocationBatch = firstInvocationParams.map(
|
|
619
|
-
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
|
|
620
|
+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay, notBefore }) => {
|
|
620
621
|
const { headers } = getHeaders({
|
|
621
622
|
initHeaderValue: "true",
|
|
622
623
|
workflowConfig: {
|
|
@@ -638,13 +639,17 @@ var triggerFirstInvocation = async (params) => {
|
|
|
638
639
|
if (useJSONContent) {
|
|
639
640
|
headers["content-type"] = "application/json";
|
|
640
641
|
}
|
|
642
|
+
if (workflowContext.label) {
|
|
643
|
+
headers[WORKFLOW_LABEL_HEADER] = workflowContext.label;
|
|
644
|
+
}
|
|
641
645
|
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
642
646
|
return {
|
|
643
647
|
headers,
|
|
644
648
|
method: "POST",
|
|
645
649
|
body,
|
|
646
650
|
url: workflowContext.url,
|
|
647
|
-
delay
|
|
651
|
+
delay,
|
|
652
|
+
notBefore
|
|
648
653
|
};
|
|
649
654
|
}
|
|
650
655
|
);
|
|
@@ -738,10 +743,11 @@ var recreateUserHeaders = (headers) => {
|
|
|
738
743
|
const pairs = headers.entries();
|
|
739
744
|
for (const [header, value] of pairs) {
|
|
740
745
|
const headerLowerCase = header.toLowerCase();
|
|
741
|
-
|
|
746
|
+
const isUserHeader = !headerLowerCase.startsWith("upstash-workflow-") && // https://vercel.com/docs/edge-network/headers/request-headers#x-vercel-id
|
|
742
747
|
!headerLowerCase.startsWith("x-vercel-") && !headerLowerCase.startsWith("x-forwarded-") && // https://blog.cloudflare.com/preventing-request-loops-using-cdn-loop/
|
|
743
748
|
headerLowerCase !== "cf-connecting-ip" && headerLowerCase !== "cdn-loop" && headerLowerCase !== "cf-ew-via" && headerLowerCase !== "cf-ray" && // For Render https://render.com
|
|
744
|
-
headerLowerCase !== "render-proxy-ttl")
|
|
749
|
+
headerLowerCase !== "render-proxy-ttl" || headerLowerCase === WORKFLOW_LABEL_HEADER.toLocaleLowerCase();
|
|
750
|
+
if (isUserHeader) {
|
|
745
751
|
filteredHeaders.append(header, value);
|
|
746
752
|
}
|
|
747
753
|
}
|
|
@@ -2771,6 +2777,22 @@ var WorkflowContext = class {
|
|
|
2771
2777
|
* and number of requests per second with the same key.
|
|
2772
2778
|
*/
|
|
2773
2779
|
flowControl;
|
|
2780
|
+
/**
|
|
2781
|
+
* Label to apply to the workflow run.
|
|
2782
|
+
*
|
|
2783
|
+
* Can be used to filter the workflow run logs.
|
|
2784
|
+
*
|
|
2785
|
+
* Can be set by passing a `label` parameter when triggering the workflow
|
|
2786
|
+
* with `client.trigger`:
|
|
2787
|
+
*
|
|
2788
|
+
* ```ts
|
|
2789
|
+
* await client.trigger({
|
|
2790
|
+
* url: "https://workflow-endpoint.com",
|
|
2791
|
+
* label: "my-label"
|
|
2792
|
+
* });
|
|
2793
|
+
* ```
|
|
2794
|
+
*/
|
|
2795
|
+
label;
|
|
2774
2796
|
constructor({
|
|
2775
2797
|
qstashClient,
|
|
2776
2798
|
workflowRunId,
|
|
@@ -2785,7 +2807,8 @@ var WorkflowContext = class {
|
|
|
2785
2807
|
retryDelay,
|
|
2786
2808
|
telemetry,
|
|
2787
2809
|
invokeCount,
|
|
2788
|
-
flowControl
|
|
2810
|
+
flowControl,
|
|
2811
|
+
label
|
|
2789
2812
|
}) {
|
|
2790
2813
|
this.qstashClient = qstashClient;
|
|
2791
2814
|
this.workflowRunId = workflowRunId;
|
|
@@ -2798,6 +2821,7 @@ var WorkflowContext = class {
|
|
|
2798
2821
|
this.retries = retries ?? DEFAULT_RETRIES;
|
|
2799
2822
|
this.retryDelay = retryDelay;
|
|
2800
2823
|
this.flowControl = flowControl;
|
|
2824
|
+
this.label = label;
|
|
2801
2825
|
this.executor = new AutoExecutor(this, this.steps, telemetry, invokeCount, debug);
|
|
2802
2826
|
}
|
|
2803
2827
|
/**
|
|
@@ -3098,7 +3122,8 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
3098
3122
|
env: context.env,
|
|
3099
3123
|
retries: context.retries,
|
|
3100
3124
|
retryDelay: context.retryDelay,
|
|
3101
|
-
flowControl: context.flowControl
|
|
3125
|
+
flowControl: context.flowControl,
|
|
3126
|
+
label: context.label
|
|
3102
3127
|
});
|
|
3103
3128
|
try {
|
|
3104
3129
|
await routeFunction(disabledContext);
|
|
@@ -3275,11 +3300,12 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
3275
3300
|
if (!errorMessage) {
|
|
3276
3301
|
errorMessage = `Couldn't parse 'failResponse' in 'failureFunction', received: '${decodedBody}'`;
|
|
3277
3302
|
}
|
|
3303
|
+
const userHeaders = recreateUserHeaders(request.headers);
|
|
3278
3304
|
const workflowContext = new WorkflowContext({
|
|
3279
3305
|
qstashClient,
|
|
3280
3306
|
workflowRunId,
|
|
3281
3307
|
initialPayload: sourceBody ? initialPayloadParser(decodeBase64(sourceBody)) : void 0,
|
|
3282
|
-
headers:
|
|
3308
|
+
headers: userHeaders,
|
|
3283
3309
|
steps: [],
|
|
3284
3310
|
url,
|
|
3285
3311
|
failureUrl: url,
|
|
@@ -3288,8 +3314,9 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
3288
3314
|
retries,
|
|
3289
3315
|
retryDelay,
|
|
3290
3316
|
flowControl,
|
|
3291
|
-
telemetry: void 0
|
|
3317
|
+
telemetry: void 0,
|
|
3292
3318
|
// not going to make requests in authentication check
|
|
3319
|
+
label: userHeaders.get(WORKFLOW_LABEL_HEADER) ?? void 0
|
|
3293
3320
|
});
|
|
3294
3321
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
3295
3322
|
routeFunction,
|
|
@@ -3322,7 +3349,7 @@ var processOptions = (options) => {
|
|
|
3322
3349
|
environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
|
|
3323
3350
|
);
|
|
3324
3351
|
return {
|
|
3325
|
-
qstashClient: new import_qstash11.Client({
|
|
3352
|
+
qstashClient: options?.qstashClient ?? new import_qstash11.Client({
|
|
3326
3353
|
baseUrl: environment.QSTASH_URL,
|
|
3327
3354
|
token: environment.QSTASH_TOKEN
|
|
3328
3355
|
}),
|
|
@@ -3498,6 +3525,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3498
3525
|
});
|
|
3499
3526
|
}
|
|
3500
3527
|
const invokeCount = Number(request.headers.get(WORKFLOW_INVOKE_COUNT_HEADER) ?? "0");
|
|
3528
|
+
const label = request.headers.get(WORKFLOW_LABEL_HEADER) ?? void 0;
|
|
3501
3529
|
const workflowContext = new WorkflowContext({
|
|
3502
3530
|
qstashClient,
|
|
3503
3531
|
workflowRunId,
|
|
@@ -3512,7 +3540,8 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
3512
3540
|
retryDelay,
|
|
3513
3541
|
telemetry,
|
|
3514
3542
|
invokeCount,
|
|
3515
|
-
flowControl
|
|
3543
|
+
flowControl,
|
|
3544
|
+
label
|
|
3516
3545
|
});
|
|
3517
3546
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
3518
3547
|
routeFunction,
|
package/nextjs.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/workflow","version":"v0.2.
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.2.19","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":{"@ai-sdk/anthropic":"^1.1.15","@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.3","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^5.1.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","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":{"@ai-sdk/openai":"^1.2.1","@upstash/qstash":"^2.8.2","ai":"^4.1.54","zod":"^3.24.1"},"directories":{"example":"examples"}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PublicServeOptions, R as RouteFunction, x as InvokableWorkflow } from './types
|
|
1
|
+
import { n as PublicServeOptions, R as RouteFunction, x as InvokableWorkflow } from './types-B7_5AkKQ.js';
|
|
2
2
|
|
|
3
3
|
type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
|
|
4
4
|
declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PublicServeOptions, R as RouteFunction, x as InvokableWorkflow } from './types
|
|
1
|
+
import { n as PublicServeOptions, R as RouteFunction, x as InvokableWorkflow } from './types-B7_5AkKQ.mjs';
|
|
2
2
|
|
|
3
3
|
type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
|
|
4
4
|
declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
|
package/solidjs.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, n as PublicServeOptions } from './types
|
|
2
|
+
import { R as RouteFunction, n as PublicServeOptions } from './types-B7_5AkKQ.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
package/solidjs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, n as PublicServeOptions } from './types
|
|
2
|
+
import { R as RouteFunction, n as PublicServeOptions } from './types-B7_5AkKQ.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|