@djangocfg/api 2.1.55 → 2.1.57

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
@@ -0,0 +1,176 @@
1
+ // Auto-generated by DjangoCFG - see CLAUDE.md
2
+ /**
3
+ * Retry Configuration and Utilities
4
+ *
5
+ * Provides automatic retry logic for failed HTTP requests using p-retry.
6
+ * Retries only on network errors and server errors (5xx), not client errors (4xx).
7
+ */
8
+
9
+ import pRetry, { AbortError } from 'p-retry';
10
+ import { APIError, NetworkError } from './errors';
11
+
12
+ /**
13
+ * Information about a failed retry attempt.
14
+ */
15
+ export interface FailedAttemptInfo {
16
+ /** The error that caused the failure */
17
+ error: Error;
18
+ /** The attempt number (1-indexed) */
19
+ attemptNumber: number;
20
+ /** Number of retries left */
21
+ retriesLeft: number;
22
+ }
23
+
24
+ /**
25
+ * Retry configuration options.
26
+ *
27
+ * Uses exponential backoff with jitter by default to avoid thundering herd.
28
+ */
29
+ export interface RetryConfig {
30
+ /**
31
+ * Maximum number of retry attempts.
32
+ * @default 3
33
+ */
34
+ retries?: number;
35
+
36
+ /**
37
+ * Exponential backoff factor.
38
+ * @default 2
39
+ */
40
+ factor?: number;
41
+
42
+ /**
43
+ * Minimum wait time between retries (ms).
44
+ * @default 1000
45
+ */
46
+ minTimeout?: number;
47
+
48
+ /**
49
+ * Maximum wait time between retries (ms).
50
+ * @default 60000
51
+ */
52
+ maxTimeout?: number;
53
+
54
+ /**
55
+ * Add randomness to wait times (jitter).
56
+ * Helps avoid thundering herd problem.
57
+ * @default true
58
+ */
59
+ randomize?: boolean;
60
+
61
+ /**
62
+ * Callback called on each failed attempt.
63
+ */
64
+ onFailedAttempt?: (info: FailedAttemptInfo) => void;
65
+ }
66
+
67
+ /**
68
+ * Default retry configuration.
69
+ */
70
+ export const DEFAULT_RETRY_CONFIG: Required<RetryConfig> = {
71
+ retries: 3,
72
+ factor: 2,
73
+ minTimeout: 1000,
74
+ maxTimeout: 60000,
75
+ randomize: true,
76
+ onFailedAttempt: () => {},
77
+ };
78
+
79
+ /**
80
+ * Determine if an error should trigger a retry.
81
+ *
82
+ * Retries on:
83
+ * - Network errors (connection refused, timeout, etc.)
84
+ * - Server errors (5xx status codes)
85
+ * - Rate limiting (429 status code)
86
+ *
87
+ * Does NOT retry on:
88
+ * - Client errors (4xx except 429)
89
+ * - Authentication errors (401, 403)
90
+ * - Not found (404)
91
+ *
92
+ * @param error - The error to check
93
+ * @returns true if should retry, false otherwise
94
+ */
95
+ export function shouldRetry(error: any): boolean {
96
+ // Always retry network errors
97
+ if (error instanceof NetworkError) {
98
+ return true;
99
+ }
100
+
101
+ // For API errors, check status code
102
+ if (error instanceof APIError) {
103
+ const status = error.statusCode;
104
+
105
+ // Retry on 5xx server errors
106
+ if (status >= 500 && status < 600) {
107
+ return true;
108
+ }
109
+
110
+ // Retry on 429 (rate limit)
111
+ if (status === 429) {
112
+ return true;
113
+ }
114
+
115
+ // Do NOT retry on 4xx client errors
116
+ return false;
117
+ }
118
+
119
+ // Retry on unknown errors (might be network issues)
120
+ return true;
121
+ }
122
+
123
+ /**
124
+ * Wrap a function with retry logic.
125
+ *
126
+ * @param fn - Async function to retry
127
+ * @param config - Retry configuration
128
+ * @returns Result of the function
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const result = await withRetry(
133
+ * async () => fetch('https://api.example.com/users'),
134
+ * { retries: 5, minTimeout: 2000 }
135
+ * );
136
+ * ```
137
+ */
138
+ export async function withRetry<T>(
139
+ fn: () => Promise<T>,
140
+ config?: RetryConfig
141
+ ): Promise<T> {
142
+ const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
143
+
144
+ return pRetry(
145
+ async () => {
146
+ try {
147
+ return await fn();
148
+ } catch (error) {
149
+ // Check if we should retry this error
150
+ if (!shouldRetry(error)) {
151
+ // Abort retry immediately for non-retryable errors
152
+ throw new AbortError(error as Error);
153
+ }
154
+
155
+ // Re-throw error to trigger retry
156
+ throw error;
157
+ }
158
+ },
159
+ {
160
+ retries: finalConfig.retries,
161
+ factor: finalConfig.factor,
162
+ minTimeout: finalConfig.minTimeout,
163
+ maxTimeout: finalConfig.maxTimeout,
164
+ randomize: finalConfig.randomize,
165
+ onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
166
+ // Adapt p-retry's FailedAttemptError to our FailedAttemptInfo
167
+ const pRetryError = error as any; // p-retry's internal type
168
+ finalConfig.onFailedAttempt!({
169
+ error: pRetryError as Error,
170
+ attemptNumber: pRetryError.attemptNumber,
171
+ retriesLeft: pRetryError.retriesLeft,
172
+ });
173
+ } : undefined,
174
+ }
175
+ );
176
+ }