@memberjunction/entity-communications-server 4.0.0 → 4.2.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 +103 -172
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,16 +1,50 @@
|
|
|
1
1
|
# @memberjunction/entity-communications-server
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
3
|
+
Server-side implementation of the MemberJunction Entity Communications Engine. Connects the entity/view system to the communication framework, enabling bulk messaging to records retrieved from entity views with full template rendering, related-entity data resolution, and multi-provider support.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
subgraph server["@memberjunction/entity-comm-server"]
|
|
10
|
+
ECE["EntityCommunicationsEngine\n(Singleton)"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
subgraph base["@memberjunction/entity-communications-base"]
|
|
14
|
+
ECB["EntityCommunicationsEngineBase"]
|
|
15
|
+
PARAMS["EntityCommunicationParams"]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
subgraph comm["@memberjunction/communication-engine"]
|
|
19
|
+
CE["CommunicationEngine"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
subgraph core["@memberjunction/core"]
|
|
23
|
+
RV["RunView"]
|
|
24
|
+
MD["Metadata"]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
subgraph providers["Registered Providers"]
|
|
28
|
+
SG["SendGrid"]
|
|
29
|
+
GM["Gmail"]
|
|
30
|
+
TW["Twilio"]
|
|
31
|
+
MSP["MS Graph"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
ECB --> ECE
|
|
35
|
+
ECE -->|queries records| RV
|
|
36
|
+
ECE -->|sends messages| CE
|
|
37
|
+
CE --> SG
|
|
38
|
+
CE --> GM
|
|
39
|
+
CE --> TW
|
|
40
|
+
CE --> MSP
|
|
41
|
+
|
|
42
|
+
style server fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
43
|
+
style base fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
44
|
+
style comm fill:#7c5295,stroke:#563a6b,color:#fff
|
|
45
|
+
style core fill:#b8762f,stroke:#8a5722,color:#fff
|
|
46
|
+
style providers fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
47
|
+
```
|
|
14
48
|
|
|
15
49
|
## Installation
|
|
16
50
|
|
|
@@ -18,16 +52,6 @@ This package provides a server-side engine for sending communications (emails, S
|
|
|
18
52
|
npm install @memberjunction/entity-communications-server
|
|
19
53
|
```
|
|
20
54
|
|
|
21
|
-
## Dependencies
|
|
22
|
-
|
|
23
|
-
This package depends on the following MemberJunction packages:
|
|
24
|
-
|
|
25
|
-
- `@memberjunction/global` - Core global utilities
|
|
26
|
-
- `@memberjunction/core` - Core MJ functionality including metadata, entities, and views
|
|
27
|
-
- `@memberjunction/core-entities` - Core entity definitions
|
|
28
|
-
- `@memberjunction/communication-engine` - Base communication engine
|
|
29
|
-
- `@memberjunction/entity-communications-base` - Base entity communications types and interfaces
|
|
30
|
-
|
|
31
55
|
## Usage
|
|
32
56
|
|
|
33
57
|
### Basic Example
|
|
@@ -35,80 +59,57 @@ This package depends on the following MemberJunction packages:
|
|
|
35
59
|
```typescript
|
|
36
60
|
import { EntityCommunicationsEngine } from '@memberjunction/entity-communications-server';
|
|
37
61
|
import { EntityCommunicationParams } from '@memberjunction/entity-communications-base';
|
|
38
|
-
import { UserInfo } from '@memberjunction/core';
|
|
39
62
|
|
|
40
|
-
// Get the singleton instance
|
|
41
63
|
const engine = EntityCommunicationsEngine.Instance;
|
|
64
|
+
await engine.Config(false, contextUser);
|
|
42
65
|
|
|
43
|
-
// Configure the engine with user context
|
|
44
|
-
const currentUser = new UserInfo(); // Your current user
|
|
45
|
-
await engine.Config(false, currentUser);
|
|
46
|
-
|
|
47
|
-
// Set up communication parameters
|
|
48
66
|
const params: EntityCommunicationParams = {
|
|
49
|
-
EntityID: 'entity-uuid
|
|
67
|
+
EntityID: 'entity-uuid',
|
|
50
68
|
RunViewParams: {
|
|
51
69
|
EntityName: 'Contacts',
|
|
52
|
-
ViewName: 'Active Contacts',
|
|
53
70
|
ExtraFilter: 'Status = "Active"'
|
|
54
71
|
},
|
|
55
72
|
ProviderName: 'SendGrid',
|
|
56
73
|
ProviderMessageTypeName: 'Email',
|
|
57
74
|
Message: {
|
|
58
|
-
Subject: 'Welcome
|
|
59
|
-
Body: 'Hello {{FirstName}}
|
|
60
|
-
|
|
61
|
-
SubjectTemplate: subjectTemplateEntity,
|
|
62
|
-
BodyTemplate: bodyTemplateEntity,
|
|
63
|
-
HTMLBodyTemplate: htmlBodyTemplateEntity
|
|
75
|
+
Subject: 'Welcome',
|
|
76
|
+
Body: 'Hello {{FirstName}}!',
|
|
77
|
+
HTMLBodyTemplate: htmlTemplate
|
|
64
78
|
},
|
|
65
|
-
PreviewOnly: false
|
|
79
|
+
PreviewOnly: false
|
|
66
80
|
};
|
|
67
81
|
|
|
68
|
-
// Execute the communication
|
|
69
82
|
const result = await engine.RunEntityCommunication(params);
|
|
70
|
-
|
|
71
83
|
if (result.Success) {
|
|
72
|
-
console.log(`
|
|
73
|
-
} else {
|
|
74
|
-
console.error(`Failed: ${result.ErrorMessage}`);
|
|
84
|
+
console.log(`Sent ${result.Results.length} messages`);
|
|
75
85
|
}
|
|
76
86
|
```
|
|
77
87
|
|
|
78
|
-
###
|
|
88
|
+
### Template Parameters with Related Entity Data
|
|
89
|
+
|
|
90
|
+
When templates reference related entities, the engine automatically fetches the related data in batch and populates each recipient's context:
|
|
79
91
|
|
|
80
92
|
```typescript
|
|
81
|
-
// Example with templates that include related entity data
|
|
82
93
|
const params: EntityCommunicationParams = {
|
|
83
94
|
EntityID: 'customer-entity-id',
|
|
84
|
-
RunViewParams: {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
ProviderName: 'Twilio',
|
|
89
|
-
ProviderMessageTypeName: 'SMS',
|
|
95
|
+
RunViewParams: { EntityName: 'Customers', ViewName: 'Premium Customers' },
|
|
96
|
+
ProviderName: 'SendGrid',
|
|
97
|
+
ProviderMessageTypeName: 'Email',
|
|
90
98
|
Message: {
|
|
91
|
-
|
|
92
|
-
BodyTemplate: templateWithOrdersParam, // Template with "Orders" parameter
|
|
93
|
-
// The engine will automatically fetch related orders for each customer
|
|
99
|
+
BodyTemplate: templateWithRelatedEntities
|
|
94
100
|
}
|
|
95
101
|
};
|
|
96
|
-
|
|
102
|
+
// Engine auto-fetches related orders for each customer
|
|
97
103
|
const result = await engine.RunEntityCommunication(params);
|
|
98
104
|
```
|
|
99
105
|
|
|
100
106
|
### Checking Entity Communication Support
|
|
101
107
|
|
|
102
108
|
```typescript
|
|
103
|
-
// Check if an entity supports communication
|
|
104
|
-
const entityID = 'entity-uuid';
|
|
105
109
|
if (engine.EntitySupportsCommunication(entityID)) {
|
|
106
|
-
// Get available message types for the entity
|
|
107
110
|
const messageTypes = engine.GetEntityCommunicationMessageTypes(entityID);
|
|
108
|
-
|
|
109
111
|
messageTypes.forEach(mt => {
|
|
110
|
-
console.log(`
|
|
111
|
-
// Each message type has associated fields that can be used for recipient addresses
|
|
112
|
+
console.log(`Type: ${mt.BaseMessageType}`);
|
|
112
113
|
mt.CommunicationFields.forEach(field => {
|
|
113
114
|
console.log(` Field: ${field.FieldName} (Priority: ${field.Priority})`);
|
|
114
115
|
});
|
|
@@ -116,76 +117,40 @@ if (engine.EntitySupportsCommunication(entityID)) {
|
|
|
116
117
|
}
|
|
117
118
|
```
|
|
118
119
|
|
|
119
|
-
##
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
##### `Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>`
|
|
144
|
-
|
|
145
|
-
Configures the engine with user context and loads metadata.
|
|
146
|
-
|
|
147
|
-
##### `EntitySupportsCommunication(entityID: string): boolean`
|
|
148
|
-
|
|
149
|
-
Checks if an entity has communication capabilities configured.
|
|
150
|
-
|
|
151
|
-
##### `GetEntityCommunicationMessageTypes(entityID: string): EntityCommunicationMessageTypeExtended[]`
|
|
152
|
-
|
|
153
|
-
Retrieves available message types for an entity.
|
|
154
|
-
|
|
155
|
-
### Types
|
|
156
|
-
|
|
157
|
-
#### EntityCommunicationParams
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
class EntityCommunicationParams {
|
|
161
|
-
EntityID: string;
|
|
162
|
-
RunViewParams: RunViewParams;
|
|
163
|
-
ProviderName: string;
|
|
164
|
-
ProviderMessageTypeName: string;
|
|
165
|
-
Message: Message;
|
|
166
|
-
PreviewOnly?: boolean;
|
|
167
|
-
IncludeProcessedMessages?: boolean;
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### EntityCommunicationResult
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
class EntityCommunicationResult {
|
|
175
|
-
Success: boolean;
|
|
176
|
-
ErrorMessage?: string;
|
|
177
|
-
Results?: EntityCommunicationResultItem[];
|
|
178
|
-
}
|
|
120
|
+
## Processing Pipeline
|
|
121
|
+
|
|
122
|
+
```mermaid
|
|
123
|
+
sequenceDiagram
|
|
124
|
+
participant App as Application
|
|
125
|
+
participant ECE as EntityCommunicationsEngine
|
|
126
|
+
participant RV as RunView
|
|
127
|
+
participant CE as CommunicationEngine
|
|
128
|
+
participant P as Provider
|
|
129
|
+
|
|
130
|
+
App->>ECE: RunEntityCommunication(params)
|
|
131
|
+
ECE->>ECE: Validate entity, provider, message type
|
|
132
|
+
ECE->>RV: RunView(params.RunViewParams)
|
|
133
|
+
RV-->>ECE: Entity records[]
|
|
134
|
+
ECE->>ECE: Load related entity data (batch)
|
|
135
|
+
loop For each record
|
|
136
|
+
ECE->>ECE: Build message with record context
|
|
137
|
+
ECE->>CE: SendSingleMessage(provider, type, message)
|
|
138
|
+
CE->>P: SendSingleMessage(processedMessage)
|
|
139
|
+
P-->>CE: MessageResult
|
|
140
|
+
CE-->>ECE: MessageResult
|
|
141
|
+
end
|
|
142
|
+
ECE-->>App: EntityCommunicationResult
|
|
179
143
|
```
|
|
180
144
|
|
|
181
|
-
|
|
145
|
+
## Key Features
|
|
182
146
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
147
|
+
- **Bulk Message Sending**: Send to all records from an entity view in a single call
|
|
148
|
+
- **Template Parameter Resolution**: Automatically fetches related entity data for template parameters
|
|
149
|
+
- **Multi-Provider Support**: Works with any registered communication provider (email, SMS, etc.)
|
|
150
|
+
- **Preview Mode**: Test communications without sending (`PreviewOnly: true`)
|
|
151
|
+
- **Context Data Population**: Per-recipient template context from entity record fields
|
|
152
|
+
- **Scheduled Sending**: Supports provider-level `SendAt` scheduling
|
|
153
|
+
- **Communication Logging**: All sends are tracked through `CommunicationRun` and `CommunicationLog` entities
|
|
189
154
|
|
|
190
155
|
## Configuration
|
|
191
156
|
|
|
@@ -211,53 +176,19 @@ When using related entity parameters, the engine automatically:
|
|
|
211
176
|
3. Filters related data per recipient record
|
|
212
177
|
4. Populates template context with filtered data
|
|
213
178
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
Communication providers must:
|
|
217
|
-
- Be registered in the CommunicationEngine
|
|
218
|
-
- Support sending (`SupportsSending = true`)
|
|
219
|
-
- Support scheduled sending if `SendAt` is specified
|
|
220
|
-
- Have matching message types configured
|
|
221
|
-
|
|
222
|
-
## Error Handling
|
|
223
|
-
|
|
224
|
-
The engine validates:
|
|
225
|
-
- Entity existence and communication support
|
|
226
|
-
- Provider availability and capabilities
|
|
227
|
-
- Message type compatibility
|
|
228
|
-
- Template parameter alignment (no conflicting parameter definitions)
|
|
229
|
-
- Field availability for recipient addresses
|
|
230
|
-
|
|
231
|
-
All errors are returned in the `EntityCommunicationResult.ErrorMessage` field.
|
|
232
|
-
|
|
233
|
-
## Performance Considerations
|
|
234
|
-
|
|
235
|
-
- The engine fetches all entity fields to ensure template access
|
|
236
|
-
- Related entity data is batch-loaded for all recipients
|
|
237
|
-
- Large recipient sets should be paginated using view parameters
|
|
238
|
-
- Use `PreviewOnly` mode for testing before bulk sends
|
|
239
|
-
|
|
240
|
-
## Integration with MemberJunction
|
|
179
|
+
## Dependencies
|
|
241
180
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
|
|
247
|
-
-
|
|
181
|
+
| Package | Purpose |
|
|
182
|
+
|---------|---------|
|
|
183
|
+
| `@memberjunction/entity-communications-base` | Shared types and base engine class |
|
|
184
|
+
| `@memberjunction/communication-engine` | CommunicationEngine for message delivery |
|
|
185
|
+
| `@memberjunction/core` | RunView, Metadata, UserInfo, EntityInfo |
|
|
186
|
+
| `@memberjunction/core-entities` | Entity type definitions |
|
|
187
|
+
| `@memberjunction/global` | Class registration |
|
|
248
188
|
|
|
249
|
-
##
|
|
189
|
+
## Development
|
|
250
190
|
|
|
251
191
|
```bash
|
|
252
|
-
npm run build
|
|
192
|
+
npm run build # Compile TypeScript
|
|
193
|
+
npm start # Watch mode
|
|
253
194
|
```
|
|
254
|
-
|
|
255
|
-
The package is built using TypeScript and outputs to the `dist` directory.
|
|
256
|
-
|
|
257
|
-
## License
|
|
258
|
-
|
|
259
|
-
ISC
|
|
260
|
-
|
|
261
|
-
## Support
|
|
262
|
-
|
|
263
|
-
For issues and questions, please refer to the main MemberJunction documentation at [MemberJunction.com](https://www.memberjunction.com)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/entity-communications-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"description": "MemberJunction: Library that connects the MJ entities framework to the communication framework",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"typescript": "^5.9.3"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@memberjunction/communication-engine": "4.
|
|
24
|
-
"@memberjunction/communication-types": "4.
|
|
25
|
-
"@memberjunction/core": "4.
|
|
26
|
-
"@memberjunction/core-entities": "4.
|
|
27
|
-
"@memberjunction/entity-communications-base": "4.
|
|
28
|
-
"@memberjunction/global": "4.
|
|
23
|
+
"@memberjunction/communication-engine": "4.2.0",
|
|
24
|
+
"@memberjunction/communication-types": "4.2.0",
|
|
25
|
+
"@memberjunction/core": "4.2.0",
|
|
26
|
+
"@memberjunction/core-entities": "4.2.0",
|
|
27
|
+
"@memberjunction/entity-communications-base": "4.2.0",
|
|
28
|
+
"@memberjunction/global": "4.2.0"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|