@messagebird/bird-plugin-medusa 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bird
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # Bird notifications for Medusa
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Send email, SMS, and WhatsApp notifications from your Medusa v2 application with Bird. This notification provider runs in your Medusa server and uses your workspace's Bird API key. It supports Medusa 2.21.2 and later v2 releases.
4
+
5
+ ## Install and configure
6
+
7
+ Install the package after its first npm release:
8
+
9
+ ```sh
10
+ npm install @messagebird/bird-plugin-medusa
11
+ ```
12
+
13
+ Set your Bird credentials in your hosting platform's environment settings. For local development, add them to `.env` and keep that file out of version control:
14
+
15
+ ```dotenv
16
+ BIRD_API_KEY=your_bird_access_key
17
+ BIRD_EMAIL_FROM=notifications@example.com
18
+ BIRD_SMS_FROM=YourShop
19
+ ```
20
+
21
+ Set `BIRD_WHATSAPP_FROM` to your connected WhatsApp number when sending from it. Omit sender variables for channels you do not use.
22
+
23
+ Add the provider to the Notification Module in your existing `medusa-config.ts`. Keep its other application settings and environment loading:
24
+
25
+ ```ts
26
+ import { defineConfig, loadEnv } from "@medusajs/framework/utils";
27
+
28
+ loadEnv(process.env.NODE_ENV || "development", process.cwd());
29
+
30
+ module.exports = defineConfig({
31
+ modules: [
32
+ {
33
+ resolve: "@medusajs/medusa/notification",
34
+ options: {
35
+ providers: [
36
+ {
37
+ resolve: "@medusajs/medusa/notification-local",
38
+ id: "local",
39
+ options: { channels: ["feed"] },
40
+ },
41
+ {
42
+ resolve: "@messagebird/bird-plugin-medusa/providers/bird",
43
+ id: "bird",
44
+ options: {
45
+ channels: ["email", "sms", "whatsapp"],
46
+ api_key: process.env.BIRD_API_KEY,
47
+ email_from: process.env.BIRD_EMAIL_FROM,
48
+ sms_from: process.env.BIRD_SMS_FROM,
49
+ whatsapp_from: process.env.BIRD_WHATSAPP_FROM,
50
+ },
51
+ },
52
+ ],
53
+ },
54
+ },
55
+ ],
56
+ });
57
+ ```
58
+
59
+ Keep the local `feed` provider for Medusa admin notifications such as product and order exports. Configuring `providers` replaces Medusa's default provider list. Medusa routes each channel to one provider: remove a channel from an existing provider before assigning it to Bird. Register this package in the Notification Module; it needs no entry in `plugins`.
60
+
61
+ Restart or redeploy Medusa after changing the configuration. On Medusa Cloud, enable the **Build** flag for the environment variables used here. Credentials and defaults are server configuration; this package adds no admin settings page or OAuth connection form.
62
+
63
+ Create an API key in your [Bird workspace](https://bird.com/dashboard) with send permissions for the channels you enable: `emails:write`, `sms:write`, and `whatsapp:write`. Keep it in server environment variables. The provider derives the API region from the key; no workspace ID or region setting is needed. Use a `bk_<region>_…` API key. Short-lived OAuth tokens (`bt_…`), legacy MessageBird keys, and SparkPost keys are not supported.
64
+
65
+ Use a verified email domain for `BIRD_EMAIL_FROM` and a configured SMS sender for `BIRD_SMS_FROM`. Configure only the channels you use. A notification's `from` overrides its channel's default sender. For WhatsApp, use a connected number as `BIRD_WHATSAPP_FROM`. For built-in SMS and WhatsApp templates, use their `bird_…` slug and omit `notification.from`; the provider skips the configured default sender. When referring to a built-in template by ID instead, use a provider configuration without that channel's default sender.
66
+
67
+ ## Send an order notification
68
+
69
+ Create and publish an email template with the slug `order-confirmation` in Bird, including an `order_id` variable. Add `src/subscribers/order-placed.ts`:
70
+
71
+ ```ts
72
+ import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
73
+ import { Modules } from "@medusajs/framework/utils";
74
+
75
+ type OrderEvent = SubscriberArgs<{ id: string }>;
76
+
77
+ export default async function orderPlaced(args: OrderEvent) {
78
+ const container = args.container;
79
+ const data = args.event.data;
80
+ const order = await container.resolve(Modules.ORDER).retrieveOrder(data.id);
81
+ if (!order.email) return;
82
+ await container.resolve(Modules.NOTIFICATION).createNotifications({
83
+ to: order.email,
84
+ channel: "email",
85
+ template: "order-confirmation",
86
+ data: { order_id: order.display_id },
87
+ idempotency_key: `order-confirmation/${order.id}`,
88
+ provider_data: { idempotency_key: `order-confirmation/${order.id}` },
89
+ });
90
+ }
91
+
92
+ export const config: SubscriberConfig = { event: "order.placed" };
93
+ ```
94
+
95
+ `template` accepts a Bird email template ID (`emt_…`) or SMS template ID (`smt_…`), or a published template slug. For email and SMS, `data` becomes the template's `parameters`. Pass `provider_data.language` when the template requires a language.
96
+
97
+ Send SMS through the same Notification Module:
98
+
99
+ ```ts
100
+ await notificationModuleService.createNotifications({
101
+ to: "+31612345678",
102
+ channel: "sms",
103
+ template: "order-shipped",
104
+ data: { order_id: "123", tracking_url: "https://shop.example/track/123" },
105
+ });
106
+ ```
107
+
108
+ Create and publish `order-shipped` as an SMS template first. Its category comes from the template; do not pass `provider_data.category` for SMS template sends.
109
+
110
+ WhatsApp uses `channel: "whatsapp"` and accepts approved template IDs (`wat_…`) or slugs. Pass template components in `data.components`. See [WhatsApp templates and text](whatsapp.md) for examples and sender requirements.
111
+
112
+ ## Inline content and provider options
113
+
114
+ When `content` is present, it takes precedence over `template`. Medusa still requires a `template` string; use a descriptive label such as `order-receipt`. Email requires `content.subject` and `content.html` or `content.text`. SMS and WhatsApp accept only `content.text`. Inline email and SMS messages default to `transactional`; use `provider_data.category: "marketing"` for marketing content.
115
+
116
+ Email `data` maps to Bird's inline Liquid parameters. Render SMS and WhatsApp text in your app or use a stored template; their inline text does not interpolate `data`. WhatsApp text requires an open customer service window.
117
+
118
+ Supported `provider_data` fields:
119
+
120
+ - `language`: Stored template language tag, such as `nl`.
121
+ - `category`: Email accepts `transactional` or `marketing`; inline SMS also accepts `authentication` or `service`.
122
+ - `cc`, `bcc`, `reply_to`: Email address arrays.
123
+ - `preview_url`: Boolean for inline WhatsApp link previews, disabled by default.
124
+ - `idempotency_key`: Stable key for retries of the same message, at most 255 characters.
125
+
126
+ Medusa email attachments map to Bird attachments without re-encoding their base64 `content`. For an inline image, set `disposition: "inline"` and `id`, then reference `cid:<id>` in the HTML. SMS and WhatsApp notifications do not accept Medusa attachments; WhatsApp template media belongs in `data.components`.
127
+
128
+ The returned ID confirms API acceptance. Delivery is asynchronous; use Bird's [message APIs](https://bird.com/docs/api/reference) or [webhooks](https://bird.com/docs/guides/webhooks) to track the outcome. Medusa's notification success state does not confirm delivery to an inbox or handset.
129
+
130
+ The provider makes one request with a 30-second timeout. It does not retry an uncertain send. Medusa's notification idempotency key is separate from Bird's; set `provider_data.idempotency_key` too when retrying. Bird retains responses for three hours by default, with the limits described in the [API reference](https://bird.com/docs/api/reference/create-email-message).
131
+
132
+ ## Develop
133
+
134
+ Run `pnpm lint`, `pnpm test`, and `pnpm build` in this package. Lint uses Medusa's module-provider ESLint preset and checks TypeScript types. Tests mock Bird's HTTP responses and send no messages. Run `pnpm test:integration` for the real Medusa Notification Module and PostgreSQL checks; see [integration test prerequisites and database cleanup](integration-tests/README.md). `npm pack` creates an installable package for testing in a Medusa application before publication; integration tests are included in source mirrors and excluded from npm packages.
135
+
136
+ Source changes live in the Bird monorepo. The [release repository](https://github.com/messagebird/bird-plugin-medusa) is a mirror; versions and releases follow Bird's surface release process. Publishing and Medusa catalog visibility are separate steps. This package includes Medusa's documented notification integration discovery keywords.