@geekmidas/emailkit 0.0.2 → 0.0.4
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/dist/__tests__/client.spec.d.cts +1 -0
- package/dist/__tests__/client.spec.d.mts +1 -0
- package/dist/client-CEgPwECo.d.mts +18 -0
- package/dist/client-Dm7WOF9y.d.cts +18 -0
- package/dist/client.d.cts +3 -0
- package/dist/client.d.mts +3 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/types-BQX9cJo1.d.cts +78 -0
- package/dist/types-DSf2ldGX.d.mts +78 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/package.json +3 -3
- package/src/client.ts +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EmailClient, EmailClientConfig, EmailOptions, SendOptions, SendResult, TemplateNames, TemplatePropsFor, TemplateRecord } from "./types-DSf2ldGX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/client.d.ts
|
|
4
|
+
declare class SMTPClient<T extends TemplateRecord> implements EmailClient<T> {
|
|
5
|
+
private transporter;
|
|
6
|
+
private config;
|
|
7
|
+
constructor(config: EmailClientConfig<T>);
|
|
8
|
+
send(options: SendOptions): Promise<SendResult>;
|
|
9
|
+
sendTemplate<K extends TemplateNames<T>>(template: K, options: Omit<EmailOptions, 'template'> & {
|
|
10
|
+
props: TemplatePropsFor<T, K>;
|
|
11
|
+
}): Promise<SendResult>;
|
|
12
|
+
verify(): Promise<boolean>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
getTemplateNames(): TemplateNames<T>[];
|
|
15
|
+
}
|
|
16
|
+
declare function createEmailClient<T extends TemplateRecord>(config: EmailClientConfig<T>): SMTPClient<T>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SMTPClient, createEmailClient };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EmailClient, EmailClientConfig, EmailOptions, SendOptions, SendResult, TemplateNames, TemplatePropsFor, TemplateRecord } from "./types-BQX9cJo1.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/client.d.ts
|
|
4
|
+
declare class SMTPClient<T extends TemplateRecord> implements EmailClient<T> {
|
|
5
|
+
private transporter;
|
|
6
|
+
private config;
|
|
7
|
+
constructor(config: EmailClientConfig<T>);
|
|
8
|
+
send(options: SendOptions): Promise<SendResult>;
|
|
9
|
+
sendTemplate<K extends TemplateNames<T>>(template: K, options: Omit<EmailOptions, 'template'> & {
|
|
10
|
+
props: TemplatePropsFor<T, K>;
|
|
11
|
+
}): Promise<SendResult>;
|
|
12
|
+
verify(): Promise<boolean>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
getTemplateNames(): TemplateNames<T>[];
|
|
15
|
+
}
|
|
16
|
+
declare function createEmailClient<T extends TemplateRecord>(config: EmailClientConfig<T>): SMTPClient<T>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SMTPClient, createEmailClient };
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendResult } from "./types-BQX9cJo1.cjs";
|
|
2
|
+
import { SMTPClient, createEmailClient } from "./client-Dm7WOF9y.cjs";
|
|
3
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPClient, SMTPConfig, SendResult, createEmailClient };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendResult } from "./types-DSf2ldGX.mjs";
|
|
2
|
+
import { SMTPClient, createEmailClient } from "./client-CEgPwECo.mjs";
|
|
3
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPClient, SMTPConfig, SendResult, createEmailClient };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Address } from "nodemailer/lib/mailer";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
interface EmailOptions {
|
|
6
|
+
from: string | Address;
|
|
7
|
+
to: string | string[] | Address[];
|
|
8
|
+
cc?: string | string[] | Address[];
|
|
9
|
+
bcc?: string | string[] | Address[];
|
|
10
|
+
subject: string;
|
|
11
|
+
replyTo?: string | Address;
|
|
12
|
+
attachments?: Attachment[];
|
|
13
|
+
}
|
|
14
|
+
interface Attachment {
|
|
15
|
+
filename: string;
|
|
16
|
+
content?: string | Buffer;
|
|
17
|
+
path?: string;
|
|
18
|
+
contentType?: string;
|
|
19
|
+
cid?: string;
|
|
20
|
+
}
|
|
21
|
+
interface PlainEmailOptions extends EmailOptions {
|
|
22
|
+
text?: string;
|
|
23
|
+
html?: string;
|
|
24
|
+
}
|
|
25
|
+
type SendOptions = Omit<PlainEmailOptions, 'from'> & {
|
|
26
|
+
from?: string | Address;
|
|
27
|
+
};
|
|
28
|
+
interface SMTPConfig {
|
|
29
|
+
host: string;
|
|
30
|
+
port: number;
|
|
31
|
+
secure?: boolean;
|
|
32
|
+
auth?: {
|
|
33
|
+
user: string;
|
|
34
|
+
pass: string;
|
|
35
|
+
};
|
|
36
|
+
tls?: {
|
|
37
|
+
rejectUnauthorized?: boolean;
|
|
38
|
+
servername?: string;
|
|
39
|
+
};
|
|
40
|
+
pool?: boolean;
|
|
41
|
+
maxConnections?: number;
|
|
42
|
+
maxMessages?: number;
|
|
43
|
+
rateLimit?: number;
|
|
44
|
+
logger?: boolean;
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface SendResult {
|
|
48
|
+
messageId: string;
|
|
49
|
+
accepted: string[];
|
|
50
|
+
rejected: string[];
|
|
51
|
+
response: string;
|
|
52
|
+
}
|
|
53
|
+
interface EmailTemplate<T = any> {
|
|
54
|
+
(props: T): ReactElement;
|
|
55
|
+
}
|
|
56
|
+
type TemplateProps<T> = T extends EmailTemplate<infer P> ? P : never;
|
|
57
|
+
type TemplateRecord = Record<string, EmailTemplate<any>>;
|
|
58
|
+
type TemplateNames<T extends TemplateRecord> = keyof T;
|
|
59
|
+
type TemplatePropsFor<T extends TemplateRecord, K extends TemplateNames<T>> = TemplateProps<T[K]>;
|
|
60
|
+
interface EmailClientConfig<T extends TemplateRecord = TemplateRecord> {
|
|
61
|
+
smtp: SMTPConfig;
|
|
62
|
+
templates: T;
|
|
63
|
+
defaults: {
|
|
64
|
+
from?: string | Address;
|
|
65
|
+
replyTo?: string | Address;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface EmailClient<T extends TemplateRecord = TemplateRecord> {
|
|
69
|
+
send(options: SendOptions): Promise<SendResult>;
|
|
70
|
+
sendTemplate<K extends TemplateNames<T>>(template: K, options: Omit<EmailOptions, 'from'> & {
|
|
71
|
+
from?: string | Address;
|
|
72
|
+
props: TemplatePropsFor<T, K>;
|
|
73
|
+
}): Promise<SendResult>;
|
|
74
|
+
verify(): Promise<boolean>;
|
|
75
|
+
close(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { Address } from "nodemailer/lib/mailer";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
interface EmailOptions {
|
|
6
|
+
from: string | Address;
|
|
7
|
+
to: string | string[] | Address[];
|
|
8
|
+
cc?: string | string[] | Address[];
|
|
9
|
+
bcc?: string | string[] | Address[];
|
|
10
|
+
subject: string;
|
|
11
|
+
replyTo?: string | Address;
|
|
12
|
+
attachments?: Attachment[];
|
|
13
|
+
}
|
|
14
|
+
interface Attachment {
|
|
15
|
+
filename: string;
|
|
16
|
+
content?: string | Buffer;
|
|
17
|
+
path?: string;
|
|
18
|
+
contentType?: string;
|
|
19
|
+
cid?: string;
|
|
20
|
+
}
|
|
21
|
+
interface PlainEmailOptions extends EmailOptions {
|
|
22
|
+
text?: string;
|
|
23
|
+
html?: string;
|
|
24
|
+
}
|
|
25
|
+
type SendOptions = Omit<PlainEmailOptions, 'from'> & {
|
|
26
|
+
from?: string | Address;
|
|
27
|
+
};
|
|
28
|
+
interface SMTPConfig {
|
|
29
|
+
host: string;
|
|
30
|
+
port: number;
|
|
31
|
+
secure?: boolean;
|
|
32
|
+
auth?: {
|
|
33
|
+
user: string;
|
|
34
|
+
pass: string;
|
|
35
|
+
};
|
|
36
|
+
tls?: {
|
|
37
|
+
rejectUnauthorized?: boolean;
|
|
38
|
+
servername?: string;
|
|
39
|
+
};
|
|
40
|
+
pool?: boolean;
|
|
41
|
+
maxConnections?: number;
|
|
42
|
+
maxMessages?: number;
|
|
43
|
+
rateLimit?: number;
|
|
44
|
+
logger?: boolean;
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface SendResult {
|
|
48
|
+
messageId: string;
|
|
49
|
+
accepted: string[];
|
|
50
|
+
rejected: string[];
|
|
51
|
+
response: string;
|
|
52
|
+
}
|
|
53
|
+
interface EmailTemplate<T = any> {
|
|
54
|
+
(props: T): ReactElement;
|
|
55
|
+
}
|
|
56
|
+
type TemplateProps<T> = T extends EmailTemplate<infer P> ? P : never;
|
|
57
|
+
type TemplateRecord = Record<string, EmailTemplate<any>>;
|
|
58
|
+
type TemplateNames<T extends TemplateRecord> = keyof T;
|
|
59
|
+
type TemplatePropsFor<T extends TemplateRecord, K extends TemplateNames<T>> = TemplateProps<T[K]>;
|
|
60
|
+
interface EmailClientConfig<T extends TemplateRecord = TemplateRecord> {
|
|
61
|
+
smtp: SMTPConfig;
|
|
62
|
+
templates: T;
|
|
63
|
+
defaults: {
|
|
64
|
+
from?: string | Address;
|
|
65
|
+
replyTo?: string | Address;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface EmailClient<T extends TemplateRecord = TemplateRecord> {
|
|
69
|
+
send(options: SendOptions): Promise<SendResult>;
|
|
70
|
+
sendTemplate<K extends TemplateNames<T>>(template: K, options: Omit<EmailOptions, 'from'> & {
|
|
71
|
+
from?: string | Address;
|
|
72
|
+
props: TemplatePropsFor<T, K>;
|
|
73
|
+
}): Promise<SendResult>;
|
|
74
|
+
verify(): Promise<boolean>;
|
|
75
|
+
close(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord };
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord } from "./types-BQX9cJo1.cjs";
|
|
2
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord } from "./types-DSf2ldGX.mjs";
|
|
2
|
+
export { Attachment, EmailClient, EmailClientConfig, EmailOptions, EmailTemplate, PlainEmailOptions, SMTPConfig, SendOptions, SendResult, TemplateNames, TemplateProps, TemplatePropsFor, TemplateRecord };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/emailkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Type-safe email client with SMTP support and React templates",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./*": {
|
|
9
|
+
"types": "./dist/*.d.ts",
|
|
9
10
|
"import": "./dist/*.mjs",
|
|
10
|
-
"require": "./dist/*.cjs"
|
|
11
|
-
"types": "./src/*.ts"
|
|
11
|
+
"require": "./dist/*.cjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
package/src/client.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
EmailClient,
|
|
5
5
|
EmailClientConfig,
|
|
6
6
|
EmailOptions,
|
|
7
|
-
|
|
7
|
+
SendOptions,
|
|
8
8
|
SendResult,
|
|
9
9
|
TemplateNames,
|
|
10
10
|
TemplatePropsFor,
|
|
@@ -20,7 +20,7 @@ export class SMTPClient<T extends TemplateRecord> implements EmailClient<T> {
|
|
|
20
20
|
this.transporter = nodemailer.createTransport(config.smtp as any);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async send(options:
|
|
23
|
+
async send(options: SendOptions): Promise<SendResult> {
|
|
24
24
|
const mailOptions = {
|
|
25
25
|
...this.config.defaults,
|
|
26
26
|
...options,
|