@intuned/runtime-dev 1.2.1-hooks.9 → 1.2.1-results.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 +2 -1
- package/dist/commands/api/run.js +6 -2
- package/dist/commands/auth-sessions/load.js +3 -3
- package/dist/commands/auth-sessions/run-check.js +2 -1
- package/dist/commands/auth-sessions/run-create.js +35 -12
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +40 -14
- package/dist/commands/intuned-cli/controller/api.js +2 -1
- package/dist/commands/intuned-cli/controller/authSession.d.ts +6 -6
- package/dist/commands/intuned-cli/controller/authSession.js +4 -3
- package/dist/commands/intuned-cli/helpers/auth.d.ts +1 -1
- package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
- package/dist/commands/intuned-cli/helpers/errors.js +4 -8
- package/dist/common/asyncLocalStorage/index.d.ts +0 -1
- package/dist/common/getPlaywrightConstructs.d.ts +30 -0
- package/dist/common/{playwrightContext.js → getPlaywrightConstructs.js} +80 -132
- package/dist/common/runApi/errors.d.ts +9 -2
- package/dist/common/runApi/errors.js +17 -3
- package/dist/common/runApi/index.d.ts +7 -2
- package/dist/common/runApi/index.js +185 -87
- package/dist/common/runApi/types.d.ts +25 -21
- package/dist/common/runApi/types.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +20 -7
- package/dist/runtime/export.d.ts +43 -49
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.js +11 -5
- package/dist/runtime/requestMoreInfo.d.ts +18 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/package.json +1 -3
- package/dist/common/initializeContextHook.d.ts +0 -16
- package/dist/common/initializeContextHook.js +0 -15
- package/dist/common/playwrightContext.d.ts +0 -49
- package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/dist/runtime/store.d.ts +0 -2
- package/dist/runtime/store.js +0 -23
package/CHANGELOG.md
CHANGED
package/dist/commands/api/run.js
CHANGED
|
@@ -48,7 +48,8 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
48
48
|
session: {
|
|
49
49
|
type: "file",
|
|
50
50
|
path: authSessionPathToUse
|
|
51
|
-
}
|
|
51
|
+
},
|
|
52
|
+
runCheck: false
|
|
52
53
|
} : undefined,
|
|
53
54
|
runOptions: {
|
|
54
55
|
environment: "cdp",
|
|
@@ -77,7 +78,10 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
77
78
|
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
|
|
78
79
|
fs.ensureDirSync(resultsDir);
|
|
79
80
|
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
80
|
-
await fs.writeJson(path,
|
|
81
|
+
await fs.writeJson(path, {
|
|
82
|
+
input: inputData,
|
|
83
|
+
output: result
|
|
84
|
+
}, {
|
|
81
85
|
spaces: 2
|
|
82
86
|
});
|
|
83
87
|
} else {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
|
-
var
|
|
5
|
+
var _getPlaywrightConstructs = require("../../common/getPlaywrightConstructs");
|
|
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,
|
|
23
|
-
await (0,
|
|
22
|
+
} = await (0, _getPlaywrightConstructs.getRemotePlaywrightContext)(cdpAddress);
|
|
23
|
+
await (0, _getPlaywrightConstructs.loadSessionToContext)({
|
|
24
24
|
context,
|
|
25
25
|
session: {
|
|
26
26
|
type: "file",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
5
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
6
|
+
var _promptly = require("promptly");
|
|
6
7
|
var _fileUtils = require("../common/utils/fileUtils");
|
|
7
8
|
var _settings = require("../common/utils/settings");
|
|
8
9
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
@@ -41,7 +42,7 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
41
42
|
throw new Error("auth session create file not found");
|
|
42
43
|
}
|
|
43
44
|
async function runCreate() {
|
|
44
|
-
const
|
|
45
|
+
const generator = (0, _runApi.runApiGenerator)({
|
|
45
46
|
automationFunction: {
|
|
46
47
|
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
|
|
47
48
|
params: inputData
|
|
@@ -54,18 +55,40 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
54
55
|
retrieveSession: true,
|
|
55
56
|
importFunction: _tsNodeImport.tsNodeImport
|
|
56
57
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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, {});
|
|
60
91
|
}
|
|
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);
|
|
69
92
|
}
|
|
70
93
|
}
|
|
71
94
|
await (0, _asyncLocalStorage.runWithContext)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function runAutomationCLI
|
|
1
|
+
export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
|
|
@@ -64,10 +64,15 @@ 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;
|
|
67
68
|
const abortController = new AbortController();
|
|
69
|
+
client.on("error", err => {
|
|
70
|
+
void generator?.throw(err).catch(() => undefined);
|
|
71
|
+
});
|
|
68
72
|
const interruptSignalHandler = async () => {
|
|
69
73
|
abortController.abort();
|
|
70
74
|
await (0, _promises.setTimeout)(60_000);
|
|
75
|
+
void generator?.throw(new Error("Interrupted")).catch(() => undefined);
|
|
71
76
|
client.end();
|
|
72
77
|
process.exit(1);
|
|
73
78
|
};
|
|
@@ -102,6 +107,11 @@ function runAutomationCLI(importFunction) {
|
|
|
102
107
|
return;
|
|
103
108
|
}
|
|
104
109
|
if (message.type === "start") {
|
|
110
|
+
generator = (0, _runApi.runApiGenerator)({
|
|
111
|
+
...message.parameters,
|
|
112
|
+
abortSignal: abortController.signal,
|
|
113
|
+
importFunction: importFunction ?? _defaultImport
|
|
114
|
+
});
|
|
105
115
|
context = {
|
|
106
116
|
extendedPayloads: [],
|
|
107
117
|
runEnvironment: message.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
|
|
@@ -120,18 +130,38 @@ function runAutomationCLI(importFunction) {
|
|
|
120
130
|
};
|
|
121
131
|
_jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
|
|
122
132
|
resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
|
|
123
|
-
return await (
|
|
124
|
-
...message.parameters,
|
|
125
|
-
abortSignal: abortController.signal,
|
|
126
|
-
importFunction: importFunction ?? _defaultImport
|
|
127
|
-
});
|
|
133
|
+
return await generator.next();
|
|
128
134
|
});
|
|
129
135
|
return;
|
|
130
136
|
}
|
|
131
137
|
if (message.type === "next") {
|
|
132
|
-
|
|
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;
|
|
133
145
|
}
|
|
134
146
|
}
|
|
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
|
+
}
|
|
135
165
|
let receiveMessagesPromise = receiveMessages();
|
|
136
166
|
while (true) {
|
|
137
167
|
const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
|
|
@@ -169,14 +199,10 @@ function runAutomationCLI(importFunction) {
|
|
|
169
199
|
const {
|
|
170
200
|
result
|
|
171
201
|
} = messageOrResult;
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
result: resultToSend,
|
|
177
|
-
success
|
|
178
|
-
});
|
|
179
|
-
break;
|
|
202
|
+
const done = await handleResult(result);
|
|
203
|
+
if (done) {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
180
206
|
}
|
|
181
207
|
if (!client.closed) {
|
|
182
208
|
client.end();
|
|
@@ -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;
|
|
18
17
|
value: string;
|
|
19
18
|
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;
|
|
49
48
|
value: string;
|
|
50
49
|
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;
|
|
78
77
|
value: string;
|
|
79
78
|
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;
|
|
106
105
|
value: string;
|
|
107
106
|
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;
|
|
138
137
|
value: string;
|
|
139
138
|
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;
|
|
174
173
|
value: string;
|
|
175
174
|
name: string;
|
|
175
|
+
path: string;
|
|
176
176
|
domain: string;
|
|
177
177
|
expires: number;
|
|
178
178
|
httpOnly: boolean;
|
|
@@ -179,7 +179,8 @@ async function runCheck({
|
|
|
179
179
|
session: {
|
|
180
180
|
type: "state",
|
|
181
181
|
state: auth
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
|
+
runCheck: false
|
|
183
184
|
},
|
|
184
185
|
importFunction: _tsNodeImport.tsNodeImport,
|
|
185
186
|
abortSignal
|
|
@@ -240,7 +241,7 @@ async function runCheckWithRetries({
|
|
|
240
241
|
return true;
|
|
241
242
|
}
|
|
242
243
|
} catch (error) {
|
|
243
|
-
if (error instanceof _runApi.
|
|
244
|
+
if (error instanceof _runApi.AutomationError) {
|
|
244
245
|
(0, _helpers.logAutomationError)(error);
|
|
245
246
|
} else {
|
|
246
247
|
throw error;
|
|
@@ -269,7 +270,7 @@ async function runCreateWithRetries({
|
|
|
269
270
|
(0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
|
|
270
271
|
break;
|
|
271
272
|
} catch (error) {
|
|
272
|
-
if (error instanceof _runApi.
|
|
273
|
+
if (error instanceof _runApi.AutomationError) {
|
|
273
274
|
(0, _helpers.logAutomationError)(error);
|
|
274
275
|
} else {
|
|
275
276
|
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;
|
|
10
9
|
value: string;
|
|
11
10
|
name: string;
|
|
11
|
+
path: string;
|
|
12
12
|
domain: string;
|
|
13
13
|
expires: number;
|
|
14
14
|
httpOnly: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AutomationError } 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:
|
|
13
|
+
export declare function logAutomationError(error: AutomationError): void;
|
|
14
14
|
export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
|
|
@@ -25,15 +25,11 @@ 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
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
|
|
32
|
-
} else {
|
|
33
|
-
(0, _terminal.terminal)(`^r${error.error.message}^:\n`);
|
|
34
|
-
}
|
|
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`);
|
|
35
31
|
} else {
|
|
36
|
-
(0, _terminal.terminal)(`^r${error.message}^:\n`);
|
|
32
|
+
(0, _terminal.terminal)(`^r${error.error.message}^:\n`);
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
function withErrorLogging(fn) {
|
|
@@ -9,7 +9,6 @@ interface TimeoutInfo {
|
|
|
9
9
|
export interface InternalRunInfo extends RunInfo {
|
|
10
10
|
extendedPayloads: Payload[];
|
|
11
11
|
timeoutInfo?: TimeoutInfo;
|
|
12
|
-
store?: Record<string, any>;
|
|
13
12
|
getAuthSessionParameters?: () => Promise<any>;
|
|
14
13
|
}
|
|
15
14
|
export declare function getExecutionContext(): InternalRunInfo | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as playwright from "playwright";
|
|
2
|
+
import type { RunApiSession } from "./runApi";
|
|
3
|
+
interface Proxy {
|
|
4
|
+
server: string;
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
interface GetPlaywrightConstructsOptions {
|
|
9
|
+
proxy?: Proxy;
|
|
10
|
+
headless?: boolean;
|
|
11
|
+
storageState?: RunApiSession;
|
|
12
|
+
downloadsPath: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, }: GetPlaywrightConstructsOptions): Promise<{
|
|
15
|
+
page: playwright.Page;
|
|
16
|
+
context: playwright.BrowserContext;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession): Promise<{
|
|
19
|
+
page: playwright.Page;
|
|
20
|
+
context: playwright.BrowserContext;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function loadSessionToContext({ context, session, }: {
|
|
23
|
+
context: playwright.BrowserContext;
|
|
24
|
+
session: RunApiSession;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
|
|
27
|
+
browser: playwright.Browser;
|
|
28
|
+
context: playwright.BrowserContext;
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|