@travetto/email 5.0.0-rc.1 → 5.0.0-rc.11
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/package.json +4 -4
- package/src/resource.ts +2 -3
- package/src/service.ts +4 -5
- package/src/template.ts +1 -1
- package/src/transport.ts +1 -2
- package/src/types.ts +1 -1
- package/src/util.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.11",
|
|
4
4
|
"description": "Email transmission module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"directory": "module/email"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@travetto/
|
|
27
|
-
"@travetto/
|
|
28
|
-
"@travetto/
|
|
26
|
+
"@travetto/config": "^5.0.0-rc.11",
|
|
27
|
+
"@travetto/di": "^5.0.0-rc.10",
|
|
28
|
+
"@travetto/runtime": "^5.0.0-rc.10",
|
|
29
29
|
"@types/mustache": "^4.2.5",
|
|
30
30
|
"mustache": "^4.2.0"
|
|
31
31
|
},
|
package/src/resource.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AppError, Env, FileLoader } from '@travetto/
|
|
2
|
-
import { RuntimeIndex } from '@travetto/manifest';
|
|
1
|
+
import { AppError, Env, FileLoader, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
3
2
|
|
|
4
3
|
/** Build a resource loader that looks into a module and it's dependencies */
|
|
5
4
|
export class EmailResourceLoader extends FileLoader {
|
|
@@ -14,6 +13,6 @@ export class EmailResourceLoader extends FileLoader {
|
|
|
14
13
|
...RuntimeIndex.getDependentModules(mod, 'children').map(x => `${x.name}#resources`),
|
|
15
14
|
'@@#resources',
|
|
16
15
|
...globalResources ?? []
|
|
17
|
-
]);
|
|
16
|
+
].map(v => Runtime.modulePath(v)));
|
|
18
17
|
}
|
|
19
18
|
}
|
package/src/service.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Runtime, RuntimeResources } from '@travetto/runtime';
|
|
2
2
|
import { Injectable } from '@travetto/di';
|
|
3
3
|
|
|
4
4
|
import { EmailCompiled, EmailOptions, SentEmail } from './types';
|
|
@@ -30,7 +30,7 @@ export class MailService {
|
|
|
30
30
|
* Get compiled content by key
|
|
31
31
|
*/
|
|
32
32
|
async getCompiled(key: string): Promise<EmailCompiled> {
|
|
33
|
-
if (
|
|
33
|
+
if (Runtime.dynamic || !this.#compiled.has(key)) {
|
|
34
34
|
const [html, text, subject] = await Promise.all([
|
|
35
35
|
RuntimeResources.read(`${key}.compiled.html`),
|
|
36
36
|
RuntimeResources.read(`${key}.compiled.text`),
|
|
@@ -48,7 +48,7 @@ export class MailService {
|
|
|
48
48
|
* @param ctx
|
|
49
49
|
* @returns
|
|
50
50
|
*/
|
|
51
|
-
async renderMessage(keyOrMessage: string | EmailCompiled, ctx: Record<string, unknown>): Promise<EmailCompiled> {
|
|
51
|
+
async renderMessage(keyOrMessage: string | EmailCompiled | EmailOptions, ctx: Record<string, unknown>): Promise<EmailCompiled> {
|
|
52
52
|
const tpl = (typeof keyOrMessage === 'string' ? await this.getCompiled(keyOrMessage) : keyOrMessage);
|
|
53
53
|
|
|
54
54
|
const [html, text, subject] = await Promise.all([
|
|
@@ -78,8 +78,7 @@ export class MailService {
|
|
|
78
78
|
): Promise<S> {
|
|
79
79
|
const keyOrMessage = key ?? ('html' in message ? message : '') ?? '';
|
|
80
80
|
const context = ctx ?? (('context' in message) ? message.context : {}) ?? {};
|
|
81
|
-
|
|
82
|
-
const compiled = await this.renderMessage(keyOrMessage as EmailCompiled, context);
|
|
81
|
+
const compiled = await this.renderMessage(keyOrMessage, context);
|
|
83
82
|
|
|
84
83
|
const final = { ...base, ...message, ...compiled, context };
|
|
85
84
|
|
package/src/template.ts
CHANGED
package/src/transport.ts
CHANGED
|
@@ -14,7 +14,6 @@ export interface MailTransport {
|
|
|
14
14
|
*/
|
|
15
15
|
export class NullTransport implements MailTransport {
|
|
16
16
|
async send<S extends SentEmail = SentEmail>(mail: EmailOptions): Promise<S> {
|
|
17
|
-
|
|
18
|
-
return {} as S;
|
|
17
|
+
return undefined! ?? {};
|
|
19
18
|
}
|
|
20
19
|
}
|
package/src/types.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Runtime, BinaryUtil } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import { EmailAttachment, EmailIdentity, EmailIdentityList, EmailOptions } from './types';
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ export class MailUtil {
|
|
|
15
15
|
static buildBrand(file: string, content: string, compile?: string): string {
|
|
16
16
|
const out = [
|
|
17
17
|
'WARNING: Do not modify.',
|
|
18
|
-
`File is generated from "${file.replace(
|
|
18
|
+
`File is generated from "${file.replace(Runtime.workspace.path, '.')}"`,
|
|
19
19
|
compile ? `Run \`${compile.replaceAll('\n', ' ')}\` to regenerate` : ''
|
|
20
20
|
];
|
|
21
21
|
return `<!-- ${out.join(' ').trim()} -->\n${content}`;
|
|
@@ -77,7 +77,7 @@ export class MailUtil {
|
|
|
77
77
|
static buildUniqueMessageId(message: EmailOptions): string {
|
|
78
78
|
const from = this.getPrimaryEmail(message.from)!;
|
|
79
79
|
const to = this.getPrimaryEmail(message.to)!;
|
|
80
|
-
const uid =
|
|
80
|
+
const uid = BinaryUtil.hash(`${to}${from}${message.subject}${Date.now()}`, 12);
|
|
81
81
|
return `<${uid}@${from.split('@')[1]}>`;
|
|
82
82
|
}
|
|
83
83
|
}
|