@memberjunction/entity-communications-base 4.0.0 → 4.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.
Files changed (2) hide show
  1. package/README.md +119 -179
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,15 +1,43 @@
1
1
  # @memberjunction/entity-communications-base
2
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
3
+ Shared types and base classes for entity-based communications in MemberJunction. This package defines the parameter, result, and data structures used by both the client-side (`entity-comm-client`) and server-side (`entity-comm-server`) entity communication implementations.
4
+
5
+ ## Architecture
6
+
7
+ ```mermaid
8
+ graph TD
9
+ subgraph base["@memberjunction/entity-communications-base"]
10
+ ENGINE["EntityCommunicationsEngineBase\n(Abstract Singleton)"]
11
+ PARAMS["EntityCommunicationParams"]
12
+ RESULT["EntityCommunicationResult"]
13
+ EXT["EntityCommunicationMessageTypeExtended"]
14
+ end
15
+
16
+ subgraph client["entity-comm-client"]
17
+ CC["EntityCommunicationsEngineClient\n(GraphQL)"]
18
+ end
19
+
20
+ subgraph server["entity-comm-server"]
21
+ CS["EntityCommunicationsEngine\n(Server-Side)"]
22
+ end
23
+
24
+ subgraph types["@memberjunction/communication-types"]
25
+ MSG["Message / ProcessedMessage"]
26
+ end
27
+
28
+ ENGINE --> CC
29
+ ENGINE --> CS
30
+ PARAMS --> CC
31
+ PARAMS --> CS
32
+ RESULT --> CC
33
+ RESULT --> CS
34
+ MSG --> PARAMS
35
+
36
+ style base fill:#2d6a9f,stroke:#1a4971,color:#fff
37
+ style client fill:#b8762f,stroke:#8a5722,color:#fff
38
+ style server fill:#2d8659,stroke:#1a5c3a,color:#fff
39
+ style types fill:#7c5295,stroke:#563a6b,color:#fff
40
+ ```
13
41
 
14
42
  ## Installation
15
43
 
@@ -17,221 +45,133 @@ The Entity Communications Base package enables developers to:
17
45
  npm install @memberjunction/entity-communications-base
18
46
  ```
19
47
 
20
- ## Core Components
48
+ ## Key Exports
21
49
 
22
50
  ### EntityCommunicationsEngineBase
23
51
 
24
- Abstract base class for implementing entity communication engines. Provides metadata loading, configuration, and validation capabilities.
52
+ Abstract singleton base class that loads entity communication metadata including message types, field mappings, and provider associations. Both the client and server implementations extend this class.
25
53
 
26
54
  ```typescript
27
55
  import { EntityCommunicationsEngineBase } from '@memberjunction/entity-communications-base';
28
56
 
29
- class MyEntityCommunicationEngine extends EntityCommunicationsEngineBase {
30
- async RunEntityCommunication(params: EntityCommunicationParams): Promise<EntityCommunicationResult> {
31
- // Implementation for sending communications
32
- }
57
+ // After Config(), access loaded metadata
58
+ const messageTypes = engine.EntityCommunicationMessageTypes;
59
+
60
+ // Check entity support
61
+ if (engine.EntitySupportsCommunication(entityID)) {
62
+ const types = engine.GetEntityCommunicationMessageTypes(entityID);
33
63
  }
34
64
  ```
35
65
 
36
- ### EntityCommunicationMessageTypeExtended
37
-
38
- Extended entity class that includes related communication fields.
66
+ #### Abstract Method
39
67
 
40
68
  ```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
- });
69
+ abstract RunEntityCommunication(
70
+ params: EntityCommunicationParams
71
+ ): Promise<EntityCommunicationResult>;
46
72
  ```
47
73
 
74
+ Both `EntityCommunicationsEngineClient` and `EntityCommunicationsEngine` (server) implement this method with their respective communication strategies.
75
+
48
76
  ### EntityCommunicationParams
49
77
 
50
- Parameters for executing entity communications:
78
+ Defines the parameters for running an entity-based communication.
51
79
 
52
80
  ```typescript
81
+ import { EntityCommunicationParams } from '@memberjunction/entity-communications-base';
82
+
53
83
  const params: EntityCommunicationParams = {
54
- EntityID: 'entity-id-here',
84
+ EntityID: 'entity-uuid',
55
85
  RunViewParams: {
56
86
  EntityName: 'Contacts',
57
- ExtraFilter: 'Status = "Active"'
87
+ ExtraFilter: 'Status = "Active"',
88
+ OrderBy: 'LastName, FirstName'
58
89
  },
59
90
  ProviderName: 'SendGrid',
60
91
  ProviderMessageTypeName: 'Email',
61
92
  Message: {
62
- Subject: 'Hello {{FirstName}}',
63
- Body: 'Welcome to our service!',
64
- HTMLBody: '<h1>Welcome {{FirstName}}!</h1>'
93
+ Subject: 'Monthly Newsletter',
94
+ Body: 'Hello {{FirstName}}!',
95
+ HTMLBody: '<h1>Hello {{FirstName}}!</h1>',
96
+ ContextData: { CompanyName: 'Acme Corp' }
65
97
  },
66
98
  PreviewOnly: false,
67
99
  IncludeProcessedMessages: true
68
100
  };
69
101
  ```
70
102
 
71
- ## Usage Examples
103
+ | Property | Type | Required | Description |
104
+ |----------|------|----------|-------------|
105
+ | `EntityID` | `string` | Yes | UUID of the entity to communicate with |
106
+ | `RunViewParams` | `RunViewParams` | Yes | View parameters for selecting recipient records |
107
+ | `ProviderName` | `string` | Yes | Communication provider name (e.g., "SendGrid") |
108
+ | `ProviderMessageTypeName` | `string` | Yes | Message type (e.g., "Email", "SMS") |
109
+ | `Message` | `Message` | Yes | Message content and optional templates |
110
+ | `PreviewOnly` | `boolean` | No | Preview without sending |
111
+ | `IncludeProcessedMessages` | `boolean` | No | Include rendered content in results |
72
112
 
73
- ### Basic Implementation
113
+ ### EntityCommunicationResult / EntityCommunicationResultItem
74
114
 
75
115
  ```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
- }
116
+ interface EntityCommunicationResult {
117
+ Success: boolean;
118
+ ErrorMessage?: string;
119
+ Results?: EntityCommunicationResultItem[];
117
120
  }
118
- ```
119
-
120
- ### Configuration and Initialization
121
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`);
122
+ interface EntityCommunicationResultItem {
123
+ RecipientData: Record<string, unknown>; // Entity record fields
124
+ Message: ProcessedMessage; // Rendered message
139
125
  }
140
126
  ```
141
127
 
142
- ### Sending Communications
128
+ ### EntityCommunicationMessageTypeExtended
143
129
 
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
- });
130
+ Extends the base `EntityCommunicationMessageTypeEntity` with communication field mappings, linking base message types to entity-specific fields for recipient resolution.
163
131
 
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}`);
132
+ ```typescript
133
+ const messageTypes = engine.GetEntityCommunicationMessageTypes(entityID);
134
+ messageTypes.forEach(mt => {
135
+ console.log(`Type: ${mt.BaseMessageType}`);
136
+ mt.CommunicationFields.forEach(field => {
137
+ console.log(` Field: ${field.FieldName} (Priority: ${field.Priority})`);
169
138
  });
170
- } else {
171
- console.error(`Communication failed: ${result.ErrorMessage}`);
172
- }
139
+ });
173
140
  ```
174
141
 
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
142
+ ## Data Flow
143
+
144
+ ```mermaid
145
+ sequenceDiagram
146
+ participant App as Application
147
+ participant Engine as EntityCommEngine
148
+ participant View as RunView
149
+ participant Comm as CommunicationEngine
150
+
151
+ App->>Engine: RunEntityCommunication(params)
152
+ Engine->>Engine: Validate entity and message type
153
+ Engine->>View: RunView(params.RunViewParams)
154
+ View-->>Engine: Entity records[]
155
+ loop For each record
156
+ Engine->>Engine: Build message with record context
157
+ Engine->>Comm: SendSingleMessage(provider, type, msg)
158
+ Comm-->>Engine: MessageResult
159
+ end
160
+ Engine-->>App: EntityCommunicationResult
161
+ ```
212
162
 
213
163
  ## Dependencies
214
164
 
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
165
+ | Package | Purpose |
166
+ |---------|---------|
167
+ | `@memberjunction/core` | BaseEngine, RunView, UserInfo, EntityInfo |
168
+ | `@memberjunction/core-entities` | Entity Communication metadata types |
169
+ | `@memberjunction/communication-types` | Message and ProcessedMessage classes |
170
+ | `@memberjunction/global` | RegisterClass decorator |
229
171
 
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
172
+ ## Development
234
173
 
235
- ## License
236
-
237
- ISC
174
+ ```bash
175
+ npm run build # Compile TypeScript
176
+ npm start # Watch mode
177
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/entity-communications-base",
3
3
  "type": "module",
4
- "version": "4.0.0",
4
+ "version": "4.1.0",
5
5
  "description": "MemberJunction: Base Types for Client/Server use with Entity Communications Engine",
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/global": "4.0.0",
24
- "@memberjunction/core": "4.0.0",
25
- "@memberjunction/core-entities": "4.0.0",
26
- "@memberjunction/communication-types": "4.0.0"
23
+ "@memberjunction/global": "4.1.0",
24
+ "@memberjunction/core": "4.1.0",
25
+ "@memberjunction/core-entities": "4.1.0",
26
+ "@memberjunction/communication-types": "4.1.0"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",