@djangocfg/api 2.1.262 → 2.1.264
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/dist/auth-server.cjs +9 -0
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +9 -0
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +76 -72
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +76 -72
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +122 -80
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +129 -172
- package/dist/clients.d.ts +129 -172
- package/dist/clients.mjs +122 -80
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +47 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +80 -57
- package/dist/hooks.d.ts +80 -57
- package/dist/hooks.mjs +47 -1
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +56 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -99
- package/dist/index.d.ts +99 -99
- package/dist/index.mjs +56 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts +46 -2
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__oauth.ts +3 -2
- package/src/_api/generated/cfg_accounts/accounts/models.ts +34 -34
- package/src/_api/generated/cfg_accounts/accounts__oauth/client.ts +1 -1
- package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +54 -54
- package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +14 -14
- package/src/_api/generated/cfg_accounts/client.ts +8 -0
- package/src/_api/generated/cfg_accounts/errors.ts +5 -0
- package/src/_api/generated/cfg_centrifugo/client.ts +8 -0
- package/src/_api/generated/cfg_centrifugo/errors.ts +5 -0
- package/src/_api/generated/cfg_totp/CLAUDE.md +3 -3
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_management.ts +7 -7
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_management.ts +5 -5
- package/src/_api/generated/cfg_totp/_utils/schemas/index.ts +0 -1
- package/src/_api/generated/cfg_totp/client.ts +8 -0
- package/src/_api/generated/cfg_totp/errors.ts +5 -0
- package/src/_api/generated/cfg_totp/schema.json +2 -103
- package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +10 -10
- package/src/_api/generated/cfg_totp/totp__totp_management/client.ts +2 -13
- package/src/_api/generated/cfg_totp/totp__totp_management/models.ts +9 -34
- package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +12 -12
- package/src/_api/generated/cfg_totp/totp__totp_verification/models.ts +8 -8
- package/src/auth/hooks/useTwoFactorStatus.ts +5 -11
- package/src/_api/generated/cfg_totp/_utils/schemas/PaginatedDeviceListResponseList.schema.ts +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.264",
|
|
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.1.0",
|
|
87
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
87
|
+
"@djangocfg/typescript-config": "^2.1.264",
|
|
88
88
|
"next": "^16.0.10",
|
|
89
89
|
"react": "^19.1.0",
|
|
90
90
|
"tsup": "^8.5.0",
|
|
@@ -35,6 +35,7 @@ import { consola } from 'consola'
|
|
|
35
35
|
import { OAuthAuthorizeRequestRequestSchema, type OAuthAuthorizeRequestRequest } from '../schemas/OAuthAuthorizeRequestRequest.schema'
|
|
36
36
|
import { OAuthAuthorizeResponseSchema, type OAuthAuthorizeResponse } from '../schemas/OAuthAuthorizeResponse.schema'
|
|
37
37
|
import { OAuthCallbackRequestRequestSchema, type OAuthCallbackRequestRequest } from '../schemas/OAuthCallbackRequestRequest.schema'
|
|
38
|
+
import { OAuthConnectionSchema, type OAuthConnection } from '../schemas/OAuthConnection.schema'
|
|
38
39
|
import { OAuthDisconnectRequestRequestSchema, type OAuthDisconnectRequestRequest } from '../schemas/OAuthDisconnectRequestRequest.schema'
|
|
39
40
|
import { OAuthProvidersResponseSchema, type OAuthProvidersResponse } from '../schemas/OAuthProvidersResponse.schema'
|
|
40
41
|
import { OAuthTokenResponseSchema, type OAuthTokenResponse } from '../schemas/OAuthTokenResponse.schema'
|
|
@@ -47,10 +48,53 @@ import { getAPIInstance } from '../../api-instance'
|
|
|
47
48
|
* @path /cfg/accounts/oauth/connections/
|
|
48
49
|
*/
|
|
49
50
|
export async function getAccountsOauthConnectionsList( client?: any
|
|
50
|
-
): Promise<
|
|
51
|
+
): Promise<OAuthConnection[]> {
|
|
51
52
|
const api = client || getAPIInstance()
|
|
52
53
|
const response = await api.oauth.accountsOauthConnectionsList()
|
|
53
|
-
|
|
54
|
+
try {
|
|
55
|
+
return OAuthConnectionSchema.array().parse(response)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
// Zod validation error - log detailed information
|
|
58
|
+
consola.error('❌ Zod Validation Failed');
|
|
59
|
+
consola.box(`getAccountsOauthConnectionsList\nPath: /cfg/accounts/oauth/connections/\nMethod: GET`);
|
|
60
|
+
|
|
61
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
62
|
+
consola.error('Validation Issues:');
|
|
63
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
64
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
65
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
66
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
67
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
consola.error('Response data:', response);
|
|
72
|
+
|
|
73
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
74
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
75
|
+
try {
|
|
76
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
77
|
+
detail: {
|
|
78
|
+
operation: 'getAccountsOauthConnectionsList',
|
|
79
|
+
path: '/cfg/accounts/oauth/connections/',
|
|
80
|
+
method: 'GET',
|
|
81
|
+
error: error,
|
|
82
|
+
response: response,
|
|
83
|
+
timestamp: new Date(),
|
|
84
|
+
},
|
|
85
|
+
bubbles: true,
|
|
86
|
+
cancelable: false,
|
|
87
|
+
});
|
|
88
|
+
window.dispatchEvent(event);
|
|
89
|
+
} catch (eventError) {
|
|
90
|
+
// Silently fail - event dispatch should never crash the app
|
|
91
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Re-throw the error
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
54
98
|
}
|
|
55
99
|
|
|
56
100
|
|
|
@@ -25,6 +25,7 @@ import type { API } from '../../index'
|
|
|
25
25
|
import type { OAuthAuthorizeRequestRequest } from '../schemas/OAuthAuthorizeRequestRequest.schema'
|
|
26
26
|
import type { OAuthAuthorizeResponse } from '../schemas/OAuthAuthorizeResponse.schema'
|
|
27
27
|
import type { OAuthCallbackRequestRequest } from '../schemas/OAuthCallbackRequestRequest.schema'
|
|
28
|
+
import type { OAuthConnection } from '../schemas/OAuthConnection.schema'
|
|
28
29
|
import type { OAuthDisconnectRequestRequest } from '../schemas/OAuthDisconnectRequestRequest.schema'
|
|
29
30
|
import type { OAuthProvidersResponse } from '../schemas/OAuthProvidersResponse.schema'
|
|
30
31
|
import type { OAuthTokenResponse } from '../schemas/OAuthTokenResponse.schema'
|
|
@@ -35,8 +36,8 @@ import type { OAuthTokenResponse } from '../schemas/OAuthTokenResponse.schema'
|
|
|
35
36
|
* @method GET
|
|
36
37
|
* @path /cfg/accounts/oauth/connections/
|
|
37
38
|
*/
|
|
38
|
-
export function useAccountsOauthConnectionsList(client?: API): ReturnType<typeof useSWR<
|
|
39
|
-
return useSWR<
|
|
39
|
+
export function useAccountsOauthConnectionsList(client?: API): ReturnType<typeof useSWR<OAuthConnection[]>> {
|
|
40
|
+
return useSWR<OAuthConnection[]>(
|
|
40
41
|
'cfg-accounts-oauth-connections',
|
|
41
42
|
() => Fetchers.getAccountsOauthConnectionsList(client)
|
|
42
43
|
)
|
|
@@ -13,6 +13,40 @@ export interface OTPVerifyRequest {
|
|
|
13
13
|
source_url?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* OTP verification response. When 2FA is required: - requires_2fa: True -
|
|
18
|
+
* session_id: UUID of 2FA verification session - refresh/access/user: null
|
|
19
|
+
* When 2FA is not required: - requires_2fa: False - session_id: null -
|
|
20
|
+
* refresh/access/user: populated
|
|
21
|
+
*
|
|
22
|
+
* Response model (includes read-only fields).
|
|
23
|
+
*/
|
|
24
|
+
export interface OTPVerifyResponse {
|
|
25
|
+
/** Whether 2FA verification is required */
|
|
26
|
+
requires_2fa?: boolean;
|
|
27
|
+
/** 2FA session ID (if requires_2fa is True) */
|
|
28
|
+
session_id?: string | null;
|
|
29
|
+
/** JWT refresh token (if requires_2fa is False) */
|
|
30
|
+
refresh?: string | null;
|
|
31
|
+
/** JWT access token (if requires_2fa is False) */
|
|
32
|
+
access?: string | null;
|
|
33
|
+
user?: User | null;
|
|
34
|
+
/** Whether user should be prompted to enable 2FA */
|
|
35
|
+
should_prompt_2fa?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Serializer for OTP request.
|
|
40
|
+
*
|
|
41
|
+
* Request model (no read-only fields).
|
|
42
|
+
*/
|
|
43
|
+
export interface OTPRequestRequest {
|
|
44
|
+
/** Email address for OTP delivery */
|
|
45
|
+
identifier: string;
|
|
46
|
+
/** Source URL for tracking registration (e.g., https://my.djangocfg.com) */
|
|
47
|
+
source_url?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
16
50
|
/**
|
|
17
51
|
* OTP request response.
|
|
18
52
|
*
|
|
@@ -44,40 +78,6 @@ export interface OTPErrorResponse {
|
|
|
44
78
|
retry_after?: number | null;
|
|
45
79
|
}
|
|
46
80
|
|
|
47
|
-
/**
|
|
48
|
-
* Serializer for OTP request.
|
|
49
|
-
*
|
|
50
|
-
* Request model (no read-only fields).
|
|
51
|
-
*/
|
|
52
|
-
export interface OTPRequestRequest {
|
|
53
|
-
/** Email address for OTP delivery */
|
|
54
|
-
identifier: string;
|
|
55
|
-
/** Source URL for tracking registration (e.g., https://my.djangocfg.com) */
|
|
56
|
-
source_url?: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* OTP verification response. When 2FA is required: - requires_2fa: True -
|
|
61
|
-
* session_id: UUID of 2FA verification session - refresh/access/user: null
|
|
62
|
-
* When 2FA is not required: - requires_2fa: False - session_id: null -
|
|
63
|
-
* refresh/access/user: populated
|
|
64
|
-
*
|
|
65
|
-
* Response model (includes read-only fields).
|
|
66
|
-
*/
|
|
67
|
-
export interface OTPVerifyResponse {
|
|
68
|
-
/** Whether 2FA verification is required */
|
|
69
|
-
requires_2fa?: boolean;
|
|
70
|
-
/** 2FA session ID (if requires_2fa is True) */
|
|
71
|
-
session_id?: string | null;
|
|
72
|
-
/** JWT refresh token (if requires_2fa is False) */
|
|
73
|
-
refresh?: string | null;
|
|
74
|
-
/** JWT access token (if requires_2fa is False) */
|
|
75
|
-
access?: string | null;
|
|
76
|
-
user?: User | null;
|
|
77
|
-
/** Whether user should be prompted to enable 2FA */
|
|
78
|
-
should_prompt_2fa?: boolean;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
81
|
/**
|
|
82
82
|
* Serializer for user details.
|
|
83
83
|
*
|
|
@@ -17,7 +17,7 @@ export class Oauth {
|
|
|
17
17
|
*
|
|
18
18
|
* Get all OAuth connections for the current user.
|
|
19
19
|
*/
|
|
20
|
-
async accountsOauthConnectionsList(): Promise<
|
|
20
|
+
async accountsOauthConnectionsList(): Promise<Models.OAuthConnection[]> {
|
|
21
21
|
const response = await this.client.request('GET', "/cfg/accounts/oauth/connections/");
|
|
22
22
|
return (response as any).results || response;
|
|
23
23
|
}
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
// Auto-generated by DjangoCFG - see CLAUDE.md
|
|
3
3
|
import * as Enums from "../enums";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Error response for OAuth endpoints.
|
|
7
|
+
*
|
|
8
|
+
* Response model (includes read-only fields).
|
|
9
|
+
*/
|
|
10
|
+
export interface OAuthError {
|
|
11
|
+
/** Error code */
|
|
12
|
+
error: string;
|
|
13
|
+
/** Human-readable error description */
|
|
14
|
+
error_description?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
/**
|
|
6
18
|
* Response with available OAuth providers.
|
|
7
19
|
*
|
|
@@ -13,27 +25,53 @@ export interface OAuthProvidersResponse {
|
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
28
|
+
* Response with OAuth authorization URL.
|
|
17
29
|
*
|
|
18
|
-
*
|
|
30
|
+
* Response model (includes read-only fields).
|
|
19
31
|
*/
|
|
20
|
-
export interface
|
|
21
|
-
/** OAuth provider
|
|
32
|
+
export interface OAuthAuthorizeResponse {
|
|
33
|
+
/** Full URL to redirect user to OAuth provider */
|
|
34
|
+
authorization_url: string;
|
|
35
|
+
/** State token for CSRF protection. Store this and verify on callback. */
|
|
36
|
+
state: string;
|
|
37
|
+
}
|
|
22
38
|
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Request to complete OAuth flow (callback handler).
|
|
41
|
+
*
|
|
42
|
+
* Request model (no read-only fields).
|
|
43
|
+
*/
|
|
44
|
+
export interface OAuthCallbackRequestRequest {
|
|
45
|
+
/** Authorization code from OAuth provider callback */
|
|
46
|
+
code: string;
|
|
47
|
+
/** State token for CSRF verification (from authorize response) */
|
|
48
|
+
state: string;
|
|
49
|
+
/** Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path */
|
|
50
|
+
redirect_uri?: string;
|
|
25
51
|
}
|
|
26
52
|
|
|
27
53
|
/**
|
|
28
|
-
*
|
|
54
|
+
* Serializer for OAuth connection info (user-facing).
|
|
29
55
|
*
|
|
30
56
|
* Response model (includes read-only fields).
|
|
31
57
|
*/
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
export interface OAuthConnection {
|
|
59
|
+
id: number;
|
|
60
|
+
/** OAuth provider name (github, google, etc.)
|
|
61
|
+
|
|
62
|
+
* `github` - GitHub */
|
|
63
|
+
provider: Enums.OAuthConnectionProvider;
|
|
64
|
+
provider_display: string;
|
|
65
|
+
/** Username on the OAuth provider platform */
|
|
66
|
+
provider_username: string;
|
|
67
|
+
/** Email from OAuth provider (may differ from user.email) */
|
|
68
|
+
provider_email: string;
|
|
69
|
+
/** Avatar URL from OAuth provider */
|
|
70
|
+
provider_avatar_url: string;
|
|
71
|
+
/** When this OAuth connection was created */
|
|
72
|
+
connected_at: string;
|
|
73
|
+
/** Last time this OAuth connection was used for login */
|
|
74
|
+
last_login_at: string;
|
|
37
75
|
}
|
|
38
76
|
|
|
39
77
|
/**
|
|
@@ -76,52 +114,14 @@ export interface OAuthTokenResponse {
|
|
|
76
114
|
}
|
|
77
115
|
|
|
78
116
|
/**
|
|
79
|
-
*
|
|
117
|
+
* Request to disconnect OAuth provider.
|
|
80
118
|
*
|
|
81
|
-
*
|
|
119
|
+
* Request model (no read-only fields).
|
|
82
120
|
*/
|
|
83
|
-
export interface
|
|
84
|
-
|
|
85
|
-
/** OAuth provider name (github, google, etc.)
|
|
121
|
+
export interface OAuthDisconnectRequestRequest {
|
|
122
|
+
/** OAuth provider to disconnect
|
|
86
123
|
|
|
87
124
|
* `github` - GitHub */
|
|
88
125
|
provider: Enums.OAuthConnectionProvider;
|
|
89
|
-
provider_display: string;
|
|
90
|
-
/** Username on the OAuth provider platform */
|
|
91
|
-
provider_username: string;
|
|
92
|
-
/** Email from OAuth provider (may differ from user.email) */
|
|
93
|
-
provider_email: string;
|
|
94
|
-
/** Avatar URL from OAuth provider */
|
|
95
|
-
provider_avatar_url: string;
|
|
96
|
-
/** When this OAuth connection was created */
|
|
97
|
-
connected_at: string;
|
|
98
|
-
/** Last time this OAuth connection was used for login */
|
|
99
|
-
last_login_at: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Response with OAuth authorization URL.
|
|
104
|
-
*
|
|
105
|
-
* Response model (includes read-only fields).
|
|
106
|
-
*/
|
|
107
|
-
export interface OAuthAuthorizeResponse {
|
|
108
|
-
/** Full URL to redirect user to OAuth provider */
|
|
109
|
-
authorization_url: string;
|
|
110
|
-
/** State token for CSRF protection. Store this and verify on callback. */
|
|
111
|
-
state: string;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Request to complete OAuth flow (callback handler).
|
|
116
|
-
*
|
|
117
|
-
* Request model (no read-only fields).
|
|
118
|
-
*/
|
|
119
|
-
export interface OAuthCallbackRequestRequest {
|
|
120
|
-
/** Authorization code from OAuth provider callback */
|
|
121
|
-
code: string;
|
|
122
|
-
/** State token for CSRF verification (from authorize response) */
|
|
123
|
-
state: string;
|
|
124
|
-
/** Same redirect_uri used in authorize request. If not provided, uses config's site_url + callback_path */
|
|
125
|
-
redirect_uri?: string;
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
// Auto-generated by DjangoCFG - see CLAUDE.md
|
|
3
|
+
/**
|
|
4
|
+
* Serializer for updating user profile.
|
|
5
|
+
*
|
|
6
|
+
* Request model (no read-only fields).
|
|
7
|
+
*/
|
|
8
|
+
export interface UserProfileUpdateRequest {
|
|
9
|
+
first_name?: string;
|
|
10
|
+
last_name?: string;
|
|
11
|
+
company?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
position?: string;
|
|
14
|
+
language?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
3
17
|
/**
|
|
4
18
|
* Serializer for updating user profile.
|
|
5
19
|
*
|
|
@@ -57,20 +71,6 @@ export interface AccountDeleteResponse {
|
|
|
57
71
|
message: string;
|
|
58
72
|
}
|
|
59
73
|
|
|
60
|
-
/**
|
|
61
|
-
* Serializer for updating user profile.
|
|
62
|
-
*
|
|
63
|
-
* Request model (no read-only fields).
|
|
64
|
-
*/
|
|
65
|
-
export interface UserProfileUpdateRequest {
|
|
66
|
-
first_name?: string;
|
|
67
|
-
last_name?: string;
|
|
68
|
-
company?: string;
|
|
69
|
-
phone?: string;
|
|
70
|
-
position?: string;
|
|
71
|
-
language?: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
74
|
/**
|
|
75
75
|
*
|
|
76
76
|
* Request model (no read-only fields).
|
|
@@ -166,6 +166,14 @@ export class APIClient {
|
|
|
166
166
|
// CSRF not needed - SessionAuthentication not enabled in DRF config
|
|
167
167
|
// Your API uses JWT/Token authentication (no CSRF required)
|
|
168
168
|
|
|
169
|
+
// Add Authorization header from tokenGetter (Bearer token / API key)
|
|
170
|
+
if (!headers['Authorization']) {
|
|
171
|
+
const token = this.getToken();
|
|
172
|
+
if (token) {
|
|
173
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
169
177
|
// Log request
|
|
170
178
|
if (this.logger) {
|
|
171
179
|
this.logger.logRequest({
|
|
@@ -78,6 +78,11 @@ export class APIError extends Error {
|
|
|
78
78
|
return Array.isArray(details.detail) ? details.detail.join(', ') : String(details.detail);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// Check for "error" field (common in custom DRF views)
|
|
82
|
+
if (details.error) {
|
|
83
|
+
return String(details.error);
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
// Check for "message" field
|
|
82
87
|
if (details.message) {
|
|
83
88
|
return String(details.message);
|
|
@@ -157,6 +157,14 @@ export class APIClient {
|
|
|
157
157
|
// CSRF not needed - SessionAuthentication not enabled in DRF config
|
|
158
158
|
// Your API uses JWT/Token authentication (no CSRF required)
|
|
159
159
|
|
|
160
|
+
// Add Authorization header from tokenGetter (Bearer token / API key)
|
|
161
|
+
if (!headers['Authorization']) {
|
|
162
|
+
const token = this.getToken();
|
|
163
|
+
if (token) {
|
|
164
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
160
168
|
// Log request
|
|
161
169
|
if (this.logger) {
|
|
162
170
|
this.logger.logRequest({
|
|
@@ -78,6 +78,11 @@ export class APIError extends Error {
|
|
|
78
78
|
return Array.isArray(details.detail) ? details.detail.join(', ') : String(details.detail);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// Check for "error" field (common in custom DRF views)
|
|
82
|
+
if (details.error) {
|
|
83
|
+
return String(details.error);
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
// Check for "message" field
|
|
82
87
|
if (details.message) {
|
|
83
88
|
return String(details.message);
|
|
@@ -12,7 +12,7 @@ python manage.py generate_client --groups cfg_totp --typescript
|
|
|
12
12
|
|---|---|
|
|
13
13
|
| Version | 3.1.0 |
|
|
14
14
|
| Operations | 9 |
|
|
15
|
-
| Schemas |
|
|
15
|
+
| Schemas | 14 |
|
|
16
16
|
|
|
17
17
|
## Resources
|
|
18
18
|
|
|
@@ -29,7 +29,7 @@ python manage.py generate_client --groups cfg_totp --typescript
|
|
|
29
29
|
- `GET` /cfg/totp/backup-codes/ → `cfg_totp_backup_codes_retrieve`
|
|
30
30
|
|
|
31
31
|
**TOTP Management:**
|
|
32
|
-
- `GET` /cfg/totp/devices/ → `
|
|
32
|
+
- `GET` /cfg/totp/devices/ → `cfg_totp_devices_retrieve`
|
|
33
33
|
- `POST` /cfg/totp/disable/ → `cfg_totp_disable_create`
|
|
34
34
|
|
|
35
35
|
**TOTP Setup:**
|
|
@@ -52,7 +52,7 @@ const client = new APIClient({ baseUrl, token });
|
|
|
52
52
|
|
|
53
53
|
await client.backup codes.retrieve({ id: 1 });
|
|
54
54
|
await client.backup codes.create({ ... });
|
|
55
|
-
await client.totp management.
|
|
55
|
+
await client.totp management.retrieve({ id: 1 });
|
|
56
56
|
await client.totp management.create({ ... });
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
import { consola } from 'consola'
|
|
35
|
+
import { DeviceListResponseSchema, type DeviceListResponse } from '../schemas/DeviceListResponse.schema'
|
|
35
36
|
import { DisableRequestSchema, type DisableRequest } from '../schemas/DisableRequest.schema'
|
|
36
|
-
import { PaginatedDeviceListResponseListSchema, type PaginatedDeviceListResponseList } from '../schemas/PaginatedDeviceListResponseList.schema'
|
|
37
37
|
import { getAPIInstance } from '../../api-instance'
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -42,16 +42,16 @@ import { getAPIInstance } from '../../api-instance'
|
|
|
42
42
|
* @method GET
|
|
43
43
|
* @path /cfg/totp/devices/
|
|
44
44
|
*/
|
|
45
|
-
export async function
|
|
46
|
-
): Promise<
|
|
45
|
+
export async function getTotpDevicesRetrieve( client?: any
|
|
46
|
+
): Promise<DeviceListResponse> {
|
|
47
47
|
const api = client || getAPIInstance()
|
|
48
|
-
const response = await api.totp_management.
|
|
48
|
+
const response = await api.totp_management.totpDevicesRetrieve()
|
|
49
49
|
try {
|
|
50
|
-
return
|
|
50
|
+
return DeviceListResponseSchema.parse(response)
|
|
51
51
|
} catch (error) {
|
|
52
52
|
// Zod validation error - log detailed information
|
|
53
53
|
consola.error('❌ Zod Validation Failed');
|
|
54
|
-
consola.box(`
|
|
54
|
+
consola.box(`getTotpDevicesRetrieve\nPath: /cfg/totp/devices/\nMethod: GET`);
|
|
55
55
|
|
|
56
56
|
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
57
57
|
consola.error('Validation Issues:');
|
|
@@ -70,7 +70,7 @@ export async function getTotpDevicesList( params?: { ordering?: string; page?:
|
|
|
70
70
|
try {
|
|
71
71
|
const event = new CustomEvent('zod-validation-error', {
|
|
72
72
|
detail: {
|
|
73
|
-
operation: '
|
|
73
|
+
operation: 'getTotpDevicesRetrieve',
|
|
74
74
|
path: '/cfg/totp/devices/',
|
|
75
75
|
method: 'GET',
|
|
76
76
|
error: error,
|
|
@@ -22,8 +22,8 @@ import useSWR from 'swr'
|
|
|
22
22
|
import { useSWRConfig } from 'swr'
|
|
23
23
|
import * as Fetchers from '../fetchers/totp__totp_management'
|
|
24
24
|
import type { API } from '../../index'
|
|
25
|
+
import type { DeviceListResponse } from '../schemas/DeviceListResponse.schema'
|
|
25
26
|
import type { DisableRequest } from '../schemas/DisableRequest.schema'
|
|
26
|
-
import type { PaginatedDeviceListResponseList } from '../schemas/PaginatedDeviceListResponseList.schema'
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* API operation
|
|
@@ -31,10 +31,10 @@ import type { PaginatedDeviceListResponseList } from '../schemas/PaginatedDevice
|
|
|
31
31
|
* @method GET
|
|
32
32
|
* @path /cfg/totp/devices/
|
|
33
33
|
*/
|
|
34
|
-
export function
|
|
35
|
-
return useSWR<
|
|
36
|
-
|
|
37
|
-
() => Fetchers.
|
|
34
|
+
export function useTotpDevicesRetrieve(client?: API): ReturnType<typeof useSWR<DeviceListResponse>> {
|
|
35
|
+
return useSWR<DeviceListResponse>(
|
|
36
|
+
'cfg-totp-device',
|
|
37
|
+
() => Fetchers.getTotpDevicesRetrieve(client)
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -26,7 +26,6 @@ export * from './ConfirmSetupResponse.schema'
|
|
|
26
26
|
export * from './DeviceList.schema'
|
|
27
27
|
export * from './DeviceListResponse.schema'
|
|
28
28
|
export * from './DisableRequest.schema'
|
|
29
|
-
export * from './PaginatedDeviceListResponseList.schema'
|
|
30
29
|
export * from './SetupRequest.schema'
|
|
31
30
|
export * from './SetupResponse.schema'
|
|
32
31
|
export * from './TotpVerifyUser.schema'
|
|
@@ -169,6 +169,14 @@ export class APIClient {
|
|
|
169
169
|
// CSRF not needed - SessionAuthentication not enabled in DRF config
|
|
170
170
|
// Your API uses JWT/Token authentication (no CSRF required)
|
|
171
171
|
|
|
172
|
+
// Add Authorization header from tokenGetter (Bearer token / API key)
|
|
173
|
+
if (!headers['Authorization']) {
|
|
174
|
+
const token = this.getToken();
|
|
175
|
+
if (token) {
|
|
176
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
172
180
|
// Log request
|
|
173
181
|
if (this.logger) {
|
|
174
182
|
this.logger.logRequest({
|
|
@@ -78,6 +78,11 @@ export class APIError extends Error {
|
|
|
78
78
|
return Array.isArray(details.detail) ? details.detail.join(', ') : String(details.detail);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// Check for "error" field (common in custom DRF views)
|
|
82
|
+
if (details.error) {
|
|
83
|
+
return String(details.error);
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
// Check for "message" field
|
|
82
87
|
if (details.message) {
|
|
83
88
|
return String(details.message);
|