@eik/service 3.0.0 → 4.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 +20 -0
- package/bin/eik-server.js +10 -10
- package/lib/config.js +143 -145
- package/lib/main.js +840 -897
- package/lib/utils.js +36 -36
- package/package.json +12 -12
- package/types/main.d.ts +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# [4.0.0](https://github.com/eik-lib/service/compare/v3.0.0...v4.0.0) (2024-11-13)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add content type parser for multipart/form-data ([b629f76](https://github.com/eik-lib/service/commit/b629f762da4e7ad916efd61d73fbebffef67cfeb))
|
7
|
+
|
8
|
+
|
9
|
+
### chore
|
10
|
+
|
11
|
+
* upgrade pino ([ec4ecde](https://github.com/eik-lib/service/commit/ec4ecdea4ba0069d9c6d38a322a17a15df5259a3))
|
12
|
+
* upgrade to Fastify 5 ([37ec354](https://github.com/eik-lib/service/commit/37ec3541c1b2764b71cc74ec14f37ab2feca1ea1))
|
13
|
+
|
14
|
+
|
15
|
+
### BREAKING CHANGES
|
16
|
+
|
17
|
+
* no longer supports the content type `multipart`.
|
18
|
+
* Requires Node 20
|
19
|
+
* requires fastify 5.x
|
20
|
+
|
1
21
|
# [3.0.0](https://github.com/eik-lib/service/compare/v2.3.2...v3.0.0) (2024-08-22)
|
2
22
|
|
3
23
|
|
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
|
4
|
-
import Eik from
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
18
|
+
await eik.health();
|
19
19
|
} catch (error) {
|
20
|
-
|
20
|
+
// Do accept errors
|
21
21
|
}
|
22
22
|
|
23
23
|
await app.listen({
|
24
|
-
|
25
|
-
|
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
|
3
|
-
import yaml from
|
4
|
-
import pino from
|
5
|
-
import path from
|
6
|
-
import fs from
|
7
|
-
import os from
|
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
|
-
|
13
|
+
pack = JSON.parse(fs.readFileSync(path.join(CWD, "package.json"), "utf-8"));
|
14
14
|
} catch (error) {
|
15
|
-
|
15
|
+
/* empty */
|
16
16
|
}
|
17
17
|
|
18
|
-
convict.addParser({ extension: [
|
18
|
+
convict.addParser({ extension: ["yml", "yaml"], parse: yaml.load });
|
19
19
|
|
20
20
|
convict.addFormat({
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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(
|
155
|
+
const env = conf.get("env");
|
158
156
|
|
159
157
|
// @ts-expect-error This is in fact callable
|
160
158
|
const logger = pino({
|
161
|
-
|
162
|
-
|
159
|
+
level: conf.get("log.level"),
|
160
|
+
name: conf.get("name"),
|
163
161
|
});
|
164
162
|
|
165
163
|
try {
|
166
|
-
|
164
|
+
conf.loadFile(path.join(CWD, "config", `${env}.yaml`));
|
167
165
|
} catch (error) {
|
168
|
-
|
166
|
+
logger.error(error);
|
169
167
|
}
|
170
168
|
|
171
169
|
conf.validate();
|