@appinventiv/aws-ses 0.0.0-stage → 1.0.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/README.md +147 -2
- package/dist/exception-handler.d.ts +48 -0
- package/dist/exception-handler.js +78 -0
- package/dist/exception-handler.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interface.d.ts +118 -0
- package/dist/interface.js +3 -0
- package/dist/interface.js.map +1 -0
- package/dist/mime.d.ts +7 -0
- package/dist/mime.js +33 -0
- package/dist/mime.js.map +1 -0
- package/dist/ses.d.ts +59 -0
- package/dist/ses.js +360 -0
- package/dist/ses.js.map +1 -0
- package/dist/template.d.ts +11 -0
- package/dist/template.js +35 -0
- package/dist/template.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +21 -4
- package/src/exception-handler.ts +78 -0
- package/src/index.ts +3 -0
- package/src/interface.ts +127 -0
- package/src/mime.ts +30 -0
- package/src/ses.ts +420 -0
- package/src/template.ts +37 -0
- package/tsconfig.json +20 -0
package/README.md
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @appinventiv/aws-ses
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AWS SES email for Node.js using [`@aws-sdk/client-sesv2`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sesv2/). Initialize once, then send app-owned HTML, stored SES templates, attachments, and batched bulk mail.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @appinventiv/aws-ses
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- `initiateSES(config)` — region required; credentials optional (omit them to use the default AWS credential chain)
|
|
14
|
+
- `sendMail` — HTML / text as a raw MIME message, with optional attachments
|
|
15
|
+
- `sendTemplatedMail` — SES stored template; attachments hydrate `{{placeholders}}` and send raw MIME
|
|
16
|
+
- `sendBulkMail` / `sendBulkTemplatedMail` — destinations in batches (default 50)
|
|
17
|
+
- Template CRUD: `createTemplate`, `updateTemplate`, `deleteTemplate`, `getTemplate`
|
|
18
|
+
- Optional `configurationSetName` applied to sends
|
|
19
|
+
|
|
20
|
+
## Initialize
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { ses } from '@appinventiv/aws-ses';
|
|
24
|
+
|
|
25
|
+
ses.initiateSES({
|
|
26
|
+
region: 'us-east-1',
|
|
27
|
+
defaultFrom: 'noreply@example.com',
|
|
28
|
+
configurationSetName: 'app-emails' // optional
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Explicit credentials are optional:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
ses.initiateSES({
|
|
36
|
+
region: 'us-east-1',
|
|
37
|
+
credentials: {
|
|
38
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
39
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
|
|
40
|
+
},
|
|
41
|
+
defaultFrom: 'noreply@example.com'
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`initiateSES` runs once. A second call is ignored. Pass `from` on a send, or set `defaultFrom` at init. `to` is required; `cc`, `bcc`, and `replyTo` are optional.
|
|
46
|
+
|
|
47
|
+
## App HTML
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await ses.sendMail({
|
|
51
|
+
to: 'user@example.com',
|
|
52
|
+
cc: 'ops@example.com',
|
|
53
|
+
subject: 'Hello',
|
|
54
|
+
html: '<p>Hi</p>',
|
|
55
|
+
text: 'Hi',
|
|
56
|
+
attachments: [
|
|
57
|
+
{ filename: 'notes.txt', content: 'hello', contentType: 'text/plain' }
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Provide at least one of `html` or `text`. Attachments accept `content` as a `Buffer` or string, plus optional `contentType` and `cid` (inline images).
|
|
63
|
+
|
|
64
|
+
## Stored templates
|
|
65
|
+
|
|
66
|
+
Create a template in SES. Placeholders are `{{name}}` or `{{user.email}}`.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
await ses.createTemplate({
|
|
70
|
+
templateName: 'InvoiceEmail',
|
|
71
|
+
subject: 'Invoice for {{name}}',
|
|
72
|
+
html: '<p>Hi {{name}}, amount {{amount}}</p>',
|
|
73
|
+
text: 'Hi {{name}}, amount {{amount}}'
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Without attachments, SES renders the template:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
await ses.sendTemplatedMail({
|
|
81
|
+
to: 'user@example.com',
|
|
82
|
+
templateName: 'InvoiceEmail',
|
|
83
|
+
templateData: { name: 'Alex', amount: '99' }
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
With attachments, the package loads the template, replaces `{{placeholders}}`, and sends raw MIME. SES template content cannot carry files.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
await ses.sendTemplatedMail({
|
|
91
|
+
to: 'user@example.com',
|
|
92
|
+
templateName: 'InvoiceEmail',
|
|
93
|
+
templateData: { name: 'Alex', amount: '99' },
|
|
94
|
+
attachments: [{ filename: 'invoice.pdf', content: pdfBuffer, contentType: 'application/pdf' }]
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`updateTemplate`, `deleteTemplate(templateName)`, and `getTemplate(templateName)` map to the SES template APIs. Replacement is simple token substitution, not Handlebars.
|
|
99
|
+
|
|
100
|
+
## Bulk sends
|
|
101
|
+
|
|
102
|
+
`batchSize` defaults to 50. A failed send throws; earlier messages in the batch may already have been accepted.
|
|
103
|
+
|
|
104
|
+
Shared HTML, with optional per-destination subject / html / text and shared attachments:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
await ses.sendBulkMail({
|
|
108
|
+
defaultSubject: 'Update',
|
|
109
|
+
defaultHtml: '<p>Hello</p>',
|
|
110
|
+
destinations: [
|
|
111
|
+
{ to: 'a@example.com' },
|
|
112
|
+
{ to: 'b@example.com', subject: 'Update for B' }
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Templated bulk without attachments uses SES `SendBulkEmail`. Each destination’s `templateData` is merged over `defaultTemplateData`.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
await ses.sendBulkTemplatedMail({
|
|
121
|
+
templateName: 'WelcomeEmail',
|
|
122
|
+
defaultTemplateData: { company: 'Acme' },
|
|
123
|
+
destinations: [
|
|
124
|
+
{ to: 'a@example.com', templateData: { name: 'A' } },
|
|
125
|
+
{ to: 'b@example.com', templateData: { name: 'B' } }
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Templated bulk with `attachments` hydrates each destination and sends raw MIME (same limit as a single templated send with files).
|
|
131
|
+
|
|
132
|
+
## Errors
|
|
133
|
+
|
|
134
|
+
SDK and validation failures throw the object from `SESException.getError()` (`status` and `data`). Call `ses.getClient()` only after `initiateSES`; otherwise it throws.
|
|
135
|
+
|
|
136
|
+
## API
|
|
137
|
+
|
|
138
|
+
| Method | Returns |
|
|
139
|
+
|--------|---------|
|
|
140
|
+
| `initiateSES(config)` | `void` |
|
|
141
|
+
| `sendMail(options)` | `{ messageId }` |
|
|
142
|
+
| `sendTemplatedMail(options)` | `{ messageId }` |
|
|
143
|
+
| `sendBulkMail(options)` | `{ messageIds }` |
|
|
144
|
+
| `sendBulkTemplatedMail(options)` | `{ messageIds }` |
|
|
145
|
+
| `createTemplate` / `updateTemplate` | `void` |
|
|
146
|
+
| `deleteTemplate(templateName)` | `void` |
|
|
147
|
+
| `getTemplate(templateName)` | template definition |
|
|
148
|
+
| `getClient()` | `SESv2Client` |
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description HTTP status messages enum
|
|
3
|
+
*/
|
|
4
|
+
export declare enum HTTP_STATUS_MESSAGE {
|
|
5
|
+
BAD_REQUEST = 400,
|
|
6
|
+
UNAUTHORIZED = 401,
|
|
7
|
+
FORBIDDEN = 403,
|
|
8
|
+
NOT_FOUND = 404,
|
|
9
|
+
CONFLICT = 409,
|
|
10
|
+
REQUEST_TIMEOUT = 408,
|
|
11
|
+
TOO_MANY_REQUESTS = 429,
|
|
12
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
13
|
+
SERVICE_UNAVAILABLE = 503
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @description Exception message types for SES operations
|
|
17
|
+
*/
|
|
18
|
+
export declare enum ExceptionMessage {
|
|
19
|
+
SES_CONNECTION_ERROR = "SES_CONNECTION_ERROR",
|
|
20
|
+
SES_OPERATION_ERROR = "SES_OPERATION_ERROR",
|
|
21
|
+
SES_VALIDATION_ERROR = "SES_VALIDATION_ERROR",
|
|
22
|
+
SES_NOT_FOUND = "SES_NOT_FOUND",
|
|
23
|
+
SES_UNKNOWN_ERROR = "SES_UNKNOWN_ERROR"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @description Base exception handler class
|
|
27
|
+
*/
|
|
28
|
+
export declare class ExceptionHandler {
|
|
29
|
+
protected code: number;
|
|
30
|
+
protected status: HTTP_STATUS_MESSAGE;
|
|
31
|
+
protected data: any;
|
|
32
|
+
/**
|
|
33
|
+
* @description Get error response object
|
|
34
|
+
*/
|
|
35
|
+
getError(): {
|
|
36
|
+
status: HTTP_STATUS_MESSAGE;
|
|
37
|
+
data: any;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description AWS SES exception handler
|
|
42
|
+
*/
|
|
43
|
+
export declare class SESException extends ExceptionHandler {
|
|
44
|
+
constructor(error: unknown, context?: {
|
|
45
|
+
operation?: string;
|
|
46
|
+
templateName?: string;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SESException = exports.ExceptionHandler = exports.ExceptionMessage = exports.HTTP_STATUS_MESSAGE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @description HTTP status messages enum
|
|
6
|
+
*/
|
|
7
|
+
var HTTP_STATUS_MESSAGE;
|
|
8
|
+
(function (HTTP_STATUS_MESSAGE) {
|
|
9
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
10
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
11
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
12
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
13
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["CONFLICT"] = 409] = "CONFLICT";
|
|
14
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
15
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
16
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
17
|
+
HTTP_STATUS_MESSAGE[HTTP_STATUS_MESSAGE["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
18
|
+
})(HTTP_STATUS_MESSAGE || (exports.HTTP_STATUS_MESSAGE = HTTP_STATUS_MESSAGE = {}));
|
|
19
|
+
/**
|
|
20
|
+
* @description Exception message types for SES operations
|
|
21
|
+
*/
|
|
22
|
+
var ExceptionMessage;
|
|
23
|
+
(function (ExceptionMessage) {
|
|
24
|
+
ExceptionMessage["SES_CONNECTION_ERROR"] = "SES_CONNECTION_ERROR";
|
|
25
|
+
ExceptionMessage["SES_OPERATION_ERROR"] = "SES_OPERATION_ERROR";
|
|
26
|
+
ExceptionMessage["SES_VALIDATION_ERROR"] = "SES_VALIDATION_ERROR";
|
|
27
|
+
ExceptionMessage["SES_NOT_FOUND"] = "SES_NOT_FOUND";
|
|
28
|
+
ExceptionMessage["SES_UNKNOWN_ERROR"] = "SES_UNKNOWN_ERROR";
|
|
29
|
+
})(ExceptionMessage || (exports.ExceptionMessage = ExceptionMessage = {}));
|
|
30
|
+
/**
|
|
31
|
+
* @description Base exception handler class
|
|
32
|
+
*/
|
|
33
|
+
class ExceptionHandler {
|
|
34
|
+
code;
|
|
35
|
+
status;
|
|
36
|
+
data;
|
|
37
|
+
/**
|
|
38
|
+
* @description Get error response object
|
|
39
|
+
*/
|
|
40
|
+
getError() {
|
|
41
|
+
return {
|
|
42
|
+
status: this.status || HTTP_STATUS_MESSAGE.BAD_REQUEST,
|
|
43
|
+
data: this.data
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ExceptionHandler = ExceptionHandler;
|
|
48
|
+
/**
|
|
49
|
+
* @description AWS SES exception handler
|
|
50
|
+
*/
|
|
51
|
+
class SESException extends ExceptionHandler {
|
|
52
|
+
constructor(error, context) {
|
|
53
|
+
super();
|
|
54
|
+
const err = error;
|
|
55
|
+
const name = err?.name || err?.Code || 'SES_UNKNOWN_ERROR';
|
|
56
|
+
const message = err?.message || 'Unknown SES error';
|
|
57
|
+
const httpStatus = err?.$metadata?.httpStatusCode;
|
|
58
|
+
if (name === 'NotFoundException' || httpStatus === 404) {
|
|
59
|
+
this.status = HTTP_STATUS_MESSAGE.NOT_FOUND;
|
|
60
|
+
this.data = { type: ExceptionMessage.SES_NOT_FOUND, message, ...context };
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (name === 'ValidationException' || name === 'BadRequestException' || httpStatus === 400) {
|
|
64
|
+
this.status = HTTP_STATUS_MESSAGE.BAD_REQUEST;
|
|
65
|
+
this.data = { type: ExceptionMessage.SES_VALIDATION_ERROR, message, ...context };
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (httpStatus === 401 || httpStatus === 403 || name === 'AccessDeniedException') {
|
|
69
|
+
this.status = HTTP_STATUS_MESSAGE.FORBIDDEN;
|
|
70
|
+
this.data = { type: ExceptionMessage.SES_OPERATION_ERROR, message, ...context };
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.status = HTTP_STATUS_MESSAGE.INTERNAL_SERVER_ERROR;
|
|
74
|
+
this.data = { type: ExceptionMessage.SES_UNKNOWN_ERROR, message, ...context };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SESException = SESException;
|
|
78
|
+
//# sourceMappingURL=exception-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-handler.js","sourceRoot":"","sources":["../src/exception-handler.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,mBAUX;AAVD,WAAY,mBAAmB;IAC3B,6EAAiB,CAAA;IACjB,+EAAkB,CAAA;IAClB,yEAAe,CAAA;IACf,yEAAe,CAAA;IACf,uEAAc,CAAA;IACd,qFAAqB,CAAA;IACrB,yFAAuB,CAAA;IACvB,iGAA2B,CAAA;IAC3B,6FAAyB,CAAA;AAC7B,CAAC,EAVW,mBAAmB,mCAAnB,mBAAmB,QAU9B;AAED;;GAEG;AACH,IAAY,gBAMX;AAND,WAAY,gBAAgB;IACxB,iEAA6C,CAAA;IAC7C,+DAA2C,CAAA;IAC3C,iEAA6C,CAAA;IAC7C,mDAA+B,CAAA;IAC/B,2DAAuC,CAAA;AAC3C,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAED;;GAEG;AACH,MAAa,gBAAgB;IACf,IAAI,CAAS;IACb,MAAM,CAAsB;IAC5B,IAAI,CAAM;IAEpB;;OAEG;IACH,QAAQ;QACJ,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,mBAAmB,CAAC,WAAW;YACtD,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC;IACN,CAAC;CACJ;AAdD,4CAcC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,gBAAgB;IAC9C,YAAY,KAAc,EAAE,OAAuD;QAC/E,KAAK,EAAE,CAAC;QACR,MAAM,GAAG,GAAG,KAAoG,CAAC;QACjH,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,mBAAmB,CAAC;QAC3D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,IAAI,mBAAmB,CAAC;QACpD,MAAM,UAAU,GAAG,GAAG,EAAE,SAAS,EAAE,cAAc,CAAC;QAElD,IAAI,IAAI,KAAK,mBAAmB,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC;YAC5C,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;YAC1E,OAAO;QACX,CAAC;QAED,IAAI,IAAI,KAAK,qBAAqB,IAAI,IAAI,KAAK,qBAAqB,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;YACzF,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,WAAW,CAAC;YAC9C,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;YACjF,OAAO;QACX,CAAC;QAED,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,IAAI,KAAK,uBAAuB,EAAE,CAAC;YAC/E,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC;YAC5C,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,mBAAmB,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;YAChF,OAAO;QACX,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,qBAAqB,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;IAClF,CAAC;CACJ;AA7BD,oCA6BC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ses"), exports);
|
|
18
|
+
__exportStar(require("./interface"), exports);
|
|
19
|
+
__exportStar(require("./exception-handler"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,8CAA4B;AAC5B,sDAAoC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description AWS SES client initialization options
|
|
3
|
+
*/
|
|
4
|
+
export interface ISESInitOptions {
|
|
5
|
+
region: string;
|
|
6
|
+
credentials?: {
|
|
7
|
+
accessKeyId: string;
|
|
8
|
+
secretAccessKey: string;
|
|
9
|
+
sessionToken?: string;
|
|
10
|
+
};
|
|
11
|
+
/** Used when send methods omit `from` */
|
|
12
|
+
defaultFrom?: string;
|
|
13
|
+
/** Optional SES configuration set applied to sends */
|
|
14
|
+
configurationSetName?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @description Email attachment (raw MIME path)
|
|
18
|
+
*/
|
|
19
|
+
export interface ISESAttachment {
|
|
20
|
+
filename: string;
|
|
21
|
+
content: Buffer | string;
|
|
22
|
+
contentType?: string;
|
|
23
|
+
/** Content-ID for inline images */
|
|
24
|
+
cid?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @description App-owned HTML / text send (+ optional attachments)
|
|
28
|
+
*/
|
|
29
|
+
export interface ISESSendMailOptions {
|
|
30
|
+
to: string | string[];
|
|
31
|
+
subject: string;
|
|
32
|
+
html?: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
from?: string;
|
|
35
|
+
cc?: string | string[];
|
|
36
|
+
bcc?: string | string[];
|
|
37
|
+
replyTo?: string | string[];
|
|
38
|
+
attachments?: ISESAttachment[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description SES stored template send.
|
|
42
|
+
* Attachments force hydrate + Raw MIME because Content.Template cannot carry files.
|
|
43
|
+
*/
|
|
44
|
+
export interface ISESSendTemplatedMailOptions {
|
|
45
|
+
to: string | string[];
|
|
46
|
+
templateName: string;
|
|
47
|
+
/** Object serialized to TemplateData JSON for {{placeholders}} */
|
|
48
|
+
templateData: Record<string, unknown>;
|
|
49
|
+
from?: string;
|
|
50
|
+
cc?: string | string[];
|
|
51
|
+
bcc?: string | string[];
|
|
52
|
+
replyTo?: string | string[];
|
|
53
|
+
attachments?: ISESAttachment[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Create / update template body stored in SES
|
|
57
|
+
*/
|
|
58
|
+
export interface ISESTemplateDefinition {
|
|
59
|
+
templateName: string;
|
|
60
|
+
subject: string;
|
|
61
|
+
html?: string;
|
|
62
|
+
text?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description One destination in a bulk send
|
|
66
|
+
*/
|
|
67
|
+
export interface ISESBulkDestination {
|
|
68
|
+
to: string | string[];
|
|
69
|
+
cc?: string | string[];
|
|
70
|
+
bcc?: string | string[];
|
|
71
|
+
/** Per-recipient template data (merged over defaultTemplateData) */
|
|
72
|
+
templateData?: Record<string, unknown>;
|
|
73
|
+
html?: string;
|
|
74
|
+
text?: string;
|
|
75
|
+
subject?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @description Bulk raw / simple HTML send
|
|
79
|
+
*/
|
|
80
|
+
export interface ISESSendBulkMailOptions {
|
|
81
|
+
defaultSubject: string;
|
|
82
|
+
defaultHtml?: string;
|
|
83
|
+
defaultText?: string;
|
|
84
|
+
from?: string;
|
|
85
|
+
replyTo?: string | string[];
|
|
86
|
+
attachments?: ISESAttachment[];
|
|
87
|
+
destinations: ISESBulkDestination[];
|
|
88
|
+
/** Max destinations processed per batch (default 50) */
|
|
89
|
+
batchSize?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @description Bulk templated send
|
|
93
|
+
*/
|
|
94
|
+
export interface ISESSendBulkTemplatedMailOptions {
|
|
95
|
+
templateName: string;
|
|
96
|
+
defaultTemplateData?: Record<string, unknown>;
|
|
97
|
+
from?: string;
|
|
98
|
+
replyTo?: string | string[];
|
|
99
|
+
destinations: ISESBulkDestination[];
|
|
100
|
+
batchSize?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Shared attachments. When set, each destination is hydrated and sent as Raw MIME
|
|
103
|
+
* because SendBulkEmail template content cannot carry MIME attachments.
|
|
104
|
+
*/
|
|
105
|
+
attachments?: ISESAttachment[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Result of a send operation
|
|
109
|
+
*/
|
|
110
|
+
export interface ISESSendResult {
|
|
111
|
+
messageId: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @description Result of a bulk send
|
|
115
|
+
*/
|
|
116
|
+
export interface ISESBulkSendResult {
|
|
117
|
+
messageIds: string[];
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":""}
|
package/dist/mime.d.ts
ADDED
package/dist/mime.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildRawMessage = buildRawMessage;
|
|
7
|
+
const mail_composer_1 = __importDefault(require("nodemailer/lib/mail-composer"));
|
|
8
|
+
/**
|
|
9
|
+
* @description Build an RFC822 message buffer for SES Content.Raw
|
|
10
|
+
*/
|
|
11
|
+
async function buildRawMessage(options) {
|
|
12
|
+
const composer = new mail_composer_1.default({
|
|
13
|
+
from: options.from,
|
|
14
|
+
to: options.to,
|
|
15
|
+
cc: options.cc,
|
|
16
|
+
bcc: options.bcc,
|
|
17
|
+
replyTo: options.replyTo,
|
|
18
|
+
subject: options.subject,
|
|
19
|
+
html: options.html,
|
|
20
|
+
text: options.text,
|
|
21
|
+
attachments: (options.attachments || []).map(toNodemailerAttachment)
|
|
22
|
+
});
|
|
23
|
+
return composer.compile().build();
|
|
24
|
+
}
|
|
25
|
+
function toNodemailerAttachment(attachment) {
|
|
26
|
+
return {
|
|
27
|
+
filename: attachment.filename,
|
|
28
|
+
content: attachment.content,
|
|
29
|
+
contentType: attachment.contentType,
|
|
30
|
+
cid: attachment.cid
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=mime.js.map
|
package/dist/mime.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":";;;;;AAMA,0CAcC;AApBD,iFAAwD;AAGxD;;GAEG;AACI,KAAK,UAAU,eAAe,CAAC,OAA+C;IACjF,MAAM,QAAQ,GAAG,IAAI,uBAAY,CAAC;QAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,WAAW,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC;KACvE,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,sBAAsB,CAAC,UAA0B;IACtD,OAAO;QACH,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,GAAG,EAAE,UAAU,CAAC,GAAG;KACtB,CAAC;AACN,CAAC"}
|
package/dist/ses.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SESv2Client } from '@aws-sdk/client-sesv2';
|
|
2
|
+
import { ISESBulkSendResult, ISESInitOptions, ISESSendBulkMailOptions, ISESSendBulkTemplatedMailOptions, ISESSendMailOptions, ISESSendResult, ISESSendTemplatedMailOptions, ISESTemplateDefinition } from './interface';
|
|
3
|
+
/**
|
|
4
|
+
* @description AWS SES provider for raw HTML, stored templates, attachments, and bulk sends
|
|
5
|
+
*/
|
|
6
|
+
export declare class AWSSESProvider {
|
|
7
|
+
private client;
|
|
8
|
+
private defaultFrom?;
|
|
9
|
+
private configurationSetName?;
|
|
10
|
+
private region?;
|
|
11
|
+
/**
|
|
12
|
+
* @description Initialize SESv2 client once
|
|
13
|
+
* @param {ISESInitOptions} config - Region, optional credentials, defaultFrom, configuration set
|
|
14
|
+
*/
|
|
15
|
+
initiateSES(config: ISESInitOptions): void;
|
|
16
|
+
/**
|
|
17
|
+
* @description Send app-owned HTML/text, optionally with attachments, via Content.Raw
|
|
18
|
+
*/
|
|
19
|
+
sendMail(options: ISESSendMailOptions): Promise<ISESSendResult>;
|
|
20
|
+
/**
|
|
21
|
+
* @description Send a stored SES template.
|
|
22
|
+
* Without attachments uses Content.Template. With attachments hydrates the template and sends Raw MIME.
|
|
23
|
+
*/
|
|
24
|
+
sendTemplatedMail(options: ISESSendTemplatedMailOptions): Promise<ISESSendResult>;
|
|
25
|
+
/**
|
|
26
|
+
* @description Send the same HTML/text (and optional shared attachments) to many destinations in batches
|
|
27
|
+
*/
|
|
28
|
+
sendBulkMail(options: ISESSendBulkMailOptions): Promise<ISESBulkSendResult>;
|
|
29
|
+
/**
|
|
30
|
+
* @description Bulk templated send.
|
|
31
|
+
* Without attachments uses SendBulkEmail. With attachments hydrates each destination and sends Raw MIME.
|
|
32
|
+
*/
|
|
33
|
+
sendBulkTemplatedMail(options: ISESSendBulkTemplatedMailOptions): Promise<ISESBulkSendResult>;
|
|
34
|
+
/**
|
|
35
|
+
* @description Create an email template in SES
|
|
36
|
+
*/
|
|
37
|
+
createTemplate(definition: ISESTemplateDefinition): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* @description Update an existing SES email template
|
|
40
|
+
*/
|
|
41
|
+
updateTemplate(definition: ISESTemplateDefinition): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* @description Delete an SES email template
|
|
44
|
+
*/
|
|
45
|
+
deleteTemplate(templateName: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* @description Load an SES email template
|
|
48
|
+
*/
|
|
49
|
+
getTemplate(templateName: string): Promise<ISESTemplateDefinition>;
|
|
50
|
+
/**
|
|
51
|
+
* @description Underlying SESv2 client (throws if not initialized)
|
|
52
|
+
*/
|
|
53
|
+
getClient(): SESv2Client;
|
|
54
|
+
private resolveFrom;
|
|
55
|
+
private assertContent;
|
|
56
|
+
private assertAddresses;
|
|
57
|
+
}
|
|
58
|
+
/** Pre-configured SES provider singleton */
|
|
59
|
+
export declare const ses: AWSSESProvider;
|