@djangocfg/ext-support 1.0.0
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/README.md +233 -0
- package/dist/chunk-AZ4LWZB7.js +2630 -0
- package/dist/hooks.cjs +2716 -0
- package/dist/hooks.d.cts +255 -0
- package/dist/hooks.d.ts +255 -0
- package/dist/hooks.js +1 -0
- package/dist/index.cjs +2693 -0
- package/dist/index.d.cts +1392 -0
- package/dist/index.d.ts +1392 -0
- package/dist/index.js +1 -0
- package/package.json +80 -0
- package/src/api/generated/ext_support/_utils/fetchers/ext_support__support.ts +642 -0
- package/src/api/generated/ext_support/_utils/fetchers/index.ts +28 -0
- package/src/api/generated/ext_support/_utils/hooks/ext_support__support.ts +237 -0
- package/src/api/generated/ext_support/_utils/hooks/index.ts +28 -0
- package/src/api/generated/ext_support/_utils/schemas/Message.schema.ts +21 -0
- package/src/api/generated/ext_support/_utils/schemas/MessageCreate.schema.ts +15 -0
- package/src/api/generated/ext_support/_utils/schemas/MessageCreateRequest.schema.ts +15 -0
- package/src/api/generated/ext_support/_utils/schemas/MessageRequest.schema.ts +15 -0
- package/src/api/generated/ext_support/_utils/schemas/PaginatedMessageList.schema.ts +24 -0
- package/src/api/generated/ext_support/_utils/schemas/PaginatedTicketList.schema.ts +24 -0
- package/src/api/generated/ext_support/_utils/schemas/PatchedMessageRequest.schema.ts +15 -0
- package/src/api/generated/ext_support/_utils/schemas/PatchedTicketRequest.schema.ts +18 -0
- package/src/api/generated/ext_support/_utils/schemas/Sender.schema.ts +21 -0
- package/src/api/generated/ext_support/_utils/schemas/Ticket.schema.ts +21 -0
- package/src/api/generated/ext_support/_utils/schemas/TicketRequest.schema.ts +18 -0
- package/src/api/generated/ext_support/_utils/schemas/index.ts +29 -0
- package/src/api/generated/ext_support/api-instance.ts +131 -0
- package/src/api/generated/ext_support/client.ts +301 -0
- package/src/api/generated/ext_support/enums.ts +45 -0
- package/src/api/generated/ext_support/errors.ts +116 -0
- package/src/api/generated/ext_support/ext_support__support/client.ts +151 -0
- package/src/api/generated/ext_support/ext_support__support/index.ts +2 -0
- package/src/api/generated/ext_support/ext_support__support/models.ts +165 -0
- package/src/api/generated/ext_support/http.ts +103 -0
- package/src/api/generated/ext_support/index.ts +273 -0
- package/src/api/generated/ext_support/logger.ts +259 -0
- package/src/api/generated/ext_support/retry.ts +175 -0
- package/src/api/generated/ext_support/schema.json +1049 -0
- package/src/api/generated/ext_support/storage.ts +161 -0
- package/src/api/generated/ext_support/validation-events.ts +133 -0
- package/src/api/index.ts +9 -0
- package/src/config.ts +20 -0
- package/src/contexts/SupportContext.tsx +250 -0
- package/src/contexts/SupportExtensionProvider.tsx +38 -0
- package/src/contexts/types.ts +26 -0
- package/src/hooks/index.ts +33 -0
- package/src/index.ts +39 -0
- package/src/layouts/SupportLayout/README.md +91 -0
- package/src/layouts/SupportLayout/SupportLayout.tsx +179 -0
- package/src/layouts/SupportLayout/components/CreateTicketDialog.tsx +155 -0
- package/src/layouts/SupportLayout/components/MessageInput.tsx +92 -0
- package/src/layouts/SupportLayout/components/MessageList.tsx +312 -0
- package/src/layouts/SupportLayout/components/TicketCard.tsx +96 -0
- package/src/layouts/SupportLayout/components/TicketList.tsx +153 -0
- package/src/layouts/SupportLayout/components/index.ts +6 -0
- package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +258 -0
- package/src/layouts/SupportLayout/context/index.ts +2 -0
- package/src/layouts/SupportLayout/events.ts +33 -0
- package/src/layouts/SupportLayout/hooks/index.ts +2 -0
- package/src/layouts/SupportLayout/hooks/useInfiniteMessages.ts +115 -0
- package/src/layouts/SupportLayout/hooks/useInfiniteTickets.ts +88 -0
- package/src/layouts/SupportLayout/index.ts +6 -0
- package/src/layouts/SupportLayout/types.ts +21 -0
- package/src/utils/logger.ts +14 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SWR Hooks for Support
|
|
5
|
+
*
|
|
6
|
+
* React hooks powered by SWR for data fetching with automatic caching,
|
|
7
|
+
* revalidation, and optimistic updates.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Query hooks (GET)
|
|
12
|
+
* const { data, error, isLoading } = useUsers({ page: 1 })
|
|
13
|
+
*
|
|
14
|
+
* // Mutation hooks (POST/PUT/PATCH/DELETE)
|
|
15
|
+
* const createUser = useCreateUser()
|
|
16
|
+
* await createUser({ name: 'John', email: 'john@example.com' })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import useSWR from 'swr'
|
|
20
|
+
import { useSWRConfig } from 'swr'
|
|
21
|
+
import * as Fetchers from '../fetchers/ext_support__support'
|
|
22
|
+
import type { API } from '../../index'
|
|
23
|
+
import type { Message } from '../schemas/Message.schema'
|
|
24
|
+
import type { MessageCreate } from '../schemas/MessageCreate.schema'
|
|
25
|
+
import type { MessageCreateRequest } from '../schemas/MessageCreateRequest.schema'
|
|
26
|
+
import type { MessageRequest } from '../schemas/MessageRequest.schema'
|
|
27
|
+
import type { PaginatedMessageList } from '../schemas/PaginatedMessageList.schema'
|
|
28
|
+
import type { PaginatedTicketList } from '../schemas/PaginatedTicketList.schema'
|
|
29
|
+
import type { PatchedMessageRequest } from '../schemas/PatchedMessageRequest.schema'
|
|
30
|
+
import type { PatchedTicketRequest } from '../schemas/PatchedTicketRequest.schema'
|
|
31
|
+
import type { Ticket } from '../schemas/Ticket.schema'
|
|
32
|
+
import type { TicketRequest } from '../schemas/TicketRequest.schema'
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* API operation
|
|
36
|
+
*
|
|
37
|
+
* @method GET
|
|
38
|
+
* @path /cfg/support/tickets/
|
|
39
|
+
*/
|
|
40
|
+
export function useSupportTicketsList(params?: { page?: number; page_size?: number }, client?: API): ReturnType<typeof useSWR<PaginatedTicketList>> {
|
|
41
|
+
return useSWR<PaginatedTicketList>(
|
|
42
|
+
params ? ['cfg-support-tickets', params] : 'cfg-support-tickets',
|
|
43
|
+
() => Fetchers.getSupportTicketsList(params, client)
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* API operation
|
|
50
|
+
*
|
|
51
|
+
* @method POST
|
|
52
|
+
* @path /cfg/support/tickets/
|
|
53
|
+
*/
|
|
54
|
+
export function useCreateSupportTicketsCreate() {
|
|
55
|
+
const { mutate } = useSWRConfig()
|
|
56
|
+
|
|
57
|
+
return async (data: TicketRequest, client?: API): Promise<Ticket> => {
|
|
58
|
+
const result = await Fetchers.createSupportTicketsCreate(data, client)
|
|
59
|
+
// Revalidate related queries
|
|
60
|
+
mutate('cfg-support-tickets')
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* API operation
|
|
68
|
+
*
|
|
69
|
+
* @method GET
|
|
70
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/
|
|
71
|
+
*/
|
|
72
|
+
export function useSupportTicketsMessagesList(ticket_uuid: string, params?: { page?: number; page_size?: number }, client?: API): ReturnType<typeof useSWR<PaginatedMessageList>> {
|
|
73
|
+
return useSWR<PaginatedMessageList>(
|
|
74
|
+
['cfg-support-tickets-messages', ticket_uuid],
|
|
75
|
+
() => Fetchers.getSupportTicketsMessagesList(ticket_uuid, params, client)
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* API operation
|
|
82
|
+
*
|
|
83
|
+
* @method POST
|
|
84
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/
|
|
85
|
+
*/
|
|
86
|
+
export function useCreateSupportTicketsMessagesCreate() {
|
|
87
|
+
const { mutate } = useSWRConfig()
|
|
88
|
+
|
|
89
|
+
return async (ticket_uuid: string, data: MessageCreateRequest, client?: API): Promise<MessageCreate> => {
|
|
90
|
+
const result = await Fetchers.createSupportTicketsMessagesCreate(ticket_uuid, data, client)
|
|
91
|
+
// Revalidate related queries
|
|
92
|
+
mutate('cfg-support-tickets-messages')
|
|
93
|
+
return result
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* API operation
|
|
100
|
+
*
|
|
101
|
+
* @method GET
|
|
102
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
|
|
103
|
+
*/
|
|
104
|
+
export function useSupportTicketsMessagesRetrieve(ticket_uuid: string, uuid: string, client?: API): ReturnType<typeof useSWR<Message>> {
|
|
105
|
+
return useSWR<Message>(
|
|
106
|
+
['cfg-support-tickets-message', ticket_uuid],
|
|
107
|
+
() => Fetchers.getSupportTicketsMessagesRetrieve(ticket_uuid, uuid, client)
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* API operation
|
|
114
|
+
*
|
|
115
|
+
* @method PUT
|
|
116
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
|
|
117
|
+
*/
|
|
118
|
+
export function useUpdateSupportTicketsMessagesUpdate() {
|
|
119
|
+
const { mutate } = useSWRConfig()
|
|
120
|
+
|
|
121
|
+
return async (ticket_uuid: string, uuid: string, data: MessageRequest, client?: API): Promise<Message> => {
|
|
122
|
+
const result = await Fetchers.updateSupportTicketsMessagesUpdate(ticket_uuid, uuid, data, client)
|
|
123
|
+
// Revalidate related queries
|
|
124
|
+
mutate('cfg-support-tickets-messages')
|
|
125
|
+
mutate('cfg-support-tickets-message')
|
|
126
|
+
return result
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* API operation
|
|
133
|
+
*
|
|
134
|
+
* @method PATCH
|
|
135
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
|
|
136
|
+
*/
|
|
137
|
+
export function usePartialUpdateSupportTicketsMessagesPartialUpdate() {
|
|
138
|
+
const { mutate } = useSWRConfig()
|
|
139
|
+
|
|
140
|
+
return async (ticket_uuid: string, uuid: string, data?: PatchedMessageRequest, client?: API): Promise<Message> => {
|
|
141
|
+
const result = await Fetchers.partialUpdateSupportTicketsMessagesPartialUpdate(ticket_uuid, uuid, data, client)
|
|
142
|
+
// Revalidate related queries
|
|
143
|
+
mutate('cfg-support-tickets-messages-partial')
|
|
144
|
+
return result
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* API operation
|
|
151
|
+
*
|
|
152
|
+
* @method DELETE
|
|
153
|
+
* @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
|
|
154
|
+
*/
|
|
155
|
+
export function useDeleteSupportTicketsMessagesDestroy() {
|
|
156
|
+
const { mutate } = useSWRConfig()
|
|
157
|
+
|
|
158
|
+
return async (ticket_uuid: string, uuid: string, client?: API): Promise<void> => {
|
|
159
|
+
const result = await Fetchers.deleteSupportTicketsMessagesDestroy(ticket_uuid, uuid, client)
|
|
160
|
+
// Revalidate related queries
|
|
161
|
+
mutate('cfg-support-tickets-messages')
|
|
162
|
+
mutate('cfg-support-tickets-message')
|
|
163
|
+
return result
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* API operation
|
|
170
|
+
*
|
|
171
|
+
* @method GET
|
|
172
|
+
* @path /cfg/support/tickets/{uuid}/
|
|
173
|
+
*/
|
|
174
|
+
export function useSupportTicketsRetrieve(uuid: string, client?: API): ReturnType<typeof useSWR<Ticket>> {
|
|
175
|
+
return useSWR<Ticket>(
|
|
176
|
+
['cfg-support-ticket', uuid],
|
|
177
|
+
() => Fetchers.getSupportTicketsRetrieve(uuid, client)
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* API operation
|
|
184
|
+
*
|
|
185
|
+
* @method PUT
|
|
186
|
+
* @path /cfg/support/tickets/{uuid}/
|
|
187
|
+
*/
|
|
188
|
+
export function useUpdateSupportTicketsUpdate() {
|
|
189
|
+
const { mutate } = useSWRConfig()
|
|
190
|
+
|
|
191
|
+
return async (uuid: string, data: TicketRequest, client?: API): Promise<Ticket> => {
|
|
192
|
+
const result = await Fetchers.updateSupportTicketsUpdate(uuid, data, client)
|
|
193
|
+
// Revalidate related queries
|
|
194
|
+
mutate('cfg-support-tickets')
|
|
195
|
+
mutate('cfg-support-ticket')
|
|
196
|
+
return result
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* API operation
|
|
203
|
+
*
|
|
204
|
+
* @method PATCH
|
|
205
|
+
* @path /cfg/support/tickets/{uuid}/
|
|
206
|
+
*/
|
|
207
|
+
export function usePartialUpdateSupportTicketsPartialUpdate() {
|
|
208
|
+
const { mutate } = useSWRConfig()
|
|
209
|
+
|
|
210
|
+
return async (uuid: string, data?: PatchedTicketRequest, client?: API): Promise<Ticket> => {
|
|
211
|
+
const result = await Fetchers.partialUpdateSupportTicketsPartialUpdate(uuid, data, client)
|
|
212
|
+
// Revalidate related queries
|
|
213
|
+
mutate('cfg-support-tickets-partial')
|
|
214
|
+
return result
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* API operation
|
|
221
|
+
*
|
|
222
|
+
* @method DELETE
|
|
223
|
+
* @path /cfg/support/tickets/{uuid}/
|
|
224
|
+
*/
|
|
225
|
+
export function useDeleteSupportTicketsDestroy() {
|
|
226
|
+
const { mutate } = useSWRConfig()
|
|
227
|
+
|
|
228
|
+
return async (uuid: string, client?: API): Promise<void> => {
|
|
229
|
+
const result = await Fetchers.deleteSupportTicketsDestroy(uuid, client)
|
|
230
|
+
// Revalidate related queries
|
|
231
|
+
mutate('cfg-support-tickets')
|
|
232
|
+
mutate('cfg-support-ticket')
|
|
233
|
+
return result
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SWR Hooks - React data fetching hooks
|
|
5
|
+
*
|
|
6
|
+
* Auto-generated from OpenAPI specification.
|
|
7
|
+
* Powered by SWR for automatic caching and revalidation.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Automatic caching and deduplication
|
|
11
|
+
* - Revalidation on focus/reconnect
|
|
12
|
+
* - Optimistic updates
|
|
13
|
+
* - Type-safe parameters and responses
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as hooks from './hooks'
|
|
18
|
+
*
|
|
19
|
+
* // Query hooks (GET)
|
|
20
|
+
* const { data, error, isLoading } = hooks.useUsers({ page: 1 })
|
|
21
|
+
*
|
|
22
|
+
* // Mutation hooks (POST/PUT/PATCH/DELETE)
|
|
23
|
+
* const createUser = hooks.useCreateUser()
|
|
24
|
+
* await createUser({ name: 'John' })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export * from './ext_support__support'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for Message
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import { SenderSchema } from './Sender.schema'
|
|
8
|
+
|
|
9
|
+
export const MessageSchema = z.object({
|
|
10
|
+
uuid: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
|
|
11
|
+
ticket: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
|
|
12
|
+
sender: SenderSchema,
|
|
13
|
+
is_from_author: z.boolean(),
|
|
14
|
+
text: z.string(),
|
|
15
|
+
created_at: z.iso.datetime(),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Infer TypeScript type from Zod schema
|
|
20
|
+
*/
|
|
21
|
+
export type Message = z.infer<typeof MessageSchema>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for MessageCreate
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export const MessageCreateSchema = z.object({
|
|
9
|
+
text: z.string(),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Infer TypeScript type from Zod schema
|
|
14
|
+
*/
|
|
15
|
+
export type MessageCreate = z.infer<typeof MessageCreateSchema>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for MessageCreateRequest
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export const MessageCreateRequestSchema = z.object({
|
|
9
|
+
text: z.string().min(1),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Infer TypeScript type from Zod schema
|
|
14
|
+
*/
|
|
15
|
+
export type MessageCreateRequest = z.infer<typeof MessageCreateRequestSchema>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for MessageRequest
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export const MessageRequestSchema = z.object({
|
|
9
|
+
text: z.string().min(1),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Infer TypeScript type from Zod schema
|
|
14
|
+
*/
|
|
15
|
+
export type MessageRequest = z.infer<typeof MessageRequestSchema>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for PaginatedMessageList
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import { MessageSchema } from './Message.schema'
|
|
8
|
+
|
|
9
|
+
export const PaginatedMessageListSchema = z.object({
|
|
10
|
+
count: z.int(),
|
|
11
|
+
page: z.int(),
|
|
12
|
+
pages: z.int(),
|
|
13
|
+
page_size: z.int(),
|
|
14
|
+
has_next: z.boolean(),
|
|
15
|
+
has_previous: z.boolean(),
|
|
16
|
+
next_page: z.int().nullable().optional(),
|
|
17
|
+
previous_page: z.int().nullable().optional(),
|
|
18
|
+
results: z.array(MessageSchema),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Infer TypeScript type from Zod schema
|
|
23
|
+
*/
|
|
24
|
+
export type PaginatedMessageList = z.infer<typeof PaginatedMessageListSchema>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for PaginatedTicketList
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import { TicketSchema } from './Ticket.schema'
|
|
8
|
+
|
|
9
|
+
export const PaginatedTicketListSchema = z.object({
|
|
10
|
+
count: z.int(),
|
|
11
|
+
page: z.int(),
|
|
12
|
+
pages: z.int(),
|
|
13
|
+
page_size: z.int(),
|
|
14
|
+
has_next: z.boolean(),
|
|
15
|
+
has_previous: z.boolean(),
|
|
16
|
+
next_page: z.int().nullable().optional(),
|
|
17
|
+
previous_page: z.int().nullable().optional(),
|
|
18
|
+
results: z.array(TicketSchema),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Infer TypeScript type from Zod schema
|
|
23
|
+
*/
|
|
24
|
+
export type PaginatedTicketList = z.infer<typeof PaginatedTicketListSchema>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for PatchedMessageRequest
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export const PatchedMessageRequestSchema = z.object({
|
|
9
|
+
text: z.string().min(1).optional(),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Infer TypeScript type from Zod schema
|
|
14
|
+
*/
|
|
15
|
+
export type PatchedMessageRequest = z.infer<typeof PatchedMessageRequestSchema>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for PatchedTicketRequest
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import * as Enums from '../../enums'
|
|
8
|
+
|
|
9
|
+
export const PatchedTicketRequestSchema = z.object({
|
|
10
|
+
user: z.int().optional(),
|
|
11
|
+
subject: z.string().min(1).max(255).optional(),
|
|
12
|
+
status: z.nativeEnum(Enums.PatchedTicketRequestStatus).optional(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Infer TypeScript type from Zod schema
|
|
17
|
+
*/
|
|
18
|
+
export type PatchedTicketRequest = z.infer<typeof PatchedTicketRequestSchema>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for Sender
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
export const SenderSchema = z.object({
|
|
9
|
+
id: z.int(),
|
|
10
|
+
display_username: z.string(),
|
|
11
|
+
email: z.email(),
|
|
12
|
+
avatar: z.string().nullable(),
|
|
13
|
+
initials: z.string(),
|
|
14
|
+
is_staff: z.boolean(),
|
|
15
|
+
is_superuser: z.boolean(),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Infer TypeScript type from Zod schema
|
|
20
|
+
*/
|
|
21
|
+
export type Sender = z.infer<typeof SenderSchema>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for Ticket
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import * as Enums from '../../enums'
|
|
8
|
+
|
|
9
|
+
export const TicketSchema = z.object({
|
|
10
|
+
uuid: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
|
|
11
|
+
user: z.int(),
|
|
12
|
+
subject: z.string().max(255),
|
|
13
|
+
status: z.nativeEnum(Enums.TicketStatus).optional(),
|
|
14
|
+
created_at: z.iso.datetime(),
|
|
15
|
+
unanswered_messages_count: z.int(),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Infer TypeScript type from Zod schema
|
|
20
|
+
*/
|
|
21
|
+
export type Ticket = z.infer<typeof TicketSchema>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schema for TicketRequest
|
|
3
|
+
*
|
|
4
|
+
* This schema provides runtime validation and type inference.
|
|
5
|
+
* */
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import * as Enums from '../../enums'
|
|
8
|
+
|
|
9
|
+
export const TicketRequestSchema = z.object({
|
|
10
|
+
user: z.int(),
|
|
11
|
+
subject: z.string().min(1).max(255),
|
|
12
|
+
status: z.nativeEnum(Enums.TicketRequestStatus).optional(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Infer TypeScript type from Zod schema
|
|
17
|
+
*/
|
|
18
|
+
export type TicketRequest = z.infer<typeof TicketRequestSchema>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod Schemas - Runtime validation and type inference
|
|
3
|
+
*
|
|
4
|
+
* Auto-generated from OpenAPI specification.
|
|
5
|
+
* Provides runtime validation for API requests and responses.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { UserSchema } from './schemas'
|
|
10
|
+
*
|
|
11
|
+
* // Validate data
|
|
12
|
+
* const user = UserSchema.parse(data)
|
|
13
|
+
*
|
|
14
|
+
* // Type inference
|
|
15
|
+
* type User = z.infer<typeof UserSchema>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export * from './Message.schema'
|
|
20
|
+
export * from './MessageCreate.schema'
|
|
21
|
+
export * from './MessageCreateRequest.schema'
|
|
22
|
+
export * from './MessageRequest.schema'
|
|
23
|
+
export * from './PaginatedMessageList.schema'
|
|
24
|
+
export * from './PaginatedTicketList.schema'
|
|
25
|
+
export * from './PatchedMessageRequest.schema'
|
|
26
|
+
export * from './PatchedTicketRequest.schema'
|
|
27
|
+
export * from './Sender.schema'
|
|
28
|
+
export * from './Ticket.schema'
|
|
29
|
+
export * from './TicketRequest.schema'
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global API Instance - Singleton configuration
|
|
3
|
+
*
|
|
4
|
+
* This module provides a global API instance that can be configured once
|
|
5
|
+
* and used throughout your application.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Configure once (e.g., in your app entry point)
|
|
10
|
+
* import { configureAPI } from './api-instance'
|
|
11
|
+
*
|
|
12
|
+
* configureAPI({
|
|
13
|
+
* baseUrl: 'https://api.example.com',
|
|
14
|
+
* token: 'your-jwt-token'
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* // Then use fetchers and hooks anywhere without configuration
|
|
18
|
+
* import { getUsers } from './fetchers'
|
|
19
|
+
* const users = await getUsers({ page: 1 })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* For SSR or multiple instances:
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { API } from './index'
|
|
25
|
+
* import { getUsers } from './fetchers'
|
|
26
|
+
*
|
|
27
|
+
* const api = new API('https://api.example.com')
|
|
28
|
+
* const users = await getUsers({ page: 1 }, api)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { API, type APIOptions } from './index'
|
|
33
|
+
|
|
34
|
+
let globalAPI: API | null = null
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the global API instance
|
|
38
|
+
* @throws Error if API is not configured
|
|
39
|
+
*/
|
|
40
|
+
export function getAPIInstance(): API {
|
|
41
|
+
if (!globalAPI) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\n' +
|
|
44
|
+
'Example:\n' +
|
|
45
|
+
' import { configureAPI } from "./api-instance"\n' +
|
|
46
|
+
' configureAPI({ baseUrl: "https://api.example.com" })'
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
return globalAPI
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if API is configured
|
|
54
|
+
*/
|
|
55
|
+
export function isAPIConfigured(): boolean {
|
|
56
|
+
return globalAPI !== null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Configure the global API instance
|
|
61
|
+
*
|
|
62
|
+
* @param baseUrl - Base URL for the API
|
|
63
|
+
* @param options - Optional configuration (storage, retry, logger)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* configureAPI({
|
|
68
|
+
* baseUrl: 'https://api.example.com',
|
|
69
|
+
* token: 'jwt-token',
|
|
70
|
+
* options: {
|
|
71
|
+
* retryConfig: { maxRetries: 3 },
|
|
72
|
+
* loggerConfig: { enabled: true }
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function configureAPI(config: {
|
|
78
|
+
baseUrl: string
|
|
79
|
+
token?: string
|
|
80
|
+
refreshToken?: string
|
|
81
|
+
options?: APIOptions
|
|
82
|
+
}): API {
|
|
83
|
+
globalAPI = new API(config.baseUrl, config.options)
|
|
84
|
+
|
|
85
|
+
if (config.token) {
|
|
86
|
+
globalAPI.setToken(config.token, config.refreshToken)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return globalAPI
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Reconfigure the global API instance with new settings
|
|
94
|
+
* Useful for updating tokens or base URL
|
|
95
|
+
*/
|
|
96
|
+
export function reconfigureAPI(updates: {
|
|
97
|
+
baseUrl?: string
|
|
98
|
+
token?: string
|
|
99
|
+
refreshToken?: string
|
|
100
|
+
}): API {
|
|
101
|
+
const instance = getAPIInstance()
|
|
102
|
+
|
|
103
|
+
if (updates.baseUrl) {
|
|
104
|
+
instance.setBaseUrl(updates.baseUrl)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (updates.token) {
|
|
108
|
+
instance.setToken(updates.token, updates.refreshToken)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return instance
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Clear tokens from the global API instance
|
|
116
|
+
*/
|
|
117
|
+
export function clearAPITokens(): void {
|
|
118
|
+
const instance = getAPIInstance()
|
|
119
|
+
instance.clearTokens()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reset the global API instance
|
|
124
|
+
* Useful for testing or logout scenarios
|
|
125
|
+
*/
|
|
126
|
+
export function resetAPI(): void {
|
|
127
|
+
if (globalAPI) {
|
|
128
|
+
globalAPI.clearTokens()
|
|
129
|
+
}
|
|
130
|
+
globalAPI = null
|
|
131
|
+
}
|