@intuned/runtime-dev 0.0.1-split.0 → 0.0.1-split.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/WebTemplate/controllers/authSessions/create.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +1 -3
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +135 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +26 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +42 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +75 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +80 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +58 -0
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/getDefaultExportFromFile.js +19 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +103 -0
- package/{src/commands/common/getFirstLineNumber.test.ts → dist/commands/common/getFirstLineNumber.test.js} +75 -121
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +33 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +28 -0
- package/dist/commands/common/utils/webTemplate.d.ts +1 -0
- package/dist/commands/common/utils/webTemplate.js +31 -0
- package/dist/commands/testing/saveVisibleHtml.d.ts +1 -0
- package/dist/commands/testing/saveVisibleHtml.js +24 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +54 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/{src/common/Logger/Logger/types.ts → dist/common/Logger/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/{src/common/Logger/types.ts → dist/common/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +16 -0
- package/dist/common/asyncLocalStorage/index.js +17 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
- package/dist/common/cleanEnvironmentVariables.js +16 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -0
- package/dist/common/contextStorageStateHelpers.d.ts +15 -0
- package/dist/common/contextStorageStateHelpers.js +48 -0
- package/dist/common/getPlaywrightConstructs.d.ts +28 -0
- package/dist/common/getPlaywrightConstructs.js +175 -0
- package/dist/common/jwtTokenManager.d.ts +16 -0
- package/dist/common/jwtTokenManager.js +81 -0
- package/dist/common/settingsSchema.d.ts +19 -0
- package/dist/common/settingsSchema.js +17 -0
- package/dist/common/telemetry.d.ts +3 -0
- package/dist/common/telemetry.js +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -0
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +26 -0
- package/{src/runtime/index.ts → dist/runtime/index.d.ts} +1 -3
- package/dist/runtime/index.js +53 -0
- package/dist/runtime/requestMoreInfo.d.ts +17 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/package.json +1 -1
- package/.vscode/extensions.json +0 -3
- package/.vscode/launch.json +0 -102
- package/.vscode/settings.json +0 -12
- package/playwright.config.ts +0 -48
- package/src/commands/api/run.ts +0 -225
- package/src/commands/auth-sessions/load.ts +0 -42
- package/src/commands/auth-sessions/run-check.ts +0 -70
- package/src/commands/auth-sessions/run-create.ts +0 -124
- package/src/commands/browser/save-state.ts +0 -22
- package/src/commands/browser/start-browser.ts +0 -17
- package/src/commands/build.ts +0 -125
- package/src/commands/common/browserUtils.ts +0 -80
- package/src/commands/common/getDefaultExportFromFile.ts +0 -13
- package/src/commands/common/getFirstLineNumber.ts +0 -146
- package/src/commands/common/sendMessageToClient.ts +0 -8
- package/src/commands/common/utils/fileUtils.ts +0 -25
- package/src/commands/common/utils/settings.ts +0 -23
- package/src/commands/common/utils/webTemplate.ts +0 -46
- package/src/commands/testing/saveVisibleHtml.ts +0 -29
- package/src/commands/ts-check.ts +0 -88
- package/src/common/Logger/Logger/index.ts +0 -64
- package/src/common/Logger/index.ts +0 -64
- package/src/common/asyncLocalStorage/index.ts +0 -29
- package/src/common/cleanEnvironmentVariables.ts +0 -13
- package/src/common/constants.ts +0 -1
- package/src/common/contextStorageStateHelpers.ts +0 -71
- package/src/common/getPlaywrightConstructs.ts +0 -283
- package/src/common/jwtTokenManager.ts +0 -111
- package/src/common/settingsSchema.ts +0 -16
- package/src/common/telemetry.ts +0 -49
- package/src/index.ts +0 -14
- package/src/runtime/RunError.ts +0 -16
- package/src/runtime/downloadDirectory.ts +0 -14
- package/src/runtime/enums.ts +0 -11
- package/src/runtime/executionHelpers.test.ts +0 -70
- package/src/runtime/extendPayload.ts +0 -22
- package/src/runtime/extendTimeout.ts +0 -32
- package/src/runtime/requestMoreInfo.ts +0 -40
- package/src/runtime/runInfo.ts +0 -19
- package/vite.config.ts +0 -17
- /package/{src → dist}/common/assets/browser_scripts.js +0 -0
- /package/{src → dist}/runtime/enums.d.ts +0 -0
- /package/{src → dist}/runtime/export.d.ts +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
var _nodeUtil = require("node:util");
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const format = _nodeUtil.formatWithOptions.bind(undefined, {
|
|
11
|
+
colors: true
|
|
12
|
+
});
|
|
13
|
+
const LOG_LEVEL_COLORS = {
|
|
14
|
+
TRACE: _chalk.default.gray,
|
|
15
|
+
DEBUG: _chalk.default.blue,
|
|
16
|
+
INFO: _chalk.default.green,
|
|
17
|
+
WARN: _chalk.default.yellow,
|
|
18
|
+
ERROR: _chalk.default.red
|
|
19
|
+
};
|
|
20
|
+
class Logger {
|
|
21
|
+
logFunction(entry) {
|
|
22
|
+
const {
|
|
23
|
+
level,
|
|
24
|
+
timestamp,
|
|
25
|
+
message,
|
|
26
|
+
meta
|
|
27
|
+
} = entry;
|
|
28
|
+
const date = new Date(timestamp);
|
|
29
|
+
const levelColor = LOG_LEVEL_COLORS[level];
|
|
30
|
+
if (meta === undefined) {
|
|
31
|
+
process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
|
|
32
|
+
} else {
|
|
33
|
+
process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
log(level, message, meta) {
|
|
37
|
+
this.logFunction({
|
|
38
|
+
level,
|
|
39
|
+
message,
|
|
40
|
+
meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
|
|
41
|
+
timestamp: Date.now()
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
trace(message, meta) {
|
|
45
|
+
this.log("TRACE", message, meta);
|
|
46
|
+
}
|
|
47
|
+
debug(message, meta) {
|
|
48
|
+
this.log("DEBUG", message, meta);
|
|
49
|
+
}
|
|
50
|
+
info(message, meta) {
|
|
51
|
+
this.log("INFO", message, meta);
|
|
52
|
+
}
|
|
53
|
+
warn(message, meta) {
|
|
54
|
+
this.log("WARN", message, meta);
|
|
55
|
+
}
|
|
56
|
+
error(message, meta) {
|
|
57
|
+
this.log("ERROR", message, meta);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const logger = exports.logger = new Logger();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
2
2
|
export type LogMetadata = Record<string | symbol, any>;
|
|
3
|
-
|
|
4
3
|
export interface LogEntry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
meta?: LogMetadata;
|
|
9
8
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LogEntry, LogMetadata } from "./types";
|
|
2
|
+
declare class Logger {
|
|
3
|
+
logFunction(entry: LogEntry): void;
|
|
4
|
+
private log;
|
|
5
|
+
trace(message: string, meta?: LogMetadata): void;
|
|
6
|
+
debug(message: string, meta?: LogMetadata): void;
|
|
7
|
+
info(message: string, meta?: LogMetadata): void;
|
|
8
|
+
warn(message: string, meta?: LogMetadata): void;
|
|
9
|
+
error(message: string, meta?: LogMetadata): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const logger: Logger;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
var _nodeUtil = require("node:util");
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const format = _nodeUtil.formatWithOptions.bind(undefined, {
|
|
11
|
+
colors: true
|
|
12
|
+
});
|
|
13
|
+
const LOG_LEVEL_COLORS = {
|
|
14
|
+
TRACE: _chalk.default.gray,
|
|
15
|
+
DEBUG: _chalk.default.blue,
|
|
16
|
+
INFO: _chalk.default.green,
|
|
17
|
+
WARN: _chalk.default.yellow,
|
|
18
|
+
ERROR: _chalk.default.red
|
|
19
|
+
};
|
|
20
|
+
class Logger {
|
|
21
|
+
logFunction(entry) {
|
|
22
|
+
const {
|
|
23
|
+
level,
|
|
24
|
+
timestamp,
|
|
25
|
+
message,
|
|
26
|
+
meta
|
|
27
|
+
} = entry;
|
|
28
|
+
const date = new Date(timestamp);
|
|
29
|
+
const levelColor = LOG_LEVEL_COLORS[level];
|
|
30
|
+
if (meta === undefined) {
|
|
31
|
+
process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
|
|
32
|
+
} else {
|
|
33
|
+
process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
log(level, message, meta) {
|
|
37
|
+
this.logFunction({
|
|
38
|
+
level,
|
|
39
|
+
message,
|
|
40
|
+
meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
|
|
41
|
+
timestamp: Date.now()
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
trace(message, meta) {
|
|
45
|
+
this.log("TRACE", message, meta);
|
|
46
|
+
}
|
|
47
|
+
debug(message, meta) {
|
|
48
|
+
this.log("DEBUG", message, meta);
|
|
49
|
+
}
|
|
50
|
+
info(message, meta) {
|
|
51
|
+
this.log("INFO", message, meta);
|
|
52
|
+
}
|
|
53
|
+
warn(message, meta) {
|
|
54
|
+
this.log("WARN", message, meta);
|
|
55
|
+
}
|
|
56
|
+
error(message, meta) {
|
|
57
|
+
this.log("ERROR", message, meta);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const logger = exports.logger = new Logger();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
2
2
|
export type LogMetadata = Record<string | symbol, any>;
|
|
3
|
-
|
|
4
3
|
export interface LogEntry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
meta?: LogMetadata;
|
|
9
8
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
import { Payload, RunInfo } from "../../runtime/export";
|
|
4
|
+
export declare const asyncLocalStorage: AsyncLocalStorage<InternalRunInfo>;
|
|
5
|
+
export declare function runWithContext<R, TArgs extends any[]>(contextData: InternalRunInfo, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
|
6
|
+
interface TimeoutInfo {
|
|
7
|
+
extendTimeoutCallback?: () => Promise<void>;
|
|
8
|
+
timeoutDuration?: number;
|
|
9
|
+
timeoutTimestamp?: number;
|
|
10
|
+
}
|
|
11
|
+
interface InternalRunInfo extends RunInfo {
|
|
12
|
+
extendedPayloads: Payload[];
|
|
13
|
+
timeoutInfo?: TimeoutInfo;
|
|
14
|
+
}
|
|
15
|
+
export declare function getExecutionContext(): InternalRunInfo | undefined;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.asyncLocalStorage = void 0;
|
|
7
|
+
exports.getExecutionContext = getExecutionContext;
|
|
8
|
+
exports.runWithContext = runWithContext;
|
|
9
|
+
var _async_hooks = require("async_hooks");
|
|
10
|
+
const asyncLocalStorage = exports.asyncLocalStorage = new _async_hooks.AsyncLocalStorage();
|
|
11
|
+
function runWithContext(contextData, callback, ...args) {
|
|
12
|
+
return asyncLocalStorage.run(contextData, callback, ...args);
|
|
13
|
+
}
|
|
14
|
+
function getExecutionContext() {
|
|
15
|
+
const contextData = asyncLocalStorage.getStore();
|
|
16
|
+
return contextData;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cleanEnvironmentVariables(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cleanEnvironmentVariables = cleanEnvironmentVariables;
|
|
7
|
+
function cleanEnvironmentVariables() {
|
|
8
|
+
Object.keys(process.env).filter(i => {
|
|
9
|
+
if (i.toLocaleLowerCase().startsWith("npm")) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}).forEach(i => delete process.env[i]);
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BrowserContext } from "@intuned/playwright";
|
|
2
|
+
import * as playwright from "@intuned/playwright-core";
|
|
3
|
+
interface OriginSessionStorage {
|
|
4
|
+
origin: string;
|
|
5
|
+
sessionStorage: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export type IntunedStorageState = Exclude<playwright.BrowserContextOptions["storageState"], string> & {
|
|
11
|
+
sessionStorage?: OriginSessionStorage[];
|
|
12
|
+
};
|
|
13
|
+
export declare function getContextStorageState(context: BrowserContext): Promise<IntunedStorageState>;
|
|
14
|
+
export declare function setContextStorageState(context: BrowserContext, storage: IntunedStorageState): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getContextStorageState = getContextStorageState;
|
|
7
|
+
exports.setContextStorageState = setContextStorageState;
|
|
8
|
+
function sessionStorageToArray(storage) {
|
|
9
|
+
const result = [];
|
|
10
|
+
for (const key in storage) {
|
|
11
|
+
result.push({
|
|
12
|
+
name: key,
|
|
13
|
+
value: storage[key]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
async function getContextStorageState(context) {
|
|
19
|
+
const cookiesAndLocalStorage = await context.storageState();
|
|
20
|
+
const pages = await context.pages();
|
|
21
|
+
const pagesSessions = [];
|
|
22
|
+
for (const page of pages) {
|
|
23
|
+
const [origin, session] = await page.evaluate(() => [location.origin, sessionStorage]);
|
|
24
|
+
const transformed = sessionStorageToArray(session);
|
|
25
|
+
pagesSessions.push({
|
|
26
|
+
origin,
|
|
27
|
+
sessionStorage: transformed
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...cookiesAndLocalStorage,
|
|
32
|
+
sessionStorage: pagesSessions
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function setContextStorageState(context, storage) {
|
|
36
|
+
await context.intunedSetStorageState(storage);
|
|
37
|
+
const sessionStorage = storage.sessionStorage;
|
|
38
|
+
await context.addInitScript(storage => {
|
|
39
|
+
for (const {
|
|
40
|
+
origin,
|
|
41
|
+
sessionStorage
|
|
42
|
+
} of storage) {
|
|
43
|
+
if (window.location.origin === origin) {
|
|
44
|
+
for (const item of sessionStorage) window.sessionStorage.setItem(item.name, item.value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, sessionStorage);
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as playwright from "@intuned/playwright-core";
|
|
2
|
+
import { IntunedStorageState } from "./contextStorageStateHelpers";
|
|
3
|
+
interface Proxy {
|
|
4
|
+
server: string;
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
interface GetPlaywrightConstructsOptions {
|
|
9
|
+
proxy?: Proxy;
|
|
10
|
+
headless?: boolean;
|
|
11
|
+
storageState?: IntunedStorageState;
|
|
12
|
+
downloadsPath: string;
|
|
13
|
+
userDataDir?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, }: GetPlaywrightConstructsOptions): Promise<{
|
|
16
|
+
page: playwright.Page;
|
|
17
|
+
context: playwright.BrowserContext;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSessionPath?: string): Promise<{
|
|
20
|
+
page: playwright.Page;
|
|
21
|
+
context: playwright.BrowserContext;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function loadAuthSessionToContext(context: playwright.BrowserContext, authSessionPath: string): Promise<void>;
|
|
24
|
+
export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
|
|
25
|
+
browser: playwright.Browser;
|
|
26
|
+
context: playwright.BrowserContext;
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
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.loadAuthSessionToContext = loadAuthSessionToContext;
|
|
10
|
+
var playwright = _interopRequireWildcard(require("@intuned/playwright-core"));
|
|
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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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 && Object.prototype.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 executablePath = playwright.chromium.executablePath();
|
|
47
|
+
const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
|
|
48
|
+
const isChrome127There = (0, _fsExtra.existsSync)(chromium127Path);
|
|
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
|
+
const userDataDir = await createUserDirWithPreferences();
|
|
51
|
+
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
52
|
+
headless,
|
|
53
|
+
ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
|
|
54
|
+
proxy,
|
|
55
|
+
executablePath: isChrome127There ? chromium127Path : executablePath,
|
|
56
|
+
args: extraArgs,
|
|
57
|
+
downloadsPath,
|
|
58
|
+
userAgent
|
|
59
|
+
});
|
|
60
|
+
context.once("close", async () => {
|
|
61
|
+
try {
|
|
62
|
+
await (0, _fsExtra.rm)(userDataDir, {
|
|
63
|
+
recursive: true,
|
|
64
|
+
force: true,
|
|
65
|
+
retryDelay: 1000,
|
|
66
|
+
maxRetries: 5
|
|
67
|
+
});
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error("Failed to remove user data dir", error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (storageState) {
|
|
73
|
+
await (0, _contextStorageStateHelpers.setContextStorageState)(context, storageState);
|
|
74
|
+
}
|
|
75
|
+
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
76
|
+
await context.addInitScript({
|
|
77
|
+
path: assetsFile
|
|
78
|
+
});
|
|
79
|
+
let page = context.pages().at(0);
|
|
80
|
+
if (page) {
|
|
81
|
+
const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
|
|
82
|
+
await page.evaluate(scriptString);
|
|
83
|
+
} else {
|
|
84
|
+
page = await context.newPage();
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
page,
|
|
88
|
+
context
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
|
|
92
|
+
async function getPlaywrightConstructsForMode(mode, cdpAddress, authSessionPath) {
|
|
93
|
+
if (mode == "playwright-standalone") {
|
|
94
|
+
if (!cdpAddress) {
|
|
95
|
+
throw new Error("cdpAddress is required");
|
|
96
|
+
}
|
|
97
|
+
const {
|
|
98
|
+
context
|
|
99
|
+
} = await getRemotePlaywrightContext(cdpAddress);
|
|
100
|
+
if (!context) {
|
|
101
|
+
throw new Error("no context found");
|
|
102
|
+
}
|
|
103
|
+
const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
104
|
+
await context.addInitScript({
|
|
105
|
+
path: assetsFile
|
|
106
|
+
});
|
|
107
|
+
const pages = await context.pages();
|
|
108
|
+
let page = null;
|
|
109
|
+
if (pages.length > 0) {
|
|
110
|
+
page = pages[0];
|
|
111
|
+
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
112
|
+
await page.evaluate(scriptString);
|
|
113
|
+
} else {
|
|
114
|
+
page = await context.newPage();
|
|
115
|
+
}
|
|
116
|
+
if (authSessionPath) {
|
|
117
|
+
await loadAuthSessionToContext(context, authSessionPath);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
page,
|
|
121
|
+
context
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
|
|
125
|
+
if (mode === "playwright" || mode === "playwright-headless") {
|
|
126
|
+
const productionConstructs = await getProductionPlaywrightConstructs({
|
|
127
|
+
headless: mode === "playwright-headless",
|
|
128
|
+
downloadsPath
|
|
129
|
+
});
|
|
130
|
+
if (authSessionPath) {
|
|
131
|
+
await loadAuthSessionToContext(productionConstructs.context, authSessionPath);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
...productionConstructs
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
throw "invalid mode";
|
|
138
|
+
}
|
|
139
|
+
async function loadAuthSessionToContext(context, authSessionPath) {
|
|
140
|
+
const fullPath = (0, _fileUtils.getFullPathInProject)(authSessionPath);
|
|
141
|
+
const data = await fs.readJson(fullPath);
|
|
142
|
+
await (0, _contextStorageStateHelpers.setContextStorageState)(context, data);
|
|
143
|
+
}
|
|
144
|
+
async function getRemotePlaywrightContext(cdpAddress) {
|
|
145
|
+
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/playwright-core")));
|
|
146
|
+
let browser = null;
|
|
147
|
+
if (!cdpAddress) {
|
|
148
|
+
throw new Error("cdpAddress is required");
|
|
149
|
+
}
|
|
150
|
+
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
151
|
+
try {
|
|
152
|
+
await (0, _waitOn.default)({
|
|
153
|
+
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
154
|
+
delay: 100,
|
|
155
|
+
interval: 100,
|
|
156
|
+
timeout: 5000,
|
|
157
|
+
tcpTimeout: 1000,
|
|
158
|
+
window: 1000
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("Failed to connect to the browser");
|
|
162
|
+
process.exit(128 + 9);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.log(e);
|
|
168
|
+
throw new Error("failed to connect to the browser");
|
|
169
|
+
}
|
|
170
|
+
const context = browser.contexts()[0];
|
|
171
|
+
return {
|
|
172
|
+
browser,
|
|
173
|
+
context
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fetch from "cross-fetch";
|
|
2
|
+
declare class JwtTokenManager {
|
|
3
|
+
private _token;
|
|
4
|
+
private tokenRefreshTimeout;
|
|
5
|
+
private refreshTokenPath;
|
|
6
|
+
constructor(refreshTokenPath: string);
|
|
7
|
+
get token(): string | undefined;
|
|
8
|
+
set token(newToken: string | undefined);
|
|
9
|
+
private get timeToRefresh();
|
|
10
|
+
private scheduleTokenRefresh;
|
|
11
|
+
private refreshToken;
|
|
12
|
+
fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
|
|
13
|
+
}
|
|
14
|
+
export declare const backendFunctionsTokenManager: JwtTokenManager;
|
|
15
|
+
export declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.backendFunctionsTokenManager = void 0;
|
|
7
|
+
exports.callBackendFunctionWithToken = callBackendFunctionWithToken;
|
|
8
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
9
|
+
var jwt = _interopRequireWildcard(require("jsonwebtoken"));
|
|
10
|
+
var _neverthrow = require("neverthrow");
|
|
11
|
+
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); }
|
|
12
|
+
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 && Object.prototype.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; }
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
class JwtTokenManager {
|
|
15
|
+
constructor(refreshTokenPath) {
|
|
16
|
+
this.refreshTokenPath = refreshTokenPath;
|
|
17
|
+
this._token = undefined;
|
|
18
|
+
}
|
|
19
|
+
get token() {
|
|
20
|
+
return this._token;
|
|
21
|
+
}
|
|
22
|
+
set token(newToken) {
|
|
23
|
+
if (this._token != newToken) {
|
|
24
|
+
this._token = newToken;
|
|
25
|
+
void this.scheduleTokenRefresh();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
get timeToRefresh() {
|
|
29
|
+
if (!this._token) return;
|
|
30
|
+
const payload = jwt.decode(this._token);
|
|
31
|
+
if (!payload || typeof payload == "string") return;
|
|
32
|
+
const expiry = payload.expiry;
|
|
33
|
+
if (!expiry || typeof expiry !== "number") return;
|
|
34
|
+
const timeWindow = 60 * 1000;
|
|
35
|
+
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
36
|
+
return Math.max(timeToRefresh, timeWindow);
|
|
37
|
+
}
|
|
38
|
+
async scheduleTokenRefresh() {
|
|
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;
|
|
41
|
+
const timeToRefresh = this.timeToRefresh;
|
|
42
|
+
if (timeToRefresh === undefined) return;
|
|
43
|
+
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
44
|
+
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
45
|
+
const result = await this.refreshToken();
|
|
46
|
+
if (result && result.isErr()) {
|
|
47
|
+
console.error(`[Internal Error] ${result.error}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await this.scheduleTokenRefresh();
|
|
51
|
+
}, timeToRefresh);
|
|
52
|
+
}
|
|
53
|
+
async refreshToken() {
|
|
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;
|
|
56
|
+
const res = await this.fetchWithToken(this.refreshTokenPath, {
|
|
57
|
+
method: "GET"
|
|
58
|
+
});
|
|
59
|
+
if (res.status === 401) {
|
|
60
|
+
return (0, _neverthrow.err)("Unauthorized");
|
|
61
|
+
}
|
|
62
|
+
const jsonResult = await _neverthrow.ResultAsync.fromPromise(res.json(), () => "not json");
|
|
63
|
+
if (jsonResult.isErr()) return;
|
|
64
|
+
const newToken = jsonResult.value.token;
|
|
65
|
+
if (newToken) this._token = newToken;
|
|
66
|
+
}
|
|
67
|
+
fetchWithToken(...[input, init]) {
|
|
68
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
69
|
+
headers.set("Authorization", `Bearer ${this.token}`);
|
|
70
|
+
return (0, _crossFetch.default)(input, {
|
|
71
|
+
...init,
|
|
72
|
+
headers
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const backendFunctionsPath = `${process.env.FUNCTIONS_DOMAIN}/api/${process.env.INTUNED_WORKSPACE_ID}/functions/${process.env.INTUNED_INTEGRATION_ID}`;
|
|
77
|
+
const backendFunctionsTokenManager = exports.backendFunctionsTokenManager = new JwtTokenManager(`${backendFunctionsPath}/refreshBackendFunctionsToken`);
|
|
78
|
+
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
79
|
+
function callBackendFunctionWithToken(path, init) {
|
|
80
|
+
return backendFunctionsTokenManager.fetchWithToken(`${backendFunctionsPath}/${path}`, init);
|
|
81
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const settingsSchema: z.ZodObject<{
|
|
3
|
+
authSessions: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
4
|
+
enabled: z.ZodBoolean;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
}, {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
}>>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
authSessions: {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
};
|
|
14
|
+
}, {
|
|
15
|
+
authSessions?: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export type IntunedSettings = z.infer<typeof settingsSchema>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.settingsSchema = void 0;
|
|
7
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
+
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); }
|
|
9
|
+
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 && Object.prototype.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; }
|
|
10
|
+
const authSessionsSchema = z.object({
|
|
11
|
+
enabled: z.boolean()
|
|
12
|
+
}).optional().default({
|
|
13
|
+
enabled: false
|
|
14
|
+
});
|
|
15
|
+
const settingsSchema = exports.settingsSchema = z.object({
|
|
16
|
+
authSessions: authSessionsSchema
|
|
17
|
+
});
|