webcrawlerapi-js 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -16,10 +16,10 @@ Install WebcrawlerAPI js package:
16
16
  ## Request example
17
17
 
18
18
  ```javascript
19
- import webcrawlerapi from "webcrawlerapi-js";
19
+ import { WebcrawlerClient } from "webcrawlerapi-js"
20
20
 
21
21
  async function main() {
22
- const client = new webcrawlerapi.WebcrawlerClient(
22
+ const client = new WebcrawlerClient(
23
23
  "YOUR API ACCESS KEY HERE",
24
24
  )
25
25
  // sync way - promise will be resolved with the all the data
@@ -79,6 +79,7 @@ main().catch(console.error);
79
79
  status: 'new',
80
80
  title: '',
81
81
  last_error: '',
82
+ error_code: '',
82
83
  created_at: '2024-12-28T21:36:04.468Z',
83
84
  updated_at: '2024-12-28T21:36:04.435Z',
84
85
  cost: 0,
package/api.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {CrawlRequest, Job, JobId, ScrapeRequest, ScrapeResponse} from "./model";
2
+ import { JobStatus } from "./constants";
2
3
 
3
4
  const BASE_PATH = "https://api.webcrawlerapi.com"
4
5
  const initialPullDelayMs = 2000
@@ -67,7 +68,7 @@ export class WebcrawlerClient {
67
68
  if (scrapeRequest.debug) {
68
69
  console.log(`Scrape result: ${JSON.stringify(scrapeResult)}`);
69
70
  }
70
- if (scrapeResult.status !== 'in_progress' && scrapeResult.status !== 'new') {
71
+ if (scrapeResult.status !== JobStatus.IN_PROGRESS && scrapeResult.status !== JobStatus.NEW) {
71
72
  return scrapeResult;
72
73
  }
73
74
  if (scrapeResult.recommended_pull_delay_ms > 0) {
@@ -139,12 +140,12 @@ export class WebcrawlerClient {
139
140
  await new Promise(resolve => setTimeout(resolve, delayIntervalMs));
140
141
  const timestamp = new Date().getTime();
141
142
  const job = await this.getJob(`${jobIdResponse.id}?t=${timestamp}`);
142
- if (job.status !== 'in_progress' && job.status !== 'new') {
143
+ if (job.status !== JobStatus.IN_PROGRESS && job.status !== JobStatus.NEW) {
143
144
  // Transform each job item to include getContent method
144
145
  job.job_items = job.job_items.map(item => ({
145
146
  ...item,
146
147
  getContent: async function(): Promise<string | null> {
147
- if (this.status !== 'done') {
148
+ if (job.status !== JobStatus.DONE || this.status !== JobStatus.DONE) {
148
149
  return null;
149
150
  }
150
151
 
package/constants.ts ADDED
@@ -0,0 +1,14 @@
1
+ export const JobStatus = {
2
+ IN_PROGRESS: 'in_progress',
3
+ NEW: 'new',
4
+ DONE: 'done'
5
+ } as const;
6
+
7
+ export const HttpStatus = {
8
+ OK: 200,
9
+ BAD_REQUEST: 400,
10
+ UNAUTHORIZED: 401,
11
+ FORBIDDEN: 403,
12
+ NOT_FOUND: 404,
13
+ INTERNAL_SERVER_ERROR: 500
14
+ } as const;
package/dist/api.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.WebcrawlerClient = void 0;
13
+ const constants_1 = require("./constants");
13
14
  const BASE_PATH = "https://api.webcrawlerapi.com";
14
15
  const initialPullDelayMs = 2000;
15
16
  const MaxPullRetries = 100;
@@ -67,7 +68,7 @@ class WebcrawlerClient {
67
68
  if (scrapeRequest.debug) {
68
69
  console.log(`Scrape result: ${JSON.stringify(scrapeResult)}`);
69
70
  }
70
- if (scrapeResult.status !== 'in_progress' && scrapeResult.status !== 'new') {
71
+ if (scrapeResult.status !== constants_1.JobStatus.IN_PROGRESS && scrapeResult.status !== constants_1.JobStatus.NEW) {
71
72
  return scrapeResult;
72
73
  }
73
74
  if (scrapeResult.recommended_pull_delay_ms > 0) {
@@ -134,11 +135,11 @@ class WebcrawlerClient {
134
135
  yield new Promise(resolve => setTimeout(resolve, delayIntervalMs));
135
136
  const timestamp = new Date().getTime();
136
137
  const job = yield this.getJob(`${jobIdResponse.id}?t=${timestamp}`);
137
- if (job.status !== 'in_progress' && job.status !== 'new') {
138
+ if (job.status !== constants_1.JobStatus.IN_PROGRESS && job.status !== constants_1.JobStatus.NEW) {
138
139
  // Transform each job item to include getContent method
139
140
  job.job_items = job.job_items.map(item => (Object.assign(Object.assign({}, item), { getContent: function () {
140
141
  return __awaiter(this, void 0, void 0, function* () {
141
- if (this.status !== 'done') {
142
+ if (job.status !== constants_1.JobStatus.DONE || this.status !== constants_1.JobStatus.DONE) {
142
143
  return null;
143
144
  }
144
145
  let contentUrl;
@@ -0,0 +1,13 @@
1
+ export declare const JobStatus: {
2
+ readonly IN_PROGRESS: "in_progress";
3
+ readonly NEW: "new";
4
+ readonly DONE: "done";
5
+ };
6
+ export declare const HttpStatus: {
7
+ readonly OK: 200;
8
+ readonly BAD_REQUEST: 400;
9
+ readonly UNAUTHORIZED: 401;
10
+ readonly FORBIDDEN: 403;
11
+ readonly NOT_FOUND: 404;
12
+ readonly INTERNAL_SERVER_ERROR: 500;
13
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpStatus = exports.JobStatus = void 0;
4
+ exports.JobStatus = {
5
+ IN_PROGRESS: 'in_progress',
6
+ NEW: 'new',
7
+ DONE: 'done'
8
+ };
9
+ exports.HttpStatus = {
10
+ OK: 200,
11
+ BAD_REQUEST: 400,
12
+ UNAUTHORIZED: 401,
13
+ FORBIDDEN: 403,
14
+ NOT_FOUND: 404,
15
+ INTERNAL_SERVER_ERROR: 500
16
+ };
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "webcrawlerapi-js",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
+
4
5
  "description": "JS client for WecrawlerAPI",
5
6
  "main": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc --outDir dist/"
10
+ },
7
11
  "keywords": [
8
12
  "scraping",
9
13
  "scraper",
@@ -19,8 +23,5 @@
19
23
  },
20
24
  "author": "Andrew <sdk@webcrawlerapi.com>",
21
25
  "license": "MIT",
22
- "dependencies": {},
23
- "scripts": {
24
- "build": "tsc --outDir dist/"
25
- }
26
- }
26
+ "dependencies": {}
27
+ }