@b2y/ecommerce-common 1.3.6 → 1.3.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 (96) hide show
  1. package/.idea/ecommerce-common.iml +11 -11
  2. package/.idea/modules.xml +7 -7
  3. package/.idea/vcs.xml +5 -5
  4. package/README.md +4 -4
  5. package/constants/AppConstants.js +15 -15
  6. package/constants/ReportConstants.js +14 -14
  7. package/constants/StatusMessageConstants.js +61 -61
  8. package/controller/LocationController.js +144 -144
  9. package/controller/SubscriptionAbstractController.js +91 -91
  10. package/controller/TenantAbstractController.js +152 -152
  11. package/controller/TenantSettingsAbstractController.js +243 -243
  12. package/dbconnection/Connect.js +498 -498
  13. package/enum/AccessModeEnum.js +8 -8
  14. package/enum/ActionByTypeEnum.js +4 -4
  15. package/enum/AddressTypeEnum.js +6 -6
  16. package/enum/BillingCycleEnum.js +5 -5
  17. package/enum/BooleanEnum.js +4 -4
  18. package/enum/BulkImportStatusEnum.js +6 -6
  19. package/enum/EntityTypeEnum.js +12 -12
  20. package/enum/FeatureTypeEnum.js +6 -6
  21. package/enum/GenderEnum.js +7 -7
  22. package/enum/NotificationStatusEnum.js +5 -5
  23. package/enum/NotificationTypeEnum.js +9 -9
  24. package/enum/OrderActionStatusEnum.js +7 -7
  25. package/enum/OrderStatusEnum.js +7 -7
  26. package/enum/PackageBoxTypeEnum.js +6 -6
  27. package/enum/PaymentMethodEnum.js +6 -6
  28. package/enum/PaymentStatusEnum.js +6 -6
  29. package/enum/PaymentTypeEnum.js +6 -6
  30. package/enum/PlatformEnum.js +4 -4
  31. package/enum/ReasonTypeEnum.js +6 -6
  32. package/enum/RegistrationStatusEnum.js +5 -5
  33. package/enum/SortByEnum.js +7 -7
  34. package/enum/SubscriptionStatusEnum.js +7 -7
  35. package/index.js +28 -28
  36. package/model/Address.js +95 -95
  37. package/model/AttributeType.js +50 -50
  38. package/model/AttributeValue.js +64 -64
  39. package/model/Banner.js +78 -78
  40. package/model/Brand.js +76 -76
  41. package/model/Cart.js +76 -76
  42. package/model/Category.js +72 -72
  43. package/model/CategoryAttributeType.js +62 -62
  44. package/model/Colour.js +52 -52
  45. package/model/Customer.js +94 -94
  46. package/model/DeviceToken.js +51 -51
  47. package/model/Document.js +73 -73
  48. package/model/DynamicUIComponent.js +52 -52
  49. package/model/Feedback.js +79 -79
  50. package/model/Inventory.js +87 -87
  51. package/model/NotificationHistory.js +67 -67
  52. package/model/Order.js +84 -84
  53. package/model/OrderActionReason.js +99 -99
  54. package/model/OrderItem.js +98 -98
  55. package/model/OrderItemHistory.js +69 -69
  56. package/model/OrderStatus.js +48 -48
  57. package/model/PackagingBox.js +78 -78
  58. package/model/Payment.js +101 -101
  59. package/model/PaymentMethod.js +36 -36
  60. package/model/PaymentStatus.js +36 -36
  61. package/model/PaymentType.js +36 -36
  62. package/model/Permission.js +55 -55
  63. package/model/Product.js +97 -97
  64. package/model/ProductGroup.js +48 -48
  65. package/model/ProductImport.js +55 -55
  66. package/model/ProductImportFailureAudits.js +57 -57
  67. package/model/ProductSpecification.js +65 -65
  68. package/model/ProductVariant.js +111 -111
  69. package/model/ProductVariantAttribute.js +58 -58
  70. package/model/ReasonContextMapping.js +70 -70
  71. package/model/ReasonMaster.js +74 -74
  72. package/model/Role.js +61 -61
  73. package/model/RolePermissionMapping.js +63 -63
  74. package/model/SpecificationType.js +41 -41
  75. package/model/Store.js +99 -99
  76. package/model/StoreUserMapping.js +44 -44
  77. package/model/SubscriptionFeature.js +53 -53
  78. package/model/SubscriptionPlan.js +70 -70
  79. package/model/SubscriptionPlanFeature.js +48 -48
  80. package/model/Tenant.js +91 -91
  81. package/model/TenantSettings.js +47 -47
  82. package/model/TenantSubscription.js +73 -73
  83. package/model/User.js +132 -132
  84. package/model/WishList.js +62 -62
  85. package/package.json +30 -30
  86. package/scripts/QueryBuilder.js +162 -162
  87. package/utility/AppUtil.js +65 -65
  88. package/utility/DateUtil.js +55 -55
  89. package/utility/ExcelUtil.js +125 -125
  90. package/utility/LocationUtility.js +130 -130
  91. package/utility/OrderTimeFilterUtil.js +88 -88
  92. package/utility/PdfUtil.js +64 -64
  93. package/utility/QueryUtil.js +261 -261
  94. package/utility/Razorpay.js +65 -65
  95. package/utility/ResolveAccessMode.js +61 -61
  96. package/utility/VariantPriceUtil.js +54 -54
@@ -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;
@@ -1,131 +1,131 @@
1
- const { getCountries, getStatesOfCountry, getCitiesOfState } = require('@countrystatecity/countries');
2
-
3
- // Helper to resolve country and state names from codes
4
- async function resolveCountryAndState(countryCode, stateCode, logger) {
5
- // eslint-disable-next-line no-useless-catch
6
- try {
7
- const trimmedCountry = countryCode ? String(countryCode).trim() : "";
8
- const trimmedState = stateCode ? String(stateCode).trim() : "";
9
-
10
- let countryName = trimmedCountry;
11
- let stateName = trimmedState;
12
-
13
- if (trimmedCountry) {
14
- try {
15
- const countries = await getCountries();
16
- const country = countries.find(
17
- (c) =>
18
- c.iso2 === trimmedCountry || c.iso2 === trimmedCountry.toUpperCase()
19
- );
20
- if (country) countryName = country.name;
21
- } catch (err) {
22
- logger.error("Error resolving country name:", err);
23
- }
24
- }
25
-
26
- if (trimmedState) {
27
- try {
28
- const states = await getStatesOfCountry(trimmedCountry);
29
- const state = states.find(
30
- (s) =>
31
- s.iso2 === trimmedState ||
32
- s.state_code === trimmedState ||
33
- s.state_code === trimmedState.toUpperCase()
34
- );
35
- if (state) stateName = state.name;
36
- } catch (err) {
37
- logger.error("Error resolving state name:", err);
38
- }
39
- }
40
-
41
- return { countryName, stateName };
42
- } catch (err) {
43
- throw err;
44
- }
45
- }
46
-
47
- // Helper to validate country and state codes
48
- async function validateCountryAndState(countryCode, stateCode, cityName, countryCallingCode, logger) {
49
- try {
50
- const trimmedCountryCode = countryCode ? String(countryCode).trim() : "";
51
- const trimmedStateCode = stateCode ? String(stateCode).trim() : "";
52
- const trimmedCityName = cityName ? cityName.trim().toLowerCase() : "";
53
- const trimmedCountryCallingCode = countryCallingCode ? countryCallingCode.replace('+', '').trim() : "";
54
- // Validate country code exists
55
- if (trimmedCountryCode) {
56
- const countries = await getCountries();
57
- const validCountry = countries.find(
58
- (c) =>
59
- c.iso2 === trimmedCountryCode ||
60
- c.iso2 === trimmedCountryCode.toUpperCase()
61
- );
62
-
63
- if (!validCountry) {
64
- return {
65
- isValid: false,
66
- error: `Invalid country code: ${countryCode}`,
67
- };
68
- }
69
-
70
- // Validate state code if provided
71
- if (trimmedStateCode) {
72
- const states = await getStatesOfCountry(trimmedCountryCode);
73
- const validState = states.find(
74
- (s) =>
75
- s.iso2 === trimmedStateCode ||
76
- s.state_code === trimmedStateCode ||
77
- s.state_code === trimmedStateCode.toUpperCase()
78
- );
79
-
80
- if (!validState) {
81
- return {
82
- isValid: false,
83
- error: `Invalid state code: ${stateCode} for country: ${countryCode}`,
84
- };
85
- }
86
- }
87
- if (trimmedCityName) {
88
- const cities = await getCitiesOfState(
89
- trimmedCountryCode,
90
- trimmedStateCode
91
- );
92
- const cityFound = cities.some(
93
- (city) => city.name.trim().toLowerCase() === trimmedCityName
94
- );
95
- if (!cityFound) {
96
- return {
97
- isValid: false,
98
- error: `Invalid city name for state code ${stateCode} and country code ${countryCode}`,
99
- };
100
- }
101
- }
102
- if (trimmedCountryCallingCode) {
103
- const countries = await getCountries();
104
- const validCallingCode = countries.find(
105
- (country) =>
106
- country.iso2 === trimmedCountryCode &&
107
- country.phonecode === trimmedCountryCallingCode
108
- );
109
- if (!validCallingCode) {
110
- return {
111
- isValid: false,
112
- error: `Invalid country calling code for country code ${trimmedCountryCode}`,
113
- };
114
- }
115
- }
116
- }
117
-
118
- return { isValid: true };
119
- } catch (err) {
120
- logger.error("Error during country/state/city validation:", err);
121
- return {
122
- isValid: false,
123
- error: "Error validating country code, state code and city name",
124
- };
125
- }
126
- }
127
-
128
- module.exports = {
129
- resolveCountryAndState,
130
- validateCountryAndState
1
+ const { getCountries, getStatesOfCountry, getCitiesOfState } = require('@countrystatecity/countries');
2
+
3
+ // Helper to resolve country and state names from codes
4
+ async function resolveCountryAndState(countryCode, stateCode, logger) {
5
+ // eslint-disable-next-line no-useless-catch
6
+ try {
7
+ const trimmedCountry = countryCode ? String(countryCode).trim() : "";
8
+ const trimmedState = stateCode ? String(stateCode).trim() : "";
9
+
10
+ let countryName = trimmedCountry;
11
+ let stateName = trimmedState;
12
+
13
+ if (trimmedCountry) {
14
+ try {
15
+ const countries = await getCountries();
16
+ const country = countries.find(
17
+ (c) =>
18
+ c.iso2 === trimmedCountry || c.iso2 === trimmedCountry.toUpperCase()
19
+ );
20
+ if (country) countryName = country.name;
21
+ } catch (err) {
22
+ logger.error("Error resolving country name:", err);
23
+ }
24
+ }
25
+
26
+ if (trimmedState) {
27
+ try {
28
+ const states = await getStatesOfCountry(trimmedCountry);
29
+ const state = states.find(
30
+ (s) =>
31
+ s.iso2 === trimmedState ||
32
+ s.state_code === trimmedState ||
33
+ s.state_code === trimmedState.toUpperCase()
34
+ );
35
+ if (state) stateName = state.name;
36
+ } catch (err) {
37
+ logger.error("Error resolving state name:", err);
38
+ }
39
+ }
40
+
41
+ return { countryName, stateName };
42
+ } catch (err) {
43
+ throw err;
44
+ }
45
+ }
46
+
47
+ // Helper to validate country and state codes
48
+ async function validateCountryAndState(countryCode, stateCode, cityName, countryCallingCode, logger) {
49
+ try {
50
+ const trimmedCountryCode = countryCode ? String(countryCode).trim() : "";
51
+ const trimmedStateCode = stateCode ? String(stateCode).trim() : "";
52
+ const trimmedCityName = cityName ? cityName.trim().toLowerCase() : "";
53
+ const trimmedCountryCallingCode = countryCallingCode ? countryCallingCode.replace('+', '').trim() : "";
54
+ // Validate country code exists
55
+ if (trimmedCountryCode) {
56
+ const countries = await getCountries();
57
+ const validCountry = countries.find(
58
+ (c) =>
59
+ c.iso2 === trimmedCountryCode ||
60
+ c.iso2 === trimmedCountryCode.toUpperCase()
61
+ );
62
+
63
+ if (!validCountry) {
64
+ return {
65
+ isValid: false,
66
+ error: `Invalid country code: ${countryCode}`,
67
+ };
68
+ }
69
+
70
+ // Validate state code if provided
71
+ if (trimmedStateCode) {
72
+ const states = await getStatesOfCountry(trimmedCountryCode);
73
+ const validState = states.find(
74
+ (s) =>
75
+ s.iso2 === trimmedStateCode ||
76
+ s.state_code === trimmedStateCode ||
77
+ s.state_code === trimmedStateCode.toUpperCase()
78
+ );
79
+
80
+ if (!validState) {
81
+ return {
82
+ isValid: false,
83
+ error: `Invalid state code: ${stateCode} for country: ${countryCode}`,
84
+ };
85
+ }
86
+ }
87
+ if (trimmedCityName) {
88
+ const cities = await getCitiesOfState(
89
+ trimmedCountryCode,
90
+ trimmedStateCode
91
+ );
92
+ const cityFound = cities.some(
93
+ (city) => city.name.trim().toLowerCase() === trimmedCityName
94
+ );
95
+ if (!cityFound) {
96
+ return {
97
+ isValid: false,
98
+ error: `Invalid city name for state code ${stateCode} and country code ${countryCode}`,
99
+ };
100
+ }
101
+ }
102
+ if (trimmedCountryCallingCode) {
103
+ const countries = await getCountries();
104
+ const validCallingCode = countries.find(
105
+ (country) =>
106
+ country.iso2 === trimmedCountryCode &&
107
+ country.phonecode === trimmedCountryCallingCode
108
+ );
109
+ if (!validCallingCode) {
110
+ return {
111
+ isValid: false,
112
+ error: `Invalid country calling code for country code ${trimmedCountryCode}`,
113
+ };
114
+ }
115
+ }
116
+ }
117
+
118
+ return { isValid: true };
119
+ } catch (err) {
120
+ logger.error("Error during country/state/city validation:", err);
121
+ return {
122
+ isValid: false,
123
+ error: "Error validating country code, state code and city name",
124
+ };
125
+ }
126
+ }
127
+
128
+ module.exports = {
129
+ resolveCountryAndState,
130
+ validateCountryAndState
131
131
  };