dbm-graph-api 1.1.36 → 1.1.38
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.
|
|
3
|
+
"version": "1.1.38",
|
|
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.741.0",
|
|
15
15
|
"@aws-sdk/s3-request-presigner": "^3.741.0",
|
|
16
|
-
"dbm": "^1.2.
|
|
16
|
+
"dbm": "^1.2.7",
|
|
17
17
|
"mime": "^4.0.6",
|
|
18
18
|
"sharp": "^0.33.5",
|
|
19
19
|
"ws": "^8.18.0"
|
|
@@ -123,12 +123,21 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
123
123
|
|
|
124
124
|
let dataFunctionItem = Dbm.getInstance().repository.getItemIfExists("graphApi/data/" + data['functionName']);
|
|
125
125
|
|
|
126
|
+
|
|
126
127
|
let returnData = null;
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
let logs = [];
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
if(dataFunctionItem) {
|
|
132
|
+
returnData = await dataFunctionItem.controller.getData(data['data'], encodeSession);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch(theError) {
|
|
136
|
+
logs.push(theError.message);
|
|
137
|
+
console.error(theError);
|
|
129
138
|
}
|
|
130
139
|
|
|
131
|
-
this._sendData({"type": "data/response", "data": returnData, "requestId": data["requestId"]});
|
|
140
|
+
this._sendData({"type": "data/response", "data": returnData, "requestId": data["requestId"], "logs": logs});
|
|
132
141
|
}
|
|
133
142
|
break;
|
|
134
143
|
case "action":
|
|
@@ -290,6 +299,12 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
290
299
|
this._sendData({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]});
|
|
291
300
|
}
|
|
292
301
|
break;
|
|
302
|
+
case "user/signOut":
|
|
303
|
+
{
|
|
304
|
+
this.item.setValue("user", null);
|
|
305
|
+
this._sendData({"type": "currentUser/response", "id": 0, "requestId": data["requestId"]});
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
293
308
|
case "heartbeat":
|
|
294
309
|
{
|
|
295
310
|
this._sendData({"type": "heartbeat/response"});
|
|
@@ -332,6 +347,8 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
332
347
|
this.item.api.controller.connectionClosed(this);
|
|
333
348
|
this.item.setValue("api", null);
|
|
334
349
|
this.item.setValue("controller", null);
|
|
350
|
+
|
|
351
|
+
this.item.setValue("user", null);
|
|
335
352
|
}
|
|
336
353
|
|
|
337
354
|
addListeners() {
|
|
@@ -368,38 +368,74 @@ export const setupEndpoints = function(aServer) {
|
|
|
368
368
|
return { success: false, error: "incorrect", message: "Incorrect details"};
|
|
369
369
|
});
|
|
370
370
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
let
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
let isValidSession = await user.verifySession(value);
|
|
382
|
-
if(isValidSession) {
|
|
383
|
-
return {success: true, data: {id: userId}};
|
|
371
|
+
let getPublicSessionIdFomCookie = function(aCookies) {
|
|
372
|
+
if(aCookies) {
|
|
373
|
+
let cookies = aCookies.split(";");
|
|
374
|
+
let currentArray = cookies;
|
|
375
|
+
let currentArrayLength = currentArray.length;
|
|
376
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
377
|
+
let [key, value] = currentArray[i].split("=");
|
|
378
|
+
if(key === "dbm_session" || key === " dbm_session") {
|
|
379
|
+
return value;
|
|
384
380
|
}
|
|
385
381
|
}
|
|
386
382
|
}
|
|
383
|
+
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let getUserFromPublicSessionId = async function(aPublicSessionId) {
|
|
388
|
+
if(aPublicSessionId) {
|
|
389
|
+
let userId = 1*aPublicSessionId.split(":")[1];
|
|
390
|
+
let user = Dbm.getRepositoryItem("graphDatabase").controller.getUser(userId);
|
|
391
|
+
|
|
392
|
+
let isValidSession = await user.verifySession(aPublicSessionId);
|
|
393
|
+
if(isValidSession) {
|
|
394
|
+
return user;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
let getUserFromCookie = async function(aCookies) {
|
|
402
|
+
let publicSessionId = getPublicSessionIdFomCookie(aCookies);
|
|
403
|
+
return await getUserFromPublicSessionId(publicSessionId);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
aServer.get('/api/user/me', async function handler (aRequest, aReply) {
|
|
407
|
+
let user = await getUserFromCookie(aRequest.headers.cookie);
|
|
408
|
+
if(user) {
|
|
409
|
+
return {success: true, data: {id: user.id}};
|
|
410
|
+
}
|
|
387
411
|
|
|
388
412
|
return {success: false, data: null};
|
|
389
413
|
});
|
|
390
414
|
|
|
391
415
|
aServer.post('/api/user/logout', async function handler (aRequest, aReply) {
|
|
392
|
-
console.log(aRequest.body);
|
|
393
416
|
|
|
394
|
-
|
|
395
|
-
|
|
417
|
+
let publicSessionId = getPublicSessionIdFomCookie(aRequest.headers.cookie);
|
|
418
|
+
let user = await getUserFromPublicSessionId(publicSessionId);
|
|
419
|
+
|
|
420
|
+
if(user) {
|
|
421
|
+
let sessionId = 1*publicSessionId.split(":")[0];
|
|
422
|
+
await user.deleteSession(sessionId);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
aReply.header("Set-Cookie", "dbm_session=; Path=/; Max-Age=0; HttpOnly;");
|
|
426
|
+
return {success: true, data: null};
|
|
396
427
|
});
|
|
397
428
|
|
|
398
429
|
aServer.post('/api/user/renewSession', async function handler (aRequest, aReply) {
|
|
399
|
-
|
|
430
|
+
let user = await getUserFromCookie(aRequest.headers.cookie);
|
|
431
|
+
if(user) {
|
|
432
|
+
//METODO: update session
|
|
433
|
+
//METODO: update cookie
|
|
434
|
+
|
|
435
|
+
//METODO: return success
|
|
436
|
+
}
|
|
400
437
|
|
|
401
|
-
|
|
402
|
-
//METODO: clear cookie
|
|
438
|
+
return {success: false, data: null};
|
|
403
439
|
});
|
|
404
440
|
|
|
405
441
|
aServer.get('/api/url', async function handler (aRequest, aReply) {
|