@memberjunction/communication-ms-graph 6.2.0-edge.6 → 6.2.0-edge.8
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/package.json +9 -9
- package/readme.md +0 -291
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/communication-ms-graph",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.0-edge.
|
|
4
|
+
"version": "6.2.0-edge.8",
|
|
5
5
|
"description": "MemberJunction: Microsoft Graph Provider for the MJ Communication Framework",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@azure/identity": "^4.13.0",
|
|
20
20
|
"@azure/msal-node": "^5.0.3",
|
|
21
|
-
"@memberjunction/ai": "6.2.0-edge.
|
|
22
|
-
"@memberjunction/ai-provider-bundle": "6.2.0-edge.
|
|
23
|
-
"@memberjunction/aiengine": "6.2.0-edge.
|
|
24
|
-
"@memberjunction/communication-types": "6.2.0-edge.
|
|
25
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
26
|
-
"@memberjunction/core-entities": "6.2.0-edge.
|
|
27
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
28
|
-
"@memberjunction/sqlserver-dataprovider": "6.2.0-edge.
|
|
21
|
+
"@memberjunction/ai": "6.2.0-edge.8",
|
|
22
|
+
"@memberjunction/ai-provider-bundle": "6.2.0-edge.8",
|
|
23
|
+
"@memberjunction/aiengine": "6.2.0-edge.8",
|
|
24
|
+
"@memberjunction/communication-types": "6.2.0-edge.8",
|
|
25
|
+
"@memberjunction/core": "6.2.0-edge.8",
|
|
26
|
+
"@memberjunction/core-entities": "6.2.0-edge.8",
|
|
27
|
+
"@memberjunction/global": "6.2.0-edge.8",
|
|
28
|
+
"@memberjunction/sqlserver-dataprovider": "6.2.0-edge.8",
|
|
29
29
|
"@microsoft/microsoft-graph-client": "^3.0.7",
|
|
30
30
|
"@microsoft/microsoft-graph-types": "^2.43.1",
|
|
31
31
|
"@types/html-to-text": "^9.0.4",
|
package/readme.md
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
# @memberjunction/communication-ms-graph
|
|
2
|
-
|
|
3
|
-
Microsoft Graph (Office 365 / Exchange Online) provider for the MemberJunction Communication Framework. This provider enables full mailbox operations -- sending, receiving, searching, managing folders, attachments, drafts, and more -- through the Microsoft Graph API with Azure AD application authentication.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
```mermaid
|
|
8
|
-
graph TD
|
|
9
|
-
subgraph msgraph["@memberjunction/communication-ms-graph"]
|
|
10
|
-
MSP["MSGraphProvider"]
|
|
11
|
-
AUTH["Auth Module\n(ClientSecretCredential)"]
|
|
12
|
-
CFG["Config Module\n(Environment Variables)"]
|
|
13
|
-
CRED["MSGraphCredentials"]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
subgraph azure["Azure / Microsoft"]
|
|
17
|
-
AAD["Azure AD\n(OAuth2 Client Credentials)"]
|
|
18
|
-
GRAPH["Microsoft Graph API\n(/users/email/...)"]
|
|
19
|
-
MAIL["Exchange Online\nMailbox"]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
subgraph base["@memberjunction/communication-types"]
|
|
23
|
-
BCP["BaseCommunicationProvider"]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
BCP --> MSP
|
|
27
|
-
MSP --> AUTH
|
|
28
|
-
MSP --> CFG
|
|
29
|
-
MSP --> CRED
|
|
30
|
-
AUTH --> AAD
|
|
31
|
-
MSP --> GRAPH
|
|
32
|
-
GRAPH --> MAIL
|
|
33
|
-
|
|
34
|
-
style msgraph fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
35
|
-
style azure fill:#7c5295,stroke:#563a6b,color:#fff
|
|
36
|
-
style base fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Installation
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npm install @memberjunction/communication-ms-graph
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Configuration
|
|
46
|
-
|
|
47
|
-
Set the following environment variables:
|
|
48
|
-
|
|
49
|
-
```env
|
|
50
|
-
AZURE_TENANT_ID=your-azure-tenant-id
|
|
51
|
-
AZURE_CLIENT_ID=your-azure-app-client-id
|
|
52
|
-
AZURE_CLIENT_SECRET=your-azure-app-client-secret
|
|
53
|
-
AZURE_ACCOUNT_EMAIL=mailbox@yourdomain.com
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Required Azure AD App Permissions (Application type)
|
|
57
|
-
|
|
58
|
-
| Permission | Operations |
|
|
59
|
-
|-----------|------------|
|
|
60
|
-
| `Mail.Send` | SendSingleMessage, ForwardMessage, ReplyToMessage |
|
|
61
|
-
| `Mail.Read` | GetMessages, GetSingleMessage, SearchMessages, ListFolders, ListAttachments, DownloadAttachment |
|
|
62
|
-
| `Mail.ReadWrite` | CreateDraft, DeleteMessage, MoveMessage, MarkAsRead, ArchiveMessage |
|
|
63
|
-
| `Calendars.Read` | GetEvents |
|
|
64
|
-
| `User.Read.All` | GetServiceAccount (user lookup, optional) |
|
|
65
|
-
|
|
66
|
-
`Calendars.Read` is sufficient for `GetEvents`; `Calendars.ReadWrite` is not required, since nothing
|
|
67
|
-
here creates or modifies an event. As **Application** permissions these are granted against the
|
|
68
|
-
tenant, not against one mailbox — narrowing an app to specific mailboxes is done in Exchange with
|
|
69
|
-
RBAC for Applications, not by these grants.
|
|
70
|
-
|
|
71
|
-
## Supported Operations
|
|
72
|
-
|
|
73
|
-
This provider supports all 15 operations defined in `BaseCommunicationProvider`:
|
|
74
|
-
|
|
75
|
-
| Operation | Description |
|
|
76
|
-
|-----------|-------------|
|
|
77
|
-
| `SendSingleMessage` | Send email via Graph API |
|
|
78
|
-
| `GetMessages` | Retrieve messages with filtering and header extraction |
|
|
79
|
-
| `GetSingleMessage` | Retrieve a single message by ID |
|
|
80
|
-
| `ForwardMessage` | Forward email to new recipients |
|
|
81
|
-
| `ReplyToMessage` | Reply to an existing email thread |
|
|
82
|
-
| `CreateDraft` | Create a draft message in the mailbox |
|
|
83
|
-
| `DeleteMessage` | Move to Deleted Items or permanently delete |
|
|
84
|
-
| `MoveMessage` | Move message to a different mail folder |
|
|
85
|
-
| `ListFolders` | List mail folders with optional message counts |
|
|
86
|
-
| `MarkAsRead` | Mark messages as read or unread (batch) |
|
|
87
|
-
| `ArchiveMessage` | Move message to Archive folder |
|
|
88
|
-
| `SearchMessages` | Full-text search with KQL syntax and date filtering |
|
|
89
|
-
| `ListAttachments` | List attachments on a message |
|
|
90
|
-
| `DownloadAttachment` | Download attachment content as base64/Buffer |
|
|
91
|
-
| `GetEvents` | Read calendar events for one mailbox |
|
|
92
|
-
|
|
93
|
-
## Usage
|
|
94
|
-
|
|
95
|
-
### Sending Email
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
import { CommunicationEngine } from '@memberjunction/communication-engine';
|
|
99
|
-
import { Message } from '@memberjunction/communication-types';
|
|
100
|
-
|
|
101
|
-
const engine = CommunicationEngine.Instance;
|
|
102
|
-
await engine.Config(false, contextUser);
|
|
103
|
-
|
|
104
|
-
const message = new Message();
|
|
105
|
-
message.From = 'user@yourdomain.com';
|
|
106
|
-
message.To = 'recipient@example.com';
|
|
107
|
-
message.Subject = 'Hello from MS Graph';
|
|
108
|
-
message.HTMLBody = '<h1>Hello</h1><p>Sent via Microsoft Graph.</p>';
|
|
109
|
-
message.ContextData = { saveToSentItems: true };
|
|
110
|
-
|
|
111
|
-
const result = await engine.SendSingleMessage(
|
|
112
|
-
'Microsoft Graph',
|
|
113
|
-
'Standard Email',
|
|
114
|
-
message
|
|
115
|
-
);
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Per-Request Credentials
|
|
119
|
-
|
|
120
|
-
Override credentials on a per-request basis for multi-tenant scenarios:
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
import { MSGraphCredentials } from '@memberjunction/communication-ms-graph';
|
|
124
|
-
|
|
125
|
-
const result = await engine.SendSingleMessage(
|
|
126
|
-
'Microsoft Graph',
|
|
127
|
-
'Standard Email',
|
|
128
|
-
message,
|
|
129
|
-
undefined,
|
|
130
|
-
false,
|
|
131
|
-
{
|
|
132
|
-
tenantId: 'customer-tenant-id',
|
|
133
|
-
clientId: 'customer-app-id',
|
|
134
|
-
clientSecret: 'customer-secret',
|
|
135
|
-
accountEmail: 'user@customer.com'
|
|
136
|
-
} as MSGraphCredentials
|
|
137
|
-
);
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Reading Messages
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
const provider = engine.GetProvider('Microsoft Graph');
|
|
144
|
-
|
|
145
|
-
const result = await provider.GetMessages({
|
|
146
|
-
NumMessages: 10,
|
|
147
|
-
UnreadOnly: true,
|
|
148
|
-
IncludeHeaders: true,
|
|
149
|
-
ContextData: {
|
|
150
|
-
ReturnAsPlainText: true,
|
|
151
|
-
MarkAsRead: true
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
result.Messages.forEach(msg => {
|
|
156
|
-
console.log(`${msg.From}: ${msg.Subject}`);
|
|
157
|
-
console.log(`Thread: ${msg.ThreadID}`);
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Reading Calendar Events
|
|
162
|
-
|
|
163
|
-
Requires `Calendars.Read`. **Whether you pass a window changes what comes back**, so `GetEvents`
|
|
164
|
-
reports which it did via `RecurrenceExpanded` rather than leaving you to guess:
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
const provider = engine.GetProvider('Microsoft Graph');
|
|
168
|
-
|
|
169
|
-
// With a window -> /calendarView: a recurring series is EXPANDED into one entry per occurrence.
|
|
170
|
-
const occurrences = await provider.GetEvents({
|
|
171
|
-
Identifier: 'rep@example.com',
|
|
172
|
-
NumEvents: 50,
|
|
173
|
-
StartDateTime: new Date('2026-09-01T00:00:00Z'),
|
|
174
|
-
EndDateTime: new Date('2026-09-08T00:00:00Z')
|
|
175
|
-
});
|
|
176
|
-
console.log(occurrences.RecurrenceExpanded); // true
|
|
177
|
-
|
|
178
|
-
// Without one -> /events: a weekly stand-up is ONE row, the series master, whose start time is
|
|
179
|
-
// whenever the series began — possibly years ago.
|
|
180
|
-
const masters = await provider.GetEvents({ Identifier: 'rep@example.com', NumEvents: 50 });
|
|
181
|
-
console.log(masters.RecurrenceExpanded); // false
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Three things worth knowing before syncing on this:
|
|
185
|
-
|
|
186
|
-
- **The window selects overlap, not start times.** An event that began before `StartDateTime` and is
|
|
187
|
-
still running when the window opens is returned. An event straddling a boundary therefore appears
|
|
188
|
-
in both adjacent windows — dedupe on the event id.
|
|
189
|
-
- **`NumEvents` is one page.** It becomes `$top`; there is no `@odata.nextLink` following. To cover a
|
|
190
|
-
period completely, narrow the window rather than raise the number.
|
|
191
|
-
- **Cancelled events are excluded by default** and cannot be recovered after the fact — Graph does not
|
|
192
|
-
return them once filtered. Pass `IncludeCancelled: true` if you are logging history.
|
|
193
|
-
|
|
194
|
-
### Searching Messages
|
|
195
|
-
|
|
196
|
-
MS Graph supports KQL (Keyword Query Language) for search:
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
const result = await provider.SearchMessages({
|
|
200
|
-
Query: 'invoice',
|
|
201
|
-
FromDate: new Date('2025-01-01'),
|
|
202
|
-
MaxResults: 25,
|
|
203
|
-
FolderID: 'inbox-folder-id'
|
|
204
|
-
});
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### Creating Drafts
|
|
208
|
-
|
|
209
|
-
```typescript
|
|
210
|
-
const result = await engine.CreateDraft(message, 'Microsoft Graph', contextUser);
|
|
211
|
-
if (result.Success) {
|
|
212
|
-
console.log(`Draft ID: ${result.DraftID}`);
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### Managing Folders
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
// List top-level folders
|
|
220
|
-
const folders = await provider.ListFolders({ IncludeCounts: true });
|
|
221
|
-
folders.Folders.forEach(f => {
|
|
222
|
-
console.log(`${f.Name}: ${f.MessageCount} total, ${f.UnreadCount} unread`);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// List subfolders
|
|
226
|
-
const subfolders = await provider.ListFolders({
|
|
227
|
-
ParentFolderID: 'parent-folder-id',
|
|
228
|
-
IncludeCounts: true
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Move a message
|
|
232
|
-
await provider.MoveMessage({
|
|
233
|
-
MessageID: 'msg-id',
|
|
234
|
-
DestinationFolderID: 'folder-id'
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// Archive a message
|
|
238
|
-
await provider.ArchiveMessage({ MessageID: 'msg-id' });
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Downloading Attachments
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
const attachments = await provider.ListAttachments({ MessageID: 'msg-id' });
|
|
245
|
-
for (const att of attachments.Attachments) {
|
|
246
|
-
const download = await provider.DownloadAttachment({
|
|
247
|
-
MessageID: 'msg-id',
|
|
248
|
-
AttachmentID: att.ID
|
|
249
|
-
});
|
|
250
|
-
// download.Content is a Buffer
|
|
251
|
-
// download.ContentBase64 is the raw base64 string
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
## Client Caching
|
|
256
|
-
|
|
257
|
-
The provider caches Microsoft Graph `Client` instances per credential set for performance. Environment credential clients are shared across all calls; per-request credential clients are cached by `tenantId:clientId`.
|
|
258
|
-
|
|
259
|
-
## System Folder Mapping
|
|
260
|
-
|
|
261
|
-
| Exchange Display Name | SystemFolderType |
|
|
262
|
-
|----------------------|-----------------|
|
|
263
|
-
| Inbox | `inbox` |
|
|
264
|
-
| Sent Items | `sent` |
|
|
265
|
-
| Drafts | `drafts` |
|
|
266
|
-
| Deleted Items | `trash` |
|
|
267
|
-
| Junk Email | `spam` |
|
|
268
|
-
| Archive | `archive` |
|
|
269
|
-
| Other folders | `other` |
|
|
270
|
-
|
|
271
|
-
## HTML to Text Conversion
|
|
272
|
-
|
|
273
|
-
When `ReturnAsPlainText` is set in `ContextData`, the provider uses the `html-to-text` library to convert HTML email bodies to plain text with 130-character word wrap.
|
|
274
|
-
|
|
275
|
-
## Dependencies
|
|
276
|
-
|
|
277
|
-
| Package | Purpose |
|
|
278
|
-
|---------|---------|
|
|
279
|
-
| `@memberjunction/communication-types` | Base provider class and type definitions |
|
|
280
|
-
| `@memberjunction/core` | Logging utilities |
|
|
281
|
-
| `@memberjunction/global` | RegisterClass decorator |
|
|
282
|
-
| `@microsoft/microsoft-graph-client` | Microsoft Graph SDK |
|
|
283
|
-
| `@azure/identity` | Azure AD ClientSecretCredential |
|
|
284
|
-
| `html-to-text` | HTML to plain text conversion |
|
|
285
|
-
|
|
286
|
-
## Development
|
|
287
|
-
|
|
288
|
-
```bash
|
|
289
|
-
npm run build # Compile TypeScript
|
|
290
|
-
npm run clean # Remove dist directory
|
|
291
|
-
```
|