mcp-scraper 0.3.19 → 0.3.20
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/bin/api-server.cjs +112 -10
- package/dist/bin/api-server.cjs.map +1 -1
- package/dist/bin/api-server.js +3 -3
- package/dist/bin/mcp-scraper-cli.cjs +1 -1
- package/dist/bin/mcp-scraper-cli.cjs.map +1 -1
- package/dist/bin/mcp-scraper-cli.js +1 -1
- package/dist/bin/mcp-scraper-install.cjs +1 -1
- package/dist/bin/mcp-scraper-install.cjs.map +1 -1
- package/dist/bin/mcp-scraper-install.js +1 -1
- package/dist/bin/mcp-stdio-server.cjs +1 -1
- package/dist/bin/mcp-stdio-server.cjs.map +1 -1
- package/dist/bin/mcp-stdio-server.js +2 -2
- package/dist/{chunk-A46NKAAM.js → chunk-6N6USFMH.js} +2 -2
- package/dist/{chunk-5H22TOXQ.js → chunk-IORA5BFI.js} +107 -6
- package/dist/chunk-IORA5BFI.js.map +1 -0
- package/dist/chunk-XLHBBA3U.js +7 -0
- package/dist/chunk-XLHBBA3U.js.map +1 -0
- package/dist/{chunk-T337IGVE.js → chunk-YZAYOFJV.js} +2 -2
- package/dist/{db-P76GVIFN.js → db-ZWV4Y43C.js} +10 -2
- package/dist/{server-EYNMXWUJ.js → server-NKZW2SEV.js} +11 -9
- package/dist/server-NKZW2SEV.js.map +1 -0
- package/dist/{worker-YZ2ZJE4F.js → worker-PR7GODIV.js} +3 -3
- package/docs/mcp-tool-manifest.generated.json +1 -1
- package/package.json +1 -1
- package/dist/chunk-5H22TOXQ.js.map +0 -1
- package/dist/chunk-AUKOY2IV.js +0 -7
- package/dist/chunk-AUKOY2IV.js.map +0 -1
- package/dist/server-EYNMXWUJ.js.map +0 -1
- /package/dist/{chunk-A46NKAAM.js.map → chunk-6N6USFMH.js.map} +0 -0
- /package/dist/{chunk-T337IGVE.js.map → chunk-YZAYOFJV.js.map} +0 -0
- /package/dist/{db-P76GVIFN.js.map → db-ZWV4Y43C.js.map} +0 -0
- /package/dist/{worker-YZ2ZJE4F.js.map → worker-PR7GODIV.js.map} +0 -0
package/dist/bin/api-server.cjs
CHANGED
|
@@ -7322,6 +7322,7 @@ var init_site_audit_service = __esm({
|
|
|
7322
7322
|
// src/api/db.ts
|
|
7323
7323
|
var db_exports = {};
|
|
7324
7324
|
__export(db_exports, {
|
|
7325
|
+
CREDIT_LOT_TTL: () => CREDIT_LOT_TTL,
|
|
7325
7326
|
SiteAuditJobRowSchema: () => SiteAuditJobRowSchema,
|
|
7326
7327
|
SiteAuditPhaseLogRowSchema: () => SiteAuditPhaseLogRowSchema,
|
|
7327
7328
|
advanceWorkflowRunStep: () => advanceWorkflowRunStep,
|
|
@@ -7348,6 +7349,7 @@ __export(db_exports, {
|
|
|
7348
7349
|
deactivateUser: () => deactivateUser,
|
|
7349
7350
|
debitMc: () => debitMc,
|
|
7350
7351
|
deleteWorkflowSchedule: () => deleteWorkflowSchedule,
|
|
7352
|
+
expireOldLots: () => expireOldLots,
|
|
7351
7353
|
failJob: () => failJob,
|
|
7352
7354
|
failKpoJob: () => failKpoJob,
|
|
7353
7355
|
failWorkflowRunRecord: () => failWorkflowRunRecord,
|
|
@@ -7385,6 +7387,7 @@ __export(db_exports, {
|
|
|
7385
7387
|
markWorkflowRunRunning: () => markWorkflowRunRunning,
|
|
7386
7388
|
markWorkflowScheduleRan: () => markWorkflowScheduleRan,
|
|
7387
7389
|
migrate: () => migrate,
|
|
7390
|
+
migrateExistingBalancesToLots: () => migrateExistingBalancesToLots,
|
|
7388
7391
|
patchWorkflowSchedule: () => patchWorkflowSchedule,
|
|
7389
7392
|
reconcileBalanceMc: () => reconcileBalanceMc,
|
|
7390
7393
|
recordStripeEvent: () => recordStripeEvent,
|
|
@@ -7393,6 +7396,7 @@ __export(db_exports, {
|
|
|
7393
7396
|
revokeApiKey: () => revokeApiKey,
|
|
7394
7397
|
rotateApiKey: () => rotateApiKey,
|
|
7395
7398
|
setConcurrencySubId: () => setConcurrencySubId,
|
|
7399
|
+
setDbForTesting: () => setDbForTesting,
|
|
7396
7400
|
setExtraConcurrencySlots: () => setExtraConcurrencySlots,
|
|
7397
7401
|
setPassword: () => setPassword,
|
|
7398
7402
|
setStripeCustomerId: () => setStripeCustomerId,
|
|
@@ -7405,6 +7409,9 @@ function getDb() {
|
|
|
7405
7409
|
if (!_db) _db = (0, import_http.createClient)({ url: DB_URL, authToken: DB_TOKEN });
|
|
7406
7410
|
return _db;
|
|
7407
7411
|
}
|
|
7412
|
+
function setDbForTesting(client2) {
|
|
7413
|
+
_db = client2;
|
|
7414
|
+
}
|
|
7408
7415
|
async function migrate() {
|
|
7409
7416
|
const db = getDb();
|
|
7410
7417
|
await db.execute(`
|
|
@@ -7546,6 +7553,19 @@ async function migrate() {
|
|
|
7546
7553
|
)
|
|
7547
7554
|
`);
|
|
7548
7555
|
await db.execute(`CREATE INDEX IF NOT EXISTS ledger_user_id ON ledger(user_id)`);
|
|
7556
|
+
await db.execute(`
|
|
7557
|
+
CREATE TABLE IF NOT EXISTS credit_lots (
|
|
7558
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7559
|
+
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
7560
|
+
amount_mc INTEGER NOT NULL,
|
|
7561
|
+
remaining_mc INTEGER NOT NULL,
|
|
7562
|
+
source TEXT NOT NULL,
|
|
7563
|
+
stripe_pi TEXT,
|
|
7564
|
+
granted_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
7565
|
+
expires_at TEXT NOT NULL
|
|
7566
|
+
)
|
|
7567
|
+
`);
|
|
7568
|
+
await db.execute(`CREATE INDEX IF NOT EXISTS credit_lots_user_active ON credit_lots(user_id, expires_at, remaining_mc)`);
|
|
7549
7569
|
await db.execute(`
|
|
7550
7570
|
CREATE TABLE IF NOT EXISTS free_credit_refreshes (
|
|
7551
7571
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
@@ -8574,12 +8594,89 @@ async function setConcurrencySubId(userId, subId) {
|
|
|
8574
8594
|
args: [subId, userId]
|
|
8575
8595
|
});
|
|
8576
8596
|
}
|
|
8597
|
+
async function ensureMigrated(userId) {
|
|
8598
|
+
const db = getDb();
|
|
8599
|
+
const hasLots = await db.execute({ sql: "SELECT 1 FROM credit_lots WHERE user_id = ? LIMIT 1", args: [userId] });
|
|
8600
|
+
if (hasLots.rows.length) return;
|
|
8601
|
+
const legacy = await db.execute({ sql: "SELECT COALESCE(SUM(amount_mc), 0) AS bal FROM ledger WHERE user_id = ?", args: [userId] });
|
|
8602
|
+
const bal = Number(legacy.rows[0]?.bal ?? 0);
|
|
8603
|
+
if (bal > 0) {
|
|
8604
|
+
await db.execute({
|
|
8605
|
+
sql: `INSERT INTO credit_lots (user_id, amount_mc, remaining_mc, source, expires_at) VALUES (?, ?, ?, 'migration', datetime('now', ?))`,
|
|
8606
|
+
args: [userId, bal, bal, CREDIT_LOT_TTL]
|
|
8607
|
+
});
|
|
8608
|
+
}
|
|
8609
|
+
}
|
|
8610
|
+
async function drainLots(userId, mc) {
|
|
8611
|
+
const db = getDb();
|
|
8612
|
+
const lots = await db.execute({
|
|
8613
|
+
sql: `SELECT id, remaining_mc FROM credit_lots WHERE user_id = ? AND remaining_mc > 0 AND expires_at > datetime('now') ORDER BY expires_at ASC, granted_at ASC, id ASC`,
|
|
8614
|
+
args: [userId]
|
|
8615
|
+
});
|
|
8616
|
+
let need = mc;
|
|
8617
|
+
const updates = [];
|
|
8618
|
+
for (const lot of lots.rows) {
|
|
8619
|
+
if (need <= 0) break;
|
|
8620
|
+
const take = Math.min(Number(lot.remaining_mc), need);
|
|
8621
|
+
updates.push({ sql: "UPDATE credit_lots SET remaining_mc = remaining_mc - ? WHERE id = ?", args: [take, Number(lot.id)] });
|
|
8622
|
+
need -= take;
|
|
8623
|
+
}
|
|
8624
|
+
if (updates.length) await db.batch(updates, "write");
|
|
8625
|
+
}
|
|
8626
|
+
async function expireOldLots() {
|
|
8627
|
+
const db = getDb();
|
|
8628
|
+
const lots = await db.execute({
|
|
8629
|
+
sql: `SELECT id, user_id, remaining_mc FROM credit_lots WHERE remaining_mc > 0 AND expires_at <= datetime('now') LIMIT 500`
|
|
8630
|
+
});
|
|
8631
|
+
if (lots.rows.length === 0) return { expired_lots: 0, expired_mc: 0 };
|
|
8632
|
+
let totalMc = 0;
|
|
8633
|
+
const users = /* @__PURE__ */ new Set();
|
|
8634
|
+
const stmts = [];
|
|
8635
|
+
for (const lot of lots.rows) {
|
|
8636
|
+
const rem = Number(lot.remaining_mc);
|
|
8637
|
+
const uid = Number(lot.user_id);
|
|
8638
|
+
totalMc += rem;
|
|
8639
|
+
users.add(uid);
|
|
8640
|
+
stmts.push({ sql: "UPDATE credit_lots SET remaining_mc = 0 WHERE id = ?", args: [Number(lot.id)] });
|
|
8641
|
+
stmts.push({ sql: `INSERT INTO ledger (user_id, amount_mc, operation, description) VALUES (?, ?, 'credit_expired', 'credits expired')`, args: [uid, -rem] });
|
|
8642
|
+
}
|
|
8643
|
+
await db.batch(stmts, "write");
|
|
8644
|
+
for (const uid of users) await reconcileBalanceMc(uid);
|
|
8645
|
+
return { expired_lots: lots.rows.length, expired_mc: totalMc };
|
|
8646
|
+
}
|
|
8647
|
+
async function migrateExistingBalancesToLots() {
|
|
8648
|
+
const db = getDb();
|
|
8649
|
+
const res = await db.execute({
|
|
8650
|
+
sql: `SELECT u.id AS user_id, COALESCE(SUM(l.amount_mc), 0) AS bal
|
|
8651
|
+
FROM users u LEFT JOIN ledger l ON l.user_id = u.id
|
|
8652
|
+
WHERE u.id NOT IN (SELECT DISTINCT user_id FROM credit_lots)
|
|
8653
|
+
GROUP BY u.id HAVING bal > 0`
|
|
8654
|
+
});
|
|
8655
|
+
let migrated = 0;
|
|
8656
|
+
let totalMc = 0;
|
|
8657
|
+
for (const row of res.rows) {
|
|
8658
|
+
const uid = Number(row.user_id);
|
|
8659
|
+
const bal = Number(row.bal);
|
|
8660
|
+
await db.execute({
|
|
8661
|
+
sql: `INSERT INTO credit_lots (user_id, amount_mc, remaining_mc, source, expires_at) VALUES (?, ?, ?, 'migration', datetime('now', ?))`,
|
|
8662
|
+
args: [uid, bal, bal, CREDIT_LOT_TTL]
|
|
8663
|
+
});
|
|
8664
|
+
await reconcileBalanceMc(uid);
|
|
8665
|
+
migrated++;
|
|
8666
|
+
totalMc += bal;
|
|
8667
|
+
}
|
|
8668
|
+
return { migrated, total_mc: totalMc };
|
|
8669
|
+
}
|
|
8577
8670
|
async function creditMc(userId, mc, operation, description, stripePaymentIntent) {
|
|
8578
8671
|
const db = getDb();
|
|
8579
|
-
await
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8672
|
+
await ensureMigrated(userId);
|
|
8673
|
+
const stmts = [];
|
|
8674
|
+
if (mc > 0) {
|
|
8675
|
+
stmts.push({ sql: `INSERT INTO credit_lots (user_id, amount_mc, remaining_mc, source, stripe_pi, expires_at) VALUES (?, ?, ?, ?, ?, datetime('now', ?))`, args: [userId, mc, mc, operation, stripePaymentIntent ?? null, CREDIT_LOT_TTL] });
|
|
8676
|
+
}
|
|
8677
|
+
stmts.push({ sql: "UPDATE users SET balance_mc = balance_mc + ? WHERE id = ?", args: [mc, userId] });
|
|
8678
|
+
stmts.push({ sql: "INSERT INTO ledger (user_id, amount_mc, operation, description, stripe_pi) VALUES (?, ?, ?, ?, ?)", args: [userId, mc, operation, description ?? null, stripePaymentIntent ?? null] });
|
|
8679
|
+
await db.batch(stmts, "write");
|
|
8583
8680
|
const res = await db.execute({ sql: "SELECT balance_mc FROM users WHERE id = ?", args: [userId] });
|
|
8584
8681
|
return Number(res.rows[0]?.balance_mc ?? 0);
|
|
8585
8682
|
}
|
|
@@ -8599,6 +8696,7 @@ async function claimMonthlyFreeRefresh(userId, month) {
|
|
|
8599
8696
|
}
|
|
8600
8697
|
async function debitMc(userId, mc, operation, description) {
|
|
8601
8698
|
const db = getDb();
|
|
8699
|
+
await ensureMigrated(userId);
|
|
8602
8700
|
const upd = await db.execute({
|
|
8603
8701
|
sql: "UPDATE users SET balance_mc = balance_mc - ? WHERE id = ? AND balance_mc >= ?",
|
|
8604
8702
|
args: [mc, userId, mc]
|
|
@@ -8607,6 +8705,7 @@ async function debitMc(userId, mc, operation, description) {
|
|
|
8607
8705
|
const res2 = await db.execute({ sql: "SELECT balance_mc FROM users WHERE id = ?", args: [userId] });
|
|
8608
8706
|
return { ok: false, balance_mc: Number(res2.rows[0]?.balance_mc ?? 0) };
|
|
8609
8707
|
}
|
|
8708
|
+
await drainLots(userId, mc);
|
|
8610
8709
|
await db.execute({
|
|
8611
8710
|
sql: "INSERT INTO ledger (user_id, amount_mc, operation, description) VALUES (?, ?, ?, ?)",
|
|
8612
8711
|
args: [userId, -mc, operation, description ?? null]
|
|
@@ -8638,8 +8737,9 @@ async function ledgerExistsForStripePI(stripePI) {
|
|
|
8638
8737
|
}
|
|
8639
8738
|
async function reconcileBalanceMc(userId) {
|
|
8640
8739
|
const db = getDb();
|
|
8740
|
+
await ensureMigrated(Number(userId));
|
|
8641
8741
|
const res = await db.execute({
|
|
8642
|
-
sql:
|
|
8742
|
+
sql: `SELECT COALESCE(SUM(remaining_mc), 0) AS balance_mc FROM credit_lots WHERE user_id = ? AND remaining_mc > 0 AND expires_at > datetime('now')`,
|
|
8643
8743
|
args: [userId]
|
|
8644
8744
|
});
|
|
8645
8745
|
const balanceMc = Number(res.rows[0]?.balance_mc ?? 0);
|
|
@@ -8649,7 +8749,7 @@ async function reconcileBalanceMc(userId) {
|
|
|
8649
8749
|
});
|
|
8650
8750
|
return balanceMc;
|
|
8651
8751
|
}
|
|
8652
|
-
var import_http, import_node_crypto2, import_zod10, DB_URL, DB_TOKEN, _db, _rateLimitSchemaReady, SiteAuditJobRowSchema, SiteAuditPhaseLogRowSchema;
|
|
8752
|
+
var import_http, import_node_crypto2, import_zod10, DB_URL, DB_TOKEN, _db, _rateLimitSchemaReady, CREDIT_LOT_TTL, SiteAuditJobRowSchema, SiteAuditPhaseLogRowSchema;
|
|
8653
8753
|
var init_db = __esm({
|
|
8654
8754
|
"src/api/db.ts"() {
|
|
8655
8755
|
"use strict";
|
|
@@ -8660,6 +8760,7 @@ var init_db = __esm({
|
|
|
8660
8760
|
DB_TOKEN = process.env.TURSO_AUTH_TOKEN;
|
|
8661
8761
|
_db = null;
|
|
8662
8762
|
_rateLimitSchemaReady = false;
|
|
8763
|
+
CREDIT_LOT_TTL = "+3 months";
|
|
8663
8764
|
SiteAuditJobRowSchema = import_zod10.z.object({
|
|
8664
8765
|
id: import_zod10.z.string(),
|
|
8665
8766
|
user_id: import_zod10.z.number(),
|
|
@@ -23762,7 +23863,7 @@ var PACKAGE_VERSION;
|
|
|
23762
23863
|
var init_version = __esm({
|
|
23763
23864
|
"src/version.ts"() {
|
|
23764
23865
|
"use strict";
|
|
23765
|
-
PACKAGE_VERSION = "0.3.
|
|
23866
|
+
PACKAGE_VERSION = "0.3.20";
|
|
23766
23867
|
}
|
|
23767
23868
|
});
|
|
23768
23869
|
|
|
@@ -29288,12 +29389,13 @@ var init_server = __esm({
|
|
|
29288
29389
|
const { drainQueue: drainQueue2 } = await Promise.resolve().then(() => (init_worker(), worker_exports));
|
|
29289
29390
|
const budget = { maxJobs: 10, deadlineMs: Date.now() + 28e4 };
|
|
29290
29391
|
const workflowDispatchResult = await dispatchDueWorkflowSchedules(`${new URL(c.req.url).protocol}//${new URL(c.req.url).host}`);
|
|
29291
|
-
const [results, sweepResult, reapResult] = await Promise.all([
|
|
29392
|
+
const [results, sweepResult, reapResult, expiredResult] = await Promise.all([
|
|
29292
29393
|
drainQueue2(budget),
|
|
29293
29394
|
runMonthlyRefreshSweep(),
|
|
29294
|
-
reapIdleBrowserSessions(120).catch(() => ({ reaped: 0 }))
|
|
29395
|
+
reapIdleBrowserSessions(120).catch(() => ({ reaped: 0 })),
|
|
29396
|
+
expireOldLots().catch(() => ({ expired_lots: 0, expired_mc: 0 }))
|
|
29295
29397
|
]);
|
|
29296
|
-
return c.json({ drained: results.length, results, sweepResult, reaped: reapResult, workflowDispatch: workflowDispatchResult });
|
|
29398
|
+
return c.json({ drained: results.length, results, sweepResult, reaped: reapResult, expired: expiredResult, workflowDispatch: workflowDispatchResult });
|
|
29297
29399
|
});
|
|
29298
29400
|
app.on(["GET", "POST", "PUT"], "/api/inngest", (0, import_hono14.serve)({ client: inngest, functions: [siteAuditFn, siteExtractFn] }));
|
|
29299
29401
|
app.route("/api/internal/site-architecture-auditor", siteAuditApp);
|