ldn-inbox-server 1.8.2 → 1.8.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/.dockerignore +10 -0
- package/.env-docker +16 -0
- package/Dockerfile +19 -0
- package/README.md +20 -0
- package/config/inbox_config.json +1 -1
- package/ecosystem.config.js-example +0 -8
- package/handler/notification_handler/multi.js +23 -10
- package/lib/util.js +4 -4
- package/package.json +1 -1
package/.dockerignore
ADDED
package/.env-docker
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LOG4JS=INFO
|
|
2
|
+
LDN_SERVER_HOST=0.0.0.0
|
|
3
|
+
LDN_SERVER_PORT=8000
|
|
4
|
+
LDN_SERVER_INBOX_GLOB="^.*\.jsonld$"
|
|
5
|
+
LDN_SERVER_BASEURL=http://0.0.0.0:8000
|
|
6
|
+
LDN_SERVER_INBOX_BATH_SIZE=5
|
|
7
|
+
LDN_SERVER_LOCKDIR=.lockdir
|
|
8
|
+
LDN_SERVER_INBOX_URL=inbox/
|
|
9
|
+
LDN_SERVER_INBOX_PATH=./inbox
|
|
10
|
+
LDN_SERVER_ERROR_PATH=./error
|
|
11
|
+
LDN_SERVER_OUTBOX_PATH=./outbox
|
|
12
|
+
LDN_SERVER_PUBLIC_PATH=./public
|
|
13
|
+
#LDN_SERVER_JSON_SCHEMA=./config/notification_schema.json
|
|
14
|
+
LDN_SERVER_INBOX_CONFIG=./config/inbox_config.json
|
|
15
|
+
LDN_SERVER_OUTBOX_CONFIG=./config/outbox_config.json
|
|
16
|
+
LDN_SERVER_HAS_PUBLIC_INBOX=1
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
FROM node:18-alpine3.20
|
|
2
|
+
|
|
3
|
+
ENV NODE_ENV=production
|
|
4
|
+
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
COPY .env-docker ./.env
|
|
8
|
+
|
|
9
|
+
COPY ecosystem.config.js-example ./ecosystem.config.js
|
|
10
|
+
|
|
11
|
+
COPY package*.json ./
|
|
12
|
+
|
|
13
|
+
RUN npm install && npm install -g pm2
|
|
14
|
+
|
|
15
|
+
COPY . .
|
|
16
|
+
|
|
17
|
+
EXPOSE 8000
|
|
18
|
+
|
|
19
|
+
CMD [ "pm2-runtime" , "start", "ecosystem.config.js" ]
|
package/README.md
CHANGED
|
@@ -272,6 +272,26 @@ Generate a ISO8601 date time string.
|
|
|
272
272
|
Parse a path containing `.json` | `.jsonld` | `.json5` | `.yaml` | `.yml` into a
|
|
273
273
|
JavaScript object.
|
|
274
274
|
|
|
275
|
+
## Docker
|
|
276
|
+
|
|
277
|
+
Pull
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
docker pull hochstenbach/ldn-inbox-server:v0.0.1
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
docker run -p 8000:8000 hochstenbach/ldn-inbox-server:v0.0.1
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Post a notification:
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
curl -X POST -H 'Content-Type: application/ld+json' --data-binary '@examples/offer.jsonld' http://localhost:8000/inbox/
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Check the inbox: http://localhost:8000/inbox/
|
|
294
|
+
|
|
275
295
|
## See also
|
|
276
296
|
|
|
277
297
|
- [mellon-server](https://www.npmjs.com/package/mellon-server)
|
package/config/inbox_config.json
CHANGED
|
@@ -3,14 +3,6 @@ module.exports = {
|
|
|
3
3
|
{
|
|
4
4
|
name : "ldn-inbox-server",
|
|
5
5
|
script : "./bin/ldn-inbox-server.js start-server"
|
|
6
|
-
} ,
|
|
7
|
-
{
|
|
8
|
-
name : "ldn-inbox-inbox",
|
|
9
|
-
script : "LOG4JS=info ./bin/ldn-inbox-server.js handler @inbox --loop 20 -hn ./handler/notification_handler/multi.js"
|
|
10
|
-
} ,
|
|
11
|
-
{
|
|
12
|
-
name : "ldn-inbox-outbox",
|
|
13
|
-
script : "LOG4JS=info ./bin/ldn-inbox-server.js handler @outbox --loop 20 -hn ./handler/notification_handler/multi.js"
|
|
14
6
|
}
|
|
15
7
|
]
|
|
16
8
|
}
|
|
@@ -13,8 +13,8 @@ const md5 = require('md5');
|
|
|
13
13
|
* need to run on an notifiction message. The inner array defines the steps: a
|
|
14
14
|
* sequence of handlers that need to success.
|
|
15
15
|
*
|
|
16
|
-
* Optionally a configuration for a handler can contain the property `$
|
|
17
|
-
* to true to force the
|
|
16
|
+
* Optionally a configuration for a handler can contain the property `$lock` set
|
|
17
|
+
* to true to force the singular execution of this handler.
|
|
18
18
|
*/
|
|
19
19
|
async function handle({path,options,_,notification}) {
|
|
20
20
|
let success = false;
|
|
@@ -70,7 +70,11 @@ async function handle({path,options,_,notification}) {
|
|
|
70
70
|
return await handler({path,options,config,notification});
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
if (result
|
|
73
|
+
if (! result) {
|
|
74
|
+
logger.error(`workflow[${i}] : failed ${step} (no results)`);
|
|
75
|
+
thisWorkflow = result['failure'];
|
|
76
|
+
}
|
|
77
|
+
else if (result['break']) {
|
|
74
78
|
logger.info(`workflow[${i}] : breaks ${step} with ${result['success']}`);
|
|
75
79
|
thisWorkflow = result['success'];
|
|
76
80
|
}
|
|
@@ -140,8 +144,10 @@ async function handle({path,options,_,notification}) {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
async function maybeLock(step,config,callback) {
|
|
143
|
-
if (config['$
|
|
144
|
-
const lockDir = process.env.
|
|
147
|
+
if (config['$lock']) {
|
|
148
|
+
const lockDir = process.env.LDN_SERVER_LOCK_DIR || '.lockdir';
|
|
149
|
+
const lockStale = process.env.LDN_SERVER_LOCK_STALE || 10000;
|
|
150
|
+
const lockRetries = process.env.LDN_SERVER_LOCK_RETRIES || 10;
|
|
145
151
|
|
|
146
152
|
if (! fs.existsSync(lockDir)) {
|
|
147
153
|
logger.debug(`creating lock dir ${lockDir}`);
|
|
@@ -155,15 +161,22 @@ async function maybeLock(step,config,callback) {
|
|
|
155
161
|
fs.writeFileSync(lockFile,'');
|
|
156
162
|
}
|
|
157
163
|
|
|
158
|
-
|
|
164
|
+
let result = null;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
logger.debug(`locking ${step} using ${lockFile}`);
|
|
159
168
|
|
|
160
|
-
|
|
169
|
+
const unlock = await lockfile.lock(lockFile, { stale : lockStale , retries: lockRetries });
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
result = await callback();
|
|
163
172
|
|
|
164
|
-
|
|
173
|
+
logger.debug(`unlocking ${step} from ${lockFile}`);
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
unlock();
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
logger.error(`lock failed: ${e.message}`);
|
|
179
|
+
}
|
|
167
180
|
|
|
168
181
|
return result;
|
|
169
182
|
}
|
package/lib/util.js
CHANGED
|
@@ -122,10 +122,10 @@ function moveTo(path,destination) {
|
|
|
122
122
|
|
|
123
123
|
const newPath = destPath + '/' + fsPath.basename(path);
|
|
124
124
|
|
|
125
|
-
fs.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
125
|
+
fs.copyFileSync(fsPath.resolve(path),fsPath.resolve(newPath));
|
|
126
|
+
fs.unlinkSync(fsPath.resolve(path));
|
|
127
|
+
|
|
128
|
+
logger.info(`moving ${path} to${newPath}`);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
function dynamic_handler(handler,fallback) {
|