@memberjunction/communication-sendgrid 5.0.0 → 5.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/README.md +180 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @memberjunction/communication-sendgrid
|
|
2
|
+
|
|
3
|
+
SendGrid provider for the MemberJunction Communication Framework. This provider enables transactional email sending through the SendGrid API, with support for HTML and plain text content, CC/BCC recipients, scheduled delivery, and per-request credential overrides.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
subgraph sendgrid["@memberjunction/communication-sendgrid"]
|
|
10
|
+
SGP["SendGridProvider"]
|
|
11
|
+
CFG["Config Module\n(Environment Variable)"]
|
|
12
|
+
CRED["SendGridCredentials"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
subgraph sg["SendGrid Service"]
|
|
16
|
+
API["SendGrid Web API v3"]
|
|
17
|
+
DELIVERY["Email Delivery"]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
subgraph base["@memberjunction/communication-types"]
|
|
21
|
+
BCP["BaseCommunicationProvider"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
BCP --> SGP
|
|
25
|
+
SGP --> CFG
|
|
26
|
+
SGP --> CRED
|
|
27
|
+
SGP --> API
|
|
28
|
+
API --> DELIVERY
|
|
29
|
+
|
|
30
|
+
style sendgrid fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
31
|
+
style sg fill:#7c5295,stroke:#563a6b,color:#fff
|
|
32
|
+
style base fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @memberjunction/communication-sendgrid
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
Set the following environment variable:
|
|
44
|
+
|
|
45
|
+
```env
|
|
46
|
+
COMMUNICATION_VENDOR_API_KEY__SENDGRID=SG.your-api-key-here
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Supported Operations
|
|
50
|
+
|
|
51
|
+
SendGrid is a send-only transactional email service. It does not provide mailbox access.
|
|
52
|
+
|
|
53
|
+
| Operation | Supported | Notes |
|
|
54
|
+
|-----------|-----------|-------|
|
|
55
|
+
| `SendSingleMessage` | Yes | Full email sending with HTML, text, CC/BCC, scheduling |
|
|
56
|
+
| `GetMessages` | No | No inbox access (throws error) |
|
|
57
|
+
| `ForwardMessage` | No | No mailbox operations (throws error) |
|
|
58
|
+
| `ReplyToMessage` | No | No mailbox operations (throws error) |
|
|
59
|
+
| `CreateDraft` | No | No mailbox access (returns error result) |
|
|
60
|
+
| Extended operations | No | No folder, search, or attachment operations |
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### Sending Email via CommunicationEngine
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { CommunicationEngine } from '@memberjunction/communication-engine';
|
|
68
|
+
import { Message } from '@memberjunction/communication-types';
|
|
69
|
+
|
|
70
|
+
const engine = CommunicationEngine.Instance;
|
|
71
|
+
await engine.Config(false, contextUser);
|
|
72
|
+
|
|
73
|
+
const message = new Message();
|
|
74
|
+
message.From = 'noreply@example.com';
|
|
75
|
+
message.FromName = 'My Application';
|
|
76
|
+
message.To = 'recipient@example.com';
|
|
77
|
+
message.Subject = 'Order Confirmation';
|
|
78
|
+
message.HTMLBody = '<h1>Thank you for your order</h1>';
|
|
79
|
+
message.Body = 'Thank you for your order';
|
|
80
|
+
message.CCRecipients = ['accounting@example.com'];
|
|
81
|
+
|
|
82
|
+
const result = await engine.SendSingleMessage('SendGrid', 'Email', message);
|
|
83
|
+
if (result.Success) {
|
|
84
|
+
console.log('Email sent successfully');
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Scheduled Sending
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const message = new Message();
|
|
92
|
+
message.From = 'noreply@example.com';
|
|
93
|
+
message.To = 'recipient@example.com';
|
|
94
|
+
message.Subject = 'Scheduled Report';
|
|
95
|
+
message.Body = 'Your weekly report is attached.';
|
|
96
|
+
message.SendAt = new Date('2025-12-01T09:00:00Z');
|
|
97
|
+
|
|
98
|
+
const result = await engine.SendSingleMessage('SendGrid', 'Email', message);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Per-Request Credentials
|
|
102
|
+
|
|
103
|
+
Override the API key for multi-tenant or customer-specific sending:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { SendGridCredentials } from '@memberjunction/communication-sendgrid';
|
|
107
|
+
|
|
108
|
+
// Override API key
|
|
109
|
+
const result = await engine.SendSingleMessage(
|
|
110
|
+
'SendGrid',
|
|
111
|
+
'Email',
|
|
112
|
+
message,
|
|
113
|
+
undefined,
|
|
114
|
+
false,
|
|
115
|
+
{ apiKey: 'SG.customer-specific-api-key' } as SendGridCredentials
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// Disable environment fallback (require explicit key)
|
|
119
|
+
const result2 = await engine.SendSingleMessage(
|
|
120
|
+
'SendGrid',
|
|
121
|
+
'Email',
|
|
122
|
+
message,
|
|
123
|
+
undefined,
|
|
124
|
+
false,
|
|
125
|
+
{
|
|
126
|
+
apiKey: 'SG.required-key',
|
|
127
|
+
disableEnvironmentFallback: true
|
|
128
|
+
} as SendGridCredentials
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Direct Provider Usage
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { SendGridProvider } from '@memberjunction/communication-sendgrid';
|
|
136
|
+
|
|
137
|
+
const provider = new SendGridProvider();
|
|
138
|
+
const result = await provider.SendSingleMessage(processedMessage);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Message Features
|
|
142
|
+
|
|
143
|
+
| Feature | Support |
|
|
144
|
+
|---------|---------|
|
|
145
|
+
| HTML body | Yes |
|
|
146
|
+
| Plain text body | Yes |
|
|
147
|
+
| CC recipients | Yes |
|
|
148
|
+
| BCC recipients | Yes |
|
|
149
|
+
| From name | Yes |
|
|
150
|
+
| Scheduled send (`SendAt`) | Yes (converted to Unix timestamp) |
|
|
151
|
+
| Subscription tracking | Disabled by default |
|
|
152
|
+
|
|
153
|
+
## SendGridCredentials
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
interface SendGridCredentials extends ProviderCredentialsBase {
|
|
157
|
+
/** SendGrid API key (typically starts with 'SG.') */
|
|
158
|
+
apiKey?: string;
|
|
159
|
+
/** If true, do not fall back to environment variables */
|
|
160
|
+
disableEnvironmentFallback?: boolean;
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Dependencies
|
|
165
|
+
|
|
166
|
+
| Package | Purpose |
|
|
167
|
+
|---------|---------|
|
|
168
|
+
| `@memberjunction/communication-types` | Base provider class and type definitions |
|
|
169
|
+
| `@memberjunction/core` | Logging utilities (LogError, LogStatus) |
|
|
170
|
+
| `@memberjunction/global` | RegisterClass decorator |
|
|
171
|
+
| `@sendgrid/mail` | Official SendGrid Node.js client |
|
|
172
|
+
| `dotenv` | Environment variable loading |
|
|
173
|
+
| `env-var` | Environment variable validation |
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm run build # Compile TypeScript
|
|
179
|
+
npm run clean # Remove dist directory
|
|
180
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/communication-sendgrid",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "MemberJunction: SendGrid Provider for the MJ Communication Framework",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"typescript": "^5.9.3"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@memberjunction/communication-types": "5.
|
|
24
|
-
"@memberjunction/core": "5.
|
|
25
|
-
"@memberjunction/core-entities": "5.
|
|
26
|
-
"@memberjunction/global": "5.
|
|
23
|
+
"@memberjunction/communication-types": "5.1.0",
|
|
24
|
+
"@memberjunction/core": "5.1.0",
|
|
25
|
+
"@memberjunction/core-entities": "5.1.0",
|
|
26
|
+
"@memberjunction/global": "5.1.0",
|
|
27
27
|
"@sendgrid/mail": "^8.1.6",
|
|
28
28
|
"dotenv": "^17.2.4"
|
|
29
29
|
},
|