@memberjunction/entity-communications-base 2.43.0 → 2.44.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 +237 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# @memberjunction/entity-communications-base
|
|
2
|
+
|
|
3
|
+
Base types and abstractions for implementing entity-level communications in MemberJunction. This package provides the foundation for building communication engines that can send messages (email, SMS, etc.) to entity records.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Entity Communications Base package enables developers to:
|
|
8
|
+
- Define communication message types for specific entities
|
|
9
|
+
- Configure communication fields and templates per entity
|
|
10
|
+
- Execute bulk communications against entity record sets
|
|
11
|
+
- Support multiple communication providers (email, SMS, etc.)
|
|
12
|
+
- Preview messages before sending
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @memberjunction/entity-communications-base
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Core Components
|
|
21
|
+
|
|
22
|
+
### EntityCommunicationsEngineBase
|
|
23
|
+
|
|
24
|
+
Abstract base class for implementing entity communication engines. Provides metadata loading, configuration, and validation capabilities.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { EntityCommunicationsEngineBase } from '@memberjunction/entity-communications-base';
|
|
28
|
+
|
|
29
|
+
class MyEntityCommunicationEngine extends EntityCommunicationsEngineBase {
|
|
30
|
+
async RunEntityCommunication(params: EntityCommunicationParams): Promise<EntityCommunicationResult> {
|
|
31
|
+
// Implementation for sending communications
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### EntityCommunicationMessageTypeExtended
|
|
37
|
+
|
|
38
|
+
Extended entity class that includes related communication fields.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const messageTypes = engine.GetEntityCommunicationMessageTypes(entityID);
|
|
42
|
+
messageTypes.forEach(messageType => {
|
|
43
|
+
console.log(`Message Type: ${messageType.Name}`);
|
|
44
|
+
console.log(`Fields: ${messageType.CommunicationFields.map(f => f.Name).join(', ')}`);
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### EntityCommunicationParams
|
|
49
|
+
|
|
50
|
+
Parameters for executing entity communications:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const params: EntityCommunicationParams = {
|
|
54
|
+
EntityID: 'entity-id-here',
|
|
55
|
+
RunViewParams: {
|
|
56
|
+
EntityName: 'Contacts',
|
|
57
|
+
ExtraFilter: 'Status = "Active"'
|
|
58
|
+
},
|
|
59
|
+
ProviderName: 'SendGrid',
|
|
60
|
+
ProviderMessageTypeName: 'Email',
|
|
61
|
+
Message: {
|
|
62
|
+
Subject: 'Hello {{FirstName}}',
|
|
63
|
+
Body: 'Welcome to our service!',
|
|
64
|
+
HTMLBody: '<h1>Welcome {{FirstName}}!</h1>'
|
|
65
|
+
},
|
|
66
|
+
PreviewOnly: false,
|
|
67
|
+
IncludeProcessedMessages: true
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage Examples
|
|
72
|
+
|
|
73
|
+
### Basic Implementation
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import {
|
|
77
|
+
EntityCommunicationsEngineBase,
|
|
78
|
+
EntityCommunicationParams,
|
|
79
|
+
EntityCommunicationResult
|
|
80
|
+
} from '@memberjunction/entity-communications-base';
|
|
81
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
82
|
+
|
|
83
|
+
@RegisterClass(EntityCommunicationsEngineBase)
|
|
84
|
+
export class CustomEntityCommunicationEngine extends EntityCommunicationsEngineBase {
|
|
85
|
+
|
|
86
|
+
async RunEntityCommunication(params: EntityCommunicationParams): Promise<EntityCommunicationResult> {
|
|
87
|
+
try {
|
|
88
|
+
// Validate entity supports communication
|
|
89
|
+
if (!this.EntitySupportsCommunication(params.EntityID)) {
|
|
90
|
+
return {
|
|
91
|
+
Success: false,
|
|
92
|
+
ErrorMessage: 'Entity does not support communications'
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Get message types for entity
|
|
97
|
+
const messageTypes = this.GetEntityCommunicationMessageTypes(params.EntityID);
|
|
98
|
+
|
|
99
|
+
// Process and send messages
|
|
100
|
+
const results = await this.processMessages(params);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
Success: true,
|
|
104
|
+
Results: results
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return {
|
|
108
|
+
Success: false,
|
|
109
|
+
ErrorMessage: error.message
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private async processMessages(params: EntityCommunicationParams) {
|
|
115
|
+
// Implementation specific to your communication provider
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Configuration and Initialization
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { CustomEntityCommunicationEngine } from './custom-engine';
|
|
124
|
+
import { UserInfo } from '@memberjunction/core';
|
|
125
|
+
|
|
126
|
+
// Initialize the engine
|
|
127
|
+
const engine = CustomEntityCommunicationEngine.Instance;
|
|
128
|
+
|
|
129
|
+
// Configure with user context
|
|
130
|
+
const user = new UserInfo();
|
|
131
|
+
await engine.Config(false, user);
|
|
132
|
+
|
|
133
|
+
// Check if entity supports communication
|
|
134
|
+
const entityID = 'some-entity-id';
|
|
135
|
+
if (engine.EntitySupportsCommunication(entityID)) {
|
|
136
|
+
// Get available message types
|
|
137
|
+
const messageTypes = engine.GetEntityCommunicationMessageTypes(entityID);
|
|
138
|
+
console.log(`Found ${messageTypes.length} message types`);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Sending Communications
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// Send email to all active contacts
|
|
146
|
+
const result = await engine.RunEntityCommunication({
|
|
147
|
+
EntityID: 'contact-entity-id',
|
|
148
|
+
RunViewParams: {
|
|
149
|
+
EntityName: 'Contacts',
|
|
150
|
+
ExtraFilter: 'IsActive = 1',
|
|
151
|
+
OrderBy: 'LastName, FirstName'
|
|
152
|
+
},
|
|
153
|
+
ProviderName: 'SendGrid',
|
|
154
|
+
ProviderMessageTypeName: 'Email',
|
|
155
|
+
Message: {
|
|
156
|
+
Subject: 'Monthly Newsletter',
|
|
157
|
+
HTMLBody: '<html>...</html>',
|
|
158
|
+
Body: 'Plain text version...'
|
|
159
|
+
},
|
|
160
|
+
PreviewOnly: false,
|
|
161
|
+
IncludeProcessedMessages: true
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (result.Success) {
|
|
165
|
+
console.log(`Sent ${result.Results.length} messages`);
|
|
166
|
+
result.Results.forEach(item => {
|
|
167
|
+
console.log(`Sent to: ${item.RecipientData.Email}`);
|
|
168
|
+
console.log(`Message ID: ${item.Message.MessageID}`);
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
console.error(`Communication failed: ${result.ErrorMessage}`);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## API Reference
|
|
176
|
+
|
|
177
|
+
### EntityCommunicationsEngineBase
|
|
178
|
+
|
|
179
|
+
#### Properties
|
|
180
|
+
|
|
181
|
+
- `EntityCommunicationMessageTypes`: Array of extended message type entities
|
|
182
|
+
- `EntityCommunicationFields`: Array of communication field entities
|
|
183
|
+
- `Instance`: Static singleton instance of the engine
|
|
184
|
+
|
|
185
|
+
#### Methods
|
|
186
|
+
|
|
187
|
+
- `Config(forceRefresh?, contextUser?, provider?)`: Initialize engine configuration
|
|
188
|
+
- `GetEntityCommunicationMessageTypes(entityID)`: Get message types for an entity
|
|
189
|
+
- `EntitySupportsCommunication(entityID)`: Check if entity supports communications
|
|
190
|
+
- `RunEntityCommunication(params)`: Abstract method to implement communication execution
|
|
191
|
+
|
|
192
|
+
### EntityCommunicationParams
|
|
193
|
+
|
|
194
|
+
- `EntityID`: ID of the entity to communicate with
|
|
195
|
+
- `RunViewParams`: Parameters for fetching entity records
|
|
196
|
+
- `ProviderName`: Name of the communication provider
|
|
197
|
+
- `ProviderMessageTypeName`: Type of message (e.g., 'Email', 'SMS')
|
|
198
|
+
- `Message`: Message content object
|
|
199
|
+
- `PreviewOnly?`: If true, preview without sending
|
|
200
|
+
- `IncludeProcessedMessages?`: Include processed message data in results
|
|
201
|
+
|
|
202
|
+
### EntityCommunicationResult
|
|
203
|
+
|
|
204
|
+
- `Success`: Boolean indicating operation success
|
|
205
|
+
- `ErrorMessage?`: Error details if operation failed
|
|
206
|
+
- `Results?`: Array of `EntityCommunicationResultItem` objects
|
|
207
|
+
|
|
208
|
+
### EntityCommunicationResultItem
|
|
209
|
+
|
|
210
|
+
- `RecipientData`: Entity record data for recipient
|
|
211
|
+
- `Message`: Processed message with provider-specific details
|
|
212
|
+
|
|
213
|
+
## Dependencies
|
|
214
|
+
|
|
215
|
+
- `@memberjunction/global`: Global utilities and registration
|
|
216
|
+
- `@memberjunction/core`: Core MemberJunction functionality
|
|
217
|
+
- `@memberjunction/core-entities`: Core entity definitions
|
|
218
|
+
- `@memberjunction/communication-types`: Communication type definitions
|
|
219
|
+
|
|
220
|
+
## Integration with Other MJ Packages
|
|
221
|
+
|
|
222
|
+
This package integrates with:
|
|
223
|
+
- **@memberjunction/communication-types**: Provides base communication types and interfaces
|
|
224
|
+
- **@memberjunction/core**: Uses BaseEngine pattern and metadata providers
|
|
225
|
+
- **@memberjunction/templates**: Can be used with template engine for dynamic content
|
|
226
|
+
- **@memberjunction/server**: Server-side implementations typically extend this base
|
|
227
|
+
|
|
228
|
+
## Build Notes
|
|
229
|
+
|
|
230
|
+
- TypeScript compilation: `npm run build`
|
|
231
|
+
- Source files in `/src`, compiled to `/dist`
|
|
232
|
+
- Supports both CommonJS and ES modules
|
|
233
|
+
- Type definitions included
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
ISC
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/entity-communications-base",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "MemberJunction: Base Types for Client/Server use with Entity Communications Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/global": "2.
|
|
23
|
-
"@memberjunction/core": "2.
|
|
24
|
-
"@memberjunction/core-entities": "2.
|
|
25
|
-
"@memberjunction/communication-types": "2.
|
|
22
|
+
"@memberjunction/global": "2.44.0",
|
|
23
|
+
"@memberjunction/core": "2.44.0",
|
|
24
|
+
"@memberjunction/core-entities": "2.44.0",
|
|
25
|
+
"@memberjunction/communication-types": "2.44.0"
|
|
26
26
|
}
|
|
27
27
|
}
|