@buun_group/destroy-network-sdk
v1.0.3
Published
Official TypeScript SDK for DESTROY.NETWORK — privacy-first disposable email service
Maintainers
Readme
@buun_group/destroy-network-sdk
Official TypeScript SDK for DESTROY.NETWORK — a privacy-first disposable email service.
Installation
npm install @buun_group/destroy-network-sdkQuick Start
import { DestroyNetwork } from '@buun_group/destroy-network-sdk';
// Reads DESTROY_NETWORK_API_KEY from environment automatically
const client = new DestroyNetwork();
// Or provide explicitly
const client = new DestroyNetwork({
apiKey: 'sk_live_abc123...',
});Usage
Inboxes
// Create a disposable inbox
const inbox = await client.inboxes.create({
domain: '748392.best',
customName: 'my-temp',
});
console.log(inbox.address); // [email protected]
// List messages (paginated)
const page = await client.inboxes.listMessages(inbox.id, { limit: 10 });
console.log(`${page.pagination.total} messages`);
// Auto-paginate through all messages
for await (const msg of client.inboxes.listMessagesAutoPaging(inbox.id)) {
console.log(msg.subject, msg.from);
}
// Get full message content
const message = await client.inboxes.getMessage(inbox.id, 'msg_123');
console.log(message.bodyText);
console.log(message.bodyHtml);
// Download attachment
const response = await client.inboxes.downloadAttachment(inbox.id, 'msg_123', 'att_456');
const blob = await response.blob();
// Extend inbox lifetime
await client.inboxes.extend(inbox.id);
// Delete inbox
await client.inboxes.delete(inbox.id);User Account
// Get current user profile
const user = await client.user.me();
console.log(user.email, user.subscriptionTier);
// Get user stats
const stats = await client.user.stats();
console.log(`${stats.messages.total} emails received`);
// List all inboxes
const inboxes = await client.user.listInboxes();Teams (Business Plan)
// Create a team
const team = await client.teams.create({ name: 'Engineering' });
// Invite a member
await client.teams.invite(team.id, { email: '[email protected]' });
// Share an inbox with the team
await client.teams.shareInbox(team.id, { inboxId: inbox.id });
// List team inboxes
const shared = await client.teams.listInboxes(team.id);Labels (Pro/Business)
// Create a label
const label = await client.labels.create({ name: 'Important', color: '#ff0000' });
// Add label to a message
await client.labels.addToMessage('msg_123', label.id);Inbox Rules (Pro/Business)
// Auto-forward emails from a specific sender
await client.inboxRules.create({
name: 'Forward GitHub',
fromPattern: '*@github.com',
action: 'forward',
actionValue: '[email protected]',
});Webhooks
// Create a webhook for new messages
const webhook = await client.webhooks.create({
url: 'https://example.com/webhook',
events: ['message.received', 'inbox.expired'],
});
console.log(webhook.secret); // Store this — only returned once
// Test webhook delivery
await client.webhooks.test(webhook.id);Custom Domains
// Add a custom domain
const domain = await client.domains.add({ domain: 'mail.example.com' });
// Verify DNS records
const txt = await client.domains.verifyTxt(domain.id);
const mx = await client.domains.verifyMx(domain.id);Billing
// Create a checkout session for upgrading
const { url } = await client.billing.createCheckout({
plan: 'pro',
interval: 'monthly',
});
// Redirect user to `url`
// Check subscription status
const sub = await client.billing.getSubscription();
console.log(sub.plan, sub.status);Error Handling
All errors extend APIError with typed subclasses:
import {
DestroyNetwork,
NotFoundError,
RateLimitError,
AuthenticationError,
} from '@buun_group/destroy-network-sdk';
try {
await client.inboxes.get('nonexistent');
} catch (error) {
if (error instanceof NotFoundError) {
console.log('Inbox not found');
} else if (error instanceof RateLimitError) {
console.log(`Retry after ${error.retryAfter}s`);
} else if (error instanceof AuthenticationError) {
console.log('Invalid API key');
}
}Configuration
const client = new DestroyNetwork({
// API key (default: reads DESTROY_NETWORK_API_KEY env var)
apiKey: 'sk_live_...',
// Base URL (default: https://destroy.network)
baseURL: 'https://destroy.network',
// Request timeout in ms (default: 30000)
timeout: 30000,
// Retry config
retry: {
maxRetries: 2, // default: 2
initialDelayMs: 500, // default: 500
maxDelayMs: 8000, // default: 8000
backoffMultiplier: 2, // default: 2
},
// Custom fetch implementation
fetch: customFetch,
});Requirements
- Node.js >= 18 (or any runtime with global
fetch) - TypeScript >= 5.0 (optional, for type safety)
License
MIT
