@crawlbrulee/sdk 0.3.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.cts CHANGED
@@ -70,13 +70,46 @@ declare class HttpClient {
70
70
  /**
71
71
  * Proxy tier used to route the fetch.
72
72
  *
73
- * - `basic` — datacenter proxy, lowest cost (default).
73
+ * - `basic` — datacenter proxy, lowest cost.
74
74
  * - `advanced` — residential proxy, higher success rate on protected sites.
75
- * - `auto` — let crawlbrulee pick the right tier per target.
75
+ * - `auto` — start at the basic tier and escalate to advanced on failure;
76
+ * billed at the delivered tier. This is the default when `proxy` is omitted.
76
77
  * - `none` — skip the proxy entirely. Rejected in production; available on
77
78
  * staging only as a debug/perf-test toggle.
78
79
  */
79
80
  type ProxyTier = 'basic' | 'advanced' | 'auto' | 'none';
81
+ /**
82
+ * Proxy tier the server actually used to route a fetch, as reported back in
83
+ * {@link Usage.proxy}. Unlike the request-side {@link ProxyTier}, this never
84
+ * includes `auto` — when a request asks for `auto`, the server resolves it to a
85
+ * concrete tier and echoes the resolved value here.
86
+ */
87
+ type ResolvedProxyTier = 'none' | 'basic' | 'advanced';
88
+ /**
89
+ * Usage accounting for a single billable operation, returned on the response
90
+ * envelope of scrape, map, and async-status (when terminal). All crawlbrulee
91
+ * responses report this on `response_meta.usage`.
92
+ */
93
+ interface Usage {
94
+ /**
95
+ * Credits charged for this operation. `0` on a cache hit (no fresh fetch was
96
+ * performed).
97
+ */
98
+ credits: number;
99
+ /** The proxy tier the server resolved and used (never `auto`). */
100
+ proxy: ResolvedProxyTier;
101
+ /** Whether the result was served from cache (no fresh fetch). */
102
+ cache_hit: boolean;
103
+ }
104
+ /**
105
+ * Response envelope `response_meta` carried by scrape responses and async-status
106
+ * responses (terminal state only). Currently exposes {@link Usage}; map
107
+ * responses extend this shape with `pagination` + `truncation`.
108
+ */
109
+ interface ResponseMeta {
110
+ /** Usage accounting for the operation. */
111
+ usage: Usage;
112
+ }
80
113
  /** Screenshot capture mode: visible viewport or the full scrollable page. */
81
114
  type ScreenshotType = 'viewport' | 'full_page';
82
115
  /** Emulated device class for the viewport (drives default width/height). */
@@ -119,11 +152,14 @@ interface ScreenshotSliceAction {
119
152
  type ScreenshotAfterAction = ScreenshotSliceAction;
120
153
  /** Custom browser viewport dimensions used during a screenshot capture. */
121
154
  interface ScreenshotViewport {
122
- /** Viewport width in pixels. */
155
+ /** Viewport width in pixels. Integer in `[16, 10000]`; out-of-range values are rejected with a 400. */
123
156
  width: number;
124
- /** Viewport height in pixels. */
157
+ /** Viewport height in pixels. Integer in `[16, 10000]`; out-of-range values are rejected with a 400. */
125
158
  height: number;
126
- /** Device pixel ratio (e.g. 2 for retina). Defaults to 1 server-side. */
159
+ /**
160
+ * Device pixel ratio (e.g. 2 for retina). Fractional values are allowed;
161
+ * must be in `[1, 4]`. Defaults to 1 server-side.
162
+ */
127
163
  device_scale_factor?: number;
128
164
  }
129
165
  /** Screenshot capture configuration. Pass this on `extract.screenshot`. */
@@ -203,7 +239,11 @@ interface ScrapeExtract {
203
239
  raw_html?: boolean;
204
240
  /** Extract all links found on the page. Default `false`. */
205
241
  links?: boolean;
206
- /** Extract all inline images found on the page. Default `false`. */
242
+ /**
243
+ * Extract all inline images found on the page. Default `false`. Image URLs
244
+ * preserve their query string, and document-relative `src`s are resolved
245
+ * against the full page URL (browser parity) — same rules as `links`.
246
+ */
207
247
  images?: boolean;
208
248
  /** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
209
249
  screenshot?: ScreenshotRequest;
@@ -250,7 +290,10 @@ interface ScrapeRequest {
250
290
  require_js?: boolean;
251
291
  /** CSS selectors to strip from the extracted content. */
252
292
  exclude_selectors?: string[];
253
- /** Proxy tier to use for fetching. Defaults to `basic`. */
293
+ /**
294
+ * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
295
+ * first, escalates to advanced on failure; billed at the delivered tier).
296
+ */
254
297
  proxy?: ProxyTier;
255
298
  /** Optional locale + country emulation. */
256
299
  location?: ScrapeLocation;
@@ -331,7 +374,10 @@ interface ScreenshotResult {
331
374
  }
332
375
  /** A single inline image discovered on the page. */
333
376
  interface PageInlineImage {
334
- /** Absolute URL of the image. */
377
+ /**
378
+ * Absolute URL of the image, query string preserved. Document-relative
379
+ * `src`s are resolved against the full page URL (browser parity).
380
+ */
335
381
  url: string;
336
382
  /** Alt text of the image, or `null` if not set. */
337
383
  alt: string | null;
@@ -391,7 +437,12 @@ interface ScrapeResponse {
391
437
  images?: PageInlineImage[];
392
438
  /** Links discovered on the page (when `extract.links`). */
393
439
  links?: PageLink[];
394
- /** Captured screenshot (when `extract.screenshot`). */
440
+ /**
441
+ * Captured screenshot (when `extract.screenshot`). In rare cases a screenshot
442
+ * can't be captured; when that happens the rest of your requested outputs are
443
+ * still returned and this field is simply left out (so it reads back as
444
+ * `undefined`). Guard with `page.screenshot?.url`.
445
+ */
395
446
  screenshot?: ScreenshotResult;
396
447
  /** Extracted page metadata (when `extract.metadata`, on by default). */
397
448
  metadata?: ScrapeMetadata;
@@ -402,6 +453,11 @@ interface ScrapeResponse {
402
453
  * omit warnings.
403
454
  */
404
455
  warnings?: string[];
456
+ /**
457
+ * Response envelope metadata. Carries `usage` (credits charged, resolved
458
+ * proxy tier, and whether the result was a cache hit).
459
+ */
460
+ response_meta: ResponseMeta;
405
461
  }
406
462
 
407
463
  /** Filter which link types appear in the map result. */
@@ -430,7 +486,10 @@ interface MapLocation {
430
486
  interface MapRequest {
431
487
  /** The website URL to map. */
432
488
  url: string;
433
- /** Proxy tier to use for fetching. Defaults to `basic`. */
489
+ /**
490
+ * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
491
+ * first, escalates to advanced on failure; billed at the delivered tier).
492
+ */
434
493
  proxy?: ProxyTier;
435
494
  /** Only use sitemap.xml — skip homepage link extraction. Default `false`. */
436
495
  sitemap_only?: boolean;
@@ -477,15 +536,20 @@ interface MapTruncation {
477
536
  /** Total URLs detected during discovery before the storage cap was applied. */
478
537
  total_detected_before_storage_cap: number;
479
538
  }
539
+ /**
540
+ * Response envelope for a map result: the shared {@link ResponseMeta} (`usage`)
541
+ * plus the map-specific `pagination` and `truncation`.
542
+ */
543
+ interface MapResponseMeta extends ResponseMeta {
544
+ pagination: MapPagination;
545
+ truncation: MapTruncation;
546
+ }
480
547
  /** Success response from `POST /api/map`. */
481
548
  interface MapResponse {
482
549
  /** The current page of discovered URLs. */
483
550
  links: MapLinkItem[];
484
- /** Pagination + truncation metadata for the result set. */
485
- meta: {
486
- pagination: MapPagination;
487
- truncation: MapTruncation;
488
- };
551
+ /** Usage, pagination, and truncation metadata for the result set. */
552
+ response_meta: MapResponseMeta;
489
553
  }
490
554
 
491
555
  /** Job lifecycle states for an async scrape. */
@@ -495,24 +559,22 @@ interface AsyncScrapeResponse {
495
559
  /** Job identifier — pass it to `getScrapeStatus` / `getScrapeResult`. */
496
560
  job_id: string;
497
561
  }
498
- /**
499
- * Response body of `GET /api/scrape/status/:jobId`.
500
- *
501
- * Note: this response uses camelCase field names (`jobId`, `createdAt`) while
502
- * most other crawlbrulee responses use snake_case (e.g. `job_id` on
503
- * {@link AsyncScrapeResponse}, `total_credits` on `UsageResponse`). The SDK
504
- * mirrors the wire format faithfully — if the inconsistency trips you up,
505
- * destructure with explicit names.
506
- */
562
+ /** Response body of `GET /api/scrape/status/:jobId`. */
507
563
  interface AsyncJobStatusResponse {
508
564
  /** The job identifier. */
509
- jobId: string;
565
+ job_id: string;
510
566
  /** Current state of the job. */
511
567
  status: AsyncJobStatus;
512
568
  /** ISO-8601 UTC timestamp when the job was created. */
513
- createdAt: string;
569
+ created_at: string;
514
570
  /** Error message if the job ended in `failed`. */
515
571
  error?: string;
572
+ /**
573
+ * Response envelope metadata — present only when the job has reached the
574
+ * terminal `done` state. Carries `usage` (credits charged, resolved proxy
575
+ * tier, and whether the result was a cache hit).
576
+ */
577
+ response_meta?: ResponseMeta;
516
578
  }
517
579
 
518
580
  /** Response from `GET /api/usage`. Current billing-cycle snapshot. */
@@ -554,7 +616,7 @@ interface WhoamiResponse {
554
616
  organization_name: string;
555
617
  /** User-assigned name of the API token. */
556
618
  token_name: string;
557
- /** Truncated preview of the API token (e.g. `cble_…xyz`). Safe to display. */
619
+ /** Truncated preview of the API token (e.g. `cwbl_…xyz`). Safe to display. */
558
620
  token_preview: string;
559
621
  }
560
622
 
@@ -570,10 +632,18 @@ interface WhoamiResponse {
570
632
  * "event_id": "evt_…",
571
633
  * "timestamp": "2026-06-13T12:00:00.000Z",
572
634
  * "event": "scrape.complete",
573
- * "data": { "job_id": "job_…", "status": "success", "url": "https://…", "completed_at": "…" }
635
+ * "data": {
636
+ * "job_id": "job_…",
637
+ * "status": "success",
638
+ * "url": "https://…",
639
+ * "completed_at": "…",
640
+ * "metadata": { "tenant": "acme" },
641
+ * "response_meta": { "usage": { "credits": 1, "proxy": "basic", "cache_hit": false } }
642
+ * }
574
643
  * }
575
644
  * ```
576
645
  */
646
+
577
647
  /** Terminal status carried by a {@link ScrapeCompleteWebhook}. */
578
648
  type ScrapeWebhookStatus = 'success' | 'failed' | 'cancelled';
579
649
  /** `data` block of a {@link ScrapeCompleteWebhook}. */
@@ -588,8 +658,17 @@ interface ScrapeCompleteWebhookData {
588
658
  completed_at: string;
589
659
  /** Failure message — present only when `status === 'failed'`. */
590
660
  error?: string;
591
- /** Correlation data echoed back from the original scrape request, if any. */
661
+ /**
662
+ * Correlation data echoed back from the original scrape request's
663
+ * `webhook.metadata`, if any.
664
+ */
592
665
  metadata?: Record<string, unknown>;
666
+ /**
667
+ * Response envelope metadata — `usage` (credits charged, resolved proxy tier,
668
+ * and whether the result was a cache hit). Present only on `status: 'success'`
669
+ * deliveries; omitted for `failed` / `cancelled` (no usage was charged).
670
+ */
671
+ response_meta?: ResponseMeta;
593
672
  }
594
673
  /**
595
674
  * Webhook envelope delivered when an async scrape job completes. The `event`
@@ -653,7 +732,7 @@ interface WaitForScrapeOptions extends Omit<RequestOptions, 'timeoutMs'> {
653
732
  * ```ts
654
733
  * import { Crawlbrulee } from '@crawlbrulee/sdk'
655
734
  *
656
- * const crawlbrulee = new Crawlbrulee({ apiKey: 'cble_…' })
735
+ * const crawlbrulee = new Crawlbrulee({ apiKey: 'cwbl_…' })
657
736
  * // or read CRAWLBRULEE_API_KEY from the environment:
658
737
  * const crawlbrulee = Crawlbrulee.fromEnv()
659
738
  *
@@ -882,8 +961,8 @@ declare function isCrawlbruleeError(err: unknown): err is CrawlbruleeError;
882
961
  * staging callers point at their own host via that option.
883
962
  */
884
963
  declare const DEFAULT_BASE_URL = "https://api.crawlbrulee.com";
885
- /** Default request timeout (60 s) when the caller doesn't specify one. */
886
- declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
964
+ /** Default request timeout when the caller doesn't specify one (0 disables the timeout). */
965
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 0;
887
966
  /** Environment variable read by `Crawlbrulee.fromEnv()` to source the API key. */
888
967
  declare const ENV_API_KEY = "CRAWLBRULEE_API_KEY";
889
968
 
@@ -979,4 +1058,4 @@ interface VerifyWebhookSignatureOptions {
979
1058
  */
980
1059
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
981
1060
 
982
- export { type ApiErrorDetails, type ApiErrorName, type ApiErrorResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncScrapeRequest, type AsyncScrapeResponse, type AsyncScrapeWebhook, AuthenticationError, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, type MapCache, type MapLinkItem, type MapLocation, type MapPagination, type MapRequest, type MapResponse, type MapTruncation, type MapTypes, NotFoundError, type PageInlineImage, type PageLink, type ProxyTier, RateLimitError, type RateLimitErrorDetails, type RequestOptions, type ScrapeCache, type ScrapeCompleteWebhook, type ScrapeCompleteWebhookData, type ScrapeExtract, type ScrapeLocation, type ScrapeMetadata, type ScrapeRequest, type ScrapeResponse, type ScrapeWebhookStatus, type ScreenshotAfterAction, type ScreenshotBeforeAction, type ScreenshotCleanup, type ScreenshotDeviceMode, type ScreenshotProperties, type ScreenshotRequest, type ScreenshotResult, type ScreenshotScrollAction, type ScreenshotSlice, type ScreenshotSliceAction, type ScreenshotType, type ScreenshotViewport, type ScreenshotViewportInfo, type ScreenshotWaitAction, TransportError, UsageAllocationError, type UsageAllocationErrorDetails, type UsageAllocationReason, type UsageLimitDetails, type UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, type WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1061
+ export { type ApiErrorDetails, type ApiErrorName, type ApiErrorResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncScrapeRequest, type AsyncScrapeResponse, type AsyncScrapeWebhook, AuthenticationError, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, type MapCache, type MapLinkItem, type MapLocation, type MapPagination, type MapRequest, type MapResponse, type MapResponseMeta, type MapTruncation, type MapTypes, NotFoundError, type PageInlineImage, type PageLink, type ProxyTier, RateLimitError, type RateLimitErrorDetails, type RequestOptions, type ResolvedProxyTier, type ResponseMeta, type ScrapeCache, type ScrapeCompleteWebhook, type ScrapeCompleteWebhookData, type ScrapeExtract, type ScrapeLocation, type ScrapeMetadata, type ScrapeRequest, type ScrapeResponse, type ScrapeWebhookStatus, type ScreenshotAfterAction, type ScreenshotBeforeAction, type ScreenshotCleanup, type ScreenshotDeviceMode, type ScreenshotProperties, type ScreenshotRequest, type ScreenshotResult, type ScreenshotScrollAction, type ScreenshotSlice, type ScreenshotSliceAction, type ScreenshotType, type ScreenshotViewport, type ScreenshotViewportInfo, type ScreenshotWaitAction, TransportError, type Usage, UsageAllocationError, type UsageAllocationErrorDetails, type UsageAllocationReason, type UsageLimitDetails, type UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, type WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -70,13 +70,46 @@ declare class HttpClient {
70
70
  /**
71
71
  * Proxy tier used to route the fetch.
72
72
  *
73
- * - `basic` — datacenter proxy, lowest cost (default).
73
+ * - `basic` — datacenter proxy, lowest cost.
74
74
  * - `advanced` — residential proxy, higher success rate on protected sites.
75
- * - `auto` — let crawlbrulee pick the right tier per target.
75
+ * - `auto` — start at the basic tier and escalate to advanced on failure;
76
+ * billed at the delivered tier. This is the default when `proxy` is omitted.
76
77
  * - `none` — skip the proxy entirely. Rejected in production; available on
77
78
  * staging only as a debug/perf-test toggle.
78
79
  */
79
80
  type ProxyTier = 'basic' | 'advanced' | 'auto' | 'none';
81
+ /**
82
+ * Proxy tier the server actually used to route a fetch, as reported back in
83
+ * {@link Usage.proxy}. Unlike the request-side {@link ProxyTier}, this never
84
+ * includes `auto` — when a request asks for `auto`, the server resolves it to a
85
+ * concrete tier and echoes the resolved value here.
86
+ */
87
+ type ResolvedProxyTier = 'none' | 'basic' | 'advanced';
88
+ /**
89
+ * Usage accounting for a single billable operation, returned on the response
90
+ * envelope of scrape, map, and async-status (when terminal). All crawlbrulee
91
+ * responses report this on `response_meta.usage`.
92
+ */
93
+ interface Usage {
94
+ /**
95
+ * Credits charged for this operation. `0` on a cache hit (no fresh fetch was
96
+ * performed).
97
+ */
98
+ credits: number;
99
+ /** The proxy tier the server resolved and used (never `auto`). */
100
+ proxy: ResolvedProxyTier;
101
+ /** Whether the result was served from cache (no fresh fetch). */
102
+ cache_hit: boolean;
103
+ }
104
+ /**
105
+ * Response envelope `response_meta` carried by scrape responses and async-status
106
+ * responses (terminal state only). Currently exposes {@link Usage}; map
107
+ * responses extend this shape with `pagination` + `truncation`.
108
+ */
109
+ interface ResponseMeta {
110
+ /** Usage accounting for the operation. */
111
+ usage: Usage;
112
+ }
80
113
  /** Screenshot capture mode: visible viewport or the full scrollable page. */
81
114
  type ScreenshotType = 'viewport' | 'full_page';
82
115
  /** Emulated device class for the viewport (drives default width/height). */
@@ -119,11 +152,14 @@ interface ScreenshotSliceAction {
119
152
  type ScreenshotAfterAction = ScreenshotSliceAction;
120
153
  /** Custom browser viewport dimensions used during a screenshot capture. */
121
154
  interface ScreenshotViewport {
122
- /** Viewport width in pixels. */
155
+ /** Viewport width in pixels. Integer in `[16, 10000]`; out-of-range values are rejected with a 400. */
123
156
  width: number;
124
- /** Viewport height in pixels. */
157
+ /** Viewport height in pixels. Integer in `[16, 10000]`; out-of-range values are rejected with a 400. */
125
158
  height: number;
126
- /** Device pixel ratio (e.g. 2 for retina). Defaults to 1 server-side. */
159
+ /**
160
+ * Device pixel ratio (e.g. 2 for retina). Fractional values are allowed;
161
+ * must be in `[1, 4]`. Defaults to 1 server-side.
162
+ */
127
163
  device_scale_factor?: number;
128
164
  }
129
165
  /** Screenshot capture configuration. Pass this on `extract.screenshot`. */
@@ -203,7 +239,11 @@ interface ScrapeExtract {
203
239
  raw_html?: boolean;
204
240
  /** Extract all links found on the page. Default `false`. */
205
241
  links?: boolean;
206
- /** Extract all inline images found on the page. Default `false`. */
242
+ /**
243
+ * Extract all inline images found on the page. Default `false`. Image URLs
244
+ * preserve their query string, and document-relative `src`s are resolved
245
+ * against the full page URL (browser parity) — same rules as `links`.
246
+ */
207
247
  images?: boolean;
208
248
  /** Capture a screenshot. Omit to skip; set to a `ScreenshotRequest` to enable. */
209
249
  screenshot?: ScreenshotRequest;
@@ -250,7 +290,10 @@ interface ScrapeRequest {
250
290
  require_js?: boolean;
251
291
  /** CSS selectors to strip from the extracted content. */
252
292
  exclude_selectors?: string[];
253
- /** Proxy tier to use for fetching. Defaults to `basic`. */
293
+ /**
294
+ * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
295
+ * first, escalates to advanced on failure; billed at the delivered tier).
296
+ */
254
297
  proxy?: ProxyTier;
255
298
  /** Optional locale + country emulation. */
256
299
  location?: ScrapeLocation;
@@ -331,7 +374,10 @@ interface ScreenshotResult {
331
374
  }
332
375
  /** A single inline image discovered on the page. */
333
376
  interface PageInlineImage {
334
- /** Absolute URL of the image. */
377
+ /**
378
+ * Absolute URL of the image, query string preserved. Document-relative
379
+ * `src`s are resolved against the full page URL (browser parity).
380
+ */
335
381
  url: string;
336
382
  /** Alt text of the image, or `null` if not set. */
337
383
  alt: string | null;
@@ -391,7 +437,12 @@ interface ScrapeResponse {
391
437
  images?: PageInlineImage[];
392
438
  /** Links discovered on the page (when `extract.links`). */
393
439
  links?: PageLink[];
394
- /** Captured screenshot (when `extract.screenshot`). */
440
+ /**
441
+ * Captured screenshot (when `extract.screenshot`). In rare cases a screenshot
442
+ * can't be captured; when that happens the rest of your requested outputs are
443
+ * still returned and this field is simply left out (so it reads back as
444
+ * `undefined`). Guard with `page.screenshot?.url`.
445
+ */
395
446
  screenshot?: ScreenshotResult;
396
447
  /** Extracted page metadata (when `extract.metadata`, on by default). */
397
448
  metadata?: ScrapeMetadata;
@@ -402,6 +453,11 @@ interface ScrapeResponse {
402
453
  * omit warnings.
403
454
  */
404
455
  warnings?: string[];
456
+ /**
457
+ * Response envelope metadata. Carries `usage` (credits charged, resolved
458
+ * proxy tier, and whether the result was a cache hit).
459
+ */
460
+ response_meta: ResponseMeta;
405
461
  }
406
462
 
407
463
  /** Filter which link types appear in the map result. */
@@ -430,7 +486,10 @@ interface MapLocation {
430
486
  interface MapRequest {
431
487
  /** The website URL to map. */
432
488
  url: string;
433
- /** Proxy tier to use for fetching. Defaults to `basic`. */
489
+ /**
490
+ * Proxy tier to use for fetching. Defaults to `auto` (tries the basic tier
491
+ * first, escalates to advanced on failure; billed at the delivered tier).
492
+ */
434
493
  proxy?: ProxyTier;
435
494
  /** Only use sitemap.xml — skip homepage link extraction. Default `false`. */
436
495
  sitemap_only?: boolean;
@@ -477,15 +536,20 @@ interface MapTruncation {
477
536
  /** Total URLs detected during discovery before the storage cap was applied. */
478
537
  total_detected_before_storage_cap: number;
479
538
  }
539
+ /**
540
+ * Response envelope for a map result: the shared {@link ResponseMeta} (`usage`)
541
+ * plus the map-specific `pagination` and `truncation`.
542
+ */
543
+ interface MapResponseMeta extends ResponseMeta {
544
+ pagination: MapPagination;
545
+ truncation: MapTruncation;
546
+ }
480
547
  /** Success response from `POST /api/map`. */
481
548
  interface MapResponse {
482
549
  /** The current page of discovered URLs. */
483
550
  links: MapLinkItem[];
484
- /** Pagination + truncation metadata for the result set. */
485
- meta: {
486
- pagination: MapPagination;
487
- truncation: MapTruncation;
488
- };
551
+ /** Usage, pagination, and truncation metadata for the result set. */
552
+ response_meta: MapResponseMeta;
489
553
  }
490
554
 
491
555
  /** Job lifecycle states for an async scrape. */
@@ -495,24 +559,22 @@ interface AsyncScrapeResponse {
495
559
  /** Job identifier — pass it to `getScrapeStatus` / `getScrapeResult`. */
496
560
  job_id: string;
497
561
  }
498
- /**
499
- * Response body of `GET /api/scrape/status/:jobId`.
500
- *
501
- * Note: this response uses camelCase field names (`jobId`, `createdAt`) while
502
- * most other crawlbrulee responses use snake_case (e.g. `job_id` on
503
- * {@link AsyncScrapeResponse}, `total_credits` on `UsageResponse`). The SDK
504
- * mirrors the wire format faithfully — if the inconsistency trips you up,
505
- * destructure with explicit names.
506
- */
562
+ /** Response body of `GET /api/scrape/status/:jobId`. */
507
563
  interface AsyncJobStatusResponse {
508
564
  /** The job identifier. */
509
- jobId: string;
565
+ job_id: string;
510
566
  /** Current state of the job. */
511
567
  status: AsyncJobStatus;
512
568
  /** ISO-8601 UTC timestamp when the job was created. */
513
- createdAt: string;
569
+ created_at: string;
514
570
  /** Error message if the job ended in `failed`. */
515
571
  error?: string;
572
+ /**
573
+ * Response envelope metadata — present only when the job has reached the
574
+ * terminal `done` state. Carries `usage` (credits charged, resolved proxy
575
+ * tier, and whether the result was a cache hit).
576
+ */
577
+ response_meta?: ResponseMeta;
516
578
  }
517
579
 
518
580
  /** Response from `GET /api/usage`. Current billing-cycle snapshot. */
@@ -554,7 +616,7 @@ interface WhoamiResponse {
554
616
  organization_name: string;
555
617
  /** User-assigned name of the API token. */
556
618
  token_name: string;
557
- /** Truncated preview of the API token (e.g. `cble_…xyz`). Safe to display. */
619
+ /** Truncated preview of the API token (e.g. `cwbl_…xyz`). Safe to display. */
558
620
  token_preview: string;
559
621
  }
560
622
 
@@ -570,10 +632,18 @@ interface WhoamiResponse {
570
632
  * "event_id": "evt_…",
571
633
  * "timestamp": "2026-06-13T12:00:00.000Z",
572
634
  * "event": "scrape.complete",
573
- * "data": { "job_id": "job_…", "status": "success", "url": "https://…", "completed_at": "…" }
635
+ * "data": {
636
+ * "job_id": "job_…",
637
+ * "status": "success",
638
+ * "url": "https://…",
639
+ * "completed_at": "…",
640
+ * "metadata": { "tenant": "acme" },
641
+ * "response_meta": { "usage": { "credits": 1, "proxy": "basic", "cache_hit": false } }
642
+ * }
574
643
  * }
575
644
  * ```
576
645
  */
646
+
577
647
  /** Terminal status carried by a {@link ScrapeCompleteWebhook}. */
578
648
  type ScrapeWebhookStatus = 'success' | 'failed' | 'cancelled';
579
649
  /** `data` block of a {@link ScrapeCompleteWebhook}. */
@@ -588,8 +658,17 @@ interface ScrapeCompleteWebhookData {
588
658
  completed_at: string;
589
659
  /** Failure message — present only when `status === 'failed'`. */
590
660
  error?: string;
591
- /** Correlation data echoed back from the original scrape request, if any. */
661
+ /**
662
+ * Correlation data echoed back from the original scrape request's
663
+ * `webhook.metadata`, if any.
664
+ */
592
665
  metadata?: Record<string, unknown>;
666
+ /**
667
+ * Response envelope metadata — `usage` (credits charged, resolved proxy tier,
668
+ * and whether the result was a cache hit). Present only on `status: 'success'`
669
+ * deliveries; omitted for `failed` / `cancelled` (no usage was charged).
670
+ */
671
+ response_meta?: ResponseMeta;
593
672
  }
594
673
  /**
595
674
  * Webhook envelope delivered when an async scrape job completes. The `event`
@@ -653,7 +732,7 @@ interface WaitForScrapeOptions extends Omit<RequestOptions, 'timeoutMs'> {
653
732
  * ```ts
654
733
  * import { Crawlbrulee } from '@crawlbrulee/sdk'
655
734
  *
656
- * const crawlbrulee = new Crawlbrulee({ apiKey: 'cble_…' })
735
+ * const crawlbrulee = new Crawlbrulee({ apiKey: 'cwbl_…' })
657
736
  * // or read CRAWLBRULEE_API_KEY from the environment:
658
737
  * const crawlbrulee = Crawlbrulee.fromEnv()
659
738
  *
@@ -882,8 +961,8 @@ declare function isCrawlbruleeError(err: unknown): err is CrawlbruleeError;
882
961
  * staging callers point at their own host via that option.
883
962
  */
884
963
  declare const DEFAULT_BASE_URL = "https://api.crawlbrulee.com";
885
- /** Default request timeout (60 s) when the caller doesn't specify one. */
886
- declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
964
+ /** Default request timeout when the caller doesn't specify one (0 disables the timeout). */
965
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 0;
887
966
  /** Environment variable read by `Crawlbrulee.fromEnv()` to source the API key. */
888
967
  declare const ENV_API_KEY = "CRAWLBRULEE_API_KEY";
889
968
 
@@ -979,4 +1058,4 @@ interface VerifyWebhookSignatureOptions {
979
1058
  */
980
1059
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
981
1060
 
982
- export { type ApiErrorDetails, type ApiErrorName, type ApiErrorResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncScrapeRequest, type AsyncScrapeResponse, type AsyncScrapeWebhook, AuthenticationError, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, type MapCache, type MapLinkItem, type MapLocation, type MapPagination, type MapRequest, type MapResponse, type MapTruncation, type MapTypes, NotFoundError, type PageInlineImage, type PageLink, type ProxyTier, RateLimitError, type RateLimitErrorDetails, type RequestOptions, type ScrapeCache, type ScrapeCompleteWebhook, type ScrapeCompleteWebhookData, type ScrapeExtract, type ScrapeLocation, type ScrapeMetadata, type ScrapeRequest, type ScrapeResponse, type ScrapeWebhookStatus, type ScreenshotAfterAction, type ScreenshotBeforeAction, type ScreenshotCleanup, type ScreenshotDeviceMode, type ScreenshotProperties, type ScreenshotRequest, type ScreenshotResult, type ScreenshotScrollAction, type ScreenshotSlice, type ScreenshotSliceAction, type ScreenshotType, type ScreenshotViewport, type ScreenshotViewportInfo, type ScreenshotWaitAction, TransportError, UsageAllocationError, type UsageAllocationErrorDetails, type UsageAllocationReason, type UsageLimitDetails, type UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, type WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1061
+ export { type ApiErrorDetails, type ApiErrorName, type ApiErrorResponse, type AsyncJobStatus, type AsyncJobStatusResponse, type AsyncScrapeRequest, type AsyncScrapeResponse, type AsyncScrapeWebhook, AuthenticationError, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, type MapCache, type MapLinkItem, type MapLocation, type MapPagination, type MapRequest, type MapResponse, type MapResponseMeta, type MapTruncation, type MapTypes, NotFoundError, type PageInlineImage, type PageLink, type ProxyTier, RateLimitError, type RateLimitErrorDetails, type RequestOptions, type ResolvedProxyTier, type ResponseMeta, type ScrapeCache, type ScrapeCompleteWebhook, type ScrapeCompleteWebhookData, type ScrapeExtract, type ScrapeLocation, type ScrapeMetadata, type ScrapeRequest, type ScrapeResponse, type ScrapeWebhookStatus, type ScreenshotAfterAction, type ScreenshotBeforeAction, type ScreenshotCleanup, type ScreenshotDeviceMode, type ScreenshotProperties, type ScreenshotRequest, type ScreenshotResult, type ScreenshotScrollAction, type ScreenshotSlice, type ScreenshotSliceAction, type ScreenshotType, type ScreenshotViewport, type ScreenshotViewportInfo, type ScreenshotWaitAction, TransportError, type Usage, UsageAllocationError, type UsageAllocationErrorDetails, type UsageAllocationReason, type UsageLimitDetails, type UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, type WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/config.ts
2
2
  var DEFAULT_BASE_URL = "https://api.crawlbrulee.com";
3
- var DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
3
+ var DEFAULT_REQUEST_TIMEOUT_MS = 0;
4
4
  var ENV_API_KEY = "CRAWLBRULEE_API_KEY";
5
- var USER_AGENT = "@crawlbrulee/sdk/0.1.2 (node)";
5
+ var USER_AGENT = "@crawlbrulee/sdk/0.4.0 (node)";
6
6
 
7
7
  // src/errors.ts
8
8
  var CrawlbruleeError = class extends Error {
@@ -157,7 +157,7 @@ var HttpClient = class {
157
157
  this.baseUrl = stripTrailingSlash(options.baseUrl ?? CwblInstrumentation.getBaseUrl());
158
158
  this.apiKey = options.apiKey;
159
159
  this.fetch = CwblInstrumentation.getFetch();
160
- this.timeoutMs = options.timeoutMs ?? 0;
160
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
161
161
  }
162
162
  /** Send a `GET` request and parse the response as `T`. */
163
163
  get(path, options) {