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 ADDED
@@ -0,0 +1,10 @@
1
+ node_modules
2
+ npm-debug.log
3
+ Dockerfile
4
+ .env
5
+ .dockerignore
6
+ .git
7
+ .gitignore
8
+ ecosystem.config.js
9
+ output/*.jsonld
10
+ inbox/*.jsonld
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)
@@ -27,7 +27,7 @@
27
27
  },
28
28
  {
29
29
  "id": "@handler/notification_handler/offer_memento.js",
30
- "$sequential": true,
30
+ "$lock": true,
31
31
  "actor": {
32
32
  "id": "http://localhost:8000/profile/card#me" ,
33
33
  "inbox": "http://localhost:8000/inbox/" ,
@@ -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 `$sequential` set
17
- * to true to force the sequential execution of this handler.
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['break']) {
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['$sequential']) {
144
- const lockDir = process.env.LDN_SERVER_LOCKDIR || '.lockdir';
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
- logger.debug(`locking ${step} using ${lockFile}`);
164
+ let result = null;
165
+
166
+ try {
167
+ logger.debug(`locking ${step} using ${lockFile}`);
159
168
 
160
- const unlock = await lockfile.lock(lockFile);
169
+ const unlock = await lockfile.lock(lockFile, { stale : lockStale , retries: lockRetries });
161
170
 
162
- const result = await callback();
171
+ result = await callback();
163
172
 
164
- logger.debug(`unlocking ${step} from ${lockFile}`);
173
+ logger.debug(`unlocking ${step} from ${lockFile}`);
165
174
 
166
- unlock();
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.rename(fsPath.resolve(path), fsPath.resolve(newPath), function (err) {
126
- if (err) throw err
127
- logger.info(`moving ${path} to${newPath}`);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldn-inbox-server",
3
- "version": "1.8.2",
3
+ "version": "1.8.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>",