@eik/service 2.0.162 → 2.0.164

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [2.0.164](https://github.com/eik-lib/service/compare/v2.0.163...v2.0.164) (2024-07-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * deprecate customSink and built-in sinks ([a1bd266](https://github.com/eik-lib/service/commit/a1bd2662d531994afcb9a591001d3100c97e8dcc))
7
+
8
+ ## [2.0.163](https://github.com/eik-lib/service/compare/v2.0.162...v2.0.163) (2024-07-29)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * sending in service default config to the FS sink ([#492](https://github.com/eik-lib/service/issues/492)) ([f9025f6](https://github.com/eik-lib/service/commit/f9025f61af27a6957717d9a0fd662ba28b336392))
14
+
1
15
  ## [2.0.162](https://github.com/eik-lib/service/compare/v2.0.161...v2.0.162) (2024-07-08)
2
16
 
3
17
 
package/README.md CHANGED
@@ -1,2 +1,67 @@
1
- # service
2
- Eik REST API - As a standalone running HTTP service
1
+ # Eik HTTP Service
2
+
3
+ As a standalone running HTTP service exposing the Eik Service.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install @eik/service
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ This server can either be run as a Node executable, or as a Fastify plugin.
14
+
15
+ ### CLI
16
+
17
+ This spins up the built-in Fastify server using configuration from your `config/` folder, or from environment variables.
18
+
19
+ ```sh
20
+ npx @eik/service
21
+ ```
22
+
23
+ ### Fastify plugin
24
+
25
+ For a production setup, the Fastify plugin method is recommended.
26
+
27
+ ```js
28
+ import fastify from 'fastify';
29
+ import Service from '@eik/service';
30
+ import SinkGoogleCloudStorage from '@eik/sink-gcs';
31
+
32
+ // Set up the Google Cloud Storage sink
33
+ // https://github.com/eik-lib/sink-gcs?tab=readme-ov-file#example
34
+ const sink = new SinkGoogleCloudStorage({
35
+ credentials: {
36
+ client_email: 'a@email.address',
37
+ private_key: '[ ...snip... ]',
38
+ projectId: 'myProject',
39
+ },
40
+ });
41
+
42
+ // Set up the Eik service as a plugin
43
+ const service = new Service({ sink });
44
+
45
+ // Set up Fastify
46
+ const app = fastify({
47
+ ignoreTrailingSlash: true,
48
+ modifyCoreObjects: false,
49
+ trustProxy: true,
50
+ });
51
+
52
+ // Register the Eik service in Fastify
53
+ app.register(service.api());
54
+
55
+ // Start the server
56
+ const run = async () => {
57
+ await service.health();
58
+ await app.listen(
59
+ service.config.get('http.port'),
60
+ service.config.get('http.address'),
61
+ );
62
+ };
63
+
64
+ run();
65
+ ```
66
+
67
+ The example above shows the Google Cloud Storage sink. You can also use the [file system sink](https://github.com/eik-lib/sink-file-system), or implement the [sink interface](https://github.com/eik-lib/sink) for your own custom storage backend.
package/bin/eik-server.js CHANGED
@@ -20,4 +20,7 @@ try {
20
20
  // Do accept errors
21
21
  }
22
22
 
23
- await app.listen(eik.config.get('http.port'), eik.config.get('http.address'));
23
+ await app.listen({
24
+ port: eik.config.get('http.port'),
25
+ host: eik.config.get('http.address')
26
+ });
package/lib/main.js CHANGED
@@ -5,32 +5,48 @@ import pino from 'pino';
5
5
  import cors from '@fastify/cors';
6
6
  import jwt from '@fastify/jwt';
7
7
  import eik from '@eik/core';
8
+ import SinkMemory from '@eik/sink-memory';
9
+ import SinkFileSystem from '@eik/sink-file-system';
8
10
 
9
11
 
10
12
  import config from './config.js';
11
13
  import * as utils from './utils.js';
12
14
 
15
+ /**
16
+ * @typedef {object} EikServiceOptions
17
+ * @property {import('@eik/sink').default} [sink]
18
+ * @property {import('@eik/sink').default} [customSink] [Deprecated] Use sink instead
19
+ * @property {string} [aliasCacheControl]
20
+ * @property {string} [notFoundCacheControl="public, max-age=5"]
21
+ */
22
+
13
23
  const EikService = class EikService {
14
- constructor({
15
- customSink,
16
- notFoundCacheControl,
17
- aliasCacheControl,
18
- } = {}) {
24
+ /**
25
+ * @param {EikServiceOptions} [options={}]
26
+ */
27
+ constructor(options = {}) {
28
+ let { sink } = options;
29
+ const {
30
+ customSink,
31
+ notFoundCacheControl,
32
+ aliasCacheControl,
33
+ } = options;
19
34
  this._notFoundCacheControl = notFoundCacheControl || 'public, max-age=5';
20
35
  const logger = pino({
36
+ // @ts-ignore
21
37
  level: config.get('log.level'),
22
38
  name: config.get('name'),
23
39
  });
24
40
 
25
- let sink;
26
41
  if (customSink) {
42
+ logger.warn('The `customSink` option is deprecated and will be removed at a later stage. Use `sink` to remove this warning.');
27
43
  sink = customSink;
28
44
  } else if (config.get('sink.type') === 'mem') {
29
45
  logger.info(`Server is running with a in memory sink. Uploaded files will be lost on restart!`);
30
- sink = new eik.sink.MEM();
46
+ sink = new SinkMemory();
31
47
  } else {
32
48
  logger.info(`Server is running with the file system sink. Uploaded files will be stored under "${config.get('sink.path')}"`);
33
- sink = new eik.sink.FS();
49
+ sink = new SinkFileSystem({ sinkFsRootPath: config.get('sink.path') });
34
50
  }
35
51
 
36
52
  // Transform organization config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/service",
3
- "version": "2.0.162",
3
+ "version": "2.0.164",
4
4
  "description": "Eik REST API as a standalone HTTP service",
5
5
  "type": "module",
6
6
  "main": "./lib/main.js",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "scripts": {
13
13
  "start": "node ./bin/eik-server.js | pino-pretty",
14
- "test": "LOG_LEVEL=fatal tap ./test --disable-coverage --allow-empty-coverage --serial=test",
15
- "test:snapshots": "LOG_LEVEL=fatal tap --snapshot --disable-coverage --allow-empty-coverage --serial=test",
14
+ "test": "cross-env LOG_LEVEL=fatal tap ./test --disable-coverage --allow-empty-coverage --serial=test",
15
+ "test:snapshots": "cross-env LOG_LEVEL=fatal tap --snapshot --disable-coverage --allow-empty-coverage --serial=test",
16
16
  "lint:fix": "eslint --fix .",
17
17
  "lint": "eslint ."
18
18
  },
@@ -33,12 +33,15 @@
33
33
  },
34
34
  "homepage": "https://github.com/eik-lib/service#readme",
35
35
  "dependencies": {
36
- "@eik/core": "1.3.47",
37
- "convict": "6.2.4",
38
- "fastify": "4.28.0",
36
+ "@eik/core": "1.3.48",
37
+ "@eik/sink": "1.2.5",
38
+ "@eik/sink-file-system": "1.0.1",
39
+ "@eik/sink-memory": "1.1.1",
39
40
  "@fastify/compress": "6.5.0",
40
41
  "@fastify/cors": "8.5.0",
41
42
  "@fastify/jwt": "7.2.4",
43
+ "convict": "6.2.4",
44
+ "fastify": "4.28.0",
42
45
  "http-errors": "2.0.0",
43
46
  "js-yaml": "4.1.0",
44
47
  "pino": "8.21.0"
@@ -47,6 +50,7 @@
47
50
  "@babel/eslint-parser": "7.24.6",
48
51
  "@semantic-release/changelog": "6.0.3",
49
52
  "@semantic-release/git": "10.0.1",
53
+ "cross-env": "^7.0.3",
50
54
  "eslint": "8.57.0",
51
55
  "eslint-config-airbnb-base": "15.0.0",
52
56
  "eslint-config-prettier": "9.1.0",