@shogo-ai/email 1.4.1

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.
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Email Module Types
3
+ *
4
+ * Type definitions for the email system.
5
+ * Designed for simplicity - template strings with {{variable}} interpolation.
6
+ */
7
+ /**
8
+ * Email address - can be a simple string or object with name
9
+ */
10
+ type EmailAddress = string | {
11
+ email: string;
12
+ name?: string;
13
+ };
14
+ /**
15
+ * Normalize email address to string format
16
+ */
17
+ declare function formatEmailAddress(address: EmailAddress): string;
18
+ /**
19
+ * Parameters for sending an email
20
+ */
21
+ interface SendEmailParams {
22
+ /** Recipient email address(es) */
23
+ to: EmailAddress | EmailAddress[];
24
+ /** Email subject line */
25
+ subject: string;
26
+ /** HTML content of the email */
27
+ html: string;
28
+ /** Plain text content (auto-generated from HTML if not provided) */
29
+ text?: string;
30
+ /** Sender email address (uses default from config if not specified) */
31
+ from?: EmailAddress;
32
+ /** Reply-to address */
33
+ replyTo?: EmailAddress;
34
+ /** CC recipients */
35
+ cc?: EmailAddress | EmailAddress[];
36
+ /** BCC recipients */
37
+ bcc?: EmailAddress | EmailAddress[];
38
+ }
39
+ /**
40
+ * Parameters for sending a templated email
41
+ */
42
+ interface SendTemplateParams<TData extends Record<string, unknown> = Record<string, unknown>> {
43
+ /** Recipient email address(es) */
44
+ to: EmailAddress | EmailAddress[];
45
+ /** Template name */
46
+ template: string;
47
+ /** Template data for variable interpolation */
48
+ data: TData;
49
+ /** Sender email address (uses default from config if not specified) */
50
+ from?: EmailAddress;
51
+ /** Reply-to address */
52
+ replyTo?: EmailAddress;
53
+ /** CC recipients */
54
+ cc?: EmailAddress | EmailAddress[];
55
+ /** BCC recipients */
56
+ bcc?: EmailAddress | EmailAddress[];
57
+ }
58
+ /**
59
+ * Result from sending an email
60
+ */
61
+ interface EmailResult {
62
+ /** Whether the email was sent successfully */
63
+ success: boolean;
64
+ /** Message ID from the email provider (if successful) */
65
+ messageId?: string;
66
+ /** Error message (if failed) */
67
+ error?: string;
68
+ }
69
+ /**
70
+ * Supported email providers
71
+ */
72
+ type EmailProviderType = 'smtp' | 'ses' | 'oci-email';
73
+ /**
74
+ * SMTP configuration
75
+ */
76
+ interface SmtpConfig {
77
+ /** SMTP server hostname */
78
+ host: string;
79
+ /** SMTP server port */
80
+ port: number;
81
+ /** SMTP authentication username */
82
+ user: string;
83
+ /** SMTP authentication password */
84
+ password: string;
85
+ /** Use TLS/SSL (default: true for port 465, STARTTLS for others) */
86
+ secure?: boolean;
87
+ }
88
+ /**
89
+ * AWS SES configuration
90
+ */
91
+ interface SesConfig {
92
+ /** AWS region (e.g., 'us-east-1') */
93
+ region: string;
94
+ /** AWS access key ID (optional if using IAM role) */
95
+ accessKeyId?: string;
96
+ /** AWS secret access key (optional if using IAM role) */
97
+ secretAccessKey?: string;
98
+ }
99
+ /**
100
+ * OCI Email Delivery configuration (SMTP-based)
101
+ */
102
+ interface OciEmailConfig {
103
+ /** SMTP host (e.g., 'smtp.email.us-ashburn-1.oci.oraclecloud.com') */
104
+ host: string;
105
+ /** SMTP port (default: 587) */
106
+ port: number;
107
+ /** SMTP auth username (OCI SMTP credential) */
108
+ user: string;
109
+ /** SMTP auth password (OCI SMTP credential) */
110
+ password: string;
111
+ /** Default sender address */
112
+ fromAddress?: string;
113
+ }
114
+ /**
115
+ * Email provider configuration
116
+ */
117
+ interface EmailConfig {
118
+ /** Provider type */
119
+ provider: EmailProviderType;
120
+ /** Default sender email address */
121
+ defaultFrom: EmailAddress;
122
+ /** Provider-specific configuration */
123
+ smtp?: SmtpConfig;
124
+ ses?: SesConfig;
125
+ ociEmail?: OciEmailConfig;
126
+ }
127
+ /**
128
+ * Email template definition
129
+ */
130
+ interface EmailTemplate<TData extends Record<string, unknown> = Record<string, unknown>> {
131
+ /** Template name (identifier) */
132
+ name: string;
133
+ /** Subject line template (supports {{variable}} interpolation) */
134
+ subject: string;
135
+ /** HTML body template (supports {{variable}} interpolation) */
136
+ html: string;
137
+ /** Plain text body template (optional, auto-generated from HTML if not provided) */
138
+ text?: string;
139
+ /** Default data values */
140
+ defaults?: Partial<TData>;
141
+ }
142
+ /**
143
+ * Template registry type
144
+ */
145
+ type TemplateRegistry = Record<string, EmailTemplate>;
146
+ /**
147
+ * Email service interface - the main API
148
+ */
149
+ interface IEmailService {
150
+ /**
151
+ * Send a raw email with explicit subject/body
152
+ */
153
+ send(params: SendEmailParams): Promise<EmailResult>;
154
+ /**
155
+ * Send a templated email
156
+ */
157
+ sendTemplate<TData extends Record<string, unknown>>(params: SendTemplateParams<TData>): Promise<EmailResult>;
158
+ /**
159
+ * Register a custom template
160
+ */
161
+ registerTemplate<TData extends Record<string, unknown>>(template: EmailTemplate<TData>): void;
162
+ /**
163
+ * Check if the service is configured and ready
164
+ */
165
+ isConfigured(): boolean;
166
+ }
167
+ /**
168
+ * Email provider interface - implemented by SMTP, SES, etc.
169
+ */
170
+ interface IEmailProvider {
171
+ /**
172
+ * Send an email via this provider
173
+ */
174
+ send(params: SendEmailParams): Promise<EmailResult>;
175
+ /**
176
+ * Check if provider is configured
177
+ */
178
+ isConfigured(): boolean;
179
+ }
180
+ /**
181
+ * Email error codes
182
+ */
183
+ type EmailErrorCode = 'config_missing' | 'connection_error' | 'authentication_error' | 'invalid_recipient' | 'send_failed' | 'template_not_found' | 'provider_not_configured';
184
+ /**
185
+ * Email error class
186
+ */
187
+ declare class EmailError extends Error {
188
+ code: EmailErrorCode;
189
+ cause?: unknown;
190
+ constructor(code: EmailErrorCode, message: string, cause?: unknown);
191
+ static configMissing(field: string): EmailError;
192
+ static templateNotFound(name: string): EmailError;
193
+ static providerNotConfigured(): EmailError;
194
+ }
195
+
196
+ export { type EmailTemplate as E, type IEmailProvider as I, type OciEmailConfig as O, type SendEmailParams as S, type TemplateRegistry as T, type EmailAddress as a, type EmailConfig as b, EmailError as c, type EmailErrorCode as d, type EmailProviderType as e, type EmailResult as f, type IEmailService as g, type SendTemplateParams as h, type SesConfig as i, type SmtpConfig as j, formatEmailAddress as k };
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Email Module Types
3
+ *
4
+ * Type definitions for the email system.
5
+ * Designed for simplicity - template strings with {{variable}} interpolation.
6
+ */
7
+ /**
8
+ * Email address - can be a simple string or object with name
9
+ */
10
+ type EmailAddress = string | {
11
+ email: string;
12
+ name?: string;
13
+ };
14
+ /**
15
+ * Normalize email address to string format
16
+ */
17
+ declare function formatEmailAddress(address: EmailAddress): string;
18
+ /**
19
+ * Parameters for sending an email
20
+ */
21
+ interface SendEmailParams {
22
+ /** Recipient email address(es) */
23
+ to: EmailAddress | EmailAddress[];
24
+ /** Email subject line */
25
+ subject: string;
26
+ /** HTML content of the email */
27
+ html: string;
28
+ /** Plain text content (auto-generated from HTML if not provided) */
29
+ text?: string;
30
+ /** Sender email address (uses default from config if not specified) */
31
+ from?: EmailAddress;
32
+ /** Reply-to address */
33
+ replyTo?: EmailAddress;
34
+ /** CC recipients */
35
+ cc?: EmailAddress | EmailAddress[];
36
+ /** BCC recipients */
37
+ bcc?: EmailAddress | EmailAddress[];
38
+ }
39
+ /**
40
+ * Parameters for sending a templated email
41
+ */
42
+ interface SendTemplateParams<TData extends Record<string, unknown> = Record<string, unknown>> {
43
+ /** Recipient email address(es) */
44
+ to: EmailAddress | EmailAddress[];
45
+ /** Template name */
46
+ template: string;
47
+ /** Template data for variable interpolation */
48
+ data: TData;
49
+ /** Sender email address (uses default from config if not specified) */
50
+ from?: EmailAddress;
51
+ /** Reply-to address */
52
+ replyTo?: EmailAddress;
53
+ /** CC recipients */
54
+ cc?: EmailAddress | EmailAddress[];
55
+ /** BCC recipients */
56
+ bcc?: EmailAddress | EmailAddress[];
57
+ }
58
+ /**
59
+ * Result from sending an email
60
+ */
61
+ interface EmailResult {
62
+ /** Whether the email was sent successfully */
63
+ success: boolean;
64
+ /** Message ID from the email provider (if successful) */
65
+ messageId?: string;
66
+ /** Error message (if failed) */
67
+ error?: string;
68
+ }
69
+ /**
70
+ * Supported email providers
71
+ */
72
+ type EmailProviderType = 'smtp' | 'ses' | 'oci-email';
73
+ /**
74
+ * SMTP configuration
75
+ */
76
+ interface SmtpConfig {
77
+ /** SMTP server hostname */
78
+ host: string;
79
+ /** SMTP server port */
80
+ port: number;
81
+ /** SMTP authentication username */
82
+ user: string;
83
+ /** SMTP authentication password */
84
+ password: string;
85
+ /** Use TLS/SSL (default: true for port 465, STARTTLS for others) */
86
+ secure?: boolean;
87
+ }
88
+ /**
89
+ * AWS SES configuration
90
+ */
91
+ interface SesConfig {
92
+ /** AWS region (e.g., 'us-east-1') */
93
+ region: string;
94
+ /** AWS access key ID (optional if using IAM role) */
95
+ accessKeyId?: string;
96
+ /** AWS secret access key (optional if using IAM role) */
97
+ secretAccessKey?: string;
98
+ }
99
+ /**
100
+ * OCI Email Delivery configuration (SMTP-based)
101
+ */
102
+ interface OciEmailConfig {
103
+ /** SMTP host (e.g., 'smtp.email.us-ashburn-1.oci.oraclecloud.com') */
104
+ host: string;
105
+ /** SMTP port (default: 587) */
106
+ port: number;
107
+ /** SMTP auth username (OCI SMTP credential) */
108
+ user: string;
109
+ /** SMTP auth password (OCI SMTP credential) */
110
+ password: string;
111
+ /** Default sender address */
112
+ fromAddress?: string;
113
+ }
114
+ /**
115
+ * Email provider configuration
116
+ */
117
+ interface EmailConfig {
118
+ /** Provider type */
119
+ provider: EmailProviderType;
120
+ /** Default sender email address */
121
+ defaultFrom: EmailAddress;
122
+ /** Provider-specific configuration */
123
+ smtp?: SmtpConfig;
124
+ ses?: SesConfig;
125
+ ociEmail?: OciEmailConfig;
126
+ }
127
+ /**
128
+ * Email template definition
129
+ */
130
+ interface EmailTemplate<TData extends Record<string, unknown> = Record<string, unknown>> {
131
+ /** Template name (identifier) */
132
+ name: string;
133
+ /** Subject line template (supports {{variable}} interpolation) */
134
+ subject: string;
135
+ /** HTML body template (supports {{variable}} interpolation) */
136
+ html: string;
137
+ /** Plain text body template (optional, auto-generated from HTML if not provided) */
138
+ text?: string;
139
+ /** Default data values */
140
+ defaults?: Partial<TData>;
141
+ }
142
+ /**
143
+ * Template registry type
144
+ */
145
+ type TemplateRegistry = Record<string, EmailTemplate>;
146
+ /**
147
+ * Email service interface - the main API
148
+ */
149
+ interface IEmailService {
150
+ /**
151
+ * Send a raw email with explicit subject/body
152
+ */
153
+ send(params: SendEmailParams): Promise<EmailResult>;
154
+ /**
155
+ * Send a templated email
156
+ */
157
+ sendTemplate<TData extends Record<string, unknown>>(params: SendTemplateParams<TData>): Promise<EmailResult>;
158
+ /**
159
+ * Register a custom template
160
+ */
161
+ registerTemplate<TData extends Record<string, unknown>>(template: EmailTemplate<TData>): void;
162
+ /**
163
+ * Check if the service is configured and ready
164
+ */
165
+ isConfigured(): boolean;
166
+ }
167
+ /**
168
+ * Email provider interface - implemented by SMTP, SES, etc.
169
+ */
170
+ interface IEmailProvider {
171
+ /**
172
+ * Send an email via this provider
173
+ */
174
+ send(params: SendEmailParams): Promise<EmailResult>;
175
+ /**
176
+ * Check if provider is configured
177
+ */
178
+ isConfigured(): boolean;
179
+ }
180
+ /**
181
+ * Email error codes
182
+ */
183
+ type EmailErrorCode = 'config_missing' | 'connection_error' | 'authentication_error' | 'invalid_recipient' | 'send_failed' | 'template_not_found' | 'provider_not_configured';
184
+ /**
185
+ * Email error class
186
+ */
187
+ declare class EmailError extends Error {
188
+ code: EmailErrorCode;
189
+ cause?: unknown;
190
+ constructor(code: EmailErrorCode, message: string, cause?: unknown);
191
+ static configMissing(field: string): EmailError;
192
+ static templateNotFound(name: string): EmailError;
193
+ static providerNotConfigured(): EmailError;
194
+ }
195
+
196
+ export { type EmailTemplate as E, type IEmailProvider as I, type OciEmailConfig as O, type SendEmailParams as S, type TemplateRegistry as T, type EmailAddress as a, type EmailConfig as b, EmailError as c, type EmailErrorCode as d, type EmailProviderType as e, type EmailResult as f, type IEmailService as g, type SendTemplateParams as h, type SesConfig as i, type SmtpConfig as j, formatEmailAddress as k };
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@shogo-ai/email",
3
+ "version": "1.4.1",
4
+ "description": "Shogo Email — multi-provider transactional email (SES, SMTP, OCI) with built-in transactional templates.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ },
17
+ "./server": {
18
+ "types": "./dist/server.d.ts",
19
+ "import": "./dist/server.js",
20
+ "require": "./dist/server.cjs"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist/**/*.js",
25
+ "dist/**/*.cjs",
26
+ "dist/**/*.d.ts",
27
+ "dist/**/*.d.cts"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "bun --no-env-file test src/"
34
+ },
35
+ "peerDependencies": {
36
+ "nodemailer": ">=6.0.0",
37
+ "@aws-sdk/client-ses": ">=3.0.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "nodemailer": {
41
+ "optional": true
42
+ },
43
+ "@aws-sdk/client-ses": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^25.5.0",
49
+ "@types/nodemailer": "^7.0.11",
50
+ "tsup": "^8.0.0",
51
+ "typescript": "^6.0.2"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "keywords": [
57
+ "shogo",
58
+ "email",
59
+ "smtp",
60
+ "ses",
61
+ "transactional",
62
+ "nodemailer"
63
+ ],
64
+ "author": "Shogo Labs",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/shogo-labs/shogo-ai.git",
68
+ "directory": "packages/email"
69
+ },
70
+ "homepage": "https://github.com/shogo-labs/shogo-ai/tree/main/packages/email#readme",
71
+ "bugs": {
72
+ "url": "https://github.com/shogo-labs/shogo-ai/issues"
73
+ }
74
+ }