UNPKG

@thorium-dev-group/x402-mcp-extension

Version:
74 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PaymentAuditStorage = void 0; const PENDING_PREFIX = "pending:"; const TTL = 86400; class PaymentAuditStorage { storage; constructor(props) { this.storage = props.storage; } async storePendingRequest(record) { const fullRecord = { ...record, requestStatus: 'pending', paymentStatus: 'pending', createdAt: new Date(), }; if (!record.requestId) { throw new Error("Invalid audit record: missing request id"); } await this.write(this.buildPendingKey(record.requestId), fullRecord); } async getPendingRequest(requestId) { return await this.read(this.buildPendingKey(requestId)) || null; } async markRequestCompleted(requestId, completedAt) { const record = await this.read(this.buildPendingKey(requestId)); if (record) { record.requestStatus = 'completed'; record.requestCompletedAt = completedAt || new Date(); await this.write(requestId.toString(), record); } } async updatePaymentStatus(requestId, status, details) { const record = await this.read(this.buildPendingKey(requestId)); if (record) { record.paymentStatus = status; record.paymentCompletedAt = details?.completedAt || new Date(); if (details?.transactionHash) { record.transactionHash = details.transactionHash; } if (details?.payerAddress) { record.payerAddress = details.payerAddress; } if (details?.errorReason) { record.errorReason = details.errorReason; } if (status !== 'pending') { await this.write(requestId.toString(), record); } else { await this.write(this.buildPendingKey(requestId), record); } } } async removePendingRequest(requestId) { await this.storage.delete(requestId.toString()); } buildPendingKey(requestId) { return `${PENDING_PREFIX}${requestId.toString()}`; } async read(key) { const str = await this.storage.get(key); if (str) { return JSON.parse(str); } } async write(key, record) { const str = JSON.stringify(record); await this.storage.set(key, str, TTL); } } exports.PaymentAuditStorage = PaymentAuditStorage; //# sourceMappingURL=PaymentAuditStore.js.map