@djangocfg/api 2.1.104 → 2.1.105

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.104",
3
+ "version": "2.1.105",
4
4
  "description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
5
5
  "keywords": [
6
6
  "django",
@@ -84,7 +84,7 @@
84
84
  "devDependencies": {
85
85
  "@types/node": "^24.7.2",
86
86
  "@types/react": "^19.0.0",
87
- "@djangocfg/typescript-config": "^2.1.104",
87
+ "@djangocfg/typescript-config": "^2.1.105",
88
88
  "next": "^16.0.0",
89
89
  "react": "^19.0.0",
90
90
  "tsup": "^8.5.0",
@@ -71,7 +71,10 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
71
71
  const response = await apiTotp.totp_management.totpDevicesList();
72
72
 
73
73
  // Map devices to our format
74
- const mappedDevices: TwoFactorDevice[] = (response.results || []).map((device) => ({
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) => ({
75
78
  id: device.id,
76
79
  name: device.name,
77
80
  createdAt: device.created_at,
@@ -80,6 +83,7 @@ export const useTwoFactorStatus = (): UseTwoFactorStatusReturn => {
80
83
  }));
81
84
 
82
85
  setDevices(mappedDevices);
86
+
83
87
  // 2FA is enabled if there are any devices
84
88
  const enabled = mappedDevices.length > 0;
85
89
  setHas2FAEnabled(enabled);
@@ -12,7 +12,7 @@ python manage.py generate_client --groups cfg_totp --typescript
12
12
  |---|---|
13
13
  | Version | 3.0.3 |
14
14
  | Operations | 9 |
15
- | Schemas | 13 |
15
+ | Schemas | 15 |
16
16
 
17
17
  ## Resources
18
18
 
@@ -32,7 +32,7 @@
32
32
  */
33
33
  import { consola } from 'consola'
34
34
  import { DisableRequestSchema, type DisableRequest } from '../schemas/DisableRequest.schema'
35
- import { PaginatedDeviceListListSchema, type PaginatedDeviceListList } from '../schemas/PaginatedDeviceListList.schema'
35
+ import { PaginatedDeviceListResponseListSchema, type PaginatedDeviceListResponseList } from '../schemas/PaginatedDeviceListResponseList.schema'
36
36
  import { getAPIInstance } from '../../api-instance'
37
37
 
38
38
  /**
@@ -42,11 +42,11 @@ import { getAPIInstance } from '../../api-instance'
42
42
  * @path /cfg/totp/devices/
43
43
  */
44
44
  export async function getTotpDevicesList( params?: { page?: number; page_size?: number }, client?: any
45
- ): Promise<PaginatedDeviceListList> {
45
+ ): Promise<PaginatedDeviceListResponseList> {
46
46
  const api = client || getAPIInstance()
47
47
  const response = await api.totp_management.totpDevicesList(params?.page, params?.page_size)
48
48
  try {
49
- return PaginatedDeviceListListSchema.parse(response)
49
+ return PaginatedDeviceListResponseListSchema.parse(response)
50
50
  } catch (error) {
51
51
  // Zod validation error - log detailed information
52
52
  consola.error('❌ Zod Validation Failed');
@@ -22,7 +22,7 @@ import { useSWRConfig } from 'swr'
22
22
  import * as Fetchers from '../fetchers/totp__totp_management'
23
23
  import type { API } from '../../index'
24
24
  import type { DisableRequest } from '../schemas/DisableRequest.schema'
25
- import type { PaginatedDeviceListList } from '../schemas/PaginatedDeviceListList.schema'
25
+ import type { PaginatedDeviceListResponseList } from '../schemas/PaginatedDeviceListResponseList.schema'
26
26
 
27
27
  /**
28
28
  * API operation
@@ -30,8 +30,8 @@ import type { PaginatedDeviceListList } from '../schemas/PaginatedDeviceListList
30
30
  * @method GET
31
31
  * @path /cfg/totp/devices/
32
32
  */
33
- export function useTotpDevicesList(params?: { page?: number; page_size?: number }, client?: API): ReturnType<typeof useSWR<PaginatedDeviceListList>> {
34
- return useSWR<PaginatedDeviceListList>(
33
+ export function useTotpDevicesList(params?: { page?: number; page_size?: number }, client?: API): ReturnType<typeof useSWR<PaginatedDeviceListResponseList>> {
34
+ return useSWR<PaginatedDeviceListResponseList>(
35
35
  params ? ['cfg-totp-devices', params] : 'cfg-totp-devices',
36
36
  () => Fetchers.getTotpDevicesList(params, client)
37
37
  )
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Zod schema for DeviceListResponse
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * Response serializer for device list endpoint.
6
+ * */
7
+ import { z } from 'zod'
8
+ import { DeviceListSchema } from './DeviceList.schema'
9
+
10
+ /**
11
+ * Response serializer for device list endpoint.
12
+ */
13
+ export const DeviceListResponseSchema = z.object({
14
+ devices: z.array(DeviceListSchema),
15
+ has_2fa_enabled: z.boolean(),
16
+ })
17
+
18
+ /**
19
+ * Infer TypeScript type from Zod schema
20
+ */
21
+ export type DeviceListResponse = z.infer<typeof DeviceListResponseSchema>
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Zod schema for PaginatedDeviceListList
2
+ * Zod schema for PaginatedDeviceListResponseList
3
3
  *
4
4
  * This schema provides runtime validation and type inference.
5
5
  * */
6
6
  import { z } from 'zod'
7
- import { DeviceListSchema } from './DeviceList.schema'
7
+ import { DeviceListResponseSchema } from './DeviceListResponse.schema'
8
8
 
9
- export const PaginatedDeviceListListSchema = z.object({
9
+ export const PaginatedDeviceListResponseListSchema = z.object({
10
10
  count: z.int(),
11
11
  page: z.int(),
12
12
  pages: z.int(),
@@ -15,10 +15,10 @@ export const PaginatedDeviceListListSchema = z.object({
15
15
  has_previous: z.boolean(),
16
16
  next_page: z.int().nullable().optional(),
17
17
  previous_page: z.int().nullable().optional(),
18
- results: z.array(DeviceListSchema),
18
+ results: z.array(DeviceListResponseSchema),
19
19
  })
20
20
 
21
21
  /**
22
22
  * Infer TypeScript type from Zod schema
23
23
  */
24
- export type PaginatedDeviceListList = z.infer<typeof PaginatedDeviceListListSchema>
24
+ export type PaginatedDeviceListResponseList = z.infer<typeof PaginatedDeviceListResponseListSchema>
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Zod schema for TotpVerifyUser
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * User data returned after 2FA verification.
6
+ * */
7
+ import { z } from 'zod'
8
+
9
+ /**
10
+ * User data returned after 2FA verification.
11
+ */
12
+ export const TotpVerifyUserSchema = z.object({
13
+ id: z.int(),
14
+ email: z.email(),
15
+ first_name: z.string().max(50).optional(),
16
+ last_name: z.string().max(50).optional(),
17
+ full_name: z.string(),
18
+ initials: z.string(),
19
+ display_username: z.string(),
20
+ company: z.string().max(100).optional(),
21
+ phone: z.string().max(20).optional(),
22
+ position: z.string().max(100).optional(),
23
+ avatar: z.union([z.url(), z.literal('')]).nullable(),
24
+ is_staff: z.boolean(),
25
+ is_superuser: z.boolean(),
26
+ date_joined: z.iso.datetime(),
27
+ last_login: z.iso.datetime().nullable(),
28
+ unanswered_messages_count: z.int(),
29
+ })
30
+
31
+ /**
32
+ * Infer TypeScript type from Zod schema
33
+ */
34
+ export type TotpVerifyUser = z.infer<typeof TotpVerifyUserSchema>
@@ -5,6 +5,7 @@
5
5
  * * Response serializer for successful 2FA verification.
6
6
  * */
7
7
  import { z } from 'zod'
8
+ import { TotpVerifyUserSchema } from './TotpVerifyUser.schema'
8
9
 
9
10
  /**
10
11
  * Response serializer for successful 2FA verification.
@@ -13,7 +14,7 @@ export const VerifyResponseSchema = z.object({
13
14
  message: z.string(),
14
15
  access_token: z.string(),
15
16
  refresh_token: z.string(),
16
- user: z.record(z.string(), z.any()),
17
+ user: TotpVerifyUserSchema,
17
18
  remaining_backup_codes: z.int().optional(),
18
19
  warning: z.string().optional(),
19
20
  })
@@ -23,10 +23,12 @@ export * from './BackupCodesStatus.schema'
23
23
  export * from './ConfirmSetupRequest.schema'
24
24
  export * from './ConfirmSetupResponse.schema'
25
25
  export * from './DeviceList.schema'
26
+ export * from './DeviceListResponse.schema'
26
27
  export * from './DisableRequest.schema'
27
- export * from './PaginatedDeviceListList.schema'
28
+ export * from './PaginatedDeviceListResponseList.schema'
28
29
  export * from './SetupRequest.schema'
29
30
  export * from './SetupResponse.schema'
31
+ export * from './TotpVerifyUser.schema'
30
32
  export * from './VerifyBackupRequest.schema'
31
33
  export * from './VerifyRequest.schema'
32
34
  export * from './VerifyResponse.schema'
@@ -135,7 +135,7 @@
135
135
  "content": {
136
136
  "application/json": {
137
137
  "schema": {
138
- "$ref": "#/components/schemas/PaginatedDeviceListList"
138
+ "$ref": "#/components/schemas/PaginatedDeviceListResponseList"
139
139
  }
140
140
  }
141
141
  },
@@ -640,6 +640,25 @@
640
640
  "status"
641
641
  ]
642
642
  },
643
+ "DeviceListResponse": {
644
+ "type": "object",
645
+ "description": "Response serializer for device list endpoint.",
646
+ "properties": {
647
+ "devices": {
648
+ "type": "array",
649
+ "items": {
650
+ "$ref": "#/components/schemas/DeviceList"
651
+ }
652
+ },
653
+ "has_2fa_enabled": {
654
+ "type": "boolean"
655
+ }
656
+ },
657
+ "required": [
658
+ "devices",
659
+ "has_2fa_enabled"
660
+ ]
661
+ },
643
662
  "DisableRequest": {
644
663
  "type": "object",
645
664
  "description": "Serializer for completely disabling 2FA.",
@@ -655,7 +674,7 @@
655
674
  "code"
656
675
  ]
657
676
  },
658
- "PaginatedDeviceListList": {
677
+ "PaginatedDeviceListResponseList": {
659
678
  "type": "object",
660
679
  "required": [
661
680
  "count",
@@ -712,7 +731,7 @@
712
731
  "results": {
713
732
  "type": "array",
714
733
  "items": {
715
- "$ref": "#/components/schemas/DeviceList"
734
+ "$ref": "#/components/schemas/DeviceListResponse"
716
735
  },
717
736
  "description": "Array of items for current page"
718
737
  }
@@ -765,6 +784,103 @@
765
784
  "secret"
766
785
  ]
767
786
  },
787
+ "TotpVerifyUser": {
788
+ "type": "object",
789
+ "description": "User data returned after 2FA verification.",
790
+ "properties": {
791
+ "id": {
792
+ "type": "integer",
793
+ "readOnly": true
794
+ },
795
+ "email": {
796
+ "type": "string",
797
+ "format": "email",
798
+ "readOnly": true
799
+ },
800
+ "first_name": {
801
+ "type": "string",
802
+ "maxLength": 50
803
+ },
804
+ "last_name": {
805
+ "type": "string",
806
+ "maxLength": 50
807
+ },
808
+ "full_name": {
809
+ "type": "string",
810
+ "description": "Get user's full name.",
811
+ "readOnly": true
812
+ },
813
+ "initials": {
814
+ "type": "string",
815
+ "description": "Get user's initials for avatar fallback.",
816
+ "readOnly": true
817
+ },
818
+ "display_username": {
819
+ "type": "string",
820
+ "description": "Get formatted username for display.",
821
+ "readOnly": true
822
+ },
823
+ "company": {
824
+ "type": "string",
825
+ "maxLength": 100
826
+ },
827
+ "phone": {
828
+ "type": "string",
829
+ "maxLength": 20
830
+ },
831
+ "position": {
832
+ "type": "string",
833
+ "maxLength": 100
834
+ },
835
+ "avatar": {
836
+ "type": "string",
837
+ "format": "uri",
838
+ "nullable": true,
839
+ "readOnly": true
840
+ },
841
+ "is_staff": {
842
+ "type": "boolean",
843
+ "readOnly": true,
844
+ "title": "Staff status",
845
+ "description": "Designates whether the user can log into this admin site."
846
+ },
847
+ "is_superuser": {
848
+ "type": "boolean",
849
+ "readOnly": true,
850
+ "title": "Superuser status",
851
+ "description": "Designates that this user has all permissions without explicitly assigning them."
852
+ },
853
+ "date_joined": {
854
+ "type": "string",
855
+ "format": "date-time",
856
+ "readOnly": true
857
+ },
858
+ "last_login": {
859
+ "type": "string",
860
+ "format": "date-time",
861
+ "readOnly": true,
862
+ "nullable": true
863
+ },
864
+ "unanswered_messages_count": {
865
+ "type": "integer",
866
+ "readOnly": true,
867
+ "default": 0
868
+ }
869
+ },
870
+ "required": [
871
+ "avatar",
872
+ "date_joined",
873
+ "display_username",
874
+ "email",
875
+ "full_name",
876
+ "id",
877
+ "initials",
878
+ "is_staff",
879
+ "is_superuser",
880
+ "last_login",
881
+ "unanswered_messages_count"
882
+ ]
883
+ },
768
884
  "VerifyBackupRequest": {
769
885
  "type": "object",
770
886
  "description": "Serializer for backup code verification during login.",
@@ -823,8 +939,11 @@
823
939
  "description": "JWT refresh token"
824
940
  },
825
941
  "user": {
826
- "type": "object",
827
- "additionalProperties": {},
942
+ "allOf": [
943
+ {
944
+ "$ref": "#/components/schemas/TotpVerifyUser"
945
+ }
946
+ ],
828
947
  "description": "User profile data"
829
948
  },
830
949
  "remaining_backup_codes": {
@@ -11,13 +11,13 @@ export class TotpManagement {
11
11
  this.client = client;
12
12
  }
13
13
 
14
- async totpDevicesList(page?: number, page_size?: number): Promise<Models.PaginatedDeviceListList>;
15
- async totpDevicesList(params?: { page?: number; page_size?: number }): Promise<Models.PaginatedDeviceListList>;
14
+ async totpDevicesList(page?: number, page_size?: number): Promise<Models.PaginatedDeviceListResponseList>;
15
+ async totpDevicesList(params?: { page?: number; page_size?: number }): Promise<Models.PaginatedDeviceListResponseList>;
16
16
 
17
17
  /**
18
18
  * List all TOTP devices for user.
19
19
  */
20
- async totpDevicesList(...args: any[]): Promise<Models.PaginatedDeviceListList> {
20
+ async totpDevicesList(...args: any[]): Promise<Models.PaginatedDeviceListResponseList> {
21
21
  const isParamsObject = args.length === 1 && typeof args[0] === 'object' && args[0] !== null && !Array.isArray(args[0]);
22
22
 
23
23
  let params;
@@ -5,7 +5,7 @@ import * as Enums from "../enums";
5
5
  *
6
6
  * Response model (includes read-only fields).
7
7
  */
8
- export interface PaginatedDeviceListList {
8
+ export interface PaginatedDeviceListResponseList {
9
9
  /** Total number of items across all pages */
10
10
  count: number;
11
11
  /** Current page number (1-based) */
@@ -23,7 +23,7 @@ export interface PaginatedDeviceListList {
23
23
  /** Previous page number (null if no previous page) */
24
24
  previous_page?: number | null;
25
25
  /** Array of items for current page */
26
- results: Array<DeviceList>;
26
+ results: Array<DeviceListResponse>;
27
27
  }
28
28
 
29
29
  /**
@@ -36,6 +36,16 @@ export interface DisableRequest {
36
36
  code: string;
37
37
  }
38
38
 
39
+ /**
40
+ * Response serializer for device list endpoint.
41
+ *
42
+ * Response model (includes read-only fields).
43
+ */
44
+ export interface DeviceListResponse {
45
+ devices: Array<DeviceList>;
46
+ has_2fa_enabled: boolean;
47
+ }
48
+
39
49
  /**
40
50
  * Serializer for listing TOTP devices.
41
51
  *
@@ -22,8 +22,7 @@ export interface VerifyResponse {
22
22
  access_token: string;
23
23
  /** JWT refresh token */
24
24
  refresh_token: string;
25
- /** User profile data */
26
- user: Record<string, any>;
25
+ user: TotpVerifyUser;
27
26
  /** Number of remaining backup codes (if backup code was used) */
28
27
  remaining_backup_codes?: number;
29
28
  /** Warning message (e.g., low backup codes) */
@@ -42,3 +41,32 @@ export interface VerifyBackupRequest {
42
41
  backup_code: string;
43
42
  }
44
43
 
44
+ /**
45
+ * User data returned after 2FA verification.
46
+ *
47
+ * Response model (includes read-only fields).
48
+ */
49
+ export interface TotpVerifyUser {
50
+ id: number;
51
+ email: string;
52
+ first_name?: string;
53
+ last_name?: string;
54
+ /** Get user's full name. */
55
+ full_name: string;
56
+ /** Get user's initials for avatar fallback. */
57
+ initials: string;
58
+ /** Get formatted username for display. */
59
+ display_username: string;
60
+ company?: string;
61
+ phone?: string;
62
+ position?: string;
63
+ avatar?: string | null;
64
+ /** Designates whether the user can log into this admin site. */
65
+ is_staff: boolean;
66
+ /** Designates that this user has all permissions without explicitly assigning them. */
67
+ is_superuser: boolean;
68
+ date_joined: string;
69
+ last_login?: string | null;
70
+ unanswered_messages_count: number;
71
+ }
72
+