mcpscraper-sdk 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,411 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ GeneratedMcpToolsClient: () => import_mcpscraper_memory_sdk2.GeneratedMcpToolsClient,
24
+ MCP_TOOL_BINDINGS: () => import_mcpscraper_memory_sdk2.MCP_TOOL_BINDINGS,
25
+ MCP_TOOL_COUNT: () => import_mcpscraper_memory_sdk2.MCP_TOOL_COUNT,
26
+ McpToolError: () => import_mcpscraper_memory_sdk2.McpToolError,
27
+ McpToolsClient: () => import_mcpscraper_memory_sdk2.McpToolsClient,
28
+ ScraperApiError: () => ScraperApiError,
29
+ ScraperClient: () => ScraperClient
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/errors.ts
34
+ function readString(body, key) {
35
+ if (body && typeof body === "object" && key in body) {
36
+ const value = body[key];
37
+ if (typeof value === "string") return value;
38
+ }
39
+ return void 0;
40
+ }
41
+ var ScraperApiError = class extends Error {
42
+ status;
43
+ code;
44
+ body;
45
+ constructor(status, body) {
46
+ super(readString(body, "message") ?? `mcpscraper.dev API request failed with status ${status}`);
47
+ this.name = "ScraperApiError";
48
+ this.status = status;
49
+ this.code = readString(body, "error_code") ?? readString(body, "error");
50
+ this.body = body;
51
+ }
52
+ isInsufficientBalance() {
53
+ return this.code === "insufficient_balance";
54
+ }
55
+ isConcurrencyLimitExceeded() {
56
+ return this.code === "concurrency_limit_exceeded";
57
+ }
58
+ isStructuredError() {
59
+ return typeof readString(this.body, "error_type") === "string";
60
+ }
61
+ };
62
+
63
+ // src/client.ts
64
+ var import_mcpscraper_memory_sdk = require("mcpscraper-memory-sdk");
65
+ var Requester = class {
66
+ constructor(apiKey, baseUrl, fetchImpl) {
67
+ this.apiKey = apiKey;
68
+ this.baseUrl = baseUrl;
69
+ this.fetchImpl = fetchImpl;
70
+ }
71
+ apiKey;
72
+ baseUrl;
73
+ fetchImpl;
74
+ async call(method, path, body, extraHeaders = {}) {
75
+ return (await this.callWithReceipt(method, path, body, extraHeaders)).data;
76
+ }
77
+ async callWithReceipt(method, path, body, extraHeaders = {}) {
78
+ const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
79
+ method,
80
+ headers: {
81
+ "x-api-key": this.apiKey,
82
+ ...body !== void 0 ? { "content-type": "application/json" } : {},
83
+ ...extraHeaders
84
+ },
85
+ body: body !== void 0 ? JSON.stringify(body) : void 0
86
+ });
87
+ const data = await res.json().catch(() => void 0);
88
+ if (!res.ok) throw new ScraperApiError(res.status, data);
89
+ return { data, headers: res.headers };
90
+ }
91
+ async callRaw(method, path) {
92
+ const res = await this.fetchImpl(`${this.baseUrl}${path}`, { method, headers: { "x-api-key": this.apiKey } });
93
+ if (!res.ok) {
94
+ const data = await res.json().catch(() => void 0);
95
+ throw new ScraperApiError(res.status, data);
96
+ }
97
+ return res.arrayBuffer();
98
+ }
99
+ };
100
+ var YoutubeNamespace = class {
101
+ constructor(r) {
102
+ this.r = r;
103
+ }
104
+ r;
105
+ harvest(params) {
106
+ return this.r.call("POST", "/youtube/harvest", params);
107
+ }
108
+ transcribe(params) {
109
+ return this.r.call("POST", "/youtube/transcribe", params);
110
+ }
111
+ };
112
+ var ScreenshotNamespace = class {
113
+ constructor(r) {
114
+ this.r = r;
115
+ }
116
+ r;
117
+ capture(params) {
118
+ return this.r.call("POST", "/screenshot", params);
119
+ }
120
+ };
121
+ var FacebookNamespace = class {
122
+ constructor(r) {
123
+ this.r = r;
124
+ }
125
+ r;
126
+ ad(params) {
127
+ return this.r.call("POST", "/facebook/ad", params);
128
+ }
129
+ pageIntel(params) {
130
+ return this.r.call("POST", "/facebook/page-intel", params);
131
+ }
132
+ adTranscribe(params) {
133
+ return this.r.call("POST", "/facebook/transcribe", params);
134
+ }
135
+ videoTranscribe(params) {
136
+ return this.r.call("POST", "/facebook/video-transcribe", params);
137
+ }
138
+ search(params) {
139
+ return this.r.call("POST", "/facebook/search", params);
140
+ }
141
+ media(params) {
142
+ return this.r.call("POST", "/facebook/media", params);
143
+ }
144
+ };
145
+ var GoogleAdsNamespace = class {
146
+ constructor(r) {
147
+ this.r = r;
148
+ }
149
+ r;
150
+ search(params) {
151
+ return this.r.call("POST", "/google-ads/search", params);
152
+ }
153
+ pageIntel(params) {
154
+ return this.r.call("POST", "/google-ads/page-intel", params);
155
+ }
156
+ transcribe(params) {
157
+ return this.r.call("POST", "/google-ads/transcribe", params);
158
+ }
159
+ };
160
+ var InstagramNamespace = class {
161
+ constructor(r) {
162
+ this.r = r;
163
+ }
164
+ r;
165
+ profileContent(params) {
166
+ return this.r.call("POST", "/instagram/profile-content", params);
167
+ }
168
+ mediaDownload(params) {
169
+ return this.r.call("POST", "/instagram/media-download", params);
170
+ }
171
+ };
172
+ var RedditNamespace = class {
173
+ constructor(r) {
174
+ this.r = r;
175
+ }
176
+ r;
177
+ thread(params) {
178
+ return this.r.call("POST", "/reddit/thread", params);
179
+ }
180
+ };
181
+ var VideoNamespace = class {
182
+ constructor(r) {
183
+ this.r = r;
184
+ }
185
+ r;
186
+ analyze(params) {
187
+ return this.r.call("POST", "/video/analyze", params);
188
+ }
189
+ status(params) {
190
+ return this.r.call("POST", "/video/status", params);
191
+ }
192
+ };
193
+ var MapsNamespace = class {
194
+ constructor(r) {
195
+ this.r = r;
196
+ }
197
+ r;
198
+ search(params) {
199
+ return this.r.call("POST", "/maps/search", params);
200
+ }
201
+ place(params) {
202
+ return this.r.call("POST", "/maps/place", params);
203
+ }
204
+ };
205
+ var DirectoryNamespace = class {
206
+ constructor(r) {
207
+ this.r = r;
208
+ }
209
+ r;
210
+ run(params) {
211
+ return this.r.call("POST", "/directory/run", params);
212
+ }
213
+ };
214
+ var SerpIntelligenceNamespace = class {
215
+ constructor(r) {
216
+ this.r = r;
217
+ }
218
+ r;
219
+ capture(params, options = {}) {
220
+ return this.r.call(
221
+ "POST",
222
+ "/serp-intelligence/capture",
223
+ params,
224
+ options.idempotencyKey === void 0 ? {} : { "Idempotency-Key": options.idempotencyKey }
225
+ );
226
+ }
227
+ async captureWithReceipt(params, options = {}) {
228
+ const result = await this.r.callWithReceipt(
229
+ "POST",
230
+ "/serp-intelligence/capture",
231
+ params,
232
+ options.idempotencyKey === void 0 ? {} : { "Idempotency-Key": options.idempotencyKey }
233
+ );
234
+ return {
235
+ data: result.data,
236
+ idempotencyKey: result.headers.get("Idempotency-Key")
237
+ };
238
+ }
239
+ pageSnapshots(params) {
240
+ return this.r.call("POST", "/serp-intelligence/page-snapshots", params);
241
+ }
242
+ };
243
+ var WorkflowsNamespace = class {
244
+ constructor(r) {
245
+ this.r = r;
246
+ }
247
+ r;
248
+ listDefinitions() {
249
+ return this.r.call("GET", "/workflows/definitions");
250
+ }
251
+ run(params) {
252
+ return this.r.call("POST", "/workflows/run", params);
253
+ }
254
+ advanceStep(id) {
255
+ return this.r.call("POST", `/workflows/runs/${encodeURIComponent(id)}/step`);
256
+ }
257
+ listRuns() {
258
+ return this.r.call("GET", "/workflows/runs");
259
+ }
260
+ getRun(id) {
261
+ return this.r.call("GET", `/workflows/runs/${encodeURIComponent(id)}`);
262
+ }
263
+ getRunArtifact(id, artifactId) {
264
+ return this.r.callRaw(
265
+ "GET",
266
+ `/workflows/runs/${encodeURIComponent(id)}/artifacts/${encodeURIComponent(artifactId)}`
267
+ );
268
+ }
269
+ createSchedule(params) {
270
+ return this.r.call("POST", "/workflows/schedules", params);
271
+ }
272
+ listSchedules() {
273
+ return this.r.call("GET", "/workflows/schedules");
274
+ }
275
+ patchSchedule(id, params) {
276
+ return this.r.call("PATCH", `/workflows/schedules/${encodeURIComponent(id)}`, params);
277
+ }
278
+ deleteSchedule(id) {
279
+ return this.r.call("DELETE", `/workflows/schedules/${encodeURIComponent(id)}`);
280
+ }
281
+ runScheduleNow(id) {
282
+ return this.r.call("POST", `/workflows/schedules/${encodeURIComponent(id)}/run`);
283
+ }
284
+ };
285
+ var MemoryTools = class {
286
+ access;
287
+ capture;
288
+ channels;
289
+ facts;
290
+ graph;
291
+ library;
292
+ memory;
293
+ recall;
294
+ schedule;
295
+ storage;
296
+ tables;
297
+ tags;
298
+ vaults;
299
+ video;
300
+ webhooks;
301
+ constructor(callTool) {
302
+ this.access = new import_mcpscraper_memory_sdk.AccessNamespace(callTool);
303
+ this.capture = new import_mcpscraper_memory_sdk.CaptureNamespace(callTool);
304
+ this.channels = new import_mcpscraper_memory_sdk.ChannelsNamespace(callTool);
305
+ this.facts = new import_mcpscraper_memory_sdk.FactsNamespace(callTool);
306
+ this.graph = new import_mcpscraper_memory_sdk.GraphNamespace(callTool);
307
+ this.library = new import_mcpscraper_memory_sdk.LibraryNamespace(callTool);
308
+ this.memory = new import_mcpscraper_memory_sdk.MemoryNamespace(callTool);
309
+ this.recall = new import_mcpscraper_memory_sdk.RecallNamespace(callTool);
310
+ this.schedule = new import_mcpscraper_memory_sdk.ScheduleNamespace(callTool);
311
+ this.storage = new import_mcpscraper_memory_sdk.StorageNamespace(callTool);
312
+ this.tables = new import_mcpscraper_memory_sdk.TablesNamespace(callTool);
313
+ this.tags = new import_mcpscraper_memory_sdk.TagsNamespace(callTool);
314
+ this.vaults = new import_mcpscraper_memory_sdk.VaultsNamespace(callTool);
315
+ this.video = new import_mcpscraper_memory_sdk.VideoNamespace(callTool);
316
+ this.webhooks = new import_mcpscraper_memory_sdk.WebhooksNamespace(callTool);
317
+ }
318
+ };
319
+ var ScraperClient = class {
320
+ r;
321
+ youtube;
322
+ screenshot;
323
+ facebook;
324
+ googleAds;
325
+ instagram;
326
+ reddit;
327
+ video;
328
+ maps;
329
+ directory;
330
+ serpIntelligence;
331
+ workflows;
332
+ memoryTools;
333
+ tools;
334
+ constructor(options) {
335
+ this.r = new Requester(options.apiKey, options.baseUrl ?? "https://mcpscraper.dev", options.fetch ?? globalThis.fetch);
336
+ this.youtube = new YoutubeNamespace(this.r);
337
+ this.screenshot = new ScreenshotNamespace(this.r);
338
+ this.facebook = new FacebookNamespace(this.r);
339
+ this.googleAds = new GoogleAdsNamespace(this.r);
340
+ this.instagram = new InstagramNamespace(this.r);
341
+ this.reddit = new RedditNamespace(this.r);
342
+ this.video = new VideoNamespace(this.r);
343
+ this.maps = new MapsNamespace(this.r);
344
+ this.directory = new DirectoryNamespace(this.r);
345
+ this.serpIntelligence = new SerpIntelligenceNamespace(this.r);
346
+ this.workflows = new WorkflowsNamespace(this.r);
347
+ this.memoryTools = new MemoryTools(this.callMemoryTool.bind(this));
348
+ this.tools = new import_mcpscraper_memory_sdk.McpToolsClient({
349
+ apiKey: options.apiKey,
350
+ baseUrl: options.baseUrl ?? "https://mcpscraper.dev",
351
+ fetch: options.fetch
352
+ });
353
+ }
354
+ async callMemoryTool(toolName, args) {
355
+ const result = await this.r.call("POST", "/memory/mcp-call", {
356
+ toolName,
357
+ args: args ?? {}
358
+ });
359
+ if (result && typeof result === "object" && result.ok === false) {
360
+ const failure = result;
361
+ throw new ScraperApiError(200, { message: failure.error, ...failure });
362
+ }
363
+ return result;
364
+ }
365
+ searchSerp(params) {
366
+ return this.r.call("POST", "/harvest/sync", { ...params, serpOnly: true });
367
+ }
368
+ harvestPaa(params) {
369
+ return this.r.call("POST", "/harvest/sync", params);
370
+ }
371
+ extractUrl(params) {
372
+ return this.r.call("POST", "/extract-url", params);
373
+ }
374
+ mapSiteUrls(params) {
375
+ return this.r.call("POST", "/map-urls", params);
376
+ }
377
+ extractSite(params) {
378
+ return this.r.call("POST", "/extract-site", params);
379
+ }
380
+ auditSite(params) {
381
+ return this.extractSite(params);
382
+ }
383
+ getExtractSiteStatus(id) {
384
+ return this.r.call("GET", `/extract-site/status/${encodeURIComponent(id)}`);
385
+ }
386
+ listJobs() {
387
+ return this.r.call("GET", "/jobs");
388
+ }
389
+ getJob(id) {
390
+ return this.r.call("GET", `/jobs/${encodeURIComponent(id)}`);
391
+ }
392
+ getHistory() {
393
+ return this.r.call("GET", "/history");
394
+ }
395
+ getLedger() {
396
+ return this.r.call("GET", "/ledger");
397
+ }
398
+ };
399
+
400
+ // src/index.ts
401
+ var import_mcpscraper_memory_sdk2 = require("mcpscraper-memory-sdk");
402
+ // Annotate the CommonJS export names for ESM import in node:
403
+ 0 && (module.exports = {
404
+ GeneratedMcpToolsClient,
405
+ MCP_TOOL_BINDINGS,
406
+ MCP_TOOL_COUNT,
407
+ McpToolError,
408
+ McpToolsClient,
409
+ ScraperApiError,
410
+ ScraperClient
411
+ });