@memberjunction/entity-communications-server 1.5.3

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.
@@ -0,0 +1,21 @@
1
+ import { Message } from "@memberjunction/communication-types";
2
+ import { RunViewParams } from "@memberjunction/core";
3
+ import { EntityCommunicationsEngineBase } from "@memberjunction/entity-communications-base";
4
+ /**
5
+ * Server-side implementation of the entity communications engine
6
+ */
7
+ export declare class EntityCommunicationsEngine extends EntityCommunicationsEngineBase {
8
+ /**
9
+ * Executes a given message request against a view of records for a given entity
10
+ * @param entityID
11
+ * @param runViewParams
12
+ * @param providerName
13
+ * @param providerMessageTypeName
14
+ * @param message
15
+ */
16
+ RunEntityCommunication(entityID: number, runViewParams: RunViewParams, providerName: string, providerMessageTypeName: string, message: Message): Promise<{
17
+ Success: boolean;
18
+ ErrorMessage: string;
19
+ }>;
20
+ }
21
+ //# sourceMappingURL=entity-communications.d.ts.map
@@ -0,0 +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,EAAE,YAAY,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAC,CAAC;CA2DlN"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityCommunicationsEngine = void 0;
4
+ const communication_engine_1 = require("@memberjunction/communication-engine");
5
+ const core_1 = require("@memberjunction/core");
6
+ const entity_communications_base_1 = require("@memberjunction/entity-communications-base");
7
+ /**
8
+ * Server-side implementation of the entity communications engine
9
+ */
10
+ class EntityCommunicationsEngine extends entity_communications_base_1.EntityCommunicationsEngineBase {
11
+ /**
12
+ * Executes a given message request against a view of records for a given entity
13
+ * @param entityID
14
+ * @param runViewParams
15
+ * @param providerName
16
+ * @param providerMessageTypeName
17
+ * @param message
18
+ */
19
+ async RunEntityCommunication(entityID, runViewParams, providerName, providerMessageTypeName, message) {
20
+ this.TryThrowIfNotLoaded();
21
+ const md = new core_1.Metadata();
22
+ const entityInfo = md.Entities.find(e => e.ID === entityID);
23
+ if (!entityInfo)
24
+ throw new Error(`Entity ${entityID} not found`);
25
+ if (!this.EntitySupportsCommunication(entityID)) {
26
+ throw new Error(`Entity ${entityID} does not support communication`);
27
+ }
28
+ await communication_engine_1.CommunicationEngine.Instance.Config(false, this.ContextUser);
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
49
+ await communication_engine_1.CommunicationEngine.Instance.Config(false, this.ContextUser);
50
+ const recipients = result.Results.map(r => {
51
+ // 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
52
+ const ToValue = !recordLevelPref ? r[entityLevelPrefField.FieldName] : r[r[entityInfo.PreferredCommunicationField]];
53
+ return {
54
+ To: ToValue,
55
+ ContextData: r
56
+ };
57
+ });
58
+ const sendResult = await communication_engine_1.CommunicationEngine.Instance.SendMessages(providerName, providerMessageTypeName, message, recipients);
59
+ if (sendResult && sendResult.length === recipients.length) {
60
+ // make sure none of the messages failed
61
+ return {
62
+ Success: !sendResult.some(r => !r.Success),
63
+ ErrorMessage: sendResult.filter(r => !r.Success).map(r => r.Error).join('; ')
64
+ };
65
+ }
66
+ }
67
+ else {
68
+ throw new Error(`Failed to run view ${runViewParams.ViewName}: ${result.ErrorMessage}`);
69
+ }
70
+ }
71
+ }
72
+ exports.EntityCommunicationsEngine = EntityCommunicationsEngine;
73
+ //# sourceMappingURL=entity-communications.js.map
@@ -0,0 +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,EAAE,YAAoB,EAAE,uBAA+B,EAAE,OAAgB;QACvJ,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAE3B,MAAM,EAAE,GAA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AE,UAAU,CAAC,CAAC;YAC/H,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;gBACxD,wCAAwC;gBACxC,OAAO;oBACH,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;oBAC1C,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;iBAChF,CAAC;YACN,CAAC;QACL,CAAC;aACI,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,sBAAsB,aAAa,CAAC,QAAQ,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QAC5F,CAAC;IACL,CAAC;CACJ;AApED,gEAoEC"}
@@ -0,0 +1,2 @@
1
+ export * from './entity-communications';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // PUBLIC API SURFACE AREA
18
+ __exportStar(require("./entity-communications"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0BAA0B;AAC1B,0DAAwC"}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@memberjunction/entity-communications-server",
3
+ "version": "1.5.3",
4
+ "description": "MemberJunction: Library that connects the MJ entities framework to the communication framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "start": "ts-node-dev src/index.ts",
12
+ "build": "tsc",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "author": "MemberJunction.com",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "ts-node-dev": "^2.0.0",
19
+ "typescript": "^5.4.5"
20
+ },
21
+ "dependencies": {
22
+ "@memberjunction/global": "1.5.3",
23
+ "@memberjunction/core": "1.5.3",
24
+ "@memberjunction/core-entities": "1.5.3",
25
+ "@memberjunction/communication-engine": "1.5.3",
26
+ "@memberjunction/entity-communications-base": "1.5.3"
27
+ }
28
+ }