@intuned/runtime-dev 1.1.6-bot-detection → 1.1.6-vnc.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.
Files changed (44) hide show
  1. package/.babelrc +2 -2
  2. package/WebTemplate.zip +0 -0
  3. package/dist/commands/api/run.js +8 -2
  4. package/dist/commands/auth-sessions/run-check.js +18 -4
  5. package/dist/commands/auth-sessions/run-create.js +2 -1
  6. package/dist/commands/cli-auth-sessions/create.js +1 -1
  7. package/dist/commands/cli-auth-sessions/utils.d.ts +1 -1
  8. package/dist/commands/cli-auth-sessions/utils.js +2 -3
  9. package/dist/commands/common/browserUtils.d.ts +1 -1
  10. package/dist/commands/common/browserUtils.js +1 -1
  11. package/dist/commands/common/getFirstLineNumber.js +2 -4
  12. package/dist/commands/deploy/utils.js +1 -2
  13. package/dist/commands/init/utils.js +1 -7
  14. package/dist/commands/interface/run.js +70 -6
  15. package/dist/commands/run-api-cli/utils.js +6 -6
  16. package/dist/common/assets/browser_scripts.js +2509 -2143
  17. package/dist/common/asyncLocalStorage/index.d.ts +1 -2
  18. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  19. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  20. package/dist/common/cli/constants.d.ts +1 -0
  21. package/dist/common/cli/constants.js +2 -1
  22. package/dist/common/cli/types.d.ts +1 -1
  23. package/dist/common/contextStorageStateHelpers.d.ts +1 -1
  24. package/dist/common/contextStorageStateHelpers.js +56 -0
  25. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  26. package/dist/common/getPlaywrightConstructs.js +12 -12
  27. package/dist/common/jwtTokenManager.js +3 -5
  28. package/dist/common/runApi/errors.d.ts +1 -1
  29. package/dist/common/runApi/errors.js +5 -6
  30. package/dist/common/runApi/index.d.ts +1 -1
  31. package/dist/common/runApi/index.js +8 -11
  32. package/dist/common/runApi/types.d.ts +16 -16
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.js +6 -0
  35. package/dist/runtime/executionHelpers.test.js +3 -4
  36. package/dist/runtime/export.d.ts +16 -0
  37. package/dist/runtime/extendPayload.js +1 -1
  38. package/dist/runtime/extendTimeout.js +0 -7
  39. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  40. package/dist/runtime/getAuthSessionParameters.js +20 -0
  41. package/dist/runtime/index.d.ts +1 -0
  42. package/dist/runtime/index.js +7 -0
  43. package/package.json +3 -5
  44. package/template.tsconfig.json +4 -7
package/.babelrc CHANGED
@@ -4,8 +4,8 @@
4
4
  "@babel/preset-env",
5
5
  {
6
6
  "targets": {
7
- "chrome": 115,
8
- "node": "16"
7
+ "chrome": 130,
8
+ "node": "20"
9
9
  },
10
10
  "modules": "commonjs"
11
11
  }
Binary file
@@ -17,6 +17,7 @@ var _nanoid = require("nanoid");
17
17
  var _chalk = _interopRequireDefault(require("chalk"));
18
18
  var _runApi = require("../../common/runApi");
19
19
  var _tsNodeImport = require("../common/tsNodeImport");
20
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
20
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
22
  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); }
22
23
  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 && {}.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; }
@@ -95,7 +96,7 @@ async function executeCLI(apiName, mode, inputData, options) {
95
96
  _Logger.logger.info("This will only take an effect if this API run was part of a job.");
96
97
  }
97
98
  }
98
- _commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
99
+ _commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").option("--authSessionParameters <authSessionParameters>", "parameters used to create the used auth session").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
99
100
  let inputData = null;
100
101
  if (options.input) {
101
102
  inputData = await fs.readJSON(options.input);
@@ -104,11 +105,16 @@ _commander.program.description("run the user function in the cli for testing pur
104
105
  } else {
105
106
  inputData = {};
106
107
  }
108
+ let authSessionParametersJson = undefined;
109
+ if (!(0, _isNil.default)(options?.authSessionParameters)) {
110
+ authSessionParametersJson = JSON.parse(options.authSessionParameters);
111
+ }
107
112
  await (0, _asyncLocalStorage.runWithContext)({
108
113
  runEnvironment: _enums.RunEnvironment.IDE,
109
114
  extendedPayloads: [],
110
115
  runId: (0, _nanoid.nanoid)(),
111
- proxy: options.proxy
116
+ proxy: options.proxy,
117
+ getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
112
118
  }, () => executeCLI(apiName, mode, inputData, options));
113
119
  process.exit(0);
114
120
  });
@@ -9,15 +9,20 @@ var _dotenv = _interopRequireDefault(require("dotenv"));
9
9
  var _constants = require("../../common/constants");
10
10
  var _runApi = require("../../common/runApi");
11
11
  var _tsNodeImport = require("../common/tsNodeImport");
12
+ var _enums = require("../../runtime/enums");
13
+ var _nanoid = require("nanoid");
14
+ var _asyncLocalStorage = require("../../common/asyncLocalStorage");
15
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
12
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
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); }
14
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 && {}.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
19
  _dotenv.default.config({
16
20
  path: `.env`
17
21
  });
18
- _commander.program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
22
+ _commander.program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").option("--authSessionParameters <authSessionParameters>", "parameters used to create the used auth session").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
19
23
  cdpAddress,
20
- authSessionPath
24
+ authSessionPath,
25
+ authSessionParameters
21
26
  }) => {
22
27
  const setting = await (0, _settings.getSettings)();
23
28
  if (!setting.authSessions.enabled) {
@@ -27,7 +32,16 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
27
32
  if (!fs.exists(checkFilePath)) {
28
33
  throw new Error("auth session check file not found");
29
34
  }
30
- const runApiResult = await (0, _runApi.runApi)({
35
+ let authSessionParametersJson = undefined;
36
+ if (!(0, _isNil.default)(authSessionParameters)) {
37
+ authSessionParametersJson = JSON.parse(authSessionParameters);
38
+ }
39
+ const runApiResult = await (0, _asyncLocalStorage.runWithContext)({
40
+ runEnvironment: _enums.RunEnvironment.IDE,
41
+ extendedPayloads: [],
42
+ runId: (0, _nanoid.nanoid)(),
43
+ getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
44
+ }, async () => await (0, _runApi.runApi)({
31
45
  automationFunction: {
32
46
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
33
47
  },
@@ -44,7 +58,7 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
44
58
  runCheck: false
45
59
  },
46
60
  importFunction: _tsNodeImport.tsNodeImport
47
- });
61
+ }));
48
62
  if (runApiResult.isErr()) {
49
63
  if (runApiResult.error instanceof _runApi.AutomationError) {
50
64
  throw runApiResult.error.error;
@@ -94,7 +94,8 @@ _commander.program.description("run auth session create").option("--cdpAddress <
94
94
  await (0, _asyncLocalStorage.runWithContext)({
95
95
  runEnvironment: _enums.RunEnvironment.IDE,
96
96
  extendedPayloads: [],
97
- runId: (0, _nanoid.nanoid)()
97
+ runId: (0, _nanoid.nanoid)(),
98
+ getAuthSessionParameters: async () => inputData
98
99
  }, runCreate);
99
100
  process.exit(0);
100
101
  });
@@ -32,7 +32,7 @@ _commander.program.description("Create an auth session").argument("[auth-session
32
32
  if (!createApiExists) {
33
33
  throw new Error("Auth session create API not implemented, please create it in the auth sessions specified directory");
34
34
  }
35
- const authSessionInput = (await (0, _utils2.loadParameters)(options === null || options === void 0 ? void 0 : options.input)) ?? {};
35
+ const authSessionInput = (await (0, _utils2.loadParameters)(options?.input)) ?? {};
36
36
  const session = await (0, _utils.runCreateApi)(authSessionInput);
37
37
  if (!session) {
38
38
  console.error(_chalk.default.red("Failed to create auth session."));
@@ -1,6 +1,6 @@
1
1
  import { StorageState } from "../../common/contextStorageStateHelpers";
2
2
  import { AuthSessionMetadata, AuthSessionType } from "../../common/cli/types";
3
- import * as playwright from "patchright";
3
+ import * as playwright from "playwright-core";
4
4
  export declare function isAuthEnabled(): Promise<boolean>;
5
5
  export declare function getAuthType(): Promise<AuthSessionType>;
6
6
  export declare function ensureRecorderURLs(): Promise<{
@@ -26,15 +26,14 @@ var _tsNodeImport = require("../common/tsNodeImport");
26
26
  var _promptly = require("promptly");
27
27
  var _utils = require("../../common/cli/utils");
28
28
  var _types = require("../../common/cli/types");
29
- var playwright = _interopRequireWildcard(require("patchright"));
29
+ var playwright = _interopRequireWildcard(require("playwright-core"));
30
30
  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); }
31
31
  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 && {}.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; }
32
32
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
33
  async function isAuthEnabled() {
34
34
  try {
35
- var _intunedJson$authSess;
36
35
  const intunedJson = await fs.readJSON(_path.default.join(process.cwd(), "Intuned.json"));
37
- return Boolean(intunedJson === null || intunedJson === void 0 || (_intunedJson$authSess = intunedJson.authSessions) === null || _intunedJson$authSess === void 0 ? void 0 : _intunedJson$authSess.enabled);
36
+ return Boolean(intunedJson?.authSessions?.enabled);
38
37
  } catch (error) {
39
38
  return false;
40
39
  }
@@ -1,4 +1,4 @@
1
- import { BrowserContext } from "patchright";
1
+ import { BrowserContext } from "playwright";
2
2
  export declare const REMOTE_DEBUGGING_PORT = 9222;
3
3
  export declare const getChromiumLaunchArgs: () => string[];
4
4
  export declare function startOrRestartBrowser(): Promise<void>;
@@ -9,7 +9,7 @@ exports.saveSession = saveSession;
9
9
  exports.saveSessionFromOpenedBrowser = saveSessionFromOpenedBrowser;
10
10
  exports.startOrRestartBrowser = startOrRestartBrowser;
11
11
  var _child_process = require("child_process");
12
- var playwright = _interopRequireWildcard(require("patchright"));
12
+ var playwright = _interopRequireWildcard(require("playwright"));
13
13
  var fs = _interopRequireWildcard(require("fs-extra"));
14
14
  var _fileUtils = require("./utils/fileUtils");
15
15
  var _contextStorageStateHelpers = require("../../common/contextStorageStateHelpers");
@@ -32,10 +32,9 @@ function compileTypeScript(apiFilePath) {
32
32
  };
33
33
  }
34
34
  function findFirstExecutableLine(sourceFile) {
35
- var _defaultExportSymbol$;
36
35
  let functionBody;
37
36
  const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
38
- const defaultExportDeclaration = defaultExportSymbol === null || defaultExportSymbol === void 0 || (_defaultExportSymbol$ = defaultExportSymbol.getDeclarations()) === null || _defaultExportSymbol$ === void 0 ? void 0 : _defaultExportSymbol$[0];
37
+ const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
39
38
  if (defaultExportDeclaration) {
40
39
  if (defaultExportDeclaration.getKind() === _tsMorph.ts.SyntaxKind.FunctionDeclaration) {
41
40
  functionBody = defaultExportDeclaration.getBody();
@@ -45,9 +44,8 @@ function findFirstExecutableLine(sourceFile) {
45
44
  const expression = exportAssignment.getExpression();
46
45
  if (!expression) continue;
47
46
  if (expression.getKind() === _tsMorph.ts.SyntaxKind.Identifier || expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction) {
48
- var _sourceFile$getVariab;
49
47
  const identifier = expression.getText();
50
- const possiblyExportedFunction = sourceFile.getFunction(identifier) || ((_sourceFile$getVariab = sourceFile.getVariableStatement(identifier)) === null || _sourceFile$getVariab === void 0 ? void 0 : _sourceFile$getVariab.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction));
48
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) || sourceFile.getVariableStatement(identifier)?.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction);
51
49
  if (possiblyExportedFunction) {
52
50
  functionBody = possiblyExportedFunction.getBody();
53
51
  break;
@@ -228,13 +228,12 @@ const validateIntunedProject = async () => {
228
228
  name: "package.json",
229
229
  check: async () => {
230
230
  try {
231
- var _packageJson$dependen;
232
231
  const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
233
232
  await fs.exists(packageJsonPath);
234
233
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
235
234
  encoding: "utf-8"
236
235
  }));
237
- const userCodePlaywrightVersion = (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen.playwright;
236
+ const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
238
237
  if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
239
238
  return {
240
239
  isValid: false,
@@ -15,7 +15,6 @@ var _types = require("../../common/cli/types");
15
15
  var _chalk = _interopRequireDefault(require("chalk"));
16
16
  var _inquirer = _interopRequireDefault(require("inquirer"));
17
17
  var _path = _interopRequireDefault(require("path"));
18
- var _boxen = _interopRequireDefault(require("boxen"));
19
18
  var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
20
19
  var _constants = require("../../common/cli/constants");
21
20
  var _cliReadme = require("../../common/cli/cliReadme");
@@ -139,12 +138,7 @@ async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
139
138
  await prepareCLITemplate(codeTree);
140
139
  await mountFiles(cwd, codeTree);
141
140
  console.log(_chalk.default.green("✓ Project files created"));
142
- console.log((0, _boxen.default)(_chalk.default.green(`✅ Project initialized successfully`) + `\n\n${_chalk.default.cyan("Project details:")}` + `\n• Template: ${_chalk.default.bold(templateId)}` + `\n• Directory: ${_chalk.default.bold(process.cwd())}` + `\n\n${_chalk.default.cyan("Next steps:")}` + `\n1. ${_chalk.default.bold("cd")} into your project directory (if not already there)` + `\n2. Run ${_chalk.default.bold("npm/yarn install")} to install dependencies` + `\n3. Develop, test and run your automation APIs`, {
143
- padding: 1,
144
- margin: 1,
145
- borderStyle: "round",
146
- borderColor: "green"
147
- }));
141
+ console.log(_chalk.default.cyan(`\n🎉 Project initialized successfully!`), _chalk.default.yellow(`\n\nRun ${_chalk.default.bold("yarn")} to install dependencies and start coding!`));
148
142
  }
149
143
  async function fetchProjectTemplate(templateId) {
150
144
  const baseUrl = (0, _utils.getBaseUrl)();
@@ -8,6 +8,7 @@ var _commander = require("commander");
8
8
  var _dotenv = _interopRequireDefault(require("dotenv"));
9
9
  var _asyncLocalStorage = require("../../common/asyncLocalStorage");
10
10
  var net = _interopRequireWildcard(require("net"));
11
+ var fs = _interopRequireWildcard(require("fs-extra"));
11
12
  var _zod = _interopRequireDefault(require("zod"));
12
13
  var _runApi = require("../../common/runApi");
13
14
  var _enums = require("../../runtime/enums");
@@ -16,6 +17,8 @@ var _promises = require("timers/promises");
16
17
  var _jwtTokenManager = require("../../common/jwtTokenManager");
17
18
  var _formatZodError = require("../../common/formatZodError");
18
19
  var _neverthrow = require("neverthrow");
20
+ var _getAuthSessionParameters = require("../../common/backendFunctions/getAuthSessionParameters");
21
+ var _child_process = require("child_process");
19
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
23
  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
24
  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 && {}.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; }
@@ -28,7 +31,8 @@ const startRunApiSchema = _zod.default.object({
28
31
  jobId: _zod.default.string().optional(),
29
32
  jobRunId: _zod.default.string().optional(),
30
33
  runId: _zod.default.string().optional(),
31
- queueId: _zod.default.string().optional()
34
+ queueId: _zod.default.string().optional(),
35
+ authSessionId: _zod.default.string().optional()
32
36
  }).optional()
33
37
  })
34
38
  });
@@ -65,14 +69,12 @@ function runAutomationCLI(importFunction) {
65
69
  let generator = null;
66
70
  const abortController = new AbortController();
67
71
  client.on("error", err => {
68
- var _generator;
69
- void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
72
+ void generator?.throw(err).catch(() => undefined);
70
73
  });
71
74
  const interruptSignalHandler = async () => {
72
- var _generator2;
73
75
  abortController.abort();
74
76
  await (0, _promises.setTimeout)(60_000);
75
- void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
77
+ void generator?.throw(new Error("Interrupted")).catch(() => undefined);
76
78
  client.end();
77
79
  process.exit(1);
78
80
  };
@@ -107,6 +109,7 @@ function runAutomationCLI(importFunction) {
107
109
  return;
108
110
  }
109
111
  if (message.type === "start") {
112
+ await startVncServer();
110
113
  generator = (0, _runApi.runApiGenerator)({
111
114
  ...message.parameters,
112
115
  abortSignal: abortController.signal,
@@ -124,6 +127,7 @@ function runAutomationCLI(importFunction) {
124
127
  });
125
128
  }
126
129
  },
130
+ getAuthSessionParameters: _getAuthSessionParameters.getAuthSessionParameters,
127
131
  ...(message.parameters.context ?? {}),
128
132
  proxy: getProxyUrlFromRunOptions(message.parameters.runOptions)
129
133
  };
@@ -207,12 +211,13 @@ function runAutomationCLI(importFunction) {
207
211
  client.end();
208
212
  await Promise.race([new Promise(resolve => client.once("close", resolve)), new Promise(resolve => client.once("error", resolve)), (0, _promises.setTimeout)(3000)]);
209
213
  }
214
+ await stopVncServer();
210
215
  process.exit(0);
211
216
  });
212
217
  _commander.program.parse(process.argv);
213
218
  }
214
219
  function getProxyUrlFromRunOptions(runOptions) {
215
- if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "standalone") return undefined;
220
+ if (runOptions?.environment !== "standalone") return undefined;
216
221
  const proxy = runOptions.proxy;
217
222
  if (!proxy) return undefined;
218
223
  const url = new URL(proxy.server);
@@ -238,4 +243,63 @@ const _defaultImport = async path => {
238
243
  };
239
244
  if (require.main === module) {
240
245
  runAutomationCLI();
246
+ }
247
+ const processes = [];
248
+ async function startVncServer() {
249
+ try {
250
+ const vncLockPath = "/tmp/.X99-lock";
251
+ if (await fs.exists(vncLockPath)) {
252
+ await fs.unlink(vncLockPath);
253
+ }
254
+ const vncUnixSocketPath = "/tmp/.X11-unix/X99";
255
+ if (await fs.exists(vncUnixSocketPath)) {
256
+ await fs.unlink(vncUnixSocketPath);
257
+ }
258
+ } catch (error) {
259
+ console.error("Error cleaning up VNC locks:", error);
260
+ }
261
+ const openboxProcess = (0, _child_process.spawn)("openbox");
262
+ processes.push(openboxProcess);
263
+ const devilspieProcess = (0, _child_process.spawn)("devilspie");
264
+ processes.push(devilspieProcess);
265
+ const xSetRootProcess = (0, _child_process.spawn)("xsetroot", ["-solid", "#000000"]);
266
+ processes.push(xSetRootProcess);
267
+ const vncStartupScript = "exec xclock -digital -update 0 -bg black";
268
+ await fs.writeFile("/tmp/vnc_startup.sh", vncStartupScript, {
269
+ mode: 0o755
270
+ });
271
+ const vncServerProcess = (0, _child_process.spawn)("vncserver", [":99", "-localhost", "yes", "-rfbauth", "~/.vnc/passwd", "-rfbport", "5900", "-geometry", "1280x720"]);
272
+ processes.push(vncServerProcess);
273
+ while (true) {
274
+ if (await fs.exists("/tmp/.X11-unix/X99")) {
275
+ break;
276
+ }
277
+ await (0, _promises.setTimeout)(1000);
278
+ }
279
+ const noVncProcess = (0, _child_process.spawn)("/opt/bin/noVNC/utils/launch.sh", ["--listen", "6080", "--vnc", "localhost:5900"]);
280
+ processes.push(noVncProcess);
281
+ }
282
+ async function stopVncServer() {
283
+ for (const process of processes.reverse()) {
284
+ if (process.exitCode === null) {
285
+ continue;
286
+ }
287
+ if (process.killed) {
288
+ continue;
289
+ }
290
+ process.kill(9);
291
+ }
292
+ processes.length = 0;
293
+ try {
294
+ const vncLockPath = "/tmp/.X99-lock";
295
+ if (await fs.exists(vncLockPath)) {
296
+ await fs.unlink(vncLockPath);
297
+ }
298
+ const vncUnixSocketPath = "/tmp/.X11-unix/X99";
299
+ if (await fs.exists(vncUnixSocketPath)) {
300
+ await fs.unlink(vncUnixSocketPath);
301
+ }
302
+ } catch (error) {
303
+ console.error("Error cleaning up VNC locks:", error);
304
+ }
241
305
  }
@@ -62,10 +62,10 @@ async function writeResultToFile(runId, result, payloadToAppend) {
62
62
  }
63
63
  async function runApiViaCLI(apiName, inputData, options) {
64
64
  let authSessionPathToUse = null;
65
- if (options !== null && options !== void 0 && options.authSession) {
65
+ if (options?.authSession) {
66
66
  const {
67
67
  authSessionInstanceStoragePath
68
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession, true);
68
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession, true);
69
69
  authSessionPathToUse = authSessionInstanceStoragePath;
70
70
  }
71
71
  if (authSessionPathToUse) {
@@ -82,17 +82,17 @@ async function runApiViaCLI(apiName, inputData, options) {
82
82
  }
83
83
  const {
84
84
  metadata
85
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession);
86
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.authSessionType) === "MANUAL") {
85
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession);
86
+ if (metadata?.authSessionType === "MANUAL") {
87
87
  throw new Error("Expired Auth session is recorder-based, please provide a new one or refresh it manually");
88
88
  }
89
- const authSessionInput = (metadata === null || metadata === void 0 ? void 0 : metadata.authSessionInput) ?? {};
89
+ const authSessionInput = metadata?.authSessionInput ?? {};
90
90
  try {
91
91
  const refresehAuthSessionInstance = await (0, _utils.runCreateApiViaCLI)(authSessionInput);
92
92
  if (!refresehAuthSessionInstance) {
93
93
  throw new Error("Failed to refresh auth session");
94
94
  }
95
- await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options === null || options === void 0 ? void 0 : options.authSession, authSessionInput);
95
+ await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options?.authSession, authSessionInput);
96
96
  const checkResult = await (0, _utils.runCheckApiViaCLI)(authSessionPathToUse);
97
97
  if (!checkResult) {
98
98
  throw new Error("Failed to refresh auth session");