dbm-graph-api 1.1.37 → 1.1.39
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/WebSocketConnection.js +8 -0
- package/src/dbm-graph-api/index.js +65 -19
- package/src/dbm-graph-api/range/encode/Menu.js +27 -0
- package/src/dbm-graph-api/range/encode/MenuItem.js +21 -0
- package/src/dbm-graph-api/range/encode/MenuLocation.js +23 -0
- package/src/dbm-graph-api/range/encode/index.js +3 -0
- package/src/dbm-graph-api/range/select/WithIdentifier.js +17 -0
- package/src/dbm-graph-api/range/select/index.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.39",
|
|
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.8",
|
|
17
17
|
"mime": "^4.0.6",
|
|
18
18
|
"sharp": "^0.33.5",
|
|
19
19
|
"ws": "^8.18.0"
|
|
@@ -299,6 +299,12 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
299
299
|
this._sendData({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]});
|
|
300
300
|
}
|
|
301
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;
|
|
302
308
|
case "heartbeat":
|
|
303
309
|
{
|
|
304
310
|
this._sendData({"type": "heartbeat/response"});
|
|
@@ -341,6 +347,8 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
341
347
|
this.item.api.controller.connectionClosed(this);
|
|
342
348
|
this.item.setValue("api", null);
|
|
343
349
|
this.item.setValue("controller", null);
|
|
350
|
+
|
|
351
|
+
this.item.setValue("user", null);
|
|
344
352
|
}
|
|
345
353
|
|
|
346
354
|
addListeners() {
|
|
@@ -57,6 +57,12 @@ let fullSelectSetup = function() {
|
|
|
57
57
|
let currentSelect = new DbmGraphApi.range.select.GlobalObjectRelationQuery();
|
|
58
58
|
currentSelect.item.register(selectPrefix + name);
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
let name = "withIdentifier";
|
|
63
|
+
let currentSelect = new DbmGraphApi.range.select.WithIdentifier();
|
|
64
|
+
currentSelect.item.register(selectPrefix + name);
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
|
|
@@ -226,6 +232,10 @@ let fullEncodeSetup = function() {
|
|
|
226
232
|
registerEncoding("language", DbmGraphApi.range.encode.SingleRelation.create("language", "in:for:language", "type"));
|
|
227
233
|
registerEncodingClass(DbmGraphApi.range.encode.TranslatedName);
|
|
228
234
|
registerEncoding("translationGroup", new DbmGraphApi.range.encode.TranslationGroup());
|
|
235
|
+
|
|
236
|
+
registerEncoding("menuLocation", new DbmGraphApi.range.encode.MenuLocation());
|
|
237
|
+
registerEncoding("menu", new DbmGraphApi.range.encode.Menu());
|
|
238
|
+
registerEncoding("menuItem", new DbmGraphApi.range.encode.MenuItem());
|
|
229
239
|
}
|
|
230
240
|
|
|
231
241
|
export {fullEncodeSetup};
|
|
@@ -368,38 +378,74 @@ export const setupEndpoints = function(aServer) {
|
|
|
368
378
|
return { success: false, error: "incorrect", message: "Incorrect details"};
|
|
369
379
|
});
|
|
370
380
|
|
|
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}};
|
|
381
|
+
let getPublicSessionIdFomCookie = function(aCookies) {
|
|
382
|
+
if(aCookies) {
|
|
383
|
+
let cookies = aCookies.split(";");
|
|
384
|
+
let currentArray = cookies;
|
|
385
|
+
let currentArrayLength = currentArray.length;
|
|
386
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
387
|
+
let [key, value] = currentArray[i].split("=");
|
|
388
|
+
if(key === "dbm_session" || key === " dbm_session") {
|
|
389
|
+
return value;
|
|
384
390
|
}
|
|
385
391
|
}
|
|
386
392
|
}
|
|
393
|
+
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
let getUserFromPublicSessionId = async function(aPublicSessionId) {
|
|
398
|
+
if(aPublicSessionId) {
|
|
399
|
+
let userId = 1*aPublicSessionId.split(":")[1];
|
|
400
|
+
let user = Dbm.getRepositoryItem("graphDatabase").controller.getUser(userId);
|
|
401
|
+
|
|
402
|
+
let isValidSession = await user.verifySession(aPublicSessionId);
|
|
403
|
+
if(isValidSession) {
|
|
404
|
+
return user;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
let getUserFromCookie = async function(aCookies) {
|
|
412
|
+
let publicSessionId = getPublicSessionIdFomCookie(aCookies);
|
|
413
|
+
return await getUserFromPublicSessionId(publicSessionId);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
aServer.get('/api/user/me', async function handler (aRequest, aReply) {
|
|
417
|
+
let user = await getUserFromCookie(aRequest.headers.cookie);
|
|
418
|
+
if(user) {
|
|
419
|
+
return {success: true, data: {id: user.id}};
|
|
420
|
+
}
|
|
387
421
|
|
|
388
422
|
return {success: false, data: null};
|
|
389
423
|
});
|
|
390
424
|
|
|
391
425
|
aServer.post('/api/user/logout', async function handler (aRequest, aReply) {
|
|
392
|
-
console.log(aRequest.body);
|
|
393
426
|
|
|
394
|
-
|
|
395
|
-
|
|
427
|
+
let publicSessionId = getPublicSessionIdFomCookie(aRequest.headers.cookie);
|
|
428
|
+
let user = await getUserFromPublicSessionId(publicSessionId);
|
|
429
|
+
|
|
430
|
+
if(user) {
|
|
431
|
+
let sessionId = 1*publicSessionId.split(":")[0];
|
|
432
|
+
await user.deleteSession(sessionId);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
aReply.header("Set-Cookie", "dbm_session=; Path=/; Max-Age=0; HttpOnly;");
|
|
436
|
+
return {success: true, data: null};
|
|
396
437
|
});
|
|
397
438
|
|
|
398
439
|
aServer.post('/api/user/renewSession', async function handler (aRequest, aReply) {
|
|
399
|
-
|
|
440
|
+
let user = await getUserFromCookie(aRequest.headers.cookie);
|
|
441
|
+
if(user) {
|
|
442
|
+
//METODO: update session
|
|
443
|
+
//METODO: update cookie
|
|
444
|
+
|
|
445
|
+
//METODO: return success
|
|
446
|
+
}
|
|
400
447
|
|
|
401
|
-
|
|
402
|
-
//METODO: clear cookie
|
|
448
|
+
return {success: false, data: null};
|
|
403
449
|
});
|
|
404
450
|
|
|
405
451
|
aServer.get('/api/url', async function handler (aRequest, aReply) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class Menu extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
14
|
+
|
|
15
|
+
await aEncodingSession.encodeSingle(aId, "language");
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
let relatedItems = await object.objectRelationQuery("in:in:menuItem");
|
|
19
|
+
returnObject["menuItems"] = await aEncodingSession.encodeObjects(relatedItems, "menuItem");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let fields = await object.getFields();
|
|
23
|
+
returnObject["order"] = fields["order"] ? fields["order"] : null;
|
|
24
|
+
|
|
25
|
+
return returnObject;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class MenuItem extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
14
|
+
|
|
15
|
+
let fields = await object.getFields();
|
|
16
|
+
returnObject["label"] = fields["label"] ? fields["label"] : null;
|
|
17
|
+
returnObject["link"] = fields["link"] ? fields["link"] : null;
|
|
18
|
+
|
|
19
|
+
return returnObject;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EncodeBaseObject from "./EncodeBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class MenuLocation extends EncodeBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getEncodedData(aId, aEncodingSession) {
|
|
10
|
+
|
|
11
|
+
let returnObject = {};
|
|
12
|
+
|
|
13
|
+
let object = Dbm.getInstance().repository.getItem("graphDatabase").controller.getObject(aId);
|
|
14
|
+
|
|
15
|
+
await aEncodingSession.encodeSingle(aId, "identifier");
|
|
16
|
+
|
|
17
|
+
let relatedItem = await object.singleObjectRelationQuery("in:at:menu");
|
|
18
|
+
|
|
19
|
+
returnObject["menu"] = await aEncodingSession.encodeObjectOrNull(relatedItem, "menu");
|
|
20
|
+
|
|
21
|
+
return returnObject;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -26,5 +26,8 @@ export {default as SingleRelation} from "./SingleRelation.js";
|
|
|
26
26
|
export {default as TranslatedTitle} from "./TranslatedTitle.js";
|
|
27
27
|
export {default as TranslatedName} from "./TranslatedName.js";
|
|
28
28
|
export {default as TranslationGroup} from "./TranslationGroup.js";
|
|
29
|
+
export {default as MenuLocation} from "./MenuLocation.js";
|
|
30
|
+
export {default as Menu} from "./Menu.js";
|
|
31
|
+
export {default as MenuItem} from "./MenuItem.js";
|
|
29
32
|
|
|
30
33
|
export * as admin from "./admin/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
import SelectBaseObject from "./SelectBaseObject.js";
|
|
4
|
+
|
|
5
|
+
export default class WithIdentifier extends SelectBaseObject {
|
|
6
|
+
_construct() {
|
|
7
|
+
super._construct();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async select(aQuery, aData, aRequest) {
|
|
11
|
+
aQuery.withIdentifier(aData["identifier"]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async filter(aIds, aData, aRequest) {
|
|
15
|
+
return aIds;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -4,4 +4,5 @@ export {default as ByObjectType} from "./ByObjectType.js";
|
|
|
4
4
|
export {default as IncludePrivate} from "./IncludePrivate.js";
|
|
5
5
|
export {default as IncludeDraft} from "./IncludeDraft.js";
|
|
6
6
|
export {default as ObjectRelationQuery} from "./ObjectRelationQuery.js";
|
|
7
|
-
export {default as GlobalObjectRelationQuery} from "./GlobalObjectRelationQuery.js";
|
|
7
|
+
export {default as GlobalObjectRelationQuery} from "./GlobalObjectRelationQuery.js";
|
|
8
|
+
export {default as WithIdentifier} from "./WithIdentifier.js";
|