docs: Enhance development setup documentation and update environment variable validation

- Added a new section in CURRENT_STATUS.md detailing prerequisites and quick start instructions for development setup.
- Updated environment variable validation to include defaults for missing variables in env.ts.
- Improved error handling in errorHandler.ts for better validation feedback.
- Made various code adjustments across services to ensure robustness and clarity.
This commit is contained in:
defiQUG
2025-11-05 19:00:46 -08:00
parent c872168d23
commit 14dfd3c9bf
18 changed files with 311 additions and 27 deletions

View File

@@ -10,6 +10,7 @@ export interface Alert {
title: string;
message: string;
metadata?: any;
timestamp?: string;
}
export class AlertingService {
@@ -90,7 +91,7 @@ export class AlertingService {
*/
private shouldThrottle(alert: Alert): boolean {
const recentAlerts = this.alertHistory.filter(
(a) => Date.now() - new Date(a.timestamp).getTime() < 5 * 60 * 1000 // 5 minutes
(a) => a.timestamp && Date.now() - new Date(a.timestamp).getTime() < 5 * 60 * 1000 // 5 minutes
);
// Throttle if more than 10 alerts in 5 minutes

View File

@@ -30,7 +30,7 @@ export async function addToDLQ(
* Get messages from DLQ for retry
*/
export async function getDLQMessages(queue: string, limit = 10): Promise<DeadLetterMessage[]> {
const result = await query<DeadLetterMessage>(
const result = await query<any>(
`SELECT * FROM dead_letter_queue
WHERE queue = $1 AND retry_count < 3
ORDER BY created_at ASC
@@ -38,13 +38,13 @@ export async function getDLQMessages(queue: string, limit = 10): Promise<DeadLet
[queue, limit]
);
return result.map((row) => ({
return result.map((row: any) => ({
messageId: row.message_id,
originalQueue: row.queue,
payload: typeof row.payload === "string" ? JSON.parse(row.payload) : row.payload,
error: row.error,
retryCount: row.retry_count,
createdAt: row.created_at,
createdAt: row.created_at ? (row.created_at instanceof Date ? row.created_at.toISOString() : String(row.created_at)) : new Date().toISOString(),
}));
}

View File

@@ -59,7 +59,8 @@ export function errorHandler(
}
// Handle validation errors
if (err.name === "ValidationError" || err.name === "ZodError" || err.issues) {
const isZodError = err.name === "ZodError" || (err as any).issues;
if (err.name === "ValidationError" || isZodError) {
logger.warn({
error: err,
requestId,
@@ -69,7 +70,7 @@ export function errorHandler(
return res.status(400).json({
error: ErrorType.VALIDATION_ERROR,
message: "Validation failed",
details: err.message || err.issues,
details: err.message || (isZodError ? (err as any).issues : undefined),
requestId,
});
}

View File

@@ -81,15 +81,15 @@ export async function generatePacs008(plan: Plan): Promise<string> {
},
CdtrAgt: {
FinInstnId: {
BICFI: payStep.beneficiary.BIC || "UNKNOWN",
BICFI: payStep.beneficiary?.BIC || "UNKNOWN",
},
},
Cdtr: {
Nm: payStep.beneficiary.name || "Unknown",
Nm: payStep.beneficiary?.name || "Unknown",
},
CdtrAcct: {
Id: {
IBAN: payStep.beneficiary.IBAN || "",
IBAN: payStep.beneficiary?.IBAN || "",
},
},
RmtInf: {

View File

@@ -115,9 +115,9 @@ export function checkStepDependencies(steps: PlanStep[]): ValidationResult {
function getStepOutput(step: PlanStep): { asset: string; amount: number } | null {
switch (step.type) {
case "borrow":
return { asset: step.asset, amount: step.amount };
return step.asset ? { asset: step.asset, amount: step.amount } : null;
case "swap":
return { asset: step.to, amount: step.amount };
return step.to ? { asset: step.to, amount: step.amount } : null;
default:
return null;
}

View File

@@ -29,6 +29,9 @@ export interface Receipt {
* Generate receipt for a plan execution
*/
export async function generateReceipt(plan: Plan): Promise<Receipt> {
if (!plan.plan_id) {
throw new Error("Plan ID is required");
}
const notaryProof = await getNotaryProof(plan.plan_id);
const dltStatus = await getDLTStatus(plan.plan_id);