dbm-graph-api 1.1.51 → 1.1.54

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm-graph-api",
3
- "version": "1.1.51",
3
+ "version": "1.1.54",
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.9",
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",
@@ -20,6 +20,7 @@ export default class ProcessActions extends Dbm.core.BaseObject {
20
20
  await action.changeLinkedType("status/actionStatus", "processing");
21
21
 
22
22
  let actionType = await action.getSingleLinkedType("type/actionType");
23
+ console.log("Action type: " + actionType);
23
24
 
24
25
  let processActionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/processAction/" + actionType);
25
26
 
@@ -39,6 +40,7 @@ export default class ProcessActions extends Dbm.core.BaseObject {
39
40
  returnObject["remaining"] = 0;
40
41
  }
41
42
 
43
+ console.log(returnObject);
42
44
  return returnObject;
43
45
  }
44
46
  }
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export {default as SendEmailVerification} from "./SendEmailVerification.js";
2
+ export {default as Verify} from "./Verify.js";
@@ -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
 
@@ -3,6 +3,8 @@ import Dbm from "dbm";
3
3
  export default class SendEmail extends Dbm.core.BaseObject {
4
4
  _construct() {
5
5
  super._construct();
6
+
7
+ this.item.requireProperty("client", null);
6
8
  }
7
9
 
8
10
  async process(aAction) {
@@ -50,6 +50,7 @@ export default class InternalTaskRunner extends Dbm.core.BaseObject {
50
50
 
51
51
  if(this._isRunning) {
52
52
  if(runDirect) {
53
+ console.log("Run direct");
53
54
  this._intervalId = setTimeout(this._runNextTaskBound, 1);
54
55
  }
55
56
  else {