mcp-scraper 0.88.2 → 0.89.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +41 -2
  2. package/README.md +6 -3
  3. package/dist/analytics-repository-J25XR5E7.js +1 -0
  4. package/dist/bin/api-server.js +2 -41
  5. package/dist/bin/mcp-scraper-cli.js +39 -756
  6. package/dist/bin/mcp-scraper-core.js +1 -60
  7. package/dist/bin/mcp-scraper-install.js +2 -25
  8. package/dist/bin/mcp-stdio-server.js +1 -19
  9. package/dist/bin/paa-harvest.js +1 -41
  10. package/dist/chunk-3GP5CYZX.js +1 -0
  11. package/dist/chunk-4FROKQJN.js +1 -0
  12. package/dist/chunk-57AHYL2O.js +20 -0
  13. package/dist/chunk-5H3MCTTP.js +1 -0
  14. package/dist/chunk-63T4W2LX.js +1271 -0
  15. package/dist/chunk-645LQBE7.js +2595 -0
  16. package/dist/chunk-6QO4F2KC.js +21710 -0
  17. package/dist/chunk-CCYWSJNG.js +16 -0
  18. package/dist/chunk-D6IQJP64.js +84 -0
  19. package/dist/chunk-DGBLGFNJ.js +182 -0
  20. package/dist/chunk-FFPD2DOF.js +59 -0
  21. package/dist/chunk-FXEWHK54.js +1 -0
  22. package/dist/chunk-HE45FFBU.js +1 -0
  23. package/dist/chunk-HUV2WTRW.js +1 -0
  24. package/dist/chunk-IJ2AO7AO.js +102 -0
  25. package/dist/chunk-KJQXUZ4Y.js +4 -0
  26. package/dist/chunk-MEM4D2QN.js +1280 -0
  27. package/dist/chunk-MZN4U5BL.js +1 -0
  28. package/dist/chunk-PRWZNHQB.js +1 -0
  29. package/dist/chunk-QPWPR5XG.js +10 -0
  30. package/dist/chunk-RYNHNEF3.js +73 -0
  31. package/dist/chunk-TMB56NCA.js +1 -0
  32. package/dist/chunk-W2BVJ7S2.js +13 -0
  33. package/dist/chunk-WO3N5FH2.js +5 -0
  34. package/dist/chunk-XLWNEVUZ.js +27 -0
  35. package/dist/chunk-YQZGZBB4.js +1 -0
  36. package/dist/chunk-YUPLOOTB.js +4 -0
  37. package/dist/chunk-ZHORX44A.js +100 -0
  38. package/dist/db-JJWJLAVQ.js +1 -0
  39. package/dist/extract-bundle-TTSEGWYF.js +26 -0
  40. package/dist/gmail-service-34PIJRLK.js +1 -0
  41. package/dist/index.cjs +21838 -6034
  42. package/dist/index.js +18 -315
  43. package/dist/lead-list-enrichment-repository-VJBBMBCG.js +1 -0
  44. package/dist/location-data-repository-W3LPT6G3.js +1 -0
  45. package/dist/server-UEY5YQL6.js +7329 -0
  46. package/dist/site-extract-repository-7W5ZUNPR.js +1 -0
  47. package/dist/worker-ZOTOKG56.js +1 -0
  48. package/package.json +11 -4
  49. package/dist/analytics-repository-GGJJCVVP.js +0 -194
  50. package/dist/chunk-4QMUF6XM.js +0 -1013
  51. package/dist/chunk-6HAV7LCE.js +0 -265
  52. package/dist/chunk-ABF2CGOZ.js +0 -113
  53. package/dist/chunk-C5Z4OFKW.js +0 -404
  54. package/dist/chunk-DNM65UCK.js +0 -299
  55. package/dist/chunk-EQGTEHLZ.js +0 -592
  56. package/dist/chunk-F5GQJWZU.js +0 -732
  57. package/dist/chunk-GGZEC22A.js +0 -215
  58. package/dist/chunk-GXBZXWXB.js +0 -184
  59. package/dist/chunk-IHXAXYIS.js +0 -843
  60. package/dist/chunk-K3Z5AQYE.js +0 -683
  61. package/dist/chunk-K45K75OF.js +0 -6
  62. package/dist/chunk-LFW2FRPJ.js +0 -224
  63. package/dist/chunk-MZDNZQWT.js +0 -2078
  64. package/dist/chunk-NVUKO5NN.js +0 -256
  65. package/dist/chunk-OM7HVEJ3.js +0 -26
  66. package/dist/chunk-OPQIGAFB.js +0 -286
  67. package/dist/chunk-OZJMVCDK.js +0 -16
  68. package/dist/chunk-P7FWOMU7.js +0 -505
  69. package/dist/chunk-PGJQDMC2.js +0 -383
  70. package/dist/chunk-PKZS6SHW.js +0 -33139
  71. package/dist/chunk-RJ7JVYKU.js +0 -68
  72. package/dist/chunk-S24LFPL7.js +0 -5262
  73. package/dist/chunk-T3MZISOF.js +0 -240
  74. package/dist/chunk-UZPTGUDV.js +0 -1915
  75. package/dist/chunk-X623GTBV.js +0 -8290
  76. package/dist/chunk-YXNDOQXN.js +0 -4018
  77. package/dist/db-Z34LPZNR.js +0 -284
  78. package/dist/extract-bundle-565SBZCR.js +0 -1003
  79. package/dist/gmail-service-E6ALS7JG.js +0 -25
  80. package/dist/lead-list-enrichment-repository-36RPVV6N.js +0 -67
  81. package/dist/location-data-repository-WPRG62GE.js +0 -34
  82. package/dist/server-SQZ3A7SY.js +0 -86606
  83. package/dist/site-extract-repository-VYFZASPU.js +0 -69
  84. package/dist/worker-LDCAULWL.js +0 -146
@@ -1,69 +0,0 @@
1
- import {
2
- XRAY_ENTITLED_EXTRACT_BILLING_CLASS,
3
- abandonExtractSettlement,
4
- claimFailedExtractJobForRefinalize,
5
- completeExtractJob,
6
- countSuccessfulPages,
7
- createExtractJob,
8
- createOrGetExtractJob,
9
- extractJobLimitInfo,
10
- failExtractJob,
11
- failStaleRunningExtractJob,
12
- failUnfundedExtractJob,
13
- finalizeXRayEntitledExtractJobCharge,
14
- finishExtractJob,
15
- getExtractJob,
16
- getExtractJobByIdempotencyKey,
17
- getExtractedImageLinks,
18
- getExtractedPages,
19
- getExtractedUrls,
20
- listExtractJobs,
21
- listExtractPages,
22
- listFundedPendingExtractJobs,
23
- listStaleRunningExtractJobs,
24
- listUnsettledExtractJobs,
25
- markExtractJobDispatchAttempt,
26
- recordExtractJobDispatchFailure,
27
- recordExtractSettlementFailure,
28
- saveExtractPages,
29
- setExtractJobPublicError,
30
- setExtractJobTotal,
31
- settleExtractJob,
32
- terminalExtractJobStatus
33
- } from "./chunk-IHXAXYIS.js";
34
- import "./chunk-DNM65UCK.js";
35
- import "./chunk-4QMUF6XM.js";
36
- import "./chunk-YXNDOQXN.js";
37
- export {
38
- XRAY_ENTITLED_EXTRACT_BILLING_CLASS,
39
- abandonExtractSettlement,
40
- claimFailedExtractJobForRefinalize,
41
- completeExtractJob,
42
- countSuccessfulPages,
43
- createExtractJob,
44
- createOrGetExtractJob,
45
- extractJobLimitInfo,
46
- failExtractJob,
47
- failStaleRunningExtractJob,
48
- failUnfundedExtractJob,
49
- finalizeXRayEntitledExtractJobCharge,
50
- finishExtractJob,
51
- getExtractJob,
52
- getExtractJobByIdempotencyKey,
53
- getExtractedImageLinks,
54
- getExtractedPages,
55
- getExtractedUrls,
56
- listExtractJobs,
57
- listExtractPages,
58
- listFundedPendingExtractJobs,
59
- listStaleRunningExtractJobs,
60
- listUnsettledExtractJobs,
61
- markExtractJobDispatchAttempt,
62
- recordExtractJobDispatchFailure,
63
- recordExtractSettlementFailure,
64
- saveExtractPages,
65
- setExtractJobPublicError,
66
- setExtractJobTotal,
67
- settleExtractJob,
68
- terminalExtractJobStatus
69
- };
@@ -1,146 +0,0 @@
1
- import {
2
- classifyHarvestProblem,
3
- createHarvestAttemptRecorder,
4
- deliverWebhook,
5
- harvestProblemEnvelope,
6
- harvestProblemResponse,
7
- serializeHarvestProblem
8
- } from "./chunk-NVUKO5NN.js";
9
- import "./chunk-OZJMVCDK.js";
10
- import {
11
- harvest
12
- } from "./chunk-S24LFPL7.js";
13
- import {
14
- sanitizeAttempts,
15
- sanitizeHarvestResult
16
- } from "./chunk-6HAV7LCE.js";
17
- import {
18
- MC_COSTS,
19
- serpActualCostMc
20
- } from "./chunk-4QMUF6XM.js";
21
- import {
22
- browserServiceApiKey
23
- } from "./chunk-OM7HVEJ3.js";
24
- import {
25
- runWithCostContext
26
- } from "./chunk-OPQIGAFB.js";
27
- import "./chunk-GXBZXWXB.js";
28
- import {
29
- claimPendingJob,
30
- completeJob,
31
- creditMc,
32
- debitMc,
33
- failJob,
34
- listHarvestAttempts
35
- } from "./chunk-YXNDOQXN.js";
36
-
37
- // src/api/worker.ts
38
- var MAX_CONCURRENT = 2;
39
- var running = 0;
40
- function countPaaQuestions(result) {
41
- if (!result || typeof result !== "object") return 0;
42
- const value = result;
43
- if (typeof value.totalQuestions === "number") return value.totalQuestions;
44
- return Array.isArray(value.flat) ? value.flat.length : 0;
45
- }
46
- function paaCostForQuestionCount(questionCount) {
47
- return MC_COSTS.paa_base + Math.max(1, questionCount) * MC_COSTS.paa;
48
- }
49
- async function processJob(job) {
50
- running++;
51
- try {
52
- const opts = typeof job.options === "string" ? JSON.parse(job.options) : job.options;
53
- const headlessSentOut = { value: null };
54
- const result = await runWithCostContext(
55
- { op: opts.serpOnly ? "serp" : "paa", userId: Number(job.user_id), headlessSentOut },
56
- () => harvest({
57
- ...opts,
58
- kernelApiKey: browserServiceApiKey(),
59
- headless: true,
60
- format: "json",
61
- outputDir: "/tmp/paa-output-api",
62
- onAttemptEvent: createHarvestAttemptRecorder(job.id, job.user_id)
63
- })
64
- );
65
- await completeJob(job.id, result);
66
- const attempts = await listHarvestAttempts(job.id, job.user_id);
67
- if (!opts.serpOnly && typeof opts.billingHoldMc === "number") {
68
- const actualCost = paaCostForQuestionCount(countPaaQuestions(result));
69
- const diff = opts.billingHoldMc - actualCost;
70
- if (diff > 0) await creditMc(job.user_id, diff, "paa_refund", "overestimate refund");
71
- else if (diff < 0) await debitMc(job.user_id, -diff, "paa", opts.query ?? job.query);
72
- } else if (opts.serpOnly && typeof opts.billingHoldMc === "number") {
73
- const actualCost = serpActualCostMc(headlessSentOut.value);
74
- const diff = opts.billingHoldMc - actualCost;
75
- if (diff > 0) await creditMc(job.user_id, diff, "serp_refund", "headless-mode pricing settle");
76
- else if (diff < 0) await debitMc(job.user_id, -diff, "serp", opts.query ?? job.query);
77
- }
78
- if (job.callback_url) {
79
- await deliverWebhook(job.callback_url, {
80
- job_id: job.id,
81
- status: "done",
82
- result: sanitizeHarvestResult(result),
83
- attempts: sanitizeAttempts(attempts)
84
- });
85
- }
86
- } catch (err) {
87
- console.error("[harvest/worker] failed", {
88
- jobId: job.id,
89
- error: err instanceof Error ? err.message : String(err)
90
- });
91
- const problem = classifyHarvestProblem(err);
92
- const failedOptions = typeof job.options === "string" ? JSON.parse(job.options) : job.options;
93
- const hasHold = typeof failedOptions.billingHoldMc === "number" && failedOptions.billingHoldMc > 0;
94
- await failJob(job.id, serializeHarvestProblem(problem), harvestProblemEnvelope(problem, {
95
- chargeStatus: hasHold ? "refund_pending" : "not_charged"
96
- }));
97
- const attempts = await listHarvestAttempts(job.id, job.user_id);
98
- try {
99
- if (hasHold) {
100
- await creditMc(job.user_id, failedOptions.billingHoldMc, "refund", "failed call");
101
- await failJob(job.id, serializeHarvestProblem(problem), harvestProblemEnvelope(problem, { chargeStatus: "refunded" }));
102
- }
103
- } catch {
104
- }
105
- if (job.callback_url) {
106
- await deliverWebhook(job.callback_url, {
107
- job_id: job.id,
108
- status: "failed",
109
- ...harvestProblemResponse(problem),
110
- attempts: sanitizeAttempts(attempts)
111
- });
112
- }
113
- } finally {
114
- running--;
115
- }
116
- }
117
- async function tickOnce() {
118
- const job = await claimPendingJob();
119
- if (!job) return { claimed: false };
120
- const startedAt = Date.now();
121
- await processJob(job);
122
- return { claimed: true, jobId: job.id, completed: true, durationMs: Date.now() - startedAt };
123
- }
124
- async function drainQueue(budget) {
125
- const results = [];
126
- for (let i = 0; i < budget.maxJobs; i++) {
127
- if (Date.now() >= budget.deadlineMs) break;
128
- const r = await tickOnce();
129
- results.push(r);
130
- if (!r.claimed) break;
131
- }
132
- return results;
133
- }
134
- function startWorker() {
135
- setInterval(async () => {
136
- if (running >= MAX_CONCURRENT) return;
137
- const job = await claimPendingJob();
138
- if (job) void processJob(job);
139
- }, 2e3);
140
- console.log(`[worker] started \u2014 polling every 2s, max ${MAX_CONCURRENT} concurrent`);
141
- }
142
- export {
143
- drainQueue,
144
- startWorker,
145
- tickOnce
146
- };