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