simplex-ts 1.0.0 → 1.0.1

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/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Simplex TypeScript Package Template
2
+
3
+ A TypeScript package for browser automation and web interaction using Simplex API.
4
+
5
+ ## Features
6
+
7
+ - Browser automation with high-level commands
8
+ - Session-based interaction
9
+ - Element interaction (click, type, scroll)
10
+ - Content extraction (text, images, bounding boxes)
11
+ - File upload and download capabilities
12
+ - TypeScript support with type definitions
13
+ - Built with modern tooling (ESM + CommonJS output)
14
+
15
+ ## Getting Started
16
+
17
+ 1. Install dependencies:
18
+ ```bash
19
+ npm install
20
+ ```
21
+
22
+ 2. Build the package:
23
+ ```bash
24
+ npm run build
25
+ ```
26
+
27
+ 3. Run tests:
28
+ ```bash
29
+ npm test
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```typescript
35
+ import { Simplex } from 'simplex-ts';
36
+
37
+ // Initialize Simplex with your API key
38
+ const simplex = new Simplex('your-api-key');
39
+
40
+ // Create a new session
41
+ const [sessionId, livestreamUrl] = await simplex.createSession();
42
+
43
+ // Navigate to a website
44
+ await simplex.goto('example.com');
45
+
46
+ // Interact with elements
47
+ await simplex.click('Login button');
48
+ await simplex.type('user@example.com');
49
+ await simplex.pressEnter();
50
+
51
+ // Extract content
52
+ const text = await simplex.extractText('Welcome message');
53
+ console.log(text);
54
+
55
+ // Close the session when done
56
+ await simplex.closeSession();
57
+ ```
58
+
59
+ ### Available Methods
60
+
61
+ - `createSession()` - Start a new browser session
62
+ - `goto(url)` - Navigate to a URL
63
+ - `click(elementDescription)` - Click an element
64
+ - `type(text)` - Type text
65
+ - `pressEnter()` - Press Enter key
66
+ - `pressTab()` - Press Tab key
67
+ - `deleteText()` - Delete text
68
+ - `extractBbox(elementDescription)` - Get element bounding box
69
+ - `extractText(elementDescription)` - Extract text from element
70
+ - `extractImage(elementDescription)` - Extract image from element
71
+ - `scroll(pixels)` - Scroll page
72
+ - `wait(milliseconds)` - Wait for specified duration
73
+ - `clickAndUpload(elementDescription, file)` - Click and upload file
74
+ - `clickAndDownload(elementDescription)` - Click and download file
75
+ - `exists(elementDescription)` - Check if element exists
76
+ - `closeSession()` - Close the browser session
77
+
78
+ ## License
79
+
80
+ MIT
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Example function to demonstrate package usage
3
+ * @param name - The name to greet
4
+ * @returns A greeting message
5
+ */
6
+ declare function greet(name: string): string;
7
+
8
+ export { greet };
package/dist/index.d.ts CHANGED
@@ -1 +1,8 @@
1
- export { Simplex } from './simplex';
1
+ /**
2
+ * Example function to demonstrate package usage
3
+ * @param name - The name to greet
4
+ * @returns A greeting message
5
+ */
6
+ declare function greet(name: string): string;
7
+
8
+ export { greet };
package/dist/index.js CHANGED
@@ -1,5 +1,33 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Simplex = void 0;
4
- var simplex_1 = require("./simplex");
5
- Object.defineProperty(exports, "Simplex", { enumerable: true, get: function () { return simplex_1.Simplex; } });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ greet: () => greet
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ function greet(name) {
27
+ return `Hello, ${name}!`;
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ greet
32
+ });
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Example function to demonstrate package usage\n * @param name - The name to greet\n * @returns A greeting message\n */\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n\n// Export other functions and types here "],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,MAAM,MAAsB;AAC1C,SAAO,UAAU,IAAI;AACvB;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ // src/index.ts
2
+ function greet(name) {
3
+ return `Hello, ${name}!`;
4
+ }
5
+ export {
6
+ greet
7
+ };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Example function to demonstrate package usage\n * @param name - The name to greet\n * @returns A greeting message\n */\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n\n// Export other functions and types here "],"mappings":";AAKO,SAAS,MAAM,MAAsB;AAC1C,SAAO,UAAU,IAAI;AACvB;","names":[]}
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
2
  "name": "simplex-ts",
3
- "version": "1.0.0",
4
- "description": "TypeScript client for the Simplex API.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
3
+ "version": "1.0.1",
4
+ "description": "A TypeScript package template",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
7
11
  "scripts": {
8
- "build": "tsc",
12
+ "build": "tsup",
9
13
  "test": "jest",
10
- "test:unit": "jest tests/simplex.unit.test.ts",
11
- "test:integration": "jest tests/simplex.integration.test.ts",
12
- "test:coverage": "jest --coverage",
13
- "prepare": "npm run build"
14
- },
15
- "dependencies": {
16
- "axios": "^1.6.0",
17
- "dotenv": "^16.4.7",
18
- "form-data": "^4.0.0"
14
+ "dev": "tsup --watch",
15
+ "clean": "rimraf dist"
19
16
  },
17
+ "keywords": [
18
+ "typescript",
19
+ "template"
20
+ ],
21
+ "author": "",
22
+ "license": "MIT",
20
23
  "devDependencies": {
21
- "@types/jest": "^29.5.0",
22
- "@types/node": "^20.8.0",
24
+ "@types/jest": "^29.5.12",
25
+ "@types/node": "^20.11.19",
23
26
  "jest": "^29.7.0",
24
- "ts-jest": "^29.1.0",
25
- "typescript": "^5.2.0"
27
+ "rimraf": "^5.0.5",
28
+ "ts-jest": "^29.1.2",
29
+ "tsup": "^8.0.2",
30
+ "typescript": "^5.3.3",
31
+ "glob": "^10.3.10"
26
32
  },
27
- "files": [
28
- "dist",
29
- "README.md"
30
- ],
31
- "keywords": [
32
- "simplex",
33
- "api",
34
- "client"
35
- ],
36
- "license": "MIT"
37
- }
33
+ "dependencies": {
34
+ "axios": "^1.6.7",
35
+ "dotenv": "^16.4.5"
36
+ }
37
+ }
package/dist/simplex.d.ts DELETED
@@ -1,32 +0,0 @@
1
- interface SimplexOptions {
2
- apiKey?: string;
3
- }
4
- export declare class Simplex {
5
- private api_key;
6
- private session_id;
7
- constructor(apiKeyOrOptions?: string | SimplexOptions);
8
- private makeRequest;
9
- closeSession(): Promise<void>;
10
- createSession(options?: {
11
- showInConsole?: boolean;
12
- proxies?: boolean;
13
- sessionData?: string;
14
- }): Promise<string>;
15
- goto(url: string, cdpUrl?: string): Promise<void>;
16
- click(elementDescription: string, cdpUrl?: string): Promise<string>;
17
- type(text: string, cdpUrl?: string): Promise<void>;
18
- pressEnter(cdpUrl?: string): Promise<void>;
19
- pressTab(cdpUrl?: string): Promise<void>;
20
- deleteText(cdpUrl?: string): Promise<void>;
21
- extractBbox(elementDescription: string, cdpUrl?: string): Promise<any>;
22
- extractText(elementDescription: string, cdpUrl?: string): Promise<string>;
23
- extractImage(elementDescription: string, cdpUrl?: string): Promise<string>;
24
- scroll(pixels: number, cdpUrl?: string): Promise<void>;
25
- wait(milliseconds: number, cdpUrl?: string): Promise<void>;
26
- createLoginSession(url: string, proxies?: boolean): Promise<string>;
27
- restoreLoginSession(sessionData: string, cdpUrl?: string): Promise<void>;
28
- clickAndUpload(elementDescription: string, filePath: string): Promise<void>;
29
- clickAndDownload(elementDescription: string): Promise<[string, string]>;
30
- exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]>;
31
- }
32
- export {};
package/dist/simplex.js DELETED
@@ -1,399 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Simplex = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const form_data_1 = __importDefault(require("form-data"));
10
- const dotenv_1 = __importDefault(require("dotenv"));
11
- // Load environment variables
12
- dotenv_1.default.config();
13
- const BASE_URL = "https://api.simplex.sh";
14
- class Simplex {
15
- constructor(apiKeyOrOptions) {
16
- this.session_id = null;
17
- // Handle different ways of passing the API key
18
- if (typeof apiKeyOrOptions === 'string') {
19
- this.api_key = apiKeyOrOptions;
20
- }
21
- else if (typeof apiKeyOrOptions === 'object') {
22
- this.api_key = apiKeyOrOptions.apiKey || '';
23
- }
24
- else {
25
- this.api_key = '';
26
- }
27
- // Fallback to environment variable if no API key provided
28
- if (!this.api_key) {
29
- this.api_key = process.env.SIMPLEX_API_KEY || '';
30
- }
31
- if (!this.api_key) {
32
- throw new Error('API key must be provided either through constructor or SIMPLEX_API_KEY environment variable');
33
- }
34
- // Register cleanup on process exit
35
- process.on('exit', () => this.closeSession());
36
- }
37
- async makeRequest(endpoint, method, data, params, files) {
38
- try {
39
- const headers = {
40
- 'x-api-key': this.api_key
41
- };
42
- const config = {
43
- method,
44
- url: `${BASE_URL}/${endpoint}`,
45
- headers
46
- };
47
- if (method === 'GET') {
48
- config.params = params;
49
- }
50
- else {
51
- if (files) {
52
- const formData = new form_data_1.default();
53
- // Add regular data to form
54
- if (data) {
55
- for (const [key, value] of Object.entries(data)) {
56
- formData.append(key, String(value));
57
- }
58
- }
59
- // Add files to form
60
- for (const [key, fileStream] of Object.entries(files)) {
61
- formData.append(key, fileStream);
62
- }
63
- config.data = formData;
64
- // Add form headers
65
- Object.assign(config.headers, formData.getHeaders());
66
- }
67
- else {
68
- config.data = data;
69
- }
70
- }
71
- const response = await (0, axios_1.default)(config);
72
- console.log('response', response.data);
73
- if (endpoint !== 'create_session' && !response.data.hasOwnProperty('succeeded')) {
74
- throw new Error(`It looks like the ${endpoint} action failed to return a response. Did you set your api_key when creating the Simplex class?`);
75
- }
76
- if (endpoint === 'create_session' && !response.data.hasOwnProperty('session_id')) {
77
- throw new Error('Create session failed to return a session_id. Did you set your api_key when creating the Simplex class?');
78
- }
79
- return response.data;
80
- }
81
- catch (error) {
82
- if (error.response) {
83
- throw new Error(`Request failed with status ${error.response.status}: ${JSON.stringify(error.response.data)}`);
84
- }
85
- throw error;
86
- }
87
- }
88
- async closeSession() {
89
- if (!this.session_id)
90
- return;
91
- const formData = new form_data_1.default();
92
- formData.append('session_id', this.session_id);
93
- const response = await this.makeRequest('close_session', 'POST', formData);
94
- this.session_id = null;
95
- if (!response.succeeded) {
96
- throw new Error(`Failed to close session: ${response.error}`);
97
- }
98
- }
99
- async createSession(options = {}) {
100
- const { showInConsole = true, proxies = true, sessionData } = options;
101
- const formData = new form_data_1.default();
102
- formData.append('proxies', String(proxies));
103
- if (sessionData) {
104
- formData.append('session_data', sessionData);
105
- }
106
- const response = await this.makeRequest('create_session', 'POST', formData);
107
- if (!response.session_id) {
108
- throw new Error("Create session failed to return a session_id. Did you set your api_key when creating the Simplex class?");
109
- }
110
- this.session_id = response.session_id;
111
- const livestreamUrl = response.livestream_url;
112
- if (showInConsole) {
113
- console.log(`Livestream URL: ${livestreamUrl}`);
114
- }
115
- return livestreamUrl;
116
- }
117
- async goto(url, cdpUrl) {
118
- if (!url) {
119
- throw new Error('URL is required for goto action');
120
- }
121
- if (!cdpUrl && !this.session_id) {
122
- throw new Error(`Must call createSession before calling action goto with url='${url}'`);
123
- }
124
- if (!url.startsWith('http://') && !url.startsWith('https://')) {
125
- url = 'https://' + url;
126
- }
127
- const formData = new form_data_1.default();
128
- formData.append('url', url);
129
- if (cdpUrl) {
130
- formData.append('cdp_url', cdpUrl);
131
- }
132
- else {
133
- formData.append('session_id', this.session_id);
134
- }
135
- const response = await this.makeRequest('goto', 'POST', formData);
136
- if (!response.succeeded) {
137
- throw new Error(`Failed to goto url: ${response.error}`);
138
- }
139
- }
140
- async click(elementDescription, cdpUrl) {
141
- if (!cdpUrl && !this.session_id) {
142
- throw new Error(`Must call createSession before calling action click with element_description='${elementDescription}'`);
143
- }
144
- const formData = new form_data_1.default();
145
- formData.append('element_description', elementDescription);
146
- if (cdpUrl) {
147
- formData.append('cdp_url', cdpUrl);
148
- }
149
- else {
150
- formData.append('session_id', this.session_id);
151
- }
152
- const response = await this.makeRequest('click', 'POST', formData);
153
- if (!response.succeeded) {
154
- throw new Error(`Failed to click element: ${response.error}`);
155
- }
156
- return response.element_clicked;
157
- }
158
- async type(text, cdpUrl) {
159
- if (!cdpUrl && !this.session_id) {
160
- throw new Error(`Must call createSession before calling action type with text='${text}'`);
161
- }
162
- const formData = new form_data_1.default();
163
- formData.append('text', text);
164
- if (cdpUrl) {
165
- formData.append('cdp_url', cdpUrl);
166
- }
167
- else {
168
- formData.append('session_id', this.session_id);
169
- }
170
- const response = await this.makeRequest('type', 'POST', formData);
171
- if (!response.succeeded) {
172
- throw new Error(`Failed to type text: ${response.error}`);
173
- }
174
- }
175
- async pressEnter(cdpUrl) {
176
- if (!cdpUrl && !this.session_id) {
177
- throw new Error('Must call createSession before calling action press_enter');
178
- }
179
- const formData = new form_data_1.default();
180
- if (cdpUrl) {
181
- formData.append('cdp_url', cdpUrl);
182
- }
183
- else {
184
- formData.append('session_id', this.session_id);
185
- }
186
- const response = await this.makeRequest('press_enter', 'POST', formData);
187
- if (!response.succeeded) {
188
- throw new Error(`Failed to press enter: ${response.error}`);
189
- }
190
- }
191
- async pressTab(cdpUrl) {
192
- if (!cdpUrl && !this.session_id) {
193
- throw new Error('Must call createSession before calling action press_tab');
194
- }
195
- const formData = new form_data_1.default();
196
- if (cdpUrl) {
197
- formData.append('cdp_url', cdpUrl);
198
- }
199
- else {
200
- formData.append('session_id', this.session_id);
201
- }
202
- const response = await this.makeRequest('press_tab', 'POST', formData);
203
- if (!response.succeeded) {
204
- throw new Error(`Failed to press tab: ${response.error}`);
205
- }
206
- }
207
- async deleteText(cdpUrl) {
208
- if (!cdpUrl && !this.session_id) {
209
- throw new Error('Must call createSession before calling action delete_text');
210
- }
211
- const formData = new form_data_1.default();
212
- if (cdpUrl) {
213
- formData.append('cdp_url', cdpUrl);
214
- }
215
- else {
216
- formData.append('session_id', this.session_id);
217
- }
218
- const response = await this.makeRequest('delete_text', 'POST', formData);
219
- if (!response.succeeded) {
220
- throw new Error(`Failed to delete text: ${response.error}`);
221
- }
222
- }
223
- async extractBbox(elementDescription, cdpUrl) {
224
- if (!cdpUrl && !this.session_id) {
225
- throw new Error(`Must call createSession before calling action extract_bbox with element_description='${elementDescription}'`);
226
- }
227
- const formData = new form_data_1.default();
228
- formData.append('element_description', elementDescription);
229
- if (cdpUrl) {
230
- formData.append('cdp_url', cdpUrl);
231
- }
232
- else {
233
- formData.append('session_id', this.session_id);
234
- }
235
- const response = await this.makeRequest('extract-bbox', 'GET', undefined, formData);
236
- if (!response.succeeded) {
237
- throw new Error(`Failed to extract bbox: ${response.error}`);
238
- }
239
- return response.bbox;
240
- }
241
- async extractText(elementDescription, cdpUrl) {
242
- if (!cdpUrl && !this.session_id) {
243
- throw new Error(`Must call createSession before calling action extract_text with element_description='${elementDescription}'`);
244
- }
245
- const params = {
246
- element_description: elementDescription
247
- };
248
- if (cdpUrl) {
249
- params.cdp_url = cdpUrl;
250
- }
251
- else {
252
- params.session_id = this.session_id;
253
- }
254
- const response = await this.makeRequest('extract-text', 'GET', undefined, params);
255
- if (!response.succeeded) {
256
- throw new Error(`Failed to extract text: ${response.error}`);
257
- }
258
- return response.text;
259
- }
260
- async extractImage(elementDescription, cdpUrl) {
261
- if (!cdpUrl && !this.session_id) {
262
- throw new Error(`Must call createSession before calling action extract_image with element_description='${elementDescription}'`);
263
- }
264
- const formData = new form_data_1.default();
265
- formData.append('element_description', elementDescription);
266
- if (cdpUrl) {
267
- formData.append('cdp_url', cdpUrl);
268
- }
269
- else {
270
- formData.append('session_id', this.session_id);
271
- }
272
- const response = await this.makeRequest('extract-image', 'GET', undefined, formData);
273
- if (!response.succeeded) {
274
- throw new Error(`Failed to extract image: ${response.error}`);
275
- }
276
- return response.image;
277
- }
278
- async scroll(pixels, cdpUrl) {
279
- if (!cdpUrl && !this.session_id) {
280
- throw new Error(`Must call createSession before calling action scroll with pixels=${pixels}`);
281
- }
282
- const formData = new form_data_1.default();
283
- formData.append('pixels', String(pixels));
284
- if (cdpUrl) {
285
- formData.append('cdp_url', cdpUrl);
286
- }
287
- else {
288
- formData.append('session_id', this.session_id);
289
- }
290
- const response = await this.makeRequest('scroll', 'POST', formData);
291
- if (!response.succeeded) {
292
- throw new Error(`Failed to scroll: ${response.error}`);
293
- }
294
- }
295
- async wait(milliseconds, cdpUrl) {
296
- if (!cdpUrl && !this.session_id) {
297
- throw new Error(`Must call createSession before calling action wait with milliseconds=${milliseconds}`);
298
- }
299
- const formData = new form_data_1.default();
300
- formData.append('milliseconds', String(milliseconds));
301
- if (cdpUrl) {
302
- formData.append('cdp_url', cdpUrl);
303
- }
304
- else {
305
- formData.append('session_id', this.session_id);
306
- }
307
- const response = await this.makeRequest('wait', 'POST', formData);
308
- if (!response.succeeded) {
309
- throw new Error(`Failed to wait: ${response.error}`);
310
- }
311
- }
312
- async createLoginSession(url, proxies = true) {
313
- const formData = new form_data_1.default();
314
- formData.append('url', url);
315
- formData.append('proxies', String(proxies));
316
- const response = await this.makeRequest('create_login_session', 'POST', formData);
317
- if (!response.succeeded) {
318
- throw new Error(`Failed to create login session: ${response.error}`);
319
- }
320
- return response.login_session_url;
321
- }
322
- async restoreLoginSession(sessionData, cdpUrl) {
323
- let sessionDataObj;
324
- try {
325
- sessionDataObj = JSON.parse(sessionData);
326
- }
327
- catch (_a) {
328
- try {
329
- sessionDataObj = JSON.parse(await fs_1.default.promises.readFile(sessionData, 'utf-8'));
330
- }
331
- catch (e) {
332
- throw new Error(`Failed to load session data. Input must be valid JSON string or path to JSON file. Error: ${e}`);
333
- }
334
- }
335
- const formData = new form_data_1.default();
336
- formData.append('session_data', JSON.stringify(sessionDataObj));
337
- if (cdpUrl) {
338
- formData.append('cdp_url', cdpUrl);
339
- }
340
- else {
341
- formData.append('session_id', this.session_id);
342
- }
343
- const response = await this.makeRequest('restore_login_session', 'POST', formData);
344
- if (!response.succeeded) {
345
- throw new Error(`Failed to restore login session: ${response.error}`);
346
- }
347
- }
348
- async clickAndUpload(elementDescription, filePath) {
349
- if (!this.session_id) {
350
- throw new Error(`Must call createSession before calling action click_and_upload with element_description='${elementDescription}'`);
351
- }
352
- const fileStream = fs_1.default.createReadStream(filePath);
353
- const formData = new form_data_1.default();
354
- formData.append('element_description', elementDescription);
355
- formData.append('session_id', this.session_id);
356
- formData.append('file', fileStream);
357
- try {
358
- const response = await this.makeRequest('click_and_upload', 'POST', formData);
359
- if (!response.succeeded) {
360
- throw new Error(`Failed to click and upload: ${response.error}`);
361
- }
362
- }
363
- finally {
364
- fileStream.destroy(); // Clean up the file stream
365
- }
366
- }
367
- async clickAndDownload(elementDescription) {
368
- if (!this.session_id) {
369
- throw new Error(`Must call createSession before calling action click_and_download with element_description='${elementDescription}'`);
370
- }
371
- const formData = new form_data_1.default();
372
- formData.append('element_description', elementDescription);
373
- formData.append('session_id', this.session_id);
374
- const response = await this.makeRequest('click_and_download', 'POST', formData);
375
- if (!response.succeeded) {
376
- throw new Error(`Failed to click and download: ${response.error}`);
377
- }
378
- return [response.b64, response.filename];
379
- }
380
- async exists(elementDescription, cdpUrl) {
381
- if (!cdpUrl && !this.session_id) {
382
- throw new Error(`Must call createSession before calling action exists with element_description='${elementDescription}'`);
383
- }
384
- const formData = new form_data_1.default();
385
- formData.append('element_description', elementDescription);
386
- if (cdpUrl) {
387
- formData.append('cdp_url', cdpUrl);
388
- }
389
- else {
390
- formData.append('session_id', this.session_id);
391
- }
392
- const response = await this.makeRequest('exists', 'POST', formData);
393
- if (!response.succeeded) {
394
- throw new Error(`Failed to check if element exists: ${response.error}`);
395
- }
396
- return [response.exists, response.reasoning];
397
- }
398
- }
399
- exports.Simplex = Simplex;