- Add comprehensive analytics components with export functionality - Implement territory management with manager performance tracking - Add seatmap components for venue layout management - Create customer management features with modal interface - Add advanced hooks for dashboard flags and territory data - Implement seat selection and venue management utilities - Add type definitions for ticketing and seatmap systems 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
157 lines
6.0 KiB
JavaScript
157 lines
6.0 KiB
JavaScript
"use strict";
|
|
const __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.api = void 0;
|
|
const https_1 = require("firebase-functions/v2/https");
|
|
const logger_1 = require("./logger");
|
|
const express_1 = __importDefault(require("express"));
|
|
const cors_1 = __importDefault(require("cors"));
|
|
// Import all individual function handlers
|
|
const verify_1 = require("./verify");
|
|
const checkout_1 = require("./checkout");
|
|
const stripeConnect_1 = require("./stripeConnect");
|
|
const claims_1 = require("./claims");
|
|
const domains_1 = require("./domains");
|
|
const orders_1 = require("./orders");
|
|
const refunds_1 = require("./refunds");
|
|
const disputes_1 = require("./disputes");
|
|
const reconciliation_1 = require("./reconciliation");
|
|
const app = (0, express_1.default)();
|
|
// CORS: allow hosting origins + dev
|
|
const allowedOrigins = [
|
|
// Add your actual Firebase project URLs here
|
|
"https://your-project-id.web.app",
|
|
"https://your-project-id.firebaseapp.com",
|
|
"http://localhost:5173", // Vite dev server
|
|
"http://localhost:4173", // Vite preview
|
|
"http://localhost:3000", // Common dev port
|
|
];
|
|
app.use((0, cors_1.default)({
|
|
origin: (origin, callback) => {
|
|
// Allow requests with no origin (mobile apps, curl, etc.)
|
|
if (!origin)
|
|
{return callback(null, true);}
|
|
if (allowedOrigins.includes(origin)) {
|
|
return callback(null, true);
|
|
}
|
|
return callback(new Error('Not allowed by CORS'));
|
|
},
|
|
credentials: true
|
|
}));
|
|
app.use(express_1.default.json({ limit: "2mb" }));
|
|
app.use(express_1.default.urlencoded({ extended: true }));
|
|
// Middleware to log API requests
|
|
app.use((req, res, next) => {
|
|
logger_1.logger.info(`API Request: ${req.method} ${req.path}`);
|
|
next();
|
|
});
|
|
// Helper function to wrap Firebase Functions for Express
|
|
const wrapFirebaseFunction = (fn) => async (req, res) => {
|
|
try {
|
|
// Create mock Firebase Functions request/response objects
|
|
const mockReq = {
|
|
...req,
|
|
method: req.method,
|
|
body: req.body,
|
|
query: req.query,
|
|
headers: req.headers,
|
|
get: (header) => req.get(header),
|
|
};
|
|
const mockRes = {
|
|
...res,
|
|
status: (code) => {
|
|
res.status(code);
|
|
return mockRes;
|
|
},
|
|
json: (data) => {
|
|
res.json(data);
|
|
return mockRes;
|
|
},
|
|
send: (data) => {
|
|
res.send(data);
|
|
return mockRes;
|
|
},
|
|
setHeader: (name, value) => {
|
|
res.setHeader(name, value);
|
|
return mockRes;
|
|
}
|
|
};
|
|
// Call the original Firebase Function
|
|
await fn.options.handler(mockReq, mockRes);
|
|
}
|
|
catch (error) {
|
|
logger_1.logger.error('Function wrapper error:', error);
|
|
res.status(500).json({
|
|
error: 'Internal server error',
|
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
});
|
|
}
|
|
};
|
|
// Wire up all endpoints under /api
|
|
// Ticket verification
|
|
app.post("/tickets/verify", wrapFirebaseFunction(verify_1.verifyTicket));
|
|
app.get("/tickets/verify/:qr", wrapFirebaseFunction(verify_1.verifyTicket));
|
|
// Checkout endpoints
|
|
app.post("/checkout/create", wrapFirebaseFunction(checkout_1.createCheckout));
|
|
app.post("/stripe/checkout/create", wrapFirebaseFunction(stripeConnect_1.createStripeCheckout));
|
|
// Stripe Connect endpoints
|
|
app.post("/stripe/connect/start", wrapFirebaseFunction(stripeConnect_1.stripeConnectStart));
|
|
app.get("/stripe/connect/status", wrapFirebaseFunction(stripeConnect_1.stripeConnectStatus));
|
|
// Orders
|
|
app.get("/orders/:orderId", wrapFirebaseFunction(orders_1.getOrder));
|
|
// Refunds
|
|
app.post("/refunds/create", wrapFirebaseFunction(refunds_1.createRefund));
|
|
app.get("/orders/:orderId/refunds", wrapFirebaseFunction(refunds_1.getOrderRefunds));
|
|
// Disputes
|
|
app.get("/orders/:orderId/disputes", wrapFirebaseFunction(disputes_1.getOrderDisputes));
|
|
// Claims management
|
|
app.get("/claims/:uid", wrapFirebaseFunction(claims_1.getUserClaims));
|
|
app.post("/claims/update", wrapFirebaseFunction(claims_1.updateUserClaims));
|
|
// Domain management
|
|
app.post("/domains/resolve", wrapFirebaseFunction(domains_1.resolveDomain));
|
|
app.post("/domains/verify-request", wrapFirebaseFunction(domains_1.requestDomainVerification));
|
|
app.post("/domains/verify", wrapFirebaseFunction(domains_1.verifyDomain));
|
|
// Reconciliation
|
|
app.get("/reconciliation/data", wrapFirebaseFunction(reconciliation_1.getReconciliationData));
|
|
app.get("/reconciliation/events", wrapFirebaseFunction(reconciliation_1.getReconciliationEvents));
|
|
// Health check
|
|
app.get("/health", (req, res) => {
|
|
res.json({
|
|
status: "ok",
|
|
timestamp: new Date().toISOString(),
|
|
version: "1.0.0"
|
|
});
|
|
});
|
|
// Stripe webhooks (these need raw body, so they stay separate - see firebase.json)
|
|
// Note: These will be handled by separate functions due to raw body requirements
|
|
// Catch-all for unmatched routes
|
|
app.use("*", (req, res) => {
|
|
res.status(404).json({
|
|
error: "Not found",
|
|
path: req.originalUrl,
|
|
availableEndpoints: [
|
|
"POST /api/tickets/verify",
|
|
"GET /api/tickets/verify/:qr",
|
|
"POST /api/checkout/create",
|
|
"POST /api/stripe/connect/start",
|
|
"GET /api/stripe/connect/status",
|
|
"GET /api/health"
|
|
]
|
|
});
|
|
});
|
|
// Error handling middleware
|
|
app.use((error, req, res, next) => {
|
|
logger_1.logger.error('Express error:', error);
|
|
res.status(500).json({
|
|
error: 'Internal server error',
|
|
message: error.message
|
|
});
|
|
});
|
|
exports.api = (0, https_1.onRequest)({
|
|
region: "us-central1",
|
|
maxInstances: 10,
|
|
cors: true
|
|
}, app);
|
|
// # sourceMappingURL=api.js.map
|