@parsrun/email 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +1192 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/console.d.ts +47 -0
- package/dist/providers/console.js +126 -0
- package/dist/providers/console.js.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.js +621 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/postmark.d.ts +47 -0
- package/dist/providers/postmark.js +202 -0
- package/dist/providers/postmark.js.map +1 -0
- package/dist/providers/resend.d.ts +47 -0
- package/dist/providers/resend.js +174 -0
- package/dist/providers/resend.js.map +1 -0
- package/dist/providers/sendgrid.d.ts +47 -0
- package/dist/providers/sendgrid.js +193 -0
- package/dist/providers/sendgrid.js.map +1 -0
- package/dist/templates/index.d.ts +114 -0
- package/dist/templates/index.js +415 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/package.json +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @parsrun/email
|
|
2
|
+
|
|
3
|
+
Edge-compatible email sending for Pars with multiple provider support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-Provider**: Resend, SendGrid, Postmark
|
|
8
|
+
- **Edge-Compatible**: Works on Cloudflare Workers, Deno
|
|
9
|
+
- **Templates**: Built-in email templates
|
|
10
|
+
- **Queue Support**: Async email sending
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @parsrun/email
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { createEmailService } from '@parsrun/email';
|
|
22
|
+
|
|
23
|
+
const email = createEmailService({
|
|
24
|
+
provider: 'resend',
|
|
25
|
+
apiKey: process.env.RESEND_API_KEY,
|
|
26
|
+
from: 'noreply@example.com',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await email.send({
|
|
30
|
+
to: 'user@example.com',
|
|
31
|
+
subject: 'Welcome!',
|
|
32
|
+
html: '<h1>Hello World</h1>',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## API Overview
|
|
37
|
+
|
|
38
|
+
### Providers
|
|
39
|
+
|
|
40
|
+
#### Resend
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createResendProvider } from '@parsrun/email/providers/resend';
|
|
44
|
+
|
|
45
|
+
const provider = createResendProvider({
|
|
46
|
+
apiKey: process.env.RESEND_API_KEY,
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### SendGrid
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { createSendGridProvider } from '@parsrun/email/providers/sendgrid';
|
|
54
|
+
|
|
55
|
+
const provider = createSendGridProvider({
|
|
56
|
+
apiKey: process.env.SENDGRID_API_KEY,
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Postmark
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { createPostmarkProvider } from '@parsrun/email/providers/postmark';
|
|
64
|
+
|
|
65
|
+
const provider = createPostmarkProvider({
|
|
66
|
+
serverToken: process.env.POSTMARK_SERVER_TOKEN,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Console (Development)
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { createConsoleProvider } from '@parsrun/email/providers/console';
|
|
74
|
+
|
|
75
|
+
const provider = createConsoleProvider(); // Logs emails to console
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Email Service
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const email = createEmailService({
|
|
82
|
+
provider: resendProvider,
|
|
83
|
+
from: 'noreply@example.com',
|
|
84
|
+
replyTo: 'support@example.com',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Send simple email
|
|
88
|
+
await email.send({
|
|
89
|
+
to: 'user@example.com',
|
|
90
|
+
subject: 'Hello',
|
|
91
|
+
html: '<p>Hello World</p>',
|
|
92
|
+
text: 'Hello World',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Send with attachments
|
|
96
|
+
await email.send({
|
|
97
|
+
to: 'user@example.com',
|
|
98
|
+
subject: 'Report',
|
|
99
|
+
html: '<p>See attached</p>',
|
|
100
|
+
attachments: [
|
|
101
|
+
{
|
|
102
|
+
filename: 'report.pdf',
|
|
103
|
+
content: pdfBuffer,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Templates
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { templates } from '@parsrun/email/templates';
|
|
113
|
+
|
|
114
|
+
// OTP Email
|
|
115
|
+
const html = templates.otp({
|
|
116
|
+
code: '123456',
|
|
117
|
+
expiresIn: '10 minutes',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Welcome Email
|
|
121
|
+
const html = templates.welcome({
|
|
122
|
+
name: 'John',
|
|
123
|
+
appName: 'MyApp',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Magic Link
|
|
127
|
+
const html = templates.magicLink({
|
|
128
|
+
url: 'https://app.example.com/verify?token=...',
|
|
129
|
+
expiresIn: '15 minutes',
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Exports
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { ... } from '@parsrun/email'; // Main exports
|
|
137
|
+
import { ... } from '@parsrun/email/providers/resend'; // Resend
|
|
138
|
+
import { ... } from '@parsrun/email/providers/sendgrid'; // SendGrid
|
|
139
|
+
import { ... } from '@parsrun/email/providers/postmark'; // Postmark
|
|
140
|
+
import { ... } from '@parsrun/email/templates'; // Email templates
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { EmailServiceConfig, EmailProviderType, EmailOptions, EmailResult, BatchEmailOptions, BatchEmailResult, EmailProviderConfig, EmailProvider } from './types.js';
|
|
2
|
+
export { EmailAddress, EmailAttachment, EmailError, EmailErrorCodes, EmailTemplate, TemplateData } from './types.js';
|
|
3
|
+
export { ResendProvider, createResendProvider } from './providers/resend.js';
|
|
4
|
+
export { SendGridProvider, createSendGridProvider } from './providers/sendgrid.js';
|
|
5
|
+
export { PostmarkProvider, createPostmarkProvider } from './providers/postmark.js';
|
|
6
|
+
export { ConsoleProvider, createConsoleProvider } from './providers/console.js';
|
|
7
|
+
export { InvitationTemplateData, MagicLinkTemplateData, OTPTemplateData, PasswordResetTemplateData, VerificationTemplateData, WelcomeTemplateData, invitationTemplate, magicLinkTemplate, otpTemplate, passwordResetTemplate, renderFunctions, renderInvitationEmail, renderMagicLinkEmail, renderOTPEmail, renderPasswordResetEmail, renderTemplate, renderVerificationEmail, renderWelcomeEmail, templates, verificationTemplate, welcomeTemplate, wrapEmailHtml } from './templates/index.js';
|
|
8
|
+
export { EmailConfig, EmailSendResult, EmailAddress as ParsEmailAddress, EmailAttachment as ParsEmailAttachment, PostmarkConfig, ResendConfig, SendEmailOptions, SendTemplateEmailOptions, SendgridConfig, SesConfig, SmtpConfig, emailAddress, emailAttachment, emailConfig, emailSendResult, postmarkConfig, resendConfig, sendEmailOptions, sendTemplateEmailOptions, sendgridConfig, sesConfig, smtpConfig, type } from '@parsrun/types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @parsrun/email
|
|
12
|
+
* Edge-compatible email sending for Pars
|
|
13
|
+
*
|
|
14
|
+
* Supports multiple providers:
|
|
15
|
+
* - Resend (recommended)
|
|
16
|
+
* - SendGrid
|
|
17
|
+
* - Postmark
|
|
18
|
+
* - Console (development)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createEmailService } from '@parsrun/email';
|
|
23
|
+
*
|
|
24
|
+
* const email = createEmailService({
|
|
25
|
+
* provider: 'resend',
|
|
26
|
+
* apiKey: process.env.RESEND_API_KEY,
|
|
27
|
+
* fromEmail: 'hello@example.com',
|
|
28
|
+
* fromName: 'My App',
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await email.send({
|
|
32
|
+
* to: 'user@example.com',
|
|
33
|
+
* subject: 'Hello',
|
|
34
|
+
* html: '<p>Hello World!</p>',
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Email Service
|
|
41
|
+
* High-level email service with provider abstraction
|
|
42
|
+
*/
|
|
43
|
+
declare class EmailService {
|
|
44
|
+
private provider;
|
|
45
|
+
private debug;
|
|
46
|
+
constructor(config: EmailServiceConfig);
|
|
47
|
+
private createProvider;
|
|
48
|
+
/**
|
|
49
|
+
* Get the provider type
|
|
50
|
+
*/
|
|
51
|
+
get providerType(): EmailProviderType;
|
|
52
|
+
/**
|
|
53
|
+
* Send a single email
|
|
54
|
+
*/
|
|
55
|
+
send(options: EmailOptions): Promise<EmailResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Send multiple emails
|
|
58
|
+
*/
|
|
59
|
+
sendBatch(options: BatchEmailOptions): Promise<BatchEmailResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Verify provider configuration
|
|
62
|
+
*/
|
|
63
|
+
verify(): Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create an email service
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // With Resend
|
|
71
|
+
* const email = createEmailService({
|
|
72
|
+
* provider: 'resend',
|
|
73
|
+
* apiKey: process.env.RESEND_API_KEY,
|
|
74
|
+
* fromEmail: 'hello@example.com',
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // With SendGrid
|
|
78
|
+
* const email = createEmailService({
|
|
79
|
+
* provider: 'sendgrid',
|
|
80
|
+
* apiKey: process.env.SENDGRID_API_KEY,
|
|
81
|
+
* fromEmail: 'hello@example.com',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // For development
|
|
85
|
+
* const email = createEmailService({
|
|
86
|
+
* provider: 'console',
|
|
87
|
+
* apiKey: 'not-needed',
|
|
88
|
+
* fromEmail: 'test@example.com',
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function createEmailService(config: EmailServiceConfig): EmailService;
|
|
93
|
+
/**
|
|
94
|
+
* Create an email provider directly
|
|
95
|
+
*/
|
|
96
|
+
declare function createEmailProvider(type: EmailProviderType, config: EmailProviderConfig): EmailProvider;
|
|
97
|
+
declare const _default: {
|
|
98
|
+
EmailService: typeof EmailService;
|
|
99
|
+
createEmailService: typeof createEmailService;
|
|
100
|
+
createEmailProvider: typeof createEmailProvider;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { BatchEmailOptions, BatchEmailResult, EmailOptions, EmailProvider, EmailProviderConfig, EmailProviderType, EmailResult, EmailService, EmailServiceConfig, createEmailProvider, createEmailService, _default as default };
|