ldn-inbox-server 1.2.0 → 1.2.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.
package/bin/ldn-inbox-server.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const { program } = require('commander');
|
|
4
5
|
const { inbox_server } = require('../lib/index');
|
|
5
6
|
const { handle_inbox , defaultSendNotificationHandler } = require('../lib/handler');
|
|
@@ -18,7 +19,7 @@ const JSON_SCHEMA_PATH = process.env.LDN_SERVER_JSON_SCHEMA ?? './config/notific
|
|
|
18
19
|
|
|
19
20
|
program
|
|
20
21
|
.name('lnd-inbox-server')
|
|
21
|
-
.version('1.2.
|
|
22
|
+
.version('1.2.1')
|
|
22
23
|
.description('A demonstration Event Notifications Inbox server');
|
|
23
24
|
|
|
24
25
|
program
|
|
@@ -53,7 +54,7 @@ program
|
|
|
53
54
|
case '@outbox':
|
|
54
55
|
box = OUTBOX_PATH;
|
|
55
56
|
options['notification_handler'] =
|
|
56
|
-
options['notification_handler'] ??
|
|
57
|
+
options['notification_handler'] ?? path.join(__dirname,'..','lib','sendNotificationHandler.js');
|
|
57
58
|
break;
|
|
58
59
|
}
|
|
59
60
|
if (options['loop']) {
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
sendNotification,
|
|
10
10
|
moveTo
|
|
11
11
|
} = require('../lib/util');
|
|
12
|
-
const { handle_inbox
|
|
12
|
+
const { handle_inbox } = require('../lib/handler');
|
|
13
13
|
const logger = getLogger();
|
|
14
14
|
|
|
15
15
|
let INBOX_URL = 'inbox/';
|
|
@@ -139,6 +139,5 @@ module.exports = {
|
|
|
139
139
|
fetchOriginal ,
|
|
140
140
|
moveTo ,
|
|
141
141
|
sendNotification ,
|
|
142
|
-
defaultSendNotificationHandler ,
|
|
143
142
|
handle_inbox
|
|
144
143
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const logger = require('../lib/util.js').getLogger();
|
|
3
|
+
const { sendNotification } = require('../lib/util.js');
|
|
4
|
+
|
|
5
|
+
async function handle({path,options}) {
|
|
6
|
+
try {
|
|
7
|
+
const json = fs.readFileSync(path, { encoding: 'utf-8'});
|
|
8
|
+
const data = JSON.parse(json);
|
|
9
|
+
const type = data['type'];
|
|
10
|
+
let inbox;
|
|
11
|
+
|
|
12
|
+
if (data['target'] && data['target']['inbox']) {
|
|
13
|
+
inbox = data['target']['inbox'];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw new Error(`no target.inbox defined for ${path}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
logger.info(`Sending ${type} to ${inbox}`);
|
|
20
|
+
await sendNotification(inbox, data);
|
|
21
|
+
|
|
22
|
+
return { path, options, success: true };
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
logger.error(e);
|
|
26
|
+
return { path, options, success: false };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { handle };
|
package/package.json
CHANGED
|
File without changes
|