@intuned/runtime-dev 1.3.14-ts-runtime-helpers-1 → 1.3.15-ts-helpers

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.
@@ -22,8 +22,8 @@ export declare const loadIntunedJson: () => Promise<{
22
22
  authSessions: {
23
23
  enabled: false;
24
24
  } | {
25
- enabled: true;
26
25
  type: "API" | "MANUAL";
26
+ enabled: true;
27
27
  startUrl?: string | undefined;
28
28
  finishUrl?: string | undefined;
29
29
  };
@@ -8,5 +8,3 @@ export declare const API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
8
8
  export declare const API_KEY_HEADER_NAME = "x-api-key";
9
9
  export declare const API_BASE_URL_ENV_VAR_KEY = "INTUNED_API_BASE_URL";
10
10
  export declare const CLI_ENV_VAR_KEY = "INTUNED_CLI";
11
- export declare const INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR = "INTUNED_AI_GATEWAY_BASE_URL";
12
- export declare const INTUNED_AI_GATEWAY_API_KEY_ENV_VAR = "INTUNED_AI_GATEWAY_API_KEY";
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR = exports.INTUNED_AI_GATEWAY_API_KEY_ENV_VAR = exports.EXTENSION_PATH_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
6
+ exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.EXTENSION_PATH_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
7
7
  const API_FOLDER_NAME = exports.API_FOLDER_NAME = "api";
8
8
  const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
9
9
  const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
@@ -13,6 +13,4 @@ const PROJECT_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT
13
13
  const API_KEY_ENV_VAR_KEY = exports.API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
14
14
  const API_KEY_HEADER_NAME = exports.API_KEY_HEADER_NAME = "x-api-key";
15
15
  const API_BASE_URL_ENV_VAR_KEY = exports.API_BASE_URL_ENV_VAR_KEY = "INTUNED_API_BASE_URL";
16
- const CLI_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = "INTUNED_CLI";
17
- const INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR = exports.INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR = "INTUNED_AI_GATEWAY_BASE_URL";
18
- const INTUNED_AI_GATEWAY_API_KEY_ENV_VAR = exports.INTUNED_AI_GATEWAY_API_KEY_ENV_VAR = "INTUNED_AI_GATEWAY_API_KEY";
16
+ const CLI_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = "INTUNED_CLI";
@@ -16,7 +16,7 @@ var _jwtTokenManager = require("../jwtTokenManager");
16
16
  var _path = _interopRequireDefault(require("path"));
17
17
  var _promises = require("fs/promises");
18
18
  var _intunedExtensionServer = require("./intunedExtensionServer");
19
- var _nodeNet = _interopRequireDefault(require("node:net"));
19
+ var _portfinder = require("portfinder");
20
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
21
  const INTUNED_WORKER = "intunedWorker.js";
22
22
  const INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
@@ -30,21 +30,6 @@ function getIntunedCaptchaExtensionPortFromEnv() {
30
30
  }
31
31
  return parsed;
32
32
  }
33
- async function getFreeEphemeralPort() {
34
- const server = _nodeNet.default.createServer();
35
- server.unref();
36
- await new Promise((resolve, reject) => {
37
- server.once("error", reject);
38
- server.listen(0, "127.0.0.1", () => resolve());
39
- });
40
- const address = server.address();
41
- const port = typeof address === "object" && address && "port" in address ? address.port : null;
42
- await new Promise(resolve => server.close(() => resolve()));
43
- if (!port) {
44
- throw new Error("Failed to allocate a free port for captcha extension");
45
- }
46
- return port;
47
- }
48
33
  function buildExtensionsList() {
49
34
  const extensionsList = [];
50
35
  if (isIntunedExtensionEnabled()) {
@@ -109,7 +94,7 @@ async function getIntunedExtensionSettings() {
109
94
  };
110
95
  })();
111
96
  const baseUrl = process.env.INTUNED_API_BASE_URL ?? domain;
112
- const port = getIntunedCaptchaExtensionPortFromEnv() ?? (await getFreeEphemeralPort());
97
+ const port = getIntunedCaptchaExtensionPortFromEnv() ?? (await (0, _portfinder.getPort)({}));
113
98
  return {
114
99
  ...(settings.captchaSolver ?? _settingsSchema.captchaSolverSettingsSchema.parse({})),
115
100
  workspaceId,
@@ -6,7 +6,7 @@ export declare class ExtensionServer {
6
6
  isHealthy: boolean;
7
7
  constructor();
8
8
  private getOrCreateTab;
9
- private handleUpsertCaptcha;
9
+ handleUpsertCaptcha(captcha: Captcha): Promise<void>;
10
10
  start({ port, host, }: {
11
11
  port: number;
12
12
  host?: string;
@@ -15,6 +15,8 @@ export declare class ExtensionServer {
15
15
  getCaptchas(page: playwright.Page, status?: CaptchaStatus): Promise<Captcha[]>;
16
16
  subscribe(page: playwright.Page, handler: CaptchaCallback, status?: CaptchaStatus): Promise<void>;
17
17
  unsubscribe(page: playwright.Page, handler: CaptchaCallback, status?: CaptchaStatus): Promise<void>;
18
+ removeTab(tabId: number): void;
19
+ getTabId(page: playwright.Page): Promise<number>;
18
20
  }
19
21
  export declare function getIntunedExtensionServer(): ExtensionServer;
20
22
  export declare function setupIntunedExtensionServer({ port, host, }: {
@@ -9,6 +9,7 @@ exports.getIntunedExtensionServer = getIntunedExtensionServer;
9
9
  exports.getTabId = getTabId;
10
10
  exports.setupIntunedExtensionServer = setupIntunedExtensionServer;
11
11
  var _fastify = _interopRequireDefault(require("fastify"));
12
+ var _types = require("./types");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  class TabCaptchaState {
14
15
  constructor(tabId) {
@@ -22,7 +23,7 @@ class TabCaptchaState {
22
23
  unsubscribe(handler, status) {
23
24
  const index = this.subscribers.findIndex(subscriber => subscriber.handler === handler && (subscriber.status === status || !status));
24
25
  if (index !== -1) {
25
- this.subscribers = this.subscribers.splice(index, 1);
26
+ this.subscribers.splice(index, 1);
26
27
  }
27
28
  }
28
29
  getCaptchas() {
@@ -31,7 +32,9 @@ class TabCaptchaState {
31
32
  async upsertCaptcha(captcha) {
32
33
  this.captchasById.set(captcha.id, captcha);
33
34
  for (const subscriber of this.subscribers) {
34
- await subscriber.handler(captcha);
35
+ if (!subscriber.status || subscriber.status === captcha.status) {
36
+ await subscriber.handler(captcha);
37
+ }
35
38
  }
36
39
  }
37
40
  }
@@ -65,23 +68,17 @@ class ExtensionServer {
65
68
  });
66
69
  this.app.post("/state", async (request, reply) => {
67
70
  try {
68
- const data = request.body ?? {};
69
- const captcha = {
70
- id: String(data?.id ?? ""),
71
- tabId: Number(data?.tabId ?? 0),
72
- type: data?.type,
73
- status: data?.status,
74
- retryCount: data?.retryCount,
75
- error: data?.error ?? null
76
- };
77
- if (!captcha.id || !captcha.tabId || !captcha.type || !captcha.status) {
71
+ const result = _types.captchaSchema.safeParse(request.body);
72
+ if (!result.success) {
78
73
  return reply.code(400).send({
79
- error: "Invalid captcha payload"
74
+ error: "Invalid captcha payload",
75
+ details: result.error.flatten().fieldErrors
80
76
  });
81
77
  }
82
- await this.handleUpsertCaptcha(captcha);
78
+ await this.handleUpsertCaptcha(result.data);
83
79
  return reply.code(200).send({});
84
80
  } catch (error) {
81
+ console.error("Error processing captcha state update:", error);
85
82
  return reply.code(500).send({
86
83
  error: "Internal server error",
87
84
  message: error?.message ?? String(error)
@@ -128,6 +125,12 @@ class ExtensionServer {
128
125
  if (!tab) return;
129
126
  tab.unsubscribe(handler, status);
130
127
  }
128
+ removeTab(tabId) {
129
+ this.tabs.delete(tabId);
130
+ }
131
+ async getTabId(page) {
132
+ return await getTabId(page);
133
+ }
131
134
  }
132
135
  exports.ExtensionServer = ExtensionServer;
133
136
  let extensionServerSingleton = null;
@@ -155,10 +158,24 @@ async function cleanIntunedExtensionServer() {
155
158
  extensionServerSingleton = null;
156
159
  }
157
160
  }
161
+ const TAB_ID_CACHE_KEY = "__INTUNED_CACHED_TAB_ID__";
158
162
  async function getTabId(page) {
159
- await page.waitForFunction("window.__INTUNED_TAB_ID__ !== undefined", {
160
- timeout: 15_000
161
- });
162
- const tabId = await page.evaluate("window.__INTUNED_TAB_ID__");
163
- return Number(tabId);
163
+ const cached = page[TAB_ID_CACHE_KEY];
164
+ if (cached !== undefined && typeof cached === "number") {
165
+ return cached;
166
+ }
167
+ let tabId;
168
+ try {
169
+ tabId = await page.evaluate("window.__INTUNED_TAB_ID__", {
170
+ timeout: 100
171
+ });
172
+ } catch {
173
+ await page.waitForFunction("window.__INTUNED_TAB_ID__ !== undefined", {
174
+ timeout: 15_000
175
+ });
176
+ tabId = await page.evaluate("window.__INTUNED_TAB_ID__");
177
+ }
178
+ const numericTabId = Number(tabId);
179
+ page[TAB_ID_CACHE_KEY] = numericTabId;
180
+ return numericTabId;
164
181
  }
@@ -1,21 +1,212 @@
1
- export type CaptchaType = "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
2
- export type CaptchaStatus = "attached" | "solving" | "solved" | "error" | "detached";
3
- export type CaptchaError = {
1
+ import { z } from "zod";
2
+ export declare const captchaTypeSchema: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
3
+ export type CaptchaType = z.infer<typeof captchaTypeSchema>;
4
+ export declare const captchaStatusSchema: z.ZodEnum<["attached", "solving", "solved", "error", "detached"]>;
5
+ export type CaptchaStatus = z.infer<typeof captchaStatusSchema>;
6
+ export declare const captchaErrorCodeSchema: z.ZodEnum<["HIT_LIMIT", "MAX_RETRIES", "UNEXPECTED_SERVER_RESPONSE", "UNEXPECTED_ERROR"]>;
7
+ export type CaptchaErrorCode = z.infer<typeof captchaErrorCodeSchema>;
8
+ export declare const captchaErrorSchema: z.ZodObject<{
9
+ code: z.ZodEnum<["HIT_LIMIT", "MAX_RETRIES", "UNEXPECTED_SERVER_RESPONSE", "UNEXPECTED_ERROR"]>;
10
+ error: z.ZodOptional<z.ZodUnknown>;
11
+ }, "strip", z.ZodTypeAny, {
4
12
  code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
5
13
  error?: unknown;
6
- };
7
- export type CaptchaBase = {
14
+ }, {
15
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
16
+ error?: unknown;
17
+ }>;
18
+ export type CaptchaError = z.infer<typeof captchaErrorSchema>;
19
+ declare const captchaBaseSchema: z.ZodObject<{
20
+ id: z.ZodString;
21
+ tabId: z.ZodNumber;
22
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
23
+ retryCount: z.ZodOptional<z.ZodNumber>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
26
+ id: string;
27
+ tabId: number;
28
+ retryCount?: number | undefined;
29
+ }, {
30
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
31
+ id: string;
32
+ tabId: number;
33
+ retryCount?: number | undefined;
34
+ }>;
35
+ export type CaptchaBase = z.infer<typeof captchaBaseSchema>;
36
+ declare const captchaNonErrorSchema: z.ZodObject<{
37
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
38
+ id: z.ZodString;
39
+ tabId: z.ZodNumber;
40
+ retryCount: z.ZodOptional<z.ZodNumber>;
41
+ status: z.ZodEnum<["attached", "solving", "solved", "detached"]>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
44
+ status: "attached" | "solving" | "solved" | "detached";
45
+ id: string;
46
+ tabId: number;
47
+ retryCount?: number | undefined;
48
+ }, {
49
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
50
+ status: "attached" | "solving" | "solved" | "detached";
51
+ id: string;
52
+ tabId: number;
53
+ retryCount?: number | undefined;
54
+ }>;
55
+ export type CaptchaNonError = z.infer<typeof captchaNonErrorSchema>;
56
+ declare const captchaErrorStatusSchema: z.ZodObject<{
57
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
58
+ id: z.ZodString;
59
+ tabId: z.ZodNumber;
60
+ retryCount: z.ZodOptional<z.ZodNumber>;
61
+ status: z.ZodLiteral<"error">;
62
+ error: z.ZodObject<{
63
+ code: z.ZodEnum<["HIT_LIMIT", "MAX_RETRIES", "UNEXPECTED_SERVER_RESPONSE", "UNEXPECTED_ERROR"]>;
64
+ error: z.ZodOptional<z.ZodUnknown>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
67
+ error?: unknown;
68
+ }, {
69
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
70
+ error?: unknown;
71
+ }>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ error: {
74
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
75
+ error?: unknown;
76
+ };
77
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
78
+ status: "error";
8
79
  id: string;
9
80
  tabId: number;
10
- type: CaptchaType;
11
- retryCount?: number;
12
- };
13
- export type CaptchaNonError = CaptchaBase & {
14
- status: Exclude<CaptchaStatus, "error">;
15
- };
16
- export type CaptchaErrorStatus = CaptchaBase & {
81
+ retryCount?: number | undefined;
82
+ }, {
83
+ error: {
84
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
85
+ error?: unknown;
86
+ };
87
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
17
88
  status: "error";
89
+ id: string;
90
+ tabId: number;
91
+ retryCount?: number | undefined;
92
+ }>;
93
+ export type CaptchaErrorStatus = z.infer<typeof captchaErrorStatusSchema>;
94
+ export declare const captchaSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
95
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
96
+ id: z.ZodString;
97
+ tabId: z.ZodNumber;
98
+ retryCount: z.ZodOptional<z.ZodNumber>;
99
+ status: z.ZodLiteral<"attached">;
100
+ }, "strip", z.ZodTypeAny, {
101
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
102
+ status: "attached";
103
+ id: string;
104
+ tabId: number;
105
+ retryCount?: number | undefined;
106
+ }, {
107
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
108
+ status: "attached";
109
+ id: string;
110
+ tabId: number;
111
+ retryCount?: number | undefined;
112
+ }>, z.ZodObject<{
113
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
114
+ id: z.ZodString;
115
+ tabId: z.ZodNumber;
116
+ retryCount: z.ZodOptional<z.ZodNumber>;
117
+ status: z.ZodLiteral<"solving">;
118
+ }, "strip", z.ZodTypeAny, {
119
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
120
+ status: "solving";
121
+ id: string;
122
+ tabId: number;
123
+ retryCount?: number | undefined;
124
+ }, {
125
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
126
+ status: "solving";
127
+ id: string;
128
+ tabId: number;
129
+ retryCount?: number | undefined;
130
+ }>, z.ZodObject<{
131
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
132
+ id: z.ZodString;
133
+ tabId: z.ZodNumber;
134
+ retryCount: z.ZodOptional<z.ZodNumber>;
135
+ status: z.ZodLiteral<"solved">;
136
+ }, "strip", z.ZodTypeAny, {
137
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
138
+ status: "solved";
139
+ id: string;
140
+ tabId: number;
141
+ retryCount?: number | undefined;
142
+ }, {
143
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
144
+ status: "solved";
145
+ id: string;
146
+ tabId: number;
147
+ retryCount?: number | undefined;
148
+ }>, z.ZodObject<{
149
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
150
+ id: z.ZodString;
151
+ tabId: z.ZodNumber;
152
+ retryCount: z.ZodOptional<z.ZodNumber>;
153
+ status: z.ZodLiteral<"detached">;
154
+ }, "strip", z.ZodTypeAny, {
155
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
156
+ status: "detached";
157
+ id: string;
158
+ tabId: number;
159
+ retryCount?: number | undefined;
160
+ }, {
161
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
162
+ status: "detached";
163
+ id: string;
164
+ tabId: number;
165
+ retryCount?: number | undefined;
166
+ }>, z.ZodObject<{
167
+ type: z.ZodEnum<["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]>;
168
+ id: z.ZodString;
169
+ tabId: z.ZodNumber;
170
+ retryCount: z.ZodOptional<z.ZodNumber>;
171
+ status: z.ZodLiteral<"error">;
172
+ error: z.ZodObject<{
173
+ code: z.ZodEnum<["HIT_LIMIT", "MAX_RETRIES", "UNEXPECTED_SERVER_RESPONSE", "UNEXPECTED_ERROR"]>;
174
+ error: z.ZodOptional<z.ZodUnknown>;
175
+ }, "strip", z.ZodTypeAny, {
176
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
177
+ error?: unknown;
178
+ }, {
179
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
180
+ error?: unknown;
181
+ }>;
182
+ }, "strip", z.ZodTypeAny, {
183
+ error: {
184
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
185
+ error?: unknown;
186
+ };
187
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
188
+ status: "error";
189
+ id: string;
190
+ tabId: number;
191
+ retryCount?: number | undefined;
192
+ }, {
193
+ error: {
194
+ code: "HIT_LIMIT" | "MAX_RETRIES" | "UNEXPECTED_SERVER_RESPONSE" | "UNEXPECTED_ERROR";
195
+ error?: unknown;
196
+ };
197
+ type: "aws" | "cloudflare" | "customcaptcha" | "funcaptcha" | "geetest" | "hcaptcha" | "lemincaptcha" | "recaptcha" | "textcaptcha";
198
+ status: "error";
199
+ id: string;
200
+ tabId: number;
201
+ retryCount?: number | undefined;
202
+ }>]>;
203
+ export type Captcha = z.infer<typeof captchaSchema>;
204
+ export type CaptchaCallback = (captcha: Captcha) => Promise<void> | void;
205
+ export declare class CaptchaSolveError extends Error {
18
206
  error: CaptchaError;
19
- };
20
- export type Captcha = CaptchaNonError | CaptchaErrorStatus;
21
- export type CaptchaCallback = (captcha: Captcha) => void | Promise<void>;
207
+ constructor(message: string, error: CaptchaError);
208
+ }
209
+ export declare class TimeoutError extends Error {
210
+ constructor(message: string);
211
+ }
212
+ export {};
@@ -2,4 +2,50 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.captchaTypeSchema = exports.captchaStatusSchema = exports.captchaSchema = exports.captchaErrorSchema = exports.captchaErrorCodeSchema = exports.TimeoutError = exports.CaptchaSolveError = void 0;
7
+ var _zod = require("zod");
8
+ const captchaTypeSchema = exports.captchaTypeSchema = _zod.z.enum(["aws", "cloudflare", "customcaptcha", "funcaptcha", "geetest", "hcaptcha", "lemincaptcha", "recaptcha", "textcaptcha"]);
9
+ const captchaStatusSchema = exports.captchaStatusSchema = _zod.z.enum(["attached", "solving", "solved", "error", "detached"]);
10
+ const captchaErrorCodeSchema = exports.captchaErrorCodeSchema = _zod.z.enum(["HIT_LIMIT", "MAX_RETRIES", "UNEXPECTED_SERVER_RESPONSE", "UNEXPECTED_ERROR"]);
11
+ const captchaErrorSchema = exports.captchaErrorSchema = _zod.z.object({
12
+ code: captchaErrorCodeSchema,
13
+ error: _zod.z.unknown().optional()
14
+ });
15
+ const captchaBaseSchema = _zod.z.object({
16
+ id: _zod.z.string().min(1),
17
+ tabId: _zod.z.number().int().positive(),
18
+ type: captchaTypeSchema,
19
+ retryCount: _zod.z.number().int().nonnegative().optional()
20
+ });
21
+ const captchaNonErrorSchema = captchaBaseSchema.extend({
22
+ status: captchaStatusSchema.exclude(["error"])
23
+ });
24
+ const captchaErrorStatusSchema = captchaBaseSchema.extend({
25
+ status: _zod.z.literal("error"),
26
+ error: captchaErrorSchema
27
+ });
28
+ const captchaSchema = exports.captchaSchema = _zod.z.discriminatedUnion("status", [captchaBaseSchema.extend({
29
+ status: _zod.z.literal("attached")
30
+ }), captchaBaseSchema.extend({
31
+ status: _zod.z.literal("solving")
32
+ }), captchaBaseSchema.extend({
33
+ status: _zod.z.literal("solved")
34
+ }), captchaBaseSchema.extend({
35
+ status: _zod.z.literal("detached")
36
+ }), captchaErrorStatusSchema]);
37
+ class CaptchaSolveError extends Error {
38
+ constructor(message, error) {
39
+ super(message);
40
+ this.error = error;
41
+ this.name = "CaptchaSolveError";
42
+ }
43
+ }
44
+ exports.CaptchaSolveError = CaptchaSolveError;
45
+ class TimeoutError extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "TimeoutError";
49
+ }
50
+ }
51
+ exports.TimeoutError = TimeoutError;
@@ -111,13 +111,13 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
111
111
  startUrl: z.ZodOptional<z.ZodString>;
112
112
  finishUrl: z.ZodOptional<z.ZodString>;
113
113
  }, "strip", z.ZodTypeAny, {
114
- enabled: true;
115
114
  type: "API" | "MANUAL";
115
+ enabled: true;
116
116
  startUrl?: string | undefined;
117
117
  finishUrl?: string | undefined;
118
118
  }, {
119
- enabled: true;
120
119
  type: "API" | "MANUAL";
120
+ enabled: true;
121
121
  startUrl?: string | undefined;
122
122
  finishUrl?: string | undefined;
123
123
  }>]>;
@@ -132,8 +132,8 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
132
132
  authSessions: {
133
133
  enabled: false;
134
134
  } | {
135
- enabled: true;
136
135
  type: "API" | "MANUAL";
136
+ enabled: true;
137
137
  startUrl?: string | undefined;
138
138
  finishUrl?: string | undefined;
139
139
  };
@@ -144,8 +144,8 @@ export declare const intunedJsonSchema: z.ZodIntersection<z.ZodObject<{
144
144
  authSessions: {
145
145
  enabled: false;
146
146
  } | {
147
- enabled: true;
148
147
  type: "API" | "MANUAL";
148
+ enabled: true;
149
149
  startUrl?: string | undefined;
150
150
  finishUrl?: string | undefined;
151
151
  };
@@ -179,8 +179,8 @@ export declare function loadIntunedJson(): Promise<Err<never, string> | Ok<{
179
179
  authSessions: {
180
180
  enabled: false;
181
181
  } | {
182
- enabled: true;
183
182
  type: "API" | "MANUAL";
183
+ enabled: true;
184
184
  startUrl?: string | undefined;
185
185
  finishUrl?: string | undefined;
186
186
  };
@@ -218,8 +218,8 @@ export declare function loadIntunedJsonSync(): Err<never, string> | Ok<{
218
218
  authSessions: {
219
219
  enabled: false;
220
220
  } | {
221
- enabled: true;
222
221
  type: "API" | "MANUAL";
222
+ enabled: true;
223
223
  startUrl?: string | undefined;
224
224
  finishUrl?: string | undefined;
225
225
  };
@@ -44,7 +44,6 @@ Object.keys(_types).forEach(function (key) {
44
44
  var _formatZodError = require("../formatZodError");
45
45
  var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
46
46
  var _importUsingImportFunction = require("./importUsingImportFunction");
47
- var _jwtTokenManager = require("../jwtTokenManager");
48
47
  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); }
49
48
  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; }
50
49
  function getObjectSizeInBytes(obj) {
@@ -54,10 +53,6 @@ function getObjectSizeInBytes(obj) {
54
53
  return new TextEncoder().encode(String(obj)).length;
55
54
  }
56
55
  }
57
- function injectRuntimeEnvVars() {
58
- process.env[_constants.INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR] = `${_jwtTokenManager.backendFunctionsTokenManager.backendFunctionsBaseUrl}/intuned-ai-gateway`;
59
- process.env[_constants.INTUNED_AI_GATEWAY_API_KEY_ENV_VAR] = _jwtTokenManager.backendFunctionsTokenManager.token ?? process.env[_constants.API_KEY_ENV_VAR_KEY];
60
- }
61
56
  async function runApi({
62
57
  abortSignal,
63
58
  importFunction,
@@ -85,7 +80,6 @@ async function runApi({
85
80
  resolve(abortSymbol);
86
81
  });
87
82
  });
88
- injectRuntimeEnvVars();
89
83
  async function runAutomation() {
90
84
  const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
91
85
  path: name,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { extendPayload, extendTimeout, runInfo, RunError, getAuthSessionParameters, attemptStore, persistentStore, } from "./runtime";
1
+ export { extendPayload, extendTimeout, runInfo, RunError, getAuthSessionParameters, attemptStore, persistentStore, getAiGatewayConfig, } from "./runtime";
2
2
  export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
3
3
  export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
4
4
  export { withPlaywrightContext } from "./common/playwrightContext";
package/dist/index.js CHANGED
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "extendTimeout", {
27
27
  return _runtime.extendTimeout;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "getAiGatewayConfig", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _runtime.getAiGatewayConfig;
34
+ }
35
+ });
30
36
  Object.defineProperty(exports, "getAuthSessionParameters", {
31
37
  enumerable: true,
32
38
  get: function () {
@@ -1,17 +1,14 @@
1
1
  import type { Page, BrowserContext } from "playwright";
2
- import { Captcha, CaptchaStatus, CaptchaCallback } from "../common/extension/types";
2
+ import { CaptchaStatus, CaptchaCallback } from "../common/extension/types";
3
3
  export type WithWaitForCaptchaSolveOptions = {
4
4
  page: Page;
5
5
  timeoutInMs?: number;
6
6
  settleDurationMs?: number;
7
7
  waitForNetworkSettled?: boolean;
8
8
  };
9
- export declare function withWaitForCaptchaSolve<T>(callback: (page: Page) => Promise<T>, options?: WithWaitForCaptchaSolveOptions): Promise<T>;
10
- export declare function waitForCaptchaSolve(page: Page, { timeoutInMs, settlePeriodInMs, }?: {
11
- timeoutInMs?: number;
12
- settlePeriodInMs?: number;
13
- }): Promise<void>;
14
- export declare function removeCaptchaEventListener(page: Page, status: CaptchaStatus, f: (captcha: Captcha) => any): Promise<void>;
9
+ export declare function withWaitForCaptchaSolve<T>(callback: (page: Page) => Promise<T>, options: WithWaitForCaptchaSolveOptions): Promise<T>;
10
+ export declare function waitForCaptchaSolve(page: Page, { timeoutInMs, settleDurationMs, }?: Pick<WithWaitForCaptchaSolveOptions, "timeoutInMs" | "settleDurationMs">): Promise<void>;
11
+ export declare function removeCaptchaEventListener(page: Page, status: CaptchaStatus, f: CaptchaCallback): Promise<void>;
15
12
  export declare function onCaptchaEvent(page: Page, status: CaptchaStatus, f: CaptchaCallback): Promise<void>;
16
13
  export declare function onceCaptchaEvent(page: Page, status: CaptchaStatus, f: CaptchaCallback): Promise<void>;
17
14
  export declare function pauseCaptchaSolver(context: BrowserContext): Promise<void>;