@codee-sh/medusa-plugin-notification-emails 1.0.0 → 1.0.2

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 CHANGED
@@ -1,26 +1,21 @@
1
- # Medusa plugin notification emails
1
+ # Medusa plugin notification
2
2
 
3
- A comprehensive notification plugin for Medusa v2 that provides a flexible, block-based template system for multiple channels (Email and Slack) with internationalization support, custom translations, and seamless integration with Medusa's notification module.
3
+ Medusa v2 plugin for building and sending transactional notifications from one place.
4
+ It provides a template system, admin builder, and rendering workflows for email and Slack.
4
5
 
5
6
  ## Features
6
7
 
7
- - **Multi-Channel Templates**: Pre-built templates for Email and Slack channels
8
- - **Block-Based System**: Templates are built using a flexible block system that can be stored in a database for future builder functionality
9
- - **Email Templates**: Customizable email templates built with [React Email](https://react.email) for common use cases
10
- - **Slack Templates**: Slack Block Kit compatible templates for Slack notifications
11
- - **Template Service Architecture**: Unified `AbstractTemplateService` with channel-specific implementations (`EmailTemplateService`, `SlackTemplateService`)
12
- - **Automatic Interpolation**: Smart variable interpolation system that processes `{{data.*}}` and `{{translations.*}}` placeholders recursively
13
- - **Internationalization**: Built-in support for multiple locales (Polish, English)
14
- - **Customizable**: Override translations and customize templates without modifying core files
15
- - **Integration**: Integrates with Medusa's notification module
16
- - **Admin Panel**: Preview and test templates directly from Medusa Admin
17
- - **Type-Safe**: Full TypeScript support with exported types
18
- - **HTML & Plain Text**: Automatically generates both HTML and plain text versions of emails
8
+ - Build and manage notification templates for two channels: email and Slack
9
+ - Use three template sources: built-in (`system`), database-managed (`db`), and code-registered (`external`)
10
+ - Build templates quickly with a reusable block system instead of writing full markup from scratch
11
+ - Edit `db` templates in Medusa Admin using a block-based builder
12
+ - Render notifications through dedicated workflows and pass output to Medusa notification providers
13
+ - Customize translations and register external templates without changing core plugin code
19
14
 
20
15
  ## Compatibility
21
16
 
22
- - **Medusa Version**: `>= 2.8.8`
23
- - **Node Version**: `>= 20`
17
+ - Medusa: `>= 2.8.8`
18
+ - Node.js: `>= 20`
24
19
 
25
20
  ## Installation
26
21
 
@@ -30,110 +25,52 @@ npm install @codee-sh/medusa-plugin-notification-emails
30
25
  yarn add @codee-sh/medusa-plugin-notification-emails
31
26
  ```
32
27
 
33
- ## Quick Start
28
+ ## Basic setup
34
29
 
35
- ### 1. Register the Plugin
36
-
37
- Add to your `medusa-config.ts`:
30
+ Register plugin in `medusa-config.ts`:
38
31
 
39
32
  ```typescript
40
33
  module.exports = defineConfig({
41
34
  plugins: [
42
- "@codee-sh/medusa-plugin-notification-emails"
43
- ]
35
+ {
36
+ resolve: "@codee-sh/medusa-plugin-notification-emails",
37
+ options: {
38
+ customTranslations: {},
39
+ extend: {
40
+ services: [],
41
+ },
42
+ },
43
+ },
44
+ ],
44
45
  })
45
46
  ```
46
47
 
47
- ### 2. Configure Notification Provider
48
-
49
- Set up a notification provider - see [Configuration Documentation](./docs/configuration.md) for details.
50
-
51
- ### 3. Use Templates
52
-
53
- The plugin includes built-in subscribers that automatically send email notifications for various events. You can also use templates directly in your code:
54
-
55
- #### Email Templates
56
-
57
- ```typescript
58
- import { emailService, TEMPLATES_NAMES } from "@codee-sh/medusa-plugin-notification-emails/templates/emails"
59
-
60
- const { html, text, subject } = await emailService.render({
61
- templateName: TEMPLATES_NAMES.ORDER_PLACED,
62
- data: templateData,
63
- options: { locale: "pl" }
64
- })
65
- ```
66
-
67
- #### Slack Templates
68
-
69
- ```typescript
70
- import { slackService, TEMPLATES_NAMES } from "@codee-sh/medusa-plugin-notification-emails/templates/slack"
71
-
72
- const { blocks } = await slackService.render({
73
- templateName: TEMPLATES_NAMES.INVENTORY_LEVEL,
74
- data: templateData,
75
- options: { locale: "en" }
76
- })
77
- ```
78
-
79
- **Note**: Templates use a block-based system where each template is defined as an array of blocks. The system automatically interpolates variables like `{{data.order.id}}` and `{{translations.headerTitle}}` throughout the blocks.
80
-
81
- See [Templates Documentation](./docs/templates.md) for detailed usage examples.
82
-
83
- ## Available Templates
84
-
85
- ### Email Templates
86
-
87
- - **[Order Placed](./docs/templates/order-placed.md)** (`order-placed`) - Order confirmation email template
88
- - **Order Completed** (`order-completed`) - Order completion notification template
89
- - **[Contact Form](./docs/templates/contact-form.md)** (`contact-form`) - Contact form submission email template
90
- - **Order Updated** (`order-updated`) - Order update notification template
91
- - **Inventory Level** (`inventory-level`) - Inventory level notification template
92
-
93
- ### Slack Templates
94
-
95
- - **Inventory Level** (`inventory-level`) - Inventory level notification for Slack
96
- - **Product** (`product`) - Product notification for Slack
97
- - **Product Variant** (`product-variant`) - Product variant notification for Slack
98
-
99
- See [Templates Documentation](./docs/templates.md) for general template information and [Blocks Documentation](./docs/blocks.md) for details on the block system.
100
-
101
- ## Built-in Subscribers
102
-
103
- The plugin includes automatic email notifications for the following events:
104
-
105
- - **`order.placed`** - Sends order confirmation email when an order is placed
106
- - **`order.completed`** - Sends order completion notification when an order is completed
107
-
108
- These subscribers automatically:
109
- - Fetch order data from Medusa
110
- - Render email templates using React Email
111
- - Send notifications via Medusa's notification module
112
- - Respect custom translations configured in plugin options
113
-
114
- See [Configuration Documentation](./docs/configuration.md) for details on customizing subscriber behavior.
48
+ Then continue with configuration and usage guides in `docs/`.
115
49
 
116
- ## Admin Panel
50
+ Template IDs are resolved by prefix:
117
51
 
118
- Access the template preview in Medusa Admin at `/app/notifications/render`. See [Admin Panel Documentation](./docs/admin.md) for details.
52
+ - IDs starting with `system` or `external` are rendered from the in-memory registry (no DB lookup).
53
+ - Other IDs are treated as DB templates and must exist in `mpn_builder_template`.
119
54
 
120
55
  ## Documentation
121
56
 
122
- - [Templates](./docs/templates.md) - Using templates and creating custom subscribers
123
- - [Blocks System](./docs/blocks.md) - Understanding the block-based template system
124
- - [Translations](./docs/translations.md) - Internationalization and custom translations
125
- - [Configuration](./docs/configuration.md) - Plugin configuration options
126
- - [Admin Panel](./docs/admin.md) - Admin interface usage
127
- - [Creating Custom Templates](./docs/contributing/creating-templates.md) - Guide for creating new templates
57
+ - [Configuration](./docs/configuration.md)
58
+ - [Templates](./docs/templates.md)
59
+ - [Blocks](./docs/blocks.md)
60
+ - [Translations](./docs/translations.md)
61
+ - [Admin](./docs/admin.md)
62
+ - [Tests](./docs/tests.md)
63
+ - [Creating Templates](./docs/contributing/creating-templates.md)
128
64
 
129
65
  ## Exports
130
66
 
131
- The plugin exports the following:
67
+ Public entrypoints:
132
68
 
133
- - `@codee-sh/medusa-plugin-notification-emails/templates/emails` - Email template service and types
134
- - `@codee-sh/medusa-plugin-notification-emails/templates/slack` - Slack template service and types
135
- - `@codee-sh/medusa-plugin-notification-emails/templates/shared` - Shared template utilities
136
- - `@codee-sh/medusa-plugin-notification-emails/utils` - Utility functions
69
+ - `@codee-sh/medusa-plugin-notification-emails/workflows`
70
+ - `@codee-sh/medusa-plugin-notification-emails/modules/*`
71
+ - `@codee-sh/medusa-plugin-notification-emails/providers/*`
72
+ - `@codee-sh/medusa-plugin-notification-emails/utils`
73
+ - `@codee-sh/medusa-plugin-notification-emails/admin`
137
74
 
138
75
  ## License
139
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codee-sh/medusa-plugin-notification-emails",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Medusa plugin for notifications emails.",
5
5
  "author": "Codee Team (https://codee.dev)",
6
6
  "license": "MIT",
@@ -38,13 +38,19 @@
38
38
  "publish-local": "npx medusa plugin:publish",
39
39
  "publish-package": "dotenv npm publish --access public",
40
40
  "email:dev": "email dev --dir emails-previews",
41
+ "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent",
42
+ "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
43
+ "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
44
+ "test:db:up": "docker compose -f docker-compose.test.yml up -d",
45
+ "test:db:down": "docker compose -f docker-compose.test.yml down -v",
41
46
  "format": "prettier --write \"src/**/*.{ts,tsx}\"",
42
47
  "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
43
48
  "changeset": "changeset",
44
49
  "version": "changeset version",
45
50
  "release": "changeset publish",
46
51
  "release:manual": "npm publish --access public",
47
- "prepare-release": "bash scripts/prepare-release.sh"
52
+ "prepare-release": "bash scripts/prepare-release.sh",
53
+ "pr:create": "bash scripts/create-pr.sh"
48
54
  },
49
55
  "dependencies": {
50
56
  "@dnd-kit/core": "^6.3.1",
@@ -76,11 +82,15 @@
76
82
  "@react-email/preview-server": "^4.3.1",
77
83
  "@react-email/render": "^1.4.0",
78
84
  "@swc/core": "1.5.7",
85
+ "@swc/jest": "^0.2.36",
86
+ "@types/jest": "^29.5.14",
87
+ "@types/lodash": "^4.17.23",
79
88
  "@types/node": "^20.0.0",
80
89
  "@types/react": "^18.3.2",
81
90
  "@types/react-dom": "^18.2.25",
82
91
  "awilix": "^8.0.1",
83
92
  "dotenv": "^17.2.3",
93
+ "jest": "^29.7.0",
84
94
  "prettier": "^3.0.0",
85
95
  "prop-types": "^15.8.1",
86
96
  "react": "^18.2.0",
@@ -90,8 +100,7 @@
90
100
  "ts-node": "^10.9.2",
91
101
  "typescript": "^5.6.2",
92
102
  "vite": "^5.2.11",
93
- "yalc": "^1.0.0-pre.53",
94
- "@types/lodash": "^4.17.23"
103
+ "yalc": "^1.0.0-pre.53"
95
104
  },
96
105
  "engines": {
97
106
  "node": ">=20"