@alba-cars/common-modules 1.2.0 → 1.2.2
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.
- package/dist/core/enums/HttpMethods.d.ts +12 -0
- package/dist/core/enums/HttpMethods.js +14 -0
- package/dist/core/enums/HttpStatusCodes.d.ts +18 -0
- package/dist/core/enums/HttpStatusCodes.js +19 -0
- package/dist/core/enums/index.d.ts +2 -0
- package/dist/core/enums/index.js +18 -0
- package/dist/core/error-handling/AppError.d.ts +21 -0
- package/dist/core/error-handling/AppError.js +46 -0
- package/dist/core/error-handling/errorHandler.d.ts +5 -0
- package/dist/core/error-handling/errorHandler.js +43 -0
- package/dist/core/error-handling/index.d.ts +2 -0
- package/dist/core/error-handling/index.js +18 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +21 -0
- package/dist/core/models/index.d.ts +1 -0
- package/dist/core/models/index.js +17 -0
- package/dist/core/models/pagination/index.d.ts +1 -0
- package/dist/core/models/pagination/index.js +17 -0
- package/dist/core/models/pagination/paginated_data.d.ts +6 -0
- package/dist/core/models/pagination/paginated_data.js +2 -0
- package/dist/core/network/api-client.d.ts +1 -0
- package/dist/core/network/api-client.js +32 -0
- package/dist/core/network/endpoint-config.d.ts +15 -0
- package/dist/core/network/endpoint-config.js +82 -0
- package/dist/core/network/fetch-api.d.ts +6 -0
- package/dist/core/network/fetch-api.js +64 -0
- package/dist/core/network/index.d.ts +4 -0
- package/dist/core/network/index.js +20 -0
- package/dist/core/network/react-query.d.ts +12 -0
- package/dist/core/network/react-query.js +15 -0
- package/dist/core/utils/global-constants.d.ts +6 -0
- package/dist/core/utils/global-constants.js +9 -0
- package/dist/core/utils/global-utils.d.ts +42 -0
- package/dist/core/utils/global-utils.js +87 -0
- package/dist/core/utils/index.d.ts +2 -0
- package/dist/core/utils/index.js +18 -0
- package/dist/features/blog/data/dto/BlogDTO.js +1 -1
- package/dist/features/blog/index.d.ts +1 -0
- package/dist/features/blog/index.js +17 -0
- package/dist/features/index.d.ts +6 -0
- package/dist/features/index.js +22 -0
- package/dist/features/newsletter/index.d.ts +1 -0
- package/dist/features/newsletter/index.js +17 -0
- package/dist/features/sales-team/api/AddAgent.d.ts +2 -0
- package/dist/features/sales-team/api/AddAgent.js +20 -0
- package/dist/features/sales-team/api/EditAgent.d.ts +2 -0
- package/dist/features/sales-team/api/EditAgent.js +21 -0
- package/dist/features/sales-team/api/GetAgent.d.ts +3 -0
- package/dist/features/sales-team/api/GetAgent.js +19 -0
- package/dist/features/sales-team/api/RemoveAgent.d.ts +1 -0
- package/dist/features/sales-team/api/RemoveAgent.js +15 -0
- package/dist/features/sales-team/api/index.d.ts +4 -0
- package/dist/features/sales-team/api/index.js +20 -0
- package/dist/features/sales-team/data/dto/SalesAgentDTO.d.ts +11 -9
- package/dist/features/sales-team/data/dto/SalesAgentDTO.js +11 -1
- package/dist/features/sales-team/data/index.d.ts +1 -0
- package/dist/features/sales-team/data/index.js +17 -0
- package/dist/features/sales-team/index.d.ts +2 -0
- package/dist/features/sales-team/index.js +18 -0
- package/dist/features/showroom-visit/data/index.d.ts +1 -0
- package/dist/features/showroom-visit/data/index.js +17 -0
- package/dist/features/showroom-visit/index.d.ts +1 -0
- package/dist/features/showroom-visit/index.js +17 -0
- package/dist/features/test-drive-request/api/GetTestDriveVehicles.d.ts +3 -0
- package/dist/features/test-drive-request/api/GetTestDriveVehicles.js +8 -0
- package/dist/features/test-drive-request/api/index.d.ts +1 -0
- package/dist/features/test-drive-request/api/index.js +17 -0
- package/dist/features/test-drive-request/data/index.d.ts +4 -0
- package/dist/features/test-drive-request/data/index.js +20 -0
- package/dist/features/test-drive-request/index.d.ts +2 -0
- package/dist/features/test-drive-request/index.js +18 -0
- package/dist/features/vehicle/api/make/CreateMake.d.ts +0 -0
- package/dist/features/vehicle/api/make/CreateMake.js +1 -0
- package/dist/features/vehicle/api/make/DeleteMake.d.ts +0 -0
- package/dist/features/vehicle/api/make/DeleteMake.js +1 -0
- package/dist/features/vehicle/api/make/GetAllMakes.d.ts +0 -0
- package/dist/features/vehicle/api/make/GetAllMakes.js +1 -0
- package/dist/features/vehicle/api/make/UpdateMake.d.ts +2 -0
- package/dist/features/vehicle/api/make/UpdateMake.js +17 -0
- package/dist/features/vehicle/api/models/CreateModel.d.ts +0 -0
- package/dist/features/vehicle/api/models/CreateModel.js +1 -0
- package/dist/features/vehicle/api/models/DeleteModel.d.ts +0 -0
- package/dist/features/vehicle/api/models/DeleteModel.js +1 -0
- package/dist/features/vehicle/api/models/GetAllModels.d.ts +0 -0
- package/dist/features/vehicle/api/models/GetAllModels.js +1 -0
- package/dist/features/vehicle/api/models/UpdateModel.d.ts +0 -0
- package/dist/features/vehicle/api/models/UpdateModel.js +1 -0
- package/dist/features/vehicle/data/dto/index.d.ts +12 -0
- package/dist/features/vehicle/data/dto/index.js +28 -0
- package/dist/features/vehicle/data/index.d.ts +4 -0
- package/dist/features/vehicle/data/index.js +20 -0
- package/dist/features/vehicle/data/models/_index.d.ts +14 -0
- package/dist/features/vehicle/data/models/_index.js +30 -0
- package/dist/features/vehicle/index.d.ts +1 -0
- package/dist/features/vehicle/index.js +17 -0
- package/dist/global/dto/index.d.ts +1 -0
- package/dist/global/dto/index.js +17 -0
- package/dist/global/index.d.ts +2 -0
- package/dist/global/index.js +18 -0
- package/dist/index.d.ts +4 -17
- package/dist/index.js +4 -17
- package/dist/models.d.ts +2 -0
- package/dist/models.js +2 -0
- package/package.json +15 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const HttpMethods: {
|
|
2
|
+
readonly OPTIONS: "OPTIONS";
|
|
3
|
+
readonly GET: "GET";
|
|
4
|
+
readonly POST: "POST";
|
|
5
|
+
readonly PUT: "PUT";
|
|
6
|
+
readonly PATCH: "PATCH";
|
|
7
|
+
readonly DELETE: "DELETE";
|
|
8
|
+
readonly HEAD: "HEAD";
|
|
9
|
+
readonly CONNECT: "CONNECT";
|
|
10
|
+
readonly TRACE: "TRACE";
|
|
11
|
+
};
|
|
12
|
+
export type HttpMethodKeys = keyof typeof HttpMethods;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = void 0;
|
|
4
|
+
exports.HttpMethods = {
|
|
5
|
+
OPTIONS: "OPTIONS",
|
|
6
|
+
GET: "GET",
|
|
7
|
+
POST: "POST",
|
|
8
|
+
PUT: "PUT",
|
|
9
|
+
PATCH: "PATCH",
|
|
10
|
+
DELETE: "DELETE",
|
|
11
|
+
HEAD: "HEAD",
|
|
12
|
+
CONNECT: "CONNECT",
|
|
13
|
+
TRACE: "TRACE",
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const HttpStatusCodes: {
|
|
2
|
+
readonly OK: 200;
|
|
3
|
+
readonly CREATED: 201;
|
|
4
|
+
readonly ACCEPTED: 202;
|
|
5
|
+
readonly NO_CONTENT: 204;
|
|
6
|
+
readonly BAD_REQUEST: 400;
|
|
7
|
+
readonly UNAUTHORIZED: 401;
|
|
8
|
+
readonly FORBIDDEN: 403;
|
|
9
|
+
readonly NOT_FOUND: 404;
|
|
10
|
+
readonly METHOD_NOT_ALLOWED: 405;
|
|
11
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
12
|
+
readonly NOT_IMPLEMENTED: 501;
|
|
13
|
+
readonly BAD_GATEWAY: 502;
|
|
14
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
|
15
|
+
readonly GATEWAY_TIMEOUT: 504;
|
|
16
|
+
};
|
|
17
|
+
export type HttpStatusKeys = keyof typeof HttpStatusCodes;
|
|
18
|
+
export type HttpStatusCodesValues = (typeof HttpStatusCodes)[HttpStatusKeys];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpStatusCodes = void 0;
|
|
4
|
+
exports.HttpStatusCodes = {
|
|
5
|
+
OK: 200,
|
|
6
|
+
CREATED: 201,
|
|
7
|
+
ACCEPTED: 202,
|
|
8
|
+
NO_CONTENT: 204,
|
|
9
|
+
BAD_REQUEST: 400,
|
|
10
|
+
UNAUTHORIZED: 401,
|
|
11
|
+
FORBIDDEN: 403,
|
|
12
|
+
NOT_FOUND: 404,
|
|
13
|
+
METHOD_NOT_ALLOWED: 405,
|
|
14
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
15
|
+
NOT_IMPLEMENTED: 501,
|
|
16
|
+
BAD_GATEWAY: 502,
|
|
17
|
+
SERVICE_UNAVAILABLE: 503,
|
|
18
|
+
GATEWAY_TIMEOUT: 504,
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./HttpMethods"), exports);
|
|
18
|
+
__exportStar(require("./HttpStatusCodes"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum ErrorType {
|
|
2
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
3
|
+
NOT_FOUND = "NOT_FOUND",
|
|
4
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
5
|
+
FORBIDDEN = "FORBIDDEN",
|
|
6
|
+
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
|
|
7
|
+
BAD_REQUEST = "BAD_REQUEST"
|
|
8
|
+
}
|
|
9
|
+
export declare class AppError extends Error {
|
|
10
|
+
message: string;
|
|
11
|
+
statusCode: number;
|
|
12
|
+
type: ErrorType;
|
|
13
|
+
details?: any;
|
|
14
|
+
constructor(message: string, statusCode: number, type: ErrorType, details?: any);
|
|
15
|
+
static badRequest(message: string, details?: any): AppError;
|
|
16
|
+
static notFound(message: string, details?: any): AppError;
|
|
17
|
+
static unauthorized(message: string, details?: any): AppError;
|
|
18
|
+
static forbidden(message: string, details?: any): AppError;
|
|
19
|
+
static internal(message: string, details?: any): AppError;
|
|
20
|
+
static validationError(message: string, details?: any): AppError;
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// AppError.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AppError = exports.ErrorType = void 0;
|
|
5
|
+
var ErrorType;
|
|
6
|
+
(function (ErrorType) {
|
|
7
|
+
ErrorType["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
8
|
+
ErrorType["NOT_FOUND"] = "NOT_FOUND";
|
|
9
|
+
ErrorType["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
10
|
+
ErrorType["FORBIDDEN"] = "FORBIDDEN";
|
|
11
|
+
ErrorType["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
12
|
+
ErrorType["BAD_REQUEST"] = "BAD_REQUEST";
|
|
13
|
+
})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
|
|
14
|
+
class AppError extends Error {
|
|
15
|
+
constructor(message, statusCode, type, details) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.message = message;
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.details = details;
|
|
21
|
+
this.statusCode = statusCode;
|
|
22
|
+
this.type = type;
|
|
23
|
+
this.details = details;
|
|
24
|
+
this.name = this.constructor.name;
|
|
25
|
+
Error.captureStackTrace(this, this.constructor);
|
|
26
|
+
}
|
|
27
|
+
static badRequest(message, details) {
|
|
28
|
+
return new AppError(message, 400, ErrorType.BAD_REQUEST, details);
|
|
29
|
+
}
|
|
30
|
+
static notFound(message, details) {
|
|
31
|
+
return new AppError(message, 404, ErrorType.NOT_FOUND, details);
|
|
32
|
+
}
|
|
33
|
+
static unauthorized(message, details) {
|
|
34
|
+
return new AppError(message, 401, ErrorType.UNAUTHORIZED, details);
|
|
35
|
+
}
|
|
36
|
+
static forbidden(message, details) {
|
|
37
|
+
return new AppError(message, 403, ErrorType.FORBIDDEN, details);
|
|
38
|
+
}
|
|
39
|
+
static internal(message, details) {
|
|
40
|
+
return new AppError(message, 500, ErrorType.INTERNAL_SERVER_ERROR, details);
|
|
41
|
+
}
|
|
42
|
+
static validationError(message, details) {
|
|
43
|
+
return new AppError(message, 422, ErrorType.VALIDATION_ERROR, details);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AppError = AppError;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
type AsyncFunction = (req: Request, res: Response, next: NextFunction) => Promise<any>;
|
|
3
|
+
export declare function asyncHandler(fn: AsyncFunction): (req: Request, res: Response, next: NextFunction) => void;
|
|
4
|
+
export declare function globalErrorHandlerMiddleware(err: Error, req: Request, res: Response, next: NextFunction): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// errorHandler.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.globalErrorHandlerMiddleware = exports.asyncHandler = void 0;
|
|
5
|
+
const AppError_1 = require("./AppError");
|
|
6
|
+
function asyncHandler(fn) {
|
|
7
|
+
return (req, res, next) => {
|
|
8
|
+
Promise.resolve(fn(req, res, next)).catch((error) => {
|
|
9
|
+
if (!(error instanceof AppError_1.AppError)) {
|
|
10
|
+
error = AppError_1.AppError.internal("Internal Server Error");
|
|
11
|
+
}
|
|
12
|
+
res.status(error.statusCode).json({
|
|
13
|
+
error: {
|
|
14
|
+
type: error.type,
|
|
15
|
+
message: error.message,
|
|
16
|
+
details: error.details,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.asyncHandler = asyncHandler;
|
|
23
|
+
function globalErrorHandlerMiddleware(err, req, res, next) {
|
|
24
|
+
if (res.headersSent) {
|
|
25
|
+
return next(err);
|
|
26
|
+
}
|
|
27
|
+
let error = err;
|
|
28
|
+
console.log(error);
|
|
29
|
+
if (!(error instanceof AppError_1.AppError)) {
|
|
30
|
+
error = AppError_1.AppError.internal("Internal Server Error");
|
|
31
|
+
}
|
|
32
|
+
const appError = error;
|
|
33
|
+
console.log(appError.statusCode);
|
|
34
|
+
console.log(appError.details);
|
|
35
|
+
res.status(appError.statusCode).json({
|
|
36
|
+
error: {
|
|
37
|
+
type: appError.type,
|
|
38
|
+
message: appError.message,
|
|
39
|
+
details: appError.details,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.globalErrorHandlerMiddleware = globalErrorHandlerMiddleware;
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./AppError"), exports);
|
|
18
|
+
__exportStar(require("./errorHandler"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./error-handling"), exports);
|
|
18
|
+
__exportStar(require("./enums"), exports);
|
|
19
|
+
__exportStar(require("./models"), exports);
|
|
20
|
+
__exportStar(require("./network"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./pagination";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./pagination"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./paginated_data";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./paginated_data"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const api: import("axios").AxiosInstance;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.api = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const global_utils_1 = require("../utils/global-utils");
|
|
9
|
+
const HttpStatusCodes_1 = require("../enums/HttpStatusCodes");
|
|
10
|
+
function authRequestInterceptor(config) {
|
|
11
|
+
if (config.headers) {
|
|
12
|
+
config.headers.Accept = "application/json";
|
|
13
|
+
config.headers.Authorization = `Bearer ${(0, global_utils_1.generateRandomBase64)(20)}`;
|
|
14
|
+
}
|
|
15
|
+
config.withCredentials = true;
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
exports.api = axios_1.default.create({
|
|
19
|
+
baseURL: process.env.NEXT_API_URL, // Base backend URL would be defined here.
|
|
20
|
+
});
|
|
21
|
+
exports.api.interceptors.request.use(authRequestInterceptor);
|
|
22
|
+
exports.api.interceptors.response.use((response) => {
|
|
23
|
+
return response.data;
|
|
24
|
+
}, (error) => {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || error.message;
|
|
27
|
+
console.log(message);
|
|
28
|
+
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === HttpStatusCodes_1.HttpStatusCodes.UNAUTHORIZED) {
|
|
29
|
+
// redirect to login
|
|
30
|
+
}
|
|
31
|
+
return Promise.reject(error);
|
|
32
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type EndpointFunction = (_id: number | string) => string;
|
|
2
|
+
interface BaseEndpoint {
|
|
3
|
+
getAll: string | EndpointFunction;
|
|
4
|
+
create: string | EndpointFunction;
|
|
5
|
+
getOne: EndpointFunction;
|
|
6
|
+
deleteOne: EndpointFunction;
|
|
7
|
+
updateOne: EndpointFunction;
|
|
8
|
+
}
|
|
9
|
+
type ExtendedEndpoint = BaseEndpoint & {
|
|
10
|
+
[key: string]: string | EndpointFunction;
|
|
11
|
+
};
|
|
12
|
+
type APIEndpointKeys = "vehicle" | "vehicleDetails" | "vehicleFinance" | "TestDrive" | "vehicleMake" | "vehicleModel" | "vehicleOrder" | "vehicleType" | "carOptions" | "payment" | "agents";
|
|
13
|
+
type APIEndpointType = Record<APIEndpointKeys, ExtendedEndpoint>;
|
|
14
|
+
export declare const API_ENDPOINTS: APIEndpointType;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_ENDPOINTS = void 0;
|
|
4
|
+
exports.API_ENDPOINTS = {
|
|
5
|
+
vehicle: {
|
|
6
|
+
getAll: `/vehicle`,
|
|
7
|
+
create: `/vehicle`,
|
|
8
|
+
getOne: (id) => `/vehicle/${id}`,
|
|
9
|
+
deleteOne: (id) => `/vehicle/${id}`,
|
|
10
|
+
updateOne: (id) => `/vehicle/${id}`,
|
|
11
|
+
},
|
|
12
|
+
vehicleDetails: {
|
|
13
|
+
getAll: `/vehicledetails`,
|
|
14
|
+
create: `/vehicledetails`,
|
|
15
|
+
getOne: (id) => `/vehicledetails/${id}`,
|
|
16
|
+
deleteOne: (id) => `/vehicledetails/${id}`,
|
|
17
|
+
updateOne: (id) => `/vehicledetails/${id}`,
|
|
18
|
+
},
|
|
19
|
+
vehicleFinance: {
|
|
20
|
+
getAll: `/vehiclefinance`,
|
|
21
|
+
create: `/vehiclefinance`,
|
|
22
|
+
getOne: (id) => `/vehiclefinance/${id}`,
|
|
23
|
+
deleteOne: (id) => `/vehiclefinance/${id}`,
|
|
24
|
+
updateOne: (id) => `/vehiclefinance/${id}`,
|
|
25
|
+
},
|
|
26
|
+
vehicleMake: {
|
|
27
|
+
getAll: `/vehicle/makes`,
|
|
28
|
+
create: `/vehicle/makes`,
|
|
29
|
+
getOne: (id) => `/vehiclemake/${id}`,
|
|
30
|
+
deleteOne: (id) => `/vehiclemake/${id}`,
|
|
31
|
+
updateOne: (id) => `/vehiclemake/${id}`,
|
|
32
|
+
},
|
|
33
|
+
vehicleModel: {
|
|
34
|
+
getAll: `/vehicle/models`,
|
|
35
|
+
create: `/vehicle/models`,
|
|
36
|
+
getOne: (id) => `/vehiclemodel/${id}`,
|
|
37
|
+
deleteOne: (id) => `/vehiclemodel/${id}`,
|
|
38
|
+
updateOne: (id) => `/vehiclemodel/${id}`,
|
|
39
|
+
},
|
|
40
|
+
TestDrive: {
|
|
41
|
+
getAll: `/test-drive-requests`,
|
|
42
|
+
create: `/test-drive-requests`,
|
|
43
|
+
getOne: (id) => `/test-drive-requests/${id}`,
|
|
44
|
+
deleteOne: (id) => `/test-drive-requests/${id}`,
|
|
45
|
+
updateOne: (id) => `/test-drive-requests/${id}`,
|
|
46
|
+
},
|
|
47
|
+
vehicleOrder: {
|
|
48
|
+
getAll: `/vehicleorder`,
|
|
49
|
+
create: `/vehicleorder`,
|
|
50
|
+
getOne: (id) => `/vehicleorder/${id}`,
|
|
51
|
+
deleteOne: (id) => `/vehicleorder/${id}`,
|
|
52
|
+
updateOne: (id) => `/vehicleorder/${id}`,
|
|
53
|
+
},
|
|
54
|
+
vehicleType: {
|
|
55
|
+
getAll: `/body-types`,
|
|
56
|
+
create: `/body-types`,
|
|
57
|
+
getOne: (id) => `/body-types/${id}`,
|
|
58
|
+
deleteOne: (id) => `/body-types/${id}`,
|
|
59
|
+
updateOne: (id) => `/body-types/${id}`,
|
|
60
|
+
},
|
|
61
|
+
carOptions: {
|
|
62
|
+
getAll: `/caroptions`,
|
|
63
|
+
create: `/caroptions`,
|
|
64
|
+
getOne: (id) => `/caroptions/${id}`,
|
|
65
|
+
deleteOne: (id) => `/caroptions/${id}`,
|
|
66
|
+
updateOne: (id) => `/caroptions/${id}`,
|
|
67
|
+
},
|
|
68
|
+
payment: {
|
|
69
|
+
getAll: `/payment`,
|
|
70
|
+
create: `/payment`,
|
|
71
|
+
getOne: (id) => `/payment/${id}`,
|
|
72
|
+
deleteOne: (id) => `/payment/${id}`,
|
|
73
|
+
updateOne: (id) => `/payment/${id}`,
|
|
74
|
+
},
|
|
75
|
+
agents: {
|
|
76
|
+
getAll: `/salesagent`,
|
|
77
|
+
create: `/salesagent`,
|
|
78
|
+
getOne: (id) => `/salesagent/${id}`,
|
|
79
|
+
deleteOne: (id) => `/salesagent/${id}`,
|
|
80
|
+
updateOne: (id) => `/salesagent/${id}`,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 = void 0;
|
|
7
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const enums_1 = require("../enums");
|
|
10
|
+
const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
11
|
+
async function apiRequest(endpoint, options = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
const headers = {
|
|
14
|
+
Accept: "application/json",
|
|
15
|
+
Authorization: `Bearer ${(0, utils_1.generateRandomBase64)(20)}`,
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...options.headers,
|
|
18
|
+
};
|
|
19
|
+
const config = {
|
|
20
|
+
method: (_a = options.method) !== null && _a !== void 0 ? _a : enums_1.HttpMethods.GET,
|
|
21
|
+
headers,
|
|
22
|
+
// credentials: "include",
|
|
23
|
+
...options,
|
|
24
|
+
};
|
|
25
|
+
options.method && options.method !== enums_1.HttpMethods.GET && console.log(config);
|
|
26
|
+
try {
|
|
27
|
+
options.method && options.method !== enums_1.HttpMethods.GET && console.log(`${BASE_URL}${endpoint}`);
|
|
28
|
+
let url = `${BASE_URL}${endpoint}`;
|
|
29
|
+
if (options.query && Object.keys(options.query).length > 0) {
|
|
30
|
+
url += `?${querystring_1.default.stringify(options.query)}`;
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(url, config);
|
|
33
|
+
// Parse the response once and store it
|
|
34
|
+
const contentType = response.headers.get('content-type');
|
|
35
|
+
let responseData;
|
|
36
|
+
if (contentType && contentType.includes("application/json")) {
|
|
37
|
+
responseData = await response.json();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
responseData = await response.text();
|
|
41
|
+
}
|
|
42
|
+
// Log for non-GET requests
|
|
43
|
+
options.method && options.method !== enums_1.HttpMethods.GET && console.log(responseData);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
if (response.status === enums_1.HttpStatusCodes.UNAUTHORIZED) {
|
|
46
|
+
// TODO: redirect to login page
|
|
47
|
+
}
|
|
48
|
+
if (contentType && contentType.includes("application/json")) {
|
|
49
|
+
return responseData;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.error('Received non-JSON response:', responseData);
|
|
53
|
+
throw new Error('Invalid response format');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Return the already parsed response
|
|
57
|
+
return responseData;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.log(error, 'ERROR DATA---');
|
|
61
|
+
return Promise.reject(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.apiRequest = apiRequest;
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./api-client"), exports);
|
|
18
|
+
__exportStar(require("./endpoint-config"), exports);
|
|
19
|
+
__exportStar(require("./fetch-api"), exports);
|
|
20
|
+
__exportStar(require("./react-query"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { QueryClient, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
export declare const queryConfig: {
|
|
3
|
+
queries: {
|
|
4
|
+
refetchOnWindowFocus: false;
|
|
5
|
+
retry: false;
|
|
6
|
+
staleTime: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const queryClient: QueryClient;
|
|
10
|
+
export type ApiFnReturnType<FnType extends (..._args: any) => Promise<any>> = Awaited<ReturnType<FnType>>;
|
|
11
|
+
export type QueryConfig<T extends (..._args: any[]) => any> = Omit<ReturnType<T>, "queryKey" | "queryFn">;
|
|
12
|
+
export type MutationConfig<MutationFnType extends (..._args: any) => Promise<any>> = UseMutationOptions<ApiFnReturnType<MutationFnType>, Error, Parameters<MutationFnType>[0]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryClient = exports.queryConfig = void 0;
|
|
4
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
+
const global_constants_1 = require("../utils/global-constants");
|
|
6
|
+
exports.queryConfig = {
|
|
7
|
+
queries: {
|
|
8
|
+
refetchOnWindowFocus: false,
|
|
9
|
+
retry: false,
|
|
10
|
+
staleTime: global_constants_1.ONE_MINUTE_MILLIS,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
exports.queryClient = new react_query_1.QueryClient({
|
|
14
|
+
defaultOptions: exports.queryConfig,
|
|
15
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const ONE_MINUTE_MILLIS: number;
|
|
2
|
+
export declare const ONE_HOUR_MILLIS: number;
|
|
3
|
+
export declare const FIFTEEN_MINUTES_MILLIS: number;
|
|
4
|
+
export declare const THIRTY_MINUTES_MILLIS: number;
|
|
5
|
+
export declare const ONE_HOUR = 3600;
|
|
6
|
+
export declare const ONE_MINUTE = 60;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a value to an array.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The value to convert.
|
|
5
|
+
* @returns An array containing the value, or the value itself if it is already an array.
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeArray: <T>(value: T) => T[];
|
|
8
|
+
/**
|
|
9
|
+
* Deeply compares two objects for equality.
|
|
10
|
+
*
|
|
11
|
+
* @param obj1 - The first object to compare.
|
|
12
|
+
* @param obj2 - The second object to compare.
|
|
13
|
+
* @returns `true` if the objects are deeply equal, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare const deepEqual: <T>(obj1: T, obj2: T) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a value is a plain object (not an array or null)
|
|
18
|
+
*
|
|
19
|
+
* @template T
|
|
20
|
+
* @param {T} obj
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export declare const isPlainObject: <T>(obj: T) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if a value is a function
|
|
26
|
+
*
|
|
27
|
+
* @param {*} value
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export declare const isFunction: (value: any) => boolean;
|
|
31
|
+
type ComparatorFunction = (_a: any, _b: any) => number;
|
|
32
|
+
/**
|
|
33
|
+
* Function to sort an array by a specific key (for arrays of objects) or a comparator function
|
|
34
|
+
*
|
|
35
|
+
* @param {any[]} array
|
|
36
|
+
* @param {(string | ComparatorFunction)} key
|
|
37
|
+
* @returns {any[]}
|
|
38
|
+
*/
|
|
39
|
+
export declare const sortBy: (array: any[], key: string | ComparatorFunction) => any[];
|
|
40
|
+
export declare function generateRandomBase64(length: number): string;
|
|
41
|
+
export declare const formatValue: (n: number | string) => string;
|
|
42
|
+
export {};
|