@hunt-labs/bytekit-sdk 0.1.0 → 0.2.2

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +21 -0
  3. package/README.md +171 -0
  4. package/dist/allowlist.d.ts +0 -1
  5. package/dist/allowlist.js +0 -1
  6. package/dist/client.d.ts +69 -10
  7. package/dist/client.js +224 -13
  8. package/dist/generated/api.d.ts +6607 -0
  9. package/dist/index.d.ts +8 -2
  10. package/dist/index.js +3 -2
  11. package/dist/resources/account.d.ts +50 -9
  12. package/dist/resources/account.js +17 -3
  13. package/dist/resources/bulk.d.ts +0 -1
  14. package/dist/resources/bulk.js +0 -1
  15. package/dist/resources/fetch.d.ts +0 -1
  16. package/dist/resources/fetch.js +0 -1
  17. package/dist/resources/monitors.d.ts +0 -1
  18. package/dist/resources/monitors.js +0 -1
  19. package/dist/resources/scrape.d.ts +50 -8
  20. package/dist/resources/scrape.js +30 -7
  21. package/dist/resources/screenshots.d.ts +54 -4
  22. package/dist/resources/screenshots.js +6 -2
  23. package/dist/resources/search.d.ts +0 -1
  24. package/dist/resources/search.js +0 -1
  25. package/dist/resources/sitemap.d.ts +0 -1
  26. package/dist/resources/sitemap.js +0 -1
  27. package/dist/types.d.ts +0 -1
  28. package/dist/types.js +0 -1
  29. package/package.json +28 -11
  30. package/dist/allowlist.d.ts.map +0 -1
  31. package/dist/allowlist.js.map +0 -1
  32. package/dist/client.d.ts.map +0 -1
  33. package/dist/client.js.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js.map +0 -1
  36. package/dist/resources/account.d.ts.map +0 -1
  37. package/dist/resources/account.js.map +0 -1
  38. package/dist/resources/bulk.d.ts.map +0 -1
  39. package/dist/resources/bulk.js.map +0 -1
  40. package/dist/resources/fetch.d.ts.map +0 -1
  41. package/dist/resources/fetch.js.map +0 -1
  42. package/dist/resources/monitors.d.ts.map +0 -1
  43. package/dist/resources/monitors.js.map +0 -1
  44. package/dist/resources/recordings.d.ts +0 -11
  45. package/dist/resources/recordings.d.ts.map +0 -1
  46. package/dist/resources/recordings.js +0 -15
  47. package/dist/resources/recordings.js.map +0 -1
  48. package/dist/resources/scrape.d.ts.map +0 -1
  49. package/dist/resources/scrape.js.map +0 -1
  50. package/dist/resources/screenshots.d.ts.map +0 -1
  51. package/dist/resources/screenshots.js.map +0 -1
  52. package/dist/resources/search.d.ts.map +0 -1
  53. package/dist/resources/search.js.map +0 -1
  54. package/dist/resources/sitemap.d.ts.map +0 -1
  55. package/dist/resources/sitemap.js.map +0 -1
  56. package/dist/types.d.ts.map +0 -1
  57. package/dist/types.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@hunt-labs/bytekit-sdk` are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ This file records only the delta between versions. For how to use the package
9
+ today, see [README.md](./README.md), which remains the authoritative usage guide.
10
+
11
+ ## [0.2.2] - 2026-07-16
12
+
13
+ ### Changed
14
+
15
+ - Re-release of 0.2.1. The 0.2.1 artifacts never reached npm — the prod publish's
16
+ `publish-sdk` step failed on a CI test-isolation flake (`cjs-require.test.ts`
17
+ rebuilding the shared `dist`), which is now fixed. No consumer-facing changes
18
+ beyond 0.2.1.
19
+
20
+ ## [0.2.1] - 2026-07-16
21
+
22
+ ### Changed
23
+
24
+ - Primary exports renamed `RapidCrawl`→`ByteKit`, `RapidCrawlError`→`ByteKitError`,
25
+ `RapidCrawlOptions`→`ByteKitOptions`. The old names remain as deprecated,
26
+ identity-preserving aliases (`RapidCrawl === ByteKit`), so existing imports keep
27
+ working. (#2421)
28
+
29
+ ### Fixed
30
+
31
+ - `request()` now returns `undefined` on `204 No Content` / empty-body responses
32
+ instead of throwing a JSON-parse error — `account.apiKeys.revoke()` now resolves
33
+ as its `Promise<void>` contract declares. (#2450)
34
+
35
+ ### Removed
36
+
37
+ - `client.recordings` (the `/v1/recordings` endpoint is permanently `410`
38
+ deactivated). (#2421)
39
+
40
+ ## [0.2.0] - 2026-07-15
41
+
42
+ This is a breaking release. Four runtime behavior changes affect code written
43
+ against 0.1.0 — read each one before upgrading.
44
+
45
+ ### Changed (breaking)
46
+
47
+ - **Default client-side timeout (120s).** Requests now abort after 120000 ms by
48
+ default (`DEFAULT_TIMEOUT_MS` in `src/client.ts`); 0.1.0 had no client-side
49
+ timeout and would hang indefinitely. A slow request now rejects with
50
+ `RapidCrawlConnectionError` carrying `code: 'timeout'`. Override per client via
51
+ `new RapidCrawl({ apiKey, timeoutMs })`.
52
+ - **Network failures throw `RapidCrawlConnectionError`.** Every `fetch()` rejection
53
+ is now wrapped by `toConnectionError()` and re-thrown as `RapidCrawlConnectionError`.
54
+ 0.1.0 surfaced undici's bare `TypeError: fetch failed`. Code that matched on a bare
55
+ `TypeError` to detect a network failure will no longer match — catch
56
+ `RapidCrawlConnectionError` instead.
57
+ - **Constructor throws on an empty `apiKey`.** `new RapidCrawl({ apiKey: '' })` (or a
58
+ missing key) now throws a `TypeError` immediately instead of silently sending
59
+ `Authorization: Bearer undefined`. Ensure `apiKey` is populated (e.g. from
60
+ `process.env.BYTEKIT_API_KEY`) before constructing the client.
61
+ - **Request-body types narrowed to the OpenAPI schema.** Request payloads are now
62
+ typed from spec-derived types generated from the OpenAPI schema
63
+ (`src/generated/api.d.ts`) rather than `Record<string, unknown>`. Payloads that
64
+ previously compiled by virtue of the loose index type may now be rejected by the
65
+ type checker; align them with the documented request shape.
66
+
67
+ ### Changed
68
+
69
+ - Package renamed to `@hunt-labs/bytekit-sdk` (the `@bytekit` npm scope was
70
+ unobtainable). The prior `rapidcrawl`/`@rapidcrawl/sdk` name remains installable at
71
+ its last version but is deprecated.
72
+ - Generated API types (`dist/generated/api.d.ts`) are now shipped in the tarball so
73
+ consumers get the typed request/response surface without regenerating from the spec.
74
+
75
+ ### Added
76
+
77
+ - Publish-ready packaging metadata: types-first `exports`, `engines`, `keywords`,
78
+ `homepage`, `bugs`, `README.md`, `LICENSE`, and an MIT `license` field.
79
+
80
+ ## [0.1.0] - 2026
81
+
82
+ ### Added
83
+
84
+ - Initial release of the ByteKit TypeScript SDK — a typed client for the ByteKit API
85
+ (scrape, screenshot, search, and related endpoints), published under the original
86
+ `@rapidcrawl/sdk` name.
87
+
88
+ [0.2.2]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/sdk-typescript
89
+ [0.2.1]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/sdk-typescript
90
+ [0.2.0]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/sdk-typescript
91
+ [0.1.0]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/sdk-typescript
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hunt Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # @hunt-labs/bytekit-sdk
2
+
3
+ Official TypeScript SDK for the [ByteKit](https://bytekit.com) API — web data
4
+ infrastructure for AI agents and training pipelines: scraping, raw fetch,
5
+ screenshots, sitemaps, page monitors, and web search.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @hunt-labs/bytekit-sdk
11
+ ```
12
+
13
+ > **ESM-only.** This package ships a single ESM build (`"type": "module"`) with
14
+ > no separate CommonJS bundle. Use it from an ESM project (`"type": "module"` in
15
+ > your `package.json`, or a `.mjs` entrypoint). From CommonJS you can either load
16
+ > it with a dynamic `await import('@hunt-labs/bytekit-sdk')`, or — on **Node
17
+ > ≥20.19 / ≥22.12**, which resolve `require()` of ESM — call a top-level
18
+ > `require('@hunt-labs/bytekit-sdk')` directly (the package's `exports` map
19
+ > carries a `default` condition for exactly this). On older Node, a top-level
20
+ > `require()` throws `ERR_REQUIRE_ESM`; use the dynamic `import()` there.
21
+
22
+ Requires Node.js 18+ (the client uses the global `fetch`).
23
+
24
+ ## Authentication
25
+
26
+ Create an API key at [app.bytekit.com](https://app.bytekit.com) (keys are
27
+ prefixed `sk_live_`) and pass it to the client constructor:
28
+
29
+ ```ts
30
+ import { RapidCrawl } from '@hunt-labs/bytekit-sdk';
31
+
32
+ const client = new RapidCrawl({ apiKey: process.env.BYTEKIT_API_KEY! }); // sk_live_...
33
+ ```
34
+
35
+ The key is sent as `Authorization: Bearer <apiKey>` on every request. Keep it
36
+ server-side — it is not safe to ship in a browser bundle.
37
+
38
+ > The client class is named `RapidCrawl` for historical reasons (ByteKit's
39
+ > previous product name). It is the SDK's only entrypoint class.
40
+
41
+ ## Base-URL override
42
+
43
+ Requests go to `https://api.bytekit.com` by default. Point the client at
44
+ staging, a local gateway, or a proxy with the `baseUrl` option:
45
+
46
+ ```ts
47
+ const client = new RapidCrawl({
48
+ apiKey: process.env.BYTEKIT_API_KEY!,
49
+ baseUrl: 'https://api-stg.bytekit.com', // default: https://api.bytekit.com
50
+ });
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ### Scrape a page
56
+
57
+ ```ts
58
+ const result = await client.scrape.create({
59
+ url: 'https://example.com',
60
+ formats: ['markdown', 'html'],
61
+ });
62
+ ```
63
+
64
+ ### Fetch an async scrape by id
65
+
66
+ ```ts
67
+ const scrape = await client.scrape.get('sc_123abc');
68
+ ```
69
+
70
+ ### Raw fetch (unprocessed response body)
71
+
72
+ ```ts
73
+ const raw = await client.fetch.create({ url: 'https://example.com' });
74
+ ```
75
+
76
+ ### Web search
77
+
78
+ ```ts
79
+ const results = await client.search.query({ query: 'ai web scraping', limit: 10 });
80
+ for (const hit of results.results) {
81
+ console.log(hit.position, hit.title, hit.url);
82
+ }
83
+ ```
84
+
85
+ ### Screenshot a page
86
+
87
+ ```ts
88
+ const shot = await client.screenshots.create({
89
+ url: 'https://example.com',
90
+ full_page: true,
91
+ });
92
+ const ready = await client.screenshots.get('ss_123abc');
93
+ ```
94
+
95
+ ### Bulk jobs
96
+
97
+ `scrape` and `fetch` each expose a `bulk` sub-resource that takes a URL list
98
+ and a webhook to notify on completion:
99
+
100
+ ```ts
101
+ const job = await client.scrape.bulk.create({
102
+ urls: ['https://example.com', 'https://example.org'],
103
+ webhook_url: 'https://your.app/hooks/bytekit',
104
+ });
105
+ const status = await client.scrape.bulk.get('bulk_123abc');
106
+ ```
107
+
108
+ `client.fetch.bulk.create()` / `client.fetch.bulk.get()` follow the same shape.
109
+
110
+ Bulk **screenshots** are not a `screenshots.bulk` sub-resource — they go
111
+ through the separate top-level `client.bulk` resource instead:
112
+
113
+ ```ts
114
+ const shots = await client.bulk.create({
115
+ urls: ['https://example.com', 'https://example.org'],
116
+ webhook_url: 'https://your.app/hooks/bytekit',
117
+ });
118
+ const shotStatus = await client.bulk.get('bulk_123abc');
119
+ await client.bulk.screenshots.list('bulk_123abc');
120
+ ```
121
+
122
+ ### Page monitors
123
+
124
+ ```ts
125
+ const monitor = await client.monitors.create({
126
+ url: 'https://example.com/pricing',
127
+ interval_type: 'daily',
128
+ webhook_url: 'https://your.app/hooks/bytekit',
129
+ });
130
+ await client.monitors.list();
131
+ await client.monitors.delete('mon_123abc');
132
+ ```
133
+
134
+ ### Sitemap crawl
135
+
136
+ ```ts
137
+ const crawl = await client.sitemap.create({ url: 'https://example.com' });
138
+ const sitemap = await client.sitemap.get('sm_123abc');
139
+ ```
140
+
141
+ ### Account, usage, and API keys
142
+
143
+ ```ts
144
+ const account = await client.account.get();
145
+ const keys = await client.account.apiKeys.list();
146
+ ```
147
+
148
+ ## Error handling
149
+
150
+ Any 4xx/5xx response throws a `RapidCrawlError` carrying the HTTP status and
151
+ the API's error code:
152
+
153
+ ```ts
154
+ import { RapidCrawl, RapidCrawlError } from '@hunt-labs/bytekit-sdk';
155
+
156
+ try {
157
+ await client.scrape.create({ url: 'https://example.com' });
158
+ } catch (err) {
159
+ if (err instanceof RapidCrawlError) {
160
+ console.error(err.status, err.code, err.message);
161
+ }
162
+ }
163
+ ```
164
+
165
+ ## Documentation
166
+
167
+ Full API reference: [bytekit.com/docs](https://bytekit.com/docs).
168
+
169
+ ## License
170
+
171
+ MIT — see [LICENSE](./LICENSE).
@@ -10,4 +10,3 @@
10
10
  */
11
11
  export declare const V01_METHODS: readonly ["scrape.create", "scrape.get", "screenshots.create", "screenshots.get", "bulk.create", "bulk.get", "bulk.cancel", "bulk.screenshots.list", "scrape.bulk.create", "scrape.bulk.get", "fetch.create", "fetch.get", "fetch.bulk.create", "fetch.bulk.get", "monitors.create", "monitors.list", "monitors.get", "monitors.update", "monitors.delete", "monitors.captures.list", "sitemap.create", "sitemap.get", "search.query", "account.get"];
12
12
  export type V01Method = (typeof V01_METHODS)[number];
13
- //# sourceMappingURL=allowlist.d.ts.map
package/dist/allowlist.js CHANGED
@@ -35,4 +35,3 @@ export const V01_METHODS = [
35
35
  'search.query',
36
36
  'account.get',
37
37
  ];
38
- //# sourceMappingURL=allowlist.js.map
package/dist/client.d.ts CHANGED
@@ -1,40 +1,99 @@
1
1
  import { ScrapeResource } from './resources/scrape.js';
2
2
  import { ScreenshotsResource } from './resources/screenshots.js';
3
- import { RecordingsResource } from './resources/recordings.js';
4
3
  import { BulkResource } from './resources/bulk.js';
5
4
  import { FetchResource } from './resources/fetch.js';
6
5
  import { MonitorsResource } from './resources/monitors.js';
7
6
  import { SitemapResource } from './resources/sitemap.js';
8
7
  import { SearchResource } from './resources/search.js';
9
8
  import { AccountResource } from './resources/account.js';
10
- export interface RapidCrawlOptions {
9
+ export interface ByteKitOptions {
11
10
  apiKey: string;
12
11
  baseUrl?: string;
12
+ /**
13
+ * Default CLIENT-SIDE request timeout in ms — the abort budget for the whole HTTP
14
+ * round-trip made by this SDK. `0` disables the SDK-side timeout. Default 120000.
15
+ *
16
+ * NOT the same thing as `ScrapeOpts.timeout_ms`, which is the SERVER-side budget the
17
+ * gateway applies to the scrape itself. Override per call with
18
+ * `RequestOptions.requestTimeoutMs`.
19
+ */
20
+ timeoutMs?: number;
21
+ }
22
+ /** Per-call overrides accepted by `request()` and by resource methods that opt in. */
23
+ export interface RequestOptions {
24
+ /**
25
+ * Caller-owned abort signal. When supplied WITHOUT a per-call `requestTimeoutMs`, it
26
+ * fully replaces the constructor timeout — supply `requestTimeoutMs` alongside it to
27
+ * keep a bound (the request then aborts on whichever fires first).
28
+ */
29
+ signal?: AbortSignal;
30
+ /**
31
+ * Per-call CLIENT-SIDE abort budget in ms. Wins over the constructor's `timeoutMs`.
32
+ * `0` disables the SDK-side timeout for this call.
33
+ *
34
+ * Deliberately NOT named `timeoutMs`: it rides on the same call as `ScrapeOpts.timeout_ms`
35
+ * (the SERVER-side scrape budget), and the two mean different things —
36
+ * `scrape.create({ timeout_ms: 30_000 }, { requestTimeoutMs: 5_000 })` says "let the
37
+ * server spend up to 30 s scraping, but give up on the wire after 5 s".
38
+ */
39
+ requestTimeoutMs?: number;
13
40
  }
41
+ /** Why a request never produced an HTTP response. */
42
+ export type ConnectionErrorCode = 'timeout' | 'aborted' | 'connection';
14
43
  /** Thrown when the API responds with a 4xx or 5xx status code. */
15
- export declare class RapidCrawlError extends Error {
44
+ export declare class ByteKitError extends Error {
16
45
  readonly status: number;
17
46
  readonly code: string;
18
47
  constructor(status: number, code: string, message: string);
19
48
  }
20
- export declare class RapidCrawl {
49
+ /**
50
+ * Thrown when the request never produced an HTTP response at all — DNS, socket, TLS,
51
+ * a client-side timeout, or a caller-initiated abort. Distinct from `ByteKitError`,
52
+ * which always carries a real HTTP status: catch both to cover every failure.
53
+ *
54
+ * The original failure is preserved on `.cause`.
55
+ */
56
+ export declare class ByteKitConnectionError extends Error {
57
+ readonly code: ConnectionErrorCode;
58
+ constructor(code: ConnectionErrorCode, message: string, options?: {
59
+ cause?: unknown;
60
+ });
61
+ }
62
+ export declare class ByteKit {
21
63
  private readonly apiKey;
22
64
  private readonly baseUrl;
65
+ private readonly defaultTimeoutMs;
23
66
  readonly scrape: ScrapeResource;
24
67
  readonly screenshots: ScreenshotsResource;
25
- readonly recordings: RecordingsResource;
26
68
  readonly bulk: BulkResource;
27
69
  readonly fetch: FetchResource;
28
70
  readonly monitors: MonitorsResource;
29
71
  readonly sitemap: SitemapResource;
30
72
  readonly search: SearchResource;
31
73
  readonly account: AccountResource;
32
- constructor(options: RapidCrawlOptions);
74
+ constructor(options: ByteKitOptions);
75
+ /**
76
+ * Resolve the abort budget for one request from the caller's options and the
77
+ * constructor default. Precedence:
78
+ *
79
+ * | caller `signal` | per-call `requestTimeoutMs` | signal attached to `fetch` |
80
+ * |-----------------|----------------------------|---------------------------------------|
81
+ * | absent | absent | timeout from the constructor default |
82
+ * | absent | present | timeout from the per-call value |
83
+ * | present | absent | the caller's signal, verbatim |
84
+ * | present | present | composition — aborts on either |
85
+ *
86
+ * A timeout of `0` (either level) means "no SDK-side timeout".
87
+ */
88
+ private resolveSignal;
33
89
  /**
34
- * Make an authenticated JSON request to the RapidCrawl API.
90
+ * Make an authenticated JSON request to the ByteKit API.
35
91
  *
36
- * Throws `RapidCrawlError` on 4xx/5xx responses.
92
+ * Throws `ByteKitError` on 4xx/5xx responses, and `ByteKitConnectionError`
93
+ * when no HTTP response was produced at all (DNS/socket/TLS failure, client-side
94
+ * timeout, or caller abort).
37
95
  */
38
- request<T>(method: string, path: string, body?: unknown): Promise<T>;
96
+ request<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<T>;
39
97
  }
40
- //# sourceMappingURL=client.d.ts.map
98
+ export { ByteKit as RapidCrawl, ByteKitError as RapidCrawlError, ByteKitConnectionError as RapidCrawlConnectionError, };
99
+ export type { ByteKitOptions as RapidCrawlOptions };