@intuned/runtime-dev 1.3.22-dev.6 → 1.3.24-auth-issue.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/.claude/settings.local.json +7 -0
- package/dist/common/binStartupScript.js +1 -40
- package/dist/common/intunedJson.d.ts +42 -12
- package/dist/common/intunedJson.js +19 -9
- package/dist/common/jwtTokenManager.js +1 -0
- package/dist/common/launchBrowser.d.ts +0 -1
- package/dist/common/launchBrowser.js +9 -3
- package/dist/common/playwrightContext.d.ts +0 -1
- package/dist/common/playwrightContext.js +2 -4
- package/dist/common/runApi/index.js +0 -1
- package/dist/runtime/getAiGatewayConfig.js +1 -1
- package/dist/vendor/runtime-interface.js +74 -27
- package/package.json +1 -1
- package/test +2 -0
|
@@ -1,46 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
4
|
-
var path = _interopRequireWildcard(require("path"));
|
|
5
|
-
var _intunedJson = require("./intunedJson");
|
|
6
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
7
4
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
5
|
_dotenv.default.config({
|
|
9
6
|
path: `.env`
|
|
10
|
-
});
|
|
11
|
-
function getStealthModeConfig() {
|
|
12
|
-
try {
|
|
13
|
-
const settingsResult = (0, _intunedJson.loadIntunedJsonSync)();
|
|
14
|
-
if (settingsResult.isErr()) {
|
|
15
|
-
console.error(`Warning: Failed to load Intuned settings: ${settingsResult.error}
|
|
16
|
-
Stealth mode will not be enabled.`);
|
|
17
|
-
return {
|
|
18
|
-
enabled: false,
|
|
19
|
-
type: "patchright"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
enabled: settingsResult.value.stealthMode?.enabled === true,
|
|
24
|
-
type: settingsResult.value.stealthMode?.type || "patchright"
|
|
25
|
-
};
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error("Error reading Intuned.json:", error.message);
|
|
28
|
-
return {
|
|
29
|
-
enabled: false,
|
|
30
|
-
type: "patchright"
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
const stealthConfig = getStealthModeConfig();
|
|
36
|
-
if (stealthConfig.enabled && stealthConfig.type === "patchright") {
|
|
37
|
-
const currentNodeModules = path.resolve(process.cwd(), "node_modules");
|
|
38
|
-
process.env.NODE_PATH = process.env.NODE_PATH ? `${process.env.NODE_PATH}:${currentNodeModules}` : currentNodeModules;
|
|
39
|
-
require("module").Module._initPaths();
|
|
40
|
-
if (process.env.PLAYWRIGHT_PATCH_SCRIPT_PATH) {
|
|
41
|
-
require(process.env.PLAYWRIGHT_PATCH_SCRIPT_PATH);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} catch (e) {
|
|
45
|
-
console.error("Failed to apply stealth mode");
|
|
46
|
-
}
|
|
7
|
+
});
|
|
@@ -16,15 +16,22 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
16
16
|
defaultRunPlaygroundInput?: unknown;
|
|
17
17
|
testAuthSessionInput?: unknown;
|
|
18
18
|
}>>>;
|
|
19
|
+
browserSize: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
20
|
+
width: z.ZodNumber;
|
|
21
|
+
height: z.ZodNumber;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}, {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}>>>;
|
|
19
29
|
stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
20
30
|
enabled: z.ZodBoolean;
|
|
21
|
-
type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["intunedBrowser", "patchright"]>>>;
|
|
22
31
|
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
type: "intunedBrowser" | "patchright";
|
|
24
32
|
enabled: boolean;
|
|
25
33
|
}, {
|
|
26
34
|
enabled: boolean;
|
|
27
|
-
type?: "intunedBrowser" | "patchright" | undefined;
|
|
28
35
|
}>>>;
|
|
29
36
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
30
37
|
projectName: z.ZodOptional<z.ZodString>;
|
|
@@ -42,15 +49,22 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
42
49
|
defaultRunPlaygroundInput?: unknown;
|
|
43
50
|
testAuthSessionInput?: unknown;
|
|
44
51
|
}>>>;
|
|
52
|
+
browserSize: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
53
|
+
width: z.ZodNumber;
|
|
54
|
+
height: z.ZodNumber;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
}, {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
}>>>;
|
|
45
62
|
stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
46
63
|
enabled: z.ZodBoolean;
|
|
47
|
-
type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["intunedBrowser", "patchright"]>>>;
|
|
48
64
|
}, "strip", z.ZodTypeAny, {
|
|
49
|
-
type: "intunedBrowser" | "patchright";
|
|
50
65
|
enabled: boolean;
|
|
51
66
|
}, {
|
|
52
67
|
enabled: boolean;
|
|
53
|
-
type?: "intunedBrowser" | "patchright" | undefined;
|
|
54
68
|
}>>>;
|
|
55
69
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
56
70
|
projectName: z.ZodOptional<z.ZodString>;
|
|
@@ -68,15 +82,22 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
68
82
|
defaultRunPlaygroundInput?: unknown;
|
|
69
83
|
testAuthSessionInput?: unknown;
|
|
70
84
|
}>>>;
|
|
85
|
+
browserSize: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
86
|
+
width: z.ZodNumber;
|
|
87
|
+
height: z.ZodNumber;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
}, {
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
}>>>;
|
|
71
95
|
stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
72
96
|
enabled: z.ZodBoolean;
|
|
73
|
-
type: z.ZodDefault<z.ZodOptional<z.ZodEnum<["intunedBrowser", "patchright"]>>>;
|
|
74
97
|
}, "strip", z.ZodTypeAny, {
|
|
75
|
-
type: "intunedBrowser" | "patchright";
|
|
76
98
|
enabled: boolean;
|
|
77
99
|
}, {
|
|
78
100
|
enabled: boolean;
|
|
79
|
-
type?: "intunedBrowser" | "patchright" | undefined;
|
|
80
101
|
}>>>;
|
|
81
102
|
}, z.ZodTypeAny, "passthrough">>, z.ZodUnion<[z.ZodObject<{
|
|
82
103
|
authSessions: z.ZodObject<{
|
|
@@ -166,7 +187,6 @@ export type IntunedJson = z.infer<typeof intunedJsonSchema>;
|
|
|
166
187
|
export declare const intunedSettingsFileNames: readonly ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
|
|
167
188
|
export declare function loadIntunedJson(): Promise<Err<never, string> | Ok<{
|
|
168
189
|
stealthMode?: {
|
|
169
|
-
type: "intunedBrowser" | "patchright";
|
|
170
190
|
enabled: boolean;
|
|
171
191
|
} | undefined;
|
|
172
192
|
workspaceId?: string | undefined;
|
|
@@ -176,6 +196,10 @@ export declare function loadIntunedJson(): Promise<Err<never, string> | Ok<{
|
|
|
176
196
|
defaultRunPlaygroundInput?: Record<string, any> | undefined;
|
|
177
197
|
testAuthSessionInput?: Record<string, any> | undefined;
|
|
178
198
|
} | undefined;
|
|
199
|
+
browserSize?: {
|
|
200
|
+
width: number;
|
|
201
|
+
height: number;
|
|
202
|
+
} | undefined;
|
|
179
203
|
} & {
|
|
180
204
|
[k: string]: unknown;
|
|
181
205
|
} & ({
|
|
@@ -206,7 +230,6 @@ export declare function getIntunedSettingsFile(): Promise<Ok<{
|
|
|
206
230
|
export declare function getIntunedSettingsFileName(): Promise<Err<never, string> | Ok<"Intuned.json" | "Intuned.jsonc" | "Intuned.yaml" | "Intuned.yml" | "Intuned.toml", never>>;
|
|
207
231
|
export declare function loadIntunedJsonSync(): Err<never, string> | Ok<{
|
|
208
232
|
stealthMode?: {
|
|
209
|
-
type: "intunedBrowser" | "patchright";
|
|
210
233
|
enabled: boolean;
|
|
211
234
|
} | undefined;
|
|
212
235
|
workspaceId?: string | undefined;
|
|
@@ -216,6 +239,10 @@ export declare function loadIntunedJsonSync(): Err<never, string> | Ok<{
|
|
|
216
239
|
defaultRunPlaygroundInput?: Record<string, any> | undefined;
|
|
217
240
|
testAuthSessionInput?: Record<string, any> | undefined;
|
|
218
241
|
} | undefined;
|
|
242
|
+
browserSize?: {
|
|
243
|
+
width: number;
|
|
244
|
+
height: number;
|
|
245
|
+
} | undefined;
|
|
219
246
|
} & {
|
|
220
247
|
[k: string]: unknown;
|
|
221
248
|
} & ({
|
|
@@ -238,7 +265,10 @@ export declare function loadIntunedJsonSync(): Err<never, string> | Ok<{
|
|
|
238
265
|
enabled: true;
|
|
239
266
|
};
|
|
240
267
|
}), never>;
|
|
268
|
+
export declare function getBrowserSizeConfig(): Promise<{
|
|
269
|
+
width: number;
|
|
270
|
+
height: number;
|
|
271
|
+
}>;
|
|
241
272
|
export declare function getStealthModeConfig(): Promise<{
|
|
242
273
|
enabled: boolean;
|
|
243
|
-
type: "intunedBrowser" | "patchright";
|
|
244
274
|
}>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getBrowserSizeConfig = getBrowserSizeConfig;
|
|
6
7
|
exports.getIntunedSettingsFile = getIntunedSettingsFile;
|
|
7
8
|
exports.getIntunedSettingsFileName = getIntunedSettingsFileName;
|
|
8
9
|
exports.getStealthModeConfig = getStealthModeConfig;
|
|
@@ -19,7 +20,6 @@ var _neverthrow = require("neverthrow");
|
|
|
19
20
|
var _formatZodError = require("./formatZodError");
|
|
20
21
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
21
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
-
const playwright = undefined;
|
|
23
23
|
const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
|
|
24
24
|
projectName: _zod.z.string().optional(),
|
|
25
25
|
workspaceId: _zod.z.string().optional(),
|
|
@@ -28,9 +28,12 @@ const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
|
|
|
28
28
|
defaultRunPlaygroundInput: _zod.z.record(_zod.z.any()).optional().catch(undefined),
|
|
29
29
|
testAuthSessionInput: _zod.z.record(_zod.z.any()).optional().catch(undefined)
|
|
30
30
|
}).optional().catch(undefined),
|
|
31
|
+
browserSize: _zod.z.object({
|
|
32
|
+
width: _zod.z.number().int().min(200).max(3840),
|
|
33
|
+
height: _zod.z.number().int().min(200).max(2160)
|
|
34
|
+
}).optional().catch(undefined),
|
|
31
35
|
stealthMode: _zod.z.object({
|
|
32
|
-
enabled: _zod.z.boolean()
|
|
33
|
-
type: _zod.z.enum(["intunedBrowser", "patchright"]).optional().default("patchright")
|
|
36
|
+
enabled: _zod.z.boolean()
|
|
34
37
|
}).optional().catch(undefined)
|
|
35
38
|
}).passthrough().and(_zod.z.union([_zod.z.object({
|
|
36
39
|
authSessions: _zod.z.object({
|
|
@@ -132,23 +135,30 @@ function getIntunedSettingsFileSync() {
|
|
|
132
135
|
}
|
|
133
136
|
return (0, _neverthrow.err)("No Intuned settings file found.");
|
|
134
137
|
}
|
|
138
|
+
async function getBrowserSizeConfig() {
|
|
139
|
+
const settingsResult = await loadIntunedJson();
|
|
140
|
+
if (settingsResult.isOk() && settingsResult.value.browserSize) {
|
|
141
|
+
return settingsResult.value.browserSize;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
width: 1024,
|
|
145
|
+
height: 800
|
|
146
|
+
};
|
|
147
|
+
}
|
|
135
148
|
async function getStealthModeConfig() {
|
|
136
149
|
try {
|
|
137
150
|
const settingsResult = await loadIntunedJson();
|
|
138
151
|
if (settingsResult.isErr()) {
|
|
139
152
|
return {
|
|
140
|
-
enabled: false
|
|
141
|
-
type: "patchright"
|
|
153
|
+
enabled: false
|
|
142
154
|
};
|
|
143
155
|
}
|
|
144
156
|
return {
|
|
145
|
-
enabled: settingsResult.value.stealthMode?.enabled === true
|
|
146
|
-
type: settingsResult.value.stealthMode?.type || "patchright"
|
|
157
|
+
enabled: settingsResult.value.stealthMode?.enabled === true
|
|
147
158
|
};
|
|
148
159
|
} catch {
|
|
149
160
|
return {
|
|
150
|
-
enabled: false
|
|
151
|
-
type: "patchright"
|
|
161
|
+
enabled: false
|
|
152
162
|
};
|
|
153
163
|
}
|
|
154
164
|
}
|
|
@@ -75,6 +75,7 @@ class JwtTokenManager {
|
|
|
75
75
|
if (this.token !== undefined) {
|
|
76
76
|
headers.set("Authorization", `Bearer ${this.token}`);
|
|
77
77
|
}
|
|
78
|
+
console.log(`[JwtTokenManager] Fetching ${input} with headers: ${headers}`);
|
|
78
79
|
const result = await (0, _crossFetch.default)(input, {
|
|
79
80
|
...init,
|
|
80
81
|
headers
|
|
@@ -27,7 +27,6 @@ export type LaunchChromiumStandaloneOptions = {
|
|
|
27
27
|
export type LaunchChromiumCdpOptions = {
|
|
28
28
|
cdpAddress: string;
|
|
29
29
|
cdpTargetId?: string;
|
|
30
|
-
ignoreHttpErrors?: boolean;
|
|
31
30
|
timeout?: number;
|
|
32
31
|
};
|
|
33
32
|
export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
|
|
@@ -44,6 +44,10 @@ async function createUserDirWithPreferences() {
|
|
|
44
44
|
const preferences = {
|
|
45
45
|
plugins: {
|
|
46
46
|
always_open_pdf_externally: true
|
|
47
|
+
},
|
|
48
|
+
credentials_enable_service: false,
|
|
49
|
+
profile: {
|
|
50
|
+
password_manager_enabled: false
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
@@ -108,11 +112,11 @@ async function launchChromium(options) {
|
|
|
108
112
|
} = options;
|
|
109
113
|
const ignoreHttpErrors = await getIgnoreHttpErrorsFromConfig(ignoreHttpErrorsParam);
|
|
110
114
|
const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
|
|
111
|
-
const extraArgs = [];
|
|
115
|
+
const extraArgs = ["--disable-notifications"];
|
|
112
116
|
const macKeychainBypassArgs = getMacKeychainBypassArgs();
|
|
113
117
|
extraArgs.push(...macKeychainBypassArgs);
|
|
114
118
|
const stealthConfig = await (0, _intunedJson.getStealthModeConfig)();
|
|
115
|
-
if (stealthConfig.enabled
|
|
119
|
+
if (stealthConfig.enabled) {
|
|
116
120
|
extraArgs.push("--stealth-mode");
|
|
117
121
|
}
|
|
118
122
|
const userDataDir = await createUserDirWithPreferences();
|
|
@@ -138,7 +142,7 @@ async function launchChromium(options) {
|
|
|
138
142
|
if (appModeInitialUrl) {
|
|
139
143
|
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
140
144
|
}
|
|
141
|
-
if (stealthConfig.enabled
|
|
145
|
+
if (stealthConfig.enabled) {
|
|
142
146
|
const stealthExecutablePath = await getIntunedBrowserExecutablePath();
|
|
143
147
|
executablePath = stealthExecutablePath;
|
|
144
148
|
} else if (executablePath) {
|
|
@@ -148,6 +152,8 @@ async function launchChromium(options) {
|
|
|
148
152
|
executablePath = undefined;
|
|
149
153
|
}
|
|
150
154
|
}
|
|
155
|
+
const browserSize = await (0, _intunedJson.getBrowserSizeConfig)();
|
|
156
|
+
extraArgs.push(`--window-size=${browserSize.width},${browserSize.height}`);
|
|
151
157
|
const viewport = null;
|
|
152
158
|
const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
|
|
153
159
|
executablePath,
|
|
@@ -22,7 +22,6 @@ export declare function withPlaywrightContext<R>(options: {
|
|
|
22
22
|
export declare function withPlaywrightContext<R>(options: {
|
|
23
23
|
cdpAddress: string;
|
|
24
24
|
cdpTargetId?: string;
|
|
25
|
-
ignoreHttpErrors?: boolean;
|
|
26
25
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
27
26
|
export declare function loadSessionToContext({ context, session, }: {
|
|
28
27
|
context: playwright.BrowserContext;
|
|
@@ -43,8 +43,7 @@ async function withPlaywrightContext({
|
|
|
43
43
|
context
|
|
44
44
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
45
45
|
cdpAddress,
|
|
46
|
-
cdpTargetId
|
|
47
|
-
ignoreHttpErrors
|
|
46
|
+
cdpTargetId
|
|
48
47
|
}));
|
|
49
48
|
} else {
|
|
50
49
|
({
|
|
@@ -67,8 +66,7 @@ async function withPlaywrightContext({
|
|
|
67
66
|
page
|
|
68
67
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
69
68
|
cdpAddress,
|
|
70
|
-
cdpTargetId
|
|
71
|
-
ignoreHttpErrors
|
|
69
|
+
cdpTargetId
|
|
72
70
|
}));
|
|
73
71
|
} else {
|
|
74
72
|
const port = await (0, _portfinder.getPort)({
|
|
@@ -157,7 +157,6 @@ async function runApi({
|
|
|
157
157
|
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
158
158
|
cdpAddress: runOptions.cdpAddress,
|
|
159
159
|
cdpTargetId: runOptions.cdpTargetId,
|
|
160
|
-
ignoreHttpErrors: runOptions.ignoreHttpErrors,
|
|
161
160
|
...playwrightContextParameters
|
|
162
161
|
}, runAutomationWithContext);
|
|
163
162
|
}
|
|
@@ -8,7 +8,7 @@ var _constants = require("../common/constants");
|
|
|
8
8
|
var _jwtTokenManager = require("../common/jwtTokenManager");
|
|
9
9
|
function getAiGatewayConfig() {
|
|
10
10
|
const baseUrl = `${_jwtTokenManager.backendFunctionsTokenManager.backendFunctionsBaseUrl}/intuned-ai-gateway`;
|
|
11
|
-
const apiKey = _jwtTokenManager.backendFunctionsTokenManager.token ?? process.env[_constants.API_KEY_ENV_VAR_KEY] ?? "";
|
|
11
|
+
const apiKey = _jwtTokenManager.backendFunctionsTokenManager.token ?? process.env[_constants.API_KEY_ENV_VAR_KEY] ?? process.env[_constants.AUTH_TOKEN_ENV_VAR_KEY] ?? "";
|
|
12
12
|
return {
|
|
13
13
|
baseUrl,
|
|
14
14
|
apiKey
|
|
@@ -163,7 +163,7 @@ var require_types = __commonJS({
|
|
|
163
163
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
164
164
|
};
|
|
165
165
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
166
|
-
exports2.outputRunApiSchema = exports2.pongMessageSchema = exports2.doneMessageSchema = exports2.extendMessageSchema = exports2.runApiInputSchema = exports2.pingSchema = exports2.tokenUpdateSchema = exports2.abortRunApiSchema = exports2.startRunApiSchema = exports2.startRunApiParametersSchema = exports2.runApiParametersSchema = exports2.runApiRunOptionsSchema = exports2.runApiCdpRunOptionsSchema = exports2.runApiStandaloneRunOptionsSchema = exports2.runApiAuthSchema = exports2.runApiTracingSchema = exports2.runApiAutomationFunctionSchema = exports2.runApiSessionSchema = exports2.runApiStorageStateSchema = void 0;
|
|
166
|
+
exports2.outputRunApiSchema = exports2.pongMessageSchema = exports2.doneMessageSchema = exports2.extendMessageSchema = exports2.runApiInputSchema = exports2.pingSchema = exports2.tokenUpdateSchema = exports2.abortRunApiSchema = exports2.startRunApiSchema = exports2.startRunApiParametersSchema = exports2.runApiParametersSchema = exports2.runApiRunOptionsSchema = exports2.runApiCdpRunOptionsSchema = exports2.runApiStandaloneRunOptionsSchema = exports2.runApiProxySchema = exports2.runApiAuthSchema = exports2.runApiTracingSchema = exports2.runApiAutomationFunctionSchema = exports2.runApiSessionSchema = exports2.runApiStorageStateSchema = void 0;
|
|
167
167
|
exports2.runApiResultOkSchema = runApiResultOkSchema;
|
|
168
168
|
exports2.runApiResultWithSessionOkSchema = runApiResultWithSessionOkSchema;
|
|
169
169
|
var zod_1 = __importDefault(require("zod"));
|
|
@@ -215,21 +215,21 @@ var require_types = __commonJS({
|
|
|
215
215
|
session: exports2.runApiSessionSchema,
|
|
216
216
|
parameters: zod_1.default.record(zod_1.default.any()).optional()
|
|
217
217
|
}).optional();
|
|
218
|
+
exports2.runApiProxySchema = zod_1.default.object({
|
|
219
|
+
server: zod_1.default.string(),
|
|
220
|
+
username: zod_1.default.string(),
|
|
221
|
+
password: zod_1.default.string()
|
|
222
|
+
});
|
|
218
223
|
exports2.runApiStandaloneRunOptionsSchema = zod_1.default.object({
|
|
219
224
|
environment: zod_1.default.literal("standalone"),
|
|
220
225
|
headless: zod_1.default.boolean().default(true),
|
|
221
|
-
proxy:
|
|
222
|
-
server: zod_1.default.string(),
|
|
223
|
-
username: zod_1.default.string(),
|
|
224
|
-
password: zod_1.default.string()
|
|
225
|
-
}).optional(),
|
|
226
|
+
proxy: exports2.runApiProxySchema.optional(),
|
|
226
227
|
ignoreHttpErrors: zod_1.default.boolean().optional()
|
|
227
228
|
});
|
|
228
229
|
exports2.runApiCdpRunOptionsSchema = zod_1.default.object({
|
|
229
230
|
environment: zod_1.default.literal("cdp"),
|
|
230
231
|
cdpAddress: zod_1.default.string(),
|
|
231
|
-
cdpTargetId: zod_1.default.string().optional()
|
|
232
|
-
ignoreHttpErrors: zod_1.default.boolean().optional()
|
|
232
|
+
cdpTargetId: zod_1.default.string().optional()
|
|
233
233
|
});
|
|
234
234
|
exports2.runApiRunOptionsSchema = zod_1.default.discriminatedUnion("environment", [
|
|
235
235
|
exports2.runApiStandaloneRunOptionsSchema,
|
|
@@ -354,35 +354,50 @@ var require_interfaceClient = __commonJS({
|
|
|
354
354
|
var net = __importStar(require("net"));
|
|
355
355
|
var readline_1 = require("readline");
|
|
356
356
|
var promises_1 = require("timers/promises");
|
|
357
|
+
var util_1 = require("util");
|
|
357
358
|
var SocketClient = class _SocketClient {
|
|
358
359
|
constructor(socket) {
|
|
360
|
+
this.dataListener = null;
|
|
359
361
|
this.socket = socket;
|
|
362
|
+
this.closeAbortController = new AbortController();
|
|
360
363
|
}
|
|
361
|
-
sendJSON(data) {
|
|
364
|
+
async sendJSON(data) {
|
|
365
|
+
if (this.socket.closed) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
362
368
|
const dataToSend = JSON.stringify(data);
|
|
363
369
|
const length = Buffer.byteLength(dataToSend);
|
|
364
370
|
const buffer = Buffer.alloc(_SocketClient.LENGTH_HEADER_LENGTH + length);
|
|
365
371
|
buffer.writeUInt32BE(length, 0);
|
|
366
372
|
buffer.write(dataToSend, _SocketClient.LENGTH_HEADER_LENGTH);
|
|
367
|
-
this.socket.write(buffer);
|
|
373
|
+
await (0, util_1.promisify)((cb) => this.socket.write(buffer, cb))();
|
|
368
374
|
}
|
|
369
375
|
async *receiveJSON() {
|
|
370
376
|
let buffer = Buffer.alloc(0);
|
|
377
|
+
let endListener;
|
|
378
|
+
let rejectListener;
|
|
371
379
|
const endPromise = new Promise((resolve, reject) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.socket.once("error",
|
|
380
|
+
endListener = () => resolve();
|
|
381
|
+
this.socket.once("end", endListener);
|
|
382
|
+
rejectListener = (e) => reject(e);
|
|
383
|
+
this.socket.once("error", rejectListener);
|
|
384
|
+
});
|
|
385
|
+
const closePromise = new Promise((resolve) => {
|
|
386
|
+
this.closeAbortController.signal.addEventListener("abort", () => resolve());
|
|
376
387
|
});
|
|
377
388
|
while (true) {
|
|
378
389
|
const chunk = await Promise.race([
|
|
379
|
-
new Promise((resolve) =>
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
390
|
+
new Promise((resolve) => {
|
|
391
|
+
this.dataListener = (data2) => {
|
|
392
|
+
if (typeof data2 === "string") {
|
|
393
|
+
return resolve(Buffer.from(data2));
|
|
394
|
+
}
|
|
395
|
+
resolve(data2);
|
|
396
|
+
};
|
|
397
|
+
this.socket.once("data", this.dataListener);
|
|
398
|
+
}),
|
|
399
|
+
endPromise,
|
|
400
|
+
closePromise
|
|
386
401
|
]);
|
|
387
402
|
if (!(chunk instanceof Buffer)) {
|
|
388
403
|
break;
|
|
@@ -403,13 +418,45 @@ var require_interfaceClient = __commonJS({
|
|
|
403
418
|
yield JSON.parse(data.toString());
|
|
404
419
|
}
|
|
405
420
|
}
|
|
406
|
-
async close() {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
421
|
+
async close(mode = "client") {
|
|
422
|
+
console.log(`[${process.pid}] Closing socket client`);
|
|
423
|
+
if (this.dataListener) {
|
|
424
|
+
this.socket.off("data", this.dataListener);
|
|
425
|
+
console.log(`[${process.pid}] Removed data listener`);
|
|
426
|
+
} else {
|
|
427
|
+
console.log(`[${process.pid}] No data listener to remove`);
|
|
428
|
+
}
|
|
429
|
+
this.closeAbortController.abort();
|
|
430
|
+
console.log(`[${process.pid}] Called abort on closeAbortController`);
|
|
431
|
+
if (mode === "client") {
|
|
432
|
+
console.log(`[${process.pid}] Sending FIN to socket`);
|
|
433
|
+
await (0, util_1.promisify)((cb) => this.socket.end(cb))();
|
|
434
|
+
console.log(`[${process.pid}] Waiting for socket to close gracefully for 3 seconds...`);
|
|
435
|
+
const closeResult = await Promise.race([
|
|
436
|
+
new Promise((resolve) => this.socket.once("close", () => resolve("closed"))),
|
|
437
|
+
new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
|
|
438
|
+
(0, promises_1.setTimeout)(3e3, "timeout")
|
|
439
|
+
]);
|
|
440
|
+
console.log(`[${process.pid}] Socket close result: ${closeResult}`);
|
|
441
|
+
if (closeResult === "timeout") {
|
|
442
|
+
console.warn(`[${process.pid}] Socket did not close within timeout, destroying socket`);
|
|
443
|
+
this.socket.destroy();
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
console.log(`[${process.pid}] Waiting for socket to end gracefully for 3 seconds...`);
|
|
448
|
+
const receiveEndResult = await Promise.race([
|
|
449
|
+
new Promise((resolve) => this.socket.once("end", () => resolve("end"))),
|
|
450
|
+
new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
|
|
451
|
+
(0, promises_1.setTimeout)(3e3, "timeout")
|
|
412
452
|
]);
|
|
453
|
+
console.log(`[${process.pid}] Socket receive end result: ${receiveEndResult}`);
|
|
454
|
+
if (receiveEndResult === "end") {
|
|
455
|
+
console.log(`[${process.pid}] Socket ended gracefully`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
console.log(`[${process.pid}] Socket did not end gracefully, destroying socket`);
|
|
459
|
+
this.socket.destroy();
|
|
413
460
|
}
|
|
414
461
|
get closed() {
|
|
415
462
|
return this.socket.closed;
|
package/package.json
CHANGED
package/test
ADDED