ldn-inbox-server 1.4.2 → 1.4.4
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/README.md +1 -1
- package/config/inbox_config.json +7 -7
- package/config/outbox_config.json +2 -2
- package/lib/handler.js +9 -1
- package/lib/index.js +55 -12
- package/lib/util.js +2 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -148,7 +148,7 @@ The json path matches when one of:
|
|
|
148
148
|
|
|
149
149
|
### Multi handler
|
|
150
150
|
|
|
151
|
-
A `handler/multi_notification_handler.js` is available to start multiple handler for each notification messages. The handlers to start are specified in a
|
|
151
|
+
A `handler/multi_notification_handler.js` is available to start multiple handler for each notification messages. The handlers to start are specified in a configuration file that can be passed via the `config` parameter of an `handle_inbox`. In the commmand line tool `bin/ldn-inbox-server` the default location of such config file is `config/inbox_config.json` when processing an `@inbox`, and `config/outbox_config.json` when processing an `@outbox`.
|
|
152
152
|
|
|
153
153
|
### Offer memento handler
|
|
154
154
|
|
package/config/inbox_config.json
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
"handlers": [
|
|
5
5
|
[
|
|
6
6
|
{
|
|
7
|
-
"id": "handler/notification_handler/jsonpath_filter.js",
|
|
7
|
+
"id": "@handler/notification_handler/jsonpath_filter.js",
|
|
8
8
|
"anyOf": [
|
|
9
9
|
[
|
|
10
10
|
{ "path": "$.type" , "value": "Offer" }
|
|
11
11
|
]
|
|
12
12
|
]
|
|
13
13
|
},
|
|
14
|
-
"handler/notification_handler/valid_artifact.js" ,
|
|
14
|
+
"@handler/notification_handler/valid_artifact.js" ,
|
|
15
15
|
{
|
|
16
|
-
"id": "handler/notification_handler/eventlog.js",
|
|
16
|
+
"id": "@handler/notification_handler/eventlog.js",
|
|
17
17
|
"log": "@artifact:strip@.jsonld",
|
|
18
18
|
"dir": "@artifact:strip@"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
"id": "handler/notification_handler/offer_memento.js",
|
|
21
|
+
"id": "@handler/notification_handler/offer_memento.js",
|
|
22
22
|
"actor": {
|
|
23
23
|
"id": "http://localhost:8000/profile/card#me" ,
|
|
24
24
|
"inbox": "http://localhost:8000/inbox/" ,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
] ,
|
|
34
34
|
[
|
|
35
35
|
{
|
|
36
|
-
"id": "handler/notification_handler/jsonpath_filter.js",
|
|
36
|
+
"id": "@handler/notification_handler/jsonpath_filter.js",
|
|
37
37
|
"anyOf": [
|
|
38
38
|
[
|
|
39
39
|
{ "path": "$.type" , "value": "Announce" } ,
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
]
|
|
42
42
|
]
|
|
43
43
|
} ,
|
|
44
|
-
"handler/notification_handler/valid_eventlog.js",
|
|
45
|
-
"handler/notification_handler/add_timemap_link.js"
|
|
44
|
+
"@handler/notification_handler/valid_eventlog.js",
|
|
45
|
+
"@handler/notification_handler/add_timemap_link.js"
|
|
46
46
|
]
|
|
47
47
|
]
|
|
48
48
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"multi": {
|
|
4
4
|
"handlers": [
|
|
5
5
|
[
|
|
6
|
-
"handler/notification_handler/send_notification.js",
|
|
6
|
+
"@handler/notification_handler/send_notification.js",
|
|
7
7
|
{
|
|
8
|
-
"id": "handler/eventlog_notification_handler.js",
|
|
8
|
+
"id": "@handler/eventlog_notification_handler.js",
|
|
9
9
|
"log": "@artifact:strip@.jsonld",
|
|
10
10
|
"dir": "@artifact:strip@"
|
|
11
11
|
}
|
package/lib/handler.js
CHANGED
|
@@ -15,7 +15,15 @@ async function defaultInboxHandler({path,options}) {
|
|
|
15
15
|
|
|
16
16
|
const queue_size = options['queue_size'] ?? 'auto';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
let worker;
|
|
19
|
+
|
|
20
|
+
if (options['notification_handler']) {
|
|
21
|
+
worker = options['notification_handler']
|
|
22
|
+
.replaceAll(/@handler/g,fsPath.resolve(__dirname,'..','handler'));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
worker = fsPath.resolve(__dirname,'..','lib','demoNotificationHandler.js');
|
|
26
|
+
}
|
|
19
27
|
|
|
20
28
|
// Run the notifications using a node.js worker pool
|
|
21
29
|
const pool = new piscina({
|
package/lib/index.js
CHANGED
|
@@ -84,30 +84,51 @@ function doInboxGET(req,res) {
|
|
|
84
84
|
|
|
85
85
|
function doInboxHEAD(req,res) {
|
|
86
86
|
const pathItem = req.url.substring(INBOX_URL.length);
|
|
87
|
+
const id = pathItem.substring(1);
|
|
87
88
|
|
|
88
89
|
logger.debug(`doInboxHEAD (for ${pathItem})`);
|
|
89
90
|
|
|
90
91
|
if (pathItem === '/') {
|
|
91
|
-
|
|
92
|
+
const meta = getBody(`${id}.meta`);
|
|
93
|
+
|
|
94
|
+
if (meta) {
|
|
95
|
+
const metadata = JSON.parse(meta);
|
|
96
|
+
for (let property in metadata) {
|
|
97
|
+
res.setHeader(property,metadata[property]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
res.setHeader('Content-Type','application/ld+json');
|
|
102
|
+
}
|
|
92
103
|
res.writeHead(200);
|
|
93
104
|
res.end();
|
|
94
105
|
return;
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
if (pathItem.match(/^\/[A-Za-z0-9_-]+\.jsonld$/)) {
|
|
98
|
-
const id = pathItem.substring(1);
|
|
99
109
|
const result = getBody(id);
|
|
100
110
|
|
|
101
|
-
if (result) {
|
|
102
|
-
res.
|
|
103
|
-
res.
|
|
104
|
-
res.end();
|
|
111
|
+
if (! result) {
|
|
112
|
+
res.writeHead(403);
|
|
113
|
+
res.end('Forbidden');
|
|
105
114
|
return;
|
|
106
115
|
}
|
|
116
|
+
|
|
117
|
+
const meta = getBody(`${id}.meta`);
|
|
118
|
+
|
|
119
|
+
if (meta) {
|
|
120
|
+
const metadata = JSON.parse(meta);
|
|
121
|
+
for (let property in metadata) {
|
|
122
|
+
res.setHeader(property,metadata[property]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
107
125
|
else {
|
|
108
|
-
res.
|
|
109
|
-
res.end('Forbidden');
|
|
126
|
+
res.setHeader('Content-Type','application/ld+json');
|
|
110
127
|
}
|
|
128
|
+
|
|
129
|
+
res.writeHead(200);
|
|
130
|
+
res.end();
|
|
131
|
+
return;
|
|
111
132
|
}
|
|
112
133
|
else {
|
|
113
134
|
res.writeHead(403);
|
|
@@ -127,17 +148,40 @@ function doInboxGET_Index(req,res) {
|
|
|
127
148
|
"contains": notifications
|
|
128
149
|
};
|
|
129
150
|
|
|
151
|
+
const meta = getBody(`.meta`);
|
|
152
|
+
|
|
153
|
+
if (meta) {
|
|
154
|
+
const metadata = JSON.parse(meta);
|
|
155
|
+
for (let property in metadata) {
|
|
156
|
+
res.setHeader(property,metadata[property]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
res.setHeader('Content-Type','application/ld+json');
|
|
161
|
+
}
|
|
162
|
+
|
|
130
163
|
res.writeHead(200);
|
|
131
164
|
res.end(JSON.stringify(result,null,2));
|
|
132
165
|
}
|
|
133
166
|
|
|
134
167
|
function doInboxGET_Read(req,res) {
|
|
135
168
|
const pathItem = req.url.substring(INBOX_URL.length);
|
|
136
|
-
|
|
137
|
-
const result = getBody(
|
|
169
|
+
const id = pathItem.substring(1);
|
|
170
|
+
const result = getBody(id);
|
|
138
171
|
|
|
139
172
|
if (result) {
|
|
140
|
-
|
|
173
|
+
const meta = getBody(`${id}.meta`);
|
|
174
|
+
|
|
175
|
+
if (meta) {
|
|
176
|
+
const metadata = JSON.parse(meta);
|
|
177
|
+
for (let property in metadata) {
|
|
178
|
+
res.setHeader(property,metadata[property]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
res.setHeader('Content-Type','application/ld+json');
|
|
183
|
+
}
|
|
184
|
+
|
|
141
185
|
res.writeHead(200);
|
|
142
186
|
res.end(result);
|
|
143
187
|
}
|
|
@@ -217,7 +261,6 @@ function getBody(id) {
|
|
|
217
261
|
return fs.readFileSync(INBOX_PATH + '/' + id, {encoding : 'utf-8'});
|
|
218
262
|
}
|
|
219
263
|
catch(e) {
|
|
220
|
-
logger.error(e);
|
|
221
264
|
return null;
|
|
222
265
|
}
|
|
223
266
|
}
|
package/lib/util.js
CHANGED
|
@@ -112,6 +112,8 @@ function dynamic_handler(handler,fallback) {
|
|
|
112
112
|
return handler;
|
|
113
113
|
}
|
|
114
114
|
else {
|
|
115
|
+
// translate dynamic path names
|
|
116
|
+
handler = handler.replaceAll(/@handler/g,fsPath.resolve(__dirname,'..','handler'));
|
|
115
117
|
const abs_handler = path.resolve(handler);
|
|
116
118
|
logger.debug(`trying dynamic load of ${handler} -> ${abs_handler}`);
|
|
117
119
|
delete require.cache[abs_handler];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldn-inbox-server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A demonstration Event Notifications Inbox server",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"server": "npx ldn-inbox-server start-server",
|
|
10
10
|
"demo-post": "curl -X POST -H 'Content-Type: application/ld+json' --data-binary '@examples/offer.jsonld' http://localhost:8000/inbox/",
|
|
11
|
-
"handle-inbox": "npx ldn-inbox-server handler @inbox -hn
|
|
12
|
-
"handle-outbox": "npx ldn-inbox-server handler @outbox -hn
|
|
13
|
-
"handle-eventlog": "npx ldn-inbox-server handler @inbox -hn handler/notification_handler/eventlog.js",
|
|
14
|
-
"handle-inbox-multi": "npx ldn-inbox-server handler @inbox -hn
|
|
15
|
-
"handle-outbox-multi": "npx ldn-inbox-server handler @outbox -hn
|
|
11
|
+
"handle-inbox": "npx ldn-inbox-server handler @inbox -hn @handler/notification_handler/accept.js",
|
|
12
|
+
"handle-outbox": "npx ldn-inbox-server handler @outbox -hn @handler/notification_handler/send_notification.js",
|
|
13
|
+
"handle-eventlog": "npx ldn-inbox-server handler @inbox -hn @handler/notification_handler/eventlog.js",
|
|
14
|
+
"handle-inbox-multi": "npx ldn-inbox-server handler @inbox -hn @handler/notification_handler/multi.js",
|
|
15
|
+
"handle-outbox-multi": "npx ldn-inbox-server handler @outbox -hn @handler/notification_handler/multi.js",
|
|
16
16
|
"clean": "rm -rf error/* inbox/* outbox/* public/events/* public/events/log/* public/artifacts/artifact1 public/artifacts/artifact2 public/artifacts/*.jsonld*"
|
|
17
17
|
},
|
|
18
18
|
"bin": "./bin/ldn-inbox-server.js",
|