@memberjunction/entity-communications-client 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.
Files changed (2) hide show
  1. package/README.md +247 -0
  2. package/package.json +6 -6
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # @memberjunction/entity-communications-client
2
+
3
+ A client library for interacting with the MemberJunction Entity Communications Engine. This package provides a GraphQL-based client implementation for executing communication requests against views of entity records.
4
+
5
+ ## Overview
6
+
7
+ The Entity Communications Client enables you to send templated messages (email, SMS, etc.) to recipients based on entity data views. It supports various communication providers and message types while leveraging MemberJunction's templating system for dynamic content generation.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @memberjunction/entity-communications-client
13
+ ```
14
+
15
+ ## Dependencies
16
+
17
+ This package depends on:
18
+ - `@memberjunction/global` - Core MemberJunction utilities
19
+ - `@memberjunction/core` - Core MemberJunction functionality
20
+ - `@memberjunction/core-entities` - Entity definitions
21
+ - `@memberjunction/entity-communications-base` - Base classes for entity communications
22
+ - `@memberjunction/graphql-dataprovider` - GraphQL data provider for API calls
23
+
24
+ ## Usage
25
+
26
+ ### Basic Example
27
+
28
+ ```typescript
29
+ import { EntityCommunicationsEngineClient } from '@memberjunction/entity-communications-client';
30
+ import { EntityCommunicationParams } from '@memberjunction/entity-communications-base';
31
+
32
+ // Initialize the client
33
+ const client = new EntityCommunicationsEngineClient();
34
+
35
+ // Configure the client (required before first use)
36
+ await client.Config();
37
+
38
+ // Set up communication parameters
39
+ const params: EntityCommunicationParams = {
40
+ EntityID: '123', // ID of the entity to communicate about
41
+ RunViewParams: {
42
+ ViewID: '456', // ID of the view that defines recipients
43
+ ExtraFilter: 'IsActive = 1', // Additional filtering
44
+ OrderBy: 'LastName ASC',
45
+ MaxRows: 100
46
+ },
47
+ ProviderName: 'SendGrid', // Communication provider to use
48
+ ProviderMessageTypeName: 'Email', // Type of message
49
+ Message: {
50
+ From: 'noreply@example.com',
51
+ To: '{{Email}}', // Can use template variables
52
+ Subject: 'Important Update',
53
+ Body: 'Hello {{FirstName}}, we have an update for you.',
54
+ ContextData: {
55
+ // Additional data for template rendering
56
+ CompanyName: 'Acme Corp',
57
+ UpdateDate: new Date()
58
+ }
59
+ },
60
+ PreviewOnly: false, // Set to true to preview without sending
61
+ IncludeProcessedMessages: true // Include processed message content in results
62
+ };
63
+
64
+ // Execute the communication
65
+ const result = await client.RunEntityCommunication(params);
66
+
67
+ if (result.Success) {
68
+ console.log(`Successfully sent ${result.Results.length} messages`);
69
+
70
+ // Process results
71
+ result.Results.forEach(item => {
72
+ console.log(`Sent to: ${item.RecipientData.Email}`);
73
+ console.log(`Message: ${item.Message.ProcessedBody}`);
74
+ });
75
+ } else {
76
+ console.error(`Communication failed: ${result.ErrorMessage}`);
77
+ }
78
+ ```
79
+
80
+ ### Using Templates
81
+
82
+ ```typescript
83
+ import { TemplateEntityExtended } from '@memberjunction/templates-base-types';
84
+
85
+ // Load your template (example)
86
+ const template = await getTemplate('Welcome Email'); // Your template loading logic
87
+
88
+ const params: EntityCommunicationParams = {
89
+ EntityID: '123',
90
+ RunViewParams: {
91
+ ViewID: '456',
92
+ // View should return records with fields matching template variables
93
+ },
94
+ ProviderName: 'SendGrid',
95
+ ProviderMessageTypeName: 'Email',
96
+ Message: {
97
+ From: 'welcome@example.com',
98
+ To: '{{Email}}',
99
+ SubjectTemplate: subjectTemplate, // Template for subject line
100
+ BodyTemplate: bodyTemplate, // Template for plain text body
101
+ HTMLBodyTemplate: htmlTemplate, // Template for HTML body
102
+ ContextData: {
103
+ // Global context data available to all recipients
104
+ Year: new Date().getFullYear()
105
+ }
106
+ }
107
+ };
108
+
109
+ const result = await client.RunEntityCommunication(params);
110
+ ```
111
+
112
+ ### Preview Mode
113
+
114
+ To test your communications without actually sending messages:
115
+
116
+ ```typescript
117
+ const params: EntityCommunicationParams = {
118
+ // ... other parameters ...
119
+ PreviewOnly: true, // Enable preview mode
120
+ IncludeProcessedMessages: true // Get the processed message content
121
+ };
122
+
123
+ const result = await client.RunEntityCommunication(params);
124
+
125
+ // Review what would be sent
126
+ result.Results.forEach(item => {
127
+ console.log('Would send to:', item.RecipientData);
128
+ console.log('Subject:', item.Message.ProcessedSubject);
129
+ console.log('Body:', item.Message.ProcessedBody);
130
+ });
131
+ ```
132
+
133
+ ## API Reference
134
+
135
+ ### EntityCommunicationsEngineClient
136
+
137
+ The main client class for entity communications.
138
+
139
+ #### Methods
140
+
141
+ ##### `Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>`
142
+
143
+ Configures the client by loading necessary metadata. Must be called before using other methods.
144
+
145
+ - `forceRefresh` - Force reload of metadata cache
146
+ - `contextUser` - User context for permissions
147
+ - `provider` - Custom metadata provider
148
+
149
+ ##### `RunEntityCommunication(params: EntityCommunicationParams): Promise<EntityCommunicationResult>`
150
+
151
+ Executes a communication request against entity records.
152
+
153
+ - `params` - Communication parameters (see below)
154
+ - Returns: Promise resolving to communication results
155
+
156
+ ### Types
157
+
158
+ #### EntityCommunicationParams
159
+
160
+ ```typescript
161
+ interface EntityCommunicationParams {
162
+ EntityID: string; // ID of the entity to communicate about
163
+ RunViewParams: RunViewParams; // View parameters to select recipients
164
+ ProviderName: string; // Name of communication provider
165
+ ProviderMessageTypeName: string; // Type of message for the provider
166
+ Message: Message; // Message content and templates
167
+ PreviewOnly?: boolean; // If true, preview without sending
168
+ IncludeProcessedMessages?: boolean; // Include processed content in results
169
+ }
170
+ ```
171
+
172
+ #### Message
173
+
174
+ ```typescript
175
+ interface Message {
176
+ MessageType?: CommunicationProviderMessageTypeEntity;
177
+ From?: string; // Sender address
178
+ To?: string; // Recipient address (can use templates)
179
+ Body?: string; // Plain text body
180
+ BodyTemplate?: TemplateEntityExtended;
181
+ HTMLBody?: string; // HTML body
182
+ HTMLBodyTemplate?: TemplateEntityExtended;
183
+ Subject?: string; // Subject line
184
+ SubjectTemplate?: TemplateEntityExtended;
185
+ ContextData?: any; // Additional template context
186
+ }
187
+ ```
188
+
189
+ #### EntityCommunicationResult
190
+
191
+ ```typescript
192
+ interface EntityCommunicationResult {
193
+ Success: boolean; // Whether communication succeeded
194
+ ErrorMessage?: string; // Error details if failed
195
+ Results?: EntityCommunicationResultItem[]; // Individual message results
196
+ }
197
+
198
+ interface EntityCommunicationResultItem {
199
+ RecipientData: any; // Data for this recipient
200
+ Message: ProcessedMessage; // The processed message
201
+ }
202
+ ```
203
+
204
+ ## Integration with MemberJunction
205
+
206
+ This client integrates seamlessly with other MemberJunction packages:
207
+
208
+ - **Templates**: Use `@memberjunction/templates-base-types` for dynamic content
209
+ - **Entities**: Works with any entity defined in your MemberJunction schema
210
+ - **Views**: Leverages MemberJunction views to select communication recipients
211
+ - **Providers**: Supports all registered communication providers (SendGrid, Twilio, MS Graph, etc.)
212
+
213
+ ## Configuration
214
+
215
+ The client uses GraphQL to communicate with the MemberJunction API. Ensure your GraphQL endpoint is properly configured through the `GraphQLDataProvider`.
216
+
217
+ ## Error Handling
218
+
219
+ The client provides detailed error information:
220
+
221
+ ```typescript
222
+ const result = await client.RunEntityCommunication(params);
223
+
224
+ if (!result.Success) {
225
+ console.error('Communication failed:', result.ErrorMessage);
226
+
227
+ // Check individual message failures
228
+ result.Results?.forEach(item => {
229
+ if (!item.Message.Success) {
230
+ console.error(`Failed for ${item.RecipientData.Email}:`, item.Message.Error);
231
+ }
232
+ });
233
+ }
234
+ ```
235
+
236
+ ## Best Practices
237
+
238
+ 1. **Always call `Config()` before first use** - This loads necessary metadata
239
+ 2. **Use preview mode for testing** - Set `PreviewOnly: true` to test without sending
240
+ 3. **Handle errors gracefully** - Check both overall and individual message success
241
+ 4. **Use templates for consistency** - Leverage MemberJunction's template system
242
+ 5. **Filter recipients carefully** - Use view filters to target the right audience
243
+ 6. **Include context data** - Provide all necessary data for template rendering
244
+
245
+ ## License
246
+
247
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/entity-communications-client",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "MemberJunction: Client for interacting with Entity Communications Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,10 +19,10 @@
19
19
  "typescript": "^5.4.5"
20
20
  },
21
21
  "dependencies": {
22
- "@memberjunction/global": "2.43.0",
23
- "@memberjunction/core": "2.43.0",
24
- "@memberjunction/core-entities": "2.43.0",
25
- "@memberjunction/entity-communications-base": "2.43.0",
26
- "@memberjunction/graphql-dataprovider": "2.43.0"
22
+ "@memberjunction/global": "2.44.0",
23
+ "@memberjunction/core": "2.44.0",
24
+ "@memberjunction/core-entities": "2.44.0",
25
+ "@memberjunction/entity-communications-base": "2.44.0",
26
+ "@memberjunction/graphql-dataprovider": "2.44.0"
27
27
  }
28
28
  }