dbm 1.4.1 → 1.4.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.
package/dbm.js CHANGED
@@ -105,4 +105,5 @@ export * as updater from "./updater/index.js";
105
105
  export * as startup from "./startup/index.js";
106
106
  export * as site from "./site/index.js";
107
107
  export * as tracking from "./tracking/index.js";
108
- export * as ecommerce from "./ecommerce/index.js";
108
+ export * as ecommerce from "./ecommerce/index.js";
109
+ export * as node from "./node/index.js";
@@ -0,0 +1,78 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class EmailMessage extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.item.requireProperty("from", null);
9
+ this.item.requireProperty("to", null);
10
+ this.item.requireProperty("subject", null);
11
+ this.item.requireProperty("textContent", null);
12
+ this.item.requireProperty("htmlContent", null);
13
+ this.item.requireProperty("additionalData", null);
14
+ }
15
+
16
+ setClient(aClientItem) {
17
+ this.item.setValue("client", aClientItem);
18
+
19
+ return this;
20
+ }
21
+
22
+ setFrom(aEmail) {
23
+ this.item.from = aEmail;
24
+
25
+ return this;
26
+ }
27
+
28
+ setTo(aEmail) {
29
+ this.item.to = aEmail;
30
+
31
+ return this;
32
+ }
33
+
34
+ setSubject(aText) {
35
+ this.item.subject = aText;
36
+
37
+ return this;
38
+ }
39
+
40
+ setHtmlContent(aText) {
41
+ this.item.htmlContent = aText;
42
+
43
+ return this;
44
+ }
45
+
46
+ setTextContent(aText) {
47
+ this.item.textContent = aText;
48
+
49
+ return this;
50
+ }
51
+
52
+ async send() {
53
+
54
+ let serviceName = this.item.client.serviceName;
55
+
56
+ let objectTypes = ["transactional-communication", "transactional-communication/email", "integration-response"];
57
+ if(serviceName) {
58
+ objectTypes.push("integration-response/" + serviceName);
59
+ }
60
+
61
+ let message = await Dbm.node.getDatabase().createObject("private", objectTypes);
62
+ await message.updateField("to", this.item.to);
63
+ await message.updateField("subject", this.item.subject);
64
+ await message.updateField("htmlContent", this.item.htmlContent);
65
+ await message.updateField("textContent", this.item.textContent);
66
+
67
+ let sendResponse = await this.item.client.controller.performSendMessage(this.item);
68
+
69
+ await message.updateField("reponse", sendResponse.response);
70
+ await message.updateField("from", sendResponse.from);
71
+
72
+ if(sendResponse.id) {
73
+ await message.setIdentifier(sendResponse.id);
74
+ }
75
+
76
+ return message;
77
+ }
78
+ }
@@ -0,0 +1,59 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class PostmarkApiClient extends Dbm.core.BaseObject {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.item.setValue("serviceName", "postmark");
9
+ this.item.setValue("defaultFrom", "website@webnotification.services");
10
+ this.item.setValue("token", null);
11
+ }
12
+
13
+ createMessage() {
14
+ let newMessage = new Dbm.node.communication.EmailMessage();
15
+ newMessage.setClient(this.item);
16
+
17
+ return newMessage;
18
+ }
19
+
20
+ async performSendMessage(aMessageItem) {
21
+ //console.log("performSendMessage");
22
+
23
+ let from = aMessageItem.from;
24
+ if(!from) {
25
+ from = this.item.defaultFrom;
26
+ }
27
+
28
+ let emailData = {
29
+ From: from,
30
+ To: aMessageItem.to,
31
+ Subject: aMessageItem.subject,
32
+ HtmlBody: aMessageItem.htmlContent,
33
+ TextBody: aMessageItem.textContent,
34
+ };
35
+
36
+ let response = await fetch('https://api.postmarkapp.com/email', {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Accept': 'application/json',
40
+ 'Content-Type': 'application/json',
41
+ 'X-Postmark-Server-Token': this.item.token
42
+ },
43
+ body: JSON.stringify(emailData)
44
+ });
45
+
46
+ let repsonseText = await response.text();
47
+
48
+ let id = null;
49
+ try {
50
+ let responseData = JSON.parse(repsonseText);
51
+ id = responseData["MessageID"];
52
+ }
53
+ catch(theError) {
54
+
55
+ }
56
+
57
+ return {"response": repsonseText, "from": from, "id": id};
58
+ }
59
+ }
@@ -0,0 +1,45 @@
1
+ import Dbm from "../../index.js";
2
+ export {default as PostmarkApiClient} from "./PostmarkApiClient.js";
3
+ export {default as EmailMessage} from "./EmailMessage.js";
4
+
5
+ export const createEmailAction = async function(aTo, aSubject, aHtmlContent, aTextContent, aFrom = null, aAdditionalData = null) {
6
+ let database = Dbm.node.getDatabase();
7
+
8
+ let data = {
9
+ "to": aTo,
10
+ "subject": aSubject,
11
+ "textContent": aTextContent,
12
+ "htmlContent": aHtmlContent,
13
+ "additionalData": aAdditionalData
14
+ };
15
+
16
+ if(aFrom) {
17
+ data["from"] = aFrom;
18
+ }
19
+
20
+ let action = await database.addActionToProcess("sendEmail", null, data);
21
+
22
+ return action;
23
+ }
24
+
25
+ export const sendUnformattedEmail = async function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
26
+ return createEmailAction(aTo, aSubject, null, aBody, aFrom, aAdditionalData);
27
+ }
28
+
29
+ export const sendEmail = async function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
30
+
31
+ let textBody = aBody; //METODO: strip tags
32
+
33
+ return createEmailAction(aTo, aSubject, aBody, textBody, aFrom, aAdditionalData);
34
+ }
35
+
36
+ export const createPostmarkClient = function(aToken, aDefaultFromEmail = null) {
37
+ let client = new Dbm.node.communication.PostmarkApiClient();
38
+
39
+ client.item.token = aToken;
40
+ if(aDefaultFromEmail) {
41
+ client.item.defaultFrom = aDefaultFromEmail;
42
+ }
43
+
44
+ return client;
45
+ }
package/node/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import Dbm from "../index.js";
2
+ export * as communication from "./communication/index.js";
3
+
4
+ export const getDatabase = function() {
5
+ return Dbm.getRepositoryItem("graphDatabase").controller;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,14 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export const convertPropertiesToArray = function(aObject, aPropertyNames) {
4
+
5
+ let returnArray = new Array();
6
+
7
+ let currentArray = aPropertyNames;
8
+ let currentArrayLength = currentArray.length;
9
+ for(let i = 0; i < currentArrayLength; i++) {
10
+ returnArray.push(aObject[currentArray[i]]);
11
+ }
12
+
13
+ return returnArray;
14
+ }
package/utils/index.js CHANGED
@@ -5,6 +5,7 @@ export * as UrlFunctions from "./UrlFunctions.js";
5
5
  export * as CompareFunctions from "./CompareFunctions.js";
6
6
  export * as TranslationFunctions from "./TranslationFunctions.js";
7
7
  export * as LevenshteinDistance from "./LevenshteinDistance.js";
8
+ export * as ObjectFunctions from "./ObjectFunctions.js";
8
9
 
9
10
  export {default as MultidimensionalArrayHolder} from "./MultidimensionalArrayHolder.js";
10
11
  export {default as ArrayOperationResult} from "./ArrayOperationResult.js";