@alba-cars/common-modules 2.0.0 → 2.1.0

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 (146) hide show
  1. package/dist/index.js +1 -21
  2. package/package.json +10 -6
  3. package/dist/core/enums/HttpMethods.js +0 -14
  4. package/dist/core/enums/HttpStatusCodes.js +0 -19
  5. package/dist/core/enums/index.js +0 -18
  6. package/dist/core/error-handling/AppError.js +0 -48
  7. package/dist/core/error-handling/index.js +0 -17
  8. package/dist/core/index.js +0 -21
  9. package/dist/core/models/index.js +0 -19
  10. package/dist/core/models/media/index.js +0 -17
  11. package/dist/core/models/media/media_data.js +0 -2
  12. package/dist/core/models/pagination/index.js +0 -17
  13. package/dist/core/models/pagination/paginated_data.js +0 -21
  14. package/dist/core/models/range.js +0 -26
  15. package/dist/core/network/api-client.d.ts +0 -1
  16. package/dist/core/network/api-client.js +0 -22
  17. package/dist/core/network/endpoint-config.js +0 -260
  18. package/dist/core/network/fetch-api.js +0 -206
  19. package/dist/core/network/index.js +0 -18
  20. package/dist/core/utils/formatCurrency.js +0 -39
  21. package/dist/core/utils/global-constants.js +0 -9
  22. package/dist/core/utils/global-utils.js +0 -190
  23. package/dist/core/utils/global_validators.js +0 -20
  24. package/dist/core/utils/index.js +0 -20
  25. package/dist/core/utils/query_flatten.js +0 -15
  26. package/dist/features/auth/data/dto/AuthDTO.js +0 -106
  27. package/dist/features/auth/data/dto/RoleDTO.js +0 -132
  28. package/dist/features/auth/data/dto/UserDTO.js +0 -222
  29. package/dist/features/auth/data/index.js +0 -19
  30. package/dist/features/auth/index.js +0 -17
  31. package/dist/features/bank-valuation-request/data/dto/BankValuationRequestDTO.js +0 -132
  32. package/dist/features/bank-valuation-request/index.js +0 -17
  33. package/dist/features/blog/data/dto/BlogDTO.js +0 -176
  34. package/dist/features/blog/index.js +0 -17
  35. package/dist/features/callback-request/data/dto/CallBackRequestDTO.js +0 -110
  36. package/dist/features/callback-request/index.js +0 -17
  37. package/dist/features/deposits/data/dto/DepositDTOs.js +0 -303
  38. package/dist/features/deposits/data/index.js +0 -17
  39. package/dist/features/deposits/index.js +0 -17
  40. package/dist/features/faq/data/dtos/CreateFaqDTO.js +0 -87
  41. package/dist/features/faq/data/dtos/FaqFetchDTO.js +0 -349
  42. package/dist/features/faq/data/dtos/UpdateFaqDTO.js +0 -91
  43. package/dist/features/faq/data/dtos/index.js +0 -19
  44. package/dist/features/faq/data/enums/index.js +0 -10
  45. package/dist/features/faq/data/index.js +0 -18
  46. package/dist/features/faq/index.js +0 -17
  47. package/dist/features/finance-eligibilty-request/data/dto/FinanceEligibilityRequestDTO.js +0 -429
  48. package/dist/features/finance-eligibilty-request/data/index.js +0 -17
  49. package/dist/features/finance-eligibilty-request/index.js +0 -17
  50. package/dist/features/google-review/data/dto/google_review_dto.js +0 -466
  51. package/dist/features/google-review/data/dto/index.js +0 -17
  52. package/dist/features/google-review/data/enums/index.js +0 -8
  53. package/dist/features/google-review/data/index.js +0 -18
  54. package/dist/features/google-review/index.js +0 -17
  55. package/dist/features/index.js +0 -34
  56. package/dist/features/lead/data/dto/index.js +0 -20
  57. package/dist/features/lead/data/dto/lead_documents_dto.js +0 -73
  58. package/dist/features/lead/data/dto/lead_dto.js +0 -435
  59. package/dist/features/lead/data/dto/lead_preference_history_dto.js +0 -321
  60. package/dist/features/lead/data/dto/lead_prefernce_dto.js +0 -308
  61. package/dist/features/lead/data/enum/index.js +0 -18
  62. package/dist/features/lead/data/enum/lead_source_status_types.js +0 -19
  63. package/dist/features/lead/data/enum/lead_status_type.js +0 -12
  64. package/dist/features/lead/index.js +0 -18
  65. package/dist/features/models/BankValuationRequest.js +0 -6
  66. package/dist/features/models/Base.js +0 -6
  67. package/dist/features/models/Deposit.js +0 -6
  68. package/dist/features/models/Lead.js +0 -6
  69. package/dist/features/models/Payment.js +0 -7
  70. package/dist/features/models/Roles.js +0 -2
  71. package/dist/features/models/Ticket.js +0 -12
  72. package/dist/features/models/User.js +0 -2
  73. package/dist/features/models/UserFavoriteVehicle.js +0 -6
  74. package/dist/features/models/Vehicle.js +0 -17
  75. package/dist/features/models/VehicleBodyType.js +0 -7
  76. package/dist/features/models/VehicleCategory.js +0 -7
  77. package/dist/features/models/VehicleFeature.js +0 -7
  78. package/dist/features/models/VehicleFeatureCategory.js +0 -7
  79. package/dist/features/models/VehicleFinance.js +0 -7
  80. package/dist/features/models/VehicleMake.js +0 -7
  81. package/dist/features/models/VehicleMedia.js +0 -7
  82. package/dist/features/models/VehicleMetaData.js +0 -7
  83. package/dist/features/models/VehicleModel.js +0 -7
  84. package/dist/features/models/VehicleOrder.js +0 -7
  85. package/dist/features/models/_index.js +0 -30
  86. package/dist/features/models/index.js +0 -37
  87. package/dist/features/newsletter/data/dto/NewsletterDTO.js +0 -79
  88. package/dist/features/newsletter/index.js +0 -17
  89. package/dist/features/sales-team/data/dto/LanguageDTO.js +0 -89
  90. package/dist/features/sales-team/data/dto/SalesAgentDTO.js +0 -613
  91. package/dist/features/sales-team/data/index.js +0 -18
  92. package/dist/features/sales-team/index.js +0 -17
  93. package/dist/features/sell-car-request/data/dto/SellCarRequestDTO.js +0 -672
  94. package/dist/features/sell-car-request/data/index.js +0 -17
  95. package/dist/features/sell-car-request/index.js +0 -17
  96. package/dist/features/showroom-visit/data/dto/ShowroomVisit.js +0 -237
  97. package/dist/features/showroom-visit/data/enums/index.js +0 -17
  98. package/dist/features/showroom-visit/data/index.js +0 -18
  99. package/dist/features/showroom-visit/index.js +0 -17
  100. package/dist/features/test-drive-request/api/GetTestDriveVehicles.js +0 -8
  101. package/dist/features/test-drive-request/api/index.js +0 -17
  102. package/dist/features/test-drive-request/data/dto/TestDriveRequestDTO.js +0 -179
  103. package/dist/features/test-drive-request/data/enums/index.js +0 -29
  104. package/dist/features/test-drive-request/data/index.js +0 -20
  105. package/dist/features/test-drive-request/data/models/TestDriveRequest.js +0 -7
  106. package/dist/features/test-drive-request/data/models/index.js +0 -5
  107. package/dist/features/test-drive-request/data/utilities.js +0 -100
  108. package/dist/features/test-drive-request/index.js +0 -18
  109. package/dist/features/tickets/data/dto/TicketDto.js +0 -293
  110. package/dist/features/tickets/data/enums/index.js +0 -18
  111. package/dist/features/tickets/index.js +0 -18
  112. package/dist/features/vehicle/data/dto/BaseDTO.js +0 -34
  113. package/dist/features/vehicle/data/dto/MediaDTO.js +0 -2
  114. package/dist/features/vehicle/data/dto/PaymentDTO.js +0 -161
  115. package/dist/features/vehicle/data/dto/SimilarVehicleDTO.js +0 -38
  116. package/dist/features/vehicle/data/dto/VehicleCategoryDTO.js +0 -114
  117. package/dist/features/vehicle/data/dto/VehicleDTO.js +0 -587
  118. package/dist/features/vehicle/data/dto/VehicleFavoritesDTO.js +0 -60
  119. package/dist/features/vehicle/data/dto/VehicleFeatureCategoriesDTO.js +0 -114
  120. package/dist/features/vehicle/data/dto/VehicleFeatureDTO.js +0 -125
  121. package/dist/features/vehicle/data/dto/VehicleFilterDTO.js +0 -771
  122. package/dist/features/vehicle/data/dto/VehicleFinanceDTO.js +0 -183
  123. package/dist/features/vehicle/data/dto/VehicleInspectionDTO.js +0 -765
  124. package/dist/features/vehicle/data/dto/VehicleMakeDTO.js +0 -189
  125. package/dist/features/vehicle/data/dto/VehicleMedia.js +0 -152
  126. package/dist/features/vehicle/data/dto/VehicleModelDTO.js +0 -182
  127. package/dist/features/vehicle/data/dto/VehicleOrderDTO.js +0 -139
  128. package/dist/features/vehicle/data/dto/VehicleTypeDTO.js +0 -102
  129. package/dist/features/vehicle/data/dto/VehicleWarrantyDTO.js +0 -47
  130. package/dist/features/vehicle/data/dto/index.js +0 -35
  131. package/dist/features/vehicle/data/enums/index.js +0 -46
  132. package/dist/features/vehicle/data/index.js +0 -20
  133. package/dist/features/vehicle/data/utilities.js +0 -520
  134. package/dist/features/vehicle/index.js +0 -17
  135. package/dist/features/vehicle-reservations/data/dto/VehicleReservationDTO.js +0 -346
  136. package/dist/features/vehicle-reservations/data/dto/index.js +0 -17
  137. package/dist/features/vehicle-reservations/data/enums/finance-type.js +0 -9
  138. package/dist/features/vehicle-reservations/data/enums/index.js +0 -19
  139. package/dist/features/vehicle-reservations/data/enums/reservation-type.js +0 -13
  140. package/dist/features/vehicle-reservations/data/enums/vehicle-reservation-type.js +0 -8
  141. package/dist/features/vehicle-reservations/index.js +0 -18
  142. package/dist/global/dto/BaseGetDTO.js +0 -18
  143. package/dist/global/dto/index.js +0 -17
  144. package/dist/global/index.js +0 -18
  145. package/dist/global/utilities.js +0 -173
  146. package/dist/models.js +0 -17
@@ -1,206 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.apiRequest = exports.interceptors = void 0;
7
- const qs_1 = __importDefault(require("qs"));
8
- const enums_1 = require("../enums");
9
- const utils_1 = require("../utils");
10
- const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
11
- const DEFAULT_TIMEOUT = (0, utils_1.timeAsMilliseconds)({ seconds: 30 });
12
- // Interceptor manager
13
- class InterceptorManager {
14
- constructor() {
15
- this.requestInterceptors = [];
16
- this.responseInterceptors = [];
17
- this.responseErrorInterceptors = [];
18
- }
19
- addRequestInterceptor(interceptor) {
20
- return this.requestInterceptors.push(interceptor) - 1;
21
- }
22
- addResponseInterceptor(interceptor) {
23
- return this.responseInterceptors.push(interceptor) - 1;
24
- }
25
- addResponseErrorInterceptor(interceptor) {
26
- return this.responseErrorInterceptors.push(interceptor) - 1;
27
- }
28
- removeRequestInterceptor(index) {
29
- if (index >= 0) {
30
- this.requestInterceptors.splice(index, 1);
31
- }
32
- }
33
- removeResponseInterceptor(index) {
34
- if (index >= 0) {
35
- this.responseInterceptors.splice(index, 1);
36
- }
37
- }
38
- removeResponseErrorInterceptor(index) {
39
- if (index >= 0) {
40
- this.responseErrorInterceptors.splice(index, 1);
41
- }
42
- }
43
- clearRequestInterceptors() {
44
- this.requestInterceptors = [];
45
- }
46
- clearResponseInterceptors() {
47
- this.responseInterceptors = [];
48
- }
49
- clearResponseErrorInterceptors() {
50
- this.responseErrorInterceptors = [];
51
- }
52
- clearAllInterceptors() {
53
- this.clearRequestInterceptors();
54
- this.clearResponseInterceptors();
55
- this.clearResponseErrorInterceptors();
56
- }
57
- async applyRequestInterceptors(config) {
58
- let modifiedConfig = { ...config };
59
- for (const interceptor of this.requestInterceptors) {
60
- modifiedConfig = await interceptor(modifiedConfig);
61
- }
62
- return modifiedConfig;
63
- }
64
- async applyResponseInterceptors(response, requestConfig) {
65
- let modifiedResponse = response;
66
- for (const interceptor of this.responseInterceptors) {
67
- modifiedResponse = await interceptor(modifiedResponse, requestConfig);
68
- }
69
- return modifiedResponse;
70
- }
71
- async applyResponseErrorInterceptors(error, requestConfig) {
72
- // Create a chain of error interceptors that can potentially resolve the error
73
- let promise = Promise.reject(error);
74
- for (const interceptor of this.responseErrorInterceptors) {
75
- promise = promise.catch((currentError) => interceptor(currentError, requestConfig));
76
- }
77
- return promise;
78
- }
79
- async retryRequest(config) {
80
- // Mark this as a retry request to avoid infinite loops
81
- const retryConfig = {
82
- ...config,
83
- options: {
84
- ...config.options,
85
- isRetry: true,
86
- },
87
- };
88
- try {
89
- // Apply request interceptors before retrying
90
- const interceptedConfig = await this.applyRequestInterceptors(retryConfig);
91
- // Make a new request with the updated config
92
- const response = await fetch(interceptedConfig.url, interceptedConfig);
93
- // Apply response interceptors
94
- const interceptedResponse = await this.applyResponseInterceptors(response, interceptedConfig);
95
- // Process the response
96
- const contentType = interceptedResponse.headers.get("content-type");
97
- const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
98
- ? await interceptedResponse.json()
99
- : await interceptedResponse.text();
100
- if (interceptedResponse.ok) {
101
- return responseData;
102
- }
103
- // Handle errors
104
- const apiError = createApiError(interceptedResponse.status, responseData);
105
- throw apiError;
106
- }
107
- catch (error) {
108
- // For retry requests, don't apply error interceptors again to avoid loops
109
- if (config.options.isRetry) {
110
- throw error;
111
- }
112
- // Apply response error interceptors
113
- return this.applyResponseErrorInterceptors(error, retryConfig);
114
- }
115
- }
116
- }
117
- // Create the interceptor manager instance
118
- exports.interceptors = new InterceptorManager();
119
- const buildUrl = (endpoint, query) => {
120
- let url = `${BASE_URL}${endpoint}`;
121
- if (query && Object.keys(query).length > 0) {
122
- url += `?${qs_1.default.stringify(query, {
123
- allowDots: true,
124
- arrayFormat: "brackets",
125
- allowEmptyArrays: false,
126
- skipNulls: true,
127
- })}`;
128
- }
129
- return url;
130
- };
131
- async function apiRequest(endpoint, options = {}) {
132
- var _a;
133
- let timeoutId;
134
- const controller = options.timeout ? new AbortController() : undefined;
135
- // If timeout is specified, create a timeout abort controller
136
- if (options.timeout && controller) {
137
- timeoutId = setTimeout(() => {
138
- controller.abort("Request timeout");
139
- }, options.timeout || DEFAULT_TIMEOUT);
140
- }
141
- // Use provided signal or timeout controller's signal
142
- const signal = options.signal || (controller === null || controller === void 0 ? void 0 : controller.signal);
143
- const headers = {
144
- Accept: "application/json",
145
- "Content-Type": "application/json",
146
- ...options.headers,
147
- };
148
- const config = {
149
- method: (_a = options.method) !== null && _a !== void 0 ? _a : enums_1.HttpMethods.GET,
150
- headers,
151
- ...(signal && { signal }),
152
- ...options,
153
- options, // Keep a reference to the original options
154
- };
155
- try {
156
- const response = await makeRequest(endpoint, config);
157
- return response;
158
- }
159
- finally {
160
- if (timeoutId) {
161
- clearTimeout(timeoutId);
162
- }
163
- }
164
- }
165
- exports.apiRequest = apiRequest;
166
- async function makeRequest(endpoint, config) {
167
- const url = buildUrl(endpoint, config.options.query);
168
- // Apply request interceptors with the full context including options
169
- let requestConfig = await exports.interceptors.applyRequestInterceptors({
170
- ...config,
171
- url,
172
- });
173
- // Extract the URL after interceptors may have modified it
174
- const interceptedUrl = requestConfig.url;
175
- try {
176
- // Make the actual request
177
- const response = await fetch(interceptedUrl, requestConfig);
178
- // Apply response interceptors with the full context
179
- const interceptedResponse = await exports.interceptors.applyResponseInterceptors(response, { ...requestConfig, url: interceptedUrl });
180
- const contentType = interceptedResponse.headers.get("content-type");
181
- const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
182
- ? await interceptedResponse.json()
183
- : await interceptedResponse.text();
184
- if (interceptedResponse.ok) {
185
- return responseData;
186
- }
187
- // Handle other errors
188
- const apiError = createApiError(interceptedResponse.status, responseData);
189
- throw apiError;
190
- }
191
- catch (error) {
192
- // Apply response error interceptors with the full context
193
- return exports.interceptors.applyResponseErrorInterceptors(error, {
194
- ...requestConfig,
195
- url: interceptedUrl,
196
- });
197
- }
198
- }
199
- function createApiError(status, responseData) {
200
- const error = new Error(typeof responseData === "object"
201
- ? responseData.message || "API Error"
202
- : "API Error");
203
- error.status = status;
204
- error.data = responseData;
205
- return error;
206
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./endpoint-config"), exports);
18
- __exportStar(require("./fetch-api"), exports);
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatCurrency = void 0;
4
- /**
5
- * Formats a number as UAE Dirham (AED) currency with proper comma separation
6
- * @param amount The numeric value to be formatted
7
- * @param options Optional configuration for formatting
8
- * @returns Formatted currency string
9
- */
10
- const formatCurrency = (amount, options = {}) => {
11
- // If amount is null or undefined, return 'N/A'
12
- if (amount == null)
13
- return 'N/A';
14
- // Default options
15
- const { currency = 'AED', minimumFractionDigits = 0, maximumFractionDigits = 0 } = options;
16
- try {
17
- // Use English locale to ensure consistent formatting
18
- const formatter = new Intl.NumberFormat('en-US', {
19
- minimumFractionDigits,
20
- maximumFractionDigits,
21
- useGrouping: true
22
- });
23
- // Format the number with comma separation
24
- const formattedAmount = formatter.format(amount);
25
- // Prepend AED to the formatted amount
26
- return `AED ${formattedAmount}`;
27
- }
28
- catch (error) {
29
- // Fallback formatting if Intl.NumberFormat fails
30
- console.warn('Currency formatting failed, using basic formatting', error);
31
- // Basic fallback formatting
32
- const baseFormatted = amount.toLocaleString('en-US', {
33
- minimumFractionDigits,
34
- maximumFractionDigits
35
- });
36
- return `AED ${baseFormatted}`;
37
- }
38
- };
39
- exports.formatCurrency = formatCurrency;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ONE_MINUTE = exports.ONE_HOUR = exports.THIRTY_MINUTES_MILLIS = exports.FIFTEEN_MINUTES_MILLIS = exports.ONE_HOUR_MILLIS = exports.ONE_MINUTE_MILLIS = void 0;
4
- exports.ONE_MINUTE_MILLIS = 1000 * 60;
5
- exports.ONE_HOUR_MILLIS = 1000 * 60 * 60;
6
- exports.FIFTEEN_MINUTES_MILLIS = 15 * 60 * 1000;
7
- exports.THIRTY_MINUTES_MILLIS = 30 * 60 * 1000;
8
- exports.ONE_HOUR = 3600;
9
- exports.ONE_MINUTE = 60;
@@ -1,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.booleanize = exports.toPlainObject = exports.sanitizeRegexString = exports.getPlural = exports.hasValue = exports.isEmptyArray = exports.isEmptyObject = exports.isEmpty = exports.makeArray = exports.formatNumberWithCommas = exports.safeParseNumber = exports.currencyFormatter = exports.removeKeyFromObject = exports.timeAsSeconds = exports.timeAsMilliseconds = exports.formatValue = exports.generateRandomBase64 = exports.sortBy = exports.isFunction = exports.isPlainObject = exports.deepEqual = void 0;
4
- /**
5
- * Deeply compares two objects for equality.
6
- *
7
- * @param obj1 - The first object to compare.
8
- * @param obj2 - The second object to compare.
9
- * @returns `true` if the objects are deeply equal, `false` otherwise.
10
- */
11
- const deepEqual = (obj1, obj2) => {
12
- // this handles primitive types
13
- if (obj1 === obj2) {
14
- return true;
15
- }
16
- if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
17
- return false;
18
- }
19
- const keys1 = Object.keys(obj1);
20
- const keys2 = Object.keys(obj2);
21
- if (keys1.length !== keys2.length) {
22
- return false;
23
- }
24
- for (const key of keys1) {
25
- if (!keys2.includes(key)) {
26
- return false;
27
- }
28
- }
29
- for (const key of keys1) {
30
- const value1 = obj1[key];
31
- const value2 = obj2[key];
32
- if (!(0, exports.deepEqual)(value1, value2)) {
33
- return false;
34
- }
35
- }
36
- return true;
37
- };
38
- exports.deepEqual = deepEqual;
39
- /**
40
- * Checks if a value is a plain object (not an array or null)
41
- *
42
- * @template T
43
- * @param {T} obj
44
- * @returns {boolean}
45
- */
46
- const isPlainObject = (obj) => typeof obj === "object" && obj !== null && !Array.isArray(obj);
47
- exports.isPlainObject = isPlainObject;
48
- /**
49
- * Checks if a value is a function
50
- *
51
- * @param {*} value
52
- * @returns {boolean}
53
- */
54
- const isFunction = (value) => typeof value === "function";
55
- exports.isFunction = isFunction;
56
- /**
57
- * Function to sort an array by a specific key (for arrays of objects) or a comparator function
58
- *
59
- * @param {any[]} array
60
- * @param {(string | ComparatorFunction)} key
61
- * @returns {any[]}
62
- */
63
- const sortBy = (array, key) => {
64
- const compareFn = typeof key === "function" ? key : (a, b) => a[key] - b[key];
65
- return array.slice().sort(compareFn);
66
- };
67
- exports.sortBy = sortBy;
68
- function generateRandomBase64(length) {
69
- const randomBytes = new Uint8Array(length);
70
- crypto.getRandomValues(randomBytes);
71
- return btoa(String.fromCharCode(...Array.from(randomBytes)));
72
- }
73
- exports.generateRandomBase64 = generateRandomBase64;
74
- const formatValue = (n) => {
75
- return Number(n)
76
- .toString()
77
- .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
78
- };
79
- exports.formatValue = formatValue;
80
- /**
81
- * Converts a time input to milliseconds
82
- */
83
- const timeAsMilliseconds = ({ minutes = 0, hours = 0, seconds = 0 }) => {
84
- return minutes * 60 * 1000 + hours * 60 * 60 * 1000 + seconds * 1000;
85
- };
86
- exports.timeAsMilliseconds = timeAsMilliseconds;
87
- /**
88
- * Converts a time input to seconds
89
- */
90
- const timeAsSeconds = ({ minutes = 0, hours = 0, seconds = 0 }) => {
91
- return minutes * 60 + hours * 60 * 60 + seconds;
92
- };
93
- exports.timeAsSeconds = timeAsSeconds;
94
- /**
95
- * Removes a key from an object or an array of objects (deeply)
96
- */
97
- function removeKeyFromObject(obj, keyToRemove) {
98
- if (Array.isArray(obj)) {
99
- return obj.map((item) => removeKeyFromObject(item, keyToRemove));
100
- }
101
- else if (typeof obj === "object" && obj !== null) {
102
- return Object.keys(obj).reduce((acc, key) => {
103
- if (key !== keyToRemove) {
104
- acc[key] = removeKeyFromObject(obj[key], keyToRemove);
105
- }
106
- return acc;
107
- }, {});
108
- }
109
- return obj;
110
- }
111
- exports.removeKeyFromObject = removeKeyFromObject;
112
- /**
113
- * Formats a number as a currency string (AED)
114
- */
115
- const currencyFormatter = ({ isDecimal, decimalPlaces = 2 }) => new Intl.NumberFormat('en-US', {
116
- style: "currency",
117
- currency: "AED",
118
- maximumFractionDigits: isDecimal ? decimalPlaces : 0,
119
- });
120
- exports.currencyFormatter = currencyFormatter;
121
- /**
122
- * Safely parses a string or number into a number
123
- */
124
- const safeParseNumber = (value) => {
125
- if (typeof value === 'number')
126
- return value;
127
- if (typeof value !== 'string')
128
- return 0;
129
- return Number(value.trim().replace(/,/g, '')) || 0;
130
- };
131
- exports.safeParseNumber = safeParseNumber;
132
- /**
133
- * Formats a number with commas
134
- */
135
- const formatNumberWithCommas = (value) => {
136
- const number = value.replace(/[^\d]/g, '');
137
- return number.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
138
- };
139
- exports.formatNumberWithCommas = formatNumberWithCommas;
140
- /**
141
- * Converts a single value or an array of values into an array
142
- */
143
- const makeArray = (value) => {
144
- return Array.isArray(value) ? value : [value];
145
- };
146
- exports.makeArray = makeArray;
147
- /**
148
- * Check if a value is empty (nullable or empty string)
149
- */
150
- const isEmpty = (value) => (value === null || value === undefined || value === '');
151
- exports.isEmpty = isEmpty;
152
- /**
153
- * Check if an object is an empty object
154
- */
155
- const isEmptyObject = (value) => Object.keys(value).length === 0 && value.constructor === Object;
156
- exports.isEmptyObject = isEmptyObject;
157
- /**
158
- * Check if a value is an empty array
159
- */
160
- const isEmptyArray = (value) => Array.isArray(value) && value.length === 0;
161
- exports.isEmptyArray = isEmptyArray;
162
- /**
163
- * Checks if a value is not empty (null, undefined, or empty string), not an empty object, and not an empty array
164
- */
165
- const hasValue = (value) => !(0, exports.isEmpty)(value) && !(0, exports.isEmptyObject)(value) && !(0, exports.isEmptyArray)(value);
166
- exports.hasValue = hasValue;
167
- /**
168
- * Returns a pluralized string based on the value
169
- * @example getPlural(1, 'item') => '1 item'
170
- * @example getPlural(4, 'item') => '4 items'
171
- * @example getPlural(2, 'person', 'people') => '2 people'
172
- * @example getPlural(0, 'item') => '0 items'
173
- */
174
- const getPlural = (value, singular, plural = null) => value === 1 ? `${value} ${singular}` : plural ? `${value} ${plural}` : `${value} ${singular}s`;
175
- exports.getPlural = getPlural;
176
- /**
177
- * Escapes special characters in a search term to prevent them from being interpreted as regex operators
178
- */
179
- const sanitizeRegexString = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
180
- exports.sanitizeRegexString = sanitizeRegexString;
181
- /**
182
- * Converts a value to a plain object by serializing to and from JSON
183
- */
184
- const toPlainObject = (value) => JSON.parse(JSON.stringify(value));
185
- exports.toPlainObject = toPlainObject;
186
- /**
187
- * Converts a Booleanish value (boolean | 'true' | '1' | 'false' | '0') to a boolean
188
- */
189
- const booleanize = (value) => ([true, 'true', '1'].includes(value) ? true : false);
190
- exports.booleanize = booleanize;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateVIN = exports.validateChassisNumber = void 0;
4
- const validateChassisNumber = (value) => {
5
- const chassisRegex = /^[A-HJ-NPR-Z0-9]{15,20}$/; // Valid alphanumerics excluding I, O, Q
6
- if (!chassisRegex.test(value)) {
7
- return "Invalid Chassis Number";
8
- }
9
- return true; // If valid, return true
10
- };
11
- exports.validateChassisNumber = validateChassisNumber;
12
- const validateVIN = (value) => {
13
- // Regex to exclude I, O, Q and check for VIN's valid structure
14
- const vinRegex = /^[A-HJ-NPR-Z0-9]{8}$/;
15
- if (!vinRegex.test(value)) {
16
- return "Invalid VIN format";
17
- }
18
- return true; // Validation passed
19
- };
20
- exports.validateVIN = validateVIN;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./global-utils"), exports);
18
- __exportStar(require("./global-constants"), exports);
19
- __exportStar(require("./global_validators"), exports);
20
- __exportStar(require("./formatCurrency"), exports);
@@ -1,15 +0,0 @@
1
- "use strict";
2
- function flattenQuery(query) {
3
- const flattened = {};
4
- for (const key in query) {
5
- if (typeof query[key] === "object" && query[key] !== null) {
6
- for (const subKey in query[key]) {
7
- flattened[subKey] = query[key][subKey];
8
- }
9
- }
10
- else {
11
- flattened[key] = query[key];
12
- }
13
- }
14
- return flattened;
15
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AuthResponseDTO = exports.OtpLoginDTO = exports.LoginDTO = exports.RegisterDTO = void 0;
13
- const class_transformer_1 = require("class-transformer");
14
- const class_validator_1 = require("class-validator");
15
- class RegisterDTO {
16
- static fromPlain(entity) {
17
- return (0, class_transformer_1.plainToClass)(RegisterDTO, entity);
18
- }
19
- toPlain() {
20
- return (0, class_transformer_1.classToPlain)(this);
21
- }
22
- validate() {
23
- const errors = (0, class_validator_1.validateSync)(this);
24
- return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
25
- }
26
- }
27
- __decorate([
28
- (0, class_validator_1.IsEmail)(),
29
- (0, class_validator_1.IsOptional)(),
30
- __metadata("design:type", String)
31
- ], RegisterDTO.prototype, "email", void 0);
32
- __decorate([
33
- (0, class_validator_1.IsString)(),
34
- (0, class_validator_1.MinLength)(8),
35
- (0, class_validator_1.IsOptional)(),
36
- __metadata("design:type", String)
37
- ], RegisterDTO.prototype, "password", void 0);
38
- __decorate([
39
- (0, class_validator_1.IsString)(),
40
- __metadata("design:type", String)
41
- ], RegisterDTO.prototype, "name", void 0);
42
- __decorate([
43
- (0, class_validator_1.IsString)(),
44
- (0, class_validator_1.IsOptional)(),
45
- __metadata("design:type", String)
46
- ], RegisterDTO.prototype, "phone", void 0);
47
- __decorate([
48
- (0, class_validator_1.IsOptional)(),
49
- (0, class_validator_1.IsString)({ each: true }),
50
- (0, class_validator_1.IsUUID)("4", { each: true }),
51
- __metadata("design:type", Array)
52
- ], RegisterDTO.prototype, "savedFavoriteVehicles", void 0);
53
- exports.RegisterDTO = RegisterDTO;
54
- class LoginDTO {
55
- static fromPlain(entity) {
56
- return (0, class_transformer_1.plainToClass)(LoginDTO, entity);
57
- }
58
- toPlain() {
59
- return (0, class_transformer_1.classToPlain)(this);
60
- }
61
- validate() {
62
- const errors = (0, class_validator_1.validateSync)(this);
63
- return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
64
- }
65
- }
66
- __decorate([
67
- (0, class_validator_1.IsEmail)(),
68
- __metadata("design:type", String)
69
- ], LoginDTO.prototype, "email", void 0);
70
- __decorate([
71
- (0, class_validator_1.IsString)(),
72
- __metadata("design:type", String)
73
- ], LoginDTO.prototype, "password", void 0);
74
- __decorate([
75
- (0, class_validator_1.IsOptional)(),
76
- (0, class_validator_1.IsString)({ each: true }),
77
- (0, class_validator_1.IsUUID)("4", { each: true }),
78
- __metadata("design:type", Array)
79
- ], LoginDTO.prototype, "savedFavoriteVehicles", void 0);
80
- exports.LoginDTO = LoginDTO;
81
- class OtpLoginDTO {
82
- static fromPlain(entity) {
83
- return (0, class_transformer_1.plainToClass)(OtpLoginDTO, entity);
84
- }
85
- toPlain() {
86
- return (0, class_transformer_1.classToPlain)(this);
87
- }
88
- validate() {
89
- const errors = (0, class_validator_1.validateSync)(this);
90
- return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
91
- }
92
- }
93
- __decorate([
94
- (0, class_validator_1.IsString)(),
95
- (0, class_validator_1.IsPhoneNumber)(),
96
- __metadata("design:type", String)
97
- ], OtpLoginDTO.prototype, "phone", void 0);
98
- __decorate([
99
- (0, class_validator_1.IsString)(),
100
- (0, class_validator_1.MinLength)(6),
101
- __metadata("design:type", String)
102
- ], OtpLoginDTO.prototype, "otp", void 0);
103
- exports.OtpLoginDTO = OtpLoginDTO;
104
- class AuthResponseDTO {
105
- }
106
- exports.AuthResponseDTO = AuthResponseDTO;