n8n-nodes-scraperapi 0.2.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +185 -0
  3. package/dist/credentials/ScraperApiApi.credentials.d.ts +9 -0
  4. package/dist/credentials/ScraperApiApi.credentials.js +47 -0
  5. package/dist/credentials/ScraperApiApi.credentials.js.map +1 -0
  6. package/dist/nodes/ScraperApi/GenericFunctions.d.ts +23 -0
  7. package/dist/nodes/ScraperApi/GenericFunctions.js +111 -0
  8. package/dist/nodes/ScraperApi/GenericFunctions.js.map +1 -0
  9. package/dist/nodes/ScraperApi/ScraperApi.node.d.ts +5 -0
  10. package/dist/nodes/ScraperApi/ScraperApi.node.js +326 -0
  11. package/dist/nodes/ScraperApi/ScraperApi.node.js.map +1 -0
  12. package/dist/nodes/ScraperApi/descriptions/BatchDescription.d.ts +3 -0
  13. package/dist/nodes/ScraperApi/descriptions/BatchDescription.js +143 -0
  14. package/dist/nodes/ScraperApi/descriptions/BatchDescription.js.map +1 -0
  15. package/dist/nodes/ScraperApi/descriptions/CrawlDescription.d.ts +3 -0
  16. package/dist/nodes/ScraperApi/descriptions/CrawlDescription.js +103 -0
  17. package/dist/nodes/ScraperApi/descriptions/CrawlDescription.js.map +1 -0
  18. package/dist/nodes/ScraperApi/descriptions/ExtractDescription.d.ts +3 -0
  19. package/dist/nodes/ScraperApi/descriptions/ExtractDescription.js +157 -0
  20. package/dist/nodes/ScraperApi/descriptions/ExtractDescription.js.map +1 -0
  21. package/dist/nodes/ScraperApi/descriptions/MapDescription.d.ts +3 -0
  22. package/dist/nodes/ScraperApi/descriptions/MapDescription.js +63 -0
  23. package/dist/nodes/ScraperApi/descriptions/MapDescription.js.map +1 -0
  24. package/dist/nodes/ScraperApi/descriptions/SearchDescription.d.ts +3 -0
  25. package/dist/nodes/ScraperApi/descriptions/SearchDescription.js +148 -0
  26. package/dist/nodes/ScraperApi/descriptions/SearchDescription.js.map +1 -0
  27. package/dist/nodes/ScraperApi/descriptions/StatisticsDescription.d.ts +3 -0
  28. package/dist/nodes/ScraperApi/descriptions/StatisticsDescription.js +48 -0
  29. package/dist/nodes/ScraperApi/descriptions/StatisticsDescription.js.map +1 -0
  30. package/dist/nodes/ScraperApi/descriptions/WebhookDescription.d.ts +3 -0
  31. package/dist/nodes/ScraperApi/descriptions/WebhookDescription.js +93 -0
  32. package/dist/nodes/ScraperApi/descriptions/WebhookDescription.js.map +1 -0
  33. package/dist/nodes/ScraperApi/descriptions/shared.d.ts +15 -0
  34. package/dist/nodes/ScraperApi/descriptions/shared.js +91 -0
  35. package/dist/nodes/ScraperApi/descriptions/shared.js.map +1 -0
  36. package/dist/nodes/ScraperApi/scraper-geonode.svg +252 -0
  37. package/dist/nodes/ScraperApiTrigger/ScraperApiTrigger.node.d.ts +12 -0
  38. package/dist/nodes/ScraperApiTrigger/ScraperApiTrigger.node.js +169 -0
  39. package/dist/nodes/ScraperApiTrigger/ScraperApiTrigger.node.js.map +1 -0
  40. package/dist/nodes/ScraperApiTrigger/scraper-geonode.svg +252 -0
  41. package/dist/package.json +63 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/index.js +1 -0
  44. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Geonode Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # n8n-nodes-scraperapi
2
+
3
+ Community n8n node package for the **Geonode Scraper API**. Wraps the public REST endpoints (`/v1/extract`, `/v1/map`, `/v1/crawl`, `/v1/webhooks`, `/v1/statistics`) and ships a webhook trigger that registers itself against `/v1/webhooks` automatically.
4
+
5
+ The default deployment target is the preprod environment:
6
+
7
+ ```
8
+ https://scraper-preprod-34do9l3uke5.geonode.com
9
+ ```
10
+
11
+ You can point it at any other deployment by editing the **Base URL** field on the credential.
12
+
13
+ ---
14
+
15
+ ## Package structure
16
+
17
+ ```
18
+ n8n-nodes-scraperapi/
19
+ ├─ credentials/
20
+ │ └─ ScraperApiApi.credentials.ts # X-Api-Key credential, tested against /v1/statistics
21
+ ├─ nodes/
22
+ │ ├─ ScraperApi/
23
+ │ │ ├─ ScraperApi.node.ts # Action node (7 resources, ~20 operations)
24
+ │ │ ├─ GenericFunctions.ts # Auth + retry/backoff helpers + polling helper
25
+ │ │ ├─ scraperapi.svg # Node icon
26
+ │ │ └─ descriptions/
27
+ │ │ ├─ ExtractDescription.ts # Form schema for extract: run / getJob / listJobs
28
+ │ │ ├─ SearchDescription.ts # Form schema for search: run / getJob / listJobs
29
+ │ │ ├─ BatchDescription.ts # Form schema for batch: start / getStatus / listJobs / cancel
30
+ │ │ ├─ MapDescription.ts # Form schema for map: discover URLs
31
+ │ │ ├─ CrawlDescription.ts # Form schema for crawl: start / getStatus
32
+ │ │ ├─ WebhookDescription.ts # Form schema for webhook CRUD + deliveries
33
+ │ │ └─ StatisticsDescription.ts # Form schema for statistics: get
34
+ │ └─ ScraperApiTrigger/
35
+ │ ├─ ScraperApiTrigger.node.ts # Trigger node — auto-registers on activate
36
+ │ └─ scraperapi.svg
37
+ ├─ docker-compose.n8n.yml # Local n8n that mounts this package as a custom extension
38
+ ├─ package.json # n8n entry points -> dist/**
39
+ ├─ tsconfig.json # Compiles credentials/** + nodes/** -> dist/
40
+ ├─ gulpfile.js # Copies SVG icons into dist/
41
+ ├─ .eslintrc.js # eslint-plugin-n8n-nodes-base rules
42
+ └─ index.js # Empty — n8n loads via the "n8n" key in package.json
43
+ ```
44
+
45
+ ### Component descriptions
46
+
47
+ #### Credential — `ScraperApiApi`
48
+
49
+ **`X-Api-Key: <key>`** — your personal API key, sent on every request.
50
+
51
+ Credential fields:
52
+
53
+ | Field | Default | When to fill |
54
+ |----------|----------------------------------------------------|-------------------------------------------------------|
55
+ | Base URL | `https://scraper-preprod-34do9l3uke5.geonode.com` | Root URL, no trailing slash. |
56
+ | API Key | (empty) | Required. Sent as `X-Api-Key`. |
57
+
58
+ Clicking **Test** issues `GET {baseUrl}/v1/statistics` with the credentials applied. This endpoint is auth-gated.
59
+
60
+ #### Action node — `ScraperApi`
61
+
62
+ One node with seven resources, each exposing the relevant operations:
63
+
64
+ | Resource | Operation | What it does |
65
+ |--------------|-------------------|----------------------------------------------------------------------------------------------------|
66
+ | `extract` | Run Extraction | `POST /v1/extract`. Pick formats (html / markdown), JS rendering, sync vs async, proxy, headers. |
67
+ | `extract` | Get Job | `GET /v1/extract/{job_id}` — fetch a single async job result. |
68
+ | `extract` | List Jobs | `GET /v1/extract/jobs` with filters (status, URL, date range) and pagination. |
69
+ | `search` | Run Search | `POST /v1/search` — query plus optional engine, locale, page, safe search and time range. |
70
+ | `search` | Get Job | `GET /v1/search/{job_id}` — fetch a single search job. |
71
+ | `search` | List Jobs | `GET /v1/search/jobs` with filters (query, status, date range) and pagination. |
72
+ | `batch` | Start Batch | `POST /v1/batch` — many URLs in one job; formats, JS rendering, proxy, headers, invalid-URL policy.|
73
+ | `batch` | Get Status | `GET /v1/batch/{job_id}` — paginated results; optional client-side polling until terminal status. |
74
+ | `batch` | List Jobs | `GET /v1/batch/jobs` with filters (status, date range) and pagination. |
75
+ | `batch` | Cancel | `DELETE /v1/batch/{job_id}` — stop a batch that has not finished. |
76
+ | `map` | Discover URLs | `POST /v1/map` — sitemap + optional search keyword, returns `links[]`. |
77
+ | `crawl` | Start Crawl | `POST /v1/crawl` — seed URL, depth, limit, formats, same-domain / subdomain rules, proxy. |
78
+ | `crawl` | Get Status | `GET /v1/crawl/{job_id}` — paginated results; optional client-side polling until terminal status. |
79
+ | `webhook` | Create | `POST /v1/webhooks` — register a target URL for an event. |
80
+ | `webhook` | Get / List | `GET /v1/webhooks/{id}` and `GET /v1/webhooks` (paginated). |
81
+ | `webhook` | Update | `PATCH /v1/webhooks/{id}` — change URL, description, event type, active flag. |
82
+ | `webhook` | Delete | `DELETE /v1/webhooks/{id}`. |
83
+ | `webhook` | Rotate Secret | `POST /v1/webhooks/{id}/rotate-secret` — issues a new HMAC signing secret. |
84
+ | `webhook` | List Deliveries | `GET /v1/webhooks/{id}/deliveries` with status filter and pagination. |
85
+ | `statistics` | Get | `GET /v1/statistics` for an optional date range. |
86
+
87
+ When a sync extract returns inline, the response is the raw `{data, ...}` body. For async (`processing_mode=async`) the API returns `{job_id, status, status_url, estimated_tokens}`; if **Wait for Completion** is on, the node polls `status_url` until the job hits `completed | failed | cancelled` and returns that final body.
88
+
89
+ The shared HTTP helper (`GenericFunctions.scraperApiRequest`) handles:
90
+ - `X-Api-Key` header injection via the credential
91
+ - Up to 5 retries on `429` and `5xx` with exponential backoff
92
+ - `Retry-After` header support (seconds or HTTP-date)
93
+ - Conversion of non-retryable errors into `NodeApiError` so n8n surfaces them in the UI
94
+
95
+ #### Trigger node — `ScraperApiTrigger`
96
+
97
+ Use this when you want a workflow to run **whenever the Scraper API emits an event** (`extract_completed`, `crawl_completed`).
98
+
99
+ On workflow activation it:
100
+ 1. Calls `POST /v1/webhooks` with n8n's public webhook URL and the chosen event type.
101
+ 2. Stashes the returned `id` and `secret` in workflow static data.
102
+
103
+ On webhook delivery it (optionally) verifies `X-Webhook-Signature: sha256=<hex>` using HMAC-SHA256 + the stored secret, then emits `{headers, body}` as workflow input.
104
+
105
+ On deactivation it calls `DELETE /v1/webhooks/{id}` to clean up.
106
+
107
+ ---
108
+
109
+ ## Running the node
110
+
111
+ A ready-made compose file lives at `docker-compose.n8n.yml` in this directory. It mounts this package into n8n's custom-extensions dir and exposes the editor on `http://localhost:5678`.
112
+
113
+ From this directory:
114
+
115
+ ```bash
116
+ # 1. Install deps and build the package
117
+ npm install
118
+ npm run build # produces ./dist/ which docker-compose mounts into n8n
119
+
120
+ # 2. Start n8n
121
+ docker compose -f docker-compose.n8n.yml up -d
122
+ ```
123
+
124
+ > The compose file mounts the package directory read-only into `/home/node/.n8n/custom/n8n-nodes-scraperapi`. n8n reads the `n8n` key from `package.json` and loads the compiled JS from `dist/**`, so **`npm run build` must succeed before starting the container** (or before restarting after code changes).
125
+
126
+ After the container is up:
127
+
128
+ 1. Open `http://localhost:5678` and finish the n8n owner setup.
129
+ 2. **Credentials → New → Scraper API**.
130
+ - Base URL: `https://scraper-preprod-34do9l3uke5.geonode.com` (the default).
131
+ - API Key: your preprod key.
132
+ - Click **Test** — expects 200 from `/v1/health`.
133
+ 3. New workflow → search **Scraper API** → drop it in.
134
+
135
+ To pick up code changes:
136
+
137
+ ```bash
138
+ npm run build
139
+ docker compose -f docker-compose.n8n.yml restart n8n
140
+ ```
141
+
142
+ To stop / clean up:
143
+
144
+ ```bash
145
+ docker compose -f docker-compose.n8n.yml down # stop, keep data
146
+ docker compose -f docker-compose.n8n.yml down -v # also drop the n8n_data volume
147
+ ```
148
+
149
+ ### Smoke test
150
+
151
+ In a workflow, add **Scraper API** → resource `extract` → operation `Run Extraction`:
152
+
153
+ ![Creation](./docs/screenshots/node-creating.png)
154
+ ![List](./docs/screenshots/nodes-list.png)
155
+
156
+ - URL: `https://example.com`
157
+ - Output Formats: `html`
158
+ - Render JavaScript: off
159
+ - Processing Mode: `Sync (Block Until Done)`
160
+
161
+ ![Execution](./docs/screenshots/node-execution.png)
162
+
163
+ Click **Execute Node** — you should see a JSON output with `data.html` populated.
164
+
165
+ Then try the trigger: in a separate workflow add **Scraper API Trigger**, pick `extract_completed`, **save** and **activate**. The node will register a webhook against `/v1/webhooks`. Run an `extract` against the same deployment with `processing_mode=async`; when it finishes, the trigger workflow fires.
166
+
167
+ ---
168
+
169
+ ## Scripts reference
170
+
171
+ ```bash
172
+ npm run build # tsc + copy SVG icons into dist/
173
+ npm run dev # tsc --watch
174
+ npm run lint # eslint with eslint-plugin-n8n-nodes-base
175
+ npm run lintfix # eslint --fix
176
+ npm run format # prettier on nodes/ and credentials/
177
+ ```
178
+
179
+ ## Notes specific to this API
180
+
181
+ - **Auth** — `X-Api-Key` header (per-user). See `app/api/security/auth_token_handler.py`. Billing user resolution happens in `app/api/security/user_resolver.py`.
182
+ - **Async extract** — `processing_mode=async` returns 202 with `{job_id, status, status_url, estimated_tokens}` (see `app/api/v1/extract/router.py`). The node polls `status_url` when **Wait for Completion** is on.
183
+ - **Throttling (HTTP 429)** — `scraperApiRequest` honors `Retry-After` and retries up to 5 times with exponential backoff (also covers transient 5xx).
184
+ - **Errors** — surfaced as `NodeApiError`. The API returns `{code, message, correlation_id, retryable}` (see `app/api/v1/extract/schemas.py`).
185
+ - **Webhook events** — `extract_completed`, `crawl_completed` (see `app/core/webhooks/event_types.py`).
@@ -0,0 +1,9 @@
1
+ import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class ScraperApiApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScraperApiApi = void 0;
4
+ class ScraperApiApi {
5
+ constructor() {
6
+ this.name = 'scraperApiApi';
7
+ this.displayName = 'Scraper API';
8
+ this.documentationUrl = 'https://github.com/geonodecom/scraper-api';
9
+ this.properties = [
10
+ {
11
+ displayName: 'Base URL',
12
+ name: 'baseUrl',
13
+ type: 'string',
14
+ default: 'https://scraper-preprod-34do9l3uke5.geonode.com',
15
+ placeholder: 'https://scraper-preprod-34do9l3uke5.geonode.com',
16
+ description: 'Root URL of the Scraper API deployment (no trailing slash)',
17
+ required: true,
18
+ },
19
+ {
20
+ displayName: 'API Key',
21
+ name: 'apiKey',
22
+ type: 'string',
23
+ typeOptions: { password: true },
24
+ default: '',
25
+ required: true,
26
+ description: 'Sent as the X-Api-Key header. Required when the deployment has billing enabled (the default).',
27
+ },
28
+ ];
29
+ this.authenticate = {
30
+ type: 'generic',
31
+ properties: {
32
+ headers: {
33
+ 'X-Api-Key': '={{$credentials.apiKey}}',
34
+ },
35
+ },
36
+ };
37
+ this.test = {
38
+ request: {
39
+ baseURL: '={{$credentials.baseUrl}}',
40
+ url: '/v1/statistics',
41
+ method: 'GET',
42
+ },
43
+ };
44
+ }
45
+ }
46
+ exports.ScraperApiApi = ScraperApiApi;
47
+ //# sourceMappingURL=ScraperApiApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScraperApiApi.credentials.js","sourceRoot":"","sources":["../../credentials/ScraperApiApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,aAAa;IAA1B;QACE,SAAI,GAAG,eAAe,CAAC;QACvB,gBAAW,GAAG,aAAa,CAAC;QAC5B,qBAAgB,GAAG,2CAA2C,CAAC;QAE/D,eAAU,GAAsB;YAC9B;gBACE,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,iDAAiD;gBAC1D,WAAW,EAAE,iDAAiD;gBAC9D,WAAW,EAAE,4DAA4D;gBACzE,QAAQ,EAAE,IAAI;aACf;YACD;gBACE,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EACT,+FAA+F;aAClG;SACF,CAAC;QAEF,iBAAY,GAAyB;YACnC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,WAAW,EAAE,0BAA0B;iBACxC;aACF;SACF,CAAC;QAIF,SAAI,GAA2B;YAC7B,OAAO,EAAE;gBACP,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,gBAAgB;gBACrB,MAAM,EAAE,KAAK;aACd;SACF,CAAC;IACJ,CAAC;CAAA;AA7CD,sCA6CC"}
@@ -0,0 +1,23 @@
1
+ import { IDataObject, IExecuteFunctions, IHookFunctions, IHttpRequestMethods, ILoadOptionsFunctions, IWebhookFunctions, JsonObject } from 'n8n-workflow';
2
+ export type ScraperApiContext = IExecuteFunctions | IHookFunctions | IWebhookFunctions | ILoadOptionsFunctions;
3
+ export interface ScraperApiRequestOptions {
4
+ method: IHttpRequestMethods;
5
+ url: string;
6
+ body?: IDataObject;
7
+ qs?: IDataObject;
8
+ }
9
+ export declare function scraperApiRequest(this: ScraperApiContext, options: ScraperApiRequestOptions): Promise<JsonObject>;
10
+ export interface PollOptions {
11
+ jobUrl: string;
12
+ intervalMs?: number;
13
+ timeoutMs?: number;
14
+ terminalStatuses?: string[];
15
+ }
16
+ export declare function pollUntilComplete(this: ScraperApiContext, opts: PollOptions): Promise<JsonObject>;
17
+ export declare function pruneEmpty<T extends Record<string, unknown>>(obj: T): T;
18
+ export declare function headersFromCollection(raw: {
19
+ header?: Array<{
20
+ name: string;
21
+ value: string;
22
+ }>;
23
+ } | undefined): Record<string, string> | undefined;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scraperApiRequest = scraperApiRequest;
4
+ exports.pollUntilComplete = pollUntilComplete;
5
+ exports.pruneEmpty = pruneEmpty;
6
+ exports.headersFromCollection = headersFromCollection;
7
+ const n8n_workflow_1 = require("n8n-workflow");
8
+ const MAX_RETRY_ATTEMPTS = 5;
9
+ const DEFAULT_BACKOFF_MS = 1000;
10
+ const TERMINAL_STATUSES = ['completed', 'failed', 'cancelled'];
11
+ function parseRetryAfter(value) {
12
+ if (value == null)
13
+ return null;
14
+ const raw = Array.isArray(value) ? value[0] : value;
15
+ const seconds = Number(raw);
16
+ if (!Number.isNaN(seconds) && seconds >= 0)
17
+ return Math.ceil(seconds * 1000);
18
+ const dateMs = Date.parse(String(raw));
19
+ if (Number.isNaN(dateMs))
20
+ return null;
21
+ return Math.max(0, dateMs - Date.now());
22
+ }
23
+ async function scraperApiRequest(options) {
24
+ var _a, _b, _c, _d;
25
+ const credentials = await this.getCredentials('scraperApiApi');
26
+ const baseUrl = String(credentials.baseUrl).replace(/\/+$/, '');
27
+ const isAbsoluteUrl = /^https?:\/\//i.test(options.url);
28
+ const requestOptions = {
29
+ method: options.method,
30
+ url: isAbsoluteUrl ? options.url : `${baseUrl}${options.url}`,
31
+ body: options.body,
32
+ qs: options.qs,
33
+ json: true,
34
+ returnFullResponse: true,
35
+ };
36
+ for (let attempt = 1;; attempt++) {
37
+ try {
38
+ const response = (await this.helpers.httpRequestWithAuthentication.call(this, 'scraperApiApi', requestOptions));
39
+ return response.body;
40
+ }
41
+ catch (error) {
42
+ const err = error;
43
+ const status = (_a = err.statusCode) !== null && _a !== void 0 ? _a : err.httpCode;
44
+ const isRetryable = status === 429 || (status !== undefined && status >= 500 && status < 600);
45
+ if (isRetryable && attempt < MAX_RETRY_ATTEMPTS) {
46
+ const retryAfterMs = (_d = parseRetryAfter((_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c['retry-after'])) !== null && _d !== void 0 ? _d : DEFAULT_BACKOFF_MS * 2 ** (attempt - 1);
47
+ await (0, n8n_workflow_1.sleep)(retryAfterMs);
48
+ continue;
49
+ }
50
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
51
+ }
52
+ }
53
+ }
54
+ async function pollUntilComplete(opts) {
55
+ var _a, _b, _c, _d;
56
+ const interval = (_a = opts.intervalMs) !== null && _a !== void 0 ? _a : 2000;
57
+ const timeout = (_b = opts.timeoutMs) !== null && _b !== void 0 ? _b : 5 * 60 * 1000;
58
+ const terminal = ((_c = opts.terminalStatuses) !== null && _c !== void 0 ? _c : TERMINAL_STATUSES).map((s) => s.toLowerCase());
59
+ const deadline = Date.now() + timeout;
60
+ while (true) {
61
+ const body = await scraperApiRequest.call(this, { method: 'GET', url: opts.jobUrl });
62
+ const status = String((_d = body.status) !== null && _d !== void 0 ? _d : '').toLowerCase();
63
+ if (terminal.includes(status))
64
+ return body;
65
+ if (Date.now() > deadline) {
66
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), {
67
+ message: `Polling timed out after ${timeout}ms (last status: ${status || 'unknown'})`,
68
+ });
69
+ }
70
+ await (0, n8n_workflow_1.sleep)(interval);
71
+ }
72
+ }
73
+ function isPlainObject(v) {
74
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
75
+ }
76
+ function pruneEmpty(obj) {
77
+ const out = {};
78
+ for (const [k, v] of Object.entries(obj)) {
79
+ if (v === undefined || v === null)
80
+ continue;
81
+ if (typeof v === 'string' && v.length === 0)
82
+ continue;
83
+ if (Array.isArray(v)) {
84
+ if (v.length === 0)
85
+ continue;
86
+ out[k] = v;
87
+ continue;
88
+ }
89
+ if (isPlainObject(v)) {
90
+ const pruned = pruneEmpty(v);
91
+ if (Object.keys(pruned).length === 0)
92
+ continue;
93
+ out[k] = pruned;
94
+ continue;
95
+ }
96
+ out[k] = v;
97
+ }
98
+ return out;
99
+ }
100
+ function headersFromCollection(raw) {
101
+ var _a, _b;
102
+ if (!((_a = raw === null || raw === void 0 ? void 0 : raw.header) === null || _a === void 0 ? void 0 : _a.length))
103
+ return undefined;
104
+ const out = {};
105
+ for (const h of raw.header) {
106
+ if (h.name)
107
+ out[h.name] = (_b = h.value) !== null && _b !== void 0 ? _b : '';
108
+ }
109
+ return Object.keys(out).length === 0 ? undefined : out;
110
+ }
111
+ //# sourceMappingURL=GenericFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/ScraperApi/GenericFunctions.ts"],"names":[],"mappings":";;AAwCA,8CA6CC;AASD,8CAoBC;AAUD,gCAmBC;AAED,sDASC;AA1JD,+CAWsB;AAetB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAE/D,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC7E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO,IAAI,C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AC;QACD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,qBAAqB,CACnC,GAAoE;;IAEpE,IAAI,CAAC,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,0CAAE,MAAM,CAAA;QAAE,OAAO,SAAS,CAAC;IAC3C,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,IAAI;YAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,MAAA,CAAC,CAAC,KAAK,mCAAI,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;AACzD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class ScraperApi implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }