ldn-inbox-server 1.4.8 → 1.5.0
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/bin/ldn-inbox-server.js +2 -1
- package/handler/notification_handler/multi.js +2 -2
- package/lib/index.js +6 -2
- package/lib/util.js +26 -1
- package/package.json +3 -2
package/bin/ldn-inbox-server.js
CHANGED
|
@@ -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 =
|
|
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 ,
|
|
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 =
|
|
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
|
@@ -9,7 +9,9 @@ const {
|
|
|
9
9
|
sendNotification,
|
|
10
10
|
moveTo,
|
|
11
11
|
parseAsJSON,
|
|
12
|
-
generateId
|
|
12
|
+
generateId,
|
|
13
|
+
generatePublished,
|
|
14
|
+
parseConfig
|
|
13
15
|
} = require('../lib/util');
|
|
14
16
|
const { handle_inbox } = require('../lib/handler');
|
|
15
17
|
const logger = getLogger();
|
|
@@ -285,5 +287,7 @@ module.exports = {
|
|
|
285
287
|
moveTo ,
|
|
286
288
|
sendNotification ,
|
|
287
289
|
handle_inbox ,
|
|
288
|
-
generateId
|
|
290
|
+
generateId ,
|
|
291
|
+
generatePublished ,
|
|
292
|
+
parseConfig
|
|
289
293
|
};
|
package/lib/util.js
CHANGED
|
@@ -5,6 +5,7 @@ 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');
|
|
8
9
|
require('dotenv').config();
|
|
9
10
|
|
|
10
11
|
const logger = getLogger();
|
|
@@ -26,6 +27,24 @@ function getLogger() {
|
|
|
26
27
|
return logger;
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
function parseConfig(path) {
|
|
31
|
+
try {
|
|
32
|
+
if (path.endsWith('.json') || path.endsWith('.jsonld')) {
|
|
33
|
+
return JSON.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
|
|
34
|
+
}
|
|
35
|
+
else if (path.endsWith('.yaml') || path.endsWith('.yml')) {
|
|
36
|
+
return YAML.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return JSON.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
logger.error(e);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
async function fetchOriginal(url) {
|
|
30
49
|
logger.info(`Fetching ${url}...`);
|
|
31
50
|
|
|
@@ -231,9 +250,14 @@ function generateId() {
|
|
|
231
250
|
return 'urn:uuid:' + uuidv4();
|
|
232
251
|
}
|
|
233
252
|
|
|
253
|
+
function generatePublished() {
|
|
254
|
+
return (new Date()).toISOString();
|
|
255
|
+
}
|
|
256
|
+
|
|
234
257
|
module.exports = {
|
|
235
258
|
getLogger ,
|
|
236
259
|
generateId ,
|
|
260
|
+
generatePublished ,
|
|
237
261
|
backOff_fetch ,
|
|
238
262
|
fetchOriginal ,
|
|
239
263
|
moveTo ,
|
|
@@ -243,5 +267,6 @@ module.exports = {
|
|
|
243
267
|
parseArtifact ,
|
|
244
268
|
parseEventLog ,
|
|
245
269
|
parseLocalResource ,
|
|
246
|
-
ldPropertyAsId
|
|
270
|
+
ldPropertyAsId ,
|
|
271
|
+
parseConfig
|
|
247
272
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldn-inbox-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A demonstration Event Notifications Inbox server",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"piscina": "^4.4.0",
|
|
34
34
|
"proper-lockfile": "^4.1.2",
|
|
35
35
|
"upath": "^2.0.1",
|
|
36
|
-
"uuid": "^9.0.1"
|
|
36
|
+
"uuid": "^9.0.1",
|
|
37
|
+
"yaml": "^2.5.0"
|
|
37
38
|
}
|
|
38
39
|
}
|