@acmekit/notification-sendgrid 2.13.1
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 +0 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/services/sendgrid.d.ts +18 -0
- package/dist/services/sendgrid.d.ts.map +1 -0
- package/dist/services/sendgrid.js +67 -0
- package/dist/services/sendgrid.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAKA,wBAEE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
4
|
+
const sendgrid_1 = require("./services/sendgrid");
|
|
5
|
+
const services = [sendgrid_1.SendgridNotificationService];
|
|
6
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.NOTIFICATION, {
|
|
7
|
+
services,
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,oDAAkE;AAClE,kDAAiE;AAEjE,MAAM,QAAQ,GAAG,CAAC,sCAA2B,CAAC,CAAA;AAE9C,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,YAAY,EAAE;IAClD,QAAQ;CACT,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Logger, NotificationTypes, SendgridNotificationServiceOptions } from "@acmekit/framework/types";
|
|
2
|
+
import { AbstractNotificationProviderService } from "@acmekit/framework/utils";
|
|
3
|
+
type InjectedDependencies = {
|
|
4
|
+
logger: Logger;
|
|
5
|
+
};
|
|
6
|
+
interface SendgridServiceConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
from: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class SendgridNotificationService extends AbstractNotificationProviderService {
|
|
11
|
+
static identifier: string;
|
|
12
|
+
protected config_: SendgridServiceConfig;
|
|
13
|
+
protected logger_: Logger;
|
|
14
|
+
constructor({ logger }: InjectedDependencies, options: SendgridNotificationServiceOptions);
|
|
15
|
+
send(notification: NotificationTypes.ProviderSendNotificationDTO): Promise<NotificationTypes.ProviderSendNotificationResultsDTO>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=sendgrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendgrid.d.ts","sourceRoot":"","sources":["../../src/services/sendgrid.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,kCAAkC,EACnC,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,mCAAmC,EAEpC,MAAM,0BAA0B,CAAA;AAGjC,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAID,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACb;AAED,qBAAa,2BAA4B,SAAQ,mCAAmC;IAClF,MAAM,CAAC,UAAU,SAA0B;IAC3C,SAAS,CAAC,OAAO,EAAE,qBAAqB,CAAA;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAGvB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAChC,OAAO,EAAE,kCAAkC;IAYvC,IAAI,CACR,YAAY,EAAE,iBAAiB,CAAC,2BAA2B,GAC1D,OAAO,CAAC,iBAAiB,CAAC,kCAAkC,CAAC;CA+DjE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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.SendgridNotificationService = void 0;
|
|
7
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
8
|
+
const mail_1 = __importDefault(require("@sendgrid/mail"));
|
|
9
|
+
class SendgridNotificationService extends utils_1.AbstractNotificationProviderService {
|
|
10
|
+
constructor({ logger }, options) {
|
|
11
|
+
super();
|
|
12
|
+
this.config_ = {
|
|
13
|
+
apiKey: options.api_key,
|
|
14
|
+
from: options.from,
|
|
15
|
+
};
|
|
16
|
+
this.logger_ = logger;
|
|
17
|
+
mail_1.default.setApiKey(this.config_.apiKey);
|
|
18
|
+
}
|
|
19
|
+
async send(notification) {
|
|
20
|
+
if (!notification) {
|
|
21
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.INVALID_DATA, `No notification information provided`);
|
|
22
|
+
}
|
|
23
|
+
const attachments = Array.isArray(notification.attachments)
|
|
24
|
+
? notification.attachments.map((attachment) => ({
|
|
25
|
+
content: attachment.content, // Base64 encoded string of the file
|
|
26
|
+
filename: attachment.filename,
|
|
27
|
+
content_type: attachment.content_type, // MIME type (e.g., 'application/pdf')
|
|
28
|
+
disposition: attachment.disposition ?? "attachment", // Default to 'attachment'
|
|
29
|
+
id: attachment.id ?? undefined, // Optional: unique identifier for inline attachments
|
|
30
|
+
}))
|
|
31
|
+
: undefined;
|
|
32
|
+
const from = notification.from?.trim() || this.config_.from;
|
|
33
|
+
let mailContent;
|
|
34
|
+
if ("content" in notification && !!notification.content) {
|
|
35
|
+
mailContent = {
|
|
36
|
+
subject: notification.content?.subject,
|
|
37
|
+
html: notification.content?.html,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// we can't mix html and templates for sendgrid
|
|
42
|
+
mailContent = {
|
|
43
|
+
templateId: notification.template,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const message = {
|
|
47
|
+
to: notification.to,
|
|
48
|
+
from: from,
|
|
49
|
+
dynamicTemplateData: notification.data,
|
|
50
|
+
attachments: attachments,
|
|
51
|
+
...mailContent,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
// Unfortunately we don't get anything useful back in the response
|
|
55
|
+
await mail_1.default.send(message);
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const errorCode = error.code;
|
|
60
|
+
const responseError = error.response?.body?.errors?.[0];
|
|
61
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.UNEXPECTED_STATE, `Failed to send email: ${errorCode} - ${responseError?.message ?? "unknown error"}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.SendgridNotificationService = SendgridNotificationService;
|
|
66
|
+
SendgridNotificationService.identifier = "notification-sendgrid";
|
|
67
|
+
//# sourceMappingURL=sendgrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendgrid.js","sourceRoot":"","sources":["../../src/services/sendgrid.ts"],"names":[],"mappings":";;;;;;AAKA,oDAGiC;AACjC,0DAAqC;AAarC,MAAa,2BAA4B,SAAQ,2CAAmC;IAKlF,YACE,EAAE,MAAM,EAAwB,EAChC,OAA2C;QAE3C,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,OAAO,GAAG;YACb,MAAM,EAAE,OAAO,CAAC,OAAO;YACvB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAA;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,cAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,IAAI,CACR,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GAAG,WAAW;SACf,CAAA;QAED,IAAI,CAAC;YACH,kEAAkE;YAClE,MAAM,cAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAC5B,OAAO,EAAE,CAAA;QACX,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;YAC5B,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;YACvD,MAAM,IAAI,oBAAY,CACpB,oBAAY,CAAC,KAAK,CAAC,gBAAgB,EACnC,yBAAyB,SAAS,MAChC,aAAa,EAAE,OAAO,IAAI,eAC5B,EAAE,CACH,CAAA;QACH,CAAC;IACH,CAAC;;AAnFH,kEAoFC;AAnFQ,sCAAU,GAAG,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/services/sendgrid.ts"],"version":"5.9.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acmekit/notification-sendgrid",
|
|
3
|
+
"version": "2.13.1",
|
|
4
|
+
"description": "Sendgrid notification provider for AcmeKit",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/acmekit/acmekit",
|
|
9
|
+
"directory": "packages/modules/providers/notification-sendgrid"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"!dist/**/__tests__",
|
|
14
|
+
"!dist/**/__mocks__",
|
|
15
|
+
"!dist/**/__fixtures__"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
19
|
+
},
|
|
20
|
+
"author": "AcmeKit",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "../../../../node_modules/.bin/jest --passWithNoTests src",
|
|
24
|
+
"test:integration": "../../../../node_modules/.bin/jest --passWithNoTests --forceExit --testPathPattern=\"integration-tests/__tests__/.*\\.spec\\.ts\"",
|
|
25
|
+
"build": "yarn run -T rimraf dist && yarn run -T tsc --build ./tsconfig.json",
|
|
26
|
+
"watch": "yarn run -T tsc --watch"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@acmekit/framework": "2.13.1"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@sendgrid/mail": "^8.1.6"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@acmekit/framework": "2.13.1"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"acmekit-provider",
|
|
39
|
+
"acmekit-provider-sendgrid"
|
|
40
|
+
]
|
|
41
|
+
}
|