@intuned/runtime-dev 1.2.1-hooks.1 → 1.2.1-hooks.11

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 (38) hide show
  1. package/dist/commands/api/run.js +1 -2
  2. package/dist/commands/auth-sessions/load.js +3 -3
  3. package/dist/commands/auth-sessions/run-check.js +1 -2
  4. package/dist/commands/auth-sessions/run-create.js +12 -35
  5. package/dist/commands/interface/run.d.ts +1 -1
  6. package/dist/commands/interface/run.js +14 -40
  7. package/dist/commands/intuned-cli/controller/api.js +1 -2
  8. package/dist/commands/intuned-cli/controller/authSession.d.ts +6 -6
  9. package/dist/commands/intuned-cli/controller/authSession.js +3 -4
  10. package/dist/commands/intuned-cli/helpers/auth.d.ts +1 -1
  11. package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
  12. package/dist/commands/intuned-cli/helpers/errors.js +8 -4
  13. package/dist/common/asyncLocalStorage/index.d.ts +1 -1
  14. package/dist/common/initializeContextHook.d.ts +16 -0
  15. package/dist/common/initializeContextHook.js +15 -0
  16. package/dist/common/playwrightContext.d.ts +49 -0
  17. package/dist/common/playwrightContext.js +237 -0
  18. package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
  19. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  20. package/dist/common/runApi/index.d.ts +2 -7
  21. package/dist/common/runApi/index.js +87 -174
  22. package/dist/common/runApi/types.d.ts +25 -29
  23. package/dist/common/runApi/types.js +1 -2
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.js +7 -20
  26. package/dist/runtime/export.d.ts +49 -43
  27. package/dist/runtime/index.d.ts +1 -3
  28. package/dist/runtime/index.js +6 -19
  29. package/dist/runtime/store.d.ts +2 -0
  30. package/dist/runtime/store.js +23 -0
  31. package/package.json +2 -2
  32. package/.npmrc.wtf +0 -1
  33. package/dist/common/getPlaywrightConstructs.d.ts +0 -31
  34. package/dist/common/getPlaywrightConstructs.js +0 -234
  35. package/dist/runtime/getCdpAddress.d.ts +0 -1
  36. package/dist/runtime/getCdpAddress.js +0 -11
  37. package/dist/runtime/requestMoreInfo.d.ts +0 -18
  38. package/dist/runtime/requestMoreInfo.js +0 -25
@@ -48,8 +48,7 @@ async function executeCLI(apiName, mode, inputData, options) {
48
48
  session: {
49
49
  type: "file",
50
50
  path: authSessionPathToUse
51
- },
52
- runCheck: false
51
+ }
53
52
  } : undefined,
54
53
  runOptions: {
55
54
  environment: "cdp",
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  var _commander = require("commander");
5
- var _getPlaywrightConstructs = require("../../common/getPlaywrightConstructs");
5
+ var _playwrightContext = require("../../common/playwrightContext");
6
6
  var _settings = require("../common/utils/settings");
7
7
  var _dotenv = _interopRequireDefault(require("dotenv"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -19,8 +19,8 @@ _commander.program.description("load auth session to browser").option("--cdpAddr
19
19
  }
20
20
  const {
21
21
  context
22
- } = await (0, _getPlaywrightConstructs.getRemotePlaywrightContext)(cdpAddress);
23
- await (0, _getPlaywrightConstructs.loadSessionToContext)({
22
+ } = await (0, _playwrightContext.getRemotePlaywrightContext)(cdpAddress);
23
+ await (0, _playwrightContext.loadSessionToContext)({
24
24
  context,
25
25
  session: {
26
26
  type: "file",
@@ -54,8 +54,7 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
54
54
  session: {
55
55
  type: "file",
56
56
  path: authSessionPath
57
- },
58
- runCheck: false
57
+ }
59
58
  },
60
59
  importFunction: _tsNodeImport.tsNodeImport
61
60
  }));
@@ -3,7 +3,6 @@
3
3
 
4
4
  var _commander = require("commander");
5
5
  var fs = _interopRequireWildcard(require("fs-extra"));
6
- var _promptly = require("promptly");
7
6
  var _fileUtils = require("../common/utils/fileUtils");
8
7
  var _settings = require("../common/utils/settings");
9
8
  var _dotenv = _interopRequireDefault(require("dotenv"));
@@ -42,7 +41,7 @@ _commander.program.description("run auth session create").option("--cdpAddress <
42
41
  throw new Error("auth session create file not found");
43
42
  }
44
43
  async function runCreate() {
45
- const generator = (0, _runApi.runApiGenerator)({
44
+ const result = await (0, _runApi.runApi)({
46
45
  automationFunction: {
47
46
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
48
47
  params: inputData
@@ -55,40 +54,18 @@ _commander.program.description("run auth session create").option("--cdpAddress <
55
54
  retrieveSession: true,
56
55
  importFunction: _tsNodeImport.tsNodeImport
57
56
  });
58
- let nextGeneratorParam = undefined;
59
- while (true) {
60
- const {
61
- value,
62
- done
63
- } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
64
- if (done) {
65
- if (value.isErr()) {
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");
71
- }
72
- const fullState = value.value.session;
73
- if (pathToSave) {
74
- const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
75
- fs.ensureFileSync(fullPath);
76
- await fs.writeJSON(fullPath, fullState);
77
- }
78
- break;
79
- }
80
- if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
81
- nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
82
- validator: input => {
83
- if (!value.choices.includes(input)) {
84
- throw new Error("Please type on of the allowed choices");
85
- }
86
- return input;
87
- }
88
- });
89
- } else if (value.action === "request_more_info" && value.requestType == "otp") {
90
- nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
57
+ if (result.isErr()) {
58
+ if (result.error instanceof _runApi.AutomationError) {
59
+ throw result.error.error;
91
60
  }
61
+ console.error(result.error);
62
+ throw new Error("Error while running create");
63
+ }
64
+ const fullState = result.value.session;
65
+ if (pathToSave) {
66
+ const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
67
+ fs.ensureFileSync(fullPath);
68
+ await fs.writeJSON(fullPath, fullState);
92
69
  }
93
70
  }
94
71
  await (0, _asyncLocalStorage.runWithContext)({
@@ -1 +1 @@
1
- export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
1
+ export declare function runAutomationCLI<ResultType = any>(importFunction?: (path: string) => Promise<any>): void;
@@ -64,15 +64,10 @@ function runAutomationCLI(importFunction) {
64
64
  const throttleTime = 60 * 1000;
65
65
  let timeoutTimestamp = Date.now();
66
66
  const client = net.createConnection(socketPath);
67
- let generator = null;
68
67
  const abortController = new AbortController();
69
- client.on("error", err => {
70
- void generator?.throw(err).catch(() => undefined);
71
- });
72
68
  const interruptSignalHandler = async () => {
73
69
  abortController.abort();
74
70
  await (0, _promises.setTimeout)(60_000);
75
- void generator?.throw(new Error("Interrupted")).catch(() => undefined);
76
71
  client.end();
77
72
  process.exit(1);
78
73
  };
@@ -107,11 +102,6 @@ function runAutomationCLI(importFunction) {
107
102
  return;
108
103
  }
109
104
  if (message.type === "start") {
110
- generator = (0, _runApi.runApiGenerator)({
111
- ...message.parameters,
112
- abortSignal: abortController.signal,
113
- importFunction: importFunction ?? _defaultImport
114
- });
115
105
  context = {
116
106
  extendedPayloads: [],
117
107
  runEnvironment: message.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
@@ -130,38 +120,18 @@ function runAutomationCLI(importFunction) {
130
120
  };
131
121
  _jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
132
122
  resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
133
- return await generator.next();
123
+ return await (0, _runApi.runApi)({
124
+ ...message.parameters,
125
+ abortSignal: abortController.signal,
126
+ importFunction: importFunction ?? _defaultImport
127
+ });
134
128
  });
135
129
  return;
136
130
  }
137
131
  if (message.type === "next") {
138
- if (!generator) {
139
- throw new Error("generator not started");
140
- }
141
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
142
- return await generator.next(message.parameters.value);
143
- });
144
- return;
132
+ throw new Error("next not supported anymore");
145
133
  }
146
134
  }
147
- async function handleResult(generatorResult) {
148
- if (!generatorResult.done) {
149
- jsonUnixSocket.sendJSON({
150
- type: "yield",
151
- result: generatorResult.value
152
- });
153
- return false;
154
- }
155
- const result = generatorResult.value;
156
- const success = result.isOk();
157
- const resultToSend = success ? result.value : result.error.json;
158
- jsonUnixSocket.sendJSON({
159
- type: "done",
160
- result: resultToSend,
161
- success
162
- });
163
- return true;
164
- }
165
135
  let receiveMessagesPromise = receiveMessages();
166
136
  while (true) {
167
137
  const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
@@ -199,10 +169,14 @@ function runAutomationCLI(importFunction) {
199
169
  const {
200
170
  result
201
171
  } = messageOrResult;
202
- const done = await handleResult(result);
203
- if (done) {
204
- break;
205
- }
172
+ const success = result.isOk();
173
+ const resultToSend = success ? result.value : result.error.json;
174
+ jsonUnixSocket.sendJSON({
175
+ type: "done",
176
+ result: resultToSend,
177
+ success
178
+ });
179
+ break;
206
180
  }
207
181
  if (!client.closed) {
208
182
  client.end();
@@ -159,8 +159,7 @@ async function attemptApi({
159
159
  session: {
160
160
  type: "state",
161
161
  state: auth
162
- },
163
- runCheck: false
162
+ }
164
163
  } : undefined,
165
164
  importFunction: _tsNodeImport.tsNodeImport,
166
165
  abortSignal
@@ -14,9 +14,9 @@ export declare function executeRunCreateAuthSessionCLI({ id, input, checkRetries
14
14
  log?: boolean;
15
15
  } & BaseCommandOptions): Promise<{
16
16
  cookies: {
17
+ path: string;
17
18
  value: string;
18
19
  name: string;
19
- path: string;
20
20
  domain: string;
21
21
  expires: number;
22
22
  httpOnly: boolean;
@@ -45,9 +45,9 @@ export declare function executeRunUpdateAuthSessionCLI({ id, input, checkRetries
45
45
  createRetries: number;
46
46
  } & BaseCommandOptions): Promise<{
47
47
  cookies: {
48
+ path: string;
48
49
  value: string;
49
50
  name: string;
50
- path: string;
51
51
  domain: string;
52
52
  expires: number;
53
53
  httpOnly: boolean;
@@ -74,9 +74,9 @@ export declare function executeAttemptCreateAuthSessionCLI({ id, input, ...rest
74
74
  input: any;
75
75
  } & BaseCommandOptions): Promise<{
76
76
  cookies: {
77
+ path: string;
77
78
  value: string;
78
79
  name: string;
79
- path: string;
80
80
  domain: string;
81
81
  expires: number;
82
82
  httpOnly: boolean;
@@ -102,9 +102,9 @@ export declare function executeAttemptCheckAuthSessionCLI({ id, ...rest }: {
102
102
  id: string;
103
103
  } & BaseCommandOptions): Promise<{
104
104
  cookies: {
105
+ path: string;
105
106
  value: string;
106
107
  name: string;
107
- path: string;
108
108
  domain: string;
109
109
  expires: number;
110
110
  httpOnly: boolean;
@@ -134,9 +134,9 @@ declare function runCreate({ authSessionInput, proxy, headless, timeout, }: {
134
134
  authSessionInput: Record<string, any>;
135
135
  } & BaseCommandOptions): Promise<{
136
136
  cookies: {
137
+ path: string;
137
138
  value: string;
138
139
  name: string;
139
- path: string;
140
140
  domain: string;
141
141
  expires: number;
142
142
  httpOnly: boolean;
@@ -170,9 +170,9 @@ declare function runCreateWithRetries({ authSessionId, authSessionInput, retries
170
170
  retries: number;
171
171
  } & BaseCommandOptions): Promise<{
172
172
  cookies: {
173
+ path: string;
173
174
  value: string;
174
175
  name: string;
175
- path: string;
176
176
  domain: string;
177
177
  expires: number;
178
178
  httpOnly: boolean;
@@ -179,8 +179,7 @@ async function runCheck({
179
179
  session: {
180
180
  type: "state",
181
181
  state: auth
182
- },
183
- runCheck: false
182
+ }
184
183
  },
185
184
  importFunction: _tsNodeImport.tsNodeImport,
186
185
  abortSignal
@@ -241,7 +240,7 @@ async function runCheckWithRetries({
241
240
  return true;
242
241
  }
243
242
  } catch (error) {
244
- if (error instanceof _runApi.AutomationError) {
243
+ if (error instanceof _runApi.RunAutomationError) {
245
244
  (0, _helpers.logAutomationError)(error);
246
245
  } else {
247
246
  throw error;
@@ -270,7 +269,7 @@ async function runCreateWithRetries({
270
269
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
271
270
  break;
272
271
  } catch (error) {
273
- if (error instanceof _runApi.AutomationError) {
272
+ if (error instanceof _runApi.RunAutomationError) {
274
273
  (0, _helpers.logAutomationError)(error);
275
274
  } else {
276
275
  throw error;
@@ -6,9 +6,9 @@ export declare function assertAuthConsistent(authSession: string | undefined): P
6
6
  export declare function loadAuthSessionInstance(authSessionId: string): Promise<{
7
7
  storageState: {
8
8
  cookies: {
9
+ path: string;
9
10
  value: string;
10
11
  name: string;
11
- path: string;
12
12
  domain: string;
13
13
  expires: number;
14
14
  httpOnly: boolean;
@@ -1,4 +1,4 @@
1
- import { AutomationError } from "../../../common/runApi";
1
+ import { RunAutomationError } from "../../../common/runApi";
2
2
  export declare class CLIError extends Error {
3
3
  autoColor: boolean;
4
4
  constructor(message: string, options?: {
@@ -10,5 +10,5 @@ export declare class CLIAssertionError extends CLIError {
10
10
  autoColor?: boolean;
11
11
  });
12
12
  }
13
- export declare function logAutomationError(error: AutomationError): void;
13
+ export declare function logAutomationError(error: RunAutomationError): void;
14
14
  export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
@@ -25,11 +25,15 @@ class CLIAssertionError extends CLIError {
25
25
  exports.CLIAssertionError = CLIAssertionError;
26
26
  function logAutomationError(error) {
27
27
  (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
28
- if (error.error.stack) {
29
- const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime") && !line.includes("node:"));
30
- (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
28
+ if (error instanceof _runApi.AutomationError) {
29
+ if (error.error.stack) {
30
+ const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime") && !line.includes("node:"));
31
+ (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
32
+ } else {
33
+ (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
34
+ }
31
35
  } else {
32
- (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
36
+ (0, _terminal.terminal)(`^r${error.message}^:\n`);
33
37
  }
34
38
  }
35
39
  function withErrorLogging(fn) {
@@ -8,8 +8,8 @@ interface TimeoutInfo {
8
8
  }
9
9
  export interface InternalRunInfo extends RunInfo {
10
10
  extendedPayloads: Payload[];
11
- cdpAddress?: string;
12
11
  timeoutInfo?: TimeoutInfo;
12
+ store?: Record<string, any>;
13
13
  getAuthSessionParameters?: () => Promise<any>;
14
14
  }
15
15
  export declare function getExecutionContext(): InternalRunInfo | undefined;
@@ -0,0 +1,16 @@
1
+ import type * as playwright from "playwright";
2
+ import type { RunAutomationError } from "./runApi/errors";
3
+ import type { Err, Ok } from "neverthrow";
4
+ import { type ImportFunction } from "./runApi/importUsingImportFunction";
5
+ export type InitializeContextHookOptions = {
6
+ apiName: string;
7
+ apiParameters: any;
8
+ cdpUrl: string;
9
+ };
10
+ export type InitializeContextHook = (options: InitializeContextHookOptions) => Promise<{
11
+ page: playwright.Page | null;
12
+ context: playwright.BrowserContext;
13
+ } | null>;
14
+ export declare function loadInitializeContextHook({ importFunction, }: {
15
+ importFunction: ImportFunction;
16
+ }): Promise<Ok<InitializeContextHook | null, any> | Err<any, RunAutomationError>>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadInitializeContextHook = loadInitializeContextHook;
7
+ var _importUsingImportFunction = require("./runApi/importUsingImportFunction");
8
+ async function loadInitializeContextHook({
9
+ importFunction
10
+ }) {
11
+ return await (0, _importUsingImportFunction.importUsingImportFunction)({
12
+ path: "hooks/initializeContext",
13
+ importFunction
14
+ });
15
+ }
@@ -0,0 +1,49 @@
1
+ import * as playwright from "playwright";
2
+ import { RunAutomationError } from "./runApi/errors";
3
+ import type { RunApiSession } from "./runApi/types";
4
+ import { Err, Ok } from "neverthrow";
5
+ import { type ImportFunction } from "./runApi/importUsingImportFunction";
6
+ export interface Proxy {
7
+ server: string;
8
+ username: string;
9
+ password: string;
10
+ }
11
+ export declare function launchChromium(options: {
12
+ proxy?: Proxy;
13
+ headless: boolean;
14
+ downloadsPath?: string;
15
+ cdpPort?: number;
16
+ }): Promise<{
17
+ page: playwright.Page;
18
+ context: playwright.BrowserContext;
19
+ }>;
20
+ export declare function launchChromium(options: {
21
+ cdpAddress: string;
22
+ }): Promise<{
23
+ page: playwright.Page;
24
+ context: playwright.BrowserContext;
25
+ }>;
26
+ export declare const browserScriptsFile: string;
27
+ type WithPlaywrightContextParameters = {
28
+ importFunction: ImportFunction;
29
+ apiName: string;
30
+ apiParameters: any;
31
+ };
32
+ export type WithPlaywrightContextWrappedFunction<R> = (context: playwright.BrowserContext, page: playwright.Page) => Promise<Ok<R, any> | Err<any, RunAutomationError>>;
33
+ export declare function withPlaywrightContext<R>(options: {
34
+ proxy?: Proxy;
35
+ headless: boolean;
36
+ downloadsPath: string;
37
+ } & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
38
+ export declare function withPlaywrightContext<R>(options: {
39
+ cdpAddress: string;
40
+ } & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
41
+ export declare function loadSessionToContext({ context, session, }: {
42
+ context: playwright.BrowserContext;
43
+ session: RunApiSession;
44
+ }): Promise<void>;
45
+ export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
46
+ browser: playwright.Browser;
47
+ context: playwright.BrowserContext;
48
+ }>;
49
+ export {};