UNPKG

@sahabaplus/moyasar

Version:

A comprehensive TypeScript SDK for integrating with the Moyasar payment gateway

48 lines 1.25 kB
import { WebhookEvents, WebhookHttpMethods } from "./enums"; export class WebhookValidation { /** * Validate webhook event type */ static isValidWebhookEvent(event) { return Object.values(WebhookEvents).includes(event); } /** * Validate HTTP method */ static isValidHttpMethod(method) { return Object.values(WebhookHttpMethods).includes(method); } /** * Validate URL format */ static isValidUrl(url) { try { const parsedUrl = new URL(url); return parsedUrl.protocol === "https:"; // Only allow HTTPS } catch { return false; } } /** * Validate required fields */ static validateRequired(obj, requiredFields) { const errors = []; for (const field of requiredFields) { if (obj[field] === undefined || obj[field] === null || obj[field] === "") { errors.push(`${String(field)} is required`); } } return errors; } /** * Sanitize webhook URL */ static sanitizeUrl(url) { return url.trim().toLowerCase(); } } //# sourceMappingURL=validation.js.map