mirror of
https://github.com/theodore-song/polymarket-analyst.git
synced 2026-08-23 20:48:08 +00:00
Fit reward audit within Vercel function limit
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { recordAuditEvent, recordUserConsent } from "./_db.js";
|
||||
import { recordAuditEvent, recordUserConsent } from "../lib/db.js";
|
||||
|
||||
function activeVersions() {
|
||||
return {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { recordAuditEvent } from "./_db.js";
|
||||
import { recordAuditEvent } from "../lib/db.js";
|
||||
|
||||
async function notifyIncidentWebhook(payload) {
|
||||
const url = process.env.INCIDENT_WEBHOOK_URL || process.env.SENTRY_WEBHOOK_URL;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { auditLiquidity } from "../lib/liquidity-audit.js";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
res.setHeader("Allow", "GET");
|
||||
return res.status(405).json({ error: "method_not_allowed" });
|
||||
}
|
||||
try {
|
||||
const report = await auditLiquidity({
|
||||
marketLimit: Number(req.query.limit || 60),
|
||||
minHoursToEnd: Number(req.query.min_hours || 48),
|
||||
});
|
||||
res.setHeader("Cache-Control", "s-maxage=60, stale-while-revalidate=120");
|
||||
return res.status(200).json({ ok: true, ...report });
|
||||
} catch (error) {
|
||||
return res.status(502).json({ ok: false, error: "liquidity_audit_unavailable", detail: String(error && error.message || error) });
|
||||
}
|
||||
}
|
||||
+18
-1
@@ -8,7 +8,8 @@ import {
|
||||
recordRealFill,
|
||||
updateRealPositionMark,
|
||||
updateTradeTicketStatus,
|
||||
} from "./_db.js";
|
||||
} from "../lib/db.js";
|
||||
import { auditLiquidity } from "../lib/liquidity-audit.js";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
const REQUIRED_ENV = [
|
||||
@@ -731,6 +732,22 @@ export default async function handler(req, res) {
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
|
||||
if (req.method === "GET") {
|
||||
if (req.query?.action === "liquidity") {
|
||||
try {
|
||||
const report = await auditLiquidity({
|
||||
marketLimit: Number(req.query.limit || 60),
|
||||
minHoursToEnd: Number(req.query.min_hours || 48),
|
||||
});
|
||||
res.setHeader("Cache-Control", "s-maxage=60, stale-while-revalidate=120");
|
||||
return res.status(200).json({ ok: true, ...report });
|
||||
} catch (error) {
|
||||
return res.status(502).json({
|
||||
ok: false,
|
||||
error: "liquidity_audit_unavailable",
|
||||
detail: String(error?.message || error),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (req.query?.action === "tickets") {
|
||||
const userId = String(req.query?.user_id || "local-readiness-user").trim();
|
||||
const tickets = await listTradeTickets(userId, req.query?.limit || 50);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasDatabase, providerEventSummary } from "./_db.js";
|
||||
import { hasDatabase, providerEventSummary } from "../lib/db.js";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { latestRiskProfile, recordAuditEvent, upsertRiskProfile } from "./_db.js";
|
||||
import { latestRiskProfile, recordAuditEvent, upsertRiskProfile } from "../lib/db.js";
|
||||
|
||||
function validateProfile(profile) {
|
||||
const errors = [];
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { get, list, put } from "@vercel/blob";
|
||||
import { databaseConnectionDiagnostics, hasDatabase, readSharedAppState, writeSharedAppState } from "./_db.js";
|
||||
import { databaseConnectionDiagnostics, hasDatabase, readSharedAppState, writeSharedAppState } from "../lib/db.js";
|
||||
|
||||
const STATE_PATH = process.env.PMA_STATE_PATH || "shared/state.json";
|
||||
const STATE_VERSION_PREFIX = process.env.PMA_STATE_VERSION_PREFIX || "shared/state-versions/";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { recordProviderEvent } from "../_db.js";
|
||||
import { firstHeader, parseJson, rawBody, safeHeaders, sendMethodNotAllowed, verifyHmacSignature } from "../_webhook.js";
|
||||
import { recordProviderEvent } from "../../lib/db.js";
|
||||
import { firstHeader, parseJson, rawBody, safeHeaders, sendMethodNotAllowed, verifyHmacSignature } from "../../lib/webhook.js";
|
||||
|
||||
const SIGNATURE_HEADERS = [
|
||||
"circle-signature",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Webhook } from "svix";
|
||||
import { recordProviderEvent } from "../_db.js";
|
||||
import { rawBody, parseJson, safeHeaders, sendMethodNotAllowed } from "../_webhook.js";
|
||||
import { recordProviderEvent } from "../../lib/db.js";
|
||||
import { rawBody, parseJson, safeHeaders, sendMethodNotAllowed } from "../../lib/webhook.js";
|
||||
|
||||
function eventType(payload) {
|
||||
return payload.type || "clerk.webhook";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { recordProviderEvent } from "../_db.js";
|
||||
import { firstHeader, parseJson, rawBody, safeHeaders, sendMethodNotAllowed, verifyHmacSignature } from "../_webhook.js";
|
||||
import { recordProviderEvent } from "../../lib/db.js";
|
||||
import { firstHeader, parseJson, rawBody, safeHeaders, sendMethodNotAllowed, verifyHmacSignature } from "../../lib/webhook.js";
|
||||
|
||||
const SIGNATURE_HEADERS = [
|
||||
"x-hmac-signature",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { databaseConnectionDiagnostics, databaseUrl, databaseUrls, normalizeDatabaseUrl } from "../api/_db.js";
|
||||
import { databaseConnectionDiagnostics, databaseUrl, databaseUrls, normalizeDatabaseUrl } from "../lib/db.js";
|
||||
import { compactAgentState, compactSuggestion, providerErrorCode } from "../api/state.js";
|
||||
|
||||
assert.equal(normalizeDatabaseUrl("psql 'postgresql://user:pass@example.test/db?sslmode=require'"),
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
{
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "/api/liquidity",
|
||||
"destination": "/api/live?action=liquidity"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"source": "/",
|
||||
|
||||
Reference in New Issue
Block a user