@medusajs/notification-sendgrid 0.0.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.js +9 -0
- package/dist/services/sendgrid.d.ts +16 -0
- package/dist/services/sendgrid.js +42 -0
- package/package.json +40 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sendgrid_1 = require("./services/sendgrid");
|
|
4
|
+
const services = [sendgrid_1.SendgridNotificationService];
|
|
5
|
+
const providerExport = {
|
|
6
|
+
services,
|
|
7
|
+
};
|
|
8
|
+
exports.default = providerExport;
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFDQSxrREFBaUU7QUFFakUsTUFBTSxRQUFRLEdBQUcsQ0FBQyxzQ0FBMkIsQ0FBQyxDQUFBO0FBRTlDLE1BQU0sY0FBYyxHQUEwQjtJQUM1QyxRQUFRO0NBQ1QsQ0FBQTtBQUVELGtCQUFlLGNBQWMsQ0FBQSJ9
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Logger, NotificationTypes, SendgridNotificationServiceOptions } from "@medusajs/types";
|
|
2
|
+
import { AbstractNotificationProviderService } from "@medusajs/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
|
+
protected config_: SendgridServiceConfig;
|
|
12
|
+
protected logger_: Logger;
|
|
13
|
+
constructor({ logger }: InjectedDependencies, options: SendgridNotificationServiceOptions);
|
|
14
|
+
send(notification: NotificationTypes.ProviderSendNotificationDTO): Promise<NotificationTypes.ProviderSendNotificationResultsDTO>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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("@medusajs/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.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `No notification information provided`);
|
|
22
|
+
}
|
|
23
|
+
const message = {
|
|
24
|
+
to: notification.to,
|
|
25
|
+
from: this.config_.from,
|
|
26
|
+
templateId: notification.template,
|
|
27
|
+
dynamicTemplateData: notification.data,
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
// Unfortunately we don't get anything useful back in the response
|
|
31
|
+
await mail_1.default.send(message);
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
const errorCode = error.code;
|
|
36
|
+
const responseError = error.response?.body?.errors?.[0];
|
|
37
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, `Failed to send email: ${errorCode} - ${responseError?.message ?? "unknown error"}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.SendgridNotificationService = SendgridNotificationService;
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZGdyaWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VydmljZXMvc2VuZGdyaWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBS0EsMkNBR3dCO0FBQ3hCLDBEQUFxQztBQVdyQyxNQUFhLDJCQUE0QixTQUFRLDJDQUFtQztJQUlsRixZQUNFLEVBQUUsTUFBTSxFQUF3QixFQUNoQyxPQUEyQztRQUUzQyxLQUFLLEVBQUUsQ0FBQTtRQUVQLElBQUksQ0FBQyxPQUFPLEdBQUc7WUFDYixNQUFNLEVBQUUsT0FBTyxDQUFDLE9BQU87WUFDdkIsSUFBSSxFQUFFLE9BQU8sQ0FBQyxJQUFJO1NBQ25CLENBQUE7UUFDRCxJQUFJLENBQUMsT0FBTyxHQUFHLE1BQU0sQ0FBQTtRQUNyQixjQUFRLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7SUFDekMsQ0FBQztJQUVELEtBQUssQ0FBQyxJQUFJLENBQ1IsWUFBMkQ7UUFFM0QsSUFBSSxDQUFDLFlBQVksRUFBRTtZQUNqQixNQUFNLElBQUksbUJBQVcsQ0FDbkIsbUJBQVcsQ0FBQyxLQUFLLENBQUMsWUFBWSxFQUM5QixzQ0FBc0MsQ0FDdkMsQ0FBQTtTQUNGO1FBRUQsTUFBTSxPQUFPLEdBQUc7WUFDZCxFQUFFLEVBQUUsWUFBWSxDQUFDLEVBQUU7WUFDbkIsSUFBSSxFQUFFLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSTtZQUN2QixVQUFVLEVBQUUsWUFBWSxDQUFDLFFBQVE7WUFDakMsbUJBQW1CLEVBQUUsWUFBWSxDQUFDLElBRXJCO1NBQ2QsQ0FBQTtRQUVELElBQUk7WUFDRixrRUFBa0U7WUFDbEUsTUFBTSxjQUFRLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFBO1lBQzVCLE9BQU8sRUFBRSxDQUFBO1NBQ1Y7UUFBQyxPQUFPLEtBQUssRUFBRTtZQUNkLE1BQU0sU0FBUyxHQUFHLEtBQUssQ0FBQyxJQUFJLENBQUE7WUFDNUIsTUFBTSxhQUFhLEdBQUcsS0FBSyxDQUFDLFFBQVEsRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUE7WUFDdkQsTUFBTSxJQUFJLG1CQUFXLENBQ25CLG1CQUFXLENBQUMsS0FBSyxDQUFDLGdCQUFnQixFQUNsQyx5QkFBeUIsU0FBUyxNQUNoQyxhQUFhLEVBQUUsT0FBTyxJQUFJLGVBQzVCLEVBQUUsQ0FDSCxDQUFBO1NBQ0Y7SUFDSCxDQUFDO0NBQ0Y7QUFwREQsa0VBb0RDIn0=
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@medusajs/notification-sendgrid",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Sendgrid notification provider for Medusa",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/medusajs/medusa",
|
|
9
|
+
"directory": "packages/modules/providers/notification-sendgrid"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=16"
|
|
16
|
+
},
|
|
17
|
+
"author": "Medusa",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
|
|
21
|
+
"test": "jest --passWithNoTests src",
|
|
22
|
+
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.spec.ts",
|
|
23
|
+
"build": "rimraf dist && tsc -p ./tsconfig.json",
|
|
24
|
+
"watch": "tsc --watch"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"cross-env": "^5.2.1",
|
|
28
|
+
"jest": "^25.5.4",
|
|
29
|
+
"rimraf": "^5.0.1",
|
|
30
|
+
"typescript": "^4.9.5"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@medusajs/utils": "^1.11.7",
|
|
34
|
+
"@sendgrid/mail": "^8.1.3"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"medusa-provider",
|
|
38
|
+
"medusa-provider-sendgrid"
|
|
39
|
+
]
|
|
40
|
+
}
|