@pearl-framework/mail 0.1.0 → 0.1.2

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.
@@ -1,5 +1,5 @@
1
1
 
2
2
  
3
- > @pearl-framework/mail@0.1.0 build /Users/sharvari/Desktop/Sharvari's Work Station/pearljs/packages/mail
3
+ > @pearl-framework/mail@0.1.0 build /Users/sharvari/Desktop/Sharvari's Work Station/Pearljs/pearl.js/packages/mail
4
4
  > tsc
5
5
 
@@ -29,30 +29,34 @@ export interface BuiltMail extends MailContent {
29
29
  *
30
30
  * Usage:
31
31
  * export class WelcomeEmail extends Mailable {
32
- * constructor(private readonly user: User) {
32
+ * constructor(private readonly to: string, private readonly name: string) {
33
33
  * super()
34
34
  * }
35
35
  *
36
36
  * build(): this {
37
37
  * return this
38
- * .to(this.user.email)
38
+ * .sendTo(this.to)
39
39
  * .subject('Welcome to Pearl!')
40
- * .html(`<h1>Hi ${this.user.name}!</h1>`)
40
+ * .html(`<h1>Hi ${this.name}!</h1>`)
41
41
  * }
42
42
  * }
43
43
  */
44
44
  export declare abstract class Mailable {
45
- private _from?;
46
- private _to;
47
- private _cc;
48
- private _bcc;
49
- private _replyTo?;
50
- private _subject;
51
- private _html?;
52
- private _text?;
53
- private _attachments;
45
+ protected _from?: MailAddress | string;
46
+ protected _to: Array<MailAddress | string>;
47
+ protected _cc: Array<MailAddress | string>;
48
+ protected _bcc: Array<MailAddress | string>;
49
+ protected _replyTo?: MailAddress | string;
50
+ protected _subject: string;
51
+ protected _html?: string;
52
+ protected _text?: string;
53
+ protected _attachments: Attachment[];
54
54
  from(address: MailAddress | string): this;
55
- to(...addresses: Array<MailAddress | string>): this;
55
+ /**
56
+ * Set the recipient(s) of the email.
57
+ * Named 'sendTo' to avoid conflicts with subclass properties named 'to'.
58
+ */
59
+ sendTo(...addresses: Array<MailAddress | string>): this;
56
60
  cc(...addresses: Array<MailAddress | string>): this;
57
61
  bcc(...addresses: Array<MailAddress | string>): this;
58
62
  replyTo(address: MailAddress | string): this;
@@ -60,13 +64,8 @@ export declare abstract class Mailable {
60
64
  html(content: string): this;
61
65
  text(content: string): this;
62
66
  attach(attachment: Attachment): this;
63
- /**
64
- * Implement this to configure the email.
65
- * Call this.to(), this.subject(), this.html() etc.
66
- */
67
67
  abstract build(): this | Promise<this>;
68
68
  compile(defaultFrom?: MailAddress | string): Promise<BuiltMail>;
69
- /** Override to send via queue instead of synchronously */
70
69
  shouldQueue(): boolean;
71
70
  get queue(): string;
72
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Mailable.d.ts","sourceRoot":"","sources":["../../src/mail/Mailable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAEhE,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,YAAY;IACzB,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IAC3B,EAAE,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;IAC/B,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;IAChC,GAAG,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;IACjC,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;CAC7B;AAED,MAAM,WAAW,SAAU,SAAQ,WAAW;IAC1C,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;IAC3B,EAAE,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;IAC/B,EAAE,CAAC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AC,IAAI,CAAC;IAEhC,OAAO,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAoBrE,WAAW,IAAI,OAAO;IAItB,IAAI,KAAK,IAAI,MAAM,CAElB;CACF"}
@@ -3,15 +3,15 @@
3
3
  *
4
4
  * Usage:
5
5
  * export class WelcomeEmail extends Mailable {
6
- * constructor(private readonly user: User) {
6
+ * constructor(private readonly to: string, private readonly name: string) {
7
7
  * super()
8
8
  * }
9
9
  *
10
10
  * build(): this {
11
11
  * return this
12
- * .to(this.user.email)
12
+ * .sendTo(this.to)
13
13
  * .subject('Welcome to Pearl!')
14
- * .html(`<h1>Hi ${this.user.name}!</h1>`)
14
+ * .html(`<h1>Hi ${this.name}!</h1>`)
15
15
  * }
16
16
  * }
17
17
  */
@@ -30,7 +30,11 @@ export class Mailable {
30
30
  this._from = address;
31
31
  return this;
32
32
  }
33
- to(...addresses) {
33
+ /**
34
+ * Set the recipient(s) of the email.
35
+ * Named 'sendTo' to avoid conflicts with subclass properties named 'to'.
36
+ */
37
+ sendTo(...addresses) {
34
38
  this._to.push(...addresses);
35
39
  return this;
36
40
  }
@@ -78,7 +82,6 @@ export class Mailable {
78
82
  };
79
83
  }
80
84
  // ─── Queue support ────────────────────────────────────────────────────────
81
- /** Override to send via queue instead of synchronously */
82
85
  shouldQueue() {
83
86
  return false;
84
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Mailable.js","sourceRoot":"","sources":["../../src/mail/Mailable.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAgB,QAAQ;IAClB,KAAK,CAAuB;IAC5B,GAAG,GAAgC,EAAE,CAAA;IACrC,GAAG,GAAgC,EAAE,CAAA;IACrC,IAAI,GAAgC,EAAE,CAAA;IACtC,QAAQ,CAAuB;IAC/B,QAAQ,GAAG,EAAE,CAAA;IACb,KAAK,CAAS;IACd,KAAK,CAAS;IACd,YAAY,GAAi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;YACL,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;YACnC,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;YACxC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YAC3C,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9D,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YACrD,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YACrD,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC;SACpE,CAAA;IACH,CAAC;IAED,6EAA6E;IAE7E,WAAW;QACT,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,KAAK;QACP,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pearl-framework/mail",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Pearl.js mail — Nodemailer-powered mailable classes, transports, and queue support",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,32 +1,32 @@
1
1
  import type { Attachment } from 'nodemailer/lib/mailer/index.js'
2
2
 
3
3
  export interface MailAddress {
4
- name?: string
5
- address: string
4
+ name?: string
5
+ address: string
6
6
  }
7
7
 
8
8
  export interface MailEnvelope {
9
- from?: MailAddress | string
10
- to: Array<MailAddress | string>
11
- cc?: Array<MailAddress | string>
12
- bcc?: Array<MailAddress | string>
13
- replyTo?: MailAddress | string
14
- subject: string
9
+ from?: MailAddress | string
10
+ to: Array<MailAddress | string>
11
+ cc?: Array<MailAddress | string>
12
+ bcc?: Array<MailAddress | string>
13
+ replyTo?: MailAddress | string
14
+ subject: string
15
15
  }
16
16
 
17
17
  export interface MailContent {
18
- html?: string
19
- text?: string
20
- attachments?: Attachment[]
18
+ html?: string
19
+ text?: string
20
+ attachments?: Attachment[]
21
21
  }
22
22
 
23
23
  export interface BuiltMail extends MailContent {
24
- from?: MailAddress | string
25
- to: Array<MailAddress | string>
26
- cc?: Array<MailAddress | string>
27
- bcc?: Array<MailAddress | string>
28
- replyTo?: MailAddress | string
29
- subject: string
24
+ from?: MailAddress | string
25
+ to: Array<MailAddress | string>
26
+ cc?: Array<MailAddress | string>
27
+ bcc?: Array<MailAddress | string>
28
+ replyTo?: MailAddress | string
29
+ subject: string
30
30
  }
31
31
 
32
32
  /**
@@ -34,110 +34,109 @@ export interface BuiltMail extends MailContent {
34
34
  *
35
35
  * Usage:
36
36
  * export class WelcomeEmail extends Mailable {
37
- * constructor(private readonly user: User) {
37
+ * constructor(private readonly to: string, private readonly name: string) {
38
38
  * super()
39
39
  * }
40
40
  *
41
41
  * build(): this {
42
42
  * return this
43
- * .to(this.user.email)
43
+ * .sendTo(this.to)
44
44
  * .subject('Welcome to Pearl!')
45
- * .html(`<h1>Hi ${this.user.name}!</h1>`)
45
+ * .html(`<h1>Hi ${this.name}!</h1>`)
46
46
  * }
47
47
  * }
48
48
  */
49
49
  export abstract class Mailable {
50
- private _from?: MailAddress | string
51
- private _to: Array<MailAddress | string> = []
52
- private _cc: Array<MailAddress | string> = []
53
- private _bcc: Array<MailAddress | string> = []
54
- private _replyTo?: MailAddress | string
55
- private _subject = ''
56
- private _html?: string
57
- private _text?: string
58
- private _attachments: Attachment[] = []
59
-
60
- // ─── Builder methods ──────────────────────────────────────────────────────
61
-
62
- from(address: MailAddress | string): this {
63
- this._from = address
64
- return this
50
+ protected _from?: MailAddress | string
51
+ protected _to: Array<MailAddress | string> = []
52
+ protected _cc: Array<MailAddress | string> = []
53
+ protected _bcc: Array<MailAddress | string> = []
54
+ protected _replyTo?: MailAddress | string
55
+ protected _subject = ''
56
+ protected _html?: string
57
+ protected _text?: string
58
+ protected _attachments: Attachment[] = []
59
+
60
+ // ─── Builder methods ──────────────────────────────────────────────────────
61
+
62
+ from(address: MailAddress | string): this {
63
+ this._from = address
64
+ return this
65
+ }
66
+
67
+ /**
68
+ * Set the recipient(s) of the email.
69
+ * Named 'sendTo' to avoid conflicts with subclass properties named 'to'.
70
+ */
71
+ sendTo(...addresses: Array<MailAddress | string>): this {
72
+ this._to.push(...addresses)
73
+ return this
74
+ }
75
+
76
+ cc(...addresses: Array<MailAddress | string>): this {
77
+ this._cc.push(...addresses)
78
+ return this
79
+ }
80
+
81
+ bcc(...addresses: Array<MailAddress | string>): this {
82
+ this._bcc.push(...addresses)
83
+ return this
84
+ }
85
+
86
+ replyTo(address: MailAddress | string): this {
87
+ this._replyTo = address
88
+ return this
89
+ }
90
+
91
+ subject(value: string): this {
92
+ this._subject = value
93
+ return this
94
+ }
95
+
96
+ html(content: string): this {
97
+ this._html = content
98
+ return this
99
+ }
100
+
101
+ text(content: string): this {
102
+ this._text = content
103
+ return this
104
+ }
105
+
106
+ attach(attachment: Attachment): this {
107
+ this._attachments.push(attachment)
108
+ return this
109
+ }
110
+
111
+ // ─── Build ────────────────────────────────────────────────────────────────
112
+
113
+ abstract build(): this | Promise<this>
114
+
115
+ async compile(defaultFrom?: MailAddress | string): Promise<BuiltMail> {
116
+ await this.build()
117
+
118
+ const from = this._from ?? defaultFrom
119
+
120
+ return {
121
+ ...(from !== undefined && { from }),
122
+ to: this._to,
123
+ ...(this._cc.length && { cc: this._cc }),
124
+ ...(this._bcc.length && { bcc: this._bcc }),
125
+ ...(this._replyTo !== undefined && { replyTo: this._replyTo }),
126
+ subject: this._subject,
127
+ ...(this._html !== undefined && { html: this._html }),
128
+ ...(this._text !== undefined && { text: this._text }),
129
+ ...(this._attachments.length && { attachments: this._attachments }),
65
130
  }
131
+ }
66
132
 
67
- to(...addresses: Array<MailAddress | string>): this {
68
- this._to.push(...addresses)
69
- return this
70
- }
71
-
72
- cc(...addresses: Array<MailAddress | string>): this {
73
- this._cc.push(...addresses)
74
- return this
75
- }
76
-
77
- bcc(...addresses: Array<MailAddress | string>): this {
78
- this._bcc.push(...addresses)
79
- return this
80
- }
81
-
82
- replyTo(address: MailAddress | string): this {
83
- this._replyTo = address
84
- return this
85
- }
86
-
87
- subject(value: string): this {
88
- this._subject = value
89
- return this
90
- }
91
-
92
- html(content: string): this {
93
- this._html = content
94
- return this
95
- }
96
-
97
- text(content: string): this {
98
- this._text = content
99
- return this
100
- }
101
-
102
- attach(attachment: Attachment): this {
103
- this._attachments.push(attachment)
104
- return this
105
- }
133
+ // ─── Queue support ────────────────────────────────────────────────────────
106
134
 
107
- // ─── Build ────────────────────────────────────────────────────────────────
108
-
109
- /**
110
- * Implement this to configure the email.
111
- * Call this.to(), this.subject(), this.html() etc.
112
- */
113
- abstract build(): this | Promise<this>
114
-
115
- async compile(defaultFrom?: MailAddress | string): Promise<BuiltMail> {
116
- await this.build()
117
-
118
- const from = this._from ?? defaultFrom
119
-
120
- return {
121
- ...(from !== undefined && { from }),
122
- to: this._to,
123
- ...(this._cc.length && { cc: this._cc }),
124
- ...(this._bcc.length && { bcc: this._bcc }),
125
- ...(this._replyTo !== undefined && { replyTo: this._replyTo }),
126
- subject: this._subject,
127
- ...(this._html !== undefined && { html: this._html }),
128
- ...(this._text !== undefined && { text: this._text }),
129
- ...(this._attachments.length && { attachments: this._attachments }),
130
- }
131
- }
132
-
133
- // ─── Queue support ────────────────────────────────────────────────────────
135
+ shouldQueue(): boolean {
136
+ return false
137
+ }
134
138
 
135
- /** Override to send via queue instead of synchronously */
136
- shouldQueue(): boolean {
137
- return false
138
- }
139
-
140
- get queue(): string {
141
- return 'mail'
142
- }
139
+ get queue(): string {
140
+ return 'mail'
141
+ }
143
142
  }