scrapfly-sdk 0.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/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ BSD 2-Clause License
2
+ --------------------
3
+
4
+ Copyright (c) 2013-2016, Scrapfly <https://scrapfly.io> and
5
+ individual contributors. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Scrapfly SDK
2
+
3
+ `npm install scrapfly-sdk`
4
+
5
+ ## Quick Intro
6
+
7
+ Get your API Key on [scrapfly.io/dashboard](https://scrapfly.io/dashboard) and start scraping:
8
+
9
+ ```javascript
10
+ import { ScrapflyClient, ScrapeConfig } from 'scrapfly-sdk';
11
+
12
+ const key = 'YOUR SCRAPFLY KEY';
13
+ const client = new ScrapflyClient({ key });
14
+ const apiResponse = await client.scrape(
15
+ new ScrapeConfig({
16
+ url: 'https://web-scraping.dev/product/1',
17
+ // optional parameters:
18
+ // enable javascript rendering
19
+ render_js: true,
20
+ // set proxy country
21
+ country: 'us',
22
+ // enable anti-scraping protection bypass
23
+ asp: true,
24
+ // set residential proxies
25
+ proxy_pool: 'public_residential_pool',
26
+ // etc.
27
+ }),
28
+ );
29
+ console.log(apiResponse.result.content); // html content
30
+ ```
31
+
32
+ For more see [/examples](/examples/) directory.
33
+ For more on Scrapfly API see full documentation: <https://scrapfly.io/docs>
34
+ For Python see [Scrapfly Python SDK](https://github.com/scrapfly/python-scrapfly)
35
+
36
+ ## Development
37
+
38
+ Install and setup environment:
39
+
40
+ ```shell
41
+ $ npm install
42
+ ```
43
+
44
+ Build and test:
45
+
46
+ ```shell
47
+ $ npm task build
48
+ $ npm task tests
49
+ ```
@@ -0,0 +1,47 @@
1
+ import { ScrapeConfig } from './scrapeconfig.js';
2
+ import * as errors from './errors.js';
3
+ import { ScrapeResult, AccountData } from './result.js';
4
+ import { Logger, ILogObj } from 'tslog';
5
+ import { AxiosResponse } from 'axios';
6
+ export declare const log: Logger<ILogObj>;
7
+ export declare class ScrapflyClient {
8
+ HOST: string;
9
+ private key;
10
+ private ua;
11
+ constructor(options: {
12
+ key: string;
13
+ });
14
+ /**
15
+ * Raise appropriate error for given response and scrape result
16
+ */
17
+ errResult(response: AxiosResponse, result: ScrapeResult): errors.ScrapflyError;
18
+ /**
19
+ * Turn scrapfly API response to ScrapeResult or raise one of ScrapflyError
20
+ */
21
+ handleResponse(response: AxiosResponse): Promise<ScrapeResult>;
22
+ /**
23
+ * Retrieve Scrapfly account details
24
+ */
25
+ account(): Promise<AccountData>;
26
+ /**
27
+ * Issue a single scrape command from a given scrape configuration
28
+ */
29
+ scrape(config: ScrapeConfig): Promise<ScrapeResult>;
30
+ /**
31
+ Concurrently scrape multiple configs
32
+ This is a async generator call it like this:
33
+
34
+ const results = [];
35
+ const errors = [];
36
+ for await (const resultOrError of client.concurrentScrape(configs)) {
37
+ if (resultOrError instanceof Error) {
38
+ errors.push(resultOrError);
39
+ } else {
40
+ results.push(resultOrError);
41
+ }
42
+ }
43
+
44
+ @param concurrencyLimit: if not set it will be taken from your account info
45
+ */
46
+ concurrentScrape(configs: ScrapeConfig[], concurrencyLimit?: number): AsyncGenerator<ScrapeResult | Error | undefined, void, undefined>;
47
+ }
@@ -0,0 +1,191 @@
1
+ import * as errors from './errors.js';
2
+ import { ScrapeResult } from './result.js';
3
+ import { Logger } from 'tslog';
4
+ import axios from 'axios';
5
+ export const log = new Logger();
6
+ export class ScrapflyClient {
7
+ HOST = 'https://api.scrapfly.io';
8
+ key;
9
+ ua;
10
+ constructor(options) {
11
+ if (typeof options.key !== 'string' || options.key.trim() === '') {
12
+ throw new errors.BadApiKeyError('Invalid key. Key must be a non-empty string');
13
+ }
14
+ this.key = options.key;
15
+ this.ua = 'Typescript Scrapfly SDK';
16
+ }
17
+ /**
18
+ * Raise appropriate error for given response and scrape result
19
+ */
20
+ errResult(response, result) {
21
+ const error = result.result.error;
22
+ const message = error.message ?? '';
23
+ const args = {
24
+ code: result.result.status,
25
+ http_status_code: result.result.status_code,
26
+ is_retryable: error.retryable ?? false,
27
+ api_response: result,
28
+ resource: result.result.status ? result.result.status.split('::')[1] : null,
29
+ retry_delay: error.retryable ? 5 : (response.headers ?? {})['X-Retry'] ?? 5,
30
+ retry_times: 3,
31
+ documentation_url: error.doc_url ?? 'https://scrapfly.io/docs/scrape-api/errors#api',
32
+ };
33
+ const resourceErrMap = {
34
+ SCRAPE: errors.ScrapflyScrapeError,
35
+ WEBHOOK: errors.ScrapflyWebhookError,
36
+ PROXY: errors.ScrapflyProxyError,
37
+ SCHEDULE: errors.ScrapflyScheduleError,
38
+ ASP: errors.ScrapflyAspError,
39
+ SESSION: errors.ScrapflySessionError,
40
+ };
41
+ const httpStatusErrMap = {
42
+ 401: errors.BadApiKeyError,
43
+ 429: errors.TooManyRequests,
44
+ };
45
+ if (result.result.success === true) {
46
+ if (args.http_status_code >= 500) {
47
+ return new errors.ApiHttpServerError(message, args);
48
+ }
49
+ if (httpStatusErrMap[args.http_status_code]) {
50
+ return new httpStatusErrMap[args.http_status_code](message, args);
51
+ }
52
+ if (resourceErrMap[args.resource]) {
53
+ return new resourceErrMap[args.resource](message, args);
54
+ }
55
+ return new errors.ApiHttpClientError(message, args);
56
+ }
57
+ else {
58
+ if (args.code === 'ERR::SCRAPE::BAD_UPSTREAM_RESPONSE') {
59
+ if (args.http_status_code >= 500) {
60
+ return new errors.UpstreamHttpServerError(message, args);
61
+ }
62
+ if (args.http_status_code >= 400) {
63
+ return new errors.UpstreamHttpClientError(message, args);
64
+ }
65
+ }
66
+ if (resourceErrMap[args.resource]) {
67
+ return new resourceErrMap[args.resource](message, args);
68
+ }
69
+ throw new errors.ScrapflyError(message, args);
70
+ }
71
+ }
72
+ /**
73
+ * Turn scrapfly API response to ScrapeResult or raise one of ScrapflyError
74
+ */
75
+ async handleResponse(response) {
76
+ const data = response.data;
77
+ const result = new ScrapeResult(data);
78
+ log.debug('scrape log url: ', result.result.log_url);
79
+ // success
80
+ if (result.result.status === 'DONE' && result.result.success === true) {
81
+ return result;
82
+ }
83
+ // something went wrong
84
+ throw this.errResult(response, result);
85
+ }
86
+ /**
87
+ * Retrieve Scrapfly account details
88
+ */
89
+ async account() {
90
+ log.debug('retrieving account info');
91
+ try {
92
+ const response = await axios.request({
93
+ method: 'GET',
94
+ url: this.HOST + '/account',
95
+ headers: {
96
+ 'user-agent': this.ua,
97
+ 'accept-ecoding': 'gzip, deflate, br',
98
+ accept: 'application/json',
99
+ },
100
+ params: { key: this.key },
101
+ });
102
+ return response.data;
103
+ }
104
+ catch (e) {
105
+ log.error('error', e);
106
+ if (e.response && e.response.status === 401) {
107
+ throw new errors.BadApiKeyError(JSON.stringify(e.response.data));
108
+ }
109
+ throw new errors.HttpError(`failed to get account details; status code ${e.response.status}`, e);
110
+ }
111
+ }
112
+ /**
113
+ * Issue a single scrape command from a given scrape configuration
114
+ */
115
+ async scrape(config) {
116
+ log.debug('scraping', { method: config.method, url: config.url });
117
+ let response;
118
+ try {
119
+ response = await axios.request({
120
+ method: config.method,
121
+ url: this.HOST + '/scrape',
122
+ headers: {
123
+ 'user-agent': this.ua,
124
+ 'content-type': config.method === 'POST' ? config.headers['content-type'] : 'application/json',
125
+ 'accept-ecoding': 'gzip, deflate, br',
126
+ accept: 'application/json',
127
+ },
128
+ params: config.toApiParams({ key: this.key }),
129
+ data: config.body,
130
+ });
131
+ }
132
+ catch (e) {
133
+ log.error('error', e);
134
+ if (e.response && e.response.status === 401) {
135
+ throw new errors.BadApiKeyError(JSON.stringify(e.response.data));
136
+ }
137
+ throw e;
138
+ }
139
+ const result = await this.handleResponse(response);
140
+ return result;
141
+ }
142
+ /**
143
+ Concurrently scrape multiple configs
144
+ This is a async generator call it like this:
145
+
146
+ const results = [];
147
+ const errors = [];
148
+ for await (const resultOrError of client.concurrentScrape(configs)) {
149
+ if (resultOrError instanceof Error) {
150
+ errors.push(resultOrError);
151
+ } else {
152
+ results.push(resultOrError);
153
+ }
154
+ }
155
+
156
+ @param concurrencyLimit: if not set it will be taken from your account info
157
+ */
158
+ async *concurrentScrape(configs, concurrencyLimit) {
159
+ if (concurrencyLimit === undefined) {
160
+ const account = await this.account();
161
+ concurrencyLimit = account.subscription.usage.scrape.concurrent_limit;
162
+ log.info(`concurrency not provided - setting it to ${concurrencyLimit} from account info`);
163
+ }
164
+ const activePromises = new Set();
165
+ const configsIterator = configs[Symbol.iterator]();
166
+ // Helper function to start a new scrape and add it to activePromises
167
+ const startNewScrape = () => {
168
+ const { value: config, done } = configsIterator.next();
169
+ if (done)
170
+ return; // No more configs
171
+ const promise = this.scrape(config).catch((error) => error); // Catch errors and return them
172
+ activePromises.add(promise);
173
+ promise.finally(() => {
174
+ activePromises.delete(promise);
175
+ // After each scrape, start a new one if there are remaining configs
176
+ startNewScrape();
177
+ });
178
+ };
179
+ // Initially start as many scrapes as the concurrency limit
180
+ for (let i = 0; i < concurrencyLimit; i++) {
181
+ startNewScrape();
182
+ }
183
+ // As each scrape finishes, yield the result or error and start a new one if there are remaining configs
184
+ while (activePromises.size > 0) {
185
+ log.debug(`concurrently scraping ${activePromises.size}/${configs.length}}`);
186
+ const resultOrError = await Promise.race(activePromises);
187
+ yield resultOrError;
188
+ }
189
+ }
190
+ }
191
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAuC,YAAY,EAAe,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAW,MAAM,OAAO,CAAC;AACxC,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,GAAG,GAAoB,IAAI,MAAM,EAAE,CAAC;AAEjD,MAAM,OAAO,cAAc;IAChB,IAAI,GAAG,yBAAyB,CAAC;IAChC,GAAG,CAAS;IACZ,EAAE,CAAS;IAEnB,YAAY,OAAwB;QAChC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC9D,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,6CAA6C,CAAC,CAAC;SAClF;QACD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,yBAAyB,CAAC;IACxC,CAAC;IACD;;OAEG;IACH,SAAS,CAAC,QAAuB,EAAE,MAAoB;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AAM,aAAa,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACzD,MAAM,aAAa,CAAC;SACvB;IACL,CAAC;CACJ"}
@@ -0,0 +1,42 @@
1
+ export declare class ScrapflyError extends Error {
2
+ args: Record<string, any>;
3
+ constructor(message: string, args?: Record<string, any>);
4
+ }
5
+ export declare class ScrapeConfigError extends ScrapflyError {
6
+ }
7
+ export declare class EncodeError extends ScrapflyError {
8
+ }
9
+ export declare class HttpError extends ScrapflyError {
10
+ }
11
+ export declare class UpstreamHttpError extends HttpError {
12
+ }
13
+ export declare class UpstreamHttpClientError extends UpstreamHttpError {
14
+ }
15
+ export declare class UpstreamHttpServerError extends UpstreamHttpClientError {
16
+ }
17
+ export declare class ApiHttpClientError extends HttpError {
18
+ }
19
+ export declare class BadApiKeyError extends ApiHttpClientError {
20
+ }
21
+ export declare class TooManyRequests extends HttpError {
22
+ }
23
+ export declare class ApiHttpServerError extends HttpError {
24
+ }
25
+ export declare class ScrapflyScrapeError extends HttpError {
26
+ }
27
+ export declare class ScrapflyProxyError extends HttpError {
28
+ }
29
+ export declare class ScrapflyThrottleError extends HttpError {
30
+ }
31
+ export declare class ScrapflyAspError extends HttpError {
32
+ }
33
+ export declare class ScrapflyScheduleError extends HttpError {
34
+ }
35
+ export declare class ScrapflyWebhookError extends HttpError {
36
+ }
37
+ export declare class ScrapflySessionError extends HttpError {
38
+ }
39
+ export declare class TooManyConcurrentRequests extends HttpError {
40
+ }
41
+ export declare class QuotaLimitReached extends HttpError {
42
+ }
@@ -0,0 +1,56 @@
1
+ export class ScrapflyError extends Error {
2
+ args;
3
+ constructor(message, args) {
4
+ super(message);
5
+ this.args = args;
6
+ }
7
+ }
8
+ // raised when scrape config is invalid
9
+ export class ScrapeConfigError extends ScrapflyError {
10
+ }
11
+ // raised when scrape parameters cannot be encoded
12
+ export class EncodeError extends ScrapflyError {
13
+ }
14
+ // Base error for all http related operations
15
+ export class HttpError extends ScrapflyError {
16
+ }
17
+ export class UpstreamHttpError extends HttpError {
18
+ }
19
+ export class UpstreamHttpClientError extends UpstreamHttpError {
20
+ }
21
+ export class UpstreamHttpServerError extends UpstreamHttpClientError {
22
+ }
23
+ export class ApiHttpClientError extends HttpError {
24
+ }
25
+ // raised when API key provided to client is not valid or not existant
26
+ export class BadApiKeyError extends ApiHttpClientError {
27
+ }
28
+ export class TooManyRequests extends HttpError {
29
+ }
30
+ export class ApiHttpServerError extends HttpError {
31
+ }
32
+ export class ScrapflyScrapeError extends HttpError {
33
+ }
34
+ // raised when proxy settings don't match available proxies (e.g. invalid proxy pool, country setting)
35
+ export class ScrapflyProxyError extends HttpError {
36
+ }
37
+ export class ScrapflyThrottleError extends HttpError {
38
+ }
39
+ // raised when ScrapFly fails to bypass anti-scraping protection
40
+ export class ScrapflyAspError extends HttpError {
41
+ }
42
+ export class ScrapflyScheduleError extends HttpError {
43
+ }
44
+ // raised when Webhook is invalid or cannot be fulfilled (i.e. full queue)
45
+ export class ScrapflyWebhookError extends HttpError {
46
+ }
47
+ // raised when session is access concurrently
48
+ export class ScrapflySessionError extends HttpError {
49
+ }
50
+ // raised when concurrent requests exceed account limits
51
+ export class TooManyConcurrentRequests extends HttpError {
52
+ }
53
+ // raised when account is out of scrape credits
54
+ export class QuotaLimitReached extends HttpError {
55
+ }
56
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpC,IAAI,CAAsB;IAE1B,YAAY,OAAe,EAAE,IAA0B;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAED,uCAAuC;AACvC,MAAM,OAAO,iBAAkB,SAAQ,aAAa;CAAG;AAEvD,kDAAkD;AAClD,MAAM,OAAO,WAAY,SAAQ,aAAa;CAAG;AAEjD,6CAA6C;AAC7C,MAAM,OAAO,SAAU,SAAQ,aAAa;CAAG;AAC/C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;CAAG;AACnD,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;CAAG;AACjE,MAAM,OAAO,uBAAwB,SAAQ,uBAAuB;CAAG;AAEvE,MAAM,OAAO,kBAAmB,SAAQ,SAAS;CAAG;AACpD,sEAAsE;AACtE,MAAM,OAAO,cAAe,SAAQ,kBAAkB;CAAG;AAEzD,MAAM,OAAO,eAAgB,SAAQ,SAAS;CAAG;AACjD,MAAM,OAAO,kBAAmB,SAAQ,SAAS;CAAG;AACpD,MAAM,OAAO,mBAAoB,SAAQ,SAAS;CAAG;AACrD,sGAAsG;AACtG,MAAM,OAAO,kBAAmB,SAAQ,SAAS;CAAG;AACpD,MAAM,OAAO,qBAAsB,SAAQ,SAAS;CAAG;AACvD,gEAAgE;AAChE,MAAM,OAAO,gBAAiB,SAAQ,SAAS;CAAG;AAClD,MAAM,OAAO,qBAAsB,SAAQ,SAAS;CAAG;AACvD,0EAA0E;AAC1E,MAAM,OAAO,oBAAqB,SAAQ,SAAS;CAAG;AACtD,6CAA6C;AAC7C,MAAM,OAAO,oBAAqB,SAAQ,SAAS;CAAG;AACtD,wDAAwD;AACxD,MAAM,OAAO,yBAA0B,SAAQ,SAAS;CAAG;AAC3D,+CAA+C;AAC/C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;CAAG"}
@@ -0,0 +1,2 @@
1
+ export { ScrapflyClient } from './client.js';
2
+ export { ScrapeConfig } from './scrapeconfig.js';
@@ -0,0 +1,3 @@
1
+ export { ScrapflyClient } from './client.js';
2
+ export { ScrapeConfig } from './scrapeconfig.js';
3
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,268 @@
1
+ import { Rec, HttpMethod } from './types.js';
2
+ export type ConfigData = {
3
+ url: string;
4
+ retry: boolean;
5
+ method: HttpMethod;
6
+ country?: string;
7
+ render_js: boolean;
8
+ cache: boolean;
9
+ cache_clear: boolean;
10
+ ssl: boolean;
11
+ dns: boolean;
12
+ asp: boolean;
13
+ debug: boolean;
14
+ raise_on_upstream_error: boolean;
15
+ cache_ttl: number;
16
+ proxy_pool: string;
17
+ session?: string;
18
+ tags: Set<string>;
19
+ correlation_id?: string;
20
+ cookies: Record<string, string>;
21
+ body?: string;
22
+ data?: Rec<any>;
23
+ headers: Rec<string>;
24
+ js?: string;
25
+ rendering_wait?: number;
26
+ wait_for_selector?: string;
27
+ session_sticky_proxy: boolean;
28
+ screenshots?: Rec<any>;
29
+ webhook?: string;
30
+ timeout?: number;
31
+ js_scenario?: Rec<any>;
32
+ extract?: Rec<any>;
33
+ lang?: string[];
34
+ os?: string;
35
+ auto_scroll?: boolean;
36
+ };
37
+ export type ContextData = {
38
+ asp: boolean;
39
+ bandwidth_consumed: number;
40
+ cache: {
41
+ state: string;
42
+ entry?: string;
43
+ };
44
+ cookies: Record<string, string>;
45
+ cost: {
46
+ details: Array<{
47
+ amount: number;
48
+ code: string;
49
+ description: string;
50
+ }>;
51
+ total: number;
52
+ };
53
+ created_at: string;
54
+ debug: {
55
+ response_url: string;
56
+ screenshot_url?: string;
57
+ };
58
+ env: string;
59
+ fingerprint: string;
60
+ headers: Record<string, string>;
61
+ is_xml_http_request: boolean;
62
+ job?: string;
63
+ lang: Array<string>;
64
+ os: {
65
+ distribution: string;
66
+ name: string;
67
+ type: string;
68
+ version: string;
69
+ };
70
+ project: string;
71
+ proxy: {
72
+ country: string;
73
+ identity: string;
74
+ network: string;
75
+ pool: string;
76
+ };
77
+ redirects: Array<string>;
78
+ retry: number;
79
+ schedule?: string;
80
+ session?: string;
81
+ spider?: any;
82
+ throttler?: any;
83
+ uri: {
84
+ base_url: string;
85
+ fragment?: string;
86
+ host: string;
87
+ params?: Rec<string>;
88
+ port: number;
89
+ query?: string;
90
+ root_domain: string;
91
+ scheme: string;
92
+ };
93
+ url: string;
94
+ webhook?: string;
95
+ };
96
+ export type ResultData = {
97
+ browser_data: {
98
+ javascript_evaluation_result: string;
99
+ js_scenario: {
100
+ duration: number;
101
+ executed: number;
102
+ response: any;
103
+ steps: Array<{
104
+ action: string;
105
+ config: Rec<string>;
106
+ duration: number;
107
+ executed: boolean;
108
+ result?: string;
109
+ success: boolean;
110
+ }>;
111
+ };
112
+ local_storage_data: Rec<string>;
113
+ session_storage_data: Rec<string>;
114
+ websockets: Array<any>;
115
+ xhr_call: Array<{
116
+ body?: string;
117
+ headers: Rec<string>;
118
+ method: string;
119
+ type: string;
120
+ url: string;
121
+ response: {
122
+ body: string;
123
+ duration: number;
124
+ format: string;
125
+ headers: Rec<string>;
126
+ status: number;
127
+ };
128
+ }>;
129
+ };
130
+ content: string;
131
+ content_encoding: string;
132
+ content_type: string;
133
+ cookies: Array<{
134
+ name: string;
135
+ value: string;
136
+ expires: string;
137
+ path: string;
138
+ comment: string;
139
+ domain: string;
140
+ max_age: number;
141
+ secure: boolean;
142
+ http_only: boolean;
143
+ version: string;
144
+ size: number;
145
+ }>;
146
+ data?: Rec<any>;
147
+ dns?: Rec<Array<Rec<any>>>;
148
+ duration: number;
149
+ error?: {
150
+ code: string;
151
+ http_code: number;
152
+ links: Rec<string>;
153
+ message: string;
154
+ retryable: boolean;
155
+ doc_url?: string;
156
+ };
157
+ format: string;
158
+ iframes: Array<{
159
+ url: string;
160
+ uri: {
161
+ root_domain: string;
162
+ base_url: string;
163
+ host: string;
164
+ scheme: string;
165
+ query?: string;
166
+ fragment?: string;
167
+ port: number;
168
+ params?: Rec<string>;
169
+ };
170
+ content: string;
171
+ }>;
172
+ log_url: string;
173
+ reason: string;
174
+ request_headers: Rec<string>;
175
+ response_headers: Rec<string>;
176
+ screenshots: Rec<{
177
+ css_selector?: string;
178
+ extension: string;
179
+ format: string;
180
+ size: number;
181
+ url: string;
182
+ }>;
183
+ size: number;
184
+ ssl?: {
185
+ certs: Array<Rec<any>>;
186
+ };
187
+ status: string;
188
+ status_code: number;
189
+ success: boolean;
190
+ url: string;
191
+ };
192
+ export declare class ScrapeResult {
193
+ config: ConfigData;
194
+ context: ContextData;
195
+ result: ResultData;
196
+ uuid: string;
197
+ constructor(data: {
198
+ config: ConfigData;
199
+ context: ContextData;
200
+ result: ResultData;
201
+ uuid: string;
202
+ });
203
+ }
204
+ export declare class AccountData {
205
+ acount: {
206
+ account_id: string;
207
+ currency: string;
208
+ timezone: string;
209
+ };
210
+ project: {
211
+ allow_extra_usage: boolean;
212
+ allowed_networks: Array<string>;
213
+ budget_limit: any;
214
+ budget_spent: any;
215
+ concurrency_limit?: number;
216
+ name: string;
217
+ quota_reached: boolean;
218
+ scrape_request_count: number;
219
+ scrape_request_limit: number;
220
+ tags: Array<string>;
221
+ };
222
+ subscription: {
223
+ billing: {
224
+ current_extra_scrape_request_price: {
225
+ currency: string;
226
+ amount: number;
227
+ };
228
+ extra_scrape_request_price_per_10k: {
229
+ currency: string;
230
+ amount: number;
231
+ };
232
+ ongoing_payment: {
233
+ currency: string;
234
+ amount: number;
235
+ };
236
+ plan_price: {
237
+ currency: string;
238
+ amount: number;
239
+ };
240
+ };
241
+ extra_scrape_allowed: boolean;
242
+ max_concurrency: number;
243
+ period: {
244
+ start: string;
245
+ end: string;
246
+ };
247
+ plan_name: string;
248
+ usage: {
249
+ schedule: {
250
+ current: number;
251
+ limit: number;
252
+ };
253
+ spider: {
254
+ current: number;
255
+ limit: number;
256
+ };
257
+ scrape: {
258
+ concurrent_limit: number;
259
+ concurrent_remaining: number;
260
+ concurrent_usage: number;
261
+ current: number;
262
+ extra: number;
263
+ limit: number;
264
+ remaining: number;
265
+ };
266
+ };
267
+ };
268
+ }
@@ -0,0 +1,18 @@
1
+ export class ScrapeResult {
2
+ config;
3
+ context;
4
+ result;
5
+ uuid;
6
+ constructor(data) {
7
+ this.config = data.config;
8
+ this.context = data.context;
9
+ this.result = data.result;
10
+ this.uuid = data.uuid;
11
+ }
12
+ }
13
+ export class AccountData {
14
+ acount;
15
+ project;
16
+ subscription;
17
+ }
18
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/result.ts"],"names":[],"mappings":"AA+LA,MAAM,OAAO,YAAY;IACrB,MAAM,CAAa;IACnB,OAAO,CAAc;IACrB,MAAM,CAAa;IACnB,IAAI,CAAS;IAEb,YAAY,IAAoF;QAC5F,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;CACJ;AAED,MAAM,OAAO,WAAW;IACpB,MAAM,CAIJ;IACF,OAAO,CAWL;IACF,YAAY,CA2BV;CACL"}
@@ -0,0 +1,76 @@
1
+ import { Rec, HttpMethod } from './types.js';
2
+ export declare class ScrapeConfig {
3
+ static PUBLIC_DATACENTER_POOL: string;
4
+ static PUBLIC_RESIDENTIAL_POOL: string;
5
+ url: string;
6
+ retry: boolean;
7
+ method: HttpMethod;
8
+ country?: string;
9
+ render_js: boolean;
10
+ cache: boolean;
11
+ cache_clear: boolean;
12
+ ssl: boolean;
13
+ dns: boolean;
14
+ asp: boolean;
15
+ debug: boolean;
16
+ raise_on_upstream_error: boolean;
17
+ cache_ttl?: number;
18
+ proxy_pool?: string;
19
+ session?: string;
20
+ tags: Set<string>;
21
+ correlation_id?: string;
22
+ cookies?: Rec<string>;
23
+ body?: string;
24
+ data?: Rec<any>;
25
+ headers?: Rec<string>;
26
+ js?: string;
27
+ rendering_wait?: number;
28
+ wait_for_selector?: string;
29
+ session_sticky_proxy: boolean;
30
+ screenshots?: Rec<any>;
31
+ webhook?: string;
32
+ timeout?: number;
33
+ js_scenario?: Rec<any>;
34
+ extract?: Rec<any>;
35
+ lang?: string[];
36
+ os?: string;
37
+ auto_scroll?: boolean;
38
+ constructor(options: {
39
+ url: string;
40
+ retry?: boolean;
41
+ method?: HttpMethod;
42
+ country?: string;
43
+ render_js?: boolean;
44
+ cache?: boolean;
45
+ cache_clear?: boolean;
46
+ ssl?: boolean;
47
+ dns?: boolean;
48
+ asp?: boolean;
49
+ debug?: boolean;
50
+ raise_on_upstream_error?: boolean;
51
+ cache_ttl?: number;
52
+ proxy_pool?: string;
53
+ session?: string;
54
+ tags?: Array<string>;
55
+ correlation_id?: string;
56
+ cookies?: Rec<string>;
57
+ body?: string;
58
+ data?: Rec<any>;
59
+ headers?: Rec<string>;
60
+ js?: string;
61
+ rendering_wait?: number;
62
+ wait_for_selector?: string;
63
+ screenshots?: Rec<any>;
64
+ session_sticky_proxy?: boolean;
65
+ webhook?: string;
66
+ timeout?: number;
67
+ js_scenario?: Rec<any>;
68
+ extract?: Rec<any>;
69
+ os?: string;
70
+ lang?: string[];
71
+ auto_scroll?: boolean;
72
+ });
73
+ toApiParams(options: {
74
+ key: string;
75
+ }): Record<string, any>;
76
+ }
@@ -0,0 +1,241 @@
1
+ import { urlsafe_b64encode } from './utils.js';
2
+ import { log } from './client.js';
3
+ import { ScrapeConfigError } from './errors.js';
4
+ class ScrapeConfig {
5
+ static PUBLIC_DATACENTER_POOL = 'public_datacenter_pool';
6
+ static PUBLIC_RESIDENTIAL_POOL = 'public_residential_pool';
7
+ url;
8
+ retry = true;
9
+ method = 'GET';
10
+ country = null;
11
+ render_js = false;
12
+ cache = false;
13
+ cache_clear = false;
14
+ ssl = false;
15
+ dns = false;
16
+ asp = false;
17
+ debug = false;
18
+ raise_on_upstream_error = true;
19
+ cache_ttl = null;
20
+ proxy_pool = null;
21
+ session = null;
22
+ tags = new Set();
23
+ correlation_id = null;
24
+ cookies = null;
25
+ body = null;
26
+ data = null;
27
+ headers = null;
28
+ js = null;
29
+ rendering_wait = null;
30
+ wait_for_selector = null;
31
+ session_sticky_proxy = false;
32
+ screenshots = null;
33
+ webhook = null;
34
+ timeout = null; // in milliseconds
35
+ js_scenario = null;
36
+ extract = null;
37
+ lang = null;
38
+ os = null;
39
+ auto_scroll = null;
40
+ constructor(options) {
41
+ this.url = options.url;
42
+ this.retry = options.retry ?? this.retry;
43
+ this.method = options.method ?? this.method;
44
+ this.country = options.country ?? this.country;
45
+ this.session_sticky_proxy = options.session_sticky_proxy ?? this.session_sticky_proxy;
46
+ this.render_js = options.render_js ?? this.render_js;
47
+ this.cache = options.cache ?? this.cache;
48
+ this.cache_clear = options.cache_clear ?? this.cache_clear;
49
+ this.asp = options.asp ?? this.asp;
50
+ this.headers = options.headers
51
+ ? Object.fromEntries(Object.entries(options.headers).map(([k, v]) => [k.toLowerCase(), v]))
52
+ : {};
53
+ this.raise_on_upstream_error = options.raise_on_upstream_error ?? this.raise_on_upstream_error;
54
+ this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
55
+ this.proxy_pool = options.proxy_pool ?? this.proxy_pool;
56
+ this.session = options.session ?? this.session;
57
+ this.tags = new Set(options.tags) ?? this.tags;
58
+ this.correlation_id = options.correlation_id ?? this.correlation_id;
59
+ this.cookies = options.cookies
60
+ ? Object.fromEntries(Object.entries(options.cookies).map(([k, v]) => [k.toLowerCase(), v]))
61
+ : {};
62
+ this.body = options.body ?? this.body;
63
+ this.data = options.data ?? this.data;
64
+ this.js = options.js ?? this.js;
65
+ this.rendering_wait = options.rendering_wait ?? this.rendering_wait;
66
+ this.wait_for_selector = options.wait_for_selector ?? this.wait_for_selector;
67
+ this.screenshots = options.screenshots ?? this.screenshots;
68
+ this.webhook = options.webhook ?? this.webhook;
69
+ this.timeout = options.timeout ?? this.timeout;
70
+ this.js_scenario = options.js_scenario ?? this.js_scenario;
71
+ this.extract = options.extract ?? this.extract;
72
+ this.os = options.os ?? this.os;
73
+ this.lang = options.lang ?? this.lang;
74
+ this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
75
+ this.dns = options.dns ?? this.dns;
76
+ this.ssl = options.ssl ?? this.ssl;
77
+ this.debug = options.debug ?? this.debug;
78
+ if (this.body && this.data) {
79
+ throw new ScrapeConfigError('Cannot set both body and data');
80
+ }
81
+ if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
82
+ if (this.data && !this.body) {
83
+ if (!this.headers['content-type']) {
84
+ this.headers['content-type'] = 'application/x-www-form-urlencoded';
85
+ this.body = new URLSearchParams(this.data).toString();
86
+ }
87
+ else {
88
+ if (this.headers['content-type']?.includes('application/json')) {
89
+ this.body = JSON.stringify(this.data);
90
+ }
91
+ else if (this.headers['content-type']?.includes('application/x-www-form-urlencoded')) {
92
+ this.body = new URLSearchParams(this.data).toString();
93
+ }
94
+ else {
95
+ throw new ScrapeConfigError(`Content-Type "${this.headers['content-type']}" not supported, use body parameter to pass pre encoded body according to your content type`);
96
+ }
97
+ }
98
+ }
99
+ else if (this.body && !this.data) {
100
+ this.headers['content-type'] = 'text/plain';
101
+ }
102
+ }
103
+ }
104
+ toApiParams(options) {
105
+ const params = {
106
+ key: options.key,
107
+ };
108
+ params.url = this.url;
109
+ if (this.country) {
110
+ params.country = this.country;
111
+ }
112
+ if (Object.keys(this.headers).length > 0) {
113
+ Object.entries(this.headers).forEach(([key, value]) => {
114
+ params[`headers[${key}]`] = value;
115
+ });
116
+ }
117
+ if (Object.keys(this.cookies).length > 0) {
118
+ const cookiesAsHeader = [...Object.entries(this.cookies)]
119
+ .map(([key, value]) => `${key}=${value}`)
120
+ .join('; ');
121
+ if (params['headers[cookie]']) {
122
+ // if current cookie value doesn't have a ';' at the end, add it.
123
+ if (params['headers[cookie]'][params['headers[cookie]'].length - 1] !== ';') {
124
+ params['headers[cookie]'] += ';';
125
+ }
126
+ params['headers[cookie]'] += ` ${cookiesAsHeader}`;
127
+ }
128
+ else {
129
+ params['headers[cookie]'] = cookiesAsHeader;
130
+ }
131
+ }
132
+ if (this.webhook) {
133
+ params.webhook_name = this.webhook;
134
+ }
135
+ if (this.timeout) {
136
+ params.timeout = this.timeout;
137
+ }
138
+ if (this.render_js === true) {
139
+ params.render_js = true;
140
+ if (this.wait_for_selector !== null) {
141
+ params.wait_for_selector = this.wait_for_selector;
142
+ }
143
+ if (this.js !== null) {
144
+ params.js = urlsafe_b64encode(this.js);
145
+ }
146
+ if (this.js_scenario !== null) {
147
+ params.js_scenario = urlsafe_b64encode(JSON.stringify(this.js_scenario));
148
+ }
149
+ if (this.rendering_wait !== null) {
150
+ params.rendering_wait = this.rendering_wait;
151
+ }
152
+ if (this.screenshots) {
153
+ Object.keys(this.screenshots).forEach((key) => {
154
+ params[`screenshots[${key}]`] = this.screenshots[key];
155
+ });
156
+ }
157
+ if (this.auto_scroll !== null) {
158
+ params.auto_scroll = this.auto_scroll;
159
+ }
160
+ }
161
+ else {
162
+ if (this.wait_for_selector !== null) {
163
+ log.warn('Params "wait_for_selector" is ignored. Works only if render_js is enabled');
164
+ }
165
+ if (this.screenshots !== null) {
166
+ log.warn('Params "screenshots" is ignored. Works only if render_js is enabled');
167
+ }
168
+ if (this.js_scenario !== null) {
169
+ log.warn('Params "js_scenario" is ignored. Works only if render_js is enabled');
170
+ }
171
+ if (this.js !== null) {
172
+ log.warn('Params "js" is ignored. Works only if render_js is enabled');
173
+ }
174
+ if (this.rendering_wait !== null) {
175
+ log.warn('Params "rendering_wait" is ignored. Works only if render_js is enabled');
176
+ }
177
+ }
178
+ if (this.asp === true) {
179
+ params.asp = true;
180
+ }
181
+ if (this.retry === false) {
182
+ params.retry = false;
183
+ }
184
+ if (this.cache === true) {
185
+ params.cache = true;
186
+ if (this.cache_clear) {
187
+ params.cache_clear = true;
188
+ }
189
+ if (this.cache_ttl) {
190
+ params.cache_ttl = this.cache_ttl;
191
+ }
192
+ }
193
+ else {
194
+ if (this.cache_clear) {
195
+ log.warn('Params "cache_clear" is ignored. Works only if cache is enabled');
196
+ }
197
+ if (this.cache_ttl) {
198
+ log.warn('Params "cache_ttl" is ignored. Works only if cache is enabled');
199
+ }
200
+ }
201
+ if (this.dns === true) {
202
+ params.dns = true;
203
+ }
204
+ if (this.ssl === true) {
205
+ params.ssl = true;
206
+ }
207
+ if (this.tags.size > 0) {
208
+ params.tags = Array.from(this.tags).join(',');
209
+ }
210
+ if (this.correlation_id) {
211
+ params.correlation_id = this.correlation_id;
212
+ }
213
+ if (this.session) {
214
+ params.session = this.session;
215
+ if (this.session_sticky_proxy) {
216
+ params.session_sticky_proxy = true;
217
+ }
218
+ }
219
+ else {
220
+ if (this.session_sticky_proxy) {
221
+ log.warn('Params "session_sticky_proxy" is ignored. Works only if session is enabled');
222
+ }
223
+ }
224
+ if (this.debug === true) {
225
+ params.debug = true;
226
+ }
227
+ if (this.proxy_pool) {
228
+ params.proxy_pool = this.proxy_pool;
229
+ }
230
+ if (this.lang !== null) {
231
+ params.lang = this.lang.join(',');
232
+ }
233
+ if (this.os !== null) {
234
+ params.os = this.os;
235
+ }
236
+ // XXX: mising this.extract(?)
237
+ return params;
238
+ }
239
+ }
240
+ export { ScrapeConfig };
241
+ //# sourceMappingURL=scrapeconfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrapeconfig.js","sourceRoot":"","sources":["../../src/scrapeconfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAa,YAAY;IACrB,MAAM,CAAC,sBAAsB,GAAG,wBAAwB,CAAC;IACzD,MAAM,CAAC,uBAAuB,GAAG,yBAAyB,CAAC;IAE3D,GAAG,CAAS;IACZ,KAAK,GAAG,IAAI,CAAC;IACb,MAAM,GAAe,KAAK,CAAC;IAC3B,OAAO,GAAY,IAAI,CAAC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AC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACrC;QACD,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;SACvB;QAED,8BAA8B;QAC9B,OAAO,MAAM,CAAC;IAClB,CAAC;;SA7QQ,YAAY"}
@@ -0,0 +1,2 @@
1
+ export type Rec<T> = Record<string, T>;
2
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function urlsafe_b64encode(data: string): string;
@@ -0,0 +1,4 @@
1
+ export function urlsafe_b64encode(data) {
2
+ return Buffer.from(data, 'utf-8').toString('base64').replace('+', '-').replace('/', '_').replace(/=+$/, '');
3
+ }
4
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAChH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "scrapfly-sdk",
3
+ "version": "0.1.0",
4
+ "description": "SDK for Scrapfly.io web scraping service",
5
+ "type": "module",
6
+ "types": "build/src/main.d.ts",
7
+ "main": "build/src/main.js",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/scrapfly/typescript-scrapfly"
11
+ },
12
+ "bugs": "https://github.com/scrapfly/typescript-scrapfly/issues",
13
+ "homepage": "https://scrapfly.io/",
14
+ "keywords": [
15
+ "web scraping",
16
+ "SDK",
17
+ "scrapfly",
18
+ "api"
19
+ ],
20
+ "files": [
21
+ "build/src"
22
+ ],
23
+ "engines": {
24
+ "node": ">= 18.12 <19"
25
+ },
26
+ "devDependencies": {
27
+ "@types/jest": "~29.5",
28
+ "@types/node": "~18",
29
+ "@typescript-eslint/eslint-plugin": "~5.59",
30
+ "@typescript-eslint/parser": "~5.59",
31
+ "eslint": "~8.38",
32
+ "eslint-config-prettier": "~8.8",
33
+ "eslint-plugin-jest": "~27.2",
34
+ "jest": "~29.5",
35
+ "prettier": "~2.8",
36
+ "rimraf": "~5.0",
37
+ "ts-api-utils": "~0.0.44",
38
+ "ts-jest": "~29.1",
39
+ "typescript": "~5.0"
40
+ },
41
+ "scripts": {
42
+ "clean": "rimraf coverage build tmp",
43
+ "prebuild": "npm run lint",
44
+ "build": "tsc -p tsconfig.json",
45
+ "build:watch": "tsc -w -p tsconfig.json",
46
+ "build:release": "npm run clean && tsc -p tsconfig.release.json",
47
+ "lint": "eslint . --ext .ts --ext .mts",
48
+ "test": "jest --coverage",
49
+ "prettier": "prettier --config .prettierrc --write .",
50
+ "test:watch": "jest --watch"
51
+ },
52
+ "author": "Bernardas Alisauskas <bernardas@scrapfly.io>",
53
+ "license": "BSD",
54
+ "dependencies": {
55
+ "axios": "^1.4.0",
56
+ "node-fetch": "^3.3.1",
57
+ "tslib": "~2.5",
58
+ "tslog": "^4.8.2"
59
+ },
60
+ "volta": {
61
+ "node": "18.17.0"
62
+ }
63
+ }