@travetto/email 3.4.4 → 4.0.0-rc.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/__index__.ts CHANGED
@@ -2,6 +2,5 @@ export * from './src/service';
2
2
  export * from './src/types';
3
3
  export * from './src/config';
4
4
  export * from './src/transport';
5
- export * from './src/resource';
6
5
  export * from './src/util';
7
6
  export * from './src/template';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/email",
3
- "version": "3.4.4",
3
+ "version": "4.0.0-rc.0",
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/base": "^3.4.2",
27
- "@travetto/config": "^3.4.4",
28
- "@travetto/di": "^3.4.2",
26
+ "@travetto/base": "^4.0.0-rc.0",
27
+ "@travetto/config": "^4.0.0-rc.0",
28
+ "@travetto/di": "^4.0.0-rc.0",
29
29
  "@types/mustache": "^4.2.5",
30
30
  "mustache": "^4.2.0"
31
31
  },
package/src/service.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { GlobalEnv } from '@travetto/base';
1
+ import { Env, RuntimeResources } from '@travetto/base';
2
2
  import { Injectable } from '@travetto/di';
3
3
 
4
4
  import { EmailCompiled, EmailOptions, SentEmail } from './types';
5
5
  import { MailTransport } from './transport';
6
6
  import { MailInterpolator } from './template';
7
7
  import { MailUtil } from './util';
8
- import { EmailResource } from './resource';
9
8
 
10
9
  type MessageWithoutBody = Omit<EmailOptions, keyof EmailCompiled>;
11
10
 
@@ -18,27 +17,24 @@ export class MailService {
18
17
  #compiled = new Map<string, EmailCompiled>();
19
18
  #transport: MailTransport;
20
19
  #interpolator: MailInterpolator;
21
- #resources: EmailResource;
22
20
 
23
21
  constructor(
24
22
  transport: MailTransport,
25
23
  interpolator: MailInterpolator,
26
- resources: EmailResource
27
24
  ) {
28
25
  this.#interpolator = interpolator;
29
26
  this.#transport = transport;
30
- this.#resources = resources;
31
27
  }
32
28
 
33
29
  /**
34
30
  * Get compiled content by key
35
31
  */
36
32
  async getCompiled(key: string): Promise<EmailCompiled> {
37
- if (GlobalEnv.dynamic || !this.#compiled.has(key)) {
33
+ if (Env.dynamic || !this.#compiled.has(key)) {
38
34
  const [html, text, subject] = await Promise.all([
39
- this.#resources.read(`${key}.compiled.html`),
40
- this.#resources.read(`${key}.compiled.text`),
41
- this.#resources.read(`${key}.compiled.subject`)
35
+ RuntimeResources.read(`${key}.compiled.html`),
36
+ RuntimeResources.read(`${key}.compiled.text`),
37
+ RuntimeResources.read(`${key}.compiled.subject`)
42
38
  ].map(x => x.then(MailUtil.purgeBrand)));
43
39
 
44
40
  this.#compiled.set(key, { html, text, subject });
package/src/template.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import mustache from 'mustache';
2
2
 
3
- import { Inject, Injectable } from '@travetto/di';
4
-
5
- import { EmailResource } from './resource';
3
+ import { Injectable } from '@travetto/di';
4
+ import { RuntimeResources } from '@travetto/base';
6
5
 
7
6
  /**
8
7
  * Mail interpolation engine
9
8
  *
10
- * @concrete ./internal/types:MailInterpolatorTarget
9
+ * @concrete ./internal/types#MailInterpolatorTarget
11
10
  */
12
11
  export interface MailInterpolator {
13
12
  /**
@@ -24,9 +23,6 @@ export interface MailInterpolator {
24
23
  @Injectable()
25
24
  export class MustacheInterpolator implements MailInterpolator {
26
25
 
27
- @Inject()
28
- resources: EmailResource;
29
-
30
26
  /**
31
27
  * Resolved nested templates
32
28
  */
@@ -34,7 +30,7 @@ export class MustacheInterpolator implements MailInterpolator {
34
30
  const promises: Promise<string>[] = [];
35
31
  template = template.replace(/[{]{2,3}>\s+(\S+)([.]html)?\s*[}]{2,3}/g, (all: string, name: string) => {
36
32
  promises.push(
37
- this.resources.read(`${name}.html`) // Ensure html file
33
+ RuntimeResources.read(`${name}.html`) // Ensure html file
38
34
  .then(contents => this.resolveNested(contents))
39
35
  );
40
36
  return `$%${promises.length - 1}%$`;
package/src/transport.ts CHANGED
@@ -3,7 +3,7 @@ import { EmailOptions, SentEmail } from './types';
3
3
  /**
4
4
  * Default mail transport
5
5
  *
6
- * @concrete ./internal/types:MailTransportTarget
6
+ * @concrete ./internal/types#MailTransportTarget
7
7
  */
8
8
  export interface MailTransport {
9
9
  send<S extends SentEmail = SentEmail>(mail: EmailOptions): Promise<S>;
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Readable } from 'stream';
2
- import { Url } from 'url';
1
+ import { Readable } from 'node:stream';
2
+ import { Url } from 'node:url';
3
3
 
4
4
  /**
5
5
  * An address
@@ -66,7 +66,7 @@ export type EmailCompiled = Record<EmailContentType, string>;
66
66
 
67
67
  // Compilation support, defined here to allow for templates to not have a direct dependency on the compiler
68
68
  type BaseTemplateConfig = {
69
- search?: string[];
69
+ search?: string[] | readonly string[];
70
70
  inline?: boolean;
71
71
  };
72
72
 
package/src/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RootIndex } from '@travetto/manifest';
1
+ import { RuntimeContext } from '@travetto/manifest';
2
2
 
3
3
  import { EmailAttachment } 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(RootIndex.manifest.workspacePath, '.')}"`,
18
+ `File is generated from "${file.replace(RuntimeContext.workspace.path, '.')}"`,
19
19
  compile ? `Run \`${compile.replaceAll('\n', ' ')}\` to regenerate` : ''
20
20
  ];
21
21
  return `<!-- ${out.join(' ').trim()} -->\n${content}`;
package/src/resource.ts DELETED
@@ -1,10 +0,0 @@
1
- import { ResourceLoader } from '@travetto/base';
2
- import { InjectableFactory } from '@travetto/di';
3
-
4
- export class EmailResource extends ResourceLoader {
5
-
6
- @InjectableFactory()
7
- static getResources(): EmailResource {
8
- return new EmailResource();
9
- }
10
- }