@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.cjs
CHANGED
|
@@ -61,6 +61,315 @@ var TokenRefreshSchema = import_zod.z.object({
|
|
|
61
61
|
refresh: import_zod.z.string()
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
// src/generated/cfg_accounts/accounts__auth/client.ts
|
|
65
|
+
var Auth = class {
|
|
66
|
+
static {
|
|
67
|
+
__name(this, "Auth");
|
|
68
|
+
}
|
|
69
|
+
constructor(client) {
|
|
70
|
+
this.client = client;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Refresh JWT token.
|
|
74
|
+
*/
|
|
75
|
+
async accountsTokenRefreshCreate(data) {
|
|
76
|
+
const response = await this.client.request("POST", "/cfg/accounts/token/refresh/", { body: data });
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/generated/cfg_accounts/accounts__oauth/client.ts
|
|
82
|
+
var Oauth = class {
|
|
83
|
+
static {
|
|
84
|
+
__name(this, "Oauth");
|
|
85
|
+
}
|
|
86
|
+
constructor(client) {
|
|
87
|
+
this.client = client;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* List OAuth connections
|
|
91
|
+
*
|
|
92
|
+
* Get all OAuth connections for the current user.
|
|
93
|
+
*/
|
|
94
|
+
async accountsOauthConnectionsList() {
|
|
95
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/connections/");
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Disconnect OAuth provider
|
|
100
|
+
*
|
|
101
|
+
* Remove OAuth connection for the specified provider.
|
|
102
|
+
*/
|
|
103
|
+
async accountsOauthDisconnectCreate(data) {
|
|
104
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/disconnect/", { body: data });
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Start GitHub OAuth
|
|
109
|
+
*
|
|
110
|
+
* Generate GitHub OAuth authorization URL. Redirect user to this URL to
|
|
111
|
+
* start authentication.
|
|
112
|
+
*/
|
|
113
|
+
async accountsOauthGithubAuthorizeCreate(data) {
|
|
114
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/authorize/", { body: data });
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Complete GitHub OAuth
|
|
119
|
+
*
|
|
120
|
+
* Exchange authorization code for JWT tokens. Call this after GitHub
|
|
121
|
+
* redirects back with code.
|
|
122
|
+
*/
|
|
123
|
+
async accountsOauthGithubCallbackCreate(data) {
|
|
124
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/callback/", { body: data });
|
|
125
|
+
return response;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* List OAuth providers
|
|
129
|
+
*
|
|
130
|
+
* Get list of available OAuth providers for authentication.
|
|
131
|
+
*/
|
|
132
|
+
async accountsOauthProvidersRetrieve() {
|
|
133
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/providers/");
|
|
134
|
+
return response;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/generated/cfg_accounts/accounts__user_profile/client.ts
|
|
139
|
+
var UserProfile = class {
|
|
140
|
+
static {
|
|
141
|
+
__name(this, "UserProfile");
|
|
142
|
+
}
|
|
143
|
+
constructor(client) {
|
|
144
|
+
this.client = client;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get current user profile
|
|
148
|
+
*
|
|
149
|
+
* Retrieve the current authenticated user's profile information.
|
|
150
|
+
*/
|
|
151
|
+
async accountsProfileRetrieve() {
|
|
152
|
+
const response = await this.client.request("GET", "/cfg/accounts/profile/");
|
|
153
|
+
return response;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Upload user avatar
|
|
157
|
+
*
|
|
158
|
+
* Upload avatar image for the current authenticated user. Accepts
|
|
159
|
+
* multipart/form-data with 'avatar' field.
|
|
160
|
+
*/
|
|
161
|
+
async accountsProfileAvatarCreate(data) {
|
|
162
|
+
const response = await this.client.request("POST", "/cfg/accounts/profile/avatar/", { formData: data });
|
|
163
|
+
return response;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Partial update user profile
|
|
167
|
+
*
|
|
168
|
+
* Partially update the current authenticated user's profile information.
|
|
169
|
+
* Supports avatar upload.
|
|
170
|
+
*/
|
|
171
|
+
async accountsProfilePartialUpdate(data) {
|
|
172
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/partial/", { body: data });
|
|
173
|
+
return response;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Partial update user profile
|
|
177
|
+
*
|
|
178
|
+
* Partially update the current authenticated user's profile information.
|
|
179
|
+
* Supports avatar upload.
|
|
180
|
+
*/
|
|
181
|
+
async accountsProfilePartialPartialUpdate(data) {
|
|
182
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/partial/", { body: data });
|
|
183
|
+
return response;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Update user profile
|
|
187
|
+
*
|
|
188
|
+
* Update the current authenticated user's profile information.
|
|
189
|
+
*/
|
|
190
|
+
async accountsProfileUpdateUpdate(data) {
|
|
191
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/update/", { body: data });
|
|
192
|
+
return response;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Update user profile
|
|
196
|
+
*
|
|
197
|
+
* Update the current authenticated user's profile information.
|
|
198
|
+
*/
|
|
199
|
+
async accountsProfileUpdatePartialUpdate(data) {
|
|
200
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/update/", { body: data });
|
|
201
|
+
return response;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/generated/cfg_accounts/accounts/client.ts
|
|
206
|
+
var Accounts = class {
|
|
207
|
+
static {
|
|
208
|
+
__name(this, "Accounts");
|
|
209
|
+
}
|
|
210
|
+
constructor(client) {
|
|
211
|
+
this.client = client;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Request OTP code to email or phone.
|
|
215
|
+
*/
|
|
216
|
+
async otpRequestCreate(data) {
|
|
217
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/request/", { body: data });
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Verify OTP code and return JWT tokens.
|
|
222
|
+
*/
|
|
223
|
+
async otpVerifyCreate(data) {
|
|
224
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/verify/", { body: data });
|
|
225
|
+
return response;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// src/generated/cfg_accounts/http.ts
|
|
230
|
+
var FetchAdapter = class {
|
|
231
|
+
static {
|
|
232
|
+
__name(this, "FetchAdapter");
|
|
233
|
+
}
|
|
234
|
+
async request(request) {
|
|
235
|
+
const { method, url, headers, body, params, formData } = request;
|
|
236
|
+
let finalUrl = url;
|
|
237
|
+
if (params) {
|
|
238
|
+
const searchParams = new URLSearchParams();
|
|
239
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
240
|
+
if (value !== null && value !== void 0) {
|
|
241
|
+
searchParams.append(key, String(value));
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const queryString = searchParams.toString();
|
|
245
|
+
if (queryString) {
|
|
246
|
+
finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const finalHeaders = { ...headers };
|
|
250
|
+
let requestBody;
|
|
251
|
+
if (formData) {
|
|
252
|
+
requestBody = formData;
|
|
253
|
+
} else if (body) {
|
|
254
|
+
finalHeaders["Content-Type"] = "application/json";
|
|
255
|
+
requestBody = JSON.stringify(body);
|
|
256
|
+
}
|
|
257
|
+
const response = await fetch(finalUrl, {
|
|
258
|
+
method,
|
|
259
|
+
headers: finalHeaders,
|
|
260
|
+
body: requestBody,
|
|
261
|
+
credentials: "include"
|
|
262
|
+
// Include Django session cookies
|
|
263
|
+
});
|
|
264
|
+
let data = null;
|
|
265
|
+
const contentType = response.headers.get("content-type");
|
|
266
|
+
if (response.status !== 204 && contentType?.includes("application/json")) {
|
|
267
|
+
data = await response.json();
|
|
268
|
+
} else if (response.status !== 204) {
|
|
269
|
+
data = await response.text();
|
|
270
|
+
}
|
|
271
|
+
const responseHeaders = {};
|
|
272
|
+
response.headers.forEach((value, key) => {
|
|
273
|
+
responseHeaders[key] = value;
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
data,
|
|
277
|
+
status: response.status,
|
|
278
|
+
statusText: response.statusText,
|
|
279
|
+
headers: responseHeaders
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// src/generated/cfg_accounts/errors.ts
|
|
285
|
+
var APIError = class extends Error {
|
|
286
|
+
constructor(statusCode, statusText, response, url, message) {
|
|
287
|
+
super(message || `HTTP ${statusCode}: ${statusText}`);
|
|
288
|
+
this.statusCode = statusCode;
|
|
289
|
+
this.statusText = statusText;
|
|
290
|
+
this.response = response;
|
|
291
|
+
this.url = url;
|
|
292
|
+
this.name = "APIError";
|
|
293
|
+
}
|
|
294
|
+
static {
|
|
295
|
+
__name(this, "APIError");
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get error details from response.
|
|
299
|
+
* DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
|
|
300
|
+
*/
|
|
301
|
+
get details() {
|
|
302
|
+
if (typeof this.response === "object" && this.response !== null) {
|
|
303
|
+
return this.response;
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get field-specific validation errors from DRF.
|
|
309
|
+
* Returns: { "field_name": ["error1", "error2"], ... }
|
|
310
|
+
*/
|
|
311
|
+
get fieldErrors() {
|
|
312
|
+
const details = this.details;
|
|
313
|
+
if (!details) return null;
|
|
314
|
+
const fieldErrors = {};
|
|
315
|
+
for (const [key, value] of Object.entries(details)) {
|
|
316
|
+
if (Array.isArray(value)) {
|
|
317
|
+
fieldErrors[key] = value;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get single error message from DRF.
|
|
324
|
+
* Checks for "detail", "message", or first field error.
|
|
325
|
+
*/
|
|
326
|
+
get errorMessage() {
|
|
327
|
+
const details = this.details;
|
|
328
|
+
if (!details) return this.message;
|
|
329
|
+
if (details.detail) {
|
|
330
|
+
return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
|
|
331
|
+
}
|
|
332
|
+
if (details.message) {
|
|
333
|
+
return String(details.message);
|
|
334
|
+
}
|
|
335
|
+
const fieldErrors = this.fieldErrors;
|
|
336
|
+
if (fieldErrors) {
|
|
337
|
+
const firstField = Object.keys(fieldErrors)[0];
|
|
338
|
+
if (firstField) {
|
|
339
|
+
return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return this.message;
|
|
343
|
+
}
|
|
344
|
+
// Helper methods for common HTTP status codes
|
|
345
|
+
get isValidationError() {
|
|
346
|
+
return this.statusCode === 400;
|
|
347
|
+
}
|
|
348
|
+
get isAuthError() {
|
|
349
|
+
return this.statusCode === 401;
|
|
350
|
+
}
|
|
351
|
+
get isPermissionError() {
|
|
352
|
+
return this.statusCode === 403;
|
|
353
|
+
}
|
|
354
|
+
get isNotFoundError() {
|
|
355
|
+
return this.statusCode === 404;
|
|
356
|
+
}
|
|
357
|
+
get isServerError() {
|
|
358
|
+
return this.statusCode >= 500 && this.statusCode < 600;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var NetworkError = class extends Error {
|
|
362
|
+
constructor(message, url, originalError) {
|
|
363
|
+
super(message);
|
|
364
|
+
this.url = url;
|
|
365
|
+
this.originalError = originalError;
|
|
366
|
+
this.name = "NetworkError";
|
|
367
|
+
}
|
|
368
|
+
static {
|
|
369
|
+
__name(this, "NetworkError");
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
64
373
|
// src/generated/cfg_accounts/logger.ts
|
|
65
374
|
var import_consola = require("consola");
|
|
66
375
|
var DEFAULT_CONFIG = {
|
|
@@ -217,6 +526,308 @@ var defaultLogger = new APILogger();
|
|
|
217
526
|
|
|
218
527
|
// src/generated/cfg_accounts/retry.ts
|
|
219
528
|
var import_p_retry = __toESM(require("p-retry"), 1);
|
|
529
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
530
|
+
retries: 3,
|
|
531
|
+
factor: 2,
|
|
532
|
+
minTimeout: 1e3,
|
|
533
|
+
maxTimeout: 6e4,
|
|
534
|
+
randomize: true,
|
|
535
|
+
onFailedAttempt: /* @__PURE__ */ __name(() => {
|
|
536
|
+
}, "onFailedAttempt")
|
|
537
|
+
};
|
|
538
|
+
function shouldRetry(error) {
|
|
539
|
+
if (error instanceof NetworkError) {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
if (error instanceof APIError) {
|
|
543
|
+
const status = error.statusCode;
|
|
544
|
+
if (status >= 500 && status < 600) {
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
if (status === 429) {
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
__name(shouldRetry, "shouldRetry");
|
|
555
|
+
async function withRetry(fn, config) {
|
|
556
|
+
const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
|
|
557
|
+
return (0, import_p_retry.default)(
|
|
558
|
+
async () => {
|
|
559
|
+
try {
|
|
560
|
+
return await fn();
|
|
561
|
+
} catch (error) {
|
|
562
|
+
if (!shouldRetry(error)) {
|
|
563
|
+
throw new import_p_retry.AbortError(error);
|
|
564
|
+
}
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
retries: finalConfig.retries,
|
|
570
|
+
factor: finalConfig.factor,
|
|
571
|
+
minTimeout: finalConfig.minTimeout,
|
|
572
|
+
maxTimeout: finalConfig.maxTimeout,
|
|
573
|
+
randomize: finalConfig.randomize,
|
|
574
|
+
onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
|
|
575
|
+
const pRetryError = error;
|
|
576
|
+
finalConfig.onFailedAttempt({
|
|
577
|
+
error: pRetryError,
|
|
578
|
+
attemptNumber: pRetryError.attemptNumber,
|
|
579
|
+
retriesLeft: pRetryError.retriesLeft
|
|
580
|
+
});
|
|
581
|
+
} : void 0
|
|
582
|
+
}
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
__name(withRetry, "withRetry");
|
|
586
|
+
|
|
587
|
+
// src/generated/cfg_accounts/client.ts
|
|
588
|
+
var APIClient = class {
|
|
589
|
+
constructor(baseUrl, options) {
|
|
590
|
+
this.logger = null;
|
|
591
|
+
this.retryConfig = null;
|
|
592
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
593
|
+
this.httpClient = options?.httpClient || new FetchAdapter();
|
|
594
|
+
if (options?.loggerConfig !== void 0) {
|
|
595
|
+
this.logger = new APILogger(options.loggerConfig);
|
|
596
|
+
}
|
|
597
|
+
if (options?.retryConfig !== void 0) {
|
|
598
|
+
this.retryConfig = options.retryConfig;
|
|
599
|
+
}
|
|
600
|
+
this.auth = new Auth(this);
|
|
601
|
+
this.oauth = new Oauth(this);
|
|
602
|
+
this.user_profile = new UserProfile(this);
|
|
603
|
+
this.accounts = new Accounts(this);
|
|
604
|
+
}
|
|
605
|
+
static {
|
|
606
|
+
__name(this, "APIClient");
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Get CSRF token from cookies (for SessionAuthentication).
|
|
610
|
+
*
|
|
611
|
+
* Returns null if cookie doesn't exist (JWT-only auth).
|
|
612
|
+
*/
|
|
613
|
+
getCsrfToken() {
|
|
614
|
+
const name = "csrftoken";
|
|
615
|
+
const value = `; ${document.cookie}`;
|
|
616
|
+
const parts = value.split(`; ${name}=`);
|
|
617
|
+
if (parts.length === 2) {
|
|
618
|
+
return parts.pop()?.split(";").shift() || null;
|
|
619
|
+
}
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Make HTTP request with Django CSRF and session handling.
|
|
624
|
+
* Automatically retries on network errors and 5xx server errors.
|
|
625
|
+
*/
|
|
626
|
+
async request(method, path, options) {
|
|
627
|
+
if (this.retryConfig) {
|
|
628
|
+
return withRetry(() => this._makeRequest(method, path, options), {
|
|
629
|
+
...this.retryConfig,
|
|
630
|
+
onFailedAttempt: /* @__PURE__ */ __name((info) => {
|
|
631
|
+
if (this.logger) {
|
|
632
|
+
this.logger.warn(
|
|
633
|
+
`Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
this.retryConfig?.onFailedAttempt?.(info);
|
|
637
|
+
}, "onFailedAttempt")
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
return this._makeRequest(method, path, options);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Internal request method (without retry wrapper).
|
|
644
|
+
* Used by request() method with optional retry logic.
|
|
645
|
+
*/
|
|
646
|
+
async _makeRequest(method, path, options) {
|
|
647
|
+
const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
|
|
648
|
+
const startTime = Date.now();
|
|
649
|
+
const headers = {
|
|
650
|
+
...options?.headers || {}
|
|
651
|
+
};
|
|
652
|
+
if (!options?.formData && !headers["Content-Type"]) {
|
|
653
|
+
headers["Content-Type"] = "application/json";
|
|
654
|
+
}
|
|
655
|
+
if (this.logger) {
|
|
656
|
+
this.logger.logRequest({
|
|
657
|
+
method,
|
|
658
|
+
url,
|
|
659
|
+
headers,
|
|
660
|
+
body: options?.formData || options?.body,
|
|
661
|
+
timestamp: startTime
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
try {
|
|
665
|
+
const response = await this.httpClient.request({
|
|
666
|
+
method,
|
|
667
|
+
url,
|
|
668
|
+
headers,
|
|
669
|
+
params: options?.params,
|
|
670
|
+
body: options?.body,
|
|
671
|
+
formData: options?.formData
|
|
672
|
+
});
|
|
673
|
+
const duration = Date.now() - startTime;
|
|
674
|
+
if (response.status >= 400) {
|
|
675
|
+
const error = new APIError(
|
|
676
|
+
response.status,
|
|
677
|
+
response.statusText,
|
|
678
|
+
response.data,
|
|
679
|
+
url
|
|
680
|
+
);
|
|
681
|
+
if (this.logger) {
|
|
682
|
+
this.logger.logError(
|
|
683
|
+
{
|
|
684
|
+
method,
|
|
685
|
+
url,
|
|
686
|
+
headers,
|
|
687
|
+
body: options?.formData || options?.body,
|
|
688
|
+
timestamp: startTime
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
message: error.message,
|
|
692
|
+
statusCode: response.status,
|
|
693
|
+
duration,
|
|
694
|
+
timestamp: Date.now()
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
if (this.logger) {
|
|
701
|
+
this.logger.logResponse(
|
|
702
|
+
{
|
|
703
|
+
method,
|
|
704
|
+
url,
|
|
705
|
+
headers,
|
|
706
|
+
body: options?.formData || options?.body,
|
|
707
|
+
timestamp: startTime
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
status: response.status,
|
|
711
|
+
statusText: response.statusText,
|
|
712
|
+
data: response.data,
|
|
713
|
+
duration,
|
|
714
|
+
timestamp: Date.now()
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
return response.data;
|
|
719
|
+
} catch (error) {
|
|
720
|
+
const duration = Date.now() - startTime;
|
|
721
|
+
if (error instanceof APIError) {
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
|
|
725
|
+
if (this.logger) {
|
|
726
|
+
if (isCORSError) {
|
|
727
|
+
this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
|
|
728
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
729
|
+
this.logger.error(` \u2192 Configure security_domains parameter on the server`);
|
|
730
|
+
} else {
|
|
731
|
+
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
732
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (typeof window !== "undefined") {
|
|
736
|
+
try {
|
|
737
|
+
if (isCORSError) {
|
|
738
|
+
window.dispatchEvent(new CustomEvent("cors-error", {
|
|
739
|
+
detail: {
|
|
740
|
+
url,
|
|
741
|
+
method,
|
|
742
|
+
error: error instanceof Error ? error.message : String(error),
|
|
743
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
744
|
+
},
|
|
745
|
+
bubbles: true,
|
|
746
|
+
cancelable: false
|
|
747
|
+
}));
|
|
748
|
+
} else {
|
|
749
|
+
window.dispatchEvent(new CustomEvent("network-error", {
|
|
750
|
+
detail: {
|
|
751
|
+
url,
|
|
752
|
+
method,
|
|
753
|
+
error: error instanceof Error ? error.message : String(error),
|
|
754
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
755
|
+
},
|
|
756
|
+
bubbles: true,
|
|
757
|
+
cancelable: false
|
|
758
|
+
}));
|
|
759
|
+
}
|
|
760
|
+
} catch (eventError) {
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
|
|
764
|
+
if (this.logger) {
|
|
765
|
+
this.logger.logError(
|
|
766
|
+
{
|
|
767
|
+
method,
|
|
768
|
+
url,
|
|
769
|
+
headers,
|
|
770
|
+
body: options?.formData || options?.body,
|
|
771
|
+
timestamp: startTime
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
message: networkError.message,
|
|
775
|
+
duration,
|
|
776
|
+
timestamp: Date.now()
|
|
777
|
+
}
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
throw networkError;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
// src/generated/cfg_accounts/storage.ts
|
|
786
|
+
var LocalStorageAdapter = class {
|
|
787
|
+
static {
|
|
788
|
+
__name(this, "LocalStorageAdapter");
|
|
789
|
+
}
|
|
790
|
+
constructor(logger) {
|
|
791
|
+
this.logger = logger;
|
|
792
|
+
}
|
|
793
|
+
getItem(key) {
|
|
794
|
+
try {
|
|
795
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
796
|
+
const value = localStorage.getItem(key);
|
|
797
|
+
this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
|
|
798
|
+
return value;
|
|
799
|
+
}
|
|
800
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
801
|
+
} catch (error) {
|
|
802
|
+
this.logger?.error("LocalStorage.getItem failed:", error);
|
|
803
|
+
}
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
setItem(key, value) {
|
|
807
|
+
try {
|
|
808
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
809
|
+
localStorage.setItem(key, value);
|
|
810
|
+
this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
|
|
811
|
+
} else {
|
|
812
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
813
|
+
}
|
|
814
|
+
} catch (error) {
|
|
815
|
+
this.logger?.error("LocalStorage.setItem failed:", error);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
removeItem(key) {
|
|
819
|
+
try {
|
|
820
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
821
|
+
localStorage.removeItem(key);
|
|
822
|
+
this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
|
|
823
|
+
} else {
|
|
824
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
825
|
+
}
|
|
826
|
+
} catch (error) {
|
|
827
|
+
this.logger?.error("LocalStorage.removeItem failed:", error);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
};
|
|
220
831
|
|
|
221
832
|
// src/generated/cfg_accounts/enums.ts
|
|
222
833
|
var OAuthConnectionProvider = /* @__PURE__ */ ((OAuthConnectionProvider2) => {
|
|
@@ -242,7 +853,7 @@ var OTPVerifyRequestChannel = /* @__PURE__ */ ((OTPVerifyRequestChannel2) => {
|
|
|
242
853
|
var import_zod2 = require("zod");
|
|
243
854
|
var CentrifugoTokenSchema = import_zod2.z.object({
|
|
244
855
|
token: import_zod2.z.string(),
|
|
245
|
-
centrifugo_url: import_zod2.z.url(),
|
|
856
|
+
centrifugo_url: import_zod2.z.union([import_zod2.z.url(), import_zod2.z.literal("")]),
|
|
246
857
|
expires_at: import_zod2.z.iso.datetime(),
|
|
247
858
|
channels: import_zod2.z.array(import_zod2.z.string())
|
|
248
859
|
});
|
|
@@ -250,14 +861,14 @@ var CentrifugoTokenSchema = import_zod2.z.object({
|
|
|
250
861
|
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts
|
|
251
862
|
var import_zod3 = require("zod");
|
|
252
863
|
var OAuthAuthorizeRequestRequestSchema = import_zod3.z.object({
|
|
253
|
-
redirect_uri: import_zod3.z.url().optional(),
|
|
254
|
-
source_url: import_zod3.z.url().optional()
|
|
864
|
+
redirect_uri: import_zod3.z.union([import_zod3.z.url(), import_zod3.z.literal("")]).optional(),
|
|
865
|
+
source_url: import_zod3.z.union([import_zod3.z.url(), import_zod3.z.literal("")]).optional()
|
|
255
866
|
});
|
|
256
867
|
|
|
257
868
|
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts
|
|
258
869
|
var import_zod4 = require("zod");
|
|
259
870
|
var OAuthAuthorizeResponseSchema = import_zod4.z.object({
|
|
260
|
-
authorization_url: import_zod4.z.url(),
|
|
871
|
+
authorization_url: import_zod4.z.union([import_zod4.z.url(), import_zod4.z.literal("")]),
|
|
261
872
|
state: import_zod4.z.string()
|
|
262
873
|
});
|
|
263
874
|
|
|
@@ -266,7 +877,7 @@ var import_zod5 = require("zod");
|
|
|
266
877
|
var OAuthCallbackRequestRequestSchema = import_zod5.z.object({
|
|
267
878
|
code: import_zod5.z.string().min(10).max(500),
|
|
268
879
|
state: import_zod5.z.string().min(20).max(100),
|
|
269
|
-
redirect_uri: import_zod5.z.url().optional()
|
|
880
|
+
redirect_uri: import_zod5.z.union([import_zod5.z.url(), import_zod5.z.literal("")]).optional()
|
|
270
881
|
});
|
|
271
882
|
|
|
272
883
|
// src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts
|
|
@@ -277,7 +888,7 @@ var OAuthConnectionSchema = import_zod6.z.object({
|
|
|
277
888
|
provider_display: import_zod6.z.string(),
|
|
278
889
|
provider_username: import_zod6.z.string(),
|
|
279
890
|
provider_email: import_zod6.z.email(),
|
|
280
|
-
provider_avatar_url: import_zod6.z.url(),
|
|
891
|
+
provider_avatar_url: import_zod6.z.union([import_zod6.z.url(), import_zod6.z.literal("")]),
|
|
281
892
|
connected_at: import_zod6.z.iso.datetime(),
|
|
282
893
|
last_login_at: import_zod6.z.iso.datetime()
|
|
283
894
|
});
|
|
@@ -298,7 +909,7 @@ var OAuthErrorSchema = import_zod8.z.object({
|
|
|
298
909
|
// src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts
|
|
299
910
|
var import_zod9 = require("zod");
|
|
300
911
|
var OAuthProvidersResponseSchema = import_zod9.z.object({
|
|
301
|
-
providers: import_zod9.z.array(import_zod9.z.record(import_zod9.z.string(), import_zod9.z.
|
|
912
|
+
providers: import_zod9.z.array(import_zod9.z.record(import_zod9.z.string(), import_zod9.z.any()))
|
|
302
913
|
});
|
|
303
914
|
|
|
304
915
|
// src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts
|
|
@@ -306,7 +917,7 @@ var import_zod10 = require("zod");
|
|
|
306
917
|
var OAuthTokenResponseSchema = import_zod10.z.object({
|
|
307
918
|
access: import_zod10.z.string(),
|
|
308
919
|
refresh: import_zod10.z.string(),
|
|
309
|
-
user: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.
|
|
920
|
+
user: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.any()),
|
|
310
921
|
is_new_user: import_zod10.z.boolean(),
|
|
311
922
|
is_new_connection: import_zod10.z.boolean()
|
|
312
923
|
});
|
|
@@ -322,7 +933,7 @@ var import_zod12 = require("zod");
|
|
|
322
933
|
var OTPRequestRequestSchema = import_zod12.z.object({
|
|
323
934
|
identifier: import_zod12.z.string().min(1),
|
|
324
935
|
channel: import_zod12.z.nativeEnum(OTPRequestRequestChannel).optional(),
|
|
325
|
-
source_url: import_zod12.z.url().optional()
|
|
936
|
+
source_url: import_zod12.z.union([import_zod12.z.url(), import_zod12.z.literal("")]).optional()
|
|
326
937
|
});
|
|
327
938
|
|
|
328
939
|
// src/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts
|
|
@@ -337,7 +948,7 @@ var OTPVerifyRequestSchema = import_zod14.z.object({
|
|
|
337
948
|
identifier: import_zod14.z.string().min(1),
|
|
338
949
|
otp: import_zod14.z.string().min(6).max(6),
|
|
339
950
|
channel: import_zod14.z.nativeEnum(OTPVerifyRequestChannel).optional(),
|
|
340
|
-
source_url: import_zod14.z.url().optional()
|
|
951
|
+
source_url: import_zod14.z.union([import_zod14.z.url(), import_zod14.z.literal("")]).optional()
|
|
341
952
|
});
|
|
342
953
|
|
|
343
954
|
// src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
|
|
@@ -356,7 +967,7 @@ var UserSchema = import_zod15.z.object({
|
|
|
356
967
|
company: import_zod15.z.string().max(100).optional(),
|
|
357
968
|
phone: import_zod15.z.string().max(20).optional(),
|
|
358
969
|
position: import_zod15.z.string().max(100).optional(),
|
|
359
|
-
avatar: import_zod15.z.url().nullable(),
|
|
970
|
+
avatar: import_zod15.z.union([import_zod15.z.url(), import_zod15.z.literal("")]).nullable(),
|
|
360
971
|
is_staff: import_zod15.z.boolean(),
|
|
361
972
|
is_superuser: import_zod15.z.boolean(),
|
|
362
973
|
date_joined: import_zod15.z.iso.datetime(),
|
|
@@ -892,12 +1503,152 @@ Method: PATCH`);
|
|
|
892
1503
|
}
|
|
893
1504
|
__name(partialUpdateAccountsProfileUpdatePartialUpdate, "partialUpdateAccountsProfileUpdatePartialUpdate");
|
|
894
1505
|
|
|
1506
|
+
// src/generated/cfg_accounts/index.ts
|
|
1507
|
+
var TOKEN_KEY = "auth_token";
|
|
1508
|
+
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
1509
|
+
var API = class {
|
|
1510
|
+
constructor(baseUrl, options) {
|
|
1511
|
+
this._token = null;
|
|
1512
|
+
this._refreshToken = null;
|
|
1513
|
+
this.baseUrl = baseUrl;
|
|
1514
|
+
this.options = options;
|
|
1515
|
+
const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
|
|
1516
|
+
this.storage = options?.storage || new LocalStorageAdapter(logger);
|
|
1517
|
+
this._loadTokensFromStorage();
|
|
1518
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1519
|
+
retryConfig: this.options?.retryConfig,
|
|
1520
|
+
loggerConfig: this.options?.loggerConfig
|
|
1521
|
+
});
|
|
1522
|
+
this._injectAuthHeader();
|
|
1523
|
+
this.auth = this._client.auth;
|
|
1524
|
+
this.oauth = this._client.oauth;
|
|
1525
|
+
this.user_profile = this._client.user_profile;
|
|
1526
|
+
this.accounts = this._client.accounts;
|
|
1527
|
+
}
|
|
1528
|
+
static {
|
|
1529
|
+
__name(this, "API");
|
|
1530
|
+
}
|
|
1531
|
+
_loadTokensFromStorage() {
|
|
1532
|
+
this._token = this.storage.getItem(TOKEN_KEY);
|
|
1533
|
+
this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1534
|
+
}
|
|
1535
|
+
_reinitClients() {
|
|
1536
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1537
|
+
retryConfig: this.options?.retryConfig,
|
|
1538
|
+
loggerConfig: this.options?.loggerConfig
|
|
1539
|
+
});
|
|
1540
|
+
this._injectAuthHeader();
|
|
1541
|
+
this.auth = this._client.auth;
|
|
1542
|
+
this.oauth = this._client.oauth;
|
|
1543
|
+
this.user_profile = this._client.user_profile;
|
|
1544
|
+
this.accounts = this._client.accounts;
|
|
1545
|
+
}
|
|
1546
|
+
_injectAuthHeader() {
|
|
1547
|
+
const originalRequest = this._client.request.bind(this._client);
|
|
1548
|
+
this._client.request = async (method, path, options) => {
|
|
1549
|
+
const token = this.getToken();
|
|
1550
|
+
const mergedOptions = {
|
|
1551
|
+
...options,
|
|
1552
|
+
headers: {
|
|
1553
|
+
...options?.headers || {},
|
|
1554
|
+
...token ? { "Authorization": `Bearer ${token}` } : {}
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
return originalRequest(method, path, mergedOptions);
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* Get current JWT token
|
|
1562
|
+
*/
|
|
1563
|
+
getToken() {
|
|
1564
|
+
return this.storage.getItem(TOKEN_KEY);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Get current refresh token
|
|
1568
|
+
*/
|
|
1569
|
+
getRefreshToken() {
|
|
1570
|
+
return this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Set JWT token and refresh token
|
|
1574
|
+
* @param token - JWT access token
|
|
1575
|
+
* @param refreshToken - JWT refresh token (optional)
|
|
1576
|
+
*/
|
|
1577
|
+
setToken(token, refreshToken) {
|
|
1578
|
+
this._token = token;
|
|
1579
|
+
this.storage.setItem(TOKEN_KEY, token);
|
|
1580
|
+
if (refreshToken) {
|
|
1581
|
+
this._refreshToken = refreshToken;
|
|
1582
|
+
this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
1583
|
+
}
|
|
1584
|
+
this._reinitClients();
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Clear all tokens
|
|
1588
|
+
*/
|
|
1589
|
+
clearTokens() {
|
|
1590
|
+
this._token = null;
|
|
1591
|
+
this._refreshToken = null;
|
|
1592
|
+
this.storage.removeItem(TOKEN_KEY);
|
|
1593
|
+
this.storage.removeItem(REFRESH_TOKEN_KEY);
|
|
1594
|
+
this._reinitClients();
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Check if user is authenticated
|
|
1598
|
+
*/
|
|
1599
|
+
isAuthenticated() {
|
|
1600
|
+
return !!this.getToken();
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Update base URL and reinitialize clients
|
|
1604
|
+
* @param url - New base URL
|
|
1605
|
+
*/
|
|
1606
|
+
setBaseUrl(url) {
|
|
1607
|
+
this.baseUrl = url;
|
|
1608
|
+
this._reinitClients();
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Get current base URL
|
|
1612
|
+
*/
|
|
1613
|
+
getBaseUrl() {
|
|
1614
|
+
return this.baseUrl;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Get OpenAPI schema path
|
|
1618
|
+
* @returns Path to the OpenAPI schema JSON file
|
|
1619
|
+
*
|
|
1620
|
+
* Note: The OpenAPI schema is available in the schema.json file.
|
|
1621
|
+
* You can load it dynamically using:
|
|
1622
|
+
* ```typescript
|
|
1623
|
+
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
1624
|
+
* // or using fs in Node.js:
|
|
1625
|
+
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
1626
|
+
* ```
|
|
1627
|
+
*/
|
|
1628
|
+
getSchemaPath() {
|
|
1629
|
+
return "./schema.json";
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
|
|
895
1633
|
// src/generated/cfg_accounts/api-instance.ts
|
|
896
1634
|
var globalAPI = null;
|
|
1635
|
+
var autoConfigAttempted = false;
|
|
1636
|
+
function tryAutoConfigureFromEnv() {
|
|
1637
|
+
if (autoConfigAttempted) return;
|
|
1638
|
+
autoConfigAttempted = true;
|
|
1639
|
+
if (globalAPI) return;
|
|
1640
|
+
if (typeof process === "undefined" || !process.env) return;
|
|
1641
|
+
const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
|
|
1642
|
+
if (baseUrl) {
|
|
1643
|
+
globalAPI = new API(baseUrl);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
__name(tryAutoConfigureFromEnv, "tryAutoConfigureFromEnv");
|
|
897
1647
|
function getAPIInstance() {
|
|
1648
|
+
tryAutoConfigureFromEnv();
|
|
898
1649
|
if (!globalAPI) {
|
|
899
1650
|
throw new Error(
|
|
900
|
-
'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" })'
|
|
1651
|
+
'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'
|
|
901
1652
|
);
|
|
902
1653
|
}
|
|
903
1654
|
return globalAPI;
|