@upstash/workflow 0.2.1 → 0.2.2
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 +121 -75
- package/astro.mjs +5 -5
- package/{chunk-ADOBNR4O.mjs → chunk-Z7WS5XIR.mjs} +96 -221
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +121 -75
- package/cloudflare.mjs +5 -5
- package/express.d.mts +1 -1
- package/express.d.ts +1 -1
- package/express.js +133 -80
- package/express.mjs +17 -10
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +121 -75
- package/h3.mjs +5 -5
- package/hono.d.mts +4 -2
- package/hono.d.ts +4 -2
- package/hono.js +121 -75
- package/hono.mjs +5 -5
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +125 -73
- package/index.mjs +189 -3
- package/nextjs.d.mts +3 -3
- package/nextjs.d.ts +3 -3
- package/nextjs.js +122 -76
- package/nextjs.mjs +6 -6
- package/package.json +1 -1
- package/solidjs.d.mts +2 -2
- package/solidjs.d.ts +2 -2
- package/solidjs.js +121 -75
- package/solidjs.mjs +5 -5
- package/svelte.d.mts +3 -3
- package/svelte.d.ts +3 -3
- package/svelte.js +124 -75
- package/svelte.mjs +8 -5
- package/{types-Be4hC1mu.d.mts → types-APRap-aV.d.mts} +10 -2
- package/{types-Be4hC1mu.d.ts → types-APRap-aV.d.ts} +10 -2
package/express.js
CHANGED
|
@@ -23556,52 +23556,12 @@ var require_express2 = __commonJS({
|
|
|
23556
23556
|
// platforms/express.ts
|
|
23557
23557
|
var express_exports = {};
|
|
23558
23558
|
__export(express_exports, {
|
|
23559
|
-
serve: () =>
|
|
23559
|
+
serve: () => serve
|
|
23560
23560
|
});
|
|
23561
23561
|
module.exports = __toCommonJS(express_exports);
|
|
23562
23562
|
|
|
23563
|
-
// src/error.ts
|
|
23564
|
-
var import_qstash = require("@upstash/qstash");
|
|
23565
|
-
var WorkflowError = class extends import_qstash.QstashError {
|
|
23566
|
-
constructor(message) {
|
|
23567
|
-
super(message);
|
|
23568
|
-
this.name = "WorkflowError";
|
|
23569
|
-
}
|
|
23570
|
-
};
|
|
23571
|
-
var WorkflowAbort = class extends Error {
|
|
23572
|
-
stepInfo;
|
|
23573
|
-
stepName;
|
|
23574
|
-
/**
|
|
23575
|
-
* whether workflow is to be canceled on abort
|
|
23576
|
-
*/
|
|
23577
|
-
cancelWorkflow;
|
|
23578
|
-
/**
|
|
23579
|
-
*
|
|
23580
|
-
* @param stepName name of the aborting step
|
|
23581
|
-
* @param stepInfo step information
|
|
23582
|
-
* @param cancelWorkflow
|
|
23583
|
-
*/
|
|
23584
|
-
constructor(stepName, stepInfo, cancelWorkflow = false) {
|
|
23585
|
-
super(
|
|
23586
|
-
`This is an Upstash Workflow error thrown after a step executes. It is expected to be raised. Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch. Aborting workflow after executing step '${stepName}'.`
|
|
23587
|
-
);
|
|
23588
|
-
this.name = "WorkflowAbort";
|
|
23589
|
-
this.stepName = stepName;
|
|
23590
|
-
this.stepInfo = stepInfo;
|
|
23591
|
-
this.cancelWorkflow = cancelWorkflow;
|
|
23592
|
-
}
|
|
23593
|
-
};
|
|
23594
|
-
var formatWorkflowError = (error) => {
|
|
23595
|
-
return error instanceof Error ? {
|
|
23596
|
-
error: error.name,
|
|
23597
|
-
message: error.message
|
|
23598
|
-
} : {
|
|
23599
|
-
error: "Error",
|
|
23600
|
-
message: "An error occured while executing workflow."
|
|
23601
|
-
};
|
|
23602
|
-
};
|
|
23603
|
-
|
|
23604
23563
|
// src/client/utils.ts
|
|
23564
|
+
var import_qstash = require("@upstash/qstash");
|
|
23605
23565
|
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
23606
23566
|
const result = await requester.request({
|
|
23607
23567
|
path: ["v2", "notify", eventId],
|
|
@@ -23628,27 +23588,72 @@ var getSteps = async (requester, workflowRunId, messageId, debug) => {
|
|
|
23628
23588
|
await debug?.log("INFO", "ENDPOINT_START", {
|
|
23629
23589
|
message: `Pulled ${steps.length} steps from QStashand returned them without filtering with messageId.`
|
|
23630
23590
|
});
|
|
23631
|
-
return steps;
|
|
23591
|
+
return { steps, workflowRunEnded: false };
|
|
23632
23592
|
} else {
|
|
23633
23593
|
const index = steps.findIndex((item) => item.messageId === messageId);
|
|
23634
23594
|
if (index === -1) {
|
|
23635
|
-
return [];
|
|
23595
|
+
return { steps: [], workflowRunEnded: false };
|
|
23636
23596
|
}
|
|
23637
23597
|
const filteredSteps = steps.slice(0, index + 1);
|
|
23638
23598
|
await debug?.log("INFO", "ENDPOINT_START", {
|
|
23639
23599
|
message: `Pulled ${steps.length} steps from QStash and filtered them to ${filteredSteps.length} using messageId.`
|
|
23640
23600
|
});
|
|
23641
|
-
return filteredSteps;
|
|
23601
|
+
return { steps: filteredSteps, workflowRunEnded: false };
|
|
23642
23602
|
}
|
|
23643
23603
|
} catch (error) {
|
|
23644
|
-
|
|
23645
|
-
|
|
23646
|
-
|
|
23647
|
-
|
|
23648
|
-
|
|
23604
|
+
if (error instanceof import_qstash.QstashError && error.status === 404) {
|
|
23605
|
+
await debug?.log("WARN", "ENDPOINT_START", {
|
|
23606
|
+
message: "Couldn't fetch workflow run steps. This can happen if the workflow run succesfully ends before some callback is executed.",
|
|
23607
|
+
error
|
|
23608
|
+
});
|
|
23609
|
+
return { steps: void 0, workflowRunEnded: true };
|
|
23610
|
+
} else {
|
|
23611
|
+
throw error;
|
|
23612
|
+
}
|
|
23649
23613
|
}
|
|
23650
23614
|
};
|
|
23651
23615
|
|
|
23616
|
+
// src/error.ts
|
|
23617
|
+
var import_qstash2 = require("@upstash/qstash");
|
|
23618
|
+
var WorkflowError = class extends import_qstash2.QstashError {
|
|
23619
|
+
constructor(message) {
|
|
23620
|
+
super(message);
|
|
23621
|
+
this.name = "WorkflowError";
|
|
23622
|
+
}
|
|
23623
|
+
};
|
|
23624
|
+
var WorkflowAbort = class extends Error {
|
|
23625
|
+
stepInfo;
|
|
23626
|
+
stepName;
|
|
23627
|
+
/**
|
|
23628
|
+
* whether workflow is to be canceled on abort
|
|
23629
|
+
*/
|
|
23630
|
+
cancelWorkflow;
|
|
23631
|
+
/**
|
|
23632
|
+
*
|
|
23633
|
+
* @param stepName name of the aborting step
|
|
23634
|
+
* @param stepInfo step information
|
|
23635
|
+
* @param cancelWorkflow
|
|
23636
|
+
*/
|
|
23637
|
+
constructor(stepName, stepInfo, cancelWorkflow = false) {
|
|
23638
|
+
super(
|
|
23639
|
+
`This is an Upstash Workflow error thrown after a step executes. It is expected to be raised. Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch. Aborting workflow after executing step '${stepName}'.`
|
|
23640
|
+
);
|
|
23641
|
+
this.name = "WorkflowAbort";
|
|
23642
|
+
this.stepName = stepName;
|
|
23643
|
+
this.stepInfo = stepInfo;
|
|
23644
|
+
this.cancelWorkflow = cancelWorkflow;
|
|
23645
|
+
}
|
|
23646
|
+
};
|
|
23647
|
+
var formatWorkflowError = (error) => {
|
|
23648
|
+
return error instanceof Error ? {
|
|
23649
|
+
error: error.name,
|
|
23650
|
+
message: error.message
|
|
23651
|
+
} : {
|
|
23652
|
+
error: "Error",
|
|
23653
|
+
message: "An error occured while executing workflow."
|
|
23654
|
+
};
|
|
23655
|
+
};
|
|
23656
|
+
|
|
23652
23657
|
// src/context/steps.ts
|
|
23653
23658
|
var BaseLazyStep = class {
|
|
23654
23659
|
stepName;
|
|
@@ -24269,8 +24274,8 @@ var StepTypes = [
|
|
|
24269
24274
|
];
|
|
24270
24275
|
|
|
24271
24276
|
// src/workflow-requests.ts
|
|
24272
|
-
var
|
|
24273
|
-
var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
24277
|
+
var import_qstash3 = require("@upstash/qstash");
|
|
24278
|
+
var triggerFirstInvocation = async (workflowContext, retries, useJSONContent, debug) => {
|
|
24274
24279
|
const { headers } = getHeaders(
|
|
24275
24280
|
"true",
|
|
24276
24281
|
workflowContext.workflowRunId,
|
|
@@ -24280,6 +24285,9 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
24280
24285
|
workflowContext.failureUrl,
|
|
24281
24286
|
retries
|
|
24282
24287
|
);
|
|
24288
|
+
if (useJSONContent) {
|
|
24289
|
+
headers["content-type"] = "application/json";
|
|
24290
|
+
}
|
|
24283
24291
|
try {
|
|
24284
24292
|
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
24285
24293
|
const result = await workflowContext.qstashClient.publish({
|
|
@@ -24323,7 +24331,7 @@ var triggerRouteFunction = async ({
|
|
|
24323
24331
|
return ok("workflow-finished");
|
|
24324
24332
|
} catch (error) {
|
|
24325
24333
|
const error_ = error;
|
|
24326
|
-
if (error instanceof
|
|
24334
|
+
if (error instanceof import_qstash3.QstashError && error.status === 400) {
|
|
24327
24335
|
await debug?.log("WARN", "RESPONSE_WORKFLOW", {
|
|
24328
24336
|
message: `tried to append to a cancelled workflow. exiting without publishing.`,
|
|
24329
24337
|
name: error.name,
|
|
@@ -24357,7 +24365,7 @@ var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
|
24357
24365
|
);
|
|
24358
24366
|
return { deleted: true };
|
|
24359
24367
|
} catch (error) {
|
|
24360
|
-
if (error instanceof
|
|
24368
|
+
if (error instanceof import_qstash3.QstashError && error.status === 404) {
|
|
24361
24369
|
await debug?.log("WARN", "SUBMIT_CLEANUP", {
|
|
24362
24370
|
message: `Failed to remove workflow run ${workflowContext.workflowRunId} as it doesn't exist.`,
|
|
24363
24371
|
name: error.name,
|
|
@@ -24394,11 +24402,19 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
|
|
|
24394
24402
|
if (!workflowRunId2)
|
|
24395
24403
|
throw new WorkflowError("workflow run id missing in context.call lazy fetch.");
|
|
24396
24404
|
if (!messageId) throw new WorkflowError("message id missing in context.call lazy fetch.");
|
|
24397
|
-
const steps = await getSteps(
|
|
24405
|
+
const { steps, workflowRunEnded } = await getSteps(
|
|
24406
|
+
client.http,
|
|
24407
|
+
workflowRunId2,
|
|
24408
|
+
messageId,
|
|
24409
|
+
debug
|
|
24410
|
+
);
|
|
24411
|
+
if (workflowRunEnded) {
|
|
24412
|
+
return ok("workflow-ended");
|
|
24413
|
+
}
|
|
24398
24414
|
const failingStep = steps.find((step) => step.messageId === messageId);
|
|
24399
24415
|
if (!failingStep)
|
|
24400
24416
|
throw new WorkflowError(
|
|
24401
|
-
"Failed to submit the context.call." + (steps.length === 0 ? "No steps found." : `No step was found with matching messageId ${messageId} out of ${steps.length} steps.`)
|
|
24417
|
+
"Failed to submit the context.call. " + (steps.length === 0 ? "No steps found." : `No step was found with matching messageId ${messageId} out of ${steps.length} steps.`)
|
|
24402
24418
|
);
|
|
24403
24419
|
callbackPayload = atob(failingStep.body);
|
|
24404
24420
|
}
|
|
@@ -25437,7 +25453,7 @@ function decodeBase64(base64) {
|
|
|
25437
25453
|
}
|
|
25438
25454
|
|
|
25439
25455
|
// src/serve/authorization.ts
|
|
25440
|
-
var
|
|
25456
|
+
var import_qstash4 = require("@upstash/qstash");
|
|
25441
25457
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
25442
25458
|
static disabledMessage = "disabled-qstash-worklfow-run";
|
|
25443
25459
|
/**
|
|
@@ -25468,7 +25484,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
25468
25484
|
*/
|
|
25469
25485
|
static async tryAuthentication(routeFunction, context) {
|
|
25470
25486
|
const disabledContext = new _DisabledWorkflowContext({
|
|
25471
|
-
qstashClient: new
|
|
25487
|
+
qstashClient: new import_qstash4.Client({
|
|
25472
25488
|
baseUrl: "disabled-client",
|
|
25473
25489
|
token: "disabled-client"
|
|
25474
25490
|
}),
|
|
@@ -25592,7 +25608,8 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
|
|
|
25592
25608
|
return {
|
|
25593
25609
|
rawInitialPayload: requestPayload ?? "",
|
|
25594
25610
|
steps: [],
|
|
25595
|
-
isLastDuplicate: false
|
|
25611
|
+
isLastDuplicate: false,
|
|
25612
|
+
workflowRunEnded: false
|
|
25596
25613
|
};
|
|
25597
25614
|
} else {
|
|
25598
25615
|
let rawSteps;
|
|
@@ -25602,7 +25619,21 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
|
|
|
25602
25619
|
"ENDPOINT_START",
|
|
25603
25620
|
"request payload is empty, steps will be fetched from QStash."
|
|
25604
25621
|
);
|
|
25605
|
-
|
|
25622
|
+
const { steps: fetchedSteps, workflowRunEnded } = await getSteps(
|
|
25623
|
+
requester,
|
|
25624
|
+
workflowRunId,
|
|
25625
|
+
messageId,
|
|
25626
|
+
debug
|
|
25627
|
+
);
|
|
25628
|
+
if (workflowRunEnded) {
|
|
25629
|
+
return {
|
|
25630
|
+
rawInitialPayload: void 0,
|
|
25631
|
+
steps: void 0,
|
|
25632
|
+
isLastDuplicate: void 0,
|
|
25633
|
+
workflowRunEnded: true
|
|
25634
|
+
};
|
|
25635
|
+
}
|
|
25636
|
+
rawSteps = fetchedSteps;
|
|
25606
25637
|
} else {
|
|
25607
25638
|
rawSteps = JSON.parse(requestPayload);
|
|
25608
25639
|
}
|
|
@@ -25612,7 +25643,8 @@ var parseRequest = async (requestPayload, isFirstInvocation, workflowRunId, requ
|
|
|
25612
25643
|
return {
|
|
25613
25644
|
rawInitialPayload,
|
|
25614
25645
|
steps: deduplicatedSteps,
|
|
25615
|
-
isLastDuplicate
|
|
25646
|
+
isLastDuplicate,
|
|
25647
|
+
workflowRunEnded: false
|
|
25616
25648
|
};
|
|
25617
25649
|
}
|
|
25618
25650
|
};
|
|
@@ -25666,15 +25698,15 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
25666
25698
|
};
|
|
25667
25699
|
|
|
25668
25700
|
// src/serve/options.ts
|
|
25669
|
-
var import_qstash4 = require("@upstash/qstash");
|
|
25670
25701
|
var import_qstash5 = require("@upstash/qstash");
|
|
25702
|
+
var import_qstash6 = require("@upstash/qstash");
|
|
25671
25703
|
var processOptions = (options) => {
|
|
25672
25704
|
const environment = options?.env ?? (typeof process === "undefined" ? {} : process.env);
|
|
25673
25705
|
const receiverEnvironmentVariablesSet = Boolean(
|
|
25674
25706
|
environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
|
|
25675
25707
|
);
|
|
25676
25708
|
return {
|
|
25677
|
-
qstashClient: new
|
|
25709
|
+
qstashClient: new import_qstash6.Client({
|
|
25678
25710
|
baseUrl: environment.QSTASH_URL,
|
|
25679
25711
|
token: environment.QSTASH_TOKEN
|
|
25680
25712
|
}),
|
|
@@ -25708,13 +25740,14 @@ var processOptions = (options) => {
|
|
|
25708
25740
|
throw error;
|
|
25709
25741
|
}
|
|
25710
25742
|
},
|
|
25711
|
-
receiver: receiverEnvironmentVariablesSet ? new
|
|
25743
|
+
receiver: receiverEnvironmentVariablesSet ? new import_qstash5.Receiver({
|
|
25712
25744
|
currentSigningKey: environment.QSTASH_CURRENT_SIGNING_KEY,
|
|
25713
25745
|
nextSigningKey: environment.QSTASH_NEXT_SIGNING_KEY
|
|
25714
25746
|
}) : void 0,
|
|
25715
25747
|
baseUrl: environment.UPSTASH_WORKFLOW_URL,
|
|
25716
25748
|
env: environment,
|
|
25717
25749
|
retries: DEFAULT_RETRIES,
|
|
25750
|
+
useJSONContent: false,
|
|
25718
25751
|
...options
|
|
25719
25752
|
};
|
|
25720
25753
|
};
|
|
@@ -25731,6 +25764,16 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
25731
25764
|
});
|
|
25732
25765
|
}
|
|
25733
25766
|
const workflowFailureUrl = failureFunction ? workflowUrl : failureUrl;
|
|
25767
|
+
if (workflowUrl.includes("localhost")) {
|
|
25768
|
+
await debug?.log("WARN", "ENDPOINT_START", {
|
|
25769
|
+
message: `Workflow URL contains localhost. This can happen in local development, but shouldn't happen in production unless you have a route which contains localhost. Received: ${workflowUrl}`
|
|
25770
|
+
});
|
|
25771
|
+
}
|
|
25772
|
+
if (!(workflowUrl.startsWith("http://") || workflowUrl.startsWith("https://"))) {
|
|
25773
|
+
throw new WorkflowError(
|
|
25774
|
+
`Workflow URL should start with 'http://' or 'https://'. Recevied is '${workflowUrl}'`
|
|
25775
|
+
);
|
|
25776
|
+
}
|
|
25734
25777
|
return {
|
|
25735
25778
|
workflowUrl,
|
|
25736
25779
|
workflowFailureUrl
|
|
@@ -25739,7 +25782,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
25739
25782
|
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`;
|
|
25740
25783
|
|
|
25741
25784
|
// src/serve/index.ts
|
|
25742
|
-
var
|
|
25785
|
+
var serveBase = (routeFunction, options) => {
|
|
25743
25786
|
const {
|
|
25744
25787
|
qstashClient,
|
|
25745
25788
|
onStepFinish,
|
|
@@ -25751,7 +25794,8 @@ var serve = (routeFunction, options) => {
|
|
|
25751
25794
|
failureFunction,
|
|
25752
25795
|
baseUrl,
|
|
25753
25796
|
env,
|
|
25754
|
-
retries
|
|
25797
|
+
retries,
|
|
25798
|
+
useJSONContent
|
|
25755
25799
|
} = processOptions(options);
|
|
25756
25800
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
25757
25801
|
const handler = async (request) => {
|
|
@@ -25768,7 +25812,7 @@ var serve = (routeFunction, options) => {
|
|
|
25768
25812
|
await verifyRequest(requestPayload, request.headers.get("upstash-signature"), receiver);
|
|
25769
25813
|
const { isFirstInvocation, workflowRunId } = validateRequest(request);
|
|
25770
25814
|
debug?.setWorkflowRunId(workflowRunId);
|
|
25771
|
-
const { rawInitialPayload, steps, isLastDuplicate } = await parseRequest(
|
|
25815
|
+
const { rawInitialPayload, steps, isLastDuplicate, workflowRunEnded } = await parseRequest(
|
|
25772
25816
|
requestPayload,
|
|
25773
25817
|
isFirstInvocation,
|
|
25774
25818
|
workflowRunId,
|
|
@@ -25776,8 +25820,11 @@ var serve = (routeFunction, options) => {
|
|
|
25776
25820
|
request.headers.get("upstash-message-id"),
|
|
25777
25821
|
debug
|
|
25778
25822
|
);
|
|
25823
|
+
if (workflowRunEnded) {
|
|
25824
|
+
return onStepFinish(workflowRunId, "workflow-already-ended");
|
|
25825
|
+
}
|
|
25779
25826
|
if (isLastDuplicate) {
|
|
25780
|
-
return onStepFinish(
|
|
25827
|
+
return onStepFinish(workflowRunId, "duplicate-step");
|
|
25781
25828
|
}
|
|
25782
25829
|
const failureCheck = await handleFailure(
|
|
25783
25830
|
request,
|
|
@@ -25791,7 +25838,7 @@ var serve = (routeFunction, options) => {
|
|
|
25791
25838
|
throw failureCheck.error;
|
|
25792
25839
|
} else if (failureCheck.value === "is-failure-callback") {
|
|
25793
25840
|
await debug?.log("WARN", "RESPONSE_DEFAULT", "failureFunction executed");
|
|
25794
|
-
return onStepFinish(
|
|
25841
|
+
return onStepFinish(workflowRunId, "failure-callback");
|
|
25795
25842
|
}
|
|
25796
25843
|
const workflowContext = new WorkflowContext({
|
|
25797
25844
|
qstashClient,
|
|
@@ -25834,7 +25881,7 @@ var serve = (routeFunction, options) => {
|
|
|
25834
25881
|
});
|
|
25835
25882
|
throw callReturnCheck.error;
|
|
25836
25883
|
} else if (callReturnCheck.value === "continue-workflow") {
|
|
25837
|
-
const result = isFirstInvocation ? await triggerFirstInvocation(workflowContext, retries, debug) : await triggerRouteFunction({
|
|
25884
|
+
const result = isFirstInvocation ? await triggerFirstInvocation(workflowContext, retries, useJSONContent, debug) : await triggerRouteFunction({
|
|
25838
25885
|
onStep: async () => routeFunction(workflowContext),
|
|
25839
25886
|
onCleanup: async () => {
|
|
25840
25887
|
await triggerWorkflowDelete(workflowContext, debug);
|
|
@@ -25850,6 +25897,8 @@ var serve = (routeFunction, options) => {
|
|
|
25850
25897
|
}
|
|
25851
25898
|
await debug?.log("INFO", "RESPONSE_WORKFLOW");
|
|
25852
25899
|
return onStepFinish(workflowContext.workflowRunId, "success");
|
|
25900
|
+
} else if (callReturnCheck.value === "workflow-ended") {
|
|
25901
|
+
return onStepFinish(workflowContext.workflowRunId, "workflow-already-ended");
|
|
25853
25902
|
}
|
|
25854
25903
|
await debug?.log("INFO", "RESPONSE_DEFAULT");
|
|
25855
25904
|
return onStepFinish("no-workflow-id", "fromCallback");
|
|
@@ -25867,21 +25916,22 @@ var serve = (routeFunction, options) => {
|
|
|
25867
25916
|
return { handler: safeHandler };
|
|
25868
25917
|
};
|
|
25869
25918
|
|
|
25870
|
-
// src/client/index.ts
|
|
25871
|
-
var import_qstash6 = require("@upstash/qstash");
|
|
25872
|
-
|
|
25873
25919
|
// platforms/express.ts
|
|
25874
25920
|
var import_express = __toESM(require_express2());
|
|
25875
|
-
function
|
|
25921
|
+
function serve(routeFunction, options) {
|
|
25876
25922
|
const router = (0, import_express.Router)();
|
|
25877
25923
|
const handler = async (request_, res) => {
|
|
25878
25924
|
if (request_.method.toUpperCase() !== "POST") {
|
|
25879
25925
|
res.status(405).json("Only POST requests are allowed in workflows");
|
|
25880
25926
|
return;
|
|
25881
25927
|
}
|
|
25882
|
-
|
|
25883
|
-
|
|
25884
|
-
|
|
25928
|
+
let requestBody;
|
|
25929
|
+
if (request_.headers["content-type"]?.includes("text/plain")) {
|
|
25930
|
+
requestBody = request_.body;
|
|
25931
|
+
} else if (request_.headers["content-type"]?.includes("application/json")) {
|
|
25932
|
+
requestBody = JSON.stringify(request_.body);
|
|
25933
|
+
} else {
|
|
25934
|
+
requestBody = typeof request_.body === "string" ? request_.body : JSON.stringify(request_.body);
|
|
25885
25935
|
}
|
|
25886
25936
|
const protocol = request_.protocol;
|
|
25887
25937
|
const host = request_.get("host") || "localhost";
|
|
@@ -25889,11 +25939,14 @@ function serve2(routeFunction, options) {
|
|
|
25889
25939
|
const webRequest = new Request(url, {
|
|
25890
25940
|
method: request_.method,
|
|
25891
25941
|
headers: new Headers(request_.headers),
|
|
25892
|
-
body:
|
|
25942
|
+
body: requestBody
|
|
25893
25943
|
});
|
|
25894
|
-
const { handler: serveHandler } =
|
|
25944
|
+
const { handler: serveHandler } = serveBase(
|
|
25895
25945
|
(workflowContext) => routeFunction(workflowContext),
|
|
25896
|
-
|
|
25946
|
+
{
|
|
25947
|
+
...options,
|
|
25948
|
+
useJSONContent: true
|
|
25949
|
+
}
|
|
25897
25950
|
);
|
|
25898
25951
|
const response = await serveHandler(webRequest);
|
|
25899
25952
|
res.status(response.status).json(await response.json());
|
package/express.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
__commonJS,
|
|
3
3
|
__require,
|
|
4
4
|
__toESM,
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
serveBase
|
|
6
|
+
} from "./chunk-Z7WS5XIR.mjs";
|
|
7
7
|
|
|
8
8
|
// node_modules/depd/index.js
|
|
9
9
|
var require_depd = __commonJS({
|
|
@@ -23530,16 +23530,20 @@ var require_express2 = __commonJS({
|
|
|
23530
23530
|
|
|
23531
23531
|
// platforms/express.ts
|
|
23532
23532
|
var import_express = __toESM(require_express2());
|
|
23533
|
-
function
|
|
23533
|
+
function serve(routeFunction, options) {
|
|
23534
23534
|
const router = (0, import_express.Router)();
|
|
23535
23535
|
const handler = async (request_, res) => {
|
|
23536
23536
|
if (request_.method.toUpperCase() !== "POST") {
|
|
23537
23537
|
res.status(405).json("Only POST requests are allowed in workflows");
|
|
23538
23538
|
return;
|
|
23539
23539
|
}
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23540
|
+
let requestBody;
|
|
23541
|
+
if (request_.headers["content-type"]?.includes("text/plain")) {
|
|
23542
|
+
requestBody = request_.body;
|
|
23543
|
+
} else if (request_.headers["content-type"]?.includes("application/json")) {
|
|
23544
|
+
requestBody = JSON.stringify(request_.body);
|
|
23545
|
+
} else {
|
|
23546
|
+
requestBody = typeof request_.body === "string" ? request_.body : JSON.stringify(request_.body);
|
|
23543
23547
|
}
|
|
23544
23548
|
const protocol = request_.protocol;
|
|
23545
23549
|
const host = request_.get("host") || "localhost";
|
|
@@ -23547,11 +23551,14 @@ function serve2(routeFunction, options) {
|
|
|
23547
23551
|
const webRequest = new Request(url, {
|
|
23548
23552
|
method: request_.method,
|
|
23549
23553
|
headers: new Headers(request_.headers),
|
|
23550
|
-
body:
|
|
23554
|
+
body: requestBody
|
|
23551
23555
|
});
|
|
23552
|
-
const { handler: serveHandler } =
|
|
23556
|
+
const { handler: serveHandler } = serveBase(
|
|
23553
23557
|
(workflowContext) => routeFunction(workflowContext),
|
|
23554
|
-
|
|
23558
|
+
{
|
|
23559
|
+
...options,
|
|
23560
|
+
useJSONContent: true
|
|
23561
|
+
}
|
|
23555
23562
|
);
|
|
23556
23563
|
const response = await serveHandler(webRequest);
|
|
23557
23564
|
res.status(response.status).json(await response.json());
|
|
@@ -23560,7 +23567,7 @@ function serve2(routeFunction, options) {
|
|
|
23560
23567
|
return router;
|
|
23561
23568
|
}
|
|
23562
23569
|
export {
|
|
23563
|
-
|
|
23570
|
+
serve
|
|
23564
23571
|
};
|
|
23565
23572
|
/*! Bundled license information:
|
|
23566
23573
|
|
package/h3.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction,
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-APRap-aV.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?:
|
|
5
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
6
6
|
handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
7
7
|
status: number;
|
|
8
8
|
body: string;
|
package/h3.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as h3 from 'h3';
|
|
2
|
-
import { R as RouteFunction,
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-APRap-aV.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?:
|
|
5
|
+
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
6
6
|
handler: h3.EventHandler<h3.EventHandlerRequest, Promise<Response | {
|
|
7
7
|
status: number;
|
|
8
8
|
body: string;
|