@crawlbrulee/sdk 1.0.0 → 1.1.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
@@ -91,19 +91,48 @@ type ResolvedProxyTier = 'basic' | 'advanced';
91
91
  */
92
92
  type BillingEngine = 'http' | 'browser' | 'screenshot' | 'cache';
93
93
  /**
94
- * Usage accounting for a single billable scrape operation, returned on the
95
- * response envelope of scrape and async-status (when terminal), and on
96
- * completion webhooks.
94
+ * Usage accounting for a single scrape, returned on `response_meta.usage` of
95
+ * scrape and async-status (when terminal) responses, and on completion
96
+ * webhooks.
97
+ *
98
+ * The response explains its own price:
99
+ * `total_credit_cost = engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost`.
100
+ *
101
+ * The four `*_credit_cost` / `proxy_multiplier` fields are optional in this
102
+ * type because older api versions do not send them. When you read the total,
103
+ * fall back to the deprecated name: `usage.total_credit_cost ?? usage.credits`.
97
104
  */
98
105
  interface Usage {
99
106
  /**
100
- * Credits charged for this operation. This equals the engine base multiplied
101
- * by the resolved proxy multiplier, plus {@link screenshot_slices}.
107
+ * Credits charged for this request. Always equals
108
+ * `engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost`.
109
+ * `0` when nothing is billed: a cache hit, or a page whose status is not
110
+ * billed (see `page_status_code` on the scrape result).
111
+ *
112
+ * Optional only because older api versions do not send it; fall back to
113
+ * {@link credits} when it is missing.
102
114
  */
103
- credits: number;
115
+ total_credit_cost?: number;
116
+ /**
117
+ * The engine base charged, before the proxy multiplier: `1` for `http`, `3`
118
+ * for `browser`, `5` for `screenshot`, `0` for `cache`. Also `0` when the
119
+ * page is not billed.
120
+ */
121
+ engine_credit_cost?: number;
122
+ /**
123
+ * The multiplier of the proxy tier the request ran on: `1` for `basic`, `5`
124
+ * for `advanced`. Always reported, even when the engine cost is `0`.
125
+ */
126
+ proxy_multiplier?: number;
127
+ /**
128
+ * The screenshot slicing add-on: `1` when the screenshot was split into
129
+ * slices on this request (a flat +1 credit outside the proxy multiplier,
130
+ * however many slices it made), otherwise `0`.
131
+ */
132
+ screenshot_slicing_credit_cost?: number;
104
133
  /**
105
- * Engine base billed for the delivered result: `http` (1), `browser` (3),
106
- * `screenshot` (5), or `cache` (0).
134
+ * Engine the delivered result was billed at: `http`, `browser`,
135
+ * `screenshot`, or `cache` (served from cache).
107
136
  */
108
137
  engine: BillingEngine;
109
138
  /**
@@ -112,8 +141,19 @@ interface Usage {
112
141
  */
113
142
  proxy: ResolvedProxyTier;
114
143
  /**
115
- * Screenshot-slice add-on billed for this request: `1` when slices were
116
- * produced during this request, otherwise `0`.
144
+ * Credits charged for this request. Same value as {@link total_credit_cost}.
145
+ *
146
+ * @deprecated Use {@link total_credit_cost}, which always has the same value.
147
+ * This field will be removed in a future version.
148
+ */
149
+ credits: number;
150
+ /**
151
+ * Screenshot slicing add-on: `1` when slices were made on this request,
152
+ * otherwise `0`. Same value as {@link screenshot_slicing_credit_cost}.
153
+ *
154
+ * @deprecated Use {@link screenshot_slicing_credit_cost}, which always has
155
+ * the same value. Despite its name this is a 0/1 charge, not a count of
156
+ * slices. This field will be removed in a future version.
117
157
  */
118
158
  screenshot_slices: number;
119
159
  }
@@ -186,7 +226,7 @@ interface ScreenshotRequest {
186
226
  * Machine-readable error names returned by the crawlbrulee API. Stable
187
227
  * identifiers — clients can switch on them.
188
228
  */
189
- type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large';
229
+ type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large' | 'target_unreachable';
190
230
  /** Reason a usage allocation was denied (when `error_name = usage_allocation_error`). */
191
231
  type UsageAllocationReason = 'credit_limit' | 'concurrency_limit' | 'duplicate_reservation' | 'internal_error';
192
232
  /** Snapshot of the org's current usage at the moment the error was raised. */
@@ -503,7 +543,14 @@ interface ScrapeMetadata {
503
543
  * outright rather than returning a hollow `200`, and isn't billed.
504
544
  */
505
545
  type ScrapeWarningCode = 'screenshot_truncated' | 'links_truncated' | 'inline_images_truncated' | 'raw_html_truncated' | 'metadata_truncated' | 'links_unavailable' | 'inline_images_unavailable' | 'metadata_unavailable';
506
- /** Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`. */
546
+ /**
547
+ * Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`.
548
+ *
549
+ * A successful response means we reached the site and got its final page —
550
+ * whatever status the site answered with. A 404, 410, 401 or 503 page comes
551
+ * back here with its content, and the site's own status is in
552
+ * {@link ScrapeResponse.page_status_code}. It is not thrown as an error.
553
+ */
507
554
  interface ScrapeResponse {
508
555
  /**
509
556
  * The URL that was actually scraped, after any redirects, in cleaned
@@ -513,6 +560,22 @@ interface ScrapeResponse {
513
560
  url: string;
514
561
  /** The URL you requested, echoed verbatim — before any redirects. */
515
562
  requested_url: string;
563
+ /**
564
+ * The HTTP status the target site answered with for the final page, after
565
+ * redirects. When the page is rendered in a browser, it is the status of the
566
+ * main document, not of images or scripts.
567
+ *
568
+ * A page the site really served is a successful result, whatever its
569
+ * status: a 404 page comes back here as `404` with its content — it is not
570
+ * thrown as an error. Check this field when the page's status matters to
571
+ * you, for example `if (page.page_status_code === 404)`.
572
+ *
573
+ * Billing follows this status: 2xx and 4xx pages are billed, except 403,
574
+ * 407, 408, 429 and 451; 5xx pages are never billed.
575
+ *
576
+ * Optional only because older api versions do not send it.
577
+ */
578
+ page_status_code?: number;
516
579
  /** `Content-Type` header returned by the origin. */
517
580
  content_type?: string;
518
581
  /**
@@ -559,8 +622,10 @@ interface ScrapeResponse {
559
622
  */
560
623
  warnings?: (ScrapeWarningCode | (string & {}))[];
561
624
  /**
562
- * Response envelope metadata. Carries `usage` (credits charged, billing
563
- * engine, resolved proxy tier, and billed screenshot slices).
625
+ * Response metadata. Carries `usage`: the credits charged
626
+ * (`total_credit_cost`) and how they add up (`engine_credit_cost`,
627
+ * `proxy_multiplier`, `screenshot_slicing_credit_cost`), plus the billed
628
+ * `engine` and the resolved `proxy` tier. See `Usage`.
564
629
  */
565
630
  response_meta: ResponseMeta;
566
631
  }
@@ -699,14 +764,48 @@ interface MapTruncation {
699
764
  }
700
765
  /** Billing engine reported by map: fresh discovery or a cached result. */
701
766
  type MapBillingEngine = 'http' | 'cache';
702
- /** Usage accounting returned by the map endpoint. Map operations do not produce screenshot slices. */
767
+ /**
768
+ * Usage accounting returned by the map endpoint. Map requests make no
769
+ * screenshots, so there is no slicing add-on:
770
+ * `total_credit_cost = engine_credit_cost × proxy_multiplier`.
771
+ *
772
+ * The `*_credit_cost` / `proxy_multiplier` fields are optional in this type
773
+ * because older api versions do not send them. When you read the total, fall
774
+ * back to the deprecated name: `usage.total_credit_cost ?? usage.credits`.
775
+ */
703
776
  interface MapUsage {
704
- /** Credits charged for this operation. */
705
- credits: number;
777
+ /**
778
+ * Credits charged for this map request. Always equals
779
+ * `engine_credit_cost × proxy_multiplier`. `0` for a cache hit, and for an
780
+ * empty map when the site answered only with statuses we don't bill (a `5xx`,
781
+ * for example) or not at all.
782
+ *
783
+ * Optional only because older api versions do not send it; fall back to
784
+ * {@link credits} when it is missing.
785
+ */
786
+ total_credit_cost?: number;
787
+ /**
788
+ * The engine base charged, before the proxy multiplier: `1` for `http`, `0`
789
+ * for `cache`. Also `0` for an empty map that is not billed.
790
+ */
791
+ engine_credit_cost?: number;
792
+ /**
793
+ * The multiplier of the proxy tier the request ran on: `1` for `basic`, `5`
794
+ * for `advanced`. Always reported, even when the engine cost is `0`.
795
+ */
796
+ proxy_multiplier?: number;
706
797
  /** `http` for fresh discovery or `cache` for a cached result. */
707
798
  engine: MapBillingEngine;
708
799
  /** The proxy tier the server resolved and used (never `auto`). */
709
800
  proxy: ResolvedProxyTier;
801
+ /**
802
+ * Credits charged for this map request. Same value as
803
+ * {@link total_credit_cost}.
804
+ *
805
+ * @deprecated Use {@link total_credit_cost}, which always has the same value.
806
+ * This field will be removed in a future version.
807
+ */
808
+ credits: number;
710
809
  }
711
810
  /**
712
811
  * Response envelope for a map result: map usage plus the map-specific
@@ -749,8 +848,8 @@ interface AsyncJobStatusResponse {
749
848
  error?: string;
750
849
  /**
751
850
  * Response envelope metadata — present only when the job has reached the
752
- * terminal `done` state. Carries `usage` (credits charged, billing engine,
753
- * resolved proxy tier, and billed screenshot slices).
851
+ * terminal `done` state. Carries `usage`: the credits charged and how they
852
+ * add up. See `Usage`.
754
853
  */
755
854
  response_meta?: ResponseMeta;
756
855
  }
@@ -810,6 +909,15 @@ interface ScrapeCompleteWebhookData {
810
909
  status: ScrapeWebhookStatus;
811
910
  /** The URL that was scraped. */
812
911
  url: string;
912
+ /**
913
+ * The HTTP status the target site answered with for the final page, after
914
+ * redirects. Present only on `status: 'success'` deliveries. A 404 page is a
915
+ * `success` delivery with `page_status_code: 404` — see
916
+ * `ScrapeResponse.page_status_code`.
917
+ *
918
+ * Optional also because older api versions do not send it.
919
+ */
920
+ page_status_code?: number;
813
921
  /** ISO-8601 UTC timestamp when the job reached its terminal state. */
814
922
  completed_at: string;
815
923
  /** Failure message — present only when `status === 'failed'`. */
@@ -820,9 +928,9 @@ interface ScrapeCompleteWebhookData {
820
928
  */
821
929
  metadata?: Record<string, unknown>;
822
930
  /**
823
- * Response envelope metadata — `usage` (credits charged, billing engine,
824
- * resolved proxy tier, and billed screenshot slices). Present only on `status: 'success'`
825
- * deliveries; omitted for `failed` / `cancelled` (no usage was charged).
931
+ * Response metadata — `usage`: the credits charged and how they add up
932
+ * (see `Usage`). Present only on `status: 'success'` deliveries;
933
+ * omitted for `failed` / `cancelled` (nothing was charged).
826
934
  */
827
935
  response_meta?: ResponseMeta;
828
936
  }
@@ -927,6 +1035,13 @@ declare class Crawlbrulee {
927
1035
  * (heavy JS rendering, screenshots of long pages) prefer
928
1036
  * {@link Crawlbrulee.scrapeAsync} so the connection isn't held open.
929
1037
  *
1038
+ * Any page the site really served is returned, whatever its status: a 404,
1039
+ * 410, 401 or 503 page resolves normally, with the site's status in
1040
+ * `page_status_code` — it does not throw. Check that field when the page's
1041
+ * status matters to you. The call throws when we could not return the page,
1042
+ * for example `TargetUnreachableError` when the site could not be reached,
1043
+ * `AntibotBlockedError`, or `PageTooLargeError`.
1044
+ *
930
1045
  * @param request — body for `POST /api/scrape`.
931
1046
  * @param options — per-call timeout and abort signal.
932
1047
  */
@@ -947,6 +1062,10 @@ declare class Crawlbrulee {
947
1062
  * Fetch the result of a completed async scrape job. Throws if the job is
948
1063
  * still pending/running — call {@link Crawlbrulee.getScrapeStatus}
949
1064
  * first, or use {@link Crawlbrulee.waitForScrape} to poll-then-fetch.
1065
+ *
1066
+ * Like {@link Crawlbrulee.scrape}, a 404 (or any other) page the site served
1067
+ * is a completed job: the result carries the site's status in
1068
+ * `page_status_code`.
950
1069
  */
951
1070
  getScrapeResult(jobId: string, options?: RequestOptions): Promise<ScrapeResponse>;
952
1071
  /**
@@ -1087,6 +1206,29 @@ declare class PageTooLargeError extends CrawlbruleeError {
1087
1206
  response?: ApiErrorResponse;
1088
1207
  });
1089
1208
  }
1209
+ /**
1210
+ * Raised when we could not reach the target site at all (HTTP 502,
1211
+ * `target_unreachable`) — for example the site did not answer in time or its
1212
+ * TLS certificate was not valid. We never got a page, so there is nothing to
1213
+ * return and you are not charged. The message is always "Could not reach the
1214
+ * target site." and there are no `details`.
1215
+ *
1216
+ * This is about the site, not your key or your request, so it is neither an
1217
+ * `AuthenticationError` nor a `ValidationError`. It is also not our own
1218
+ * outage ({@link ServiceUnavailableError}). Retrying later may help, since
1219
+ * the site may come back. The SDK does not retry for you.
1220
+ *
1221
+ * Not the same as a page with an error status: when the site answers with a
1222
+ * 404 or 503 page, the scrape succeeds and the site's status is in
1223
+ * `page_status_code`. Returned by both `scrape` and `map`.
1224
+ */
1225
+ declare class TargetUnreachableError extends CrawlbruleeError {
1226
+ constructor(message: string, options: {
1227
+ status: number;
1228
+ errorName: ApiErrorName;
1229
+ response?: ApiErrorResponse;
1230
+ });
1231
+ }
1090
1232
  /**
1091
1233
  * Raised for HTTP 429 responses. When the server included a `retry_after_ms`
1092
1234
  * hint in `details` it is surfaced directly on the instance.
@@ -1133,7 +1275,14 @@ declare class ValidationError extends CrawlbruleeError {
1133
1275
  response?: ApiErrorResponse;
1134
1276
  });
1135
1277
  }
1136
- /** Raised for 404 responses (e.g. unknown async job ID). */
1278
+ /**
1279
+ * Raised for 404 responses from the crawlbrulee api — something on our side
1280
+ * was not found, for example an unknown or expired async job ID.
1281
+ *
1282
+ * It never means the target page was not found. When the site you scrape
1283
+ * answers with a 404 page, the scrape succeeds and returns that page with
1284
+ * `page_status_code: 404`.
1285
+ */
1137
1286
  declare class NotFoundError extends CrawlbruleeError {
1138
1287
  constructor(message: string, options: {
1139
1288
  status: number;
@@ -1280,5 +1429,5 @@ interface VerifyWebhookSignatureOptions {
1280
1429
  */
1281
1430
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
1282
1431
  //#endregion
1283
- export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1432
+ export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TargetUnreachableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1284
1433
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -91,19 +91,48 @@ type ResolvedProxyTier = 'basic' | 'advanced';
91
91
  */
92
92
  type BillingEngine = 'http' | 'browser' | 'screenshot' | 'cache';
93
93
  /**
94
- * Usage accounting for a single billable scrape operation, returned on the
95
- * response envelope of scrape and async-status (when terminal), and on
96
- * completion webhooks.
94
+ * Usage accounting for a single scrape, returned on `response_meta.usage` of
95
+ * scrape and async-status (when terminal) responses, and on completion
96
+ * webhooks.
97
+ *
98
+ * The response explains its own price:
99
+ * `total_credit_cost = engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost`.
100
+ *
101
+ * The four `*_credit_cost` / `proxy_multiplier` fields are optional in this
102
+ * type because older api versions do not send them. When you read the total,
103
+ * fall back to the deprecated name: `usage.total_credit_cost ?? usage.credits`.
97
104
  */
98
105
  interface Usage {
99
106
  /**
100
- * Credits charged for this operation. This equals the engine base multiplied
101
- * by the resolved proxy multiplier, plus {@link screenshot_slices}.
107
+ * Credits charged for this request. Always equals
108
+ * `engine_credit_cost × proxy_multiplier + screenshot_slicing_credit_cost`.
109
+ * `0` when nothing is billed: a cache hit, or a page whose status is not
110
+ * billed (see `page_status_code` on the scrape result).
111
+ *
112
+ * Optional only because older api versions do not send it; fall back to
113
+ * {@link credits} when it is missing.
102
114
  */
103
- credits: number;
115
+ total_credit_cost?: number;
116
+ /**
117
+ * The engine base charged, before the proxy multiplier: `1` for `http`, `3`
118
+ * for `browser`, `5` for `screenshot`, `0` for `cache`. Also `0` when the
119
+ * page is not billed.
120
+ */
121
+ engine_credit_cost?: number;
122
+ /**
123
+ * The multiplier of the proxy tier the request ran on: `1` for `basic`, `5`
124
+ * for `advanced`. Always reported, even when the engine cost is `0`.
125
+ */
126
+ proxy_multiplier?: number;
127
+ /**
128
+ * The screenshot slicing add-on: `1` when the screenshot was split into
129
+ * slices on this request (a flat +1 credit outside the proxy multiplier,
130
+ * however many slices it made), otherwise `0`.
131
+ */
132
+ screenshot_slicing_credit_cost?: number;
104
133
  /**
105
- * Engine base billed for the delivered result: `http` (1), `browser` (3),
106
- * `screenshot` (5), or `cache` (0).
134
+ * Engine the delivered result was billed at: `http`, `browser`,
135
+ * `screenshot`, or `cache` (served from cache).
107
136
  */
108
137
  engine: BillingEngine;
109
138
  /**
@@ -112,8 +141,19 @@ interface Usage {
112
141
  */
113
142
  proxy: ResolvedProxyTier;
114
143
  /**
115
- * Screenshot-slice add-on billed for this request: `1` when slices were
116
- * produced during this request, otherwise `0`.
144
+ * Credits charged for this request. Same value as {@link total_credit_cost}.
145
+ *
146
+ * @deprecated Use {@link total_credit_cost}, which always has the same value.
147
+ * This field will be removed in a future version.
148
+ */
149
+ credits: number;
150
+ /**
151
+ * Screenshot slicing add-on: `1` when slices were made on this request,
152
+ * otherwise `0`. Same value as {@link screenshot_slicing_credit_cost}.
153
+ *
154
+ * @deprecated Use {@link screenshot_slicing_credit_cost}, which always has
155
+ * the same value. Despite its name this is a 0/1 charge, not a count of
156
+ * slices. This field will be removed in a future version.
117
157
  */
118
158
  screenshot_slices: number;
119
159
  }
@@ -186,7 +226,7 @@ interface ScreenshotRequest {
186
226
  * Machine-readable error names returned by the crawlbrulee API. Stable
187
227
  * identifiers — clients can switch on them.
188
228
  */
189
- type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large';
229
+ type ApiErrorName = 'usage_allocation_error' | 'request_timeout' | 'invalid_url' | 'url_too_long' | 'client_closed_request' | 'reset_password_token_expired' | 'user_not_found' | 'unsupported_url_schema' | 'url_credentials_not_supported' | 'blocked_url' | 'scrape_error' | 'job_failed' | 'incorrect_login_method_used' | 'not_found' | 'invalid_credentials' | 'resource_already_exists' | 'access_denied' | 'internal_server_error' | 'service_unavailable' | 'too_many_requests' | 'unsupported_content' | 'unsupported_screenshot_output' | 'validation_error' | 'antibot_blocked' | 'too_many_redirects' | 'page_too_large' | 'target_unreachable';
190
230
  /** Reason a usage allocation was denied (when `error_name = usage_allocation_error`). */
191
231
  type UsageAllocationReason = 'credit_limit' | 'concurrency_limit' | 'duplicate_reservation' | 'internal_error';
192
232
  /** Snapshot of the org's current usage at the moment the error was raised. */
@@ -503,7 +543,14 @@ interface ScrapeMetadata {
503
543
  * outright rather than returning a hollow `200`, and isn't billed.
504
544
  */
505
545
  type ScrapeWarningCode = 'screenshot_truncated' | 'links_truncated' | 'inline_images_truncated' | 'raw_html_truncated' | 'metadata_truncated' | 'links_unavailable' | 'inline_images_unavailable' | 'metadata_unavailable';
506
- /** Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`. */
546
+ /**
547
+ * Successful response from `POST /api/scrape` and `GET /api/scrape/result/:jobId`.
548
+ *
549
+ * A successful response means we reached the site and got its final page —
550
+ * whatever status the site answered with. A 404, 410, 401 or 503 page comes
551
+ * back here with its content, and the site's own status is in
552
+ * {@link ScrapeResponse.page_status_code}. It is not thrown as an error.
553
+ */
507
554
  interface ScrapeResponse {
508
555
  /**
509
556
  * The URL that was actually scraped, after any redirects, in cleaned
@@ -513,6 +560,22 @@ interface ScrapeResponse {
513
560
  url: string;
514
561
  /** The URL you requested, echoed verbatim — before any redirects. */
515
562
  requested_url: string;
563
+ /**
564
+ * The HTTP status the target site answered with for the final page, after
565
+ * redirects. When the page is rendered in a browser, it is the status of the
566
+ * main document, not of images or scripts.
567
+ *
568
+ * A page the site really served is a successful result, whatever its
569
+ * status: a 404 page comes back here as `404` with its content — it is not
570
+ * thrown as an error. Check this field when the page's status matters to
571
+ * you, for example `if (page.page_status_code === 404)`.
572
+ *
573
+ * Billing follows this status: 2xx and 4xx pages are billed, except 403,
574
+ * 407, 408, 429 and 451; 5xx pages are never billed.
575
+ *
576
+ * Optional only because older api versions do not send it.
577
+ */
578
+ page_status_code?: number;
516
579
  /** `Content-Type` header returned by the origin. */
517
580
  content_type?: string;
518
581
  /**
@@ -559,8 +622,10 @@ interface ScrapeResponse {
559
622
  */
560
623
  warnings?: (ScrapeWarningCode | (string & {}))[];
561
624
  /**
562
- * Response envelope metadata. Carries `usage` (credits charged, billing
563
- * engine, resolved proxy tier, and billed screenshot slices).
625
+ * Response metadata. Carries `usage`: the credits charged
626
+ * (`total_credit_cost`) and how they add up (`engine_credit_cost`,
627
+ * `proxy_multiplier`, `screenshot_slicing_credit_cost`), plus the billed
628
+ * `engine` and the resolved `proxy` tier. See `Usage`.
564
629
  */
565
630
  response_meta: ResponseMeta;
566
631
  }
@@ -699,14 +764,48 @@ interface MapTruncation {
699
764
  }
700
765
  /** Billing engine reported by map: fresh discovery or a cached result. */
701
766
  type MapBillingEngine = 'http' | 'cache';
702
- /** Usage accounting returned by the map endpoint. Map operations do not produce screenshot slices. */
767
+ /**
768
+ * Usage accounting returned by the map endpoint. Map requests make no
769
+ * screenshots, so there is no slicing add-on:
770
+ * `total_credit_cost = engine_credit_cost × proxy_multiplier`.
771
+ *
772
+ * The `*_credit_cost` / `proxy_multiplier` fields are optional in this type
773
+ * because older api versions do not send them. When you read the total, fall
774
+ * back to the deprecated name: `usage.total_credit_cost ?? usage.credits`.
775
+ */
703
776
  interface MapUsage {
704
- /** Credits charged for this operation. */
705
- credits: number;
777
+ /**
778
+ * Credits charged for this map request. Always equals
779
+ * `engine_credit_cost × proxy_multiplier`. `0` for a cache hit, and for an
780
+ * empty map when the site answered only with statuses we don't bill (a `5xx`,
781
+ * for example) or not at all.
782
+ *
783
+ * Optional only because older api versions do not send it; fall back to
784
+ * {@link credits} when it is missing.
785
+ */
786
+ total_credit_cost?: number;
787
+ /**
788
+ * The engine base charged, before the proxy multiplier: `1` for `http`, `0`
789
+ * for `cache`. Also `0` for an empty map that is not billed.
790
+ */
791
+ engine_credit_cost?: number;
792
+ /**
793
+ * The multiplier of the proxy tier the request ran on: `1` for `basic`, `5`
794
+ * for `advanced`. Always reported, even when the engine cost is `0`.
795
+ */
796
+ proxy_multiplier?: number;
706
797
  /** `http` for fresh discovery or `cache` for a cached result. */
707
798
  engine: MapBillingEngine;
708
799
  /** The proxy tier the server resolved and used (never `auto`). */
709
800
  proxy: ResolvedProxyTier;
801
+ /**
802
+ * Credits charged for this map request. Same value as
803
+ * {@link total_credit_cost}.
804
+ *
805
+ * @deprecated Use {@link total_credit_cost}, which always has the same value.
806
+ * This field will be removed in a future version.
807
+ */
808
+ credits: number;
710
809
  }
711
810
  /**
712
811
  * Response envelope for a map result: map usage plus the map-specific
@@ -749,8 +848,8 @@ interface AsyncJobStatusResponse {
749
848
  error?: string;
750
849
  /**
751
850
  * Response envelope metadata — present only when the job has reached the
752
- * terminal `done` state. Carries `usage` (credits charged, billing engine,
753
- * resolved proxy tier, and billed screenshot slices).
851
+ * terminal `done` state. Carries `usage`: the credits charged and how they
852
+ * add up. See `Usage`.
754
853
  */
755
854
  response_meta?: ResponseMeta;
756
855
  }
@@ -810,6 +909,15 @@ interface ScrapeCompleteWebhookData {
810
909
  status: ScrapeWebhookStatus;
811
910
  /** The URL that was scraped. */
812
911
  url: string;
912
+ /**
913
+ * The HTTP status the target site answered with for the final page, after
914
+ * redirects. Present only on `status: 'success'` deliveries. A 404 page is a
915
+ * `success` delivery with `page_status_code: 404` — see
916
+ * `ScrapeResponse.page_status_code`.
917
+ *
918
+ * Optional also because older api versions do not send it.
919
+ */
920
+ page_status_code?: number;
813
921
  /** ISO-8601 UTC timestamp when the job reached its terminal state. */
814
922
  completed_at: string;
815
923
  /** Failure message — present only when `status === 'failed'`. */
@@ -820,9 +928,9 @@ interface ScrapeCompleteWebhookData {
820
928
  */
821
929
  metadata?: Record<string, unknown>;
822
930
  /**
823
- * Response envelope metadata — `usage` (credits charged, billing engine,
824
- * resolved proxy tier, and billed screenshot slices). Present only on `status: 'success'`
825
- * deliveries; omitted for `failed` / `cancelled` (no usage was charged).
931
+ * Response metadata — `usage`: the credits charged and how they add up
932
+ * (see `Usage`). Present only on `status: 'success'` deliveries;
933
+ * omitted for `failed` / `cancelled` (nothing was charged).
826
934
  */
827
935
  response_meta?: ResponseMeta;
828
936
  }
@@ -927,6 +1035,13 @@ declare class Crawlbrulee {
927
1035
  * (heavy JS rendering, screenshots of long pages) prefer
928
1036
  * {@link Crawlbrulee.scrapeAsync} so the connection isn't held open.
929
1037
  *
1038
+ * Any page the site really served is returned, whatever its status: a 404,
1039
+ * 410, 401 or 503 page resolves normally, with the site's status in
1040
+ * `page_status_code` — it does not throw. Check that field when the page's
1041
+ * status matters to you. The call throws when we could not return the page,
1042
+ * for example `TargetUnreachableError` when the site could not be reached,
1043
+ * `AntibotBlockedError`, or `PageTooLargeError`.
1044
+ *
930
1045
  * @param request — body for `POST /api/scrape`.
931
1046
  * @param options — per-call timeout and abort signal.
932
1047
  */
@@ -947,6 +1062,10 @@ declare class Crawlbrulee {
947
1062
  * Fetch the result of a completed async scrape job. Throws if the job is
948
1063
  * still pending/running — call {@link Crawlbrulee.getScrapeStatus}
949
1064
  * first, or use {@link Crawlbrulee.waitForScrape} to poll-then-fetch.
1065
+ *
1066
+ * Like {@link Crawlbrulee.scrape}, a 404 (or any other) page the site served
1067
+ * is a completed job: the result carries the site's status in
1068
+ * `page_status_code`.
950
1069
  */
951
1070
  getScrapeResult(jobId: string, options?: RequestOptions): Promise<ScrapeResponse>;
952
1071
  /**
@@ -1087,6 +1206,29 @@ declare class PageTooLargeError extends CrawlbruleeError {
1087
1206
  response?: ApiErrorResponse;
1088
1207
  });
1089
1208
  }
1209
+ /**
1210
+ * Raised when we could not reach the target site at all (HTTP 502,
1211
+ * `target_unreachable`) — for example the site did not answer in time or its
1212
+ * TLS certificate was not valid. We never got a page, so there is nothing to
1213
+ * return and you are not charged. The message is always "Could not reach the
1214
+ * target site." and there are no `details`.
1215
+ *
1216
+ * This is about the site, not your key or your request, so it is neither an
1217
+ * `AuthenticationError` nor a `ValidationError`. It is also not our own
1218
+ * outage ({@link ServiceUnavailableError}). Retrying later may help, since
1219
+ * the site may come back. The SDK does not retry for you.
1220
+ *
1221
+ * Not the same as a page with an error status: when the site answers with a
1222
+ * 404 or 503 page, the scrape succeeds and the site's status is in
1223
+ * `page_status_code`. Returned by both `scrape` and `map`.
1224
+ */
1225
+ declare class TargetUnreachableError extends CrawlbruleeError {
1226
+ constructor(message: string, options: {
1227
+ status: number;
1228
+ errorName: ApiErrorName;
1229
+ response?: ApiErrorResponse;
1230
+ });
1231
+ }
1090
1232
  /**
1091
1233
  * Raised for HTTP 429 responses. When the server included a `retry_after_ms`
1092
1234
  * hint in `details` it is surfaced directly on the instance.
@@ -1133,7 +1275,14 @@ declare class ValidationError extends CrawlbruleeError {
1133
1275
  response?: ApiErrorResponse;
1134
1276
  });
1135
1277
  }
1136
- /** Raised for 404 responses (e.g. unknown async job ID). */
1278
+ /**
1279
+ * Raised for 404 responses from the crawlbrulee api — something on our side
1280
+ * was not found, for example an unknown or expired async job ID.
1281
+ *
1282
+ * It never means the target page was not found. When the site you scrape
1283
+ * answers with a 404 page, the scrape succeeds and returns that page with
1284
+ * `page_status_code: 404`.
1285
+ */
1137
1286
  declare class NotFoundError extends CrawlbruleeError {
1138
1287
  constructor(message: string, options: {
1139
1288
  status: number;
@@ -1280,5 +1429,5 @@ interface VerifyWebhookSignatureOptions {
1280
1429
  */
1281
1430
  declare function verifyWebhookSignature(options: VerifyWebhookSignatureOptions): Promise<WebhookVerificationResult>;
1282
1431
  //#endregion
1283
- export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1432
+ export { AntibotBlockedError, ApiErrorDetails, ApiErrorName, ApiErrorResponse, AsyncJobStatus, AsyncJobStatusResponse, AsyncScrapeRequest, AsyncScrapeResponse, AsyncScrapeWebhook, AuthenticationError, BillingEngine, Crawlbrulee, CrawlbruleeError, type CrawlbruleeOptions, DEFAULT_BASE_URL, DEFAULT_REQUEST_TIMEOUT_MS, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, ENV_API_KEY, type HttpMethod, MapBillingEngine, MapCache, MapDiscoveryCapReason, MapLinkItem, MapLocation, MapPagination, MapRequest, MapResponse, MapResponseMeta, MapTruncation, MapTypes, MapUsage, NotFoundError, PageInlineImage, PageLink, PageTooLargeError, ProxyTier, RateLimitError, RateLimitErrorDetails, type RequestOptions, ResolvedProxyTier, ResponseMeta, ScrapeCache, ScrapeCleanup, ScrapeCompleteWebhook, ScrapeCompleteWebhookData, ScrapeExtract, ScrapeLocation, ScrapeMetadata, ScrapeRequest, ScrapeResponse, ScrapeWarningCode, ScrapeWebhookStatus, ScreenshotAfterAction, ScreenshotBeforeAction, ScreenshotDeviceMode, ScreenshotProperties, ScreenshotRequest, ScreenshotResult, ScreenshotScrollAction, ScreenshotSlice, ScreenshotSliceAction, ScreenshotType, ScreenshotViewport, ScreenshotViewportInfo, ScreenshotWaitAction, ServiceUnavailableError, TargetUnreachableError, TooManyRedirectsError, TransportError, Usage, UsageAllocationError, UsageAllocationErrorDetails, UsageAllocationReason, UsageLimitDetails, UsageResponse, ValidationError, type VerifyWebhookSignatureOptions, WEBHOOK_EVENT_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_ROTATED_HEADER, type WaitForScrapeOptions, type WebhookSignatureSource, type WebhookVerificationFailureReason, type WebhookVerificationResult, WhoamiResponse, isCrawlbruleeError, verifyWebhookSignature };
1284
1433
  //# sourceMappingURL=index.d.ts.map