@typetron/framework 0.5.35 → 0.5.37
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/Framework/Readme.md +4 -0
- package/Mail/Readme.md +91 -3
- package/Storage/Readme.md +0 -1
- package/build/Framework/Config/MailConfig.d.ts +3 -0
- package/build/Framework/Config/MailConfig.d.ts.map +1 -1
- package/build/Framework/Config/MailConfig.js +1 -0
- package/build/Framework/Config/MailConfig.js.map +1 -1
- package/build/Framework/Providers/MailProvider.d.ts.map +1 -1
- package/build/Framework/Providers/MailProvider.js +10 -3
- package/build/Framework/Providers/MailProvider.js.map +1 -1
- package/build/Mail/MailError.d.ts +12 -0
- package/build/Mail/MailError.d.ts.map +1 -0
- package/build/Mail/MailError.js +17 -0
- package/build/Mail/MailError.js.map +1 -0
- package/build/Mail/Mailer.d.ts +2 -1
- package/build/Mail/Mailer.d.ts.map +1 -1
- package/build/Mail/Mailer.js +4 -1
- package/build/Mail/Mailer.js.map +1 -1
- package/build/Mail/PendingMail.js +1 -1
- package/build/Mail/PendingMail.js.map +1 -1
- package/build/Mail/SentMessage.d.ts +5 -0
- package/build/Mail/SentMessage.d.ts.map +1 -1
- package/build/Mail/SentMessage.js +5 -0
- package/build/Mail/SentMessage.js.map +1 -1
- package/build/Mail/Transports/CloudflareTransport.d.ts +13 -0
- package/build/Mail/Transports/CloudflareTransport.d.ts.map +1 -0
- package/build/Mail/Transports/CloudflareTransport.js +86 -0
- package/build/Mail/Transports/CloudflareTransport.js.map +1 -0
- package/build/Mail/Transports/SendGridTransport.d.ts.map +1 -1
- package/build/Mail/Transports/SendGridTransport.js +13 -2
- package/build/Mail/Transports/SendGridTransport.js.map +1 -1
- package/build/Mail/index.d.ts +3 -0
- package/build/Mail/index.d.ts.map +1 -1
- package/build/Mail/index.js +3 -0
- package/build/Mail/index.js.map +1 -1
- package/package.json +1 -1
package/Framework/Readme.md
CHANGED
|
@@ -60,6 +60,10 @@ the application loads each file.
|
|
|
60
60
|
`AppConfig.server` selects the Node or uWebSockets HTTP server. A configured `websocketsPort` starts the separate WebSocket provider. Static
|
|
61
61
|
assets are served when `staticAssets` entries are present.
|
|
62
62
|
|
|
63
|
+
`MailConfig.default` supports `memory`, `SendGrid`, and `Cloudflare`. Cloudflare requires `mailers.Cloudflare.accountId` and
|
|
64
|
+
`mailers.Cloudflare.apiToken`; see [Mail configuration](../Mail/Readme.md#cloudflare).
|
|
65
|
+
Optional `MailConfig.replyTo` sets the default Reply-To; explicit per-message values override it.
|
|
66
|
+
|
|
63
67
|
Authentication configuration must provide a signing `signature`. If it is missing, application creation throws an error stating that
|
|
64
68
|
`APP_SECRET` is not set up.
|
|
65
69
|
|
package/Mail/Readme.md
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
- [Sending Mail](#sending-mail)
|
|
7
7
|
- [Recipients and Message Details](#recipients-and-message-details)
|
|
8
8
|
- [Transports and Testing](#transports-and-testing)
|
|
9
|
+
- [Delivery Outcomes](#delivery-outcomes)
|
|
10
|
+
- [Cloudflare](#cloudflare)
|
|
11
|
+
- [Delivery Errors](#delivery-errors)
|
|
9
12
|
|
|
10
13
|
## Introduction
|
|
11
14
|
|
|
@@ -14,8 +17,8 @@ performs the delivery.
|
|
|
14
17
|
|
|
15
18
|
## Configuration
|
|
16
19
|
|
|
17
|
-
Applications normally register `MailProvider` and configure `MailConfig`. The `default` mailer may be `memory
|
|
18
|
-
supplies the default sender.
|
|
20
|
+
Applications normally register `MailProvider` and configure `MailConfig`. The `default` mailer may be `memory`, `SendGrid`, or `Cloudflare`,
|
|
21
|
+
and `from` supplies the default sender. Optional `replyTo` supplies the default reply address.
|
|
19
22
|
|
|
20
23
|
```ts
|
|
21
24
|
import { MailConfig } from '@Typetron/Framework'
|
|
@@ -26,12 +29,19 @@ export default new MailConfig({
|
|
|
26
29
|
email: 'hello@example.com',
|
|
27
30
|
name: 'Typetron',
|
|
28
31
|
},
|
|
32
|
+
replyTo: 'support@example.com',
|
|
29
33
|
})
|
|
30
34
|
```
|
|
31
35
|
|
|
32
36
|
The SendGrid transport also requires `mailers.SendGrid.key`. Constructing `Mailer` without a transport throws an error instructing the
|
|
33
37
|
application to register `MailProvider` or bind a mailer manually.
|
|
34
38
|
|
|
39
|
+
`replyTo` accepts an email string, a `{email, name?}` address, or an array of these. It applies to outgoing messages without an explicit
|
|
40
|
+
Reply-To, including messages passed directly to `Mailer.send`. A fluent `.replyTo(...)` overrides the mailable's own `replyTo`, which
|
|
41
|
+
in turn overrides the configured default. Without a default, messages with no explicit Reply-To leave it unset.
|
|
42
|
+
|
|
43
|
+
For manual setup, pass the default as the third argument: `new Mailer(from, transport, replyTo)`.
|
|
44
|
+
|
|
35
45
|
## Defining Mailables
|
|
36
46
|
|
|
37
47
|
Represent a reusable message by extending `Mailable` and implementing `content`:
|
|
@@ -89,7 +99,7 @@ await mail
|
|
|
89
99
|
## Transports and Testing
|
|
90
100
|
|
|
91
101
|
`MemoryTransport` stores sent messages in its public `messages` array and is suitable for tests and local development. `SendGridTransport`
|
|
92
|
-
sends through `@sendgrid/mail`
|
|
102
|
+
sends through `@sendgrid/mail`. `CloudflareTransport` uses Node's built-in `fetch` to send through Cloudflare's REST API.
|
|
93
103
|
|
|
94
104
|
```ts
|
|
95
105
|
const [message] = transport.messages
|
|
@@ -97,3 +107,81 @@ const [message] = transport.messages
|
|
|
97
107
|
console.log(message.to)
|
|
98
108
|
console.log(message.body)
|
|
99
109
|
```
|
|
110
|
+
|
|
111
|
+
## Delivery Outcomes
|
|
112
|
+
|
|
113
|
+
Every transport returns the shared `SentMessage` type, exported from `@Typetron/Mail`. In addition to the original message details,
|
|
114
|
+
it has optional `messageId`, `delivered`, `queued`, `permanentBounces`, and `suppressedRecipients` fields.
|
|
115
|
+
|
|
116
|
+
Providers populate only the information they report. An `undefined` address array means the outcome was not reported; an empty array
|
|
117
|
+
means the provider reported no recipients with that outcome. A successful send means the transport accepted the request, and does not
|
|
118
|
+
guarantee delivery to every recipient. Outcomes describe the send response and are not updated later.
|
|
119
|
+
|
|
120
|
+
Cloudflare reports delivery, queue, and permanent bounce address arrays, plus suppressed recipients and a message ID when provided.
|
|
121
|
+
SendGrid exposes its [X-Message-ID response header](https://www.twilio.com/docs/sendgrid/glossary/x-message-id) as `messageId`,
|
|
122
|
+
leaving delivery outcomes undefined. Memory transport leaves all delivery metadata undefined.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const sent = await mail.to('john@example.com').subject('Welcome').send('Welcome!')
|
|
126
|
+
if (sent.permanentBounces?.length) {
|
|
127
|
+
console.warn('Recipients bounced:', sent.permanentBounces)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Cloudflare
|
|
132
|
+
|
|
133
|
+
Configure a Cloudflare account ID, an API token with email sending permission, and a sender on a domain configured for
|
|
134
|
+
[Cloudflare Email Service](https://developers.cloudflare.com/email-service/get-started/send-emails/):
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { MailConfig } from '@Typetron/Framework'
|
|
138
|
+
|
|
139
|
+
export default new MailConfig({
|
|
140
|
+
default: 'Cloudflare',
|
|
141
|
+
from: {email: 'hello@example.com', name: 'Example'},
|
|
142
|
+
mailers: {
|
|
143
|
+
memory: {},
|
|
144
|
+
Cloudflare: {
|
|
145
|
+
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
|
|
146
|
+
apiToken: process.env.CLOUDFLARE_API_TOKEN!,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Registration throws `MailError` if either credential is missing or blank. For manual setup, use
|
|
153
|
+
`new CloudflareTransport({accountId, apiToken})` from `@Typetron/Mail` and pass it to `Mailer`.
|
|
154
|
+
|
|
155
|
+
A string body is sent as HTML, matching SendGrid. An `{html, text}` body sends both alternatives. Strings, named addresses, and address
|
|
156
|
+
arrays on `Mailable` are converted to Cloudflare's REST format for the sender, recipients, CC, BCC, and reply-to fields.
|
|
157
|
+
|
|
158
|
+
Delivery outcomes are available on the shared `SentMessage`; queued recipients may be delivered later. A successful API response
|
|
159
|
+
resolves even if some or all recipients permanently bounced or were suppressed.
|
|
160
|
+
|
|
161
|
+
Each send makes one request. The transport does not automatically retry failed or ambiguous requests, since an email may have already
|
|
162
|
+
been accepted before a network failure. Applications decide whether to retry.
|
|
163
|
+
|
|
164
|
+
## Delivery Errors
|
|
165
|
+
|
|
166
|
+
Cloudflare and SendGrid throw `MailError` for API rejections and network failures. `provider` identifies the service, `status` contains
|
|
167
|
+
the upstream HTTP status when available, `context` holds provider-specific response details, and `cause` preserves an underlying error
|
|
168
|
+
when available. Cloudflare also throws `MailError` for malformed responses. A network failure leaves delivery uncertain.
|
|
169
|
+
|
|
170
|
+
For Cloudflare API rejections, `context` contains the response envelope, including its `errors` array. For non-JSON responses, it
|
|
171
|
+
contains the response text. For SendGrid API rejections, it contains `error.response.body`.
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { MailError } from '@Typetron/Mail'
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
await mail.to('john@example.com').send('Hello')
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error instanceof MailError) {
|
|
180
|
+
console.error(error.provider, error.status, error.context)
|
|
181
|
+
}
|
|
182
|
+
throw error
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
SendGrid failures now throw `MailError` instead of Router's `HttpError`. Applications choose how to translate provider failures into
|
|
187
|
+
their own HTTP responses.
|
package/Storage/Readme.md
CHANGED
|
@@ -57,7 +57,6 @@ export default new StorageConfig({
|
|
|
57
57
|
AWS disks use the SDK's default credential chain when `credentials` is omitted. The S3 driver is loaded only when an S3 disk is resolved;
|
|
58
58
|
applications using it must install `@aws-sdk/client-s3` and `@aws-sdk/s3-request-presigner`.
|
|
59
59
|
|
|
60
|
-
|
|
61
60
|
Local disks refuse keys that pass through a symbolic link inside the root and throw `StorageSymbolicLink`, so a link
|
|
62
61
|
created in the disk can't redirect reads or writes outside of it.
|
|
63
62
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseConfig } from './BaseConfig';
|
|
2
|
+
import type { CloudflareTransportConfig, Mailable } from '@Typetron/Mail';
|
|
2
3
|
export type Mailers = keyof MailConfig['mailers'];
|
|
3
4
|
export declare class MailConfig extends BaseConfig<MailConfig> {
|
|
4
5
|
default: Mailers;
|
|
@@ -6,11 +7,13 @@ export declare class MailConfig extends BaseConfig<MailConfig> {
|
|
|
6
7
|
email: string;
|
|
7
8
|
name?: string;
|
|
8
9
|
};
|
|
10
|
+
replyTo?: Mailable['replyTo'];
|
|
9
11
|
mailers: {
|
|
10
12
|
memory: any;
|
|
11
13
|
SendGrid?: {
|
|
12
14
|
key: string;
|
|
13
15
|
};
|
|
16
|
+
Cloudflare?: CloudflareTransportConfig;
|
|
14
17
|
SES?: {};
|
|
15
18
|
Mailgun?: {};
|
|
16
19
|
Postmark?: {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailConfig.d.ts","sourceRoot":"","sources":["../../../Framework/Config/MailConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"MailConfig.d.ts","sourceRoot":"","sources":["../../../Framework/Config/MailConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzE,MAAM,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,CAAA;AAEjD,qBAAa,UAAW,SAAQ,UAAU,CAAC,UAAU,CAAC;IAClD,OAAO,EAAE,OAAO,CAA6C;IAE7D,IAAI,EAAE;QACF,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACjB,CAAA;IAED,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;IAE7B,OAAO,EAAE;QACL,MAAM,EAAE,GAAG,CAAC;QAEZ,QAAQ,CAAC,EAAE;YACP,GAAG,EAAE,MAAM,CAAC;SACf,CAAC;QACF,UAAU,CAAC,EAAE,yBAAyB,CAAC;QACvC,GAAG,CAAC,EAAE,EAEL,CAAC;QACF,OAAO,CAAC,EAAE,EAET,CAAC;QACF,QAAQ,CAAC,EAAE,EAEV,CAAC;KAEL,CAAA;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailConfig.js","sourceRoot":"","sources":["../../../Framework/Config/MailConfig.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;
|
|
1
|
+
{"version":3,"file":"MailConfig.js","sourceRoot":"","sources":["../../../Framework/Config/MailConfig.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAKzC,MAAa,UAAW,SAAQ,uBAAsB;IAClD,OAAO,GAAY,OAAO,CAAC,GAAG,EAAE,MAAiB,IAAI,QAAQ,CAAA;IAE7D,IAAI,CAGH;IAED,OAAO,CAAsB;IAE7B,OAAO,CAiBN;CACJ;AA5BD,gCA4BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailProvider.d.ts","sourceRoot":"","sources":["../../../Framework/Providers/MailProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAW,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"MailProvider.d.ts","sourceRoot":"","sources":["../../../Framework/Providers/MailProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAW,MAAM,WAAW,CAAA;AAyB/C,qBAAa,YAAa,SAAQ,QAAQ;IAEtC,MAAM,EAAE,UAAU,CAAA;IAEX,QAAQ;CAIlB"}
|
|
@@ -20,17 +20,24 @@ const mailers = {
|
|
|
20
20
|
return new Mail_1.MemoryTransport();
|
|
21
21
|
},
|
|
22
22
|
SendGrid: (app, config) => {
|
|
23
|
-
if (!config.mailers
|
|
24
|
-
throw new
|
|
23
|
+
if (!config.mailers?.SendGrid?.key) {
|
|
24
|
+
throw new Mail_1.MailError('SendGrid key is not set', { provider: 'SendGrid' });
|
|
25
25
|
}
|
|
26
26
|
return new SendGridTransport_1.SendGridTransport(config.mailers.SendGrid?.key);
|
|
27
27
|
},
|
|
28
|
+
Cloudflare: (app, config) => {
|
|
29
|
+
const options = config.mailers?.Cloudflare;
|
|
30
|
+
if (!options) {
|
|
31
|
+
throw new Mail_1.MailError('Cloudflare accountId and apiToken are required', { provider: 'Cloudflare' });
|
|
32
|
+
}
|
|
33
|
+
return new Mail_1.CloudflareTransport(options);
|
|
34
|
+
},
|
|
28
35
|
};
|
|
29
36
|
class MailProvider extends Provider_1.Provider {
|
|
30
37
|
config;
|
|
31
38
|
register() {
|
|
32
39
|
const transport = mailers[this.config.default]?.(this.app, this.config);
|
|
33
|
-
this.app.set(Mail_1.Mailer, new Mail_1.Mailer(this.config.from, transport));
|
|
40
|
+
this.app.set(Mail_1.Mailer, new Mail_1.Mailer(this.config.from, transport, this.config.replyTo));
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
exports.MailProvider = MailProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailProvider.js","sourceRoot":"","sources":["../../../Framework/Providers/MailProvider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;AAEZ,mDAAuD;AACvD,0CAAsC;AACtC,sCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"MailProvider.js","sourceRoot":"","sources":["../../../Framework/Providers/MailProvider.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;AAEZ,mDAAuD;AACvD,0CAAsC;AACtC,sCAA+C;AAC/C,y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AAM,GAAE;8BACD,mBAAU;4CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface MailErrorOptions extends ErrorOptions {
|
|
2
|
+
provider: string;
|
|
3
|
+
status?: number;
|
|
4
|
+
context?: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare class MailError extends Error {
|
|
7
|
+
readonly provider: string;
|
|
8
|
+
readonly status?: number;
|
|
9
|
+
readonly context?: unknown;
|
|
10
|
+
constructor(message: string, options: MailErrorOptions);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=MailError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MailError.d.ts","sourceRoot":"","sources":["../../Mail/MailError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,qBAAa,SAAU,SAAQ,KAAK;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB;CAOzD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailError = void 0;
|
|
4
|
+
class MailError extends Error {
|
|
5
|
+
provider;
|
|
6
|
+
status;
|
|
7
|
+
context;
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, { cause: options.cause });
|
|
10
|
+
this.name = 'MailError';
|
|
11
|
+
this.provider = options.provider;
|
|
12
|
+
this.status = options.status;
|
|
13
|
+
this.context = options.context;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.MailError = MailError;
|
|
17
|
+
//# sourceMappingURL=MailError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MailError.js","sourceRoot":"","sources":["../../Mail/MailError.ts"],"names":[],"mappings":";;;AAMA,MAAa,SAAU,SAAQ,KAAK;IACvB,QAAQ,CAAQ;IAChB,MAAM,CAAS;IACf,OAAO,CAAU;IAE1B,YAAY,OAAe,EAAE,OAAyB;QAClD,KAAK,CAAC,OAAO,EAAE,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IAClC,CAAC;CACJ;AAZD,8BAYC"}
|
package/build/Mail/Mailer.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { Mailable } from './Mailable';
|
|
|
4
4
|
import { MailAddress } from '@Typetron/Mail/MailAddress';
|
|
5
5
|
export declare class Mailer {
|
|
6
6
|
from: MailAddress;
|
|
7
|
+
replyTo?: Mailable['replyTo'];
|
|
7
8
|
transport: MailTransport;
|
|
8
|
-
constructor(from: MailAddress, transport?: MailTransport);
|
|
9
|
+
constructor(from: MailAddress, transport?: MailTransport, replyTo?: Mailable['replyTo']);
|
|
9
10
|
to(email: string): PendingMail;
|
|
10
11
|
send(message: Mailable): Promise<import("./SentMessage").SentMessage>;
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mailer.d.ts","sourceRoot":"","sources":["../../Mail/Mailer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,qBAAa,MAAM;IAGI,IAAI,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"Mailer.d.ts","sourceRoot":"","sources":["../../Mail/Mailer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,qBAAa,MAAM;IAGI,IAAI,EAAE,WAAW;IAAoC,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;IAFrG,SAAS,EAAE,aAAa,CAAA;gBAEL,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,aAAa,EAAS,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;IAQrG,EAAE,CAAC,KAAK,EAAE,MAAM;IAOV,IAAI,CAAC,OAAO,EAAE,QAAQ;CAI/B"}
|
package/build/Mail/Mailer.js
CHANGED
|
@@ -4,9 +4,11 @@ exports.Mailer = void 0;
|
|
|
4
4
|
const PendingMail_1 = require("./PendingMail");
|
|
5
5
|
class Mailer {
|
|
6
6
|
from;
|
|
7
|
+
replyTo;
|
|
7
8
|
transport;
|
|
8
|
-
constructor(from, transport) {
|
|
9
|
+
constructor(from, transport, replyTo) {
|
|
9
10
|
this.from = from;
|
|
11
|
+
this.replyTo = replyTo;
|
|
10
12
|
if (!transport) {
|
|
11
13
|
throw new Error('Please add the MailProvider in your app in order to use the Mailing feature, ' +
|
|
12
14
|
'or manually add a Mailer instance in the app container ');
|
|
@@ -20,6 +22,7 @@ class Mailer {
|
|
|
20
22
|
return mail;
|
|
21
23
|
}
|
|
22
24
|
async send(message) {
|
|
25
|
+
message.replyTo ??= this.replyTo;
|
|
23
26
|
return await this.transport.send(message);
|
|
24
27
|
}
|
|
25
28
|
}
|
package/build/Mail/Mailer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../Mail/Mailer.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAI3C,MAAa,MAAM;IAGI;
|
|
1
|
+
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../Mail/Mailer.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAI3C,MAAa,MAAM;IAGI;IAAqD;IAFxE,SAAS,CAAe;IAExB,YAAmB,IAAiB,EAAE,SAAyB,EAAS,OAA6B;QAAlF,SAAI,GAAJ,IAAI,CAAa;QAAoC,YAAO,GAAP,OAAO,CAAsB;QACjG,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,+EAA+E;gBAC3F,yDAAyD,CAAC,CAAA;QAClE,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC9B,CAAC;IAED,EAAE,CAAC,KAAa;QACZ,MAAM,IAAI,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACpB,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QACd,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAiB;QACxB,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAA;QAChC,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;CACJ;AAtBD,wBAsBC"}
|
|
@@ -44,7 +44,7 @@ class PendingMail {
|
|
|
44
44
|
mail.subject = this.details.subject;
|
|
45
45
|
mail.from = this.details.from;
|
|
46
46
|
mail.to = this.details.to;
|
|
47
|
-
mail.replyTo = this.details.replyTo;
|
|
47
|
+
mail.replyTo = this.details.replyTo ?? mail.replyTo;
|
|
48
48
|
mail.cc = this.details.cc;
|
|
49
49
|
mail.bcc = this.details.bcc;
|
|
50
50
|
return this.mailer.send(mail);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PendingMail.js","sourceRoot":"","sources":["../../Mail/PendingMail.ts"],"names":[],"mappings":";;;AACA,yCAAqC;AAGrC,MAAa,WAAW;IAYA;IAVpB,OAAO,GAQH,EAAC,IAAI,EAAE,EAAE,EAAC,CAAA;IAEd,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAClC,CAAC;IAED,OAAO,CAAC,OAAe;QACnB,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAA;QAC9B,OAAO,IAAI,CAAA;IACf,CAAC;IAED,IAAI,CAAC,KAA2B;QAC5B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,KAAK,CAAA;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,EAAE,CAAC,KAA2B;QAC1B,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,CAAA;QACvB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,OAAO,CAAC,KAA2B;QAC/B,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAA;QAC5B,OAAO,IAAI,CAAA;IACf,CAAC;IAED,EAAE,CAAC,KAA2B;QAC1B,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,CAAA;QACvB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,GAAG,CAAC,KAA2B;QAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,KAAK,CAAA;QACxB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAsD;QAC7D,IAAI,IAAI,CAAA;QACR,IAAI,IAAI,YAAY,mBAAQ,EAAE,CAAC;YAC3B,IAAI,GAAG,IAAI,CAAA;QACf,CAAC;aAAM,C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AAC,GAAG,GAAG,KAAK,CAAA;QACxB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAsD;QAC7D,IAAI,IAAI,CAAA;QACR,IAAI,IAAI,YAAY,mBAAQ,EAAE,CAAC;YAC3B,IAAI,GAAG,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACJ,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAA;YACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QACpB,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAA;QACnD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;QACzB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAA;QAE3B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;CACJ;AA/DD,kCA+DC"}
|
|
@@ -11,6 +11,11 @@ export declare class SentMessage {
|
|
|
11
11
|
readonly replyTo?: string | MailAddress | (string | MailAddress)[];
|
|
12
12
|
readonly cc?: string | MailAddress | (string | MailAddress)[];
|
|
13
13
|
readonly bcc?: string | MailAddress | (string | MailAddress)[];
|
|
14
|
+
messageId?: string;
|
|
15
|
+
delivered?: string[];
|
|
16
|
+
queued?: string[];
|
|
17
|
+
permanentBounces?: string[];
|
|
18
|
+
suppressedRecipients?: string[];
|
|
14
19
|
constructor(mail: Mailable);
|
|
15
20
|
}
|
|
16
21
|
//# sourceMappingURL=SentMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentMessage.d.ts","sourceRoot":"","sources":["../../Mail/SentMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAElD,qBAAa,WAAW;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAA;IACrD,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAClE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAC7D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"SentMessage.d.ts","sourceRoot":"","sources":["../../Mail/SentMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAElD,qBAAa,WAAW;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAA;IACrD,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAClE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAC7D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IAE9D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;gBAEnB,IAAI,EAAE,QAAQ;CAO7B"}
|
|
@@ -9,6 +9,11 @@ class SentMessage {
|
|
|
9
9
|
replyTo;
|
|
10
10
|
cc;
|
|
11
11
|
bcc;
|
|
12
|
+
messageId;
|
|
13
|
+
delivered;
|
|
14
|
+
queued;
|
|
15
|
+
permanentBounces;
|
|
16
|
+
suppressedRecipients;
|
|
12
17
|
constructor(mail) {
|
|
13
18
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
19
|
const { content, ...mailDetails } = mail;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentMessage.js","sourceRoot":"","sources":["../../Mail/SentMessage.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IACX,IAAI,CAAsB;IAC1B,OAAO,CAAS;IAChB,IAAI,CAAwC;IAC5C,EAAE,CAAkD;IACpD,OAAO,CAAkD;IACzD,EAAE,CAAkD;IACpD,GAAG,CAAkD;IAE9D,YAAY,IAAc;QACtB,6DAA6D;QAC7D,MAAM,EAAC,OAAO,EAAE,GAAG,WAAW,EAAC,GAAG,IAAI,CAAA;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAA;IAC3C,CAAC;CAEJ;
|
|
1
|
+
{"version":3,"file":"SentMessage.js","sourceRoot":"","sources":["../../Mail/SentMessage.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IACX,IAAI,CAAsB;IAC1B,OAAO,CAAS;IAChB,IAAI,CAAwC;IAC5C,EAAE,CAAkD;IACpD,OAAO,CAAkD;IACzD,EAAE,CAAkD;IACpD,GAAG,CAAkD;IAE9D,SAAS,CAAS;IAClB,SAAS,CAAW;IACpB,MAAM,CAAW;IACjB,gBAAgB,CAAW;IAC3B,oBAAoB,CAAW;IAE/B,YAAY,IAAc;QACtB,6DAA6D;QAC7D,MAAM,EAAC,OAAO,EAAE,GAAG,WAAW,EAAC,GAAG,IAAI,CAAA;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAA;IAC3C,CAAC;CAEJ;AAtBD,kCAsBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Mailable } from '../Mailable';
|
|
2
|
+
import { MailTransport } from '../MailTransport';
|
|
3
|
+
import { SentMessage } from '../SentMessage';
|
|
4
|
+
export interface CloudflareTransportConfig {
|
|
5
|
+
accountId: string;
|
|
6
|
+
apiToken: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CloudflareTransport extends MailTransport {
|
|
9
|
+
private config;
|
|
10
|
+
constructor(config: CloudflareTransportConfig);
|
|
11
|
+
send(message: Mailable): Promise<SentMessage>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=CloudflareTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareTransport.d.ts","sourceRoot":"","sources":["../../../Mail/Transports/CloudflareTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,WAAW,yBAAyB;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAUD,qBAAa,mBAAoB,SAAQ,aAAa;IACtC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,yBAAyB;IAO/C,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;CAoEtD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflareTransport = void 0;
|
|
4
|
+
const MailError_1 = require("../MailError");
|
|
5
|
+
const MailTransport_1 = require("../MailTransport");
|
|
6
|
+
const SentMessage_1 = require("../SentMessage");
|
|
7
|
+
function address(value) {
|
|
8
|
+
return typeof value === 'string' ? value : { address: value.email, name: value.name };
|
|
9
|
+
}
|
|
10
|
+
function addresses(value) {
|
|
11
|
+
return Array.isArray(value) ? value.map(address) : value === undefined ? undefined : address(value);
|
|
12
|
+
}
|
|
13
|
+
class CloudflareTransport extends MailTransport_1.MailTransport {
|
|
14
|
+
config;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super();
|
|
17
|
+
this.config = config;
|
|
18
|
+
if (!config.accountId?.trim() || !config.apiToken?.trim()) {
|
|
19
|
+
throw new MailError_1.MailError('Cloudflare accountId and apiToken are required', { provider: 'Cloudflare' });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async send(message) {
|
|
23
|
+
const sentMessage = new SentMessage_1.SentMessage(message);
|
|
24
|
+
const content = typeof sentMessage.body === 'string' ? { html: sentMessage.body } : sentMessage.body;
|
|
25
|
+
let response;
|
|
26
|
+
let body;
|
|
27
|
+
try {
|
|
28
|
+
response = await globalThis.fetch(`https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(this.config.accountId)}/email/sending/send`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${this.config.apiToken}`,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
from: address(sentMessage.from),
|
|
36
|
+
to: addresses(sentMessage.to),
|
|
37
|
+
cc: addresses(sentMessage.cc),
|
|
38
|
+
bcc: addresses(sentMessage.bcc),
|
|
39
|
+
reply_to: addresses(sentMessage.replyTo),
|
|
40
|
+
subject: sentMessage.subject,
|
|
41
|
+
...content,
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (cause) {
|
|
46
|
+
throw new MailError_1.MailError('Cloudflare mail request failed', { provider: 'Cloudflare', cause });
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
body = await response.text();
|
|
50
|
+
}
|
|
51
|
+
catch (cause) {
|
|
52
|
+
throw new MailError_1.MailError('Could not read Cloudflare mail response', { provider: 'Cloudflare', status: response.status, cause });
|
|
53
|
+
}
|
|
54
|
+
let data;
|
|
55
|
+
try {
|
|
56
|
+
data = JSON.parse(body);
|
|
57
|
+
}
|
|
58
|
+
catch (cause) {
|
|
59
|
+
throw new MailError_1.MailError('Cloudflare returned an invalid mail response', {
|
|
60
|
+
provider: 'Cloudflare', status: response.status, context: body, cause,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (!response.ok || data?.success !== true) {
|
|
64
|
+
throw new MailError_1.MailError('Cloudflare rejected the mail request', {
|
|
65
|
+
provider: 'Cloudflare', status: response.status, context: data,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const result = data.result;
|
|
69
|
+
const isAddresses = (value) => Array.isArray(value) && value.every(item => typeof item === 'string');
|
|
70
|
+
if (!result || !isAddresses(result.delivered) || !isAddresses(result.queued) || !isAddresses(result.permanent_bounces)
|
|
71
|
+
|| (result.suppressed_recipients !== undefined && !isAddresses(result.suppressed_recipients))
|
|
72
|
+
|| (result.message_id !== undefined && typeof result.message_id !== 'string')) {
|
|
73
|
+
throw new MailError_1.MailError('Cloudflare returned an invalid mail delivery result', {
|
|
74
|
+
provider: 'Cloudflare', status: response.status, context: data,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
sentMessage.delivered = result.delivered;
|
|
78
|
+
sentMessage.queued = result.queued;
|
|
79
|
+
sentMessage.permanentBounces = result.permanent_bounces;
|
|
80
|
+
sentMessage.suppressedRecipients = result.suppressed_recipients;
|
|
81
|
+
sentMessage.messageId = result.message_id;
|
|
82
|
+
return sentMessage;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.CloudflareTransport = CloudflareTransport;
|
|
86
|
+
//# sourceMappingURL=CloudflareTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareTransport.js","sourceRoot":"","sources":["../../../Mail/Transports/CloudflareTransport.ts"],"names":[],"mappings":";;;AAEA,4CAAwC;AACxC,oDAAgD;AAChD,gDAA4C;AAO5C,SAAS,OAAO,CAAC,KAA2B;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAC,CAAA;AACvF,CAAC;AAED,SAAS,SAAS,CAAC,KAAqB;IACpC,OAAO,KAAK,CAAC,OAAO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","sourceRoot":"","sources":["../../../Mail/Transports/SendGridTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,qBAAa,iBAAkB,SAAQ,aAAa;IAChD,QAAQ,EAAE,WAAW,EAAE,CAAK;IAG5B,MAAM,EAAE,UAAU,CAAA;gBAEN,GAAG,EAAE,MAAM;IAMjB,IAAI,CAAC,OAAO,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"SendGridTransport.d.ts","sourceRoot":"","sources":["../../../Mail/Transports/SendGridTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,qBAAa,iBAAkB,SAAQ,aAAa;IAChD,QAAQ,EAAE,WAAW,EAAE,CAAK;IAG5B,MAAM,EAAE,UAAU,CAAA;gBAEN,GAAG,EAAE,MAAM;IAMjB,IAAI,CAAC,OAAO,EAAE,QAAQ;CAsF/B"}
|
|
@@ -18,7 +18,7 @@ const SentMessage_1 = require("../SentMessage");
|
|
|
18
18
|
const Container_1 = require("../../Container");
|
|
19
19
|
const Framework_1 = require("../../Framework");
|
|
20
20
|
const mail_1 = __importDefault(require("@sendgrid/mail"));
|
|
21
|
-
const
|
|
21
|
+
const MailError_1 = require("../MailError");
|
|
22
22
|
class SendGridTransport extends MailTransport_1.MailTransport {
|
|
23
23
|
messages = [];
|
|
24
24
|
config;
|
|
@@ -94,7 +94,18 @@ class SendGridTransport extends MailTransport_1.MailTransport {
|
|
|
94
94
|
};
|
|
95
95
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
96
|
/* @ts-ignore */ // SendGrid has TS issues
|
|
97
|
-
await mail_1.default.send(sendGridMessage).catch(error => {
|
|
97
|
+
const [response] = await mail_1.default.send(sendGridMessage).catch(error => {
|
|
98
|
+
throw new MailError_1.MailError('SendGrid mail request failed', {
|
|
99
|
+
provider: 'SendGrid',
|
|
100
|
+
status: typeof error.code === 'number' ? error.code : undefined,
|
|
101
|
+
context: error.response?.body,
|
|
102
|
+
cause: error,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
const messageId = response.headers['x-message-id'];
|
|
106
|
+
if (typeof messageId === 'string') {
|
|
107
|
+
sentMessage.messageId = messageId;
|
|
108
|
+
}
|
|
98
109
|
return sentMessage;
|
|
99
110
|
}
|
|
100
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SendGridTransport.js","sourceRoot":"","sources":["../../../Mail/Transports/SendGridTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAgD;AAChD,gDAA4C;AAE5C,+CAAwC;AACxC,+CAA4C;AAC5C,0DAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"SendGridTransport.js","sourceRoot":"","sources":["../../../Mail/Transports/SendGridTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAgD;AAChD,gDAA4C;AAE5C,+CAAwC;AACxC,+CAA4C;AAC5C,0DAAmC;AACnC,4CAAwC;AAExC,MAAa,iBAAkB,SAAQ,6BAAa;IAChD,QAAQ,GAAkB,EAAE,CAAA;IAG5B,MAAM,CAAY;IAElB,YAAY,GAAW;QACnB,KAAK,EAAE,CAAA;QAEP,cAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAiB;QACxB,MAAM,WAAW,GAAG,IAAI,yBAAW,CAAC,OAAO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ChD,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;gBAC/D,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI;gBAC7B,KAAK,EAAE,KAAK;aACf,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAClD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAChC,WAAW,CAAC,SAAS,GAAG,SAAS,CAAA;QACrC,CAAC;QAED,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ;AAlGD,8CAkGC;AA9FG;IADC,IAAA,kBAAM,GAAE;8BACD,sBAAU;iDAAA"}
|
package/build/Mail/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../Mail/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../Mail/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,kCAAkC,CAAA;AAChD,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA"}
|
package/build/Mail/index.js
CHANGED
|
@@ -15,6 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Transports/MemoryTransport"), exports);
|
|
18
|
+
__exportStar(require("./Transports/CloudflareTransport"), exports);
|
|
19
|
+
__exportStar(require("./SentMessage"), exports);
|
|
20
|
+
__exportStar(require("./MailError"), exports);
|
|
18
21
|
__exportStar(require("./Mailer"), exports);
|
|
19
22
|
__exportStar(require("./Mailable"), exports);
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
package/build/Mail/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../Mail/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,2CAAwB;AACxB,6CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../Mail/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,mEAAgD;AAChD,gDAA6B;AAC7B,8CAA2B;AAC3B,2CAAwB;AACxB,6CAA0B"}
|