@dnax/core 0.25.1 → 0.27.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/app/index.ts +6 -4
- package/config/index.ts +39 -13
- package/package.json +1 -1
- package/types/index.ts +4 -0
- package/utils/index.ts +4 -1
package/app/index.ts
CHANGED
|
@@ -85,22 +85,24 @@ async function runApp(config?: configRunApp, clb?: Function) {
|
|
|
85
85
|
process.env.NODE_ENV === "production"
|
|
86
86
|
? "production"
|
|
87
87
|
: process.env?.NODE_ENV || "development"
|
|
88
|
-
}`.
|
|
89
|
-
info += `Server: http://localhost:${PORT}\n`.
|
|
88
|
+
}`.green + "\n";
|
|
89
|
+
info += `Server: http://localhost:${PORT}\n`.green;
|
|
90
|
+
//info += `Jwt Secret: ${Cfg.server.jwt?.secret}\n`.gray;
|
|
90
91
|
info += `\n`;
|
|
91
92
|
info += "TENANTS :".gray.italic.underline;
|
|
92
93
|
info += `\n`;
|
|
93
94
|
Cfg.tenants?.map((t: any) => {
|
|
94
95
|
info += `\n${t?.name?.blue || "_"} : ${t?.id?.green}`.italic;
|
|
95
96
|
});
|
|
96
|
-
info += `\n`;
|
|
97
|
+
info += `\n\n`;
|
|
98
|
+
info += `🔄 ${new Date().toLocaleString()}`.gray;
|
|
97
99
|
|
|
98
100
|
if (clb) clb();
|
|
99
101
|
|
|
100
102
|
console.log(
|
|
101
103
|
boxen(info, {
|
|
102
104
|
borderStyle: "round",
|
|
103
|
-
title: `@dnax/server ${pkg.version}
|
|
105
|
+
title: `@dnax/server ${pkg.version}`,
|
|
104
106
|
padding: 1,
|
|
105
107
|
dimBorder: true,
|
|
106
108
|
titleAlignment: "center",
|
package/config/index.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { cors } from "hono/cors";
|
|
2
2
|
import { Config } from "./../types/index";
|
|
3
3
|
import type { Config } from "../types";
|
|
4
|
+
|
|
5
|
+
import { systemCache } from "../lib/bento";
|
|
4
6
|
import { Glob } from "bun";
|
|
5
7
|
import path from "path";
|
|
8
|
+
import { v4 } from "uuid";
|
|
9
|
+
|
|
6
10
|
const ROOT_PATH = process.cwd();
|
|
7
11
|
const Cfg: Config = {
|
|
12
|
+
clusterMode: false,
|
|
8
13
|
cwd: process.cwd(),
|
|
9
14
|
server: {
|
|
10
15
|
port: 4000,
|
|
16
|
+
jwt: {
|
|
17
|
+
secret: null,
|
|
18
|
+
expiresIn: "7d",
|
|
19
|
+
},
|
|
11
20
|
},
|
|
12
21
|
|
|
13
22
|
tenants: [
|
|
@@ -22,22 +31,39 @@ const Cfg: Config = {
|
|
|
22
31
|
],
|
|
23
32
|
};
|
|
24
33
|
|
|
25
|
-
function setCfg(config: Config) {
|
|
34
|
+
async function setCfg(config: Config) {
|
|
26
35
|
if (!config?.clusterMode) Cfg.clusterMode = true;
|
|
27
36
|
Cfg.clusterMode = config?.clusterMode ?? false;
|
|
28
|
-
Cfg.server =
|
|
37
|
+
Cfg.server = {
|
|
38
|
+
...Cfg.server,
|
|
39
|
+
...config.server,
|
|
40
|
+
};
|
|
29
41
|
Cfg.tenants = config?.tenants;
|
|
30
42
|
Cfg.email = config?.email;
|
|
31
43
|
|
|
32
|
-
Cfg
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
if (!Cfg?.server?.jwt?.expiresIn) {
|
|
45
|
+
Cfg["server"]["jwt"]["expiresIn"] = "7d";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!Cfg?.server?.jwt.secret && process?.env?.JWT_SECRET) {
|
|
49
|
+
Cfg.server.jwt.secret = process.env.JWT_SECRET;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!Cfg?.server?.jwt?.secret) {
|
|
53
|
+
let jwtSecret = await systemCache.get(".jwt.json");
|
|
54
|
+
if (!jwtSecret) {
|
|
55
|
+
jwtSecret = v4().replaceAll("-", "");
|
|
56
|
+
await systemCache.set({
|
|
57
|
+
key: ".jwt.json",
|
|
58
|
+
value: jwtSecret,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
Cfg.server.jwt.secret = jwtSecret;
|
|
62
|
+
}
|
|
38
63
|
|
|
39
|
-
if (!Cfg.
|
|
40
|
-
console.error("
|
|
64
|
+
if (!Cfg?.server.jwt?.secret) {
|
|
65
|
+
console.error("JWT_SECRET is not defined");
|
|
66
|
+
process.exit(1);
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
if (!Cfg?.server.port) {
|
|
@@ -56,15 +82,15 @@ function setCfg(config: Config) {
|
|
|
56
82
|
async function loadCfg() {
|
|
57
83
|
let configPath = process.cwd() + `/config/app.ts`;
|
|
58
84
|
await import(path.join(configPath))
|
|
59
|
-
.then((inject: { default: Config }) => {
|
|
85
|
+
.then(async (inject: { default: Config }) => {
|
|
60
86
|
// Cfg.tenants = inject.default?.tenants || [];
|
|
61
87
|
// Cfg.server = inject.default?.server || [];
|
|
62
88
|
|
|
63
|
-
setCfg(inject.default);
|
|
89
|
+
await setCfg(inject.default);
|
|
64
90
|
//console.log(Cfg);
|
|
65
91
|
})
|
|
66
92
|
.catch((err) => {
|
|
67
|
-
console.error("/config/app.ts
|
|
93
|
+
console.error("/config/app.ts ::", err?.message);
|
|
68
94
|
});
|
|
69
95
|
}
|
|
70
96
|
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
package/utils/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { mapKeys } from "radash";
|
|
|
4
4
|
import { cleanDoubleSlashes } from "ufo";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { parse, format } from "@lukeed/ms";
|
|
7
|
+
import { Cfg } from "../config";
|
|
7
8
|
import jwto from "jsonwebtoken";
|
|
8
9
|
import generateUniqueId from "generate-unique-id";
|
|
9
10
|
import dayjs from "dayjs";
|
|
@@ -15,7 +16,9 @@ import dotJson from "dot-object";
|
|
|
15
16
|
import deepCopy from "deepcopy";
|
|
16
17
|
import { applyPatch, createPatch, Pointer } from "rfc6902";
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
const JWT_SECRET = process?.env?.JWT_SECRET || null;
|
|
21
|
+
|
|
19
22
|
import * as _ from "radash";
|
|
20
23
|
import { email } from "../lib/mail";
|
|
21
24
|
|