dbm 1.4.2 → 1.4.4
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 +2 -1
- package/flow/controllers/transform/PartOfObject.js +1 -1
- package/node/communication/EmailMessage.js +78 -0
- package/node/communication/PostmarkApiClient.js +59 -0
- package/node/communication/index.js +45 -0
- package/node/index.js +6 -0
- package/package.json +1 -1
- package/react/admin/objects/itemeditors/DraggableHierarchyDisplay.js +22 -1
- package/react/admin/objects/itemeditors/HierarchyOrderedRelationsList.js +53 -5
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";
|
|
@@ -25,7 +25,7 @@ export default class PartOfObject extends Dbm.core.BaseObject {
|
|
|
25
25
|
|
|
26
26
|
if(stringValue !== this._lastUpdatedValue) {
|
|
27
27
|
this._lastUpdatedValue = stringValue;
|
|
28
|
-
let newValue = JSON.parse(stringValue);
|
|
28
|
+
let newValue = stringValue ? JSON.parse(stringValue) : null;
|
|
29
29
|
this.item.value = newValue;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -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
package/package.json
CHANGED
|
@@ -6,6 +6,15 @@ export default class DraggableHierarchyDisplay extends Dbm.react.BaseObject {
|
|
|
6
6
|
super._construct();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
_remove() {
|
|
10
|
+
console.log("_remove");
|
|
11
|
+
let hierarchyItem = this.context.hierarchyItem;
|
|
12
|
+
|
|
13
|
+
console.log(hierarchyItem);
|
|
14
|
+
|
|
15
|
+
this.context.hierarchyController.removeHierarchyItem(hierarchyItem);
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
_renderMainElement() {
|
|
10
19
|
|
|
11
20
|
let children = this.getPropValue("children");
|
|
@@ -20,7 +29,19 @@ export default class DraggableHierarchyDisplay extends Dbm.react.BaseObject {
|
|
|
20
29
|
),
|
|
21
30
|
React.createElement("div", {className: "flex-row-item flex-resize"},
|
|
22
31
|
children
|
|
23
|
-
)
|
|
32
|
+
),
|
|
33
|
+
React.createElement("div", {className: "flex-row-item flex-no-resize"},
|
|
34
|
+
React.createElement("div", {className: "spacing small"}),
|
|
35
|
+
React.createElement(Dbm.react.interaction.ConfirmButton, {"command": Dbm.commands.callFunction(this._remove.bind(this))},
|
|
36
|
+
React.createElement(Dbm.react.image.Image, {"src": "/assets/img/icons/delete.svg", "className": "background-contain text-row-icon action-icon-color cursor-pointer"}),
|
|
37
|
+
React.createElement("div", {"data-slot": "confirm", className: "absolute-container cursor-pointer", title: "Click to remove"},
|
|
38
|
+
React.createElement(Dbm.react.image.Image, {"src": "/assets/img/icons/delete.svg", "className": "background-contain text-row-icon hover-icon remove-action-icon-color cursor-pointer"}),
|
|
39
|
+
React.createElement("div", {className:"centered-tip-text no-pointer-events"},
|
|
40
|
+
"Remove?"
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
),
|
|
24
45
|
)
|
|
25
46
|
|
|
26
47
|
)
|
|
@@ -46,6 +46,7 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
46
46
|
_removeMissingPartsOfHierarchy(aHierarchy, aMustBeInArray) {
|
|
47
47
|
//console.log("_removeMissingPartsOfHierarchy");
|
|
48
48
|
//console.log(aHierarchy, aMustBeInArray);
|
|
49
|
+
|
|
49
50
|
let currentArray = aHierarchy;
|
|
50
51
|
let currentArrayLength = currentArray.length;
|
|
51
52
|
|
|
@@ -54,6 +55,11 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
54
55
|
if(aMustBeInArray.indexOf(currentItem.id) !== -1) {
|
|
55
56
|
this._removeMissingPartsOfHierarchy(currentItem.children, aMustBeInArray);
|
|
56
57
|
}
|
|
58
|
+
else {
|
|
59
|
+
currentArray.splice(i, 1);
|
|
60
|
+
i--;
|
|
61
|
+
currentArrayLength--;
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
|
|
@@ -68,6 +74,17 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
|
|
77
|
+
_getAllLinkedIdsFromHierarchy(aItems, aReturnArray) {
|
|
78
|
+
let currentArray = aItems;
|
|
79
|
+
let currentArrayLength = currentArray.length;
|
|
80
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
81
|
+
let currentItem = currentArray[i];
|
|
82
|
+
|
|
83
|
+
aReturnArray.push(currentItem.linkedItem.id);
|
|
84
|
+
this._getAllLinkedIdsFromHierarchy(currentItem.children, aReturnArray);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
71
88
|
_getFullHierarchy() {
|
|
72
89
|
let relations = this._relationsEditor.value;
|
|
73
90
|
let hierarchyValue = this._orderEditor.value;
|
|
@@ -257,6 +274,28 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
257
274
|
this._orderEditor.value = hierarchyValue;
|
|
258
275
|
}
|
|
259
276
|
|
|
277
|
+
removeHierarchyItem(aHierarchyItem) {
|
|
278
|
+
console.log("removeHierarchyItem");
|
|
279
|
+
let position = this._findPosition(aHierarchyItem, this.item.hierarchy.children);
|
|
280
|
+
|
|
281
|
+
let idsToRemove = [];
|
|
282
|
+
this._getAllLinkedIdsFromHierarchy([aHierarchyItem], idsToRemove);
|
|
283
|
+
|
|
284
|
+
console.log(position, idsToRemove);
|
|
285
|
+
|
|
286
|
+
let editor = this._getEditor();
|
|
287
|
+
let newValues = [].concat(editor.value);
|
|
288
|
+
|
|
289
|
+
console.log(JSON.stringify(newValues), idsToRemove);
|
|
290
|
+
newValues = Dbm.utils.ArrayFunctions.removeValues(newValues, idsToRemove);
|
|
291
|
+
console.log(JSON.stringify(newValues), idsToRemove);
|
|
292
|
+
|
|
293
|
+
editor.value = newValues;
|
|
294
|
+
|
|
295
|
+
let hierarchyValue = this._getFullHierarchy();
|
|
296
|
+
this._orderEditor.value = hierarchyValue;
|
|
297
|
+
}
|
|
298
|
+
|
|
260
299
|
_create() {
|
|
261
300
|
console.log("_create");
|
|
262
301
|
let objectType = this.getPropValue("objectType");
|
|
@@ -270,10 +309,7 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
270
309
|
Dbm.flow.addUpdateCommand(request.properties.status, Dbm.commands.callFunction(this._created.bind(this), [Dbm.core.source.staticObject(request, "item")]));
|
|
271
310
|
}
|
|
272
311
|
|
|
273
|
-
|
|
274
|
-
console.log("_created");
|
|
275
|
-
console.log(aItem);
|
|
276
|
-
|
|
312
|
+
_getEditor() {
|
|
277
313
|
let itemEditor = this.context.itemEditor;
|
|
278
314
|
|
|
279
315
|
let direction = this.getPropValue("direction");
|
|
@@ -291,9 +327,21 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
291
327
|
console.error("Unknown direction", direction, this);
|
|
292
328
|
}
|
|
293
329
|
|
|
330
|
+
return editor;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
_created(aItem) {
|
|
334
|
+
console.log("_created");
|
|
335
|
+
console.log(aItem);
|
|
336
|
+
|
|
337
|
+
let editor = this._getEditor();
|
|
338
|
+
|
|
294
339
|
let newValues = [].concat(editor.value);
|
|
295
340
|
newValues.push(aItem.id);
|
|
296
341
|
editor.value = newValues;
|
|
342
|
+
|
|
343
|
+
let hierarchyValue = this._getFullHierarchy();
|
|
344
|
+
this._orderEditor.value = hierarchyValue;
|
|
297
345
|
}
|
|
298
346
|
|
|
299
347
|
_renderMainElement() {
|
|
@@ -302,7 +350,7 @@ export default class HierarchyOrderedRelationsList extends Dbm.react.BaseObject
|
|
|
302
350
|
let children = this.getPropValue("children");
|
|
303
351
|
|
|
304
352
|
return React.createElement("div", {},
|
|
305
|
-
React.createElement(Dbm.react.context.AddContextVariables, {"values": {"dragController": this}},
|
|
353
|
+
React.createElement(Dbm.react.context.AddContextVariables, {"values": {"dragController": this, "hierarchyController": this}},
|
|
306
354
|
React.createElement(Dbm.react.form.LabelledArea, {label: label}),
|
|
307
355
|
React.createElement("div", {"className": ""},
|
|
308
356
|
React.createElement(Dbm.react.area.List, {items: this.item.hierarchy.properties.children, as: "hierarchyItem"},
|