npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codepunter-labs/mock-mail

v0.2.0

Published

TODO

Readme

@codepunter-labs/mock-mail

Mock SDK for email APIs. Provides fully-typed mock implementations for testing email sending, templates, status tracking, and webhooks without making real API calls.

npm version GitHub

Installation

npm install @codepunter-labs/mock-mail

Features

  • Send Email: Send direct emails and template-based emails
  • Email Status: Track email delivery status
  • Templates: Create and manage email templates
  • Webhooks: Verify webhook signatures and parse events
  • Type-safe: Full TypeScript support with accurate API types
  • Test Framework Agnostic: Works with Jest, Vitest, and other spy-based frameworks

Repository

  • GitHub: https://github.com/DERRICK-TORKORNOO/mock-sdks/tree/main/packages/mock-mail
  • Source Code: src/
  • Tests: tests/

Usage

Basic Setup

import { vi } from 'vitest';
import { createMockMail } from '@codepunter-labs/mock-mail';

const mail = createMockMail({ spy: vi.fn });

Using with Jest

import { createMockMail } from '@codepunter-labs/mock-mail';

const mail = createMockMail({ spy: jest.fn });

Example: Send Email

// Default behavior - returns realistic mock data
const result = await mail.sendEmail({
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Test Email',
  html: '<p>Hello World</p>'
});

Example: Send Template Email

const result = await mail.sendTemplateEmail({
  templateId: 'tpl_123',
  to: '[email protected]',
  variables: { name: 'John' }
});

Example: Get Email Status

const result = await mail.getEmailStatus('msg_123');

Example: Override Mock Response

import { makeSendEmailResponse } from '@codepunter-labs/mock-mail';

mail.sendEmail.mockResolvedValue({
  success: true,
  message: 'Email sent successfully',
  data: makeSendEmailResponse({ status: 'sent' })
});

Example: Error Simulation

import { MailErrors } from '@codepunter-labs/mock-mail';

mail.sendEmail.mockRejectedValue(
  MailErrors.invalidEmail()
);

Example: Webhook Verification

const isValid = mail.verifyWebhookSignature(
  payload,
  signature,
  'webhook-secret'
);

const event = mail.parseWebhookEvent(payload);

API Reference

MockMail

| Method | Description | Source | |--------|-------------|--------| | sendEmail(request) | Send email | mock-mail.ts | | sendTemplateEmail(request) | Send template email | mock-mail.ts | | getEmailStatus(messageId) | Get email status | mock-mail.ts | | listEmailStatuses(options?) | List email statuses | mock-mail.ts | | createTemplate(request) | Create email template | mock-mail.ts | | getTemplate(templateId) | Get template details | mock-mail.ts | | listTemplates() | List all templates | mock-mail.ts | | verifyWebhookSignature(payload, signature, secret) | Verify webhook signature | mock-mail.ts | | parseWebhookEvent(payload) | Parse webhook event | mock-mail.ts |

Fixture Factories

| Factory | Description | Source | |---------|-------------|--------| | makeSendEmailResponse(options?) | Create send email response | fixtures.ts | | makeEmailStatus(options?) | Create email status | fixtures.ts | | makeEmailTemplate(options?) | Create email template | fixtures.ts | | makeWebhookEvent(options?) | Create webhook event | fixtures.ts |

Error Factories

| Error | Description | Source | |-------|-------------|--------| | MailErrors.unauthorized() | Unauthorized error | errors.ts | | MailErrors.invalidEmail() | Invalid email error | errors.ts | | MailErrors.sendFailed() | Send failed error | errors.ts | | MailErrors.serverError() | Server error | errors.ts |

Testing Patterns

Test Success Path

test('should send email successfully', async () => {
  const mail = createMockMail({ spy: vi.fn });
  
  const result = await mail.sendEmail(request);
  
  expect(result.success).toBe(true);
  expect(result.data.messageId).toBeDefined();
});

Test Error Handling

test('should handle invalid email address error', async () => {
  const mail = createMockMail({ spy: vi.fn });
  
  mail.sendEmail.mockRejectedValue(
    MailErrors.invalidEmail()
  );
  
  await expect(mail.sendEmail(request)).rejects.toMatchObject({ message: /Invalid email/ });
});

Test with Custom Data

test('should use custom email status', async () => {
  const mail = createMockMail({ spy: vi.fn });
  
  mail.sendEmail.mockResolvedValue({
    success: true,
    message: 'Email sent successfully',
    data: makeSendEmailResponse({ status: 'delivered' })
  });
  
  const result = await mail.sendEmail(request);
  expect(result.data.status).toBe('delivered');
});

Test Webhook

test('should verify webhook signature', () => {
  const mail = createMockMail({ spy: vi.fn });
  
  const isValid = mail.verifyWebhookSignature(
    '{"event":"delivered"}',
    'signature',
    'secret'
  );
  
  expect(isValid).toBe(true);
});

License

MIT