@dnax/core 0.10.2 → 0.10.4

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/config/index.ts CHANGED
@@ -24,7 +24,8 @@ const Cfg: Config = {
24
24
 
25
25
  function setCfg(config: Config) {
26
26
  Cfg.server = config.server;
27
- Cfg.tenants = config.tenants;
27
+ Cfg.tenants = config?.tenants;
28
+ Cfg.email = config?.email;
28
29
 
29
30
  Cfg.studio = {
30
31
  enabled: config.studio?.enabled ?? false,
@@ -56,7 +57,7 @@ async function loadCfg() {
56
57
  .then((inject: { default: Config }) => {
57
58
  // Cfg.tenants = inject.default?.tenants || [];
58
59
  // Cfg.server = inject.default?.server || [];
59
- ///console.log(inject.default);
60
+
60
61
  setCfg(inject.default);
61
62
  //console.log(Cfg);
62
63
  })
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,57 @@ function verifySmtpConnection(smtpConfig: emailConfigType["smtpOptions"]) {
109
109
  });
110
110
  }
111
111
 
112
+ function send(
113
+ options: {
114
+ config?: 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 = options?.config?.smtpOptions || Cfg.email?.smtpOptions;
130
+
131
+ const transport = createTransport({
132
+ ...smtp,
133
+ });
134
+
135
+ var response = await transport.sendMail({
136
+ from:
137
+ options?.mailOptions?.from ||
138
+ `${options?.config?.fromName || ""} <${
139
+ options?.config?.fromAddress || ""
140
+ }>`,
141
+ to: options?.mailOptions?.to || undefined,
142
+ subject: options?.mailOptions?.subject || "",
143
+ text: options?.mailOptions?.text || "",
144
+ html: options?.mailOptions?.html || "",
145
+ replyTo: options?.mailOptions?.replyTo || undefined,
146
+ cc: options?.mailOptions?.cc || undefined,
147
+ bcc: options?.mailOptions?.bcc || undefined,
148
+ });
149
+ resolve(response);
150
+ } catch (err) {
151
+ reject(err);
152
+ }
153
+ });
154
+ }
155
+
156
+ function getConfig() {
157
+ return Cfg?.email || {};
158
+ }
159
+
112
160
  const email = {
161
+ getConfig,
162
+ send,
113
163
  sendEmail,
114
164
  sendLocalEmail,
115
165
  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.4",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -306,7 +306,7 @@ export type loggerFunction = (
306
306
  action?: string;
307
307
  collection?: string;
308
308
  cleanDeep?: boolean;
309
-
309
+
310
310
  useCache?: boolean;
311
311
  method: string;
312
312
  url?: string;
@@ -477,8 +477,8 @@ export type Service = {
477
477
 
478
478
  export type emailConfigType = {
479
479
  provider: "smtp";
480
- fromName: string;
481
- fromAddress: string;
480
+ fromName?: string;
481
+ fromAddress?: string;
482
482
  smtpOptions?: {
483
483
  host: string;
484
484
  port: number;