@hunt-labs/bytekit-sdk 0.4.0 → 0.6.0

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/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { ByteKit, ByteKitError, ByteKitConnectionError } from './client.js';
2
- export type { ByteKitOptions, RequestOptions, ApiResponse, ConnectionErrorCode } from './client.js';
2
+ export type { ByteKitOptions, RequestOptions, ApiResponse, ConnectionErrorCode, ByteKitErrorDetails, } from './client.js';
3
3
  export { V01_METHODS } from './allowlist.js';
4
4
  export type { V01Method } from './allowlist.js';
5
5
  export type { ScrapeId, ScreenshotId, BulkId, MonitorId, SitemapId, ApiKeyId, WebhookDeliveryId, SearchType, SearchDateRange, SearchOpts, SearchResult, SearchResultImage, SearchResponse, } from './types.js';
6
- export type { ScrapeCookie, ScrapeCreateResponse, ScrapeGetResponse, ScrapeBulkCreateRequest, ScrapeBulkCreateResponse, ScrapeBulkGetResponse, } from './resources/scrape.js';
6
+ export type { ScrapeCookie, ScrapeOpts, MarkdownMode, MarkdownLinks, MarkdownImages, TokenEncoding, ScrapeCreateResponse, ScrapeGetResponse, ScrapeBulkCreateRequest, ScrapeBulkCreateResponse, ScrapeBulkGetResponse, } from './resources/scrape.js';
7
7
  export type { ScreenshotCreateRequest, ScreenshotCreateResponse, ScreenshotGetResponse, } from './resources/screenshots.js';
8
8
  export type { FetchOpts, FetchGetOpts, FetchResult, FetchCacheStatus, FetchBulkCreateRequest, FetchBulkCreateResponse, FetchBulkGetResponse, } from './resources/fetch.js';
9
9
  export type { MonitorCreateRequest, MonitorCreateResponse, ListMonitorsParams, MonitorStatus, ListMonitorsResponse, MonitorResponse, MonitorUpdateRequest, UpdateMonitorResponse, ListMonitorCapturesResponse, } from './resources/monitors.js';
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  export class AccountResource {
2
3
  client;
3
4
  apiKeys;
@@ -35,11 +36,11 @@ class ApiKeysResource {
35
36
  }
36
37
  /** GET /v1/account/api-keys/{id} — get an API key by ID */
37
38
  get(id, requestOptions) {
38
- return this.client.request('GET', `/v1/account/api-keys/${id}`, undefined, requestOptions);
39
+ return this.client.request('GET', buildPath('/v1/account/api-keys/{id}', { segments: { id } }), undefined, requestOptions);
39
40
  }
40
41
  /** PATCH /v1/account/api-keys/{id} — update an API key */
41
42
  update(id, opts, requestOptions) {
42
- return this.client.request('PATCH', `/v1/account/api-keys/${id}`, opts, requestOptions);
43
+ return this.client.request('PATCH', buildPath('/v1/account/api-keys/{id}', { segments: { id } }), opts, requestOptions);
43
44
  }
44
45
  /**
45
46
  * DELETE /v1/account/api-keys/{id} — revoke an API key (idempotent).
@@ -53,10 +54,10 @@ class ApiKeysResource {
53
54
  * method resolves cleanly on the gateway's empty 204 body.
54
55
  */
55
56
  revoke(id, requestOptions) {
56
- return this.client.request('DELETE', `/v1/account/api-keys/${id}`, undefined, requestOptions);
57
+ return this.client.request('DELETE', buildPath('/v1/account/api-keys/{id}', { segments: { id } }), undefined, requestOptions);
57
58
  }
58
59
  /** POST /v1/account/api-keys/{id}/reveal — reveal the plaintext API key value */
59
60
  reveal(id, requestOptions) {
60
- return this.client.request('POST', `/v1/account/api-keys/${id}/reveal`, undefined, requestOptions);
61
+ return this.client.request('POST', buildPath('/v1/account/api-keys/{id}/reveal', { segments: { id } }), undefined, requestOptions);
61
62
  }
62
63
  }
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  export class BulkResource {
2
3
  client;
3
4
  screenshots;
@@ -16,11 +17,11 @@ export class BulkResource {
16
17
  }
17
18
  /** GET /v1/bulk/{id} — get a bulk job status */
18
19
  get(id, requestOptions) {
19
- return this.client.request('GET', `/v1/bulk/${id}`, undefined, requestOptions);
20
+ return this.client.request('GET', buildPath('/v1/bulk/{id}', { segments: { id } }), undefined, requestOptions);
20
21
  }
21
22
  /** DELETE /v1/bulk/{id} — cancel an in-flight bulk job */
22
23
  cancel(id, requestOptions) {
23
- return this.client.request('DELETE', `/v1/bulk/${id}`, undefined, requestOptions);
24
+ return this.client.request('DELETE', buildPath('/v1/bulk/{id}', { segments: { id } }), undefined, requestOptions);
24
25
  }
25
26
  }
26
27
  class BulkScreenshotsResource {
@@ -30,6 +31,6 @@ class BulkScreenshotsResource {
30
31
  }
31
32
  /** GET /v1/bulk/{id}/screenshots — list screenshots in a bulk job */
32
33
  list(id, requestOptions) {
33
- return this.client.request('GET', `/v1/bulk/${id}/screenshots`, undefined, requestOptions);
34
+ return this.client.request('GET', buildPath('/v1/bulk/{id}/screenshots', { segments: { id } }), undefined, requestOptions);
34
35
  }
35
36
  }
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  /**
2
3
  * The query params `GET /v1/fetch` accepts, in serialization order.
3
4
  *
@@ -14,7 +15,10 @@ const CACHE_STATUSES = ['hit', 'miss', 'bypass'];
14
15
  function toFetchResult(raw) {
15
16
  const { body, bytes, headers } = raw;
16
17
  const creditsRaw = headers.get('X-Fetch-Credits-Charged');
17
- const credits = creditsRaw === null ? NaN : Number(creditsRaw);
18
+ // An empty-but-present header must be treated the same as an absent one: `Number('')`
19
+ // is `0` (finite), so without this check an empty header parsed as a real zero-credit
20
+ // charge instead of "unparseable" (#2595).
21
+ const credits = creditsRaw === null || creditsRaw.trim() === '' ? NaN : Number(creditsRaw);
18
22
  const cacheRaw = headers.get('X-Fetch-Cache');
19
23
  return {
20
24
  body,
@@ -77,7 +81,7 @@ export class FetchResource {
77
81
  if (value !== undefined)
78
82
  params.set(key, String(value));
79
83
  }
80
- return toFetchResult(await this.client.requestRaw('GET', `/v1/fetch?${params.toString()}`, undefined, requestOptions));
84
+ return toFetchResult(await this.client.requestRaw('GET', buildPath('/v1/fetch', { query: `?${params.toString()}` }), undefined, requestOptions));
81
85
  }
82
86
  }
83
87
  class FetchBulkResource {
@@ -91,6 +95,6 @@ class FetchBulkResource {
91
95
  }
92
96
  /** GET /v1/fetch/bulk/{id} — get a bulk fetch job */
93
97
  get(id, requestOptions) {
94
- return this.client.request('GET', `/v1/fetch/bulk/${id}`, undefined, requestOptions);
98
+ return this.client.request('GET', buildPath('/v1/fetch/bulk/{id}', { segments: { id } }), undefined, requestOptions);
95
99
  }
96
100
  }
@@ -46,6 +46,19 @@ export type MonitorUpdateRequest = operations['updateMonitor']['requestBody']['c
46
46
  export type UpdateMonitorResponse = operations['updateMonitor']['responses'][200]['content']['application/json'];
47
47
  /** 200 payload of GET /v1/monitors/{id}/captures — the paginated capture list. */
48
48
  export type ListMonitorCapturesResponse = operations['listMonitorCaptures']['responses'][200]['content']['application/json'];
49
+ /**
50
+ * Query params of GET /v1/monitors/{id}/captures — `limit`/`cursor`, both optional and
51
+ * omitted when unset.
52
+ *
53
+ * DERIVED from the generated `listMonitorCaptures` query type (#2594), mirroring
54
+ * {@link ListMonitorsParams} — never hand-authored, so a spec drift (a renamed/removed query
55
+ * param) surfaces as a `tsc` error here rather than a silent request-shape mismatch (E1).
56
+ *
57
+ * Still a `type` alias (not an `interface`), for the same implicit-index-signature reason as
58
+ * {@link ListMonitorsParams} — it must stay assignable to {@link toQueryString}'s
59
+ * `Record<string, string | number | undefined>` param.
60
+ */
61
+ export type ListMonitorCapturesParams = NonNullable<operations['listMonitorCaptures']['parameters']['query']>;
49
62
  export declare class MonitorsResource {
50
63
  private readonly client;
51
64
  readonly captures: MonitorCapturesResource;
@@ -79,7 +92,13 @@ export declare class MonitorsResource {
79
92
  declare class MonitorCapturesResource {
80
93
  private readonly client;
81
94
  constructor(client: ByteKit);
82
- /** GET /v1/monitors/{id}/captures — list captures for a monitor */
83
- list(id: MonitorId, requestOptions?: RequestOptions): Promise<ListMonitorCapturesResponse>;
95
+ /**
96
+ * GET /v1/monitors/{id}/captures — list captures for a monitor.
97
+ *
98
+ * `params` is optional and each key is omitted-when-absent (#2594), so `list(id)` with no
99
+ * second argument serializes the bare `/v1/monitors/{id}/captures` URL unchanged — existing
100
+ * zero-arg callers are unaffected (inverse case).
101
+ */
102
+ list(id: MonitorId, params?: ListMonitorCapturesParams, requestOptions?: RequestOptions): Promise<ListMonitorCapturesResponse>;
84
103
  }
85
104
  export {};
@@ -1,4 +1,5 @@
1
1
  import { toQueryString } from './query-string.js';
2
+ import { buildPath } from '../client.js';
2
3
  export class MonitorsResource {
3
4
  client;
4
5
  captures;
@@ -20,15 +21,15 @@ export class MonitorsResource {
20
21
  * serializes the bare `/v1/monitors` URL unchanged — existing zero-arg callers are unaffected.
21
22
  */
22
23
  list(params, requestOptions) {
23
- return this.client.request('GET', `/v1/monitors${toQueryString(params)}`, undefined, requestOptions);
24
+ return this.client.request('GET', buildPath('/v1/monitors', { query: toQueryString(params) }), undefined, requestOptions);
24
25
  }
25
26
  /** GET /v1/monitors/{id} — get a monitor by ID */
26
27
  get(id, requestOptions) {
27
- return this.client.request('GET', `/v1/monitors/${id}`, undefined, requestOptions);
28
+ return this.client.request('GET', buildPath('/v1/monitors/{id}', { segments: { id } }), undefined, requestOptions);
28
29
  }
29
30
  /** PATCH /v1/monitors/{id} — update a monitor */
30
31
  update(id, opts, requestOptions) {
31
- return this.client.request('PATCH', `/v1/monitors/${id}`, opts, requestOptions);
32
+ return this.client.request('PATCH', buildPath('/v1/monitors/{id}', { segments: { id } }), opts, requestOptions);
32
33
  }
33
34
  /**
34
35
  * DELETE /v1/monitors/{id} — delete a monitor.
@@ -39,7 +40,7 @@ export class MonitorsResource {
39
40
  * body to `undefined` before it would parse as JSON (#2450).
40
41
  */
41
42
  delete(id, requestOptions) {
42
- return this.client.request('DELETE', `/v1/monitors/${id}`, undefined, requestOptions);
43
+ return this.client.request('DELETE', buildPath('/v1/monitors/{id}', { segments: { id } }), undefined, requestOptions);
43
44
  }
44
45
  }
45
46
  class MonitorCapturesResource {
@@ -47,8 +48,14 @@ class MonitorCapturesResource {
47
48
  constructor(client) {
48
49
  this.client = client;
49
50
  }
50
- /** GET /v1/monitors/{id}/captures — list captures for a monitor */
51
- list(id, requestOptions) {
52
- return this.client.request('GET', `/v1/monitors/${id}/captures`, undefined, requestOptions);
51
+ /**
52
+ * GET /v1/monitors/{id}/captures — list captures for a monitor.
53
+ *
54
+ * `params` is optional and each key is omitted-when-absent (#2594), so `list(id)` with no
55
+ * second argument serializes the bare `/v1/monitors/{id}/captures` URL unchanged — existing
56
+ * zero-arg callers are unaffected (inverse case).
57
+ */
58
+ list(id, params, requestOptions) {
59
+ return this.client.request('GET', buildPath('/v1/monitors/{id}/captures', { segments: { id }, query: toQueryString(params) }), undefined, requestOptions);
53
60
  }
54
61
  }
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  export class ScrapeResource {
2
3
  client;
3
4
  bulk;
@@ -35,7 +36,7 @@ export class ScrapeResource {
35
36
  * gateway and is out of this ticket's scope.
36
37
  */
37
38
  get(id, requestOptions) {
38
- return this.client.request('GET', `/v1/scrape/${id}`, undefined, requestOptions);
39
+ return this.client.request('GET', buildPath('/v1/scrape/{id}', { segments: { id } }), undefined, requestOptions);
39
40
  }
40
41
  }
41
42
  class ScrapeBulkResource {
@@ -54,6 +55,6 @@ class ScrapeBulkResource {
54
55
  }
55
56
  /** GET /v1/scrape/bulk/{id} — get a bulk scrape job */
56
57
  get(id, requestOptions) {
57
- return this.client.request('GET', `/v1/scrape/bulk/${id}`, undefined, requestOptions);
58
+ return this.client.request('GET', buildPath('/v1/scrape/bulk/{id}', { segments: { id } }), undefined, requestOptions);
58
59
  }
59
60
  }
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  export class ScreenshotsResource {
2
3
  client;
3
4
  constructor(client) {
@@ -17,7 +18,7 @@ export class ScreenshotsResource {
17
18
  */
18
19
  create(opts, params, requestOptions) {
19
20
  const suffix = params?.async === true ? '?async=true' : '';
20
- return this.client.request('POST', `/v1/screenshots${suffix}`, opts, requestOptions);
21
+ return this.client.request('POST', buildPath('/v1/screenshots', { query: suffix }), opts, requestOptions);
21
22
  }
22
23
  /**
23
24
  * GET /v1/screenshots/{id} — poll a screenshot by ID.
@@ -26,7 +27,7 @@ export class ScreenshotsResource {
26
27
  * (issue #2027), so narrow the result before reading `image_url`.
27
28
  */
28
29
  get(id, requestOptions) {
29
- return this.client.request('GET', `/v1/screenshots/${id}`, undefined, requestOptions);
30
+ return this.client.request('GET', buildPath('/v1/screenshots/{id}', { segments: { id } }), undefined, requestOptions);
30
31
  }
31
32
  /**
32
33
  * POST /v1/screenshots, returning the header set alongside the body (#2547).
@@ -42,7 +43,7 @@ export class ScreenshotsResource {
42
43
  */
43
44
  createWithResponse(opts, params, requestOptions) {
44
45
  const suffix = params?.async === true ? '?async=true' : '';
45
- return this.client.requestWithResponse('POST', `/v1/screenshots${suffix}`, opts, requestOptions);
46
+ return this.client.requestWithResponse('POST', buildPath('/v1/screenshots', { query: suffix }), opts, requestOptions);
46
47
  }
47
48
  /**
48
49
  * GET /v1/screenshots/{id}, returning the header set alongside the body (#2547).
@@ -53,6 +54,6 @@ export class ScreenshotsResource {
53
54
  * `X-Raw-Bytes`, `X-Billable-Bytes` and `X-Billing-Multiplier` headers are on `headers`.
54
55
  */
55
56
  getWithResponse(id, requestOptions) {
56
- return this.client.requestWithResponse('GET', `/v1/screenshots/${id}`, undefined, requestOptions);
57
+ return this.client.requestWithResponse('GET', buildPath('/v1/screenshots/{id}', { segments: { id } }), undefined, requestOptions);
57
58
  }
58
59
  }
@@ -1,3 +1,4 @@
1
+ import { buildPath } from '../client.js';
1
2
  export class SitemapResource {
2
3
  client;
3
4
  constructor(client) {
@@ -14,7 +15,7 @@ export class SitemapResource {
14
15
  }
15
16
  /** GET /v1/sitemap/{id} — get a sitemap job by ID */
16
17
  get(id, requestOptions) {
17
- return this.client.request('GET', `/v1/sitemap/${id}`, undefined, requestOptions);
18
+ return this.client.request('GET', buildPath('/v1/sitemap/{id}', { segments: { id } }), undefined, requestOptions);
18
19
  }
19
20
  /**
20
21
  * GET /v1/sitemap/{id}, returning the header set alongside the body (#2547).
@@ -27,6 +28,6 @@ export class SitemapResource {
27
28
  * `X-Billable-Bytes` on this endpoint's 200; every one of them is on `headers`.
28
29
  */
29
30
  getWithResponse(id, requestOptions) {
30
- return this.client.requestWithResponse('GET', `/v1/sitemap/${id}`, undefined, requestOptions);
31
+ return this.client.requestWithResponse('GET', buildPath('/v1/sitemap/{id}', { segments: { id } }), undefined, requestOptions);
31
32
  }
32
33
  }
@@ -1,4 +1,5 @@
1
1
  import { toQueryString } from './query-string.js';
2
+ import { buildPath } from '../client.js';
2
3
  export class UsageResource {
3
4
  client;
4
5
  constructor(client) {
@@ -18,13 +19,13 @@ export class UsageResource {
18
19
  * Default range is the last 30 days; max range is 366 days.
19
20
  */
20
21
  daily(params, requestOptions) {
21
- return this.client.request('GET', `/v1/usage/daily${toQueryString(params)}`, undefined, requestOptions);
22
+ return this.client.request('GET', buildPath('/v1/usage/daily', { query: toQueryString(params) }), undefined, requestOptions);
22
23
  }
23
24
  /**
24
25
  * GET /v1/usage/by-endpoint — get per-endpoint bandwidth breakdown.
25
26
  * Default range is the last 30 days; max range is 366 days.
26
27
  */
27
28
  byEndpoint(params, requestOptions) {
28
- return this.client.request('GET', `/v1/usage/by-endpoint${toQueryString(params)}`, undefined, requestOptions);
29
+ return this.client.request('GET', buildPath('/v1/usage/by-endpoint', { query: toQueryString(params) }), undefined, requestOptions);
29
30
  }
30
31
  }
@@ -1,4 +1,5 @@
1
1
  import { toQueryString } from './query-string.js';
2
+ import { buildPath } from '../client.js';
2
3
  export class WebhooksResource {
3
4
  client;
4
5
  constructor(client) {
@@ -11,10 +12,10 @@ export class WebhooksResource {
11
12
  * optional caller `signal`; both override the constructor's `timeoutMs` default.
12
13
  */
13
14
  list(params, requestOptions) {
14
- return this.client.request('GET', `/v1/webhook-deliveries${toQueryString(params)}`, undefined, requestOptions);
15
+ return this.client.request('GET', buildPath('/v1/webhook-deliveries', { query: toQueryString(params) }), undefined, requestOptions);
15
16
  }
16
17
  /** POST /v1/webhook-deliveries/{id}/retry — requeue a failed or exhausted delivery. */
17
18
  retry(id, requestOptions) {
18
- return this.client.request('POST', `/v1/webhook-deliveries/${id}/retry`, undefined, requestOptions);
19
+ return this.client.request('POST', buildPath('/v1/webhook-deliveries/{id}/retry', { segments: { id } }), undefined, requestOptions);
19
20
  }
20
21
  }
package/dist/types.d.ts CHANGED
@@ -64,8 +64,12 @@ export interface SearchResult {
64
64
  position: number;
65
65
  title: string;
66
66
  url: string;
67
- /** Short text excerpt for the result. Omitted for `images` results. */
68
- snippet: string;
67
+ /**
68
+ * Short text excerpt for the result. Present for `web` and `news` results;
69
+ * omitted entirely (`undefined`) for `images` results — read it behind a
70
+ * guard, exactly like `date` (#2678).
71
+ */
72
+ snippet?: string;
69
73
  /**
70
74
  * Published date when the provider reports one, else `null`. Present for
71
75
  * `web`/`news` results; omitted entirely (`undefined`) for `images` results.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hunt-labs/bytekit-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Official TypeScript SDK for the ByteKit API",
5
5
  "license": "MIT",
6
6
  "type": "module",