sidekick-server-2 0.1.1

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 (218) hide show
  1. package/README.md +223 -0
  2. package/dist/ai/index.d.ts +2 -0
  3. package/dist/ai/index.d.ts.map +1 -0
  4. package/dist/ai/index.js +2 -0
  5. package/dist/ai/index.js.map +1 -0
  6. package/dist/ai/perplexity-ai.d.ts +3 -0
  7. package/dist/ai/perplexity-ai.d.ts.map +1 -0
  8. package/dist/ai/perplexity-ai.js +28 -0
  9. package/dist/ai/perplexity-ai.js.map +1 -0
  10. package/dist/app-config.d.ts +13 -0
  11. package/dist/app-config.d.ts.map +1 -0
  12. package/dist/app-config.js +33 -0
  13. package/dist/app-config.js.map +1 -0
  14. package/dist/cors-config.d.ts +9 -0
  15. package/dist/cors-config.d.ts.map +1 -0
  16. package/dist/cors-config.js +24 -0
  17. package/dist/cors-config.js.map +1 -0
  18. package/dist/db-connection.d.ts +13 -0
  19. package/dist/db-connection.d.ts.map +1 -0
  20. package/dist/db-connection.js +22 -0
  21. package/dist/db-connection.js.map +1 -0
  22. package/dist/error-handler.d.ts +3 -0
  23. package/dist/error-handler.d.ts.map +1 -0
  24. package/dist/error-handler.js +15 -0
  25. package/dist/error-handler.js.map +1 -0
  26. package/dist/index.d.ts +19 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +87 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/local-cache.d.ts +14 -0
  31. package/dist/local-cache.d.ts.map +1 -0
  32. package/dist/local-cache.js +44 -0
  33. package/dist/local-cache.js.map +1 -0
  34. package/dist/r2-buckets/get-signed-url.d.ts +2 -0
  35. package/dist/r2-buckets/get-signed-url.d.ts.map +1 -0
  36. package/dist/r2-buckets/get-signed-url.js +22 -0
  37. package/dist/r2-buckets/get-signed-url.js.map +1 -0
  38. package/dist/r2-buckets/index.d.ts +3 -0
  39. package/dist/r2-buckets/index.d.ts.map +1 -0
  40. package/dist/r2-buckets/index.js +3 -0
  41. package/dist/r2-buckets/index.js.map +1 -0
  42. package/dist/r2-buckets/r2-client.d.ts +3 -0
  43. package/dist/r2-buckets/r2-client.d.ts.map +1 -0
  44. package/dist/r2-buckets/r2-client.js +18 -0
  45. package/dist/r2-buckets/r2-client.js.map +1 -0
  46. package/dist/r2-buckets/upload-r2.d.ts +11 -0
  47. package/dist/r2-buckets/upload-r2.d.ts.map +1 -0
  48. package/dist/r2-buckets/upload-r2.js +49 -0
  49. package/dist/r2-buckets/upload-r2.js.map +1 -0
  50. package/dist/routes/authentication/check-session.d.ts +4 -0
  51. package/dist/routes/authentication/check-session.d.ts.map +1 -0
  52. package/dist/routes/authentication/check-session.js +79 -0
  53. package/dist/routes/authentication/check-session.js.map +1 -0
  54. package/dist/routes/authentication/login-router.d.ts +3 -0
  55. package/dist/routes/authentication/login-router.d.ts.map +1 -0
  56. package/dist/routes/authentication/login-router.js +83 -0
  57. package/dist/routes/authentication/login-router.js.map +1 -0
  58. package/dist/routes/authentication/reset-password.d.ts +3 -0
  59. package/dist/routes/authentication/reset-password.d.ts.map +1 -0
  60. package/dist/routes/authentication/reset-password.js +92 -0
  61. package/dist/routes/authentication/reset-password.js.map +1 -0
  62. package/dist/routes/authentication/send-otp-router.d.ts +3 -0
  63. package/dist/routes/authentication/send-otp-router.d.ts.map +1 -0
  64. package/dist/routes/authentication/send-otp-router.js +89 -0
  65. package/dist/routes/authentication/send-otp-router.js.map +1 -0
  66. package/dist/routes/authentication/user-profile.d.ts +3 -0
  67. package/dist/routes/authentication/user-profile.d.ts.map +1 -0
  68. package/dist/routes/authentication/user-profile.js +44 -0
  69. package/dist/routes/authentication/user-profile.js.map +1 -0
  70. package/dist/routes/authentication/user-registration-router.d.ts +3 -0
  71. package/dist/routes/authentication/user-registration-router.d.ts.map +1 -0
  72. package/dist/routes/authentication/user-registration-router.js +120 -0
  73. package/dist/routes/authentication/user-registration-router.js.map +1 -0
  74. package/dist/routes/authentication/validator.d.ts +14 -0
  75. package/dist/routes/authentication/validator.d.ts.map +1 -0
  76. package/dist/routes/authentication/validator.js +69 -0
  77. package/dist/routes/authentication/validator.js.map +1 -0
  78. package/dist/routes/countries/countries-router.d.ts +3 -0
  79. package/dist/routes/countries/countries-router.d.ts.map +1 -0
  80. package/dist/routes/countries/countries-router.js +23 -0
  81. package/dist/routes/countries/countries-router.js.map +1 -0
  82. package/dist/routes/feature-flags/feature-flags.d.ts +5 -0
  83. package/dist/routes/feature-flags/feature-flags.d.ts.map +1 -0
  84. package/dist/routes/feature-flags/feature-flags.js +28 -0
  85. package/dist/routes/feature-flags/feature-flags.js.map +1 -0
  86. package/dist/routes/index.d.ts +9 -0
  87. package/dist/routes/index.d.ts.map +1 -0
  88. package/dist/routes/index.js +92 -0
  89. package/dist/routes/index.js.map +1 -0
  90. package/dist/routes/link-metadata.d.ts +3 -0
  91. package/dist/routes/link-metadata.d.ts.map +1 -0
  92. package/dist/routes/link-metadata.js +34 -0
  93. package/dist/routes/link-metadata.js.map +1 -0
  94. package/dist/routes/orgs/index.d.ts +2 -0
  95. package/dist/routes/orgs/index.d.ts.map +1 -0
  96. package/dist/routes/orgs/index.js +2 -0
  97. package/dist/routes/orgs/index.js.map +1 -0
  98. package/dist/routes/orgs/invitation.d.ts +3 -0
  99. package/dist/routes/orgs/invitation.d.ts.map +1 -0
  100. package/dist/routes/orgs/invitation.js +103 -0
  101. package/dist/routes/orgs/invitation.js.map +1 -0
  102. package/dist/routes/orgs/org-delete.d.ts +3 -0
  103. package/dist/routes/orgs/org-delete.d.ts.map +1 -0
  104. package/dist/routes/orgs/org-delete.js +53 -0
  105. package/dist/routes/orgs/org-delete.js.map +1 -0
  106. package/dist/routes/orgs/org-get.d.ts +3 -0
  107. package/dist/routes/orgs/org-get.d.ts.map +1 -0
  108. package/dist/routes/orgs/org-get.js +45 -0
  109. package/dist/routes/orgs/org-get.js.map +1 -0
  110. package/dist/routes/orgs/org-members.d.ts +12 -0
  111. package/dist/routes/orgs/org-members.d.ts.map +1 -0
  112. package/dist/routes/orgs/org-members.js +560 -0
  113. package/dist/routes/orgs/org-members.js.map +1 -0
  114. package/dist/routes/orgs/org-post.d.ts +3 -0
  115. package/dist/routes/orgs/org-post.d.ts.map +1 -0
  116. package/dist/routes/orgs/org-post.js +89 -0
  117. package/dist/routes/orgs/org-post.js.map +1 -0
  118. package/dist/routes/orgs/org-put.d.ts +3 -0
  119. package/dist/routes/orgs/org-put.d.ts.map +1 -0
  120. package/dist/routes/orgs/org-put.js +87 -0
  121. package/dist/routes/orgs/org-put.js.map +1 -0
  122. package/dist/routes/orgs/org-registration-router.d.ts +3 -0
  123. package/dist/routes/orgs/org-registration-router.d.ts.map +1 -0
  124. package/dist/routes/orgs/org-registration-router.js +12 -0
  125. package/dist/routes/orgs/org-registration-router.js.map +1 -0
  126. package/dist/routes/orgs/org-utils.d.ts +14 -0
  127. package/dist/routes/orgs/org-utils.d.ts.map +1 -0
  128. package/dist/routes/orgs/org-utils.js +234 -0
  129. package/dist/routes/orgs/org-utils.js.map +1 -0
  130. package/dist/routes/orgs/premium-org-utils.d.ts +3 -0
  131. package/dist/routes/orgs/premium-org-utils.d.ts.map +1 -0
  132. package/dist/routes/orgs/premium-org-utils.js +61 -0
  133. package/dist/routes/orgs/premium-org-utils.js.map +1 -0
  134. package/dist/routes/paid-plans/billingsdk-config.d.ts +36 -0
  135. package/dist/routes/paid-plans/billingsdk-config.d.ts.map +1 -0
  136. package/dist/routes/paid-plans/billingsdk-config.js +2 -0
  137. package/dist/routes/paid-plans/billingsdk-config.js.map +1 -0
  138. package/dist/routes/paid-plans/get-subscription-config.d.ts +3 -0
  139. package/dist/routes/paid-plans/get-subscription-config.d.ts.map +1 -0
  140. package/dist/routes/paid-plans/get-subscription-config.js +25 -0
  141. package/dist/routes/paid-plans/get-subscription-config.js.map +1 -0
  142. package/dist/routes/paid-plans/payment-gateway.d.ts +3 -0
  143. package/dist/routes/paid-plans/payment-gateway.d.ts.map +1 -0
  144. package/dist/routes/paid-plans/payment-gateway.js +324 -0
  145. package/dist/routes/paid-plans/payment-gateway.js.map +1 -0
  146. package/dist/routes/paid-plans/purchased-plans.d.ts +8 -0
  147. package/dist/routes/paid-plans/purchased-plans.d.ts.map +1 -0
  148. package/dist/routes/paid-plans/purchased-plans.js +191 -0
  149. package/dist/routes/paid-plans/purchased-plans.js.map +1 -0
  150. package/dist/routes/paid-plans/subscription-utils.d.ts +25 -0
  151. package/dist/routes/paid-plans/subscription-utils.d.ts.map +1 -0
  152. package/dist/routes/paid-plans/subscription-utils.js +156 -0
  153. package/dist/routes/paid-plans/subscription-utils.js.map +1 -0
  154. package/dist/s3-buckets/get-signed-url.d.ts +2 -0
  155. package/dist/s3-buckets/get-signed-url.d.ts.map +1 -0
  156. package/dist/s3-buckets/get-signed-url.js +22 -0
  157. package/dist/s3-buckets/get-signed-url.js.map +1 -0
  158. package/dist/s3-buckets/index.d.ts +3 -0
  159. package/dist/s3-buckets/index.d.ts.map +1 -0
  160. package/dist/s3-buckets/index.js +3 -0
  161. package/dist/s3-buckets/index.js.map +1 -0
  162. package/dist/s3-buckets/s3-client.d.ts +3 -0
  163. package/dist/s3-buckets/s3-client.d.ts.map +1 -0
  164. package/dist/s3-buckets/s3-client.js +17 -0
  165. package/dist/s3-buckets/s3-client.js.map +1 -0
  166. package/dist/s3-buckets/upload-s3.d.ts +11 -0
  167. package/dist/s3-buckets/upload-s3.d.ts.map +1 -0
  168. package/dist/s3-buckets/upload-s3.js +51 -0
  169. package/dist/s3-buckets/upload-s3.js.map +1 -0
  170. package/dist/secret.d.ts +4 -0
  171. package/dist/secret.d.ts.map +1 -0
  172. package/dist/secret.js +11 -0
  173. package/dist/secret.js.map +1 -0
  174. package/dist/socket-config.d.ts +4 -0
  175. package/dist/socket-config.d.ts.map +1 -0
  176. package/dist/socket-config.js +23 -0
  177. package/dist/socket-config.js.map +1 -0
  178. package/dist/types.d.ts +141 -0
  179. package/dist/types.d.ts.map +1 -0
  180. package/dist/types.js +2 -0
  181. package/dist/types.js.map +1 -0
  182. package/dist/utils/common-utils.d.ts +61 -0
  183. package/dist/utils/common-utils.d.ts.map +1 -0
  184. package/dist/utils/common-utils.js +99 -0
  185. package/dist/utils/common-utils.js.map +1 -0
  186. package/dist/utils/email-helper.d.ts +6 -0
  187. package/dist/utils/email-helper.d.ts.map +1 -0
  188. package/dist/utils/email-helper.js +33 -0
  189. package/dist/utils/email-helper.js.map +1 -0
  190. package/dist/utils/enums.d.ts +17 -0
  191. package/dist/utils/enums.d.ts.map +1 -0
  192. package/dist/utils/enums.js +27 -0
  193. package/dist/utils/enums.js.map +1 -0
  194. package/dist/utils/error-logger.d.ts +4 -0
  195. package/dist/utils/error-logger.d.ts.map +1 -0
  196. package/dist/utils/error-logger.js +30 -0
  197. package/dist/utils/error-logger.js.map +1 -0
  198. package/dist/utils/index.d.ts +9 -0
  199. package/dist/utils/index.d.ts.map +1 -0
  200. package/dist/utils/index.js +9 -0
  201. package/dist/utils/index.js.map +1 -0
  202. package/dist/utils/otp-helper.d.ts +5 -0
  203. package/dist/utils/otp-helper.d.ts.map +1 -0
  204. package/dist/utils/otp-helper.js +89 -0
  205. package/dist/utils/otp-helper.js.map +1 -0
  206. package/dist/utils/response-utils.d.ts +8 -0
  207. package/dist/utils/response-utils.d.ts.map +1 -0
  208. package/dist/utils/response-utils.js +37 -0
  209. package/dist/utils/response-utils.js.map +1 -0
  210. package/dist/utils/sql-helper.d.ts +27 -0
  211. package/dist/utils/sql-helper.d.ts.map +1 -0
  212. package/dist/utils/sql-helper.js +97 -0
  213. package/dist/utils/sql-helper.js.map +1 -0
  214. package/dist/utils/type.d.ts +81 -0
  215. package/dist/utils/type.d.ts.map +1 -0
  216. package/dist/utils/type.js +2 -0
  217. package/dist/utils/type.js.map +1 -0
  218. package/package.json +70 -0
@@ -0,0 +1,99 @@
1
+ import bcrypt from 'bcrypt';
2
+ import jwt from 'jsonwebtoken';
3
+ const SALT_ROUNDS = 10;
4
+ const JWT_SECRET = '12'; // Replace with your actual secret
5
+ const JWT_EXPIRATION = '7d'; //24hr or 7d Token expiration time
6
+ /**
7
+ * Check weather the email is valid or not.
8
+ *
9
+ * @param email - An email id
10
+ * @returns Boolean
11
+ */
12
+ export const isEmailValid = (email) => {
13
+ if (!email) {
14
+ return false;
15
+ }
16
+ const arrayEmail = String(email)
17
+ .toLowerCase()
18
+ .match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
19
+ return Array.isArray(arrayEmail) && arrayEmail.length > 0;
20
+ };
21
+ /**
22
+ * This method returns the object which only contains fields which needed for operation.
23
+ *
24
+ * @param request - Whole Object
25
+ * @param fields - an array of required fields
26
+ * @returns - The object contains only required field
27
+ */
28
+ export const getRequestFromRoute = (request, fields) => {
29
+ const result = {};
30
+ for (const fieldName of fields) {
31
+ result[fieldName] = request[fieldName] || null;
32
+ }
33
+ return result;
34
+ };
35
+ /**
36
+ * Hashes a plain password using bcrypt.
37
+ *
38
+ * @param plainPassword - The raw password to hash.
39
+ * @returns A promise that resolves to the hashed password.
40
+ */
41
+ export const hashPassword = async (plainPassword) => {
42
+ return await bcrypt.hash(plainPassword, SALT_ROUNDS);
43
+ };
44
+ /**
45
+ * Compares a plain password to a hashed one.
46
+ *
47
+ * @param plainPassword - The raw password input.
48
+ * @param hashedPassword - The stored hash to verify against.
49
+ * @returns A promise that resolves to true if match, false otherwise.
50
+ */
51
+ export const verifyPassword = async (plainPassword, hashedPassword) => {
52
+ return await bcrypt.compare(plainPassword, hashedPassword);
53
+ };
54
+ /**
55
+ * Generates a JWT token for the user.
56
+ *
57
+ * @param user - The user object to encode in the token.
58
+ * @returns The generated JWT token.
59
+ */
60
+ export const generateToken = (user) => {
61
+ return jwt.sign({ email: user.email, id: user.id }, JWT_SECRET, {
62
+ expiresIn: JWT_EXPIRATION,
63
+ });
64
+ };
65
+ /**
66
+ * Verifies the provided JWT token and returns the decoded payload.
67
+ *
68
+ * @param token - The JWT token to verify.
69
+ * @returns The decoded payload if the token is valid, otherwise throws an error.
70
+ */
71
+ export const verifyToken = (token) => {
72
+ return jwt.verify(token, JWT_SECRET);
73
+ };
74
+ /**
75
+ * Generates a 4-digit numeric OTP as a string.
76
+ *
77
+ * @returns A 4-digit OTP.
78
+ */
79
+ export const generateOTP = () => {
80
+ return Math.floor(1000 + Math.random() * 9000).toString();
81
+ };
82
+ /**
83
+ * Checks if the provided object is empty (has no own enumerable properties).
84
+ *
85
+ * @param obj - The object to check.
86
+ * @returns True if the object is empty, false otherwise.
87
+ */
88
+ export const isObjectEmpty = (obj) => {
89
+ return obj && Object.keys(obj).length === 0;
90
+ };
91
+ export const isCustomError = (obj) => {
92
+ return obj && 'success' in obj;
93
+ };
94
+ export const isValidId = (id) => {
95
+ const intId = parseInt(id, 10);
96
+ return intId > 0;
97
+ };
98
+ export const convertServerDateToJS = (serverDateStr) => new Date(serverDateStr);
99
+ //# sourceMappingURL=common-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-utils.js","sourceRoot":"","sources":["../../src/utils/common-utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,kCAAkC;AAC3D,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,kCAAkC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC;SAC7B,WAAW,EAAE;SACb,KAAK,CAC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CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAwB,EAAW,EAAE;IACjE,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAwB,EAAW,EAAE;IACjE,OAAO,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAmB,EAAE,EAAE;IAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAY,EAAE,EAAE,CAAC,CAAC;IACzC,OAAO,KAAK,GAAG,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,aAAqB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { IEmailConfig } from '../types.js';
2
+ import { SendEmailInf } from './type.js';
3
+ export declare const setEmailConfig: (config: IEmailConfig | null) => void;
4
+ declare const sendEmail: ({ email, subject, html }: SendEmailInf) => Promise<import("nodemailer/lib/smtp-transport/index.js").SentMessageInfo>;
5
+ export default sendEmail;
6
+ //# sourceMappingURL=email-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-helper.d.ts","sourceRoot":"","sources":["../../src/utils/email-helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAczC,eAAO,MAAM,cAAc,GAAI,QAAQ,YAAY,GAAG,IAAI,SAKzD,CAAC;AAEF,QAAA,MAAM,SAAS,GAAI,0BAA0B,YAAY,8EAexD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,33 @@
1
+ import nodemailer from 'nodemailer';
2
+ import { isObjectEmpty } from './common-utils.js';
3
+ const emailConfig = {
4
+ host: 'smtp.zoho.in',
5
+ port: 465,
6
+ secure: true,
7
+ auth: {
8
+ user: 'security@becomfort.in',
9
+ pass: '123~bnzk6kV_',
10
+ },
11
+ };
12
+ let emailConfigSet = false;
13
+ export const setEmailConfig = (config) => {
14
+ if (!config || isObjectEmpty(config))
15
+ return;
16
+ Object.assign(emailConfig, config);
17
+ emailConfigSet = true;
18
+ };
19
+ const sendEmail = ({ email, subject, html }) => {
20
+ if (!emailConfigSet) {
21
+ throw new Error('Email configuration not set. Please set it using setEmailConfig() before sending emails.');
22
+ }
23
+ const transporter = nodemailer.createTransport(emailConfig);
24
+ const mailOptions = {
25
+ from: 'security@becomfort.in',
26
+ to: email,
27
+ subject,
28
+ html,
29
+ };
30
+ return transporter.sendMail(mailOptions);
31
+ };
32
+ export default sendEmail;
33
+ //# sourceMappingURL=email-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-helper.js","sourceRoot":"","sources":["../../src/utils/email-helper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,MAAM,WAAW,GAAiB;IAChC,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE,cAAc;KACrB;CACF,CAAC;AAEF,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAA2B,EAAE,EAAE;IAC5D,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO;IAE7C,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACnC,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAgB,EAAE,EAAE;IAC3D,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAC;IAC9G,CAAC;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAE5D,MAAM,WAAW,GAAG;QAClB,IAAI,EAAE,uBAAuB;QAC7B,EAAE,EAAE,KAAK;QACT,OAAO;QACP,IAAI;KACL,CAAC;IAEF,OAAO,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const INVITATION_ENUMS: {
2
+ INVITED: number;
3
+ ACCEPTED: number;
4
+ REJECTED: number;
5
+ LEFT: number;
6
+ };
7
+ export declare const ROLES: {
8
+ READ: number;
9
+ ADMIN: number;
10
+ WRITE: number;
11
+ Is_ADMIN: (roleId: number) => boolean;
12
+ CAN_WRITE: (roleId: number) => boolean;
13
+ CAN_READ: (roleId: number) => boolean;
14
+ IS_VALID_ROLE_ID: (roleId: number | undefined) => boolean;
15
+ };
16
+ export declare const updateRolesEnum: (newRoles: any) => void;
17
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/utils/enums.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;CAK5B,CAAC;AAEF,eAAO,MAAM,KAAK;;;;uBAIY,MAAM;wBAGL,MAAM;uBAGP,MAAM;+BAGE,MAAM,GAAG,SAAS;CAGvD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,UAAU,GAAG,SAE5C,CAAC"}
@@ -0,0 +1,27 @@
1
+ export const INVITATION_ENUMS = {
2
+ INVITED: 0,
3
+ ACCEPTED: 1,
4
+ REJECTED: 2,
5
+ LEFT: 3,
6
+ };
7
+ export const ROLES = {
8
+ READ: 0,
9
+ ADMIN: 1,
10
+ WRITE: 2,
11
+ Is_ADMIN: function (roleId) {
12
+ return roleId === this.ADMIN;
13
+ },
14
+ CAN_WRITE: function (roleId) {
15
+ return roleId === this.WRITE || roleId === this.ADMIN;
16
+ },
17
+ CAN_READ: function (roleId) {
18
+ return roleId === this.READ || roleId === this.WRITE || roleId === this.ADMIN;
19
+ },
20
+ IS_VALID_ROLE_ID: function (roleId) {
21
+ return roleId === this.READ || roleId === this.ADMIN || roleId === this.WRITE;
22
+ },
23
+ };
24
+ export const updateRolesEnum = (newRoles) => {
25
+ Object.assign(ROLES, newRoles);
26
+ };
27
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.js","sourceRoot":"","sources":["../../src/utils/enums.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;CACR,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,QAAQ,EAAE,UAAU,MAAc;QAChC,OAAO,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC;IACD,SAAS,EAAE,UAAU,MAAc;QACjC,OAAO,MAAM,KAAK,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC;IACxD,CAAC;IACD,QAAQ,EAAE,UAAU,MAAc;QAChC,OAAO,MAAM,KAAK,IAAI,CAAC,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC;IAChF,CAAC;IACD,gBAAgB,EAAE,UAAU,MAA0B;QACpD,OAAO,MAAM,KAAK,IAAI,CAAC,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC;IAChF,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAa,EAAE,EAAE;IAC/C,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import winston from 'winston';
2
+ declare const logger: winston.Logger;
3
+ export default logger;
4
+ //# sourceMappingURL=error-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-logger.d.ts","sourceRoot":"","sources":["../../src/utils/error-logger.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B,QAAA,MAAM,MAAM,gBAeV,CAAC;AAOH,eAAe,MAAM,CAAC"}
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import winston from 'winston';
4
+ // Create logs directory if it doesn't exist
5
+ const logsDir = path.join(process.cwd(), 'logs');
6
+ if (!fs.existsSync(logsDir)) {
7
+ fs.mkdirSync(logsDir);
8
+ }
9
+ const logger = winston.createLogger({
10
+ level: 'info',
11
+ format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
12
+ transports: [
13
+ new winston.transports.Console({
14
+ format: winston.format.simple(),
15
+ }),
16
+ new winston.transports.File({
17
+ filename: path.join(logsDir, 'error.log'),
18
+ level: 'error',
19
+ }),
20
+ new winston.transports.File({
21
+ filename: path.join(logsDir, 'combined.log'),
22
+ }),
23
+ ],
24
+ });
25
+ process.on('uncaughtException', (err) => {
26
+ logger.error('Uncaught Exception:', err);
27
+ process.exit(1);
28
+ });
29
+ export default logger;
30
+ //# sourceMappingURL=error-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-logger.js","sourceRoot":"","sources":["../../src/utils/error-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,4CAA4C;AAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;AACjD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;IAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAClC,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACjF,UAAU,EAAE;QACV,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;SAChC,CAAC;QACF,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;YACzC,KAAK,EAAE,OAAO;SACf,CAAC;QACF,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;SAC7C,CAAC;KACH;CACF,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ import logger from './error-logger.js';
2
+ export * from './common-utils.js';
3
+ export * from './email-helper.js';
4
+ export * from './enums.js';
5
+ export { logger };
6
+ export * from './response-utils.js';
7
+ export * from './sql-helper.js';
8
+ export * from './type.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ import logger from './error-logger.js';
2
+ export * from './common-utils.js';
3
+ export * from './email-helper.js';
4
+ export * from './enums.js';
5
+ export { logger };
6
+ export * from './response-utils.js';
7
+ export * from './sql-helper.js';
8
+ export * from './type.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { OTPCache } from './type.js';
2
+ export declare const otpTemplate: (otp: string) => string;
3
+ export declare const cachedOTPs: OTPCache;
4
+ export declare const validateOTP: (email: string, otp: string) => boolean;
5
+ //# sourceMappingURL=otp-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp-helper.d.ts","sourceRoot":"","sources":["../../src/utils/otp-helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,WA+EtC,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,QAAa,CAAC;AAEvC,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,YAMrD,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { appInfo } from '../app-config.js';
2
+ export const otpTemplate = (otp) => {
3
+ return `
4
+ <!DOCTYPE html>
5
+ <html>
6
+ <head>
7
+ <meta charset="UTF-8" />
8
+ <title>${appInfo.appName} OTP for Email Verification</title>
9
+ <style>
10
+ body {
11
+ font-family: Arial, sans-serif;
12
+ background-color: #f5f7fa;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+ .container {
17
+ width: 100%;
18
+ max-width: 480px;
19
+ margin: 30px auto;
20
+ background-color: #ffffff;
21
+ border-radius: 8px;
22
+ padding: 20px;
23
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
24
+ color: #333333;
25
+ }
26
+ .header {
27
+ font-size: 24px;
28
+ font-weight: bold;
29
+ color: ${appInfo.primaryThemeColor};
30
+ margin-bottom: 20px;
31
+ justify-content: center;
32
+ display: flex;
33
+ gap: 5px;
34
+ }
35
+ .content p {
36
+ font-size: 16px;
37
+ line-height: 1.5;
38
+ }
39
+ .otp-code {
40
+ display: block;
41
+ width: fit-content;
42
+ margin: 20px auto;
43
+ font-size: 28px;
44
+ font-weight: bold;
45
+ letter-spacing: 4px;
46
+ color: ${appInfo.primaryThemeColor};
47
+ padding: 10px 20px;
48
+ border: 2px dashed ${appInfo.primaryThemeColor};
49
+ border-radius: 6px;
50
+ user-select: all;
51
+ }
52
+ .footer {
53
+ font-size: 14px;
54
+ color: #777777;
55
+ text-align: center;
56
+ margin-top: 30px;
57
+ }
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <div class="container">
62
+ <div class="header">
63
+ <div>${appInfo.logo}</div>
64
+ <div style="margin-top: 0">${appInfo.appName}</div>
65
+ </div>
66
+ <div class="content">
67
+ <p>Hello there,</p>
68
+ <p>Your One-Time Password (OTP) for email verification is:</p>
69
+ <span class="otp-code">${otp}</span>
70
+ <p>
71
+ This OTP is valid for the next 10 minutes. Please do not share it with
72
+ anyone.
73
+ </p>
74
+ <p>If you did not request this, please ignore this email.</p>
75
+ </div>
76
+ <div class="footer">${appInfo.appName}</div>
77
+ </div>
78
+ </body>
79
+ </html>
80
+ `;
81
+ };
82
+ export const cachedOTPs = {};
83
+ export const validateOTP = (email, otp) => {
84
+ if (email in cachedOTPs === false) {
85
+ return false;
86
+ }
87
+ return cachedOTPs[email] === otp;
88
+ };
89
+ //# sourceMappingURL=otp-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp-helper.js","sourceRoot":"","sources":["../../src/utils/otp-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE;IACzC,OAAO;;;;;iBAKQ,OAAO,CAAC,OAAO;;;;;;;;;;;;;;;;;;;;;qBAqBX,OAAO,CAAC,iBAAiB;;;;;;;;;;;;;;;;;qBAiBzB,OAAO,CAAC,iBAAiB;;iCAEb,OAAO,CAAC,iBAAiB;;;;;;;;;;;;;;;mBAevC,OAAO,CAAC,IAAI;yCACU,OAAO,CAAC,OAAO;;;;;qCAKnB,GAAG;;;;;;;gCAOR,OAAO,CAAC,OAAO;;;;KAI1C,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAa,EAAE,CAAC;AAEvC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE;IACxD,IAAI,KAAK,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;AACnC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Response } from 'express';
2
+ import { ErrorMsgs, ErrorResponse, SuccessResponse } from './type.js';
3
+ export declare const getResponseObj: (response: object) => SuccessResponse;
4
+ export declare const getErrorResponseObj: (errorMsgs: ErrorMsgs, error?: object) => ErrorResponse;
5
+ export declare const sendSuccessResponse: (response: Response, responseObj: SuccessResponse) => void;
6
+ export declare const sendErrorResponse: (response: Response, responseObj: ErrorResponse) => void;
7
+ export declare const throwErrorInResponseIfErrorIsNotCustom: (response: Response | null, errorObj: ErrorResponse | any, defaultErrorMsgs: ErrorMsgs) => any;
8
+ //# sourceMappingURL=response-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../src/utils/response-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,KAAG,eAKjD,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,WAAW,SAAS,EAAE,QAAQ,MAAM,KAAG,aAW1E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,UAAU,QAAQ,EAAE,aAAa,eAAe,KAAG,IAEtF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,UAAU,QAAQ,EAAE,aAAa,aAAa,KAAG,IAElF,CAAC;AAEF,eAAO,MAAM,sCAAsC,GAAI,UAAU,QAAQ,GAAG,IAAI,EAAE,UAAU,aAAa,GAAG,GAAG,EAAE,kBAAkB,SAAS,QAY3I,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { isCustomError } from './common-utils.js';
2
+ export const getResponseObj = (response) => {
3
+ return {
4
+ success: true,
5
+ response,
6
+ };
7
+ };
8
+ export const getErrorResponseObj = (errorMsgs, error) => {
9
+ return {
10
+ success: false,
11
+ error: {
12
+ errorMsg: errorMsgs.errorMsg || '',
13
+ solution: errorMsgs.solution || '',
14
+ error: {
15
+ ...(error || {}),
16
+ },
17
+ },
18
+ };
19
+ };
20
+ export const sendSuccessResponse = (response, responseObj) => {
21
+ response.status(200).json(responseObj);
22
+ };
23
+ export const sendErrorResponse = (response, responseObj) => {
24
+ response.status(403).json(responseObj);
25
+ };
26
+ export const throwErrorInResponseIfErrorIsNotCustom = (response, errorObj, defaultErrorMsgs) => {
27
+ const errorMsg = {
28
+ ...defaultErrorMsgs,
29
+ errorMsg: (errorObj && errorObj?.message) || defaultErrorMsgs.errorMsg,
30
+ };
31
+ const responseError = errorObj && isCustomError(errorObj) ? errorObj : getErrorResponseObj(errorMsg, errorObj);
32
+ //here, error means always in correct format.
33
+ if (response)
34
+ sendErrorResponse(response, responseError);
35
+ return responseError;
36
+ };
37
+ //# sourceMappingURL=response-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-utils.js","sourceRoot":"","sources":["../../src/utils/response-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAmB,EAAE;IAClE,OAAO;QACL,OAAO,EAAE,IAAI;QACb,QAAQ;KACT,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAoB,EAAE,KAAc,EAAiB,EAAE;IACzF,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE;YACL,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE;YAClC,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE;YAClC,KAAK,EAAE;gBACL,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;aACjB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAkB,EAAE,WAA4B,EAAQ,EAAE;IAC5F,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAAE,WAA0B,EAAQ,EAAE;IACxF,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,QAAyB,EAAE,QAA6B,EAAE,gBAA2B,EAAE,EAAE;IAC9I,MAAM,QAAQ,GAAG;QACf,GAAG,gBAAgB;QACnB,QAAQ,EAAE,CAAC,QAAQ,IAAI,QAAQ,EAAE,OAAO,CAAC,IAAI,gBAAgB,CAAC,QAAQ;KACvE,CAAC;IAEF,MAAM,aAAa,GAAG,QAAQ,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE/G,6CAA6C;IAC7C,IAAI,QAAQ;QAAE,iBAAiB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAEzD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This function will take care of start and release the connection with DB.
3
+ * @param promiseFn
4
+ */
5
+ export declare const initializeConnection: (promiseFn: (connection: any) => Promise<any>) => Promise<any>;
6
+ export declare const insertRecords: (tableName: string, records: Record<string, any>[], connection: any) => Promise<any>;
7
+ /**
8
+ * Updates records in the specified table that match the where condition.
9
+ * @param tableName - The name of the table to update
10
+ * @param updateValues - Object containing the fields and values to update
11
+ * @param where - Object containing the where conditions
12
+ * @param connection - Database connection
13
+ * @returns - The result of the update operation
14
+ */
15
+ export declare const updateRecords: (tableName: string, updateValues: Record<string, any>, where: Record<string, any>, connection: any) => Promise<any>;
16
+ /**
17
+ * This method fetch the records from DB.
18
+ * @param tableName
19
+ * @param fieldNames
20
+ * @param where
21
+ * @param connection
22
+ * @returns - Returns an array of object for the satisfied conditions.
23
+ */
24
+ export declare const selectRecords: (tableName: string, fieldNames: string[] | undefined, where: Record<string, any> | undefined, connection: any) => Promise<any>;
25
+ export declare const executeSql: (sql: string, connection: any) => Promise<any>;
26
+ export declare const isTruthyValue: (value: 1 | "1" | boolean | 0 | "0") => value is true | 1 | "1";
27
+ //# sourceMappingURL=sql-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-helper.d.ts","sourceRoot":"","sources":["../../src/utils/sql-helper.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAU,WAAW,CAAC,UAAU,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iBAWtF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,YAAY,GAAG,iBA0BrG,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,cAAc,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,iBAqBpI,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,YAAY,MAAM,EAAE,YAAQ,EAAE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAAK,EAAE,YAAY,GAAG,iBAgBpI,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,EAAE,YAAY,GAAG,iBAO5D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,CAAC,GAAG,GAAG,GAAG,OAAO,GAAG,CAAC,GAAG,GAAG,4BAAmD,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { getDatabaseConnection } from '../db-connection.js';
2
+ /**
3
+ * This function will take care of start and release the connection with DB.
4
+ * @param promiseFn
5
+ */
6
+ export const initializeConnection = async (promiseFn) => {
7
+ let connection;
8
+ try {
9
+ const dbConnectionPool = getDatabaseConnection();
10
+ connection = await dbConnectionPool.getConnection();
11
+ return await promiseFn(connection);
12
+ }
13
+ finally {
14
+ connection?.release();
15
+ }
16
+ };
17
+ export const insertRecords = async (tableName, records, connection) => {
18
+ if (!Array.isArray(records) || records.length === 0) {
19
+ throw new Error('records must be a non-empty array');
20
+ }
21
+ const keys = Object.keys(records[0]); // take keys from the first object
22
+ const placeholders = records
23
+ .map(() => `(${keys.map(() => '?').join(', ')})`) // (?,?,?), (?,?,?) ...
24
+ .join(', ');
25
+ const values = records.flatMap(Object.values); // flatten all values into one array
26
+ const sql = `INSERT INTO ${tableName} (${keys.join(', ')}) VALUES ${placeholders}`;
27
+ try {
28
+ const [result] = await connection.execute(sql, values);
29
+ // Check if all records were inserted
30
+ if (result.affectedRows !== records.length) {
31
+ throw new Error(`Expected to insert ${records.length} records, but only ${result.affectedRows} were inserted.`);
32
+ }
33
+ return result;
34
+ }
35
+ catch (e) {
36
+ throw e;
37
+ }
38
+ };
39
+ /**
40
+ * Updates records in the specified table that match the where condition.
41
+ * @param tableName - The name of the table to update
42
+ * @param updateValues - Object containing the fields and values to update
43
+ * @param where - Object containing the where conditions
44
+ * @param connection - Database connection
45
+ * @returns - The result of the update operation
46
+ */
47
+ export const updateRecords = async (tableName, updateValues, where, connection) => {
48
+ const updateKeys = Object.keys(updateValues);
49
+ const whereKeys = Object.keys(where);
50
+ if (updateKeys.length === 0) {
51
+ throw new Error('updateValues must not be empty');
52
+ }
53
+ const setClause = updateKeys.map((key) => `${key} = ?`).join(', ');
54
+ const whereClause = whereKeys.length ? 'WHERE ' + whereKeys.map((key) => `${key} = ?`).join(' AND ') : '';
55
+ const values = [...Object.values(updateValues), ...Object.values(where)];
56
+ const sql = `UPDATE ${tableName} SET ${setClause} ${whereClause}`;
57
+ try {
58
+ const [result] = await connection.execute(sql, values);
59
+ return result;
60
+ }
61
+ catch (e) {
62
+ throw e;
63
+ }
64
+ };
65
+ /**
66
+ * This method fetch the records from DB.
67
+ * @param tableName
68
+ * @param fieldNames
69
+ * @param where
70
+ * @param connection
71
+ * @returns - Returns an array of object for the satisfied conditions.
72
+ */
73
+ export const selectRecords = async (tableName, fieldNames = ['*'], where = {}, connection) => {
74
+ const whereKeys = Object.keys(where);
75
+ const whereClause = whereKeys.length ? 'WHERE ' + whereKeys.map((key) => `${key} = ?`).join(' AND ') : '';
76
+ const values = whereKeys.map((key) => where[key]);
77
+ const fields = fieldNames.length ? fieldNames.join(', ') : '*';
78
+ const sql = `SELECT ${fields} FROM ${tableName} ${whereClause}`;
79
+ try {
80
+ const [records] = await connection.execute(sql, values);
81
+ return records;
82
+ }
83
+ catch (e) {
84
+ throw e;
85
+ }
86
+ };
87
+ export const executeSql = async (sql, connection) => {
88
+ try {
89
+ const [records] = await connection.execute(sql);
90
+ return records;
91
+ }
92
+ catch (e) {
93
+ throw e;
94
+ }
95
+ };
96
+ export const isTruthyValue = (value) => value === 1 || value === '1' || value === true;
97
+ //# sourceMappingURL=sql-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-helper.js","sourceRoot":"","sources":["../../src/utils/sql-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,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