@brilab-mailer/contracts 0.0.1-beta.44 → 0.0.1-beta.45
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/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/lib/mailer-messages.d.ts +59 -0
- package/lib/mailer-messages.d.ts.map +1 -0
- package/lib/mailer-messages.js +117 -0
- package/lib/mailer-provider.d.ts +4 -4
- package/lib/mailer-provider.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/mailer-message-builder.d.ts +0 -58
- package/lib/mailer-message-builder.d.ts.map +0 -1
- package/lib/mailer-message-builder.js +0 -60
package/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from './lib/mailer-contracts.js';
|
|
|
2
2
|
export * from './lib/mailer-provider.js';
|
|
3
3
|
export * from './lib/mailer-templates.js';
|
|
4
4
|
export * from './lib/mailer-config-properties.js';
|
|
5
|
-
export * from './lib/mailer-
|
|
5
|
+
export * from './lib/mailer-messages.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC"}
|
package/index.js
CHANGED
|
@@ -2,4 +2,4 @@ export * from './lib/mailer-contracts.js';
|
|
|
2
2
|
export * from './lib/mailer-provider.js';
|
|
3
3
|
export * from './lib/mailer-templates.js';
|
|
4
4
|
export * from './lib/mailer-config-properties.js';
|
|
5
|
-
export * from './lib/mailer-
|
|
5
|
+
export * from './lib/mailer-messages.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type MailerSender = {
|
|
2
|
+
email: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
};
|
|
5
|
+
type MailerRecipient = {
|
|
6
|
+
email: string;
|
|
7
|
+
};
|
|
8
|
+
export type MailerMessagesBuilderDraft = {
|
|
9
|
+
from?: MailerSender;
|
|
10
|
+
to?: MailerRecipient[];
|
|
11
|
+
subject?: string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
meta: Record<string, any>;
|
|
14
|
+
text?: string | Buffer;
|
|
15
|
+
html?: string | Buffer;
|
|
16
|
+
};
|
|
17
|
+
export type MailerMessagesContent = {
|
|
18
|
+
kind: 'text';
|
|
19
|
+
text: string | Buffer;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'html';
|
|
22
|
+
html: string | Buffer;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'mixed';
|
|
25
|
+
text?: string | Buffer;
|
|
26
|
+
html?: string | Buffer;
|
|
27
|
+
};
|
|
28
|
+
export type MailerMessagesResolved = Omit<MailerMessagesBuilderDraft, 'text' | 'html' | 'from' | 'to'> & {
|
|
29
|
+
from: MailerSender;
|
|
30
|
+
to: MailerRecipient[];
|
|
31
|
+
subject: string;
|
|
32
|
+
content: MailerMessagesContent;
|
|
33
|
+
};
|
|
34
|
+
export declare class MailerMessagesBuilder {
|
|
35
|
+
private readonly draft;
|
|
36
|
+
protected generateDraft(): MailerMessagesBuilderDraft;
|
|
37
|
+
protected prepare(): MailerMessagesResolved;
|
|
38
|
+
setFrom(email: MailerSender["email"], name?: MailerSender['name']): this;
|
|
39
|
+
setFrom(from: MailerSender): this;
|
|
40
|
+
private resolveRecipientToItem;
|
|
41
|
+
addTo(email: MailerRecipient["email"]): this;
|
|
42
|
+
addTo(emails: MailerRecipient["email"][]): this;
|
|
43
|
+
addTo(recipient: MailerRecipient): this;
|
|
44
|
+
addTo(recipients: MailerRecipient[]): this;
|
|
45
|
+
setTo(email: MailerRecipient["email"]): this;
|
|
46
|
+
setTo(emails: MailerRecipient["email"][]): this;
|
|
47
|
+
setTo(recipient: MailerRecipient): this;
|
|
48
|
+
setTo(recipients: MailerRecipient[]): this;
|
|
49
|
+
setSubject(subject: string): this;
|
|
50
|
+
setText(text: string | Buffer): this;
|
|
51
|
+
setHtml(html: string | Buffer): this;
|
|
52
|
+
}
|
|
53
|
+
export declare const normalizeDataBodyString: <Body extends string | Buffer>(body?: Body) => string;
|
|
54
|
+
export declare const segmentedDataContentPayload: <Response extends Base, Keys extends {
|
|
55
|
+
text: keyof Response;
|
|
56
|
+
html: keyof Response;
|
|
57
|
+
}, Base extends Partial<Response> = Partial<Response>>(resolved: MailerMessagesResolved, keys: Keys | null, normalizer: null | (<Body extends string | Buffer>(body?: Body) => string), base?: Base) => Response;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=mailer-messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailer-messages.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-messages.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAA;AAED,KAAK,eAAe,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,IA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const draft = this.generateDraft();
|
|
12
|
+
if (!draft.from?.email)
|
|
13
|
+
throw new Error('from.email is required');
|
|
14
|
+
if (!draft.to?.length)
|
|
15
|
+
throw new Error('to[] required');
|
|
16
|
+
if (!draft.subject)
|
|
17
|
+
throw new Error('subject required');
|
|
18
|
+
const text = typeof draft.text === 'string' ? draft.text : draft.text?.toString();
|
|
19
|
+
const html = typeof draft.html === 'string' ? draft.html : draft.html?.toString();
|
|
20
|
+
const content = text && html
|
|
21
|
+
? { kind: 'mixed', text, html }
|
|
22
|
+
: html
|
|
23
|
+
? { kind: 'html', html }
|
|
24
|
+
: { kind: 'text', text: text };
|
|
25
|
+
return {
|
|
26
|
+
...draft,
|
|
27
|
+
from: draft.from,
|
|
28
|
+
to: draft.to,
|
|
29
|
+
subject: draft.subject,
|
|
30
|
+
content,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
setFrom(fromOrEmail, name) {
|
|
34
|
+
const fromEmail = typeof fromOrEmail === 'string' ? fromOrEmail : fromOrEmail.email;
|
|
35
|
+
const fromName = typeof fromOrEmail === 'string' ? name : fromOrEmail.name;
|
|
36
|
+
this.draft.from = {
|
|
37
|
+
email: fromEmail,
|
|
38
|
+
name: fromName
|
|
39
|
+
};
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
resolveRecipientToItem(emailOrRecipient) {
|
|
43
|
+
if (typeof emailOrRecipient === 'string')
|
|
44
|
+
return { email: emailOrRecipient };
|
|
45
|
+
return emailOrRecipient;
|
|
46
|
+
}
|
|
47
|
+
addTo(input) {
|
|
48
|
+
const prevTo = this.draft.to || [];
|
|
49
|
+
const newTo = (() => {
|
|
50
|
+
const isArr = Array.isArray(input);
|
|
51
|
+
const recipients = isArr
|
|
52
|
+
? input.map(this.resolveRecipientToItem)
|
|
53
|
+
: [this.resolveRecipientToItem(input)];
|
|
54
|
+
const remaining = [];
|
|
55
|
+
for (const r of recipients) {
|
|
56
|
+
const idx = prevTo.findIndex(p => p.email === r.email);
|
|
57
|
+
if (idx !== -1) {
|
|
58
|
+
prevTo[idx] = { ...prevTo[idx], ...r };
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
remaining.push(r);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return remaining;
|
|
65
|
+
})();
|
|
66
|
+
this.draft.to = [...prevTo, ...newTo];
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
setTo(input) {
|
|
70
|
+
const isArr = Array.isArray(input);
|
|
71
|
+
this.draft.to = isArr
|
|
72
|
+
? input.map(this.resolveRecipientToItem)
|
|
73
|
+
: [this.resolveRecipientToItem(input)];
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
setSubject(subject) {
|
|
77
|
+
this.draft.subject = subject;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
setText(text) {
|
|
81
|
+
this.draft.text = text;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
setHtml(html) {
|
|
85
|
+
this.draft.html = html;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export const normalizeDataBodyString = (body) => {
|
|
90
|
+
if (!body)
|
|
91
|
+
return '';
|
|
92
|
+
if (typeof body === 'string')
|
|
93
|
+
return body;
|
|
94
|
+
return body.toString();
|
|
95
|
+
};
|
|
96
|
+
export const segmentedDataContentPayload = (resolved, keys, normalizer, base = {}) => {
|
|
97
|
+
const { text: keyText, html: keyHtml } = keys || { text: 'text', html: 'html' };
|
|
98
|
+
const normalize = normalizer || normalizeDataBodyString;
|
|
99
|
+
switch (resolved.content.kind) {
|
|
100
|
+
case 'text':
|
|
101
|
+
return { ...base, [keyText]: normalize(resolved.content.text) };
|
|
102
|
+
case 'html':
|
|
103
|
+
return { ...base, [keyHtml]: normalize(resolved.content.html) };
|
|
104
|
+
case 'mixed':
|
|
105
|
+
return {
|
|
106
|
+
...base,
|
|
107
|
+
[keyText]: normalize(resolved.content.text),
|
|
108
|
+
[keyHtml]: normalize(resolved.content.html),
|
|
109
|
+
};
|
|
110
|
+
default:
|
|
111
|
+
return {
|
|
112
|
+
...base,
|
|
113
|
+
[keyText]: normalize(''),
|
|
114
|
+
[keyHtml]: normalize(''),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
package/lib/mailer-provider.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MailerMessagesResolved } from "./mailer-messages.js";
|
|
2
2
|
export type MailerProviderOptionsType = Record<string, any> | undefined;
|
|
3
3
|
export type MailerNativeClientType<P> = P extends {
|
|
4
4
|
getClient: (...args: any[]) => infer C;
|
|
5
5
|
} ? C : never;
|
|
6
|
-
export interface MailerProvider<Options = object, NativeClient = unknown> {
|
|
7
|
-
message: MailerMessageBuilder;
|
|
8
|
-
send(builder: MailerMessageBuilder): Promise<void>;
|
|
6
|
+
export interface MailerProvider<Options = object, NativeClient = unknown, Payload = object> {
|
|
9
7
|
getClient(): NativeClient;
|
|
8
|
+
createPayload(resolved: MailerMessagesResolved): Payload;
|
|
9
|
+
send(payload: Payload): Promise<void>;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=mailer-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailer-provider.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mailer-provider.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAExE,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAEzG,MAAM,WAAW,cAAc,CAC9B,OAAO,GAAG,MAAM,EAChB,YAAY,GAAG,OAAO,EACtB,OAAO,GAAG,MAAM;IAEhB,SAAS,IAAI,YAAY,CAAC;IAC1B,aAAa,CAAC,QAAQ,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC"}
|
package/package.json
CHANGED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export type MailerMessageContent = {
|
|
2
|
-
kind: 'text';
|
|
3
|
-
text: string;
|
|
4
|
-
} | {
|
|
5
|
-
kind: 'html';
|
|
6
|
-
html: string;
|
|
7
|
-
} | {
|
|
8
|
-
kind: 'mixed';
|
|
9
|
-
text?: string;
|
|
10
|
-
html?: string;
|
|
11
|
-
};
|
|
12
|
-
export type MailerMessageTemplate = {
|
|
13
|
-
kind: 'handlebars';
|
|
14
|
-
template: string;
|
|
15
|
-
data: Record<string, any>;
|
|
16
|
-
};
|
|
17
|
-
export type MailerMessage = {
|
|
18
|
-
content?: MailerMessageContent;
|
|
19
|
-
template?: MailerMessageTemplate;
|
|
20
|
-
headers?: Record<string, string>;
|
|
21
|
-
tags?: string[];
|
|
22
|
-
metadata?: Record<string, string>;
|
|
23
|
-
};
|
|
24
|
-
type MailerSenderType = {
|
|
25
|
-
email: string;
|
|
26
|
-
name?: string;
|
|
27
|
-
};
|
|
28
|
-
type MailerRecipientType = {
|
|
29
|
-
email: string;
|
|
30
|
-
};
|
|
31
|
-
export declare abstract class MailerMessageBuilder {
|
|
32
|
-
protected from: MailerSenderType | null;
|
|
33
|
-
protected to: Array<MailerRecipientType>;
|
|
34
|
-
protected subject: string;
|
|
35
|
-
protected meta: Record<string, string>;
|
|
36
|
-
protected text?: string;
|
|
37
|
-
protected html?: string;
|
|
38
|
-
get draft(): {
|
|
39
|
-
from: MailerSenderType;
|
|
40
|
-
to: MailerRecipientType[];
|
|
41
|
-
subject: string;
|
|
42
|
-
text: string | undefined;
|
|
43
|
-
html: string | undefined;
|
|
44
|
-
};
|
|
45
|
-
setFrom(email: MailerSenderType["email"], name?: MailerSenderType['name']): this;
|
|
46
|
-
setFrom(from: MailerSenderType): this;
|
|
47
|
-
private resolveToItem;
|
|
48
|
-
addTo(email: MailerRecipientType["email"]): this;
|
|
49
|
-
addTo(emails: MailerRecipientType["email"][]): this;
|
|
50
|
-
addTo(recipient: MailerRecipientType): this;
|
|
51
|
-
addTo(recipients: MailerRecipientType[]): this;
|
|
52
|
-
setTo(email: MailerRecipientType["email"]): this;
|
|
53
|
-
setTo(emails: MailerRecipientType["email"][]): this;
|
|
54
|
-
setTo(recipient: MailerRecipientType): this;
|
|
55
|
-
setTo(recipients: MailerRecipientType[]): this;
|
|
56
|
-
}
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=mailer-message-builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mailer-message-builder.d.ts","sourceRoot":"","sources":["../../src/lib/mailer-message-builder.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC;AAEvE,MAAM,MAAM,aAAa,G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,CAAC,UAAU,EAAE,mBAAmB,EAAE,GAAG,IAAI;IA2B9C,KAAK,CAAC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,IAAI;IAChD,KAAK,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI;IACnD,KAAK,CAAC,SAAS,EAAE,mBAAmB,GAAG,IAAI;IAC3C,KAAK,CAAC,UAAU,EAAE,mBAAmB,EAAE,GAAG,IAAI;CAQrD"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export class MailerMessageBuilder {
|
|
2
|
-
from = null;
|
|
3
|
-
to = [];
|
|
4
|
-
subject = '';
|
|
5
|
-
meta = {};
|
|
6
|
-
text;
|
|
7
|
-
html;
|
|
8
|
-
get draft() {
|
|
9
|
-
return {
|
|
10
|
-
from: this.from,
|
|
11
|
-
to: this.to,
|
|
12
|
-
subject: this.subject,
|
|
13
|
-
text: this.text,
|
|
14
|
-
html: this.html,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
setFrom(fromOrEmail, name) {
|
|
18
|
-
const fromEmail = typeof fromOrEmail === 'string' ? fromOrEmail : fromOrEmail.email;
|
|
19
|
-
const fromName = typeof fromOrEmail === 'string' ? name : fromOrEmail.name;
|
|
20
|
-
this.from = {
|
|
21
|
-
email: fromEmail,
|
|
22
|
-
name: fromName
|
|
23
|
-
};
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
resolveToItem(emailOrRecipient) {
|
|
27
|
-
if (typeof emailOrRecipient === 'string')
|
|
28
|
-
return { email: emailOrRecipient };
|
|
29
|
-
return emailOrRecipient;
|
|
30
|
-
}
|
|
31
|
-
addTo(input) {
|
|
32
|
-
const prevTo = this.to || [];
|
|
33
|
-
const newTo = (() => {
|
|
34
|
-
const isArr = Array.isArray(input);
|
|
35
|
-
const recipients = isArr
|
|
36
|
-
? input.map(this.resolveToItem)
|
|
37
|
-
: [this.resolveToItem(input)];
|
|
38
|
-
const remaining = [];
|
|
39
|
-
for (const r of recipients) {
|
|
40
|
-
const idx = prevTo.findIndex(p => p.email === r.email);
|
|
41
|
-
if (idx !== -1) {
|
|
42
|
-
prevTo[idx] = { ...prevTo[idx], ...r };
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
remaining.push(r);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return remaining;
|
|
49
|
-
})();
|
|
50
|
-
this.to = [...prevTo, ...newTo];
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
setTo(input) {
|
|
54
|
-
const isArr = Array.isArray(input);
|
|
55
|
-
this.to = isArr
|
|
56
|
-
? input.map(this.resolveToItem)
|
|
57
|
-
: [this.resolveToItem(input)];
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
}
|