@djangocfg/api 2.1.55 → 2.1.57

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 (93) hide show
  1. package/dist/auth.cjs +28 -15
  2. package/dist/auth.cjs.map +1 -1
  3. package/dist/auth.d.cts +6 -6
  4. package/dist/auth.d.ts +6 -6
  5. package/dist/auth.mjs +28 -15
  6. package/dist/auth.mjs.map +1 -1
  7. package/dist/clients.cjs +56 -17
  8. package/dist/clients.cjs.map +1 -1
  9. package/dist/clients.d.cts +17 -17
  10. package/dist/clients.d.ts +17 -17
  11. package/dist/clients.mjs +56 -17
  12. package/dist/clients.mjs.map +1 -1
  13. package/dist/hooks.cjs +763 -12
  14. package/dist/hooks.cjs.map +1 -1
  15. package/dist/hooks.d.cts +11 -11
  16. package/dist/hooks.d.ts +11 -11
  17. package/dist/hooks.mjs +763 -12
  18. package/dist/hooks.mjs.map +1 -1
  19. package/dist/index.cjs +893 -69
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +59 -41
  22. package/dist/index.d.ts +59 -41
  23. package/dist/index.mjs +893 -69
  24. package/dist/index.mjs.map +1 -1
  25. package/package.json +3 -3
  26. package/src/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +1 -1
  27. package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +2 -2
  28. package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +1 -1
  29. package/src/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +1 -1
  30. package/src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +1 -1
  31. package/src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +1 -1
  32. package/src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +1 -1
  33. package/src/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +1 -1
  34. package/src/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +1 -1
  35. package/src/generated/cfg_accounts/_utils/schemas/User.schema.ts +1 -1
  36. package/src/generated/cfg_accounts/api-instance.ts +61 -13
  37. package/src/generated/cfg_centrifugo/api-instance.ts +61 -13
  38. package/src/generated/cfg_totp/CLAUDE.md +90 -0
  39. package/src/generated/cfg_totp/_utils/fetchers/index.ts +33 -0
  40. package/src/generated/cfg_totp/_utils/fetchers/totp.ts +49 -0
  41. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_management.ts +108 -0
  42. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_setup.ts +153 -0
  43. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_verification.ts +152 -0
  44. package/src/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +152 -0
  45. package/src/generated/cfg_totp/_utils/hooks/index.ts +33 -0
  46. package/src/generated/cfg_totp/_utils/hooks/totp.ts +42 -0
  47. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_management.ts +58 -0
  48. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_setup.ts +63 -0
  49. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_verification.ts +62 -0
  50. package/src/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +59 -0
  51. package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +19 -0
  52. package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +20 -0
  53. package/src/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +21 -0
  54. package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +20 -0
  55. package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +21 -0
  56. package/src/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +26 -0
  57. package/src/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +19 -0
  58. package/src/generated/cfg_totp/_utils/schemas/PaginatedDeviceListList.schema.ts +24 -0
  59. package/src/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +19 -0
  60. package/src/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +23 -0
  61. package/src/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +20 -0
  62. package/src/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +20 -0
  63. package/src/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +24 -0
  64. package/src/generated/cfg_totp/_utils/schemas/index.ts +32 -0
  65. package/src/generated/cfg_totp/api-instance.ts +180 -0
  66. package/src/generated/cfg_totp/client.ts +313 -0
  67. package/src/generated/cfg_totp/enums.ts +12 -0
  68. package/src/generated/cfg_totp/errors.ts +117 -0
  69. package/src/generated/cfg_totp/http.ts +104 -0
  70. package/src/generated/cfg_totp/index.ts +302 -0
  71. package/src/generated/cfg_totp/logger.ts +260 -0
  72. package/src/generated/cfg_totp/retry.ts +176 -0
  73. package/src/generated/cfg_totp/schema.json +859 -0
  74. package/src/generated/cfg_totp/storage.ts +162 -0
  75. package/src/generated/cfg_totp/totp/client.ts +23 -0
  76. package/src/generated/cfg_totp/totp/index.ts +3 -0
  77. package/src/generated/cfg_totp/totp/models.ts +1 -0
  78. package/src/generated/cfg_totp/totp__2fa_management/client.ts +41 -0
  79. package/src/generated/cfg_totp/totp__2fa_management/index.ts +3 -0
  80. package/src/generated/cfg_totp/totp__2fa_management/models.ts +60 -0
  81. package/src/generated/cfg_totp/totp__2fa_setup/client.ts +32 -0
  82. package/src/generated/cfg_totp/totp__2fa_setup/index.ts +3 -0
  83. package/src/generated/cfg_totp/totp__2fa_setup/models.ts +54 -0
  84. package/src/generated/cfg_totp/totp__2fa_verification/client.ts +32 -0
  85. package/src/generated/cfg_totp/totp__2fa_verification/index.ts +3 -0
  86. package/src/generated/cfg_totp/totp__2fa_verification/models.ts +44 -0
  87. package/src/generated/cfg_totp/totp__backup_codes/client.ts +31 -0
  88. package/src/generated/cfg_totp/totp__backup_codes/index.ts +3 -0
  89. package/src/generated/cfg_totp/totp__backup_codes/models.ts +37 -0
  90. package/src/generated/cfg_totp/validation-events.ts +134 -0
  91. package/src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts +2 -2
  92. package/src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts +1 -1
  93. package/src/generated/cfg_webpush/api-instance.ts +61 -13
@@ -0,0 +1,162 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Storage adapters for cross-platform token storage.
4
+ *
5
+ * Supports:
6
+ * - LocalStorage (browser)
7
+ * - Cookies (SSR/browser)
8
+ * - Memory (Node.js/Electron/testing)
9
+ */
10
+
11
+ import type { APILogger } from './logger';
12
+
13
+ /**
14
+ * Storage adapter interface for cross-platform token storage.
15
+ */
16
+ export interface StorageAdapter {
17
+ getItem(key: string): string | null;
18
+ setItem(key: string, value: string): void;
19
+ removeItem(key: string): void;
20
+ }
21
+
22
+ /**
23
+ * LocalStorage adapter with safe try-catch for browser environments.
24
+ * Works in modern browsers with localStorage support.
25
+ *
26
+ * Note: This adapter uses window.localStorage and should only be used in browser/client environments.
27
+ * For server-side usage, use MemoryStorageAdapter or CookieStorageAdapter instead.
28
+ */
29
+ export class LocalStorageAdapter implements StorageAdapter {
30
+ private logger?: APILogger;
31
+
32
+ constructor(logger?: APILogger) {
33
+ this.logger = logger;
34
+ }
35
+
36
+ getItem(key: string): string | null {
37
+ try {
38
+ if (typeof window !== 'undefined' && window.localStorage) {
39
+ const value = localStorage.getItem(key);
40
+ this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? 'found' : 'not found'}`);
41
+ return value;
42
+ }
43
+ this.logger?.warn('LocalStorage not available: window.localStorage is undefined');
44
+ } catch (error) {
45
+ this.logger?.error('LocalStorage.getItem failed:', error);
46
+ }
47
+ return null;
48
+ }
49
+
50
+ setItem(key: string, value: string): void {
51
+ try {
52
+ if (typeof window !== 'undefined' && window.localStorage) {
53
+ localStorage.setItem(key, value);
54
+ this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
55
+ } else {
56
+ this.logger?.warn('LocalStorage not available: window.localStorage is undefined');
57
+ }
58
+ } catch (error) {
59
+ this.logger?.error('LocalStorage.setItem failed:', error);
60
+ }
61
+ }
62
+
63
+ removeItem(key: string): void {
64
+ try {
65
+ if (typeof window !== 'undefined' && window.localStorage) {
66
+ localStorage.removeItem(key);
67
+ this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
68
+ } else {
69
+ this.logger?.warn('LocalStorage not available: window.localStorage is undefined');
70
+ }
71
+ } catch (error) {
72
+ this.logger?.error('LocalStorage.removeItem failed:', error);
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Cookie-based storage adapter for SSR and browser environments.
79
+ * Useful for Next.js, Nuxt.js, and other SSR frameworks.
80
+ */
81
+ export class CookieStorageAdapter implements StorageAdapter {
82
+ private logger?: APILogger;
83
+
84
+ constructor(logger?: APILogger) {
85
+ this.logger = logger;
86
+ }
87
+
88
+ getItem(key: string): string | null {
89
+ try {
90
+ if (typeof document === 'undefined') {
91
+ this.logger?.warn('Cookies not available: document is undefined (SSR context?)');
92
+ return null;
93
+ }
94
+ const value = `; ${document.cookie}`;
95
+ const parts = value.split(`; ${key}=`);
96
+ if (parts.length === 2) {
97
+ const result = parts.pop()?.split(';').shift() || null;
98
+ this.logger?.debug(`CookieStorage.getItem("${key}"): ${result ? 'found' : 'not found'}`);
99
+ return result;
100
+ }
101
+ this.logger?.debug(`CookieStorage.getItem("${key}"): not found`);
102
+ } catch (error) {
103
+ this.logger?.error('CookieStorage.getItem failed:', error);
104
+ }
105
+ return null;
106
+ }
107
+
108
+ setItem(key: string, value: string): void {
109
+ try {
110
+ if (typeof document !== 'undefined') {
111
+ document.cookie = `${key}=${value}; path=/; max-age=31536000`;
112
+ this.logger?.debug(`CookieStorage.setItem("${key}"): success`);
113
+ } else {
114
+ this.logger?.warn('Cookies not available: document is undefined (SSR context?)');
115
+ }
116
+ } catch (error) {
117
+ this.logger?.error('CookieStorage.setItem failed:', error);
118
+ }
119
+ }
120
+
121
+ removeItem(key: string): void {
122
+ try {
123
+ if (typeof document !== 'undefined') {
124
+ document.cookie = `${key}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
125
+ this.logger?.debug(`CookieStorage.removeItem("${key}"): success`);
126
+ } else {
127
+ this.logger?.warn('Cookies not available: document is undefined (SSR context?)');
128
+ }
129
+ } catch (error) {
130
+ this.logger?.error('CookieStorage.removeItem failed:', error);
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * In-memory storage adapter for Node.js, Electron, and testing environments.
137
+ * Data is stored in RAM and cleared when process exits.
138
+ */
139
+ export class MemoryStorageAdapter implements StorageAdapter {
140
+ private storage: Map<string, string> = new Map();
141
+ private logger?: APILogger;
142
+
143
+ constructor(logger?: APILogger) {
144
+ this.logger = logger;
145
+ }
146
+
147
+ getItem(key: string): string | null {
148
+ const value = this.storage.get(key) || null;
149
+ this.logger?.debug(`MemoryStorage.getItem("${key}"): ${value ? 'found' : 'not found'}`);
150
+ return value;
151
+ }
152
+
153
+ setItem(key: string, value: string): void {
154
+ this.storage.set(key, value);
155
+ this.logger?.debug(`MemoryStorage.setItem("${key}"): success`);
156
+ }
157
+
158
+ removeItem(key: string): void {
159
+ this.storage.delete(key);
160
+ this.logger?.debug(`MemoryStorage.removeItem("${key}"): success`);
161
+ }
162
+ }
@@ -0,0 +1,23 @@
1
+ import * as Models from "./models";
2
+
3
+
4
+ /**
5
+ * API endpoints for Totp.
6
+ */
7
+ export class Totp {
8
+ private client: any;
9
+
10
+ constructor(client: any) {
11
+ this.client = client;
12
+ }
13
+
14
+ /**
15
+ * Delete a TOTP device. Requires verification code if removing the
16
+ * last/primary device.
17
+ */
18
+ async devicesDestroy(id: string): Promise<void> {
19
+ const response = await this.client.request('DELETE', `/cfg/totp/devices/${id}/`);
20
+ return;
21
+ }
22
+
23
+ }
@@ -0,0 +1,3 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ export * from "./client";
3
+ export * as Models from "./models";
@@ -0,0 +1 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
@@ -0,0 +1,41 @@
1
+ import * as Models from "./models";
2
+
3
+
4
+ /**
5
+ * API endpoints for 2fa Management.
6
+ */
7
+ export class 2faManagement {
8
+ private client: any;
9
+
10
+ constructor(client: any) {
11
+ this.client = client;
12
+ }
13
+
14
+ async totpDevicesList(page?: number, page_size?: number): Promise<Models.PaginatedDeviceListList>;
15
+ async totpDevicesList(params?: { page?: number; page_size?: number }): Promise<Models.PaginatedDeviceListList>;
16
+
17
+ /**
18
+ * List all TOTP devices for user.
19
+ */
20
+ async totpDevicesList(...args: any[]): Promise<Models.PaginatedDeviceListList> {
21
+ const isParamsObject = args.length === 1 && typeof args[0] === 'object' && args[0] !== null && !Array.isArray(args[0]);
22
+
23
+ let params;
24
+ if (isParamsObject) {
25
+ params = args[0];
26
+ } else {
27
+ params = { page: args[0], page_size: args[1] };
28
+ }
29
+ const response = await this.client.request('GET', "/cfg/totp/devices/", { params });
30
+ return response;
31
+ }
32
+
33
+ /**
34
+ * Completely disable 2FA for account. Requires verification code.
35
+ */
36
+ async totpDisableCreate(data: Models.DisableRequest): Promise<any> {
37
+ const response = await this.client.request('POST', "/cfg/totp/disable/", { body: data });
38
+ return response;
39
+ }
40
+
41
+ }
@@ -0,0 +1,3 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ export * from "./client";
3
+ export * as Models from "./models";
@@ -0,0 +1,60 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ import * as Enums from "../enums";
3
+
4
+ /**
5
+ *
6
+ * Response model (includes read-only fields).
7
+ */
8
+ export interface PaginatedDeviceListList {
9
+ /** Total number of items across all pages */
10
+ count: number;
11
+ /** Current page number (1-based) */
12
+ page: number;
13
+ /** Total number of pages */
14
+ pages: number;
15
+ /** Number of items per page */
16
+ page_size: number;
17
+ /** Whether there is a next page */
18
+ has_next: boolean;
19
+ /** Whether there is a previous page */
20
+ has_previous: boolean;
21
+ /** Next page number (null if no next page) */
22
+ next_page?: number | null;
23
+ /** Previous page number (null if no previous page) */
24
+ previous_page?: number | null;
25
+ /** Array of items for current page */
26
+ results: Array<DeviceList>;
27
+ }
28
+
29
+ /**
30
+ * Serializer for completely disabling 2FA.
31
+ *
32
+ * Request model (no read-only fields).
33
+ */
34
+ export interface DisableRequest {
35
+ /** TOTP code for verification */
36
+ code: string;
37
+ }
38
+
39
+ /**
40
+ * Serializer for listing TOTP devices.
41
+ *
42
+ * Response model (includes read-only fields).
43
+ */
44
+ export interface DeviceList {
45
+ id: number;
46
+ /** Device name for identification */
47
+ name: string;
48
+ /** Primary device used for verification */
49
+ is_primary: boolean;
50
+ /** * `pending` - Pending Confirmation
51
+ * `active` - Active
52
+ * `disabled` - Disabled */
53
+ status: Enums.DeviceListStatus;
54
+ created_at: string;
55
+ /** When device setup was confirmed */
56
+ confirmed_at?: string | null;
57
+ /** Last successful verification */
58
+ last_used_at?: string | null;
59
+ }
60
+
@@ -0,0 +1,32 @@
1
+ import * as Models from "./models";
2
+
3
+
4
+ /**
5
+ * API endpoints for 2fa Setup.
6
+ */
7
+ export class 2faSetup {
8
+ private client: any;
9
+
10
+ constructor(client: any) {
11
+ this.client = client;
12
+ }
13
+
14
+ /**
15
+ * Start 2FA setup process. Creates a new TOTP device and returns QR code
16
+ * for scanning.
17
+ */
18
+ async totpSetupCreate(data: Models.SetupRequest): Promise<Models.SetupResponse> {
19
+ const response = await this.client.request('POST', "/cfg/totp/setup/", { body: data });
20
+ return response;
21
+ }
22
+
23
+ /**
24
+ * Confirm 2FA setup with first valid code. Activates the device and
25
+ * generates backup codes.
26
+ */
27
+ async totpSetupConfirmCreate(data: Models.ConfirmSetupRequest): Promise<Models.ConfirmSetupResponse> {
28
+ const response = await this.client.request('POST', "/cfg/totp/setup/confirm/", { body: data });
29
+ return response;
30
+ }
31
+
32
+ }
@@ -0,0 +1,3 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ export * from "./client";
3
+ export * as Models from "./models";
@@ -0,0 +1,54 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Serializer for starting 2FA setup.
4
+ *
5
+ * Request model (no read-only fields).
6
+ */
7
+ export interface SetupRequest {
8
+ /** Device name for identification (e.g., 'My iPhone') */
9
+ device_name?: string;
10
+ }
11
+
12
+ /**
13
+ * Response serializer for setup initiation.
14
+ *
15
+ * Response model (includes read-only fields).
16
+ */
17
+ export interface SetupResponse {
18
+ /** Device ID to use for confirmation */
19
+ device_id: string;
20
+ /** Base32-encoded TOTP secret (for manual entry) */
21
+ secret: string;
22
+ /** otpauth:// URI for QR code generation */
23
+ provisioning_uri: string;
24
+ /** Base64-encoded QR code image (data URI) */
25
+ qr_code_base64: string;
26
+ /** Seconds until setup expires (typically 600 = 10 minutes) */
27
+ expires_in: number;
28
+ }
29
+
30
+ /**
31
+ * Serializer for confirming 2FA setup with first code.
32
+ *
33
+ * Request model (no read-only fields).
34
+ */
35
+ export interface ConfirmSetupRequest {
36
+ /** Device ID from setup response */
37
+ device_id: string;
38
+ /** 6-digit TOTP code from authenticator app */
39
+ code: string;
40
+ }
41
+
42
+ /**
43
+ * Response serializer for setup confirmation.
44
+ *
45
+ * Response model (includes read-only fields).
46
+ */
47
+ export interface ConfirmSetupResponse {
48
+ message: string;
49
+ /** List of backup recovery codes (save these!) */
50
+ backup_codes: Array<string>;
51
+ /** Warning message about backup codes */
52
+ backup_codes_warning: string;
53
+ }
54
+
@@ -0,0 +1,32 @@
1
+ import * as Models from "./models";
2
+
3
+
4
+ /**
5
+ * API endpoints for 2fa Verification.
6
+ */
7
+ export class 2faVerification {
8
+ private client: any;
9
+
10
+ constructor(client: any) {
11
+ this.client = client;
12
+ }
13
+
14
+ /**
15
+ * Verify TOTP code for 2FA session. Completes authentication and returns
16
+ * JWT tokens on success.
17
+ */
18
+ async totpVerifyCreate(data: Models.VerifyRequest): Promise<Models.VerifyResponse> {
19
+ const response = await this.client.request('POST', "/cfg/totp/verify/", { body: data });
20
+ return response;
21
+ }
22
+
23
+ /**
24
+ * Verify backup recovery code for 2FA session. Alternative verification
25
+ * method when TOTP device unavailable.
26
+ */
27
+ async totpVerifyBackupCreate(data: Models.VerifyBackupRequest): Promise<Models.VerifyResponse> {
28
+ const response = await this.client.request('POST', "/cfg/totp/verify/backup/", { body: data });
29
+ return response;
30
+ }
31
+
32
+ }
@@ -0,0 +1,3 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ export * from "./client";
3
+ export * as Models from "./models";
@@ -0,0 +1,44 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Serializer for TOTP code verification during login.
4
+ *
5
+ * Request model (no read-only fields).
6
+ */
7
+ export interface VerifyRequest {
8
+ /** 2FA session ID from login response */
9
+ session_id: string;
10
+ /** 6-digit TOTP code from authenticator app */
11
+ code: string;
12
+ }
13
+
14
+ /**
15
+ * Response serializer for successful 2FA verification.
16
+ *
17
+ * Response model (includes read-only fields).
18
+ */
19
+ export interface VerifyResponse {
20
+ message: string;
21
+ /** JWT access token */
22
+ access_token: string;
23
+ /** JWT refresh token */
24
+ refresh_token: string;
25
+ /** User profile data */
26
+ user: Record<string, any>;
27
+ /** Number of remaining backup codes (if backup code was used) */
28
+ remaining_backup_codes?: number;
29
+ /** Warning message (e.g., low backup codes) */
30
+ warning?: string;
31
+ }
32
+
33
+ /**
34
+ * Serializer for backup code verification during login.
35
+ *
36
+ * Request model (no read-only fields).
37
+ */
38
+ export interface VerifyBackupRequest {
39
+ /** 2FA session ID from login response */
40
+ session_id: string;
41
+ /** 8-character backup recovery code */
42
+ backup_code: string;
43
+ }
44
+
@@ -0,0 +1,31 @@
1
+ import * as Models from "./models";
2
+
3
+
4
+ /**
5
+ * API endpoints for Backup Codes.
6
+ */
7
+ export class BackupCodes {
8
+ private client: any;
9
+
10
+ constructor(client: any) {
11
+ this.client = client;
12
+ }
13
+
14
+ /**
15
+ * Get backup codes status for user.
16
+ */
17
+ async totpBackupCodesRetrieve(): Promise<Models.BackupCodesStatus> {
18
+ const response = await this.client.request('GET', "/cfg/totp/backup-codes/");
19
+ return response;
20
+ }
21
+
22
+ /**
23
+ * Regenerate backup codes. Requires TOTP code for verification.
24
+ * Invalidates all existing codes.
25
+ */
26
+ async totpBackupCodesRegenerateCreate(data: Models.BackupCodesRegenerateRequest): Promise<Models.BackupCodesRegenerateResponse> {
27
+ const response = await this.client.request('POST', "/cfg/totp/backup-codes/regenerate/", { body: data });
28
+ return response;
29
+ }
30
+
31
+ }
@@ -0,0 +1,3 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ export * from "./client";
3
+ export * as Models from "./models";
@@ -0,0 +1,37 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Serializer for backup codes status.
4
+ *
5
+ * Response model (includes read-only fields).
6
+ */
7
+ export interface BackupCodesStatus {
8
+ /** Number of unused backup codes */
9
+ remaining_count: number;
10
+ /** Total number of codes generated */
11
+ total_generated: number;
12
+ /** Warning if running low on codes */
13
+ warning?: string | null;
14
+ }
15
+
16
+ /**
17
+ * Serializer for regenerating backup codes.
18
+ *
19
+ * Request model (no read-only fields).
20
+ */
21
+ export interface BackupCodesRegenerateRequest {
22
+ /** TOTP code for verification */
23
+ code: string;
24
+ }
25
+
26
+ /**
27
+ * Response serializer for backup codes regeneration.
28
+ *
29
+ * Response model (includes read-only fields).
30
+ */
31
+ export interface BackupCodesRegenerateResponse {
32
+ /** List of new backup codes (save these!) */
33
+ backup_codes: Array<string>;
34
+ /** Warning about previous codes being invalidated */
35
+ warning: string;
36
+ }
37
+
@@ -0,0 +1,134 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Zod Validation Events - Browser CustomEvent integration
4
+ *
5
+ * Dispatches browser CustomEvents when Zod validation fails, allowing
6
+ * React/frontend apps to listen and handle validation errors globally.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // In your React app
11
+ * window.addEventListener('zod-validation-error', (event) => {
12
+ * const { operation, path, method, error, response } = event.detail;
13
+ * console.error(`Validation failed for ${method} ${path}`, error);
14
+ * // Show toast notification, log to Sentry, etc.
15
+ * });
16
+ * ```
17
+ */
18
+
19
+ import type { ZodError } from 'zod'
20
+
21
+ /**
22
+ * Validation error event detail
23
+ */
24
+ export interface ValidationErrorDetail {
25
+ /** Operation/function name that failed validation */
26
+ operation: string
27
+ /** API endpoint path */
28
+ path: string
29
+ /** HTTP method */
30
+ method: string
31
+ /** Zod validation error */
32
+ error: ZodError
33
+ /** Raw response data that failed validation */
34
+ response: any
35
+ /** Timestamp of the error */
36
+ timestamp: Date
37
+ }
38
+
39
+ /**
40
+ * Custom event type for Zod validation errors
41
+ */
42
+ export type ValidationErrorEvent = CustomEvent<ValidationErrorDetail>
43
+
44
+ /**
45
+ * Dispatch a Zod validation error event.
46
+ *
47
+ * Only dispatches in browser environment (when window is defined).
48
+ * Safe to call in Node.js/SSR - will be a no-op.
49
+ *
50
+ * @param detail - Validation error details
51
+ */
52
+ export function dispatchValidationError(detail: ValidationErrorDetail): void {
53
+ // Check if running in browser
54
+ if (typeof window === 'undefined') {
55
+ return
56
+ }
57
+
58
+ try {
59
+ const event = new CustomEvent<ValidationErrorDetail>('zod-validation-error', {
60
+ detail,
61
+ bubbles: true,
62
+ cancelable: false,
63
+ })
64
+
65
+ window.dispatchEvent(event)
66
+ } catch (error) {
67
+ // Silently fail - validation event dispatch should never crash the app
68
+ console.warn('Failed to dispatch validation error event:', error)
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Add a global listener for Zod validation errors.
74
+ *
75
+ * @param callback - Function to call when validation error occurs
76
+ * @returns Cleanup function to remove the listener
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const cleanup = onValidationError(({ operation, error }) => {
81
+ * toast.error(`Validation failed in ${operation}`);
82
+ * logToSentry(error);
83
+ * });
84
+ *
85
+ * // Later, remove listener
86
+ * cleanup();
87
+ * ```
88
+ */
89
+ export function onValidationError(
90
+ callback: (detail: ValidationErrorDetail) => void
91
+ ): () => void {
92
+ if (typeof window === 'undefined') {
93
+ // Return no-op cleanup function for SSR
94
+ return () => {}
95
+ }
96
+
97
+ const handler = (event: Event) => {
98
+ if (event instanceof CustomEvent) {
99
+ callback(event.detail)
100
+ }
101
+ }
102
+
103
+ window.addEventListener('zod-validation-error', handler)
104
+
105
+ // Return cleanup function
106
+ return () => {
107
+ window.removeEventListener('zod-validation-error', handler)
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Format Zod error for logging/display.
113
+ *
114
+ * @param error - Zod validation error
115
+ * @returns Formatted error message
116
+ */
117
+ export function formatZodError(error: ZodError): string {
118
+ const issues = error.issues.map((issue, index) => {
119
+ const path = issue.path.join('.') || 'root'
120
+ const parts = [`${index + 1}. ${path}: ${issue.message}`]
121
+
122
+ if ('expected' in issue && issue.expected) {
123
+ parts.push(` Expected: ${issue.expected}`)
124
+ }
125
+
126
+ if ('received' in issue && issue.received) {
127
+ parts.push(` Received: ${issue.received}`)
128
+ }
129
+
130
+ return parts.join('\n')
131
+ })
132
+
133
+ return issues.join('\n')
134
+ }