@dnax/core 0.10.1 → 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/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.1",
3
+ "version": "0.10.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {