totalum-sdk 1.10.5 → 1.11.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/CHANGELOG.md +19 -0
- package/dist/_types/{coerce.d-Dgx5wOUv.d.ts → coerce.d-D_rylvPs.d.ts} +1 -1
- package/dist/_types/{errors.d-CIkIZmY-.d.ts → errors.d-BPpY5QKu.d.ts} +32 -2
- package/dist/_types/{integrations.d-B3Ea8Iuc.d.ts → integrations.d-BTZHy48D.d.ts} +2 -2
- package/dist/_types/{ops.d-G13QAhKA.d.ts → ops.d-Ce5zJyX0.d.ts} +2 -2
- package/dist/ai/index.d.ts +275 -23
- package/dist/ai/index.js +305 -24
- package/dist/analytics/index.d.ts +58 -12
- package/dist/analytics/index.js +46 -3
- package/dist/browser/index.d.ts +228 -20
- package/dist/browser/index.js +122 -13
- package/dist/connections/index.d.ts +601 -0
- package/dist/connections/index.js +353 -0
- package/dist/cron/index.d.ts +147 -20
- package/dist/cron/index.js +157 -15
- package/dist/d1/errors.js +15 -0
- package/dist/d1/index.d.ts +254 -10
- package/dist/d1/index.js +24 -4
- package/dist/d1/session.js +26 -2
- package/dist/email/index.d.ts +65 -10
- package/dist/email/index.js +60 -5
- package/dist/errors.js +17 -0
- package/dist/files/index.d.ts +243 -20
- package/dist/files/index.js +247 -14
- package/dist/index.d.ts +28 -10
- package/dist/index.js +22 -5
- package/dist/logs/index.d.ts +48 -10
- package/dist/logs/index.js +39 -4
- package/dist/payments/index.d.ts +221 -23
- package/dist/payments/index.js +216 -18
- package/dist/pdf/index.d.ts +59 -9
- package/dist/pdf/index.js +54 -4
- package/dist/react/index.d.ts +78 -6
- package/dist/react/index.js +51 -5
- package/dist/realtime/index.d.ts +55 -8
- package/dist/realtime/index.js +53 -6
- package/dist/scan/index.d.ts +78 -10
- package/dist/scan/index.js +63 -3
- package/dist/seo/index.d.ts +43 -7
- package/dist/seo/index.js +39 -3
- package/dist/speech/index.d.ts +34 -10
- package/dist/speech/index.js +25 -5
- package/dist/vectors/index.d.ts +96 -9
- package/dist/vectors/index.js +93 -7
- package/dist/web/index.d.ts +168 -15
- package/dist/web/index.js +163 -10
- package/dist/webhooks/index.d.ts +122 -15
- package/dist/webhooks/index.js +119 -13
- package/package.json +6 -1
- package/totalum-sdk.md +8900 -664
- package/totalum-sdk.signatures.json +61 -1
package/dist/browser/index.js
CHANGED
|
@@ -98,8 +98,8 @@ const POSITIONAL = {
|
|
|
98
98
|
observe: ['instruction'],
|
|
99
99
|
};
|
|
100
100
|
/**
|
|
101
|
-
* `
|
|
102
|
-
* over HTTPS, so every command works from a Worker. A command's refusal throws `TotalumError` with its frozen
|
|
101
|
+
* Creates the `browser` namespace (the same object as `totalum.browser`, scope `browser`): remote browser sessions
|
|
102
|
+
* driven entirely over HTTPS, so every command works from a Worker. A command's refusal throws `TotalumError` with its frozen
|
|
103
103
|
* code (`ACTION_TIMEOUT`, `ACTION_FAILED`, …); `actions()` returns every result instead.
|
|
104
104
|
*
|
|
105
105
|
* #### Things that still need a CDP connection
|
|
@@ -112,7 +112,20 @@ const POSITIONAL = {
|
|
|
112
112
|
*
|
|
113
113
|
* #### Not possible for anyone, over any transport
|
|
114
114
|
*
|
|
115
|
-
* - Seeding a saved profile from raw bytes (`CONTEXT_SEED_UNSUPPORTED`) — the
|
|
115
|
+
* - Seeding a saved profile from raw bytes (`CONTEXT_SEED_UNSUPPORTED`) — the browser provider's profile upload is deprecated; create a profile by running a session with `context: { persist: true }`, and replay cookies and web storage with `cookies.set` and `storage.set` (a service worker or an IndexedDB database cannot be replayed).
|
|
116
|
+
*
|
|
117
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
118
|
+
* @returns The `browser` namespace: the methods below.
|
|
119
|
+
* @example
|
|
120
|
+
* import { totalumBrowser } from 'totalum-sdk/browser';
|
|
121
|
+
*
|
|
122
|
+
* const browser = totalumBrowser();
|
|
123
|
+
* const s = await browser.session();
|
|
124
|
+
* try {
|
|
125
|
+
* await s.goto('https://example.com');
|
|
126
|
+
* } finally {
|
|
127
|
+
* await s.close();
|
|
128
|
+
* }
|
|
116
129
|
*/
|
|
117
130
|
export function totalumBrowser(options = {}) {
|
|
118
131
|
const call = jsonClient(options);
|
|
@@ -153,24 +166,120 @@ export function totalumBrowser(options = {}) {
|
|
|
153
166
|
}
|
|
154
167
|
return {
|
|
155
168
|
/**
|
|
156
|
-
* Opens a session.
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
169
|
+
* Opens a session. It returns the cloud browser's handle: call commands on it (`s.goto(url)`, `s.click(target)`,
|
|
170
|
+
* …) and `close()` it in `finally`. Billed per started minute while open. At most 3 sessions are open at once per
|
|
171
|
+
* project (1 on Free); one more waits in a queue up to 60 s. A session with no call for 60 s is closed; it lasts
|
|
172
|
+
* at most `timeoutMinutes`.
|
|
173
|
+
*
|
|
174
|
+
* Totalum-synthesised options (Totalum applies them to every page, so the browser provider validates none of them):
|
|
175
|
+
* `locale`, `timezone`, `geolocation`, `userAgent`, `extraHeaders`, `blockResources`, `device`, `captureDownloads`,
|
|
176
|
+
* `viewport`. Mapped onto vendor fields: `stealth` (`'off' | 'basic' | 'verified'`; `'verified'` needs a higher
|
|
177
|
+
* provider tier, else `STEALTH_TIER_UNAVAILABLE`, and ignores `viewport`) and `region` (four regions; `'eu'` and
|
|
178
|
+
* `'us'` are aliases). Every other option is passed to the browser provider as is.
|
|
179
|
+
*
|
|
180
|
+
* @param opts - Proxy, CAPTCHA solving, stealth, region, a saved profile, emulation and recording options; all
|
|
181
|
+
* optional.
|
|
182
|
+
* @returns The session handle.
|
|
183
|
+
* @throws SESSION_LIMIT_REACHED (429) `timeoutMinutes` is above the plan's longest session (15 min on Free, 60 on
|
|
184
|
+
* Starter, 180 on Builder, 360 on Professional and Enterprise).
|
|
185
|
+
* @throws CONCURRENCY_QUEUE_TIMEOUT (429) The plan's sessions at once were busy for 60 s; retry after `details.retryAfter`
|
|
186
|
+
* seconds, or open fewer sessions.
|
|
187
|
+
* @throws CONCURRENCY_QUEUE_FULL (429) Too many sessions waiting already.
|
|
188
|
+
* @throws RATE_LIMIT_EXCEEDED (429) The plan's new sessions per minute or monthly browser minutes are used up.
|
|
189
|
+
* @throws STEALTH_TIER_UNAVAILABLE (409) `stealth: 'verified'` is not available.
|
|
190
|
+
* @throws PROVIDER_UNAVAILABLE (503) The browser did not start; retry.
|
|
191
|
+
* @example
|
|
192
|
+
* const s = await totalum.browser.session({ locale: 'es-ES', timezone: 'Europe/Madrid' });
|
|
193
|
+
* try {
|
|
194
|
+
* await s.goto('https://example.com');
|
|
195
|
+
* const info = await s.pageInfo();
|
|
196
|
+
* } finally {
|
|
197
|
+
* await s.close();
|
|
198
|
+
* }
|
|
199
|
+
* //=>
|
|
200
|
+
* {
|
|
201
|
+
* id: 'bs_a285ef5dfce1d3837b913a887a384298',
|
|
202
|
+
* liveViewUrl: 'https://sdk-api.totalum.app/v1/browser/live/eyJzIjoiYnNfYTI4NWVm…',
|
|
203
|
+
* expiresAt: '2026-10-11T17:56:24.666Z',
|
|
204
|
+
* goto: [Function], click: [Function], …, close: [Function]
|
|
205
|
+
* }
|
|
162
206
|
*/
|
|
163
207
|
session: async (opts = {}) => handle(await call('POST', '/v1/browser/sessions', opts)),
|
|
164
208
|
sessions: {
|
|
165
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* The project's sessions, newest first — open ones and the history — filtered by `status` or `metadata`. Free.
|
|
211
|
+
*
|
|
212
|
+
* @param q - Filters and paging; all optional.
|
|
213
|
+
* @param q.status - Only sessions in this state: `running`, `ended`, `expired` or `failed`.
|
|
214
|
+
* @param q.metadata - Only sessions with this metadata entry, as `key:value` (`'orderId:ord_42'`).
|
|
215
|
+
* @param q.limit - Sessions per page.
|
|
216
|
+
* @param q.cursor - The previous page's `nextCursor`.
|
|
217
|
+
* @returns One page of sessions.
|
|
218
|
+
* @throws VALIDATION_ERROR (400) A filter is malformed.
|
|
219
|
+
* @example
|
|
220
|
+
* const { items } = await totalum.browser.sessions.list({ status: 'running', limit: 2 });
|
|
221
|
+
* //=>
|
|
222
|
+
* {
|
|
223
|
+
* "items": [
|
|
224
|
+
* { "id": "bs_20b6813a9f10ce41b3ff002d80e911c4", "status": "ended", "region": "us-west-2", "metadata": null, "startedAt": "2026-09-28T13:18:46.849Z", "expiresAt": "2026-09-28T13:33:46.244Z", "minutes": 1, "proxyMb": 0, "captchas": 0, "credits": 0.056 }
|
|
225
|
+
* ],
|
|
226
|
+
* "nextCursor": "1790600898279:bs_8cbb1dd693454f4fd82fedbfb9671d0c"
|
|
227
|
+
* }
|
|
228
|
+
*/
|
|
166
229
|
list: (q = {}) => call('GET', `/v1/browser/sessions${query(q)}`),
|
|
167
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* A handle on an existing session, to keep driving it from another request (the id was stored). No call is made;
|
|
232
|
+
* the first command fails with `SESSION_EXPIRED` if it has ended. Calling a command also keeps it from closing
|
|
233
|
+
* after 60 s idle.
|
|
234
|
+
*
|
|
235
|
+
* @param id - The session's `id`.
|
|
236
|
+
* @returns The session handle (`liveViewUrl` and `expiresAt` are empty: read `status()`).
|
|
237
|
+
* @example
|
|
238
|
+
* const s = totalum.browser.sessions.get(job.browserSessionId);
|
|
239
|
+
* await s.click({ text: 'Next page' });
|
|
240
|
+
*/
|
|
168
241
|
get: (id) => handle({ id }),
|
|
169
242
|
},
|
|
170
243
|
programs: {
|
|
171
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* A program's status and, once finished, each step's result and the final variables. Free.
|
|
246
|
+
*
|
|
247
|
+
* @param programId - The `programId` from `s.program()`.
|
|
248
|
+
* @returns The program's status and results.
|
|
249
|
+
* @throws PROGRAM_NOT_FOUND (404) No such program in this project.
|
|
250
|
+
* @example
|
|
251
|
+
* const p = await totalum.browser.programs.get('bp_a285ef5dfce1d3837b913a887a384298_3982732f');
|
|
252
|
+
* //=>
|
|
253
|
+
* {
|
|
254
|
+
* "programId": "bp_a285ef5dfce1d3837b913a887a384298_3982732f",
|
|
255
|
+
* "sessionId": "bs_a285ef5dfce1d3837b913a887a384298",
|
|
256
|
+
* "status": "completed",
|
|
257
|
+
* "steps": [
|
|
258
|
+
* { "index": 0, "type": "goto", "ok": true, "data": { "url": "https://example.com/", "status": 200, "redirected": false } },
|
|
259
|
+
* { "index": 1, "type": "pageInfo", "ok": true, "data": { "url": "https://example.com/", "title": "Example Domain", … } }
|
|
260
|
+
* ],
|
|
261
|
+
* "vars": {},
|
|
262
|
+
* "startedAt": "2026-10-11T17:42:25.605Z",
|
|
263
|
+
* "endedAt": "2026-10-11T17:42:27.912Z",
|
|
264
|
+
* "credits": 0
|
|
265
|
+
* }
|
|
266
|
+
*/
|
|
172
267
|
get: (programId) => call('GET', `/v1/browser/programs/${encodeURIComponent(programId)}`),
|
|
173
|
-
/**
|
|
268
|
+
/**
|
|
269
|
+
* Polls a program until it leaves `pending`/`running` and returns it (the `browser.program.completed` webhook is
|
|
270
|
+
* the push alternative). Keep it within a request's time: programs run at most 60 s.
|
|
271
|
+
*
|
|
272
|
+
* @param programId - The `programId` from `s.program()`.
|
|
273
|
+
* @param opts - How often and how long to poll.
|
|
274
|
+
* @param opts.intervalMs - Milliseconds between polls. Default 2000.
|
|
275
|
+
* @param opts.timeoutMs - Stop polling after this long and return the program as it is. Default 960000.
|
|
276
|
+
* @returns The finished program (or as it is when the timeout passed).
|
|
277
|
+
* @throws PROGRAM_NOT_FOUND (404) No such program in this project.
|
|
278
|
+
* @example
|
|
279
|
+
* const done = await totalum.browser.programs.wait(programId, { intervalMs: 1000 });
|
|
280
|
+
* //=>
|
|
281
|
+
* { "programId": "bp_a285ef5dfce1d3837b913a887a384298_3982732f", "status": "completed", "steps": [ … ], "vars": {}, "credits": 0, … }
|
|
282
|
+
*/
|
|
174
283
|
wait: async (programId, opts = {}) => {
|
|
175
284
|
const until = Date.now() + (opts.timeoutMs ?? 960_000);
|
|
176
285
|
for (;;) {
|