dbm-graph-api 1.1.50 → 1.1.52
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/package.json +2 -2
- package/src/dbm-graph-api/UrlRequest.js +4 -4
- package/src/dbm-graph-api/action/index.js +2 -1
- package/src/dbm-graph-api/action/verification/SendEmailVerification.js +66 -0
- package/src/dbm-graph-api/action/verification/Verify.js +66 -0
- package/src/dbm-graph-api/action/verification/index.js +2 -0
- package/src/dbm-graph-api/index.js +5 -2
- package/src/dbm-graph-api/processAction/communication/SendEmail.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.52",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@aws-sdk/client-s3": "^3.984.0",
|
|
15
15
|
"@aws-sdk/s3-request-presigner": "^3.984.0",
|
|
16
|
-
"dbm": "^1.4.
|
|
16
|
+
"dbm": "^1.4.10",
|
|
17
17
|
"html-to-text": "^9.0.5",
|
|
18
18
|
"mime": "^4.1.0",
|
|
19
19
|
"node-cron": "^4.2.1",
|
|
@@ -202,15 +202,15 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
202
202
|
|
|
203
203
|
let incomingWebhook = await database.createObject("private", ["incomingWebhook"]);
|
|
204
204
|
await incomingWebhook.updateField("data", data);
|
|
205
|
-
await incomingWebhook.
|
|
205
|
+
await incomingWebhook.incomingRelations.add(webhookType, "for");
|
|
206
206
|
|
|
207
207
|
let actionType = await database.getTypeObject("type/actionType", "incomingWebhook/" + type);
|
|
208
208
|
let actionStatus = await database.getTypeObject("status/actionStatus", "readyToProcess");
|
|
209
209
|
|
|
210
210
|
let action = await database.createObject("private", ["action"]);
|
|
211
|
-
await action.
|
|
212
|
-
await action.
|
|
213
|
-
await action.
|
|
211
|
+
await action.incomingRelations.add(actionType, "for");
|
|
212
|
+
await action.outgoingRelations.add(incomingWebhook, "from");
|
|
213
|
+
await action.incomingRelations.add(actionStatus, "for");
|
|
214
214
|
|
|
215
215
|
returnObject["id"] = incomingWebhook.id;
|
|
216
216
|
returnObject["action"] = action.id;
|
|
@@ -4,4 +4,5 @@ export {default as SubmitForm} from "./SubmitForm.js";
|
|
|
4
4
|
|
|
5
5
|
export * as cron from "./cron/index.js";
|
|
6
6
|
export * as admin from "./admin/index.js";
|
|
7
|
-
export * as development from "./development/index.js";
|
|
7
|
+
export * as development from "./development/index.js";
|
|
8
|
+
export * as verification from "./verification/index.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
|
|
4
|
+
export default class SendEmailVerification extends Dbm.core.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.item.requireProperty("dataSalt", "7m,/7!lH6U~2lL[Z0RMfE`y.KKa+twH}[A7*|6=f|mu?sB[efsGJD{i~GU$<m8Q|");
|
|
9
|
+
this.item.requireProperty("codeSalt", "rUMP^jiM%llGT+EnV{@?l[CmPdv.Oq-Z>ZgX;DV85NAp o:B]QO`n]Kyl=vhE~hC");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_timestampToMysqlDate(aTime) {
|
|
13
|
+
let date = new Date(aTime);
|
|
14
|
+
|
|
15
|
+
return date.toISOString().split("T").join(" ").split(".")[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async performAction(aData, aEncodeSession) {
|
|
19
|
+
let returnObject = {};
|
|
20
|
+
|
|
21
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
22
|
+
|
|
23
|
+
let verification = await database.createObject("private", ["verification"]);
|
|
24
|
+
verification.addObjectType("verification/email");
|
|
25
|
+
|
|
26
|
+
let email = aData["email"];
|
|
27
|
+
|
|
28
|
+
let hash = crypto.createHash('sha256');
|
|
29
|
+
hash.update(email + verification.id + this.item.dataSalt);
|
|
30
|
+
let hashedData = hash.digest('hex');
|
|
31
|
+
await verification.updateField("data", hashedData);
|
|
32
|
+
|
|
33
|
+
let now = (new Date()).valueOf();
|
|
34
|
+
let expireTime = now + 15 * 60 * 1000;
|
|
35
|
+
let unverifiedStatus = await database.getTypeObject("status/verifcationStatus", "unverified");
|
|
36
|
+
await verification.incomingRelations.add(unverifiedStatus, "for", this._timestampToMysqlDate(now), this._timestampToMysqlDate(expireTime));
|
|
37
|
+
|
|
38
|
+
let expiredStatus = await database.getTypeObject("status/verifcationStatus", "expired");
|
|
39
|
+
await verification.incomingRelations.add(expiredStatus, "for", this._timestampToMysqlDate(expireTime));
|
|
40
|
+
|
|
41
|
+
let code = crypto.randomInt(100000, 1000000);
|
|
42
|
+
let codeHash = crypto.createHash('sha256');
|
|
43
|
+
codeHash.update(code + "" + verification.id + this.item.codeSalt);
|
|
44
|
+
let hashedCode = codeHash.digest('hex');
|
|
45
|
+
await verification.updateField("code", hashedCode);
|
|
46
|
+
|
|
47
|
+
let key = crypto.randomUUID();
|
|
48
|
+
await verification.setIdentifier(key);
|
|
49
|
+
|
|
50
|
+
returnObject["email"] = email;
|
|
51
|
+
returnObject["key"] = key;
|
|
52
|
+
|
|
53
|
+
let codeKeywords = {
|
|
54
|
+
"code": code
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let keywordReplace = new Dbm.utils.KeywordReplace();
|
|
58
|
+
keywordReplace.addKeywordProvider("verification", codeKeywords);
|
|
59
|
+
|
|
60
|
+
let language = aData["language"] ? aData["language"] : "en";
|
|
61
|
+
let communication = await Dbm.node.communication.sendEmailTemplate("emailVerification", email, keywordReplace, language);
|
|
62
|
+
await verification.incomingRelations.add(communication, "for");
|
|
63
|
+
|
|
64
|
+
return returnObject;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
|
|
4
|
+
export default class Verify extends Dbm.core.BaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.item.requireProperty("codeSalt", "rUMP^jiM%llGT+EnV{@?l[CmPdv.Oq-Z>ZgX;DV85NAp o:B]QO`n]Kyl=vhE~hC");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_timestampToMysqlDate(aTime) {
|
|
12
|
+
let date = new Date(aTime);
|
|
13
|
+
|
|
14
|
+
return date.toISOString().split("T").join(" ").split(".")[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async performAction(aData, aEncodeSession) {
|
|
18
|
+
let returnObject = {};
|
|
19
|
+
|
|
20
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
21
|
+
|
|
22
|
+
let key = aData["key"];
|
|
23
|
+
|
|
24
|
+
returnObject["result"] = "none";
|
|
25
|
+
|
|
26
|
+
let verification = await database.getIdentifiableObjectIfExists("verification", key);
|
|
27
|
+
if(verification) {
|
|
28
|
+
|
|
29
|
+
let statusObject = await verification.singleObjectRelationQuery("in:for:status/verifcationStatus");
|
|
30
|
+
let status = await statusObject.getIdentifier();
|
|
31
|
+
|
|
32
|
+
if(status === "unverified" || status === "verified") {
|
|
33
|
+
let code = aData["code"];
|
|
34
|
+
|
|
35
|
+
let fields = await verification.getFields();
|
|
36
|
+
|
|
37
|
+
let codeHash = crypto.createHash('sha256');
|
|
38
|
+
codeHash.update(code + "" + verification.id + this.item.codeSalt);
|
|
39
|
+
let hashedCode = codeHash.digest('hex');
|
|
40
|
+
|
|
41
|
+
if(fields["code"] === hashedCode) {
|
|
42
|
+
if(status === "unverified") {
|
|
43
|
+
let now = (new Date()).valueOf();
|
|
44
|
+
let expireTime = now + 30 * 60 * 1000;
|
|
45
|
+
let verifiedStatus = await database.getTypeObject("status/verifcationStatus", "verified");
|
|
46
|
+
await verification.incomingRelations.replace(verifiedStatus, "for", "status/verifcationStatus", this._timestampToMysqlDate(expireTime));
|
|
47
|
+
|
|
48
|
+
let expiredStatus = await database.getTypeObject("status/verifcationStatus", "expired");
|
|
49
|
+
await verification.incomingRelations.add(expiredStatus, "for", this._timestampToMysqlDate(expireTime));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
returnObject["result"] = "verified";
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
returnObject["result"] = "incorrectCode";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
returnObject["result"] = "invalidStatus";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return returnObject;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -236,6 +236,9 @@ export const fullActionSetup = function() {
|
|
|
236
236
|
registerActionFunction("admin/setup/setupWebsite", new DbmGraphApi.action.admin.setup.SetupWebsite());
|
|
237
237
|
registerActionFunction("admin/setup/setupOrganization", new DbmGraphApi.action.admin.setup.SetupOrganization());
|
|
238
238
|
|
|
239
|
+
registerActionFunction("verification/sendEmailVerification", new DbmGraphApi.action.verification.SendEmailVerification());
|
|
240
|
+
registerActionFunction("verification/verify", new DbmGraphApi.action.verification.Verify());
|
|
241
|
+
|
|
239
242
|
registerActionFunction("development/restartServer", new DbmGraphApi.action.development.RestartServer());
|
|
240
243
|
registerActionFunction("development/restartDatabaseConnection", new DbmGraphApi.action.development.RestartDatabaseConnection());
|
|
241
244
|
|
|
@@ -558,7 +561,7 @@ export const setupEndpoints = function(aServer) {
|
|
|
558
561
|
request.setup(aRequest, aReply);
|
|
559
562
|
|
|
560
563
|
let currentUrl = url.parse(aRequest.url);
|
|
561
|
-
let webhookType = currentUrl.pathname.substring("/api/
|
|
564
|
+
let webhookType = currentUrl.pathname.substring("/api/webhook/".length);
|
|
562
565
|
|
|
563
566
|
await request.incomingWebhook(webhookType, params);
|
|
564
567
|
|
|
@@ -571,7 +574,7 @@ export const setupEndpoints = function(aServer) {
|
|
|
571
574
|
request.setup(aRequest, aReply);
|
|
572
575
|
|
|
573
576
|
let currentUrl = url.parse(aRequest.url);
|
|
574
|
-
let webhookType = currentUrl.pathname.substring("/api/
|
|
577
|
+
let webhookType = currentUrl.pathname.substring("/api/webhook/".length);
|
|
575
578
|
|
|
576
579
|
await request.incomingWebhook(webhookType, params);
|
|
577
580
|
|