@farm.js/core 0.1.17 → 0.1.18
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/dist/after.cjs +12 -225
- package/dist/agent-runtime.cjs +83 -2800
- package/dist/api/client.cjs +17 -4060
- package/dist/api/route-manager.cjs +34 -4354
- package/dist/api/runtime.cjs +29 -2696
- package/dist/api.cjs +88 -8434
- package/dist/app-markdown.cjs +39 -280
- package/dist/cache.cjs +38 -1560
- package/dist/chunk-22GUSVNJ.cjs +351 -0
- package/dist/chunk-2CQ74SP6.cjs +13 -0
- package/dist/chunk-2SJ4RQ6P.cjs +57 -0
- package/dist/chunk-3376ZTRC.cjs +1 -0
- package/dist/{chunk-YD4J4XCI.mjs → chunk-3XG26Z3J.mjs} +1 -1
- package/dist/chunk-4PNUXIVU.cjs +472 -0
- package/dist/chunk-4PPEPOZZ.cjs +21 -0
- package/dist/chunk-4ZFL5GFN.cjs +520 -0
- package/dist/chunk-5OVTOKGH.cjs +65 -0
- package/dist/chunk-5QIKR7RR.cjs +224 -0
- package/dist/chunk-5ZSWG4UX.cjs +127 -0
- package/dist/chunk-62YJ2IEB.cjs +238 -0
- package/dist/chunk-6EODJYCX.cjs +183 -0
- package/dist/chunk-6EXBPJ24.cjs +434 -0
- package/dist/chunk-6QQDAAAZ.cjs +38 -0
- package/dist/chunk-6V4TDWEC.cjs +455 -0
- package/dist/chunk-72ADZ6GQ.cjs +19 -0
- package/dist/chunk-75BRBIFP.cjs +172 -0
- package/dist/chunk-7W3CPVXS.cjs +24 -0
- package/dist/chunk-A6WIQH5Z.cjs +31 -0
- package/dist/chunk-AFOD3LYZ.cjs +377 -0
- package/dist/chunk-AMDMVWMI.cjs +39 -0
- package/dist/chunk-AORPIPNB.cjs +552 -0
- package/dist/chunk-ARJWXNQL.cjs +256 -0
- package/dist/chunk-AWRISO2H.cjs +2199 -0
- package/dist/chunk-AYJR42WX.cjs +711 -0
- package/dist/chunk-B4CH33IG.cjs +644 -0
- package/dist/chunk-BIDYX3SL.cjs +91 -0
- package/dist/chunk-BSTRERPP.cjs +40 -0
- package/dist/chunk-BYODCJD6.cjs +663 -0
- package/dist/chunk-C3VRMB6H.cjs +85 -0
- package/dist/chunk-C5GUTBZK.cjs +173 -0
- package/dist/chunk-CIAGU2X4.cjs +337 -0
- package/dist/chunk-CMGMGHUZ.cjs +27 -0
- package/dist/chunk-CXP5U3RW.cjs +54 -0
- package/dist/chunk-D2ULAULS.cjs +166 -0
- package/dist/chunk-D7JTOLFK.cjs +285 -0
- package/dist/chunk-DVM4FKZL.cjs +169 -0
- package/dist/chunk-DYEJQTDN.cjs +49 -0
- package/dist/chunk-E2BMSZ2W.cjs +151 -0
- package/dist/chunk-E3UK5IIB.cjs +593 -0
- package/dist/chunk-EM6SBQKM.cjs +470 -0
- package/dist/chunk-FJSWYIR7.cjs +482 -0
- package/dist/chunk-FK6GO24V.cjs +54 -0
- package/dist/chunk-FXUUWYAX.cjs +654 -0
- package/dist/chunk-G3HRIVEY.cjs +395 -0
- package/dist/chunk-G643DQCH.cjs +13 -0
- package/dist/chunk-G7HXGLEC.cjs +175 -0
- package/dist/chunk-GDSHDTJ4.cjs +152 -0
- package/dist/chunk-GNEO2XOF.cjs +2040 -0
- package/dist/{chunk-56DAX2BE.mjs → chunk-GYKJCFTS.mjs} +1 -1
- package/dist/chunk-H6G5INWM.cjs +1094 -0
- package/dist/chunk-HBTUGXHS.cjs +180 -0
- package/dist/chunk-HREOKQWT.cjs +45 -0
- package/dist/chunk-I4J452B7.cjs +435 -0
- package/dist/chunk-I57LW5VZ.cjs +94 -0
- package/dist/chunk-I7PUUDGY.cjs +389 -0
- package/dist/chunk-IAMRBF3Z.cjs +86 -0
- package/dist/chunk-IKNRN4VS.cjs +14214 -0
- package/dist/chunk-IQXFRNY2.cjs +169 -0
- package/dist/chunk-IXTFU4PL.cjs +2355 -0
- package/dist/chunk-J2OP5GG3.cjs +725 -0
- package/dist/chunk-J3LOGE4T.cjs +42 -0
- package/dist/chunk-J7FSKED3.cjs +93 -0
- package/dist/chunk-JDNHKPTD.cjs +22 -0
- package/dist/chunk-JSROZYYO.cjs +164 -0
- package/dist/chunk-K6FNHVDR.cjs +696 -0
- package/dist/chunk-KGZIORNL.cjs +43 -0
- package/dist/{chunk-MVIWBEJF.mjs → chunk-KPNVGRBL.mjs} +1 -1
- package/dist/chunk-KR6CKSXT.cjs +15 -0
- package/dist/chunk-KROWKCUH.cjs +185 -0
- package/dist/chunk-KVFPGF2M.cjs +46 -0
- package/dist/chunk-LCCBO7PJ.cjs +46 -0
- package/dist/chunk-LIUGYUX3.cjs +22 -0
- package/dist/chunk-LTNGXMQ6.cjs +55 -0
- package/dist/chunk-M2L4MYDQ.cjs +14 -0
- package/dist/chunk-MCJLA63J.cjs +1 -0
- package/dist/chunk-MKB2EGIR.cjs +148 -0
- package/dist/chunk-MQ3H6LT5.cjs +202 -0
- package/dist/chunk-MT763TDW.cjs +43 -0
- package/dist/chunk-MWSK6C4J.cjs +18 -0
- package/dist/chunk-MWWVKDW3.cjs +169 -0
- package/dist/chunk-NO3WWW3N.cjs +192 -0
- package/dist/chunk-NV3A5DXM.cjs +862 -0
- package/dist/chunk-NWOD6NIT.cjs +9 -0
- package/dist/chunk-NZKJGRB3.cjs +230 -0
- package/dist/chunk-OAVTUMJP.cjs +1496 -0
- package/dist/chunk-OHY2ZWUG.cjs +25 -0
- package/dist/chunk-OI6CMLWX.cjs +47 -0
- package/dist/chunk-OIEOCXKG.cjs +453 -0
- package/dist/chunk-OWOUTKIJ.cjs +558 -0
- package/dist/chunk-OX6O6WVA.cjs +74 -0
- package/dist/chunk-OXSIH4D6.cjs +476 -0
- package/dist/chunk-OYEUREB6.cjs +35 -0
- package/dist/chunk-PCOTGFSM.cjs +139 -0
- package/dist/chunk-PZYCPSCC.cjs +35 -0
- package/dist/chunk-QBK2AA4U.cjs +445 -0
- package/dist/chunk-QBPXNZGV.cjs +487 -0
- package/dist/chunk-QNPEUFHQ.cjs +27 -0
- package/dist/chunk-QZRVZSPN.cjs +236 -0
- package/dist/chunk-R5A5KNVX.cjs +20 -0
- package/dist/chunk-R5JIFR6B.cjs +42 -0
- package/dist/chunk-R6AIILII.cjs +193 -0
- package/dist/chunk-RG3ZOTG5.cjs +34 -0
- package/dist/chunk-ROUTX2E5.cjs +390 -0
- package/dist/chunk-RTHIVJ2G.cjs +54 -0
- package/dist/chunk-S3A45T7F.cjs +166 -0
- package/dist/chunk-S3JO3N4H.cjs +17 -0
- package/dist/chunk-SK35NQKK.cjs +27 -0
- package/dist/chunk-SU7MH53P.cjs +180 -0
- package/dist/chunk-SVRTJOUF.cjs +113 -0
- package/dist/chunk-SWN467MP.cjs +18 -0
- package/dist/chunk-SYQ3MOWW.cjs +73 -0
- package/dist/chunk-T5CERMEH.cjs +417 -0
- package/dist/chunk-TFAXUHWX.cjs +206 -0
- package/dist/chunk-TIWHTW3Q.cjs +24 -0
- package/dist/chunk-TKJZFIML.cjs +20 -0
- package/dist/chunk-TKNSDBBN.cjs +193 -0
- package/dist/chunk-TWGMSEHX.cjs +525 -0
- package/dist/chunk-TYQUSXUG.cjs +1357 -0
- package/dist/chunk-U4KT7QP3.cjs +23 -0
- package/dist/chunk-UJ2C4ICS.cjs +277 -0
- package/dist/chunk-UN5GHC5V.cjs +10244 -0
- package/dist/chunk-UQZ4AYTH.cjs +168 -0
- package/dist/chunk-US2QVW3E.cjs +36 -0
- package/dist/chunk-VB6UCX3V.cjs +421 -0
- package/dist/chunk-VEKFLAQM.cjs +300 -0
- package/dist/chunk-VQDBNVOO.cjs +14 -0
- package/dist/chunk-W4E7WMXE.cjs +71 -0
- package/dist/chunk-WJ3HK3LJ.cjs +1102 -0
- package/dist/chunk-WMAPPDMM.cjs +28 -0
- package/dist/chunk-WMOGFOUJ.cjs +223 -0
- package/dist/chunk-WPYFSQKK.cjs +37 -0
- package/dist/chunk-WZMNW2IW.cjs +1415 -0
- package/dist/chunk-XGC343EY.cjs +443 -0
- package/dist/chunk-XSKZORAS.cjs +727 -0
- package/dist/chunk-XWAWFQFS.cjs +82 -0
- package/dist/chunk-Y4YMF2NQ.cjs +460 -0
- package/dist/chunk-Y4YWHNKU.cjs +250 -0
- package/dist/chunk-Y53ZSFN6.cjs +504 -0
- package/dist/chunk-YA6LLTIJ.cjs +411 -0
- package/dist/chunk-YFPGHF5F.cjs +202 -0
- package/dist/chunk-YJRZR7VU.cjs +28 -0
- package/dist/chunk-YTAABQEV.cjs +1 -0
- package/dist/chunk-YX3DBN4M.cjs +18 -0
- package/dist/chunk-YZTASLPQ.cjs +64 -0
- package/dist/chunk-Z5HIWVDP.cjs +2173 -0
- package/dist/chunk-ZEG3OPIB.cjs +93 -0
- package/dist/chunk-ZMN3H73H.cjs +155 -0
- package/dist/client/lifecycle.cjs +6 -35
- package/dist/client-plugins.cjs +7 -448
- package/dist/client.cjs +171 -9808
- package/dist/config.cjs +8 -36
- package/dist/cron.cjs +24 -491
- package/dist/deferred.cjs +26 -475
- package/dist/deployment.cjs +39 -210
- package/dist/devtools-OUIPHVV6.cjs +388 -0
- package/dist/devtools-client-4WAPJY5L.cjs +254 -0
- package/dist/devtools-ui-5GBDIGMK.cjs +1296 -0
- package/dist/docs.cjs +46 -5657
- package/dist/env-types.cjs +5 -226
- package/dist/env.cjs +21 -338
- package/dist/environment/vite.cjs +8 -372
- package/dist/environment.cjs +12 -94
- package/dist/font.cjs +13 -63
- package/dist/headers.cjs +7 -123
- package/dist/i18n/client.cjs +55 -294
- package/dist/i18n/index.cjs +22 -209
- package/dist/i18n/server.cjs +22 -745
- package/dist/image/server.cjs +13 -729
- package/dist/image/sharp.cjs +33 -171
- package/dist/image.cjs +41 -85
- package/dist/index.cjs +1151 -68080
- package/dist/index.mjs +3 -3
- package/dist/instrumentation.cjs +12 -138
- package/dist/integration-orm-55F7CII5.cjs +13 -0
- package/dist/integrations.cjs +55 -4090
- package/dist/internal/app-markdown-runtime.cjs +27 -224
- package/dist/internal/build-runtime.cjs +120 -52259
- package/dist/internal/build-runtime.mjs +3 -3
- package/dist/internal/cli-runtime.cjs +67 -13811
- package/dist/internal/client-error-overlay.cjs +80 -733
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/client-runtime.cjs +81 -913
- package/dist/internal/compression-runtime.cjs +8 -214
- package/dist/internal/config-runtime.cjs +42 -6547
- package/dist/internal/docs-precompiled-runtime.cjs +26 -46
- package/dist/internal/infra-analytics-runtime.cjs +10 -536
- package/dist/internal/isolated-boundary.cjs +14 -414
- package/dist/internal/metadata-image-runtime.cjs +7 -285
- package/dist/internal/product-telemetry-runtime.cjs +42 -97
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-node-env.cjs +6 -63
- package/dist/internal/production-runtime.cjs +418 -7133
- package/dist/internal/request-cookies.cjs +6 -54
- package/dist/json-ld.cjs +24 -50
- package/dist/layers-E4WPJNY5.cjs +17 -0
- package/dist/manager-G4B2IPYE.cjs +14 -0
- package/dist/markdown.cjs +21 -547
- package/dist/middleware.cjs +36 -2995
- package/dist/navigation.cjs +22 -2588
- package/dist/nitro-4I2MYLY2.cjs +652 -0
- package/dist/observability.cjs +22 -614
- package/dist/og.cjs +5 -28
- package/dist/plugin.cjs +106 -37442
- package/dist/plugin.mjs +2 -2
- package/dist/query/client.cjs +113 -449
- package/dist/query/index.cjs +26 -288
- package/dist/query/parsers.cjs +23 -247
- package/dist/query/server.cjs +36 -298
- package/dist/renderer/react/client.cjs +9 -43
- package/dist/renderer/react/server.cjs +40 -103
- package/dist/renderer/react/vite.cjs +7 -29
- package/dist/renderer-client.cjs +126 -4295
- package/dist/renderer.cjs +31 -249
- package/dist/request.cjs +5 -68
- package/dist/router.cjs +11 -474
- package/dist/routes.cjs +42 -2461
- package/dist/schema-dev-notice-MXSZMVDG.cjs +56 -0
- package/dist/schema.cjs +6 -33
- package/dist/search-client-G3RICOFU.cjs +13 -0
- package/dist/server-action-security.cjs +25 -541
- package/dist/server-fn-client.cjs +6 -337
- package/dist/server-fn.cjs +32 -1841
- package/dist/server-plugins.cjs +15 -884
- package/dist/server-query-client.cjs +15 -1883
- package/dist/server-query.cjs +16 -1838
- package/dist/server.cjs +296 -44681
- package/dist/server.mjs +2 -2
- package/dist/storage.cjs +57 -576
- package/dist/testing.cjs +89 -3186
- package/dist/theme/client.cjs +13 -108
- package/dist/theme/index.cjs +6 -68
- package/dist/theme/runtime.cjs +13 -78
- package/dist/theme/server.cjs +10 -179
- package/dist/version.cjs +4 -32
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +119 -37773
- package/dist/vite.mjs +2 -2
- package/dist/workflows.cjs +19 -1040
- package/package.json +1 -1
package/dist/workflows.cjs
CHANGED
|
@@ -1,1062 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
30
2
|
|
|
31
|
-
// src/workflows.ts
|
|
32
|
-
var workflows_exports = {};
|
|
33
|
-
__export(workflows_exports, {
|
|
34
|
-
DEFAULT_FARM_WORKFLOW_DIRS: () => DEFAULT_FARM_WORKFLOW_DIRS,
|
|
35
|
-
DEFAULT_FARM_WORKFLOW_ROUTE: () => DEFAULT_FARM_WORKFLOW_ROUTE,
|
|
36
|
-
DEFAULT_FARM_WORKFLOW_SECRET_ENV: () => DEFAULT_FARM_WORKFLOW_SECRET_ENV,
|
|
37
|
-
applyFarmWorkflowVercelCrons: () => applyFarmWorkflowVercelCrons,
|
|
38
|
-
createFarmWorkflowRequestHandler: () => createFarmWorkflowRequestHandler,
|
|
39
|
-
createFarmWorkflowVercelCrons: () => createFarmWorkflowVercelCrons,
|
|
40
|
-
defineCron: () => defineCron,
|
|
41
|
-
defineTask: () => defineTask,
|
|
42
|
-
defineWorkflow: () => defineWorkflow,
|
|
43
|
-
discoverFarmWorkflows: () => discoverFarmWorkflows,
|
|
44
|
-
prepareFarmWorkflowsForNitro: () => prepareFarmWorkflowsForNitro,
|
|
45
|
-
resolveWorkflowsConfig: () => resolveWorkflowsConfig,
|
|
46
|
-
runFarmWorkflowModule: () => runFarmWorkflowModule
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(workflows_exports);
|
|
49
3
|
|
|
50
|
-
// src/routing/specificity.ts
|
|
51
|
-
var _BrowserUnstableRouteError = class _BrowserUnstableRouteError extends TypeError {
|
|
52
|
-
constructor(message) {
|
|
53
|
-
super(message);
|
|
54
|
-
this.name = "BrowserUnstableRouteError";
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
__name(_BrowserUnstableRouteError, "BrowserUnstableRouteError");
|
|
58
|
-
var BrowserUnstableRouteError = _BrowserUnstableRouteError;
|
|
59
|
-
function assertBrowserStableRoutePath(pattern) {
|
|
60
|
-
if (pattern.includes("\\") || hasControlCharacter(pattern)) {
|
|
61
|
-
throw new BrowserUnstableRouteError(
|
|
62
|
-
`Route path "${pattern}" cannot contain backslashes or control characters.`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
66
|
-
if (segment.startsWith("(") && segment.endsWith(")") || segment.startsWith("[") && segment.endsWith("]")) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
let decoded = segment;
|
|
70
|
-
try {
|
|
71
|
-
decoded = decodeURIComponent(segment);
|
|
72
|
-
} catch {
|
|
73
|
-
}
|
|
74
|
-
if (decoded === "." || decoded === ".." || decoded.includes("/") || decoded.includes("\\") || hasControlCharacter(decoded)) {
|
|
75
|
-
throw new BrowserUnstableRouteError(
|
|
76
|
-
`Route path "${pattern}" contains browser-unstable segment "${segment}".`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
__name(assertBrowserStableRoutePath, "assertBrowserStableRoutePath");
|
|
82
|
-
function hasControlCharacter(value) {
|
|
83
|
-
return Array.from(value).some((character) => {
|
|
84
|
-
const code = character.charCodeAt(0);
|
|
85
|
-
return code <= 31 || code >= 127 && code <= 159;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
__name(hasControlCharacter, "hasControlCharacter");
|
|
89
4
|
|
|
90
|
-
// src/server-http.ts
|
|
91
|
-
var DEFAULT_FARM_SERVER_BODY_SIZE_LIMIT = 1e7;
|
|
92
|
-
var DEFAULT_FARM_SERVER_HEADERS_TIMEOUT = 6e4;
|
|
93
|
-
var DEFAULT_FARM_SERVER_REQUEST_TIMEOUT = 3e5;
|
|
94
|
-
var DEFAULT_FARM_SERVER_KEEP_ALIVE_TIMEOUT = 5e3;
|
|
95
|
-
var DEFAULT_FARM_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT = 3e4;
|
|
96
|
-
var MAX_FARM_SERVER_TIMEOUT = 2147483647;
|
|
97
|
-
var _FarmRequestBodyError = class _FarmRequestBodyError extends Error {
|
|
98
|
-
constructor(code, status, message) {
|
|
99
|
-
super(message);
|
|
100
|
-
this.name = "FarmRequestBodyError";
|
|
101
|
-
this.code = code;
|
|
102
|
-
this.status = status;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
__name(_FarmRequestBodyError, "FarmRequestBodyError");
|
|
106
|
-
var FarmRequestBodyError = _FarmRequestBodyError;
|
|
107
|
-
function resolveFarmServerConfig(config) {
|
|
108
|
-
const headersTimeout = parseFarmServerDuration(
|
|
109
|
-
config?.headersTimeout ?? DEFAULT_FARM_SERVER_HEADERS_TIMEOUT,
|
|
110
|
-
"server.headersTimeout"
|
|
111
|
-
);
|
|
112
|
-
const requestTimeout = parseFarmServerDuration(
|
|
113
|
-
config?.requestTimeout ?? DEFAULT_FARM_SERVER_REQUEST_TIMEOUT,
|
|
114
|
-
"server.requestTimeout"
|
|
115
|
-
);
|
|
116
|
-
if (headersTimeout > requestTimeout) {
|
|
117
|
-
throw new TypeError("server.headersTimeout must not exceed server.requestTimeout");
|
|
118
|
-
}
|
|
119
|
-
return Object.freeze({
|
|
120
|
-
bodySizeLimit: parseBodySizeLimit(
|
|
121
|
-
config?.bodySizeLimit ?? DEFAULT_FARM_SERVER_BODY_SIZE_LIMIT,
|
|
122
|
-
"server.bodySizeLimit"
|
|
123
|
-
),
|
|
124
|
-
trustProxy: config?.trustProxy === true,
|
|
125
|
-
headersTimeout,
|
|
126
|
-
requestTimeout,
|
|
127
|
-
keepAliveTimeout: parseFarmServerDuration(
|
|
128
|
-
config?.keepAliveTimeout ?? DEFAULT_FARM_SERVER_KEEP_ALIVE_TIMEOUT,
|
|
129
|
-
"server.keepAliveTimeout"
|
|
130
|
-
),
|
|
131
|
-
gracefulShutdownTimeout: parseFarmServerDuration(
|
|
132
|
-
config?.gracefulShutdownTimeout ?? DEFAULT_FARM_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT,
|
|
133
|
-
"server.gracefulShutdownTimeout"
|
|
134
|
-
),
|
|
135
|
-
health: resolveFarmServerHealthConfig(config?.health)
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
__name(resolveFarmServerConfig, "resolveFarmServerConfig");
|
|
139
|
-
function parseFarmServerDuration(value, optionName = "duration") {
|
|
140
|
-
if (typeof value === "number") {
|
|
141
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
142
|
-
throw new TypeError(`${optionName} must be a positive safe integer`);
|
|
143
|
-
}
|
|
144
|
-
if (value > MAX_FARM_SERVER_TIMEOUT) {
|
|
145
|
-
throw new TypeError(`${optionName} must not exceed ${MAX_FARM_SERVER_TIMEOUT} milliseconds`);
|
|
146
|
-
}
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
const match = value.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)$/);
|
|
150
|
-
if (!match) {
|
|
151
|
-
throw new TypeError(`${optionName} must be milliseconds or a duration such as "30s" or "2m"`);
|
|
152
|
-
}
|
|
153
|
-
const amount = Number(match[1]);
|
|
154
|
-
const unit = match[2];
|
|
155
|
-
const multiplier = unit === "ms" ? 1 : unit === "s" ? 1e3 : unit === "m" ? 6e4 : 36e5;
|
|
156
|
-
const milliseconds = Math.floor(amount * multiplier);
|
|
157
|
-
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) {
|
|
158
|
-
throw new TypeError(`${optionName} must resolve to a positive safe integer`);
|
|
159
|
-
}
|
|
160
|
-
if (milliseconds > MAX_FARM_SERVER_TIMEOUT) {
|
|
161
|
-
throw new TypeError(`${optionName} must not exceed ${MAX_FARM_SERVER_TIMEOUT} milliseconds`);
|
|
162
|
-
}
|
|
163
|
-
return milliseconds;
|
|
164
|
-
}
|
|
165
|
-
__name(parseFarmServerDuration, "parseFarmServerDuration");
|
|
166
|
-
function resolveFarmServerHealthConfig(config) {
|
|
167
|
-
if (config === false || config && "enabled" in config && config.enabled === false) {
|
|
168
|
-
return Object.freeze({
|
|
169
|
-
enabled: false,
|
|
170
|
-
livenessPath: "/_farm/health/live",
|
|
171
|
-
readinessPath: "/_farm/health/ready"
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
const livenessPath = normalizeHealthPath(
|
|
175
|
-
config?.livenessPath ?? "/_farm/health/live",
|
|
176
|
-
"server.health.livenessPath"
|
|
177
|
-
);
|
|
178
|
-
const readinessPath = normalizeHealthPath(
|
|
179
|
-
config?.readinessPath ?? "/_farm/health/ready",
|
|
180
|
-
"server.health.readinessPath"
|
|
181
|
-
);
|
|
182
|
-
if (livenessPath === readinessPath) {
|
|
183
|
-
throw new TypeError("server.health livenessPath and readinessPath must be different");
|
|
184
|
-
}
|
|
185
|
-
return Object.freeze({ enabled: true, livenessPath, readinessPath });
|
|
186
|
-
}
|
|
187
|
-
__name(resolveFarmServerHealthConfig, "resolveFarmServerHealthConfig");
|
|
188
|
-
function normalizeHealthPath(value, optionName) {
|
|
189
|
-
const path = value.trim();
|
|
190
|
-
if (!path.startsWith("/") || path.includes("?") || path.includes("#") || path.includes("*")) {
|
|
191
|
-
throw new TypeError(`${optionName} must be an absolute pathname without a query or wildcard`);
|
|
192
|
-
}
|
|
193
|
-
const normalized = path.length > 1 ? path.replace(/\/+$/, "") || "/" : path;
|
|
194
|
-
assertBrowserStableRoutePath(normalized);
|
|
195
|
-
return normalized;
|
|
196
|
-
}
|
|
197
|
-
__name(normalizeHealthPath, "normalizeHealthPath");
|
|
198
|
-
function parseBodySizeLimit(value, optionName = "bodySizeLimit") {
|
|
199
|
-
if (typeof value === "number") {
|
|
200
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
201
|
-
throw new TypeError(`${optionName} must be a positive safe integer`);
|
|
202
|
-
}
|
|
203
|
-
return value;
|
|
204
|
-
}
|
|
205
|
-
const match = value.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|kib|mib|gib)?$/);
|
|
206
|
-
if (!match) {
|
|
207
|
-
throw new TypeError(`${optionName} must be bytes or a size string such as "500kb" or "10mb"`);
|
|
208
|
-
}
|
|
209
|
-
const amount = Number(match[1]);
|
|
210
|
-
const unit = match[2] ?? "b";
|
|
211
|
-
const multiplier = {
|
|
212
|
-
b: 1,
|
|
213
|
-
kb: 1e3,
|
|
214
|
-
mb: 1e6,
|
|
215
|
-
gb: 1e9,
|
|
216
|
-
kib: 1024,
|
|
217
|
-
mib: 1048576,
|
|
218
|
-
gib: 1073741824
|
|
219
|
-
};
|
|
220
|
-
const bytes = Math.floor(amount * multiplier[unit]);
|
|
221
|
-
if (!Number.isSafeInteger(bytes) || bytes <= 0) {
|
|
222
|
-
throw new TypeError(`${optionName} must resolve to a positive safe integer`);
|
|
223
|
-
}
|
|
224
|
-
return bytes;
|
|
225
|
-
}
|
|
226
|
-
__name(parseBodySizeLimit, "parseBodySizeLimit");
|
|
227
|
-
async function readFarmRequestBody(request, limit) {
|
|
228
|
-
try {
|
|
229
|
-
validateContentLength(request.headers.get("content-length"), limit);
|
|
230
|
-
} catch (error) {
|
|
231
|
-
void request.body?.cancel(error).catch(() => {
|
|
232
|
-
});
|
|
233
|
-
throw error;
|
|
234
|
-
}
|
|
235
|
-
throwIfAborted(request.signal);
|
|
236
|
-
if (!request.body) return new Uint8Array();
|
|
237
|
-
const reader = request.body.getReader();
|
|
238
|
-
const chunks = [];
|
|
239
|
-
let total = 0;
|
|
240
|
-
const cancelBodyRead = /* @__PURE__ */ __name(() => {
|
|
241
|
-
void reader.cancel(request.signal.reason).catch(() => {
|
|
242
|
-
});
|
|
243
|
-
}, "cancelBodyRead");
|
|
244
|
-
request.signal.addEventListener("abort", cancelBodyRead, { once: true });
|
|
245
|
-
try {
|
|
246
|
-
while (true) {
|
|
247
|
-
throwIfAborted(request.signal);
|
|
248
|
-
const { done, value } = await reader.read();
|
|
249
|
-
throwIfAborted(request.signal);
|
|
250
|
-
if (done) break;
|
|
251
|
-
if (!value) continue;
|
|
252
|
-
total += value.byteLength;
|
|
253
|
-
if (total > limit) {
|
|
254
|
-
const error = new FarmRequestBodyError("BODY_TOO_LARGE", 413, "Request body is too large");
|
|
255
|
-
void reader.cancel(error).catch(() => {
|
|
256
|
-
});
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
chunks.push(value);
|
|
260
|
-
}
|
|
261
|
-
} catch (error) {
|
|
262
|
-
if (request.signal.aborted) throwIfAborted(request.signal);
|
|
263
|
-
throw error;
|
|
264
|
-
} finally {
|
|
265
|
-
request.signal.removeEventListener("abort", cancelBodyRead);
|
|
266
|
-
reader.releaseLock();
|
|
267
|
-
}
|
|
268
|
-
const body = new Uint8Array(total);
|
|
269
|
-
let offset = 0;
|
|
270
|
-
for (const chunk of chunks) {
|
|
271
|
-
body.set(chunk, offset);
|
|
272
|
-
offset += chunk.byteLength;
|
|
273
|
-
}
|
|
274
|
-
return body;
|
|
275
|
-
}
|
|
276
|
-
__name(readFarmRequestBody, "readFarmRequestBody");
|
|
277
|
-
function createFarmRequestBodyErrorResponse(error) {
|
|
278
|
-
if (!(error instanceof FarmRequestBodyError)) return null;
|
|
279
|
-
return new Response(error.status === 413 ? "Payload Too Large" : "Bad Request", {
|
|
280
|
-
status: error.status,
|
|
281
|
-
headers: {
|
|
282
|
-
"cache-control": "no-store",
|
|
283
|
-
"content-type": "text/plain; charset=utf-8",
|
|
284
|
-
"x-content-type-options": "nosniff"
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
__name(createFarmRequestBodyErrorResponse, "createFarmRequestBodyErrorResponse");
|
|
289
|
-
function validateContentLength(value, limit) {
|
|
290
|
-
const contentLength = value?.trim();
|
|
291
|
-
if (!contentLength) return;
|
|
292
|
-
if (!/^\d+$/.test(contentLength)) {
|
|
293
|
-
throw new FarmRequestBodyError("INVALID_CONTENT_LENGTH", 400, "Invalid content-length header");
|
|
294
|
-
}
|
|
295
|
-
if (Number(contentLength) > limit) {
|
|
296
|
-
throw new FarmRequestBodyError("BODY_TOO_LARGE", 413, "Request body is too large");
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
__name(validateContentLength, "validateContentLength");
|
|
300
|
-
function throwIfAborted(signal) {
|
|
301
|
-
if (!signal.aborted) return;
|
|
302
|
-
if (signal.reason !== void 0) throw signal.reason;
|
|
303
|
-
throw new DOMException("The operation was aborted", "AbortError");
|
|
304
|
-
}
|
|
305
|
-
__name(throwIfAborted, "throwIfAborted");
|
|
306
5
|
|
|
307
|
-
// src/search-params.ts
|
|
308
|
-
function searchParamsToObject(searchParams) {
|
|
309
|
-
const output = {};
|
|
310
|
-
searchParams.forEach((value, key) => {
|
|
311
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype") return;
|
|
312
|
-
const existing = Object.prototype.hasOwnProperty.call(output, key) ? output[key] : void 0;
|
|
313
|
-
if (existing !== void 0) {
|
|
314
|
-
if (Array.isArray(existing)) {
|
|
315
|
-
existing.push(value);
|
|
316
|
-
} else {
|
|
317
|
-
output[key] = [existing, value];
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
output[key] = value;
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
return output;
|
|
324
|
-
}
|
|
325
|
-
__name(searchParamsToObject, "searchParamsToObject");
|
|
326
6
|
|
|
327
|
-
// src/secret-compare.ts
|
|
328
|
-
function farmSecretsMatch(provided, expected) {
|
|
329
|
-
if (typeof provided !== "string" || typeof expected !== "string") return false;
|
|
330
|
-
if (expected.length === 0) return false;
|
|
331
|
-
let mismatch = provided.length ^ expected.length;
|
|
332
|
-
const length = Math.max(provided.length, expected.length);
|
|
333
|
-
for (let index = 0; index < length; index += 1) {
|
|
334
|
-
const providedCode = index < provided.length ? provided.charCodeAt(index) : 0;
|
|
335
|
-
const expectedCode = index < expected.length ? expected.charCodeAt(index) : 0;
|
|
336
|
-
mismatch |= providedCode ^ expectedCode;
|
|
337
|
-
}
|
|
338
|
-
return mismatch === 0;
|
|
339
|
-
}
|
|
340
|
-
__name(farmSecretsMatch, "farmSecretsMatch");
|
|
341
7
|
|
|
342
|
-
// src/utils/runtime-env.ts
|
|
343
|
-
function getFarmRuntimeBindings() {
|
|
344
|
-
const runtimeBindings = globalThis.__env__;
|
|
345
|
-
return runtimeBindings && typeof runtimeBindings === "object" ? runtimeBindings : void 0;
|
|
346
|
-
}
|
|
347
|
-
__name(getFarmRuntimeBindings, "getFarmRuntimeBindings");
|
|
348
|
-
function readFarmEnvironmentValue(name) {
|
|
349
|
-
const runtimeValue = getFarmRuntimeBindings()?.[name];
|
|
350
|
-
if (typeof runtimeValue === "string") return runtimeValue;
|
|
351
|
-
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
352
|
-
}
|
|
353
|
-
__name(readFarmEnvironmentValue, "readFarmEnvironmentValue");
|
|
354
|
-
function isFarmDeployedRuntime() {
|
|
355
|
-
if (getFarmRuntimeBindings()) return true;
|
|
356
|
-
return readFarmEnvironmentValue("NODE_ENV") === "production";
|
|
357
|
-
}
|
|
358
|
-
__name(isFarmDeployedRuntime, "isFarmDeployedRuntime");
|
|
359
8
|
|
|
360
|
-
// src/utils/decode.ts
|
|
361
|
-
function decodeRouteSegment(segment) {
|
|
362
|
-
try {
|
|
363
|
-
return decodeURIComponent(segment);
|
|
364
|
-
} catch {
|
|
365
|
-
return segment;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
__name(decodeRouteSegment, "decodeRouteSegment");
|
|
369
9
|
|
|
370
|
-
// src/utils.ts
|
|
371
|
-
function toPosixPath(filePath) {
|
|
372
|
-
return filePath.replace(/\\/g, "/");
|
|
373
|
-
}
|
|
374
|
-
__name(toPosixPath, "toPosixPath");
|
|
375
10
|
|
|
376
|
-
// src/plugins/route-pattern.ts
|
|
377
|
-
function validateConfigRouteSource(source, field = "Config route source") {
|
|
378
|
-
if (typeof source !== "string" || source.length === 0) {
|
|
379
|
-
throw new TypeError(`${field} must be a non-empty pathname pattern.`);
|
|
380
|
-
}
|
|
381
|
-
if (source.trim() !== source) {
|
|
382
|
-
throw new Error(`${field} cannot contain leading or trailing whitespace.`);
|
|
383
|
-
}
|
|
384
|
-
if (!source.startsWith("/")) {
|
|
385
|
-
throw new Error(`${field} must start with "/".`);
|
|
386
|
-
}
|
|
387
|
-
if (source.includes("?") || source.includes("#")) {
|
|
388
|
-
throw new Error(`${field} must be a pathname without a query string or hash.`);
|
|
389
|
-
}
|
|
390
|
-
if (source.includes("\\") || Array.from(source).some((character) => {
|
|
391
|
-
const code = character.charCodeAt(0);
|
|
392
|
-
return code <= 31 || code >= 127 && code <= 159;
|
|
393
|
-
})) {
|
|
394
|
-
throw new Error(`${field} cannot contain backslashes or control characters.`);
|
|
395
|
-
}
|
|
396
|
-
assertBrowserStableRoutePath(source);
|
|
397
|
-
return source;
|
|
398
|
-
}
|
|
399
|
-
__name(validateConfigRouteSource, "validateConfigRouteSource");
|
|
400
11
|
|
|
401
|
-
// src/workflows.ts
|
|
402
|
-
var import_node_path = require("path");
|
|
403
|
-
var DEFAULT_FARM_WORKFLOW_DIRS = ["src/jobs", "src/workflows", "src/cron"];
|
|
404
|
-
var DEFAULT_FARM_WORKFLOW_ROUTE = "/api/_farm/workflows";
|
|
405
|
-
var DEFAULT_FARM_WORKFLOW_SECRET_ENV = "CRON_SECRET";
|
|
406
|
-
var MISSING_FARM_WORKFLOW_SECRET_ERROR = "Workflow route requires a secret. Set the CRON_SECRET environment variable, configure workflows.secret, or set workflows.allowUnsecured to true.";
|
|
407
|
-
function defineWorkflow(definition) {
|
|
408
|
-
return {
|
|
409
|
-
...definition,
|
|
410
|
-
kind: "farm-workflow"
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
__name(defineWorkflow, "defineWorkflow");
|
|
414
|
-
function defineTask(definition) {
|
|
415
|
-
return defineWorkflow(definition);
|
|
416
|
-
}
|
|
417
|
-
__name(defineTask, "defineTask");
|
|
418
|
-
function defineCron(definition) {
|
|
419
|
-
return {
|
|
420
|
-
...definition,
|
|
421
|
-
kind: "farm-workflow"
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
__name(defineCron, "defineCron");
|
|
425
|
-
function resolveWorkflowsConfig(workflows) {
|
|
426
|
-
if (workflows === false) {
|
|
427
|
-
return {
|
|
428
|
-
enabled: false,
|
|
429
|
-
dirs: [...DEFAULT_FARM_WORKFLOW_DIRS],
|
|
430
|
-
route: DEFAULT_FARM_WORKFLOW_ROUTE,
|
|
431
|
-
secretEnv: DEFAULT_FARM_WORKFLOW_SECRET_ENV
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
const options = workflows && typeof workflows === "object" ? workflows : {};
|
|
435
|
-
const dirs = normalizeWorkflowDirs(options);
|
|
436
|
-
return {
|
|
437
|
-
enabled: options.enabled ?? true,
|
|
438
|
-
dirs,
|
|
439
|
-
route: normalizeWorkflowRoute(options.route || DEFAULT_FARM_WORKFLOW_ROUTE),
|
|
440
|
-
secretEnv: options.secretEnv || DEFAULT_FARM_WORKFLOW_SECRET_ENV,
|
|
441
|
-
secret: options.secret,
|
|
442
|
-
allowUnsecured: options.allowUnsecured === true
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
__name(resolveWorkflowsConfig, "resolveWorkflowsConfig");
|
|
446
|
-
async function discoverFarmWorkflows(config, options = {}) {
|
|
447
|
-
const workflowConfig = isResolvedWorkflowConfig(config.workflows) ? config.workflows : resolveWorkflowsConfig(config.workflows);
|
|
448
|
-
if (!workflowConfig.enabled) return [];
|
|
449
|
-
const root = config.root || process.cwd();
|
|
450
|
-
const files = await findWorkflowFiles(root, workflowConfig.dirs);
|
|
451
|
-
const workflows = [];
|
|
452
|
-
const seenIds = /* @__PURE__ */ new Map();
|
|
453
|
-
for (const filePath of files) {
|
|
454
|
-
const module2 = options.loadModule ? await options.loadModule(filePath) : await loadWorkflowModule(filePath, root);
|
|
455
|
-
const definition = resolveWorkflowDefinition(module2);
|
|
456
|
-
if (!definition) continue;
|
|
457
|
-
const id = normalizeWorkflowId(
|
|
458
|
-
definition.id || workflowIdFromFile(root, workflowConfig.dirs, filePath)
|
|
459
|
-
);
|
|
460
|
-
const previousPath = seenIds.get(id);
|
|
461
|
-
if (previousPath) {
|
|
462
|
-
throw new Error(
|
|
463
|
-
`Duplicate Farm workflow id "${id}" found in ${relativePath(root, previousPath)} and ${relativePath(root, filePath)}.`
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
seenIds.set(id, filePath);
|
|
467
|
-
workflows.push({
|
|
468
|
-
id,
|
|
469
|
-
filePath,
|
|
470
|
-
description: definition.description,
|
|
471
|
-
schedule: normalizeSchedule(definition.schedule),
|
|
472
|
-
timezone: definition.timezone,
|
|
473
|
-
routePath: joinRoute(workflowConfig.route, encodeURIComponent(id))
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
return workflows;
|
|
477
|
-
}
|
|
478
|
-
__name(discoverFarmWorkflows, "discoverFarmWorkflows");
|
|
479
|
-
function createFarmWorkflowRequestHandler(options) {
|
|
480
|
-
const workflowsById = new Map(options.workflows.map((workflow) => [workflow.id, workflow]));
|
|
481
|
-
return /* @__PURE__ */ __name(async function handleFarmWorkflowRequest(request) {
|
|
482
|
-
const url = new URL(request.url);
|
|
483
|
-
const route = normalizeWorkflowRoute(options.config.route);
|
|
484
|
-
if (url.pathname !== route && !url.pathname.startsWith(`${route}/`)) {
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
if (url.pathname === route) {
|
|
488
|
-
const secretError2 = verifyWorkflowSecret(request, options.config);
|
|
489
|
-
if (secretError2) return secretError2;
|
|
490
|
-
return Response.json({
|
|
491
|
-
workflows: options.workflows.map(toWorkflowMetadata)
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
const id = decodeRouteSegment(url.pathname.slice(route.length + 1));
|
|
495
|
-
const secretError = verifyWorkflowSecret(request, options.config);
|
|
496
|
-
if (secretError) return secretError;
|
|
497
|
-
const workflow = workflowsById.get(id);
|
|
498
|
-
if (!workflow) {
|
|
499
|
-
return Response.json({ error: `Workflow "${id}" was not found.` }, { status: 404 });
|
|
500
|
-
}
|
|
501
|
-
let payload;
|
|
502
|
-
try {
|
|
503
|
-
payload = await readWorkflowPayload(
|
|
504
|
-
request,
|
|
505
|
-
resolveFarmServerConfig(options.server).bodySizeLimit
|
|
506
|
-
);
|
|
507
|
-
} catch (error) {
|
|
508
|
-
const response = createFarmRequestBodyErrorResponse(error);
|
|
509
|
-
if (response) return response;
|
|
510
|
-
if (error instanceof SyntaxError) {
|
|
511
|
-
return Response.json({ error: "Invalid workflow request body." }, { status: 400 });
|
|
512
|
-
}
|
|
513
|
-
throw error;
|
|
514
|
-
}
|
|
515
|
-
const module2 = await options.loadModule(workflow);
|
|
516
|
-
const result = await runFarmWorkflowModule(module2, {
|
|
517
|
-
id: workflow.id,
|
|
518
|
-
name: workflow.id,
|
|
519
|
-
payload,
|
|
520
|
-
request,
|
|
521
|
-
scheduledTime: readScheduledTime(payload)
|
|
522
|
-
});
|
|
523
|
-
return Response.json({
|
|
524
|
-
id: workflow.id,
|
|
525
|
-
ok: true,
|
|
526
|
-
result: result ?? null
|
|
527
|
-
});
|
|
528
|
-
}, "handleFarmWorkflowRequest");
|
|
529
|
-
}
|
|
530
|
-
__name(createFarmWorkflowRequestHandler, "createFarmWorkflowRequestHandler");
|
|
531
|
-
async function runFarmWorkflowModule(module2, context) {
|
|
532
|
-
const definition = resolveWorkflowDefinition(module2);
|
|
533
|
-
if (!definition) {
|
|
534
|
-
throw new Error(`Farm workflow "${context.id}" does not export a workflow definition.`);
|
|
535
|
-
}
|
|
536
|
-
return await definition.run({
|
|
537
|
-
id: context.id,
|
|
538
|
-
name: context.name || context.id,
|
|
539
|
-
payload: context.payload,
|
|
540
|
-
scheduledTime: context.scheduledTime,
|
|
541
|
-
request: context.request,
|
|
542
|
-
event: context.event,
|
|
543
|
-
env: context.env || process.env,
|
|
544
|
-
data: /* @__PURE__ */ new Map(),
|
|
545
|
-
log: console
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
__name(runFarmWorkflowModule, "runFarmWorkflowModule");
|
|
549
|
-
async function prepareFarmWorkflowsForNitro(config) {
|
|
550
|
-
const workflowConfig = isResolvedWorkflowConfig(config.workflows) ? config.workflows : resolveWorkflowsConfig(config.workflows);
|
|
551
|
-
const root = config.root || process.cwd();
|
|
552
|
-
const distDir = config.distDir || ".farm";
|
|
553
|
-
const fs = await import("fs/promises");
|
|
554
|
-
const path = await import("path");
|
|
555
|
-
const generatedDir = path.join(root, distDir, ".nitro", "farm-workflows");
|
|
556
|
-
const workflows = await discoverFarmWorkflows({
|
|
557
|
-
root,
|
|
558
|
-
workflows: workflowConfig
|
|
559
|
-
});
|
|
560
|
-
if (workflows.length === 0) {
|
|
561
|
-
await fs.rm(generatedDir, { recursive: true, force: true });
|
|
562
|
-
return {
|
|
563
|
-
workflows,
|
|
564
|
-
tasks: {},
|
|
565
|
-
scheduledTasks: {}
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
await fs.rm(generatedDir, { recursive: true, force: true });
|
|
569
|
-
await fs.mkdir(generatedDir, { recursive: true });
|
|
570
|
-
const tasks = {};
|
|
571
|
-
const scheduledTasks = createScheduledTasks(workflows);
|
|
572
|
-
const wrapperNames = resolveWorkflowWrapperFileNames(workflows.map((workflow) => workflow.id));
|
|
573
|
-
for (const workflow of workflows) {
|
|
574
|
-
const wrapperPath = toPosixPath(
|
|
575
|
-
path.join(generatedDir, `${wrapperNames.get(workflow.id)}.mjs`)
|
|
576
|
-
);
|
|
577
|
-
await fs.writeFile(wrapperPath, createNitroTaskWrapper(workflow), "utf8");
|
|
578
|
-
tasks[workflow.id] = {
|
|
579
|
-
handler: wrapperPath,
|
|
580
|
-
description: workflow.description || `Farm workflow ${workflow.id}`
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
const handlerPath = toPosixPath(path.join(generatedDir, "http-handler.mjs"));
|
|
584
|
-
await fs.writeFile(
|
|
585
|
-
handlerPath,
|
|
586
|
-
createNitroWorkflowHTTPHandler(
|
|
587
|
-
workflowConfig,
|
|
588
|
-
workflows,
|
|
589
|
-
resolveFarmServerConfig(config.server)
|
|
590
|
-
),
|
|
591
|
-
"utf8"
|
|
592
|
-
);
|
|
593
|
-
const manifestPath = path.join(generatedDir, "manifest.json");
|
|
594
|
-
await fs.writeFile(
|
|
595
|
-
manifestPath,
|
|
596
|
-
JSON.stringify(
|
|
597
|
-
{
|
|
598
|
-
route: workflowConfig.route,
|
|
599
|
-
secretEnv: workflowConfig.secretEnv,
|
|
600
|
-
trigger: {
|
|
601
|
-
method: "GET",
|
|
602
|
-
authorization: `Bearer $${workflowConfig.secretEnv}`
|
|
603
|
-
},
|
|
604
|
-
workflows: workflows.map(toWorkflowMetadata)
|
|
605
|
-
},
|
|
606
|
-
null,
|
|
607
|
-
2
|
|
608
|
-
),
|
|
609
|
-
"utf8"
|
|
610
|
-
);
|
|
611
|
-
return {
|
|
612
|
-
workflows,
|
|
613
|
-
tasks,
|
|
614
|
-
scheduledTasks,
|
|
615
|
-
handlerPath,
|
|
616
|
-
manifestPath
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
__name(prepareFarmWorkflowsForNitro, "prepareFarmWorkflowsForNitro");
|
|
620
|
-
function createFarmWorkflowVercelCrons(workflows) {
|
|
621
|
-
return workflows.flatMap(
|
|
622
|
-
(workflow) => workflow.schedule.map((schedule) => ({
|
|
623
|
-
path: workflow.routePath,
|
|
624
|
-
schedule
|
|
625
|
-
}))
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
__name(createFarmWorkflowVercelCrons, "createFarmWorkflowVercelCrons");
|
|
629
|
-
function applyFarmWorkflowVercelCrons(vercelConfig, workflows) {
|
|
630
|
-
const crons = createFarmWorkflowVercelCrons(workflows);
|
|
631
|
-
if (crons.length === 0) return vercelConfig;
|
|
632
|
-
const existingCrons = Array.isArray(vercelConfig.crons) ? vercelConfig.crons : [];
|
|
633
|
-
const seen = new Set(existingCrons.map((cron) => `${cron.path}:${cron.schedule}`));
|
|
634
|
-
const nextCrons = [...existingCrons];
|
|
635
|
-
for (const cron of crons) {
|
|
636
|
-
const key = `${cron.path}:${cron.schedule}`;
|
|
637
|
-
if (seen.has(key)) continue;
|
|
638
|
-
seen.add(key);
|
|
639
|
-
nextCrons.push(cron);
|
|
640
|
-
}
|
|
641
|
-
return {
|
|
642
|
-
...vercelConfig,
|
|
643
|
-
crons: nextCrons
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
__name(applyFarmWorkflowVercelCrons, "applyFarmWorkflowVercelCrons");
|
|
647
|
-
function isResolvedWorkflowConfig(value) {
|
|
648
|
-
return !!value && typeof value === "object" && "dirs" in value && Array.isArray(value.dirs) && typeof value.route === "string";
|
|
649
|
-
}
|
|
650
|
-
__name(isResolvedWorkflowConfig, "isResolvedWorkflowConfig");
|
|
651
|
-
function normalizeWorkflowDirs(options) {
|
|
652
|
-
const rawDirs = options.dirs || (Array.isArray(options.dir) ? options.dir : options.dir ? [options.dir] : void 0);
|
|
653
|
-
const dirs = rawDirs && rawDirs.length > 0 ? rawDirs : DEFAULT_FARM_WORKFLOW_DIRS;
|
|
654
|
-
return [...new Set(dirs.map(normalizeWorkflowDir).filter(Boolean))];
|
|
655
|
-
}
|
|
656
|
-
__name(normalizeWorkflowDirs, "normalizeWorkflowDirs");
|
|
657
|
-
function normalizeWorkflowDir(value) {
|
|
658
|
-
const dir = value.trim();
|
|
659
|
-
if (!dir) return "";
|
|
660
|
-
return (0, import_node_path.isAbsolute)(dir) ? (0, import_node_path.normalize)(dir) : trimSlashes(dir);
|
|
661
|
-
}
|
|
662
|
-
__name(normalizeWorkflowDir, "normalizeWorkflowDir");
|
|
663
|
-
function normalizeWorkflowRoute(route) {
|
|
664
|
-
const trimmed = route.trim();
|
|
665
|
-
if (!trimmed || trimmed === "/") return DEFAULT_FARM_WORKFLOW_ROUTE;
|
|
666
|
-
const normalized = `/${trimSlashes(trimmed)}`;
|
|
667
|
-
validateConfigRouteSource(normalized, "workflows.route");
|
|
668
|
-
return normalized;
|
|
669
|
-
}
|
|
670
|
-
__name(normalizeWorkflowRoute, "normalizeWorkflowRoute");
|
|
671
|
-
function normalizeWorkflowId(id) {
|
|
672
|
-
const normalized = id.replace(/\\/g, "/").replace(/\.(tsx?|jsx?|mjs|cjs)$/, "").replace(/\/index$/, "").replace(/[^a-zA-Z0-9._/-]+/g, "-").replace(/^\/+|\/+$/g, "").replace(/\/+/g, "/");
|
|
673
|
-
return normalized || "workflow";
|
|
674
|
-
}
|
|
675
|
-
__name(normalizeWorkflowId, "normalizeWorkflowId");
|
|
676
|
-
function normalizeSchedule(schedule) {
|
|
677
|
-
if (!schedule) return [];
|
|
678
|
-
return (Array.isArray(schedule) ? schedule : [schedule]).map((value) => value.trim()).filter(Boolean);
|
|
679
|
-
}
|
|
680
|
-
__name(normalizeSchedule, "normalizeSchedule");
|
|
681
|
-
function resolveWorkflowDefinition(module2) {
|
|
682
|
-
const candidates = [module2.default, module2.workflow, module2.cron, module2.task, module2.job];
|
|
683
|
-
for (const candidate of candidates) {
|
|
684
|
-
if (candidate && typeof candidate === "object" && typeof candidate.run === "function") {
|
|
685
|
-
return candidate;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
return null;
|
|
689
|
-
}
|
|
690
|
-
__name(resolveWorkflowDefinition, "resolveWorkflowDefinition");
|
|
691
|
-
async function findWorkflowFiles(root, dirs) {
|
|
692
|
-
const path = await import("path");
|
|
693
|
-
const files = [];
|
|
694
|
-
for (const dir of dirs) {
|
|
695
|
-
const absoluteDir = path.isAbsolute(dir) ? dir : path.join(root, dir);
|
|
696
|
-
if (!await pathExists(absoluteDir)) continue;
|
|
697
|
-
await walkWorkflowDir(absoluteDir, files);
|
|
698
|
-
}
|
|
699
|
-
return files.sort();
|
|
700
|
-
}
|
|
701
|
-
__name(findWorkflowFiles, "findWorkflowFiles");
|
|
702
|
-
async function walkWorkflowDir(dir, files) {
|
|
703
|
-
const fs = await import("fs/promises");
|
|
704
|
-
const path = await import("path");
|
|
705
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
706
|
-
for (const entry of entries) {
|
|
707
|
-
const filePath = path.join(dir, entry.name);
|
|
708
|
-
if (entry.isDirectory()) {
|
|
709
|
-
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
710
|
-
await walkWorkflowDir(filePath, files);
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
if (isWorkflowFile(entry.name)) {
|
|
714
|
-
files.push(filePath);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
__name(walkWorkflowDir, "walkWorkflowDir");
|
|
719
|
-
async function pathExists(filePath) {
|
|
720
|
-
const fs = await import("fs/promises");
|
|
721
|
-
return fs.access(filePath).then(() => true).catch(() => false);
|
|
722
|
-
}
|
|
723
|
-
__name(pathExists, "pathExists");
|
|
724
|
-
function isWorkflowFile(fileName) {
|
|
725
|
-
return /\.(?:ts|tsx|js|jsx|mjs|cjs)$/.test(fileName) && !/\.d\.[cm]?ts$/.test(fileName);
|
|
726
|
-
}
|
|
727
|
-
__name(isWorkflowFile, "isWorkflowFile");
|
|
728
|
-
async function loadWorkflowModule(filePath, root) {
|
|
729
|
-
const fs = await import("fs/promises");
|
|
730
|
-
const path = await import("path");
|
|
731
|
-
const { pathToFileURL } = await import("url");
|
|
732
|
-
const { build } = await import("esbuild");
|
|
733
|
-
const outDir = path.join(root, ".farm", ".workflow-loader");
|
|
734
|
-
await fs.mkdir(outDir, { recursive: true });
|
|
735
|
-
const outfile = path.join(
|
|
736
|
-
outDir,
|
|
737
|
-
`workflow-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`
|
|
738
|
-
);
|
|
739
|
-
await build({
|
|
740
|
-
absWorkingDir: root,
|
|
741
|
-
entryPoints: [filePath],
|
|
742
|
-
outfile,
|
|
743
|
-
bundle: true,
|
|
744
|
-
format: "esm",
|
|
745
|
-
platform: "node",
|
|
746
|
-
target: `node${process.versions.node.split(".")[0]}`,
|
|
747
|
-
packages: "external",
|
|
748
|
-
external: ["@farm.js/core", "@farm.js/core/*", "nitro", "nitro/*"],
|
|
749
|
-
jsx: "automatic",
|
|
750
|
-
logLevel: "silent",
|
|
751
|
-
sourcemap: "inline"
|
|
752
|
-
});
|
|
753
|
-
try {
|
|
754
|
-
return await import(
|
|
755
|
-
/* @vite-ignore */
|
|
756
|
-
`${pathToFileURL(outfile).href}?t=${Date.now()}`
|
|
757
|
-
);
|
|
758
|
-
} finally {
|
|
759
|
-
await fs.unlink(outfile).catch(() => void 0);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
__name(loadWorkflowModule, "loadWorkflowModule");
|
|
763
|
-
function workflowIdFromFile(root, dirs, filePath) {
|
|
764
|
-
for (const dir of dirs) {
|
|
765
|
-
const scanRoot = (0, import_node_path.isAbsolute)(dir) ? dir : (0, import_node_path.resolve)(root, dir);
|
|
766
|
-
const candidate = (0, import_node_path.relative)(scanRoot, filePath);
|
|
767
|
-
if (candidate && candidate !== ".." && !candidate.startsWith(`..${import_node_path.sep}`)) {
|
|
768
|
-
return normalizeWorkflowId(candidate);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
return normalizeWorkflowId((0, import_node_path.relative)(root, filePath));
|
|
772
|
-
}
|
|
773
|
-
__name(workflowIdFromFile, "workflowIdFromFile");
|
|
774
|
-
function createScheduledTasks(workflows) {
|
|
775
|
-
const scheduleMap = /* @__PURE__ */ new Map();
|
|
776
|
-
for (const workflow of workflows) {
|
|
777
|
-
for (const schedule of workflow.schedule) {
|
|
778
|
-
const taskIds = scheduleMap.get(schedule) || [];
|
|
779
|
-
taskIds.push(workflow.id);
|
|
780
|
-
scheduleMap.set(schedule, taskIds);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
return Object.fromEntries(
|
|
784
|
-
[...scheduleMap.entries()].map(([schedule, taskIds]) => [
|
|
785
|
-
schedule,
|
|
786
|
-
taskIds.length === 1 ? taskIds[0] : taskIds
|
|
787
|
-
])
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
|
-
__name(createScheduledTasks, "createScheduledTasks");
|
|
791
|
-
function createNitroTaskWrapper(workflow) {
|
|
792
|
-
const normalizedPath = workflow.filePath.replace(/\\/g, "/");
|
|
793
|
-
return `
|
|
794
|
-
import { defineTask } from "nitro/task";
|
|
795
|
-
import { runFarmWorkflowModule } from "@farm.js/core/workflows";
|
|
796
|
-
import * as workflowModule from ${JSON.stringify(normalizedPath)};
|
|
797
12
|
|
|
798
|
-
export default defineTask({
|
|
799
|
-
meta: {
|
|
800
|
-
description: ${JSON.stringify(workflow.description || `Farm workflow ${workflow.id}`)}
|
|
801
|
-
},
|
|
802
|
-
async run(event) {
|
|
803
|
-
const payload = event?.payload || {};
|
|
804
|
-
const env = event?.context?.cloudflare?.env || event?.context?.env || process.env;
|
|
805
|
-
return await runFarmWorkflowModule(workflowModule, {
|
|
806
|
-
id: ${JSON.stringify(workflow.id)},
|
|
807
|
-
name: event?.name || ${JSON.stringify(workflow.id)},
|
|
808
|
-
payload,
|
|
809
|
-
scheduledTime: payload.scheduledTime,
|
|
810
|
-
request: event?.context?.request,
|
|
811
|
-
event,
|
|
812
|
-
env
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
});
|
|
816
|
-
`.trim();
|
|
817
|
-
}
|
|
818
|
-
__name(createNitroTaskWrapper, "createNitroTaskWrapper");
|
|
819
|
-
function createNitroWorkflowHTTPHandler(config, workflows, server) {
|
|
820
|
-
return `
|
|
821
|
-
import { H3 } from "h3";
|
|
822
|
-
import { runTask } from "nitro/task";
|
|
823
|
-
import {
|
|
824
|
-
createFarmRequestBodyErrorResponse,
|
|
825
|
-
farmSecretsMatch,
|
|
826
|
-
readFarmRequestBody,
|
|
827
|
-
searchParamsToObject
|
|
828
|
-
} from "@farm.js/core/internal/production-runtime";
|
|
829
13
|
|
|
830
|
-
const route = ${JSON.stringify(config.route)};
|
|
831
|
-
const secretEnv = ${JSON.stringify(config.secretEnv)};
|
|
832
|
-
const inlineSecret = ${JSON.stringify(config.secret || "")};
|
|
833
|
-
const allowUnsecured = ${JSON.stringify(config.allowUnsecured === true)};
|
|
834
|
-
const bodySizeLimit = ${JSON.stringify(server.bodySizeLimit)};
|
|
835
|
-
const workflows = ${JSON.stringify(workflows.map(toWorkflowMetadata))};
|
|
836
|
-
const workflowIds = new Set(workflows.map((workflow) => workflow.id));
|
|
837
14
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
15
|
+
var _chunkK6FNHVDRcjs = require('./chunk-K6FNHVDR.cjs');
|
|
16
|
+
require('./chunk-JDNHKPTD.cjs');
|
|
17
|
+
require('./chunk-CMGMGHUZ.cjs');
|
|
18
|
+
require('./chunk-EM6SBQKM.cjs');
|
|
19
|
+
require('./chunk-5QIKR7RR.cjs');
|
|
20
|
+
require('./chunk-QNPEUFHQ.cjs');
|
|
21
|
+
require('./chunk-DVM4FKZL.cjs');
|
|
22
|
+
require('./chunk-US2QVW3E.cjs');
|
|
23
|
+
require('./chunk-BIDYX3SL.cjs');
|
|
24
|
+
require('./chunk-I57LW5VZ.cjs');
|
|
25
|
+
require('./chunk-NO3WWW3N.cjs');
|
|
26
|
+
require('./chunk-S3JO3N4H.cjs');
|
|
844
27
|
|
|
845
|
-
function decodeRouteSegment(segment) {
|
|
846
|
-
try {
|
|
847
|
-
return decodeURIComponent(segment);
|
|
848
|
-
} catch {
|
|
849
|
-
return segment;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
28
|
|
|
853
|
-
function getHeader(event, name) {
|
|
854
|
-
return event.req.headers.get(name);
|
|
855
|
-
}
|
|
856
29
|
|
|
857
|
-
function getSecret() {
|
|
858
|
-
// Match the dev-path verifyWorkflowSecret's resolution (readFarmEnvironmentValue):
|
|
859
|
-
// runtime bindings on globalThis.__env__ first, then process.env. Reading
|
|
860
|
-
// process.env alone misses a Cloudflare Workers secret, so a correctly
|
|
861
|
-
// configured deployment would see no secret and reject every request with 401.
|
|
862
|
-
const runtimeBindings = globalThis.__env__;
|
|
863
|
-
const runtimeSecret =
|
|
864
|
-
runtimeBindings && typeof runtimeBindings === "object" ? runtimeBindings[secretEnv] : undefined;
|
|
865
|
-
const resolved =
|
|
866
|
-
typeof runtimeSecret === "string"
|
|
867
|
-
? runtimeSecret
|
|
868
|
-
: typeof process !== "undefined"
|
|
869
|
-
? process.env?.[secretEnv]
|
|
870
|
-
: undefined;
|
|
871
|
-
return inlineSecret || resolved || "";
|
|
872
|
-
}
|
|
873
30
|
|
|
874
|
-
function verifySecret(event) {
|
|
875
|
-
const secret = getSecret();
|
|
876
|
-
if (!secret) {
|
|
877
|
-
if (allowUnsecured) return null;
|
|
878
|
-
return json({ error: ${JSON.stringify(MISSING_FARM_WORKFLOW_SECRET_ERROR)} }, 401);
|
|
879
|
-
}
|
|
880
|
-
const authorization = getHeader(event, "authorization") || "";
|
|
881
|
-
const headerSecret = getHeader(event, "x-farm-workflow-secret") || "";
|
|
882
|
-
const bearer = authorization.match(/^Bearer\\s+(.+)$/i)?.[1] || "";
|
|
883
|
-
if (farmSecretsMatch(headerSecret, secret) || farmSecretsMatch(bearer, secret)) return null;
|
|
884
|
-
return json({ error: "Unauthorized workflow request." }, 401);
|
|
885
|
-
}
|
|
886
31
|
|
|
887
|
-
async function readPayload(event) {
|
|
888
|
-
if (event.req.method === "GET" || event.req.method === "HEAD") {
|
|
889
|
-
return searchParamsToObject(event.url.searchParams);
|
|
890
|
-
}
|
|
891
|
-
const bytes = await readFarmRequestBody(event.req, bodySizeLimit);
|
|
892
|
-
const text = new TextDecoder().decode(bytes);
|
|
893
|
-
if (!text) return {};
|
|
894
|
-
const contentType = (getHeader(event, "content-type") || "").split(";", 1)[0].trim().toLowerCase();
|
|
895
|
-
if (
|
|
896
|
-
contentType === "application/json" ||
|
|
897
|
-
(contentType.startsWith("application/") && contentType.endsWith("+json"))
|
|
898
|
-
) {
|
|
899
|
-
return JSON.parse(text);
|
|
900
|
-
}
|
|
901
|
-
return { text };
|
|
902
|
-
}
|
|
903
32
|
|
|
904
|
-
export default new H3()
|
|
905
|
-
.get(route, (event) => {
|
|
906
|
-
const unauthorized = verifySecret(event);
|
|
907
|
-
if (unauthorized) return unauthorized;
|
|
908
|
-
return { workflows };
|
|
909
|
-
})
|
|
910
|
-
.all(route + "/:id", async (event) => {
|
|
911
|
-
const id = decodeRouteSegment(event.context.params?.id || "");
|
|
912
33
|
|
|
913
|
-
// Verify the secret before consulting the workflow id map so the
|
|
914
|
-
// existing-vs-missing distinction is not disclosed to callers without
|
|
915
|
-
// the secret (a 401 for unknown ids would otherwise become a 404 oracle).
|
|
916
|
-
const unauthorized = verifySecret(event);
|
|
917
|
-
if (unauthorized) return unauthorized;
|
|
918
34
|
|
|
919
|
-
if (!workflowIds.has(id)) {
|
|
920
|
-
return json({ error: "Workflow " + id + " was not found." }, 404);
|
|
921
|
-
}
|
|
922
35
|
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (error instanceof SyntaxError) return json({ error: "Invalid workflow request body." }, 400);
|
|
930
|
-
throw error;
|
|
931
|
-
}
|
|
932
|
-
const result = await runTask(id, {
|
|
933
|
-
payload,
|
|
934
|
-
context: {
|
|
935
|
-
source: "http",
|
|
936
|
-
request: event.req,
|
|
937
|
-
route,
|
|
938
|
-
url: event.url.href,
|
|
939
|
-
method: event.req.method
|
|
940
|
-
}
|
|
941
|
-
});
|
|
942
|
-
return {
|
|
943
|
-
id,
|
|
944
|
-
ok: true,
|
|
945
|
-
result: result ?? null
|
|
946
|
-
};
|
|
947
|
-
});
|
|
948
|
-
`.trim();
|
|
949
|
-
}
|
|
950
|
-
__name(createNitroWorkflowHTTPHandler, "createNitroWorkflowHTTPHandler");
|
|
951
|
-
function toWorkflowMetadata(workflow) {
|
|
952
|
-
return {
|
|
953
|
-
id: workflow.id,
|
|
954
|
-
description: workflow.description || null,
|
|
955
|
-
schedule: workflow.schedule,
|
|
956
|
-
timezone: workflow.timezone || null,
|
|
957
|
-
path: workflow.routePath
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
__name(toWorkflowMetadata, "toWorkflowMetadata");
|
|
961
|
-
async function readWorkflowPayload(request, bodySizeLimit) {
|
|
962
|
-
const url = new URL(request.url);
|
|
963
|
-
if (request.method === "GET" || request.method === "HEAD") {
|
|
964
|
-
return searchParamsToObject(url.searchParams);
|
|
965
|
-
}
|
|
966
|
-
const bytes = await readFarmRequestBody(request, bodySizeLimit);
|
|
967
|
-
const text = new TextDecoder().decode(bytes);
|
|
968
|
-
if (!text) return {};
|
|
969
|
-
const contentType = (request.headers.get("content-type") || "").split(";", 1)[0].trim().toLowerCase();
|
|
970
|
-
if (contentType === "application/json" || contentType.startsWith("application/") && contentType.endsWith("+json")) {
|
|
971
|
-
return JSON.parse(text);
|
|
972
|
-
}
|
|
973
|
-
return { text };
|
|
974
|
-
}
|
|
975
|
-
__name(readWorkflowPayload, "readWorkflowPayload");
|
|
976
|
-
function readScheduledTime(payload) {
|
|
977
|
-
return payload && typeof payload === "object" && "scheduledTime" in payload ? payload.scheduledTime : void 0;
|
|
978
|
-
}
|
|
979
|
-
__name(readScheduledTime, "readScheduledTime");
|
|
980
|
-
function verifyWorkflowSecret(request, config) {
|
|
981
|
-
const secret = config.secret || readFarmEnvironmentValue(config.secretEnv) || "";
|
|
982
|
-
if (!secret) {
|
|
983
|
-
if (config.allowUnsecured === true || !isFarmDeployedRuntime()) return null;
|
|
984
|
-
return Response.json(
|
|
985
|
-
{
|
|
986
|
-
error: MISSING_FARM_WORKFLOW_SECRET_ERROR
|
|
987
|
-
},
|
|
988
|
-
{ status: 401 }
|
|
989
|
-
);
|
|
990
|
-
}
|
|
991
|
-
const authorization = request.headers.get("authorization") || "";
|
|
992
|
-
const bearer = authorization.match(/^Bearer\s+(.+)$/i)?.[1] || "";
|
|
993
|
-
const headerSecret = request.headers.get("x-farm-workflow-secret") || "";
|
|
994
|
-
if (farmSecretsMatch(bearer, secret) || farmSecretsMatch(headerSecret, secret)) return null;
|
|
995
|
-
return Response.json({ error: "Unauthorized workflow request." }, { status: 401 });
|
|
996
|
-
}
|
|
997
|
-
__name(verifyWorkflowSecret, "verifyWorkflowSecret");
|
|
998
|
-
function joinRoute(...parts) {
|
|
999
|
-
return `/${parts.map((part) => trimSlashes(part)).filter(Boolean).join("/")}`;
|
|
1000
|
-
}
|
|
1001
|
-
__name(joinRoute, "joinRoute");
|
|
1002
|
-
function trimSlashes(value) {
|
|
1003
|
-
return value.replace(/^\/+|\/+$/g, "");
|
|
1004
|
-
}
|
|
1005
|
-
__name(trimSlashes, "trimSlashes");
|
|
1006
|
-
function resolveWorkflowWrapperFileNames(ids) {
|
|
1007
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1008
|
-
for (const id of ids) {
|
|
1009
|
-
const key = safeFileName(id).toLowerCase();
|
|
1010
|
-
groups.set(key, (groups.get(key) ?? 0) + 1);
|
|
1011
|
-
}
|
|
1012
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
1013
|
-
const claimed = /* @__PURE__ */ new Map();
|
|
1014
|
-
for (const id of ids) {
|
|
1015
|
-
const base = safeFileName(id);
|
|
1016
|
-
const key = base.toLowerCase();
|
|
1017
|
-
const fileName = (groups.get(key) ?? 0) > 1 ? `${key}-${workflowIdFingerprint(id)}` : base;
|
|
1018
|
-
const claimedBy = claimed.get(fileName.toLowerCase());
|
|
1019
|
-
if (claimedBy !== void 0) {
|
|
1020
|
-
throw new Error(
|
|
1021
|
-
`Farm workflows ${JSON.stringify(claimedBy)} and ${JSON.stringify(id)} generate the same wrapper file ${JSON.stringify(`${fileName}.mjs`)}. Rename one of them.`
|
|
1022
|
-
);
|
|
1023
|
-
}
|
|
1024
|
-
claimed.set(fileName.toLowerCase(), id);
|
|
1025
|
-
resolved.set(id, fileName);
|
|
1026
|
-
}
|
|
1027
|
-
return resolved;
|
|
1028
|
-
}
|
|
1029
|
-
__name(resolveWorkflowWrapperFileNames, "resolveWorkflowWrapperFileNames");
|
|
1030
|
-
function workflowIdFingerprint(value) {
|
|
1031
|
-
let hash = 2166136261;
|
|
1032
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1033
|
-
hash ^= value.charCodeAt(index);
|
|
1034
|
-
hash = Math.imul(hash, 16777619);
|
|
1035
|
-
}
|
|
1036
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
1037
|
-
}
|
|
1038
|
-
__name(workflowIdFingerprint, "workflowIdFingerprint");
|
|
1039
|
-
function safeFileName(value) {
|
|
1040
|
-
return value.replace(/[^a-zA-Z0-9._-]+/g, "-") || "workflow";
|
|
1041
|
-
}
|
|
1042
|
-
__name(safeFileName, "safeFileName");
|
|
1043
|
-
function relativePath(root, filePath) {
|
|
1044
|
-
return filePath.replace(/\\/g, "/").replace(`${root.replace(/\\/g, "/")}/`, "");
|
|
1045
|
-
}
|
|
1046
|
-
__name(relativePath, "relativePath");
|
|
1047
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1048
|
-
0 && (module.exports = {
|
|
1049
|
-
DEFAULT_FARM_WORKFLOW_DIRS,
|
|
1050
|
-
DEFAULT_FARM_WORKFLOW_ROUTE,
|
|
1051
|
-
DEFAULT_FARM_WORKFLOW_SECRET_ENV,
|
|
1052
|
-
applyFarmWorkflowVercelCrons,
|
|
1053
|
-
createFarmWorkflowRequestHandler,
|
|
1054
|
-
createFarmWorkflowVercelCrons,
|
|
1055
|
-
defineCron,
|
|
1056
|
-
defineTask,
|
|
1057
|
-
defineWorkflow,
|
|
1058
|
-
discoverFarmWorkflows,
|
|
1059
|
-
prepareFarmWorkflowsForNitro,
|
|
1060
|
-
resolveWorkflowsConfig,
|
|
1061
|
-
runFarmWorkflowModule
|
|
1062
|
-
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.DEFAULT_FARM_WORKFLOW_DIRS = _chunkK6FNHVDRcjs.DEFAULT_FARM_WORKFLOW_DIRS; exports.DEFAULT_FARM_WORKFLOW_ROUTE = _chunkK6FNHVDRcjs.DEFAULT_FARM_WORKFLOW_ROUTE; exports.DEFAULT_FARM_WORKFLOW_SECRET_ENV = _chunkK6FNHVDRcjs.DEFAULT_FARM_WORKFLOW_SECRET_ENV; exports.applyFarmWorkflowVercelCrons = _chunkK6FNHVDRcjs.applyFarmWorkflowVercelCrons; exports.createFarmWorkflowRequestHandler = _chunkK6FNHVDRcjs.createFarmWorkflowRequestHandler; exports.createFarmWorkflowVercelCrons = _chunkK6FNHVDRcjs.createFarmWorkflowVercelCrons; exports.defineCron = _chunkK6FNHVDRcjs.defineCron; exports.defineTask = _chunkK6FNHVDRcjs.defineTask; exports.defineWorkflow = _chunkK6FNHVDRcjs.defineWorkflow; exports.discoverFarmWorkflows = _chunkK6FNHVDRcjs.discoverFarmWorkflows; exports.prepareFarmWorkflowsForNitro = _chunkK6FNHVDRcjs.prepareFarmWorkflowsForNitro; exports.resolveWorkflowsConfig = _chunkK6FNHVDRcjs.resolveWorkflowsConfig; exports.runFarmWorkflowModule = _chunkK6FNHVDRcjs.runFarmWorkflowModule;
|