UNPKG

@hellocoop/email-verification

Version:

Functions for generating and verifying JWT tokens used in the Email Verification Protocol

100 lines 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JWKSFetchError = exports.DNSDiscoveryError = exports.EmailValidationError = exports.JWKValidationError = exports.TokenFormatError = exports.TimeValidationError = exports.InvalidSignatureError = exports.MissingClaimError = exports.EmailVerificationError = void 0; /** * Base error class for all email-verification related errors */ class EmailVerificationError extends Error { code; constructor(message, code) { super(message); this.code = code; this.name = 'EmailVerificationError'; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, EmailVerificationError); } } } exports.EmailVerificationError = EmailVerificationError; /** * Error thrown when a required claim is missing from a JWT */ class MissingClaimError extends EmailVerificationError { constructor(claim) { super(`Required claim '${claim}' is missing`, 'missing_claim'); this.name = 'MissingClaimError'; } } exports.MissingClaimError = MissingClaimError; /** * Error thrown when JWT signature verification fails */ class InvalidSignatureError extends EmailVerificationError { constructor(message = 'Token signature verification failed') { super(message, 'invalid_signature'); this.name = 'InvalidSignatureError'; } } exports.InvalidSignatureError = InvalidSignatureError; /** * Error thrown when time-based validation fails (iat claims) */ class TimeValidationError extends EmailVerificationError { constructor(message) { super(message, 'time_validation'); this.name = 'TimeValidationError'; } } exports.TimeValidationError = TimeValidationError; /** * Error thrown when token format is invalid or malformed */ class TokenFormatError extends EmailVerificationError { constructor(message) { super(message, 'token_format'); this.name = 'TokenFormatError'; } } exports.TokenFormatError = TokenFormatError; /** * Error thrown when JWK validation fails */ class JWKValidationError extends EmailVerificationError { constructor(message) { super(message, 'jwk_validation'); this.name = 'JWKValidationError'; } } exports.JWKValidationError = JWKValidationError; /** * Error thrown when email validation fails */ class EmailValidationError extends EmailVerificationError { constructor(message) { super(message, 'email_validation'); this.name = 'EmailValidationError'; } } exports.EmailValidationError = EmailValidationError; /** * Error thrown when DNS discovery fails */ class DNSDiscoveryError extends EmailVerificationError { constructor(message) { super(message, 'dns_discovery'); this.name = 'DNSDiscoveryError'; } } exports.DNSDiscoveryError = DNSDiscoveryError; /** * Error thrown when JWKS fetching fails */ class JWKSFetchError extends EmailVerificationError { constructor(message) { super(message, 'jwks_fetch'); this.name = 'JWKSFetchError'; } } exports.JWKSFetchError = JWKSFetchError; //# sourceMappingURL=errors.js.map