@djangocfg/api 2.1.346 → 2.1.347

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.346",
3
+ "version": "2.1.347",
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",
@@ -79,7 +79,7 @@
79
79
  "devDependencies": {
80
80
  "@types/node": "^24.7.2",
81
81
  "@types/react": "^19.1.0",
82
- "@djangocfg/typescript-config": "^2.1.346",
82
+ "@djangocfg/typescript-config": "^2.1.347",
83
83
  "next": "^16.2.2",
84
84
  "react": "^19.1.0",
85
85
  "tsup": "^8.5.0",
@@ -292,6 +292,12 @@ export function installAuthOnClient(client: HeyClient): void {
292
292
  const apiKey = auth.getApiKey();
293
293
  if (apiKey) request.headers.set('X-API-Key', apiKey);
294
294
 
295
+ try {
296
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
297
+ if (tz) request.headers.set('X-Timezone', tz);
298
+ } catch {}
299
+ request.headers.set('X-Client-Time', new Date().toISOString());
300
+
295
301
  return request;
296
302
  });
297
303
 
@@ -26,6 +26,13 @@ export { API as CfgTotpAPI } from './_cfg_totp';
26
26
 
27
27
  // Hey API SDK classes — one per OpenAPI tag. Lets consumers call
28
28
  // `Centrifugo.cfgCentrifugoAuthTokenRetrieve({...})` directly.
29
+ //
30
+ // NOTE: classes whose name would collide with a barrel-level type
31
+ // alias (e.g. `Auth`, which is also `type Auth = typeof auth`) are
32
+ // re-exported under a `*SDK` suffix here. The original name is still
33
+ // available via the per-group import: `import { Auth } from
34
+ // '<api>/_auth'`. To remove the alias, rename the OpenAPI tag on the
35
+ // backend so the SDK class doesn't collide.
29
36
 
30
37
 
31
38
  // Shared utilities (errors, storage adapters, logger).
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Auth-related constants shared across the frontend.
3
+ * Single source of truth — do not redefine these elsewhere.
4
+ */
5
+
6
+ export const AUTH_CONSTANTS = {
7
+ /** Email OTP code length (numeric). */
8
+ EMAIL_OTP_LENGTH: 4,
9
+ /** TOTP code length (RFC 6238 — authenticator apps). */
10
+ TOTP_LENGTH: 6,
11
+ /** Backup code max length. */
12
+ BACKUP_CODE_MAX_LENGTH: 12,
13
+ } as const;
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useCallback, useEffect, useRef } from 'react';
4
4
 
5
+ import { AUTH_CONSTANTS } from '../constants';
5
6
  import { useAuth } from '../context';
6
7
  import { authLogger } from '../utils/logger';
7
8
  import { useAuthFormState } from './useAuthFormState';
@@ -167,8 +168,8 @@ export const useAuthForm = (options: UseAuthFormOptions): AuthFormReturn => {
167
168
  submitIdentifier: string,
168
169
  submitOtp: string,
169
170
  ): Promise<boolean> => {
170
- if (!submitOtp || submitOtp.length < 6) {
171
- const msg = 'Please enter the 6-digit verification code';
171
+ if (!submitOtp || submitOtp.length < AUTH_CONSTANTS.EMAIL_OTP_LENGTH) {
172
+ const msg = `Please enter the ${AUTH_CONSTANTS.EMAIL_OTP_LENGTH}-digit verification code`;
172
173
  setError(msg);
173
174
  onError?.(msg);
174
175
  return false;
@@ -3,6 +3,7 @@
3
3
  import { usePathname } from 'next/navigation';
4
4
  import { useEffect } from 'react';
5
5
 
6
+ import { AUTH_CONSTANTS } from '../constants';
6
7
  import { authLogger } from '../utils/logger';
7
8
  import { useCfgRouter } from './useCfgRouter';
8
9
  import { useQueryParams } from './useQueryParams';
@@ -37,7 +38,7 @@ export const useAutoAuth = (options: UseAutoAuthOptions = {}) => {
37
38
 
38
39
  // Handle OTP detection - only on allowed paths to avoid conflicts with other pages
39
40
  // (e.g., /dashboard/device uses ?otp= for device authorization, not user auth)
40
- if (queryOtp && typeof queryOtp === 'string' && queryOtp.length === 6) {
41
+ if (queryOtp && typeof queryOtp === 'string' && queryOtp.length === AUTH_CONSTANTS.EMAIL_OTP_LENGTH) {
41
42
  authLogger.info('OTP detected in URL on auth page:', queryOtp);
42
43
  onOTPDetected?.(queryOtp);
43
44
  }
package/src/auth/index.ts CHANGED
@@ -24,6 +24,9 @@
24
24
  * ```
25
25
  */
26
26
 
27
+ // Constants
28
+ export * from './constants';
29
+
27
30
  // Contexts
28
31
  export * from './context';
29
32