@intuned/runtime-dev 0.1.0-test.8 → 1.0.0-udas.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/.babelrc +0 -2
- package/InterfaceTemplate/index.playwright.ts +5 -0
- package/InterfaceTemplate/utils.ts +39 -0
- package/WebTemplate/api.ts +90 -92
- package/WebTemplate/controllers/async.ts +52 -48
- package/WebTemplate/controllers/authSessions/check.ts +4 -5
- package/WebTemplate/controllers/authSessions/create.ts +6 -8
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +13 -8
- package/WebTemplate/index.playwright.ts +32 -42
- package/WebTemplate/jobs.ts +13 -2
- package/WebTemplate/utils.ts +48 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +7 -5
- package/dist/commands/auth-sessions/run-check.js +9 -3
- package/dist/commands/auth-sessions/run-create.js +11 -6
- package/dist/commands/build.js +16 -12
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/tsNodeImport.js +20 -0
- package/dist/commands/common/utils/settings.js +5 -5
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/{webTemplate.js → template.js} +7 -7
- package/dist/commands/interface/run.d.ts +1 -2
- package/dist/commands/interface/run.js +147 -110
- package/dist/commands/ts-check.js +9 -7
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/getPlaywrightConstructs.js +6 -2
- package/dist/common/runApi/errors.d.ts +8 -3
- package/dist/common/runApi/errors.js +26 -3
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +36 -65
- package/dist/common/runApi/types.d.ts +287 -71
- package/dist/common/runApi/types.js +29 -5
- package/dist/runtime/executionHelpers.test.js +6 -6
- package/package.json +3 -3
- package/tsconfig.json +1 -2
- package/InterfaceTemplate/index.ts +0 -1
- package/Intuned.json +0 -5
- package/api/authed.ts +0 -12
- package/api/test.ts +0 -3
- package/api/test2.ts +0 -22
- package/auth-sessions/check.ts +0 -9
- package/auth-sessions/create.ts +0 -32
- package/authSessions +0 -1
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -17
- package/dist/commands/common/utils/webTemplate.d.ts +0 -1
- package/output.txt +0 -39
- package/preserve-dynamic-imports.js +0 -16
- package/testing +0 -0
package/WebTemplate/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as playwright from "@intuned/playwright-core";
|
|
2
2
|
import { Handler, Response } from "@tinyhttp/app";
|
|
3
3
|
import * as path from "path";
|
|
4
|
-
import { getExecutionContext } from "@intuned/runtime
|
|
4
|
+
import { getExecutionContext } from "@intuned/runtime";
|
|
5
5
|
import { setTimeout } from "timers/promises";
|
|
6
6
|
|
|
7
7
|
export class FunctionNotFoundError extends Error {
|
|
@@ -208,3 +208,50 @@ export async function waitWithExtendableTimeout<T>({
|
|
|
208
208
|
result: await promise,
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
+
|
|
212
|
+
export async function importModule(path: string) {
|
|
213
|
+
const [folderName, ...functionNameParts] = path.split("/");
|
|
214
|
+
const functionNameDepth = functionNameParts.length;
|
|
215
|
+
|
|
216
|
+
// string literals should be inline
|
|
217
|
+
// currently we support only 5 levels of depth
|
|
218
|
+
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
219
|
+
try {
|
|
220
|
+
let imported: any = undefined;
|
|
221
|
+
switch (functionNameDepth) {
|
|
222
|
+
case 1:
|
|
223
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
224
|
+
break;
|
|
225
|
+
case 2:
|
|
226
|
+
imported = await import(
|
|
227
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
228
|
+
);
|
|
229
|
+
break;
|
|
230
|
+
case 3:
|
|
231
|
+
imported = await import(
|
|
232
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
233
|
+
);
|
|
234
|
+
break;
|
|
235
|
+
case 4:
|
|
236
|
+
imported = await import(
|
|
237
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
238
|
+
);
|
|
239
|
+
break;
|
|
240
|
+
case 5:
|
|
241
|
+
imported = await import(
|
|
242
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
243
|
+
);
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(
|
|
247
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return imported;
|
|
251
|
+
} catch (error: any) {
|
|
252
|
+
if (error.message.includes("Unknown variable dynamic import")) {
|
|
253
|
+
throw new FunctionNotFoundError("", path);
|
|
254
|
+
}
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/bin/intuned-ts-check
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require("../dist/commands/ts-check.js");
|
|
2
|
+
require("../dist/commands/ts-check.js");
|
package/dist/commands/api/run.js
CHANGED
|
@@ -16,6 +16,7 @@ var _Logger = require("../../common/Logger");
|
|
|
16
16
|
var _nanoid = require("nanoid");
|
|
17
17
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
18
|
var _runApi = require("../../common/runApi");
|
|
19
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -39,7 +40,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
39
40
|
const runApiResult = await (0, _runApi.runApi)({
|
|
40
41
|
automationFunction: {
|
|
41
42
|
name: `api/${apiName}`,
|
|
42
|
-
params: inputData
|
|
43
|
+
params: inputData
|
|
43
44
|
},
|
|
44
45
|
auth: authSessionPathToUse ? {
|
|
45
46
|
session: {
|
|
@@ -49,17 +50,18 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
49
50
|
runCheck: false
|
|
50
51
|
} : undefined,
|
|
51
52
|
runOptions: {
|
|
52
|
-
environment: "
|
|
53
|
+
environment: "cdp",
|
|
53
54
|
cdpAddress: options.cdpAddress,
|
|
54
55
|
mode
|
|
55
|
-
}
|
|
56
|
+
},
|
|
57
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
56
58
|
});
|
|
57
59
|
if (runApiResult.isErr()) {
|
|
58
60
|
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
59
61
|
throw runApiResult.error.error;
|
|
60
62
|
}
|
|
61
|
-
console.error(
|
|
62
|
-
|
|
63
|
+
console.error(runApiResult.error);
|
|
64
|
+
throw new Error("An error occurred while running the API");
|
|
63
65
|
}
|
|
64
66
|
const {
|
|
65
67
|
result,
|
|
@@ -8,6 +8,7 @@ var _settings = require("../common/utils/settings");
|
|
|
8
8
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
9
9
|
var _constants = require("../../common/constants");
|
|
10
10
|
var _runApi = require("../../common/runApi");
|
|
11
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -31,7 +32,7 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
31
32
|
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
32
33
|
},
|
|
33
34
|
runOptions: {
|
|
34
|
-
environment: "
|
|
35
|
+
environment: "cdp",
|
|
35
36
|
mode,
|
|
36
37
|
cdpAddress
|
|
37
38
|
},
|
|
@@ -41,10 +42,15 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
41
42
|
path: authSessionPath
|
|
42
43
|
},
|
|
43
44
|
runCheck: false
|
|
44
|
-
}
|
|
45
|
+
},
|
|
46
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
45
47
|
});
|
|
46
48
|
if (runApiResult.isErr()) {
|
|
47
|
-
|
|
49
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
50
|
+
throw runApiResult.error.error;
|
|
51
|
+
}
|
|
52
|
+
console.error(runApiResult.error);
|
|
53
|
+
throw new Error("Error running auth session check");
|
|
48
54
|
}
|
|
49
55
|
const result = runApiResult.value.result;
|
|
50
56
|
console.log("check result", result);
|
|
@@ -12,6 +12,7 @@ var _runApi = require("../../common/runApi");
|
|
|
12
12
|
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
13
13
|
var _nanoid = require("nanoid");
|
|
14
14
|
var _enums = require("../../runtime/enums");
|
|
15
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -43,15 +44,16 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
43
44
|
async function runCreate() {
|
|
44
45
|
const generator = (0, _runApi.runApiGenerator)({
|
|
45
46
|
automationFunction: {
|
|
46
|
-
name:
|
|
47
|
-
params: inputData
|
|
47
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
|
|
48
|
+
params: inputData
|
|
48
49
|
},
|
|
49
50
|
runOptions: {
|
|
50
|
-
environment: "
|
|
51
|
+
environment: "cdp",
|
|
51
52
|
mode,
|
|
52
53
|
cdpAddress
|
|
53
54
|
},
|
|
54
|
-
retrieveSession: true
|
|
55
|
+
retrieveSession: true,
|
|
56
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
55
57
|
});
|
|
56
58
|
let nextGeneratorParam = undefined;
|
|
57
59
|
while (true) {
|
|
@@ -61,8 +63,11 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
61
63
|
} = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
|
|
62
64
|
if (done) {
|
|
63
65
|
if (value.isErr()) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
if (value.error instanceof _runApi.AutomationError) {
|
|
67
|
+
throw value.error.error;
|
|
68
|
+
}
|
|
69
|
+
console.error(value.error);
|
|
70
|
+
throw new Error("Error while running create");
|
|
66
71
|
}
|
|
67
72
|
const fullState = value.value.session;
|
|
68
73
|
if (pathToSave) {
|
package/dist/commands/build.js
CHANGED
|
@@ -10,7 +10,7 @@ var _pluginDynamicImportVars = _interopRequireDefault(require("@rollup/plugin-dy
|
|
|
10
10
|
var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
|
|
11
11
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
12
|
var path = _interopRequireWildcard(require("path"));
|
|
13
|
-
var
|
|
13
|
+
var _template = require("./common/utils/template");
|
|
14
14
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -21,18 +21,20 @@ function isThirdPartyWarning(warning) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
_dotenv.default.config();
|
|
24
|
-
_commander.program.description("build the intuned server").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await
|
|
28
|
-
|
|
24
|
+
_commander.program.description("build the intuned server").option("-t, --template <type>", "template to use", "WebTemplate").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile, {
|
|
25
|
+
template
|
|
26
|
+
}) => {
|
|
27
|
+
await (0, _template.moveTemplateFiles)(template);
|
|
28
|
+
const currentTemplateTsConfig = path.resolve(path.dirname(__filename), "..", "..", "template.tsconfig.json");
|
|
29
|
+
await fs.copy(currentTemplateTsConfig, `./intuned/${template}/tsconfig.json`);
|
|
30
|
+
await build(outfile, mode, template);
|
|
29
31
|
});
|
|
30
|
-
async function build(outfile, mode) {
|
|
32
|
+
async function build(outfile, mode, template) {
|
|
31
33
|
let bundle = null;
|
|
32
34
|
let buildFailed = false;
|
|
33
35
|
try {
|
|
34
36
|
bundle = await (0, _rollup.rollup)({
|
|
35
|
-
input: `./intuned/
|
|
37
|
+
input: `./intuned/${template}/index.${mode}.ts`,
|
|
36
38
|
output: {
|
|
37
39
|
globals: {
|
|
38
40
|
crypto: "crypto"
|
|
@@ -42,13 +44,15 @@ async function build(outfile, mode) {
|
|
|
42
44
|
exportConditions: ["node"],
|
|
43
45
|
preferBuiltins: true
|
|
44
46
|
}), (0, _pluginTypescript.default)({
|
|
45
|
-
tsconfig:
|
|
47
|
+
tsconfig: `./intuned/${template}/tsconfig.json`
|
|
46
48
|
}), (0, _pluginCommonjs.default)({
|
|
47
|
-
include: ["node_modules/**",
|
|
49
|
+
include: ["node_modules/**", `intuned/${template}/**`, "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
|
|
48
50
|
extensions: [".js"],
|
|
49
51
|
ignoreGlobal: false,
|
|
50
52
|
sourceMap: false,
|
|
51
|
-
dynamicRequireTargets: ["
|
|
53
|
+
dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
|
|
54
|
+
requireReturnsDefault: "auto",
|
|
55
|
+
transformMixedEsModules: true
|
|
52
56
|
}), (0, _pluginDynamicImportVars.default)({
|
|
53
57
|
include: ["**/*.js", "**/*.ts"],
|
|
54
58
|
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
@@ -61,7 +65,7 @@ async function build(outfile, mode) {
|
|
|
61
65
|
});
|
|
62
66
|
console.log(`📦 Building ${outfile}`);
|
|
63
67
|
const outfileFolder = path.dirname(outfile);
|
|
64
|
-
const assetsDir = path.resolve(
|
|
68
|
+
const assetsDir = path.resolve(path.dirname(__filename), "..", "common", "assets");
|
|
65
69
|
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
66
70
|
await bundle.write({
|
|
67
71
|
format: "cjs",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function tsNodeImport(apiName: string): Promise<any>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tsNodeImport = tsNodeImport;
|
|
7
|
+
var _fileUtils = require("./utils/fileUtils");
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
async function tsNodeImport(apiName) {
|
|
11
|
+
require("ts-node").register({
|
|
12
|
+
transpileOnly: true,
|
|
13
|
+
compilerOptions: {
|
|
14
|
+
lib: ["dom", "es2020"]
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
18
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
19
|
+
return imported;
|
|
20
|
+
}
|
|
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getSettings = getSettings;
|
|
7
7
|
var _fileUtils = require("./fileUtils");
|
|
8
8
|
var _settingsSchema = require("../../../common/settingsSchema");
|
|
9
|
-
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
11
|
async function getSettings() {
|
|
11
12
|
const settingsFilePath = (0, _fileUtils.getFullPathInProject)("Intuned.json");
|
|
12
13
|
console.log("loading settings");
|
|
13
|
-
const settings = await (
|
|
14
|
-
if (settings) {
|
|
15
|
-
const parsed = _settingsSchema.settingsSchema.safeParse(settings);
|
|
16
|
-
console.log(parsed);
|
|
14
|
+
const settings = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(settingsFilePath);
|
|
15
|
+
if (settings.default) {
|
|
16
|
+
const parsed = _settingsSchema.settingsSchema.safeParse(settings.default);
|
|
17
17
|
if (parsed.success) {
|
|
18
18
|
return parsed.data;
|
|
19
19
|
} else {
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.moveTemplateFiles = void 0;
|
|
7
7
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
8
8
|
var path = _interopRequireWildcard(require("path"));
|
|
9
9
|
var _fileUtils = require("./fileUtils");
|
|
10
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
-
const
|
|
12
|
+
const moveTemplateFiles = async templateName => {
|
|
13
13
|
await fs.remove("./intuned");
|
|
14
14
|
await fs.ensureDir("./intuned");
|
|
15
|
-
const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..",
|
|
16
|
-
await fs.copy(`${currentFileLocation}`,
|
|
17
|
-
filter: (src,
|
|
15
|
+
const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..", templateName);
|
|
16
|
+
await fs.copy(`${currentFileLocation}`, `./intuned/${templateName}`, {
|
|
17
|
+
filter: (src, _) => {
|
|
18
18
|
if (src.includes(".d.ts")) {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
@@ -25,7 +25,7 @@ const moveWebTemplateFiles = async () => {
|
|
|
25
25
|
const pathsIgnoreList = [(0, _fileUtils.getFullPathInProject)("intuned"), (0, _fileUtils.getFullPathInProject)("node_modules"), (0, _fileUtils.getFullPathInProject)("package.json"), (0, _fileUtils.getFullPathInProject)("yarn.lock"), (0, _fileUtils.getFullPathInProject)(".env")];
|
|
26
26
|
const filesToCopy = filesAndFolders.filter(file => !pathsIgnoreList.includes(file.fullPath));
|
|
27
27
|
for (const file of filesToCopy) {
|
|
28
|
-
await fs.copy(file.fullPath, `./intuned
|
|
28
|
+
await fs.copy(file.fullPath, `./intuned/${templateName}/${file.name}`);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
exports.
|
|
31
|
+
exports.moveTemplateFiles = moveTemplateFiles;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export {};
|
|
1
|
+
export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
"use strict";
|
|
3
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runAutomationCLI = runAutomationCLI;
|
|
4
7
|
var _commander = require("commander");
|
|
5
8
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
6
9
|
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
7
10
|
var net = _interopRequireWildcard(require("net"));
|
|
8
11
|
var _zod = _interopRequireDefault(require("zod"));
|
|
9
12
|
var _runApi = require("../../common/runApi");
|
|
10
|
-
var _enums = require("
|
|
13
|
+
var _enums = require("../../runtime/enums");
|
|
11
14
|
var _unixSocket = require("../common/utils/unixSocket");
|
|
12
15
|
var _promises = require("timers/promises");
|
|
16
|
+
var _jwtTokenManager = require("../../common/jwtTokenManager");
|
|
17
|
+
var _formatZodError = require("../../common/formatZodError");
|
|
18
|
+
var _stream = require("stream");
|
|
13
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -17,6 +23,7 @@ const startRunApiSchema = _zod.default.object({
|
|
|
17
23
|
type: _zod.default.literal("start"),
|
|
18
24
|
parameters: _runApi.runApiParametersSchema.extend({
|
|
19
25
|
retrieveSession: _zod.default.boolean(),
|
|
26
|
+
functionsToken: _zod.default.string().optional(),
|
|
20
27
|
context: _zod.default.object({
|
|
21
28
|
jobId: _zod.default.string().optional(),
|
|
22
29
|
jobRunId: _zod.default.string().optional(),
|
|
@@ -35,127 +42,157 @@ const abortRunApiSchema = _zod.default.object({
|
|
|
35
42
|
type: _zod.default.literal("abort"),
|
|
36
43
|
parameters: _zod.default.object({}).optional()
|
|
37
44
|
});
|
|
38
|
-
const
|
|
45
|
+
const tokenUpdateSchema = _zod.default.object({
|
|
46
|
+
type: _zod.default.literal("tokenUpdate"),
|
|
47
|
+
parameters: _zod.default.object({
|
|
48
|
+
functionsToken: _zod.default.string()
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema]);
|
|
39
52
|
_dotenv.default.config({
|
|
40
53
|
path: `.env`
|
|
41
54
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const resultToSend = result.value.isOk() ? result.value.value : result.value.error.json;
|
|
72
|
-
const success = result.value.isOk();
|
|
73
|
-
jsonUnixSocket.sendJSON({
|
|
74
|
-
type: "done",
|
|
75
|
-
result: resultToSend,
|
|
76
|
-
success
|
|
77
|
-
});
|
|
78
|
-
return true;
|
|
79
|
-
} else {
|
|
80
|
-
jsonUnixSocket.sendJSON({
|
|
81
|
-
type: "yield",
|
|
82
|
-
result: result.value
|
|
83
|
-
});
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
for await (const data of jsonUnixSocket.receiveJSON()) {
|
|
88
|
-
const inputParseResult = inputSchema.safeParse(data);
|
|
89
|
-
if (!inputParseResult.success) {
|
|
90
|
-
console.error(inputParseResult.error.errors);
|
|
91
|
-
jsonUnixSocket.sendJSON({
|
|
92
|
-
type: "done",
|
|
93
|
-
result: {
|
|
94
|
-
error: "InvalidJSON",
|
|
95
|
-
message: "Invalid input",
|
|
96
|
-
details: {
|
|
97
|
-
errors: inputParseResult.error.errors
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
success: false
|
|
101
|
-
});
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
const input = inputParseResult.data;
|
|
105
|
-
if (input.type === "abort") {
|
|
106
|
-
abortController.abort();
|
|
107
|
-
await (0, _promises.setTimeout)(10);
|
|
108
|
-
jsonUnixSocket.sendJSON({
|
|
109
|
-
type: "done",
|
|
110
|
-
result: null
|
|
111
|
-
});
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
if (input.type === "start") {
|
|
115
|
-
const gen = (0, _runApi.runApiGenerator)({
|
|
116
|
-
...input.parameters,
|
|
117
|
-
abortSignal: abortController.signal
|
|
118
|
-
});
|
|
119
|
-
generator = gen;
|
|
120
|
-
context = {
|
|
121
|
-
extendedPayloads: [],
|
|
122
|
-
runEnvironment: input.parameters.runOptions.environment === "deployed" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
|
|
123
|
-
timeoutInfo: {
|
|
124
|
-
extendTimeoutCallback: async () => {
|
|
125
|
-
if (Date.now() - timeoutTimestamp < throttleTime) return;
|
|
126
|
-
timeoutTimestamp = Date.now();
|
|
127
|
-
jsonUnixSocket.sendJSON({
|
|
128
|
-
type: "extend"
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
...(input.parameters.context ?? {}),
|
|
133
|
-
proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
|
|
55
|
+
function runAutomationCLI(importFunction) {
|
|
56
|
+
_commander.program.description("run user automation and communicate using unix socket").argument("<socket-path>", "path to unix socket").action(async socketPath => {
|
|
57
|
+
let context;
|
|
58
|
+
const throttleTime = 60 * 1000;
|
|
59
|
+
let timeoutTimestamp = Date.now();
|
|
60
|
+
const client = net.createConnection(socketPath);
|
|
61
|
+
let generator = null;
|
|
62
|
+
const abortController = new AbortController();
|
|
63
|
+
client.on("error", err => {
|
|
64
|
+
var _generator2;
|
|
65
|
+
void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(err).catch(() => undefined));
|
|
66
|
+
});
|
|
67
|
+
process.on("SIGINT", () => {
|
|
68
|
+
var _generator3;
|
|
69
|
+
void ((_generator3 = generator) === null || _generator3 === void 0 ? void 0 : _generator3.throw(new Error("Interrupted")).catch(() => undefined));
|
|
70
|
+
client.end();
|
|
71
|
+
process.exit(1);
|
|
72
|
+
});
|
|
73
|
+
process.on("SIGTERM", () => {
|
|
74
|
+
var _generator4;
|
|
75
|
+
void ((_generator4 = generator) === null || _generator4 === void 0 ? void 0 : _generator4.throw(new Error("Interrupted")).catch(() => undefined));
|
|
76
|
+
client.end();
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|
|
79
|
+
const jsonUnixSocket = new _unixSocket.JSONUnixSocket(client);
|
|
80
|
+
async function runGeneratorAndSendResult(next) {
|
|
81
|
+
const _generator = generator;
|
|
82
|
+
if (_generator == null) return {
|
|
83
|
+
done: true
|
|
134
84
|
};
|
|
135
|
-
|
|
136
|
-
|
|
85
|
+
const result = await (0, _asyncLocalStorage.runWithContext)(context, () => _generator.next(next));
|
|
86
|
+
if (result.done) {
|
|
87
|
+
const resultToSend = result.value.isOk() ? result.value.value : result.value.error.json;
|
|
88
|
+
const success = result.value.isOk();
|
|
89
|
+
jsonUnixSocket.sendJSON({
|
|
90
|
+
type: "done",
|
|
91
|
+
result: resultToSend,
|
|
92
|
+
success
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
jsonUnixSocket.sendJSON({
|
|
96
|
+
type: "yield",
|
|
97
|
+
result: result.value
|
|
98
|
+
});
|
|
137
99
|
}
|
|
138
|
-
|
|
100
|
+
return {
|
|
101
|
+
done: result.done ?? false
|
|
102
|
+
};
|
|
139
103
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
104
|
+
const stream = new _stream.PassThrough({
|
|
105
|
+
objectMode: true
|
|
106
|
+
});
|
|
107
|
+
async function messagesLoop() {
|
|
108
|
+
for await (const data of jsonUnixSocket.receiveJSON()) {
|
|
109
|
+
const inputParseResult = inputSchema.safeParse(data);
|
|
110
|
+
if (!inputParseResult.success) {
|
|
111
|
+
console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
|
|
112
|
+
jsonUnixSocket.sendJSON({
|
|
113
|
+
type: "done",
|
|
114
|
+
result: new _runApi.InternalInvalidInputError("Invalid input", (0, _formatZodError.formatZodError)(inputParseResult.error)).json,
|
|
115
|
+
success: false
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const input = inputParseResult.data;
|
|
120
|
+
if (input.type === "abort") {
|
|
121
|
+
abortController.abort();
|
|
122
|
+
await (0, _promises.setTimeout)(10);
|
|
123
|
+
jsonUnixSocket.sendJSON({
|
|
124
|
+
type: "done",
|
|
125
|
+
result: null
|
|
126
|
+
});
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (input.type === "tokenUpdate") {
|
|
130
|
+
_jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (input.type === "start") {
|
|
134
|
+
_jwtTokenManager.backendFunctionsTokenManager.token = input.parameters.functionsToken;
|
|
135
|
+
generator = (0, _runApi.runApiGenerator)({
|
|
136
|
+
...input.parameters,
|
|
137
|
+
abortSignal: abortController.signal,
|
|
138
|
+
importFunction
|
|
139
|
+
});
|
|
140
|
+
context = {
|
|
141
|
+
extendedPayloads: [],
|
|
142
|
+
runEnvironment: input.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
|
|
143
|
+
timeoutInfo: {
|
|
144
|
+
extendTimeoutCallback: async () => {
|
|
145
|
+
if (Date.now() - timeoutTimestamp < throttleTime) return;
|
|
146
|
+
timeoutTimestamp = Date.now();
|
|
147
|
+
jsonUnixSocket.sendJSON({
|
|
148
|
+
type: "extend"
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
...(input.parameters.context ?? {}),
|
|
153
|
+
proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
|
|
154
|
+
};
|
|
155
|
+
stream.write({});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (input.type === "next") {
|
|
159
|
+
if (!generator) {
|
|
160
|
+
throw new Error("generator not started");
|
|
161
|
+
}
|
|
162
|
+
stream.write({
|
|
163
|
+
value: input.parameters.value
|
|
164
|
+
});
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
146
167
|
}
|
|
147
|
-
|
|
168
|
+
stream.end();
|
|
169
|
+
client.end();
|
|
148
170
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
171
|
+
void messagesLoop();
|
|
172
|
+
for await (const {
|
|
173
|
+
value
|
|
174
|
+
} of stream) {
|
|
175
|
+
const {
|
|
176
|
+
done
|
|
177
|
+
} = await runGeneratorAndSendResult(value);
|
|
178
|
+
if (done) break;
|
|
179
|
+
}
|
|
180
|
+
if (!client.closed) {
|
|
181
|
+
client.end();
|
|
182
|
+
}
|
|
183
|
+
process.exit(0);
|
|
184
|
+
});
|
|
185
|
+
_commander.program.parse(process.argv);
|
|
186
|
+
}
|
|
153
187
|
function getProxyUrlFromRunOptions(runOptions) {
|
|
154
|
-
if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "
|
|
188
|
+
if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "standalone") return undefined;
|
|
155
189
|
const proxy = runOptions.proxy;
|
|
156
190
|
if (!proxy) return undefined;
|
|
157
191
|
const url = new URL(proxy.server);
|
|
158
192
|
url.username = proxy.username;
|
|
159
193
|
url.password = proxy.password;
|
|
160
194
|
return url.toString();
|
|
195
|
+
}
|
|
196
|
+
if (require.main === module) {
|
|
197
|
+
runAutomationCLI();
|
|
161
198
|
}
|