@intuned/runtime 1.3.11 → 1.3.12

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.
@@ -0,0 +1,229 @@
1
+ import { z } from "zod";
2
+ import { type Err, type Ok } from "neverthrow";
3
+ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
4
+ projectName: z.ZodOptional<z.ZodString>;
5
+ workspaceId: z.ZodOptional<z.ZodString>;
6
+ metadata: z.ZodCatch<z.ZodOptional<z.ZodObject<{
7
+ defaultJobInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
8
+ defaultRunPlaygroundInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
9
+ testAuthSessionInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ defaultJobInput?: Record<string, any> | undefined;
12
+ defaultRunPlaygroundInput?: Record<string, any> | undefined;
13
+ testAuthSessionInput?: Record<string, any> | undefined;
14
+ }, {
15
+ defaultJobInput?: unknown;
16
+ defaultRunPlaygroundInput?: unknown;
17
+ testAuthSessionInput?: unknown;
18
+ }>>>;
19
+ stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
20
+ enabled: z.ZodBoolean;
21
+ }, "strip", z.ZodTypeAny, {
22
+ enabled: boolean;
23
+ }, {
24
+ enabled: boolean;
25
+ }>>>;
26
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
27
+ projectName: z.ZodOptional<z.ZodString>;
28
+ workspaceId: z.ZodOptional<z.ZodString>;
29
+ metadata: z.ZodCatch<z.ZodOptional<z.ZodObject<{
30
+ defaultJobInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
31
+ defaultRunPlaygroundInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
32
+ testAuthSessionInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ defaultJobInput?: Record<string, any> | undefined;
35
+ defaultRunPlaygroundInput?: Record<string, any> | undefined;
36
+ testAuthSessionInput?: Record<string, any> | undefined;
37
+ }, {
38
+ defaultJobInput?: unknown;
39
+ defaultRunPlaygroundInput?: unknown;
40
+ testAuthSessionInput?: unknown;
41
+ }>>>;
42
+ stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
43
+ enabled: z.ZodBoolean;
44
+ }, "strip", z.ZodTypeAny, {
45
+ enabled: boolean;
46
+ }, {
47
+ enabled: boolean;
48
+ }>>>;
49
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
50
+ projectName: z.ZodOptional<z.ZodString>;
51
+ workspaceId: z.ZodOptional<z.ZodString>;
52
+ metadata: z.ZodCatch<z.ZodOptional<z.ZodObject<{
53
+ defaultJobInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
54
+ defaultRunPlaygroundInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
55
+ testAuthSessionInput: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ defaultJobInput?: Record<string, any> | undefined;
58
+ defaultRunPlaygroundInput?: Record<string, any> | undefined;
59
+ testAuthSessionInput?: Record<string, any> | undefined;
60
+ }, {
61
+ defaultJobInput?: unknown;
62
+ defaultRunPlaygroundInput?: unknown;
63
+ testAuthSessionInput?: unknown;
64
+ }>>>;
65
+ stealthMode: z.ZodCatch<z.ZodOptional<z.ZodObject<{
66
+ enabled: z.ZodBoolean;
67
+ }, "strip", z.ZodTypeAny, {
68
+ enabled: boolean;
69
+ }, {
70
+ enabled: boolean;
71
+ }>>>;
72
+ }, z.ZodTypeAny, "passthrough">>, z.ZodUnion<[z.ZodObject<{
73
+ authSessions: z.ZodObject<{
74
+ enabled: z.ZodLiteral<false>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ enabled: false;
77
+ }, {
78
+ enabled: false;
79
+ }>;
80
+ apiAccess: z.ZodObject<{
81
+ enabled: z.ZodLiteral<false>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ enabled: false;
84
+ }, {
85
+ enabled: false;
86
+ }>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ authSessions: {
89
+ enabled: false;
90
+ };
91
+ apiAccess: {
92
+ enabled: false;
93
+ };
94
+ }, {
95
+ authSessions: {
96
+ enabled: false;
97
+ };
98
+ apiAccess: {
99
+ enabled: false;
100
+ };
101
+ }>, z.ZodObject<{
102
+ authSessions: z.ZodUnion<[z.ZodObject<{
103
+ enabled: z.ZodLiteral<false>;
104
+ }, "strip", z.ZodTypeAny, {
105
+ enabled: false;
106
+ }, {
107
+ enabled: false;
108
+ }>, z.ZodObject<{
109
+ enabled: z.ZodLiteral<true>;
110
+ type: z.ZodEnum<["MANUAL", "API"]>;
111
+ startUrl: z.ZodOptional<z.ZodString>;
112
+ finishUrl: z.ZodOptional<z.ZodString>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ type: "API" | "MANUAL";
115
+ enabled: true;
116
+ startUrl?: string | undefined;
117
+ finishUrl?: string | undefined;
118
+ }, {
119
+ type: "API" | "MANUAL";
120
+ enabled: true;
121
+ startUrl?: string | undefined;
122
+ finishUrl?: string | undefined;
123
+ }>]>;
124
+ apiAccess: z.ZodObject<{
125
+ enabled: z.ZodLiteral<true>;
126
+ }, "strip", z.ZodTypeAny, {
127
+ enabled: true;
128
+ }, {
129
+ enabled: true;
130
+ }>;
131
+ }, "strip", z.ZodTypeAny, {
132
+ authSessions: {
133
+ enabled: false;
134
+ } | {
135
+ type: "API" | "MANUAL";
136
+ enabled: true;
137
+ startUrl?: string | undefined;
138
+ finishUrl?: string | undefined;
139
+ };
140
+ apiAccess: {
141
+ enabled: true;
142
+ };
143
+ }, {
144
+ authSessions: {
145
+ enabled: false;
146
+ } | {
147
+ type: "API" | "MANUAL";
148
+ enabled: true;
149
+ startUrl?: string | undefined;
150
+ finishUrl?: string | undefined;
151
+ };
152
+ apiAccess: {
153
+ enabled: true;
154
+ };
155
+ }>]>>;
156
+ export type IntunedJson = z.infer<typeof intunedJsonSchema>;
157
+ export declare const intunedSettingsFileNames: readonly ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
158
+ export declare function loadIntunedJson(): Promise<Err<never, string> | Ok<{
159
+ projectName?: string | undefined;
160
+ workspaceId?: string | undefined;
161
+ metadata?: {
162
+ defaultJobInput?: Record<string, any> | undefined;
163
+ defaultRunPlaygroundInput?: Record<string, any> | undefined;
164
+ testAuthSessionInput?: Record<string, any> | undefined;
165
+ } | undefined;
166
+ stealthMode?: {
167
+ enabled: boolean;
168
+ } | undefined;
169
+ } & {
170
+ [k: string]: unknown;
171
+ } & ({
172
+ authSessions: {
173
+ enabled: false;
174
+ };
175
+ apiAccess: {
176
+ enabled: false;
177
+ };
178
+ } | {
179
+ authSessions: {
180
+ enabled: false;
181
+ } | {
182
+ type: "API" | "MANUAL";
183
+ enabled: true;
184
+ startUrl?: string | undefined;
185
+ finishUrl?: string | undefined;
186
+ };
187
+ apiAccess: {
188
+ enabled: true;
189
+ };
190
+ }), never>>;
191
+ export declare function getIntunedSettingsFile(): Promise<Ok<{
192
+ name: typeof intunedSettingsFileNames[number];
193
+ path: string;
194
+ parse: (content: string) => any;
195
+ }, never> | Err<never, string>>;
196
+ export declare function getIntunedSettingsFileName(): Promise<Err<never, string> | Ok<"Intuned.json" | "Intuned.jsonc" | "Intuned.yaml" | "Intuned.yml" | "Intuned.toml", never>>;
197
+ export declare function loadIntunedJsonSync(): Err<never, string> | Ok<{
198
+ projectName?: string | undefined;
199
+ workspaceId?: string | undefined;
200
+ metadata?: {
201
+ defaultJobInput?: Record<string, any> | undefined;
202
+ defaultRunPlaygroundInput?: Record<string, any> | undefined;
203
+ testAuthSessionInput?: Record<string, any> | undefined;
204
+ } | undefined;
205
+ stealthMode?: {
206
+ enabled: boolean;
207
+ } | undefined;
208
+ } & {
209
+ [k: string]: unknown;
210
+ } & ({
211
+ authSessions: {
212
+ enabled: false;
213
+ };
214
+ apiAccess: {
215
+ enabled: false;
216
+ };
217
+ } | {
218
+ authSessions: {
219
+ enabled: false;
220
+ } | {
221
+ type: "API" | "MANUAL";
222
+ enabled: true;
223
+ startUrl?: string | undefined;
224
+ finishUrl?: string | undefined;
225
+ };
226
+ apiAccess: {
227
+ enabled: true;
228
+ };
229
+ }), never>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getIntunedSettingsFile = getIntunedSettingsFile;
7
+ exports.getIntunedSettingsFileName = getIntunedSettingsFileName;
8
+ exports.intunedSettingsFileNames = exports.intunedJsonSchema = void 0;
9
+ exports.loadIntunedJson = loadIntunedJson;
10
+ exports.loadIntunedJsonSync = loadIntunedJsonSync;
11
+ var _path = _interopRequireDefault(require("path"));
12
+ var fs = _interopRequireWildcard(require("fs-extra"));
13
+ var _zod = require("zod");
14
+ var JSONC = _interopRequireWildcard(require("jsonc-parser"));
15
+ var YAML = _interopRequireWildcard(require("yaml"));
16
+ var TOML = _interopRequireWildcard(require("smol-toml"));
17
+ var _neverthrow = require("neverthrow");
18
+ 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); }
19
+ 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; }
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ const playwright = undefined;
22
+ const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
23
+ projectName: _zod.z.string().optional(),
24
+ workspaceId: _zod.z.string().optional(),
25
+ metadata: _zod.z.object({
26
+ defaultJobInput: _zod.z.record(_zod.z.any()).optional().catch(undefined),
27
+ defaultRunPlaygroundInput: _zod.z.record(_zod.z.any()).optional().catch(undefined),
28
+ testAuthSessionInput: _zod.z.record(_zod.z.any()).optional().catch(undefined)
29
+ }).optional().catch(undefined),
30
+ stealthMode: _zod.z.object({
31
+ enabled: _zod.z.boolean()
32
+ }).optional().catch(undefined)
33
+ }).passthrough().and(_zod.z.union([_zod.z.object({
34
+ authSessions: _zod.z.object({
35
+ enabled: _zod.z.literal(false)
36
+ }),
37
+ apiAccess: _zod.z.object({
38
+ enabled: _zod.z.literal(false)
39
+ })
40
+ }), _zod.z.object({
41
+ authSessions: _zod.z.union([_zod.z.object({
42
+ enabled: _zod.z.literal(false)
43
+ }), _zod.z.object({
44
+ enabled: _zod.z.literal(true),
45
+ type: _zod.z.enum(["MANUAL", "API"]),
46
+ startUrl: _zod.z.string().optional(),
47
+ finishUrl: _zod.z.string().optional()
48
+ })]),
49
+ apiAccess: _zod.z.object({
50
+ enabled: _zod.z.literal(true)
51
+ })
52
+ })]));
53
+ const intunedSettingsFileNames = exports.intunedSettingsFileNames = ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
54
+ async function loadIntunedJson() {
55
+ const settingsFileResult = await getIntunedSettingsFile();
56
+ if (!settingsFileResult.isOk()) {
57
+ return settingsFileResult;
58
+ }
59
+ const settingsFile = settingsFileResult.value;
60
+ const intunedJsonContent = await fs.readFile(settingsFile.path, "utf-8");
61
+ let intunedJson;
62
+ try {
63
+ intunedJson = settingsFile.parse(intunedJsonContent);
64
+ } catch (e) {
65
+ return (0, _neverthrow.err)(`Failed to parse ${settingsFile.name}: ${e.message}`);
66
+ }
67
+ const parseResult = intunedJsonSchema.safeParse(intunedJson);
68
+ if (!parseResult.success) {
69
+ const formattedError = parseResult.error.errors.map(e => `- ${e.path.join(".")}: ${e.message}`).join("\n");
70
+ return (0, _neverthrow.err)(`${settingsFile.name} is not valid:\n${formattedError}\nPlease fix the errors and try again.`);
71
+ }
72
+ return (0, _neverthrow.ok)(parseResult.data);
73
+ }
74
+ const intunedSettingsParsers = {
75
+ "Intuned.json": JSON.parse,
76
+ "Intuned.jsonc": JSONC.parse,
77
+ "Intuned.yaml": YAML.parse,
78
+ "Intuned.yml": YAML.parse,
79
+ "Intuned.toml": TOML.parse
80
+ };
81
+ async function getIntunedSettingsFile() {
82
+ for (const fileName of intunedSettingsFileNames) {
83
+ const filePath = _path.default.join(process.cwd(), fileName);
84
+ if (await fs.exists(filePath)) {
85
+ return (0, _neverthrow.ok)({
86
+ name: fileName,
87
+ path: filePath,
88
+ parse: intunedSettingsParsers[fileName]
89
+ });
90
+ }
91
+ }
92
+ return (0, _neverthrow.err)("No Intuned settings file found.");
93
+ }
94
+ async function getIntunedSettingsFileName() {
95
+ const settingsFileResult = await getIntunedSettingsFile();
96
+ if (!settingsFileResult.isOk()) {
97
+ return settingsFileResult;
98
+ }
99
+ return (0, _neverthrow.ok)(settingsFileResult.value.name);
100
+ }
101
+ function loadIntunedJsonSync() {
102
+ const settingsFileResult = getIntunedSettingsFileSync();
103
+ if (!settingsFileResult.isOk()) {
104
+ return settingsFileResult;
105
+ }
106
+ const settingsFile = settingsFileResult.value;
107
+ const intunedJsonContent = fs.readFileSync(settingsFile.path, "utf-8");
108
+ let intunedJson;
109
+ try {
110
+ intunedJson = settingsFile.parse(intunedJsonContent);
111
+ } catch (e) {
112
+ return (0, _neverthrow.err)(`Failed to parse ${settingsFile.name}: ${e.message}`);
113
+ }
114
+ const parseResult = intunedJsonSchema.safeParse(intunedJson);
115
+ if (!parseResult.success) {
116
+ const formattedError = parseResult.error.errors.map(e => `- ${e.path.join(".")}: ${e.message}`).join("\n");
117
+ return (0, _neverthrow.err)(`${settingsFile.name} is not valid:\n${formattedError}\nPlease fix the errors and try again.`);
118
+ }
119
+ return (0, _neverthrow.ok)(parseResult.data);
120
+ }
121
+ function getIntunedSettingsFileSync() {
122
+ for (const fileName of intunedSettingsFileNames) {
123
+ const filePath = _path.default.join(process.cwd(), fileName);
124
+ if (fs.existsSync(filePath)) {
125
+ return (0, _neverthrow.ok)({
126
+ name: fileName,
127
+ path: filePath,
128
+ parse: intunedSettingsParsers[fileName]
129
+ });
130
+ }
131
+ }
132
+ return (0, _neverthrow.err)("No Intuned settings file found.");
133
+ }
@@ -21,5 +21,11 @@ export type LaunchChromiumCdpOptions = {
21
21
  };
22
22
  export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
23
23
  export declare function launchChromium(options: LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
24
+ export declare function getBrowserExecutablePath(): Promise<string | undefined>;
24
25
  export declare function launchBrowser(options: Omit<LaunchChromiumStandaloneOptions, "executablePath"> | LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
25
26
  export declare function getLocalCdpAddress(port: number): string;
27
+ export declare function getHeadlessUserAgent({ executablePath, args, ignoreDefaultArgs, }: {
28
+ executablePath?: string;
29
+ args?: string[];
30
+ ignoreDefaultArgs?: string[];
31
+ }): Promise<string | undefined>;
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getBrowserExecutablePath = getBrowserExecutablePath;
7
+ exports.getHeadlessUserAgent = getHeadlessUserAgent;
6
8
  exports.getLocalCdpAddress = getLocalCdpAddress;
7
9
  exports.launchBrowser = launchBrowser;
8
10
  exports.launchChromium = launchChromium;
@@ -86,10 +88,15 @@ async function launchChromium(options) {
86
88
  executablePath = undefined;
87
89
  }
88
90
  }
91
+ const viewport = null;
92
+ const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
93
+ executablePath
94
+ }));
89
95
  const context = await playwright.chromium.launchPersistentContext(userDataDir, {
96
+ userAgent,
90
97
  executablePath,
91
98
  headless,
92
- viewport: null,
99
+ viewport,
93
100
  proxy,
94
101
  downloadsPath,
95
102
  args: extraArgs,
@@ -120,25 +127,20 @@ async function launchChromium(options) {
120
127
  context
121
128
  };
122
129
  }
130
+ async function getBrowserExecutablePath() {
131
+ const browserType = getBrowserType();
132
+ if (browserType === "brave") {
133
+ return await getBraveExecutablePath();
134
+ }
135
+ }
123
136
  async function launchBrowser(options) {
124
137
  if ("cdpAddress" in options) {
125
138
  return launchChromium(options);
126
139
  }
127
- const browserType = getBrowserType();
128
- switch (browserType) {
129
- case "chromium":
130
- {
131
- return launchChromium(options);
132
- }
133
- case "brave":
134
- {
135
- const braveExecutablePath = await getBraveExecutablePath();
136
- return launchChromium({
137
- ...options,
138
- executablePath: braveExecutablePath
139
- });
140
- }
141
- }
140
+ return launchChromium({
141
+ ...options,
142
+ executablePath: await getBrowserExecutablePath()
143
+ });
142
144
  }
143
145
  function getBrowserType() {
144
146
  if (process.env.BROWSER_TYPE === "brave") {
@@ -169,4 +171,25 @@ async function waitOnCdpAddress(cdpAddress) {
169
171
  tcpTimeout: 1000,
170
172
  window: 1000
171
173
  });
174
+ }
175
+ async function getHeadlessUserAgent({
176
+ executablePath,
177
+ args,
178
+ ignoreDefaultArgs
179
+ }) {
180
+ const browser = await playwright.chromium.launch({
181
+ headless: true,
182
+ executablePath,
183
+ args,
184
+ ignoreDefaultArgs
185
+ });
186
+ const context = await browser.newContext();
187
+ const page = await context.newPage();
188
+ let userAgent = await page.evaluate(() => navigator.userAgent);
189
+ await browser.close();
190
+ if (!userAgent || typeof userAgent !== "string") {
191
+ return undefined;
192
+ }
193
+ userAgent = userAgent.replace("HeadlessChrome", "Chrome");
194
+ return userAgent;
172
195
  }
@@ -100,6 +100,7 @@ async function runApi({
100
100
  apiParameters: params,
101
101
  importFunction
102
102
  };
103
+ const intunedContext = (0, _asyncLocalStorage.getExecutionContext)();
103
104
  const runAutomationWithContext = async (context, page) => {
104
105
  async function saveTraceIfNeeded({
105
106
  errorMessage
@@ -148,7 +149,7 @@ async function runApi({
148
149
  }
149
150
  return (0, _neverthrow.ok)({
150
151
  result: automationFunctionResult,
151
- extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
152
+ extendedPayloads: intunedContext?.extendedPayloads,
152
153
  session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
153
154
  });
154
155
  } catch (error) {
@@ -159,6 +160,9 @@ async function runApi({
159
160
  });
160
161
  }
161
162
  };
163
+ if (intunedContext?.store) {
164
+ intunedContext.store = {};
165
+ }
162
166
  if (runOptions.environment === "standalone") {
163
167
  const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
164
168
  try {