@djangocfg/api 2.1.541 → 2.1.543

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 (67) hide show
  1. package/README.md +1 -2
  2. package/dist/auth-server.cjs +1 -0
  3. package/dist/auth-server.cjs.map +1 -1
  4. package/dist/auth.cjs +156 -170
  5. package/dist/auth.cjs.map +1 -1
  6. package/dist/auth.d.cts +134 -29
  7. package/dist/auth.d.ts +134 -29
  8. package/dist/auth.mjs +168 -183
  9. package/dist/auth.mjs.map +1 -1
  10. package/dist/clients.cjs +4 -99
  11. package/dist/clients.cjs.map +1 -1
  12. package/dist/clients.d.cts +4 -136
  13. package/dist/clients.d.ts +4 -136
  14. package/dist/clients.mjs +3 -99
  15. package/dist/clients.mjs.map +1 -1
  16. package/dist/hooks.cjs +1 -0
  17. package/dist/hooks.cjs.map +1 -1
  18. package/dist/hooks.d.cts +2 -4
  19. package/dist/hooks.d.ts +2 -4
  20. package/dist/hooks.mjs.map +1 -1
  21. package/dist/index.cjs +4 -100
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +10 -340
  24. package/dist/index.d.ts +10 -340
  25. package/dist/index.mjs +3 -100
  26. package/dist/index.mjs.map +1 -1
  27. package/package.json +5 -4
  28. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +8 -2
  29. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +8 -2
  30. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +8 -2
  31. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpConsentPolicyRetrieve.ts +8 -2
  32. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +8 -2
  33. package/src/_api/generated/_cfg_accounts/openapi.json +0 -45
  34. package/src/_api/generated/_cfg_accounts/schemas/User.ts +0 -2
  35. package/src/_api/generated/_cfg_accounts/schemas/index.ts +0 -1
  36. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +8 -2
  37. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +8 -2
  38. package/src/_api/generated/index.ts +1 -5
  39. package/src/_api/generated/openapi.json +0 -135
  40. package/src/_api/generated/sdk.gen.ts +1 -20
  41. package/src/_api/generated/types.gen.ts +0 -79
  42. package/src/_api/index.ts +1 -1
  43. package/src/auth/__tests__/useTwoFactorStatus.test.ts +2 -2
  44. package/src/auth/context/AccountsContext.tsx +15 -11
  45. package/src/auth/hooks/useAuthForm.ts +0 -1
  46. package/src/auth/hooks/useCfgRouter.ts +1 -4
  47. package/src/auth/hooks/useGithubAuth.ts +25 -3
  48. package/src/auth/hooks/useLocalStorage.ts +7 -30
  49. package/src/auth/hooks/useSessionStorage.ts +6 -29
  50. package/src/auth/hooks/useTwoFactorVerify.ts +5 -9
  51. package/src/auth/utils/analytics.ts +22 -2
  52. package/src/auth/utils/errors.ts +22 -11
  53. package/src/auth/utils/storage.ts +64 -0
  54. package/src/clients.ts +2 -4
  55. package/src/index.ts +0 -2
  56. package/src/log-control.ts +1 -1
  57. package/src/server.ts +0 -4
  58. package/src/_api/generated/_cfg_accounts/schemas/CentrifugoToken.ts +0 -14
  59. package/src/_api/generated/_cfg_centrifugo/api.ts +0 -87
  60. package/src/_api/generated/_cfg_centrifugo/hooks/index.ts +0 -4
  61. package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +0 -74
  62. package/src/_api/generated/_cfg_centrifugo/index.ts +0 -29
  63. package/src/_api/generated/_cfg_centrifugo/openapi.json +0 -136
  64. package/src/_api/generated/_cfg_centrifugo/schemas/ConnectionTokenResponse.ts +0 -14
  65. package/src/_api/generated/_cfg_centrifugo/schemas/index.ts +0 -4
  66. package/src/_api/generated/_cfg_centrifugo/sdk.gen.ts +0 -5
  67. package/src/_api/generated/_cfg_centrifugo/types.gen.ts +0 -5
package/dist/auth.mjs CHANGED
@@ -16,10 +16,10 @@ var AUTH_CONSTANTS = {
16
16
  import { usePathname as usePathname3 } from "next/navigation";
17
17
  import {
18
18
  createContext as createContext2,
19
- memo as memo2,
19
+ memo,
20
20
  useCallback as useCallback11,
21
21
  useContext as useContext2,
22
- useEffect as useEffect7,
22
+ useEffect as useEffect6,
23
23
  useMemo as useMemo3,
24
24
  useRef as useRef6,
25
25
  useState as useState11
@@ -873,9 +873,6 @@ __name(withBasePath, "withBasePath");
873
873
  function useCfgRouter() {
874
874
  const router = useNextRouter();
875
875
  const basePath = useMemo(() => getBasePath(), []);
876
- const isStaticBuild2 = useMemo(() => {
877
- return typeof process !== "undefined" && process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
878
- }, []);
879
876
  const push = useCallback((href, options) => {
880
877
  if (basePath) {
881
878
  window.location.href = withBasePath(href, basePath);
@@ -2472,6 +2469,33 @@ var Analytics = {
2472
2469
 
2473
2470
  // src/auth/hooks/useSessionStorage.ts
2474
2471
  import { useState as useState3 } from "react";
2472
+
2473
+ // src/auth/utils/storage.ts
2474
+ var MAX_ITEM_KB = 1024;
2475
+ function isQuotaExceededError(error) {
2476
+ if (typeof error !== "object" || error === null) return false;
2477
+ const { name, code, message } = error;
2478
+ return name === "QuotaExceededError" || code === 22 || typeof message === "string" && message.includes("quota");
2479
+ }
2480
+ __name(isQuotaExceededError, "isQuotaExceededError");
2481
+ function isWithinSizeLimit(data, key) {
2482
+ try {
2483
+ const sizeInKB = new Blob([JSON.stringify(data)]).size / 1024;
2484
+ if (sizeInKB > MAX_ITEM_KB) {
2485
+ authLogger.warn(
2486
+ `Data size (${sizeInKB.toFixed(2)}KB) exceeds 1MB limit for key "${key}"`
2487
+ );
2488
+ return false;
2489
+ }
2490
+ return true;
2491
+ } catch (error) {
2492
+ authLogger.error(`Error checking data size for key "${key}":`, error);
2493
+ return false;
2494
+ }
2495
+ }
2496
+ __name(isWithinSizeLimit, "isWithinSizeLimit");
2497
+
2498
+ // src/auth/hooks/useSessionStorage.ts
2475
2499
  function useSessionStorage(key, initialValue) {
2476
2500
  const [storedValue, setStoredValue] = useState3(() => {
2477
2501
  if (typeof window === "undefined") {
@@ -2485,21 +2509,6 @@ function useSessionStorage(key, initialValue) {
2485
2509
  return initialValue;
2486
2510
  }
2487
2511
  });
2488
- const checkDataSize = /* @__PURE__ */ __name((data) => {
2489
- try {
2490
- const jsonString = JSON.stringify(data);
2491
- const sizeInBytes = new Blob([jsonString]).size;
2492
- const sizeInKB = sizeInBytes / 1024;
2493
- if (sizeInKB > 1024) {
2494
- authLogger.warn(`Data size (${sizeInKB.toFixed(2)}KB) exceeds 1MB limit for key "${key}"`);
2495
- return false;
2496
- }
2497
- return true;
2498
- } catch (error) {
2499
- authLogger.error(`Error checking data size for key "${key}":`, error);
2500
- return false;
2501
- }
2502
- }, "checkDataSize");
2503
2512
  const clearOldData = /* @__PURE__ */ __name(() => {
2504
2513
  try {
2505
2514
  const keys = Object.keys(sessionStorage).filter((key2) => key2 && typeof key2 === "string");
@@ -2536,7 +2545,7 @@ function useSessionStorage(key, initialValue) {
2536
2545
  const setValue = /* @__PURE__ */ __name((value) => {
2537
2546
  try {
2538
2547
  const valueToStore = value instanceof Function ? value(storedValue) : value;
2539
- if (!checkDataSize(valueToStore)) {
2548
+ if (!isWithinSizeLimit(valueToStore, key)) {
2540
2549
  authLogger.warn(`Data size too large for key "${key}", removing key`);
2541
2550
  try {
2542
2551
  window.sessionStorage.removeItem(key);
@@ -2552,7 +2561,7 @@ function useSessionStorage(key, initialValue) {
2552
2561
  window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
2553
2562
  window.sessionStorage.setItem(`${key}_timestamp`, Date.now().toString());
2554
2563
  } catch (storageError) {
2555
- if (storageError.name === "QuotaExceededError" || storageError.code === 22 || storageError.message?.includes("quota")) {
2564
+ if (isQuotaExceededError(storageError)) {
2556
2565
  authLogger.warn("sessionStorage quota exceeded, clearing old data...");
2557
2566
  clearOldData();
2558
2567
  try {
@@ -2588,7 +2597,7 @@ function useSessionStorage(key, initialValue) {
2588
2597
  window.sessionStorage.removeItem(key);
2589
2598
  window.sessionStorage.removeItem(`${key}_timestamp`);
2590
2599
  } catch (removeError) {
2591
- if (removeError.name === "QuotaExceededError" || removeError.code === 22 || removeError.message?.includes("quota")) {
2600
+ if (isQuotaExceededError(removeError)) {
2592
2601
  authLogger.warn("sessionStorage quota exceeded during removal, clearing old data...");
2593
2602
  clearOldData();
2594
2603
  try {
@@ -2863,7 +2872,6 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
2863
2872
  const {
2864
2873
  identifier,
2865
2874
  otp,
2866
- isLoading,
2867
2875
  acceptedTerms,
2868
2876
  marketingConsent,
2869
2877
  rememberMe,
@@ -3215,7 +3223,9 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
3215
3223
  if (response.user?.id) {
3216
3224
  Analytics.setUser(String(response.user.id));
3217
3225
  }
3218
- onSuccess?.(response.user, response.is_new_user || false);
3226
+ if (response.user) {
3227
+ onSuccess?.(response.user, response.is_new_user || false);
3228
+ }
3219
3229
  if (!skipRedirect) {
3220
3230
  const finalRedirectUrl = redirectUrl || "/private";
3221
3231
  router.hardPush(finalRedirectUrl);
@@ -3448,21 +3458,6 @@ function useLocalStorage(key, initialValue) {
3448
3458
  return initialValue;
3449
3459
  }
3450
3460
  });
3451
- const checkDataSize = /* @__PURE__ */ __name((data) => {
3452
- try {
3453
- const jsonString = JSON.stringify(data);
3454
- const sizeInBytes = new Blob([jsonString]).size;
3455
- const sizeInKB = sizeInBytes / 1024;
3456
- if (sizeInKB > 1024) {
3457
- authLogger.warn(`Data size (${sizeInKB.toFixed(2)}KB) exceeds 1MB limit for key "${key}"`);
3458
- return false;
3459
- }
3460
- return true;
3461
- } catch (error) {
3462
- authLogger.error(`Error checking data size for key "${key}":`, error);
3463
- return false;
3464
- }
3465
- }, "checkDataSize");
3466
3461
  const clearOldData = /* @__PURE__ */ __name(() => {
3467
3462
  try {
3468
3463
  const keys = Object.keys(localStorage).filter((key2) => key2 && typeof key2 === "string");
@@ -3499,7 +3494,7 @@ function useLocalStorage(key, initialValue) {
3499
3494
  const setValue = /* @__PURE__ */ __name((value) => {
3500
3495
  try {
3501
3496
  const valueToStore = value instanceof Function ? value(storedValue) : value;
3502
- if (!checkDataSize(valueToStore)) {
3497
+ if (!isWithinSizeLimit(valueToStore, key)) {
3503
3498
  authLogger.warn(`Data size too large for key "${key}", removing key`);
3504
3499
  try {
3505
3500
  window.localStorage.removeItem(key);
@@ -3519,7 +3514,7 @@ function useLocalStorage(key, initialValue) {
3519
3514
  }
3520
3515
  window.localStorage.setItem(`${key}_timestamp`, Date.now().toString());
3521
3516
  } catch (storageError) {
3522
- if (storageError.name === "QuotaExceededError" || storageError.code === 22 || storageError.message?.includes("quota")) {
3517
+ if (isQuotaExceededError(storageError)) {
3523
3518
  authLogger.warn("localStorage quota exceeded, clearing old data...");
3524
3519
  clearOldData();
3525
3520
  try {
@@ -3563,7 +3558,7 @@ function useLocalStorage(key, initialValue) {
3563
3558
  window.localStorage.removeItem(key);
3564
3559
  window.localStorage.removeItem(`${key}_timestamp`);
3565
3560
  } catch (removeError) {
3566
- if (removeError.name === "QuotaExceededError" || removeError.code === 22 || removeError.message?.includes("quota")) {
3561
+ if (isQuotaExceededError(removeError)) {
3567
3562
  authLogger.warn("localStorage quota exceeded during removal, clearing old data...");
3568
3563
  clearOldData();
3569
3564
  try {
@@ -3767,7 +3762,7 @@ import {
3767
3762
  createContext,
3768
3763
  useCallback as useCallback10,
3769
3764
  useContext,
3770
- useEffect as useEffect6,
3765
+ useEffect as useEffect5,
3771
3766
  useMemo as useMemo2,
3772
3767
  useRef as useRef5,
3773
3768
  useState as useState10
@@ -3982,53 +3977,41 @@ __name(useCfgAccountsOtpRequestCreate, "useCfgAccountsOtpRequestCreate");
3982
3977
  import useSWRMutation8 from "swr/mutation";
3983
3978
 
3984
3979
  // src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts
3985
- import { z as z19 } from "zod";
3986
-
3987
- // src/_api/generated/_cfg_accounts/schemas/User.ts
3988
3980
  import { z as z18 } from "zod";
3989
3981
 
3990
- // src/_api/generated/_cfg_accounts/schemas/CentrifugoToken.ts
3991
- import { z as z17 } from "zod";
3992
- var CentrifugoTokenSchema = z17.object({
3993
- token: z17.string(),
3994
- centrifugo_url: z17.string(),
3995
- expires_at: z17.string().datetime({ offset: true }),
3996
- channels: z17.array(z17.string())
3997
- });
3998
-
3999
3982
  // src/_api/generated/_cfg_accounts/schemas/User.ts
4000
- var UserSchema = z18.object({
4001
- id: z18.number().int(),
4002
- email: z18.email(),
4003
- first_name: z18.string().max(50).nullable().optional(),
4004
- last_name: z18.string().max(50).nullable().optional(),
4005
- full_name: z18.string(),
4006
- initials: z18.string(),
4007
- display_username: z18.string(),
4008
- company: z18.string().max(100).nullable().optional(),
4009
- phone: z18.string().max(20).nullable().optional(),
4010
- position: z18.string().max(100).nullable().optional(),
4011
- language: z18.string().max(10).nullable().optional(),
4012
- timezone: z18.string().max(64).nullable().optional(),
4013
- avatar: z18.string().nullable(),
4014
- is_staff: z18.boolean(),
4015
- is_superuser: z18.boolean(),
4016
- date_joined: z18.string().datetime({ offset: true }),
4017
- last_login: z18.string().datetime({ offset: true }).nullable(),
4018
- unanswered_messages_count: z18.number().int().default(0),
4019
- centrifugo: CentrifugoTokenSchema.nullable(),
4020
- api_key: z18.string().nullable()
3983
+ import { z as z17 } from "zod";
3984
+ var UserSchema = z17.object({
3985
+ id: z17.number().int(),
3986
+ email: z17.email(),
3987
+ first_name: z17.string().max(50).nullable().optional(),
3988
+ last_name: z17.string().max(50).nullable().optional(),
3989
+ full_name: z17.string(),
3990
+ initials: z17.string(),
3991
+ display_username: z17.string(),
3992
+ company: z17.string().max(100).nullable().optional(),
3993
+ phone: z17.string().max(20).nullable().optional(),
3994
+ position: z17.string().max(100).nullable().optional(),
3995
+ language: z17.string().max(10).nullable().optional(),
3996
+ timezone: z17.string().max(64).nullable().optional(),
3997
+ avatar: z17.string().nullable(),
3998
+ is_staff: z17.boolean(),
3999
+ is_superuser: z17.boolean(),
4000
+ date_joined: z17.string().datetime({ offset: true }),
4001
+ last_login: z17.string().datetime({ offset: true }).nullable(),
4002
+ unanswered_messages_count: z17.number().int().default(0),
4003
+ api_key: z17.string().nullable()
4021
4004
  });
4022
4005
 
4023
4006
  // src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts
4024
- var OTPVerifyResponseSchema = z19.object({
4025
- requires_2fa: z19.boolean().default(false).optional(),
4026
- session_id: z19.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
4027
- refresh: z19.string().nullable().optional(),
4028
- access: z19.string().nullable().optional(),
4007
+ var OTPVerifyResponseSchema = z18.object({
4008
+ requires_2fa: z18.boolean().default(false).optional(),
4009
+ session_id: z18.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
4010
+ refresh: z18.string().nullable().optional(),
4011
+ access: z18.string().nullable().optional(),
4029
4012
  user: UserSchema.nullable().optional(),
4030
- should_prompt_2fa: z19.boolean().optional(),
4031
- persistent_session: z19.boolean().optional()
4013
+ should_prompt_2fa: z18.boolean().optional(),
4014
+ persistent_session: z18.boolean().optional()
4032
4015
  });
4033
4016
 
4034
4017
  // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts
@@ -4130,10 +4113,10 @@ __name(useCfgAccountsProfileAvatarCreate, "useCfgAccountsProfileAvatarCreate");
4130
4113
  import useSWRMutation10 from "swr/mutation";
4131
4114
 
4132
4115
  // src/_api/generated/_cfg_accounts/schemas/AccountDeleteResponse.ts
4133
- import { z as z20 } from "zod";
4134
- var AccountDeleteResponseSchema = z20.object({
4135
- success: z20.boolean(),
4136
- message: z20.string()
4116
+ import { z as z19 } from "zod";
4117
+ var AccountDeleteResponseSchema = z19.object({
4118
+ success: z19.boolean(),
4119
+ message: z19.string()
4137
4120
  });
4138
4121
 
4139
4122
  // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfilePartialPartialUpdate.ts
@@ -4248,117 +4231,117 @@ import useSWRMutation15 from "swr/mutation";
4248
4231
  import useSWRMutation16 from "swr/mutation";
4249
4232
 
4250
4233
  // src/_api/generated/_cfg_accounts/schemas/TokenRefresh.ts
4251
- import { z as z21 } from "zod";
4252
- var TokenRefreshSchema = z21.object({
4253
- access: z21.string(),
4254
- refresh: z21.string()
4234
+ import { z as z20 } from "zod";
4235
+ var TokenRefreshSchema = z20.object({
4236
+ access: z20.string(),
4237
+ refresh: z20.string()
4255
4238
  });
4256
4239
 
4257
4240
  // src/_api/generated/_cfg_accounts/schemas/APIKeyRequest.ts
4258
- import { z as z22 } from "zod";
4259
- var APIKeyRequestSchema = z22.object({
4260
- key: z22.string().min(1),
4261
- reissued_at: z22.string().datetime({ offset: true }).nullable(),
4262
- created_at: z22.string().datetime({ offset: true })
4241
+ import { z as z21 } from "zod";
4242
+ var APIKeyRequestSchema = z21.object({
4243
+ key: z21.string().min(1),
4244
+ reissued_at: z21.string().datetime({ offset: true }).nullable(),
4245
+ created_at: z21.string().datetime({ offset: true })
4263
4246
  });
4264
4247
 
4265
4248
  // src/_api/generated/_cfg_accounts/schemas/APIKeyTestRequest.ts
4266
- import { z as z23 } from "zod";
4267
- var APIKeyTestRequestSchema = z23.object({
4268
- key: z23.string().min(1)
4249
+ import { z as z22 } from "zod";
4250
+ var APIKeyTestRequestSchema = z22.object({
4251
+ key: z22.string().min(1)
4269
4252
  });
4270
4253
 
4271
4254
  // src/_api/generated/_cfg_accounts/schemas/CfgUserUpdateRequest.ts
4272
- import { z as z24 } from "zod";
4273
- var CfgUserUpdateRequestSchema = z24.object({
4274
- first_name: z24.string().max(50).optional(),
4275
- last_name: z24.string().max(50).optional(),
4276
- company: z24.string().max(100).optional(),
4277
- phone: z24.string().max(20).optional(),
4278
- position: z24.string().max(100).optional(),
4279
- language: z24.string().max(10).optional(),
4280
- timezone: z24.string().max(64).optional()
4255
+ import { z as z23 } from "zod";
4256
+ var CfgUserUpdateRequestSchema = z23.object({
4257
+ first_name: z23.string().max(50).optional(),
4258
+ last_name: z23.string().max(50).optional(),
4259
+ company: z23.string().max(100).optional(),
4260
+ phone: z23.string().max(20).optional(),
4261
+ position: z23.string().max(100).optional(),
4262
+ language: z23.string().max(10).optional(),
4263
+ timezone: z23.string().max(64).optional()
4281
4264
  });
4282
4265
 
4283
4266
  // src/_api/generated/_cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts
4284
- import { z as z25 } from "zod";
4285
- var OAuthAuthorizeRequestRequestSchema = z25.object({
4286
- redirect_uri: z25.string().optional(),
4287
- source_url: z25.string().optional()
4267
+ import { z as z24 } from "zod";
4268
+ var OAuthAuthorizeRequestRequestSchema = z24.object({
4269
+ redirect_uri: z24.string().optional(),
4270
+ source_url: z24.string().optional()
4288
4271
  });
4289
4272
 
4290
4273
  // src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts
4291
- import { z as z26 } from "zod";
4292
- var OAuthCallbackRequestRequestSchema = z26.object({
4293
- code: z26.string().min(10).max(500),
4294
- state: z26.string().min(20).max(100),
4295
- redirect_uri: z26.string().optional(),
4296
- remember_me: z26.boolean().default(false).optional()
4274
+ import { z as z25 } from "zod";
4275
+ var OAuthCallbackRequestRequestSchema = z25.object({
4276
+ code: z25.string().min(10).max(500),
4277
+ state: z25.string().min(20).max(100),
4278
+ redirect_uri: z25.string().optional(),
4279
+ remember_me: z25.boolean().default(false).optional()
4297
4280
  });
4298
4281
 
4299
4282
  // src/_api/generated/_cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts
4300
- import { z as z27 } from "zod";
4301
- var OAuthDisconnectRequestRequestSchema = z27.object({
4283
+ import { z as z26 } from "zod";
4284
+ var OAuthDisconnectRequestRequestSchema = z26.object({
4302
4285
  provider: OAuthProviderEnumSchema
4303
4286
  });
4304
4287
 
4305
4288
  // src/_api/generated/_cfg_accounts/schemas/OAuthError.ts
4289
+ import { z as z27 } from "zod";
4290
+ var OAuthErrorSchema = z27.object({
4291
+ error: z27.string(),
4292
+ error_description: z27.string().optional()
4293
+ });
4294
+
4295
+ // src/_api/generated/_cfg_accounts/schemas/OTPErrorResponse.ts
4306
4296
  import { z as z28 } from "zod";
4307
- var OAuthErrorSchema = z28.object({
4297
+ var OTPErrorResponseSchema = z28.object({
4308
4298
  error: z28.string(),
4309
- error_description: z28.string().optional()
4299
+ error_code: z28.string().nullable().optional(),
4300
+ retry_after: z28.number().int().nullable().optional()
4310
4301
  });
4311
4302
 
4312
- // src/_api/generated/_cfg_accounts/schemas/OTPErrorResponse.ts
4303
+ // src/_api/generated/_cfg_accounts/schemas/OTPRequestRequest.ts
4313
4304
  import { z as z29 } from "zod";
4314
- var OTPErrorResponseSchema = z29.object({
4315
- error: z29.string(),
4316
- error_code: z29.string().nullable().optional(),
4317
- retry_after: z29.number().int().nullable().optional()
4305
+ var OTPRequestRequestSchema = z29.object({
4306
+ identifier: z29.string().min(1),
4307
+ source_url: z29.string().optional(),
4308
+ marketing_consent: z29.boolean().nullable().optional(),
4309
+ consent_disclosure_version: z29.string().max(64).optional()
4318
4310
  });
4319
4311
 
4320
- // src/_api/generated/_cfg_accounts/schemas/OTPRequestRequest.ts
4312
+ // src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts
4321
4313
  import { z as z30 } from "zod";
4322
- var OTPRequestRequestSchema = z30.object({
4314
+ var OTPVerifyRequestSchema = z30.object({
4323
4315
  identifier: z30.string().min(1),
4316
+ otp: z30.string().min(4).max(4),
4324
4317
  source_url: z30.string().optional(),
4325
- marketing_consent: z30.boolean().nullable().optional(),
4326
- consent_disclosure_version: z30.string().max(64).optional()
4318
+ remember_me: z30.boolean().default(false).optional()
4327
4319
  });
4328
4320
 
4329
- // src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts
4321
+ // src/_api/generated/_cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts
4330
4322
  import { z as z31 } from "zod";
4331
- var OTPVerifyRequestSchema = z31.object({
4332
- identifier: z31.string().min(1),
4333
- otp: z31.string().min(4).max(4),
4334
- source_url: z31.string().optional(),
4335
- remember_me: z31.boolean().default(false).optional()
4323
+ var PatchedCfgUserUpdateRequestSchema = z31.object({
4324
+ first_name: z31.string().max(50).optional(),
4325
+ last_name: z31.string().max(50).optional(),
4326
+ company: z31.string().max(100).optional(),
4327
+ phone: z31.string().max(20).optional(),
4328
+ position: z31.string().max(100).optional(),
4329
+ language: z31.string().max(10).optional(),
4330
+ timezone: z31.string().max(64).optional()
4336
4331
  });
4337
4332
 
4338
- // src/_api/generated/_cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts
4333
+ // src/_api/generated/_cfg_accounts/schemas/TokenBlacklistRequest.ts
4339
4334
  import { z as z32 } from "zod";
4340
- var PatchedCfgUserUpdateRequestSchema = z32.object({
4341
- first_name: z32.string().max(50).optional(),
4342
- last_name: z32.string().max(50).optional(),
4343
- company: z32.string().max(100).optional(),
4344
- phone: z32.string().max(20).optional(),
4345
- position: z32.string().max(100).optional(),
4346
- language: z32.string().max(10).optional(),
4347
- timezone: z32.string().max(64).optional()
4335
+ var TokenBlacklistRequestSchema = z32.object({
4336
+ refresh: z32.string().min(1)
4348
4337
  });
4349
4338
 
4350
- // src/_api/generated/_cfg_accounts/schemas/TokenBlacklistRequest.ts
4339
+ // src/_api/generated/_cfg_accounts/schemas/TokenRefreshRequest.ts
4351
4340
  import { z as z33 } from "zod";
4352
- var TokenBlacklistRequestSchema = z33.object({
4341
+ var TokenRefreshRequestSchema = z33.object({
4353
4342
  refresh: z33.string().min(1)
4354
4343
  });
4355
4344
 
4356
- // src/_api/generated/_cfg_accounts/schemas/TokenRefreshRequest.ts
4357
- import { z as z34 } from "zod";
4358
- var TokenRefreshRequestSchema = z34.object({
4359
- refresh: z34.string().min(1)
4360
- });
4361
-
4362
4345
  // src/auth/context/AccountsContext.tsx
4363
4346
  import { jsx } from "react/jsx-runtime";
4364
4347
  function hasApiOrigin() {
@@ -4382,10 +4365,10 @@ function AccountsProvider({ children }) {
4382
4365
  const [profileError, setProfileError] = useState10(null);
4383
4366
  const profileRef = useRef5(profile);
4384
4367
  const isLoadingRef = useRef5(false);
4385
- useEffect6(() => {
4368
+ useEffect5(() => {
4386
4369
  profileRef.current = profile;
4387
4370
  }, [profile]);
4388
- useEffect6(() => {
4371
+ useEffect5(() => {
4389
4372
  isLoadingRef.current = isLoadingProfile;
4390
4373
  }, [isLoadingProfile]);
4391
4374
  const { trigger: triggerProfileUpdate } = useCfgAccountsProfileUpdateUpdate();
@@ -4423,26 +4406,26 @@ function AccountsProvider({ children }) {
4423
4406
  isLoadingRef.current = false;
4424
4407
  }
4425
4408
  }, []);
4426
- const updateProfile = /* @__PURE__ */ __name(async (data) => {
4409
+ const updateProfile = useCallback10(async (data) => {
4427
4410
  await triggerProfileUpdate({ body: data });
4428
4411
  const user = await refreshProfile({ callerId: "updateProfile", force: true });
4429
4412
  return user;
4430
- }, "updateProfile");
4431
- const partialUpdateProfile = /* @__PURE__ */ __name(async (data) => {
4413
+ }, [triggerProfileUpdate, refreshProfile]);
4414
+ const partialUpdateProfile = useCallback10(async (data) => {
4432
4415
  await triggerProfilePartialUpdate({ body: data });
4433
4416
  const user = await refreshProfile({ callerId: "partialUpdateProfile", force: true });
4434
4417
  return user;
4435
- }, "partialUpdateProfile");
4436
- const uploadAvatar = /* @__PURE__ */ __name(async (avatar) => {
4418
+ }, [triggerProfilePartialUpdate, refreshProfile]);
4419
+ const uploadAvatar = useCallback10(async (avatar) => {
4437
4420
  await triggerAvatar({ body: { avatar } });
4438
4421
  const user = await refreshProfile({ callerId: "uploadAvatar", force: true });
4439
4422
  return user;
4440
- }, "uploadAvatar");
4441
- const requestOTP = /* @__PURE__ */ __name(async (data) => {
4423
+ }, [triggerAvatar, refreshProfile]);
4424
+ const requestOTP = useCallback10(async (data) => {
4442
4425
  const result = await triggerOtpRequest({ body: data });
4443
4426
  return result;
4444
- }, "requestOTP");
4445
- const verifyOTP = /* @__PURE__ */ __name(async (data) => {
4427
+ }, [triggerOtpRequest]);
4428
+ const verifyOTP = useCallback10(async (data) => {
4446
4429
  const result = await triggerOtpVerify({ body: data });
4447
4430
  if (result.requires_2fa && result.session_id) {
4448
4431
  authLogger.info("2FA required, session:", result.session_id);
@@ -4457,7 +4440,7 @@ function AccountsProvider({ children }) {
4457
4440
  }
4458
4441
  }
4459
4442
  return result;
4460
- }, "verifyOTP");
4443
+ }, [triggerOtpVerify, refreshProfile]);
4461
4444
  const logout = useCallback10(() => {
4462
4445
  const refresh = auth.getRefreshToken();
4463
4446
  if (refresh) {
@@ -4536,7 +4519,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
4536
4519
  );
4537
4520
  const routes = useMemo3(() => resolveAuthRoutes(config?.routes), [config?.routes]);
4538
4521
  const routesRef = useRef6(routes);
4539
- useEffect7(() => {
4522
+ useEffect6(() => {
4540
4523
  routesRef.current = routes;
4541
4524
  }, [routes]);
4542
4525
  const redirectManager = useAuthRedirectManager({
@@ -4544,18 +4527,18 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
4544
4527
  clearOnUse: true
4545
4528
  });
4546
4529
  const configRef = useRef6(config);
4547
- useEffect7(() => {
4530
+ useEffect6(() => {
4548
4531
  configRef.current = config;
4549
4532
  }, [config]);
4550
4533
  const accountsRef = useRef6(accounts);
4551
- useEffect7(() => {
4534
+ useEffect6(() => {
4552
4535
  accountsRef.current = accounts;
4553
4536
  }, [accounts]);
4554
4537
  const pendingManualNavRef = useRef6(false);
4555
4538
  const [profileSettled, setProfileSettled] = useState11(false);
4556
4539
  const hasProfile = Boolean(accounts.profile);
4557
4540
  const profileAttemptedRef = useRef6(false);
4558
- useEffect7(() => {
4541
+ useEffect6(() => {
4559
4542
  if (!isAuthenticated) {
4560
4543
  profileAttemptedRef.current = false;
4561
4544
  const hasTokens = Boolean(auth.getToken() || auth.getRefreshToken());
@@ -4584,7 +4567,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
4584
4567
  }, [isAuthenticated, hasProfile]);
4585
4568
  const isLoading = !profileSettled;
4586
4569
  const expiredHandledRef = useRef6(false);
4587
- useEffect7(() => {
4570
+ useEffect6(() => {
4588
4571
  const unsubscribe = auth.onSessionExpired(() => {
4589
4572
  if (expiredHandledRef.current) return;
4590
4573
  expiredHandledRef.current = true;
@@ -4597,7 +4580,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
4597
4580
  });
4598
4581
  return unsubscribe;
4599
4582
  }, [router]);
4600
- useEffect7(() => {
4583
+ useEffect6(() => {
4601
4584
  if (!isAuthenticated || pendingManualNavRef.current) return;
4602
4585
  if (pathname === routes.auth && !queryParams.get("flow")) {
4603
4586
  const saved = redirectManager.hasRedirect() ? redirectManager.getRedirect() : null;
@@ -4749,7 +4732,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
4749
4732
  }, [router]);
4750
4733
  const user = accounts.profile ?? null;
4751
4734
  const isAdminUser = Boolean(user?.is_staff || user?.is_superuser);
4752
- useEffect7(() => {
4735
+ useEffect6(() => {
4753
4736
  applyRoleLogPolicy({ isAdmin: isAdminUser });
4754
4737
  }, [isAdminUser]);
4755
4738
  const updateProfile = useCallback11(
@@ -4817,7 +4800,7 @@ function AuthProviderRaw({ children, config, enabled = true }) {
4817
4800
  return /* @__PURE__ */ jsx2(AccountsProvider, { children: /* @__PURE__ */ jsx2(AuthProviderInternal, { config, children }) });
4818
4801
  }
4819
4802
  __name(AuthProviderRaw, "AuthProviderRaw");
4820
- var AuthProvider = memo2(AuthProviderRaw);
4803
+ var AuthProvider = memo(AuthProviderRaw);
4821
4804
  var defaultAuthState = {
4822
4805
  user: null,
4823
4806
  isLoading: false,
@@ -4887,18 +4870,20 @@ var validateEmail = /* @__PURE__ */ __name((email) => {
4887
4870
  }, "validateEmail");
4888
4871
 
4889
4872
  // src/auth/utils/errors.ts
4873
+ var prop = /* @__PURE__ */ __name((value, key) => typeof value === "object" && value !== null ? value[key] : void 0, "prop");
4890
4874
  var formatAuthError = /* @__PURE__ */ __name((error) => {
4891
4875
  if (typeof error === "string") {
4892
4876
  return error;
4893
4877
  }
4894
- if (error?.message) {
4895
- return error.message;
4896
- }
4897
- if (error?.detail) {
4898
- return error.detail;
4899
- }
4900
- if (error?.response?.data?.detail) {
4901
- return error.response.data.detail;
4878
+ const candidates = [
4879
+ prop(error, "message"),
4880
+ prop(error, "detail"),
4881
+ prop(prop(prop(error, "response"), "data"), "detail")
4882
+ ];
4883
+ for (const candidate of candidates) {
4884
+ if (typeof candidate === "string" && candidate) {
4885
+ return candidate;
4886
+ }
4902
4887
  }
4903
4888
  return "An unexpected error occurred";
4904
4889
  }, "formatAuthError");