feat: implement MailGun webhook service for logging email events
Implemented a production-ready TypeScript/Express.js service to receive and log MailGun webhook events (delivered, failed, opened, clicked, etc.). Key features: - Webhook endpoint (POST /webhook) with comprehensive event logging - Full TypeScript type definitions for all MailGun event types - Prometheus metrics integration for monitoring - Health check endpoint (GET /ping) - Comprehensive Jest test suite with 87.76% coverage - Docker containerization with build scripts Removed template/example code: - All SQL/MSSQL dependencies and related code - Example auth router and middleware - PRTG metrics support (simplified to Prometheus only) - Unused middleware (CORS, IP whitelist, request parsing/validation) - Template documentation (kept only MailGun webhook API spec) The service is clean, minimal, and focused solely on receiving and logging MailGun webhook events to the console. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
59
mailgun-webhook/tests/helpers/mockHttpContext.ts
Normal file
59
mailgun-webhook/tests/helpers/mockHttpContext.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @fileoverview
|
||||
* This file is a part of an "auth" example router, which was taken from an existing integration.
|
||||
* It is to be used only as a reference for how an API router for a web service should be structured.
|
||||
* In a real-live implementation all files related to `/auth` route example should be removed
|
||||
* by new set of files implementing the new API.
|
||||
*/
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { AppLocals } from "../../src/types/AppLocals";
|
||||
|
||||
interface IMockHttpParams {
|
||||
sessionID?: number
|
||||
sessionGUID?: string
|
||||
table_id?: string
|
||||
clientIp?: string
|
||||
free_play: 0 | 1
|
||||
}
|
||||
|
||||
interface IMockHttpContext {
|
||||
clientIpAddress?:string
|
||||
reqPath?:string
|
||||
headersSent?:boolean
|
||||
writableEnded?:boolean
|
||||
method?:string
|
||||
params?: IMockHttpParams
|
||||
}
|
||||
|
||||
export const defaultMockParams:IMockHttpParams = {
|
||||
sessionID: 123,
|
||||
sessionGUID: '016e6812-b915-4e5e-94fe-193582239b96',
|
||||
table_id: 'mock-table-id',
|
||||
clientIp: '192.168.1.10',
|
||||
free_play: 0
|
||||
}
|
||||
|
||||
export const mockHttpContext = ({reqPath="/", headersSent=false, writableEnded=false, method="GET", params=defaultMockParams}:IMockHttpContext|undefined = {}) => {
|
||||
const req = {
|
||||
path:reqPath,
|
||||
method,
|
||||
url:`https://localhost${reqPath}`,
|
||||
params,
|
||||
} as unknown as Request;
|
||||
|
||||
const res = {
|
||||
end: jest.fn(),
|
||||
status: jest.fn(),
|
||||
setHeader: jest.fn(),
|
||||
params,
|
||||
locals: {
|
||||
stopPrometheusTimer: jest.fn(),
|
||||
} as unknown as AppLocals,
|
||||
headersSent,
|
||||
writableEnded,
|
||||
} as unknown as Response;
|
||||
|
||||
const next:NextFunction = jest.fn();
|
||||
|
||||
return({req,res,next})
|
||||
}
|
||||
Reference in New Issue
Block a user