@dnax/core 0.26.0 → 0.28.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/config/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { cors } from "hono/cors";
2
2
  import { Config } from "./../types/index";
3
3
  import type { Config } from "../types";
4
+
4
5
  import { systemCache } from "../lib/bento";
5
6
  import { Glob } from "bun";
6
7
  import path from "path";
@@ -48,11 +49,14 @@ async function setCfg(config: Config) {
48
49
  Cfg.server.jwt.secret = process.env.JWT_SECRET;
49
50
  }
50
51
 
51
- if (!Cfg?.server?.jwt.secret) {
52
+ if (!Cfg?.server?.jwt?.secret) {
52
53
  let jwtSecret = await systemCache.get(".jwt.json");
53
54
  if (!jwtSecret) {
54
55
  jwtSecret = v4().replaceAll("-", "");
55
- await systemCache.set(".jwt.json", jwtSecret);
56
+ await systemCache.set({
57
+ key: ".jwt.json",
58
+ value: jwtSecret,
59
+ });
56
60
  }
57
61
  Cfg.server.jwt.secret = jwtSecret;
58
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/utils/index.ts CHANGED
@@ -16,7 +16,6 @@ import dotJson from "dot-object";
16
16
  import deepCopy from "deepcopy";
17
17
  import { applyPatch, createPatch, Pointer } from "rfc6902";
18
18
 
19
- const JWT_SECRET = process?.env?.JWT_SECRET || null;
20
19
  import * as _ from "radash";
21
20
  import { email } from "../lib/mail";
22
21
 
@@ -29,6 +28,8 @@ function copy(data: object): object | any {
29
28
 
30
29
  const jwt = {
31
30
  verify: (token: string): { decode: any; valid: boolean; error: any } => {
31
+ const JWT_SECRET =
32
+ Cfg.server.jwt?.secret || String(process?.env?.JWT_SECRET);
32
33
  let decode = null;
33
34
  let valid = true;
34
35
  let error = null;
@@ -59,7 +60,8 @@ const jwt = {
59
60
  }
60
61
  ) => {
61
62
  // console.log("payload", payload, options);
62
-
63
+ const JWT_SECRET =
64
+ Cfg.server.jwt?.secret || String(process?.env?.JWT_SECRET);
63
65
  return jwto.sign({ session: payload }, JWT_SECRET, {
64
66
  ...options,
65
67
  });
@@ -70,6 +72,9 @@ const jwt = {
70
72
  expiresIn: process.env?.JWT_EXPIRES_IN || "7d",
71
73
  }
72
74
  ) => {
75
+ const JWT_SECRET =
76
+ Cfg.server.jwt?.secret || String(process?.env?.JWT_SECRET);
77
+
73
78
  return jwto.sign(
74
79
  {
75
80
  ...payload,
@@ -81,6 +86,7 @@ const jwt = {
81
86
  JWT_SECRET,
82
87
  {
83
88
  ...options,
89
+ expiresIn: options?.expiresIn || Cfg.server.jwt?.expiresIn || "7d",
84
90
  }
85
91
  );
86
92
  },