ldn-inbox-server 1.4.9 → 1.5.1

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.
@@ -5,6 +5,7 @@ const { program } = require('commander');
5
5
  const { start_server } = require('mellon-server');
6
6
  const { doInbox } = require('../lib/index');
7
7
  const { handle_inbox } = require('../lib/handler');
8
+ const { parseConfig } = require('../lib/util');
8
9
  require('dotenv').config();
9
10
 
10
11
  const HOST = process.env.LDN_SERVER_HOST ?? 'localhost';
@@ -58,7 +59,7 @@ program
58
59
  }
59
60
 
60
61
  if (options['config'] && fs.existsSync(options['config'])) {
61
- const config = JSON.parse(fs.readFileSync(options['config'], { encoding: 'utf-8'}));
62
+ const config = parseConfig(options['config']);
62
63
  if (config.registry) {
63
64
  for (let i = 0 ; i < config.registry.length ; i++) {
64
65
  const registry_item = config.registry[i];
@@ -1,4 +1,4 @@
1
- const { dynamic_handler , parseAsJSON } = require('../../lib/util.js');
1
+ const { dynamic_handler , parseConfig } = require('../../lib/util.js');
2
2
  const logger = require('../../lib/util.js').getLogger();
3
3
 
4
4
  /**
@@ -8,7 +8,7 @@ const logger = require('../../lib/util.js').getLogger();
8
8
  async function handle({path,options}) {
9
9
  let success = false;
10
10
 
11
- const config = parseAsJSON(options['config']);
11
+ const config = parseConfig(options['config']);
12
12
 
13
13
  if (! config) {
14
14
  logger.error('no configuration found for multi_notification_handler');
package/lib/index.js CHANGED
@@ -10,7 +10,8 @@ const {
10
10
  moveTo,
11
11
  parseAsJSON,
12
12
  generateId,
13
- generatePublished
13
+ generatePublished,
14
+ parseConfig
14
15
  } = require('../lib/util');
15
16
  const { handle_inbox } = require('../lib/handler');
16
17
  const logger = getLogger();
@@ -287,5 +288,6 @@ module.exports = {
287
288
  sendNotification ,
288
289
  handle_inbox ,
289
290
  generateId ,
290
- generatePublished
291
+ generatePublished ,
292
+ parseConfig
291
293
  };
package/lib/util.js CHANGED
@@ -5,6 +5,8 @@ const path = require('path');
5
5
  const { backOff } = require('exponential-backoff');
6
6
  const { v4: uuidv4 } = require('uuid');
7
7
  const fetch = require('node-fetch');
8
+ const YAML = require('yaml');
9
+ const JSON5 = require('json5');
8
10
  require('dotenv').config();
9
11
 
10
12
  const logger = getLogger();
@@ -26,6 +28,27 @@ function getLogger() {
26
28
  return logger;
27
29
  }
28
30
 
31
+ function parseConfig(path) {
32
+ try {
33
+ if (path.endsWith('.json') || path.endsWith('.jsonld')) {
34
+ return JSON.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
35
+ }
36
+ else if (path.endsWith('.json5')) {
37
+ return JSON5.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
38
+ }
39
+ else if (path.endsWith('.yaml') || path.endsWith('.yml')) {
40
+ return YAML.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
41
+ }
42
+ else {
43
+ return JSON.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
44
+ }
45
+ }
46
+ catch (e) {
47
+ logger.error(e);
48
+ return null;
49
+ }
50
+ }
51
+
29
52
  async function fetchOriginal(url) {
30
53
  logger.info(`Fetching ${url}...`);
31
54
 
@@ -248,5 +271,6 @@ module.exports = {
248
271
  parseArtifact ,
249
272
  parseEventLog ,
250
273
  parseLocalResource ,
251
- ldPropertyAsId
274
+ ldPropertyAsId ,
275
+ parseConfig
252
276
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldn-inbox-server",
3
- "version": "1.4.9",
3
+ "version": "1.5.1",
4
4
  "description": "A demonstration Event Notifications Inbox server",
5
5
  "main": "lib/index.js",
6
6
  "author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",
@@ -25,6 +25,7 @@
25
25
  "commander": "^12.0.0",
26
26
  "dotenv": "^16.4.5",
27
27
  "exponential-backoff": "^3.1.1",
28
+ "json5": "^2.2.3",
28
29
  "jsonpath": "^1.1.1",
29
30
  "jsonschema": "^1.4.1",
30
31
  "md5": "^2.3.0",
@@ -33,6 +34,7 @@
33
34
  "piscina": "^4.4.0",
34
35
  "proper-lockfile": "^4.1.2",
35
36
  "upath": "^2.0.1",
36
- "uuid": "^9.0.1"
37
+ "uuid": "^9.0.1",
38
+ "yaml": "^2.5.0"
37
39
  }
38
40
  }