@dealcrawl/sdk 2.0.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/README.md +540 -0
- package/dist/sdk/src/client.d.ts +285 -0
- package/dist/sdk/src/client.d.ts.map +1 -0
- package/dist/sdk/src/client.js +336 -0
- package/dist/sdk/src/client.js.map +1 -0
- package/dist/sdk/src/error.d.ts +54 -0
- package/dist/sdk/src/error.d.ts.map +1 -0
- package/dist/sdk/src/error.js +115 -0
- package/dist/sdk/src/error.js.map +1 -0
- package/dist/sdk/src/index.d.ts +58 -0
- package/dist/sdk/src/index.d.ts.map +1 -0
- package/dist/sdk/src/index.js +65 -0
- package/dist/sdk/src/index.js.map +1 -0
- package/dist/sdk/src/resources/account.d.ts +143 -0
- package/dist/sdk/src/resources/account.d.ts.map +1 -0
- package/dist/sdk/src/resources/account.js +186 -0
- package/dist/sdk/src/resources/account.js.map +1 -0
- package/dist/sdk/src/resources/crawl.d.ts +87 -0
- package/dist/sdk/src/resources/crawl.d.ts.map +1 -0
- package/dist/sdk/src/resources/crawl.js +205 -0
- package/dist/sdk/src/resources/crawl.js.map +1 -0
- package/dist/sdk/src/resources/data.d.ts +157 -0
- package/dist/sdk/src/resources/data.d.ts.map +1 -0
- package/dist/sdk/src/resources/data.js +239 -0
- package/dist/sdk/src/resources/data.js.map +1 -0
- package/dist/sdk/src/resources/dork.d.ts +104 -0
- package/dist/sdk/src/resources/dork.d.ts.map +1 -0
- package/dist/sdk/src/resources/dork.js +163 -0
- package/dist/sdk/src/resources/dork.js.map +1 -0
- package/dist/sdk/src/resources/extract.d.ts +105 -0
- package/dist/sdk/src/resources/extract.d.ts.map +1 -0
- package/dist/sdk/src/resources/extract.js +246 -0
- package/dist/sdk/src/resources/extract.js.map +1 -0
- package/dist/sdk/src/resources/index.d.ts +14 -0
- package/dist/sdk/src/resources/index.d.ts.map +1 -0
- package/dist/sdk/src/resources/index.js +14 -0
- package/dist/sdk/src/resources/index.js.map +1 -0
- package/dist/sdk/src/resources/keys.d.ts +124 -0
- package/dist/sdk/src/resources/keys.d.ts.map +1 -0
- package/dist/sdk/src/resources/keys.js +168 -0
- package/dist/sdk/src/resources/keys.js.map +1 -0
- package/dist/sdk/src/resources/scrape.d.ts +53 -0
- package/dist/sdk/src/resources/scrape.d.ts.map +1 -0
- package/dist/sdk/src/resources/scrape.js +85 -0
- package/dist/sdk/src/resources/scrape.js.map +1 -0
- package/dist/sdk/src/resources/status.d.ts +100 -0
- package/dist/sdk/src/resources/status.d.ts.map +1 -0
- package/dist/sdk/src/resources/status.js +133 -0
- package/dist/sdk/src/resources/status.js.map +1 -0
- package/dist/sdk/src/resources/webhooks.d.ts +126 -0
- package/dist/sdk/src/resources/webhooks.d.ts.map +1 -0
- package/dist/sdk/src/resources/webhooks.js +167 -0
- package/dist/sdk/src/resources/webhooks.js.map +1 -0
- package/dist/sdk/src/types/config.d.ts +45 -0
- package/dist/sdk/src/types/config.d.ts.map +1 -0
- package/dist/sdk/src/types/config.js +10 -0
- package/dist/sdk/src/types/config.js.map +1 -0
- package/dist/sdk/src/types/index.d.ts +8 -0
- package/dist/sdk/src/types/index.d.ts.map +1 -0
- package/dist/sdk/src/types/index.js +8 -0
- package/dist/sdk/src/types/index.js.map +1 -0
- package/dist/sdk/src/types/options.d.ts +286 -0
- package/dist/sdk/src/types/options.d.ts.map +1 -0
- package/dist/sdk/src/types/options.js +6 -0
- package/dist/sdk/src/types/options.js.map +1 -0
- package/dist/sdk/src/types/responses.d.ts +385 -0
- package/dist/sdk/src/types/responses.d.ts.map +1 -0
- package/dist/sdk/src/types/responses.js +6 -0
- package/dist/sdk/src/types/responses.js.map +1 -0
- package/dist/sdk/src/utils/polling.d.ts +57 -0
- package/dist/sdk/src/utils/polling.d.ts.map +1 -0
- package/dist/sdk/src/utils/polling.js +110 -0
- package/dist/sdk/src/utils/polling.js.map +1 -0
- package/dist/sdk/src/utils/request.d.ts +47 -0
- package/dist/sdk/src/utils/request.d.ts.map +1 -0
- package/dist/sdk/src/utils/request.js +161 -0
- package/dist/sdk/src/utils/request.js.map +1 -0
- package/dist/shared/src/constants/errors.d.ts +26 -0
- package/dist/shared/src/constants/errors.d.ts.map +1 -0
- package/dist/shared/src/constants/errors.js +39 -0
- package/dist/shared/src/constants/errors.js.map +1 -0
- package/dist/shared/src/constants/http.d.ts +26 -0
- package/dist/shared/src/constants/http.d.ts.map +1 -0
- package/dist/shared/src/constants/http.js +26 -0
- package/dist/shared/src/constants/http.js.map +1 -0
- package/dist/shared/src/constants/index.d.ts +4 -0
- package/dist/shared/src/constants/index.d.ts.map +1 -0
- package/dist/shared/src/constants/index.js +5 -0
- package/dist/shared/src/constants/index.js.map +1 -0
- package/dist/shared/src/constants/limits.d.ts +52 -0
- package/dist/shared/src/constants/limits.d.ts.map +1 -0
- package/dist/shared/src/constants/limits.js +43 -0
- package/dist/shared/src/constants/limits.js.map +1 -0
- package/dist/shared/src/index.d.ts +5 -0
- package/dist/shared/src/index.d.ts.map +1 -0
- package/dist/shared/src/index.js +11 -0
- package/dist/shared/src/index.js.map +1 -0
- package/dist/shared/src/lib/index.d.ts +2 -0
- package/dist/shared/src/lib/index.d.ts.map +1 -0
- package/dist/shared/src/lib/index.js +2 -0
- package/dist/shared/src/lib/index.js.map +1 -0
- package/dist/shared/src/lib/redis.d.ts +14 -0
- package/dist/shared/src/lib/redis.d.ts.map +1 -0
- package/dist/shared/src/lib/redis.js +60 -0
- package/dist/shared/src/lib/redis.js.map +1 -0
- package/dist/shared/src/types/api-key.types.d.ts +94 -0
- package/dist/shared/src/types/api-key.types.d.ts.map +1 -0
- package/dist/shared/src/types/api-key.types.js +30 -0
- package/dist/shared/src/types/api-key.types.js.map +1 -0
- package/dist/shared/src/types/api.types.d.ts +38 -0
- package/dist/shared/src/types/api.types.d.ts.map +1 -0
- package/dist/shared/src/types/api.types.js +2 -0
- package/dist/shared/src/types/api.types.js.map +1 -0
- package/dist/shared/src/types/client.types.d.ts +73 -0
- package/dist/shared/src/types/client.types.d.ts.map +1 -0
- package/dist/shared/src/types/client.types.js +9 -0
- package/dist/shared/src/types/client.types.js.map +1 -0
- package/dist/shared/src/types/crawl.types.d.ts +65 -0
- package/dist/shared/src/types/crawl.types.d.ts.map +1 -0
- package/dist/shared/src/types/crawl.types.js +2 -0
- package/dist/shared/src/types/crawl.types.js.map +1 -0
- package/dist/shared/src/types/deal.types.d.ts +210 -0
- package/dist/shared/src/types/deal.types.d.ts.map +1 -0
- package/dist/shared/src/types/deal.types.js +6 -0
- package/dist/shared/src/types/deal.types.js.map +1 -0
- package/dist/shared/src/types/dork.types.d.ts +29 -0
- package/dist/shared/src/types/dork.types.d.ts.map +1 -0
- package/dist/shared/src/types/dork.types.js +2 -0
- package/dist/shared/src/types/dork.types.js.map +1 -0
- package/dist/shared/src/types/index.d.ts +8 -0
- package/dist/shared/src/types/index.d.ts.map +1 -0
- package/dist/shared/src/types/index.js +9 -0
- package/dist/shared/src/types/index.js.map +1 -0
- package/dist/shared/src/types/scrape.types.d.ts +151 -0
- package/dist/shared/src/types/scrape.types.d.ts.map +1 -0
- package/dist/shared/src/types/scrape.types.js +2 -0
- package/dist/shared/src/types/scrape.types.js.map +1 -0
- package/dist/shared/src/utils/date.d.ts +7 -0
- package/dist/shared/src/utils/date.d.ts.map +1 -0
- package/dist/shared/src/utils/date.js +25 -0
- package/dist/shared/src/utils/date.js.map +1 -0
- package/dist/shared/src/utils/hash.d.ts +4 -0
- package/dist/shared/src/utils/hash.d.ts.map +1 -0
- package/dist/shared/src/utils/hash.js +21 -0
- package/dist/shared/src/utils/hash.js.map +1 -0
- package/dist/shared/src/utils/index.d.ts +7 -0
- package/dist/shared/src/utils/index.d.ts.map +1 -0
- package/dist/shared/src/utils/index.js +8 -0
- package/dist/shared/src/utils/index.js.map +1 -0
- package/dist/shared/src/utils/logger.d.ts +66 -0
- package/dist/shared/src/utils/logger.d.ts.map +1 -0
- package/dist/shared/src/utils/logger.js +268 -0
- package/dist/shared/src/utils/logger.js.map +1 -0
- package/dist/shared/src/utils/retry.d.ts +11 -0
- package/dist/shared/src/utils/retry.d.ts.map +1 -0
- package/dist/shared/src/utils/retry.js +36 -0
- package/dist/shared/src/utils/retry.js.map +1 -0
- package/dist/shared/src/utils/url-validator.d.ts +37 -0
- package/dist/shared/src/utils/url-validator.d.ts.map +1 -0
- package/dist/shared/src/utils/url-validator.js +179 -0
- package/dist/shared/src/utils/url-validator.js.map +1 -0
- package/dist/shared/src/utils/url.d.ts +6 -0
- package/dist/shared/src/utils/url.d.ts.map +1 -0
- package/dist/shared/src/utils/url.js +56 -0
- package/dist/shared/src/utils/url.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DealCrawl SDK Client
|
|
3
|
+
* Main entry point for the SDK
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { DealCrawl } from "@dealcrawl/sdk";
|
|
8
|
+
*
|
|
9
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
10
|
+
*
|
|
11
|
+
* // Scrape a page
|
|
12
|
+
* const job = await client.scrape.create({
|
|
13
|
+
* url: "https://example.com/product",
|
|
14
|
+
* extractDeal: true
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Wait for result
|
|
18
|
+
* const result = await client.waitForResult(job.jobId);
|
|
19
|
+
* console.log(result);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { DealCrawlConfig } from "./types/config";
|
|
23
|
+
import type { WaitOptions, WaitResult } from "./utils/polling";
|
|
24
|
+
import { ScrapeResource } from "./resources/scrape";
|
|
25
|
+
import { CrawlResource } from "./resources/crawl";
|
|
26
|
+
import { ExtractResource } from "./resources/extract";
|
|
27
|
+
import { DorkResource } from "./resources/dork";
|
|
28
|
+
import { StatusResource } from "./resources/status";
|
|
29
|
+
import { DataResource } from "./resources/data";
|
|
30
|
+
import { WebhooksResource } from "./resources/webhooks";
|
|
31
|
+
import { KeysResource } from "./resources/keys";
|
|
32
|
+
import { AccountResource } from "./resources/account";
|
|
33
|
+
/**
|
|
34
|
+
* DealCrawl SDK Client
|
|
35
|
+
*
|
|
36
|
+
* Provides access to all DealCrawl API endpoints through
|
|
37
|
+
* organized resource classes following a Stripe-like pattern.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
42
|
+
*
|
|
43
|
+
* // Core operations
|
|
44
|
+
* await client.scrape.create({ url: "..." });
|
|
45
|
+
* await client.crawl.create({ url: "...", maxPages: 100 });
|
|
46
|
+
* await client.extract.create({ url: "...", schema: {...} });
|
|
47
|
+
* await client.dork.create({ query: "..." });
|
|
48
|
+
*
|
|
49
|
+
* // Status & polling
|
|
50
|
+
* await client.status.get(jobId);
|
|
51
|
+
* await client.waitForResult(jobId);
|
|
52
|
+
*
|
|
53
|
+
* // Data access
|
|
54
|
+
* await client.data.listJobs();
|
|
55
|
+
* await client.data.listDeals();
|
|
56
|
+
*
|
|
57
|
+
* // Management
|
|
58
|
+
* await client.webhooks.create({...});
|
|
59
|
+
* await client.keys.create({...});
|
|
60
|
+
* await client.account.get();
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare class DealCrawl {
|
|
64
|
+
/** Internal request context */
|
|
65
|
+
private readonly ctx;
|
|
66
|
+
/**
|
|
67
|
+
* Scrape resource - Single page scraping
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const job = await client.scrape.create({
|
|
72
|
+
* url: "https://example.com",
|
|
73
|
+
* extractDeal: true
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
readonly scrape: ScrapeResource;
|
|
78
|
+
/**
|
|
79
|
+
* Crawl resource - Website crawling
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const job = await client.crawl.create({
|
|
84
|
+
* url: "https://shop.example.com",
|
|
85
|
+
* maxPages: 100
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // With template
|
|
89
|
+
* const job = await client.crawl.withTemplate("ecommerce", {
|
|
90
|
+
* url: "https://shop.example.com"
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
readonly crawl: CrawlResource;
|
|
95
|
+
/**
|
|
96
|
+
* Extract resource - LLM-based structured data extraction
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const job = await client.extract.create({
|
|
101
|
+
* url: "https://example.com/product",
|
|
102
|
+
* schema: { type: "object", properties: {...} }
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
readonly extract: ExtractResource;
|
|
107
|
+
/**
|
|
108
|
+
* Dork resource - Google Dork searches
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const job = await client.dork.create({
|
|
113
|
+
* query: "discount coupon",
|
|
114
|
+
* site: "amazon.com"
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
readonly dork: DorkResource;
|
|
119
|
+
/**
|
|
120
|
+
* Status resource - Job status management
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const status = await client.status.get(jobId);
|
|
125
|
+
* const deals = await client.status.getDeals(jobId);
|
|
126
|
+
* await client.status.cancel(jobId);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
readonly status: StatusResource;
|
|
130
|
+
/**
|
|
131
|
+
* Data resource - Jobs and deals data access
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const jobs = await client.data.listJobs();
|
|
136
|
+
* const deals = await client.data.listDeals({ minScore: 70 });
|
|
137
|
+
* const stats = await client.data.getStats();
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
readonly data: DataResource;
|
|
141
|
+
/**
|
|
142
|
+
* Webhooks resource - Webhook management
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* await client.webhooks.create({
|
|
147
|
+
* event: "deal.found",
|
|
148
|
+
* url: "https://..."
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
readonly webhooks: WebhooksResource;
|
|
153
|
+
/**
|
|
154
|
+
* Keys resource - API key management
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const newKey = await client.keys.create({
|
|
159
|
+
* name: "Production",
|
|
160
|
+
* scopes: ["scrape:write"]
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
readonly keys: KeysResource;
|
|
165
|
+
/**
|
|
166
|
+
* Account resource - Account info and preferences
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* const account = await client.account.get();
|
|
171
|
+
* await client.account.updatePreferences({
|
|
172
|
+
* minDealScore: 70
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
readonly account: AccountResource;
|
|
177
|
+
/**
|
|
178
|
+
* Create a new DealCrawl client
|
|
179
|
+
*
|
|
180
|
+
* @param config - Client configuration
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* // Minimal config
|
|
185
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
186
|
+
*
|
|
187
|
+
* // Full config
|
|
188
|
+
* const client = new DealCrawl({
|
|
189
|
+
* apiKey: "sk_xxx",
|
|
190
|
+
* baseUrl: "https://api.dealcrawl.dev",
|
|
191
|
+
* timeout: 30000,
|
|
192
|
+
* maxRetries: 3,
|
|
193
|
+
* retryDelay: 1000,
|
|
194
|
+
* onRateLimit: (info) => console.log("Rate limited!", info)
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
constructor(config: DealCrawlConfig);
|
|
199
|
+
/**
|
|
200
|
+
* Wait for a job to complete
|
|
201
|
+
* Polls the status endpoint until the job finishes
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const job = await client.scrape.create({ url: "..." });
|
|
206
|
+
*
|
|
207
|
+
* // Simple wait
|
|
208
|
+
* const result = await client.waitForResult(job.jobId);
|
|
209
|
+
*
|
|
210
|
+
* // With options
|
|
211
|
+
* const result = await client.waitForResult(job.jobId, {
|
|
212
|
+
* pollInterval: 1000,
|
|
213
|
+
* timeout: 60000,
|
|
214
|
+
* onProgress: (status) => console.log(status.progress)
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
waitForResult<T = unknown>(jobId: string, options?: WaitOptions): Promise<WaitResult<T>>;
|
|
219
|
+
/**
|
|
220
|
+
* Wait for multiple jobs to complete
|
|
221
|
+
* Returns when all jobs are done
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const jobs = await Promise.all([
|
|
226
|
+
* client.scrape.create({ url: "url1" }),
|
|
227
|
+
* client.scrape.create({ url: "url2" }),
|
|
228
|
+
* ]);
|
|
229
|
+
*
|
|
230
|
+
* const results = await client.waitForAll(jobs.map(j => j.jobId));
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
waitForAll<T = unknown>(jobIds: string[], options?: WaitOptions): Promise<WaitResult<T>[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Wait for any job to complete
|
|
236
|
+
* Returns as soon as one job finishes
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* const jobIds = ["job1", "job2", "job3"];
|
|
241
|
+
* const firstResult = await client.waitForAny(jobIds);
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
waitForAny<T = unknown>(jobIds: string[], options?: WaitOptions): Promise<WaitResult<T>>;
|
|
245
|
+
/**
|
|
246
|
+
* Scrape a URL and wait for result
|
|
247
|
+
* Combines create and waitForResult
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* const result = await client.scrapeAndWait({
|
|
252
|
+
* url: "https://example.com",
|
|
253
|
+
* extractDeal: true
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
scrapeAndWait<T = unknown>(options: Parameters<ScrapeResource["create"]>[0], waitOptions?: WaitOptions): Promise<WaitResult<T>>;
|
|
258
|
+
/**
|
|
259
|
+
* Crawl a URL and wait for result
|
|
260
|
+
* Combines create and waitForResult
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const result = await client.crawlAndWait({
|
|
265
|
+
* url: "https://shop.example.com",
|
|
266
|
+
* maxPages: 50
|
|
267
|
+
* });
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
crawlAndWait<T = unknown>(options: Parameters<CrawlResource["create"]>[0], waitOptions?: WaitOptions): Promise<WaitResult<T>>;
|
|
271
|
+
/**
|
|
272
|
+
* Extract data and wait for result
|
|
273
|
+
* Combines create and waitForResult
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const result = await client.extractAndWait({
|
|
278
|
+
* url: "https://example.com/product",
|
|
279
|
+
* schema: { type: "object", properties: {...} }
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
extractAndWait<T = unknown>(options: Parameters<ExtractResource["create"]>[0], waitOptions?: WaitOptions): Promise<WaitResult<T>>;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.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OAAO,EAC9B,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EACjD,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CAI1B"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DealCrawl SDK Client
|
|
3
|
+
* Main entry point for the SDK
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { DealCrawl } from "@dealcrawl/sdk";
|
|
8
|
+
*
|
|
9
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
10
|
+
*
|
|
11
|
+
* // Scrape a page
|
|
12
|
+
* const job = await client.scrape.create({
|
|
13
|
+
* url: "https://example.com/product",
|
|
14
|
+
* extractDeal: true
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Wait for result
|
|
18
|
+
* const result = await client.waitForResult(job.jobId);
|
|
19
|
+
* console.log(result);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { DEFAULT_CONFIG } from "./types/config";
|
|
23
|
+
import { waitForResult, waitForAll, waitForAny } from "./utils/polling";
|
|
24
|
+
// Import resources
|
|
25
|
+
import { ScrapeResource } from "./resources/scrape";
|
|
26
|
+
import { CrawlResource } from "./resources/crawl";
|
|
27
|
+
import { ExtractResource } from "./resources/extract";
|
|
28
|
+
import { DorkResource } from "./resources/dork";
|
|
29
|
+
import { StatusResource } from "./resources/status";
|
|
30
|
+
import { DataResource } from "./resources/data";
|
|
31
|
+
import { WebhooksResource } from "./resources/webhooks";
|
|
32
|
+
import { KeysResource } from "./resources/keys";
|
|
33
|
+
import { AccountResource } from "./resources/account";
|
|
34
|
+
/**
|
|
35
|
+
* DealCrawl SDK Client
|
|
36
|
+
*
|
|
37
|
+
* Provides access to all DealCrawl API endpoints through
|
|
38
|
+
* organized resource classes following a Stripe-like pattern.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
43
|
+
*
|
|
44
|
+
* // Core operations
|
|
45
|
+
* await client.scrape.create({ url: "..." });
|
|
46
|
+
* await client.crawl.create({ url: "...", maxPages: 100 });
|
|
47
|
+
* await client.extract.create({ url: "...", schema: {...} });
|
|
48
|
+
* await client.dork.create({ query: "..." });
|
|
49
|
+
*
|
|
50
|
+
* // Status & polling
|
|
51
|
+
* await client.status.get(jobId);
|
|
52
|
+
* await client.waitForResult(jobId);
|
|
53
|
+
*
|
|
54
|
+
* // Data access
|
|
55
|
+
* await client.data.listJobs();
|
|
56
|
+
* await client.data.listDeals();
|
|
57
|
+
*
|
|
58
|
+
* // Management
|
|
59
|
+
* await client.webhooks.create({...});
|
|
60
|
+
* await client.keys.create({...});
|
|
61
|
+
* await client.account.get();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export class DealCrawl {
|
|
65
|
+
/** Internal request context */
|
|
66
|
+
ctx;
|
|
67
|
+
// ============================================
|
|
68
|
+
// RESOURCES
|
|
69
|
+
// ============================================
|
|
70
|
+
/**
|
|
71
|
+
* Scrape resource - Single page scraping
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const job = await client.scrape.create({
|
|
76
|
+
* url: "https://example.com",
|
|
77
|
+
* extractDeal: true
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
scrape;
|
|
82
|
+
/**
|
|
83
|
+
* Crawl resource - Website crawling
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const job = await client.crawl.create({
|
|
88
|
+
* url: "https://shop.example.com",
|
|
89
|
+
* maxPages: 100
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // With template
|
|
93
|
+
* const job = await client.crawl.withTemplate("ecommerce", {
|
|
94
|
+
* url: "https://shop.example.com"
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
crawl;
|
|
99
|
+
/**
|
|
100
|
+
* Extract resource - LLM-based structured data extraction
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const job = await client.extract.create({
|
|
105
|
+
* url: "https://example.com/product",
|
|
106
|
+
* schema: { type: "object", properties: {...} }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
extract;
|
|
111
|
+
/**
|
|
112
|
+
* Dork resource - Google Dork searches
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const job = await client.dork.create({
|
|
117
|
+
* query: "discount coupon",
|
|
118
|
+
* site: "amazon.com"
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
dork;
|
|
123
|
+
/**
|
|
124
|
+
* Status resource - Job status management
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const status = await client.status.get(jobId);
|
|
129
|
+
* const deals = await client.status.getDeals(jobId);
|
|
130
|
+
* await client.status.cancel(jobId);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
status;
|
|
134
|
+
/**
|
|
135
|
+
* Data resource - Jobs and deals data access
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const jobs = await client.data.listJobs();
|
|
140
|
+
* const deals = await client.data.listDeals({ minScore: 70 });
|
|
141
|
+
* const stats = await client.data.getStats();
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
data;
|
|
145
|
+
/**
|
|
146
|
+
* Webhooks resource - Webhook management
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* await client.webhooks.create({
|
|
151
|
+
* event: "deal.found",
|
|
152
|
+
* url: "https://..."
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
webhooks;
|
|
157
|
+
/**
|
|
158
|
+
* Keys resource - API key management
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const newKey = await client.keys.create({
|
|
163
|
+
* name: "Production",
|
|
164
|
+
* scopes: ["scrape:write"]
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
keys;
|
|
169
|
+
/**
|
|
170
|
+
* Account resource - Account info and preferences
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const account = await client.account.get();
|
|
175
|
+
* await client.account.updatePreferences({
|
|
176
|
+
* minDealScore: 70
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
account;
|
|
181
|
+
// ============================================
|
|
182
|
+
// CONSTRUCTOR
|
|
183
|
+
// ============================================
|
|
184
|
+
/**
|
|
185
|
+
* Create a new DealCrawl client
|
|
186
|
+
*
|
|
187
|
+
* @param config - Client configuration
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* // Minimal config
|
|
192
|
+
* const client = new DealCrawl({ apiKey: "sk_xxx" });
|
|
193
|
+
*
|
|
194
|
+
* // Full config
|
|
195
|
+
* const client = new DealCrawl({
|
|
196
|
+
* apiKey: "sk_xxx",
|
|
197
|
+
* baseUrl: "https://api.dealcrawl.dev",
|
|
198
|
+
* timeout: 30000,
|
|
199
|
+
* maxRetries: 3,
|
|
200
|
+
* retryDelay: 1000,
|
|
201
|
+
* onRateLimit: (info) => console.log("Rate limited!", info)
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
constructor(config) {
|
|
206
|
+
if (!config.apiKey) {
|
|
207
|
+
throw new Error("API key is required");
|
|
208
|
+
}
|
|
209
|
+
// Build request context
|
|
210
|
+
this.ctx = {
|
|
211
|
+
apiKey: config.apiKey,
|
|
212
|
+
baseUrl: config.baseUrl ?? DEFAULT_CONFIG.baseUrl,
|
|
213
|
+
timeout: config.timeout ?? DEFAULT_CONFIG.timeout,
|
|
214
|
+
maxRetries: config.maxRetries ?? DEFAULT_CONFIG.maxRetries,
|
|
215
|
+
retryDelay: config.retryDelay ?? DEFAULT_CONFIG.retryDelay,
|
|
216
|
+
onRateLimit: config.onRateLimit,
|
|
217
|
+
};
|
|
218
|
+
// Initialize resources
|
|
219
|
+
this.scrape = new ScrapeResource(this.ctx);
|
|
220
|
+
this.crawl = new CrawlResource(this.ctx);
|
|
221
|
+
this.extract = new ExtractResource(this.ctx);
|
|
222
|
+
this.dork = new DorkResource(this.ctx);
|
|
223
|
+
this.status = new StatusResource(this.ctx);
|
|
224
|
+
this.data = new DataResource(this.ctx);
|
|
225
|
+
this.webhooks = new WebhooksResource(this.ctx);
|
|
226
|
+
this.keys = new KeysResource(this.ctx);
|
|
227
|
+
this.account = new AccountResource(this.ctx);
|
|
228
|
+
}
|
|
229
|
+
// ============================================
|
|
230
|
+
// POLLING METHODS
|
|
231
|
+
// ============================================
|
|
232
|
+
/**
|
|
233
|
+
* Wait for a job to complete
|
|
234
|
+
* Polls the status endpoint until the job finishes
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const job = await client.scrape.create({ url: "..." });
|
|
239
|
+
*
|
|
240
|
+
* // Simple wait
|
|
241
|
+
* const result = await client.waitForResult(job.jobId);
|
|
242
|
+
*
|
|
243
|
+
* // With options
|
|
244
|
+
* const result = await client.waitForResult(job.jobId, {
|
|
245
|
+
* pollInterval: 1000,
|
|
246
|
+
* timeout: 60000,
|
|
247
|
+
* onProgress: (status) => console.log(status.progress)
|
|
248
|
+
* });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async waitForResult(jobId, options) {
|
|
252
|
+
return waitForResult(this.ctx, jobId, options);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Wait for multiple jobs to complete
|
|
256
|
+
* Returns when all jobs are done
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const jobs = await Promise.all([
|
|
261
|
+
* client.scrape.create({ url: "url1" }),
|
|
262
|
+
* client.scrape.create({ url: "url2" }),
|
|
263
|
+
* ]);
|
|
264
|
+
*
|
|
265
|
+
* const results = await client.waitForAll(jobs.map(j => j.jobId));
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
async waitForAll(jobIds, options) {
|
|
269
|
+
return waitForAll(this.ctx, jobIds, options);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Wait for any job to complete
|
|
273
|
+
* Returns as soon as one job finishes
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const jobIds = ["job1", "job2", "job3"];
|
|
278
|
+
* const firstResult = await client.waitForAny(jobIds);
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
async waitForAny(jobIds, options) {
|
|
282
|
+
return waitForAny(this.ctx, jobIds, options);
|
|
283
|
+
}
|
|
284
|
+
// ============================================
|
|
285
|
+
// CONVENIENCE METHODS
|
|
286
|
+
// ============================================
|
|
287
|
+
/**
|
|
288
|
+
* Scrape a URL and wait for result
|
|
289
|
+
* Combines create and waitForResult
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const result = await client.scrapeAndWait({
|
|
294
|
+
* url: "https://example.com",
|
|
295
|
+
* extractDeal: true
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
async scrapeAndWait(options, waitOptions) {
|
|
300
|
+
const job = await this.scrape.create(options);
|
|
301
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Crawl a URL and wait for result
|
|
305
|
+
* Combines create and waitForResult
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* const result = await client.crawlAndWait({
|
|
310
|
+
* url: "https://shop.example.com",
|
|
311
|
+
* maxPages: 50
|
|
312
|
+
* });
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
async crawlAndWait(options, waitOptions) {
|
|
316
|
+
const job = await this.crawl.create(options);
|
|
317
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Extract data and wait for result
|
|
321
|
+
* Combines create and waitForResult
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* const result = await client.extractAndWait({
|
|
326
|
+
* url: "https://example.com/product",
|
|
327
|
+
* schema: { type: "object", properties: {...} }
|
|
328
|
+
* });
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
async extractAndWait(options, waitOptions) {
|
|
332
|
+
const job = await this.extract.create(options);
|
|
333
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAExE,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,c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;;;OASG;IACH,KAAK,CAAC,UAAU,CACd,MAAgB,EAChB,OAAqB;QAErB,OAAO,UAAU,CAAI,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,+CAA+C;IAC/C,sBAAsB;IACtB,+CAA+C;IAE/C;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,aAAa,CACjB,OAAgD,EAChD,WAAyB;QAEzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,aAAa,CAAI,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,YAAY,CAChB,OAA+C,EAC/C,WAAyB;QAEzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAI,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,cAAc,CAClB,OAAiD,EACjD,WAAyB;QAEzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,aAAa,CAAI,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ERROR_CODES, type ErrorCode } from "@dealcrawl/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for DealCrawl SDK
|
|
4
|
+
* Provides structured error handling with error codes
|
|
5
|
+
*/
|
|
6
|
+
export declare class DealCrawlError extends Error {
|
|
7
|
+
/** Error code from ERROR_CODES */
|
|
8
|
+
readonly code: ErrorCode;
|
|
9
|
+
/** HTTP status code from the API response */
|
|
10
|
+
readonly statusCode: number;
|
|
11
|
+
/** Additional error details */
|
|
12
|
+
readonly details?: Record<string, unknown>;
|
|
13
|
+
/** Retry-After header value in seconds (for rate limiting) */
|
|
14
|
+
readonly retryAfter?: number;
|
|
15
|
+
constructor(options: {
|
|
16
|
+
code: ErrorCode;
|
|
17
|
+
message: string;
|
|
18
|
+
statusCode?: number;
|
|
19
|
+
details?: Record<string, unknown>;
|
|
20
|
+
retryAfter?: number;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Check if the error is retryable
|
|
24
|
+
* Rate limits and transient errors are retryable
|
|
25
|
+
*/
|
|
26
|
+
isRetryable(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Check if the error is due to authentication issues
|
|
29
|
+
*/
|
|
30
|
+
isAuthError(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the error is due to rate limiting
|
|
33
|
+
*/
|
|
34
|
+
isRateLimited(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Check if the error is due to quota exceeded
|
|
37
|
+
*/
|
|
38
|
+
isQuotaExceeded(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Convert error to JSON-serializable object
|
|
41
|
+
*/
|
|
42
|
+
toJSON(): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Create a DealCrawlError from an API error response
|
|
45
|
+
*/
|
|
46
|
+
static fromResponse(statusCode: number, body: {
|
|
47
|
+
code?: string;
|
|
48
|
+
message?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
details?: Record<string, unknown>;
|
|
51
|
+
}): DealCrawlError;
|
|
52
|
+
}
|
|
53
|
+
export { ERROR_CODES, type ErrorCode };
|
|
54
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,M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