@memberjunction/entity-communications-server 1.5.3 → 1.6.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-communications.d.ts","sourceRoot":"","sources":["../src/entity-communications.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAqB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAG5F;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,8BAA8B;IAC1E;;;;;;;OAOG;IACU,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"entity-communications.d.ts","sourceRoot":"","sources":["../src/entity-communications.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAqB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAG5F;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,8BAA8B;IAC1E;;;;;;;OAOG;IACU,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAC9C,YAAY,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,EACrD,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAC,CAAC;CA6F3G"}
|
|
@@ -17,55 +17,87 @@ class EntityCommunicationsEngine extends entity_communications_base_1.EntityComm
|
|
|
17
17
|
* @param message
|
|
18
18
|
*/
|
|
19
19
|
async RunEntityCommunication(entityID, runViewParams, providerName, providerMessageTypeName, message) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const provider = communication_engine_1.CommunicationEngine.Instance.Providers.find(p => p.Name.trim().toLowerCase() === providerName.trim().toLowerCase());
|
|
30
|
-
if (!provider)
|
|
31
|
-
throw new Error(`Provider ${providerName} not found`);
|
|
32
|
-
const providerMessageType = provider.MessageTypes.find(mt => mt.Name.trim().toLowerCase() === providerMessageTypeName.trim().toLowerCase());
|
|
33
|
-
const entityMessageTypes = this.GetEntityCommunicationMessageTypes(entityID);
|
|
34
|
-
const entityMessageType = entityMessageTypes.find(m => m.BaseMessageTypeID === providerMessageType.CommunicationBaseMessageTypeID);
|
|
35
|
-
if (!entityMessageType) {
|
|
36
|
-
throw new Error(`Entity ${entityID} does not support message type ${providerMessageType.CommunicationBaseMessageType}`);
|
|
37
|
-
}
|
|
38
|
-
// we have now validated we are good on the message type requested...
|
|
39
|
-
// next up we will figure out which field to use for the entity, starting at the entity level and then going to the record level, IF the entity has
|
|
40
|
-
// a PreferredCommunicationField we will flag that here as recordLevelPref = true
|
|
41
|
-
const recordLevelPref = entityInfo.PreferredCommunicationField?.length > 0;
|
|
42
|
-
// get the highest priority field within the entityMessageType.communicationFields property
|
|
43
|
-
const entityLevelPrefField = entityMessageType.CommunicationFields.sort((a, b) => a.Priority - b.Priority)[0];
|
|
44
|
-
// next our main job here is to run the view, get all the records, and then call the communication engine
|
|
45
|
-
const rv = new core_1.RunView();
|
|
46
|
-
const result = await rv.RunView(runViewParams, this.ContextUser);
|
|
47
|
-
if (result && result.Success) {
|
|
48
|
-
// have the results, now we can map the results to the types the comm engine needs and call SendMessages() in the comm engine
|
|
20
|
+
try {
|
|
21
|
+
this.TryThrowIfNotLoaded();
|
|
22
|
+
const md = new core_1.Metadata();
|
|
23
|
+
const entityInfo = md.Entities.find(e => e.ID === entityID);
|
|
24
|
+
if (!entityInfo)
|
|
25
|
+
throw new Error(`Entity ${entityID} not found`);
|
|
26
|
+
if (!this.EntitySupportsCommunication(entityID)) {
|
|
27
|
+
throw new Error(`Entity ${entityID} does not support communication`);
|
|
28
|
+
}
|
|
49
29
|
await communication_engine_1.CommunicationEngine.Instance.Config(false, this.ContextUser);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
30
|
+
const provider = communication_engine_1.CommunicationEngine.Instance.Providers.find(p => p.Name.trim().toLowerCase() === providerName.trim().toLowerCase());
|
|
31
|
+
if (!provider)
|
|
32
|
+
throw new Error(`Provider ${providerName} not found`);
|
|
33
|
+
const providerMessageType = provider.MessageTypes.find(mt => mt.Name.trim().toLowerCase() === providerMessageTypeName.trim().toLowerCase());
|
|
34
|
+
const entityMessageTypes = this.GetEntityCommunicationMessageTypes(entityID);
|
|
35
|
+
const entityMessageType = entityMessageTypes.find(m => m.BaseMessageTypeID === providerMessageType.CommunicationBaseMessageTypeID);
|
|
36
|
+
if (!entityMessageType) {
|
|
37
|
+
throw new Error(`Entity ${entityID} does not support message type ${providerMessageType.CommunicationBaseMessageType}`);
|
|
38
|
+
}
|
|
39
|
+
// we have now validated we are good on the message type requested...
|
|
40
|
+
// next up we will figure out which field to use for the entity, starting at the entity level and then going to the record level, IF the entity has
|
|
41
|
+
// a PreferredCommunicationField we will flag that here as recordLevelPref = true
|
|
42
|
+
const recordLevelPref = entityInfo.PreferredCommunicationField?.length > 0;
|
|
43
|
+
// get the highest priority field within the entityMessageType.communicationFields property
|
|
44
|
+
const entityLevelPrefField = entityMessageType.CommunicationFields.sort((a, b) => a.Priority - b.Priority)[0];
|
|
45
|
+
// next our main job here is to run the view, get all the records, and then call the communication engine
|
|
46
|
+
const rv = new core_1.RunView();
|
|
47
|
+
const rvParams2 = {
|
|
48
|
+
...runViewParams
|
|
49
|
+
};
|
|
50
|
+
// now change rvParams2.Fields to have ALL entity fields to make sure we get them all
|
|
51
|
+
rvParams2.Fields = entityInfo.Fields.map(f => f.Name);
|
|
52
|
+
const result = await rv.RunView(rvParams2, this.ContextUser);
|
|
53
|
+
if (result && result.Success) {
|
|
54
|
+
// have the results, now we can map the results to the types the comm engine needs and call SendMessages() in the comm engine
|
|
55
|
+
await communication_engine_1.CommunicationEngine.Instance.Config(false, this.ContextUser);
|
|
56
|
+
const recipients = result.Results.map(r => {
|
|
57
|
+
// in the below we get the VALUE of the record level preferred field if it exists, otherwise we get the value of the entity level preferred field
|
|
58
|
+
const ToValue = !recordLevelPref ? r[entityLevelPrefField.FieldName] : r[r[entityInfo.PreferredCommunicationField]];
|
|
59
|
+
return {
|
|
60
|
+
To: ToValue,
|
|
61
|
+
ContextData: { ...r,
|
|
62
|
+
recommendedArticles: [
|
|
63
|
+
{
|
|
64
|
+
title: 'Exemplifying the Importance of Code Reviews',
|
|
65
|
+
url: 'https://example.com/article1'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
title: 'AI and Software Development: A New Frontier',
|
|
69
|
+
url: 'https://example.com/article2'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: 'Gardening Tips for Fun Loving Software Developers',
|
|
73
|
+
url: 'https://example.com/article3'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
const sendResult = await communication_engine_1.CommunicationEngine.Instance.SendMessages(providerName, providerMessageTypeName, message, recipients);
|
|
80
|
+
if (sendResult && sendResult.length === recipients.length) {
|
|
81
|
+
// make sure none of the messages failed
|
|
82
|
+
return {
|
|
83
|
+
Success: !sendResult.some(r => !r.Success),
|
|
84
|
+
ErrorMessage: sendResult.filter(r => !r.Success).map(r => r.Error).join('; ')
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error(`Failed to run view ${runViewParams.ViewName}: ${result.ErrorMessage}`);
|
|
65
90
|
}
|
|
91
|
+
return {
|
|
92
|
+
Success: false,
|
|
93
|
+
ErrorMessage: 'Unknown error'
|
|
94
|
+
};
|
|
66
95
|
}
|
|
67
|
-
|
|
68
|
-
|
|
96
|
+
catch (e) {
|
|
97
|
+
return {
|
|
98
|
+
Success: false,
|
|
99
|
+
ErrorMessage: e.message
|
|
100
|
+
};
|
|
69
101
|
}
|
|
70
102
|
}
|
|
71
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-communications.js","sourceRoot":"","sources":["../src/entity-communications.ts"],"names":[],"mappings":";;;AAAA,+EAA2E;AAE3E,+CAAwE;AACxE,2FAA4F;AAG5F;;GAEG;AACH,MAAa,0BAA2B,SAAQ,2DAA8B;IAC1E;;;;;;;OAOG;IACI,KAAK,CAAC,sBAAsB,CAAC,QAAgB,EAAE,aAA4B,
|
|
1
|
+
{"version":3,"file":"entity-communications.js","sourceRoot":"","sources":["../src/entity-communications.ts"],"names":[],"mappings":";;;AAAA,+EAA2E;AAE3E,+CAAwE;AACxE,2FAA4F;AAG5F;;GAEG;AACH,MAAa,0BAA2B,SAAQ,2DAA8B;IAC1E;;;;;;;OAOG;IACI,KAAK,CAAC,sBAAsB,CAAC,QAAgB,EAAE,aAA4B,EAC9C,YAAoB,EAAE,uBAA+B,EACrD,OAAgB;QAChD,IAAI,CAAC;YACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAE3B,MAAM,EAAE,GAAG,IAAI,eAAQ,EAAE,CAAC;YAC1B,MAAM,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;YAC5D,IAAI,CAAC,UAAU;gBACX,MAAM,IAAI,KAAK,CAAC,UAAU,QAAQ,YAAY,CAAC,CAAC;YAEpD,IAAI,CAAC,IA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D,GAAG,EAAE,8BAA8B;iCACpC;6BACF;yBACF;qBACJ,CAAC;gBACN,CAAC,CAAC,CAAA;gBACF,MAAM,UAAU,GAAG,MAAM,0CAAmB,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,EAAE,uBAAuB,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;gBAC/H,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;oBACxD,wCAAwC;oBACxC,OAAO;wBACH,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;wBAC1C,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;qBAChF,CAAC;gBACN,CAAC;YACL,CAAC;iBACI,CAAC;gBACF,MAAM,IAAI,KAAK,CAAC,sBAAsB,aAAa,CAAC,QAAQ,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;YAC5F,CAAC;YAED,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE,eAAe;aAChC,CAAA;QACL,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE,CAAC,CAAC,OAAO;aAC1B,CAAA;QACL,CAAC;IACL,CAAC;CACJ;AAxGD,gEAwGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/entity-communications-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "MemberJunction: Library that connects the MJ entities framework to the communication framework",
|
|
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": "1.
|
|
23
|
-
"@memberjunction/core": "1.
|
|
24
|
-
"@memberjunction/core-entities": "1.
|
|
25
|
-
"@memberjunction/communication-engine": "1.
|
|
26
|
-
"@memberjunction/entity-communications-base": "1.
|
|
22
|
+
"@memberjunction/global": "1.6.1",
|
|
23
|
+
"@memberjunction/core": "1.6.1",
|
|
24
|
+
"@memberjunction/core-entities": "1.6.1",
|
|
25
|
+
"@memberjunction/communication-engine": "1.6.1",
|
|
26
|
+
"@memberjunction/entity-communications-base": "1.6.1"
|
|
27
27
|
}
|
|
28
28
|
}
|