@dnax/core 0.10.2 → 0.10.3

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/hono.ts CHANGED
@@ -75,10 +75,9 @@ function HonoInstance(): typeof app {
75
75
  if (typeof Cfg?.server?.logger == "boolean" && Cfg?.server?.logger) {
76
76
  app.use(async (c, next) => {
77
77
  let ip =
78
- c.req.header("cf-connecting-ip") ||
79
- c.req.header("x-forwarded-for") ||
80
- c.req.header("x-client-ip") ||
81
- c.req.header("x-forwarded-for");
78
+ c.req.raw.headers?.get("CF-Connecting-IP") ||
79
+ c.req.raw.headers?.get("x-forwarded-for") ||
80
+ c.req.raw.headers?.get("x-real-ip");
82
81
  const origin =
83
82
  c.req?.header("Origin") || c.req.raw?.headers?.get("Origin") || "";
84
83
  const info = getConnInfo(c);
@@ -146,11 +145,6 @@ function HonoInstance(): typeof app {
146
145
  //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoibm9tIiwiaWF0IjoxNzE3Nzc0MDQzLCJleHAiOjE3MTc3NzQxMDN9.Ud4-0y8pa4SMIcSn8PU1A-sjC-hT4ZVe_u3AdChyIJU
147
146
  // Middlewares Injection
148
147
  app.use(async (c, next) => {
149
- let IP_ =
150
- c.req.header("cf-connecting-ip") ||
151
- c.req.header("x-forwarded-for") ||
152
- c.req.header("x-client-ip") ||
153
- c.req.header("x-forwarded-for");
154
148
  return asyncLocalStorage.run(new Map(), async () => {
155
149
  let cookie = getCookie(c);
156
150
  let secretKeyStudio = cookie["_STUDIO_SECRET_KEY_"] || null;
@@ -171,7 +165,10 @@ function HonoInstance(): typeof app {
171
165
 
172
166
  let _v = {
173
167
  token: token || null,
174
- ip: IP_,
168
+ ip:
169
+ c.req.raw.headers?.get("CF-Connecting-IP") ||
170
+ c.req.raw.headers?.get("x-forwarded-for") ||
171
+ c.req.raw.headers?.get("x-real-ip"),
175
172
  isAuth: valid ? true : false,
176
173
  reqAt: moment().format().toString(),
177
174
  setAt: sessionData?._v?.setAt || null,
package/index.ts CHANGED
@@ -7,6 +7,7 @@ import define from "./define";
7
7
  import moment from "moment";
8
8
  import * as utils from "./utils";
9
9
  import { searchEngine } from "./lib/orama";
10
+ import { dataCache } from "./lib/bento";
10
11
 
11
12
  /**
12
13
  * v is internal data validation and based of Joi validation.
@@ -15,4 +16,4 @@ import { searchEngine } from "./lib/orama";
15
16
  */
16
17
  const v = Joi;
17
18
 
18
- export { runApp, define, utils, useRest, v, searchEngine };
19
+ export { runApp, define, utils, useRest, v, searchEngine, dataCache };
@@ -5,12 +5,19 @@ import { v4 } from "uuid";
5
5
  import fs from "fs-extra";
6
6
  import path from "path";
7
7
  const cacheDirectory = path.join(process.cwd(), "/.cache/system/");
8
-
8
+ const cacheDirectoryData = path.join(process.cwd(), "/.cache/data/");
9
9
  if (!fs?.existsSync(cacheDirectory + "bentocache")) {
10
10
  fs.mkdirSync(cacheDirectory + "bentocache", {
11
11
  recursive: true,
12
12
  });
13
13
  }
14
+
15
+ if (!fs?.existsSync(cacheDirectoryData + "bentocache")) {
16
+ fs.mkdirSync(cacheDirectory + "bentocache", {
17
+ recursive: true,
18
+ });
19
+ }
20
+
14
21
  const systemCache = new BentoCache({
15
22
  default: "systemCache",
16
23
  stores: {
@@ -24,6 +31,19 @@ const systemCache = new BentoCache({
24
31
  },
25
32
  });
26
33
 
34
+ const dataCache = new BentoCache({
35
+ default: "systemCache",
36
+ stores: {
37
+ systemCache: bentostore().useL2Layer(
38
+ fileDriver({
39
+ directory: cacheDirectoryData,
40
+ pruneInterval: "1h",
41
+ //maxSize: 100 * 1024 * 1024,
42
+ })
43
+ ),
44
+ },
45
+ });
46
+
27
47
  const bentoCache = new BentoCache({
28
48
  default: "dnaxCache",
29
49
  stores: {
@@ -53,4 +73,4 @@ function bentoKey(data: object | string) {
53
73
 
54
74
  const sessionCache = systemCache.namespace("tokens");
55
75
 
56
- export { bentoCache, bentoKey, systemCache, sessionCache };
76
+ export { bentoCache, bentoKey, systemCache, sessionCache, dataCache };
package/lib/mail.ts CHANGED
@@ -109,7 +109,51 @@ function verifySmtpConnection(smtpConfig: emailConfigType["smtpOptions"]) {
109
109
  });
110
110
  }
111
111
 
112
+ function send(
113
+ options: {
114
+ emailConfig?: emailConfigType;
115
+ mailOptions?: {
116
+ from?: string;
117
+ text?: string;
118
+ html?: string;
119
+ subject?: string;
120
+ to?: string | Array<string> | null | undefined;
121
+ replyTo?: string;
122
+ cc?: string | Array<string> | null | undefined;
123
+ bcc?: string | Array<string> | null | undefined;
124
+ };
125
+ } = {}
126
+ ) {
127
+ return new Promise(async (resolve, reject) => {
128
+ try {
129
+ const smtp = Cfg.email?.smtpOptions;
130
+ const transport = createTransport(
131
+ options?.emailConfig?.smtpOptions || smtp
132
+ );
133
+
134
+ var response = await transport.sendMail({
135
+ from:
136
+ options?.mailOptions?.from ||
137
+ `${options?.emailConfig?.fromName || ""} <${
138
+ options?.emailConfig?.fromAddress || ""
139
+ }>`,
140
+ to: options?.mailOptions?.to || undefined,
141
+ subject: options?.mailOptions?.subject || "",
142
+ text: options?.mailOptions?.text || "",
143
+ html: options?.mailOptions?.html || "",
144
+ replyTo: options?.mailOptions?.replyTo || undefined,
145
+ cc: options?.mailOptions?.cc || undefined,
146
+ bcc: options?.mailOptions?.bcc || undefined,
147
+ });
148
+ resolve(response);
149
+ } catch (err) {
150
+ reject(err);
151
+ }
152
+ });
153
+ }
154
+
112
155
  const email = {
156
+ send,
113
157
  sendEmail,
114
158
  sendLocalEmail,
115
159
  updateLocalEmailConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {