@djangocfg/ext-support 1.0.1 → 1.0.3

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.
@@ -0,0 +1,1398 @@
1
+ import { ConsolaInstance } from 'consola';
2
+ import React from 'react';
3
+ import { z, ZodError } from 'zod';
4
+ import * as _djangocfg_ext_base from '@djangocfg/ext-base';
5
+
6
+ /**
7
+ * * `open` - Open
8
+ * * `waiting_for_user` - Waiting for User
9
+ * * `waiting_for_admin` - Waiting for Admin
10
+ * * `resolved` - Resolved
11
+ * * `closed` - Closed
12
+ */
13
+ declare enum PatchedTicketRequestStatus {
14
+ OPEN = "open",
15
+ WAITING_FOR_USER = "waiting_for_user",
16
+ WAITING_FOR_ADMIN = "waiting_for_admin",
17
+ RESOLVED = "resolved",
18
+ CLOSED = "closed"
19
+ }
20
+ /**
21
+ * * `open` - Open
22
+ * * `waiting_for_user` - Waiting for User
23
+ * * `waiting_for_admin` - Waiting for Admin
24
+ * * `resolved` - Resolved
25
+ * * `closed` - Closed
26
+ */
27
+ declare enum TicketStatus {
28
+ OPEN = "open",
29
+ WAITING_FOR_USER = "waiting_for_user",
30
+ WAITING_FOR_ADMIN = "waiting_for_admin",
31
+ RESOLVED = "resolved",
32
+ CLOSED = "closed"
33
+ }
34
+ /**
35
+ * * `open` - Open
36
+ * * `waiting_for_user` - Waiting for User
37
+ * * `waiting_for_admin` - Waiting for Admin
38
+ * * `resolved` - Resolved
39
+ * * `closed` - Closed
40
+ */
41
+ declare enum TicketRequestStatus {
42
+ OPEN = "open",
43
+ WAITING_FOR_USER = "waiting_for_user",
44
+ WAITING_FOR_ADMIN = "waiting_for_admin",
45
+ RESOLVED = "resolved",
46
+ CLOSED = "closed"
47
+ }
48
+
49
+ type enums_PatchedTicketRequestStatus = PatchedTicketRequestStatus;
50
+ declare const enums_PatchedTicketRequestStatus: typeof PatchedTicketRequestStatus;
51
+ type enums_TicketRequestStatus = TicketRequestStatus;
52
+ declare const enums_TicketRequestStatus: typeof TicketRequestStatus;
53
+ type enums_TicketStatus = TicketStatus;
54
+ declare const enums_TicketStatus: typeof TicketStatus;
55
+ declare namespace enums {
56
+ export { enums_PatchedTicketRequestStatus as PatchedTicketRequestStatus, enums_TicketRequestStatus as TicketRequestStatus, enums_TicketStatus as TicketStatus };
57
+ }
58
+
59
+ /**
60
+ *
61
+ * Response model (includes read-only fields).
62
+ */
63
+ interface PaginatedTicketList$1 {
64
+ /** Total number of items across all pages */
65
+ count: number;
66
+ /** Current page number (1-based) */
67
+ page: number;
68
+ /** Total number of pages */
69
+ pages: number;
70
+ /** Number of items per page */
71
+ page_size: number;
72
+ /** Whether there is a next page */
73
+ has_next: boolean;
74
+ /** Whether there is a previous page */
75
+ has_previous: boolean;
76
+ /** Next page number (null if no next page) */
77
+ next_page?: number | null;
78
+ /** Previous page number (null if no previous page) */
79
+ previous_page?: number | null;
80
+ /** Array of items for current page */
81
+ results: Array<Ticket$1>;
82
+ }
83
+ /**
84
+ *
85
+ * Request model (no read-only fields).
86
+ */
87
+ interface TicketRequest$1 {
88
+ user: number;
89
+ subject: string;
90
+ /** * `open` - Open
91
+ * `waiting_for_user` - Waiting for User
92
+ * `waiting_for_admin` - Waiting for Admin
93
+ * `resolved` - Resolved
94
+ * `closed` - Closed */
95
+ status?: TicketRequestStatus;
96
+ }
97
+ /**
98
+ *
99
+ * Response model (includes read-only fields).
100
+ */
101
+ interface Ticket$1 {
102
+ uuid: string;
103
+ user: number;
104
+ subject: string;
105
+ /** * `open` - Open
106
+ * `waiting_for_user` - Waiting for User
107
+ * `waiting_for_admin` - Waiting for Admin
108
+ * `resolved` - Resolved
109
+ * `closed` - Closed */
110
+ status?: TicketStatus;
111
+ created_at: string;
112
+ /** Get count of unanswered messages for this specific ticket. */
113
+ unanswered_messages_count: number;
114
+ }
115
+ /**
116
+ *
117
+ * Response model (includes read-only fields).
118
+ */
119
+ interface PaginatedMessageList$1 {
120
+ /** Total number of items across all pages */
121
+ count: number;
122
+ /** Current page number (1-based) */
123
+ page: number;
124
+ /** Total number of pages */
125
+ pages: number;
126
+ /** Number of items per page */
127
+ page_size: number;
128
+ /** Whether there is a next page */
129
+ has_next: boolean;
130
+ /** Whether there is a previous page */
131
+ has_previous: boolean;
132
+ /** Next page number (null if no next page) */
133
+ next_page?: number | null;
134
+ /** Previous page number (null if no previous page) */
135
+ previous_page?: number | null;
136
+ /** Array of items for current page */
137
+ results: Array<Message$1>;
138
+ }
139
+ /**
140
+ *
141
+ * Request model (no read-only fields).
142
+ */
143
+ interface MessageCreateRequest$1 {
144
+ text: string;
145
+ }
146
+ /**
147
+ *
148
+ * Response model (includes read-only fields).
149
+ */
150
+ interface MessageCreate$1 {
151
+ text: string;
152
+ }
153
+ /**
154
+ *
155
+ * Response model (includes read-only fields).
156
+ */
157
+ interface Message$1 {
158
+ uuid: string;
159
+ ticket: string;
160
+ sender: Sender$1;
161
+ /** Check if this message is from the ticket author. */
162
+ is_from_author: boolean;
163
+ text: string;
164
+ created_at: string;
165
+ }
166
+ /**
167
+ *
168
+ * Request model (no read-only fields).
169
+ */
170
+ interface MessageRequest$1 {
171
+ text: string;
172
+ }
173
+ /**
174
+ *
175
+ * Request model (no read-only fields).
176
+ */
177
+ interface PatchedMessageRequest$1 {
178
+ text?: string;
179
+ }
180
+ /**
181
+ *
182
+ * Request model (no read-only fields).
183
+ */
184
+ interface PatchedTicketRequest$1 {
185
+ user?: number;
186
+ subject?: string;
187
+ /** * `open` - Open
188
+ * `waiting_for_user` - Waiting for User
189
+ * `waiting_for_admin` - Waiting for Admin
190
+ * `resolved` - Resolved
191
+ * `closed` - Closed */
192
+ status?: PatchedTicketRequestStatus;
193
+ }
194
+ /**
195
+ *
196
+ * Response model (includes read-only fields).
197
+ */
198
+ interface Sender$1 {
199
+ id: number;
200
+ /** Get formatted username for display. */
201
+ display_username: string;
202
+ email: string;
203
+ avatar?: string | null;
204
+ /** Get user's initials for avatar fallback. */
205
+ initials: string;
206
+ /** Designates whether the user can log into this admin site. */
207
+ is_staff: boolean;
208
+ /** Designates that this user has all permissions without explicitly assigning them. */
209
+ is_superuser: boolean;
210
+ }
211
+
212
+ declare namespace models {
213
+ export type { Message$1 as Message, MessageCreate$1 as MessageCreate, MessageCreateRequest$1 as MessageCreateRequest, MessageRequest$1 as MessageRequest, PaginatedMessageList$1 as PaginatedMessageList, PaginatedTicketList$1 as PaginatedTicketList, PatchedMessageRequest$1 as PatchedMessageRequest, PatchedTicketRequest$1 as PatchedTicketRequest, Sender$1 as Sender, Ticket$1 as Ticket, TicketRequest$1 as TicketRequest };
214
+ }
215
+
216
+ /**
217
+ * API endpoints for Support.
218
+ */
219
+ declare class ExtSupportSupport {
220
+ private client;
221
+ constructor(client: any);
222
+ ticketsList(page?: number, page_size?: number): Promise<PaginatedTicketList$1>;
223
+ ticketsList(params?: {
224
+ page?: number;
225
+ page_size?: number;
226
+ }): Promise<PaginatedTicketList$1>;
227
+ /**
228
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
229
+ * or Session). Staff users can see all tickets, regular users see only
230
+ * their own.
231
+ */
232
+ ticketsCreate(data: TicketRequest$1): Promise<Ticket$1>;
233
+ ticketsMessagesList(ticket_uuid: string, page?: number, page_size?: number): Promise<PaginatedMessageList$1>;
234
+ ticketsMessagesList(ticket_uuid: string, params?: {
235
+ page?: number;
236
+ page_size?: number;
237
+ }): Promise<PaginatedMessageList$1>;
238
+ /**
239
+ * ViewSet for managing support messages. Requires authenticated user (JWT
240
+ * or Session). Users can only access messages for their own tickets.
241
+ */
242
+ ticketsMessagesCreate(ticket_uuid: string, data: MessageCreateRequest$1): Promise<MessageCreate$1>;
243
+ /**
244
+ * ViewSet for managing support messages. Requires authenticated user (JWT
245
+ * or Session). Users can only access messages for their own tickets.
246
+ */
247
+ ticketsMessagesRetrieve(ticket_uuid: string, uuid: string): Promise<Message$1>;
248
+ /**
249
+ * ViewSet for managing support messages. Requires authenticated user (JWT
250
+ * or Session). Users can only access messages for their own tickets.
251
+ */
252
+ ticketsMessagesUpdate(ticket_uuid: string, uuid: string, data: MessageRequest$1): Promise<Message$1>;
253
+ /**
254
+ * ViewSet for managing support messages. Requires authenticated user (JWT
255
+ * or Session). Users can only access messages for their own tickets.
256
+ */
257
+ ticketsMessagesPartialUpdate(ticket_uuid: string, uuid: string, data?: PatchedMessageRequest$1): Promise<Message$1>;
258
+ /**
259
+ * ViewSet for managing support messages. Requires authenticated user (JWT
260
+ * or Session). Users can only access messages for their own tickets.
261
+ */
262
+ ticketsMessagesDestroy(ticket_uuid: string, uuid: string): Promise<void>;
263
+ /**
264
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
265
+ * or Session). Staff users can see all tickets, regular users see only
266
+ * their own.
267
+ */
268
+ ticketsRetrieve(uuid: string): Promise<Ticket$1>;
269
+ /**
270
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
271
+ * or Session). Staff users can see all tickets, regular users see only
272
+ * their own.
273
+ */
274
+ ticketsUpdate(uuid: string, data: TicketRequest$1): Promise<Ticket$1>;
275
+ /**
276
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
277
+ * or Session). Staff users can see all tickets, regular users see only
278
+ * their own.
279
+ */
280
+ ticketsPartialUpdate(uuid: string, data?: PatchedTicketRequest$1): Promise<Ticket$1>;
281
+ /**
282
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
283
+ * or Session). Staff users can see all tickets, regular users see only
284
+ * their own.
285
+ */
286
+ ticketsDestroy(uuid: string): Promise<void>;
287
+ }
288
+
289
+ /**
290
+ * HTTP Client Adapter Pattern
291
+ *
292
+ * Allows switching between fetch/axios/httpx without changing generated code.
293
+ * Provides unified interface for making HTTP requests.
294
+ */
295
+ interface HttpRequest {
296
+ method: string;
297
+ url: string;
298
+ headers?: Record<string, string>;
299
+ body?: any;
300
+ params?: Record<string, any>;
301
+ /** FormData for file uploads (multipart/form-data) */
302
+ formData?: FormData;
303
+ }
304
+ interface HttpResponse<T = any> {
305
+ data: T;
306
+ status: number;
307
+ statusText: string;
308
+ headers: Record<string, string>;
309
+ }
310
+ /**
311
+ * HTTP Client Adapter Interface.
312
+ * Implement this to use custom HTTP clients (axios, httpx, etc.)
313
+ */
314
+ interface HttpClientAdapter {
315
+ request<T = any>(request: HttpRequest): Promise<HttpResponse<T>>;
316
+ }
317
+ /**
318
+ * Default Fetch API adapter.
319
+ * Uses native browser fetch() with proper error handling.
320
+ */
321
+ declare class FetchAdapter implements HttpClientAdapter {
322
+ request<T = any>(request: HttpRequest): Promise<HttpResponse<T>>;
323
+ }
324
+
325
+ /**
326
+ * API Logger with Consola
327
+ * Beautiful console logging for API requests and responses
328
+ *
329
+ * Installation:
330
+ * npm install consola
331
+ */
332
+
333
+ /**
334
+ * Request log data
335
+ */
336
+ interface RequestLog {
337
+ method: string;
338
+ url: string;
339
+ headers?: Record<string, string>;
340
+ body?: any;
341
+ timestamp: number;
342
+ }
343
+ /**
344
+ * Response log data
345
+ */
346
+ interface ResponseLog {
347
+ status: number;
348
+ statusText: string;
349
+ data?: any;
350
+ duration: number;
351
+ timestamp: number;
352
+ }
353
+ /**
354
+ * Error log data
355
+ */
356
+ interface ErrorLog {
357
+ message: string;
358
+ statusCode?: number;
359
+ fieldErrors?: Record<string, string[]>;
360
+ duration: number;
361
+ timestamp: number;
362
+ }
363
+ /**
364
+ * Logger configuration
365
+ */
366
+ interface LoggerConfig {
367
+ /** Enable logging */
368
+ enabled: boolean;
369
+ /** Log requests */
370
+ logRequests: boolean;
371
+ /** Log responses */
372
+ logResponses: boolean;
373
+ /** Log errors */
374
+ logErrors: boolean;
375
+ /** Log request/response bodies */
376
+ logBodies: boolean;
377
+ /** Log headers (excluding sensitive ones) */
378
+ logHeaders: boolean;
379
+ /** Custom consola instance */
380
+ consola?: ConsolaInstance;
381
+ }
382
+ /**
383
+ * API Logger class
384
+ */
385
+ declare class APILogger {
386
+ private config;
387
+ private consola;
388
+ constructor(config?: Partial<LoggerConfig>);
389
+ /**
390
+ * Enable logging
391
+ */
392
+ enable(): void;
393
+ /**
394
+ * Disable logging
395
+ */
396
+ disable(): void;
397
+ /**
398
+ * Update configuration
399
+ */
400
+ setConfig(config: Partial<LoggerConfig>): void;
401
+ /**
402
+ * Filter sensitive headers
403
+ */
404
+ private filterHeaders;
405
+ /**
406
+ * Log request
407
+ */
408
+ logRequest(request: RequestLog): void;
409
+ /**
410
+ * Log response
411
+ */
412
+ logResponse(request: RequestLog, response: ResponseLog): void;
413
+ /**
414
+ * Log error
415
+ */
416
+ logError(request: RequestLog, error: ErrorLog): void;
417
+ /**
418
+ * Log general info
419
+ */
420
+ info(message: string, ...args: any[]): void;
421
+ /**
422
+ * Log warning
423
+ */
424
+ warn(message: string, ...args: any[]): void;
425
+ /**
426
+ * Log error
427
+ */
428
+ error(message: string, ...args: any[]): void;
429
+ /**
430
+ * Log debug
431
+ */
432
+ debug(message: string, ...args: any[]): void;
433
+ /**
434
+ * Log success
435
+ */
436
+ success(message: string, ...args: any[]): void;
437
+ /**
438
+ * Create a sub-logger with prefix
439
+ */
440
+ withTag(tag: string): ConsolaInstance;
441
+ }
442
+
443
+ /**
444
+ * Retry Configuration and Utilities
445
+ *
446
+ * Provides automatic retry logic for failed HTTP requests using p-retry.
447
+ * Retries only on network errors and server errors (5xx), not client errors (4xx).
448
+ */
449
+ /**
450
+ * Information about a failed retry attempt.
451
+ */
452
+ interface FailedAttemptInfo {
453
+ /** The error that caused the failure */
454
+ error: Error;
455
+ /** The attempt number (1-indexed) */
456
+ attemptNumber: number;
457
+ /** Number of retries left */
458
+ retriesLeft: number;
459
+ }
460
+ /**
461
+ * Retry configuration options.
462
+ *
463
+ * Uses exponential backoff with jitter by default to avoid thundering herd.
464
+ */
465
+ interface RetryConfig {
466
+ /**
467
+ * Maximum number of retry attempts.
468
+ * @default 3
469
+ */
470
+ retries?: number;
471
+ /**
472
+ * Exponential backoff factor.
473
+ * @default 2
474
+ */
475
+ factor?: number;
476
+ /**
477
+ * Minimum wait time between retries (ms).
478
+ * @default 1000
479
+ */
480
+ minTimeout?: number;
481
+ /**
482
+ * Maximum wait time between retries (ms).
483
+ * @default 60000
484
+ */
485
+ maxTimeout?: number;
486
+ /**
487
+ * Add randomness to wait times (jitter).
488
+ * Helps avoid thundering herd problem.
489
+ * @default true
490
+ */
491
+ randomize?: boolean;
492
+ /**
493
+ * Callback called on each failed attempt.
494
+ */
495
+ onFailedAttempt?: (info: FailedAttemptInfo) => void;
496
+ }
497
+ /**
498
+ * Default retry configuration.
499
+ */
500
+ declare const DEFAULT_RETRY_CONFIG: Required<RetryConfig>;
501
+ /**
502
+ * Determine if an error should trigger a retry.
503
+ *
504
+ * Retries on:
505
+ * - Network errors (connection refused, timeout, etc.)
506
+ * - Server errors (5xx status codes)
507
+ * - Rate limiting (429 status code)
508
+ *
509
+ * Does NOT retry on:
510
+ * - Client errors (4xx except 429)
511
+ * - Authentication errors (401, 403)
512
+ * - Not found (404)
513
+ *
514
+ * @param error - The error to check
515
+ * @returns true if should retry, false otherwise
516
+ */
517
+ declare function shouldRetry(error: any): boolean;
518
+ /**
519
+ * Wrap a function with retry logic.
520
+ *
521
+ * @param fn - Async function to retry
522
+ * @param config - Retry configuration
523
+ * @returns Result of the function
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * const result = await withRetry(
528
+ * async () => fetch('https://api.example.com/users'),
529
+ * { retries: 5, minTimeout: 2000 }
530
+ * );
531
+ * ```
532
+ */
533
+ declare function withRetry<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
534
+
535
+ /**
536
+ * Async API client for Django CFG API.
537
+ *
538
+ * Usage:
539
+ * ```typescript
540
+ * const client = new APIClient('https://api.example.com');
541
+ * const users = await client.users.list();
542
+ * const post = await client.posts.create(newPost);
543
+ *
544
+ * // Custom HTTP adapter (e.g., Axios)
545
+ * const client = new APIClient('https://api.example.com', {
546
+ * httpClient: new AxiosAdapter()
547
+ * });
548
+ * ```
549
+ */
550
+ declare class APIClient {
551
+ private baseUrl;
552
+ private httpClient;
553
+ private logger;
554
+ private retryConfig;
555
+ ext_support_support: ExtSupportSupport;
556
+ constructor(baseUrl: string, options?: {
557
+ httpClient?: HttpClientAdapter;
558
+ loggerConfig?: Partial<LoggerConfig>;
559
+ retryConfig?: RetryConfig;
560
+ });
561
+ /**
562
+ * Get CSRF token from cookies (for SessionAuthentication).
563
+ *
564
+ * Returns null if cookie doesn't exist (JWT-only auth).
565
+ */
566
+ getCsrfToken(): string | null;
567
+ /**
568
+ * Make HTTP request with Django CSRF and session handling.
569
+ * Automatically retries on network errors and 5xx server errors.
570
+ */
571
+ request<T>(method: string, path: string, options?: {
572
+ params?: Record<string, any>;
573
+ body?: any;
574
+ formData?: FormData;
575
+ headers?: Record<string, string>;
576
+ }): Promise<T>;
577
+ /**
578
+ * Internal request method (without retry wrapper).
579
+ * Used by request() method with optional retry logic.
580
+ */
581
+ private _makeRequest;
582
+ }
583
+
584
+ /**
585
+ * Storage adapters for cross-platform token storage.
586
+ *
587
+ * Supports:
588
+ * - LocalStorage (browser)
589
+ * - Cookies (SSR/browser)
590
+ * - Memory (Node.js/Electron/testing)
591
+ */
592
+
593
+ /**
594
+ * Storage adapter interface for cross-platform token storage.
595
+ */
596
+ interface StorageAdapter {
597
+ getItem(key: string): string | null;
598
+ setItem(key: string, value: string): void;
599
+ removeItem(key: string): void;
600
+ }
601
+ /**
602
+ * LocalStorage adapter with safe try-catch for browser environments.
603
+ * Works in modern browsers with localStorage support.
604
+ *
605
+ * Note: This adapter uses window.localStorage and should only be used in browser/client environments.
606
+ * For server-side usage, use MemoryStorageAdapter or CookieStorageAdapter instead.
607
+ */
608
+ declare class LocalStorageAdapter implements StorageAdapter {
609
+ private logger?;
610
+ constructor(logger?: APILogger);
611
+ getItem(key: string): string | null;
612
+ setItem(key: string, value: string): void;
613
+ removeItem(key: string): void;
614
+ }
615
+ /**
616
+ * Cookie-based storage adapter for SSR and browser environments.
617
+ * Useful for Next.js, Nuxt.js, and other SSR frameworks.
618
+ */
619
+ declare class CookieStorageAdapter implements StorageAdapter {
620
+ private logger?;
621
+ constructor(logger?: APILogger);
622
+ getItem(key: string): string | null;
623
+ setItem(key: string, value: string): void;
624
+ removeItem(key: string): void;
625
+ }
626
+ /**
627
+ * In-memory storage adapter for Node.js, Electron, and testing environments.
628
+ * Data is stored in RAM and cleared when process exits.
629
+ */
630
+ declare class MemoryStorageAdapter implements StorageAdapter {
631
+ private storage;
632
+ private logger?;
633
+ constructor(logger?: APILogger);
634
+ getItem(key: string): string | null;
635
+ setItem(key: string, value: string): void;
636
+ removeItem(key: string): void;
637
+ }
638
+
639
+ /**
640
+ * Zod schema for Message
641
+ *
642
+ * This schema provides runtime validation and type inference.
643
+ * */
644
+
645
+ declare const MessageSchema: z.ZodObject<{
646
+ uuid: z.ZodString;
647
+ ticket: z.ZodString;
648
+ sender: z.ZodObject<{
649
+ id: z.ZodInt;
650
+ display_username: z.ZodString;
651
+ email: z.ZodEmail;
652
+ avatar: z.ZodNullable<z.ZodString>;
653
+ initials: z.ZodString;
654
+ is_staff: z.ZodBoolean;
655
+ is_superuser: z.ZodBoolean;
656
+ }, z.core.$strip>;
657
+ is_from_author: z.ZodBoolean;
658
+ text: z.ZodString;
659
+ created_at: z.ZodISODateTime;
660
+ }, z.core.$strip>;
661
+ /**
662
+ * Infer TypeScript type from Zod schema
663
+ */
664
+ type Message = z.infer<typeof MessageSchema>;
665
+
666
+ /**
667
+ * Zod schema for MessageCreate
668
+ *
669
+ * This schema provides runtime validation and type inference.
670
+ * */
671
+
672
+ declare const MessageCreateSchema: z.ZodObject<{
673
+ text: z.ZodString;
674
+ }, z.core.$strip>;
675
+ /**
676
+ * Infer TypeScript type from Zod schema
677
+ */
678
+ type MessageCreate = z.infer<typeof MessageCreateSchema>;
679
+
680
+ /**
681
+ * Zod schema for MessageCreateRequest
682
+ *
683
+ * This schema provides runtime validation and type inference.
684
+ * */
685
+
686
+ declare const MessageCreateRequestSchema: z.ZodObject<{
687
+ text: z.ZodString;
688
+ }, z.core.$strip>;
689
+ /**
690
+ * Infer TypeScript type from Zod schema
691
+ */
692
+ type MessageCreateRequest = z.infer<typeof MessageCreateRequestSchema>;
693
+
694
+ /**
695
+ * Zod schema for MessageRequest
696
+ *
697
+ * This schema provides runtime validation and type inference.
698
+ * */
699
+
700
+ declare const MessageRequestSchema: z.ZodObject<{
701
+ text: z.ZodString;
702
+ }, z.core.$strip>;
703
+ /**
704
+ * Infer TypeScript type from Zod schema
705
+ */
706
+ type MessageRequest = z.infer<typeof MessageRequestSchema>;
707
+
708
+ /**
709
+ * Zod schema for PaginatedMessageList
710
+ *
711
+ * This schema provides runtime validation and type inference.
712
+ * */
713
+
714
+ declare const PaginatedMessageListSchema: z.ZodObject<{
715
+ count: z.ZodInt;
716
+ page: z.ZodInt;
717
+ pages: z.ZodInt;
718
+ page_size: z.ZodInt;
719
+ has_next: z.ZodBoolean;
720
+ has_previous: z.ZodBoolean;
721
+ next_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
722
+ previous_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
723
+ results: z.ZodArray<z.ZodObject<{
724
+ uuid: z.ZodString;
725
+ ticket: z.ZodString;
726
+ sender: z.ZodObject<{
727
+ id: z.ZodInt;
728
+ display_username: z.ZodString;
729
+ email: z.ZodEmail;
730
+ avatar: z.ZodNullable<z.ZodString>;
731
+ initials: z.ZodString;
732
+ is_staff: z.ZodBoolean;
733
+ is_superuser: z.ZodBoolean;
734
+ }, z.core.$strip>;
735
+ is_from_author: z.ZodBoolean;
736
+ text: z.ZodString;
737
+ created_at: z.ZodISODateTime;
738
+ }, z.core.$strip>>;
739
+ }, z.core.$strip>;
740
+ /**
741
+ * Infer TypeScript type from Zod schema
742
+ */
743
+ type PaginatedMessageList = z.infer<typeof PaginatedMessageListSchema>;
744
+
745
+ declare const PaginatedTicketListSchema: z.ZodObject<{
746
+ count: z.ZodInt;
747
+ page: z.ZodInt;
748
+ pages: z.ZodInt;
749
+ page_size: z.ZodInt;
750
+ has_next: z.ZodBoolean;
751
+ has_previous: z.ZodBoolean;
752
+ next_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
753
+ previous_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
754
+ results: z.ZodArray<z.ZodObject<{
755
+ uuid: z.ZodString;
756
+ user: z.ZodInt;
757
+ subject: z.ZodString;
758
+ status: z.ZodOptional<z.ZodEnum<typeof TicketStatus>>;
759
+ created_at: z.ZodISODateTime;
760
+ unanswered_messages_count: z.ZodInt;
761
+ }, z.core.$strip>>;
762
+ }, z.core.$strip>;
763
+ /**
764
+ * Infer TypeScript type from Zod schema
765
+ */
766
+ type PaginatedTicketList = z.infer<typeof PaginatedTicketListSchema>;
767
+
768
+ /**
769
+ * Zod schema for PatchedMessageRequest
770
+ *
771
+ * This schema provides runtime validation and type inference.
772
+ * */
773
+
774
+ declare const PatchedMessageRequestSchema: z.ZodObject<{
775
+ text: z.ZodOptional<z.ZodString>;
776
+ }, z.core.$strip>;
777
+ /**
778
+ * Infer TypeScript type from Zod schema
779
+ */
780
+ type PatchedMessageRequest = z.infer<typeof PatchedMessageRequestSchema>;
781
+
782
+ /**
783
+ * Zod schema for PatchedTicketRequest
784
+ *
785
+ * This schema provides runtime validation and type inference.
786
+ * */
787
+
788
+ declare const PatchedTicketRequestSchema: z.ZodObject<{
789
+ user: z.ZodOptional<z.ZodInt>;
790
+ subject: z.ZodOptional<z.ZodString>;
791
+ status: z.ZodOptional<z.ZodEnum<typeof PatchedTicketRequestStatus>>;
792
+ }, z.core.$strip>;
793
+ /**
794
+ * Infer TypeScript type from Zod schema
795
+ */
796
+ type PatchedTicketRequest = z.infer<typeof PatchedTicketRequestSchema>;
797
+
798
+ /**
799
+ * Zod schema for Sender
800
+ *
801
+ * This schema provides runtime validation and type inference.
802
+ * */
803
+
804
+ declare const SenderSchema: z.ZodObject<{
805
+ id: z.ZodInt;
806
+ display_username: z.ZodString;
807
+ email: z.ZodEmail;
808
+ avatar: z.ZodNullable<z.ZodString>;
809
+ initials: z.ZodString;
810
+ is_staff: z.ZodBoolean;
811
+ is_superuser: z.ZodBoolean;
812
+ }, z.core.$strip>;
813
+ /**
814
+ * Infer TypeScript type from Zod schema
815
+ */
816
+ type Sender = z.infer<typeof SenderSchema>;
817
+
818
+ /**
819
+ * Zod schema for Ticket
820
+ *
821
+ * This schema provides runtime validation and type inference.
822
+ * */
823
+
824
+ declare const TicketSchema: z.ZodObject<{
825
+ uuid: z.ZodString;
826
+ user: z.ZodInt;
827
+ subject: z.ZodString;
828
+ status: z.ZodOptional<z.ZodEnum<typeof TicketStatus>>;
829
+ created_at: z.ZodISODateTime;
830
+ unanswered_messages_count: z.ZodInt;
831
+ }, z.core.$strip>;
832
+ /**
833
+ * Infer TypeScript type from Zod schema
834
+ */
835
+ type Ticket = z.infer<typeof TicketSchema>;
836
+
837
+ /**
838
+ * Zod schema for TicketRequest
839
+ *
840
+ * This schema provides runtime validation and type inference.
841
+ * */
842
+
843
+ declare const TicketRequestSchema: z.ZodObject<{
844
+ user: z.ZodInt;
845
+ subject: z.ZodString;
846
+ status: z.ZodOptional<z.ZodEnum<typeof TicketRequestStatus>>;
847
+ }, z.core.$strip>;
848
+ /**
849
+ * Infer TypeScript type from Zod schema
850
+ */
851
+ type TicketRequest = z.infer<typeof TicketRequestSchema>;
852
+
853
+ /**
854
+ * Zod Schemas - Runtime validation and type inference
855
+ *
856
+ * Auto-generated from OpenAPI specification.
857
+ * Provides runtime validation for API requests and responses.
858
+ *
859
+ * Usage:
860
+ * ```typescript
861
+ * import { UserSchema } from './schemas'
862
+ *
863
+ * // Validate data
864
+ * const user = UserSchema.parse(data)
865
+ *
866
+ * // Type inference
867
+ * type User = z.infer<typeof UserSchema>
868
+ * ```
869
+ */
870
+
871
+ type index$1_Message = Message;
872
+ type index$1_MessageCreate = MessageCreate;
873
+ type index$1_MessageCreateRequest = MessageCreateRequest;
874
+ declare const index$1_MessageCreateRequestSchema: typeof MessageCreateRequestSchema;
875
+ declare const index$1_MessageCreateSchema: typeof MessageCreateSchema;
876
+ type index$1_MessageRequest = MessageRequest;
877
+ declare const index$1_MessageRequestSchema: typeof MessageRequestSchema;
878
+ declare const index$1_MessageSchema: typeof MessageSchema;
879
+ type index$1_PaginatedMessageList = PaginatedMessageList;
880
+ declare const index$1_PaginatedMessageListSchema: typeof PaginatedMessageListSchema;
881
+ type index$1_PaginatedTicketList = PaginatedTicketList;
882
+ declare const index$1_PaginatedTicketListSchema: typeof PaginatedTicketListSchema;
883
+ type index$1_PatchedMessageRequest = PatchedMessageRequest;
884
+ declare const index$1_PatchedMessageRequestSchema: typeof PatchedMessageRequestSchema;
885
+ type index$1_PatchedTicketRequest = PatchedTicketRequest;
886
+ declare const index$1_PatchedTicketRequestSchema: typeof PatchedTicketRequestSchema;
887
+ type index$1_Sender = Sender;
888
+ declare const index$1_SenderSchema: typeof SenderSchema;
889
+ type index$1_Ticket = Ticket;
890
+ type index$1_TicketRequest = TicketRequest;
891
+ declare const index$1_TicketRequestSchema: typeof TicketRequestSchema;
892
+ declare const index$1_TicketSchema: typeof TicketSchema;
893
+ declare namespace index$1 {
894
+ export { type index$1_Message as Message, type index$1_MessageCreate as MessageCreate, type index$1_MessageCreateRequest as MessageCreateRequest, index$1_MessageCreateRequestSchema as MessageCreateRequestSchema, index$1_MessageCreateSchema as MessageCreateSchema, type index$1_MessageRequest as MessageRequest, index$1_MessageRequestSchema as MessageRequestSchema, index$1_MessageSchema as MessageSchema, type index$1_PaginatedMessageList as PaginatedMessageList, index$1_PaginatedMessageListSchema as PaginatedMessageListSchema, type index$1_PaginatedTicketList as PaginatedTicketList, index$1_PaginatedTicketListSchema as PaginatedTicketListSchema, type index$1_PatchedMessageRequest as PatchedMessageRequest, index$1_PatchedMessageRequestSchema as PatchedMessageRequestSchema, type index$1_PatchedTicketRequest as PatchedTicketRequest, index$1_PatchedTicketRequestSchema as PatchedTicketRequestSchema, type index$1_Sender as Sender, index$1_SenderSchema as SenderSchema, type index$1_Ticket as Ticket, type index$1_TicketRequest as TicketRequest, index$1_TicketRequestSchema as TicketRequestSchema, index$1_TicketSchema as TicketSchema };
895
+ }
896
+
897
+ /**
898
+ * Zod Validation Events - Browser CustomEvent integration
899
+ *
900
+ * Dispatches browser CustomEvents when Zod validation fails, allowing
901
+ * React/frontend apps to listen and handle validation errors globally.
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * // In your React app
906
+ * window.addEventListener('zod-validation-error', (event) => {
907
+ * const { operation, path, method, error, response } = event.detail;
908
+ * console.error(`Validation failed for ${method} ${path}`, error);
909
+ * // Show toast notification, log to Sentry, etc.
910
+ * });
911
+ * ```
912
+ */
913
+
914
+ /**
915
+ * Validation error event detail
916
+ */
917
+ interface ValidationErrorDetail {
918
+ /** Operation/function name that failed validation */
919
+ operation: string;
920
+ /** API endpoint path */
921
+ path: string;
922
+ /** HTTP method */
923
+ method: string;
924
+ /** Zod validation error */
925
+ error: ZodError;
926
+ /** Raw response data that failed validation */
927
+ response: any;
928
+ /** Timestamp of the error */
929
+ timestamp: Date;
930
+ }
931
+ /**
932
+ * Custom event type for Zod validation errors
933
+ */
934
+ type ValidationErrorEvent = CustomEvent<ValidationErrorDetail>;
935
+ /**
936
+ * Dispatch a Zod validation error event.
937
+ *
938
+ * Only dispatches in browser environment (when window is defined).
939
+ * Safe to call in Node.js/SSR - will be a no-op.
940
+ *
941
+ * @param detail - Validation error details
942
+ */
943
+ declare function dispatchValidationError(detail: ValidationErrorDetail): void;
944
+ /**
945
+ * Add a global listener for Zod validation errors.
946
+ *
947
+ * @param callback - Function to call when validation error occurs
948
+ * @returns Cleanup function to remove the listener
949
+ *
950
+ * @example
951
+ * ```typescript
952
+ * const cleanup = onValidationError(({ operation, error }) => {
953
+ * toast.error(`Validation failed in ${operation}`);
954
+ * logToSentry(error);
955
+ * });
956
+ *
957
+ * // Later, remove listener
958
+ * cleanup();
959
+ * ```
960
+ */
961
+ declare function onValidationError(callback: (detail: ValidationErrorDetail) => void): () => void;
962
+ /**
963
+ * Format Zod error for logging/display.
964
+ *
965
+ * @param error - Zod validation error
966
+ * @returns Formatted error message
967
+ */
968
+ declare function formatZodError(error: ZodError): string;
969
+
970
+ /**
971
+ * API operation
972
+ *
973
+ * @method GET
974
+ * @path /cfg/support/tickets/
975
+ */
976
+ declare function getSupportTicketsList(params?: {
977
+ page?: number;
978
+ page_size?: number;
979
+ }, client?: any): Promise<PaginatedTicketList>;
980
+ /**
981
+ * API operation
982
+ *
983
+ * @method POST
984
+ * @path /cfg/support/tickets/
985
+ */
986
+ declare function createSupportTicketsCreate(data: TicketRequest, client?: any): Promise<Ticket>;
987
+ /**
988
+ * API operation
989
+ *
990
+ * @method GET
991
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/
992
+ */
993
+ declare function getSupportTicketsMessagesList(ticket_uuid: string, params?: {
994
+ page?: number;
995
+ page_size?: number;
996
+ }, client?: any): Promise<PaginatedMessageList>;
997
+ /**
998
+ * API operation
999
+ *
1000
+ * @method POST
1001
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/
1002
+ */
1003
+ declare function createSupportTicketsMessagesCreate(ticket_uuid: string, data: MessageCreateRequest, client?: any): Promise<MessageCreate>;
1004
+ /**
1005
+ * API operation
1006
+ *
1007
+ * @method GET
1008
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1009
+ */
1010
+ declare function getSupportTicketsMessagesRetrieve(ticket_uuid: string, uuid: string, client?: any): Promise<Message>;
1011
+ /**
1012
+ * API operation
1013
+ *
1014
+ * @method PUT
1015
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1016
+ */
1017
+ declare function updateSupportTicketsMessagesUpdate(ticket_uuid: string, uuid: string, data: MessageRequest, client?: any): Promise<Message>;
1018
+ /**
1019
+ * API operation
1020
+ *
1021
+ * @method PATCH
1022
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1023
+ */
1024
+ declare function partialUpdateSupportTicketsMessagesPartialUpdate(ticket_uuid: string, uuid: string, data?: PatchedMessageRequest, client?: any): Promise<Message>;
1025
+ /**
1026
+ * API operation
1027
+ *
1028
+ * @method DELETE
1029
+ * @path /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1030
+ */
1031
+ declare function deleteSupportTicketsMessagesDestroy(ticket_uuid: string, uuid: string, client?: any): Promise<void>;
1032
+ /**
1033
+ * API operation
1034
+ *
1035
+ * @method GET
1036
+ * @path /cfg/support/tickets/{uuid}/
1037
+ */
1038
+ declare function getSupportTicketsRetrieve(uuid: string, client?: any): Promise<Ticket>;
1039
+ /**
1040
+ * API operation
1041
+ *
1042
+ * @method PUT
1043
+ * @path /cfg/support/tickets/{uuid}/
1044
+ */
1045
+ declare function updateSupportTicketsUpdate(uuid: string, data: TicketRequest, client?: any): Promise<Ticket>;
1046
+ /**
1047
+ * API operation
1048
+ *
1049
+ * @method PATCH
1050
+ * @path /cfg/support/tickets/{uuid}/
1051
+ */
1052
+ declare function partialUpdateSupportTicketsPartialUpdate(uuid: string, data?: PatchedTicketRequest, client?: any): Promise<Ticket>;
1053
+ /**
1054
+ * API operation
1055
+ *
1056
+ * @method DELETE
1057
+ * @path /cfg/support/tickets/{uuid}/
1058
+ */
1059
+ declare function deleteSupportTicketsDestroy(uuid: string, client?: any): Promise<void>;
1060
+
1061
+ /**
1062
+ * Typed Fetchers - Universal API functions
1063
+ *
1064
+ * Auto-generated from OpenAPI specification.
1065
+ * These functions work in any JavaScript environment.
1066
+ *
1067
+ * Features:
1068
+ * - Runtime validation with Zod
1069
+ * - Type-safe parameters and responses
1070
+ * - Works with any data-fetching library (SWR, React Query, etc)
1071
+ * - Server Component compatible
1072
+ *
1073
+ * Usage:
1074
+ * ```typescript
1075
+ * import * as fetchers from './fetchers'
1076
+ *
1077
+ * // Direct usage
1078
+ * const user = await fetchers.getUser(1)
1079
+ *
1080
+ * // With SWR
1081
+ * const { data } = useSWR('user-1', () => fetchers.getUser(1))
1082
+ *
1083
+ * // With React Query
1084
+ * const { data } = useQuery(['user', 1], () => fetchers.getUser(1))
1085
+ * ```
1086
+ */
1087
+
1088
+ declare const index_createSupportTicketsCreate: typeof createSupportTicketsCreate;
1089
+ declare const index_createSupportTicketsMessagesCreate: typeof createSupportTicketsMessagesCreate;
1090
+ declare const index_deleteSupportTicketsDestroy: typeof deleteSupportTicketsDestroy;
1091
+ declare const index_deleteSupportTicketsMessagesDestroy: typeof deleteSupportTicketsMessagesDestroy;
1092
+ declare const index_getSupportTicketsList: typeof getSupportTicketsList;
1093
+ declare const index_getSupportTicketsMessagesList: typeof getSupportTicketsMessagesList;
1094
+ declare const index_getSupportTicketsMessagesRetrieve: typeof getSupportTicketsMessagesRetrieve;
1095
+ declare const index_getSupportTicketsRetrieve: typeof getSupportTicketsRetrieve;
1096
+ declare const index_partialUpdateSupportTicketsMessagesPartialUpdate: typeof partialUpdateSupportTicketsMessagesPartialUpdate;
1097
+ declare const index_partialUpdateSupportTicketsPartialUpdate: typeof partialUpdateSupportTicketsPartialUpdate;
1098
+ declare const index_updateSupportTicketsMessagesUpdate: typeof updateSupportTicketsMessagesUpdate;
1099
+ declare const index_updateSupportTicketsUpdate: typeof updateSupportTicketsUpdate;
1100
+ declare namespace index {
1101
+ export { index_createSupportTicketsCreate as createSupportTicketsCreate, index_createSupportTicketsMessagesCreate as createSupportTicketsMessagesCreate, index_deleteSupportTicketsDestroy as deleteSupportTicketsDestroy, index_deleteSupportTicketsMessagesDestroy as deleteSupportTicketsMessagesDestroy, index_getSupportTicketsList as getSupportTicketsList, index_getSupportTicketsMessagesList as getSupportTicketsMessagesList, index_getSupportTicketsMessagesRetrieve as getSupportTicketsMessagesRetrieve, index_getSupportTicketsRetrieve as getSupportTicketsRetrieve, index_partialUpdateSupportTicketsMessagesPartialUpdate as partialUpdateSupportTicketsMessagesPartialUpdate, index_partialUpdateSupportTicketsPartialUpdate as partialUpdateSupportTicketsPartialUpdate, index_updateSupportTicketsMessagesUpdate as updateSupportTicketsMessagesUpdate, index_updateSupportTicketsUpdate as updateSupportTicketsUpdate };
1102
+ }
1103
+
1104
+ /**
1105
+ * Global API Instance - Singleton configuration
1106
+ *
1107
+ * This module provides a global API instance that can be configured once
1108
+ * and used throughout your application.
1109
+ *
1110
+ * Usage:
1111
+ * ```typescript
1112
+ * // Configure once (e.g., in your app entry point)
1113
+ * import { configureAPI } from './api-instance'
1114
+ *
1115
+ * configureAPI({
1116
+ * baseUrl: 'https://api.example.com',
1117
+ * token: 'your-jwt-token'
1118
+ * })
1119
+ *
1120
+ * // Then use fetchers and hooks anywhere without configuration
1121
+ * import { getUsers } from './fetchers'
1122
+ * const users = await getUsers({ page: 1 })
1123
+ * ```
1124
+ *
1125
+ * For SSR or multiple instances:
1126
+ * ```typescript
1127
+ * import { API } from './index'
1128
+ * import { getUsers } from './fetchers'
1129
+ *
1130
+ * const api = new API('https://api.example.com')
1131
+ * const users = await getUsers({ page: 1 }, api)
1132
+ * ```
1133
+ */
1134
+
1135
+ /**
1136
+ * Get the global API instance
1137
+ * @throws Error if API is not configured
1138
+ */
1139
+ declare function getAPIInstance(): API;
1140
+ /**
1141
+ * Check if API is configured
1142
+ */
1143
+ declare function isAPIConfigured(): boolean;
1144
+ /**
1145
+ * Configure the global API instance
1146
+ *
1147
+ * @param baseUrl - Base URL for the API
1148
+ * @param options - Optional configuration (storage, retry, logger)
1149
+ *
1150
+ * @example
1151
+ * ```typescript
1152
+ * configureAPI({
1153
+ * baseUrl: 'https://api.example.com',
1154
+ * token: 'jwt-token',
1155
+ * options: {
1156
+ * retryConfig: { maxRetries: 3 },
1157
+ * loggerConfig: { enabled: true }
1158
+ * }
1159
+ * })
1160
+ * ```
1161
+ */
1162
+ declare function configureAPI(config: {
1163
+ baseUrl: string;
1164
+ token?: string;
1165
+ refreshToken?: string;
1166
+ options?: APIOptions;
1167
+ }): API;
1168
+ /**
1169
+ * Reconfigure the global API instance with new settings
1170
+ * Useful for updating tokens or base URL
1171
+ */
1172
+ declare function reconfigureAPI(updates: {
1173
+ baseUrl?: string;
1174
+ token?: string;
1175
+ refreshToken?: string;
1176
+ }): API;
1177
+ /**
1178
+ * Clear tokens from the global API instance
1179
+ */
1180
+ declare function clearAPITokens(): void;
1181
+ /**
1182
+ * Reset the global API instance
1183
+ * Useful for testing or logout scenarios
1184
+ */
1185
+ declare function resetAPI(): void;
1186
+
1187
+ /**
1188
+ * API Error Classes
1189
+ *
1190
+ * Typed error classes with Django REST Framework support.
1191
+ */
1192
+ /**
1193
+ * HTTP API Error with DRF field-specific validation errors.
1194
+ *
1195
+ * Usage:
1196
+ * ```typescript
1197
+ * try {
1198
+ * await api.users.create(userData);
1199
+ * } catch (error) {
1200
+ * if (error instanceof APIError) {
1201
+ * if (error.isValidationError) {
1202
+ * console.log('Field errors:', error.fieldErrors);
1203
+ * // { "email": ["Email already exists"], "username": ["Required"] }
1204
+ * }
1205
+ * }
1206
+ * }
1207
+ * ```
1208
+ */
1209
+ declare class APIError extends Error {
1210
+ statusCode: number;
1211
+ statusText: string;
1212
+ response: any;
1213
+ url: string;
1214
+ constructor(statusCode: number, statusText: string, response: any, url: string, message?: string);
1215
+ /**
1216
+ * Get error details from response.
1217
+ * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
1218
+ */
1219
+ get details(): Record<string, any> | null;
1220
+ /**
1221
+ * Get field-specific validation errors from DRF.
1222
+ * Returns: { "field_name": ["error1", "error2"], ... }
1223
+ */
1224
+ get fieldErrors(): Record<string, string[]> | null;
1225
+ /**
1226
+ * Get single error message from DRF.
1227
+ * Checks for "detail", "message", or first field error.
1228
+ */
1229
+ get errorMessage(): string;
1230
+ get isValidationError(): boolean;
1231
+ get isAuthError(): boolean;
1232
+ get isPermissionError(): boolean;
1233
+ get isNotFoundError(): boolean;
1234
+ get isServerError(): boolean;
1235
+ }
1236
+ /**
1237
+ * Network Error (connection failed, timeout, etc.)
1238
+ */
1239
+ declare class NetworkError extends Error {
1240
+ url: string;
1241
+ originalError?: Error;
1242
+ constructor(message: string, url: string, originalError?: Error);
1243
+ }
1244
+
1245
+ /**
1246
+ * Django CFG API - API Client with JWT Management
1247
+ *
1248
+ * Usage:
1249
+ * ```typescript
1250
+ * import { API } from './api';
1251
+ *
1252
+ * const api = new API('https://api.example.com');
1253
+ *
1254
+ * // Set JWT token
1255
+ * api.setToken('your-jwt-token', 'refresh-token');
1256
+ *
1257
+ * // Use API
1258
+ * const posts = await api.posts.list();
1259
+ * const user = await api.users.retrieve(1);
1260
+ *
1261
+ * // Check authentication
1262
+ * if (api.isAuthenticated()) {
1263
+ * // ...
1264
+ * }
1265
+ *
1266
+ * // Custom storage with logging (for Electron/Node.js)
1267
+ * import { MemoryStorageAdapter, APILogger } from './storage';
1268
+ * const logger = new APILogger({ enabled: true, logLevel: 'debug' });
1269
+ * const api = new API('https://api.example.com', {
1270
+ * storage: new MemoryStorageAdapter(logger),
1271
+ * loggerConfig: { enabled: true, logLevel: 'debug' }
1272
+ * });
1273
+ *
1274
+ * // Get OpenAPI schema
1275
+ * const schema = api.getSchema();
1276
+ * ```
1277
+ */
1278
+
1279
+ declare const TOKEN_KEY = "auth_token";
1280
+ declare const REFRESH_TOKEN_KEY = "refresh_token";
1281
+ interface APIOptions {
1282
+ /** Custom storage adapter (defaults to LocalStorageAdapter) */
1283
+ storage?: StorageAdapter;
1284
+ /** Retry configuration for failed requests */
1285
+ retryConfig?: RetryConfig;
1286
+ /** Logger configuration */
1287
+ loggerConfig?: Partial<LoggerConfig>;
1288
+ }
1289
+ declare class API {
1290
+ private baseUrl;
1291
+ private _client;
1292
+ private _token;
1293
+ private _refreshToken;
1294
+ private storage;
1295
+ private options?;
1296
+ ext_support_support: ExtSupportSupport;
1297
+ constructor(baseUrl: string, options?: APIOptions);
1298
+ private _loadTokensFromStorage;
1299
+ private _reinitClients;
1300
+ private _injectAuthHeader;
1301
+ /**
1302
+ * Get current JWT token
1303
+ */
1304
+ getToken(): string | null;
1305
+ /**
1306
+ * Get current refresh token
1307
+ */
1308
+ getRefreshToken(): string | null;
1309
+ /**
1310
+ * Set JWT token and refresh token
1311
+ * @param token - JWT access token
1312
+ * @param refreshToken - JWT refresh token (optional)
1313
+ */
1314
+ setToken(token: string, refreshToken?: string): void;
1315
+ /**
1316
+ * Clear all tokens
1317
+ */
1318
+ clearTokens(): void;
1319
+ /**
1320
+ * Check if user is authenticated
1321
+ */
1322
+ isAuthenticated(): boolean;
1323
+ /**
1324
+ * Update base URL and reinitialize clients
1325
+ * @param url - New base URL
1326
+ */
1327
+ setBaseUrl(url: string): void;
1328
+ /**
1329
+ * Get current base URL
1330
+ */
1331
+ getBaseUrl(): string;
1332
+ /**
1333
+ * Get OpenAPI schema path
1334
+ * @returns Path to the OpenAPI schema JSON file
1335
+ *
1336
+ * Note: The OpenAPI schema is available in the schema.json file.
1337
+ * You can load it dynamically using:
1338
+ * ```typescript
1339
+ * const schema = await fetch('./schema.json').then(r => r.json());
1340
+ * // or using fs in Node.js:
1341
+ * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
1342
+ * ```
1343
+ */
1344
+ getSchemaPath(): string;
1345
+ }
1346
+
1347
+ /**
1348
+ * Support Extension API
1349
+ *
1350
+ * Pre-configured API instance with shared authentication
1351
+ */
1352
+
1353
+ declare const apiSupport: API;
1354
+
1355
+ /**
1356
+ * Support Layout
1357
+ * Modern support layout with resizable panels for desktop and mobile-optimized view
1358
+ */
1359
+
1360
+ interface SupportLayoutProps {
1361
+ children?: React.ReactNode;
1362
+ }
1363
+ declare const SupportLayout: React.FC<SupportLayoutProps>;
1364
+
1365
+ /**
1366
+ * Support Layout Types
1367
+ * UI state types for SupportLayout
1368
+ */
1369
+ interface SupportUIState {
1370
+ selectedTicketUuid: string | null;
1371
+ isCreateDialogOpen: boolean;
1372
+ viewMode: 'list' | 'grid';
1373
+ }
1374
+ interface TicketFormData {
1375
+ subject: string;
1376
+ message: string;
1377
+ }
1378
+
1379
+ /**
1380
+ * Support Layout Events
1381
+ * Event system for SupportLayout
1382
+ */
1383
+ declare const SUPPORT_LAYOUT_EVENTS: {
1384
+ readonly OPEN_CREATE_DIALOG: "support-layout:open-create-dialog";
1385
+ readonly CLOSE_CREATE_DIALOG: "support-layout:close-create-dialog";
1386
+ readonly TICKET_SELECTED: "support-layout:ticket-selected";
1387
+ readonly TICKET_CREATED: "support-layout:ticket-created";
1388
+ readonly MESSAGE_SENT: "support-layout:message-sent";
1389
+ };
1390
+ declare const openCreateTicketDialog: () => void;
1391
+ declare const closeCreateTicketDialog: () => void;
1392
+
1393
+ /**
1394
+ * Support extension configuration
1395
+ */
1396
+ declare const extensionConfig: _djangocfg_ext_base.ExtensionMetadata;
1397
+
1398
+ export { API, APIClient, APIError, APILogger, type APIOptions, CookieStorageAdapter, DEFAULT_RETRY_CONFIG, enums as Enums, type ErrorLog, models as ExtSupportSupportTypes, type FailedAttemptInfo, FetchAdapter, index as Fetchers, type HttpClientAdapter, type HttpRequest, type HttpResponse, LocalStorageAdapter, type LoggerConfig, MemoryStorageAdapter, type Message, type MessageCreate, type MessageCreateRequest, MessageCreateRequestSchema, MessageCreateSchema, type MessageRequest, MessageRequestSchema, MessageSchema, NetworkError, type PaginatedMessageList, PaginatedMessageListSchema, type PaginatedTicketList, PaginatedTicketListSchema, type PatchedMessageRequest, PatchedMessageRequestSchema, type PatchedTicketRequest, PatchedTicketRequestSchema, REFRESH_TOKEN_KEY, type RequestLog, type ResponseLog, type RetryConfig, SUPPORT_LAYOUT_EVENTS, index$1 as Schemas, type Sender, SenderSchema, type StorageAdapter, SupportLayout, type SupportLayoutProps, type SupportUIState, TOKEN_KEY, type Ticket, type TicketFormData, type TicketRequest, TicketRequestSchema, TicketSchema, type ValidationErrorDetail, type ValidationErrorEvent, apiSupport, clearAPITokens, closeCreateTicketDialog, configureAPI, createSupportTicketsCreate, createSupportTicketsMessagesCreate, deleteSupportTicketsDestroy, deleteSupportTicketsMessagesDestroy, dispatchValidationError, extensionConfig, formatZodError, getAPIInstance, getSupportTicketsList, getSupportTicketsMessagesList, getSupportTicketsMessagesRetrieve, getSupportTicketsRetrieve, isAPIConfigured, onValidationError, openCreateTicketDialog, partialUpdateSupportTicketsMessagesPartialUpdate, partialUpdateSupportTicketsPartialUpdate, reconfigureAPI, resetAPI, shouldRetry, updateSupportTicketsMessagesUpdate, updateSupportTicketsUpdate, withRetry };