@titus-system/syncdesk 0.5.0 → 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.
Files changed (118) hide show
  1. package/dist/api/client.d.ts +7 -0
  2. package/dist/api/client.d.ts.map +1 -0
  3. package/dist/api/client.js +105 -0
  4. package/{src/api/index.ts → dist/api/index.d.ts} +1 -0
  5. package/dist/api/index.d.ts.map +1 -0
  6. package/dist/api/index.js +1 -0
  7. package/dist/api/typings.d.ts +4 -0
  8. package/dist/api/typings.d.ts.map +1 -0
  9. package/dist/api/typings.js +1 -0
  10. package/dist/auth/hooks/useAuth.d.ts +51 -0
  11. package/dist/auth/hooks/useAuth.d.ts.map +1 -0
  12. package/dist/auth/hooks/useAuth.js +127 -0
  13. package/dist/auth/index.d.ts +4 -0
  14. package/dist/auth/index.d.ts.map +1 -0
  15. package/dist/auth/index.js +1 -0
  16. package/dist/auth/types/auth.d.ts +51 -0
  17. package/dist/auth/types/auth.d.ts.map +1 -0
  18. package/dist/auth/types/auth.js +1 -0
  19. package/dist/auth/types/session.d.ts +12 -0
  20. package/dist/auth/types/session.d.ts.map +1 -0
  21. package/dist/auth/types/session.js +1 -0
  22. package/dist/config.d.ts +14 -0
  23. package/dist/config.d.ts.map +1 -0
  24. package/dist/config.js +10 -0
  25. package/dist/health/hooks/useHealth.d.ts +17 -0
  26. package/dist/health/hooks/useHealth.d.ts.map +1 -0
  27. package/dist/health/hooks/useHealth.js +42 -0
  28. package/dist/health/index.d.ts +3 -0
  29. package/dist/health/index.d.ts.map +1 -0
  30. package/dist/health/types/health.d.ts +10 -0
  31. package/dist/health/types/health.d.ts.map +1 -0
  32. package/dist/health/types/health.js +1 -0
  33. package/{src/index.ts → dist/index.d.ts} +1 -1
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +9 -0
  36. package/dist/live_chat/hooks/useLiveChat.d.ts +37 -0
  37. package/dist/live_chat/hooks/useLiveChat.d.ts.map +1 -0
  38. package/dist/live_chat/hooks/useLiveChat.js +91 -0
  39. package/dist/live_chat/hooks/useLiveChatWebSocket.d.ts +11 -0
  40. package/dist/live_chat/hooks/useLiveChatWebSocket.d.ts.map +1 -0
  41. package/dist/live_chat/hooks/useLiveChatWebSocket.js +68 -0
  42. package/dist/live_chat/index.d.ts +4 -0
  43. package/dist/live_chat/index.d.ts.map +1 -0
  44. package/dist/live_chat/index.js +2 -0
  45. package/dist/live_chat/types/live_chat.d.ts +45 -0
  46. package/dist/live_chat/types/live_chat.d.ts.map +1 -0
  47. package/dist/live_chat/types/live_chat.js +1 -0
  48. package/dist/permissions/hooks/usePermissions.d.ts +71 -0
  49. package/dist/permissions/hooks/usePermissions.d.ts.map +1 -0
  50. package/dist/permissions/hooks/usePermissions.js +147 -0
  51. package/dist/permissions/index.d.ts +3 -0
  52. package/dist/permissions/index.d.ts.map +1 -0
  53. package/dist/permissions/types/index.d.ts +2 -0
  54. package/dist/permissions/types/index.d.ts.map +1 -0
  55. package/dist/permissions/types/permission.d.ts +23 -0
  56. package/dist/permissions/types/permission.d.ts.map +1 -0
  57. package/dist/permissions/types/permission.js +1 -0
  58. package/dist/roles/hooks/useRoles.d.ts +62 -0
  59. package/dist/roles/hooks/useRoles.d.ts.map +1 -0
  60. package/dist/roles/hooks/useRoles.js +138 -0
  61. package/dist/roles/index.d.ts +3 -0
  62. package/dist/roles/index.d.ts.map +1 -0
  63. package/dist/roles/types/index.d.ts +2 -0
  64. package/dist/roles/types/index.d.ts.map +1 -0
  65. package/dist/roles/types/role.d.ts +23 -0
  66. package/dist/roles/types/role.d.ts.map +1 -0
  67. package/dist/roles/types/role.js +1 -0
  68. package/dist/ticket/hooks/useTickets.d.ts +27 -0
  69. package/dist/ticket/hooks/useTickets.d.ts.map +1 -0
  70. package/dist/ticket/hooks/useTickets.js +57 -0
  71. package/dist/ticket/index.d.ts +3 -0
  72. package/dist/ticket/index.d.ts.map +1 -0
  73. package/dist/ticket/types/ticket.d.ts +74 -0
  74. package/dist/ticket/types/ticket.d.ts.map +1 -0
  75. package/dist/ticket/types/ticket.js +1 -0
  76. package/dist/users/hooks/useUsers.d.ts +46 -0
  77. package/dist/users/hooks/useUsers.d.ts.map +1 -0
  78. package/dist/users/hooks/useUsers.js +105 -0
  79. package/dist/users/index.d.ts +3 -0
  80. package/dist/users/index.d.ts.map +1 -0
  81. package/dist/users/index.js +1 -0
  82. package/dist/users/types/user.d.ts +30 -0
  83. package/dist/users/types/user.d.ts.map +1 -0
  84. package/dist/users/types/user.js +1 -0
  85. package/package.json +10 -4
  86. package/.editorconfig +0 -53
  87. package/.github/workflows/notify-main.yml +0 -17
  88. package/CHANGELOG.md +0 -29
  89. package/src/api/client.ts +0 -135
  90. package/src/api/typings.ts +0 -3
  91. package/src/auth/hooks/useAuth.ts +0 -173
  92. package/src/auth/index.ts +0 -12
  93. package/src/auth/types/auth.ts +0 -61
  94. package/src/auth/types/session.ts +0 -12
  95. package/src/config.ts +0 -31
  96. package/src/health/hooks/useHealth.ts +0 -57
  97. package/src/health/types/health.ts +0 -10
  98. package/src/live_chat/hooks/useLiveChat.ts +0 -124
  99. package/src/live_chat/hooks/useLiveChatWebSocket.ts +0 -86
  100. package/src/live_chat/index.ts +0 -15
  101. package/src/live_chat/types/live_chat.ts +0 -48
  102. package/src/permissions/hooks/usePermissions.ts +0 -196
  103. package/src/permissions/types/permission.ts +0 -27
  104. package/src/roles/hooks/useRoles.ts +0 -167
  105. package/src/roles/types/role.ts +0 -28
  106. package/src/ticket/hooks/useTickets.ts +0 -89
  107. package/src/ticket/types/ticket.ts +0 -88
  108. package/src/users/hooks/useUsers.ts +0 -150
  109. package/src/users/index.ts +0 -16
  110. package/src/users/types/user.ts +0 -36
  111. package/tsconfig.json +0 -29
  112. package/tsup.config.ts +0 -12
  113. /package/{src/health/index.ts → dist/health/index.js} +0 -0
  114. /package/{src/permissions/index.ts → dist/permissions/index.js} +0 -0
  115. /package/{src/permissions/types/index.ts → dist/permissions/types/index.js} +0 -0
  116. /package/{src/roles/index.ts → dist/roles/index.js} +0 -0
  117. /package/{src/roles/types/index.ts → dist/roles/types/index.js} +0 -0
  118. /package/{src/ticket/index.ts → dist/ticket/index.js} +0 -0
@@ -1,17 +0,0 @@
1
- name: Notify Main Repo
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- dispatch:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Repository Dispatch
13
- uses: peter-evans/repository-dispatch@v3
14
- with:
15
- token: ${{ secrets.PAT_TOKEN }}
16
- repository: Titus-System/SyncDesk
17
- event-type: submodule_update
package/CHANGELOG.md DELETED
@@ -1,29 +0,0 @@
1
- # CHANGELOG
2
-
3
- All notable changes to this project will be documented in this file.
4
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
-
7
- ## [Unreleased]
8
-
9
- ### Added
10
-
11
- ### Changed
12
-
13
- ### Deprecated
14
-
15
- ### Removed
16
-
17
- ### Fixed
18
-
19
- ### Security
20
-
21
- ### Dev Notes
22
-
23
- ---
24
-
25
- # 0.5.0 - 2026-04-04
26
-
27
- ### Added
28
-
29
- - Get a specific client's conversations.
package/src/api/client.ts DELETED
@@ -1,135 +0,0 @@
1
- import axios, { InternalAxiosRequestConfig } from "axios";
2
- import { config, LibraryConfig } from "../config";
3
-
4
- export const apiClient = axios.create();
5
-
6
- /**
7
- * Configure the library with user-provided settings.
8
- */
9
- export const configureLibrary = (userConfig: LibraryConfig) => {
10
- // Overwrite the default internal config with the user's settings
11
- Object.assign(config, userConfig);
12
-
13
- apiClient.defaults.baseURL = config.baseURL;
14
- apiClient.defaults.timeout = config.timeout;
15
- };
16
-
17
- // INTERCEPTORS
18
-
19
- /**
20
- * Request Interceptor.
21
- * Automatically adds the access token to the Authorization header of every request if it's available.
22
- */
23
- apiClient.interceptors.request.use(
24
- async (reqConfig) => {
25
- const token = await config.getAccessToken();
26
- if (token && reqConfig.headers) {
27
- reqConfig.headers.Authorization = `Bearer ${token}`;
28
- }
29
- return reqConfig;
30
- },
31
- (error) => Promise.reject(error),
32
- );
33
-
34
- /**
35
- * Response Interceptor.
36
- */
37
- let isRefreshing = false; // Flag to prevent multiple simultaneous refresh attempts
38
- let failedQueue: Array<{
39
- // Queue to hold requests that come in while we're refreshing tokens
40
- resolve: (token: string) => void;
41
- reject: (error: any) => void;
42
- }> = [];
43
- /** Processes the queue of failed requests after token refresh. */
44
- const processQueue = (error: any, token: string | null = null) => {
45
- failedQueue.forEach((promise) => {
46
- if (error) {
47
- promise.reject(error);
48
- } else {
49
- promise.resolve(token as string);
50
- }
51
- });
52
- failedQueue = [];
53
- };
54
-
55
- /**
56
- * This interceptor watches for 401 responses. If it sees one, it tries to get a new access token using
57
- * the refresh token.
58
- *
59
- * Meanwhile, it queues up any new requests that also fail with 401, and once it gets a new token,
60
- * it retries all the failed requests with the new token. If the refresh token is also expired/invalid,
61
- * it calls the onUnauthorized callback to let the app know they need to log in again.
62
- */
63
- apiClient.interceptors.response.use(
64
- (response) => response, // success
65
- async (error) => {
66
- const originalRequest = error.config as InternalAxiosRequestConfig & {
67
- _retry?: boolean;
68
- };
69
-
70
- // if 401 and not retried
71
- if (error.response?.status === 401 && !originalRequest._retry) {
72
- if (
73
- originalRequest.url?.includes("/refresh") ||
74
- originalRequest.url?.includes("/login")
75
- ) {
76
- config.onUnauthorized();
77
- return Promise.reject(error);
78
- }
79
-
80
- // If another request is currently refreshing the token, pause this request and add to queue
81
- if (isRefreshing) {
82
- return (
83
- new Promise((resolve, reject) => {
84
- failedQueue.push({ resolve, reject });
85
- })
86
- .then((token) => {
87
- // on success, add the new token to the request header and return the client
88
- originalRequest.headers.Authorization = `Bearer ${token}`;
89
- return apiClient(originalRequest);
90
- })
91
- // on error, reject the request
92
- .catch((err) => Promise.reject(err))
93
- );
94
- }
95
-
96
- // Mark that we are starting the refresh process
97
- originalRequest._retry = true;
98
- isRefreshing = true;
99
-
100
- try {
101
- const refreshToken = await config.getRefreshToken();
102
-
103
- if (!refreshToken) {
104
- throw new Error("No refresh token available.");
105
- }
106
-
107
- // Do a standard axios call to get the new token, so the interceptors are not called again.
108
- const refreshResponse = await axios.post(`${config.baseURL}/refresh`, {
109
- refresh_token: refreshToken,
110
- });
111
-
112
- const newAccessToken = refreshResponse.data.data.access_token;
113
- const newRefreshToken = refreshResponse.data.data.refresh_token;
114
-
115
- await config.onTokensRefreshed(newAccessToken, newRefreshToken);
116
-
117
- // Resume all the other paused requests with the new token
118
- processQueue(null, newAccessToken);
119
-
120
- // Retry the original request that failed
121
- originalRequest.headers.Authorization = `Bearer ${newAccessToken}`;
122
- return apiClient(originalRequest);
123
- } catch (refreshError) {
124
- // If the refresh token is completely expired, kill the queue and log them out
125
- processQueue(refreshError, null);
126
- config.onUnauthorized();
127
- return Promise.reject(refreshError);
128
- } finally {
129
- isRefreshing = false;
130
- }
131
- }
132
-
133
- return Promise.reject(error);
134
- },
135
- );
@@ -1,3 +0,0 @@
1
- export interface ApiResponse<T> {
2
- data: T;
3
- }
@@ -1,173 +0,0 @@
1
- import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
- import { apiClient, ApiResponse } from "../../api";
3
- import {
4
- AdminRegisterUserRequest,
5
- ChangePasswordRequest,
6
- ForgotPasswordRequest,
7
- ForgotPasswordResponse,
8
- LoginResponse,
9
- RegisterUserRequest,
10
- ResetPasswordRequest,
11
- UserCreatedResponse,
12
- UserLoginRequest,
13
- UserWithRoles,
14
- } from "../types/auth";
15
- import { User } from "../../users/types/user";
16
-
17
- const PATH = "auth";
18
-
19
- /**
20
- * Get the currently authenticated user's profile.
21
- * @returns {UseQueryResult<UserWithRoles, Error>} The query result.
22
- */
23
- export const useGetMe = () => {
24
- return useQuery({
25
- queryKey: ["me"],
26
- queryFn: async (): Promise<UserWithRoles> => {
27
- const response = await apiClient.get<ApiResponse<UserWithRoles>>(
28
- `${PATH}/me`,
29
- );
30
-
31
- return response.data.data;
32
- },
33
- // if the user isn't logged in (401)
34
- retry: false,
35
- });
36
- };
37
-
38
- /**
39
- * Log in a user.
40
- *
41
- * Refresh tokens are handled automatically using Interceptors.
42
- * @param {UserLoginRequest} credentials The user login credentials.
43
- * @returns {UseMutationResult<LoginResponse, Error, UserLoginRequest>} The mutation result.
44
- */
45
- export const useLogin = () => {
46
- const queryClient = useQueryClient();
47
-
48
- return useMutation({
49
- mutationFn: async (
50
- credentials: UserLoginRequest,
51
- ): Promise<LoginResponse> => {
52
- const response = await apiClient.post<ApiResponse<LoginResponse>>(
53
- `${PATH}/login`,
54
- credentials,
55
- );
56
- return response.data.data;
57
- },
58
- onSuccess: () => {
59
- // After a successful login, fetch the new user's profile
60
- queryClient.invalidateQueries({ queryKey: ["me"] });
61
- },
62
- });
63
- };
64
-
65
- /**
66
- * Register a new user.
67
- * @param {RegisterUserRequest} userData The user registration details.
68
- * @returns {UseMutationResult<UserCreatedResponse, Error, RegisterUserRequest>} The mutation result.
69
- */
70
- export const useRegister = () => {
71
- const queryClient = useQueryClient();
72
-
73
- return useMutation({
74
- mutationFn: async (
75
- userData: RegisterUserRequest,
76
- ): Promise<UserCreatedResponse> => {
77
- const response = await apiClient.post<ApiResponse<UserCreatedResponse>>(
78
- `${PATH}/register`,
79
- userData,
80
- );
81
- return response.data.data;
82
- },
83
- onSuccess: () => {
84
- // Registration also logs them in (returns tokens), so fetch their profile
85
- queryClient.invalidateQueries({ queryKey: ["me"] });
86
- },
87
- });
88
- };
89
-
90
- /**
91
- * Log out the current user.
92
- * @returns {UseMutationResult<void, Error, void>} The mutation result.
93
- */
94
- export const useLogout = () => {
95
- const queryClient = useQueryClient();
96
-
97
- return useMutation({
98
- mutationFn: async (): Promise<void> => {
99
- await apiClient.post(`${PATH}/logout`);
100
- },
101
- onSuccess: () => {
102
- // clear cache
103
- queryClient.setQueryData(["me"], null);
104
- queryClient.clear();
105
- },
106
- });
107
- };
108
-
109
- /**
110
- * Register a new user as admin.
111
- * @param {AdminRegisterUserRequest} userData The admin user registration details.
112
- * @returns {UseMutationResult<User, Error, AdminRegisterUserRequest>} The mutation result.
113
- */
114
- export const useAdminRegister = () => {
115
- const queryClient = useQueryClient();
116
-
117
- return useMutation({
118
- mutationFn: async (userData: AdminRegisterUserRequest): Promise<User> => {
119
- const response = await apiClient.post<ApiResponse<User>>(
120
- `${PATH}/admin/register`,
121
- userData,
122
- );
123
- return response.data.data;
124
- },
125
- onSuccess: () => {
126
- queryClient.invalidateQueries({ queryKey: ["users"] });
127
- },
128
- });
129
- };
130
-
131
- /**
132
- * Change the current user's password.
133
- * @param {ChangePasswordRequest} data The password change request details.
134
- * @returns {UseMutationResult<void, Error, ChangePasswordRequest>} The mutation result.
135
- */
136
- export const useChangePassword = () => {
137
- return useMutation({
138
- mutationFn: async (data: ChangePasswordRequest): Promise<void> => {
139
- await apiClient.post(`${PATH}/change-password`, data);
140
- },
141
- });
142
- };
143
-
144
- /**
145
- * Request a password reset.
146
- * @param {ForgotPasswordRequest} data The forgot password request details.
147
- * @returns {UseMutationResult<ForgotPasswordResponse, Error, ForgotPasswordRequest>} The mutation result.
148
- */
149
- export const useForgotPassword = () => {
150
- return useMutation({
151
- mutationFn: async (
152
- data: ForgotPasswordRequest,
153
- ): Promise<ForgotPasswordResponse> => {
154
- const response = await apiClient.post<
155
- ApiResponse<ForgotPasswordResponse>
156
- >(`${PATH}/forgot-password`, data);
157
- return response.data.data;
158
- },
159
- });
160
- };
161
-
162
- /**
163
- * Reset the current user's password using a valid reset token.
164
- * @param {ResetPasswordRequest} data The reset password request details.
165
- * @returns {UseMutationResult<void, Error, ResetPasswordRequest>} The mutation result.
166
- */
167
- export const useResetPassword = () => {
168
- return useMutation({
169
- mutationFn: async (data: ResetPasswordRequest): Promise<void> => {
170
- await apiClient.post(`${PATH}/reset-password`, data);
171
- },
172
- });
173
- };
package/src/auth/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export { useGetMe, useLogin, useRegister, useLogout } from "./hooks/useAuth";
2
-
3
- export type {
4
- OAuthProvider,
5
- LoginResponse,
6
- UserCreatedResponse,
7
- UserLoginRequest,
8
- RegisterUserRequest,
9
- UserWithRoles,
10
- } from "./types/auth";
11
-
12
- export type { Status, Session } from "./types/session";
@@ -1,61 +0,0 @@
1
- export type OAuthProvider = "local" | "google" | "microsoft";
2
-
3
- export interface LoginResponse {
4
- access_token: string;
5
- refresh_token: string;
6
- must_change_password?: boolean;
7
- must_accept_terms?: boolean;
8
- }
9
-
10
- export interface UserCreatedResponse {
11
- id: string;
12
- email: string;
13
- username: string;
14
- access_token: string;
15
- refresh_token: string;
16
- }
17
-
18
- export interface UserLoginRequest {
19
- email: string;
20
- password: string;
21
- }
22
-
23
- export interface RegisterUserRequest {
24
- email: string;
25
- name?: string;
26
- username?: string;
27
- password: string;
28
- }
29
-
30
- export interface AdminRegisterUserRequest {
31
- email: string;
32
- name?: string | null;
33
- role_ids?: number[];
34
- }
35
-
36
- export interface ChangePasswordRequest {
37
- current_password: string;
38
- new_password: string;
39
- }
40
-
41
- export interface ForgotPasswordRequest {
42
- email: string;
43
- }
44
-
45
- export interface ResetPasswordRequest {
46
- token: string;
47
- new_password: string;
48
- }
49
-
50
- export interface ForgotPasswordResponse {
51
- message: string;
52
- }
53
-
54
- // I am making a safe assumption for your /me route based on "user_with_roles"
55
- export interface UserWithRoles {
56
- id: string;
57
- email: string;
58
- username: string;
59
- name?: string | null;
60
- roles: string[];
61
- }
@@ -1,12 +0,0 @@
1
- export type Status = "active" | "expired" | "invalid" | "revoked";
2
-
3
- export interface Session {
4
- id: string;
5
- user_id: string;
6
- refresh_token_hash: string;
7
- status: Status;
8
- device_info: Record<string, unknown>;
9
- expires_at: Date | string;
10
- last_used_at: Date | string;
11
- revoked_at: Date | string;
12
- }
package/src/config.ts DELETED
@@ -1,31 +0,0 @@
1
- export interface LibraryConfig {
2
- /** API URL */
3
- baseURL: string;
4
- timeout?: number;
5
-
6
- /* Get current access token */
7
- getAccessToken: () => string | null | Promise<string | null>;
8
-
9
- /** Get the refresh token when it needs a new one */
10
- getRefreshToken: () => string | null | Promise<string | null>;
11
-
12
- /** Callback fired when the library successfully gets new tokens from the backend */
13
- onTokensRefreshed: (
14
- accessToken: string,
15
- refreshToken: string,
16
- ) => void | Promise<void>;
17
-
18
- /** Fired if the user is not authenticated and refresh token fails. */
19
- onUnauthorized: () => void;
20
- }
21
-
22
- export const config: Required<LibraryConfig> = {
23
- baseURL: "",
24
- timeout: 10000,
25
- getAccessToken: () => null,
26
- getRefreshToken: () => null,
27
- onTokensRefreshed: () => {},
28
- onUnauthorized: () => {
29
- console.warn("Unauthorized error caught. No handler provided.");
30
- },
31
- };
@@ -1,57 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import { apiClient, ApiResponse } from "../../api";
3
- import type {
4
- PingResponse,
5
- HealthResponse,
6
- ReadyResponse,
7
- } from "../types/health";
8
-
9
- const PATH = "";
10
-
11
- /**
12
- * Ping the server to check for basic connectivity.
13
- * @returns {UseQueryResult<PingResponse, Error>} The result.
14
- */
15
- export const usePing = () => {
16
- return useQuery({
17
- queryKey: ["health", "ping"],
18
- queryFn: async (): Promise<PingResponse> => {
19
- const response = await apiClient.get<ApiResponse<PingResponse>>(
20
- `${PATH}/ping`,
21
- );
22
- return response.data.data;
23
- },
24
- });
25
- };
26
-
27
- /**
28
- * Check the detailed health of the server and its dependencies (e.g. databases).
29
- * @returns {UseQueryResult<HealthResponse, Error>} The result.
30
- */
31
- export const useHealth = () => {
32
- return useQuery({
33
- queryKey: ["health", "status"],
34
- queryFn: async (): Promise<HealthResponse> => {
35
- const response = await apiClient.get<ApiResponse<HealthResponse>>(
36
- `${PATH}/health`,
37
- );
38
- return response.data.data;
39
- },
40
- });
41
- };
42
-
43
- /**
44
- * Check if the server is ready to accept traffic.
45
- * @returns {UseQueryResult<ReadyResponse, Error>} The result.
46
- */
47
- export const useReady = () => {
48
- return useQuery({
49
- queryKey: ["health", "ready"],
50
- queryFn: async (): Promise<ReadyResponse> => {
51
- const response = await apiClient.get<ApiResponse<ReadyResponse>>(
52
- `${PATH}/ready`,
53
- );
54
- return response.data.data;
55
- },
56
- });
57
- };
@@ -1,10 +0,0 @@
1
- export interface PingResponse {
2
- message: string;
3
- }
4
-
5
- export interface HealthResponse {
6
- postgres_status: "connected" | "degraded";
7
- mongo_status: "connected" | "degraded";
8
- }
9
-
10
- export interface ReadyResponse {}
@@ -1,124 +0,0 @@
1
- import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
- import { apiClient, ApiResponse } from "../../api";
3
- import {
4
- Conversation,
5
- CreateConversationDTO,
6
- PaginatedMessages,
7
- } from "../types/live_chat";
8
-
9
- const PATH = "/conversations";
10
-
11
- /**
12
- * Get all conversations of a ticket.
13
- * @param {string} ticket_id ticket_id parameter.
14
- * @returns {UseQueryResult<Conversation[]>} The query result.
15
- */
16
- export const useGetConversations = (ticket_id: string) => {
17
- return useQuery({
18
- queryKey: ["conversations", "ticket", ticket_id],
19
- queryFn: async (): Promise<Conversation[]> => {
20
- const response = await apiClient.get<ApiResponse<Conversation[]>>(
21
- `${PATH}/ticket/${ticket_id}`,
22
- );
23
- return response.data.data;
24
- },
25
- enabled: !!ticket_id,
26
- });
27
- };
28
-
29
- /**
30
- * Get a specific client's conversations.
31
- * @param {string} client_id client_id parameter.
32
- * @returns {UseQueryResult<Conversation[]>} The query result.
33
- */
34
- export const useGetClientConversations = (client_id: string) => {
35
- return useQuery({
36
- queryKey: ["conversations", "client", client_id],
37
- queryFn: async (): Promise<Conversation[]> => {
38
- const response = await apiClient.get<ApiResponse<Conversation[]>>(
39
- `${PATH}/client/${client_id}`,
40
- );
41
- return response.data.data;
42
- },
43
- enabled: !!client_id,
44
- });
45
- };
46
-
47
- /**
48
- * Get ticket messages with pagination.
49
- * @param {string} ticket_id ticket_id parameter.
50
- * @param {number} page page parameter.
51
- * @param {number} limit limit parameter.
52
- * @returns {UseQueryResult<PaginatedMessages>} The query result.
53
- */
54
- export const useGetPaginatedMessages = (
55
- ticket_id: string,
56
- page = 1,
57
- limit = 10,
58
- ) => {
59
- return useQuery({
60
- queryKey: [
61
- "conversations",
62
- "ticket",
63
- ticket_id,
64
- "messages",
65
- { page, limit },
66
- ],
67
- queryFn: async (): Promise<PaginatedMessages> => {
68
- const response = await apiClient.get<ApiResponse<PaginatedMessages>>(
69
- `${PATH}/ticket/${ticket_id}/messages`,
70
- { params: { page, limit } },
71
- );
72
- return response.data.data;
73
- },
74
- enabled: !!ticket_id,
75
- });
76
- };
77
-
78
- /**
79
- * Create a new conversation.
80
- * @param {CreateConversationDTO} dto The conversation creation details.
81
- * @returns {UseMutationResult<Conversation, Error, CreateConversationDTO>} The mutation result.
82
- */
83
- export const useCreateConversation = () => {
84
- const queryClient = useQueryClient();
85
-
86
- return useMutation({
87
- mutationFn: async (dto: CreateConversationDTO): Promise<Conversation> => {
88
- const response = await apiClient.post<ApiResponse<Conversation>>(
89
- PATH,
90
- dto,
91
- );
92
- return response.data.data;
93
- },
94
- onSuccess: (_, variables) => {
95
- queryClient.invalidateQueries({
96
- queryKey: ["conversations", "ticket", variables.ticket_id],
97
- });
98
- },
99
- });
100
- };
101
-
102
- /**
103
- * Assign an agent to a conversation.
104
- * @param {{ chat_id: string; agent_id: string }} params The chat ID and agent ID payload.
105
- * @returns {UseMutationResult<void, Error, { chat_id: string; agent_id: string }>} The mutation result.
106
- */
107
- export const useSetConversationAgent = () => {
108
- const queryClient = useQueryClient();
109
-
110
- return useMutation({
111
- mutationFn: async ({
112
- chat_id,
113
- agent_id,
114
- }: {
115
- chat_id: string;
116
- agent_id: string;
117
- }): Promise<void> => {
118
- await apiClient.patch(`${PATH}/${chat_id}/set-agent/${agent_id}`);
119
- },
120
- onSuccess: () => {
121
- queryClient.invalidateQueries({ queryKey: ["conversations"] });
122
- },
123
- });
124
- };