A comprehensive messaging library for Email, SMS, and Push notifications
npm install @nuvix/messagingA comprehensive messaging library for Email, SMS, and Push notifications with support for multiple service providers.
- Mailgun - Email delivery service
- SendGrid - Email delivery platform
- SMTP - Generic SMTP support
- Twilio - SMS and communication APIs
- Vonage (formerly Nexmo) - Global communications platform
- Msg91 - SMS and communication platform
- Telesign - Customer verification platform
- TextMagic - SMS marketing platform
- FCM (Firebase Cloud Messaging) - Google's messaging solution
- APNS (Apple Push Notification Service) - Apple's push notification service
``bash`
bun install
This library includes comprehensive tests for all adapters using real API credentials. Tests are designed to work with actual services to ensure reliability.
1. Copy the example environment file:
`bash`
cp .env.example .env
2. Configure your credentials in .env:
`bash
# Example for Mailgun
MAILGUN_API_KEY=key-1234567890abcdef
MAILGUN_DOMAIN=mg.yourdomain.com
MAILGUN_IS_EU=false
# Example for Twilio
TWILIO_ACCOUNT_SID=AC1234567890abcdef
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_FROM=+1234567890
# Add other service credentials as needed
`
3. Alternatively, configure credentials in test.config.ts:
`typescript`
export const testConfig: TestConfig = {
mailgun: {
apiKey: "your-actual-api-key",
domain: "your-domain.com",
isEU: false,
testEmail: "test@yourdomain.com",
},
// ... other configurations
};
`bashRun all tests
bun test
$3
- Configured Services: Tests will run with real API calls for services with valid credentials
- Unconfigured Services: Tests will be automatically skipped with helpful messages
- Real API Calls: Tests use actual service APIs to ensure reliability
- Test Messages: All test messages are clearly marked and include unique identifiers
$3
`
๐งช Starting Nuvix Messaging Adapter Tests
๐ Test Configuration Summary:
โ
Configured services: mailgun, twilio, fcm
โ ๏ธ Unconfigured services (will be skipped): sendgrid, vonage, msg91, telesign, textmagic, apns
๐ก To test these services, configure credentials in test.config.ts or environment variablesโ
Mailgun text email sent successfully
โ
Twilio SMS sent successfully
โ
FCM push notification sent successfully
โญ๏ธ Skipping SendGrid tests: credentials not configured
`Usage Examples
$3
`typescript
import { Mailgun } from "@nuvix/messaging/adapter/Email/Mailgun";
import { Email } from "@nuvix/messaging/messages/Email";const adapter = new Mailgun("api-key", "domain.com");
const email = new Email({
to: ["user@example.com"],
subject: "Hello World",
content: "This is a test email",
fromName: "Your App",
fromEmail: "noreply@yourdomain.com",
});
const result = await adapter.send(email);
console.log(
Delivered to ${result.deliveredTo} recipients);
`$3
`typescript
import { Twilio } from "@nuvix/messaging/adapter/SMS/Twilio";
import { SMS } from "@nuvix/messaging/messages/SMS";const adapter = new Twilio("account-sid", "auth-token", "+1234567890");
const sms = new SMS({
to: ["+1987654321"],
content: "Hello from your app!",
});
const result = await adapter.send(sms);
`$3
`typescript
import { FCM } from "@nuvix/messaging/adapter/Push/FCM";
import { Push } from "@nuvix/messaging/messages/Push";const adapter = new FCM("service-account-json");
const push = new Push({
to: ["device-token"],
title: "New Message",
body: "You have a new notification",
data: { type: "message", id: "123" },
});
const result = await adapter.send(push);
`Development
$3
`
src/
โโโ adapter.ts # Base adapter class
โโโ response.ts # Response handling
โโโ types.ts # Type definitions
โโโ adapter/ # Adapter implementations
โ โโโ Email.ts # Email base class
โ โโโ SMS.ts # SMS base class
โ โโโ Push.ts # Push base class
โ โโโ Email/ # Email adapters
โ โโโ SMS/ # SMS adapters
โ โโโ Push/ # Push adapters
โโโ messages/ # Message classes
โ โโโ Email.ts
โ โโโ SMS.ts
โ โโโ Push.ts
โโโ helpers/ # Utility functionstests/
โโโ setup.ts # Test configuration
โโโ utils.ts # Test utilities
โโโ adapters/ # Adapter tests
โโโ email.test.ts
โโโ sms.test.ts
โโโ push.test.ts
โโโ messages.test.ts
`$3
`bash
bun run build
`$3
`bash
bun run lint
bun run lint:fix
``This project is licensed under the MIT License.
1. Fork the repository
2. Create a feature branch
3. Add tests for any new functionality
4. Ensure all tests pass with real credentials
5. Submit a pull request
- Mailgun API
- SendGrid API
- Twilio SMS API
- Vonage SMS API
- Firebase Cloud Messaging
- Apple Push Notification Service