@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.
- package/dist/auth.cjs +28 -15
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +6 -6
- package/dist/auth.d.ts +6 -6
- package/dist/auth.mjs +28 -15
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +56 -17
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +17 -17
- package/dist/clients.d.ts +17 -17
- package/dist/clients.mjs +56 -17
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +763 -12
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +11 -11
- package/dist/hooks.d.ts +11 -11
- package/dist/hooks.mjs +763 -12
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +893 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -41
- package/dist/index.d.ts +59 -41
- package/dist/index.mjs +893 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +2 -2
- package/src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +1 -1
- package/src/generated/cfg_accounts/_utils/schemas/User.schema.ts +1 -1
- package/src/generated/cfg_accounts/api-instance.ts +61 -13
- package/src/generated/cfg_centrifugo/api-instance.ts +61 -13
- package/src/generated/cfg_totp/CLAUDE.md +90 -0
- package/src/generated/cfg_totp/_utils/fetchers/index.ts +33 -0
- package/src/generated/cfg_totp/_utils/fetchers/totp.ts +49 -0
- package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_management.ts +108 -0
- package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_setup.ts +153 -0
- package/src/generated/cfg_totp/_utils/fetchers/totp__2fa_verification.ts +152 -0
- package/src/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +152 -0
- package/src/generated/cfg_totp/_utils/hooks/index.ts +33 -0
- package/src/generated/cfg_totp/_utils/hooks/totp.ts +42 -0
- package/src/generated/cfg_totp/_utils/hooks/totp__2fa_management.ts +58 -0
- package/src/generated/cfg_totp/_utils/hooks/totp__2fa_setup.ts +63 -0
- package/src/generated/cfg_totp/_utils/hooks/totp__2fa_verification.ts +62 -0
- package/src/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +59 -0
- package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +19 -0
- package/src/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +20 -0
- package/src/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +21 -0
- package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +20 -0
- package/src/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +21 -0
- package/src/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +26 -0
- package/src/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +19 -0
- package/src/generated/cfg_totp/_utils/schemas/PaginatedDeviceListList.schema.ts +24 -0
- package/src/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +19 -0
- package/src/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +23 -0
- package/src/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +20 -0
- package/src/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +20 -0
- package/src/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +24 -0
- package/src/generated/cfg_totp/_utils/schemas/index.ts +32 -0
- package/src/generated/cfg_totp/api-instance.ts +180 -0
- package/src/generated/cfg_totp/client.ts +313 -0
- package/src/generated/cfg_totp/enums.ts +12 -0
- package/src/generated/cfg_totp/errors.ts +117 -0
- package/src/generated/cfg_totp/http.ts +104 -0
- package/src/generated/cfg_totp/index.ts +302 -0
- package/src/generated/cfg_totp/logger.ts +260 -0
- package/src/generated/cfg_totp/retry.ts +176 -0
- package/src/generated/cfg_totp/schema.json +859 -0
- package/src/generated/cfg_totp/storage.ts +162 -0
- package/src/generated/cfg_totp/totp/client.ts +23 -0
- package/src/generated/cfg_totp/totp/index.ts +3 -0
- package/src/generated/cfg_totp/totp/models.ts +1 -0
- package/src/generated/cfg_totp/totp__2fa_management/client.ts +41 -0
- package/src/generated/cfg_totp/totp__2fa_management/index.ts +3 -0
- package/src/generated/cfg_totp/totp__2fa_management/models.ts +60 -0
- package/src/generated/cfg_totp/totp__2fa_setup/client.ts +32 -0
- package/src/generated/cfg_totp/totp__2fa_setup/index.ts +3 -0
- package/src/generated/cfg_totp/totp__2fa_setup/models.ts +54 -0
- package/src/generated/cfg_totp/totp__2fa_verification/client.ts +32 -0
- package/src/generated/cfg_totp/totp__2fa_verification/index.ts +3 -0
- package/src/generated/cfg_totp/totp__2fa_verification/models.ts +44 -0
- package/src/generated/cfg_totp/totp__backup_codes/client.ts +31 -0
- package/src/generated/cfg_totp/totp__backup_codes/index.ts +3 -0
- package/src/generated/cfg_totp/totp__backup_codes/models.ts +37 -0
- package/src/generated/cfg_totp/validation-events.ts +134 -0
- package/src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts +2 -2
- package/src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts +1 -1
- package/src/generated/cfg_webpush/api-instance.ts +61 -13
package/dist/hooks.mjs
CHANGED
|
@@ -15,6 +15,315 @@ var TokenRefreshSchema = z.object({
|
|
|
15
15
|
refresh: z.string()
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
// src/generated/cfg_accounts/accounts__auth/client.ts
|
|
19
|
+
var Auth = class {
|
|
20
|
+
static {
|
|
21
|
+
__name(this, "Auth");
|
|
22
|
+
}
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Refresh JWT token.
|
|
28
|
+
*/
|
|
29
|
+
async accountsTokenRefreshCreate(data) {
|
|
30
|
+
const response = await this.client.request("POST", "/cfg/accounts/token/refresh/", { body: data });
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/generated/cfg_accounts/accounts__oauth/client.ts
|
|
36
|
+
var Oauth = class {
|
|
37
|
+
static {
|
|
38
|
+
__name(this, "Oauth");
|
|
39
|
+
}
|
|
40
|
+
constructor(client) {
|
|
41
|
+
this.client = client;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* List OAuth connections
|
|
45
|
+
*
|
|
46
|
+
* Get all OAuth connections for the current user.
|
|
47
|
+
*/
|
|
48
|
+
async accountsOauthConnectionsList() {
|
|
49
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/connections/");
|
|
50
|
+
return response;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Disconnect OAuth provider
|
|
54
|
+
*
|
|
55
|
+
* Remove OAuth connection for the specified provider.
|
|
56
|
+
*/
|
|
57
|
+
async accountsOauthDisconnectCreate(data) {
|
|
58
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/disconnect/", { body: data });
|
|
59
|
+
return response;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Start GitHub OAuth
|
|
63
|
+
*
|
|
64
|
+
* Generate GitHub OAuth authorization URL. Redirect user to this URL to
|
|
65
|
+
* start authentication.
|
|
66
|
+
*/
|
|
67
|
+
async accountsOauthGithubAuthorizeCreate(data) {
|
|
68
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/authorize/", { body: data });
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Complete GitHub OAuth
|
|
73
|
+
*
|
|
74
|
+
* Exchange authorization code for JWT tokens. Call this after GitHub
|
|
75
|
+
* redirects back with code.
|
|
76
|
+
*/
|
|
77
|
+
async accountsOauthGithubCallbackCreate(data) {
|
|
78
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/callback/", { body: data });
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* List OAuth providers
|
|
83
|
+
*
|
|
84
|
+
* Get list of available OAuth providers for authentication.
|
|
85
|
+
*/
|
|
86
|
+
async accountsOauthProvidersRetrieve() {
|
|
87
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/providers/");
|
|
88
|
+
return response;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/generated/cfg_accounts/accounts__user_profile/client.ts
|
|
93
|
+
var UserProfile = class {
|
|
94
|
+
static {
|
|
95
|
+
__name(this, "UserProfile");
|
|
96
|
+
}
|
|
97
|
+
constructor(client) {
|
|
98
|
+
this.client = client;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get current user profile
|
|
102
|
+
*
|
|
103
|
+
* Retrieve the current authenticated user's profile information.
|
|
104
|
+
*/
|
|
105
|
+
async accountsProfileRetrieve() {
|
|
106
|
+
const response = await this.client.request("GET", "/cfg/accounts/profile/");
|
|
107
|
+
return response;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Upload user avatar
|
|
111
|
+
*
|
|
112
|
+
* Upload avatar image for the current authenticated user. Accepts
|
|
113
|
+
* multipart/form-data with 'avatar' field.
|
|
114
|
+
*/
|
|
115
|
+
async accountsProfileAvatarCreate(data) {
|
|
116
|
+
const response = await this.client.request("POST", "/cfg/accounts/profile/avatar/", { formData: data });
|
|
117
|
+
return response;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Partial update user profile
|
|
121
|
+
*
|
|
122
|
+
* Partially update the current authenticated user's profile information.
|
|
123
|
+
* Supports avatar upload.
|
|
124
|
+
*/
|
|
125
|
+
async accountsProfilePartialUpdate(data) {
|
|
126
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/partial/", { body: data });
|
|
127
|
+
return response;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Partial update user profile
|
|
131
|
+
*
|
|
132
|
+
* Partially update the current authenticated user's profile information.
|
|
133
|
+
* Supports avatar upload.
|
|
134
|
+
*/
|
|
135
|
+
async accountsProfilePartialPartialUpdate(data) {
|
|
136
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/partial/", { body: data });
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Update user profile
|
|
141
|
+
*
|
|
142
|
+
* Update the current authenticated user's profile information.
|
|
143
|
+
*/
|
|
144
|
+
async accountsProfileUpdateUpdate(data) {
|
|
145
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/update/", { body: data });
|
|
146
|
+
return response;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Update user profile
|
|
150
|
+
*
|
|
151
|
+
* Update the current authenticated user's profile information.
|
|
152
|
+
*/
|
|
153
|
+
async accountsProfileUpdatePartialUpdate(data) {
|
|
154
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/update/", { body: data });
|
|
155
|
+
return response;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/generated/cfg_accounts/accounts/client.ts
|
|
160
|
+
var Accounts = class {
|
|
161
|
+
static {
|
|
162
|
+
__name(this, "Accounts");
|
|
163
|
+
}
|
|
164
|
+
constructor(client) {
|
|
165
|
+
this.client = client;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Request OTP code to email or phone.
|
|
169
|
+
*/
|
|
170
|
+
async otpRequestCreate(data) {
|
|
171
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/request/", { body: data });
|
|
172
|
+
return response;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Verify OTP code and return JWT tokens.
|
|
176
|
+
*/
|
|
177
|
+
async otpVerifyCreate(data) {
|
|
178
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/verify/", { body: data });
|
|
179
|
+
return response;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/generated/cfg_accounts/http.ts
|
|
184
|
+
var FetchAdapter = class {
|
|
185
|
+
static {
|
|
186
|
+
__name(this, "FetchAdapter");
|
|
187
|
+
}
|
|
188
|
+
async request(request) {
|
|
189
|
+
const { method, url, headers, body, params, formData } = request;
|
|
190
|
+
let finalUrl = url;
|
|
191
|
+
if (params) {
|
|
192
|
+
const searchParams = new URLSearchParams();
|
|
193
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
194
|
+
if (value !== null && value !== void 0) {
|
|
195
|
+
searchParams.append(key, String(value));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const queryString = searchParams.toString();
|
|
199
|
+
if (queryString) {
|
|
200
|
+
finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const finalHeaders = { ...headers };
|
|
204
|
+
let requestBody;
|
|
205
|
+
if (formData) {
|
|
206
|
+
requestBody = formData;
|
|
207
|
+
} else if (body) {
|
|
208
|
+
finalHeaders["Content-Type"] = "application/json";
|
|
209
|
+
requestBody = JSON.stringify(body);
|
|
210
|
+
}
|
|
211
|
+
const response = await fetch(finalUrl, {
|
|
212
|
+
method,
|
|
213
|
+
headers: finalHeaders,
|
|
214
|
+
body: requestBody,
|
|
215
|
+
credentials: "include"
|
|
216
|
+
// Include Django session cookies
|
|
217
|
+
});
|
|
218
|
+
let data = null;
|
|
219
|
+
const contentType = response.headers.get("content-type");
|
|
220
|
+
if (response.status !== 204 && contentType?.includes("application/json")) {
|
|
221
|
+
data = await response.json();
|
|
222
|
+
} else if (response.status !== 204) {
|
|
223
|
+
data = await response.text();
|
|
224
|
+
}
|
|
225
|
+
const responseHeaders = {};
|
|
226
|
+
response.headers.forEach((value, key) => {
|
|
227
|
+
responseHeaders[key] = value;
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
data,
|
|
231
|
+
status: response.status,
|
|
232
|
+
statusText: response.statusText,
|
|
233
|
+
headers: responseHeaders
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/generated/cfg_accounts/errors.ts
|
|
239
|
+
var APIError = class extends Error {
|
|
240
|
+
constructor(statusCode, statusText, response, url, message) {
|
|
241
|
+
super(message || `HTTP ${statusCode}: ${statusText}`);
|
|
242
|
+
this.statusCode = statusCode;
|
|
243
|
+
this.statusText = statusText;
|
|
244
|
+
this.response = response;
|
|
245
|
+
this.url = url;
|
|
246
|
+
this.name = "APIError";
|
|
247
|
+
}
|
|
248
|
+
static {
|
|
249
|
+
__name(this, "APIError");
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get error details from response.
|
|
253
|
+
* DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
|
|
254
|
+
*/
|
|
255
|
+
get details() {
|
|
256
|
+
if (typeof this.response === "object" && this.response !== null) {
|
|
257
|
+
return this.response;
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Get field-specific validation errors from DRF.
|
|
263
|
+
* Returns: { "field_name": ["error1", "error2"], ... }
|
|
264
|
+
*/
|
|
265
|
+
get fieldErrors() {
|
|
266
|
+
const details = this.details;
|
|
267
|
+
if (!details) return null;
|
|
268
|
+
const fieldErrors = {};
|
|
269
|
+
for (const [key, value] of Object.entries(details)) {
|
|
270
|
+
if (Array.isArray(value)) {
|
|
271
|
+
fieldErrors[key] = value;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Get single error message from DRF.
|
|
278
|
+
* Checks for "detail", "message", or first field error.
|
|
279
|
+
*/
|
|
280
|
+
get errorMessage() {
|
|
281
|
+
const details = this.details;
|
|
282
|
+
if (!details) return this.message;
|
|
283
|
+
if (details.detail) {
|
|
284
|
+
return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
|
|
285
|
+
}
|
|
286
|
+
if (details.message) {
|
|
287
|
+
return String(details.message);
|
|
288
|
+
}
|
|
289
|
+
const fieldErrors = this.fieldErrors;
|
|
290
|
+
if (fieldErrors) {
|
|
291
|
+
const firstField = Object.keys(fieldErrors)[0];
|
|
292
|
+
if (firstField) {
|
|
293
|
+
return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return this.message;
|
|
297
|
+
}
|
|
298
|
+
// Helper methods for common HTTP status codes
|
|
299
|
+
get isValidationError() {
|
|
300
|
+
return this.statusCode === 400;
|
|
301
|
+
}
|
|
302
|
+
get isAuthError() {
|
|
303
|
+
return this.statusCode === 401;
|
|
304
|
+
}
|
|
305
|
+
get isPermissionError() {
|
|
306
|
+
return this.statusCode === 403;
|
|
307
|
+
}
|
|
308
|
+
get isNotFoundError() {
|
|
309
|
+
return this.statusCode === 404;
|
|
310
|
+
}
|
|
311
|
+
get isServerError() {
|
|
312
|
+
return this.statusCode >= 500 && this.statusCode < 600;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var NetworkError = class extends Error {
|
|
316
|
+
constructor(message, url, originalError) {
|
|
317
|
+
super(message);
|
|
318
|
+
this.url = url;
|
|
319
|
+
this.originalError = originalError;
|
|
320
|
+
this.name = "NetworkError";
|
|
321
|
+
}
|
|
322
|
+
static {
|
|
323
|
+
__name(this, "NetworkError");
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
18
327
|
// src/generated/cfg_accounts/logger.ts
|
|
19
328
|
import { createConsola } from "consola";
|
|
20
329
|
var DEFAULT_CONFIG = {
|
|
@@ -171,6 +480,308 @@ var defaultLogger = new APILogger();
|
|
|
171
480
|
|
|
172
481
|
// src/generated/cfg_accounts/retry.ts
|
|
173
482
|
import pRetry, { AbortError } from "p-retry";
|
|
483
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
484
|
+
retries: 3,
|
|
485
|
+
factor: 2,
|
|
486
|
+
minTimeout: 1e3,
|
|
487
|
+
maxTimeout: 6e4,
|
|
488
|
+
randomize: true,
|
|
489
|
+
onFailedAttempt: /* @__PURE__ */ __name(() => {
|
|
490
|
+
}, "onFailedAttempt")
|
|
491
|
+
};
|
|
492
|
+
function shouldRetry(error) {
|
|
493
|
+
if (error instanceof NetworkError) {
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
if (error instanceof APIError) {
|
|
497
|
+
const status = error.statusCode;
|
|
498
|
+
if (status >= 500 && status < 600) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
if (status === 429) {
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
__name(shouldRetry, "shouldRetry");
|
|
509
|
+
async function withRetry(fn, config) {
|
|
510
|
+
const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
|
|
511
|
+
return pRetry(
|
|
512
|
+
async () => {
|
|
513
|
+
try {
|
|
514
|
+
return await fn();
|
|
515
|
+
} catch (error) {
|
|
516
|
+
if (!shouldRetry(error)) {
|
|
517
|
+
throw new AbortError(error);
|
|
518
|
+
}
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
retries: finalConfig.retries,
|
|
524
|
+
factor: finalConfig.factor,
|
|
525
|
+
minTimeout: finalConfig.minTimeout,
|
|
526
|
+
maxTimeout: finalConfig.maxTimeout,
|
|
527
|
+
randomize: finalConfig.randomize,
|
|
528
|
+
onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
|
|
529
|
+
const pRetryError = error;
|
|
530
|
+
finalConfig.onFailedAttempt({
|
|
531
|
+
error: pRetryError,
|
|
532
|
+
attemptNumber: pRetryError.attemptNumber,
|
|
533
|
+
retriesLeft: pRetryError.retriesLeft
|
|
534
|
+
});
|
|
535
|
+
} : void 0
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
__name(withRetry, "withRetry");
|
|
540
|
+
|
|
541
|
+
// src/generated/cfg_accounts/client.ts
|
|
542
|
+
var APIClient = class {
|
|
543
|
+
constructor(baseUrl, options) {
|
|
544
|
+
this.logger = null;
|
|
545
|
+
this.retryConfig = null;
|
|
546
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
547
|
+
this.httpClient = options?.httpClient || new FetchAdapter();
|
|
548
|
+
if (options?.loggerConfig !== void 0) {
|
|
549
|
+
this.logger = new APILogger(options.loggerConfig);
|
|
550
|
+
}
|
|
551
|
+
if (options?.retryConfig !== void 0) {
|
|
552
|
+
this.retryConfig = options.retryConfig;
|
|
553
|
+
}
|
|
554
|
+
this.auth = new Auth(this);
|
|
555
|
+
this.oauth = new Oauth(this);
|
|
556
|
+
this.user_profile = new UserProfile(this);
|
|
557
|
+
this.accounts = new Accounts(this);
|
|
558
|
+
}
|
|
559
|
+
static {
|
|
560
|
+
__name(this, "APIClient");
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Get CSRF token from cookies (for SessionAuthentication).
|
|
564
|
+
*
|
|
565
|
+
* Returns null if cookie doesn't exist (JWT-only auth).
|
|
566
|
+
*/
|
|
567
|
+
getCsrfToken() {
|
|
568
|
+
const name = "csrftoken";
|
|
569
|
+
const value = `; ${document.cookie}`;
|
|
570
|
+
const parts = value.split(`; ${name}=`);
|
|
571
|
+
if (parts.length === 2) {
|
|
572
|
+
return parts.pop()?.split(";").shift() || null;
|
|
573
|
+
}
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Make HTTP request with Django CSRF and session handling.
|
|
578
|
+
* Automatically retries on network errors and 5xx server errors.
|
|
579
|
+
*/
|
|
580
|
+
async request(method, path, options) {
|
|
581
|
+
if (this.retryConfig) {
|
|
582
|
+
return withRetry(() => this._makeRequest(method, path, options), {
|
|
583
|
+
...this.retryConfig,
|
|
584
|
+
onFailedAttempt: /* @__PURE__ */ __name((info) => {
|
|
585
|
+
if (this.logger) {
|
|
586
|
+
this.logger.warn(
|
|
587
|
+
`Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
this.retryConfig?.onFailedAttempt?.(info);
|
|
591
|
+
}, "onFailedAttempt")
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
return this._makeRequest(method, path, options);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Internal request method (without retry wrapper).
|
|
598
|
+
* Used by request() method with optional retry logic.
|
|
599
|
+
*/
|
|
600
|
+
async _makeRequest(method, path, options) {
|
|
601
|
+
const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
|
|
602
|
+
const startTime = Date.now();
|
|
603
|
+
const headers = {
|
|
604
|
+
...options?.headers || {}
|
|
605
|
+
};
|
|
606
|
+
if (!options?.formData && !headers["Content-Type"]) {
|
|
607
|
+
headers["Content-Type"] = "application/json";
|
|
608
|
+
}
|
|
609
|
+
if (this.logger) {
|
|
610
|
+
this.logger.logRequest({
|
|
611
|
+
method,
|
|
612
|
+
url,
|
|
613
|
+
headers,
|
|
614
|
+
body: options?.formData || options?.body,
|
|
615
|
+
timestamp: startTime
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
const response = await this.httpClient.request({
|
|
620
|
+
method,
|
|
621
|
+
url,
|
|
622
|
+
headers,
|
|
623
|
+
params: options?.params,
|
|
624
|
+
body: options?.body,
|
|
625
|
+
formData: options?.formData
|
|
626
|
+
});
|
|
627
|
+
const duration = Date.now() - startTime;
|
|
628
|
+
if (response.status >= 400) {
|
|
629
|
+
const error = new APIError(
|
|
630
|
+
response.status,
|
|
631
|
+
response.statusText,
|
|
632
|
+
response.data,
|
|
633
|
+
url
|
|
634
|
+
);
|
|
635
|
+
if (this.logger) {
|
|
636
|
+
this.logger.logError(
|
|
637
|
+
{
|
|
638
|
+
method,
|
|
639
|
+
url,
|
|
640
|
+
headers,
|
|
641
|
+
body: options?.formData || options?.body,
|
|
642
|
+
timestamp: startTime
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
message: error.message,
|
|
646
|
+
statusCode: response.status,
|
|
647
|
+
duration,
|
|
648
|
+
timestamp: Date.now()
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
throw error;
|
|
653
|
+
}
|
|
654
|
+
if (this.logger) {
|
|
655
|
+
this.logger.logResponse(
|
|
656
|
+
{
|
|
657
|
+
method,
|
|
658
|
+
url,
|
|
659
|
+
headers,
|
|
660
|
+
body: options?.formData || options?.body,
|
|
661
|
+
timestamp: startTime
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
status: response.status,
|
|
665
|
+
statusText: response.statusText,
|
|
666
|
+
data: response.data,
|
|
667
|
+
duration,
|
|
668
|
+
timestamp: Date.now()
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
return response.data;
|
|
673
|
+
} catch (error) {
|
|
674
|
+
const duration = Date.now() - startTime;
|
|
675
|
+
if (error instanceof APIError) {
|
|
676
|
+
throw error;
|
|
677
|
+
}
|
|
678
|
+
const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
|
|
679
|
+
if (this.logger) {
|
|
680
|
+
if (isCORSError) {
|
|
681
|
+
this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
|
|
682
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
683
|
+
this.logger.error(` \u2192 Configure security_domains parameter on the server`);
|
|
684
|
+
} else {
|
|
685
|
+
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
686
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (typeof window !== "undefined") {
|
|
690
|
+
try {
|
|
691
|
+
if (isCORSError) {
|
|
692
|
+
window.dispatchEvent(new CustomEvent("cors-error", {
|
|
693
|
+
detail: {
|
|
694
|
+
url,
|
|
695
|
+
method,
|
|
696
|
+
error: error instanceof Error ? error.message : String(error),
|
|
697
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
698
|
+
},
|
|
699
|
+
bubbles: true,
|
|
700
|
+
cancelable: false
|
|
701
|
+
}));
|
|
702
|
+
} else {
|
|
703
|
+
window.dispatchEvent(new CustomEvent("network-error", {
|
|
704
|
+
detail: {
|
|
705
|
+
url,
|
|
706
|
+
method,
|
|
707
|
+
error: error instanceof Error ? error.message : String(error),
|
|
708
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
709
|
+
},
|
|
710
|
+
bubbles: true,
|
|
711
|
+
cancelable: false
|
|
712
|
+
}));
|
|
713
|
+
}
|
|
714
|
+
} catch (eventError) {
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
|
|
718
|
+
if (this.logger) {
|
|
719
|
+
this.logger.logError(
|
|
720
|
+
{
|
|
721
|
+
method,
|
|
722
|
+
url,
|
|
723
|
+
headers,
|
|
724
|
+
body: options?.formData || options?.body,
|
|
725
|
+
timestamp: startTime
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
message: networkError.message,
|
|
729
|
+
duration,
|
|
730
|
+
timestamp: Date.now()
|
|
731
|
+
}
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
throw networkError;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// src/generated/cfg_accounts/storage.ts
|
|
740
|
+
var LocalStorageAdapter = class {
|
|
741
|
+
static {
|
|
742
|
+
__name(this, "LocalStorageAdapter");
|
|
743
|
+
}
|
|
744
|
+
constructor(logger) {
|
|
745
|
+
this.logger = logger;
|
|
746
|
+
}
|
|
747
|
+
getItem(key) {
|
|
748
|
+
try {
|
|
749
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
750
|
+
const value = localStorage.getItem(key);
|
|
751
|
+
this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
|
|
752
|
+
return value;
|
|
753
|
+
}
|
|
754
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
755
|
+
} catch (error) {
|
|
756
|
+
this.logger?.error("LocalStorage.getItem failed:", error);
|
|
757
|
+
}
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
setItem(key, value) {
|
|
761
|
+
try {
|
|
762
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
763
|
+
localStorage.setItem(key, value);
|
|
764
|
+
this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
|
|
765
|
+
} else {
|
|
766
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
767
|
+
}
|
|
768
|
+
} catch (error) {
|
|
769
|
+
this.logger?.error("LocalStorage.setItem failed:", error);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
removeItem(key) {
|
|
773
|
+
try {
|
|
774
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
775
|
+
localStorage.removeItem(key);
|
|
776
|
+
this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
|
|
777
|
+
} else {
|
|
778
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
779
|
+
}
|
|
780
|
+
} catch (error) {
|
|
781
|
+
this.logger?.error("LocalStorage.removeItem failed:", error);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
};
|
|
174
785
|
|
|
175
786
|
// src/generated/cfg_accounts/enums.ts
|
|
176
787
|
var OAuthConnectionProvider = /* @__PURE__ */ ((OAuthConnectionProvider2) => {
|
|
@@ -196,7 +807,7 @@ var OTPVerifyRequestChannel = /* @__PURE__ */ ((OTPVerifyRequestChannel2) => {
|
|
|
196
807
|
import { z as z2 } from "zod";
|
|
197
808
|
var CentrifugoTokenSchema = z2.object({
|
|
198
809
|
token: z2.string(),
|
|
199
|
-
centrifugo_url: z2.url(),
|
|
810
|
+
centrifugo_url: z2.union([z2.url(), z2.literal("")]),
|
|
200
811
|
expires_at: z2.iso.datetime(),
|
|
201
812
|
channels: z2.array(z2.string())
|
|
202
813
|
});
|
|
@@ -204,14 +815,14 @@ var CentrifugoTokenSchema = z2.object({
|
|
|
204
815
|
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts
|
|
205
816
|
import { z as z3 } from "zod";
|
|
206
817
|
var OAuthAuthorizeRequestRequestSchema = z3.object({
|
|
207
|
-
redirect_uri: z3.url().optional(),
|
|
208
|
-
source_url: z3.url().optional()
|
|
818
|
+
redirect_uri: z3.union([z3.url(), z3.literal("")]).optional(),
|
|
819
|
+
source_url: z3.union([z3.url(), z3.literal("")]).optional()
|
|
209
820
|
});
|
|
210
821
|
|
|
211
822
|
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts
|
|
212
823
|
import { z as z4 } from "zod";
|
|
213
824
|
var OAuthAuthorizeResponseSchema = z4.object({
|
|
214
|
-
authorization_url: z4.url(),
|
|
825
|
+
authorization_url: z4.union([z4.url(), z4.literal("")]),
|
|
215
826
|
state: z4.string()
|
|
216
827
|
});
|
|
217
828
|
|
|
@@ -220,7 +831,7 @@ import { z as z5 } from "zod";
|
|
|
220
831
|
var OAuthCallbackRequestRequestSchema = z5.object({
|
|
221
832
|
code: z5.string().min(10).max(500),
|
|
222
833
|
state: z5.string().min(20).max(100),
|
|
223
|
-
redirect_uri: z5.url().optional()
|
|
834
|
+
redirect_uri: z5.union([z5.url(), z5.literal("")]).optional()
|
|
224
835
|
});
|
|
225
836
|
|
|
226
837
|
// src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts
|
|
@@ -231,7 +842,7 @@ var OAuthConnectionSchema = z6.object({
|
|
|
231
842
|
provider_display: z6.string(),
|
|
232
843
|
provider_username: z6.string(),
|
|
233
844
|
provider_email: z6.email(),
|
|
234
|
-
provider_avatar_url: z6.url(),
|
|
845
|
+
provider_avatar_url: z6.union([z6.url(), z6.literal("")]),
|
|
235
846
|
connected_at: z6.iso.datetime(),
|
|
236
847
|
last_login_at: z6.iso.datetime()
|
|
237
848
|
});
|
|
@@ -252,7 +863,7 @@ var OAuthErrorSchema = z8.object({
|
|
|
252
863
|
// src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts
|
|
253
864
|
import { z as z9 } from "zod";
|
|
254
865
|
var OAuthProvidersResponseSchema = z9.object({
|
|
255
|
-
providers: z9.array(z9.record(z9.string(), z9.
|
|
866
|
+
providers: z9.array(z9.record(z9.string(), z9.any()))
|
|
256
867
|
});
|
|
257
868
|
|
|
258
869
|
// src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts
|
|
@@ -260,7 +871,7 @@ import { z as z10 } from "zod";
|
|
|
260
871
|
var OAuthTokenResponseSchema = z10.object({
|
|
261
872
|
access: z10.string(),
|
|
262
873
|
refresh: z10.string(),
|
|
263
|
-
user: z10.record(z10.string(), z10.
|
|
874
|
+
user: z10.record(z10.string(), z10.any()),
|
|
264
875
|
is_new_user: z10.boolean(),
|
|
265
876
|
is_new_connection: z10.boolean()
|
|
266
877
|
});
|
|
@@ -276,7 +887,7 @@ import { z as z12 } from "zod";
|
|
|
276
887
|
var OTPRequestRequestSchema = z12.object({
|
|
277
888
|
identifier: z12.string().min(1),
|
|
278
889
|
channel: z12.nativeEnum(OTPRequestRequestChannel).optional(),
|
|
279
|
-
source_url: z12.url().optional()
|
|
890
|
+
source_url: z12.union([z12.url(), z12.literal("")]).optional()
|
|
280
891
|
});
|
|
281
892
|
|
|
282
893
|
// src/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts
|
|
@@ -291,7 +902,7 @@ var OTPVerifyRequestSchema = z14.object({
|
|
|
291
902
|
identifier: z14.string().min(1),
|
|
292
903
|
otp: z14.string().min(6).max(6),
|
|
293
904
|
channel: z14.nativeEnum(OTPVerifyRequestChannel).optional(),
|
|
294
|
-
source_url: z14.url().optional()
|
|
905
|
+
source_url: z14.union([z14.url(), z14.literal("")]).optional()
|
|
295
906
|
});
|
|
296
907
|
|
|
297
908
|
// src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
|
|
@@ -310,7 +921,7 @@ var UserSchema = z15.object({
|
|
|
310
921
|
company: z15.string().max(100).optional(),
|
|
311
922
|
phone: z15.string().max(20).optional(),
|
|
312
923
|
position: z15.string().max(100).optional(),
|
|
313
|
-
avatar: z15.url().nullable(),
|
|
924
|
+
avatar: z15.union([z15.url(), z15.literal("")]).nullable(),
|
|
314
925
|
is_staff: z15.boolean(),
|
|
315
926
|
is_superuser: z15.boolean(),
|
|
316
927
|
date_joined: z15.iso.datetime(),
|
|
@@ -846,12 +1457,152 @@ Method: PATCH`);
|
|
|
846
1457
|
}
|
|
847
1458
|
__name(partialUpdateAccountsProfileUpdatePartialUpdate, "partialUpdateAccountsProfileUpdatePartialUpdate");
|
|
848
1459
|
|
|
1460
|
+
// src/generated/cfg_accounts/index.ts
|
|
1461
|
+
var TOKEN_KEY = "auth_token";
|
|
1462
|
+
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
1463
|
+
var API = class {
|
|
1464
|
+
constructor(baseUrl, options) {
|
|
1465
|
+
this._token = null;
|
|
1466
|
+
this._refreshToken = null;
|
|
1467
|
+
this.baseUrl = baseUrl;
|
|
1468
|
+
this.options = options;
|
|
1469
|
+
const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
|
|
1470
|
+
this.storage = options?.storage || new LocalStorageAdapter(logger);
|
|
1471
|
+
this._loadTokensFromStorage();
|
|
1472
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1473
|
+
retryConfig: this.options?.retryConfig,
|
|
1474
|
+
loggerConfig: this.options?.loggerConfig
|
|
1475
|
+
});
|
|
1476
|
+
this._injectAuthHeader();
|
|
1477
|
+
this.auth = this._client.auth;
|
|
1478
|
+
this.oauth = this._client.oauth;
|
|
1479
|
+
this.user_profile = this._client.user_profile;
|
|
1480
|
+
this.accounts = this._client.accounts;
|
|
1481
|
+
}
|
|
1482
|
+
static {
|
|
1483
|
+
__name(this, "API");
|
|
1484
|
+
}
|
|
1485
|
+
_loadTokensFromStorage() {
|
|
1486
|
+
this._token = this.storage.getItem(TOKEN_KEY);
|
|
1487
|
+
this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1488
|
+
}
|
|
1489
|
+
_reinitClients() {
|
|
1490
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1491
|
+
retryConfig: this.options?.retryConfig,
|
|
1492
|
+
loggerConfig: this.options?.loggerConfig
|
|
1493
|
+
});
|
|
1494
|
+
this._injectAuthHeader();
|
|
1495
|
+
this.auth = this._client.auth;
|
|
1496
|
+
this.oauth = this._client.oauth;
|
|
1497
|
+
this.user_profile = this._client.user_profile;
|
|
1498
|
+
this.accounts = this._client.accounts;
|
|
1499
|
+
}
|
|
1500
|
+
_injectAuthHeader() {
|
|
1501
|
+
const originalRequest = this._client.request.bind(this._client);
|
|
1502
|
+
this._client.request = async (method, path, options) => {
|
|
1503
|
+
const token = this.getToken();
|
|
1504
|
+
const mergedOptions = {
|
|
1505
|
+
...options,
|
|
1506
|
+
headers: {
|
|
1507
|
+
...options?.headers || {},
|
|
1508
|
+
...token ? { "Authorization": `Bearer ${token}` } : {}
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
return originalRequest(method, path, mergedOptions);
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Get current JWT token
|
|
1516
|
+
*/
|
|
1517
|
+
getToken() {
|
|
1518
|
+
return this.storage.getItem(TOKEN_KEY);
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Get current refresh token
|
|
1522
|
+
*/
|
|
1523
|
+
getRefreshToken() {
|
|
1524
|
+
return this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Set JWT token and refresh token
|
|
1528
|
+
* @param token - JWT access token
|
|
1529
|
+
* @param refreshToken - JWT refresh token (optional)
|
|
1530
|
+
*/
|
|
1531
|
+
setToken(token, refreshToken) {
|
|
1532
|
+
this._token = token;
|
|
1533
|
+
this.storage.setItem(TOKEN_KEY, token);
|
|
1534
|
+
if (refreshToken) {
|
|
1535
|
+
this._refreshToken = refreshToken;
|
|
1536
|
+
this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
1537
|
+
}
|
|
1538
|
+
this._reinitClients();
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Clear all tokens
|
|
1542
|
+
*/
|
|
1543
|
+
clearTokens() {
|
|
1544
|
+
this._token = null;
|
|
1545
|
+
this._refreshToken = null;
|
|
1546
|
+
this.storage.removeItem(TOKEN_KEY);
|
|
1547
|
+
this.storage.removeItem(REFRESH_TOKEN_KEY);
|
|
1548
|
+
this._reinitClients();
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Check if user is authenticated
|
|
1552
|
+
*/
|
|
1553
|
+
isAuthenticated() {
|
|
1554
|
+
return !!this.getToken();
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Update base URL and reinitialize clients
|
|
1558
|
+
* @param url - New base URL
|
|
1559
|
+
*/
|
|
1560
|
+
setBaseUrl(url) {
|
|
1561
|
+
this.baseUrl = url;
|
|
1562
|
+
this._reinitClients();
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Get current base URL
|
|
1566
|
+
*/
|
|
1567
|
+
getBaseUrl() {
|
|
1568
|
+
return this.baseUrl;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Get OpenAPI schema path
|
|
1572
|
+
* @returns Path to the OpenAPI schema JSON file
|
|
1573
|
+
*
|
|
1574
|
+
* Note: The OpenAPI schema is available in the schema.json file.
|
|
1575
|
+
* You can load it dynamically using:
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
1578
|
+
* // or using fs in Node.js:
|
|
1579
|
+
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
1580
|
+
* ```
|
|
1581
|
+
*/
|
|
1582
|
+
getSchemaPath() {
|
|
1583
|
+
return "./schema.json";
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
|
|
849
1587
|
// src/generated/cfg_accounts/api-instance.ts
|
|
850
1588
|
var globalAPI = null;
|
|
1589
|
+
var autoConfigAttempted = false;
|
|
1590
|
+
function tryAutoConfigureFromEnv() {
|
|
1591
|
+
if (autoConfigAttempted) return;
|
|
1592
|
+
autoConfigAttempted = true;
|
|
1593
|
+
if (globalAPI) return;
|
|
1594
|
+
if (typeof process === "undefined" || !process.env) return;
|
|
1595
|
+
const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
|
|
1596
|
+
if (baseUrl) {
|
|
1597
|
+
globalAPI = new API(baseUrl);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
__name(tryAutoConfigureFromEnv, "tryAutoConfigureFromEnv");
|
|
851
1601
|
function getAPIInstance() {
|
|
1602
|
+
tryAutoConfigureFromEnv();
|
|
852
1603
|
if (!globalAPI) {
|
|
853
1604
|
throw new Error(
|
|
854
|
-
'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })'
|
|
1605
|
+
'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })\n\nOr set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
|
|
855
1606
|
);
|
|
856
1607
|
}
|
|
857
1608
|
return globalAPI;
|