akeyless-server-commons 1.0.191 → 1.0.192
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/dist/cjs/helpers/firebase_helpers.d.ts +1 -1
- package/dist/cjs/helpers/firebase_helpers.js +4 -2
- package/dist/cjs/helpers/firebase_helpers.js.map +1 -1
- package/dist/cjs/helpers/global_helpers.d.ts +1 -1
- package/dist/cjs/helpers/tasks.d.ts +12 -0
- package/dist/cjs/helpers/tasks.js +62 -0
- package/dist/cjs/helpers/tasks.js.map +1 -0
- package/dist/cjs/managers/cacche_manager2.d.ts +18 -0
- package/dist/cjs/managers/cacche_manager2.js +41 -0
- package/dist/cjs/managers/cacche_manager2.js.map +1 -0
- package/dist/cjs/managers/socket_manager.js +245 -0
- package/dist/cjs/managers/socket_manager.js.map +1 -0
- package/dist/esm/helpers/firebase_helpers.d.ts +1 -1
- package/dist/esm/helpers/firebase_helpers.js +4 -2
- package/dist/esm/helpers/firebase_helpers.js.map +1 -1
- package/dist/esm/helpers/global_helpers.d.ts +1 -1
- package/dist/esm/helpers/tasks.d.ts +12 -0
- package/dist/esm/helpers/tasks.js +58 -0
- package/dist/esm/helpers/tasks.js.map +1 -0
- package/dist/esm/managers/cacche_manager2.d.ts +18 -0
- package/dist/esm/managers/cacche_manager2.js +37 -0
- package/dist/esm/managers/cacche_manager2.js.map +1 -0
- package/dist/esm/managers/socket_manager.js +243 -0
- package/dist/esm/managers/socket_manager.js.map +1 -0
- package/package.json +1 -1
- package/dist/helpers/boards_helpers.js +0 -62
- package/dist/helpers/email_helpers.js +0 -153
- package/dist/helpers/firebase_helpers.js +0 -576
- package/dist/helpers/global_helpers.js +0 -147
- package/dist/helpers/index.js +0 -12
- package/dist/helpers/location_helpers.js +0 -15
- package/dist/helpers/login_helpers.js +0 -18
- package/dist/helpers/notification_helpers.js +0 -234
- package/dist/helpers/phone_number_helpers.js +0 -91
- package/dist/helpers/redis/index.js +0 -3
- package/dist/helpers/redis/initialize.js +0 -139
- package/dist/helpers/redis/keys.js +0 -23
- package/dist/helpers/redis/snapshot.js +0 -163
- package/dist/helpers/start.js +0 -43
- package/dist/helpers/tasks_helpers.js +0 -136
- package/dist/helpers/time_helpers.js +0 -167
- package/dist/index.js +0 -5
- package/dist/managers/cache_manager.js +0 -27
- package/dist/managers/index.js +0 -3
- package/dist/managers/logger_manager.js +0 -51
- package/dist/managers/translation_manager.js +0 -38
- package/dist/middlewares/auth_mw.js +0 -50
- package/dist/middlewares/error_handling.js +0 -20
- package/dist/middlewares/global_mw.js +0 -110
- package/dist/middlewares/index.js +0 -4
- package/dist/middlewares/trim_mw.js +0 -7
- package/dist/test.js +0 -1
- package/dist/types/enums/global.js +0 -8
- package/dist/types/enums/index.js +0 -1
- package/dist/types/helpers/boards_helpers.d.ts +0 -10
- package/dist/types/helpers/email_helpers.d.ts +0 -12
- package/dist/types/helpers/firebase_helpers.d.ts +0 -55
- package/dist/types/helpers/global_helpers.d.ts +0 -16
- package/dist/types/helpers/index.d.ts +0 -12
- package/dist/types/helpers/location_helpers.d.ts +0 -3
- package/dist/types/helpers/login_helpers.d.ts +0 -4
- package/dist/types/helpers/notification_helpers.d.ts +0 -11
- package/dist/types/helpers/phone_number_helpers.d.ts +0 -14
- package/dist/types/helpers/redis/index.d.ts +0 -3
- package/dist/types/helpers/redis/initialize.d.ts +0 -6
- package/dist/types/helpers/redis/keys.d.ts +0 -5
- package/dist/types/helpers/redis/snapshot.d.ts +0 -2
- package/dist/types/helpers/start.d.ts +0 -4
- package/dist/types/helpers/tasks_helpers.d.ts +0 -22
- package/dist/types/helpers/time_helpers.d.ts +0 -40
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -3
- package/dist/types/interfaces/index.js +0 -2
- package/dist/types/managers/cache_manager.d.ts +0 -11
- package/dist/types/managers/index.d.ts +0 -3
- package/dist/types/managers/logger_manager.d.ts +0 -12
- package/dist/types/managers/translation_manager.d.ts +0 -14
- package/dist/types/middlewares/auth_mw.d.ts +0 -4
- package/dist/types/middlewares/error_handling.d.ts +0 -11
- package/dist/types/middlewares/global_mw.d.ts +0 -5
- package/dist/types/middlewares/index.d.ts +0 -4
- package/dist/types/middlewares/trim_mw.d.ts +0 -2
- package/dist/types/test.d.ts +0 -0
- package/dist/types/types/enums/global.d.ts +0 -9
- package/dist/types/types/enums/index.d.ts +0 -1
- package/dist/types/types/firebase_types.js +0 -1
- package/dist/types/types/global.js +0 -1
- package/dist/types/types/index.d.ts +0 -3
- package/dist/types/types/index.js +0 -2
- package/dist/types/types/interfaces/email.d.ts +0 -33
- package/dist/types/types/interfaces/global.d.ts +0 -23
- package/dist/types/types/interfaces/index.d.ts +0 -2
- package/dist/types/types/types/firebase_types.d.ts +0 -50
- package/dist/types/types/types/global.d.ts +0 -17
- package/dist/types/types/types/index.d.ts +0 -2
- /package/dist/{types/interfaces/email.js → cjs/managers/socket_manager.d.ts} +0 -0
- /package/dist/{types/interfaces/global.js → esm/managers/socket_manager.d.ts} +0 -0
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import sendgrid from "@sendgrid/mail";
|
|
2
|
-
import { add_audit_record, get_document_by_id, ignore_ssl_request } from ".";
|
|
3
|
-
import { logger } from "../managers";
|
|
4
|
-
import * as fs from "fs";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
export const create_attachment_from_file = async (file_path, filename, disposition = "attachment") => {
|
|
7
|
-
try {
|
|
8
|
-
const content = fs.readFileSync(file_path);
|
|
9
|
-
const base64_content = content.toString("base64");
|
|
10
|
-
const mime_type = get_mime_type(file_path);
|
|
11
|
-
return {
|
|
12
|
-
content: base64_content,
|
|
13
|
-
filename: filename || path.basename(file_path),
|
|
14
|
-
type: mime_type,
|
|
15
|
-
disposition,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
logger.error("error creating attachment from file", { error, file_path });
|
|
20
|
-
throw error;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
export const create_attachment_from_buffer = (buffer, filename, mime_type, disposition = "attachment") => {
|
|
24
|
-
const buf = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
|
25
|
-
return {
|
|
26
|
-
content: buf.toString("base64"),
|
|
27
|
-
filename,
|
|
28
|
-
type: mime_type,
|
|
29
|
-
disposition,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export const create_attachment_from_url = async (url, filename) => {
|
|
33
|
-
try {
|
|
34
|
-
const response = await ignore_ssl_request({
|
|
35
|
-
method: "GET",
|
|
36
|
-
url,
|
|
37
|
-
responseType: "arraybuffer",
|
|
38
|
-
timeout: 20000,
|
|
39
|
-
});
|
|
40
|
-
const buffer = Buffer.from(response.data);
|
|
41
|
-
const content_type = response.headers?.["content-type"] || "application/pdf";
|
|
42
|
-
return {
|
|
43
|
-
content: buffer.toString("base64"),
|
|
44
|
-
filename: filename,
|
|
45
|
-
type: content_type,
|
|
46
|
-
disposition: "attachment",
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
logger.error("error creating attachment from url", { error, url });
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const get_mime_type = (file_path) => {
|
|
55
|
-
const ext = path.extname(file_path).toLowerCase();
|
|
56
|
-
const mime_types = {
|
|
57
|
-
".pdf": "application/pdf",
|
|
58
|
-
".doc": "application/msword",
|
|
59
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
60
|
-
".xls": "application/vnd.ms-excel",
|
|
61
|
-
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
62
|
-
".ppt": "application/vnd.ms-powerpoint",
|
|
63
|
-
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
64
|
-
".txt": "text/plain",
|
|
65
|
-
".csv": "text/csv",
|
|
66
|
-
".json": "application/json",
|
|
67
|
-
".xml": "application/xml",
|
|
68
|
-
".zip": "application/zip",
|
|
69
|
-
".rar": "application/x-rar-compressed",
|
|
70
|
-
".7z": "application/x-7z-compressed",
|
|
71
|
-
".jpg": "image/jpeg",
|
|
72
|
-
".jpeg": "image/jpeg",
|
|
73
|
-
".png": "image/png",
|
|
74
|
-
".gif": "image/gif",
|
|
75
|
-
".bmp": "image/bmp",
|
|
76
|
-
".svg": "image/svg+xml",
|
|
77
|
-
".mp3": "audio/mpeg",
|
|
78
|
-
".mp4": "video/mp4",
|
|
79
|
-
".avi": "video/x-msvideo",
|
|
80
|
-
".mov": "video/quicktime",
|
|
81
|
-
};
|
|
82
|
-
return mime_types[ext] || "application/octet-stream";
|
|
83
|
-
};
|
|
84
|
-
export const send_email = async (email_data, options) => {
|
|
85
|
-
try {
|
|
86
|
-
const emails_settings = (await get_document_by_id("nx-settings", "emails"));
|
|
87
|
-
const { sendgrid_api_key, groups, default_from, default_cc } = emails_settings;
|
|
88
|
-
let { from, to, cc, group_name, body_html, body_plain_text, subject, entity_for_audit, attachments } = email_data;
|
|
89
|
-
const cc_array = cc ? (Array.isArray(cc) ? cc : [cc]) : [];
|
|
90
|
-
cc = [...cc_array, ...default_cc];
|
|
91
|
-
/// validate data
|
|
92
|
-
if (!to?.length && !group_name?.length) {
|
|
93
|
-
throw "must supply a 'group_name' or 'to' value ";
|
|
94
|
-
}
|
|
95
|
-
if (!body_html?.length && !body_plain_text?.length) {
|
|
96
|
-
throw "must supply a 'body_plain_text' or 'html' value ";
|
|
97
|
-
}
|
|
98
|
-
if (to?.length && !group_name?.length) {
|
|
99
|
-
}
|
|
100
|
-
/// merge to and cc
|
|
101
|
-
if (group_name) {
|
|
102
|
-
if (!groups[group_name]) {
|
|
103
|
-
throw "must supply a valid 'group_name'";
|
|
104
|
-
}
|
|
105
|
-
if (!to) {
|
|
106
|
-
to = groups[group_name].to;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
to = typeof to === "string" ? [...groups[group_name].to, to] : [...groups[group_name].to, ...to];
|
|
110
|
-
}
|
|
111
|
-
cc.push(...(groups[group_name].cc || []));
|
|
112
|
-
}
|
|
113
|
-
/// set sendgrid account
|
|
114
|
-
sendgrid.setApiKey(sendgrid_api_key);
|
|
115
|
-
/// prepare message
|
|
116
|
-
const msg = body_html
|
|
117
|
-
? {
|
|
118
|
-
subject,
|
|
119
|
-
from: from || default_from,
|
|
120
|
-
to,
|
|
121
|
-
cc,
|
|
122
|
-
html: body_html,
|
|
123
|
-
attachments: attachments,
|
|
124
|
-
}
|
|
125
|
-
: {
|
|
126
|
-
subject,
|
|
127
|
-
from: from || default_from,
|
|
128
|
-
to,
|
|
129
|
-
cc,
|
|
130
|
-
text: body_plain_text,
|
|
131
|
-
attachments: attachments,
|
|
132
|
-
};
|
|
133
|
-
if (!attachments?.length) {
|
|
134
|
-
delete msg.attachments;
|
|
135
|
-
}
|
|
136
|
-
/// send email
|
|
137
|
-
const email_result = await sendgrid.send(msg);
|
|
138
|
-
if (email_result[0].statusCode !== 202) {
|
|
139
|
-
throw email_result[0].body;
|
|
140
|
-
}
|
|
141
|
-
/// add audit
|
|
142
|
-
await add_audit_record("send_email", entity_for_audit, { ...email_data, ...msg });
|
|
143
|
-
if (options?.debug) {
|
|
144
|
-
logger.log("email send successfully", { ...email_data, ...msg });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
logger.error("error sending email", error);
|
|
149
|
-
if (options?.debug) {
|
|
150
|
-
logger.error("email payload", { message: JSON.stringify(email_data) });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|