@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
package/dist/auth.d.cts CHANGED
@@ -723,24 +723,6 @@ interface UseTwoFactorStatusReturn {
723
723
  /** Clear error */
724
724
  clearError: () => void;
725
725
  }
726
- /**
727
- * Hook for checking and managing 2FA status.
728
- *
729
- * @example
730
- * ```tsx
731
- * const { has2FAEnabled, devices, fetchStatus, disable2FA, isLoading } = useTwoFactorStatus();
732
- *
733
- * useEffect(() => {
734
- * fetchStatus();
735
- * }, [fetchStatus]);
736
- *
737
- * if (has2FAEnabled) {
738
- * // Show disable button
739
- * } else {
740
- * // Show enable button
741
- * }
742
- * ```
743
- */
744
726
  declare const useTwoFactorStatus: () => UseTwoFactorStatusReturn;
745
727
 
746
728
  interface AuthRedirectOptions {
package/dist/auth.d.ts CHANGED
@@ -723,24 +723,6 @@ interface UseTwoFactorStatusReturn {
723
723
  /** Clear error */
724
724
  clearError: () => void;
725
725
  }
726
- /**
727
- * Hook for checking and managing 2FA status.
728
- *
729
- * @example
730
- * ```tsx
731
- * const { has2FAEnabled, devices, fetchStatus, disable2FA, isLoading } = useTwoFactorStatus();
732
- *
733
- * useEffect(() => {
734
- * fetchStatus();
735
- * }, [fetchStatus]);
736
- *
737
- * if (has2FAEnabled) {
738
- * // Show disable button
739
- * } else {
740
- * // Show enable button
741
- * }
742
- * ```
743
- */
744
726
  declare const useTwoFactorStatus: () => UseTwoFactorStatusReturn;
745
727
 
746
728
  interface AuthRedirectOptions {
package/dist/auth.mjs CHANGED
@@ -2622,15 +2622,8 @@ var TotpManagement = class {
2622
2622
  /**
2623
2623
  * List all TOTP devices for user.
2624
2624
  */
2625
- async totpDevicesList(...args) {
2626
- const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
2627
- let params;
2628
- if (isParamsObject) {
2629
- params = args[0];
2630
- } else {
2631
- params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
2632
- }
2633
- const response = await this.client.request("GET", "/cfg/totp/devices/", { params });
2625
+ async totpDevicesRetrieve() {
2626
+ const response = await this.client.request("GET", "/cfg/totp/devices/");
2634
2627
  return response;
2635
2628
  }
2636
2629
  /**
@@ -3417,81 +3410,67 @@ var DisableRequestSchema = z30.object({
3417
3410
  code: z30.string().min(6).max(6)
3418
3411
  });
3419
3412
 
3420
- // src/_api/generated/cfg_totp/_utils/schemas/PaginatedDeviceListResponseList.schema.ts
3413
+ // src/_api/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts
3421
3414
  import { z as z31 } from "zod";
3422
- var PaginatedDeviceListResponseListSchema = z31.object({
3423
- count: z31.number().int(),
3424
- page: z31.number().int(),
3425
- pages: z31.number().int(),
3426
- page_size: z31.number().int(),
3427
- has_next: z31.boolean(),
3428
- has_previous: z31.boolean(),
3429
- next_page: z31.number().int().nullable().optional(),
3430
- previous_page: z31.number().int().nullable().optional(),
3431
- results: z31.array(DeviceListResponseSchema)
3415
+ var SetupRequestSchema = z31.object({
3416
+ device_name: z31.string().min(1).max(100).optional()
3432
3417
  });
3433
3418
 
3434
- // src/_api/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts
3419
+ // src/_api/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts
3435
3420
  import { z as z32 } from "zod";
3436
- var SetupRequestSchema = z32.object({
3437
- device_name: z32.string().min(1).max(100).optional()
3421
+ var SetupResponseSchema = z32.object({
3422
+ device_id: z32.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
3423
+ secret: z32.string(),
3424
+ provisioning_uri: z32.string(),
3425
+ qr_code_base64: z32.string(),
3426
+ expires_in: z32.number().int()
3438
3427
  });
3439
3428
 
3440
- // src/_api/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts
3429
+ // src/_api/generated/cfg_totp/_utils/schemas/TotpVerifyUser.schema.ts
3441
3430
  import { z as z33 } from "zod";
3442
- var SetupResponseSchema = z33.object({
3443
- device_id: z33.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
3444
- secret: z33.string(),
3445
- provisioning_uri: z33.string(),
3446
- qr_code_base64: z33.string(),
3447
- expires_in: z33.number().int()
3431
+ var TotpVerifyUserSchema = z33.object({
3432
+ id: z33.number().int(),
3433
+ email: z33.email(),
3434
+ first_name: z33.string().max(50).optional(),
3435
+ last_name: z33.string().max(50).optional(),
3436
+ full_name: z33.string(),
3437
+ initials: z33.string(),
3438
+ display_username: z33.string(),
3439
+ company: z33.string().max(100).optional(),
3440
+ phone: z33.string().max(20).optional(),
3441
+ position: z33.string().max(100).optional(),
3442
+ language: z33.string().max(10).optional(),
3443
+ avatar: z33.string().nullable(),
3444
+ is_staff: z33.boolean(),
3445
+ is_superuser: z33.boolean(),
3446
+ date_joined: z33.string().datetime({ offset: true }),
3447
+ last_login: z33.string().datetime({ offset: true }).nullable(),
3448
+ unanswered_messages_count: z33.number().int()
3448
3449
  });
3449
3450
 
3450
- // src/_api/generated/cfg_totp/_utils/schemas/TotpVerifyUser.schema.ts
3451
+ // src/_api/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts
3451
3452
  import { z as z34 } from "zod";
3452
- var TotpVerifyUserSchema = z34.object({
3453
- id: z34.number().int(),
3454
- email: z34.email(),
3455
- first_name: z34.string().max(50).optional(),
3456
- last_name: z34.string().max(50).optional(),
3457
- full_name: z34.string(),
3458
- initials: z34.string(),
3459
- display_username: z34.string(),
3460
- company: z34.string().max(100).optional(),
3461
- phone: z34.string().max(20).optional(),
3462
- position: z34.string().max(100).optional(),
3463
- language: z34.string().max(10).optional(),
3464
- avatar: z34.string().nullable(),
3465
- is_staff: z34.boolean(),
3466
- is_superuser: z34.boolean(),
3467
- date_joined: z34.string().datetime({ offset: true }),
3468
- last_login: z34.string().datetime({ offset: true }).nullable(),
3469
- unanswered_messages_count: z34.number().int()
3453
+ var VerifyBackupRequestSchema = z34.object({
3454
+ session_id: z34.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
3455
+ backup_code: z34.string().min(8).max(8)
3470
3456
  });
3471
3457
 
3472
- // src/_api/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts
3458
+ // src/_api/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts
3473
3459
  import { z as z35 } from "zod";
3474
- var VerifyBackupRequestSchema = z35.object({
3460
+ var VerifyRequestSchema = z35.object({
3475
3461
  session_id: z35.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
3476
- backup_code: z35.string().min(8).max(8)
3477
- });
3478
-
3479
- // src/_api/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts
3480
- import { z as z36 } from "zod";
3481
- var VerifyRequestSchema = z36.object({
3482
- session_id: z36.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
3483
- code: z36.string().min(6).max(6)
3462
+ code: z35.string().min(6).max(6)
3484
3463
  });
3485
3464
 
3486
3465
  // src/_api/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts
3487
- import { z as z37 } from "zod";
3488
- var VerifyResponseSchema = z37.object({
3489
- message: z37.string(),
3490
- access_token: z37.string(),
3491
- refresh_token: z37.string(),
3466
+ import { z as z36 } from "zod";
3467
+ var VerifyResponseSchema = z36.object({
3468
+ message: z36.string(),
3469
+ access_token: z36.string(),
3470
+ refresh_token: z36.string(),
3492
3471
  user: TotpVerifyUserSchema,
3493
- remaining_backup_codes: z37.number().int().optional(),
3494
- warning: z37.string().optional()
3472
+ remaining_backup_codes: z36.number().int().optional(),
3473
+ warning: z36.string().optional()
3495
3474
  });
3496
3475
 
3497
3476
  // src/_api/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts
@@ -4432,6 +4411,17 @@ var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
4432
4411
 
4433
4412
  // src/auth/hooks/useTwoFactorStatus.ts
4434
4413
  import { useCallback as useCallback8, useState as useState6 } from "react";
4414
+ function extractErrorMessage(err, fallback) {
4415
+ if (err instanceof APIError3) {
4416
+ const body = err.response;
4417
+ if (typeof body?.error === "string") return body.error;
4418
+ if (typeof body?.detail === "string") return body.detail;
4419
+ return err.message;
4420
+ }
4421
+ if (err instanceof Error) return err.message;
4422
+ return fallback;
4423
+ }
4424
+ __name(extractErrorMessage, "extractErrorMessage");
4435
4425
  var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4436
4426
  const [isLoading, setIsLoading] = useState6(false);
4437
4427
  const [error, setError] = useState6(null);
@@ -4445,9 +4435,8 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4445
4435
  setError(null);
4446
4436
  try {
4447
4437
  authLogger.info("Fetching 2FA status...");
4448
- const response = await apiTotp.totp_management.totpDevicesList();
4449
- const devices2 = response.results.flatMap((device) => device.devices);
4450
- const mappedDevices = devices2.map((device) => ({
4438
+ const response = await apiTotp.totp_management.totpDevicesRetrieve();
4439
+ const mappedDevices = response.devices.map((device) => ({
4451
4440
  id: device.id,
4452
4441
  name: device.name,
4453
4442
  createdAt: device.created_at,
@@ -4455,11 +4444,10 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4455
4444
  isPrimary: device.is_primary
4456
4445
  }));
4457
4446
  setDevices(mappedDevices);
4458
- const enabled = mappedDevices.length > 0;
4459
- setHas2FAEnabled(enabled);
4460
- authLogger.info("2FA status:", enabled ? "enabled" : "disabled");
4447
+ setHas2FAEnabled(response.has_2fa_enabled);
4448
+ authLogger.info("2FA status:", response.has_2fa_enabled ? "enabled" : "disabled");
4461
4449
  } catch (err) {
4462
- const errorMessage = err instanceof Error ? err.message : "Failed to fetch 2FA status";
4450
+ const errorMessage = extractErrorMessage(err, "Failed to fetch 2FA status");
4463
4451
  authLogger.error("Failed to fetch 2FA status:", err);
4464
4452
  setError(errorMessage);
4465
4453
  } finally {
@@ -4481,7 +4469,7 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
4481
4469
  authLogger.info("2FA disabled successfully");
4482
4470
  return true;
4483
4471
  } catch (err) {
4484
- const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
4472
+ const errorMessage = extractErrorMessage(err, "Invalid verification code");
4485
4473
  authLogger.error("Failed to disable 2FA:", err);
4486
4474
  setError(errorMessage);
4487
4475
  return false;