dbm-graph-api 1.1.15 → 1.1.17
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/admin/edit/AddObjectType.js +12 -0
- package/src/dbm-graph-api/admin/edit/RemoveObjectType.js +12 -0
- package/src/dbm-graph-api/admin/edit/ReplaceMultipleIncomingRelations.js +12 -0
- package/src/dbm-graph-api/admin/edit/ReplaceMultipleOutgoingRelations.js +12 -0
- package/src/dbm-graph-api/admin/edit/index.js +29 -0
- package/src/dbm-graph-api/data/HelpSectionSuggestions.js +69 -0
- package/src/dbm-graph-api/data/index.js +1 -0
- package/src/dbm-graph-api/index.js +1 -0
- package/src/dbm-graph-api/range/encode/Relations.js +10 -0
- package/src/dbm-graph-api/schema/JsonLdGenerator.js +66 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbm-graph-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
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.1.
|
|
16
|
+
"dbm": "^1.1.12",
|
|
17
17
|
"mime": "^4.0.6",
|
|
18
18
|
"sharp": "^0.33.5",
|
|
19
19
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddObjectType extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.addObjectType(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class AddObjectType extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.removeObjectType(aData["value"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class ReplaceMultipleIncomingRelations extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.replaceMultipleIncomingRelations(aData["value"], aData["type"], aData["objectType"]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import EditBaseObject from "./EditBaseObject.js";
|
|
3
|
+
|
|
4
|
+
export default class ReplaceMultipleOutgoingRelations extends EditBaseObject {
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async performChange(aObject, aData, aRequest) {
|
|
10
|
+
await aObject.replaceMultipleOutgoingRelations(aData["value"], aData["type"]), aData["objectType"];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -10,6 +10,11 @@ export {default as AddOutgoingRelation} from "./AddOutgoingRelation.js";
|
|
|
10
10
|
export {default as ClearCloudflareCache} from "./ClearCloudflareCache.js";
|
|
11
11
|
export {default as ReplaceIncomingRelation} from "./ReplaceIncomingRelation.js";
|
|
12
12
|
export {default as ReplaceOutgoingRelation} from "./ReplaceOutgoingRelation.js";
|
|
13
|
+
export {default as ReplaceMultipleIncomingRelations} from "./ReplaceMultipleIncomingRelations.js";
|
|
14
|
+
export {default as ReplaceMultipleOutgoingRelations} from "./ReplaceMultipleOutgoingRelations.js";
|
|
15
|
+
export {default as AddObjectType} from "./AddObjectType.js";
|
|
16
|
+
export {default as RemoveObjectType} from "./RemoveObjectType.js";
|
|
17
|
+
|
|
13
18
|
|
|
14
19
|
export const fullSetup = function() {
|
|
15
20
|
let prefix = "graphApi/admin/edit/";
|
|
@@ -61,9 +66,33 @@ export const fullSetup = function() {
|
|
|
61
66
|
currentSelect.item.register(prefix + name);
|
|
62
67
|
}
|
|
63
68
|
|
|
69
|
+
{
|
|
70
|
+
let name = "replaceMultipleIncomingRelations";
|
|
71
|
+
let currentSelect = new DbmGraphApi.admin.edit.ReplaceMultipleIncomingRelations();
|
|
72
|
+
currentSelect.item.register(prefix + name);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
let name = "replaceMultipleOutgoingRelations";
|
|
77
|
+
let currentSelect = new DbmGraphApi.admin.edit.ReplaceMultipleOutgoingRelations();
|
|
78
|
+
currentSelect.item.register(prefix + name);
|
|
79
|
+
}
|
|
80
|
+
|
|
64
81
|
{
|
|
65
82
|
let name = "clearCache";
|
|
66
83
|
let currentSelect = new DbmGraphApi.admin.edit.ClearCloudflareCache();
|
|
67
84
|
currentSelect.item.register(prefix + name);
|
|
68
85
|
}
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
let name = "addObjectType";
|
|
89
|
+
let currentSelect = new DbmGraphApi.admin.edit.AddObjectType();
|
|
90
|
+
currentSelect.item.register(prefix + name);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
{
|
|
94
|
+
let name = "removeObjectType";
|
|
95
|
+
let currentSelect = new DbmGraphApi.admin.edit.RemoveObjectType();
|
|
96
|
+
currentSelect.item.register(prefix + name);
|
|
97
|
+
}
|
|
69
98
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
|
|
3
|
+
export default class HelpSectionSuggestions extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async getData(aData, aEncodeSession) {
|
|
9
|
+
|
|
10
|
+
await aEncodeSession.outputController.requireRole("admin");
|
|
11
|
+
|
|
12
|
+
let returnObject = {};
|
|
13
|
+
|
|
14
|
+
let content = aData["value"];
|
|
15
|
+
returnObject["content"] = content;
|
|
16
|
+
|
|
17
|
+
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
18
|
+
let item = await database.createObject("private", ["aiGeneratedHelpSectionSuggestions"]);
|
|
19
|
+
await item.updateField("content", content);
|
|
20
|
+
returnObject["id"] = item.id;
|
|
21
|
+
|
|
22
|
+
let alreadyAdded = [
|
|
23
|
+
"All about this section"
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
let alreadyAddedString = "The page already have these faq sections: " + JSON.stringify(alreadyAdded);
|
|
27
|
+
|
|
28
|
+
let contentString = JSON.stringify(content);
|
|
29
|
+
|
|
30
|
+
let instructions = "Generate a seo description for the page data provided by the user. Split up the description into different lines and only keep the ones that can be used to link to this page. {additionalInstructions} Respond with only a json object {seoDescription: string, linkTitles: array of string}, no markdown.";
|
|
31
|
+
instructions = instructions.split("{data}").join(contentString);
|
|
32
|
+
|
|
33
|
+
let additionalInstructions = "";
|
|
34
|
+
instructions = instructions.split("{additionalInstructions}").join(additionalInstructions);
|
|
35
|
+
|
|
36
|
+
let body = {
|
|
37
|
+
"model": "gpt-4o",
|
|
38
|
+
"response_format": { "type": "json_object" },
|
|
39
|
+
"messages": [
|
|
40
|
+
{"role":"system","content": instructions},
|
|
41
|
+
/*{"role": "user", "content": alreadyAddedString},*/
|
|
42
|
+
{"role": "user", "content": contentString}
|
|
43
|
+
],
|
|
44
|
+
"temperature": 0.1
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let headers = {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
'Authorization': 'Bearer ' + Dbm.getInstance().repository.getItem("openAi").token
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: headers,
|
|
55
|
+
body: JSON.stringify(body),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
let data = await response.json();
|
|
59
|
+
await item.updateField("response", data);
|
|
60
|
+
|
|
61
|
+
let message = data.choices[0].message;
|
|
62
|
+
let responseContent = JSON.parse(message.content);
|
|
63
|
+
console.log(responseContent);
|
|
64
|
+
|
|
65
|
+
returnObject["titles"] = responseContent;
|
|
66
|
+
|
|
67
|
+
return returnObject;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -2,6 +2,7 @@ export {default as Example} from "./Example.js";
|
|
|
2
2
|
export {default as UploadS3} from "./UploadS3.js";
|
|
3
3
|
export {default as FreeUrl} from "./FreeUrl.js";
|
|
4
4
|
export {default as SeoSummary} from "./SeoSummary.js";
|
|
5
|
+
export {default as HelpSectionSuggestions} from "./HelpSectionSuggestions.js";
|
|
5
6
|
export {default as AltText} from "./AltText.js";
|
|
6
7
|
export {default as Breadcrumb} from "./Breadcrumb.js";
|
|
7
8
|
export {default as Question} from "./Question.js";
|
|
@@ -208,6 +208,7 @@ let fullDataSetup = function() {
|
|
|
208
208
|
|
|
209
209
|
registerDataFunction("admin/freeUrl", new DbmGraphApi.data.FreeUrl());
|
|
210
210
|
registerDataFunction("admin/seoSummary", new DbmGraphApi.data.SeoSummary());
|
|
211
|
+
registerDataFunction("admin/helpSectionSuggestions", new DbmGraphApi.data.HelpSectionSuggestions());
|
|
211
212
|
registerDataFunction("admin/altText", new DbmGraphApi.data.AltText());
|
|
212
213
|
|
|
213
214
|
registerDataFunction("server/status", new DbmGraphApi.data.server.Status());
|
|
@@ -18,6 +18,16 @@ export default class Relations extends EncodeBaseObject {
|
|
|
18
18
|
|
|
19
19
|
returnObject["relations"] = relations;
|
|
20
20
|
|
|
21
|
+
{
|
|
22
|
+
let ids = Dbm.utils.ArrayFunctions.mapField(relations["in"], "id");
|
|
23
|
+
await aEncodingSession.encodeObjects(database.getObjects(ids), "objectTypes");
|
|
24
|
+
}
|
|
25
|
+
{
|
|
26
|
+
let ids = Dbm.utils.ArrayFunctions.mapField(relations["out"], "id");
|
|
27
|
+
await aEncodingSession.encodeObjects(database.getObjects(ids), "objectTypes");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
21
31
|
return returnObject;
|
|
22
32
|
}
|
|
23
33
|
}
|
|
@@ -32,28 +32,49 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
32
32
|
let site = Dbm.getInstance().repository.getItem("site");
|
|
33
33
|
let fields = await aDatabaseObject.getFields();
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
let returnObject = {
|
|
36
36
|
"@type": "Organization",
|
|
37
37
|
"@id": this.baseUrl + "/" + "#organization",
|
|
38
38
|
"url": this.baseUrl + "/",
|
|
39
39
|
"name": fields["name"] ? fields["name"] : site.name,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
let image = await aDatabaseObject.singleObjectRelationQuery("in:isLogoFor:image");
|
|
43
|
+
if(image) {
|
|
44
|
+
let fields = await image.getFields();
|
|
45
|
+
returnObject["logo"] = fields["url"];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return returnObject;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
async encodeLocalBusiness(aDatabaseObject) {
|
|
46
52
|
|
|
53
|
+
|
|
47
54
|
let site = Dbm.getInstance().repository.getItem("site");
|
|
48
55
|
|
|
49
56
|
let type = await aDatabaseObject.singleObjectRelationQuery("in:for:schema/type");
|
|
50
|
-
let typeName =
|
|
57
|
+
let typeName = "LocalBusiness";
|
|
58
|
+
if(type) {
|
|
59
|
+
typeName = await type.getIdentifier();
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
let fields = await aDatabaseObject.getFields();
|
|
52
63
|
|
|
64
|
+
let baseUrl = this.baseUrl;
|
|
65
|
+
|
|
66
|
+
let representingPage = await aDatabaseObject.singleObjectRelationQuery("in:pageRepresentationFor:page");
|
|
67
|
+
if(representingPage) {
|
|
68
|
+
baseUrl += await representingPage.getUrl();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
baseUrl += "/";
|
|
72
|
+
}
|
|
73
|
+
|
|
53
74
|
let returnObject = {
|
|
54
75
|
"@type": typeName,
|
|
55
|
-
"@id":
|
|
56
|
-
"url":
|
|
76
|
+
"@id": baseUrl + "#local-business",
|
|
77
|
+
"url": baseUrl,
|
|
57
78
|
"name": fields["name"] ? fields["name"] : site.name,
|
|
58
79
|
"telephone": fields["phoneNumber"],
|
|
59
80
|
"email": fields["email"],
|
|
@@ -93,6 +114,12 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
93
114
|
};
|
|
94
115
|
}
|
|
95
116
|
|
|
117
|
+
let image = await aDatabaseObject.singleObjectRelationQuery("in:isMainImageFor:image");
|
|
118
|
+
if(image) {
|
|
119
|
+
let fields = await image.getFields();
|
|
120
|
+
returnObject["image"] = fields["url"];
|
|
121
|
+
}
|
|
122
|
+
|
|
96
123
|
return returnObject;
|
|
97
124
|
}
|
|
98
125
|
|
|
@@ -107,13 +134,19 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
107
134
|
returnArray.push(await this.encodeWebsiteEntity(website));
|
|
108
135
|
|
|
109
136
|
let organization = await website.singleObjectRelationQuery("out:by:organization");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
|
|
137
|
+
if(organization) {
|
|
138
|
+
returnArray.push(await this.encodeOrganizationEntity(organization));
|
|
139
|
+
|
|
140
|
+
let currentArray = await website.objectRelationQuery("out:by:organization,in:in:localBusiness");
|
|
141
|
+
let currentArrayLength = currentArray.length;
|
|
142
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
143
|
+
let currentLocalBusiness = currentArray[i];
|
|
144
|
+
if(currentLocalBusiness) {
|
|
145
|
+
console.log(currentLocalBusiness);
|
|
146
|
+
returnArray.push(await this.encodeLocalBusiness(currentLocalBusiness));
|
|
147
|
+
console.log("-");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
117
150
|
}
|
|
118
151
|
}
|
|
119
152
|
|
|
@@ -140,7 +173,27 @@ export default class JsonLdGenerator extends Dbm.core.BaseObject{
|
|
|
140
173
|
"@id": fullUrl +"#breadcrumb"
|
|
141
174
|
},
|
|
142
175
|
|
|
143
|
-
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
let image = await aPage.singleObjectRelationQuery("in:isMainImageFor:image");
|
|
179
|
+
if(image) {
|
|
180
|
+
let fields = await image.getFields();
|
|
181
|
+
|
|
182
|
+
let imageObject = {
|
|
183
|
+
"@type": "ImageObject",
|
|
184
|
+
"url": fields["url"]
|
|
185
|
+
};
|
|
186
|
+
pageObject["primaryImageOfPage"] = imageObject;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
let representingEntity = await aPage.singleObjectRelationQuery("out:pageRepresentationFor:localBusiness");
|
|
191
|
+
if(representingEntity) {
|
|
192
|
+
pageObject["mainEntity"] = {
|
|
193
|
+
"@id": fullUrl + "#local-business"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
144
197
|
returnArray.push(pageObject);
|
|
145
198
|
|
|
146
199
|
let urlParts = url.split("/");
|