akeyless-server-commons 1.0.206 → 1.0.207

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.
Files changed (113) hide show
  1. package/dist/cjs/helpers/index.d.ts +1 -0
  2. package/dist/cjs/helpers/index.js +1 -0
  3. package/dist/cjs/helpers/index.js.map +1 -1
  4. package/dist/cjs/helpers/postponed_actions.d.ts +7 -17
  5. package/dist/cjs/helpers/postponed_actions.js +25 -26
  6. package/dist/cjs/helpers/postponed_actions.js.map +1 -1
  7. package/dist/cjs/helpers/tasks.d.ts +12 -0
  8. package/dist/cjs/helpers/tasks.js +62 -0
  9. package/dist/cjs/helpers/tasks.js.map +1 -0
  10. package/dist/cjs/managers/cacche_manager2.d.ts +18 -0
  11. package/dist/cjs/managers/cacche_manager2.js +41 -0
  12. package/dist/cjs/managers/cacche_manager2.js.map +1 -0
  13. package/dist/cjs/managers/socket_manager.js +245 -0
  14. package/dist/cjs/managers/socket_manager.js.map +1 -0
  15. package/dist/esm/helpers/index.d.ts +1 -0
  16. package/dist/esm/helpers/index.js +1 -0
  17. package/dist/esm/helpers/index.js.map +1 -1
  18. package/dist/esm/helpers/postponed_actions.d.ts +7 -17
  19. package/dist/esm/helpers/postponed_actions.js +12 -12
  20. package/dist/esm/helpers/postponed_actions.js.map +1 -1
  21. package/dist/esm/helpers/tasks.d.ts +12 -0
  22. package/dist/esm/helpers/tasks.js +58 -0
  23. package/dist/esm/helpers/tasks.js.map +1 -0
  24. package/dist/esm/managers/cacche_manager2.d.ts +18 -0
  25. package/dist/esm/managers/cacche_manager2.js +37 -0
  26. package/dist/esm/managers/cacche_manager2.js.map +1 -0
  27. package/dist/esm/managers/socket_manager.js +243 -0
  28. package/dist/esm/managers/socket_manager.js.map +1 -0
  29. package/package.json +1 -1
  30. package/dist/cjs/helpers/rabbitmq_helpers.d.ts +0 -64
  31. package/dist/cjs/helpers/rabbitmq_helpers.js +0 -193
  32. package/dist/cjs/helpers/rabbitmq_helpers.js.map +0 -1
  33. package/dist/esm/helpers/rabbitmq_helpers.d.ts +0 -64
  34. package/dist/esm/helpers/rabbitmq_helpers.js +0 -186
  35. package/dist/esm/helpers/rabbitmq_helpers.js.map +0 -1
  36. package/dist/helpers/boards_helpers.js +0 -62
  37. package/dist/helpers/email_helpers.js +0 -153
  38. package/dist/helpers/firebase_helpers.js +0 -601
  39. package/dist/helpers/global_helpers.js +0 -147
  40. package/dist/helpers/index.js +0 -13
  41. package/dist/helpers/location_helpers.js +0 -15
  42. package/dist/helpers/login_helpers.js +0 -18
  43. package/dist/helpers/notification_helpers.js +0 -248
  44. package/dist/helpers/phone_number_helpers.js +0 -96
  45. package/dist/helpers/postponed_actions.js +0 -358
  46. package/dist/helpers/redis/helpers.js +0 -215
  47. package/dist/helpers/redis/index.js +0 -4
  48. package/dist/helpers/redis/initialize.js +0 -139
  49. package/dist/helpers/redis/keys.js +0 -23
  50. package/dist/helpers/redis/snapshot.js +0 -166
  51. package/dist/helpers/start.js +0 -83
  52. package/dist/helpers/tasks_helpers.js +0 -139
  53. package/dist/helpers/time_helpers.js +0 -167
  54. package/dist/index.js +0 -5
  55. package/dist/managers/cache_manager.js +0 -37
  56. package/dist/managers/index.js +0 -4
  57. package/dist/managers/logger_manager.js +0 -68
  58. package/dist/managers/rabbitmq_manager.js +0 -182
  59. package/dist/managers/translation_manager.js +0 -38
  60. package/dist/middlewares/auth_mw.js +0 -50
  61. package/dist/middlewares/error_handling.js +0 -20
  62. package/dist/middlewares/global_mw.js +0 -119
  63. package/dist/middlewares/index.js +0 -4
  64. package/dist/middlewares/trim_mw.js +0 -7
  65. package/dist/test.js +0 -1
  66. package/dist/types/enums/global.js +0 -8
  67. package/dist/types/enums/index.js +0 -1
  68. package/dist/types/helpers/boards_helpers.d.ts +0 -10
  69. package/dist/types/helpers/email_helpers.d.ts +0 -12
  70. package/dist/types/helpers/firebase_helpers.d.ts +0 -56
  71. package/dist/types/helpers/global_helpers.d.ts +0 -16
  72. package/dist/types/helpers/index.d.ts +0 -13
  73. package/dist/types/helpers/location_helpers.d.ts +0 -3
  74. package/dist/types/helpers/login_helpers.d.ts +0 -4
  75. package/dist/types/helpers/notification_helpers.d.ts +0 -11
  76. package/dist/types/helpers/phone_number_helpers.d.ts +0 -19
  77. package/dist/types/helpers/postponed_actions.d.ts +0 -113
  78. package/dist/types/helpers/redis/helpers.d.ts +0 -11
  79. package/dist/types/helpers/redis/index.d.ts +0 -4
  80. package/dist/types/helpers/redis/initialize.d.ts +0 -6
  81. package/dist/types/helpers/redis/keys.d.ts +0 -5
  82. package/dist/types/helpers/redis/snapshot.d.ts +0 -2
  83. package/dist/types/helpers/start.d.ts +0 -4
  84. package/dist/types/helpers/tasks_helpers.d.ts +0 -25
  85. package/dist/types/helpers/time_helpers.d.ts +0 -40
  86. package/dist/types/index.d.ts +0 -5
  87. package/dist/types/index.js +0 -3
  88. package/dist/types/interfaces/index.js +0 -2
  89. package/dist/types/managers/cache_manager.d.ts +0 -12
  90. package/dist/types/managers/index.d.ts +0 -4
  91. package/dist/types/managers/logger_manager.d.ts +0 -14
  92. package/dist/types/managers/rabbitmq_manager.d.ts +0 -60
  93. package/dist/types/managers/translation_manager.d.ts +0 -14
  94. package/dist/types/middlewares/auth_mw.d.ts +0 -4
  95. package/dist/types/middlewares/error_handling.d.ts +0 -11
  96. package/dist/types/middlewares/global_mw.d.ts +0 -5
  97. package/dist/types/middlewares/index.d.ts +0 -4
  98. package/dist/types/middlewares/trim_mw.d.ts +0 -2
  99. package/dist/types/test.d.ts +0 -0
  100. package/dist/types/types/enums/global.d.ts +0 -9
  101. package/dist/types/types/enums/index.d.ts +0 -1
  102. package/dist/types/types/firebase_types.js +0 -1
  103. package/dist/types/types/global.js +0 -1
  104. package/dist/types/types/index.d.ts +0 -3
  105. package/dist/types/types/index.js +0 -2
  106. package/dist/types/types/interfaces/email.d.ts +0 -33
  107. package/dist/types/types/interfaces/global.d.ts +0 -27
  108. package/dist/types/types/interfaces/index.d.ts +0 -2
  109. package/dist/types/types/types/firebase_types.d.ts +0 -50
  110. package/dist/types/types/types/global.d.ts +0 -17
  111. package/dist/types/types/types/index.d.ts +0 -2
  112. /package/dist/{types/interfaces/email.js → cjs/managers/socket_manager.d.ts} +0 -0
  113. /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
- };