@intuned/runtime-dev 1.6.0-dev-52-10 → 1.7.0-dev-52
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 +2 -2
- package/dist/commands/api/run.js +1 -1
- package/dist/commands/cli-auth-sessions/create.js +1 -1
- package/dist/commands/cli-auth-sessions/utils.js +2 -1
- package/dist/commands/common/browserUtils.d.ts +1 -1
- package/dist/commands/common/browserUtils.js +1 -1
- package/dist/commands/common/getFirstLineNumber.js +4 -2
- package/dist/commands/deploy/utils.js +2 -1
- package/dist/commands/interface/run.js +5 -3
- package/dist/commands/run-api-cli/utils.js +6 -6
- package/dist/common/assets/browser_scripts.js +2213 -0
- package/dist/common/contextStorageStateHelpers.d.ts +1 -1
- package/dist/common/contextStorageStateHelpers.js +1 -17
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +5 -13
- package/dist/common/jwtTokenManager.js +5 -3
- package/dist/common/runApi/errors.js +5 -4
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +11 -8
- package/dist/runtime/executionHelpers.test.js +4 -3
- package/dist/runtime/extendPayload.js +1 -1
- package/package.json +3 -2
|
@@ -30,23 +30,7 @@ async function setStorageState(context, state) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
if ("sessionStorage" in state && state.sessionStorage) {
|
|
34
|
-
await context.addInitScript(storage => {
|
|
35
|
-
for (const {
|
|
36
|
-
origin,
|
|
37
|
-
sessionStorage
|
|
38
|
-
} of storage) {
|
|
39
|
-
if (window.location.origin === origin) {
|
|
40
|
-
for (const item of sessionStorage) {
|
|
41
|
-
const value = window.sessionStorage.getItem(item.name);
|
|
42
|
-
if (!value) {
|
|
43
|
-
window.sessionStorage.setItem(item.name, item.value);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, state.sessionStorage);
|
|
49
|
-
}
|
|
33
|
+
if ("sessionStorage" in state && state.sessionStorage) {}
|
|
50
34
|
await page.close();
|
|
51
35
|
}
|
|
52
36
|
async function getStorageState(context) {
|
|
@@ -7,7 +7,7 @@ exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
|
|
|
7
7
|
exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
|
|
8
8
|
exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
|
|
9
9
|
exports.loadSessionToContext = loadSessionToContext;
|
|
10
|
-
var playwright = _interopRequireWildcard(require("playwright"));
|
|
10
|
+
var playwright = _interopRequireWildcard(require("playwright-core"));
|
|
11
11
|
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
12
12
|
var fs = _fsExtra;
|
|
13
13
|
var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
|
|
@@ -46,16 +46,16 @@ async function getProductionPlaywrightConstructs({
|
|
|
46
46
|
const executablePath = playwright.chromium.executablePath();
|
|
47
47
|
const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
|
|
48
48
|
const isChrome127There = await (0, _fsExtra.exists)(chromium127Path);
|
|
49
|
-
const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome
|
|
49
|
+
const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
|
|
50
50
|
const userDataDir = await createUserDirWithPreferences();
|
|
51
51
|
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
52
52
|
headless,
|
|
53
|
-
viewport: null,
|
|
54
53
|
ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
|
|
55
54
|
proxy,
|
|
56
55
|
executablePath: isChrome127There ? chromium127Path : executablePath,
|
|
57
56
|
args: extraArgs,
|
|
58
|
-
downloadsPath
|
|
57
|
+
downloadsPath,
|
|
58
|
+
userAgent
|
|
59
59
|
});
|
|
60
60
|
context.once("close", async () => {
|
|
61
61
|
try {
|
|
@@ -76,13 +76,9 @@ async function getProductionPlaywrightConstructs({
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
79
|
-
await context.addInitScript({
|
|
80
|
-
path: assetsFile
|
|
81
|
-
});
|
|
82
79
|
let page = context.pages().at(0);
|
|
83
80
|
if (page) {
|
|
84
81
|
const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
|
|
85
|
-
await page.evaluate(scriptString);
|
|
86
82
|
} else {
|
|
87
83
|
page = await context.newPage();
|
|
88
84
|
}
|
|
@@ -104,15 +100,11 @@ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
|
|
|
104
100
|
throw new Error("no context found");
|
|
105
101
|
}
|
|
106
102
|
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
107
|
-
await context.addInitScript({
|
|
108
|
-
path: assetsFile
|
|
109
|
-
});
|
|
110
103
|
const pages = await context.pages();
|
|
111
104
|
let page = null;
|
|
112
105
|
if (pages.length > 0) {
|
|
113
106
|
page = pages[0];
|
|
114
107
|
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
115
|
-
await page.evaluate(scriptString);
|
|
116
108
|
} else {
|
|
117
109
|
page = await context.newPage();
|
|
118
110
|
}
|
|
@@ -163,7 +155,7 @@ async function loadSessionToContext({
|
|
|
163
155
|
await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
|
|
164
156
|
}
|
|
165
157
|
async function getRemotePlaywrightContext(cdpAddress) {
|
|
166
|
-
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
|
|
158
|
+
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright-core")));
|
|
167
159
|
let browser = null;
|
|
168
160
|
if (!cdpAddress) {
|
|
169
161
|
throw new Error("cdpAddress is required");
|
|
@@ -36,7 +36,8 @@ class JwtTokenManager {
|
|
|
36
36
|
return Math.max(timeToRefresh, timeWindow);
|
|
37
37
|
}
|
|
38
38
|
async scheduleTokenRefresh() {
|
|
39
|
-
|
|
39
|
+
var _process$env$RUN_ENVI;
|
|
40
|
+
if (((_process$env$RUN_ENVI = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI === void 0 ? void 0 : _process$env$RUN_ENVI.toLowerCase()) !== "authoring") return;
|
|
40
41
|
const timeToRefresh = this.timeToRefresh;
|
|
41
42
|
if (timeToRefresh === undefined) return;
|
|
42
43
|
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
@@ -50,7 +51,8 @@ class JwtTokenManager {
|
|
|
50
51
|
}, timeToRefresh);
|
|
51
52
|
}
|
|
52
53
|
async refreshToken() {
|
|
53
|
-
|
|
54
|
+
var _process$env$RUN_ENVI2;
|
|
55
|
+
if (((_process$env$RUN_ENVI2 = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI2 === void 0 ? void 0 : _process$env$RUN_ENVI2.toLowerCase()) !== "authoring") return;
|
|
54
56
|
const res = await this.fetchWithToken(this.refreshTokenPath, {
|
|
55
57
|
method: "GET"
|
|
56
58
|
});
|
|
@@ -63,7 +65,7 @@ class JwtTokenManager {
|
|
|
63
65
|
if (newToken) this._token = newToken;
|
|
64
66
|
}
|
|
65
67
|
fetchWithToken(...[input, init]) {
|
|
66
|
-
const headers = new Headers(init
|
|
68
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
67
69
|
headers.set("Authorization", `Bearer ${this.token}`);
|
|
68
70
|
return (0, _crossFetch.default)(input, {
|
|
69
71
|
...init,
|
|
@@ -22,10 +22,11 @@ const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundEr
|
|
|
22
22
|
class RunAutomationError {
|
|
23
23
|
wrapped = false;
|
|
24
24
|
get json() {
|
|
25
|
+
var _this$cause;
|
|
25
26
|
return {
|
|
26
27
|
code: this.code,
|
|
27
28
|
details: this.details,
|
|
28
|
-
cause: this.cause
|
|
29
|
+
cause: (_this$cause = this.cause) === null || _this$cause === void 0 ? void 0 : _this$cause.json
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -135,10 +136,10 @@ class AutomationError extends RunAutomationError {
|
|
|
135
136
|
};
|
|
136
137
|
}
|
|
137
138
|
this.statusCode = 500;
|
|
138
|
-
this.message = `[${error
|
|
139
|
+
this.message = `[${(error === null || error === void 0 ? void 0 : error.name) ?? error}] ${error === null || error === void 0 ? void 0 : error.message}`;
|
|
139
140
|
this.details = {
|
|
140
|
-
name: error
|
|
141
|
-
message: error
|
|
141
|
+
name: error === null || error === void 0 ? void 0 : error.name,
|
|
142
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
145
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
2
|
import { RunAutomationError } from "./errors";
|
|
3
|
-
import { Page, BrowserContext } from "playwright";
|
|
3
|
+
import { Page, BrowserContext } from "playwright-core";
|
|
4
4
|
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
|
|
5
5
|
export * from "./types";
|
|
6
6
|
export * from "./errors";
|
|
@@ -80,15 +80,17 @@ async function* runApiGenerator({
|
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
try {
|
|
83
|
-
|
|
83
|
+
var _context;
|
|
84
|
+
await ((_context = context) === null || _context === void 0 ? void 0 : _context.tracing.stop({
|
|
84
85
|
path: tracing.filePath
|
|
85
|
-
});
|
|
86
|
+
}));
|
|
86
87
|
} catch (error) {
|
|
87
|
-
console.log(errorMessage, error
|
|
88
|
+
console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
|
|
88
89
|
await (0, _fsExtra.remove)(tracing.filePath);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
async function* runAutomation() {
|
|
93
|
+
var _getExecutionContext;
|
|
92
94
|
let page;
|
|
93
95
|
const validatedModuleResult = await importUsingImportFunction(automationFunction.name, importFunction);
|
|
94
96
|
if (validatedModuleResult.isErr()) {
|
|
@@ -96,7 +98,7 @@ async function* runApiGenerator({
|
|
|
96
98
|
}
|
|
97
99
|
const importedModule = validatedModuleResult.value;
|
|
98
100
|
let checkFn;
|
|
99
|
-
if (auth
|
|
101
|
+
if (auth !== null && auth !== void 0 && auth.runCheck) {
|
|
100
102
|
if (!auth.session) {
|
|
101
103
|
return (0, _neverthrow.err)(new _errors.AuthRequiredError());
|
|
102
104
|
}
|
|
@@ -128,7 +130,7 @@ async function* runApiGenerator({
|
|
|
128
130
|
headless,
|
|
129
131
|
proxy,
|
|
130
132
|
downloadsPath,
|
|
131
|
-
storageState: auth
|
|
133
|
+
storageState: auth === null || auth === void 0 ? void 0 : auth.session
|
|
132
134
|
}));
|
|
133
135
|
} else {
|
|
134
136
|
const {
|
|
@@ -138,7 +140,7 @@ async function* runApiGenerator({
|
|
|
138
140
|
({
|
|
139
141
|
page,
|
|
140
142
|
context
|
|
141
|
-
} = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth
|
|
143
|
+
} = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
|
|
142
144
|
}
|
|
143
145
|
if (tracing.enabled) {
|
|
144
146
|
await context.tracing.start({
|
|
@@ -183,7 +185,7 @@ async function* runApiGenerator({
|
|
|
183
185
|
}
|
|
184
186
|
return (0, _neverthrow.ok)({
|
|
185
187
|
result,
|
|
186
|
-
extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()
|
|
188
|
+
extendedPayloads: (_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
|
|
187
189
|
session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
|
|
188
190
|
});
|
|
189
191
|
}
|
|
@@ -204,10 +206,11 @@ async function* runApiGenerator({
|
|
|
204
206
|
} catch (error) {
|
|
205
207
|
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
206
208
|
} finally {
|
|
209
|
+
var _context2;
|
|
207
210
|
await saveTraceIfNeeded({
|
|
208
211
|
errorMessage: "failed to save trace"
|
|
209
212
|
});
|
|
210
|
-
await context
|
|
213
|
+
await ((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2.close());
|
|
211
214
|
if (downloadsPath !== undefined) {
|
|
212
215
|
await fs.remove(downloadsPath);
|
|
213
216
|
}
|
|
@@ -24,12 +24,13 @@ var _enums = require("./enums");
|
|
|
24
24
|
runId: "test-run-id",
|
|
25
25
|
extendedPayloads: []
|
|
26
26
|
}, () => {
|
|
27
|
-
|
|
27
|
+
var _getExecutionContext, _getExecutionContext2;
|
|
28
|
+
(0, _vitest.expect)((_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
|
|
28
29
|
(0, _.extendPayload)({
|
|
29
30
|
api: "test-api",
|
|
30
31
|
parameters: {}
|
|
31
32
|
});
|
|
32
|
-
(0, _vitest.expect)((0, _asyncLocalStorage.getExecutionContext)()
|
|
33
|
+
(0, _vitest.expect)((_getExecutionContext2 = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
|
|
33
34
|
api: "test-api",
|
|
34
35
|
parameters: {}
|
|
35
36
|
}]);
|
|
@@ -46,7 +47,7 @@ var _enums = require("./enums");
|
|
|
46
47
|
parameters: {}
|
|
47
48
|
});
|
|
48
49
|
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
49
|
-
(0, _vitest.expect)(context
|
|
50
|
+
(0, _vitest.expect)(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
|
|
50
51
|
});
|
|
51
52
|
});
|
|
52
53
|
});
|
|
@@ -16,6 +16,6 @@ function extendPayload(payload) {
|
|
|
16
16
|
context.extendedPayloads = [...items];
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
context
|
|
19
|
+
context === null || context === void 0 || context.extendedPayloads.push(...items);
|
|
20
20
|
(0, _extendTimeout.extendTimeout)();
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-dev-52",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"vitest": "^1.1.3"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
|
-
"playwright": "*"
|
|
133
|
+
"playwright": "*",
|
|
134
|
+
"playwright-core": "*"
|
|
134
135
|
}
|
|
135
136
|
}
|