totalum-sdk 1.11.0 → 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 +9 -0
- package/dist/_types/{coerce.d-BKhuaDya.d.ts → coerce.d-D_rylvPs.d.ts} +1 -1
- package/dist/_types/{errors.d-RTRkidv5.d.ts → errors.d-BPpY5QKu.d.ts} +20 -2
- package/dist/_types/{integrations.d-CzTa9T-L.d.ts → integrations.d-BTZHy48D.d.ts} +2 -2
- package/dist/_types/{ops.d-CNsrT4Ma.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 +208 -18
- package/dist/browser/index.js +122 -13
- package/dist/connections/index.d.ts +305 -23
- package/dist/connections/index.js +302 -21
- 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 +24 -9
- package/dist/index.js +19 -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 +2 -1
- package/totalum-sdk.md +8841 -754
- package/totalum-sdk.signatures.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZodObject, e as ZodArray, j as ZodBoolean, c as ZodOptional, g as ZodUnknown, f as ZodEnum, d as ZodString, m as $strip, l as ZodInt, o as output, $ as $loose, s as ZodType, t as $ZodTypeInternals, h as ZodRecord, p as ZodURL, u as ZodISODateTime, k as ZodNumber, r as ZodLiteral, T as TotalumClientOptions } from '../_types/errors.d-
|
|
2
|
-
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-
|
|
1
|
+
import { Z as ZodObject, e as ZodArray, j as ZodBoolean, c as ZodOptional, g as ZodUnknown, f as ZodEnum, d as ZodString, m as $strip, l as ZodInt, o as output, $ as $loose, s as ZodType, t as $ZodTypeInternals, h as ZodRecord, p as ZodURL, u as ZodISODateTime, k as ZodNumber, r as ZodLiteral, T as TotalumClientOptions } from '../_types/errors.d-BPpY5QKu.js';
|
|
2
|
+
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-BPpY5QKu.js';
|
|
3
3
|
|
|
4
4
|
declare const BrowserCommandName: ZodEnum<{
|
|
5
5
|
type: "type";
|
|
@@ -1621,24 +1621,101 @@ type Group<K extends string> = K extends `${infer G}.${infer M}` ? {
|
|
|
1621
1621
|
[P in G]: Record<M, Command>;
|
|
1622
1622
|
} : Record<K, Command>;
|
|
1623
1623
|
type Merge<U> = (U extends unknown ? (u: U) => void : never) extends (u: infer I) => void ? I : never;
|
|
1624
|
-
/**
|
|
1624
|
+
/**
|
|
1625
|
+
* The command methods of a session: one per command (`goto`, `click`, … `tabs.new`, `network.har`, …), named like the
|
|
1626
|
+
* command; dotted commands are groups (`s.tabs.new()`). See the session commands table under `BrowserSession`.
|
|
1627
|
+
*/
|
|
1625
1628
|
type BrowserCommands = Merge<Group<BrowserCommandName>>;
|
|
1629
|
+
/**
|
|
1630
|
+
* An open cloud-browser session, from `browser.session()` or `browser.sessions.get(id)`: its id and live view, the
|
|
1631
|
+
* methods below, and one method per command (the table below). Each method is one HTTPS call. Always `close()` it in
|
|
1632
|
+
* `finally`: an open session is billed per minute until it closes (or until 60 s pass with no call).
|
|
1633
|
+
*/
|
|
1626
1634
|
type BrowserSession = BrowserCommands & {
|
|
1635
|
+
/** The session id (`bs_…`): pass it to `browser.sessions.get(id)` to drive the same session from another request. */
|
|
1627
1636
|
readonly id: string;
|
|
1637
|
+
/** A signed link to watch the session live (and take over: a user can solve a login step), valid a few minutes. `''` on a handle from `sessions.get`. */
|
|
1628
1638
|
readonly liveViewUrl: string;
|
|
1639
|
+
/** When the session ends at the latest (its `timeoutMinutes`). `''` on a handle from `sessions.get`. */
|
|
1629
1640
|
readonly expiresAt: string;
|
|
1630
|
-
/**
|
|
1641
|
+
/**
|
|
1642
|
+
* Runs up to 20 commands in one round trip, in order, under the session's lock, and returns every result instead of
|
|
1643
|
+
* throwing: faster than one call per command. With `stopOnError` (the default), the commands after a failure are
|
|
1644
|
+
* not run and answer `SKIPPED`.
|
|
1645
|
+
*
|
|
1646
|
+
* @param batch - The commands: `{ type, …parameters }` each (`{ type: 'goto', url }`, `{ type: 'click', target }`).
|
|
1647
|
+
* @param opts - `stopOnError`.
|
|
1648
|
+
* @param opts.stopOnError - Stop at the first failing command. Default `true`.
|
|
1649
|
+
* @returns One result per command, in order: `{ ok: true, data }` or `{ ok: false, error: { code, message } }`.
|
|
1650
|
+
* @throws BATCH_TOO_LARGE (400) More than 20 commands.
|
|
1651
|
+
* @throws SESSION_BUSY (409) Another command or batch is running on this session.
|
|
1652
|
+
* @throws SESSION_EXPIRED (410) The session has ended: open a new one.
|
|
1653
|
+
* @throws UNKNOWN_COMMAND (400) A `type` is not one of the commands.
|
|
1654
|
+
* @example
|
|
1655
|
+
* const results = await s.actions([
|
|
1656
|
+
* { type: 'goto', url: 'https://example.com' },
|
|
1657
|
+
* { type: 'evaluate', expression: '1 + 1' },
|
|
1658
|
+
* ]);
|
|
1659
|
+
* //=>
|
|
1660
|
+
* [
|
|
1661
|
+
* { "ok": true, "data": { "url": "https://example.com/", "status": 200, "redirected": false } },
|
|
1662
|
+
* { "ok": true, "data": 2 }
|
|
1663
|
+
* ]
|
|
1664
|
+
*/
|
|
1631
1665
|
actions(batch: BrowserCommand[], opts?: {
|
|
1632
1666
|
stopOnError?: boolean;
|
|
1633
1667
|
}): Promise<BrowserCommandResult[]>;
|
|
1634
|
-
/**
|
|
1668
|
+
/**
|
|
1669
|
+
* Starts a program on the session: a list of steps (commands, plus bounded `repeat`, `if`, `try` and `set`) that runs
|
|
1670
|
+
* in the background — data, never code — so a long task outlives the request. Read it with
|
|
1671
|
+
* `browser.programs.get(programId)` / `programs.wait`, or receive the `browser.program.completed` webhook.
|
|
1672
|
+
*
|
|
1673
|
+
* @param program - The steps, variables, time limit and webhook.
|
|
1674
|
+
* @returns The program id and where to poll it.
|
|
1675
|
+
* @throws PROGRAM_TOO_LARGE (400) More than 200 steps or nesting deeper than 5.
|
|
1676
|
+
* @throws PROGRAM_UNBOUNDED (400) A `repeat` without `max` (≤ 100) and exactly one of `times` / `until`.
|
|
1677
|
+
* @throws UNKNOWN_STEP (400) A step that is not `do`, `repeat`, `if`, `try` or `set`.
|
|
1678
|
+
* @throws PROGRAM_IN_FLIGHT (409) A program is already running on this session.
|
|
1679
|
+
* @throws PROGRAM_LIMIT_REACHED (429) The plan's programs at once (or per hour) are reached.
|
|
1680
|
+
* @example
|
|
1681
|
+
* const { programId } = await s.program({
|
|
1682
|
+
* steps: [
|
|
1683
|
+
* { do: { type: 'goto', url: 'https://example.com' } },
|
|
1684
|
+
* { do: { type: 'pageInfo' } },
|
|
1685
|
+
* ],
|
|
1686
|
+
* });
|
|
1687
|
+
* const done = await totalum.browser.programs.wait(programId);
|
|
1688
|
+
* //=>
|
|
1689
|
+
* { "programId": "bp_a285ef5dfce1d3837b913a887a384298_3982732f", "status": "pending", "pollUrl": "https://sdk-api.totalum.app/v1/browser/programs/bp_a285ef5dfce1d3837b913a887a384298_3982732f" }
|
|
1690
|
+
*/
|
|
1635
1691
|
program(program: BrowserProgram): Promise<BrowserProgramCreated>;
|
|
1692
|
+
/**
|
|
1693
|
+
* The session's state and what it has used so far (minutes, proxy MB, CAPTCHAs, credits). Also keeps an idle session
|
|
1694
|
+
* open: a session with no call for 60 s is closed.
|
|
1695
|
+
*
|
|
1696
|
+
* @returns The session's status.
|
|
1697
|
+
* @throws SESSION_NOT_FOUND (404) No such session in this project.
|
|
1698
|
+
* @example
|
|
1699
|
+
* const status = await s.status();
|
|
1700
|
+
* //=>
|
|
1701
|
+
* { "id": "bs_a285ef5dfce1d3837b913a887a384298", "status": "running", "startedAt": "2026-10-11T17:41:24.666Z", "minutes": 1, "proxyMb": 0, "captchas": 0, "credits": 0.1647, "expiresAt": "2026-10-11T17:56:24.666Z" }
|
|
1702
|
+
*/
|
|
1636
1703
|
status(): Promise<BrowserSessionStatus>;
|
|
1704
|
+
/**
|
|
1705
|
+
* Ends the session and settles its charge. Always call it in `finally`: an open session is billed per started minute.
|
|
1706
|
+
*
|
|
1707
|
+
* @returns What the session used and cost.
|
|
1708
|
+
* @throws SESSION_NOT_FOUND (404) No such session in this project.
|
|
1709
|
+
* @example
|
|
1710
|
+
* const closed = await s.close();
|
|
1711
|
+
* //=>
|
|
1712
|
+
* { "minutes": 2, "proxyMb": 0, "captchas": 0, "creditsUsed": 0.279 }
|
|
1713
|
+
*/
|
|
1637
1714
|
close(): Promise<BrowserSessionClosed>;
|
|
1638
1715
|
};
|
|
1639
1716
|
/**
|
|
1640
|
-
* `
|
|
1641
|
-
* over HTTPS, so every command works from a Worker. A command's refusal throws `TotalumError` with its frozen
|
|
1717
|
+
* Creates the `browser` namespace (the same object as `totalum.browser`, scope `browser`): remote browser sessions
|
|
1718
|
+
* driven entirely over HTTPS, so every command works from a Worker. A command's refusal throws `TotalumError` with its frozen
|
|
1642
1719
|
* code (`ACTION_TIMEOUT`, `ACTION_FAILED`, …); `actions()` returns every result instead.
|
|
1643
1720
|
*
|
|
1644
1721
|
* #### Things that still need a CDP connection
|
|
@@ -1651,37 +1728,136 @@ type BrowserSession = BrowserCommands & {
|
|
|
1651
1728
|
*
|
|
1652
1729
|
* #### Not possible for anyone, over any transport
|
|
1653
1730
|
*
|
|
1654
|
-
* - Seeding a saved profile from raw bytes (`CONTEXT_SEED_UNSUPPORTED`) — the
|
|
1731
|
+
* - 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).
|
|
1732
|
+
*
|
|
1733
|
+
* @param options - The project key, API URL and environment; each falls back to its environment variable.
|
|
1734
|
+
* @returns The `browser` namespace: the methods below.
|
|
1735
|
+
* @example
|
|
1736
|
+
* import { totalumBrowser } from 'totalum-sdk/browser';
|
|
1737
|
+
*
|
|
1738
|
+
* const browser = totalumBrowser();
|
|
1739
|
+
* const s = await browser.session();
|
|
1740
|
+
* try {
|
|
1741
|
+
* await s.goto('https://example.com');
|
|
1742
|
+
* } finally {
|
|
1743
|
+
* await s.close();
|
|
1744
|
+
* }
|
|
1655
1745
|
*/
|
|
1656
1746
|
declare function totalumBrowser(options?: TotalumClientOptions): {
|
|
1657
1747
|
/**
|
|
1658
|
-
* Opens a session.
|
|
1659
|
-
*
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1748
|
+
* Opens a session. It returns the cloud browser's handle: call commands on it (`s.goto(url)`, `s.click(target)`,
|
|
1749
|
+
* …) and `close()` it in `finally`. Billed per started minute while open. At most 3 sessions are open at once per
|
|
1750
|
+
* 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
|
|
1751
|
+
* at most `timeoutMinutes`.
|
|
1752
|
+
*
|
|
1753
|
+
* Totalum-synthesised options (Totalum applies them to every page, so the browser provider validates none of them):
|
|
1754
|
+
* `locale`, `timezone`, `geolocation`, `userAgent`, `extraHeaders`, `blockResources`, `device`, `captureDownloads`,
|
|
1755
|
+
* `viewport`. Mapped onto vendor fields: `stealth` (`'off' | 'basic' | 'verified'`; `'verified'` needs a higher
|
|
1756
|
+
* provider tier, else `STEALTH_TIER_UNAVAILABLE`, and ignores `viewport`) and `region` (four regions; `'eu'` and
|
|
1757
|
+
* `'us'` are aliases). Every other option is passed to the browser provider as is.
|
|
1758
|
+
*
|
|
1759
|
+
* @param opts - Proxy, CAPTCHA solving, stealth, region, a saved profile, emulation and recording options; all
|
|
1760
|
+
* optional.
|
|
1761
|
+
* @returns The session handle.
|
|
1762
|
+
* @throws SESSION_LIMIT_REACHED (429) `timeoutMinutes` is above the plan's longest session (15 min on Free, 60 on
|
|
1763
|
+
* Starter, 180 on Builder, 360 on Professional and Enterprise).
|
|
1764
|
+
* @throws CONCURRENCY_QUEUE_TIMEOUT (429) The plan's sessions at once were busy for 60 s; retry after `details.retryAfter`
|
|
1765
|
+
* seconds, or open fewer sessions.
|
|
1766
|
+
* @throws CONCURRENCY_QUEUE_FULL (429) Too many sessions waiting already.
|
|
1767
|
+
* @throws RATE_LIMIT_EXCEEDED (429) The plan's new sessions per minute or monthly browser minutes are used up.
|
|
1768
|
+
* @throws STEALTH_TIER_UNAVAILABLE (409) `stealth: 'verified'` is not available.
|
|
1769
|
+
* @throws PROVIDER_UNAVAILABLE (503) The browser did not start; retry.
|
|
1770
|
+
* @example
|
|
1771
|
+
* const s = await totalum.browser.session({ locale: 'es-ES', timezone: 'Europe/Madrid' });
|
|
1772
|
+
* try {
|
|
1773
|
+
* await s.goto('https://example.com');
|
|
1774
|
+
* const info = await s.pageInfo();
|
|
1775
|
+
* } finally {
|
|
1776
|
+
* await s.close();
|
|
1777
|
+
* }
|
|
1778
|
+
* //=>
|
|
1779
|
+
* {
|
|
1780
|
+
* id: 'bs_a285ef5dfce1d3837b913a887a384298',
|
|
1781
|
+
* liveViewUrl: 'https://sdk-api.totalum.app/v1/browser/live/eyJzIjoiYnNfYTI4NWVm…',
|
|
1782
|
+
* expiresAt: '2026-10-11T17:56:24.666Z',
|
|
1783
|
+
* goto: [Function], click: [Function], …, close: [Function]
|
|
1784
|
+
* }
|
|
1664
1785
|
*/
|
|
1665
1786
|
session: (opts?: BrowserSessionInput) => Promise<BrowserSession>;
|
|
1666
1787
|
sessions: {
|
|
1667
|
-
/**
|
|
1788
|
+
/**
|
|
1789
|
+
* The project's sessions, newest first — open ones and the history — filtered by `status` or `metadata`. Free.
|
|
1790
|
+
*
|
|
1791
|
+
* @param q - Filters and paging; all optional.
|
|
1792
|
+
* @param q.status - Only sessions in this state: `running`, `ended`, `expired` or `failed`.
|
|
1793
|
+
* @param q.metadata - Only sessions with this metadata entry, as `key:value` (`'orderId:ord_42'`).
|
|
1794
|
+
* @param q.limit - Sessions per page.
|
|
1795
|
+
* @param q.cursor - The previous page's `nextCursor`.
|
|
1796
|
+
* @returns One page of sessions.
|
|
1797
|
+
* @throws VALIDATION_ERROR (400) A filter is malformed.
|
|
1798
|
+
* @example
|
|
1799
|
+
* const { items } = await totalum.browser.sessions.list({ status: 'running', limit: 2 });
|
|
1800
|
+
* //=>
|
|
1801
|
+
* {
|
|
1802
|
+
* "items": [
|
|
1803
|
+
* { "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 }
|
|
1804
|
+
* ],
|
|
1805
|
+
* "nextCursor": "1790600898279:bs_8cbb1dd693454f4fd82fedbfb9671d0c"
|
|
1806
|
+
* }
|
|
1807
|
+
*/
|
|
1668
1808
|
list: (q?: {
|
|
1669
1809
|
status?: string;
|
|
1670
1810
|
metadata?: string;
|
|
1671
1811
|
limit?: number;
|
|
1672
1812
|
cursor?: string;
|
|
1673
1813
|
}) => Promise<{
|
|
1814
|
+
/** The sessions, newest first: each one's status and usage, plus its region and metadata. */
|
|
1674
1815
|
items: (BrowserSessionStatus & {
|
|
1816
|
+
/** Where it runs. */
|
|
1675
1817
|
region: string;
|
|
1818
|
+
/** The `metadata` it was opened with, or `null`. */
|
|
1676
1819
|
metadata: Record<string, string> | null;
|
|
1677
1820
|
})[];
|
|
1821
|
+
/** Pass it as `cursor` for the next page; absent on the last. */
|
|
1678
1822
|
nextCursor?: string;
|
|
1679
1823
|
}>;
|
|
1680
|
-
/**
|
|
1824
|
+
/**
|
|
1825
|
+
* A handle on an existing session, to keep driving it from another request (the id was stored). No call is made;
|
|
1826
|
+
* the first command fails with `SESSION_EXPIRED` if it has ended. Calling a command also keeps it from closing
|
|
1827
|
+
* after 60 s idle.
|
|
1828
|
+
*
|
|
1829
|
+
* @param id - The session's `id`.
|
|
1830
|
+
* @returns The session handle (`liveViewUrl` and `expiresAt` are empty: read `status()`).
|
|
1831
|
+
* @example
|
|
1832
|
+
* const s = totalum.browser.sessions.get(job.browserSessionId);
|
|
1833
|
+
* await s.click({ text: 'Next page' });
|
|
1834
|
+
*/
|
|
1681
1835
|
get: (id: string) => BrowserSession;
|
|
1682
1836
|
};
|
|
1683
1837
|
programs: {
|
|
1684
|
-
/**
|
|
1838
|
+
/**
|
|
1839
|
+
* A program's status and, once finished, each step's result and the final variables. Free.
|
|
1840
|
+
*
|
|
1841
|
+
* @param programId - The `programId` from `s.program()`.
|
|
1842
|
+
* @returns The program's status and results.
|
|
1843
|
+
* @throws PROGRAM_NOT_FOUND (404) No such program in this project.
|
|
1844
|
+
* @example
|
|
1845
|
+
* const p = await totalum.browser.programs.get('bp_a285ef5dfce1d3837b913a887a384298_3982732f');
|
|
1846
|
+
* //=>
|
|
1847
|
+
* {
|
|
1848
|
+
* "programId": "bp_a285ef5dfce1d3837b913a887a384298_3982732f",
|
|
1849
|
+
* "sessionId": "bs_a285ef5dfce1d3837b913a887a384298",
|
|
1850
|
+
* "status": "completed",
|
|
1851
|
+
* "steps": [
|
|
1852
|
+
* { "index": 0, "type": "goto", "ok": true, "data": { "url": "https://example.com/", "status": 200, "redirected": false } },
|
|
1853
|
+
* { "index": 1, "type": "pageInfo", "ok": true, "data": { "url": "https://example.com/", "title": "Example Domain", … } }
|
|
1854
|
+
* ],
|
|
1855
|
+
* "vars": {},
|
|
1856
|
+
* "startedAt": "2026-10-11T17:42:25.605Z",
|
|
1857
|
+
* "endedAt": "2026-10-11T17:42:27.912Z",
|
|
1858
|
+
* "credits": 0
|
|
1859
|
+
* }
|
|
1860
|
+
*/
|
|
1685
1861
|
get: (programId: string) => Promise<{
|
|
1686
1862
|
programId: string;
|
|
1687
1863
|
sessionId: string;
|
|
@@ -1702,7 +1878,21 @@ declare function totalumBrowser(options?: TotalumClientOptions): {
|
|
|
1702
1878
|
result?: unknown;
|
|
1703
1879
|
endedAt?: string | undefined;
|
|
1704
1880
|
}>;
|
|
1705
|
-
/**
|
|
1881
|
+
/**
|
|
1882
|
+
* Polls a program until it leaves `pending`/`running` and returns it (the `browser.program.completed` webhook is
|
|
1883
|
+
* the push alternative). Keep it within a request's time: programs run at most 60 s.
|
|
1884
|
+
*
|
|
1885
|
+
* @param programId - The `programId` from `s.program()`.
|
|
1886
|
+
* @param opts - How often and how long to poll.
|
|
1887
|
+
* @param opts.intervalMs - Milliseconds between polls. Default 2000.
|
|
1888
|
+
* @param opts.timeoutMs - Stop polling after this long and return the program as it is. Default 960000.
|
|
1889
|
+
* @returns The finished program (or as it is when the timeout passed).
|
|
1890
|
+
* @throws PROGRAM_NOT_FOUND (404) No such program in this project.
|
|
1891
|
+
* @example
|
|
1892
|
+
* const done = await totalum.browser.programs.wait(programId, { intervalMs: 1000 });
|
|
1893
|
+
* //=>
|
|
1894
|
+
* { "programId": "bp_a285ef5dfce1d3837b913a887a384298_3982732f", "status": "completed", "steps": [ … ], "vars": {}, "credits": 0, … }
|
|
1895
|
+
*/
|
|
1706
1896
|
wait: (programId: string, opts?: {
|
|
1707
1897
|
intervalMs?: number;
|
|
1708
1898
|
timeoutMs?: number;
|
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 (;;) {
|