mcp-scraper 0.88.2 → 0.89.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 (87) hide show
  1. package/CHANGELOG.md +36 -15
  2. package/README.md +6 -5
  3. package/THIRD_PARTY_NOTICES.html +203 -0
  4. package/dist/analytics-repository-2BMT5JNE.js +1 -0
  5. package/dist/bin/api-server.js +2 -41
  6. package/dist/bin/mcp-scraper-cli.js +39 -756
  7. package/dist/bin/mcp-scraper-core.js +1 -60
  8. package/dist/bin/mcp-scraper-install.js +2 -25
  9. package/dist/bin/mcp-stdio-server.js +1 -19
  10. package/dist/bin/paa-harvest.js +1 -41
  11. package/dist/chunk-3GP5CYZX.js +1 -0
  12. package/dist/chunk-4AI7DOS7.js +59 -0
  13. package/dist/chunk-4FROKQJN.js +1 -0
  14. package/dist/chunk-7YGVI5J4.js +21710 -0
  15. package/dist/chunk-CCYWSJNG.js +16 -0
  16. package/dist/chunk-CFI6CXIV.js +182 -0
  17. package/dist/chunk-E2WRWV3A.js +1 -0
  18. package/dist/chunk-GMWKPIYX.js +1172 -0
  19. package/dist/chunk-HDPYG3XV.js +102 -0
  20. package/dist/chunk-HE45FFBU.js +1 -0
  21. package/dist/chunk-HUV2WTRW.js +1 -0
  22. package/dist/chunk-KJQXUZ4Y.js +4 -0
  23. package/dist/chunk-L4CGLFPU.js +4 -0
  24. package/dist/chunk-M22MM4N4.js +84 -0
  25. package/dist/chunk-MASR22K4.js +73 -0
  26. package/dist/chunk-MZN4U5BL.js +1 -0
  27. package/dist/chunk-PUHFVA7P.js +1280 -0
  28. package/dist/chunk-QPWPR5XG.js +10 -0
  29. package/dist/chunk-TMB56NCA.js +1 -0
  30. package/dist/chunk-TXENITMS.js +20 -0
  31. package/dist/chunk-W2BVJ7S2.js +13 -0
  32. package/dist/chunk-WO3N5FH2.js +5 -0
  33. package/dist/chunk-WSCGYRWA.js +2595 -0
  34. package/dist/chunk-X54CQLK2.js +1 -0
  35. package/dist/chunk-XLWNEVUZ.js +27 -0
  36. package/dist/chunk-XPZVJIZ2.js +100 -0
  37. package/dist/chunk-YQZGZBB4.js +1 -0
  38. package/dist/chunk-Z2QGQJS2.js +1 -0
  39. package/dist/db-F2MX63GI.js +1 -0
  40. package/dist/extract-bundle-SNUIHM3J.js +26 -0
  41. package/dist/gmail-service-BZ3H75XC.js +1 -0
  42. package/dist/index.cjs +21750 -6045
  43. package/dist/index.d.cts +14 -14
  44. package/dist/index.d.ts +14 -14
  45. package/dist/index.js +18 -315
  46. package/dist/lead-list-enrichment-repository-S2H3U7T7.js +1 -0
  47. package/dist/location-data-repository-OTWHWMV6.js +1 -0
  48. package/dist/server-RFR2A5UJ.js +7303 -0
  49. package/dist/site-extract-repository-SE776XDC.js +1 -0
  50. package/dist/worker-XUDSM3AL.js +1 -0
  51. package/package.json +17 -124
  52. package/dist/analytics-repository-GGJJCVVP.js +0 -194
  53. package/dist/chunk-4QMUF6XM.js +0 -1013
  54. package/dist/chunk-6HAV7LCE.js +0 -265
  55. package/dist/chunk-ABF2CGOZ.js +0 -113
  56. package/dist/chunk-C5Z4OFKW.js +0 -404
  57. package/dist/chunk-DNM65UCK.js +0 -299
  58. package/dist/chunk-EQGTEHLZ.js +0 -592
  59. package/dist/chunk-F5GQJWZU.js +0 -732
  60. package/dist/chunk-GGZEC22A.js +0 -215
  61. package/dist/chunk-GXBZXWXB.js +0 -184
  62. package/dist/chunk-IHXAXYIS.js +0 -843
  63. package/dist/chunk-K3Z5AQYE.js +0 -683
  64. package/dist/chunk-K45K75OF.js +0 -6
  65. package/dist/chunk-LFW2FRPJ.js +0 -224
  66. package/dist/chunk-MZDNZQWT.js +0 -2078
  67. package/dist/chunk-NVUKO5NN.js +0 -256
  68. package/dist/chunk-OM7HVEJ3.js +0 -26
  69. package/dist/chunk-OPQIGAFB.js +0 -286
  70. package/dist/chunk-OZJMVCDK.js +0 -16
  71. package/dist/chunk-P7FWOMU7.js +0 -505
  72. package/dist/chunk-PGJQDMC2.js +0 -383
  73. package/dist/chunk-PKZS6SHW.js +0 -33139
  74. package/dist/chunk-RJ7JVYKU.js +0 -68
  75. package/dist/chunk-S24LFPL7.js +0 -5262
  76. package/dist/chunk-T3MZISOF.js +0 -240
  77. package/dist/chunk-UZPTGUDV.js +0 -1915
  78. package/dist/chunk-X623GTBV.js +0 -8290
  79. package/dist/chunk-YXNDOQXN.js +0 -4018
  80. package/dist/db-Z34LPZNR.js +0 -284
  81. package/dist/extract-bundle-565SBZCR.js +0 -1003
  82. package/dist/gmail-service-E6ALS7JG.js +0 -25
  83. package/dist/lead-list-enrichment-repository-36RPVV6N.js +0 -67
  84. package/dist/location-data-repository-WPRG62GE.js +0 -34
  85. package/dist/server-SQZ3A7SY.js +0 -86606
  86. package/dist/site-extract-repository-VYFZASPU.js +0 -69
  87. package/dist/worker-LDCAULWL.js +0 -146
@@ -1,299 +0,0 @@
1
- // src/api/private-artifacts.ts
2
- import { createHash } from "crypto";
3
- import { mkdir, readFile, writeFile } from "fs/promises";
4
- import { createWriteStream } from "fs";
5
- import { homedir } from "os";
6
- import { dirname, join } from "path";
7
- import { Transform } from "stream";
8
- import { pipeline } from "stream/promises";
9
- var DURABLE_ARTIFACT_EXPIRES_AT = "9999-12-31T23:59:59.999Z";
10
- function hostedByEnvironment() {
11
- return process.env.VERCEL === "1" || process.env.NODE_ENV === "production";
12
- }
13
- function policyHosted(policy) {
14
- return policy.hosted ?? hostedByEnvironment();
15
- }
16
- function policyLocalBaseDir(policy) {
17
- return policy.localBaseDir?.trim() || process.env.MCP_SCRAPER_OUTPUT_DIR?.trim() || join(homedir(), "Downloads", "mcp-scraper");
18
- }
19
- function normalizedPrefix(prefix) {
20
- const normalized = prefix.replace(/^\/+/, "").replace(/\/+$/, "");
21
- if (!normalized || normalized.includes("..") || !/^[a-zA-Z0-9/_-]+$/.test(normalized)) {
22
- throw new Error("private artifact prefix is invalid");
23
- }
24
- return `${normalized}/`;
25
- }
26
- function requiredSafeSegment(value, field) {
27
- const trimmed = value.trim();
28
- if (!/^[a-zA-Z0-9_-]{1,160}$/.test(trimmed)) {
29
- throw new Error(`${field} must contain only letters, numbers, underscores, or hyphens`);
30
- }
31
- return trimmed;
32
- }
33
- function requiredSafeArtifactKey(value) {
34
- const trimmed = value.trim();
35
- if (!/^[a-zA-Z0-9_.-]{1,200}$/.test(trimmed) || trimmed === "." || trimmed === "..") {
36
- throw new Error("private artifact key is invalid");
37
- }
38
- return trimmed;
39
- }
40
- function safeDownloadFilename(value) {
41
- const normalized = value.trim().replace(/[^a-zA-Z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "");
42
- return (normalized || "artifact").slice(0, 160);
43
- }
44
- function createdAtMs(value) {
45
- const normalized = typeof value === "string" && /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(value) ? `${value.replace(" ", "T")}Z` : value;
46
- const timestamp = normalized instanceof Date ? normalized.getTime() : typeof normalized === "number" ? normalized : new Date(normalized).getTime();
47
- if (!Number.isSafeInteger(timestamp) || timestamp <= 0) throw new Error("private artifact createdAt is invalid");
48
- return timestamp;
49
- }
50
- function validatePolicy(policy) {
51
- if (policy.artifactTtlMs !== null && (!Number.isSafeInteger(policy.artifactTtlMs) || policy.artifactTtlMs <= 0)) {
52
- throw new Error("private artifact TTL must be a positive integer");
53
- }
54
- if (!Number.isSafeInteger(policy.downloadTtlMs) || policy.downloadTtlMs <= 0) {
55
- throw new Error("private artifact download TTL must be a positive integer");
56
- }
57
- return {
58
- prefix: normalizedPrefix(policy.prefix),
59
- artifactTtlMs: policy.artifactTtlMs,
60
- downloadTtlMs: policy.downloadTtlMs
61
- };
62
- }
63
- function artifactTimestamp(artifactId, prefix) {
64
- const normalized = normalizedPrefix(prefix);
65
- if (!artifactId.startsWith(normalized)) return null;
66
- const filename = artifactId.split("/").at(-1) ?? "";
67
- const match = filename.match(/^(\d{13})-/);
68
- if (!match) return null;
69
- const timestamp = Number(match[1]);
70
- return Number.isSafeInteger(timestamp) && timestamp > 0 ? timestamp : null;
71
- }
72
- function privateArtifactOwnerId(artifactId, prefix) {
73
- const normalized = normalizedPrefix(prefix);
74
- if (!artifactId.startsWith(normalized) || artifactId.includes("..")) return null;
75
- const rest = artifactId.slice(normalized.length);
76
- const segments = rest.split("/");
77
- if (segments.length < 2) return null;
78
- try {
79
- return requiredSafeSegment(segments[0] ?? "", "ownerId");
80
- } catch {
81
- return null;
82
- }
83
- }
84
- function privateArtifactExpiresAt(artifactId, policy) {
85
- const validated = validatePolicy(policy);
86
- if (privateArtifactOwnerId(artifactId, validated.prefix) === null) return null;
87
- if (validated.artifactTtlMs === null) return null;
88
- const timestamp = artifactTimestamp(artifactId, validated.prefix);
89
- return timestamp === null ? null : new Date(timestamp + validated.artifactTtlMs);
90
- }
91
- async function signedDownloadUrl(pathname, expiresAt, policy) {
92
- const token = policy.token?.trim();
93
- if (!token) return null;
94
- const validUntil = expiresAt ? Math.min(Date.now() + policy.downloadTtlMs, expiresAt.getTime()) : Date.now() + policy.downloadTtlMs;
95
- if (validUntil <= Date.now()) return null;
96
- const { issueSignedToken, presignUrl } = await import("@vercel/blob");
97
- const signedToken = await issueSignedToken({
98
- token,
99
- pathname,
100
- operations: ["get"],
101
- validUntil
102
- });
103
- const { presignedUrl } = await presignUrl(signedToken, {
104
- access: "private",
105
- operation: "get",
106
- pathname,
107
- validUntil
108
- });
109
- return { url: presignedUrl, expiresAt: new Date(validUntil).toISOString() };
110
- }
111
- async function createPrivateArtifact(args) {
112
- const policy = { ...args.policy, ...validatePolicy(args.policy) };
113
- const ownerId = requiredSafeSegment(args.ownerId, "ownerId");
114
- const artifactKey = requiredSafeArtifactKey(args.artifactKey);
115
- const scope = (args.scopeSegments ?? []).map((segment, index) => requiredSafeSegment(segment, `scopeSegments[${index}]`));
116
- const timestamp = createdAtMs(args.createdAt);
117
- const requestedPathname = `${policy.prefix}${ownerId}/${scope.length ? `${scope.join("/")}/` : ""}${timestamp}-${artifactKey}`;
118
- const body = Buffer.isBuffer(args.content) ? args.content : Buffer.from(args.content);
119
- const bytes = body.length;
120
- const sha256 = createHash("sha256").update(body).digest("hex");
121
- const expiresAt = policy.artifactTtlMs === null ? null : new Date(timestamp + policy.artifactTtlMs);
122
- const token = policy.token?.trim() || null;
123
- let artifactId = requestedPathname;
124
- if (token) {
125
- const { put } = await import("@vercel/blob");
126
- const stored = await put(requestedPathname, body, {
127
- access: "private",
128
- token,
129
- contentType: args.contentType,
130
- addRandomSuffix: false,
131
- allowOverwrite: true,
132
- cacheControlMaxAge: 60,
133
- multipart: bytes > 100 * 1024 * 1024
134
- });
135
- artifactId = stored.pathname;
136
- } else {
137
- if (policyHosted(policy)) throw new Error("private_artifact_blob_not_configured");
138
- const path = join(policyLocalBaseDir(policy), "blobs", requestedPathname);
139
- await mkdir(dirname(path), { recursive: true });
140
- await writeFile(path, body);
141
- }
142
- const download = await signedDownloadUrl(artifactId, expiresAt, policy);
143
- return {
144
- artifactId,
145
- filename: safeDownloadFilename(args.filename),
146
- contentType: args.contentType,
147
- bytes,
148
- sha256,
149
- expiresAt: expiresAt?.toISOString() ?? DURABLE_ARTIFACT_EXPIRES_AT,
150
- downloadUrl: download?.url ?? null,
151
- downloadUrlExpiresAt: download?.expiresAt ?? null
152
- };
153
- }
154
- async function createPrivateArtifactFromStream(args) {
155
- const policy = { ...args.policy, ...validatePolicy(args.policy) };
156
- const ownerId = requiredSafeSegment(args.ownerId, "ownerId");
157
- const artifactKey = requiredSafeArtifactKey(args.artifactKey);
158
- const scope = (args.scopeSegments ?? []).map((segment, index) => requiredSafeSegment(segment, `scopeSegments[${index}]`));
159
- const timestamp = createdAtMs(args.createdAt);
160
- const requestedPathname = `${policy.prefix}${ownerId}/${scope.length ? `${scope.join("/")}/` : ""}${timestamp}-${artifactKey}`;
161
- const expiresAt = policy.artifactTtlMs === null ? null : new Date(timestamp + policy.artifactTtlMs);
162
- const token = policy.token?.trim() || null;
163
- const hash = createHash("sha256");
164
- let bytes = 0;
165
- const meter = new Transform({
166
- transform(chunk, _encoding, callback) {
167
- bytes += chunk.length;
168
- hash.update(chunk);
169
- callback(null, chunk);
170
- }
171
- });
172
- let artifactId = requestedPathname;
173
- if (token) {
174
- const { put } = await import("@vercel/blob");
175
- const pumping = pipeline(args.content, meter);
176
- try {
177
- const stored = await put(requestedPathname, meter, {
178
- access: "private",
179
- token,
180
- contentType: args.contentType,
181
- addRandomSuffix: false,
182
- allowOverwrite: true,
183
- cacheControlMaxAge: 60,
184
- multipart: true
185
- });
186
- await pumping;
187
- artifactId = stored.pathname;
188
- } catch (error) {
189
- args.content.destroy(error instanceof Error ? error : new Error(String(error)));
190
- meter.destroy(error instanceof Error ? error : new Error(String(error)));
191
- await pumping.catch(() => void 0);
192
- throw error;
193
- }
194
- } else {
195
- if (policyHosted(policy)) throw new Error("private_artifact_blob_not_configured");
196
- const path = join(policyLocalBaseDir(policy), "blobs", requestedPathname);
197
- await mkdir(dirname(path), { recursive: true });
198
- await pipeline(args.content, meter, createWriteStream(path));
199
- }
200
- const sha256 = hash.digest("hex");
201
- const download = await signedDownloadUrl(artifactId, expiresAt, policy);
202
- return {
203
- artifactId,
204
- filename: safeDownloadFilename(args.filename),
205
- contentType: args.contentType,
206
- bytes,
207
- sha256,
208
- expiresAt: expiresAt?.toISOString() ?? DURABLE_ARTIFACT_EXPIRES_AT,
209
- downloadUrl: download?.url ?? null,
210
- downloadUrlExpiresAt: download?.expiresAt ?? null
211
- };
212
- }
213
- async function renewPrivateArtifactDownload(args) {
214
- if (privateArtifactOwnerId(args.artifactId, args.policy.prefix) !== args.ownerId) return null;
215
- const expiresAt = privateArtifactExpiresAt(args.artifactId, args.policy);
216
- if (args.policy.artifactTtlMs !== null && (!expiresAt || expiresAt.getTime() <= Date.now())) return null;
217
- const download = await signedDownloadUrl(args.artifactId, expiresAt, args.policy);
218
- if (!download) return null;
219
- return {
220
- downloadUrl: download.url,
221
- downloadUrlExpiresAt: download.expiresAt,
222
- expiresAt: expiresAt?.toISOString() ?? DURABLE_ARTIFACT_EXPIRES_AT
223
- };
224
- }
225
- async function streamToBuffer(stream) {
226
- const reader = stream.getReader();
227
- const chunks = [];
228
- try {
229
- for (; ; ) {
230
- const { done, value } = await reader.read();
231
- if (done) break;
232
- if (value) chunks.push(Buffer.from(value));
233
- }
234
- } finally {
235
- reader.releaseLock();
236
- }
237
- return Buffer.concat(chunks);
238
- }
239
- async function readPrivateArtifactWindow(args) {
240
- if (privateArtifactOwnerId(args.artifactId, args.policy.prefix) === null) return null;
241
- const expiresAt = privateArtifactExpiresAt(args.artifactId, args.policy);
242
- if (args.policy.artifactTtlMs !== null && (!expiresAt || expiresAt.getTime() <= Date.now())) return null;
243
- if (!Number.isSafeInteger(args.offset) || args.offset < 0) throw new Error("private artifact offset is invalid");
244
- if (!Number.isSafeInteger(args.maxBytes) || args.maxBytes <= 0) throw new Error("private artifact maxBytes is invalid");
245
- const token = args.policy.token?.trim() || null;
246
- let buffer;
247
- if (token) {
248
- const { get } = await import("@vercel/blob");
249
- const result = await get(args.artifactId, { access: "private", token, useCache: false });
250
- if (!result || result.statusCode !== 200) return null;
251
- buffer = await streamToBuffer(result.stream);
252
- } else {
253
- if (policyHosted(args.policy)) return null;
254
- try {
255
- buffer = await readFile(join(policyLocalBaseDir(args.policy), "blobs", args.artifactId));
256
- } catch {
257
- return null;
258
- }
259
- }
260
- const totalBytes = buffer.length;
261
- const end = Math.min(totalBytes, args.offset + args.maxBytes);
262
- return {
263
- text: buffer.subarray(args.offset, end).toString("utf8"),
264
- totalBytes,
265
- nextOffset: end < totalBytes ? end : null
266
- };
267
- }
268
- async function readPrivateArtifactBuffer(args) {
269
- if (privateArtifactOwnerId(args.artifactId, args.policy.prefix) === null) return null;
270
- const expiresAt = privateArtifactExpiresAt(args.artifactId, args.policy);
271
- if (args.policy.artifactTtlMs !== null && (!expiresAt || expiresAt.getTime() <= Date.now())) return null;
272
- if (!Number.isSafeInteger(args.maxBytes) || args.maxBytes <= 0) throw new Error("private artifact maxBytes is invalid");
273
- const token = args.policy.token?.trim() || null;
274
- let buffer;
275
- if (token) {
276
- const { get } = await import("@vercel/blob");
277
- const result = await get(args.artifactId, { access: "private", token, useCache: false });
278
- if (!result || result.statusCode !== 200) return null;
279
- buffer = await streamToBuffer(result.stream);
280
- } else {
281
- if (policyHosted(args.policy)) return null;
282
- try {
283
- buffer = await readFile(join(policyLocalBaseDir(args.policy), "blobs", args.artifactId));
284
- } catch {
285
- return null;
286
- }
287
- }
288
- if (buffer.length > args.maxBytes) throw new Error("private artifact exceeds read limit");
289
- return buffer;
290
- }
291
-
292
- export {
293
- privateArtifactOwnerId,
294
- createPrivateArtifact,
295
- createPrivateArtifactFromStream,
296
- renewPrivateArtifactDownload,
297
- readPrivateArtifactWindow,
298
- readPrivateArtifactBuffer
299
- };