@djangocfg/api 2.1.263 → 2.1.266

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 (33) hide show
  1. package/dist/auth.cjs +62 -74
  2. package/dist/auth.cjs.map +1 -1
  3. package/dist/auth.d.cts +0 -18
  4. package/dist/auth.d.ts +0 -18
  5. package/dist/auth.mjs +62 -74
  6. package/dist/auth.mjs.map +1 -1
  7. package/dist/clients.cjs +57 -79
  8. package/dist/clients.cjs.map +1 -1
  9. package/dist/clients.d.cts +113 -179
  10. package/dist/clients.d.ts +113 -179
  11. package/dist/clients.mjs +57 -79
  12. package/dist/clients.mjs.map +1 -1
  13. package/dist/hooks.d.cts +72 -72
  14. package/dist/hooks.d.ts +72 -72
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +97 -97
  17. package/dist/index.d.ts +97 -97
  18. package/dist/index.mjs.map +1 -1
  19. package/package.json +2 -2
  20. package/src/_api/generated/cfg_accounts/accounts/models.ts +31 -31
  21. package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +40 -40
  22. package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +31 -31
  23. package/src/_api/generated/cfg_totp/CLAUDE.md +3 -3
  24. package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_management.ts +7 -7
  25. package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_management.ts +5 -5
  26. package/src/_api/generated/cfg_totp/_utils/schemas/index.ts +0 -1
  27. package/src/_api/generated/cfg_totp/schema.json +2 -103
  28. package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +14 -14
  29. package/src/_api/generated/cfg_totp/totp__totp_management/client.ts +2 -13
  30. package/src/_api/generated/cfg_totp/totp__totp_management/models.ts +4 -29
  31. package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +13 -13
  32. package/src/auth/hooks/useTwoFactorStatus.ts +21 -14
  33. package/src/_api/generated/cfg_totp/_utils/schemas/PaginatedDeviceListResponseList.schema.ts +0 -24
@@ -3,6 +3,7 @@
3
3
  import { useCallback, useState } from 'react';
4
4
 
5
5
  import { apiTotp } from '../../clients';
6
+ import { APIError } from '../../_api/generated/cfg_totp';
6
7
  import { authLogger } from '../utils/logger';
7
8
 
8
9
  export interface TwoFactorDevice {
@@ -48,6 +49,18 @@ export interface UseTwoFactorStatusReturn {
48
49
  * }
49
50
  * ```
50
51
  */
52
+ /** Extract a human-readable message from a thrown error. */
53
+ function extractErrorMessage(err: unknown, fallback: string): string {
54
+ if (err instanceof APIError) {
55
+ const body = err.response as Record<string, unknown> | null;
56
+ if (typeof body?.error === 'string') return body.error;
57
+ if (typeof body?.detail === 'string') return body.detail;
58
+ return err.message;
59
+ }
60
+ if (err instanceof Error) return err.message;
61
+ return fallback;
62
+ }
63
+
51
64
  export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
52
65
  const [isLoading, setIsLoading] = useState(false);
53
66
  const [error, setError] = useState<string | null>(null);
@@ -68,13 +81,10 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
68
81
  try {
69
82
  authLogger.info('Fetching 2FA status...');
70
83
 
71
- const response = await apiTotp.totp_management.totpDevicesList();
84
+ // API returns { devices: [...], has_2fa_enabled: bool }
85
+ const response = await apiTotp.totp_management.totpDevicesRetrieve();
72
86
 
73
- // Map devices to our format
74
-
75
- // Join all devices into a single array
76
- const devices = response.results.flatMap((device) => device.devices);
77
- const mappedDevices: TwoFactorDevice[] = devices.map((device) => ({
87
+ const mappedDevices: TwoFactorDevice[] = response.devices.map((device) => ({
78
88
  id: device.id,
79
89
  name: device.name,
80
90
  createdAt: device.created_at,
@@ -83,15 +93,12 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
83
93
  }));
84
94
 
85
95
  setDevices(mappedDevices);
86
-
87
- // 2FA is enabled if there are any devices
88
- const enabled = mappedDevices.length > 0;
89
- setHas2FAEnabled(enabled);
96
+ setHas2FAEnabled(response.has_2fa_enabled);
90
97
 
91
- authLogger.info('2FA status:', enabled ? 'enabled' : 'disabled');
98
+ authLogger.info('2FA status:', response.has_2fa_enabled ? 'enabled' : 'disabled');
92
99
 
93
100
  } catch (err) {
94
- const errorMessage = err instanceof Error ? err.message : 'Failed to fetch 2FA status';
101
+ const errorMessage = extractErrorMessage(err, 'Failed to fetch 2FA status');
95
102
  authLogger.error('Failed to fetch 2FA status:', err);
96
103
  setError(errorMessage);
97
104
  } finally {
@@ -122,8 +129,8 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
122
129
  authLogger.info('2FA disabled successfully');
123
130
  return true;
124
131
 
125
- } catch (err) {
126
- const errorMessage = err instanceof Error ? err.message : 'Invalid verification code';
132
+ } catch (err: unknown) {
133
+ const errorMessage = extractErrorMessage(err, 'Invalid verification code');
127
134
  authLogger.error('Failed to disable 2FA:', err);
128
135
  setError(errorMessage);
129
136
  return false;
@@ -1,24 +0,0 @@
1
- /**
2
- * Zod schema for PaginatedDeviceListResponseList
3
- *
4
- * This schema provides runtime validation and type inference.
5
- * */
6
- import { z } from 'zod'
7
- import { DeviceListResponseSchema } from './DeviceListResponse.schema'
8
-
9
- export const PaginatedDeviceListResponseListSchema = z.object({
10
- count: z.number().int(),
11
- page: z.number().int(),
12
- pages: z.number().int(),
13
- page_size: z.number().int(),
14
- has_next: z.boolean(),
15
- has_previous: z.boolean(),
16
- next_page: z.number().int().nullable().optional(),
17
- previous_page: z.number().int().nullable().optional(),
18
- results: z.array(DeviceListResponseSchema),
19
- })
20
-
21
- /**
22
- * Infer TypeScript type from Zod schema
23
- */
24
- export type PaginatedDeviceListResponseList = z.infer<typeof PaginatedDeviceListResponseListSchema>