@alba-cars/common-modules 1.3.2 → 1.3.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.
- package/dist/core/error-handling/AppError.d.ts +3 -1
- package/dist/core/error-handling/AppError.js +2 -0
- package/dist/core/network/endpoint-config.d.ts +10 -0
- package/dist/core/network/endpoint-config.js +18 -2
- package/dist/core/network/fetch-api.d.ts +8 -0
- package/dist/core/network/fetch-api.js +121 -30
- package/dist/features/auth/data/dto/AuthDTO.d.ts +21 -0
- package/dist/features/auth/data/dto/AuthDTO.js +68 -0
- package/dist/features/auth/data/dto/RoleDTO.d.ts +37 -0
- package/dist/features/auth/data/dto/RoleDTO.js +119 -0
- package/dist/features/auth/data/dto/UserDTO.d.ts +40 -0
- package/dist/features/auth/data/dto/UserDTO.js +120 -0
- package/dist/features/auth/data/index.d.ts +3 -0
- package/dist/features/{sales-team/api → auth/data}/index.js +3 -4
- package/dist/features/auth/index.d.ts +1 -0
- package/dist/features/auth/index.js +17 -0
- package/dist/features/finance-eligibilty-request/data/dto/FinanceEligibilityRequestDTO.d.ts +21 -0
- package/dist/features/finance-eligibilty-request/data/dto/FinanceEligibilityRequestDTO.js +56 -1
- package/dist/features/index.d.ts +2 -1
- package/dist/features/index.js +2 -1
- package/dist/features/models/Roles.d.ts +7 -0
- package/dist/features/models/Roles.js +2 -0
- package/dist/features/models/User.d.ts +14 -0
- package/dist/features/{vehicle/data/models → models}/User.js +0 -4
- package/dist/features/{vehicle/data/models → models}/Vehicle.d.ts +6 -0
- package/dist/features/{vehicle/data/models → models}/Vehicle.js +4 -1
- package/dist/features/{vehicle/data/models → models}/VehicleMedia.d.ts +1 -1
- package/dist/features/{vehicle/data/models → models}/index.js +1 -3
- package/dist/features/sales-team/data/dto/LanguageDTO.d.ts +20 -0
- package/dist/features/sales-team/data/dto/LanguageDTO.js +89 -0
- package/dist/features/sales-team/data/dto/SalesAgentDTO.d.ts +17 -22
- package/dist/features/sales-team/data/dto/SalesAgentDTO.js +67 -45
- package/dist/features/sales-team/data/index.d.ts +1 -0
- package/dist/features/sales-team/data/index.js +1 -0
- package/dist/features/sell-car-request/data/dto/SellCarRequestDTO.d.ts +154 -0
- package/dist/features/sell-car-request/data/dto/SellCarRequestDTO.js +444 -0
- package/dist/features/sell-car-request/data/index.d.ts +1 -0
- package/dist/features/sell-car-request/data/index.js +17 -0
- package/dist/features/sell-car-request/index.d.ts +1 -0
- package/dist/features/sell-car-request/index.js +17 -0
- package/dist/features/showroom-visit/data/dto/ShowroomVisit.d.ts +19 -0
- package/dist/features/showroom-visit/data/dto/ShowroomVisit.js +46 -1
- package/dist/features/test-drive-request/data/models/TestDriveRequest.d.ts +2 -2
- package/dist/features/test-drive-request/data/models/TestDriveRequest.js +1 -1
- package/dist/features/vehicle/data/dto/BaseDTO.d.ts +3 -4
- package/dist/features/vehicle/data/dto/BaseDTO.js +6 -14
- package/dist/features/vehicle/data/dto/VehicleFilterDTO.d.ts +2 -2
- package/dist/features/vehicle/data/dto/VehicleMakeDTO.d.ts +5 -5
- package/dist/features/vehicle/data/dto/VehicleMakeDTO.js +7 -7
- package/dist/features/vehicle/data/dto/VehicleModelDTO.d.ts +2 -2
- package/dist/features/vehicle/data/dto/VehicleModelDTO.js +2 -2
- package/dist/features/vehicle/data/dto/index.d.ts +0 -1
- package/dist/features/vehicle/data/dto/index.js +0 -1
- package/dist/features/vehicle/data/index.d.ts +1 -1
- package/dist/features/vehicle/data/index.js +1 -1
- package/dist/features/vehicle/data/utilities.d.ts +7 -7
- package/package.json +1 -1
- package/dist/core/error-handling/errorHandler.d.ts +0 -5
- package/dist/core/error-handling/errorHandler.js +0 -69
- package/dist/core/network/react-query.d.ts +0 -6
- package/dist/core/network/react-query.js +0 -15
- package/dist/features/sales-team/api/AddAgent.d.ts +0 -2
- package/dist/features/sales-team/api/AddAgent.js +0 -20
- package/dist/features/sales-team/api/EditAgent.d.ts +0 -2
- package/dist/features/sales-team/api/EditAgent.js +0 -21
- package/dist/features/sales-team/api/GetAgent.d.ts +0 -3
- package/dist/features/sales-team/api/GetAgent.js +0 -19
- package/dist/features/sales-team/api/RemoveAgent.d.ts +0 -1
- package/dist/features/sales-team/api/RemoveAgent.js +0 -15
- package/dist/features/sales-team/api/index.d.ts +0 -4
- package/dist/features/vehicle/api/make/CreateMake.d.ts +0 -2
- package/dist/features/vehicle/api/make/CreateMake.js +0 -22
- package/dist/features/vehicle/api/make/DeleteMake.d.ts +0 -2
- package/dist/features/vehicle/api/make/DeleteMake.js +0 -17
- package/dist/features/vehicle/api/make/GetAllMakes.d.ts +0 -3
- package/dist/features/vehicle/api/make/GetAllMakes.js +0 -26
- package/dist/features/vehicle/api/make/UpdateMake.d.ts +0 -2
- package/dist/features/vehicle/api/make/UpdateMake.js +0 -22
- package/dist/features/vehicle/api/models/CreateModel.d.ts +0 -2
- package/dist/features/vehicle/api/models/CreateModel.js +0 -22
- package/dist/features/vehicle/api/models/DeleteModel.d.ts +0 -2
- package/dist/features/vehicle/api/models/DeleteModel.js +0 -17
- package/dist/features/vehicle/api/models/GetAllModels.d.ts +0 -3
- package/dist/features/vehicle/api/models/GetAllModels.js +0 -37
- package/dist/features/vehicle/api/models/UpdateModel.d.ts +0 -2
- package/dist/features/vehicle/api/models/UpdateModel.js +0 -22
- package/dist/features/vehicle/data/dto/UserDTO.d.ts +0 -16
- package/dist/features/vehicle/data/dto/UserDTO.js +0 -53
- package/dist/features/vehicle/data/models/User.d.ts +0 -15
- /package/dist/features/{vehicle/data/models → models}/Base.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/Base.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/Payment.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/Payment.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleBodyType.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleBodyType.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleCategory.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleCategory.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFeature.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFeature.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFeatureCategory.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFeatureCategory.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFinance.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleFinance.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleMake.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleMake.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleMedia.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleMetaData.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleMetaData.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleModel.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleModel.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleOrder.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/VehicleOrder.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/_index.d.ts +0 -0
- /package/dist/features/{vehicle/data/models → models}/_index.js +0 -0
- /package/dist/features/{vehicle/data/models → models}/index.d.ts +0 -0
|
@@ -4,7 +4,9 @@ export declare enum ErrorType {
|
|
|
4
4
|
UNAUTHORIZED = "UNAUTHORIZED",
|
|
5
5
|
FORBIDDEN = "FORBIDDEN",
|
|
6
6
|
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
|
|
7
|
-
BAD_REQUEST = "BAD_REQUEST"
|
|
7
|
+
BAD_REQUEST = "BAD_REQUEST",
|
|
8
|
+
AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
|
|
9
|
+
AUTHORIZATION_ERROR = "AUTHORIZATION_ERROR"
|
|
8
10
|
}
|
|
9
11
|
export declare class AppError extends Error {
|
|
10
12
|
message: string;
|
|
@@ -10,6 +10,8 @@ var ErrorType;
|
|
|
10
10
|
ErrorType["FORBIDDEN"] = "FORBIDDEN";
|
|
11
11
|
ErrorType["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
12
12
|
ErrorType["BAD_REQUEST"] = "BAD_REQUEST";
|
|
13
|
+
ErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
14
|
+
ErrorType["AUTHORIZATION_ERROR"] = "AUTHORIZATION_ERROR";
|
|
13
15
|
})(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
|
|
14
16
|
class AppError extends Error {
|
|
15
17
|
constructor(message, statusCode, type, details) {
|
|
@@ -9,6 +9,10 @@ interface BaseEndpoint {
|
|
|
9
9
|
interface VehicleEndpoints extends BaseEndpoint {
|
|
10
10
|
getSimilar: EndpointFunction;
|
|
11
11
|
getOneBySlug: EndpointFunction;
|
|
12
|
+
publishVehicle: EndpointFunction;
|
|
13
|
+
reserveVehicle: EndpointFunction;
|
|
14
|
+
selfReserveVehicle: EndpointFunction;
|
|
15
|
+
markVehicleSold: EndpointFunction;
|
|
12
16
|
}
|
|
13
17
|
interface BlogEndpoints extends BaseEndpoint {
|
|
14
18
|
getOneBySlug: EndpointFunction;
|
|
@@ -32,6 +36,7 @@ type APIEndpointType = {
|
|
|
32
36
|
sellCarRequest: BaseEndpoint;
|
|
33
37
|
financeEligibilityRequest: BaseEndpoint;
|
|
34
38
|
vehicleReservations: BaseEndpoint;
|
|
39
|
+
languages: BaseEndpoint;
|
|
35
40
|
};
|
|
36
41
|
export declare const API_ENDPOINTS: APIEndpointType;
|
|
37
42
|
export declare const UTIL_ENDPOINTS: {
|
|
@@ -40,4 +45,9 @@ export declare const UTIL_ENDPOINTS: {
|
|
|
40
45
|
preprocessMediaUrl: string;
|
|
41
46
|
};
|
|
42
47
|
};
|
|
48
|
+
export declare const AUTH_ENDPOINTS: {
|
|
49
|
+
login: string;
|
|
50
|
+
register: string;
|
|
51
|
+
getLoggedInUser: string;
|
|
52
|
+
};
|
|
43
53
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UTIL_ENDPOINTS = exports.API_ENDPOINTS = void 0;
|
|
3
|
+
exports.AUTH_ENDPOINTS = exports.UTIL_ENDPOINTS = exports.API_ENDPOINTS = void 0;
|
|
4
4
|
exports.API_ENDPOINTS = {
|
|
5
5
|
vehicle: {
|
|
6
6
|
getAll: `/vehicle`,
|
|
@@ -10,6 +10,10 @@ exports.API_ENDPOINTS = {
|
|
|
10
10
|
getSimilar: (id) => `/vehicle/similar/${id}`,
|
|
11
11
|
deleteOne: (id) => `/vehicle/${id}`,
|
|
12
12
|
updateOne: (id) => `/vehicle/${id}`,
|
|
13
|
+
publishVehicle: (id) => `/vehicle/publish/${id}`,
|
|
14
|
+
reserveVehicle: (id) => `/vehicle/reserve/${id}`,
|
|
15
|
+
selfReserveVehicle: (id) => `/vehicle/self-reserve/${id}`,
|
|
16
|
+
markVehicleSold: (id) => `/vehicle/mark-vehicle-sold/${id}`,
|
|
13
17
|
},
|
|
14
18
|
vehicleDetails: {
|
|
15
19
|
getAll: `/vehicledetails`,
|
|
@@ -130,7 +134,14 @@ exports.API_ENDPOINTS = {
|
|
|
130
134
|
getOne: (id) => `/vehicle-reservation/${id}`,
|
|
131
135
|
deleteOne: (id) => `/vehicle-reservation/${id}`,
|
|
132
136
|
updateOne: (id) => `/vehicle-reservation/${id}`,
|
|
133
|
-
}
|
|
137
|
+
},
|
|
138
|
+
languages: {
|
|
139
|
+
getAll: `/languages`,
|
|
140
|
+
create: `/languages`,
|
|
141
|
+
getOne: (id) => `/languages/${id}`,
|
|
142
|
+
deleteOne: (id) => `/languages/${id}`,
|
|
143
|
+
updateOne: (id) => `/languages/${id}`,
|
|
144
|
+
},
|
|
134
145
|
};
|
|
135
146
|
exports.UTIL_ENDPOINTS = {
|
|
136
147
|
media: {
|
|
@@ -138,3 +149,8 @@ exports.UTIL_ENDPOINTS = {
|
|
|
138
149
|
preprocessMediaUrl: "/utils/process-media",
|
|
139
150
|
},
|
|
140
151
|
};
|
|
152
|
+
exports.AUTH_ENDPOINTS = {
|
|
153
|
+
login: "/auth/login",
|
|
154
|
+
register: "/auth/register",
|
|
155
|
+
getLoggedInUser: "/auth/me",
|
|
156
|
+
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
interface ApiRequestOptions extends RequestInit {
|
|
2
2
|
headers?: Record<string, string>;
|
|
3
3
|
query?: Record<string, any>;
|
|
4
|
+
skipAuth?: boolean;
|
|
4
5
|
}
|
|
6
|
+
interface Tokens {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const getTokens: () => Tokens | null;
|
|
11
|
+
export declare const setTokens: (tokens: Tokens) => void;
|
|
12
|
+
export declare const removeTokens: () => void;
|
|
5
13
|
export declare function apiRequest<T>(endpoint: string, options?: ApiRequestOptions): Promise<T>;
|
|
6
14
|
export {};
|
|
@@ -3,67 +3,158 @@ 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.removeTokens = exports.setTokens = exports.getTokens = void 0;
|
|
7
7
|
const qs_1 = __importDefault(require("qs"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
8
|
const enums_1 = require("../enums");
|
|
10
9
|
const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
10
|
+
const AUTH_STORAGE_KEY = "auth_tokens";
|
|
11
|
+
let isRefreshing = false;
|
|
12
|
+
let refreshSubscribers = [];
|
|
13
|
+
const getTokens = () => {
|
|
14
|
+
if (typeof window === "undefined")
|
|
15
|
+
return null;
|
|
16
|
+
const tokens = localStorage.getItem(AUTH_STORAGE_KEY);
|
|
17
|
+
return tokens ? JSON.parse(tokens) : null;
|
|
18
|
+
};
|
|
19
|
+
exports.getTokens = getTokens;
|
|
20
|
+
const setTokens = (tokens) => {
|
|
21
|
+
localStorage.setItem(AUTH_STORAGE_KEY, JSON.stringify(tokens));
|
|
22
|
+
};
|
|
23
|
+
exports.setTokens = setTokens;
|
|
24
|
+
const removeTokens = () => {
|
|
25
|
+
localStorage.removeItem(AUTH_STORAGE_KEY);
|
|
26
|
+
};
|
|
27
|
+
exports.removeTokens = removeTokens;
|
|
28
|
+
const subscribeTokenRefresh = (cb) => {
|
|
29
|
+
refreshSubscribers.push(cb);
|
|
30
|
+
};
|
|
31
|
+
const onTokenRefreshed = (token) => {
|
|
32
|
+
refreshSubscribers.forEach((cb) => cb(token));
|
|
33
|
+
refreshSubscribers = [];
|
|
34
|
+
};
|
|
35
|
+
const refreshTokens = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const tokens = (0, exports.getTokens)();
|
|
38
|
+
if (!(tokens === null || tokens === void 0 ? void 0 : tokens.refreshToken)) {
|
|
39
|
+
throw new Error("No refresh token available");
|
|
40
|
+
}
|
|
41
|
+
const response = await apiRequest("/auth/refresh", {
|
|
42
|
+
method: enums_1.HttpMethods.POST,
|
|
43
|
+
body: JSON.stringify({ refreshToken: tokens.refreshToken }),
|
|
44
|
+
skipAuth: true, // Skip auth to avoid infinite loop
|
|
45
|
+
});
|
|
46
|
+
(0, exports.setTokens)({
|
|
47
|
+
accessToken: response.accessToken,
|
|
48
|
+
refreshToken: response.refreshToken,
|
|
49
|
+
});
|
|
50
|
+
return response.accessToken;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
(0, exports.removeTokens)();
|
|
54
|
+
window.location.href = "/login";
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const buildUrl = (endpoint, query) => {
|
|
59
|
+
let url = `${BASE_URL}${endpoint}`;
|
|
60
|
+
if (query && Object.keys(query).length > 0) {
|
|
61
|
+
url += `?${qs_1.default.stringify(query, {
|
|
62
|
+
allowDots: true,
|
|
63
|
+
arrayFormat: "brackets",
|
|
64
|
+
allowEmptyArrays: false,
|
|
65
|
+
skipNulls: true,
|
|
66
|
+
})}`;
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
};
|
|
11
70
|
async function apiRequest(endpoint, options = {}) {
|
|
12
|
-
var _a;
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const tokens = (0, exports.getTokens)();
|
|
13
73
|
const headers = {
|
|
14
74
|
Accept: "application/json",
|
|
15
|
-
Authorization: `Bearer ${(0, utils_1.generateRandomBase64)(20)}`,
|
|
16
75
|
"Content-Type": "application/json",
|
|
17
76
|
...options.headers,
|
|
18
77
|
};
|
|
78
|
+
if (!options.skipAuth && (tokens === null || tokens === void 0 ? void 0 : tokens.accessToken)) {
|
|
79
|
+
headers.Authorization = `Bearer ${tokens.accessToken}`;
|
|
80
|
+
}
|
|
19
81
|
const config = {
|
|
20
82
|
method: (_a = options.method) !== null && _a !== void 0 ? _a : enums_1.HttpMethods.GET,
|
|
21
83
|
headers,
|
|
22
|
-
// credentials: "include",
|
|
23
84
|
...options,
|
|
24
85
|
};
|
|
25
|
-
options.method && options.method !== enums_1.HttpMethods.GET
|
|
86
|
+
const logNonGetRequest = options.method && options.method !== enums_1.HttpMethods.GET;
|
|
87
|
+
if (logNonGetRequest) {
|
|
88
|
+
console.log("Request Config:", config);
|
|
89
|
+
console.log("Request URL:", buildUrl(endpoint, options.query));
|
|
90
|
+
}
|
|
26
91
|
try {
|
|
27
|
-
options.
|
|
28
|
-
options.method !== enums_1.HttpMethods.GET &&
|
|
29
|
-
console.log(`${BASE_URL}${endpoint}`);
|
|
30
|
-
let url = `${BASE_URL}${endpoint}`;
|
|
31
|
-
if (options.query && Object.keys(options.query).length > 0) {
|
|
32
|
-
console.log("Raw params ", options.query);
|
|
33
|
-
console.log("Stringified params = ", qs_1.default.stringify(options.query));
|
|
34
|
-
url += `?${qs_1.default.stringify(options.query, {
|
|
35
|
-
allowDots: true,
|
|
36
|
-
arrayFormat: "brackets",
|
|
37
|
-
allowEmptyArrays: false,
|
|
38
|
-
skipNulls: true,
|
|
39
|
-
})}`;
|
|
40
|
-
}
|
|
92
|
+
const url = buildUrl(endpoint, options.query);
|
|
41
93
|
const response = await fetch(url, config);
|
|
42
|
-
// Parse the response once and store it
|
|
43
94
|
const contentType = response.headers.get("content-type");
|
|
44
|
-
|
|
95
|
+
const responseData = (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json"))
|
|
45
96
|
? await response.json()
|
|
46
97
|
: await response.text();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.log(responseData);
|
|
98
|
+
if (logNonGetRequest) {
|
|
99
|
+
console.log("Response Data:", responseData);
|
|
100
|
+
}
|
|
51
101
|
if (!response.ok) {
|
|
52
102
|
const error = new Error(typeof responseData === "object"
|
|
53
103
|
? responseData.message || "API Error"
|
|
54
104
|
: "API Error");
|
|
55
105
|
error.status = response.status;
|
|
56
106
|
error.data = responseData;
|
|
57
|
-
|
|
58
|
-
|
|
107
|
+
// Handle token expired error
|
|
108
|
+
if (response.status === enums_1.HttpStatusCodes.UNAUTHORIZED &&
|
|
109
|
+
((_b = responseData === null || responseData === void 0 ? void 0 : responseData.error) === null || _b === void 0 ? void 0 : _b.type) === "AUTHENTICATION_ERROR" &&
|
|
110
|
+
((_c = responseData === null || responseData === void 0 ? void 0 : responseData.error) === null || _c === void 0 ? void 0 : _c.message) === "Token expired" &&
|
|
111
|
+
!options.skipAuth) {
|
|
112
|
+
if (isRefreshing) {
|
|
113
|
+
// Wait for token refresh if already in progress
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
subscribeTokenRefresh(async (newToken) => {
|
|
116
|
+
try {
|
|
117
|
+
// Retry the original request with new token
|
|
118
|
+
const retriedResponse = await apiRequest(endpoint, {
|
|
119
|
+
...options,
|
|
120
|
+
headers: {
|
|
121
|
+
...options.headers,
|
|
122
|
+
Authorization: `Bearer ${newToken}`,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
resolve(retriedResponse);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
reject(error);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
isRefreshing = true;
|
|
134
|
+
try {
|
|
135
|
+
const newToken = await refreshTokens();
|
|
136
|
+
onTokenRefreshed(newToken);
|
|
137
|
+
isRefreshing = false;
|
|
138
|
+
// Retry the original request with new token
|
|
139
|
+
return apiRequest(endpoint, {
|
|
140
|
+
...options,
|
|
141
|
+
headers: {
|
|
142
|
+
...options.headers,
|
|
143
|
+
Authorization: `Bearer ${newToken}`,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (refreshError) {
|
|
148
|
+
isRefreshing = false;
|
|
149
|
+
throw refreshError;
|
|
150
|
+
}
|
|
59
151
|
}
|
|
60
152
|
throw error;
|
|
61
153
|
}
|
|
62
|
-
// Return the already parsed response
|
|
63
154
|
return responseData;
|
|
64
155
|
}
|
|
65
156
|
catch (error) {
|
|
66
|
-
console.
|
|
157
|
+
console.error("API Request Error:", error);
|
|
67
158
|
return Promise.reject(error);
|
|
68
159
|
}
|
|
69
160
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { User } from "../../../models";
|
|
2
|
+
export declare class RegisterDTO {
|
|
3
|
+
email: string;
|
|
4
|
+
password: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
phone?: string;
|
|
7
|
+
static fromPlain(entity: any): RegisterDTO;
|
|
8
|
+
toPlain(): Record<string, unknown>;
|
|
9
|
+
validate(): string[];
|
|
10
|
+
}
|
|
11
|
+
export declare class LoginDTO {
|
|
12
|
+
email: string;
|
|
13
|
+
password: string;
|
|
14
|
+
static fromPlain(entity: any): LoginDTO;
|
|
15
|
+
toPlain(): Record<string, unknown>;
|
|
16
|
+
validate(): string[];
|
|
17
|
+
}
|
|
18
|
+
export declare class AuthResponseDTO {
|
|
19
|
+
user: User;
|
|
20
|
+
token: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.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
|
+
__metadata("design:type", String)
|
|
30
|
+
], RegisterDTO.prototype, "email", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, class_validator_1.IsString)(),
|
|
33
|
+
(0, class_validator_1.MinLength)(8),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], RegisterDTO.prototype, "password", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, class_validator_1.IsString)(),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], RegisterDTO.prototype, "name", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, class_validator_1.IsString)(),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], RegisterDTO.prototype, "phone", void 0);
|
|
44
|
+
exports.RegisterDTO = RegisterDTO;
|
|
45
|
+
class LoginDTO {
|
|
46
|
+
static fromPlain(entity) {
|
|
47
|
+
return (0, class_transformer_1.plainToClass)(LoginDTO, entity);
|
|
48
|
+
}
|
|
49
|
+
toPlain() {
|
|
50
|
+
return (0, class_transformer_1.classToPlain)(this);
|
|
51
|
+
}
|
|
52
|
+
validate() {
|
|
53
|
+
const errors = (0, class_validator_1.validateSync)(this);
|
|
54
|
+
return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, class_validator_1.IsEmail)(),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], LoginDTO.prototype, "email", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, class_validator_1.IsString)(),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], LoginDTO.prototype, "password", void 0);
|
|
65
|
+
exports.LoginDTO = LoginDTO;
|
|
66
|
+
class AuthResponseDTO {
|
|
67
|
+
}
|
|
68
|
+
exports.AuthResponseDTO = AuthResponseDTO;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { User } from "../../../models";
|
|
2
|
+
export declare class RoleGetDTO {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
permissions: string[];
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
users?: User[];
|
|
11
|
+
static fromEntity(entity: any): RoleGetDTO;
|
|
12
|
+
toPlain(): Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export declare class RoleCreateDTO {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
permissions: string[];
|
|
18
|
+
isActive?: boolean;
|
|
19
|
+
validate(): string[];
|
|
20
|
+
static fromPlain(plain: Record<string, unknown>): RoleCreateDTO;
|
|
21
|
+
toPlain(): Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export declare class RoleUpdateDTO {
|
|
24
|
+
name?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
permissions?: string[];
|
|
27
|
+
isActive?: boolean;
|
|
28
|
+
validate(): string[];
|
|
29
|
+
static fromPlain(plain: Record<string, unknown>): RoleUpdateDTO;
|
|
30
|
+
toPlain(): Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
export declare class RolePermissionUpdateDTO {
|
|
33
|
+
permissions: string[];
|
|
34
|
+
validate(): string[];
|
|
35
|
+
static fromPlain(plain: Record<string, unknown>): RolePermissionUpdateDTO;
|
|
36
|
+
toPlain(): Record<string, unknown>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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.RolePermissionUpdateDTO = exports.RoleUpdateDTO = exports.RoleCreateDTO = exports.RoleGetDTO = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const class_transformer_1 = require("class-transformer");
|
|
15
|
+
class RoleGetDTO {
|
|
16
|
+
static fromEntity(entity) {
|
|
17
|
+
return (0, class_transformer_1.plainToClass)(RoleGetDTO, entity);
|
|
18
|
+
}
|
|
19
|
+
toPlain() {
|
|
20
|
+
return (0, class_transformer_1.classToPlain)(this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.RoleGetDTO = RoleGetDTO;
|
|
24
|
+
class RoleCreateDTO {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.isActive = true;
|
|
27
|
+
}
|
|
28
|
+
validate() {
|
|
29
|
+
const errors = (0, class_validator_1.validateSync)(this);
|
|
30
|
+
return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
|
|
31
|
+
}
|
|
32
|
+
static fromPlain(plain) {
|
|
33
|
+
return (0, class_transformer_1.plainToClass)(RoleCreateDTO, plain);
|
|
34
|
+
}
|
|
35
|
+
toPlain() {
|
|
36
|
+
const plain = (0, class_transformer_1.classToPlain)(this);
|
|
37
|
+
// Add timestamps for creation
|
|
38
|
+
plain.createdAt = new Date();
|
|
39
|
+
plain.updatedAt = new Date();
|
|
40
|
+
return plain;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, class_validator_1.IsString)(),
|
|
45
|
+
__metadata("design:type", String)
|
|
46
|
+
], RoleCreateDTO.prototype, "name", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, class_validator_1.IsOptional)(),
|
|
49
|
+
(0, class_validator_1.IsString)(),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], RoleCreateDTO.prototype, "description", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, class_validator_1.IsArray)(),
|
|
54
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
55
|
+
__metadata("design:type", Array)
|
|
56
|
+
], RoleCreateDTO.prototype, "permissions", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, class_validator_1.IsOptional)(),
|
|
59
|
+
(0, class_validator_1.IsBoolean)(),
|
|
60
|
+
__metadata("design:type", Boolean)
|
|
61
|
+
], RoleCreateDTO.prototype, "isActive", void 0);
|
|
62
|
+
exports.RoleCreateDTO = RoleCreateDTO;
|
|
63
|
+
class RoleUpdateDTO {
|
|
64
|
+
validate() {
|
|
65
|
+
const errors = (0, class_validator_1.validateSync)(this);
|
|
66
|
+
return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
|
|
67
|
+
}
|
|
68
|
+
static fromPlain(plain) {
|
|
69
|
+
return (0, class_transformer_1.plainToClass)(RoleUpdateDTO, plain);
|
|
70
|
+
}
|
|
71
|
+
toPlain() {
|
|
72
|
+
const plain = (0, class_transformer_1.classToPlain)(this);
|
|
73
|
+
// Add updated timestamp
|
|
74
|
+
plain.updatedAt = new Date();
|
|
75
|
+
return plain;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
__decorate([
|
|
79
|
+
(0, class_validator_1.IsOptional)(),
|
|
80
|
+
(0, class_validator_1.IsString)(),
|
|
81
|
+
__metadata("design:type", String)
|
|
82
|
+
], RoleUpdateDTO.prototype, "name", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, class_validator_1.IsOptional)(),
|
|
85
|
+
(0, class_validator_1.IsString)(),
|
|
86
|
+
__metadata("design:type", String)
|
|
87
|
+
], RoleUpdateDTO.prototype, "description", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, class_validator_1.IsOptional)(),
|
|
90
|
+
(0, class_validator_1.IsArray)(),
|
|
91
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
92
|
+
__metadata("design:type", Array)
|
|
93
|
+
], RoleUpdateDTO.prototype, "permissions", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, class_validator_1.IsOptional)(),
|
|
96
|
+
(0, class_validator_1.IsBoolean)(),
|
|
97
|
+
__metadata("design:type", Boolean)
|
|
98
|
+
], RoleUpdateDTO.prototype, "isActive", void 0);
|
|
99
|
+
exports.RoleUpdateDTO = RoleUpdateDTO;
|
|
100
|
+
class RolePermissionUpdateDTO {
|
|
101
|
+
validate() {
|
|
102
|
+
const errors = (0, class_validator_1.validateSync)(this);
|
|
103
|
+
return errors.map((error) => { var _a; return Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}); }).flat();
|
|
104
|
+
}
|
|
105
|
+
static fromPlain(plain) {
|
|
106
|
+
return (0, class_transformer_1.plainToClass)(RolePermissionUpdateDTO, plain);
|
|
107
|
+
}
|
|
108
|
+
toPlain() {
|
|
109
|
+
const plain = (0, class_transformer_1.classToPlain)(this);
|
|
110
|
+
plain.updatedAt = new Date();
|
|
111
|
+
return plain;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, class_validator_1.IsArray)(),
|
|
116
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
117
|
+
__metadata("design:type", Array)
|
|
118
|
+
], RolePermissionUpdateDTO.prototype, "permissions", void 0);
|
|
119
|
+
exports.RolePermissionUpdateDTO = RolePermissionUpdateDTO;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Role } from "../../../models/Roles";
|
|
2
|
+
export declare class UserGetDTO {
|
|
3
|
+
id: string;
|
|
4
|
+
refId: number;
|
|
5
|
+
email: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
phone?: string;
|
|
8
|
+
photo?: string;
|
|
9
|
+
roles: Role[];
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
lastLogin?: Date;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
static fromEntity(entity: any): UserGetDTO;
|
|
15
|
+
toPlain(): Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export declare class UserCreateDTO {
|
|
18
|
+
email?: string;
|
|
19
|
+
password: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
phone: string;
|
|
22
|
+
photo?: string;
|
|
23
|
+
roleIds?: string[];
|
|
24
|
+
isActive?: boolean;
|
|
25
|
+
validate(): string[];
|
|
26
|
+
static fromPlain(plain: Record<string, unknown>): UserCreateDTO;
|
|
27
|
+
toPlain(): Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare class UserUpdateDTO {
|
|
30
|
+
password?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
phone?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
photo?: string;
|
|
35
|
+
roleIds?: string[];
|
|
36
|
+
isActive?: boolean;
|
|
37
|
+
validate(): string[];
|
|
38
|
+
static fromPlain(plain: Record<string, unknown>): UserUpdateDTO;
|
|
39
|
+
toPlain(): Record<string, unknown>;
|
|
40
|
+
}
|