UNPKG

@receeco/pos-agent

Version:

Receeco POS Integration Middleware Agent

111 lines 4.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const cors_1 = __importDefault(require("cors")); const helmet_1 = __importDefault(require("helmet")); const dotenv_1 = __importDefault(require("dotenv")); const logger_1 = require("./utils/logger"); const pos_integration_1 = require("./services/pos-integration"); const receipt_service_1 = require("./services/receipt-service"); const qr_service_1 = require("./services/qr-service"); const offline_queue_1 = require("./services/offline-queue"); dotenv_1.default.config(); const app = (0, express_1.default)(); const PORT = process.env.PORT || 3001; const logger = (0, logger_1.createLogger)(); app.use((0, helmet_1.default)()); app.use((0, cors_1.default)()); app.use(express_1.default.json({ limit: "10mb" })); app.use(express_1.default.urlencoded({ extended: true })); const receiptService = new receipt_service_1.ReceiptService(); const qrService = new qr_service_1.QRCodeService(); const offlineQueue = new offline_queue_1.OfflineQueueService(); const posIntegration = new pos_integration_1.POSIntegrationService(receiptService, qrService, offlineQueue); app.get("/health", (req, res) => { res.json({ status: "healthy", timestamp: new Date().toISOString(), version: "1.0.5", }); }); app.get("/config", (req, res) => { res.json({ merchantId: process.env.MERCHANT_ID || "", apiUrl: process.env.RECEECO_API_URL || "https://receeco.com/api", webUrl: process.env.RECEECO_WEB_URL || "https://receeco.com", hasApiKey: !!(process.env.RECEECO_API_KEY), version: "1.0.5", }); }); app.post("/transactions", async (req, res) => { try { logger.info("Received transaction:", { merchantId: req.body.merchantId, amount: req.body.totalAmount, }); const result = await posIntegration.processTransaction(req.body); logger.info("Transaction processed successfully:", { receiptId: result.receiptId, }); res.json(result); } catch (error) { logger.error("Transaction processing failed:", error); res.status(500).json({ error: "Transaction processing failed", message: error instanceof Error ? error.message : "Unknown error", }); } }); app.post("/webhooks/receipt-status", async (req, res) => { try { const { receiptId, status, timestamp } = req.body; logger.info("Receipt status update:", { receiptId, status }); await posIntegration.handleReceiptStatusUpdate(receiptId, status, timestamp); res.json({ success: true }); } catch (error) { logger.error("Webhook processing failed:", error); res.status(500).json({ error: "Webhook processing failed" }); } }); app.get("/transactions/:id/status", async (req, res) => { try { const status = await posIntegration.getTransactionStatus(req.params.id); res.json(status); } catch (error) { logger.error("Status check failed:", error); res.status(404).json({ error: "Transaction not found" }); } }); app.get("/queue/status", async (req, res) => { try { const status = await offlineQueue.getQueueStatus(); res.json(status); } catch (error) { logger.error("Queue status check failed:", error); res.status(500).json({ error: "Queue status unavailable" }); } }); app.listen(PORT, () => { logger.info(`Receeco POS Agent running on port ${PORT}`); logger.info("Environment:", { nodeEnv: process.env.NODE_ENV, rececoApiUrl: process.env.RECEECO_API_URL, merchantId: process.env.MERCHANT_ID, }); }); process.on("SIGTERM", () => { logger.info("SIGTERM received, shutting down gracefully"); process.exit(0); }); process.on("SIGINT", () => { logger.info("SIGINT received, shutting down gracefully"); process.exit(0); }); //# sourceMappingURL=index.js.map