@titus-system/syncdesk 0.5.1 → 0.5.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/api/client.d.ts +7 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +105 -0
- package/{src/api/index.ts → dist/api/index.d.ts} +1 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/typings.d.ts +4 -0
- package/dist/api/typings.d.ts.map +1 -0
- package/dist/api/typings.js +1 -0
- package/dist/auth/hooks/useAuth.d.ts +51 -0
- package/dist/auth/hooks/useAuth.d.ts.map +1 -0
- package/dist/auth/hooks/useAuth.js +127 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/types/auth.d.ts +51 -0
- package/dist/auth/types/auth.d.ts.map +1 -0
- package/dist/auth/types/auth.js +1 -0
- package/dist/auth/types/session.d.ts +12 -0
- package/dist/auth/types/session.d.ts.map +1 -0
- package/dist/auth/types/session.js +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +10 -0
- package/dist/health/hooks/useHealth.d.ts +17 -0
- package/dist/health/hooks/useHealth.d.ts.map +1 -0
- package/dist/health/hooks/useHealth.js +42 -0
- package/dist/health/index.d.ts +3 -0
- package/dist/health/index.d.ts.map +1 -0
- package/dist/health/types/health.d.ts +10 -0
- package/dist/health/types/health.d.ts.map +1 -0
- package/dist/health/types/health.js +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/live_chat/hooks/useLiveChat.d.ts +37 -0
- package/dist/live_chat/hooks/useLiveChat.d.ts.map +1 -0
- package/dist/live_chat/hooks/useLiveChat.js +91 -0
- package/dist/live_chat/hooks/useLiveChatWebSocket.d.ts +11 -0
- package/dist/live_chat/hooks/useLiveChatWebSocket.d.ts.map +1 -0
- package/dist/live_chat/hooks/useLiveChatWebSocket.js +68 -0
- package/dist/live_chat/index.d.ts +4 -0
- package/dist/live_chat/index.d.ts.map +1 -0
- package/dist/live_chat/index.js +2 -0
- package/dist/live_chat/types/live_chat.d.ts +45 -0
- package/dist/live_chat/types/live_chat.d.ts.map +1 -0
- package/dist/live_chat/types/live_chat.js +1 -0
- package/dist/permissions/hooks/usePermissions.d.ts +71 -0
- package/dist/permissions/hooks/usePermissions.d.ts.map +1 -0
- package/dist/permissions/hooks/usePermissions.js +147 -0
- package/dist/permissions/index.d.ts +3 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/types/index.d.ts +2 -0
- package/dist/permissions/types/index.d.ts.map +1 -0
- package/dist/permissions/types/permission.d.ts +23 -0
- package/dist/permissions/types/permission.d.ts.map +1 -0
- package/dist/permissions/types/permission.js +1 -0
- package/dist/roles/hooks/useRoles.d.ts +62 -0
- package/dist/roles/hooks/useRoles.d.ts.map +1 -0
- package/dist/roles/hooks/useRoles.js +138 -0
- package/dist/roles/index.d.ts +3 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/types/index.d.ts +2 -0
- package/dist/roles/types/index.d.ts.map +1 -0
- package/dist/roles/types/role.d.ts +23 -0
- package/dist/roles/types/role.d.ts.map +1 -0
- package/dist/roles/types/role.js +1 -0
- package/dist/ticket/hooks/useTickets.d.ts +27 -0
- package/dist/ticket/hooks/useTickets.d.ts.map +1 -0
- package/dist/ticket/hooks/useTickets.js +57 -0
- package/dist/ticket/index.d.ts +3 -0
- package/dist/ticket/index.d.ts.map +1 -0
- package/dist/ticket/types/ticket.d.ts +74 -0
- package/dist/ticket/types/ticket.d.ts.map +1 -0
- package/dist/ticket/types/ticket.js +1 -0
- package/dist/users/hooks/useUsers.d.ts +46 -0
- package/dist/users/hooks/useUsers.d.ts.map +1 -0
- package/dist/users/hooks/useUsers.js +105 -0
- package/dist/users/index.d.ts +3 -0
- package/dist/users/index.d.ts.map +1 -0
- package/dist/users/index.js +1 -0
- package/dist/users/types/user.d.ts +30 -0
- package/dist/users/types/user.d.ts.map +1 -0
- package/dist/users/types/user.js +1 -0
- package/package.json +5 -2
- package/.editorconfig +0 -53
- package/.github/workflows/notify-main.yml +0 -17
- package/CHANGELOG.md +0 -29
- package/src/api/client.ts +0 -135
- package/src/api/typings.ts +0 -3
- package/src/auth/hooks/useAuth.ts +0 -173
- package/src/auth/index.ts +0 -12
- package/src/auth/types/auth.ts +0 -61
- package/src/auth/types/session.ts +0 -12
- package/src/config.ts +0 -31
- package/src/health/hooks/useHealth.ts +0 -57
- package/src/health/types/health.ts +0 -10
- package/src/live_chat/hooks/useLiveChat.ts +0 -124
- package/src/live_chat/hooks/useLiveChatWebSocket.ts +0 -86
- package/src/live_chat/index.ts +0 -15
- package/src/live_chat/types/live_chat.ts +0 -48
- package/src/permissions/hooks/usePermissions.ts +0 -196
- package/src/permissions/types/permission.ts +0 -27
- package/src/roles/hooks/useRoles.ts +0 -167
- package/src/roles/types/role.ts +0 -28
- package/src/ticket/hooks/useTickets.ts +0 -89
- package/src/ticket/types/ticket.ts +0 -88
- package/src/users/hooks/useUsers.ts +0 -150
- package/src/users/index.ts +0 -16
- package/src/users/types/user.ts +0 -36
- package/tsconfig.json +0 -29
- package/tsup.config.ts +0 -12
- /package/{src/health/index.ts → dist/health/index.js} +0 -0
- /package/{src/permissions/index.ts → dist/permissions/index.js} +0 -0
- /package/{src/permissions/types/index.ts → dist/permissions/types/index.js} +0 -0
- /package/{src/roles/index.ts → dist/roles/index.js} +0 -0
- /package/{src/roles/types/index.ts → dist/roles/types/index.js} +0 -0
- /package/{src/ticket/index.ts → dist/ticket/index.js} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LibraryConfig } from "../config";
|
|
2
|
+
export declare const apiClient: import("axios").AxiosInstance;
|
|
3
|
+
/**
|
|
4
|
+
* Configure the library with user-provided settings.
|
|
5
|
+
*/
|
|
6
|
+
export declare const configureLibrary: (userConfig: LibraryConfig) => void;
|
|
7
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,aAAa,EAAE,MAAM,WAAW,CAAC;AAElD,eAAO,MAAM,SAAS,+BAAiB,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,aAAa,SAMzD,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { config } from "../config";
|
|
3
|
+
export const apiClient = axios.create();
|
|
4
|
+
/**
|
|
5
|
+
* Configure the library with user-provided settings.
|
|
6
|
+
*/
|
|
7
|
+
export const configureLibrary = (userConfig) => {
|
|
8
|
+
// Overwrite the default internal config with the user's settings
|
|
9
|
+
Object.assign(config, userConfig);
|
|
10
|
+
apiClient.defaults.baseURL = config.baseURL;
|
|
11
|
+
apiClient.defaults.timeout = config.timeout;
|
|
12
|
+
};
|
|
13
|
+
// INTERCEPTORS
|
|
14
|
+
/**
|
|
15
|
+
* Request Interceptor.
|
|
16
|
+
* Automatically adds the access token to the Authorization header of every request if it's available.
|
|
17
|
+
*/
|
|
18
|
+
apiClient.interceptors.request.use(async (reqConfig) => {
|
|
19
|
+
const token = await config.getAccessToken();
|
|
20
|
+
if (token && reqConfig.headers) {
|
|
21
|
+
reqConfig.headers.Authorization = `Bearer ${token}`;
|
|
22
|
+
}
|
|
23
|
+
return reqConfig;
|
|
24
|
+
}, (error) => Promise.reject(error));
|
|
25
|
+
/**
|
|
26
|
+
* Response Interceptor.
|
|
27
|
+
*/
|
|
28
|
+
let isRefreshing = false; // Flag to prevent multiple simultaneous refresh attempts
|
|
29
|
+
let failedQueue = [];
|
|
30
|
+
/** Processes the queue of failed requests after token refresh. */
|
|
31
|
+
const processQueue = (error, token = null) => {
|
|
32
|
+
failedQueue.forEach((promise) => {
|
|
33
|
+
if (error) {
|
|
34
|
+
promise.reject(error);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
promise.resolve(token);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
failedQueue = [];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* This interceptor watches for 401 responses. If it sees one, it tries to get a new access token using
|
|
44
|
+
* the refresh token.
|
|
45
|
+
*
|
|
46
|
+
* Meanwhile, it queues up any new requests that also fail with 401, and once it gets a new token,
|
|
47
|
+
* it retries all the failed requests with the new token. If the refresh token is also expired/invalid,
|
|
48
|
+
* it calls the onUnauthorized callback to let the app know they need to log in again.
|
|
49
|
+
*/
|
|
50
|
+
apiClient.interceptors.response.use((response) => response, // success
|
|
51
|
+
async (error) => {
|
|
52
|
+
const originalRequest = error.config;
|
|
53
|
+
// if 401 and not retried
|
|
54
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
55
|
+
if (originalRequest.url?.includes("/refresh") ||
|
|
56
|
+
originalRequest.url?.includes("/login")) {
|
|
57
|
+
config.onUnauthorized();
|
|
58
|
+
return Promise.reject(error);
|
|
59
|
+
}
|
|
60
|
+
// If another request is currently refreshing the token, pause this request and add to queue
|
|
61
|
+
if (isRefreshing) {
|
|
62
|
+
return (new Promise((resolve, reject) => {
|
|
63
|
+
failedQueue.push({ resolve, reject });
|
|
64
|
+
})
|
|
65
|
+
.then((token) => {
|
|
66
|
+
// on success, add the new token to the request header and return the client
|
|
67
|
+
originalRequest.headers.Authorization = `Bearer ${token}`;
|
|
68
|
+
return apiClient(originalRequest);
|
|
69
|
+
})
|
|
70
|
+
// on error, reject the request
|
|
71
|
+
.catch((err) => Promise.reject(err)));
|
|
72
|
+
}
|
|
73
|
+
// Mark that we are starting the refresh process
|
|
74
|
+
originalRequest._retry = true;
|
|
75
|
+
isRefreshing = true;
|
|
76
|
+
try {
|
|
77
|
+
const refreshToken = await config.getRefreshToken();
|
|
78
|
+
if (!refreshToken) {
|
|
79
|
+
throw new Error("No refresh token available.");
|
|
80
|
+
}
|
|
81
|
+
// Do a standard axios call to get the new token, so the interceptors are not called again.
|
|
82
|
+
const refreshResponse = await axios.post(`${config.baseURL}/refresh`, {
|
|
83
|
+
refresh_token: refreshToken,
|
|
84
|
+
});
|
|
85
|
+
const newAccessToken = refreshResponse.data.data.access_token;
|
|
86
|
+
const newRefreshToken = refreshResponse.data.data.refresh_token;
|
|
87
|
+
await config.onTokensRefreshed(newAccessToken, newRefreshToken);
|
|
88
|
+
// Resume all the other paused requests with the new token
|
|
89
|
+
processQueue(null, newAccessToken);
|
|
90
|
+
// Retry the original request that failed
|
|
91
|
+
originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
|
|
92
|
+
return apiClient(originalRequest);
|
|
93
|
+
}
|
|
94
|
+
catch (refreshError) {
|
|
95
|
+
// If the refresh token is completely expired, kill the queue and log them out
|
|
96
|
+
processQueue(refreshError, null);
|
|
97
|
+
config.onUnauthorized();
|
|
98
|
+
return Promise.reject(refreshError);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
isRefreshing = false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return Promise.reject(error);
|
|
105
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { apiClient, configureLibrary } from "./client";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typings.d.ts","sourceRoot":"","sources":["../../src/api/typings.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC;CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AdminRegisterUserRequest, ChangePasswordRequest, ForgotPasswordRequest, ForgotPasswordResponse, LoginResponse, RegisterUserRequest, ResetPasswordRequest, UserCreatedResponse, UserLoginRequest, UserWithRoles } from "../types/auth";
|
|
2
|
+
import { User } from "../../users/types/user";
|
|
3
|
+
/**
|
|
4
|
+
* Get the currently authenticated user's profile.
|
|
5
|
+
* @returns {UseQueryResult<UserWithRoles, Error>} The query result.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useGetMe: () => import("@tanstack/react-query").UseQueryResult<UserWithRoles, Error>;
|
|
8
|
+
/**
|
|
9
|
+
* Log in a user.
|
|
10
|
+
*
|
|
11
|
+
* Refresh tokens are handled automatically using Interceptors.
|
|
12
|
+
* @param {UserLoginRequest} credentials The user login credentials.
|
|
13
|
+
* @returns {UseMutationResult<LoginResponse, Error, UserLoginRequest>} The mutation result.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useLogin: () => import("@tanstack/react-query").UseMutationResult<LoginResponse, Error, UserLoginRequest, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Register a new user.
|
|
18
|
+
* @param {RegisterUserRequest} userData The user registration details.
|
|
19
|
+
* @returns {UseMutationResult<UserCreatedResponse, Error, RegisterUserRequest>} The mutation result.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useRegister: () => import("@tanstack/react-query").UseMutationResult<UserCreatedResponse, Error, RegisterUserRequest, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Log out the current user.
|
|
24
|
+
* @returns {UseMutationResult<void, Error, void>} The mutation result.
|
|
25
|
+
*/
|
|
26
|
+
export declare const useLogout: () => import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Register a new user as admin.
|
|
29
|
+
* @param {AdminRegisterUserRequest} userData The admin user registration details.
|
|
30
|
+
* @returns {UseMutationResult<User, Error, AdminRegisterUserRequest>} The mutation result.
|
|
31
|
+
*/
|
|
32
|
+
export declare const useAdminRegister: () => import("@tanstack/react-query").UseMutationResult<User, Error, AdminRegisterUserRequest, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Change the current user's password.
|
|
35
|
+
* @param {ChangePasswordRequest} data The password change request details.
|
|
36
|
+
* @returns {UseMutationResult<void, Error, ChangePasswordRequest>} The mutation result.
|
|
37
|
+
*/
|
|
38
|
+
export declare const useChangePassword: () => import("@tanstack/react-query").UseMutationResult<void, Error, ChangePasswordRequest, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Request a password reset.
|
|
41
|
+
* @param {ForgotPasswordRequest} data The forgot password request details.
|
|
42
|
+
* @returns {UseMutationResult<ForgotPasswordResponse, Error, ForgotPasswordRequest>} The mutation result.
|
|
43
|
+
*/
|
|
44
|
+
export declare const useForgotPassword: () => import("@tanstack/react-query").UseMutationResult<ForgotPasswordResponse, Error, ForgotPasswordRequest, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Reset the current user's password using a valid reset token.
|
|
47
|
+
* @param {ResetPasswordRequest} data The reset password request details.
|
|
48
|
+
* @returns {UseMutationResult<void, Error, ResetPasswordRequest>} The mutation result.
|
|
49
|
+
*/
|
|
50
|
+
export declare const useResetPassword: () => import("@tanstack/react-query").UseMutationResult<void, Error, ResetPasswordRequest, unknown>;
|
|
51
|
+
//# sourceMappingURL=useAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../../src/auth/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAI9C;;;GAGG;AACH,eAAO,MAAM,QAAQ,4EAapB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,0GAkBpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,mHAkBvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,qFAarB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,yGAe5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,sGAM7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,wHAW7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,qGAM5B,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { apiClient } from "../../api";
|
|
3
|
+
const PATH = "auth";
|
|
4
|
+
/**
|
|
5
|
+
* Get the currently authenticated user's profile.
|
|
6
|
+
* @returns {UseQueryResult<UserWithRoles, Error>} The query result.
|
|
7
|
+
*/
|
|
8
|
+
export const useGetMe = () => {
|
|
9
|
+
return useQuery({
|
|
10
|
+
queryKey: ["me"],
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const response = await apiClient.get(`${PATH}/me`);
|
|
13
|
+
return response.data.data;
|
|
14
|
+
},
|
|
15
|
+
// if the user isn't logged in (401)
|
|
16
|
+
retry: false,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Log in a user.
|
|
21
|
+
*
|
|
22
|
+
* Refresh tokens are handled automatically using Interceptors.
|
|
23
|
+
* @param {UserLoginRequest} credentials The user login credentials.
|
|
24
|
+
* @returns {UseMutationResult<LoginResponse, Error, UserLoginRequest>} The mutation result.
|
|
25
|
+
*/
|
|
26
|
+
export const useLogin = () => {
|
|
27
|
+
const queryClient = useQueryClient();
|
|
28
|
+
return useMutation({
|
|
29
|
+
mutationFn: async (credentials) => {
|
|
30
|
+
const response = await apiClient.post(`${PATH}/login`, credentials);
|
|
31
|
+
return response.data.data;
|
|
32
|
+
},
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
// After a successful login, fetch the new user's profile
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: ["me"] });
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Register a new user.
|
|
41
|
+
* @param {RegisterUserRequest} userData The user registration details.
|
|
42
|
+
* @returns {UseMutationResult<UserCreatedResponse, Error, RegisterUserRequest>} The mutation result.
|
|
43
|
+
*/
|
|
44
|
+
export const useRegister = () => {
|
|
45
|
+
const queryClient = useQueryClient();
|
|
46
|
+
return useMutation({
|
|
47
|
+
mutationFn: async (userData) => {
|
|
48
|
+
const response = await apiClient.post(`${PATH}/register`, userData);
|
|
49
|
+
return response.data.data;
|
|
50
|
+
},
|
|
51
|
+
onSuccess: () => {
|
|
52
|
+
// Registration also logs them in (returns tokens), so fetch their profile
|
|
53
|
+
queryClient.invalidateQueries({ queryKey: ["me"] });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Log out the current user.
|
|
59
|
+
* @returns {UseMutationResult<void, Error, void>} The mutation result.
|
|
60
|
+
*/
|
|
61
|
+
export const useLogout = () => {
|
|
62
|
+
const queryClient = useQueryClient();
|
|
63
|
+
return useMutation({
|
|
64
|
+
mutationFn: async () => {
|
|
65
|
+
await apiClient.post(`${PATH}/logout`);
|
|
66
|
+
},
|
|
67
|
+
onSuccess: () => {
|
|
68
|
+
// clear cache
|
|
69
|
+
queryClient.setQueryData(["me"], null);
|
|
70
|
+
queryClient.clear();
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Register a new user as admin.
|
|
76
|
+
* @param {AdminRegisterUserRequest} userData The admin user registration details.
|
|
77
|
+
* @returns {UseMutationResult<User, Error, AdminRegisterUserRequest>} The mutation result.
|
|
78
|
+
*/
|
|
79
|
+
export const useAdminRegister = () => {
|
|
80
|
+
const queryClient = useQueryClient();
|
|
81
|
+
return useMutation({
|
|
82
|
+
mutationFn: async (userData) => {
|
|
83
|
+
const response = await apiClient.post(`${PATH}/admin/register`, userData);
|
|
84
|
+
return response.data.data;
|
|
85
|
+
},
|
|
86
|
+
onSuccess: () => {
|
|
87
|
+
queryClient.invalidateQueries({ queryKey: ["users"] });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Change the current user's password.
|
|
93
|
+
* @param {ChangePasswordRequest} data The password change request details.
|
|
94
|
+
* @returns {UseMutationResult<void, Error, ChangePasswordRequest>} The mutation result.
|
|
95
|
+
*/
|
|
96
|
+
export const useChangePassword = () => {
|
|
97
|
+
return useMutation({
|
|
98
|
+
mutationFn: async (data) => {
|
|
99
|
+
await apiClient.post(`${PATH}/change-password`, data);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Request a password reset.
|
|
105
|
+
* @param {ForgotPasswordRequest} data The forgot password request details.
|
|
106
|
+
* @returns {UseMutationResult<ForgotPasswordResponse, Error, ForgotPasswordRequest>} The mutation result.
|
|
107
|
+
*/
|
|
108
|
+
export const useForgotPassword = () => {
|
|
109
|
+
return useMutation({
|
|
110
|
+
mutationFn: async (data) => {
|
|
111
|
+
const response = await apiClient.post(`${PATH}/forgot-password`, data);
|
|
112
|
+
return response.data.data;
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Reset the current user's password using a valid reset token.
|
|
118
|
+
* @param {ResetPasswordRequest} data The reset password request details.
|
|
119
|
+
* @returns {UseMutationResult<void, Error, ResetPasswordRequest>} The mutation result.
|
|
120
|
+
*/
|
|
121
|
+
export const useResetPassword = () => {
|
|
122
|
+
return useMutation({
|
|
123
|
+
mutationFn: async (data) => {
|
|
124
|
+
await apiClient.post(`${PATH}/reset-password`, data);
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { useGetMe, useLogin, useRegister, useLogout } from "./hooks/useAuth";
|
|
2
|
+
export type { OAuthProvider, LoginResponse, UserCreatedResponse, UserLoginRequest, RegisterUserRequest, UserWithRoles, } from "./types/auth";
|
|
3
|
+
export type { Status, Session } from "./types/session";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7E,YAAY,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useGetMe, useLogin, useRegister, useLogout } from "./hooks/useAuth";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type OAuthProvider = "local" | "google" | "microsoft";
|
|
2
|
+
export interface LoginResponse {
|
|
3
|
+
access_token: string;
|
|
4
|
+
refresh_token: string;
|
|
5
|
+
must_change_password?: boolean;
|
|
6
|
+
must_accept_terms?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UserCreatedResponse {
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
username: string;
|
|
12
|
+
access_token: string;
|
|
13
|
+
refresh_token: string;
|
|
14
|
+
}
|
|
15
|
+
export interface UserLoginRequest {
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RegisterUserRequest {
|
|
20
|
+
email: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
username?: string;
|
|
23
|
+
password: string;
|
|
24
|
+
}
|
|
25
|
+
export interface AdminRegisterUserRequest {
|
|
26
|
+
email: string;
|
|
27
|
+
name?: string | null;
|
|
28
|
+
role_ids?: number[];
|
|
29
|
+
}
|
|
30
|
+
export interface ChangePasswordRequest {
|
|
31
|
+
current_password: string;
|
|
32
|
+
new_password: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ForgotPasswordRequest {
|
|
35
|
+
email: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ResetPasswordRequest {
|
|
38
|
+
token: string;
|
|
39
|
+
new_password: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ForgotPasswordResponse {
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export interface UserWithRoles {
|
|
45
|
+
id: string;
|
|
46
|
+
email: string;
|
|
47
|
+
username: string;
|
|
48
|
+
name?: string | null;
|
|
49
|
+
roles: string[];
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/auth/types/auth.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE7D,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Status = "active" | "expired" | "invalid" | "revoked";
|
|
2
|
+
export interface Session {
|
|
3
|
+
id: string;
|
|
4
|
+
user_id: string;
|
|
5
|
+
refresh_token_hash: string;
|
|
6
|
+
status: Status;
|
|
7
|
+
device_info: Record<string, unknown>;
|
|
8
|
+
expires_at: Date | string;
|
|
9
|
+
last_used_at: Date | string;
|
|
10
|
+
revoked_at: Date | string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/auth/types/session.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAC1B,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC;IAC5B,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface LibraryConfig {
|
|
2
|
+
/** API URL */
|
|
3
|
+
baseURL: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
getAccessToken: () => string | null | Promise<string | null>;
|
|
6
|
+
/** Get the refresh token when it needs a new one */
|
|
7
|
+
getRefreshToken: () => string | null | Promise<string | null>;
|
|
8
|
+
/** Callback fired when the library successfully gets new tokens from the backend */
|
|
9
|
+
onTokensRefreshed: (accessToken: string, refreshToken: string) => void | Promise<void>;
|
|
10
|
+
/** Fired if the user is not authenticated and refresh token fails. */
|
|
11
|
+
onUnauthorized: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const config: Required<LibraryConfig>;
|
|
14
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE7D,oDAAoD;IACpD,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE9D,oFAAoF;IACpF,iBAAiB,EAAE,CACjB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,KACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B,sEAAsE;IACtE,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,aAAa,CAS1C,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PingResponse, HealthResponse, ReadyResponse } from "../types/health";
|
|
2
|
+
/**
|
|
3
|
+
* Ping the server to check for basic connectivity.
|
|
4
|
+
* @returns {UseQueryResult<PingResponse, Error>} The result.
|
|
5
|
+
*/
|
|
6
|
+
export declare const usePing: () => import("@tanstack/react-query").UseQueryResult<PingResponse, Error>;
|
|
7
|
+
/**
|
|
8
|
+
* Check the detailed health of the server and its dependencies (e.g. databases).
|
|
9
|
+
* @returns {UseQueryResult<HealthResponse, Error>} The result.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useHealth: () => import("@tanstack/react-query").UseQueryResult<HealthResponse, Error>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the server is ready to accept traffic.
|
|
14
|
+
* @returns {UseQueryResult<ReadyResponse, Error>} The result.
|
|
15
|
+
*/
|
|
16
|
+
export declare const useReady: () => import("@tanstack/react-query").UseQueryResult<ReadyResponse, Error>;
|
|
17
|
+
//# sourceMappingURL=useHealth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHealth.d.ts","sourceRoot":"","sources":["../../../src/health/hooks/useHealth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACd,MAAM,iBAAiB,CAAC;AAIzB;;;GAGG;AACH,eAAO,MAAM,OAAO,2EAUnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,6EAUrB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,4EAUpB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { apiClient } from "../../api";
|
|
3
|
+
const PATH = "";
|
|
4
|
+
/**
|
|
5
|
+
* Ping the server to check for basic connectivity.
|
|
6
|
+
* @returns {UseQueryResult<PingResponse, Error>} The result.
|
|
7
|
+
*/
|
|
8
|
+
export const usePing = () => {
|
|
9
|
+
return useQuery({
|
|
10
|
+
queryKey: ["health", "ping"],
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const response = await apiClient.get(`${PATH}/ping`);
|
|
13
|
+
return response.data.data;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check the detailed health of the server and its dependencies (e.g. databases).
|
|
19
|
+
* @returns {UseQueryResult<HealthResponse, Error>} The result.
|
|
20
|
+
*/
|
|
21
|
+
export const useHealth = () => {
|
|
22
|
+
return useQuery({
|
|
23
|
+
queryKey: ["health", "status"],
|
|
24
|
+
queryFn: async () => {
|
|
25
|
+
const response = await apiClient.get(`${PATH}/health`);
|
|
26
|
+
return response.data.data;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Check if the server is ready to accept traffic.
|
|
32
|
+
* @returns {UseQueryResult<ReadyResponse, Error>} The result.
|
|
33
|
+
*/
|
|
34
|
+
export const useReady = () => {
|
|
35
|
+
return useQuery({
|
|
36
|
+
queryKey: ["health", "ready"],
|
|
37
|
+
queryFn: async () => {
|
|
38
|
+
const response = await apiClient.get(`${PATH}/ready`);
|
|
39
|
+
return response.data.data;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/health/types/health.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,WAAW,GAAG,UAAU,CAAC;IAC1C,YAAY,EAAE,WAAW,GAAG,UAAU,CAAC;CACxC;AAED,MAAM,WAAW,aAAa;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Conversation, CreateConversationDTO, PaginatedMessages } from "../types/live_chat";
|
|
2
|
+
/**
|
|
3
|
+
* Get all conversations of a ticket.
|
|
4
|
+
* @param {string} ticket_id ticket_id parameter.
|
|
5
|
+
* @returns {UseQueryResult<Conversation[]>} The query result.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useGetConversations: (ticket_id: string) => import("@tanstack/react-query").UseQueryResult<Conversation[], Error>;
|
|
8
|
+
/**
|
|
9
|
+
* Get a specific client's conversations.
|
|
10
|
+
* @param {string} client_id client_id parameter.
|
|
11
|
+
* @returns {UseQueryResult<Conversation[]>} The query result.
|
|
12
|
+
*/
|
|
13
|
+
export declare const useGetClientConversations: (client_id: string) => import("@tanstack/react-query").UseQueryResult<Conversation[], Error>;
|
|
14
|
+
/**
|
|
15
|
+
* Get ticket messages with pagination.
|
|
16
|
+
* @param {string} ticket_id ticket_id parameter.
|
|
17
|
+
* @param {number} page page parameter.
|
|
18
|
+
* @param {number} limit limit parameter.
|
|
19
|
+
* @returns {UseQueryResult<PaginatedMessages>} The query result.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useGetPaginatedMessages: (ticket_id: string, page?: number, limit?: number) => import("@tanstack/react-query").UseQueryResult<PaginatedMessages, Error>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new conversation.
|
|
24
|
+
* @param {CreateConversationDTO} dto The conversation creation details.
|
|
25
|
+
* @returns {UseMutationResult<Conversation, Error, CreateConversationDTO>} The mutation result.
|
|
26
|
+
*/
|
|
27
|
+
export declare const useCreateConversation: () => import("@tanstack/react-query").UseMutationResult<Conversation, Error, CreateConversationDTO, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Assign an agent to a conversation.
|
|
30
|
+
* @param {{ chat_id: string; agent_id: string }} params The chat ID and agent ID payload.
|
|
31
|
+
* @returns {UseMutationResult<void, Error, { chat_id: string; agent_id: string }>} The mutation result.
|
|
32
|
+
*/
|
|
33
|
+
export declare const useSetConversationAgent: () => import("@tanstack/react-query").UseMutationResult<void, Error, {
|
|
34
|
+
chat_id: string;
|
|
35
|
+
agent_id: string;
|
|
36
|
+
}, unknown>;
|
|
37
|
+
//# sourceMappingURL=useLiveChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveChat.d.ts","sourceRoot":"","sources":["../../../src/live_chat/hooks/useLiveChat.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,0EAWpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,WAAW,MAAM,0EAW1D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,WAAW,MAAM,EACjB,aAAQ,EACR,cAAU,6EAmBX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,8GAiBjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;aAQrB,MAAM;cACL,MAAM;WAQrB,CAAC"}
|