@b2y/ecommerce-common 1.0.5 → 1.0.7

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 (68) hide show
  1. package/README.md +4 -4
  2. package/constants/AppConstants.js +3 -3
  3. package/constants/ReportConstants.js +14 -14
  4. package/constants/StatusMessageConstants.js +17 -17
  5. package/dbconnection/Connect.js +383 -379
  6. package/enum/AddressTypeEnum.js +6 -6
  7. package/enum/BooleanEnum.js +4 -4
  8. package/enum/EntityTypeEnum.js +11 -11
  9. package/enum/GenderEnum.js +7 -7
  10. package/enum/NotificationStatusEnum.js +5 -5
  11. package/enum/NotificationTypeEnum.js +9 -9
  12. package/enum/OrderStatusEnum.js +7 -7
  13. package/enum/PaymentMethodEnum.js +6 -6
  14. package/enum/PaymentStatusEnum.js +6 -6
  15. package/enum/PaymentTypeEnum.js +6 -6
  16. package/enum/PlatformEnum.js +4 -4
  17. package/enum/RegistrationStatusEnum.js +5 -5
  18. package/enum/SortByEnum.js +7 -7
  19. package/index.js +22 -22
  20. package/model/Address.js +95 -95
  21. package/model/AttributeType.js +50 -50
  22. package/model/AttributeValue.js +64 -64
  23. package/model/Banner.js +78 -78
  24. package/model/Brand.js +76 -76
  25. package/model/Cart.js +76 -76
  26. package/model/Category.js +72 -72
  27. package/model/CategoryAttributeType.js +62 -62
  28. package/model/Colour.js +52 -52
  29. package/model/Customer.js +94 -94
  30. package/model/DeviceToken.js +51 -51
  31. package/model/Document.js +70 -70
  32. package/model/DynamicUIComponent.js +52 -52
  33. package/model/Feedback.js +79 -79
  34. package/model/Inventory.js +83 -83
  35. package/model/NotificationHistory.js +67 -67
  36. package/model/Order.js +94 -94
  37. package/model/OrderItem.js +98 -98
  38. package/model/OrderItemHistory.js +69 -69
  39. package/model/OrderStatus.js +48 -48
  40. package/model/Payment.js +101 -101
  41. package/model/PaymentMethod.js +36 -36
  42. package/model/PaymentStatus.js +36 -36
  43. package/model/PaymentType.js +36 -36
  44. package/model/Permission.js +55 -55
  45. package/model/Product.js +82 -82
  46. package/model/ProductGroup.js +48 -48
  47. package/model/ProductSpecification.js +65 -65
  48. package/model/ProductVariant.js +75 -75
  49. package/model/ProductVariantAttribute.js +58 -58
  50. package/model/Role.js +61 -61
  51. package/model/RolePermissionMapping.js +63 -63
  52. package/model/SpecificationType.js +41 -41
  53. package/model/Store.js +99 -99
  54. package/model/StoreUserMapping.js +44 -44
  55. package/model/Tenant.js +91 -91
  56. package/model/TenantSettings.js +47 -47
  57. package/model/User.js +132 -132
  58. package/model/WishList.js +62 -62
  59. package/package.json +29 -28
  60. package/utility/AppUtil.js +65 -57
  61. package/utility/DateUtil.js +55 -55
  62. package/utility/ExcelUtil.js +125 -125
  63. package/utility/LocationUtility.js +130 -130
  64. package/utility/OrderTimeFilterUtil.js +87 -87
  65. package/utility/PdfUtil.js +64 -0
  66. package/utility/QueryUtil.js +261 -261
  67. package/utility/Razorpay.js +65 -65
  68. package/utility/VariantPriceUtil.js +54 -54
package/package.json CHANGED
@@ -1,28 +1,29 @@
1
- {
2
- "name": "@b2y/ecommerce-common",
3
- "version": "1.0.5",
4
- "description": "E-commerce common library",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/yuvakrishna29/ecommerce-common.git"
12
- },
13
- "publishConfig": {
14
- "access": "public"
15
- },
16
- "author": "Shikha",
17
- "license": "ISC",
18
- "bugs": {
19
- "url": "https://github.com/yuvakrishna29/ecommerce-common/issues"
20
- },
21
- "homepage": "https://github.com/yuvakrishna29/ecommerce-common#readme",
22
- "peerDependencies": {
23
- "exceljs": "^4.4.0",
24
- "luxon": "^3.7.2",
25
- "sequelize": "^6.37.5",
26
- "@countrystatecity/countries": "^1.0.4"
27
- }
28
- }
1
+ {
2
+ "name": "@b2y/ecommerce-common",
3
+ "version": "1.0.7",
4
+ "description": "E-commerce common library",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/yuvakrishna29/ecommerce-common.git"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "author": "Shikha",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/yuvakrishna29/ecommerce-common/issues"
20
+ },
21
+ "homepage": "https://github.com/yuvakrishna29/ecommerce-common#readme",
22
+ "peerDependencies": {
23
+ "@countrystatecity/countries": "^1.0.4",
24
+ "exceljs": "^4.4.0",
25
+ "luxon": "^3.7.2",
26
+ "puppeteer": "^24.35.0",
27
+ "sequelize": "^6.37.5"
28
+ }
29
+ }
@@ -1,58 +1,66 @@
1
- const BooleanEnum = require('../enum/BooleanEnum');
2
- const AppUtil = {
3
- generateResponse: function (statusCode, status, message, payload, res, customCode = null) {
4
- let response = {
5
- status,
6
- };
7
- if (
8
- payload &&
9
- (Array.isArray(payload) || Object.keys(payload).length > 0)
10
- ) {
11
- if (payload.rows && typeof payload.count !== "undefined") {
12
- const { rows, count, pageNumber, limit } = payload;
13
- const currentPage = Number(pageNumber) || 1;
14
- const pageSize = Number(limit) || count;
15
- const totalPages = Math.ceil(count / pageSize);
16
- response.data = rows;
17
- response.pagination = {
18
- totalRecords: count,
19
- totalPages,
20
- currentPage,
21
- pageSize,
22
- hasNext: currentPage < totalPages,
23
- hasPrev: currentPage > 1,
24
- };
25
- } else {
26
- // Non-paginated response
27
- response.data = payload;
28
- }
29
- }
30
- if (message) {
31
- // No data => return message (POST/PUT/DELETE-like APIs)
32
- response.message = message || "";
33
- }
34
- // if custome code also need to send in reponse body
35
- if (customCode) {
36
- response.customCode = customCode;
37
- }
38
- res.status(statusCode).send(response);
39
- },
40
- parseIsActive: function (isActive) {
41
- if (isActive === true || isActive === "true") return BooleanEnum.TRUE;
42
- if (isActive === false || isActive === "false") return BooleanEnum.FALSE;
43
- return undefined;
44
- },
45
- getPagination: function (page, size) {
46
- if (!size || !page) return {};
47
- const limit = +size;
48
- const offset = (page - 1) * limit;
49
- return { limit, offset };
50
- },
51
- trimDecimal: function (decimal) {
52
- const value = parseFloat(decimal);
53
- return Math.round(value)
54
- },
55
- };
56
-
57
-
1
+ const BooleanEnum = require('../enum/BooleanEnum');
2
+ const AppUtil = {
3
+ generateResponse: function (statusCode, status, message, payload, res, customCode = null) {
4
+ let response = {
5
+ status,
6
+ };
7
+ if (
8
+ payload &&
9
+ (Array.isArray(payload) || Object.keys(payload).length > 0)
10
+ ) {
11
+ if (payload.rows && typeof payload.count !== "undefined") {
12
+ const { rows, count, pageNumber, limit } = payload;
13
+ const currentPage = Number(pageNumber) || 1;
14
+ const pageSize = Number(limit) || count;
15
+ const totalPages = Math.ceil(count / pageSize);
16
+ response.data = rows;
17
+ response.pagination = {
18
+ totalRecords: count,
19
+ totalPages,
20
+ currentPage,
21
+ pageSize,
22
+ hasNext: currentPage < totalPages,
23
+ hasPrev: currentPage > 1,
24
+ };
25
+ } else {
26
+ // Non-paginated response
27
+ response.data = payload;
28
+ }
29
+ }
30
+ if (message) {
31
+ // No data => return message (POST/PUT/DELETE-like APIs)
32
+ response.message = message || "";
33
+ }
34
+ // if custome code also need to send in reponse body
35
+ if (customCode) {
36
+ response.customCode = customCode;
37
+ }
38
+ res.status(statusCode).send(response);
39
+ },
40
+ parseIsActive: function (isActive) {
41
+ if (isActive === true || isActive === "true") return BooleanEnum.TRUE;
42
+ if (isActive === false || isActive === "false") return BooleanEnum.FALSE;
43
+ return undefined;
44
+ },
45
+ getPagination: function (page, size) {
46
+ if (!size || !page) return {};
47
+ const limit = +size;
48
+ const offset = (page - 1) * limit;
49
+ return { limit, offset };
50
+ },
51
+ trimDecimal: function (decimal) {
52
+ const value = parseFloat(decimal);
53
+ return Math.round(value)
54
+ },
55
+ isValidEmail: function (email) {
56
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
57
+ return emailRegex.test(email.trim());
58
+ },
59
+ isValidPhone: function (phoneNumber) {
60
+ const phoneRegex = /^\d{10,20}$/;
61
+ return phoneRegex.test(phoneNumber);
62
+ }
63
+ };
64
+
65
+
58
66
  module.exports = AppUtil;
@@ -1,55 +1,55 @@
1
- const AppConstants = require('../constants/AppConstants');
2
- const {DateTime} = require('luxon');
3
- const StatusMessage = require('../constants/StatusMessageConstants');
4
- const DateUtil = {
5
- isValidDate: function (dateStr) {
6
- const dt = DateTime.fromISO(dateStr);
7
- return dt.isValid;
8
- },
9
- getDateRange: function (startDate, endDate, logger) {
10
- let currentStartDate, currentEndDate, previousStartDate, previousEndDate;
11
- if (startDate && endDate) {
12
- if (!this.isValidDate(startDate) || !this.isValidDate(endDate)) {
13
- logger.warn("invalid date format");
14
- throw new Error(StatusMessage.INVALID_DATE_FORMAT);
15
- }
16
- currentStartDate = DateTime.fromISO(startDate, { zone: "utc" });
17
- currentEndDate = DateTime.fromISO(endDate, { zone: "utc" });
18
- if (currentStartDate > currentEndDate) {
19
- logger.warn("invalid date range");
20
- throw new Error(StatusMessage.INVALID_DATE_RANGE);
21
- }
22
- const duration = currentEndDate.diff(currentStartDate);
23
- previousEndDate = currentStartDate;
24
- previousStartDate = previousEndDate.minus(duration);
25
- } else if (startDate || endDate) {
26
- // Only one provided
27
- logger.warn("start date and date date both required");
28
- throw new Error(StatusMessage.DATE_RANGE_REQUIRED);
29
- } else {
30
- // Default 7 days including today
31
- currentEndDate = DateTime.utc();
32
- currentStartDate = currentEndDate.minus({
33
- days: AppConstants.DASHBOARD_DEFAULT_DAYS - 1,
34
- });
35
-
36
- const duration = currentEndDate.diff(currentStartDate);
37
- previousEndDate = currentStartDate;
38
- previousStartDate = previousEndDate.minus(duration);
39
- }
40
-
41
- return {
42
- currentStartDate: currentStartDate.toISO(),
43
- currentEndDate: currentEndDate.toISO(),
44
- previousStartDate: previousStartDate.toISO(),
45
- previousEndDate: previousEndDate.toISO(),
46
- };
47
- },
48
- formatDate: function (date) {
49
- if (!(date instanceof Date)) return null;
50
- // conver JS date object to luxon date time
51
- const dt = DateTime.fromJSDate(date);
52
- return dt.toFormat('dd/MM/yyyy HH:mm:ss');
53
- }
54
- };
55
- module.exports = DateUtil;
1
+ const AppConstants = require('../constants/AppConstants');
2
+ const {DateTime} = require('luxon');
3
+ const StatusMessage = require('../constants/StatusMessageConstants');
4
+ const DateUtil = {
5
+ isValidDate: function (dateStr) {
6
+ const dt = DateTime.fromISO(dateStr);
7
+ return dt.isValid;
8
+ },
9
+ getDateRange: function (startDate, endDate, logger) {
10
+ let currentStartDate, currentEndDate, previousStartDate, previousEndDate;
11
+ if (startDate && endDate) {
12
+ if (!this.isValidDate(startDate) || !this.isValidDate(endDate)) {
13
+ logger.warn("invalid date format");
14
+ throw new Error(StatusMessage.INVALID_DATE_FORMAT);
15
+ }
16
+ currentStartDate = DateTime.fromISO(startDate, { zone: "utc" });
17
+ currentEndDate = DateTime.fromISO(endDate, { zone: "utc" });
18
+ if (currentStartDate > currentEndDate) {
19
+ logger.warn("invalid date range");
20
+ throw new Error(StatusMessage.INVALID_DATE_RANGE);
21
+ }
22
+ const duration = currentEndDate.diff(currentStartDate);
23
+ previousEndDate = currentStartDate;
24
+ previousStartDate = previousEndDate.minus(duration);
25
+ } else if (startDate || endDate) {
26
+ // Only one provided
27
+ logger.warn("start date and date date both required");
28
+ throw new Error(StatusMessage.DATE_RANGE_REQUIRED);
29
+ } else {
30
+ // Default 7 days including today
31
+ currentEndDate = DateTime.utc();
32
+ currentStartDate = currentEndDate.minus({
33
+ days: AppConstants.DASHBOARD_DEFAULT_DAYS - 1,
34
+ });
35
+
36
+ const duration = currentEndDate.diff(currentStartDate);
37
+ previousEndDate = currentStartDate;
38
+ previousStartDate = previousEndDate.minus(duration);
39
+ }
40
+
41
+ return {
42
+ currentStartDate: currentStartDate.toISO(),
43
+ currentEndDate: currentEndDate.toISO(),
44
+ previousStartDate: previousStartDate.toISO(),
45
+ previousEndDate: previousEndDate.toISO(),
46
+ };
47
+ },
48
+ formatDate: function (date) {
49
+ if (!(date instanceof Date)) return null;
50
+ // conver JS date object to luxon date time
51
+ const dt = DateTime.fromJSDate(date);
52
+ return dt.toFormat('dd/MM/yyyy HH:mm:ss');
53
+ }
54
+ };
55
+ module.exports = DateUtil;
@@ -1,125 +1,125 @@
1
- const ExcelJS = require('exceljs');
2
- const { EXCEL_METADATA, EXCEL_DEFAULT_THEME } = require("../constants/ReportConstants");
3
-
4
- class ExcelUtil {
5
-
6
- // Create workbook with metadata
7
- static createWorkbook() {
8
- const workbook = new ExcelJS.Workbook();
9
- workbook.creator = EXCEL_METADATA.CREATOR;
10
- workbook.lastModifiedBy = EXCEL_METADATA.LAST_MODIFIED_BY;
11
- workbook.created = new Date();
12
- workbook.modified = new Date();
13
- return workbook;
14
- }
15
-
16
- // Safe worksheet name
17
- static createWorksheet(workbook, sheetName) {
18
- const cleanSheetName = sheetName
19
- .replace(/[\\/*[\]:?]/g, "")
20
- .substring(0, 31);
21
-
22
- return workbook.addWorksheet(cleanSheetName);
23
- }
24
-
25
- // Setup headers using theme from constants
26
- static setupHeaders(worksheet, headers) {
27
- worksheet.columns = headers;
28
-
29
- const headerRow = worksheet.getRow(1);
30
- headerRow.eachCell(cell => {
31
- cell.font = {
32
- bold: true,
33
- color: { argb: EXCEL_DEFAULT_THEME.HEADER_FONT_COLOR },
34
- size: 11
35
- };
36
- cell.fill = {
37
- type: "pattern",
38
- pattern: "solid",
39
- fgColor: { argb: EXCEL_DEFAULT_THEME.HEADER_FILL_COLOR }
40
- };
41
- cell.alignment = { horizontal: "center", vertical: "middle", wrapText: true };
42
- cell.border = {
43
- top: { style: "thin" },
44
- left: { style: "thin" },
45
- bottom: { style: "thin" },
46
- right: { style: "thin" }
47
- };
48
- });
49
-
50
- worksheet.views = [{ state: "frozen", ySplit: 1 }];
51
- }
52
-
53
- static cleanValue(val) {
54
- if (val == null) return "";
55
-
56
- if (typeof val === "string") {
57
- // eslint-disable-next-line no-control-regex
58
- return val.replace(/[\x00-\x1F\x7F]/g, "");
59
- }
60
-
61
- if (typeof val === "object") {
62
- return JSON.stringify(val).substring(0, 32767);
63
- }
64
-
65
- return val;
66
- }
67
-
68
- static cleanRow(row) {
69
- const clean = {};
70
- for (let key in row) clean[key] = ExcelUtil.cleanValue(row[key]);
71
- return clean;
72
- }
73
-
74
- static styleDataRows(worksheet) {
75
- worksheet.eachRow((row, idx) => {
76
- if (idx !== 1) {
77
- row.eachCell(cell => {
78
- const isNumber = typeof cell.value === 'number';
79
- cell.alignment = { horizontal: isNumber ? 'right' : 'left', vertical: "middle", wrapText: true };
80
- cell.border = {
81
- top: { style: "thin" },
82
- left: { style: "thin" },
83
- bottom: { style: "thin" },
84
- right: { style: "thin" }
85
- };
86
- });
87
- }
88
- });
89
- }
90
-
91
- static autoAdjustColumns(worksheet) {
92
- worksheet.columns.forEach(col => {
93
- let maxLength = 10;
94
- col.eachCell({ includeEmpty: true }, cell => {
95
- const val = cell.value ? cell.value.toString() : "";
96
- maxLength = Math.max(maxLength, val.length + 2);
97
- });
98
- col.width = Math.min(maxLength, 50);
99
- });
100
- }
101
-
102
- static async writeToResponse(workbook, res, filename, logger) {
103
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
104
- const finalName = `${filename}_${timestamp}.xlsx`;
105
-
106
- res.setHeader("Content-Disposition", `attachment; filename="${finalName}"`);
107
- res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
108
- res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
109
- res.setHeader("Pragma", "no-cache");
110
- res.setHeader("Expires", "0");
111
- res.setHeader("Content-Transfer-Encoding", "binary");
112
-
113
- try {
114
- await workbook.xlsx.write(res);
115
- res.end();
116
- } catch (err) {
117
- logger.error("Excel generation error:", err);
118
- if (!res.headersSent) {
119
- res.status(500).json({ error: "Excel generation failed" });
120
- }
121
- }
122
- }
123
- }
124
-
125
- module.exports = ExcelUtil;
1
+ const ExcelJS = require('exceljs');
2
+ const { EXCEL_METADATA, EXCEL_DEFAULT_THEME } = require("../constants/ReportConstants");
3
+
4
+ class ExcelUtil {
5
+
6
+ // Create workbook with metadata
7
+ static createWorkbook() {
8
+ const workbook = new ExcelJS.Workbook();
9
+ workbook.creator = EXCEL_METADATA.CREATOR;
10
+ workbook.lastModifiedBy = EXCEL_METADATA.LAST_MODIFIED_BY;
11
+ workbook.created = new Date();
12
+ workbook.modified = new Date();
13
+ return workbook;
14
+ }
15
+
16
+ // Safe worksheet name
17
+ static createWorksheet(workbook, sheetName) {
18
+ const cleanSheetName = sheetName
19
+ .replace(/[\\/*[\]:?]/g, "")
20
+ .substring(0, 31);
21
+
22
+ return workbook.addWorksheet(cleanSheetName);
23
+ }
24
+
25
+ // Setup headers using theme from constants
26
+ static setupHeaders(worksheet, headers) {
27
+ worksheet.columns = headers;
28
+
29
+ const headerRow = worksheet.getRow(1);
30
+ headerRow.eachCell(cell => {
31
+ cell.font = {
32
+ bold: true,
33
+ color: { argb: EXCEL_DEFAULT_THEME.HEADER_FONT_COLOR },
34
+ size: 11
35
+ };
36
+ cell.fill = {
37
+ type: "pattern",
38
+ pattern: "solid",
39
+ fgColor: { argb: EXCEL_DEFAULT_THEME.HEADER_FILL_COLOR }
40
+ };
41
+ cell.alignment = { horizontal: "center", vertical: "middle", wrapText: true };
42
+ cell.border = {
43
+ top: { style: "thin" },
44
+ left: { style: "thin" },
45
+ bottom: { style: "thin" },
46
+ right: { style: "thin" }
47
+ };
48
+ });
49
+
50
+ worksheet.views = [{ state: "frozen", ySplit: 1 }];
51
+ }
52
+
53
+ static cleanValue(val) {
54
+ if (val == null) return "";
55
+
56
+ if (typeof val === "string") {
57
+ // eslint-disable-next-line no-control-regex
58
+ return val.replace(/[\x00-\x1F\x7F]/g, "");
59
+ }
60
+
61
+ if (typeof val === "object") {
62
+ return JSON.stringify(val).substring(0, 32767);
63
+ }
64
+
65
+ return val;
66
+ }
67
+
68
+ static cleanRow(row) {
69
+ const clean = {};
70
+ for (let key in row) clean[key] = ExcelUtil.cleanValue(row[key]);
71
+ return clean;
72
+ }
73
+
74
+ static styleDataRows(worksheet) {
75
+ worksheet.eachRow((row, idx) => {
76
+ if (idx !== 1) {
77
+ row.eachCell(cell => {
78
+ const isNumber = typeof cell.value === 'number';
79
+ cell.alignment = { horizontal: isNumber ? 'right' : 'left', vertical: "middle", wrapText: true };
80
+ cell.border = {
81
+ top: { style: "thin" },
82
+ left: { style: "thin" },
83
+ bottom: { style: "thin" },
84
+ right: { style: "thin" }
85
+ };
86
+ });
87
+ }
88
+ });
89
+ }
90
+
91
+ static autoAdjustColumns(worksheet) {
92
+ worksheet.columns.forEach(col => {
93
+ let maxLength = 10;
94
+ col.eachCell({ includeEmpty: true }, cell => {
95
+ const val = cell.value ? cell.value.toString() : "";
96
+ maxLength = Math.max(maxLength, val.length + 2);
97
+ });
98
+ col.width = Math.min(maxLength, 50);
99
+ });
100
+ }
101
+
102
+ static async writeToResponse(workbook, res, filename, logger) {
103
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
104
+ const finalName = `${filename}_${timestamp}.xlsx`;
105
+
106
+ res.setHeader("Content-Disposition", `attachment; filename="${finalName}"`);
107
+ res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
108
+ res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
109
+ res.setHeader("Pragma", "no-cache");
110
+ res.setHeader("Expires", "0");
111
+ res.setHeader("Content-Transfer-Encoding", "binary");
112
+
113
+ try {
114
+ await workbook.xlsx.write(res);
115
+ res.end();
116
+ } catch (err) {
117
+ logger.error("Excel generation error:", err);
118
+ if (!res.headersSent) {
119
+ res.status(500).json({ error: "Excel generation failed" });
120
+ }
121
+ }
122
+ }
123
+ }
124
+
125
+ module.exports = ExcelUtil;