@intuned/runtime-dev 1.3.1-api-token.6 → 1.3.4-dev.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/dist/commands/api/run.js +5 -3
- package/dist/commands/auth-sessions/load.js +3 -3
- package/dist/commands/auth-sessions/run-check.js +1 -2
- package/dist/commands/auth-sessions/run-create.js +12 -35
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +14 -40
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +1 -2
- package/dist/commands/intuned-cli/controller/api.js +1 -2
- package/dist/commands/intuned-cli/controller/authSession.js +3 -4
- package/dist/commands/intuned-cli/controller/save.js +27 -28
- package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
- package/dist/commands/intuned-cli/helpers/errors.js +8 -4
- package/dist/commands/intuned-cli/main.js +2 -2
- package/dist/common/asyncLocalStorage/index.d.ts +1 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +2 -1
- package/dist/common/extensionsHelpers.d.ts +15 -0
- package/dist/common/extensionsHelpers.js +81 -0
- package/dist/common/playwrightContext.d.ts +54 -0
- package/dist/common/playwrightContext.js +274 -0
- package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
- package/dist/common/runApi/importUsingImportFunction.js +46 -0
- package/dist/common/runApi/index.d.ts +2 -7
- package/dist/common/runApi/index.js +92 -177
- package/dist/common/runApi/types.d.ts +1 -5
- package/dist/common/runApi/types.js +1 -2
- package/dist/common/settingsSchema.d.ts +513 -0
- package/dist/common/settingsSchema.js +40 -2
- package/dist/common/setupContextHook.d.ts +17 -0
- package/dist/common/setupContextHook.js +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -19
- package/dist/runtime/attemptStore.d.ts +2 -0
- package/dist/runtime/attemptStore.js +23 -0
- package/dist/runtime/export.d.ts +51 -41
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +7 -13
- package/package.json +3 -1
- package/WebTemplate.zip +0 -0
- package/dist/common/getPlaywrightConstructs.d.ts +0 -30
- package/dist/common/getPlaywrightConstructs.js +0 -188
- package/dist/runtime/requestMoreInfo.d.ts +0 -18
- package/dist/runtime/requestMoreInfo.js +0 -25
package/dist/index.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "RunError", {
|
|
|
9
9
|
return _runtime.RunError;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "attemptStore", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _runtime.attemptStore;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "extendPayload", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
@@ -39,24 +45,6 @@ Object.defineProperty(exports, "getExecutionContext", {
|
|
|
39
45
|
return _asyncLocalStorage.getExecutionContext;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
|
-
Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _getPlaywrightConstructs.getProductionPlaywrightConstructs;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _runtime.requestMultipleChoice;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "requestOTP", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _runtime.requestOTP;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
48
|
Object.defineProperty(exports, "runInfo", {
|
|
61
49
|
enumerable: true,
|
|
62
50
|
get: function () {
|
|
@@ -69,7 +57,13 @@ Object.defineProperty(exports, "runWithContext", {
|
|
|
69
57
|
return _asyncLocalStorage.runWithContext;
|
|
70
58
|
}
|
|
71
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "withPlaywrightContext", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _playwrightContext.withPlaywrightContext;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
72
66
|
var _runtime = require("./runtime");
|
|
73
67
|
var _asyncLocalStorage = require("./common/asyncLocalStorage");
|
|
74
68
|
var _downloadDirectory = require("./runtime/downloadDirectory");
|
|
75
|
-
var
|
|
69
|
+
var _playwrightContext = require("./common/playwrightContext");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attemptStore = void 0;
|
|
7
|
+
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
+
const attemptStore = exports.attemptStore = Object.freeze({
|
|
9
|
+
get: key => {
|
|
10
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
|
+
return context?.store ? context.store[key] : undefined;
|
|
12
|
+
},
|
|
13
|
+
set: (key, value) => {
|
|
14
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error("store.set failed due to an internal error.");
|
|
17
|
+
}
|
|
18
|
+
if (!context.store) {
|
|
19
|
+
context.store = {};
|
|
20
|
+
}
|
|
21
|
+
context.store[key] = value;
|
|
22
|
+
}
|
|
23
|
+
});
|
package/dist/runtime/export.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ export interface RunErrorOptions {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
+
* @deprecated This error is deprecated. it will be treated like any normal error
|
|
130
|
+
*
|
|
129
131
|
* Represents an error that occurs during a run.
|
|
130
132
|
*
|
|
131
133
|
* @class
|
|
@@ -154,65 +156,73 @@ export declare class RunError extends Error {
|
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* **Note:** This function is currently in beta and may be subject to changes.
|
|
159
|
+
* Retrieves the parameters for the authentication session currently being used.
|
|
160
160
|
*
|
|
161
|
-
* @
|
|
162
|
-
* @param {string[]} choices - An array of choices to present to the user.
|
|
161
|
+
* @returns {AuthSessionParameters} An object containing the parameters for the current authentication session.
|
|
163
162
|
*
|
|
164
163
|
* @example
|
|
165
|
-
* ```typescript
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* import { requestMultipleChoice } from "@intuned/sdk/runtime"
|
|
169
|
-
*
|
|
170
|
-
* const message = "What is your favorite color?";
|
|
171
|
-
* const choices = ["Red", "Blue", "Green", "Yellow"];
|
|
172
|
-
*
|
|
173
|
-
* const selectedChoice = yield requestMultipleChoice(message, choices);
|
|
164
|
+
* ```typescript getAuthSessionParameters
|
|
165
|
+
* import { getAuthSessionParameters } from "@intuned/sdk/runtime"
|
|
174
166
|
*
|
|
175
|
-
*
|
|
167
|
+
* const authSessionParams = getAuthSessionParameters();
|
|
168
|
+
* console.log(authSessionParams);
|
|
176
169
|
* ```
|
|
177
170
|
*/
|
|
178
|
-
export declare function
|
|
179
|
-
message: string,
|
|
180
|
-
choices: string[]
|
|
181
|
-
): unknown;
|
|
171
|
+
export declare function getAuthSessionParameters(): Promise<any>;
|
|
182
172
|
|
|
183
173
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param {string} message - The message to display to the user.
|
|
174
|
+
* @interface Store
|
|
175
|
+
* @property {function} get - Retrieves a value from the store by key
|
|
176
|
+
* @property {function} set - Sets a value in the store by key
|
|
189
177
|
*
|
|
190
178
|
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* import { requestOTP } from "@intuned/sdk/runtime"
|
|
179
|
+
* ```typescript Store usage
|
|
180
|
+
* import { store } from "@intuned/sdk/runtime"
|
|
195
181
|
*
|
|
196
|
-
*
|
|
182
|
+
* // Set a value in the store
|
|
183
|
+
* store.set('userPreference', { theme: 'dark' });
|
|
197
184
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* console.log(otp);
|
|
185
|
+
* // Get a value from the store
|
|
186
|
+
* const preference = store.get('userPreference');
|
|
201
187
|
* ```
|
|
202
188
|
*/
|
|
203
|
-
export
|
|
189
|
+
export interface Store {
|
|
190
|
+
/**
|
|
191
|
+
* Retrieves a value from the store by key.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} key - The key to retrieve the value for
|
|
194
|
+
* @returns {any} The value associated with the key, or undefined if not found
|
|
195
|
+
*/
|
|
196
|
+
get(key: string): any;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Sets a value in the store by key.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} key - The key to set the value for
|
|
202
|
+
* @param {any} value - The value to store
|
|
203
|
+
* @throws {Error} Throws an error if the store operation fails
|
|
204
|
+
*/
|
|
205
|
+
set(key: string, value: any): void;
|
|
206
|
+
}
|
|
204
207
|
|
|
205
208
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
+
* ## Description
|
|
210
|
+
* A persistent key-value store that maintains data within the execution context.
|
|
211
|
+
* This store allows you to share data between different parts of your API execution.
|
|
209
212
|
*
|
|
210
213
|
* @example
|
|
211
|
-
* ```typescript
|
|
212
|
-
* import {
|
|
214
|
+
* ```typescript Store usage
|
|
215
|
+
* import { store } from "@intuned/sdk/runtime"
|
|
213
216
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
217
|
+
* // Set a value in the store
|
|
218
|
+
* store.set('sessionData', { userId: '123', token: 'abc' });
|
|
219
|
+
*
|
|
220
|
+
* // Get a value from the store
|
|
221
|
+
* const sessionData = store.get('sessionData');
|
|
222
|
+
* console.log(sessionData.userId); // '123'
|
|
223
|
+
*
|
|
224
|
+
* // Handle missing values
|
|
225
|
+
* const missingData = store.get('nonexistent'); // undefined
|
|
216
226
|
* ```
|
|
217
227
|
*/
|
|
218
|
-
export declare
|
|
228
|
+
export declare const attemptStore: Store;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { extendPayload } from "./extendPayload";
|
|
2
2
|
export { extendTimeout } from "./extendTimeout";
|
|
3
|
+
export { attemptStore } from "./attemptStore";
|
|
3
4
|
export { getAuthSessionParameters } from "./getAuthSessionParameters";
|
|
4
5
|
export { runInfo } from "./runInfo";
|
|
5
6
|
export { RunError } from "./RunError";
|
|
6
|
-
export { requestMultipleChoice, requestOTP } from "./requestMoreInfo";
|
|
7
|
-
export type { RequestMoreInfoDetails } from "./requestMoreInfo";
|
|
8
7
|
export { getDownloadDirectoryPath } from "./downloadDirectory";
|
package/dist/runtime/index.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "RunError", {
|
|
|
9
9
|
return _RunError.RunError;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "attemptStore", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _attemptStore.attemptStore;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "extendPayload", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
@@ -33,18 +39,6 @@ Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
|
33
39
|
return _downloadDirectory.getDownloadDirectoryPath;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
|
-
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _requestMoreInfo.requestMultipleChoice;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "requestOTP", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _requestMoreInfo.requestOTP;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
42
|
Object.defineProperty(exports, "runInfo", {
|
|
49
43
|
enumerable: true,
|
|
50
44
|
get: function () {
|
|
@@ -53,8 +47,8 @@ Object.defineProperty(exports, "runInfo", {
|
|
|
53
47
|
});
|
|
54
48
|
var _extendPayload = require("./extendPayload");
|
|
55
49
|
var _extendTimeout = require("./extendTimeout");
|
|
50
|
+
var _attemptStore = require("./attemptStore");
|
|
56
51
|
var _getAuthSessionParameters = require("./getAuthSessionParameters");
|
|
57
52
|
var _runInfo = require("./runInfo");
|
|
58
53
|
var _RunError = require("./RunError");
|
|
59
|
-
var _requestMoreInfo = require("./requestMoreInfo");
|
|
60
54
|
var _downloadDirectory = require("./downloadDirectory");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4-dev.0",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"nanoid": "3",
|
|
80
80
|
"neverthrow": "6.1.0",
|
|
81
81
|
"playwright-extra": "4.3.6",
|
|
82
|
+
"portfinder": "^1.0.37",
|
|
82
83
|
"prettier": "2.8.0",
|
|
83
84
|
"promptly": "3.2.0",
|
|
84
85
|
"rollup": "3.26.2",
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
"eslint-plugin-deprecation": "^1.3.3",
|
|
119
120
|
"eslint-plugin-prettier": "^4.2.1",
|
|
120
121
|
"msw": "^2.1.2",
|
|
122
|
+
"playwright": "^1.55.0",
|
|
121
123
|
"typedoc": "^0.25.13",
|
|
122
124
|
"typedoc-plugin-frontmatter": "^1.0.0",
|
|
123
125
|
"typedoc-plugin-markdown": "^4.0.2",
|
package/WebTemplate.zip
DELETED
|
Binary file
|
|
@@ -1,30 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
|
|
7
|
-
exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
|
|
8
|
-
exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
|
|
9
|
-
exports.loadSessionToContext = loadSessionToContext;
|
|
10
|
-
var playwright = _interopRequireWildcard(require("playwright"));
|
|
11
|
-
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var fs = _fsExtra;
|
|
13
|
-
var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
|
|
14
|
-
var _path = _interopRequireWildcard(require("path"));
|
|
15
|
-
var _fileUtils = require("../commands/common/utils/fileUtils");
|
|
16
|
-
var _waitOn = _interopRequireDefault(require("wait-on"));
|
|
17
|
-
var _runtime = require("../runtime");
|
|
18
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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); }
|
|
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 && {}.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
|
-
async function createUserDirWithPreferences() {
|
|
22
|
-
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
23
|
-
const userDir = (0, _path.join)(playwrightTempDir, "userdir");
|
|
24
|
-
const defaultDir = (0, _path.join)(userDir, "Default");
|
|
25
|
-
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
26
|
-
recursive: true
|
|
27
|
-
});
|
|
28
|
-
const preferences = {
|
|
29
|
-
plugins: {
|
|
30
|
-
always_open_pdf_externally: true
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
34
|
-
return userDir;
|
|
35
|
-
}
|
|
36
|
-
async function getProductionPlaywrightConstructs({
|
|
37
|
-
proxy,
|
|
38
|
-
headless = true,
|
|
39
|
-
storageState,
|
|
40
|
-
downloadsPath
|
|
41
|
-
}) {
|
|
42
|
-
const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
|
|
43
|
-
if (headless) {
|
|
44
|
-
extraArgs.push("--headless=new");
|
|
45
|
-
}
|
|
46
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
47
|
-
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
48
|
-
headless,
|
|
49
|
-
viewport: null,
|
|
50
|
-
proxy,
|
|
51
|
-
downloadsPath
|
|
52
|
-
});
|
|
53
|
-
context.once("close", async () => {
|
|
54
|
-
try {
|
|
55
|
-
await (0, _fsExtra.rm)(userDataDir, {
|
|
56
|
-
recursive: true,
|
|
57
|
-
force: true,
|
|
58
|
-
retryDelay: 1000,
|
|
59
|
-
maxRetries: 5
|
|
60
|
-
});
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error("Failed to remove user data dir", error);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (storageState) {
|
|
66
|
-
await loadSessionToContext({
|
|
67
|
-
context,
|
|
68
|
-
session: storageState
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
72
|
-
await context.addInitScript({
|
|
73
|
-
path: assetsFile
|
|
74
|
-
});
|
|
75
|
-
let page = context.pages().at(0);
|
|
76
|
-
if (page) {
|
|
77
|
-
const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
|
|
78
|
-
await page.evaluate(scriptString);
|
|
79
|
-
} else {
|
|
80
|
-
page = await context.newPage();
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
page,
|
|
84
|
-
context
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
|
|
88
|
-
if (mode == "playwright-standalone") {
|
|
89
|
-
if (!cdpAddress) {
|
|
90
|
-
throw new Error("cdpAddress is required");
|
|
91
|
-
}
|
|
92
|
-
const {
|
|
93
|
-
context
|
|
94
|
-
} = await getRemotePlaywrightContext(cdpAddress);
|
|
95
|
-
if (!context) {
|
|
96
|
-
throw new Error("no context found");
|
|
97
|
-
}
|
|
98
|
-
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
99
|
-
await context.addInitScript({
|
|
100
|
-
path: assetsFile
|
|
101
|
-
});
|
|
102
|
-
const pages = await context.pages();
|
|
103
|
-
let page = null;
|
|
104
|
-
if (pages.length > 0) {
|
|
105
|
-
page = pages[0];
|
|
106
|
-
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
107
|
-
await page.evaluate(scriptString);
|
|
108
|
-
} else {
|
|
109
|
-
page = await context.newPage();
|
|
110
|
-
}
|
|
111
|
-
if (authSession) {
|
|
112
|
-
await loadSessionToContext({
|
|
113
|
-
context,
|
|
114
|
-
session: authSession
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
page,
|
|
119
|
-
context
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
|
|
123
|
-
if (mode === "playwright" || mode === "playwright-headless") {
|
|
124
|
-
const productionConstructs = await getProductionPlaywrightConstructs({
|
|
125
|
-
headless: mode === "playwright-headless",
|
|
126
|
-
downloadsPath
|
|
127
|
-
});
|
|
128
|
-
if (authSession) {
|
|
129
|
-
await loadSessionToContext({
|
|
130
|
-
context: productionConstructs.context,
|
|
131
|
-
session: authSession
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
...productionConstructs
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
throw "invalid mode";
|
|
139
|
-
}
|
|
140
|
-
async function loadSessionToContext({
|
|
141
|
-
context,
|
|
142
|
-
session
|
|
143
|
-
}) {
|
|
144
|
-
let sessionToLoad;
|
|
145
|
-
if (session.type === "state") {
|
|
146
|
-
const state = session.state;
|
|
147
|
-
if (state === undefined || state === null) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
sessionToLoad = state;
|
|
151
|
-
} else {
|
|
152
|
-
const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
|
|
153
|
-
sessionToLoad = await fs.readJson(fullPath);
|
|
154
|
-
}
|
|
155
|
-
await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
|
|
156
|
-
}
|
|
157
|
-
async function getRemotePlaywrightContext(cdpAddress) {
|
|
158
|
-
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
|
|
159
|
-
let browser = null;
|
|
160
|
-
if (!cdpAddress) {
|
|
161
|
-
throw new Error("cdpAddress is required");
|
|
162
|
-
}
|
|
163
|
-
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
164
|
-
try {
|
|
165
|
-
await (0, _waitOn.default)({
|
|
166
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
167
|
-
delay: 100,
|
|
168
|
-
interval: 100,
|
|
169
|
-
timeout: 5000,
|
|
170
|
-
tcpTimeout: 1000,
|
|
171
|
-
window: 1000
|
|
172
|
-
});
|
|
173
|
-
} catch (error) {
|
|
174
|
-
console.error("Failed to connect to the browser");
|
|
175
|
-
process.exit(128 + 9);
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
console.log(e);
|
|
181
|
-
throw new Error("failed to connect to the browser");
|
|
182
|
-
}
|
|
183
|
-
const context = browser.contexts()[0];
|
|
184
|
-
return {
|
|
185
|
-
browser,
|
|
186
|
-
context
|
|
187
|
-
};
|
|
188
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface RequestMoreInfoReturnTypeBase {
|
|
2
|
-
[REQUEST_MORE_INFO_KEY]: true;
|
|
3
|
-
action: "request_more_info";
|
|
4
|
-
}
|
|
5
|
-
interface RequestMultipleChoiceReturnType extends RequestMoreInfoReturnTypeBase {
|
|
6
|
-
messageToUser: string;
|
|
7
|
-
choices: string[];
|
|
8
|
-
requestType: "multiple_choice";
|
|
9
|
-
}
|
|
10
|
-
interface RequestOtpReturnType extends RequestMoreInfoReturnTypeBase {
|
|
11
|
-
messageToUser: string;
|
|
12
|
-
requestType: "otp";
|
|
13
|
-
}
|
|
14
|
-
declare const REQUEST_MORE_INFO_KEY: unique symbol;
|
|
15
|
-
export declare function requestOTP(messageToUser: string): RequestOtpReturnType;
|
|
16
|
-
export declare function requestMultipleChoice(messageToUser: string, choices: string[]): RequestMultipleChoiceReturnType;
|
|
17
|
-
export type RequestMoreInfoDetails = RequestMultipleChoiceReturnType | RequestOtpReturnType;
|
|
18
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.requestMultipleChoice = requestMultipleChoice;
|
|
7
|
-
exports.requestOTP = requestOTP;
|
|
8
|
-
const REQUEST_MORE_INFO_KEY = Symbol("REQUEST_MORE_INFO");
|
|
9
|
-
function requestOTP(messageToUser) {
|
|
10
|
-
return {
|
|
11
|
-
[REQUEST_MORE_INFO_KEY]: true,
|
|
12
|
-
action: "request_more_info",
|
|
13
|
-
messageToUser,
|
|
14
|
-
requestType: "otp"
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function requestMultipleChoice(messageToUser, choices) {
|
|
18
|
-
return {
|
|
19
|
-
[REQUEST_MORE_INFO_KEY]: true,
|
|
20
|
-
action: "request_more_info",
|
|
21
|
-
messageToUser,
|
|
22
|
-
requestType: "multiple_choice",
|
|
23
|
-
choices
|
|
24
|
-
};
|
|
25
|
-
}
|