@openfn/ws-worker 0.8.1 → 1.0.0
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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +49 -121
- package/dist/index.js +283 -141
- package/dist/start.js +381 -220
- package/package.json +7 -6
package/dist/start.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
4
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
5
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
6
|
}) : x)(function(x) {
|
|
@@ -6,6 +8,110 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
8
|
return require.apply(this, arguments);
|
|
7
9
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
8
10
|
});
|
|
11
|
+
var __esm = (fn, res) => function __init() {
|
|
12
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name2 in all)
|
|
16
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// package.json
|
|
20
|
+
var package_exports = {};
|
|
21
|
+
__export(package_exports, {
|
|
22
|
+
author: () => author,
|
|
23
|
+
bin: () => bin,
|
|
24
|
+
default: () => package_default,
|
|
25
|
+
dependencies: () => dependencies,
|
|
26
|
+
description: () => description,
|
|
27
|
+
devDependencies: () => devDependencies,
|
|
28
|
+
files: () => files,
|
|
29
|
+
license: () => license,
|
|
30
|
+
main: () => main,
|
|
31
|
+
name: () => name,
|
|
32
|
+
scripts: () => scripts,
|
|
33
|
+
type: () => type,
|
|
34
|
+
version: () => version
|
|
35
|
+
});
|
|
36
|
+
var name, version, description, main, type, scripts, bin, author, license, dependencies, devDependencies, files, package_default;
|
|
37
|
+
var init_package = __esm({
|
|
38
|
+
"package.json"() {
|
|
39
|
+
name = "@openfn/ws-worker";
|
|
40
|
+
version = "1.0.0";
|
|
41
|
+
description = "A Websocket Worker to connect Lightning to a Runtime Engine";
|
|
42
|
+
main = "dist/index.js";
|
|
43
|
+
type = "module";
|
|
44
|
+
scripts = {
|
|
45
|
+
test: "pnpm ava --serial",
|
|
46
|
+
"test:types": "pnpm tsc --noEmit --project tsconfig.json",
|
|
47
|
+
build: "tsup --config tsup.config.js",
|
|
48
|
+
"build:watch": "pnpm build --watch",
|
|
49
|
+
start: "ts-node-esm --transpile-only src/start.ts",
|
|
50
|
+
"start:prod": "node dist/start.js",
|
|
51
|
+
"start:watch": "nodemon -e ts,js --watch ../runtime-manager/dist --watch ./src --exec 'pnpm start'",
|
|
52
|
+
pack: "pnpm pack --pack-destination ../../dist"
|
|
53
|
+
};
|
|
54
|
+
bin = {
|
|
55
|
+
worker: "dist/start.js"
|
|
56
|
+
};
|
|
57
|
+
author = "Open Function Group <admin@openfn.org>";
|
|
58
|
+
license = "ISC";
|
|
59
|
+
dependencies = {
|
|
60
|
+
"@koa/router": "^12.0.0",
|
|
61
|
+
"@openfn/engine-multi": "workspace:*",
|
|
62
|
+
"@openfn/lexicon": "workspace:^",
|
|
63
|
+
"@openfn/logger": "workspace:*",
|
|
64
|
+
"@openfn/runtime": "workspace:*",
|
|
65
|
+
"@types/koa-logger": "^3.1.2",
|
|
66
|
+
"@types/ws": "^8.5.6",
|
|
67
|
+
"fast-safe-stringify": "^2.1.1",
|
|
68
|
+
figures: "^5.0.0",
|
|
69
|
+
"human-id": "^4.1.0",
|
|
70
|
+
jose: "^4.14.6",
|
|
71
|
+
koa: "^2.13.4",
|
|
72
|
+
"koa-bodyparser": "^4.4.0",
|
|
73
|
+
"koa-logger": "^3.2.1",
|
|
74
|
+
phoenix: "1.7.10",
|
|
75
|
+
ws: "^8.14.1"
|
|
76
|
+
};
|
|
77
|
+
devDependencies = {
|
|
78
|
+
"@openfn/lightning-mock": "workspace:*",
|
|
79
|
+
"@types/koa": "^2.13.5",
|
|
80
|
+
"@types/koa-bodyparser": "^4.3.10",
|
|
81
|
+
"@types/koa__router": "^12.0.1",
|
|
82
|
+
"@types/node": "^18.15.3",
|
|
83
|
+
"@types/nodemon": "1.19.3",
|
|
84
|
+
"@types/phoenix": "^1.6.2",
|
|
85
|
+
"@types/yargs": "^17.0.12",
|
|
86
|
+
ava: "5.1.0",
|
|
87
|
+
nodemon: "3.0.1",
|
|
88
|
+
"ts-node": "^10.9.1",
|
|
89
|
+
tslib: "^2.4.0",
|
|
90
|
+
tsup: "^6.2.3",
|
|
91
|
+
typescript: "^4.6.4",
|
|
92
|
+
yargs: "^17.6.2"
|
|
93
|
+
};
|
|
94
|
+
files = [
|
|
95
|
+
"dist",
|
|
96
|
+
"README.md",
|
|
97
|
+
"CHANGELOG.md"
|
|
98
|
+
];
|
|
99
|
+
package_default = {
|
|
100
|
+
name,
|
|
101
|
+
version,
|
|
102
|
+
description,
|
|
103
|
+
main,
|
|
104
|
+
type,
|
|
105
|
+
scripts,
|
|
106
|
+
bin,
|
|
107
|
+
author,
|
|
108
|
+
license,
|
|
109
|
+
dependencies,
|
|
110
|
+
devDependencies,
|
|
111
|
+
files
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
9
115
|
|
|
10
116
|
// ../../node_modules/.pnpm/yargs@17.7.2/node_modules/yargs/lib/platform-shims/esm.mjs
|
|
11
117
|
import { notStrictEqual, strictEqual } from "assert";
|
|
@@ -1167,26 +1273,26 @@ var YargsParser = class {
|
|
|
1167
1273
|
return defaultForType(guessType2(key));
|
|
1168
1274
|
}
|
|
1169
1275
|
}
|
|
1170
|
-
function defaultForType(
|
|
1276
|
+
function defaultForType(type2) {
|
|
1171
1277
|
const def = {
|
|
1172
1278
|
[DefaultValuesForTypeKey.BOOLEAN]: true,
|
|
1173
1279
|
[DefaultValuesForTypeKey.STRING]: "",
|
|
1174
1280
|
[DefaultValuesForTypeKey.NUMBER]: void 0,
|
|
1175
1281
|
[DefaultValuesForTypeKey.ARRAY]: []
|
|
1176
1282
|
};
|
|
1177
|
-
return def[
|
|
1283
|
+
return def[type2];
|
|
1178
1284
|
}
|
|
1179
1285
|
function guessType2(key) {
|
|
1180
|
-
let
|
|
1286
|
+
let type2 = DefaultValuesForTypeKey.BOOLEAN;
|
|
1181
1287
|
if (checkAllAliases(key, flags.strings))
|
|
1182
|
-
|
|
1288
|
+
type2 = DefaultValuesForTypeKey.STRING;
|
|
1183
1289
|
else if (checkAllAliases(key, flags.numbers))
|
|
1184
|
-
|
|
1290
|
+
type2 = DefaultValuesForTypeKey.NUMBER;
|
|
1185
1291
|
else if (checkAllAliases(key, flags.bools))
|
|
1186
|
-
|
|
1292
|
+
type2 = DefaultValuesForTypeKey.BOOLEAN;
|
|
1187
1293
|
else if (checkAllAliases(key, flags.arrays))
|
|
1188
|
-
|
|
1189
|
-
return
|
|
1294
|
+
type2 = DefaultValuesForTypeKey.ARRAY;
|
|
1295
|
+
return type2;
|
|
1190
1296
|
}
|
|
1191
1297
|
function isUndefined(num) {
|
|
1192
1298
|
return num === void 0;
|
|
@@ -1560,7 +1666,7 @@ var esm_default = {
|
|
|
1560
1666
|
process: {
|
|
1561
1667
|
argv: () => process.argv,
|
|
1562
1668
|
cwd: process.cwd,
|
|
1563
|
-
emitWarning: (warning,
|
|
1669
|
+
emitWarning: (warning, type2) => process.emitWarning(warning, type2),
|
|
1564
1670
|
execPath: () => process.execPath,
|
|
1565
1671
|
exit: process.exit,
|
|
1566
1672
|
nextTick: process.nextTick,
|
|
@@ -1658,7 +1764,7 @@ function argsert(arg1, arg2, arg3) {
|
|
|
1658
1764
|
parsed.demanded.forEach((demanded) => {
|
|
1659
1765
|
const arg = args2.shift();
|
|
1660
1766
|
const observedType = guessType(arg);
|
|
1661
|
-
const matchingTypes = demanded.cmd.filter((
|
|
1767
|
+
const matchingTypes = demanded.cmd.filter((type2) => type2 === observedType || type2 === "*");
|
|
1662
1768
|
if (matchingTypes.length === 0)
|
|
1663
1769
|
argumentTypeError(observedType, demanded.cmd, position);
|
|
1664
1770
|
position += 1;
|
|
@@ -1668,7 +1774,7 @@ function argsert(arg1, arg2, arg3) {
|
|
|
1668
1774
|
return;
|
|
1669
1775
|
const arg = args2.shift();
|
|
1670
1776
|
const observedType = guessType(arg);
|
|
1671
|
-
const matchingTypes = optional.cmd.filter((
|
|
1777
|
+
const matchingTypes = optional.cmd.filter((type2) => type2 === observedType || type2 === "*");
|
|
1672
1778
|
if (matchingTypes.length === 0)
|
|
1673
1779
|
argumentTypeError(observedType, optional.cmd, position);
|
|
1674
1780
|
position += 1;
|
|
@@ -1790,8 +1896,8 @@ function isFunction(arg) {
|
|
|
1790
1896
|
function whichModule(exported) {
|
|
1791
1897
|
if (typeof __require === "undefined")
|
|
1792
1898
|
return null;
|
|
1793
|
-
for (let i = 0,
|
|
1794
|
-
mod = __require.cache[
|
|
1899
|
+
for (let i = 0, files2 = Object.keys(__require.cache), mod; i < files2.length; i++) {
|
|
1900
|
+
mod = __require.cache[files2[i]];
|
|
1795
1901
|
if (mod.exports === exported)
|
|
1796
1902
|
return mod;
|
|
1797
1903
|
}
|
|
@@ -1831,7 +1937,7 @@ var CommandInstance = class {
|
|
|
1831
1937
|
};
|
|
1832
1938
|
this.shim.requireDirectory({ require: req, filename: callerFile }, dir, opts);
|
|
1833
1939
|
}
|
|
1834
|
-
addHandler(cmd,
|
|
1940
|
+
addHandler(cmd, description2, builder, handler, commandMiddleware, deprecated) {
|
|
1835
1941
|
let aliases = [];
|
|
1836
1942
|
const middlewares = commandMiddlewareFactory(commandMiddleware);
|
|
1837
1943
|
handler = handler || (() => {
|
|
@@ -1851,7 +1957,7 @@ var CommandInstance = class {
|
|
|
1851
1957
|
this.addHandler(command2, this.extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
1852
1958
|
return;
|
|
1853
1959
|
} else if (isCommandBuilderDefinition(builder)) {
|
|
1854
|
-
this.addHandler([cmd].concat(aliases),
|
|
1960
|
+
this.addHandler([cmd].concat(aliases), description2, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
|
|
1855
1961
|
return;
|
|
1856
1962
|
}
|
|
1857
1963
|
if (typeof cmd === "string") {
|
|
@@ -1875,12 +1981,12 @@ var CommandInstance = class {
|
|
|
1875
1981
|
aliases.forEach((alias) => {
|
|
1876
1982
|
this.aliasMap[alias] = parsedCommand.cmd;
|
|
1877
1983
|
});
|
|
1878
|
-
if (
|
|
1879
|
-
this.usage.command(cmd,
|
|
1984
|
+
if (description2 !== false) {
|
|
1985
|
+
this.usage.command(cmd, description2, isDefault, aliases, deprecated);
|
|
1880
1986
|
}
|
|
1881
1987
|
this.handlers[parsedCommand.cmd] = {
|
|
1882
1988
|
original: cmd,
|
|
1883
|
-
description,
|
|
1989
|
+
description: description2,
|
|
1884
1990
|
handler,
|
|
1885
1991
|
builder: builder || {},
|
|
1886
1992
|
middlewares,
|
|
@@ -2139,8 +2245,8 @@ var CommandInstance = class {
|
|
|
2139
2245
|
commandFromFilename(filename) {
|
|
2140
2246
|
return this.shim.path.basename(filename, this.shim.path.extname(filename));
|
|
2141
2247
|
}
|
|
2142
|
-
extractDesc({ describe, description, desc }) {
|
|
2143
|
-
for (const test of [describe,
|
|
2248
|
+
extractDesc({ describe, description: description2, desc }) {
|
|
2249
|
+
for (const test of [describe, description2, desc]) {
|
|
2144
2250
|
if (typeof test === "string" || test === false)
|
|
2145
2251
|
return test;
|
|
2146
2252
|
assertNotStrictEqual(test, true, this.shim);
|
|
@@ -2281,14 +2387,14 @@ function usage(yargs, shim3) {
|
|
|
2281
2387
|
};
|
|
2282
2388
|
let usages = [];
|
|
2283
2389
|
let usageDisabled = false;
|
|
2284
|
-
self.usage = (msg,
|
|
2390
|
+
self.usage = (msg, description2) => {
|
|
2285
2391
|
if (msg === null) {
|
|
2286
2392
|
usageDisabled = true;
|
|
2287
2393
|
usages = [];
|
|
2288
2394
|
return self;
|
|
2289
2395
|
}
|
|
2290
2396
|
usageDisabled = false;
|
|
2291
|
-
usages.push([msg,
|
|
2397
|
+
usages.push([msg, description2 || ""]);
|
|
2292
2398
|
return self;
|
|
2293
2399
|
};
|
|
2294
2400
|
self.getUsage = () => {
|
|
@@ -2301,18 +2407,18 @@ function usage(yargs, shim3) {
|
|
|
2301
2407
|
return __("Positionals:");
|
|
2302
2408
|
};
|
|
2303
2409
|
let examples = [];
|
|
2304
|
-
self.example = (cmd,
|
|
2305
|
-
examples.push([cmd,
|
|
2410
|
+
self.example = (cmd, description2) => {
|
|
2411
|
+
examples.push([cmd, description2 || ""]);
|
|
2306
2412
|
};
|
|
2307
2413
|
let commands = [];
|
|
2308
|
-
self.command = function command2(cmd,
|
|
2414
|
+
self.command = function command2(cmd, description2, isDefault, aliases, deprecated = false) {
|
|
2309
2415
|
if (isDefault) {
|
|
2310
2416
|
commands = commands.map((cmdArray) => {
|
|
2311
2417
|
cmdArray[2] = false;
|
|
2312
2418
|
return cmdArray;
|
|
2313
2419
|
});
|
|
2314
2420
|
}
|
|
2315
|
-
commands.push([cmd,
|
|
2421
|
+
commands.push([cmd, description2 || "", isDefault, aliases, deprecated]);
|
|
2316
2422
|
};
|
|
2317
2423
|
self.getCommands = () => commands;
|
|
2318
2424
|
let descriptions = {};
|
|
@@ -2485,25 +2591,25 @@ function usage(yargs, shim3) {
|
|
|
2485
2591
|
normalizedKeys.forEach((key) => {
|
|
2486
2592
|
const kswitch = switches[key];
|
|
2487
2593
|
let desc = descriptions[key] || "";
|
|
2488
|
-
let
|
|
2594
|
+
let type2 = null;
|
|
2489
2595
|
if (desc.includes(deferY18nLookupPrefix))
|
|
2490
2596
|
desc = __(desc.substring(deferY18nLookupPrefix.length));
|
|
2491
2597
|
if (options.boolean.includes(key))
|
|
2492
|
-
|
|
2598
|
+
type2 = `[${__("boolean")}]`;
|
|
2493
2599
|
if (options.count.includes(key))
|
|
2494
|
-
|
|
2600
|
+
type2 = `[${__("count")}]`;
|
|
2495
2601
|
if (options.string.includes(key))
|
|
2496
|
-
|
|
2602
|
+
type2 = `[${__("string")}]`;
|
|
2497
2603
|
if (options.normalize.includes(key))
|
|
2498
|
-
|
|
2604
|
+
type2 = `[${__("string")}]`;
|
|
2499
2605
|
if (options.array.includes(key))
|
|
2500
|
-
|
|
2606
|
+
type2 = `[${__("array")}]`;
|
|
2501
2607
|
if (options.number.includes(key))
|
|
2502
|
-
|
|
2608
|
+
type2 = `[${__("number")}]`;
|
|
2503
2609
|
const deprecatedExtra = (deprecated) => typeof deprecated === "string" ? `[${__("deprecated: %s", deprecated)}]` : `[${__("deprecated")}]`;
|
|
2504
2610
|
const extra = [
|
|
2505
2611
|
key in deprecatedOptions ? deprecatedExtra(deprecatedOptions[key]) : null,
|
|
2506
|
-
|
|
2612
|
+
type2,
|
|
2507
2613
|
key in demandedOptions ? `[${__("required")}]` : null,
|
|
2508
2614
|
options.choices && options.choices[key] ? `[${__("choices:")} ${self.stringifiedValues(options.choices[key])}]` : null,
|
|
2509
2615
|
defaultString(options.default[key], options.defaultDescription[key])
|
|
@@ -2622,8 +2728,8 @@ function usage(yargs, shim3) {
|
|
|
2622
2728
|
emit(self.help());
|
|
2623
2729
|
};
|
|
2624
2730
|
self.functionDescription = (fn) => {
|
|
2625
|
-
const
|
|
2626
|
-
return ["(",
|
|
2731
|
+
const description2 = fn.name ? shim3.Parser.decamelize(fn.name, "-") : __("generated-value");
|
|
2732
|
+
return ["(", description2, ")"].join("");
|
|
2627
2733
|
};
|
|
2628
2734
|
self.stringifiedValues = function stringifiedValues(values, separator) {
|
|
2629
2735
|
let string = "";
|
|
@@ -2666,16 +2772,16 @@ function usage(yargs, shim3) {
|
|
|
2666
2772
|
return maxWidth2;
|
|
2667
2773
|
}
|
|
2668
2774
|
}
|
|
2669
|
-
let
|
|
2775
|
+
let version2 = null;
|
|
2670
2776
|
self.version = (ver) => {
|
|
2671
|
-
|
|
2777
|
+
version2 = ver;
|
|
2672
2778
|
};
|
|
2673
2779
|
self.showVersion = (level) => {
|
|
2674
2780
|
const logger2 = yargs.getInternalMethods().getLoggerInstance();
|
|
2675
2781
|
if (!level)
|
|
2676
2782
|
level = "error";
|
|
2677
2783
|
const emit = typeof level === "function" ? level : logger2[level];
|
|
2678
|
-
emit(
|
|
2784
|
+
emit(version2);
|
|
2679
2785
|
};
|
|
2680
2786
|
self.reset = function reset(localLookup) {
|
|
2681
2787
|
failMessage = null;
|
|
@@ -2979,10 +3085,10 @@ var Completion = class {
|
|
|
2979
3085
|
}
|
|
2980
3086
|
generateCompletionScript($0, cmd) {
|
|
2981
3087
|
let script = this.zshShell ? completionZshTemplate : completionShTemplate;
|
|
2982
|
-
const
|
|
3088
|
+
const name2 = this.shim.path.basename($0);
|
|
2983
3089
|
if ($0.match(/\.js$/))
|
|
2984
3090
|
$0 = `./${$0}`;
|
|
2985
|
-
script = script.replace(/{{app_name}}/g,
|
|
3091
|
+
script = script.replace(/{{app_name}}/g, name2);
|
|
2986
3092
|
script = script.replace(/{{completion_command}}/g, cmd);
|
|
2987
3093
|
return script.replace(/{{app_path}}/g, $0);
|
|
2988
3094
|
}
|
|
@@ -3663,13 +3769,13 @@ var YargsInstance = class {
|
|
|
3663
3769
|
__classPrivateFieldGet(this, _YargsInstance_completion, "f").registerFunction(fn);
|
|
3664
3770
|
return this;
|
|
3665
3771
|
}
|
|
3666
|
-
command(cmd,
|
|
3667
|
-
argsert("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]", [cmd,
|
|
3668
|
-
__classPrivateFieldGet(this, _YargsInstance_command, "f").addHandler(cmd,
|
|
3772
|
+
command(cmd, description2, builder, handler, middlewares, deprecated) {
|
|
3773
|
+
argsert("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]", [cmd, description2, builder, handler, middlewares, deprecated], arguments.length);
|
|
3774
|
+
__classPrivateFieldGet(this, _YargsInstance_command, "f").addHandler(cmd, description2, builder, handler, middlewares, deprecated);
|
|
3669
3775
|
return this;
|
|
3670
3776
|
}
|
|
3671
|
-
commands(cmd,
|
|
3672
|
-
return this.command(cmd,
|
|
3777
|
+
commands(cmd, description2, builder, handler, middlewares, deprecated) {
|
|
3778
|
+
return this.command(cmd, description2, builder, handler, middlewares, deprecated);
|
|
3673
3779
|
}
|
|
3674
3780
|
commandDir(dir, opts) {
|
|
3675
3781
|
argsert("<string> [object]", [dir, opts], arguments.length);
|
|
@@ -3754,10 +3860,10 @@ var YargsInstance = class {
|
|
|
3754
3860
|
__classPrivateFieldGet(this, _YargsInstance_options, "f").deprecatedOptions[option] = message;
|
|
3755
3861
|
return this;
|
|
3756
3862
|
}
|
|
3757
|
-
describe(keys,
|
|
3758
|
-
argsert("<object|string|array> [string]", [keys,
|
|
3863
|
+
describe(keys, description2) {
|
|
3864
|
+
argsert("<object|string|array> [string]", [keys, description2], arguments.length);
|
|
3759
3865
|
this[kSetKey](keys, true);
|
|
3760
|
-
__classPrivateFieldGet(this, _YargsInstance_usage, "f").describe(keys,
|
|
3866
|
+
__classPrivateFieldGet(this, _YargsInstance_usage, "f").describe(keys, description2);
|
|
3761
3867
|
return this;
|
|
3762
3868
|
}
|
|
3763
3869
|
detectLocale(detect) {
|
|
@@ -3781,12 +3887,12 @@ var YargsInstance = class {
|
|
|
3781
3887
|
epilog(msg) {
|
|
3782
3888
|
return this.epilogue(msg);
|
|
3783
3889
|
}
|
|
3784
|
-
example(cmd,
|
|
3785
|
-
argsert("<string|array> [string]", [cmd,
|
|
3890
|
+
example(cmd, description2) {
|
|
3891
|
+
argsert("<string|array> [string]", [cmd, description2], arguments.length);
|
|
3786
3892
|
if (Array.isArray(cmd)) {
|
|
3787
3893
|
cmd.forEach((exampleParams) => this.example(...exampleParams));
|
|
3788
3894
|
} else {
|
|
3789
|
-
__classPrivateFieldGet(this, _YargsInstance_usage, "f").example(cmd,
|
|
3895
|
+
__classPrivateFieldGet(this, _YargsInstance_usage, "f").example(cmd, description2);
|
|
3790
3896
|
}
|
|
3791
3897
|
return this;
|
|
3792
3898
|
}
|
|
@@ -4271,12 +4377,12 @@ var YargsInstance = class {
|
|
|
4271
4377
|
__classPrivateFieldGet(this, _YargsInstance_shim, "f").y18n.updateLocale(obj);
|
|
4272
4378
|
return this;
|
|
4273
4379
|
}
|
|
4274
|
-
usage(msg,
|
|
4275
|
-
argsert("<string|null|undefined> [string|boolean] [function|object] [function]", [msg,
|
|
4276
|
-
if (
|
|
4380
|
+
usage(msg, description2, builder, handler) {
|
|
4381
|
+
argsert("<string|null|undefined> [string|boolean] [function|object] [function]", [msg, description2, builder, handler], arguments.length);
|
|
4382
|
+
if (description2 !== void 0) {
|
|
4277
4383
|
assertNotStrictEqual(msg, null, __classPrivateFieldGet(this, _YargsInstance_shim, "f"));
|
|
4278
4384
|
if ((msg || "").match(/^\$0( |$)/)) {
|
|
4279
|
-
return this.command(msg,
|
|
4385
|
+
return this.command(msg, description2, builder, handler);
|
|
4280
4386
|
} else {
|
|
4281
4387
|
throw new YError(".usage() description must start with $0 if being used as alias for .command()");
|
|
4282
4388
|
}
|
|
@@ -4367,9 +4473,9 @@ var YargsInstance = class {
|
|
|
4367
4473
|
});
|
|
4368
4474
|
delete __classPrivateFieldGet(this, _YargsInstance_usage, "f").getDescriptions()[optionKey];
|
|
4369
4475
|
}
|
|
4370
|
-
[kEmitWarning](warning,
|
|
4476
|
+
[kEmitWarning](warning, type2, deduplicationId) {
|
|
4371
4477
|
if (!__classPrivateFieldGet(this, _YargsInstance_emittedWarnings, "f")[deduplicationId]) {
|
|
4372
|
-
__classPrivateFieldGet(this, _YargsInstance_shim, "f").process.emitWarning(warning,
|
|
4478
|
+
__classPrivateFieldGet(this, _YargsInstance_shim, "f").process.emitWarning(warning, type2);
|
|
4373
4479
|
__classPrivateFieldGet(this, _YargsInstance_emittedWarnings, "f")[deduplicationId] = true;
|
|
4374
4480
|
}
|
|
4375
4481
|
}
|
|
@@ -4461,24 +4567,24 @@ var YargsInstance = class {
|
|
|
4461
4567
|
__classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath] = obj || {};
|
|
4462
4568
|
return __classPrivateFieldGet(this, _YargsInstance_pkgs, "f")[npath];
|
|
4463
4569
|
}
|
|
4464
|
-
[kPopulateParserHintArray](
|
|
4570
|
+
[kPopulateParserHintArray](type2, keys) {
|
|
4465
4571
|
keys = [].concat(keys);
|
|
4466
4572
|
keys.forEach((key) => {
|
|
4467
4573
|
key = this[kSanitizeKey](key);
|
|
4468
|
-
__classPrivateFieldGet(this, _YargsInstance_options, "f")[
|
|
4574
|
+
__classPrivateFieldGet(this, _YargsInstance_options, "f")[type2].push(key);
|
|
4469
4575
|
});
|
|
4470
4576
|
}
|
|
4471
|
-
[kPopulateParserHintSingleValueDictionary](builder,
|
|
4472
|
-
this[kPopulateParserHintDictionary](builder,
|
|
4473
|
-
__classPrivateFieldGet(this, _YargsInstance_options, "f")[
|
|
4577
|
+
[kPopulateParserHintSingleValueDictionary](builder, type2, key, value) {
|
|
4578
|
+
this[kPopulateParserHintDictionary](builder, type2, key, value, (type3, key2, value2) => {
|
|
4579
|
+
__classPrivateFieldGet(this, _YargsInstance_options, "f")[type3][key2] = value2;
|
|
4474
4580
|
});
|
|
4475
4581
|
}
|
|
4476
|
-
[kPopulateParserHintArrayDictionary](builder,
|
|
4477
|
-
this[kPopulateParserHintDictionary](builder,
|
|
4478
|
-
__classPrivateFieldGet(this, _YargsInstance_options, "f")[
|
|
4582
|
+
[kPopulateParserHintArrayDictionary](builder, type2, key, value) {
|
|
4583
|
+
this[kPopulateParserHintDictionary](builder, type2, key, value, (type3, key2, value2) => {
|
|
4584
|
+
__classPrivateFieldGet(this, _YargsInstance_options, "f")[type3][key2] = (__classPrivateFieldGet(this, _YargsInstance_options, "f")[type3][key2] || []).concat(value2);
|
|
4479
4585
|
});
|
|
4480
4586
|
}
|
|
4481
|
-
[kPopulateParserHintDictionary](builder,
|
|
4587
|
+
[kPopulateParserHintDictionary](builder, type2, key, value, singleKeyHandler) {
|
|
4482
4588
|
if (Array.isArray(key)) {
|
|
4483
4589
|
key.forEach((k) => {
|
|
4484
4590
|
builder(k, value);
|
|
@@ -4488,7 +4594,7 @@ var YargsInstance = class {
|
|
|
4488
4594
|
builder(k, key[k]);
|
|
4489
4595
|
}
|
|
4490
4596
|
} else {
|
|
4491
|
-
singleKeyHandler(
|
|
4597
|
+
singleKeyHandler(type2, this[kSanitizeKey](key), value);
|
|
4492
4598
|
}
|
|
4493
4599
|
}
|
|
4494
4600
|
[kSanitizeKey](key) {
|
|
@@ -4899,24 +5005,26 @@ async function createMock() {
|
|
|
4899
5005
|
const activeWorkflows = {};
|
|
4900
5006
|
const bus = new EventEmitter();
|
|
4901
5007
|
const listeners = {};
|
|
4902
|
-
const dispatch = (
|
|
5008
|
+
const dispatch = (type2, args2) => {
|
|
4903
5009
|
if (args2.workflowId) {
|
|
4904
|
-
listeners[args2.workflowId]?.[
|
|
5010
|
+
listeners[args2.workflowId]?.[type2]?.(args2);
|
|
4905
5011
|
}
|
|
4906
|
-
bus.emit(
|
|
5012
|
+
bus.emit(type2, args2);
|
|
4907
5013
|
};
|
|
4908
5014
|
const on = (event, fn) => bus.on(event, fn);
|
|
4909
5015
|
const once = (event, fn) => bus.once(event, fn);
|
|
4910
5016
|
const listen = (planId, events) => {
|
|
4911
5017
|
listeners[planId] = events;
|
|
4912
5018
|
};
|
|
4913
|
-
const execute2 = async (xplan, options = {
|
|
5019
|
+
const execute2 = async (xplan, input, options = {
|
|
4914
5020
|
resolvers: resolvers_default
|
|
4915
5021
|
}) => {
|
|
4916
|
-
const { id
|
|
5022
|
+
const { id } = xplan;
|
|
5023
|
+
const { steps } = xplan.workflow;
|
|
4917
5024
|
activeWorkflows[id] = true;
|
|
4918
5025
|
const threadId = crypto.randomUUID();
|
|
4919
|
-
for (const
|
|
5026
|
+
for (const step of steps) {
|
|
5027
|
+
const job = step;
|
|
4920
5028
|
if (typeof job.configuration === "string") {
|
|
4921
5029
|
job.configuration = await options.resolvers?.credential?.(
|
|
4922
5030
|
job.configuration
|
|
@@ -4944,8 +5052,8 @@ async function createMock() {
|
|
|
4944
5052
|
...options,
|
|
4945
5053
|
globals: helpers,
|
|
4946
5054
|
callbacks: {
|
|
4947
|
-
notify: (
|
|
4948
|
-
dispatch(
|
|
5055
|
+
notify: (name2, payload) => {
|
|
5056
|
+
dispatch(name2, {
|
|
4949
5057
|
workflowId: id,
|
|
4950
5058
|
threadId,
|
|
4951
5059
|
...payload
|
|
@@ -4956,7 +5064,7 @@ async function createMock() {
|
|
|
4956
5064
|
setTimeout(async () => {
|
|
4957
5065
|
dispatch("workflow-start", { workflowId: id, threadId });
|
|
4958
5066
|
try {
|
|
4959
|
-
await run(xplan,
|
|
5067
|
+
await run(xplan, input, opts);
|
|
4960
5068
|
dispatch("workflow-complete", { workflowId: id, threadId });
|
|
4961
5069
|
} catch (e) {
|
|
4962
5070
|
dispatch("workflow-error", {
|
|
@@ -4999,8 +5107,8 @@ import { createMockLogger as createMockLogger2 } from "@openfn/logger";
|
|
|
4999
5107
|
// src/events.ts
|
|
5000
5108
|
var CLAIM = "claim";
|
|
5001
5109
|
var GET_PLAN = "fetch:plan";
|
|
5002
|
-
var GET_CREDENTIAL = "fetch:credential";
|
|
5003
5110
|
var GET_DATACLIP = "fetch:dataclip";
|
|
5111
|
+
var GET_CREDENTIAL = "fetch:credential";
|
|
5004
5112
|
var RUN_START = "run:start";
|
|
5005
5113
|
var RUN_COMPLETE = "run:complete";
|
|
5006
5114
|
var RUN_LOG = "run:log";
|
|
@@ -5024,6 +5132,7 @@ var destroy = async (app, logger2) => {
|
|
|
5024
5132
|
await waitForRuns(app, logger2);
|
|
5025
5133
|
await app.engine.destroy();
|
|
5026
5134
|
app.socket?.disconnect();
|
|
5135
|
+
logger2.info("Server closed....");
|
|
5027
5136
|
resolve5();
|
|
5028
5137
|
})
|
|
5029
5138
|
]);
|
|
@@ -5048,6 +5157,7 @@ var waitForRuns = (app, logger2) => new Promise((resolve5) => {
|
|
|
5048
5157
|
log();
|
|
5049
5158
|
app.events.on(INTERNAL_RUN_COMPLETE, onRunComplete);
|
|
5050
5159
|
} else {
|
|
5160
|
+
logger2.debug("No active rns detected");
|
|
5051
5161
|
resolve5();
|
|
5052
5162
|
}
|
|
5053
5163
|
});
|
|
@@ -5095,10 +5205,22 @@ var tryWithBackoff = (fn, opts = {}) => {
|
|
|
5095
5205
|
var try_with_backoff_default = tryWithBackoff;
|
|
5096
5206
|
|
|
5097
5207
|
// src/api/claim.ts
|
|
5208
|
+
import crypto2 from "node:crypto";
|
|
5209
|
+
import * as jose from "jose";
|
|
5098
5210
|
import { createMockLogger } from "@openfn/logger";
|
|
5099
5211
|
var mockLogger = createMockLogger();
|
|
5100
|
-
var
|
|
5212
|
+
var verifyToken = async (token, publicKey) => {
|
|
5213
|
+
const key = crypto2.createPublicKey(publicKey);
|
|
5214
|
+
const { payload } = await jose.jwtVerify(token, key, {
|
|
5215
|
+
issuer: "Lightning"
|
|
5216
|
+
});
|
|
5217
|
+
if (payload) {
|
|
5218
|
+
return true;
|
|
5219
|
+
}
|
|
5220
|
+
};
|
|
5221
|
+
var claim = (app, logger2 = mockLogger, options = {}) => {
|
|
5101
5222
|
return new Promise((resolve5, reject) => {
|
|
5223
|
+
const { maxWorkers = 5 } = options;
|
|
5102
5224
|
const activeWorkers = Object.keys(app.workflows).length;
|
|
5103
5225
|
if (activeWorkers >= maxWorkers) {
|
|
5104
5226
|
return reject(new Error("Server at capacity"));
|
|
@@ -5112,7 +5234,21 @@ var claim = (app, logger2 = mockLogger, maxWorkers = 5) => {
|
|
|
5112
5234
|
if (!runs?.length) {
|
|
5113
5235
|
return reject(new Error("No runs returned"));
|
|
5114
5236
|
}
|
|
5115
|
-
runs.forEach((run2) => {
|
|
5237
|
+
runs.forEach(async (run2) => {
|
|
5238
|
+
if (app.options?.runPublicKey) {
|
|
5239
|
+
try {
|
|
5240
|
+
await verifyToken(run2.token, app.options.runPublicKey);
|
|
5241
|
+
logger2.debug("verified run token for", run2.id);
|
|
5242
|
+
} catch (e) {
|
|
5243
|
+
logger2.error("Error validating run token");
|
|
5244
|
+
logger2.error(e);
|
|
5245
|
+
reject();
|
|
5246
|
+
app.destroy();
|
|
5247
|
+
return;
|
|
5248
|
+
}
|
|
5249
|
+
} else {
|
|
5250
|
+
logger2.debug("skipping run token validation for", run2.id);
|
|
5251
|
+
}
|
|
5116
5252
|
logger2.debug("starting run", run2.id);
|
|
5117
5253
|
app.execute(run2);
|
|
5118
5254
|
resolve5();
|
|
@@ -5133,10 +5269,15 @@ var startWorkloop = (app, logger2, minBackoff2, maxBackoff2, maxWorkers) => {
|
|
|
5133
5269
|
let cancelled = false;
|
|
5134
5270
|
const workLoop = () => {
|
|
5135
5271
|
if (!cancelled) {
|
|
5136
|
-
promise = try_with_backoff_default(
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5272
|
+
promise = try_with_backoff_default(
|
|
5273
|
+
() => claim_default(app, logger2, {
|
|
5274
|
+
maxWorkers
|
|
5275
|
+
}),
|
|
5276
|
+
{
|
|
5277
|
+
min: minBackoff2,
|
|
5278
|
+
max: maxBackoff2
|
|
5279
|
+
}
|
|
5280
|
+
);
|
|
5140
5281
|
promise.then(() => {
|
|
5141
5282
|
if (!cancelled) {
|
|
5142
5283
|
setTimeout(workLoop, minBackoff2);
|
|
@@ -5154,8 +5295,8 @@ var startWorkloop = (app, logger2, minBackoff2, maxBackoff2, maxWorkers) => {
|
|
|
5154
5295
|
};
|
|
5155
5296
|
var workloop_default = startWorkloop;
|
|
5156
5297
|
|
|
5157
|
-
// src/util/convert-
|
|
5158
|
-
import
|
|
5298
|
+
// src/util/convert-lightning-plan.ts
|
|
5299
|
+
import crypto3 from "node:crypto";
|
|
5159
5300
|
var conditions = {
|
|
5160
5301
|
on_job_success: (upstreamId) => `Boolean(!state?.errors?.["${upstreamId}"] ?? true)`,
|
|
5161
5302
|
on_job_failure: (upstreamId) => `Boolean(state?.errors && state.errors["${upstreamId}"])`,
|
|
@@ -5175,19 +5316,30 @@ var mapTriggerEdgeCondition = (edge) => {
|
|
|
5175
5316
|
return true;
|
|
5176
5317
|
return condition;
|
|
5177
5318
|
};
|
|
5178
|
-
var
|
|
5179
|
-
|
|
5180
|
-
};
|
|
5181
|
-
|
|
5182
|
-
|
|
5319
|
+
var convert_lightning_plan_default = (run2) => {
|
|
5320
|
+
const runtimeOpts = {};
|
|
5321
|
+
const engineOpts = {};
|
|
5322
|
+
if (run2.options) {
|
|
5323
|
+
if (run2.options.runTimeoutMs) {
|
|
5324
|
+
engineOpts.runTimeoutMs = run2.options.runTimeoutMs;
|
|
5325
|
+
}
|
|
5326
|
+
if (run2.options.sanitize) {
|
|
5327
|
+
engineOpts.sanitize = run2.options.sanitize;
|
|
5328
|
+
}
|
|
5329
|
+
if (run2.options.hasOwnProperty("output_dataclips")) {
|
|
5330
|
+
engineOpts.outputDataclips = run2.options.output_dataclips;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5183
5333
|
const plan = {
|
|
5184
|
-
id: run2.id
|
|
5334
|
+
id: run2.id,
|
|
5335
|
+
options: runtimeOpts
|
|
5185
5336
|
};
|
|
5337
|
+
let initialState;
|
|
5186
5338
|
if (run2.dataclip_id) {
|
|
5187
|
-
|
|
5339
|
+
initialState = run2.dataclip_id;
|
|
5188
5340
|
}
|
|
5189
5341
|
if (run2.starting_node_id) {
|
|
5190
|
-
|
|
5342
|
+
runtimeOpts.start = run2.starting_node_id;
|
|
5191
5343
|
}
|
|
5192
5344
|
const nodes = {};
|
|
5193
5345
|
const edges = run2.edges ?? [];
|
|
@@ -5199,27 +5351,33 @@ var convert_run_default = (run2) => {
|
|
|
5199
5351
|
};
|
|
5200
5352
|
const connectedEdges = edges.filter((e) => e.source_trigger_id === id);
|
|
5201
5353
|
if (connectedEdges.length) {
|
|
5202
|
-
nodes[id].next = connectedEdges.reduce(
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5354
|
+
nodes[id].next = connectedEdges.reduce(
|
|
5355
|
+
(obj, edge) => {
|
|
5356
|
+
if (edge.enabled !== false) {
|
|
5357
|
+
obj[edge.target_job_id] = mapTriggerEdgeCondition(edge);
|
|
5358
|
+
}
|
|
5359
|
+
return obj;
|
|
5360
|
+
},
|
|
5361
|
+
{}
|
|
5362
|
+
);
|
|
5208
5363
|
} else {
|
|
5209
5364
|
}
|
|
5210
5365
|
});
|
|
5211
5366
|
}
|
|
5212
5367
|
if (run2.jobs?.length) {
|
|
5213
|
-
run2.jobs.forEach((
|
|
5214
|
-
const id =
|
|
5215
|
-
|
|
5368
|
+
run2.jobs.forEach((step) => {
|
|
5369
|
+
const id = step.id || crypto3.randomUUID();
|
|
5370
|
+
const job = {
|
|
5216
5371
|
id,
|
|
5217
|
-
configuration:
|
|
5218
|
-
expression:
|
|
5219
|
-
adaptor:
|
|
5372
|
+
configuration: step.credential || step.credential_id,
|
|
5373
|
+
expression: step.body,
|
|
5374
|
+
adaptor: step.adaptor
|
|
5220
5375
|
};
|
|
5221
|
-
if (
|
|
5222
|
-
|
|
5376
|
+
if (step.name) {
|
|
5377
|
+
job.name = step.name;
|
|
5378
|
+
}
|
|
5379
|
+
if (step.state) {
|
|
5380
|
+
job.state = step.state;
|
|
5223
5381
|
}
|
|
5224
5382
|
const next = edges.filter((e) => e.source_job_id === id).reduce((obj, edge) => {
|
|
5225
5383
|
const newEdge = {};
|
|
@@ -5234,21 +5392,32 @@ var convert_run_default = (run2) => {
|
|
|
5234
5392
|
return obj;
|
|
5235
5393
|
}, {});
|
|
5236
5394
|
if (Object.keys(next).length) {
|
|
5237
|
-
|
|
5395
|
+
job.next = next;
|
|
5238
5396
|
}
|
|
5397
|
+
nodes[id] = job;
|
|
5239
5398
|
});
|
|
5240
5399
|
}
|
|
5241
|
-
plan.
|
|
5400
|
+
plan.workflow = {
|
|
5401
|
+
steps: Object.values(nodes)
|
|
5402
|
+
};
|
|
5403
|
+
if (run2.name) {
|
|
5404
|
+
plan.workflow.name = run2.name;
|
|
5405
|
+
}
|
|
5242
5406
|
return {
|
|
5243
5407
|
plan,
|
|
5244
|
-
options:
|
|
5408
|
+
options: engineOpts,
|
|
5409
|
+
input: initialState || {}
|
|
5245
5410
|
};
|
|
5246
5411
|
};
|
|
5247
5412
|
|
|
5248
5413
|
// src/util/get-with-reply.ts
|
|
5249
|
-
var get_with_reply_default = (channel, event, payload) => new Promise((resolve5) => {
|
|
5414
|
+
var get_with_reply_default = (channel, event, payload) => new Promise((resolve5, reject) => {
|
|
5250
5415
|
channel.push(event, payload).receive("ok", (evt) => {
|
|
5251
5416
|
resolve5(evt);
|
|
5417
|
+
}).receive("error", (e) => {
|
|
5418
|
+
reject(e);
|
|
5419
|
+
}).receive("timeout", (e) => {
|
|
5420
|
+
reject(e);
|
|
5252
5421
|
});
|
|
5253
5422
|
});
|
|
5254
5423
|
|
|
@@ -5262,19 +5431,20 @@ var stringify_default = (obj) => stringify(obj, (_key, value) => {
|
|
|
5262
5431
|
});
|
|
5263
5432
|
|
|
5264
5433
|
// src/util/create-run-state.ts
|
|
5265
|
-
var create_run_state_default = (plan,
|
|
5434
|
+
var create_run_state_default = (plan, input) => {
|
|
5266
5435
|
const state = {
|
|
5267
|
-
plan,
|
|
5268
5436
|
lastDataclipId: "",
|
|
5269
5437
|
dataclips: {},
|
|
5270
5438
|
inputDataclips: {},
|
|
5271
5439
|
reasons: {},
|
|
5272
|
-
|
|
5440
|
+
plan,
|
|
5441
|
+
input
|
|
5273
5442
|
};
|
|
5274
|
-
if (typeof
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5443
|
+
if (typeof input === "string") {
|
|
5444
|
+
const jobs = plan.workflow.steps;
|
|
5445
|
+
let startNode = jobs[0];
|
|
5446
|
+
if (plan.options.start) {
|
|
5447
|
+
startNode = jobs.find(({ id }) => id === plan.options.start);
|
|
5278
5448
|
}
|
|
5279
5449
|
const initialRuns = [];
|
|
5280
5450
|
if (!startNode.expression) {
|
|
@@ -5283,7 +5453,7 @@ var create_run_state_default = (plan, options = {}) => {
|
|
|
5283
5453
|
initialRuns.push(startNode.id);
|
|
5284
5454
|
}
|
|
5285
5455
|
initialRuns.forEach((id) => {
|
|
5286
|
-
state.inputDataclips[id] =
|
|
5456
|
+
state.inputDataclips[id] = input;
|
|
5287
5457
|
});
|
|
5288
5458
|
} else {
|
|
5289
5459
|
}
|
|
@@ -5318,7 +5488,7 @@ var createThrottler = () => {
|
|
|
5318
5488
|
var throttle_default = createThrottler;
|
|
5319
5489
|
|
|
5320
5490
|
// src/events/step-complete.ts
|
|
5321
|
-
import
|
|
5491
|
+
import crypto4 from "node:crypto";
|
|
5322
5492
|
|
|
5323
5493
|
// src/api/reasons.ts
|
|
5324
5494
|
var calculateJobExitReason = (jobId, state = { data: {} }, error) => {
|
|
@@ -5344,7 +5514,7 @@ var isLeafNode = (state, job) => {
|
|
|
5344
5514
|
};
|
|
5345
5515
|
var calculateRunExitReason = (state) => {
|
|
5346
5516
|
if (state.plan && state.reasons) {
|
|
5347
|
-
const leafJobReasons = state.plan.
|
|
5517
|
+
const leafJobReasons = state.plan.workflow.steps.filter((job) => isLeafNode(state, job)).map(({ id }) => state.reasons[id]);
|
|
5348
5518
|
const fail = leafJobReasons.find((r) => r && r.reason === "fail");
|
|
5349
5519
|
if (fail) {
|
|
5350
5520
|
return fail;
|
|
@@ -5354,8 +5524,8 @@ var calculateRunExitReason = (state) => {
|
|
|
5354
5524
|
};
|
|
5355
5525
|
|
|
5356
5526
|
// src/events/step-complete.ts
|
|
5357
|
-
function onStepComplete({ channel, state }, event, error) {
|
|
5358
|
-
const dataclipId =
|
|
5527
|
+
function onStepComplete({ channel, state, options }, event, error) {
|
|
5528
|
+
const dataclipId = crypto4.randomUUID();
|
|
5359
5529
|
const step_id = state.activeStep;
|
|
5360
5530
|
const job_id = state.activeJob;
|
|
5361
5531
|
if (!state.dataclips) {
|
|
@@ -5379,7 +5549,6 @@ function onStepComplete({ channel, state }, event, error) {
|
|
|
5379
5549
|
step_id,
|
|
5380
5550
|
job_id,
|
|
5381
5551
|
output_dataclip_id: dataclipId,
|
|
5382
|
-
output_dataclip: stringify_default(outputState),
|
|
5383
5552
|
reason,
|
|
5384
5553
|
error_message,
|
|
5385
5554
|
error_type,
|
|
@@ -5387,94 +5556,34 @@ function onStepComplete({ channel, state }, event, error) {
|
|
|
5387
5556
|
duration: event.duration,
|
|
5388
5557
|
thread_id: event.threadId
|
|
5389
5558
|
};
|
|
5559
|
+
if (!options || options.outputDataclips !== false) {
|
|
5560
|
+
evt.output_dataclip = stringify_default(outputState);
|
|
5561
|
+
}
|
|
5390
5562
|
return sendEvent(channel, STEP_COMPLETE, evt);
|
|
5391
5563
|
}
|
|
5392
5564
|
|
|
5393
5565
|
// src/events/step-start.ts
|
|
5394
|
-
|
|
5566
|
+
init_package();
|
|
5567
|
+
import crypto5 from "node:crypto";
|
|
5395
5568
|
import { timestamp } from "@openfn/logger";
|
|
5396
5569
|
|
|
5397
|
-
// package.json
|
|
5398
|
-
var package_default = {
|
|
5399
|
-
name: "@openfn/ws-worker",
|
|
5400
|
-
version: "0.8.1",
|
|
5401
|
-
description: "A Websocket Worker to connect Lightning to a Runtime Engine",
|
|
5402
|
-
main: "dist/index.js",
|
|
5403
|
-
type: "module",
|
|
5404
|
-
scripts: {
|
|
5405
|
-
test: "pnpm ava --serial",
|
|
5406
|
-
"test:types": "pnpm tsc --noEmit --project tsconfig.json",
|
|
5407
|
-
build: "tsup --config tsup.config.js",
|
|
5408
|
-
"build:watch": "pnpm build --watch",
|
|
5409
|
-
start: "ts-node-esm --transpile-only src/start.ts",
|
|
5410
|
-
"start:prod": "node dist/start.js",
|
|
5411
|
-
"start:watch": "nodemon -e ts,js --watch ../runtime-manager/dist --watch ./src --exec 'pnpm start'",
|
|
5412
|
-
pack: "pnpm pack --pack-destination ../../dist"
|
|
5413
|
-
},
|
|
5414
|
-
bin: {
|
|
5415
|
-
worker: "dist/start.js"
|
|
5416
|
-
},
|
|
5417
|
-
author: "Open Function Group <admin@openfn.org>",
|
|
5418
|
-
license: "ISC",
|
|
5419
|
-
dependencies: {
|
|
5420
|
-
"@koa/router": "^12.0.0",
|
|
5421
|
-
"@openfn/engine-multi": "workspace:*",
|
|
5422
|
-
"@openfn/logger": "workspace:*",
|
|
5423
|
-
"@openfn/runtime": "workspace:*",
|
|
5424
|
-
"@types/koa-logger": "^3.1.2",
|
|
5425
|
-
"@types/ws": "^8.5.6",
|
|
5426
|
-
"fast-safe-stringify": "^2.1.1",
|
|
5427
|
-
figures: "^5.0.0",
|
|
5428
|
-
"human-id": "^4.1.0",
|
|
5429
|
-
jose: "^4.14.6",
|
|
5430
|
-
koa: "^2.13.4",
|
|
5431
|
-
"koa-bodyparser": "^4.4.0",
|
|
5432
|
-
"koa-logger": "^3.2.1",
|
|
5433
|
-
phoenix: "^1.7.7",
|
|
5434
|
-
ws: "^8.14.1"
|
|
5435
|
-
},
|
|
5436
|
-
devDependencies: {
|
|
5437
|
-
"@openfn/lightning-mock": "workspace:*",
|
|
5438
|
-
"@types/koa": "^2.13.5",
|
|
5439
|
-
"@types/koa-bodyparser": "^4.3.10",
|
|
5440
|
-
"@types/koa__router": "^12.0.1",
|
|
5441
|
-
"@types/node": "^18.15.3",
|
|
5442
|
-
"@types/nodemon": "1.19.3",
|
|
5443
|
-
"@types/phoenix": "^1.6.2",
|
|
5444
|
-
"@types/yargs": "^17.0.12",
|
|
5445
|
-
ava: "5.1.0",
|
|
5446
|
-
nodemon: "3.0.1",
|
|
5447
|
-
"ts-node": "^10.9.1",
|
|
5448
|
-
tslib: "^2.4.0",
|
|
5449
|
-
tsup: "^6.2.3",
|
|
5450
|
-
typescript: "^4.6.4",
|
|
5451
|
-
yargs: "^17.6.2"
|
|
5452
|
-
},
|
|
5453
|
-
files: [
|
|
5454
|
-
"dist",
|
|
5455
|
-
"README.md",
|
|
5456
|
-
"CHANGELOG.md"
|
|
5457
|
-
]
|
|
5458
|
-
};
|
|
5459
|
-
|
|
5460
5570
|
// src/util/versions.ts
|
|
5461
5571
|
import { mainSymbols } from "figures";
|
|
5462
5572
|
var { triangleRightSmall: t } = mainSymbols;
|
|
5463
5573
|
var versions_default = (stepId, versions, adaptor) => {
|
|
5464
|
-
let longest = "
|
|
5574
|
+
let longest = "worker".length;
|
|
5465
5575
|
for (const v in versions) {
|
|
5466
5576
|
longest = Math.max(v.length, longest);
|
|
5467
5577
|
}
|
|
5468
|
-
const { node,
|
|
5578
|
+
const { node, worker, ...adaptors } = versions;
|
|
5469
5579
|
const prefix = (str2) => ` ${t} ${str2.padEnd(longest + 4, " ")}`;
|
|
5470
5580
|
let str = `Versions for step ${stepId}:
|
|
5471
5581
|
${prefix("node.js")}${versions.node || "unknown"}
|
|
5472
|
-
${prefix("worker")}${versions.worker || "unknown"}
|
|
5473
|
-
${prefix("engine")}${versions.engine || "unknown"}`;
|
|
5582
|
+
${prefix("worker")}${versions.worker || "unknown"}`;
|
|
5474
5583
|
if (Object.keys(adaptors).length) {
|
|
5475
5584
|
let allAdaptors = Object.keys(adaptors);
|
|
5476
5585
|
if (adaptor) {
|
|
5477
|
-
allAdaptors = allAdaptors.filter((
|
|
5586
|
+
allAdaptors = allAdaptors.filter((name2) => adaptor.startsWith(name2));
|
|
5478
5587
|
}
|
|
5479
5588
|
str += "\n" + allAdaptors.sort().map((adaptorName) => `${prefix(adaptorName)}${adaptors[adaptorName]}`).join("\n");
|
|
5480
5589
|
}
|
|
@@ -5485,9 +5594,11 @@ ${prefix("engine")}${versions.engine || "unknown"}`;
|
|
|
5485
5594
|
async function onStepStart(context, event) {
|
|
5486
5595
|
const time = (timestamp() - BigInt(1e7)).toString();
|
|
5487
5596
|
const { channel, state } = context;
|
|
5488
|
-
state.activeStep =
|
|
5597
|
+
state.activeStep = crypto5.randomUUID();
|
|
5489
5598
|
state.activeJob = event.jobId;
|
|
5490
|
-
const job = state.plan.
|
|
5599
|
+
const job = state.plan.workflow.steps.find(
|
|
5600
|
+
({ id }) => id === event.jobId
|
|
5601
|
+
);
|
|
5491
5602
|
const input_dataclip_id = state.inputDataclips[event.jobId];
|
|
5492
5603
|
const versions = {
|
|
5493
5604
|
worker: package_default.version,
|
|
@@ -5565,7 +5676,7 @@ async function onRunError(context, event) {
|
|
|
5565
5676
|
});
|
|
5566
5677
|
onFinish({ reason });
|
|
5567
5678
|
} catch (e) {
|
|
5568
|
-
logger2.error("ERROR in
|
|
5679
|
+
logger2.error("ERROR in run-error handler:", e.message);
|
|
5569
5680
|
logger2.error(e);
|
|
5570
5681
|
onFinish({});
|
|
5571
5682
|
}
|
|
@@ -5580,11 +5691,18 @@ var eventMap = {
|
|
|
5580
5691
|
"workflow-log": RUN_LOG,
|
|
5581
5692
|
"workflow-complete": RUN_COMPLETE
|
|
5582
5693
|
};
|
|
5583
|
-
function execute(channel, engine, logger2, plan, options = {}, onFinish = (_result) => {
|
|
5694
|
+
function execute(channel, engine, logger2, plan, input, options = {}, onFinish = (_result) => {
|
|
5584
5695
|
}) {
|
|
5585
5696
|
logger2.info("executing ", plan.id);
|
|
5586
|
-
const state = create_run_state_default(plan,
|
|
5587
|
-
const context = {
|
|
5697
|
+
const state = create_run_state_default(plan, input);
|
|
5698
|
+
const context = {
|
|
5699
|
+
channel,
|
|
5700
|
+
state,
|
|
5701
|
+
logger: logger2,
|
|
5702
|
+
engine,
|
|
5703
|
+
options,
|
|
5704
|
+
onFinish
|
|
5705
|
+
};
|
|
5588
5706
|
const throttle = throttle_default();
|
|
5589
5707
|
const addEvent = (eventName, handler) => {
|
|
5590
5708
|
const wrappedFn = async (event) => {
|
|
@@ -5617,17 +5735,24 @@ function execute(channel, engine, logger2, plan, options = {}, onFinish = (_resu
|
|
|
5617
5735
|
const resolvers = {
|
|
5618
5736
|
credential: (id) => loadCredential(channel, id)
|
|
5619
5737
|
};
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5738
|
+
setTimeout(async () => {
|
|
5739
|
+
let loadedInput = input;
|
|
5740
|
+
if (typeof input === "string") {
|
|
5741
|
+
logger2.debug("loading dataclip", input);
|
|
5742
|
+
try {
|
|
5743
|
+
loadedInput = await loadDataclip(channel, input);
|
|
5744
|
+
logger2.success("dataclip loaded");
|
|
5745
|
+
} catch (e) {
|
|
5746
|
+
return onRunError(context, {
|
|
5747
|
+
workflowId: plan.id,
|
|
5748
|
+
message: `Failed to load dataclip ${input}${e.message ? `: ${e.message}` : ""}`,
|
|
5749
|
+
type: "DataClipError",
|
|
5750
|
+
severity: "exception"
|
|
5751
|
+
});
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
5629
5754
|
try {
|
|
5630
|
-
engine.execute(plan, { resolvers, ...options });
|
|
5755
|
+
engine.execute(plan, loadedInput, { resolvers, ...options });
|
|
5631
5756
|
} catch (e) {
|
|
5632
5757
|
onRunError(context, {
|
|
5633
5758
|
workflowId: plan.id,
|
|
@@ -5696,9 +5821,9 @@ var joinRunChannel = (socket, token, runId, logger2) => {
|
|
|
5696
5821
|
if (!didReceiveOk) {
|
|
5697
5822
|
didReceiveOk = true;
|
|
5698
5823
|
logger2.success(`connected to ${channelName}`, e);
|
|
5699
|
-
const { plan, options } = await loadRun(channel);
|
|
5824
|
+
const { plan, options, input } = await loadRun(channel);
|
|
5700
5825
|
logger2.debug("converted run as execution plan:", plan);
|
|
5701
|
-
resolve5({ channel, plan, options });
|
|
5826
|
+
resolve5({ channel, plan, options, input });
|
|
5702
5827
|
}
|
|
5703
5828
|
}).receive("error", (err) => {
|
|
5704
5829
|
logger2.error(`error connecting to ${channelName}`, err);
|
|
@@ -5709,16 +5834,17 @@ var joinRunChannel = (socket, token, runId, logger2) => {
|
|
|
5709
5834
|
var run_default = joinRunChannel;
|
|
5710
5835
|
async function loadRun(channel) {
|
|
5711
5836
|
const runBody = await get_with_reply_default(channel, GET_PLAN);
|
|
5712
|
-
return
|
|
5837
|
+
return convert_lightning_plan_default(runBody);
|
|
5713
5838
|
}
|
|
5714
5839
|
|
|
5715
5840
|
// src/channels/worker-queue.ts
|
|
5716
5841
|
import EventEmitter2 from "node:events";
|
|
5717
5842
|
import { Socket as PhxSocket } from "phoenix";
|
|
5718
5843
|
import { WebSocket } from "ws";
|
|
5844
|
+
import { API_VERSION } from "@openfn/lexicon/lightning";
|
|
5719
5845
|
|
|
5720
5846
|
// src/util/worker-token.ts
|
|
5721
|
-
import * as
|
|
5847
|
+
import * as jose2 from "jose";
|
|
5722
5848
|
var alg = "HS256";
|
|
5723
5849
|
var generateWorkerToken = async (secret, workerId, logger2) => {
|
|
5724
5850
|
if (!secret) {
|
|
@@ -5733,7 +5859,7 @@ var generateWorkerToken = async (secret, workerId, logger2) => {
|
|
|
5733
5859
|
const claims = {
|
|
5734
5860
|
worker_id: workerId
|
|
5735
5861
|
};
|
|
5736
|
-
const jwt = await new
|
|
5862
|
+
const jwt = await new jose2.SignJWT(claims).setProtectedHeader({ alg }).setIssuedAt().setIssuer("urn:openfn:worker").sign(encodedSecret);
|
|
5737
5863
|
return jwt;
|
|
5738
5864
|
};
|
|
5739
5865
|
var worker_token_default = generateWorkerToken;
|
|
@@ -5741,9 +5867,15 @@ var worker_token_default = generateWorkerToken;
|
|
|
5741
5867
|
// src/channels/worker-queue.ts
|
|
5742
5868
|
var connectToWorkerQueue = (endpoint, serverId, secret, logger2, SocketConstructor = PhxSocket) => {
|
|
5743
5869
|
const events = new EventEmitter2();
|
|
5744
|
-
worker_token_default(secret, serverId, logger2).then((token) => {
|
|
5870
|
+
worker_token_default(secret, serverId, logger2).then(async (token) => {
|
|
5871
|
+
const pkg = await Promise.resolve().then(() => (init_package(), package_exports));
|
|
5872
|
+
const params = {
|
|
5873
|
+
token,
|
|
5874
|
+
api_version: API_VERSION,
|
|
5875
|
+
worker_version: pkg.default.version
|
|
5876
|
+
};
|
|
5745
5877
|
const socket = new SocketConstructor(endpoint, {
|
|
5746
|
-
params
|
|
5878
|
+
params,
|
|
5747
5879
|
transport: WebSocket
|
|
5748
5880
|
});
|
|
5749
5881
|
let didOpen = false;
|
|
@@ -5782,6 +5914,9 @@ var MAX_BACKOFF = 1e3 * 30;
|
|
|
5782
5914
|
function connect(app, logger2, options = {}) {
|
|
5783
5915
|
logger2.debug("Connecting to Lightning at", options.lightning);
|
|
5784
5916
|
const onConnect = ({ socket, channel }) => {
|
|
5917
|
+
if (app.destroyed) {
|
|
5918
|
+
return;
|
|
5919
|
+
}
|
|
5785
5920
|
logger2.success("Connected to Lightning at", options.lightning);
|
|
5786
5921
|
app.socket = socket;
|
|
5787
5922
|
app.queueChannel = channel;
|
|
@@ -5816,6 +5951,9 @@ function connect(app, logger2, options = {}) {
|
|
|
5816
5951
|
}
|
|
5817
5952
|
};
|
|
5818
5953
|
const onError = (e) => {
|
|
5954
|
+
if (app.destroyed) {
|
|
5955
|
+
return;
|
|
5956
|
+
}
|
|
5819
5957
|
logger2.error(
|
|
5820
5958
|
"CRITICAL ERROR: could not connect to lightning at",
|
|
5821
5959
|
options.lightning
|
|
@@ -5845,13 +5983,15 @@ function createServer(engine, options = {}) {
|
|
|
5845
5983
|
process.send?.("READY");
|
|
5846
5984
|
router.get("/livez", healthcheck_default);
|
|
5847
5985
|
router.get("/", healthcheck_default);
|
|
5986
|
+
app.options = options || {};
|
|
5848
5987
|
app.execute = async ({ id, token }) => {
|
|
5849
5988
|
if (app.socket) {
|
|
5850
5989
|
app.workflows[id] = true;
|
|
5851
5990
|
const {
|
|
5852
5991
|
channel: runChannel,
|
|
5853
5992
|
plan,
|
|
5854
|
-
options: options2
|
|
5993
|
+
options: options2,
|
|
5994
|
+
input
|
|
5855
5995
|
} = await run_default(app.socket, token, id, logger2);
|
|
5856
5996
|
const onFinish = () => {
|
|
5857
5997
|
delete app.workflows[id];
|
|
@@ -5863,6 +6003,7 @@ function createServer(engine, options = {}) {
|
|
|
5863
6003
|
engine,
|
|
5864
6004
|
logger2,
|
|
5865
6005
|
plan,
|
|
6006
|
+
input,
|
|
5866
6007
|
options2,
|
|
5867
6008
|
onFinish
|
|
5868
6009
|
);
|
|
@@ -5873,7 +6014,9 @@ function createServer(engine, options = {}) {
|
|
|
5873
6014
|
};
|
|
5874
6015
|
router.post("/claim", async (ctx) => {
|
|
5875
6016
|
logger2.info("triggering claim from POST request");
|
|
5876
|
-
return claim_default(app, logger2,
|
|
6017
|
+
return claim_default(app, logger2, {
|
|
6018
|
+
maxWorkers: options.maxWorkflows
|
|
6019
|
+
}).then(() => {
|
|
5877
6020
|
logger2.info("claim complete: 1 run claimed");
|
|
5878
6021
|
ctx.body = "complete";
|
|
5879
6022
|
ctx.status = 200;
|
|
@@ -5912,6 +6055,7 @@ var server_default = createServer;
|
|
|
5912
6055
|
var {
|
|
5913
6056
|
WORKER_BACKOFF,
|
|
5914
6057
|
WORKER_CAPACITY,
|
|
6058
|
+
WORKER_LIGHTNING_PUBLIC_KEY,
|
|
5915
6059
|
WORKER_LIGHTNING_SERVICE_URL,
|
|
5916
6060
|
WORKER_LOG_LEVEL,
|
|
5917
6061
|
WORKER_MAX_RUN_DURATION_SECONDS,
|
|
@@ -5938,6 +6082,9 @@ var args = yargs_default(hideBin(process.argv)).command("server", "Start a ws-wo
|
|
|
5938
6082
|
alias: "s",
|
|
5939
6083
|
description: "Worker secret. (comes from WORKER_SECRET by default). Env: WORKER_SECRET",
|
|
5940
6084
|
default: WORKER_SECRET
|
|
6085
|
+
}).option("lightning-public-key", {
|
|
6086
|
+
description: "Base64-encoded public key. Used to verify run tokens. Env: WORKER_LIGHTNING_PUBLIC_KEY",
|
|
6087
|
+
default: WORKER_LIGHTNING_PUBLIC_KEY
|
|
5941
6088
|
}).option("log", {
|
|
5942
6089
|
description: "Set the log level for stdout (default to info, set to debug for verbose output). Env: WORKER_LOG_LEVEL",
|
|
5943
6090
|
default: WORKER_LOG_LEVEL || "debug",
|
|
@@ -5996,7 +6143,21 @@ function engineReady(engine) {
|
|
|
5996
6143
|
},
|
|
5997
6144
|
maxWorkflows: args.capacity
|
|
5998
6145
|
};
|
|
5999
|
-
|
|
6146
|
+
if (args.lightningPublicKey) {
|
|
6147
|
+
logger.info(
|
|
6148
|
+
"Lightning public key found: run tokens from Lightning will be verified by this worker"
|
|
6149
|
+
);
|
|
6150
|
+
workerOptions.runPublicKey = Buffer.from(
|
|
6151
|
+
args.lightningPublicKey,
|
|
6152
|
+
"base64"
|
|
6153
|
+
).toString();
|
|
6154
|
+
}
|
|
6155
|
+
const {
|
|
6156
|
+
logger: _l,
|
|
6157
|
+
secret: _s,
|
|
6158
|
+
runPublicKey,
|
|
6159
|
+
...humanOptions
|
|
6160
|
+
} = workerOptions;
|
|
6000
6161
|
logger.debug("Worker options:", humanOptions);
|
|
6001
6162
|
server_default(engine, workerOptions);
|
|
6002
6163
|
}
|