@eik/service 3.0.0 → 5.0.0

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,37 @@
1
+ # [5.0.0](https://github.com/eik-lib/service/compare/v4.0.0...v5.0.0) (2024-11-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * set minimum engine ([8d339a3](https://github.com/eik-lib/service/commit/8d339a33b902d916d9a7fe526e6cf05b3553d621))
7
+ * update eik dependencies ([9c8f3af](https://github.com/eik-lib/service/commit/9c8f3afc22cae7139f1baa879d4d40f9ad8c7371))
8
+
9
+
10
+ ### BREAKING CHANGES
11
+
12
+ * returns mimetype text/javascript instead of the deprecated application/javascript.
13
+ * Requires Node >=20.5.0.
14
+
15
+ # [4.0.0](https://github.com/eik-lib/service/compare/v3.0.0...v4.0.0) (2024-11-13)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add content type parser for multipart/form-data ([b629f76](https://github.com/eik-lib/service/commit/b629f762da4e7ad916efd61d73fbebffef67cfeb))
21
+
22
+
23
+ ### chore
24
+
25
+ * upgrade pino ([ec4ecde](https://github.com/eik-lib/service/commit/ec4ecdea4ba0069d9c6d38a322a17a15df5259a3))
26
+ * upgrade to Fastify 5 ([37ec354](https://github.com/eik-lib/service/commit/37ec3541c1b2764b71cc74ec14f37ab2feca1ea1))
27
+
28
+
29
+ ### BREAKING CHANGES
30
+
31
+ * no longer supports the content type `multipart`.
32
+ * Requires Node 20
33
+ * requires fastify 5.x
34
+
1
35
  # [3.0.0](https://github.com/eik-lib/service/compare/v2.3.2...v3.0.0) (2024-08-22)
2
36
 
3
37
 
package/bin/eik-server.js CHANGED
@@ -1,26 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable no-unused-vars */
3
- import Fastify from 'fastify';
4
- import Eik from '../lib/main.js';
3
+ import Fastify from "fastify";
4
+ import Eik from "../lib/main.js";
5
5
 
6
6
  const eik = new Eik();
7
7
 
8
8
  const app = Fastify({
9
- ignoreTrailingSlash: true,
10
- modifyCoreObjects: false,
11
- trustProxy: true,
12
- http2: eik.config.get('http.http2'),
9
+ ignoreTrailingSlash: true,
10
+ modifyCoreObjects: false,
11
+ trustProxy: true,
12
+ http2: eik.config.get("http.http2"),
13
13
  });
14
14
 
15
15
  await app.register(eik.api());
16
16
 
17
17
  try {
18
- await eik.health();
18
+ await eik.health();
19
19
  } catch (error) {
20
- // Do accept errors
20
+ // Do accept errors
21
21
  }
22
22
 
23
23
  await app.listen({
24
- port: eik.config.get('http.port'),
25
- host: eik.config.get('http.address'),
24
+ port: eik.config.get("http.port"),
25
+ host: eik.config.get("http.address"),
26
26
  });
package/lib/config.js CHANGED
@@ -1,171 +1,169 @@
1
1
  /* eslint-disable no-unused-vars */
2
- import convict from 'convict';
3
- import yaml from 'js-yaml';
4
- import pino from 'pino';
5
- import path from 'path';
6
- import fs from 'fs';
7
- import os from 'os';
2
+ import convict from "convict";
3
+ import yaml from "js-yaml";
4
+ import pino from "pino";
5
+ import path from "path";
6
+ import fs from "fs";
7
+ import os from "os";
8
8
 
9
9
  const CWD = process.cwd();
10
10
 
11
11
  let pack = {};
12
12
  try {
13
- pack = JSON.parse(fs.readFileSync(path.join(CWD, 'package.json'), 'utf-8'));
13
+ pack = JSON.parse(fs.readFileSync(path.join(CWD, "package.json"), "utf-8"));
14
14
  } catch (error) {
15
- /* empty */
15
+ /* empty */
16
16
  }
17
17
 
18
- convict.addParser({ extension: ['yml', 'yaml'], parse: yaml.load });
18
+ convict.addParser({ extension: ["yml", "yaml"], parse: yaml.load });
19
19
 
20
20
  convict.addFormat({
21
- name: 'secret-string',
22
- validate: (value) => {
23
- if (typeof value !== 'string') {
24
- throw new Error('Value must be a String');
25
- }
26
- },
27
- coerce: (value) => {
28
- if (path.isAbsolute(value)) {
29
- try {
30
- const file = fs.readFileSync(value);
31
- return file.toString();
32
- } catch (error) {
33
- throw new Error(
34
- `Config could not load secret from path: ${value}`,
35
- );
36
- }
37
- }
38
- return value;
39
- },
21
+ name: "secret-string",
22
+ validate: (value) => {
23
+ if (typeof value !== "string") {
24
+ throw new Error("Value must be a String");
25
+ }
26
+ },
27
+ coerce: (value) => {
28
+ if (path.isAbsolute(value)) {
29
+ try {
30
+ const file = fs.readFileSync(value);
31
+ return file.toString();
32
+ } catch (error) {
33
+ throw new Error(`Config could not load secret from path: ${value}`);
34
+ }
35
+ }
36
+ return value;
37
+ },
40
38
  });
41
39
 
42
40
  const conf = convict({
43
- name: {
44
- doc: 'Name of the apllication',
45
- default: pack.name,
46
- format: String,
47
- },
48
- env: {
49
- doc: 'Applicaton environments',
50
- format: ['development', 'production'],
51
- default: 'development',
52
- env: 'NODE_ENV',
53
- arg: 'node-env',
54
- },
55
- metrics: {
56
- format: Boolean,
57
- default: true,
58
- env: 'METRICS',
59
- },
60
- log: {
61
- level: {
62
- doc: 'Log level to log at',
63
- format: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'],
64
- default: 'info',
65
- env: 'LOG_LEVEL',
66
- arg: 'log-level',
67
- },
68
- },
69
- http: {
70
- http2: {
71
- doc: 'Enable http2 for the server',
72
- format: Boolean,
73
- default: false,
74
- env: 'HTTP_HTTP2',
75
- },
76
- address: {
77
- doc: 'The address the http server should bind to',
78
- format: String,
79
- default: 'localhost',
80
- env: 'HTTP_ADDRESS',
81
- },
82
- port: {
83
- doc: 'The port the http server should bind to',
84
- format: 'port',
85
- default: 4001,
86
- env: 'HTTP_PORT',
87
- },
88
- },
89
- compression: {
90
- global: {
91
- doc: 'Enable global compression for all http routes',
92
- format: Boolean,
93
- default: true,
94
- env: 'COMPRESSION_GLOBAL',
95
- },
96
- },
97
- jwt: {
98
- secret: {
99
- doc: 'Secret used for JWT signing',
100
- format: 'secret-string',
101
- default: 'change_me',
102
- env: 'AUTH_JWT_SECRET',
103
- sensitive: true,
104
- },
105
- expire: {
106
- doc: 'Expire time for JWT',
107
- format: String,
108
- default: '60d',
109
- env: 'AUTH_JWT_EXPIRE',
110
- },
111
- },
112
- basicAuth: {
113
- type: {
114
- doc: 'Type of basic auth to use',
115
- format: ['key', 'disabled'],
116
- default: 'key',
117
- env: 'BASIC_AUTH_TYPE',
118
- },
119
- key: {
120
- doc: 'Key used for basic authorization',
121
- format: 'secret-string',
122
- default: 'change_me',
123
- env: 'BASIC_AUTH_KEY',
124
- sensitive: true,
125
- },
126
- },
127
- organization: {
128
- name: {
129
- doc: 'Organization name - Used as a folder name in the storage of files',
130
- format: String,
131
- default: 'local',
132
- env: 'ORG_NAME',
133
- },
134
- hostnames: {
135
- doc: 'Hostnames the organization maps to',
136
- format: Array,
137
- default: ['localhost', '127.0.0.1'],
138
- env: 'ORG_HOSTNAMES',
139
- },
140
- },
141
- sink: {
142
- type: {
143
- doc: 'Type of sink to use',
144
- format: ['fs', 'mem', 'test'],
145
- default: 'fs',
146
- env: 'SINK_TYPE',
147
- },
148
- path: {
149
- doc: 'Absolute path to store files in when using the "fs" sink',
150
- format: String,
151
- default: path.join(os.tmpdir(), 'eik'),
152
- env: 'SINK_PATH',
153
- },
154
- },
41
+ name: {
42
+ doc: "Name of the apllication",
43
+ default: pack.name,
44
+ format: String,
45
+ },
46
+ env: {
47
+ doc: "Applicaton environments",
48
+ format: ["development", "production"],
49
+ default: "development",
50
+ env: "NODE_ENV",
51
+ arg: "node-env",
52
+ },
53
+ metrics: {
54
+ format: Boolean,
55
+ default: true,
56
+ env: "METRICS",
57
+ },
58
+ log: {
59
+ level: {
60
+ doc: "Log level to log at",
61
+ format: ["trace", "debug", "info", "warn", "error", "fatal"],
62
+ default: "info",
63
+ env: "LOG_LEVEL",
64
+ arg: "log-level",
65
+ },
66
+ },
67
+ http: {
68
+ http2: {
69
+ doc: "Enable http2 for the server",
70
+ format: Boolean,
71
+ default: false,
72
+ env: "HTTP_HTTP2",
73
+ },
74
+ address: {
75
+ doc: "The address the http server should bind to",
76
+ format: String,
77
+ default: "localhost",
78
+ env: "HTTP_ADDRESS",
79
+ },
80
+ port: {
81
+ doc: "The port the http server should bind to",
82
+ format: "port",
83
+ default: 4001,
84
+ env: "HTTP_PORT",
85
+ },
86
+ },
87
+ compression: {
88
+ global: {
89
+ doc: "Enable global compression for all http routes",
90
+ format: Boolean,
91
+ default: true,
92
+ env: "COMPRESSION_GLOBAL",
93
+ },
94
+ },
95
+ jwt: {
96
+ secret: {
97
+ doc: "Secret used for JWT signing",
98
+ format: "secret-string",
99
+ default: "change_me",
100
+ env: "AUTH_JWT_SECRET",
101
+ sensitive: true,
102
+ },
103
+ expire: {
104
+ doc: "Expire time for JWT",
105
+ format: String,
106
+ default: "60d",
107
+ env: "AUTH_JWT_EXPIRE",
108
+ },
109
+ },
110
+ basicAuth: {
111
+ type: {
112
+ doc: "Type of basic auth to use",
113
+ format: ["key", "disabled"],
114
+ default: "key",
115
+ env: "BASIC_AUTH_TYPE",
116
+ },
117
+ key: {
118
+ doc: "Key used for basic authorization",
119
+ format: "secret-string",
120
+ default: "change_me",
121
+ env: "BASIC_AUTH_KEY",
122
+ sensitive: true,
123
+ },
124
+ },
125
+ organization: {
126
+ name: {
127
+ doc: "Organization name - Used as a folder name in the storage of files",
128
+ format: String,
129
+ default: "local",
130
+ env: "ORG_NAME",
131
+ },
132
+ hostnames: {
133
+ doc: "Hostnames the organization maps to",
134
+ format: Array,
135
+ default: ["localhost", "127.0.0.1"],
136
+ env: "ORG_HOSTNAMES",
137
+ },
138
+ },
139
+ sink: {
140
+ type: {
141
+ doc: "Type of sink to use",
142
+ format: ["fs", "mem", "test"],
143
+ default: "fs",
144
+ env: "SINK_TYPE",
145
+ },
146
+ path: {
147
+ doc: 'Absolute path to store files in when using the "fs" sink',
148
+ format: String,
149
+ default: path.join(os.tmpdir(), "eik"),
150
+ env: "SINK_PATH",
151
+ },
152
+ },
155
153
  });
156
154
 
157
- const env = conf.get('env');
155
+ const env = conf.get("env");
158
156
 
159
157
  // @ts-expect-error This is in fact callable
160
158
  const logger = pino({
161
- level: conf.get('log.level'),
162
- name: conf.get('name'),
159
+ level: conf.get("log.level"),
160
+ name: conf.get("name"),
163
161
  });
164
162
 
165
163
  try {
166
- conf.loadFile(path.join(CWD, 'config', `${env}.yaml`));
164
+ conf.loadFile(path.join(CWD, "config", `${env}.yaml`));
167
165
  } catch (error) {
168
- logger.error(error);
166
+ logger.error(error);
169
167
  }
170
168
 
171
169
  conf.validate();