dbm-graph-api 1.1.47 → 1.1.49

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.47",
3
+ "version": "1.1.49",
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.741.0",
15
- "@aws-sdk/s3-request-presigner": "^3.741.0",
16
- "dbm": "^1.4.5",
17
- "mime": "^4.0.6",
18
- "sharp": "^0.33.5",
19
- "ws": "^8.18.0"
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.9"
24
+ "bufferutil": "^4.1.0"
23
25
  }
24
26
  }
@@ -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
- let registerEncoding = function(aName, aEncoder) {
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 {registerEncoding};
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 {registerEncodingClass};
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 {fullEncodeSetup};
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
- let fullDataSetup = function() {
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 {fullDataSetup};
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
- let fullActionSetup = function() {
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 {fullActionSetup};
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
- let fullProcessActionSetup = function() {
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 {fullProcessActionSetup};
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 {setupInternalTaskRunner};
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
- let fullSetup = function() {
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
 
@@ -693,10 +700,18 @@ export const setupSite = function(aServer) {
693
700
  let assetsUri = site.assetsUri;
694
701
  let language = site.language;
695
702
  let siteName = site.name;
696
- let loader = "loader.js?version=" + site.version;
697
- if((process.env.NODE_ENV === "production" && request.query.forceLoad !== "unminified") || request.query.forceLoad === "minified") {
698
- loader = "loader.min.js?version=" + site.version;
699
- }
703
+ let loaderName = "loader";
704
+
705
+ if(request.query.forceLoader) {
706
+ loaderName = request.query.forceLoader;
707
+ }
708
+ else {
709
+ if((process.env.NODE_ENV === "production" && request.query.forceLoad !== "unminified") || request.query.forceLoad === "minified") {
710
+ loaderName += ".min";
711
+ }
712
+ }
713
+
714
+ let loader = loaderName + ".js?version=" + site.version;
700
715
 
701
716
  let url = request.url;
702
717
  let shouldRedirect = false;
@@ -23,6 +23,8 @@ export default class SendEmail extends Dbm.core.BaseObject {
23
23
  message.setTextContent(data["textContent"]);
24
24
  message.setHtmlContent(data["htmlContent"]);
25
25
 
26
+ message.item.additionalData = data["additionalData"];
27
+
26
28
  await message.send();
27
29
  }
28
30
  }
@@ -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
+ }