@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.
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 +5 -2
  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
@@ -0,0 +1,91 @@
1
+ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
+ import { apiClient } from "../../api";
3
+ const PATH = "/conversations";
4
+ /**
5
+ * Get all conversations of a ticket.
6
+ * @param {string} ticket_id ticket_id parameter.
7
+ * @returns {UseQueryResult<Conversation[]>} The query result.
8
+ */
9
+ export const useGetConversations = (ticket_id) => {
10
+ return useQuery({
11
+ queryKey: ["conversations", "ticket", ticket_id],
12
+ queryFn: async () => {
13
+ const response = await apiClient.get(`${PATH}/ticket/${ticket_id}`);
14
+ return response.data.data;
15
+ },
16
+ enabled: !!ticket_id,
17
+ });
18
+ };
19
+ /**
20
+ * Get a specific client's conversations.
21
+ * @param {string} client_id client_id parameter.
22
+ * @returns {UseQueryResult<Conversation[]>} The query result.
23
+ */
24
+ export const useGetClientConversations = (client_id) => {
25
+ return useQuery({
26
+ queryKey: ["conversations", "client", client_id],
27
+ queryFn: async () => {
28
+ const response = await apiClient.get(`${PATH}/client/${client_id}`);
29
+ return response.data.data;
30
+ },
31
+ enabled: !!client_id,
32
+ });
33
+ };
34
+ /**
35
+ * Get ticket messages with pagination.
36
+ * @param {string} ticket_id ticket_id parameter.
37
+ * @param {number} page page parameter.
38
+ * @param {number} limit limit parameter.
39
+ * @returns {UseQueryResult<PaginatedMessages>} The query result.
40
+ */
41
+ export const useGetPaginatedMessages = (ticket_id, page = 1, limit = 10) => {
42
+ return useQuery({
43
+ queryKey: [
44
+ "conversations",
45
+ "ticket",
46
+ ticket_id,
47
+ "messages",
48
+ { page, limit },
49
+ ],
50
+ queryFn: async () => {
51
+ const response = await apiClient.get(`${PATH}/ticket/${ticket_id}/messages`, { params: { page, limit } });
52
+ return response.data.data;
53
+ },
54
+ enabled: !!ticket_id,
55
+ });
56
+ };
57
+ /**
58
+ * Create a new conversation.
59
+ * @param {CreateConversationDTO} dto The conversation creation details.
60
+ * @returns {UseMutationResult<Conversation, Error, CreateConversationDTO>} The mutation result.
61
+ */
62
+ export const useCreateConversation = () => {
63
+ const queryClient = useQueryClient();
64
+ return useMutation({
65
+ mutationFn: async (dto) => {
66
+ const response = await apiClient.post(PATH, dto);
67
+ return response.data.data;
68
+ },
69
+ onSuccess: (_, variables) => {
70
+ queryClient.invalidateQueries({
71
+ queryKey: ["conversations", "ticket", variables.ticket_id],
72
+ });
73
+ },
74
+ });
75
+ };
76
+ /**
77
+ * Assign an agent to a conversation.
78
+ * @param {{ chat_id: string; agent_id: string }} params The chat ID and agent ID payload.
79
+ * @returns {UseMutationResult<void, Error, { chat_id: string; agent_id: string }>} The mutation result.
80
+ */
81
+ export const useSetConversationAgent = () => {
82
+ const queryClient = useQueryClient();
83
+ return useMutation({
84
+ mutationFn: async ({ chat_id, agent_id, }) => {
85
+ await apiClient.patch(`${PATH}/${chat_id}/set-agent/${agent_id}`);
86
+ },
87
+ onSuccess: () => {
88
+ queryClient.invalidateQueries({ queryKey: ["conversations"] });
89
+ },
90
+ });
91
+ };
@@ -0,0 +1,11 @@
1
+ import { ReadyState } from "react-use-websocket";
2
+ import type { ChatMessage, SendMessagePayload } from "../types/live_chat";
3
+ import type { ApiResponse } from "../../api";
4
+ export declare function useLiveChatWebSocket(chatId: string | null | undefined): {
5
+ sendMessage: (payload: SendMessagePayload) => void;
6
+ lastMessage: ChatMessage;
7
+ rawLastMessage: ApiResponse<ChatMessage>;
8
+ connectionStatus: string;
9
+ readyState: ReadyState;
10
+ };
11
+ //# sourceMappingURL=useLiveChatWebSocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveChatWebSocket.d.ts","sourceRoot":"","sources":["../../../src/live_chat/hooks/useLiveChatWebSocket.ts"],"names":[],"mappings":"AACA,OAAqB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;2BAkExD,kBAAkB;;;;;EAa/B"}
@@ -0,0 +1,68 @@
1
+ import { useEffect, useState, useCallback } from "react";
2
+ import useWebSocket, { ReadyState } from "react-use-websocket";
3
+ import { config } from "../../config";
4
+ export function useLiveChatWebSocket(chatId) {
5
+ const [token, setToken] = useState(null);
6
+ // We need the token resolved before connecting to WebSocket
7
+ useEffect(() => {
8
+ if (!chatId)
9
+ return;
10
+ const fetchToken = async () => {
11
+ const t = await config.getAccessToken();
12
+ setToken(t);
13
+ };
14
+ fetchToken();
15
+ }, [chatId]);
16
+ // Construct WebSocket URL from the configured baseURL
17
+ const wsUrl = () => {
18
+ if (!config.baseURL || !chatId || !token)
19
+ return null;
20
+ try {
21
+ const url = new URL(config.baseURL);
22
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
23
+ url.pathname = `${url.pathname.replace(/\/$/, "")}/live_chat/room/${chatId}`;
24
+ return url.toString();
25
+ }
26
+ catch {
27
+ // If baseURL is relative (e.g. "/api"), use window location
28
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
29
+ const host = window.location.host;
30
+ return `${protocol}//${host}${config.baseURL.replace(/\/$/, "")}/live_chat/room/${chatId}`;
31
+ }
32
+ };
33
+ const finalUrl = wsUrl();
34
+ const { sendMessage, lastJsonMessage, readyState } = useWebSocket(finalUrl, {
35
+ // Using token as a subprotocol to pass it due to WebSocket standard not allowing custom headers in browsers.
36
+ // E.g. Sec-WebSocket-Protocol: access_token, <token>
37
+ protocols: token ? ["access_token", token] : [],
38
+ shouldReconnect: (closeEvent) => {
39
+ // Do not reconnect on unauthorized or permission denied errors
40
+ if (closeEvent.code === 1008 ||
41
+ closeEvent.code === 403 ||
42
+ closeEvent.code === 1011)
43
+ return false;
44
+ return true;
45
+ },
46
+ reconnectAttempts: 10,
47
+ reconnectInterval: 3000,
48
+ },
49
+ // Only connect if we have a valid URL (meaning chat id and token exist)
50
+ !!finalUrl);
51
+ const connectionStatus = {
52
+ [ReadyState.CONNECTING]: "Connecting",
53
+ [ReadyState.OPEN]: "Open",
54
+ [ReadyState.CLOSING]: "Closing",
55
+ [ReadyState.CLOSED]: "Closed",
56
+ [ReadyState.UNINSTANTIATED]: "Uninstantiated",
57
+ }[readyState];
58
+ const sendPayload = useCallback((payload) => {
59
+ sendMessage(JSON.stringify(payload));
60
+ }, [sendMessage]);
61
+ return {
62
+ sendMessage: sendPayload,
63
+ lastMessage: lastJsonMessage?.data || null,
64
+ rawLastMessage: lastJsonMessage,
65
+ connectionStatus,
66
+ readyState,
67
+ };
68
+ }
@@ -0,0 +1,4 @@
1
+ export { useGetConversations, useGetPaginatedMessages, useCreateConversation, useSetConversationAgent, } from "./hooks/useLiveChat";
2
+ export { useLiveChatWebSocket } from "./hooks/useLiveChatWebSocket";
3
+ export type { ChatMessage, Conversation, CreateConversationDTO, PaginatedMessages, } from "./types/live_chat";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/live_chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,YAAY,EACV,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { useGetConversations, useGetPaginatedMessages, useCreateConversation, useSetConversationAgent, } from "./hooks/useLiveChat";
2
+ export { useLiveChatWebSocket } from "./hooks/useLiveChatWebSocket";
@@ -0,0 +1,45 @@
1
+ export interface SendMessagePayload {
2
+ type: "text" | "file";
3
+ content: string;
4
+ mime_type?: string | null;
5
+ filename?: string | null;
6
+ responding_to?: string | null;
7
+ }
8
+ export interface ChatMessage {
9
+ id: string;
10
+ conversation_id: string;
11
+ sender_id: string | "System";
12
+ timestamp: string;
13
+ type: "text" | "file";
14
+ content: string;
15
+ mime_type?: string | null;
16
+ filename?: string | null;
17
+ responding_to?: string | null;
18
+ }
19
+ export interface Conversation {
20
+ _id: string;
21
+ ticket_id: string;
22
+ agent_id?: string | null;
23
+ client_id: string;
24
+ sequential_index: number;
25
+ parent_id?: string | null;
26
+ children_ids: string[];
27
+ started_at: string;
28
+ finished_at?: string | null;
29
+ messages: ChatMessage[];
30
+ }
31
+ export interface CreateConversationDTO {
32
+ ticket_id: string;
33
+ agent_id?: string | null;
34
+ client_id: string;
35
+ sequential_index?: number;
36
+ parent_id?: string | null;
37
+ }
38
+ export interface PaginatedMessages {
39
+ messages: ChatMessage[];
40
+ total: number;
41
+ page: number;
42
+ limit: number;
43
+ has_next: boolean;
44
+ }
45
+ //# sourceMappingURL=live_chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live_chat.d.ts","sourceRoot":"","sources":["../../../src/live_chat/types/live_chat.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ import type { Permission, CreatePermissionDTO, ReplacePermissionDTO, UpdatePermissionDTO, AddPermissionRolesDTO } from "../types/permission";
2
+ /**
3
+ * List all permissions.
4
+ * @returns {UseQueryResult<Permission[]>} The query result.
5
+ */
6
+ export declare function usePermissions(): import("@tanstack/react-query").UseQueryResult<Permission[], Error>;
7
+ /**
8
+ * Get a permission by ID.
9
+ * @param {number} id id parameter.
10
+ * @returns {UseQueryResult<Permission>} The query result.
11
+ */
12
+ export declare function usePermission(id: number): import("@tanstack/react-query").UseQueryResult<Permission, Error>;
13
+ /**
14
+ * Create a new permission.
15
+ * @param {CreatePermissionDTO} dto DTO containing details.
16
+ * @returns {UseMutationResult<Permission, Error, CreatePermissionDTO>} The mutation result.
17
+ */
18
+ export declare function useCreatePermission(): import("@tanstack/react-query").UseMutationResult<Permission, Error, CreatePermissionDTO, unknown>;
19
+ /**
20
+ * Replace a permission by ID.
21
+ * @param {number} id ID.
22
+ * @param {ReplacePermissionDTO} dto DTO containing details.
23
+ * @returns {UseMutationResult<Permission,
24
+ Error,
25
+ { id: number; dto: ReplacePermissionDTO }>} The mutation result.
26
+ */
27
+ export declare function useReplacePermission(): import("@tanstack/react-query").UseMutationResult<Permission, Error, {
28
+ id: number;
29
+ dto: ReplacePermissionDTO;
30
+ }, unknown>;
31
+ /**
32
+ * Update a permission by ID.
33
+ * @param {number} id ID.
34
+ * @param {UpdatePermissionDTO} dto DTO containing details.
35
+ * @returns {UseMutationResult<Permission,
36
+ Error,
37
+ { id: number; dto: UpdatePermissionDTO }>} The mutation result.
38
+ */
39
+ export declare function useUpdatePermission(): import("@tanstack/react-query").UseMutationResult<Permission, Error, {
40
+ id: number;
41
+ dto: UpdatePermissionDTO;
42
+ }, unknown>;
43
+ /**
44
+ * Delete a permission by ID.
45
+ * @param {number} dto DTO containing details.
46
+ * @returns {UseMutationResult<Permission, Error, number>} The mutation result.
47
+ */
48
+ export declare function useDeletePermission(): import("@tanstack/react-query").UseMutationResult<Permission, Error, number, unknown>;
49
+ /**
50
+ * Get permission with associated roles.
51
+ *
52
+ * All roles that have this permission will be included in the
53
+ * response under a `roles` field.
54
+ *
55
+ * @param {number} id id parameter.
56
+ * @returns {UseQueryResult<Permission>} The query result.
57
+ */
58
+ export declare function usePermissionRoles(id: number): import("@tanstack/react-query").UseQueryResult<Permission, Error>;
59
+ /**
60
+ * Add a permission to a list of roles.
61
+ * @param {number} id ID.
62
+ * @param {AddPermissionRolesDTO} dto DTO containing details.
63
+ * @returns {UseMutationResult<Permission,
64
+ Error,
65
+ { id: number; dto: AddPermissionRolesDTO }>} The mutation result.
66
+ */
67
+ export declare function useAddPermissionRoles(): import("@tanstack/react-query").UseMutationResult<Permission, Error, {
68
+ id: number;
69
+ dto: AddPermissionRolesDTO;
70
+ }, unknown>;
71
+ //# sourceMappingURL=usePermissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePermissions.d.ts","sourceRoot":"","sources":["../../../src/permissions/hooks/usePermissions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAI7B;;;GAGG;AACH,wBAAgB,cAAc,wEAU7B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,qEAWvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,uGAclC;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB;QAK1B,MAAM;SAAO,oBAAoB;YAc1C;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB;QAKzB,MAAM;SAAO,mBAAmB;YAczC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,0FAclC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,qEAW5C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB;QAK3B,MAAM;SAAO,qBAAqB;YAa3C"}
@@ -0,0 +1,147 @@
1
+ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
+ import { apiClient } from "../../api";
3
+ const PATH = "/permissions";
4
+ /**
5
+ * List all permissions.
6
+ * @returns {UseQueryResult<Permission[]>} The query result.
7
+ */
8
+ export function usePermissions() {
9
+ return useQuery({
10
+ queryKey: ["permissions"],
11
+ queryFn: async () => {
12
+ const response = await apiClient.get(`${PATH}/`);
13
+ return response.data.data;
14
+ },
15
+ });
16
+ }
17
+ /**
18
+ * Get a permission by ID.
19
+ * @param {number} id id parameter.
20
+ * @returns {UseQueryResult<Permission>} The query result.
21
+ */
22
+ export function usePermission(id) {
23
+ return useQuery({
24
+ queryKey: ["permissions", id],
25
+ queryFn: async () => {
26
+ const response = await apiClient.get(`${PATH}/${id}`);
27
+ return response.data.data;
28
+ },
29
+ enabled: !!id,
30
+ });
31
+ }
32
+ /**
33
+ * Create a new permission.
34
+ * @param {CreatePermissionDTO} dto DTO containing details.
35
+ * @returns {UseMutationResult<Permission, Error, CreatePermissionDTO>} The mutation result.
36
+ */
37
+ export function useCreatePermission() {
38
+ const queryClient = useQueryClient();
39
+ return useMutation({
40
+ mutationFn: async (dto) => {
41
+ const response = await apiClient.post(`${PATH}/`, dto);
42
+ return response.data.data;
43
+ },
44
+ onSuccess: () => {
45
+ queryClient.invalidateQueries({ queryKey: ["permissions"] });
46
+ },
47
+ });
48
+ }
49
+ /**
50
+ * Replace a permission by ID.
51
+ * @param {number} id ID.
52
+ * @param {ReplacePermissionDTO} dto DTO containing details.
53
+ * @returns {UseMutationResult<Permission,
54
+ Error,
55
+ { id: number; dto: ReplacePermissionDTO }>} The mutation result.
56
+ */
57
+ export function useReplacePermission() {
58
+ const queryClient = useQueryClient();
59
+ return useMutation({
60
+ mutationFn: async ({ id, dto }) => {
61
+ const response = await apiClient.put(`${PATH}/${id}`, dto);
62
+ return response.data.data;
63
+ },
64
+ onSuccess: (_, { id }) => {
65
+ queryClient.invalidateQueries({ queryKey: ["permissions"] });
66
+ queryClient.invalidateQueries({ queryKey: ["permissions", id] });
67
+ },
68
+ });
69
+ }
70
+ /**
71
+ * Update a permission by ID.
72
+ * @param {number} id ID.
73
+ * @param {UpdatePermissionDTO} dto DTO containing details.
74
+ * @returns {UseMutationResult<Permission,
75
+ Error,
76
+ { id: number; dto: UpdatePermissionDTO }>} The mutation result.
77
+ */
78
+ export function useUpdatePermission() {
79
+ const queryClient = useQueryClient();
80
+ return useMutation({
81
+ mutationFn: async ({ id, dto }) => {
82
+ const response = await apiClient.patch(`${PATH}/${id}`, dto);
83
+ return response.data.data;
84
+ },
85
+ onSuccess: (_, { id }) => {
86
+ queryClient.invalidateQueries({ queryKey: ["permissions"] });
87
+ queryClient.invalidateQueries({ queryKey: ["permissions", id] });
88
+ },
89
+ });
90
+ }
91
+ /**
92
+ * Delete a permission by ID.
93
+ * @param {number} dto DTO containing details.
94
+ * @returns {UseMutationResult<Permission, Error, number>} The mutation result.
95
+ */
96
+ export function useDeletePermission() {
97
+ const queryClient = useQueryClient();
98
+ return useMutation({
99
+ mutationFn: async (id) => {
100
+ const response = await apiClient.delete(`${PATH}/${id}`);
101
+ return response.data.data;
102
+ },
103
+ onSuccess: (_, id) => {
104
+ queryClient.invalidateQueries({ queryKey: ["permissions"] });
105
+ queryClient.invalidateQueries({ queryKey: ["permissions", id] });
106
+ },
107
+ });
108
+ }
109
+ /**
110
+ * Get permission with associated roles.
111
+ *
112
+ * All roles that have this permission will be included in the
113
+ * response under a `roles` field.
114
+ *
115
+ * @param {number} id id parameter.
116
+ * @returns {UseQueryResult<Permission>} The query result.
117
+ */
118
+ export function usePermissionRoles(id) {
119
+ return useQuery({
120
+ queryKey: ["permissions", id, "roles"],
121
+ queryFn: async () => {
122
+ const response = await apiClient.get(`${PATH}/${id}/roles`);
123
+ return response.data.data;
124
+ },
125
+ enabled: !!id,
126
+ });
127
+ }
128
+ /**
129
+ * Add a permission to a list of roles.
130
+ * @param {number} id ID.
131
+ * @param {AddPermissionRolesDTO} dto DTO containing details.
132
+ * @returns {UseMutationResult<Permission,
133
+ Error,
134
+ { id: number; dto: AddPermissionRolesDTO }>} The mutation result.
135
+ */
136
+ export function useAddPermissionRoles() {
137
+ const queryClient = useQueryClient();
138
+ return useMutation({
139
+ mutationFn: async ({ id, dto }) => {
140
+ const response = await apiClient.post(`${PATH}/${id}/roles`, dto);
141
+ return response.data.data;
142
+ },
143
+ onSuccess: (_, { id }) => {
144
+ queryClient.invalidateQueries({ queryKey: ["permissions", id, "roles"] });
145
+ },
146
+ });
147
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./hooks/usePermissions";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/permissions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./permission";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/permissions/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Role } from "../../roles/types/role";
2
+ export interface Permission {
3
+ id: number;
4
+ name: string;
5
+ description?: string | null;
6
+ roles?: Role[];
7
+ }
8
+ export interface CreatePermissionDTO {
9
+ name: string;
10
+ description?: string | null;
11
+ }
12
+ export interface ReplacePermissionDTO {
13
+ name: string;
14
+ description?: string | null;
15
+ }
16
+ export interface UpdatePermissionDTO {
17
+ name?: string | null;
18
+ description?: string | null;
19
+ }
20
+ export interface AddPermissionRolesDTO {
21
+ ids: number[];
22
+ }
23
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../../../src/permissions/types/permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,EAAE,CAAC;CACf"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import type { Role, CreateRoleDTO, ReplaceRoleDTO, UpdateRoleDTO, AddRolePermissionsDTO } from "../types/role";
2
+ /**
3
+ * List all roles.
4
+ * @returns {UseQueryResult<Role[]>} The query result.
5
+ */
6
+ export declare function useRoles(): import("@tanstack/react-query").UseQueryResult<Role[], Error>;
7
+ /**
8
+ * Get a role by ID.
9
+ * @param {number} id id parameter.
10
+ * @returns {UseQueryResult<Role>} The query result.
11
+ */
12
+ export declare function useRole(id: number): import("@tanstack/react-query").UseQueryResult<Role, Error>;
13
+ /**
14
+ * Create a new role.
15
+ * @param {CreateRoleDTO} dto DTO containing details.
16
+ * @returns {UseMutationResult<Role, Error, CreateRoleDTO>} The mutation result.
17
+ */
18
+ export declare function useCreateRole(): import("@tanstack/react-query").UseMutationResult<Role, Error, CreateRoleDTO, unknown>;
19
+ /**
20
+ * Replace a role by ID.
21
+ * @param {number} id ID.
22
+ * @param {ReplaceRoleDTO} dto DTO containing details.
23
+ * @returns {UseMutationResult<Role, Error, { id: number; dto: ReplaceRoleDTO }>} The mutation result.
24
+ */
25
+ export declare function useReplaceRole(): import("@tanstack/react-query").UseMutationResult<Role, Error, {
26
+ id: number;
27
+ dto: ReplaceRoleDTO;
28
+ }, unknown>;
29
+ /**
30
+ * Update a role by ID.
31
+ * @param {number} id ID.
32
+ * @param {UpdateRoleDTO} dto DTO containing details.
33
+ * @returns {UseMutationResult<Role, Error, { id: number; dto: UpdateRoleDTO }>} The mutation result.
34
+ */
35
+ export declare function useUpdateRole(): import("@tanstack/react-query").UseMutationResult<Role, Error, {
36
+ id: number;
37
+ dto: UpdateRoleDTO;
38
+ }, unknown>;
39
+ /**
40
+ * Delete a role by ID.
41
+ * @param {number} dto DTO containing details.
42
+ * @returns {UseMutationResult<Role, Error, number>} The mutation result.
43
+ */
44
+ export declare function useDeleteRole(): import("@tanstack/react-query").UseMutationResult<Role, Error, number, unknown>;
45
+ /**
46
+ * Get the permissions for a role by ID.
47
+ * @param {number} id id parameter.
48
+ * @returns {UseQueryResult<Role>} The query result.
49
+ */
50
+ export declare function useRolePermissions(id: number): import("@tanstack/react-query").UseQueryResult<Role, Error>;
51
+ /**
52
+ * Add permissions to a role.
53
+ *
54
+ * @param {number} id ID.
55
+ * @param {AddRolePermissionsDTO} dto DTO containing details.
56
+ * @returns {UseMutationResult<Role, Error, { id: number; dto: AddRolePermissionsDTO }>} The mutation result.
57
+ */
58
+ export declare function useAddRolePermissions(): import("@tanstack/react-query").UseMutationResult<Role, Error, {
59
+ id: number;
60
+ dto: AddRolePermissionsDTO;
61
+ }, unknown>;
62
+ //# sourceMappingURL=useRoles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRoles.d.ts","sourceRoot":"","sources":["../../../src/roles/hooks/useRoles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,aAAa,EACb,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAIvB;;;GAGG;AACH,wBAAgB,QAAQ,kEAQvB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,+DASjC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,2FAW5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc;QAEU,MAAM;SAAO,cAAc;YAalE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa;QAEW,MAAM;SAAO,aAAa;YAajE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,oFAc5B;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,+DAW5C;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB;QAEG,MAAM;SAAO,qBAAqB;YAYzE"}