@dnax/core 0.25.0 → 0.26.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 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
- }`.italic.blue.green + "\n";
89
- info += `Server: http://localhost:${PORT}\n`.italic.blue;
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}`.italic,
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,21 @@
1
1
  import { cors } from "hono/cors";
2
2
  import { Config } from "./../types/index";
3
3
  import type { Config } from "../types";
4
+ import { systemCache } from "../lib/bento";
4
5
  import { Glob } from "bun";
5
6
  import path from "path";
7
+ import { v4 } from "uuid";
8
+
6
9
  const ROOT_PATH = process.cwd();
7
10
  const Cfg: Config = {
11
+ clusterMode: false,
8
12
  cwd: process.cwd(),
9
13
  server: {
10
14
  port: 4000,
15
+ jwt: {
16
+ secret: null,
17
+ expiresIn: "7d",
18
+ },
11
19
  },
12
20
 
13
21
  tenants: [
@@ -22,22 +30,36 @@ const Cfg: Config = {
22
30
  ],
23
31
  };
24
32
 
25
- function setCfg(config: Config) {
33
+ async function setCfg(config: Config) {
26
34
  if (!config?.clusterMode) Cfg.clusterMode = true;
27
35
  Cfg.clusterMode = config?.clusterMode ?? false;
28
- Cfg.server = config.server;
36
+ Cfg.server = {
37
+ ...Cfg.server,
38
+ ...config.server,
39
+ };
29
40
  Cfg.tenants = config?.tenants;
30
41
  Cfg.email = config?.email;
31
42
 
32
- Cfg.studio = {
33
- enabled: config.studio?.enabled ?? false,
34
- enableIps: config.studio?.enableIps ?? false,
35
- whiteListIps: config.studio?.whiteListIps ?? [],
36
- secretKey: config?.studio?.secretKey ?? "",
37
- };
43
+ if (!Cfg?.server?.jwt?.expiresIn) {
44
+ Cfg["server"]["jwt"]["expiresIn"] = "7d";
45
+ }
46
+
47
+ if (!Cfg?.server?.jwt.secret && process?.env?.JWT_SECRET) {
48
+ Cfg.server.jwt.secret = process.env.JWT_SECRET;
49
+ }
50
+
51
+ if (!Cfg?.server?.jwt.secret) {
52
+ let jwtSecret = await systemCache.get(".jwt.json");
53
+ if (!jwtSecret) {
54
+ jwtSecret = v4().replaceAll("-", "");
55
+ await systemCache.set(".jwt.json", jwtSecret);
56
+ }
57
+ Cfg.server.jwt.secret = jwtSecret;
58
+ }
38
59
 
39
- if (!Cfg.studio?.secretKey && Cfg?.studio?.enabled) {
40
- console.error("Please provide a studio secret key");
60
+ if (!Cfg?.server.jwt?.secret) {
61
+ console.error("JWT_SECRET is not defined");
62
+ process.exit(1);
41
63
  }
42
64
 
43
65
  if (!Cfg?.server.port) {
@@ -56,15 +78,15 @@ function setCfg(config: Config) {
56
78
  async function loadCfg() {
57
79
  let configPath = process.cwd() + `/config/app.ts`;
58
80
  await import(path.join(configPath))
59
- .then((inject: { default: Config }) => {
81
+ .then(async (inject: { default: Config }) => {
60
82
  // Cfg.tenants = inject.default?.tenants || [];
61
83
  // Cfg.server = inject.default?.server || [];
62
84
 
63
- setCfg(inject.default);
85
+ await setCfg(inject.default);
64
86
  //console.log(Cfg);
65
87
  })
66
88
  .catch((err) => {
67
- console.error("/config/app.ts not set ");
89
+ console.error("/config/app.ts ::", err?.message);
68
90
  });
69
91
  }
70
92
 
@@ -33,9 +33,9 @@ const systemCache = new BentoCache({
33
33
  });
34
34
 
35
35
  const dataCache = new BentoCache({
36
- default: "systemCache",
36
+ default: "dataCache",
37
37
  stores: {
38
- systemCache: bentostore().useL2Layer(
38
+ dataCache: bentostore().useL2Layer(
39
39
  fileDriver({
40
40
  directory: cacheDirectoryData,
41
41
  pruneInterval: "1h",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -414,6 +414,10 @@ export type Config = {
414
414
  logger?: Boolean | loggerFunction;
415
415
  whiteListIps?: Array<string>;
416
416
  blackListIps?: string[];
417
+ jwt?: {
418
+ secret: string;
419
+ expiresIn?: string;
420
+ };
417
421
  cors?: {
418
422
  origin:
419
423
  | string[]
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,7 @@ import dotJson from "dot-object";
15
16
  import deepCopy from "deepcopy";
16
17
  import { applyPatch, createPatch, Pointer } from "rfc6902";
17
18
 
18
- const JWT_SECRET = process?.env?.JWT_SECRET || "secret-libv";
19
+ const JWT_SECRET = process?.env?.JWT_SECRET || null;
19
20
  import * as _ from "radash";
20
21
  import { email } from "../lib/mail";
21
22