@djangocfg/api 2.1.55 → 2.1.56

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 (93) hide show
  1. package/dist/auth.cjs +28 -15
  2. package/dist/auth.cjs.map +1 -1
  3. package/dist/auth.d.cts +6 -6
  4. package/dist/auth.d.ts +6 -6
  5. package/dist/auth.mjs +28 -15
  6. package/dist/auth.mjs.map +1 -1
  7. package/dist/clients.cjs +56 -17
  8. package/dist/clients.cjs.map +1 -1
  9. package/dist/clients.d.cts +17 -17
  10. package/dist/clients.d.ts +17 -17
  11. package/dist/clients.mjs +56 -17
  12. package/dist/clients.mjs.map +1 -1
  13. package/dist/hooks.cjs +763 -12
  14. package/dist/hooks.cjs.map +1 -1
  15. package/dist/hooks.d.cts +11 -11
  16. package/dist/hooks.d.ts +11 -11
  17. package/dist/hooks.mjs +763 -12
  18. package/dist/hooks.mjs.map +1 -1
  19. package/dist/index.cjs +893 -69
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +59 -41
  22. package/dist/index.d.ts +59 -41
  23. package/dist/index.mjs +893 -69
  24. package/dist/index.mjs.map +1 -1
  25. package/package.json +3 -3
  26. package/src/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +1 -1
  27. package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +2 -2
  28. package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +1 -1
  29. package/src/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +1 -1
  30. package/src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +1 -1
  31. package/src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +1 -1
  32. package/src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +1 -1
  33. package/src/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +1 -1
  34. package/src/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +1 -1
  35. package/src/generated/cfg_accounts/_utils/schemas/User.schema.ts +1 -1
  36. package/src/generated/cfg_accounts/api-instance.ts +61 -13
  37. package/src/generated/cfg_centrifugo/api-instance.ts +61 -13
  38. package/src/generated/cfg_totp/CLAUDE.md +90 -0
  39. package/src/generated/cfg_totp/_utils/fetchers/index.ts +33 -0
  40. package/src/generated/cfg_totp/_utils/fetchers/totp.ts +49 -0
  41. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_management.ts +108 -0
  42. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_setup.ts +153 -0
  43. package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_verification.ts +152 -0
  44. package/src/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +152 -0
  45. package/src/generated/cfg_totp/_utils/hooks/index.ts +33 -0
  46. package/src/generated/cfg_totp/_utils/hooks/totp.ts +42 -0
  47. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_management.ts +58 -0
  48. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_setup.ts +63 -0
  49. package/src/generated/cfg_totp/_utils/hooks/totp__2fa_verification.ts +62 -0
  50. package/src/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +59 -0
  51. package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +19 -0
  52. package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +20 -0
  53. package/src/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +21 -0
  54. package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +20 -0
  55. package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +21 -0
  56. package/src/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +26 -0
  57. package/src/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +19 -0
  58. package/src/generated/cfg_totp/_utils/schemas/PaginatedDeviceListList.schema.ts +24 -0
  59. package/src/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +19 -0
  60. package/src/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +23 -0
  61. package/src/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +20 -0
  62. package/src/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +20 -0
  63. package/src/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +24 -0
  64. package/src/generated/cfg_totp/_utils/schemas/index.ts +32 -0
  65. package/src/generated/cfg_totp/api-instance.ts +180 -0
  66. package/src/generated/cfg_totp/client.ts +313 -0
  67. package/src/generated/cfg_totp/enums.ts +12 -0
  68. package/src/generated/cfg_totp/errors.ts +117 -0
  69. package/src/generated/cfg_totp/http.ts +104 -0
  70. package/src/generated/cfg_totp/index.ts +302 -0
  71. package/src/generated/cfg_totp/logger.ts +260 -0
  72. package/src/generated/cfg_totp/retry.ts +176 -0
  73. package/src/generated/cfg_totp/schema.json +859 -0
  74. package/src/generated/cfg_totp/storage.ts +162 -0
  75. package/src/generated/cfg_totp/totp/client.ts +23 -0
  76. package/src/generated/cfg_totp/totp/index.ts +3 -0
  77. package/src/generated/cfg_totp/totp/models.ts +1 -0
  78. package/src/generated/cfg_totp/totp__2fa_management/client.ts +41 -0
  79. package/src/generated/cfg_totp/totp__2fa_management/index.ts +3 -0
  80. package/src/generated/cfg_totp/totp__2fa_management/models.ts +60 -0
  81. package/src/generated/cfg_totp/totp__2fa_setup/client.ts +32 -0
  82. package/src/generated/cfg_totp/totp__2fa_setup/index.ts +3 -0
  83. package/src/generated/cfg_totp/totp__2fa_setup/models.ts +54 -0
  84. package/src/generated/cfg_totp/totp__2fa_verification/client.ts +32 -0
  85. package/src/generated/cfg_totp/totp__2fa_verification/index.ts +3 -0
  86. package/src/generated/cfg_totp/totp__2fa_verification/models.ts +44 -0
  87. package/src/generated/cfg_totp/totp__backup_codes/client.ts +31 -0
  88. package/src/generated/cfg_totp/totp__backup_codes/index.ts +3 -0
  89. package/src/generated/cfg_totp/totp__backup_codes/models.ts +37 -0
  90. package/src/generated/cfg_totp/validation-events.ts +134 -0
  91. package/src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts +2 -2
  92. package/src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts +1 -1
  93. package/src/generated/cfg_webpush/api-instance.ts +61 -13
@@ -12,8 +12,8 @@ import { z } from 'zod'
12
12
  export const SendPushRequestRequestSchema = z.object({
13
13
  title: z.string().min(1).max(255),
14
14
  body: z.string().min(1),
15
- icon: z.url().nullable().optional(),
16
- url: z.url().nullable().optional(),
15
+ icon: z.union([z.url(), z.literal('')]).nullable().optional(),
16
+ url: z.union([z.url(), z.literal('')]).nullable().optional(),
17
17
  })
18
18
 
19
19
  /**
@@ -10,7 +10,7 @@ import { z } from 'zod'
10
10
  * Request serializer for subscribing to push notifications.
11
11
  */
12
12
  export const SubscribeRequestRequestSchema = z.object({
13
- endpoint: z.url(),
13
+ endpoint: z.union([z.url(), z.literal('')]),
14
14
  keys: z.record(z.string(), z.string().min(1)),
15
15
  })
16
16
 
@@ -1,29 +1,37 @@
1
1
  // Auto-generated by DjangoCFG - see CLAUDE.md
2
2
  /**
3
- * Global API Instance - Singleton configuration
3
+ * Global API Instance - Singleton configuration with auto-configuration support
4
4
  *
5
- * This module provides a global API instance that can be configured once
6
- * and used throughout your application.
5
+ * This module provides a global API instance that auto-configures from
6
+ * environment variables or can be configured manually.
7
7
  *
8
- * Usage:
8
+ * AUTO-CONFIGURATION (recommended):
9
+ * Set one of these environment variables and the API will auto-configure:
10
+ * - NEXT_PUBLIC_API_URL (Next.js)
11
+ * - VITE_API_URL (Vite)
12
+ * - REACT_APP_API_URL (Create React App)
13
+ * - API_URL (generic)
14
+ *
15
+ * Then just use fetchers and hooks directly:
16
+ * ```typescript
17
+ * import { getUsers } from './_utils/fetchers'
18
+ * const users = await getUsers({ page: 1 })
19
+ * ```
20
+ *
21
+ * MANUAL CONFIGURATION:
9
22
  * ```typescript
10
- * // Configure once (e.g., in your app entry point)
11
23
  * import { configureAPI } from './api-instance'
12
24
  *
13
25
  * configureAPI({
14
26
  * baseUrl: 'https://api.example.com',
15
27
  * token: 'your-jwt-token'
16
28
  * })
17
- *
18
- * // Then use fetchers and hooks anywhere without configuration
19
- * import { getUsers } from './fetchers'
20
- * const users = await getUsers({ page: 1 })
21
29
  * ```
22
30
  *
23
31
  * For SSR or multiple instances:
24
32
  * ```typescript
25
33
  * import { API } from './index'
26
- * import { getUsers } from './fetchers'
34
+ * import { getUsers } from './_utils/fetchers'
27
35
  *
28
36
  * const api = new API('https://api.example.com')
29
37
  * const users = await getUsers({ page: 1 }, api)
@@ -33,27 +41,67 @@
33
41
  import { API, type APIOptions } from './index'
34
42
 
35
43
  let globalAPI: API | null = null
44
+ let autoConfigAttempted = false
45
+
46
+ /**
47
+ * Auto-configure from environment variable if available (Next.js pattern)
48
+ * This allows hooks and fetchers to work without explicit configureAPI() call
49
+ *
50
+ * Supported environment variables:
51
+ * - NEXT_PUBLIC_API_URL (Next.js)
52
+ * - VITE_API_URL (Vite)
53
+ * - REACT_APP_API_URL (Create React App)
54
+ * - API_URL (generic)
55
+ */
56
+ function tryAutoConfigureFromEnv(): void {
57
+ // Only attempt once
58
+ if (autoConfigAttempted) return
59
+ autoConfigAttempted = true
60
+
61
+ // Skip if already configured
62
+ if (globalAPI) return
63
+
64
+ // Skip if process is not available (pure browser without bundler)
65
+ if (typeof process === 'undefined' || !process.env) return
66
+
67
+ // Try different environment variable patterns
68
+ const baseUrl =
69
+ process.env.NEXT_PUBLIC_API_URL ||
70
+ process.env.VITE_API_URL ||
71
+ process.env.REACT_APP_API_URL ||
72
+ process.env.API_URL
73
+
74
+ if (baseUrl) {
75
+ globalAPI = new API(baseUrl)
76
+ }
77
+ }
36
78
 
37
79
  /**
38
80
  * Get the global API instance
39
- * @throws Error if API is not configured
81
+ * Auto-configures from environment variables on first call if not manually configured.
82
+ * @throws Error if API is not configured and no env variable is set
40
83
  */
41
84
  export function getAPIInstance(): API {
85
+ // Try auto-configuration on first access (lazy initialization)
86
+ tryAutoConfigureFromEnv()
87
+
42
88
  if (!globalAPI) {
43
89
  throw new Error(
44
90
  'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\n' +
45
91
  'Example:\n' +
46
92
  ' import { configureAPI } from "./api-instance"\n' +
47
- ' configureAPI({ baseUrl: "https://api.example.com" })'
93
+ ' configureAPI({ baseUrl: "https://api.example.com" })\n\n' +
94
+ 'Or set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
48
95
  )
49
96
  }
50
97
  return globalAPI
51
98
  }
52
99
 
53
100
  /**
54
- * Check if API is configured
101
+ * Check if API is configured (or can be auto-configured)
55
102
  */
56
103
  export function isAPIConfigured(): boolean {
104
+ tryAutoConfigureFromEnv()
57
105
  return globalAPI !== null
58
106
  }
59
107