@djangocfg/api 2.1.227 → 2.1.228

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 (56) hide show
  1. package/README.md +8 -9
  2. package/dist/auth-server.cjs +4 -9
  3. package/dist/auth-server.cjs.map +1 -1
  4. package/dist/auth-server.mjs +4 -9
  5. package/dist/auth-server.mjs.map +1 -1
  6. package/dist/auth.cjs +120 -158
  7. package/dist/auth.cjs.map +1 -1
  8. package/dist/auth.d.cts +120 -177
  9. package/dist/auth.d.ts +120 -177
  10. package/dist/auth.mjs +149 -191
  11. package/dist/auth.mjs.map +1 -1
  12. package/dist/clients.cjs +5 -11
  13. package/dist/clients.cjs.map +1 -1
  14. package/dist/clients.d.cts +218 -219
  15. package/dist/clients.d.ts +218 -219
  16. package/dist/clients.mjs +5 -11
  17. package/dist/clients.mjs.map +1 -1
  18. package/dist/hooks.cjs +4 -9
  19. package/dist/hooks.cjs.map +1 -1
  20. package/dist/hooks.d.cts +70 -91
  21. package/dist/hooks.d.ts +70 -91
  22. package/dist/hooks.mjs +4 -9
  23. package/dist/hooks.mjs.map +1 -1
  24. package/dist/index.cjs +5 -11
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +116 -106
  27. package/dist/index.d.ts +116 -106
  28. package/dist/index.mjs +5 -11
  29. package/dist/index.mjs.map +1 -1
  30. package/package.json +2 -2
  31. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts +24 -2
  32. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +0 -2
  33. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +0 -2
  34. package/src/_api/generated/cfg_accounts/accounts/client.ts +1 -1
  35. package/src/_api/generated/cfg_accounts/accounts/models.ts +25 -26
  36. package/src/_api/generated/cfg_accounts/accounts__auth/models.ts +5 -5
  37. package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +42 -42
  38. package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +23 -23
  39. package/src/_api/generated/cfg_accounts/enums.ts +0 -10
  40. package/src/_api/generated/cfg_accounts/schema.json +31 -25
  41. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_admin_api/models.ts +57 -57
  42. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_monitoring/models.ts +24 -24
  43. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_testing/models.ts +14 -14
  44. package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +14 -14
  45. package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +10 -10
  46. package/src/_api/generated/cfg_totp/totp__totp_verification/models.ts +8 -8
  47. package/src/auth/context/AccountsContext.tsx +6 -2
  48. package/src/auth/context/AuthContext.tsx +32 -39
  49. package/src/auth/context/types.ts +5 -9
  50. package/src/auth/hooks/index.ts +1 -1
  51. package/src/auth/hooks/useAuthForm.ts +42 -75
  52. package/src/auth/hooks/useAuthFormState.ts +35 -6
  53. package/src/auth/hooks/useAuthValidation.ts +5 -65
  54. package/src/auth/hooks/useTwoFactor.ts +17 -2
  55. package/src/auth/types/form.ts +25 -70
  56. package/src/auth/types/index.ts +2 -6
package/dist/auth.d.cts CHANGED
@@ -1,18 +1,8 @@
1
- import React$1, { ReactNode, MutableRefObject } from 'react';
1
+ import React$1, { MutableRefObject, ReactNode } from 'react';
2
2
  import { z } from 'zod';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as consola from 'consola';
5
5
 
6
- /**
7
- * Delivery channel: 'email' or 'phone'. Auto-detected if not provided.
8
- * * `email` - Email
9
- * * `phone` - Phone
10
- */
11
- declare enum OTPRequestRequestChannel {
12
- EMAIL = "email",
13
- PHONE = "phone"
14
- }
15
-
16
6
  /**
17
7
  * Zod schema for OTPRequestRequest
18
8
  *
@@ -25,7 +15,6 @@ declare enum OTPRequestRequestChannel {
25
15
  */
26
16
  declare const OTPRequestRequestSchema: z.ZodObject<{
27
17
  identifier: z.ZodString;
28
- channel: z.ZodOptional<z.ZodEnum<typeof OTPRequestRequestChannel>>;
29
18
  source_url: z.ZodOptional<z.ZodString>;
30
19
  }, z.core.$strip>;
31
20
  /**
@@ -64,7 +53,6 @@ type OTPRequestResponse = z.infer<typeof OTPRequestResponseSchema>;
64
53
  declare const OTPVerifyRequestSchema: z.ZodObject<{
65
54
  identifier: z.ZodString;
66
55
  otp: z.ZodString;
67
- channel: z.ZodOptional<z.ZodEnum<typeof OTPRequestRequestChannel>>;
68
56
  source_url: z.ZodOptional<z.ZodString>;
69
57
  }, z.core.$strip>;
70
58
  /**
@@ -240,6 +228,118 @@ declare const UserProfileUpdateRequestSchema: z.ZodObject<{
240
228
  */
241
229
  type UserProfileUpdateRequest = z.infer<typeof UserProfileUpdateRequestSchema>;
242
230
 
231
+ /**
232
+ * Auth Form Types
233
+ *
234
+ * Single source of truth for auth form state and handlers.
235
+ * Used by both @djangocfg/api/auth hooks and @djangocfg/layouts/AuthLayout.
236
+ */
237
+
238
+ type AuthStep = 'identifier' | 'otp' | '2fa' | '2fa-setup' | 'success';
239
+ interface OTPRequestResult {
240
+ success: boolean;
241
+ message: string;
242
+ statusCode?: number;
243
+ retryAfter?: number;
244
+ }
245
+ interface AuthFormState {
246
+ /** Email address */
247
+ identifier: string;
248
+ /** OTP code input */
249
+ otp: string;
250
+ /** Loading state */
251
+ isLoading: boolean;
252
+ /** Terms acceptance state */
253
+ acceptedTerms: boolean;
254
+ /** Current form step */
255
+ step: AuthStep;
256
+ /** Error message */
257
+ error: string;
258
+ /** 2FA session ID from OTP/OAuth verification */
259
+ twoFactorSessionId: string | null;
260
+ /** Whether user should be prompted to enable 2FA */
261
+ shouldPrompt2FA: boolean;
262
+ /** 2FA code input */
263
+ twoFactorCode: string;
264
+ /** Using backup code instead of TOTP */
265
+ useBackupCode: boolean;
266
+ /** Seconds remaining until rate limit lifts (0 = not rate limited) */
267
+ rateLimitSeconds: number;
268
+ /** True when rateLimitSeconds > 0 — submit should be disabled */
269
+ isRateLimited: boolean;
270
+ /** Formatted countdown label, e.g. "19:00" or "42s" */
271
+ rateLimitLabel: string;
272
+ }
273
+ interface AuthFormStateHandlers {
274
+ setIdentifier: (identifier: string) => void;
275
+ setOtp: (otp: string) => void;
276
+ setAcceptedTerms: (accepted: boolean) => void;
277
+ setError: (error: string) => void;
278
+ clearError: () => void;
279
+ setStep: (step: AuthStep) => void;
280
+ setIsLoading: (loading: boolean) => void;
281
+ setTwoFactorSessionId: (sessionId: string | null) => void;
282
+ setShouldPrompt2FA: (prompt: boolean) => void;
283
+ setTwoFactorCode: (code: string) => void;
284
+ setUseBackupCode: (useBackup: boolean) => void;
285
+ /** Start a countdown timer that disables submit for `seconds` seconds */
286
+ startRateLimitCountdown: (seconds: number) => void;
287
+ }
288
+ interface AuthFormSubmitHandlers {
289
+ handleIdentifierSubmit: (e: React.FormEvent) => Promise<void>;
290
+ handleOTPSubmit: (e: React.FormEvent) => Promise<void>;
291
+ handleResendOTP: () => Promise<void>;
292
+ handleBackToIdentifier: () => void;
293
+ forceOTPStep: () => void;
294
+ /** Handle 2FA TOTP/backup code verification */
295
+ handle2FASubmit: (e: React.FormEvent) => Promise<void>;
296
+ /** Switch to backup code input */
297
+ handleUseBackupCode: () => void;
298
+ /** Switch back to TOTP input */
299
+ handleUseTOTP: () => void;
300
+ }
301
+ interface AuthFormValidation {
302
+ /** Validate identifier format */
303
+ validateIdentifier: (identifier: string) => boolean;
304
+ }
305
+ interface AuthFormAutoSubmit {
306
+ /** Ref to track if auto-submit from URL is in progress */
307
+ isAutoSubmittingFromUrl: MutableRefObject<boolean>;
308
+ }
309
+ interface AuthForm2FAState {
310
+ /** Loading state for 2FA verification */
311
+ is2FALoading: boolean;
312
+ /** Warning message from 2FA (e.g., low backup codes) */
313
+ twoFactorWarning: string | null;
314
+ /** Remaining attempts before 2FA lockout (null = unknown) */
315
+ twoFactorAttemptsRemaining: number | null;
316
+ }
317
+ interface AuthFormReturn extends AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthFormAutoSubmit, AuthForm2FAState {
318
+ }
319
+ interface UseAuthFormOptions {
320
+ /** Callback when identifier step succeeds */
321
+ onIdentifierSuccess?: (identifier: string) => void;
322
+ /** Callback when OTP verification succeeds */
323
+ onOTPSuccess?: () => void;
324
+ /** Callback on any error */
325
+ onError?: (message: string) => void;
326
+ /** Source URL for tracking */
327
+ sourceUrl: string;
328
+ /** URL to redirect after successful OTP verification */
329
+ redirectUrl?: string;
330
+ /** If true, user must accept terms before submitting. Default: false */
331
+ requireTermsAcceptance?: boolean;
332
+ /** Path to auth page for auto-OTP detection. Default: '/auth' */
333
+ authPath?: string;
334
+ /**
335
+ * Enable 2FA setup prompt after successful authentication.
336
+ * When true (default), users without 2FA will see a setup prompt after login.
337
+ * When false, users go directly to success without 2FA setup prompt.
338
+ * @default true
339
+ */
340
+ enable2FASetup?: boolean;
341
+ }
342
+
243
343
  type UserProfile = User;
244
344
  interface AuthConfig {
245
345
  apiUrl?: string;
@@ -262,14 +362,8 @@ interface AuthContextType {
262
362
  getSavedEmail: () => string | null;
263
363
  saveEmail: (email: string) => void;
264
364
  clearSavedEmail: () => void;
265
- getSavedPhone: () => string | null;
266
- savePhone: (phone: string) => void;
267
- clearSavedPhone: () => void;
268
- requestOTP: (identifier: string, channel?: 'email' | 'phone', sourceUrl?: string) => Promise<{
269
- success: boolean;
270
- message: string;
271
- }>;
272
- verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string, redirectUrl?: string, skipRedirect?: boolean) => Promise<{
365
+ requestOTP: (identifier: string, sourceUrl?: string) => Promise<OTPRequestResult>;
366
+ verifyOTP: (identifier: string, otpCode: string, sourceUrl?: string, redirectUrl?: string, skipRedirect?: boolean) => Promise<{
273
367
  success: boolean;
274
368
  message: string;
275
369
  user?: UserProfile;
@@ -405,169 +499,16 @@ declare function useCfgRouter(): {
405
499
  */
406
500
  declare function useQueryParams(): URLSearchParams;
407
501
 
408
- /**
409
- * Auth Form Types
410
- *
411
- * Single source of truth for auth form state and handlers.
412
- * Used by both @djangocfg/api/auth hooks and @djangocfg/layouts/AuthLayout.
413
- */
414
-
415
- type AuthChannel = 'email' | 'phone';
416
- type AuthStep = 'identifier' | 'otp' | '2fa' | '2fa-setup' | 'success';
417
- interface AuthFormState {
418
- /** Email or phone number */
419
- identifier: string;
420
- /** Current auth channel */
421
- channel: AuthChannel;
422
- /** OTP code input */
423
- otp: string;
424
- /** Loading state */
425
- isLoading: boolean;
426
- /** Terms acceptance state */
427
- acceptedTerms: boolean;
428
- /** Current form step */
429
- step: AuthStep;
430
- /** Error message */
431
- error: string;
432
- /** 2FA session ID from OTP/OAuth verification */
433
- twoFactorSessionId: string | null;
434
- /** Whether user should be prompted to enable 2FA */
435
- shouldPrompt2FA: boolean;
436
- /** 2FA code input */
437
- twoFactorCode: string;
438
- /** Using backup code instead of TOTP */
439
- useBackupCode: boolean;
440
- }
441
- interface AuthFormStateHandlers {
442
- setIdentifier: (identifier: string) => void;
443
- setChannel: (channel: AuthChannel) => void;
444
- setOtp: (otp: string) => void;
445
- setAcceptedTerms: (accepted: boolean) => void;
446
- setError: (error: string) => void;
447
- clearError: () => void;
448
- setStep: (step: AuthStep) => void;
449
- setIsLoading: (loading: boolean) => void;
450
- setTwoFactorSessionId: (sessionId: string | null) => void;
451
- setShouldPrompt2FA: (prompt: boolean) => void;
452
- setTwoFactorCode: (code: string) => void;
453
- setUseBackupCode: (useBackup: boolean) => void;
454
- }
455
- interface AuthFormSubmitHandlers {
456
- handleIdentifierSubmit: (e: React.FormEvent) => Promise<void>;
457
- handleOTPSubmit: (e: React.FormEvent) => Promise<void>;
458
- handleResendOTP: () => Promise<void>;
459
- handleBackToIdentifier: () => void;
460
- forceOTPStep: () => void;
461
- /** Handle 2FA TOTP/backup code verification */
462
- handle2FASubmit: (e: React.FormEvent) => Promise<void>;
463
- /** Switch to backup code input */
464
- handleUseBackupCode: () => void;
465
- /** Switch back to TOTP input */
466
- handleUseTOTP: () => void;
467
- }
468
- interface AuthFormValidation {
469
- /** Detect channel from identifier string */
470
- detectChannelFromIdentifier: (identifier: string) => AuthChannel | null;
471
- /** Validate identifier format */
472
- validateIdentifier: (identifier: string, channel?: AuthChannel) => boolean;
473
- }
474
- interface AuthFormAutoSubmit {
475
- /** Ref to track if auto-submit from URL is in progress */
476
- isAutoSubmittingFromUrl: MutableRefObject<boolean>;
477
- }
478
- interface AuthForm2FAState {
479
- /** Loading state for 2FA verification */
480
- is2FALoading: boolean;
481
- /** Warning message from 2FA (e.g., low backup codes) */
482
- twoFactorWarning: string | null;
483
- }
484
- interface AuthFormReturn extends AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthFormAutoSubmit, AuthForm2FAState {
485
- }
486
- interface UseAuthFormOptions {
487
- /** Callback when identifier step succeeds */
488
- onIdentifierSuccess?: (identifier: string, channel: AuthChannel) => void;
489
- /** Callback when OTP verification succeeds */
490
- onOTPSuccess?: () => void;
491
- /** Callback on any error */
492
- onError?: (message: string) => void;
493
- /** Source URL for tracking */
494
- sourceUrl: string;
495
- /** URL to redirect after successful OTP verification */
496
- redirectUrl?: string;
497
- /** If true, user must accept terms before submitting. Default: false */
498
- requireTermsAcceptance?: boolean;
499
- /** Path to auth page for auto-OTP detection. Default: '/auth' */
500
- authPath?: string;
501
- /**
502
- * Enable 2FA setup prompt after successful authentication.
503
- * When true (default), users without 2FA will see a setup prompt after login.
504
- * When false, users go directly to success without 2FA setup prompt.
505
- * @default true
506
- */
507
- enable2FASetup?: boolean;
508
- }
509
- interface AuthLayoutConfig {
510
- /** Support page URL */
511
- supportUrl?: string;
512
- /** Terms of service URL */
513
- termsUrl?: string;
514
- /** Privacy policy URL */
515
- privacyUrl?: string;
516
- /** Source URL for tracking */
517
- sourceUrl: string;
518
- /** Enable phone authentication tab */
519
- enablePhoneAuth?: boolean;
520
- /** Enable GitHub OAuth button */
521
- enableGithubAuth?: boolean;
522
- /** Logo URL for success screen (SVG recommended) */
523
- logoUrl?: string;
524
- /** URL to redirect after successful auth (default: /dashboard) */
525
- redirectUrl?: string;
526
- /**
527
- * Enable 2FA setup prompt after successful authentication.
528
- * When true (default), users without 2FA will see a setup prompt after login.
529
- * When false, users go directly to success without 2FA setup prompt.
530
- * Note: This only affects the setup prompt - existing 2FA verification still works.
531
- * @default true
532
- */
533
- enable2FASetup?: boolean;
534
- }
535
- interface AuthFormContextType extends AuthFormReturn, AuthLayoutConfig {
536
- }
537
- interface AuthLayoutProps extends AuthLayoutConfig {
538
- children?: React.ReactNode;
539
- className?: string;
540
- /** URL to redirect after successful auth (default: /dashboard) */
541
- redirectUrl?: string;
542
- /** Callback when identifier step succeeds */
543
- onIdentifierSuccess?: (identifier: string, channel: AuthChannel) => void;
544
- /** Callback when OTP verification succeeds */
545
- onOTPSuccess?: () => void;
546
- /** Callback when OAuth succeeds */
547
- onOAuthSuccess?: (user: any, isNewUser: boolean, provider: string) => void;
548
- /** Callback on any error */
549
- onError?: (message: string) => void;
550
- }
551
- interface AuthHelpProps {
552
- className?: string;
553
- variant?: 'default' | 'compact';
554
- }
555
-
556
502
  interface UseAuthFormStateReturn extends AuthFormState, AuthFormStateHandlers {
557
503
  }
558
504
  /**
559
505
  * Hook for auth form state management.
560
506
  * Pure state - no side effects, no API calls.
561
507
  */
562
- declare const useAuthFormState: (initialIdentifier?: string, initialChannel?: AuthChannel) => UseAuthFormStateReturn;
508
+ declare const useAuthFormState: (initialIdentifier?: string) => UseAuthFormStateReturn;
563
509
 
564
- /**
565
- * Hook for auth identifier validation.
566
- * Pure functions - no state, no side effects.
567
- */
568
510
  declare const useAuthValidation: () => AuthFormValidation;
569
- declare const detectChannelFromIdentifier: (id: string) => AuthChannel | null;
570
- declare const validateIdentifier: (id: string, channelType?: AuthChannel) => boolean;
511
+ declare const validateIdentifier: (id: string) => boolean;
571
512
 
572
513
  /**
573
514
  * Complete auth form hook.
@@ -647,6 +588,8 @@ interface UseTwoFactorReturn {
647
588
  warning: string | null;
648
589
  /** Remaining backup codes (if backup code was used) */
649
590
  remainingBackupCodes: number | null;
591
+ /** Remaining verification attempts before lockout */
592
+ attemptsRemaining: number | null;
650
593
  /** Verify TOTP code */
651
594
  verifyTOTP: (sessionId: string, code: string) => Promise<boolean>;
652
595
  /** Verify backup code */
@@ -1016,4 +959,4 @@ declare const Analytics: {
1016
959
  setUser(userId: string): void;
1017
960
  };
1018
961
 
1019
- export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthChannel, type AuthConfig, type AuthContextType, type AuthFormAutoSubmit, type AuthFormContextType, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, type AuthHelpProps, type AuthLayoutConfig, type AuthLayoutProps, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UserProfile, authLogger, clearProfileCache, decodeBase64, detectChannelFromIdentifier, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthGuard, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSessionStorage, useTokenRefresh, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, validateEmail, validateIdentifier };
962
+ export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type OTPRequestResult, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UserProfile, authLogger, clearProfileCache, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthGuard, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSessionStorage, useTokenRefresh, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, validateEmail, validateIdentifier };