@alba-cars/common-modules 1.10.2 → 1.10.4

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.
@@ -28,6 +28,7 @@ type MetaEndpoints = BaseEndpoint & {
28
28
  };
29
29
  type DepositEndpoints = BaseEndpoint & {
30
30
  initiateRefund: string | EndpointFunction;
31
+ getOrCreateUserInformation: string;
31
32
  };
32
33
  type UserEndpoints = BaseEndpoint & {
33
34
  changeProfilePicture: EndpointFunction;
@@ -107,6 +107,7 @@ exports.API_ENDPOINTS = {
107
107
  deleteOne: (id) => `/deposits/${id}`,
108
108
  updateOne: (id) => `/deposits/${id}`,
109
109
  initiateRefund: `/deposits/refund/`,
110
+ getOrCreateUserInformation: `/deposits/user-info`,
110
111
  },
111
112
  leads: {
112
113
  getAll: `/leads`,
@@ -4,5 +4,53 @@ interface ApiRequestOptions extends RequestInit {
4
4
  timeout?: number;
5
5
  signal?: AbortSignal;
6
6
  }
7
+ type RequestInterceptor = (config: RequestInit & {
8
+ url: string;
9
+ options: ApiRequestOptions;
10
+ }) => Promise<RequestInit & {
11
+ url: string;
12
+ options: ApiRequestOptions;
13
+ }> | (RequestInit & {
14
+ url: string;
15
+ options: ApiRequestOptions;
16
+ });
17
+ type ResponseInterceptor = (response: Response, requestConfig: RequestInit & {
18
+ url: string;
19
+ }) => Promise<Response> | Response;
20
+ type ResponseErrorInterceptor = (error: any, requestConfig: RequestInit & {
21
+ url: string;
22
+ }) => Promise<Response> | Response | Promise<any> | any;
23
+ declare class InterceptorManager {
24
+ private requestInterceptors;
25
+ private responseInterceptors;
26
+ private responseErrorInterceptors;
27
+ addRequestInterceptor(interceptor: RequestInterceptor): number;
28
+ addResponseInterceptor(interceptor: ResponseInterceptor): number;
29
+ addResponseErrorInterceptor(interceptor: ResponseErrorInterceptor): number;
30
+ removeRequestInterceptor(index: number): void;
31
+ removeResponseInterceptor(index: number): void;
32
+ removeResponseErrorInterceptor(index: number): void;
33
+ clearRequestInterceptors(): void;
34
+ clearResponseInterceptors(): void;
35
+ clearResponseErrorInterceptors(): void;
36
+ clearAllInterceptors(): void;
37
+ applyRequestInterceptors(config: RequestInit & {
38
+ url: string;
39
+ options: ApiRequestOptions;
40
+ }): Promise<RequestInit & {
41
+ url: string;
42
+ options: ApiRequestOptions;
43
+ }>;
44
+ applyResponseInterceptors(response: Response, requestConfig: RequestInit & {
45
+ url: string;
46
+ }): Promise<Response>;
47
+ applyResponseErrorInterceptors(error: any, requestConfig: RequestInit & {
48
+ url: string;
49
+ }): Promise<any>;
50
+ retryRequest<T>(config: RequestInit & {
51
+ url: string;
52
+ }): Promise<T>;
53
+ }
54
+ export declare const interceptors: InterceptorManager;
7
55
  export declare function apiRequest<T>(endpoint: string, options?: ApiRequestOptions): Promise<T>;
8
56
  export {};
@@ -3,12 +3,115 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.apiRequest = void 0;
6
+ exports.apiRequest = exports.interceptors = void 0;
7
7
  const qs_1 = __importDefault(require("qs"));
8
8
  const enums_1 = require("../enums");
9
9
  const utils_1 = require("../utils");
10
10
  const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
11
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
+ let modifiedError = error;
73
+ for (const interceptor of this.responseErrorInterceptors) {
74
+ try {
75
+ // If an interceptor resolves the error, return the resolved value
76
+ const result = await interceptor(modifiedError, requestConfig);
77
+ if (result instanceof Response) {
78
+ return result;
79
+ }
80
+ modifiedError = result;
81
+ }
82
+ catch (newError) {
83
+ // If an interceptor rejects, continue with the new error
84
+ modifiedError = newError;
85
+ }
86
+ }
87
+ // If no interceptor handled the error, throw it
88
+ throw modifiedError;
89
+ }
90
+ async retryRequest(config) {
91
+ try {
92
+ // Make a new request with the updated config
93
+ const response = await fetch(config.url, config);
94
+ // Apply response interceptors
95
+ const interceptedResponse = await this.applyResponseInterceptors(response, config);
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
+ // Apply response error interceptors
109
+ return this.applyResponseErrorInterceptors(error, config);
110
+ }
111
+ }
112
+ }
113
+ // Create the interceptor manager instance
114
+ exports.interceptors = new InterceptorManager();
12
115
  const buildUrl = (endpoint, query) => {
13
116
  let url = `${BASE_URL}${endpoint}`;
14
117
  if (query && Object.keys(query).length > 0) {
@@ -28,8 +131,8 @@ async function apiRequest(endpoint, options = {}) {
28
131
  // If timeout is specified, create a timeout abort controller
29
132
  if (options.timeout && controller) {
30
133
  timeoutId = setTimeout(() => {
31
- controller.abort('Request timeout');
32
- }, options.timeout);
134
+ controller.abort("Request timeout");
135
+ }, options.timeout || DEFAULT_TIMEOUT);
33
136
  }
34
137
  // Use provided signal or timeout controller's signal
35
138
  const signal = options.signal || (controller === null || controller === void 0 ? void 0 : controller.signal);
@@ -51,20 +154,46 @@ async function apiRequest(endpoint, options = {}) {
51
154
  catch (error) {
52
155
  return Promise.reject(error);
53
156
  }
157
+ finally {
158
+ if (timeoutId) {
159
+ clearTimeout(timeoutId);
160
+ }
161
+ }
54
162
  }
55
163
  exports.apiRequest = apiRequest;
56
164
  async function makeRequest(endpoint, config, options = {}) {
57
165
  const url = buildUrl(endpoint, options.query);
58
- const response = await fetch(url, config);
59
- const contentType = response.headers.get("content-type");
60
- const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
61
- ? await response.json()
62
- : await response.text();
63
- if (response.ok) {
64
- return responseData;
65
- }
66
- // Handle other errors
67
- throw createApiError(response.status, responseData);
166
+ // Apply request interceptors
167
+ let requestConfig = await exports.interceptors.applyRequestInterceptors({
168
+ ...config,
169
+ url,
170
+ options,
171
+ });
172
+ // Extract the URL after interceptors may have modified it
173
+ const interceptedUrl = requestConfig.url;
174
+ try {
175
+ // Make the actual request
176
+ const response = await fetch(interceptedUrl, requestConfig);
177
+ // Apply response interceptors
178
+ const interceptedResponse = await exports.interceptors.applyResponseInterceptors(response, { ...requestConfig, url: interceptedUrl });
179
+ const contentType = interceptedResponse.headers.get("content-type");
180
+ const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
181
+ ? await interceptedResponse.json()
182
+ : await interceptedResponse.text();
183
+ if (interceptedResponse.ok) {
184
+ return responseData;
185
+ }
186
+ // Handle other errors
187
+ const apiError = createApiError(interceptedResponse.status, responseData);
188
+ throw apiError;
189
+ }
190
+ catch (error) {
191
+ // Apply response error interceptors
192
+ return exports.interceptors.applyResponseErrorInterceptors(error, {
193
+ ...requestConfig,
194
+ url: interceptedUrl,
195
+ });
196
+ }
68
197
  }
69
198
  function createApiError(status, responseData) {
70
199
  const error = new Error(typeof responseData === "object"
@@ -6,6 +6,11 @@ export declare enum DepositStatus {
6
6
  COMPLETED = "completed",
7
7
  FAILED = "failed"
8
8
  }
9
+ export declare enum PaymentOption {
10
+ CASH = "cash",
11
+ BANK_TYPE_A = "bank-a",
12
+ BANK_TYPE_B = "bank-b"
13
+ }
9
14
  export declare class DepositDTO {
10
15
  id: string;
11
16
  stripePaymentIntentId: string;
@@ -13,6 +18,7 @@ export declare class DepositDTO {
13
18
  currency: string;
14
19
  status: DepositStatus;
15
20
  isRefundable: boolean;
21
+ paymentOption: PaymentOption;
16
22
  isRefunded: boolean;
17
23
  lead?: LeadDTO;
18
24
  vehicle: Vehicle;
@@ -26,6 +32,7 @@ export declare class DepositDTO {
26
32
  export declare class DepositCreateDTO {
27
33
  stripePaymentIntentId: string;
28
34
  amount: number;
35
+ paymentOption: PaymentOption;
29
36
  currency: string;
30
37
  status: DepositStatus;
31
38
  isRefundable?: boolean;
@@ -41,6 +48,7 @@ export declare class DepositUpdateDTO {
41
48
  status?: DepositStatus;
42
49
  isRefundable?: boolean;
43
50
  isRefunded?: boolean;
51
+ paymentOption?: PaymentOption;
44
52
  isDeleted?: boolean;
45
53
  validate(): string[];
46
54
  static fromPlain(plain: Record<string, unknown>): DepositUpdateDTO;
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DepositGetDTO = exports.DepositOptions = exports.DepositFilter = exports.DepositUpdateDTO = exports.DepositCreateDTO = exports.DepositDTO = exports.DepositStatus = void 0;
12
+ exports.DepositGetDTO = exports.DepositOptions = exports.DepositFilter = exports.DepositUpdateDTO = exports.DepositCreateDTO = exports.DepositDTO = exports.PaymentOption = exports.DepositStatus = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
14
  const class_transformer_1 = require("class-transformer");
15
15
  const global_1 = require("../../../../global");
@@ -21,6 +21,12 @@ var DepositStatus;
21
21
  DepositStatus["COMPLETED"] = "completed";
22
22
  DepositStatus["FAILED"] = "failed";
23
23
  })(DepositStatus = exports.DepositStatus || (exports.DepositStatus = {}));
24
+ var PaymentOption;
25
+ (function (PaymentOption) {
26
+ PaymentOption["CASH"] = "cash";
27
+ PaymentOption["BANK_TYPE_A"] = "bank-a";
28
+ PaymentOption["BANK_TYPE_B"] = "bank-b";
29
+ })(PaymentOption = exports.PaymentOption || (exports.PaymentOption = {}));
24
30
  class DepositDTO {
25
31
  validate() {
26
32
  const errors = (0, class_validator_1.validateSync)(this);
@@ -57,6 +63,10 @@ __decorate([
57
63
  (0, class_validator_1.IsBoolean)(),
58
64
  __metadata("design:type", Boolean)
59
65
  ], DepositDTO.prototype, "isRefundable", void 0);
66
+ __decorate([
67
+ (0, class_validator_1.IsEnum)(PaymentOption),
68
+ __metadata("design:type", String)
69
+ ], DepositDTO.prototype, "paymentOption", void 0);
60
70
  __decorate([
61
71
  (0, class_validator_1.IsBoolean)(),
62
72
  __metadata("design:type", Boolean)
@@ -90,7 +100,7 @@ __decorate([
90
100
  exports.DepositDTO = DepositDTO;
91
101
  class DepositCreateDTO {
92
102
  constructor() {
93
- this.currency = 'aed';
103
+ this.currency = "aed";
94
104
  this.status = DepositStatus.PENDING;
95
105
  this.isRefundable = false;
96
106
  this.isRefunded = false;
@@ -114,6 +124,10 @@ __decorate([
114
124
  (0, class_validator_1.IsNumber)(),
115
125
  __metadata("design:type", Number)
116
126
  ], DepositCreateDTO.prototype, "amount", void 0);
127
+ __decorate([
128
+ (0, class_validator_1.IsEnum)(PaymentOption),
129
+ __metadata("design:type", String)
130
+ ], DepositCreateDTO.prototype, "paymentOption", void 0);
117
131
  __decorate([
118
132
  (0, class_validator_1.IsString)(),
119
133
  __metadata("design:type", String)
@@ -174,6 +188,11 @@ __decorate([
174
188
  (0, class_validator_1.IsBoolean)(),
175
189
  __metadata("design:type", Boolean)
176
190
  ], DepositUpdateDTO.prototype, "isRefunded", void 0);
191
+ __decorate([
192
+ (0, class_validator_1.IsOptional)(),
193
+ (0, class_validator_1.IsEnum)(PaymentOption),
194
+ __metadata("design:type", String)
195
+ ], DepositUpdateDTO.prototype, "paymentOption", void 0);
177
196
  __decorate([
178
197
  (0, class_validator_1.IsOptional)(),
179
198
  (0, class_validator_1.IsBoolean)(),
@@ -87,6 +87,16 @@ export declare class UpdateReviewDTO {
87
87
  placeId?: string;
88
88
  updatedAt?: Date;
89
89
  }
90
+ export declare class CreateReviewDTO {
91
+ username?: string;
92
+ photo?: string;
93
+ platform?: ReviewPlatform;
94
+ comment?: string;
95
+ rating?: number;
96
+ showPublic?: boolean;
97
+ placeId?: string;
98
+ date?: Date;
99
+ }
90
100
  export declare class UpdateReviewShowPublicDTO {
91
101
  id: string;
92
102
  showPublic: boolean;
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UpdateReviewShowPublicDTO = exports.UpdateReviewDTO = exports.ReviewOptions = exports.ReviewFilter = exports.ReviewGetDTO = exports.GoogleReviewResponseDTO = exports.SaveGoogleReviewDTO = exports.FetchGoogleReviewsDTO = exports.GoogleReviewDTO = exports.ReviewDTO = void 0;
12
+ exports.UpdateReviewShowPublicDTO = exports.CreateReviewDTO = exports.UpdateReviewDTO = exports.ReviewOptions = exports.ReviewFilter = exports.ReviewGetDTO = exports.GoogleReviewResponseDTO = exports.SaveGoogleReviewDTO = exports.FetchGoogleReviewsDTO = exports.GoogleReviewDTO = exports.ReviewDTO = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
14
  const class_transformer_1 = require("class-transformer");
15
15
  const enums_1 = require("../enums");
@@ -403,6 +403,54 @@ __decorate([
403
403
  __metadata("design:type", Date)
404
404
  ], UpdateReviewDTO.prototype, "updatedAt", void 0);
405
405
  exports.UpdateReviewDTO = UpdateReviewDTO;
406
+ class CreateReviewDTO {
407
+ }
408
+ __decorate([
409
+ (0, class_validator_1.IsString)(),
410
+ (0, class_validator_1.IsOptional)(),
411
+ (0, class_validator_1.Length)(1, 100),
412
+ __metadata("design:type", String)
413
+ ], CreateReviewDTO.prototype, "username", void 0);
414
+ __decorate([
415
+ (0, class_validator_1.IsOptional)(),
416
+ (0, class_validator_1.IsString)(),
417
+ __metadata("design:type", String)
418
+ ], CreateReviewDTO.prototype, "photo", void 0);
419
+ __decorate([
420
+ (0, class_validator_1.IsEnum)(enums_1.ReviewPlatform),
421
+ (0, class_validator_1.IsOptional)(),
422
+ __metadata("design:type", String)
423
+ ], CreateReviewDTO.prototype, "platform", void 0);
424
+ __decorate([
425
+ (0, class_validator_1.IsString)(),
426
+ (0, class_validator_1.IsOptional)(),
427
+ (0, class_validator_1.Length)(1, 1000),
428
+ __metadata("design:type", String)
429
+ ], CreateReviewDTO.prototype, "comment", void 0);
430
+ __decorate([
431
+ (0, class_validator_1.IsNumber)(),
432
+ (0, class_validator_1.IsOptional)(),
433
+ (0, class_validator_1.Min)(1),
434
+ (0, class_validator_1.Max)(5),
435
+ __metadata("design:type", Number)
436
+ ], CreateReviewDTO.prototype, "rating", void 0);
437
+ __decorate([
438
+ (0, class_validator_1.IsBoolean)(),
439
+ (0, class_validator_1.IsOptional)(),
440
+ __metadata("design:type", Boolean)
441
+ ], CreateReviewDTO.prototype, "showPublic", void 0);
442
+ __decorate([
443
+ (0, class_validator_1.IsString)(),
444
+ (0, class_validator_1.IsOptional)(),
445
+ __metadata("design:type", String)
446
+ ], CreateReviewDTO.prototype, "placeId", void 0);
447
+ __decorate([
448
+ (0, class_transformer_1.Type)(() => Date),
449
+ (0, class_validator_1.IsDate)(),
450
+ (0, class_validator_1.IsOptional)(),
451
+ __metadata("design:type", Date)
452
+ ], CreateReviewDTO.prototype, "date", void 0);
453
+ exports.CreateReviewDTO = CreateReviewDTO;
406
454
  class UpdateReviewShowPublicDTO {
407
455
  }
408
456
  __decorate([
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.10.2",
6
+ "version": "1.10.4",
7
7
  "description": "A package containing DTOs, validation classes and common modules and interfaces for Alba Cars",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",