@websitescreenshotworld/sdk 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +21 -0
  3. package/README.md +399 -2
  4. package/dist/cjs/auto-schedule.d.ts +20 -0
  5. package/dist/cjs/auto-schedule.js +34 -0
  6. package/dist/cjs/client.d.ts +41 -0
  7. package/dist/cjs/client.js +58 -0
  8. package/dist/cjs/error-codes.d.ts +54 -0
  9. package/dist/cjs/error-codes.js +94 -0
  10. package/dist/cjs/errors.d.ts +56 -0
  11. package/dist/cjs/errors.js +112 -0
  12. package/dist/cjs/files.d.ts +6 -0
  13. package/dist/cjs/files.js +45 -0
  14. package/dist/cjs/index.d.ts +16 -0
  15. package/dist/cjs/index.js +37 -0
  16. package/dist/cjs/instant-snap.d.ts +99 -0
  17. package/dist/cjs/instant-snap.js +205 -0
  18. package/dist/cjs/models/capture-file.d.ts +35 -0
  19. package/dist/cjs/models/capture-file.js +34 -0
  20. package/dist/cjs/models/capture-options.d.ts +144 -0
  21. package/dist/cjs/models/capture-options.js +2 -0
  22. package/dist/cjs/models/capture.d.ts +108 -0
  23. package/dist/cjs/models/capture.js +63 -0
  24. package/dist/cjs/models/defaults.d.ts +82 -0
  25. package/dist/cjs/models/defaults.js +46 -0
  26. package/dist/cjs/models/tokens.d.ts +92 -0
  27. package/dist/cjs/models/tokens.js +85 -0
  28. package/dist/cjs/models/trigger-result.d.ts +20 -0
  29. package/dist/cjs/models/trigger-result.js +13 -0
  30. package/dist/cjs/package.json +3 -0
  31. package/dist/cjs/transport.d.ts +55 -0
  32. package/dist/cjs/transport.js +206 -0
  33. package/dist/cjs/version.d.ts +2 -0
  34. package/dist/cjs/version.js +5 -0
  35. package/dist/cjs/webhooks/events.d.ts +128 -0
  36. package/dist/cjs/webhooks/events.js +13 -0
  37. package/dist/cjs/webhooks/parse-event.d.ts +10 -0
  38. package/dist/cjs/webhooks/parse-event.js +149 -0
  39. package/dist/cjs/webhooks/webhook.d.ts +26 -0
  40. package/dist/cjs/webhooks/webhook.js +78 -0
  41. package/dist/cjs/wire.d.ts +15 -0
  42. package/dist/cjs/wire.js +71 -0
  43. package/dist/esm/auto-schedule.d.ts +20 -0
  44. package/dist/esm/auto-schedule.js +30 -0
  45. package/dist/esm/client.d.ts +41 -0
  46. package/dist/esm/client.js +54 -0
  47. package/dist/esm/error-codes.d.ts +54 -0
  48. package/dist/esm/error-codes.js +91 -0
  49. package/dist/esm/errors.d.ts +56 -0
  50. package/dist/esm/errors.js +98 -0
  51. package/dist/esm/files.d.ts +6 -0
  52. package/dist/esm/files.js +41 -0
  53. package/dist/esm/index.d.ts +16 -0
  54. package/dist/esm/index.js +7 -0
  55. package/dist/esm/instant-snap.d.ts +99 -0
  56. package/dist/esm/instant-snap.js +201 -0
  57. package/dist/esm/models/capture-file.d.ts +35 -0
  58. package/dist/esm/models/capture-file.js +31 -0
  59. package/dist/esm/models/capture-options.d.ts +144 -0
  60. package/dist/esm/models/capture-options.js +1 -0
  61. package/dist/esm/models/capture.d.ts +108 -0
  62. package/dist/esm/models/capture.js +57 -0
  63. package/dist/esm/models/defaults.d.ts +82 -0
  64. package/dist/esm/models/defaults.js +42 -0
  65. package/dist/esm/models/tokens.d.ts +92 -0
  66. package/dist/esm/models/tokens.js +82 -0
  67. package/dist/esm/models/trigger-result.d.ts +20 -0
  68. package/dist/esm/models/trigger-result.js +10 -0
  69. package/dist/esm/transport.d.ts +55 -0
  70. package/dist/esm/transport.js +201 -0
  71. package/dist/esm/version.d.ts +2 -0
  72. package/dist/esm/version.js +2 -0
  73. package/dist/esm/webhooks/events.d.ts +128 -0
  74. package/dist/esm/webhooks/events.js +10 -0
  75. package/dist/esm/webhooks/parse-event.d.ts +10 -0
  76. package/dist/esm/webhooks/parse-event.js +146 -0
  77. package/dist/esm/webhooks/webhook.d.ts +26 -0
  78. package/dist/esm/webhooks/webhook.js +75 -0
  79. package/dist/esm/wire.d.ts +15 -0
  80. package/dist/esm/wire.js +66 -0
  81. package/package.json +68 -4
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FALLBACK_CODE_FOR_OTHER_STATUS = exports.FALLBACK_CODE_BY_STATUS = exports.RETRYABLE_CODES = exports.ERROR_KINDS = exports.ErrorCode = void 0;
4
+ /**
5
+ * The `error_code` tokens the APIs answer with. Switch on these, never on the HTTP status or the
6
+ * message. A code added to the API later still comes through as a plain string.
7
+ */
8
+ exports.ErrorCode = {
9
+ ApiKeyInvalid: "api_key_invalid",
10
+ ValidationFailed: "validation_failed",
11
+ S3DestinationInvalid: "s3_destination_invalid",
12
+ WebPageIdInvalid: "web_page_id_invalid",
13
+ IdempotencyKeyReused: "idempotency_key_reused",
14
+ /** The web page is a sitemap schedule, which runs only on its schedule. Not retried. */
15
+ SitemapScheduleNotTriggerable: "sitemap_schedule_not_triggerable",
16
+ QuotaExhausted: "quota_exhausted",
17
+ FeatureNotAvailable: "feature_not_available",
18
+ NoTriggerAllowance: "no_trigger_allowance",
19
+ Forbidden: "forbidden",
20
+ CaptureNotFound: "capture_not_found",
21
+ WebPageNotFound: "web_page_not_found",
22
+ NotFound: "not_found",
23
+ RateLimited: "rate_limited",
24
+ /** Too many async captures are already waiting or running. Not retried. */
25
+ QueueFull: "queue_full",
26
+ CaptureFailed: "capture_failed",
27
+ CaptureTimeout: "capture_timeout",
28
+ PayloadTooLarge: "payload_too_large",
29
+ /** An async capture still waited for a browser 15 minutes after it was accepted. Not charged. */
30
+ CaptureExpired: "capture_expired",
31
+ CaptureBusy: "capture_busy",
32
+ ServiceUnavailable: "service_unavailable",
33
+ InternalError: "internal_error",
34
+ RequestCancelled: "request_cancelled",
35
+ IdempotencyKeyInUse: "idempotency_key_in_use",
36
+ UnknownError: "unknown_error",
37
+ };
38
+ /** The kind of error each known code raises. Codes not listed raise the base error. */
39
+ exports.ERROR_KINDS = {
40
+ authentication: ["api_key_invalid"],
41
+ invalid_request: [
42
+ "validation_failed",
43
+ "s3_destination_invalid",
44
+ "web_page_id_invalid",
45
+ "idempotency_key_reused",
46
+ "sitemap_schedule_not_triggerable",
47
+ ],
48
+ plan_limit: [
49
+ "quota_exhausted",
50
+ "feature_not_available",
51
+ "no_trigger_allowance",
52
+ "forbidden",
53
+ ],
54
+ not_found: ["capture_not_found", "web_page_not_found", "not_found"],
55
+ rate_limit: ["rate_limited", "queue_full"],
56
+ capture: [
57
+ "capture_failed",
58
+ "capture_timeout",
59
+ "payload_too_large",
60
+ "capture_expired",
61
+ ],
62
+ service: [
63
+ "capture_busy",
64
+ "service_unavailable",
65
+ "internal_error",
66
+ "request_cancelled",
67
+ "idempotency_key_in_use",
68
+ ],
69
+ };
70
+ /**
71
+ * Codes that are worth sending the same request again for. `queue_full` is not one: the async queue
72
+ * stays full until captures finish, so it is raised for the caller with `retryAfterSeconds`.
73
+ */
74
+ exports.RETRYABLE_CODES = new Set([
75
+ "rate_limited",
76
+ "capture_busy",
77
+ "service_unavailable",
78
+ "idempotency_key_in_use",
79
+ ]);
80
+ /** The code for a refusal that came without a JSON error body, usually from a proxy. */
81
+ exports.FALLBACK_CODE_BY_STATUS = {
82
+ 400: "validation_failed",
83
+ 401: "api_key_invalid",
84
+ 403: "forbidden",
85
+ 404: "not_found",
86
+ 409: "idempotency_key_in_use",
87
+ 413: "payload_too_large",
88
+ 429: "rate_limited",
89
+ 500: "internal_error",
90
+ 502: "service_unavailable",
91
+ 503: "service_unavailable",
92
+ 504: "service_unavailable",
93
+ };
94
+ exports.FALLBACK_CODE_FOR_OTHER_STATUS = "unknown_error";
@@ -0,0 +1,56 @@
1
+ import { type ErrorCode } from "./error-codes.js";
2
+ /** What an error knows about the answer that caused it. */
3
+ export interface ErrorDetails {
4
+ errorCode?: ErrorCode | null;
5
+ httpStatus?: number | null;
6
+ retryAfterSeconds?: number | null;
7
+ rawBody?: string | null;
8
+ cause?: unknown;
9
+ }
10
+ /**
11
+ * The base class of every error this library throws. An `error_code` this version does not know
12
+ * raises this class itself; known codes raise one of its subclasses.
13
+ */
14
+ export declare class WebsiteScreenshotWorldError extends Error {
15
+ /** The API's error token, such as `rate_limited`. `null` when no answer came back. */
16
+ readonly errorCode: ErrorCode | null;
17
+ /** The HTTP status of the answer. `null` when no answer came back. */
18
+ readonly httpStatus: number | null;
19
+ /** How long the API asked to wait before trying again, in seconds. */
20
+ readonly retryAfterSeconds: number | null;
21
+ /** The body of the answer as received. */
22
+ readonly rawBody: string | null;
23
+ constructor(message: string, details?: ErrorDetails);
24
+ }
25
+ /** The API key is missing, malformed, revoked or belongs to the other product. */
26
+ export declare class AuthenticationError extends WebsiteScreenshotWorldError {
27
+ }
28
+ /** The request was refused as invalid. Sending it again will not help. */
29
+ export declare class InvalidRequestError extends WebsiteScreenshotWorldError {
30
+ }
31
+ /** The plan has run out of captures, or does not include what was asked for. */
32
+ export declare class PlanLimitError extends WebsiteScreenshotWorldError {
33
+ }
34
+ /** The capture or web page does not exist for this account. */
35
+ export declare class NotFoundError extends WebsiteScreenshotWorldError {
36
+ }
37
+ /** Too many requests, still refused after the retries ran out. */
38
+ export declare class RateLimitError extends WebsiteScreenshotWorldError {
39
+ }
40
+ /** The website could not be captured, or the file was too large to return. Not retried. */
41
+ export declare class CaptureError extends WebsiteScreenshotWorldError {
42
+ }
43
+ /** The service was busy or failed on its side. */
44
+ export declare class ServiceError extends WebsiteScreenshotWorldError {
45
+ }
46
+ /**
47
+ * The request could not be sent, no answer came back, or the call ran out of time. The underlying
48
+ * error, when there is one, is the `cause`.
49
+ */
50
+ export declare class ConnectionError extends WebsiteScreenshotWorldError {
51
+ }
52
+ /** A webhook's signature header is missing, malformed, too old or does not match the body. */
53
+ export declare class SignatureVerificationError extends WebsiteScreenshotWorldError {
54
+ }
55
+ /** Creates the error class that `errorCode` raises. */
56
+ export declare function errorFor(errorCode: string, message: string, details: Omit<ErrorDetails, "errorCode">): WebsiteScreenshotWorldError;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignatureVerificationError = exports.ConnectionError = exports.ServiceError = exports.CaptureError = exports.RateLimitError = exports.NotFoundError = exports.PlanLimitError = exports.InvalidRequestError = exports.AuthenticationError = exports.WebsiteScreenshotWorldError = void 0;
4
+ exports.errorFor = errorFor;
5
+ const error_codes_js_1 = require("./error-codes.js");
6
+ /**
7
+ * The base class of every error this library throws. An `error_code` this version does not know
8
+ * raises this class itself; known codes raise one of its subclasses.
9
+ */
10
+ class WebsiteScreenshotWorldError extends Error {
11
+ static {
12
+ this.prototype.name = "WebsiteScreenshotWorldError";
13
+ }
14
+ /** The API's error token, such as `rate_limited`. `null` when no answer came back. */
15
+ errorCode;
16
+ /** The HTTP status of the answer. `null` when no answer came back. */
17
+ httpStatus;
18
+ /** How long the API asked to wait before trying again, in seconds. */
19
+ retryAfterSeconds;
20
+ /** The body of the answer as received. */
21
+ rawBody;
22
+ constructor(message, details = {}) {
23
+ super(message, details.cause === undefined ? undefined : { cause: details.cause });
24
+ this.errorCode = details.errorCode ?? null;
25
+ this.httpStatus = details.httpStatus ?? null;
26
+ this.retryAfterSeconds = details.retryAfterSeconds ?? null;
27
+ this.rawBody = details.rawBody ?? null;
28
+ }
29
+ }
30
+ exports.WebsiteScreenshotWorldError = WebsiteScreenshotWorldError;
31
+ /** The API key is missing, malformed, revoked or belongs to the other product. */
32
+ class AuthenticationError extends WebsiteScreenshotWorldError {
33
+ static {
34
+ this.prototype.name = "AuthenticationError";
35
+ }
36
+ }
37
+ exports.AuthenticationError = AuthenticationError;
38
+ /** The request was refused as invalid. Sending it again will not help. */
39
+ class InvalidRequestError extends WebsiteScreenshotWorldError {
40
+ static {
41
+ this.prototype.name = "InvalidRequestError";
42
+ }
43
+ }
44
+ exports.InvalidRequestError = InvalidRequestError;
45
+ /** The plan has run out of captures, or does not include what was asked for. */
46
+ class PlanLimitError extends WebsiteScreenshotWorldError {
47
+ static {
48
+ this.prototype.name = "PlanLimitError";
49
+ }
50
+ }
51
+ exports.PlanLimitError = PlanLimitError;
52
+ /** The capture or web page does not exist for this account. */
53
+ class NotFoundError extends WebsiteScreenshotWorldError {
54
+ static {
55
+ this.prototype.name = "NotFoundError";
56
+ }
57
+ }
58
+ exports.NotFoundError = NotFoundError;
59
+ /** Too many requests, still refused after the retries ran out. */
60
+ class RateLimitError extends WebsiteScreenshotWorldError {
61
+ static {
62
+ this.prototype.name = "RateLimitError";
63
+ }
64
+ }
65
+ exports.RateLimitError = RateLimitError;
66
+ /** The website could not be captured, or the file was too large to return. Not retried. */
67
+ class CaptureError extends WebsiteScreenshotWorldError {
68
+ static {
69
+ this.prototype.name = "CaptureError";
70
+ }
71
+ }
72
+ exports.CaptureError = CaptureError;
73
+ /** The service was busy or failed on its side. */
74
+ class ServiceError extends WebsiteScreenshotWorldError {
75
+ static {
76
+ this.prototype.name = "ServiceError";
77
+ }
78
+ }
79
+ exports.ServiceError = ServiceError;
80
+ /**
81
+ * The request could not be sent, no answer came back, or the call ran out of time. The underlying
82
+ * error, when there is one, is the `cause`.
83
+ */
84
+ class ConnectionError extends WebsiteScreenshotWorldError {
85
+ static {
86
+ this.prototype.name = "ConnectionError";
87
+ }
88
+ }
89
+ exports.ConnectionError = ConnectionError;
90
+ /** A webhook's signature header is missing, malformed, too old or does not match the body. */
91
+ class SignatureVerificationError extends WebsiteScreenshotWorldError {
92
+ static {
93
+ this.prototype.name = "SignatureVerificationError";
94
+ }
95
+ }
96
+ exports.SignatureVerificationError = SignatureVerificationError;
97
+ const CLASS_BY_KIND = {
98
+ authentication: AuthenticationError,
99
+ invalid_request: InvalidRequestError,
100
+ plan_limit: PlanLimitError,
101
+ not_found: NotFoundError,
102
+ rate_limit: RateLimitError,
103
+ capture: CaptureError,
104
+ service: ServiceError,
105
+ };
106
+ const KIND_BY_CODE = new Map(Object.entries(error_codes_js_1.ERROR_KINDS).flatMap(([kind, codes]) => codes.map((code) => [code, kind])));
107
+ /** Creates the error class that `errorCode` raises. */
108
+ function errorFor(errorCode, message, details) {
109
+ const kind = KIND_BY_CODE.get(errorCode);
110
+ const ErrorClass = kind === undefined ? WebsiteScreenshotWorldError : CLASS_BY_KIND[kind];
111
+ return new ErrorClass(message, { ...details, errorCode });
112
+ }
@@ -0,0 +1,6 @@
1
+ /** Where a file is written: a path, a Node.js writable stream or a web `WritableStream`. */
2
+ export type FileDestination = string | NodeJS.WritableStream | WritableStream<Uint8Array>;
3
+ /** Streams `body` to `destination`. A file left half-written by a failure is removed. */
4
+ export declare function writeBody(body: ReadableStream<Uint8Array>, destination: FileDestination, signal?: AbortSignal): Promise<void>;
5
+ /** The file name from a `Content-Disposition` header, preferring the RFC 6266 `filename*` form. */
6
+ export declare function filenameFrom(contentDisposition: string | null): string | null;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeBody = writeBody;
4
+ exports.filenameFrom = filenameFrom;
5
+ const node_fs_1 = require("node:fs");
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_stream_1 = require("node:stream");
8
+ const promises_2 = require("node:stream/promises");
9
+ /** Streams `body` to `destination`. A file left half-written by a failure is removed. */
10
+ async function writeBody(body, destination, signal) {
11
+ const options = signal === undefined ? {} : { signal };
12
+ if (destination instanceof WritableStream) {
13
+ await body.pipeTo(destination, options);
14
+ return;
15
+ }
16
+ const source = node_stream_1.Readable.fromWeb(body);
17
+ if (typeof destination !== "string") {
18
+ await (0, promises_2.pipeline)(source, destination, options);
19
+ return;
20
+ }
21
+ try {
22
+ await (0, promises_2.pipeline)(source, (0, node_fs_1.createWriteStream)(destination), options);
23
+ }
24
+ catch (error) {
25
+ await (0, promises_1.rm)(destination, { force: true });
26
+ throw error;
27
+ }
28
+ }
29
+ /** The file name from a `Content-Disposition` header, preferring the RFC 6266 `filename*` form. */
30
+ function filenameFrom(contentDisposition) {
31
+ if (contentDisposition === null)
32
+ return null;
33
+ const extended = /filename\*\s*=\s*([^']*)'[^']*'([^;]+)/i.exec(contentDisposition);
34
+ if (extended?.[2] !== undefined) {
35
+ try {
36
+ return decodeURIComponent(extended[2].trim());
37
+ }
38
+ catch {
39
+ // A malformed percent-encoding: the plain form below may still hold a usable name.
40
+ }
41
+ }
42
+ const plain = /filename\s*=\s*(?:"((?:\\.|[^"\\])*)"|([^;]+))/i.exec(contentDisposition);
43
+ const name = plain?.[1]?.replace(/\\(.)/g, "$1") ?? plain?.[2]?.trim();
44
+ return name === undefined || name === "" ? null : name;
45
+ }
@@ -0,0 +1,16 @@
1
+ export { WebsiteScreenshotWorld, type ClientOptions } from "./client.js";
2
+ export type { InstantSnap, WaitOptions } from "./instant-snap.js";
3
+ export type { AutoSchedule } from "./auto-schedule.js";
4
+ export type { CaptureRequestOptions, RequestOptions } from "./transport.js";
5
+ export type { FileDestination } from "./files.js";
6
+ export type { CaptureFileOptions, CaptureOptions, CaptureToBucketOptions, GeolocationOptions, PageSourceOptions, ProxyOptions, S3DeliveryOptions, SelectorOptions, TimestampWatermarkOptions, ViewportOptions, } from "./models/capture-options.js";
7
+ export type { Capture, CaptureFields, PageSource, S3Delivery, } from "./models/capture.js";
8
+ export type { CaptureFile } from "./models/capture-file.js";
9
+ export type { Catalog, DefaultViewport, Defaults } from "./models/defaults.js";
10
+ export type { TriggerResult } from "./models/trigger-result.js";
11
+ export { CaptureFormat, CaptureStatus, DeviceCategory, MediaCategory, PageSourceFormat, Product, ResponseType, S3DeliveryStatus, ScrollMode, TriggeredBy, TriggerStatus, WatermarkLocation, } from "./models/tokens.js";
12
+ export { ErrorCode } from "./error-codes.js";
13
+ export { AuthenticationError, CaptureError, ConnectionError, InvalidRequestError, NotFoundError, PlanLimitError, RateLimitError, ServiceError, SignatureVerificationError, WebsiteScreenshotWorldError, type ErrorDetails, } from "./errors.js";
14
+ export { Webhook, type VerifyOptions } from "./webhooks/webhook.js";
15
+ export { WebhookEventType, type AutoScheduleCaptureEvent, type CaptureChangedData, type CaptureChangedEvent, type DeliveryCompletedData, type DeliveryCompletedEvent, type Destination, type InstantSnapCaptureData, type InstantSnapCaptureEvent, type PingData, type PingEvent, type ScheduledCapture, type SchedulePausedData, type SchedulePausedEvent, type SitemapRunCompletedData, type SitemapRunCompletedEvent, type UnknownWebhookEvent, type WebhookEvent, } from "./webhooks/events.js";
16
+ export { VERSION } from "./version.js";
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = exports.WebhookEventType = exports.Webhook = exports.WebsiteScreenshotWorldError = exports.SignatureVerificationError = exports.ServiceError = exports.RateLimitError = exports.PlanLimitError = exports.NotFoundError = exports.InvalidRequestError = exports.ConnectionError = exports.CaptureError = exports.AuthenticationError = exports.ErrorCode = exports.WatermarkLocation = exports.TriggerStatus = exports.TriggeredBy = exports.ScrollMode = exports.S3DeliveryStatus = exports.ResponseType = exports.Product = exports.PageSourceFormat = exports.MediaCategory = exports.DeviceCategory = exports.CaptureStatus = exports.CaptureFormat = exports.WebsiteScreenshotWorld = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "WebsiteScreenshotWorld", { enumerable: true, get: function () { return client_js_1.WebsiteScreenshotWorld; } });
6
+ var tokens_js_1 = require("./models/tokens.js");
7
+ Object.defineProperty(exports, "CaptureFormat", { enumerable: true, get: function () { return tokens_js_1.CaptureFormat; } });
8
+ Object.defineProperty(exports, "CaptureStatus", { enumerable: true, get: function () { return tokens_js_1.CaptureStatus; } });
9
+ Object.defineProperty(exports, "DeviceCategory", { enumerable: true, get: function () { return tokens_js_1.DeviceCategory; } });
10
+ Object.defineProperty(exports, "MediaCategory", { enumerable: true, get: function () { return tokens_js_1.MediaCategory; } });
11
+ Object.defineProperty(exports, "PageSourceFormat", { enumerable: true, get: function () { return tokens_js_1.PageSourceFormat; } });
12
+ Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return tokens_js_1.Product; } });
13
+ Object.defineProperty(exports, "ResponseType", { enumerable: true, get: function () { return tokens_js_1.ResponseType; } });
14
+ Object.defineProperty(exports, "S3DeliveryStatus", { enumerable: true, get: function () { return tokens_js_1.S3DeliveryStatus; } });
15
+ Object.defineProperty(exports, "ScrollMode", { enumerable: true, get: function () { return tokens_js_1.ScrollMode; } });
16
+ Object.defineProperty(exports, "TriggeredBy", { enumerable: true, get: function () { return tokens_js_1.TriggeredBy; } });
17
+ Object.defineProperty(exports, "TriggerStatus", { enumerable: true, get: function () { return tokens_js_1.TriggerStatus; } });
18
+ Object.defineProperty(exports, "WatermarkLocation", { enumerable: true, get: function () { return tokens_js_1.WatermarkLocation; } });
19
+ var error_codes_js_1 = require("./error-codes.js");
20
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_codes_js_1.ErrorCode; } });
21
+ var errors_js_1 = require("./errors.js");
22
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
23
+ Object.defineProperty(exports, "CaptureError", { enumerable: true, get: function () { return errors_js_1.CaptureError; } });
24
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
25
+ Object.defineProperty(exports, "InvalidRequestError", { enumerable: true, get: function () { return errors_js_1.InvalidRequestError; } });
26
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
27
+ Object.defineProperty(exports, "PlanLimitError", { enumerable: true, get: function () { return errors_js_1.PlanLimitError; } });
28
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
29
+ Object.defineProperty(exports, "ServiceError", { enumerable: true, get: function () { return errors_js_1.ServiceError; } });
30
+ Object.defineProperty(exports, "SignatureVerificationError", { enumerable: true, get: function () { return errors_js_1.SignatureVerificationError; } });
31
+ Object.defineProperty(exports, "WebsiteScreenshotWorldError", { enumerable: true, get: function () { return errors_js_1.WebsiteScreenshotWorldError; } });
32
+ var webhook_js_1 = require("./webhooks/webhook.js");
33
+ Object.defineProperty(exports, "Webhook", { enumerable: true, get: function () { return webhook_js_1.Webhook; } });
34
+ var events_js_1 = require("./webhooks/events.js");
35
+ Object.defineProperty(exports, "WebhookEventType", { enumerable: true, get: function () { return events_js_1.WebhookEventType; } });
36
+ var version_js_1 = require("./version.js");
37
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
@@ -0,0 +1,99 @@
1
+ import { type FileDestination } from "./files.js";
2
+ import { type CaptureFile } from "./models/capture-file.js";
3
+ import type { CaptureFileOptions, CaptureOptions, CaptureToBucketOptions } from "./models/capture-options.js";
4
+ import { type Capture } from "./models/capture.js";
5
+ import { type Catalog, type Defaults } from "./models/defaults.js";
6
+ import type { CaptureRequestOptions, RequestOptions, Transport } from "./transport.js";
7
+ /** Options for {@link InstantSnap.wait}. */
8
+ export interface WaitOptions {
9
+ /**
10
+ * Seconds to keep reading the capture. When they run out, `wait` returns the capture as last
11
+ * read, still unfinished, rather than throwing. Default 360.
12
+ */
13
+ timeoutSeconds?: number;
14
+ /** Seconds between reads. Default 3; `0` reads again at once. */
15
+ pollIntervalSeconds?: number;
16
+ /**
17
+ * Stops waiting, and the read in progress, as soon as it aborts; `wait` then rejects with the
18
+ * signal's reason.
19
+ */
20
+ signal?: AbortSignal;
21
+ }
22
+ /** What {@link InstantSnap} needs from the client. */
23
+ export interface InstantSnapConfig {
24
+ transport: Transport;
25
+ apiKey: string | undefined;
26
+ baseUrl: string;
27
+ timeout: number;
28
+ captureTimeout: number;
29
+ }
30
+ /** On-demand captures: an image, a video or a PDF of a web page. */
31
+ export declare class InstantSnap {
32
+ #private;
33
+ /**
34
+ * Captures a page and returns the capture, with a `downloadUrl` valid for 60 minutes.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const capture = await client.instantSnap.capture({ url: "https://example.com", format: "webp" });
39
+ * ```
40
+ */
41
+ capture(options: CaptureOptions, requestOptions?: CaptureRequestOptions): Promise<Capture>;
42
+ /**
43
+ * Captures a page and returns the file itself as a stream, with its metadata. The API does not
44
+ * keep the file, so read or save it before discarding the result.
45
+ */
46
+ captureFile(options: CaptureFileOptions, requestOptions?: CaptureRequestOptions): Promise<CaptureFile>;
47
+ /** Captures a page and uploads the file to your S3-compatible bucket. */
48
+ captureToBucket(options: CaptureToBucketOptions, requestOptions?: CaptureRequestOptions): Promise<Capture>;
49
+ /**
50
+ * Queues a capture and returns at once with it, `status` `queued`; it runs when a browser is
51
+ * free. Read it with {@link InstantSnap.wait} or {@link InstantSnap.get}, or receive it at
52
+ * `callbackUrl`.
53
+ *
54
+ * `options.timeout` sets the browser time it may take, 30 to 300 seconds. The call itself uses
55
+ * the client's `timeout`, not `captureTimeout`, since nothing is captured while it waits. A
56
+ * capture still queued 15 minutes later ends `failed` with `capture_expired`, not charged.
57
+ *
58
+ * @throws `RateLimitError` with `errorCode` `queue_full` when too many async captures are
59
+ * already waiting or running. It is not retried; `retryAfterSeconds` says when to try again.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const queued = await client.instantSnap.submit({ url: "https://example.com", timeout: 240 });
64
+ * const capture = await client.instantSnap.wait(queued.id);
65
+ * ```
66
+ */
67
+ submit(options: CaptureOptions, requestOptions?: CaptureRequestOptions): Promise<Capture>;
68
+ /**
69
+ * Queues a capture that uploads the file to your S3-compatible bucket, and returns at once with
70
+ * it, `status` `queued`. Otherwise as {@link InstantSnap.submit}.
71
+ */
72
+ submitToBucket(options: CaptureToBucketOptions, requestOptions?: CaptureRequestOptions): Promise<Capture>;
73
+ /**
74
+ * Reads a capture with `get` every `pollIntervalSeconds` until its status is no longer `queued`,
75
+ * `running` or `pending`, and returns it. When `timeoutSeconds` runs out first, returns the
76
+ * capture as last read, still unfinished, so you can decide whether to wait again. An error from
77
+ * `get` is thrown as it is.
78
+ *
79
+ * @param capture - A capture's id, or the capture itself, such as the one `submit` returned.
80
+ */
81
+ wait(capture: string | {
82
+ id: string;
83
+ }, options?: WaitOptions): Promise<Capture>;
84
+ /** Reads a capture back, with a fresh `downloadUrl`. */
85
+ get(id: string, requestOptions?: RequestOptions): Promise<Capture>;
86
+ /**
87
+ * Downloads a capture's file, or its page source, to a path or a stream.
88
+ *
89
+ * @param source - A capture from `capture` or `get`, or its `pageSource`.
90
+ * @param destination - A file path, a Node.js writable stream or a web `WritableStream`.
91
+ */
92
+ download(source: {
93
+ downloadUrl: string | null;
94
+ }, destination: FileDestination, requestOptions?: RequestOptions): Promise<void>;
95
+ /** The values a capture takes for fields it does not set, and the limits. Needs no API key. */
96
+ defaults(requestOptions?: RequestOptions): Promise<Defaults>;
97
+ /** The devices `emulatedDevice` accepts and the countries `proxy.country` accepts. */
98
+ catalog(requestOptions?: RequestOptions): Promise<Catalog>;
99
+ }