medusa-plugin-ses 1.0.2 → 2.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/.babelrc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "plugins": [
3
+ "@babel/plugin-proposal-class-properties",
4
+ "@babel/plugin-transform-instanceof",
5
+ "@babel/plugin-transform-classes"
6
+ ],
7
+ "presets": ["@babel/preset-env"],
8
+ "env": {
9
+ "test": {
10
+ "plugins": ["@babel/plugin-transform-runtime"]
11
+ }
12
+ }
13
+ }
package/README.md CHANGED
@@ -4,11 +4,11 @@ Notifications plugin for Medusa ecommerce server that sends transactional emails
4
4
 
5
5
  ## Features
6
6
 
7
- - Uses the email templating features built into AWS SES
7
+ - THERE ARE BREAKING CHANGES IF YOU ARE UPGRADING FROM 1.x to 2.0
8
+ - ~~Uses the email templating features built into AWS SES~~ Changed in version 2.0. Templates are now stored locally. See Configuration section below.
8
9
  - Templates are based on handlebars, so they are compatible with Sendgrid email templates
9
- - AWS has no frontend for managing templates like Sendgrid does. You must use the AWS CLI or a third party template manager.
10
- - Refer to the AWS documentation at https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_CreateEmailTemplate.html.
11
- - This plugin does not currently handle email attachments of any sort. If you have a plugin that adds pdf invoices or other attachments, they will not be sent via this plugin. This may be added at a later time if the need is there.
10
+ - ~~This plugin does not currently handle email attachments of any sort. If you have a plugin that adds pdf invoices or other attachments, they will not be sent via this plugin. This may be added at a later time if the need is there.~~ Support for attachments added in version 2.0.
11
+ - An API endpoint for testing and that can be used with other (non-Medusa) applications is included. By default, the endpoint does nothing for security reasons. See configuration options below to enable it.
12
12
 
13
13
  ## Configuration
14
14
 
@@ -21,23 +21,24 @@ Enable in your medusa-config.js file similar to other plugins:
21
21
  access_key_id: process.env.SES_ACCESS_KEY_ID,
22
22
  secret_access_key: process.env.SES_SECRET_ACCESS_KEY,
23
23
  region: process.env.SES_REGION,
24
- from: "example@example.com",
25
- order_placed_template: "order_placed"
26
- //order_return_requested_template: ""
27
- //swap_shipment_created_template: ""
28
- //claim_shipment_created_template: ""
29
- //order_items_returned_template: ""
30
- //swap_received_template: ""
31
- //swap_created_template: ""
32
- //gift_card_created_template: ""
33
- //gift_card_created_template: ""
34
- //order_shipped_template: ""
35
- //order_canceled_template: ""
36
- //user_password_reset_template: ""
37
- //medusa_restock_template: ""
38
- //order_refund_created_template: ""
24
+ from: process.env.SES_FROM,
25
+ enable_endpoint: process.env.SES_ENABLE_ENDPOINT,
26
+ template_path: process.env.SES_TEMPLATE_PATH,
27
+ order_placed_template: 'order_placed',
28
+ order_shipped_template: 'order_shipped',
29
+ user_password_reset_template: 'user_password_reset',
30
+ gift_card_created_template: 'gift_card_created',
31
+ //order_canceled_template: 'order_canceled',
32
+ //order_refund_created_template: 'order_refund_created',
33
+ //order_return_requested_template: 'order_return_requested',
34
+ //order_items_returned_template: 'order_items_returned',
35
+ //swap_created_template: 'swap_created',
36
+ //swap_shipment_created_template: 'swap_shipment_created',
37
+ //swap_received_template: 'swap_received',
38
+ //claim_shipment_created_template: 'claim_shipment_created',
39
+ //medusa_restock_template: 'medusa_restock',
39
40
  }
40
- }
41
+ },
41
42
  ```
42
43
 
43
44
  The credentials and region are pulled from env variables.
@@ -45,11 +46,49 @@ The credentials and region are pulled from env variables.
45
46
  SES_REGION=""
46
47
  SES_ACCESS_KEY_ID=""
47
48
  SES_SECRET_ACCESS_KEY=""
49
+ SES_FROM="Cool Company <orders@example.com>"
50
+ SES_ENABLE_ENDPOINT=false
51
+ SES_TEMPLATE_PATH="/full/absolute/path/to/medusa-server/data/templates"
48
52
  ```
49
53
  - SES_REGION will be for example "us-east-1"
50
- - Obtain the access key and secret access key by creating an IAM user with SES send permissions
51
54
 
52
- The from email address must be a verified sender in your AWS account.
55
+ - Obtain the access key id and secret access key by creating an IAM user with SES send permissions.
56
+
57
+ - The SES_FROM email address must be a verified sender in your AWS account.
58
+
59
+ - The template path is the relative path from the medusa-server root folder. For example, create a 'data/templates' folder and make 'data/templates' the SES_TEMPLATE_PATH variable.
60
+ ```
61
+ medusa-server // root directory
62
+ |-data
63
+ |-templates
64
+ |-order_placed // or whatever you name your templates and specify in the config file
65
+ |-subject.hbs
66
+ |-html.hbs
67
+ |-text.hbs
68
+ |-gift_card_created
69
+ |-subject.hbs
70
+ |-html.hbs
71
+ |-text.hbs
72
+ |- etc
73
+ ```
74
+
75
+ - When emails are sent, each of the three parts will be compiled.
76
+ * subject is required
77
+ * either html or text is required, but one or the other can be blank.
78
+ - The template reference here explains the variables that can be used: https://docs.medusajs.com/add-plugins/sendgrid/#template-reference
79
+
80
+
81
+ - This plugin adds an endpoint at http://[server]/ses/send
82
+ By default, the endpoint will refuse to send any emails.
83
+ This endpoint may be useful for testing purposes and for use by related applications.
84
+ There is NO SECURITY on the endpoint by default.
85
+ Most people will NOT need to enable this endpoint.
86
+ If you are certain that you want to enable it and that you know what you are doing,
87
+ set the environment variable SES_ENABLE_ENDPOINT to "42" (string).
88
+ The unsual setting is meant to prevent enabling by accident or without thought.
89
+ To use the endpoint, POST a json req.body with: template_id, from, to, and data to /ses/send.
90
+ Remember that the from email address must be a verified sender in your AWS console.
91
+ Also remember that if your AWS account is still in sandbox mode, you can only SEND emails to verified sender email addresses.
53
92
 
54
93
  ## Acknowledgement
55
94
 
package/api/index.js CHANGED
@@ -5,11 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _express = require("express");
8
- var _routes = _interopRequireDefault(require("./routes"));
8
+ var _bodyParser = _interopRequireDefault(require("body-parser"));
9
+ var _medusaCoreUtils = require("medusa-core-utils");
9
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- var _default = function _default(container) {
11
- var app = (0, _express.Router)();
12
- (0, _routes["default"])(app);
13
- return app;
11
+ var router = (0, _express.Router)();
12
+ var _default = function _default(app) {
13
+ router.use(_bodyParser["default"].json());
14
+ router.post("/ses/send", function (req, res) {
15
+ var sesService = req.scope.resolve("sesService");
16
+ var schema = _medusaCoreUtils.Validator.object().keys({
17
+ template_id: _medusaCoreUtils.Validator.string().required(),
18
+ from: _medusaCoreUtils.Validator.string().required(),
19
+ to: _medusaCoreUtils.Validator.string().required(),
20
+ data: _medusaCoreUtils.Validator.object().optional()["default"]({})
21
+ });
22
+ var _schema$validate = schema.validate(req.body),
23
+ value = _schema$validate.value,
24
+ error = _schema$validate.error;
25
+ if (error) {
26
+ throw new _medusaCoreUtils.MedusaError(_medusaCoreUtils.MedusaError.Types.INVALID_DATA, error.details);
27
+ }
28
+ sesService.sendEmail(value.template_id, value.from, value.to, value.data).then(function (result) {
29
+ return res.json({
30
+ result: result
31
+ });
32
+ });
33
+ });
34
+ return router;
14
35
  };
15
36
  exports["default"] = _default;
package/jest.config.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ testEnvironment: "node",
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "medusa-plugin-ses",
3
- "version": "1.0.2",
4
- "description": "AWS SES transactional emails based on medusa-plugin-sendgrid by Oliver Juhl",
3
+ "version": "2.0.1",
4
+ "description": "AWS SES transactional emails using local handlebars templates",
5
5
  "main": "index.js",
6
6
  "repository": {
7
7
  "type": "git",
@@ -22,24 +22,28 @@
22
22
  "client-sessions": "^0.8.0",
23
23
  "cross-env": "^5.2.1",
24
24
  "jest": "^25.5.2",
25
- "medusa-interfaces": "^1.3.3"
25
+ "medusa-interfaces": "^1.3.4"
26
26
  },
27
27
  "scripts": {
28
- "build": "babel src -d .",
29
28
  "prepare": "cross-env NODE_ENV=production yarn run build",
30
- "watch": "babel -w src --out-dir . --ignore **/__tests__",
31
- "test": "jest --passWithNoTests"
29
+ "test": "jest --passWithNoTests src",
30
+ "build": "babel src --out-dir . --ignore '**/__tests__','**/__mocks__'",
31
+ "watch": "babel -w src --out-dir . --ignore '**/__tests__','**/__mocks__'"
32
32
  },
33
33
  "peerDependencies": {
34
- "medusa-interfaces": "1.x"
34
+ "medusa-interfaces": "^1.3.4"
35
35
  },
36
36
  "dependencies": {
37
37
  "@aws-sdk/client-ses": "^3.241.0",
38
38
  "@babel/plugin-transform-classes": "^7.9.5",
39
39
  "body-parser": "^1.19.0",
40
40
  "express": "^4.17.1",
41
+ "fs": "^0.0.1-security",
42
+ "handlebars": "^4.7.7",
41
43
  "medusa-core-utils": "^1.1.37",
42
- "medusa-test-utils": "^1.1.37"
44
+ "medusa-test-utils": "^1.1.37",
45
+ "nodemailer": "^6.9.1",
46
+ "path": "^0.12.7"
43
47
  },
44
48
  "gitHead": "3bbd1e8507e00bc471de6ae3c30207999a4a4011",
45
49
  "keywords": [