dbm-graph-api 1.1.48 → 1.1.50
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 +10 -8
- package/src/dbm-graph-api/Api.js +10 -12
- package/src/dbm-graph-api/UrlRequest.js +66 -10
- package/src/dbm-graph-api/WebSocketConnection.js +102 -37
- package/src/dbm-graph-api/index.js +35 -28
- package/src/dbm-graph-api/processAction/communication/SendEmail.js +2 -0
- package/src/dbm-graph-api/taskrunner/CronBaseObject.js +42 -0
- package/src/dbm-graph-api/taskrunner/ExternalCron.js +39 -0
- package/src/dbm-graph-api/taskrunner/InternalCron.js +32 -0
- package/src/dbm-graph-api/taskrunner/index.js +13 -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.50",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -11,14 +11,16 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"description": "",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@aws-sdk/client-s3": "^3.
|
|
15
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
16
|
-
"dbm": "^1.4.
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
14
|
+
"@aws-sdk/client-s3": "^3.984.0",
|
|
15
|
+
"@aws-sdk/s3-request-presigner": "^3.984.0",
|
|
16
|
+
"dbm": "^1.4.7",
|
|
17
|
+
"html-to-text": "^9.0.5",
|
|
18
|
+
"mime": "^4.1.0",
|
|
19
|
+
"node-cron": "^4.2.1",
|
|
20
|
+
"sharp": "^0.34.5",
|
|
21
|
+
"ws": "^8.19.0"
|
|
20
22
|
},
|
|
21
23
|
"optionalDependencies": {
|
|
22
|
-
"bufferutil": "^4.0
|
|
24
|
+
"bufferutil": "^4.1.0"
|
|
23
25
|
}
|
|
24
26
|
}
|
package/src/dbm-graph-api/Api.js
CHANGED
|
@@ -25,7 +25,7 @@ export default class Api extends Dbm.core.BaseObject {
|
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
_callback_connection(aWebSocket, aRequest) {
|
|
28
|
+
async _callback_connection(aWebSocket, aRequest) {
|
|
29
29
|
let newWebSocketConnection = new WebSocketConnection();
|
|
30
30
|
|
|
31
31
|
newWebSocketConnection.item.setValue("api", this.item);
|
|
@@ -48,17 +48,15 @@ export default class Api extends Dbm.core.BaseObject {
|
|
|
48
48
|
let userId = 1*value.split(":")[1];
|
|
49
49
|
let user = Dbm.getRepositoryItem("graphDatabase").controller.getUser(userId);
|
|
50
50
|
|
|
51
|
-
user.verifySession(value)
|
|
52
|
-
//console.log("verifySession", aIsValidSession);
|
|
51
|
+
let isValidSession = await user.verifySession(value);
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
53
|
+
if(isValidSession) {
|
|
54
|
+
await newWebSocketConnection.setInitialUser(userId);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
await newWebSocketConnection.setInitialUser(0);
|
|
58
|
+
};
|
|
59
|
+
|
|
62
60
|
hasUserCookie = true;
|
|
63
61
|
break;
|
|
64
62
|
}
|
|
@@ -66,7 +64,7 @@ export default class Api extends Dbm.core.BaseObject {
|
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
if(!hasUserCookie) {
|
|
69
|
-
newWebSocketConnection.setInitialUser(0);
|
|
67
|
+
await newWebSocketConnection.setInitialUser(0);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -30,16 +30,36 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
30
30
|
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
31
31
|
let urlObject = await database.getObjectByUrl(url);
|
|
32
32
|
|
|
33
|
+
let logs = [];
|
|
34
|
+
|
|
33
35
|
if(urlObject) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
let isOk = false;
|
|
37
|
+
let visibility = await urlObject.getVisibility();
|
|
38
|
+
if(visibility === "public") {
|
|
39
|
+
isOk = true;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
let isAdmin = await this.hasRole("admin");
|
|
43
|
+
if(isAdmin) {
|
|
44
|
+
isOk = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
if(isOk) {
|
|
49
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
50
|
+
encodeSession.outputController = this;
|
|
51
|
+
|
|
52
|
+
await encodeSession.encodeSingleWithTypes(urlObject.id, ["urlRequest"]);
|
|
53
|
+
encodeSession.destroy();
|
|
54
|
+
this._responseData = {"id": urlObject.id, "logs": logs};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this._responseData = {"id": urlObject.id, "logs": ["Not allowed to load item"]};
|
|
58
|
+
}
|
|
40
59
|
}
|
|
41
60
|
else {
|
|
42
|
-
|
|
61
|
+
logs.push("Not found");
|
|
62
|
+
this._responseData = {"id": 0, "logs": logs};
|
|
43
63
|
}
|
|
44
64
|
}
|
|
45
65
|
|
|
@@ -111,13 +131,29 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
111
131
|
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
112
132
|
encodeSession.outputController = this;
|
|
113
133
|
|
|
114
|
-
|
|
134
|
+
let isOk = false;
|
|
135
|
+
let visibility = await Dbm.node.getDatabase().getObjectVisibility(aId);
|
|
136
|
+
if(visibility === "public") {
|
|
137
|
+
isOk = true;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
let isAdmin = await this.hasRole("admin");
|
|
141
|
+
if(isAdmin) {
|
|
142
|
+
isOk = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
115
145
|
|
|
116
|
-
|
|
146
|
+
let logs = [];
|
|
147
|
+
if(isOk) {
|
|
148
|
+
await encodeSession.encodeSingleWithTypes(aId, aEncodes);
|
|
117
149
|
|
|
118
|
-
|
|
150
|
+
encodeSession.destroy();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
logs.push("Not allowed to load item");
|
|
154
|
+
}
|
|
119
155
|
|
|
120
|
-
this._responseData = {"id": aId};
|
|
156
|
+
this._responseData = {"id": aId, "logs": logs};
|
|
121
157
|
}
|
|
122
158
|
|
|
123
159
|
async requestData(aFunctionName, aData) {
|
|
@@ -236,6 +272,26 @@ export default class UrlRequest extends Dbm.core.BaseObject {
|
|
|
236
272
|
throw(new Error("Only signed in users can use this endpoint"));
|
|
237
273
|
}
|
|
238
274
|
|
|
275
|
+
let hasRole = await user.hasRole(aRole);
|
|
276
|
+
if(!hasRole) {
|
|
277
|
+
throw(new Error("User doesn't have privileges"));
|
|
278
|
+
}
|
|
279
|
+
|
|
239
280
|
return true;
|
|
240
281
|
}
|
|
282
|
+
|
|
283
|
+
async hasRole(aRole) {
|
|
284
|
+
let user = await this.getUser();
|
|
285
|
+
|
|
286
|
+
if(!user) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let hasRole = await user.hasRole(aRole);
|
|
291
|
+
if(!hasRole) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
241
297
|
}
|
|
@@ -166,23 +166,39 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
166
166
|
case "item":
|
|
167
167
|
{
|
|
168
168
|
let id = data['id'];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
let
|
|
172
|
-
|
|
169
|
+
|
|
170
|
+
let isOk = false;
|
|
171
|
+
let visibility = await Dbm.node.getDatabase().getObjectVisibility(id);
|
|
172
|
+
if(visibility === "public") {
|
|
173
|
+
isOk = true;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
let isAdmin = await this.hasRole("admin");
|
|
177
|
+
if(isAdmin) {
|
|
178
|
+
isOk = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
173
181
|
|
|
174
182
|
let logs = [];
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
|
|
184
|
+
if(isOk) {
|
|
185
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
186
|
+
encodeSession.outputController = this;
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await encodeSession.encodeSingleWithTypes(id, data.encode);
|
|
190
|
+
}
|
|
191
|
+
catch(theError) {
|
|
192
|
+
logs.push(theError.message);
|
|
193
|
+
console.error(theError);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
encodeSession.destroy();
|
|
178
197
|
}
|
|
179
|
-
|
|
180
|
-
logs.push(
|
|
181
|
-
console.error(theError);
|
|
198
|
+
else {
|
|
199
|
+
logs.push("Not allowed to load item");
|
|
182
200
|
}
|
|
183
201
|
|
|
184
|
-
encodeSession.destroy();
|
|
185
|
-
|
|
186
202
|
this._sendData({"type": "item/response", "id": id, "requestId": data["requestId"], "logs": logs});
|
|
187
203
|
}
|
|
188
204
|
break;
|
|
@@ -192,32 +208,47 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
192
208
|
if(url[url.length-1] !== "/") {
|
|
193
209
|
url += "/";
|
|
194
210
|
}
|
|
195
|
-
//METODO: check visibility in database
|
|
196
|
-
|
|
197
211
|
|
|
198
|
-
|
|
199
|
-
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
212
|
+
let database = Dbm.node.getDatabase();
|
|
200
213
|
let urlObject = await database.getObjectByUrl(url);
|
|
201
214
|
|
|
215
|
+
let logs = [];
|
|
216
|
+
|
|
217
|
+
let id = 0;
|
|
202
218
|
if(urlObject) {
|
|
203
|
-
|
|
204
|
-
encodeSession.outputController = this;
|
|
219
|
+
id = urlObject.id;
|
|
205
220
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
221
|
+
let isOk = false;
|
|
222
|
+
let visibility = await urlObject.getVisibility();
|
|
223
|
+
if(visibility === "public") {
|
|
224
|
+
isOk = true;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
let isAdmin = await this.hasRole("admin");
|
|
228
|
+
if(isAdmin) {
|
|
229
|
+
isOk = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if(isOk) {
|
|
234
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
235
|
+
encodeSession.outputController = this;
|
|
236
|
+
|
|
237
|
+
await encodeSession.encodeSingleWithTypes(urlObject.id, ["urlRequest"]);
|
|
238
|
+
encodeSession.destroy();
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
logs.push("Not allowed to load item");
|
|
242
|
+
}
|
|
212
243
|
}
|
|
244
|
+
|
|
245
|
+
this._sendData({"type": "url/response", "id": id, "requestId": data["requestId"], "logs": logs});
|
|
213
246
|
}
|
|
214
247
|
break;
|
|
215
248
|
case "admin/createObject":
|
|
216
249
|
{
|
|
217
|
-
//METODO: require role
|
|
218
250
|
let returnId = 0;
|
|
219
|
-
|
|
220
|
-
if(user) {
|
|
251
|
+
if(await this.hasRole("admin")) {
|
|
221
252
|
let types = data['types'];
|
|
222
253
|
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
223
254
|
let visibility = data['visibility'] ? data['visibility'] : 'draft';
|
|
@@ -256,8 +287,7 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
256
287
|
|
|
257
288
|
let theObject = database.getObject(data.id);
|
|
258
289
|
|
|
259
|
-
|
|
260
|
-
if(user) {
|
|
290
|
+
if(await this.hasRole("admin")) {
|
|
261
291
|
if(data.changes) {
|
|
262
292
|
await this._applyChanges(theObject, data.changes, request);
|
|
263
293
|
}
|
|
@@ -288,21 +318,28 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
288
318
|
|
|
289
319
|
let isVerified = await user.verifySignedSessionToken(data.token);
|
|
290
320
|
|
|
321
|
+
let roleIds = [];
|
|
291
322
|
let userId = 0;
|
|
292
323
|
if(isVerified) {
|
|
293
|
-
//METODO: set user for connection
|
|
294
|
-
|
|
295
324
|
userId = user.id;
|
|
296
325
|
this.item.setValue("user", user);
|
|
326
|
+
|
|
327
|
+
let roles = await user.getRoles();
|
|
328
|
+
|
|
329
|
+
let currentArray = roles;
|
|
330
|
+
let currentArrayLength = currentArray.length;
|
|
331
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
332
|
+
roleIds.push(await currentArray[i].getIdentifier());
|
|
333
|
+
}
|
|
297
334
|
}
|
|
298
335
|
|
|
299
|
-
this._sendData({"type": "currentUser/response", "id": userId, "requestId": data["requestId"]});
|
|
336
|
+
this._sendData({"type": "currentUser/response", "id": userId, "roles": roleIds, "requestId": data["requestId"]});
|
|
300
337
|
}
|
|
301
338
|
break;
|
|
302
339
|
case "user/signOut":
|
|
303
340
|
{
|
|
304
341
|
this.item.setValue("user", null);
|
|
305
|
-
this._sendData({"type": "currentUser/response", "id": 0, "requestId": data["requestId"]});
|
|
342
|
+
this._sendData({"type": "currentUser/response", "id": 0, "roles": [], "requestId": data["requestId"]});
|
|
306
343
|
}
|
|
307
344
|
break;
|
|
308
345
|
case "heartbeat":
|
|
@@ -367,19 +404,27 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
367
404
|
|
|
368
405
|
}
|
|
369
406
|
|
|
370
|
-
setInitialUser(aId) {
|
|
407
|
+
async setInitialUser(aId) {
|
|
371
408
|
|
|
372
|
-
|
|
373
|
-
let database = Dbm.getInstance().repository.getItem("graphDatabase").controller;
|
|
409
|
+
let roleIds = [];
|
|
374
410
|
|
|
375
|
-
|
|
411
|
+
if(aId) {
|
|
412
|
+
let user = Dbm.node.getDatabase().getUser(aId);
|
|
376
413
|
this.item.setValue("user", user);
|
|
414
|
+
|
|
415
|
+
let roles = await user.getRoles();
|
|
416
|
+
|
|
417
|
+
let currentArray = roles;
|
|
418
|
+
let currentArrayLength = currentArray.length;
|
|
419
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
420
|
+
roleIds.push(await currentArray[i].getIdentifier());
|
|
421
|
+
}
|
|
377
422
|
}
|
|
378
423
|
else {
|
|
379
424
|
this.item.setValue("user", null);
|
|
380
425
|
}
|
|
381
426
|
|
|
382
|
-
this._sendData({"type": "connectionReady", "user": aId});
|
|
427
|
+
this._sendData({"type": "connectionReady", "user": aId, "roles": roleIds});
|
|
383
428
|
}
|
|
384
429
|
|
|
385
430
|
async getUser() {
|
|
@@ -393,6 +438,26 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
393
438
|
throw(new Error("Only signed in users can use this endpoint"));
|
|
394
439
|
}
|
|
395
440
|
|
|
441
|
+
let hasRole = await user.hasRole(aRole);
|
|
442
|
+
if(!hasRole) {
|
|
443
|
+
throw(new Error("User doesn't have privileges"));
|
|
444
|
+
}
|
|
445
|
+
|
|
396
446
|
return true;
|
|
397
447
|
}
|
|
448
|
+
|
|
449
|
+
async hasRole(aRole) {
|
|
450
|
+
let user = await this.getUser();
|
|
451
|
+
|
|
452
|
+
if(!user) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let hasRole = await user.hasRole(aRole);
|
|
457
|
+
if(!hasRole) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
398
463
|
}
|
|
@@ -9,6 +9,7 @@ import UrlRequest from "./UrlRequest.js";
|
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import sharp from 'sharp';
|
|
11
11
|
import mime from 'mime';
|
|
12
|
+
import { htmlToText } from "html-to-text";
|
|
12
13
|
|
|
13
14
|
export {Api};
|
|
14
15
|
|
|
@@ -24,7 +25,7 @@ export const fullSelectSetup = function() {
|
|
|
24
25
|
DbmGraphApi.range.select.fullSetup();
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
export const registerEncoding = function(aName, aEncoder) {
|
|
28
29
|
let encodePrefix = "graphApi/range/encode/";
|
|
29
30
|
aEncoder.item.register(encodePrefix + aName);
|
|
30
31
|
aEncoder.item.setValue("encodingType", aName);
|
|
@@ -32,15 +33,11 @@ let registerEncoding = function(aName, aEncoder) {
|
|
|
32
33
|
return aEncoder;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export {
|
|
36
|
-
|
|
37
|
-
let registerEncodingClass = function(aEncoderClass) {
|
|
36
|
+
export const registerEncodingClass = function(aEncoderClass) {
|
|
38
37
|
return registerEncoding(aEncoderClass.DEFAULT_ENCODING_NAME, new aEncoderClass());
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
export {
|
|
42
|
-
|
|
43
|
-
let fullEncodeSetup = function() {
|
|
40
|
+
export const fullEncodeSetup = function() {
|
|
44
41
|
let encodePrefix = "graphApi/range/encode/";
|
|
45
42
|
{
|
|
46
43
|
let name = "example";
|
|
@@ -195,9 +192,7 @@ let fullEncodeSetup = function() {
|
|
|
195
192
|
registerEncoding("action", new DbmGraphApi.range.encode.Action());
|
|
196
193
|
}
|
|
197
194
|
|
|
198
|
-
export {
|
|
199
|
-
|
|
200
|
-
export let registerDataFunction = function(aName, aDataFunction) {
|
|
195
|
+
export const registerDataFunction = function(aName, aDataFunction) {
|
|
201
196
|
|
|
202
197
|
aDataFunction.item.register("graphApi/data/" + aName);
|
|
203
198
|
aDataFunction.item.setValue("functionName", aName);
|
|
@@ -205,7 +200,7 @@ export let registerDataFunction = function(aName, aDataFunction) {
|
|
|
205
200
|
return aDataFunction;
|
|
206
201
|
}
|
|
207
202
|
|
|
208
|
-
|
|
203
|
+
export const fullDataSetup = function() {
|
|
209
204
|
registerDataFunction("example", new DbmGraphApi.data.Example());
|
|
210
205
|
|
|
211
206
|
registerDataFunction("breadcrumb", new DbmGraphApi.data.Breadcrumb());
|
|
@@ -221,9 +216,7 @@ let fullDataSetup = function() {
|
|
|
221
216
|
registerDataFunction("server/status", new DbmGraphApi.data.server.Status());
|
|
222
217
|
}
|
|
223
218
|
|
|
224
|
-
export {
|
|
225
|
-
|
|
226
|
-
export let registerActionFunction = function(aName, aDataFunction) {
|
|
219
|
+
export const registerActionFunction = function(aName, aDataFunction) {
|
|
227
220
|
|
|
228
221
|
aDataFunction.item.register("graphApi/action/" + aName);
|
|
229
222
|
aDataFunction.item.setValue("functionName", aName);
|
|
@@ -231,7 +224,7 @@ export let registerActionFunction = function(aName, aDataFunction) {
|
|
|
231
224
|
return aDataFunction;
|
|
232
225
|
}
|
|
233
226
|
|
|
234
|
-
|
|
227
|
+
export const fullActionSetup = function() {
|
|
235
228
|
registerActionFunction("example", new DbmGraphApi.action.Example());
|
|
236
229
|
registerActionFunction("submitForm", new DbmGraphApi.action.SubmitForm());
|
|
237
230
|
registerActionFunction("incomingWebhook", new DbmGraphApi.action.IncomingWebhook());
|
|
@@ -249,9 +242,7 @@ let fullActionSetup = function() {
|
|
|
249
242
|
registerActionFunction("development/reRenderPages", new DbmGraphApi.action.development.ReRenderPages());
|
|
250
243
|
}
|
|
251
244
|
|
|
252
|
-
export {
|
|
253
|
-
|
|
254
|
-
export let registerProcessActionFunction = function(aName, aDataFunction) {
|
|
245
|
+
export const registerProcessActionFunction = function(aName, aDataFunction) {
|
|
255
246
|
|
|
256
247
|
aDataFunction.item.register("graphApi/processAction/" + aName);
|
|
257
248
|
aDataFunction.item.setValue("functionName", aName);
|
|
@@ -259,7 +250,7 @@ export let registerProcessActionFunction = function(aName, aDataFunction) {
|
|
|
259
250
|
return aDataFunction;
|
|
260
251
|
}
|
|
261
252
|
|
|
262
|
-
|
|
253
|
+
export const fullProcessActionSetup = function() {
|
|
263
254
|
registerProcessActionFunction("example", new DbmGraphApi.processAction.Example());
|
|
264
255
|
|
|
265
256
|
registerProcessActionFunction("handleFormSubmission", new DbmGraphApi.processAction.HandleFormSubmission());
|
|
@@ -273,9 +264,7 @@ let fullProcessActionSetup = function() {
|
|
|
273
264
|
registerProcessActionFunction("pageUpdates/clearCache", new DbmGraphApi.processAction.pageUpdates.ClearCloudflareCache());
|
|
274
265
|
}
|
|
275
266
|
|
|
276
|
-
export {
|
|
277
|
-
|
|
278
|
-
let setupInternalTaskRunner = function() {
|
|
267
|
+
export const setupInternalTaskRunner = function() {
|
|
279
268
|
Dbm.getRepositoryItem("taskRunner").requireProperty("runners", []);
|
|
280
269
|
|
|
281
270
|
let runner = new DbmGraphApi.taskrunner.InternalTaskRunner();
|
|
@@ -287,10 +276,30 @@ let setupInternalTaskRunner = function() {
|
|
|
287
276
|
|
|
288
277
|
}
|
|
289
278
|
|
|
290
|
-
export {
|
|
291
|
-
|
|
279
|
+
export const fullSettingsSetup = function() {
|
|
280
|
+
let htmlToTextConverter = {"item": new Dbm.repository.Item(), "convertToText": function(aHtmlText) {
|
|
281
|
+
return htmlToText(aHtmlText, {
|
|
282
|
+
wordwrap: false,
|
|
283
|
+
selectors: [
|
|
284
|
+
{
|
|
285
|
+
selector: "a",
|
|
286
|
+
options: {
|
|
287
|
+
hideLinkHrefIfSameAsText: true
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
selector: "img",
|
|
292
|
+
format: "skip"
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
]
|
|
296
|
+
});
|
|
297
|
+
}};
|
|
298
|
+
htmlToTextConverter.item.setValue("controller", htmlToTextConverter);
|
|
299
|
+
htmlToTextConverter.item.register("htmlToTextConverter");
|
|
300
|
+
}
|
|
292
301
|
|
|
293
|
-
|
|
302
|
+
export const fullSetup = function() {
|
|
294
303
|
|
|
295
304
|
fullSelectSetup();
|
|
296
305
|
fullEncodeSetup();
|
|
@@ -298,12 +307,11 @@ let fullSetup = function() {
|
|
|
298
307
|
fullActionSetup();
|
|
299
308
|
fullProcessActionSetup();
|
|
300
309
|
setupInternalTaskRunner();
|
|
310
|
+
fullSettingsSetup();
|
|
301
311
|
|
|
302
312
|
DbmGraphApi.admin.edit.fullSetup();
|
|
303
313
|
}
|
|
304
314
|
|
|
305
|
-
export {fullSetup};
|
|
306
|
-
|
|
307
315
|
export const setupEndpoints = function(aServer) {
|
|
308
316
|
aServer.post('/api/user/login', async function handler (aRequest, aReply) {
|
|
309
317
|
|
|
@@ -357,7 +365,6 @@ export const setupEndpoints = function(aServer) {
|
|
|
357
365
|
}
|
|
358
366
|
|
|
359
367
|
let user = await loginMethod.controller.getUser(params);
|
|
360
|
-
console.log(user);
|
|
361
368
|
if(user) {
|
|
362
369
|
let sessionId = await user.createSession();
|
|
363
370
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../../index.js";
|
|
3
|
+
|
|
4
|
+
import cron from 'node-cron';
|
|
5
|
+
|
|
6
|
+
export default class CronBaseObject extends Dbm.core.BaseObject {
|
|
7
|
+
|
|
8
|
+
_construct() {
|
|
9
|
+
super._construct();
|
|
10
|
+
|
|
11
|
+
this._cronTask = null;
|
|
12
|
+
|
|
13
|
+
this._callback_runTaskBound = this._callback_runTask.bind(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
start(aSchedule, aTimezone = null) {
|
|
17
|
+
if(!this._cronTask) {
|
|
18
|
+
let options = {};
|
|
19
|
+
if(aTimezone) {
|
|
20
|
+
options["timezone"] = aTimezone;
|
|
21
|
+
}
|
|
22
|
+
this._cronTask = cron.createTask(aSchedule, this._callback_runTaskBound, options);
|
|
23
|
+
this._cronTask.start();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
stop() {
|
|
28
|
+
if(this._cronTask) {
|
|
29
|
+
this._cronTask.stop();
|
|
30
|
+
this._cronTask.destroy();
|
|
31
|
+
this._cronTask = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async runTask() {
|
|
36
|
+
console.warn("runTask should be overridden", this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async _callback_runTask(aTaskContext) {
|
|
40
|
+
return await this.runTask();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class ExternalCron extends DbmGraphApi.taskrunner.CronBaseObject {
|
|
5
|
+
|
|
6
|
+
_construct() {
|
|
7
|
+
super._construct();
|
|
8
|
+
|
|
9
|
+
this.item.requireProperty("url", null);
|
|
10
|
+
this.item.requireProperty("method", "GET");
|
|
11
|
+
this.item.requireProperty("headers", {});
|
|
12
|
+
this.item.requireProperty("body", null);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async runTask() {
|
|
16
|
+
//console.log("ExternalCron::runTask");
|
|
17
|
+
|
|
18
|
+
let requestData = {
|
|
19
|
+
method: this.item.method,
|
|
20
|
+
headers: this.item.headers
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if(this.item.body) {
|
|
24
|
+
requestData["body"] = this.item.body;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
let startTime = performance.now();
|
|
29
|
+
let response = await fetch(this.item.url, requestData);
|
|
30
|
+
|
|
31
|
+
let responseText = await response.text();
|
|
32
|
+
|
|
33
|
+
let endTime = performance.now();
|
|
34
|
+
}
|
|
35
|
+
catch(theError) {
|
|
36
|
+
console.log(theError);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Dbm from "dbm";
|
|
2
|
+
import DbmGraphApi from "../../../index.js";
|
|
3
|
+
|
|
4
|
+
export default class InternalCron extends DbmGraphApi.taskrunner.CronBaseObject {
|
|
5
|
+
|
|
6
|
+
_construct() {
|
|
7
|
+
super._construct();
|
|
8
|
+
|
|
9
|
+
this.item.setValue("cronName", null);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async runTask() {
|
|
13
|
+
console.log("InternalCron::runTask");
|
|
14
|
+
let encodeSession = new DbmGraphApi.range.EncodeSession();
|
|
15
|
+
encodeSession.outputController = this;
|
|
16
|
+
|
|
17
|
+
let dataFunctionItem = Dbm.getRepositoryItemIfExists("graphApi/action/cron/" + this.item.cronName);
|
|
18
|
+
|
|
19
|
+
if(dataFunctionItem) {
|
|
20
|
+
try {
|
|
21
|
+
await dataFunctionItem.controller.performAction({}, encodeSession);
|
|
22
|
+
}
|
|
23
|
+
catch(theError) {
|
|
24
|
+
console.log(theError);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.warn("No cron function called " + this.item.cronName + ". Can't run internal cron.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
import DbmGraphApi from "../../../index.js";
|
|
2
|
+
|
|
1
3
|
export {default as InternalTaskRunner} from "./InternalTaskRunner.js";
|
|
2
|
-
export {default as ExternalTaskRunner} from "./ExternalTaskRunner.js";
|
|
4
|
+
export {default as ExternalTaskRunner} from "./ExternalTaskRunner.js";
|
|
5
|
+
export {default as CronBaseObject} from "./CronBaseObject.js";
|
|
6
|
+
export {default as InternalCron} from "./InternalCron.js";
|
|
7
|
+
export {default as ExternalCron} from "./ExternalCron.js";
|
|
8
|
+
|
|
9
|
+
export const startInternalCron = function(aSchedule, aFunctionName) {
|
|
10
|
+
let cronRunner = new DbmGraphApi.taskrunner.InternalCron();
|
|
11
|
+
cronRunner.item.cronName = aFunctionName;
|
|
12
|
+
cronRunner.start(aSchedule);
|
|
13
|
+
return cronRunner;
|
|
14
|
+
}
|