@djangocfg/api 2.1.86 → 2.1.88
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-server.cjs +1948 -4
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.d.cts +35 -1
- package/dist/auth-server.d.ts +35 -1
- package/dist/auth-server.mjs +1938 -4
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +237 -112
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +17 -1
- package/dist/auth.d.ts +17 -1
- package/dist/auth.mjs +200 -75
- package/dist/auth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/auth/context/AuthContext.tsx +56 -10
- package/src/auth/hooks/index.ts +3 -0
- package/src/auth/hooks/useProfileCache.ts +1 -1
- package/src/auth/hooks/useTokenRefresh.ts +167 -0
- package/src/auth/middlewares/index.ts +8 -1
- package/src/auth/middlewares/tokenRefresh.ts +169 -0
package/dist/auth-server.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,13 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/auth/server.ts
|
|
21
31
|
var server_exports = {};
|
|
22
32
|
__export(server_exports, {
|
|
33
|
+
createAutoRefreshFetch: () => createAutoRefreshFetch,
|
|
34
|
+
isAuthenticationError: () => isAuthenticationError,
|
|
35
|
+
isTokenExpiringSoon: () => isTokenExpiringSoon,
|
|
23
36
|
proxyMiddleware: () => proxyMiddleware,
|
|
24
|
-
proxyMiddlewareConfig: () => proxyMiddlewareConfig
|
|
37
|
+
proxyMiddlewareConfig: () => proxyMiddlewareConfig,
|
|
38
|
+
refreshAccessToken: () => refreshAccessToken,
|
|
39
|
+
refreshIfExpiringSoon: () => refreshIfExpiringSoon
|
|
25
40
|
});
|
|
26
41
|
module.exports = __toCommonJS(server_exports);
|
|
27
42
|
|
|
@@ -29,13 +44,13 @@ module.exports = __toCommonJS(server_exports);
|
|
|
29
44
|
var import_server = require("next/server");
|
|
30
45
|
function proxyMiddleware(request) {
|
|
31
46
|
const { pathname, search } = request.nextUrl;
|
|
32
|
-
const
|
|
47
|
+
const apiUrl2 = process.env.NEXT_PUBLIC_API_URL;
|
|
33
48
|
if (pathname.startsWith("/media/")) {
|
|
34
|
-
const targetUrl = `${
|
|
49
|
+
const targetUrl = `${apiUrl2}${pathname}${search}`;
|
|
35
50
|
return import_server.NextResponse.rewrite(targetUrl, { request: { headers: request.headers } });
|
|
36
51
|
}
|
|
37
52
|
if (pathname.startsWith("/api/")) {
|
|
38
|
-
const targetUrl = `${
|
|
53
|
+
const targetUrl = `${apiUrl2}${pathname}${search}`;
|
|
39
54
|
return import_server.NextResponse.rewrite(targetUrl, { request: { headers: request.headers } });
|
|
40
55
|
}
|
|
41
56
|
return import_server.NextResponse.next();
|
|
@@ -44,4 +59,1933 @@ __name(proxyMiddleware, "proxyMiddleware");
|
|
|
44
59
|
var proxyMiddlewareConfig = {
|
|
45
60
|
matcher: ["/media/:path*", "/api/:path*"]
|
|
46
61
|
};
|
|
62
|
+
|
|
63
|
+
// src/generated/cfg_accounts/accounts__auth/client.ts
|
|
64
|
+
var Auth = class {
|
|
65
|
+
static {
|
|
66
|
+
__name(this, "Auth");
|
|
67
|
+
}
|
|
68
|
+
constructor(client) {
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Refresh JWT token.
|
|
73
|
+
*/
|
|
74
|
+
async accountsTokenRefreshCreate(data) {
|
|
75
|
+
const response = await this.client.request("POST", "/cfg/accounts/token/refresh/", { body: data });
|
|
76
|
+
return response;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/generated/cfg_accounts/accounts__oauth/client.ts
|
|
81
|
+
var Oauth = class {
|
|
82
|
+
static {
|
|
83
|
+
__name(this, "Oauth");
|
|
84
|
+
}
|
|
85
|
+
constructor(client) {
|
|
86
|
+
this.client = client;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* List OAuth connections
|
|
90
|
+
*
|
|
91
|
+
* Get all OAuth connections for the current user.
|
|
92
|
+
*/
|
|
93
|
+
async accountsOauthConnectionsList() {
|
|
94
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/connections/");
|
|
95
|
+
return response;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Disconnect OAuth provider
|
|
99
|
+
*
|
|
100
|
+
* Remove OAuth connection for the specified provider.
|
|
101
|
+
*/
|
|
102
|
+
async accountsOauthDisconnectCreate(data) {
|
|
103
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/disconnect/", { body: data });
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Start GitHub OAuth
|
|
108
|
+
*
|
|
109
|
+
* Generate GitHub OAuth authorization URL. Redirect user to this URL to
|
|
110
|
+
* start authentication.
|
|
111
|
+
*/
|
|
112
|
+
async accountsOauthGithubAuthorizeCreate(data) {
|
|
113
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/authorize/", { body: data });
|
|
114
|
+
return response;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Complete GitHub OAuth
|
|
118
|
+
*
|
|
119
|
+
* Exchange authorization code for JWT tokens. Call this after GitHub
|
|
120
|
+
* redirects back with code.
|
|
121
|
+
*/
|
|
122
|
+
async accountsOauthGithubCallbackCreate(data) {
|
|
123
|
+
const response = await this.client.request("POST", "/cfg/accounts/oauth/github/callback/", { body: data });
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* List OAuth providers
|
|
128
|
+
*
|
|
129
|
+
* Get list of available OAuth providers for authentication.
|
|
130
|
+
*/
|
|
131
|
+
async accountsOauthProvidersRetrieve() {
|
|
132
|
+
const response = await this.client.request("GET", "/cfg/accounts/oauth/providers/");
|
|
133
|
+
return response;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/generated/cfg_accounts/accounts__user_profile/client.ts
|
|
138
|
+
var UserProfile = class {
|
|
139
|
+
static {
|
|
140
|
+
__name(this, "UserProfile");
|
|
141
|
+
}
|
|
142
|
+
constructor(client) {
|
|
143
|
+
this.client = client;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get current user profile
|
|
147
|
+
*
|
|
148
|
+
* Retrieve the current authenticated user's profile information.
|
|
149
|
+
*/
|
|
150
|
+
async accountsProfileRetrieve() {
|
|
151
|
+
const response = await this.client.request("GET", "/cfg/accounts/profile/");
|
|
152
|
+
return response;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Upload user avatar
|
|
156
|
+
*
|
|
157
|
+
* Upload avatar image for the current authenticated user. Accepts
|
|
158
|
+
* multipart/form-data with 'avatar' field.
|
|
159
|
+
*/
|
|
160
|
+
async accountsProfileAvatarCreate(data) {
|
|
161
|
+
const response = await this.client.request("POST", "/cfg/accounts/profile/avatar/", { formData: data });
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Partial update user profile
|
|
166
|
+
*
|
|
167
|
+
* Partially update the current authenticated user's profile information.
|
|
168
|
+
* Supports avatar upload.
|
|
169
|
+
*/
|
|
170
|
+
async accountsProfilePartialUpdate(data) {
|
|
171
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/partial/", { body: data });
|
|
172
|
+
return response;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Partial update user profile
|
|
176
|
+
*
|
|
177
|
+
* Partially update the current authenticated user's profile information.
|
|
178
|
+
* Supports avatar upload.
|
|
179
|
+
*/
|
|
180
|
+
async accountsProfilePartialPartialUpdate(data) {
|
|
181
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/partial/", { body: data });
|
|
182
|
+
return response;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Update user profile
|
|
186
|
+
*
|
|
187
|
+
* Update the current authenticated user's profile information.
|
|
188
|
+
*/
|
|
189
|
+
async accountsProfileUpdateUpdate(data) {
|
|
190
|
+
const response = await this.client.request("PUT", "/cfg/accounts/profile/update/", { body: data });
|
|
191
|
+
return response;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Update user profile
|
|
195
|
+
*
|
|
196
|
+
* Update the current authenticated user's profile information.
|
|
197
|
+
*/
|
|
198
|
+
async accountsProfileUpdatePartialUpdate(data) {
|
|
199
|
+
const response = await this.client.request("PATCH", "/cfg/accounts/profile/update/", { body: data });
|
|
200
|
+
return response;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/generated/cfg_accounts/accounts/client.ts
|
|
205
|
+
var Accounts = class {
|
|
206
|
+
static {
|
|
207
|
+
__name(this, "Accounts");
|
|
208
|
+
}
|
|
209
|
+
constructor(client) {
|
|
210
|
+
this.client = client;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Request OTP code to email or phone.
|
|
214
|
+
*/
|
|
215
|
+
async otpRequestCreate(data) {
|
|
216
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/request/", { body: data });
|
|
217
|
+
return response;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Verify OTP code and return JWT tokens or 2FA session. If user has 2FA
|
|
221
|
+
* enabled: - Returns requires_2fa=True with session_id - Client must
|
|
222
|
+
* complete 2FA verification at /cfg/totp/verify/ If user has no 2FA: -
|
|
223
|
+
* Returns JWT tokens and user data directly
|
|
224
|
+
*/
|
|
225
|
+
async otpVerifyCreate(data) {
|
|
226
|
+
const response = await this.client.request("POST", "/cfg/accounts/otp/verify/", { body: data });
|
|
227
|
+
return response;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/generated/cfg_accounts/http.ts
|
|
232
|
+
var FetchAdapter = class {
|
|
233
|
+
static {
|
|
234
|
+
__name(this, "FetchAdapter");
|
|
235
|
+
}
|
|
236
|
+
async request(request) {
|
|
237
|
+
const { method, url, headers, body, params, formData, binaryBody } = request;
|
|
238
|
+
let finalUrl = url;
|
|
239
|
+
if (params) {
|
|
240
|
+
const searchParams = new URLSearchParams();
|
|
241
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
242
|
+
if (value !== null && value !== void 0) {
|
|
243
|
+
searchParams.append(key, String(value));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const queryString = searchParams.toString();
|
|
247
|
+
if (queryString) {
|
|
248
|
+
finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const finalHeaders = { ...headers };
|
|
252
|
+
let requestBody;
|
|
253
|
+
if (formData) {
|
|
254
|
+
requestBody = formData;
|
|
255
|
+
} else if (binaryBody) {
|
|
256
|
+
finalHeaders["Content-Type"] = "application/octet-stream";
|
|
257
|
+
requestBody = binaryBody;
|
|
258
|
+
} else if (body) {
|
|
259
|
+
finalHeaders["Content-Type"] = "application/json";
|
|
260
|
+
requestBody = JSON.stringify(body);
|
|
261
|
+
}
|
|
262
|
+
const response = await fetch(finalUrl, {
|
|
263
|
+
method,
|
|
264
|
+
headers: finalHeaders,
|
|
265
|
+
body: requestBody,
|
|
266
|
+
credentials: "include"
|
|
267
|
+
// Include Django session cookies
|
|
268
|
+
});
|
|
269
|
+
let data = null;
|
|
270
|
+
const contentType = response.headers.get("content-type");
|
|
271
|
+
if (response.status !== 204 && contentType?.includes("application/json")) {
|
|
272
|
+
data = await response.json();
|
|
273
|
+
} else if (response.status !== 204) {
|
|
274
|
+
data = await response.text();
|
|
275
|
+
}
|
|
276
|
+
const responseHeaders = {};
|
|
277
|
+
response.headers.forEach((value, key) => {
|
|
278
|
+
responseHeaders[key] = value;
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
data,
|
|
282
|
+
status: response.status,
|
|
283
|
+
statusText: response.statusText,
|
|
284
|
+
headers: responseHeaders
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/generated/cfg_accounts/errors.ts
|
|
290
|
+
var APIError = class extends Error {
|
|
291
|
+
constructor(statusCode, statusText, response, url, message) {
|
|
292
|
+
super(message || `HTTP ${statusCode}: ${statusText}`);
|
|
293
|
+
this.statusCode = statusCode;
|
|
294
|
+
this.statusText = statusText;
|
|
295
|
+
this.response = response;
|
|
296
|
+
this.url = url;
|
|
297
|
+
this.name = "APIError";
|
|
298
|
+
}
|
|
299
|
+
static {
|
|
300
|
+
__name(this, "APIError");
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get error details from response.
|
|
304
|
+
* DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
|
|
305
|
+
*/
|
|
306
|
+
get details() {
|
|
307
|
+
if (typeof this.response === "object" && this.response !== null) {
|
|
308
|
+
return this.response;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get field-specific validation errors from DRF.
|
|
314
|
+
* Returns: { "field_name": ["error1", "error2"], ... }
|
|
315
|
+
*/
|
|
316
|
+
get fieldErrors() {
|
|
317
|
+
const details = this.details;
|
|
318
|
+
if (!details) return null;
|
|
319
|
+
const fieldErrors = {};
|
|
320
|
+
for (const [key, value] of Object.entries(details)) {
|
|
321
|
+
if (Array.isArray(value)) {
|
|
322
|
+
fieldErrors[key] = value;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get single error message from DRF.
|
|
329
|
+
* Checks for "detail", "message", or first field error.
|
|
330
|
+
*/
|
|
331
|
+
get errorMessage() {
|
|
332
|
+
const details = this.details;
|
|
333
|
+
if (!details) return this.message;
|
|
334
|
+
if (details.detail) {
|
|
335
|
+
return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
|
|
336
|
+
}
|
|
337
|
+
if (details.message) {
|
|
338
|
+
return String(details.message);
|
|
339
|
+
}
|
|
340
|
+
const fieldErrors = this.fieldErrors;
|
|
341
|
+
if (fieldErrors) {
|
|
342
|
+
const firstField = Object.keys(fieldErrors)[0];
|
|
343
|
+
if (firstField) {
|
|
344
|
+
return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return this.message;
|
|
348
|
+
}
|
|
349
|
+
// Helper methods for common HTTP status codes
|
|
350
|
+
get isValidationError() {
|
|
351
|
+
return this.statusCode === 400;
|
|
352
|
+
}
|
|
353
|
+
get isAuthError() {
|
|
354
|
+
return this.statusCode === 401;
|
|
355
|
+
}
|
|
356
|
+
get isPermissionError() {
|
|
357
|
+
return this.statusCode === 403;
|
|
358
|
+
}
|
|
359
|
+
get isNotFoundError() {
|
|
360
|
+
return this.statusCode === 404;
|
|
361
|
+
}
|
|
362
|
+
get isServerError() {
|
|
363
|
+
return this.statusCode >= 500 && this.statusCode < 600;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var NetworkError = class extends Error {
|
|
367
|
+
constructor(message, url, originalError) {
|
|
368
|
+
super(message);
|
|
369
|
+
this.url = url;
|
|
370
|
+
this.originalError = originalError;
|
|
371
|
+
this.name = "NetworkError";
|
|
372
|
+
}
|
|
373
|
+
static {
|
|
374
|
+
__name(this, "NetworkError");
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/generated/cfg_accounts/logger.ts
|
|
379
|
+
var import_consola = require("consola");
|
|
380
|
+
var DEFAULT_CONFIG = {
|
|
381
|
+
enabled: process.env.NODE_ENV !== "production",
|
|
382
|
+
logRequests: true,
|
|
383
|
+
logResponses: true,
|
|
384
|
+
logErrors: true,
|
|
385
|
+
logBodies: true,
|
|
386
|
+
logHeaders: false
|
|
387
|
+
};
|
|
388
|
+
var SENSITIVE_HEADERS = [
|
|
389
|
+
"authorization",
|
|
390
|
+
"cookie",
|
|
391
|
+
"set-cookie",
|
|
392
|
+
"x-api-key",
|
|
393
|
+
"x-csrf-token"
|
|
394
|
+
];
|
|
395
|
+
var APILogger = class {
|
|
396
|
+
static {
|
|
397
|
+
__name(this, "APILogger");
|
|
398
|
+
}
|
|
399
|
+
constructor(config = {}) {
|
|
400
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
401
|
+
this.consola = config.consola || (0, import_consola.createConsola)({
|
|
402
|
+
level: this.config.enabled ? 4 : 0
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Enable logging
|
|
407
|
+
*/
|
|
408
|
+
enable() {
|
|
409
|
+
this.config.enabled = true;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Disable logging
|
|
413
|
+
*/
|
|
414
|
+
disable() {
|
|
415
|
+
this.config.enabled = false;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Update configuration
|
|
419
|
+
*/
|
|
420
|
+
setConfig(config) {
|
|
421
|
+
this.config = { ...this.config, ...config };
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Filter sensitive headers
|
|
425
|
+
*/
|
|
426
|
+
filterHeaders(headers) {
|
|
427
|
+
if (!headers) return {};
|
|
428
|
+
const filtered = {};
|
|
429
|
+
Object.keys(headers).forEach((key) => {
|
|
430
|
+
const lowerKey = key.toLowerCase();
|
|
431
|
+
if (SENSITIVE_HEADERS.includes(lowerKey)) {
|
|
432
|
+
filtered[key] = "***";
|
|
433
|
+
} else {
|
|
434
|
+
filtered[key] = headers[key] || "";
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return filtered;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Log request
|
|
441
|
+
*/
|
|
442
|
+
logRequest(request) {
|
|
443
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
444
|
+
const { method, url, headers, body } = request;
|
|
445
|
+
this.consola.start(`${method} ${url}`);
|
|
446
|
+
if (this.config.logHeaders && headers) {
|
|
447
|
+
this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
448
|
+
}
|
|
449
|
+
if (this.config.logBodies && body) {
|
|
450
|
+
this.consola.debug("Body:", body);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Log response
|
|
455
|
+
*/
|
|
456
|
+
logResponse(request, response) {
|
|
457
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
458
|
+
const { method, url } = request;
|
|
459
|
+
const { status, statusText, data, duration } = response;
|
|
460
|
+
const statusColor = status >= 500 ? "red" : status >= 400 ? "yellow" : status >= 300 ? "cyan" : "green";
|
|
461
|
+
this.consola.success(
|
|
462
|
+
`${method} ${url} ${status} ${statusText} (${duration}ms)`
|
|
463
|
+
);
|
|
464
|
+
if (this.config.logBodies && data) {
|
|
465
|
+
this.consola.debug("Response:", data);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Log error
|
|
470
|
+
*/
|
|
471
|
+
logError(request, error) {
|
|
472
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
473
|
+
const { method, url } = request;
|
|
474
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
475
|
+
this.consola.error(
|
|
476
|
+
`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
|
|
477
|
+
);
|
|
478
|
+
this.consola.error("Message:", message);
|
|
479
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
480
|
+
this.consola.error("Field Errors:");
|
|
481
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
482
|
+
errors.forEach((err) => {
|
|
483
|
+
this.consola.error(` \u2022 ${field}: ${err}`);
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Log general info
|
|
490
|
+
*/
|
|
491
|
+
info(message, ...args) {
|
|
492
|
+
if (!this.config.enabled) return;
|
|
493
|
+
this.consola.info(message, ...args);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Log warning
|
|
497
|
+
*/
|
|
498
|
+
warn(message, ...args) {
|
|
499
|
+
if (!this.config.enabled) return;
|
|
500
|
+
this.consola.warn(message, ...args);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Log error
|
|
504
|
+
*/
|
|
505
|
+
error(message, ...args) {
|
|
506
|
+
if (!this.config.enabled) return;
|
|
507
|
+
this.consola.error(message, ...args);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Log debug
|
|
511
|
+
*/
|
|
512
|
+
debug(message, ...args) {
|
|
513
|
+
if (!this.config.enabled) return;
|
|
514
|
+
this.consola.debug(message, ...args);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Log success
|
|
518
|
+
*/
|
|
519
|
+
success(message, ...args) {
|
|
520
|
+
if (!this.config.enabled) return;
|
|
521
|
+
this.consola.success(message, ...args);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Create a sub-logger with prefix
|
|
525
|
+
*/
|
|
526
|
+
withTag(tag) {
|
|
527
|
+
return this.consola.withTag(tag);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
var defaultLogger = new APILogger();
|
|
531
|
+
|
|
532
|
+
// src/generated/cfg_accounts/retry.ts
|
|
533
|
+
var import_p_retry = __toESM(require("p-retry"), 1);
|
|
534
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
535
|
+
retries: 3,
|
|
536
|
+
factor: 2,
|
|
537
|
+
minTimeout: 1e3,
|
|
538
|
+
maxTimeout: 6e4,
|
|
539
|
+
randomize: true,
|
|
540
|
+
onFailedAttempt: /* @__PURE__ */ __name(() => {
|
|
541
|
+
}, "onFailedAttempt")
|
|
542
|
+
};
|
|
543
|
+
function shouldRetry(error) {
|
|
544
|
+
if (error instanceof NetworkError) {
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
if (error instanceof APIError) {
|
|
548
|
+
const status = error.statusCode;
|
|
549
|
+
if (status >= 500 && status < 600) {
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
if (status === 429) {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
__name(shouldRetry, "shouldRetry");
|
|
560
|
+
async function withRetry(fn, config) {
|
|
561
|
+
const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
|
|
562
|
+
return (0, import_p_retry.default)(
|
|
563
|
+
async () => {
|
|
564
|
+
try {
|
|
565
|
+
return await fn();
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (!shouldRetry(error)) {
|
|
568
|
+
throw new import_p_retry.AbortError(error);
|
|
569
|
+
}
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
retries: finalConfig.retries,
|
|
575
|
+
factor: finalConfig.factor,
|
|
576
|
+
minTimeout: finalConfig.minTimeout,
|
|
577
|
+
maxTimeout: finalConfig.maxTimeout,
|
|
578
|
+
randomize: finalConfig.randomize,
|
|
579
|
+
onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
|
|
580
|
+
const pRetryError = error;
|
|
581
|
+
finalConfig.onFailedAttempt({
|
|
582
|
+
error: pRetryError,
|
|
583
|
+
attemptNumber: pRetryError.attemptNumber,
|
|
584
|
+
retriesLeft: pRetryError.retriesLeft
|
|
585
|
+
});
|
|
586
|
+
} : void 0
|
|
587
|
+
}
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
__name(withRetry, "withRetry");
|
|
591
|
+
|
|
592
|
+
// src/generated/cfg_accounts/client.ts
|
|
593
|
+
var APIClient = class {
|
|
594
|
+
constructor(baseUrl, options) {
|
|
595
|
+
this.logger = null;
|
|
596
|
+
this.retryConfig = null;
|
|
597
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
598
|
+
this.httpClient = options?.httpClient || new FetchAdapter();
|
|
599
|
+
if (options?.loggerConfig !== void 0) {
|
|
600
|
+
this.logger = new APILogger(options.loggerConfig);
|
|
601
|
+
}
|
|
602
|
+
if (options?.retryConfig !== void 0) {
|
|
603
|
+
this.retryConfig = options.retryConfig;
|
|
604
|
+
}
|
|
605
|
+
this.auth = new Auth(this);
|
|
606
|
+
this.oauth = new Oauth(this);
|
|
607
|
+
this.user_profile = new UserProfile(this);
|
|
608
|
+
this.accounts = new Accounts(this);
|
|
609
|
+
}
|
|
610
|
+
static {
|
|
611
|
+
__name(this, "APIClient");
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Get CSRF token from cookies (for SessionAuthentication).
|
|
615
|
+
*
|
|
616
|
+
* Returns null if cookie doesn't exist (JWT-only auth).
|
|
617
|
+
*/
|
|
618
|
+
getCsrfToken() {
|
|
619
|
+
const name = "csrftoken";
|
|
620
|
+
const value = `; ${document.cookie}`;
|
|
621
|
+
const parts = value.split(`; ${name}=`);
|
|
622
|
+
if (parts.length === 2) {
|
|
623
|
+
return parts.pop()?.split(";").shift() || null;
|
|
624
|
+
}
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Make HTTP request with Django CSRF and session handling.
|
|
629
|
+
* Automatically retries on network errors and 5xx server errors.
|
|
630
|
+
*/
|
|
631
|
+
async request(method, path, options) {
|
|
632
|
+
if (this.retryConfig) {
|
|
633
|
+
return withRetry(() => this._makeRequest(method, path, options), {
|
|
634
|
+
...this.retryConfig,
|
|
635
|
+
onFailedAttempt: /* @__PURE__ */ __name((info) => {
|
|
636
|
+
if (this.logger) {
|
|
637
|
+
this.logger.warn(
|
|
638
|
+
`Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
this.retryConfig?.onFailedAttempt?.(info);
|
|
642
|
+
}, "onFailedAttempt")
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
return this._makeRequest(method, path, options);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Internal request method (without retry wrapper).
|
|
649
|
+
* Used by request() method with optional retry logic.
|
|
650
|
+
*/
|
|
651
|
+
async _makeRequest(method, path, options) {
|
|
652
|
+
const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
|
|
653
|
+
const startTime = Date.now();
|
|
654
|
+
const headers = {
|
|
655
|
+
...options?.headers || {}
|
|
656
|
+
};
|
|
657
|
+
if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
|
|
658
|
+
headers["Content-Type"] = "application/json";
|
|
659
|
+
}
|
|
660
|
+
if (this.logger) {
|
|
661
|
+
this.logger.logRequest({
|
|
662
|
+
method,
|
|
663
|
+
url,
|
|
664
|
+
headers,
|
|
665
|
+
body: options?.formData || options?.body,
|
|
666
|
+
timestamp: startTime
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
try {
|
|
670
|
+
const response = await this.httpClient.request({
|
|
671
|
+
method,
|
|
672
|
+
url,
|
|
673
|
+
headers,
|
|
674
|
+
params: options?.params,
|
|
675
|
+
body: options?.body,
|
|
676
|
+
formData: options?.formData,
|
|
677
|
+
binaryBody: options?.binaryBody
|
|
678
|
+
});
|
|
679
|
+
const duration = Date.now() - startTime;
|
|
680
|
+
if (response.status >= 400) {
|
|
681
|
+
const error = new APIError(
|
|
682
|
+
response.status,
|
|
683
|
+
response.statusText,
|
|
684
|
+
response.data,
|
|
685
|
+
url
|
|
686
|
+
);
|
|
687
|
+
if (this.logger) {
|
|
688
|
+
this.logger.logError(
|
|
689
|
+
{
|
|
690
|
+
method,
|
|
691
|
+
url,
|
|
692
|
+
headers,
|
|
693
|
+
body: options?.formData || options?.body,
|
|
694
|
+
timestamp: startTime
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
message: error.message,
|
|
698
|
+
statusCode: response.status,
|
|
699
|
+
duration,
|
|
700
|
+
timestamp: Date.now()
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
throw error;
|
|
705
|
+
}
|
|
706
|
+
if (this.logger) {
|
|
707
|
+
this.logger.logResponse(
|
|
708
|
+
{
|
|
709
|
+
method,
|
|
710
|
+
url,
|
|
711
|
+
headers,
|
|
712
|
+
body: options?.formData || options?.body,
|
|
713
|
+
timestamp: startTime
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
status: response.status,
|
|
717
|
+
statusText: response.statusText,
|
|
718
|
+
data: response.data,
|
|
719
|
+
duration,
|
|
720
|
+
timestamp: Date.now()
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
return response.data;
|
|
725
|
+
} catch (error) {
|
|
726
|
+
const duration = Date.now() - startTime;
|
|
727
|
+
if (error instanceof APIError) {
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
|
|
731
|
+
if (this.logger) {
|
|
732
|
+
if (isCORSError) {
|
|
733
|
+
this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
|
|
734
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
735
|
+
this.logger.error(` \u2192 Configure security_domains parameter on the server`);
|
|
736
|
+
} else {
|
|
737
|
+
this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
|
|
738
|
+
this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (typeof window !== "undefined") {
|
|
742
|
+
try {
|
|
743
|
+
if (isCORSError) {
|
|
744
|
+
window.dispatchEvent(new CustomEvent("cors-error", {
|
|
745
|
+
detail: {
|
|
746
|
+
url,
|
|
747
|
+
method,
|
|
748
|
+
error: error instanceof Error ? error.message : String(error),
|
|
749
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
750
|
+
},
|
|
751
|
+
bubbles: true,
|
|
752
|
+
cancelable: false
|
|
753
|
+
}));
|
|
754
|
+
} else {
|
|
755
|
+
window.dispatchEvent(new CustomEvent("network-error", {
|
|
756
|
+
detail: {
|
|
757
|
+
url,
|
|
758
|
+
method,
|
|
759
|
+
error: error instanceof Error ? error.message : String(error),
|
|
760
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
761
|
+
},
|
|
762
|
+
bubbles: true,
|
|
763
|
+
cancelable: false
|
|
764
|
+
}));
|
|
765
|
+
}
|
|
766
|
+
} catch (eventError) {
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
|
|
770
|
+
if (this.logger) {
|
|
771
|
+
this.logger.logError(
|
|
772
|
+
{
|
|
773
|
+
method,
|
|
774
|
+
url,
|
|
775
|
+
headers,
|
|
776
|
+
body: options?.formData || options?.body,
|
|
777
|
+
timestamp: startTime
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
message: networkError.message,
|
|
781
|
+
duration,
|
|
782
|
+
timestamp: Date.now()
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
throw networkError;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/generated/cfg_accounts/storage.ts
|
|
792
|
+
var LocalStorageAdapter = class {
|
|
793
|
+
static {
|
|
794
|
+
__name(this, "LocalStorageAdapter");
|
|
795
|
+
}
|
|
796
|
+
constructor(logger2) {
|
|
797
|
+
this.logger = logger2;
|
|
798
|
+
}
|
|
799
|
+
getItem(key) {
|
|
800
|
+
try {
|
|
801
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
802
|
+
const value = localStorage.getItem(key);
|
|
803
|
+
this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
|
|
804
|
+
return value;
|
|
805
|
+
}
|
|
806
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
807
|
+
} catch (error) {
|
|
808
|
+
this.logger?.error("LocalStorage.getItem failed:", error);
|
|
809
|
+
}
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
setItem(key, value) {
|
|
813
|
+
try {
|
|
814
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
815
|
+
localStorage.setItem(key, value);
|
|
816
|
+
this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
|
|
817
|
+
} else {
|
|
818
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
819
|
+
}
|
|
820
|
+
} catch (error) {
|
|
821
|
+
this.logger?.error("LocalStorage.setItem failed:", error);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
removeItem(key) {
|
|
825
|
+
try {
|
|
826
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
827
|
+
localStorage.removeItem(key);
|
|
828
|
+
this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
|
|
829
|
+
} else {
|
|
830
|
+
this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
|
|
831
|
+
}
|
|
832
|
+
} catch (error) {
|
|
833
|
+
this.logger?.error("LocalStorage.removeItem failed:", error);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// src/generated/cfg_accounts/enums.ts
|
|
839
|
+
var OAuthConnectionProvider = /* @__PURE__ */ ((OAuthConnectionProvider2) => {
|
|
840
|
+
OAuthConnectionProvider2["GITHUB"] = "github";
|
|
841
|
+
return OAuthConnectionProvider2;
|
|
842
|
+
})(OAuthConnectionProvider || {});
|
|
843
|
+
var OAuthDisconnectRequestRequestProvider = /* @__PURE__ */ ((OAuthDisconnectRequestRequestProvider2) => {
|
|
844
|
+
OAuthDisconnectRequestRequestProvider2["GITHUB"] = "github";
|
|
845
|
+
return OAuthDisconnectRequestRequestProvider2;
|
|
846
|
+
})(OAuthDisconnectRequestRequestProvider || {});
|
|
847
|
+
var OTPRequestRequestChannel = /* @__PURE__ */ ((OTPRequestRequestChannel2) => {
|
|
848
|
+
OTPRequestRequestChannel2["EMAIL"] = "email";
|
|
849
|
+
OTPRequestRequestChannel2["PHONE"] = "phone";
|
|
850
|
+
return OTPRequestRequestChannel2;
|
|
851
|
+
})(OTPRequestRequestChannel || {});
|
|
852
|
+
var OTPVerifyRequestChannel = /* @__PURE__ */ ((OTPVerifyRequestChannel2) => {
|
|
853
|
+
OTPVerifyRequestChannel2["EMAIL"] = "email";
|
|
854
|
+
OTPVerifyRequestChannel2["PHONE"] = "phone";
|
|
855
|
+
return OTPVerifyRequestChannel2;
|
|
856
|
+
})(OTPVerifyRequestChannel || {});
|
|
857
|
+
|
|
858
|
+
// src/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts
|
|
859
|
+
var import_zod = require("zod");
|
|
860
|
+
var CentrifugoTokenSchema = import_zod.z.object({
|
|
861
|
+
token: import_zod.z.string(),
|
|
862
|
+
centrifugo_url: import_zod.z.union([import_zod.z.url(), import_zod.z.literal("")]),
|
|
863
|
+
expires_at: import_zod.z.iso.datetime(),
|
|
864
|
+
channels: import_zod.z.array(import_zod.z.string())
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts
|
|
868
|
+
var import_zod2 = require("zod");
|
|
869
|
+
var OAuthAuthorizeRequestRequestSchema = import_zod2.z.object({
|
|
870
|
+
redirect_uri: import_zod2.z.union([import_zod2.z.url(), import_zod2.z.literal("")]).optional(),
|
|
871
|
+
source_url: import_zod2.z.union([import_zod2.z.url(), import_zod2.z.literal("")]).optional()
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts
|
|
875
|
+
var import_zod3 = require("zod");
|
|
876
|
+
var OAuthAuthorizeResponseSchema = import_zod3.z.object({
|
|
877
|
+
authorization_url: import_zod3.z.union([import_zod3.z.url(), import_zod3.z.literal("")]),
|
|
878
|
+
state: import_zod3.z.string()
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts
|
|
882
|
+
var import_zod4 = require("zod");
|
|
883
|
+
var OAuthCallbackRequestRequestSchema = import_zod4.z.object({
|
|
884
|
+
code: import_zod4.z.string().min(10).max(500),
|
|
885
|
+
state: import_zod4.z.string().min(20).max(100),
|
|
886
|
+
redirect_uri: import_zod4.z.union([import_zod4.z.url(), import_zod4.z.literal("")]).optional()
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts
|
|
890
|
+
var import_zod5 = require("zod");
|
|
891
|
+
var OAuthConnectionSchema = import_zod5.z.object({
|
|
892
|
+
id: import_zod5.z.int(),
|
|
893
|
+
provider: import_zod5.z.nativeEnum(OAuthConnectionProvider),
|
|
894
|
+
provider_display: import_zod5.z.string(),
|
|
895
|
+
provider_username: import_zod5.z.string(),
|
|
896
|
+
provider_email: import_zod5.z.email(),
|
|
897
|
+
provider_avatar_url: import_zod5.z.union([import_zod5.z.url(), import_zod5.z.literal("")]),
|
|
898
|
+
connected_at: import_zod5.z.iso.datetime(),
|
|
899
|
+
last_login_at: import_zod5.z.iso.datetime()
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthDisconnectRequestRequest.schema.ts
|
|
903
|
+
var import_zod6 = require("zod");
|
|
904
|
+
var OAuthDisconnectRequestRequestSchema = import_zod6.z.object({
|
|
905
|
+
provider: import_zod6.z.nativeEnum(OAuthDisconnectRequestRequestProvider)
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthError.schema.ts
|
|
909
|
+
var import_zod7 = require("zod");
|
|
910
|
+
var OAuthErrorSchema = import_zod7.z.object({
|
|
911
|
+
error: import_zod7.z.string(),
|
|
912
|
+
error_description: import_zod7.z.string().optional()
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts
|
|
916
|
+
var import_zod8 = require("zod");
|
|
917
|
+
var OAuthProvidersResponseSchema = import_zod8.z.object({
|
|
918
|
+
providers: import_zod8.z.array(import_zod8.z.record(import_zod8.z.string(), import_zod8.z.any()))
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
// src/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts
|
|
922
|
+
var import_zod9 = require("zod");
|
|
923
|
+
var OAuthTokenResponseSchema = import_zod9.z.object({
|
|
924
|
+
requires_2fa: import_zod9.z.boolean().optional(),
|
|
925
|
+
session_id: import_zod9.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
|
|
926
|
+
access: import_zod9.z.string().nullable().optional(),
|
|
927
|
+
refresh: import_zod9.z.string().nullable().optional(),
|
|
928
|
+
user: import_zod9.z.record(import_zod9.z.string(), import_zod9.z.any()).nullable().optional(),
|
|
929
|
+
is_new_user: import_zod9.z.boolean(),
|
|
930
|
+
is_new_connection: import_zod9.z.boolean(),
|
|
931
|
+
should_prompt_2fa: import_zod9.z.boolean().optional()
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts
|
|
935
|
+
var import_zod10 = require("zod");
|
|
936
|
+
var OTPErrorResponseSchema = import_zod10.z.object({
|
|
937
|
+
error: import_zod10.z.string()
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts
|
|
941
|
+
var import_zod11 = require("zod");
|
|
942
|
+
var OTPRequestRequestSchema = import_zod11.z.object({
|
|
943
|
+
identifier: import_zod11.z.string().min(1),
|
|
944
|
+
channel: import_zod11.z.nativeEnum(OTPRequestRequestChannel).optional(),
|
|
945
|
+
source_url: import_zod11.z.union([import_zod11.z.url(), import_zod11.z.literal("")]).optional()
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts
|
|
949
|
+
var import_zod12 = require("zod");
|
|
950
|
+
var OTPRequestResponseSchema = import_zod12.z.object({
|
|
951
|
+
message: import_zod12.z.string()
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts
|
|
955
|
+
var import_zod13 = require("zod");
|
|
956
|
+
var OTPVerifyRequestSchema = import_zod13.z.object({
|
|
957
|
+
identifier: import_zod13.z.string().min(1),
|
|
958
|
+
otp: import_zod13.z.string().min(6).max(6),
|
|
959
|
+
channel: import_zod13.z.nativeEnum(OTPVerifyRequestChannel).optional(),
|
|
960
|
+
source_url: import_zod13.z.union([import_zod13.z.url(), import_zod13.z.literal("")]).optional()
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
|
|
964
|
+
var import_zod15 = require("zod");
|
|
965
|
+
|
|
966
|
+
// src/generated/cfg_accounts/_utils/schemas/User.schema.ts
|
|
967
|
+
var import_zod14 = require("zod");
|
|
968
|
+
var UserSchema = import_zod14.z.object({
|
|
969
|
+
id: import_zod14.z.int(),
|
|
970
|
+
email: import_zod14.z.email(),
|
|
971
|
+
first_name: import_zod14.z.string().max(50).optional(),
|
|
972
|
+
last_name: import_zod14.z.string().max(50).optional(),
|
|
973
|
+
full_name: import_zod14.z.string(),
|
|
974
|
+
initials: import_zod14.z.string(),
|
|
975
|
+
display_username: import_zod14.z.string(),
|
|
976
|
+
company: import_zod14.z.string().max(100).optional(),
|
|
977
|
+
phone: import_zod14.z.string().max(20).optional(),
|
|
978
|
+
position: import_zod14.z.string().max(100).optional(),
|
|
979
|
+
avatar: import_zod14.z.union([import_zod14.z.url(), import_zod14.z.literal("")]).nullable(),
|
|
980
|
+
is_staff: import_zod14.z.boolean(),
|
|
981
|
+
is_superuser: import_zod14.z.boolean(),
|
|
982
|
+
date_joined: import_zod14.z.iso.datetime(),
|
|
983
|
+
last_login: import_zod14.z.iso.datetime().nullable(),
|
|
984
|
+
unanswered_messages_count: import_zod14.z.int(),
|
|
985
|
+
centrifugo: CentrifugoTokenSchema.nullable()
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
// src/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
|
|
989
|
+
var OTPVerifyResponseSchema = import_zod15.z.object({
|
|
990
|
+
requires_2fa: import_zod15.z.boolean().optional(),
|
|
991
|
+
session_id: import_zod15.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
|
|
992
|
+
refresh: import_zod15.z.string().nullable().optional(),
|
|
993
|
+
access: import_zod15.z.string().nullable().optional(),
|
|
994
|
+
user: UserSchema.nullable().optional(),
|
|
995
|
+
should_prompt_2fa: import_zod15.z.boolean().optional()
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
// src/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts
|
|
999
|
+
var import_zod16 = require("zod");
|
|
1000
|
+
var PatchedUserProfileUpdateRequestSchema = import_zod16.z.object({
|
|
1001
|
+
first_name: import_zod16.z.string().max(50).optional(),
|
|
1002
|
+
last_name: import_zod16.z.string().max(50).optional(),
|
|
1003
|
+
company: import_zod16.z.string().max(100).optional(),
|
|
1004
|
+
phone: import_zod16.z.string().max(20).optional(),
|
|
1005
|
+
position: import_zod16.z.string().max(100).optional()
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
// src/generated/cfg_accounts/_utils/schemas/TokenRefresh.schema.ts
|
|
1009
|
+
var import_zod17 = require("zod");
|
|
1010
|
+
var TokenRefreshSchema = import_zod17.z.object({
|
|
1011
|
+
access: import_zod17.z.string(),
|
|
1012
|
+
refresh: import_zod17.z.string()
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
// src/generated/cfg_accounts/_utils/schemas/TokenRefreshRequest.schema.ts
|
|
1016
|
+
var import_zod18 = require("zod");
|
|
1017
|
+
var TokenRefreshRequestSchema = import_zod18.z.object({
|
|
1018
|
+
refresh: import_zod18.z.string().min(1)
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
// src/generated/cfg_accounts/_utils/schemas/UserProfileUpdateRequest.schema.ts
|
|
1022
|
+
var import_zod19 = require("zod");
|
|
1023
|
+
var UserProfileUpdateRequestSchema = import_zod19.z.object({
|
|
1024
|
+
first_name: import_zod19.z.string().max(50).optional(),
|
|
1025
|
+
last_name: import_zod19.z.string().max(50).optional(),
|
|
1026
|
+
company: import_zod19.z.string().max(100).optional(),
|
|
1027
|
+
phone: import_zod19.z.string().max(20).optional(),
|
|
1028
|
+
position: import_zod19.z.string().max(100).optional()
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
// src/generated/cfg_accounts/_utils/fetchers/accounts.ts
|
|
1032
|
+
var import_consola2 = require("consola");
|
|
1033
|
+
|
|
1034
|
+
// src/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts
|
|
1035
|
+
var import_consola3 = require("consola");
|
|
1036
|
+
|
|
1037
|
+
// src/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts
|
|
1038
|
+
var import_consola4 = require("consola");
|
|
1039
|
+
|
|
1040
|
+
// src/generated/cfg_accounts/_utils/fetchers/accounts__user_profile.ts
|
|
1041
|
+
var import_consola5 = require("consola");
|
|
1042
|
+
|
|
1043
|
+
// src/generated/cfg_accounts/index.ts
|
|
1044
|
+
var TOKEN_KEY = "auth_token";
|
|
1045
|
+
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
1046
|
+
var API = class {
|
|
1047
|
+
constructor(baseUrl, options) {
|
|
1048
|
+
this._token = null;
|
|
1049
|
+
this._refreshToken = null;
|
|
1050
|
+
this.baseUrl = baseUrl;
|
|
1051
|
+
this.options = options;
|
|
1052
|
+
const logger2 = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
|
|
1053
|
+
this.storage = options?.storage || new LocalStorageAdapter(logger2);
|
|
1054
|
+
this._loadTokensFromStorage();
|
|
1055
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1056
|
+
retryConfig: this.options?.retryConfig,
|
|
1057
|
+
loggerConfig: this.options?.loggerConfig
|
|
1058
|
+
});
|
|
1059
|
+
this._injectAuthHeader();
|
|
1060
|
+
this.auth = this._client.auth;
|
|
1061
|
+
this.oauth = this._client.oauth;
|
|
1062
|
+
this.user_profile = this._client.user_profile;
|
|
1063
|
+
this.accounts = this._client.accounts;
|
|
1064
|
+
}
|
|
1065
|
+
static {
|
|
1066
|
+
__name(this, "API");
|
|
1067
|
+
}
|
|
1068
|
+
_loadTokensFromStorage() {
|
|
1069
|
+
this._token = this.storage.getItem(TOKEN_KEY);
|
|
1070
|
+
this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1071
|
+
}
|
|
1072
|
+
_reinitClients() {
|
|
1073
|
+
this._client = new APIClient(this.baseUrl, {
|
|
1074
|
+
retryConfig: this.options?.retryConfig,
|
|
1075
|
+
loggerConfig: this.options?.loggerConfig
|
|
1076
|
+
});
|
|
1077
|
+
this._injectAuthHeader();
|
|
1078
|
+
this.auth = this._client.auth;
|
|
1079
|
+
this.oauth = this._client.oauth;
|
|
1080
|
+
this.user_profile = this._client.user_profile;
|
|
1081
|
+
this.accounts = this._client.accounts;
|
|
1082
|
+
}
|
|
1083
|
+
_injectAuthHeader() {
|
|
1084
|
+
const originalRequest = this._client.request.bind(this._client);
|
|
1085
|
+
this._client.request = async (method, path, options) => {
|
|
1086
|
+
const token = this.getToken();
|
|
1087
|
+
const mergedOptions = {
|
|
1088
|
+
...options,
|
|
1089
|
+
headers: {
|
|
1090
|
+
...options?.headers || {},
|
|
1091
|
+
...token ? { "Authorization": `Bearer ${token}` } : {}
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
return originalRequest(method, path, mergedOptions);
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Get current JWT token
|
|
1099
|
+
*/
|
|
1100
|
+
getToken() {
|
|
1101
|
+
return this.storage.getItem(TOKEN_KEY);
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Get current refresh token
|
|
1105
|
+
*/
|
|
1106
|
+
getRefreshToken() {
|
|
1107
|
+
return this.storage.getItem(REFRESH_TOKEN_KEY);
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Set JWT token and refresh token
|
|
1111
|
+
* @param token - JWT access token
|
|
1112
|
+
* @param refreshToken - JWT refresh token (optional)
|
|
1113
|
+
*/
|
|
1114
|
+
setToken(token, refreshToken) {
|
|
1115
|
+
this._token = token;
|
|
1116
|
+
this.storage.setItem(TOKEN_KEY, token);
|
|
1117
|
+
if (refreshToken) {
|
|
1118
|
+
this._refreshToken = refreshToken;
|
|
1119
|
+
this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
1120
|
+
}
|
|
1121
|
+
this._reinitClients();
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Clear all tokens
|
|
1125
|
+
*/
|
|
1126
|
+
clearTokens() {
|
|
1127
|
+
this._token = null;
|
|
1128
|
+
this._refreshToken = null;
|
|
1129
|
+
this.storage.removeItem(TOKEN_KEY);
|
|
1130
|
+
this.storage.removeItem(REFRESH_TOKEN_KEY);
|
|
1131
|
+
this._reinitClients();
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Check if user is authenticated
|
|
1135
|
+
*/
|
|
1136
|
+
isAuthenticated() {
|
|
1137
|
+
return !!this.getToken();
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Update base URL and reinitialize clients
|
|
1141
|
+
* @param url - New base URL
|
|
1142
|
+
*/
|
|
1143
|
+
setBaseUrl(url) {
|
|
1144
|
+
this.baseUrl = url;
|
|
1145
|
+
this._reinitClients();
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Get current base URL
|
|
1149
|
+
*/
|
|
1150
|
+
getBaseUrl() {
|
|
1151
|
+
return this.baseUrl;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Get OpenAPI schema path
|
|
1155
|
+
* @returns Path to the OpenAPI schema JSON file
|
|
1156
|
+
*
|
|
1157
|
+
* Note: The OpenAPI schema is available in the schema.json file.
|
|
1158
|
+
* You can load it dynamically using:
|
|
1159
|
+
* ```typescript
|
|
1160
|
+
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
1161
|
+
* // or using fs in Node.js:
|
|
1162
|
+
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
getSchemaPath() {
|
|
1166
|
+
return "./schema.json";
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// src/generated/cfg_centrifugo/logger.ts
|
|
1171
|
+
var import_consola6 = require("consola");
|
|
1172
|
+
var DEFAULT_CONFIG2 = {
|
|
1173
|
+
enabled: process.env.NODE_ENV !== "production",
|
|
1174
|
+
logRequests: true,
|
|
1175
|
+
logResponses: true,
|
|
1176
|
+
logErrors: true,
|
|
1177
|
+
logBodies: true,
|
|
1178
|
+
logHeaders: false
|
|
1179
|
+
};
|
|
1180
|
+
var SENSITIVE_HEADERS2 = [
|
|
1181
|
+
"authorization",
|
|
1182
|
+
"cookie",
|
|
1183
|
+
"set-cookie",
|
|
1184
|
+
"x-api-key",
|
|
1185
|
+
"x-csrf-token"
|
|
1186
|
+
];
|
|
1187
|
+
var APILogger2 = class {
|
|
1188
|
+
static {
|
|
1189
|
+
__name(this, "APILogger");
|
|
1190
|
+
}
|
|
1191
|
+
constructor(config = {}) {
|
|
1192
|
+
this.config = { ...DEFAULT_CONFIG2, ...config };
|
|
1193
|
+
this.consola = config.consola || (0, import_consola6.createConsola)({
|
|
1194
|
+
level: this.config.enabled ? 4 : 0
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Enable logging
|
|
1199
|
+
*/
|
|
1200
|
+
enable() {
|
|
1201
|
+
this.config.enabled = true;
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Disable logging
|
|
1205
|
+
*/
|
|
1206
|
+
disable() {
|
|
1207
|
+
this.config.enabled = false;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Update configuration
|
|
1211
|
+
*/
|
|
1212
|
+
setConfig(config) {
|
|
1213
|
+
this.config = { ...this.config, ...config };
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Filter sensitive headers
|
|
1217
|
+
*/
|
|
1218
|
+
filterHeaders(headers) {
|
|
1219
|
+
if (!headers) return {};
|
|
1220
|
+
const filtered = {};
|
|
1221
|
+
Object.keys(headers).forEach((key) => {
|
|
1222
|
+
const lowerKey = key.toLowerCase();
|
|
1223
|
+
if (SENSITIVE_HEADERS2.includes(lowerKey)) {
|
|
1224
|
+
filtered[key] = "***";
|
|
1225
|
+
} else {
|
|
1226
|
+
filtered[key] = headers[key] || "";
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
return filtered;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Log request
|
|
1233
|
+
*/
|
|
1234
|
+
logRequest(request) {
|
|
1235
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
1236
|
+
const { method, url, headers, body } = request;
|
|
1237
|
+
this.consola.start(`${method} ${url}`);
|
|
1238
|
+
if (this.config.logHeaders && headers) {
|
|
1239
|
+
this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
1240
|
+
}
|
|
1241
|
+
if (this.config.logBodies && body) {
|
|
1242
|
+
this.consola.debug("Body:", body);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Log response
|
|
1247
|
+
*/
|
|
1248
|
+
logResponse(request, response) {
|
|
1249
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
1250
|
+
const { method, url } = request;
|
|
1251
|
+
const { status, statusText, data, duration } = response;
|
|
1252
|
+
const statusColor = status >= 500 ? "red" : status >= 400 ? "yellow" : status >= 300 ? "cyan" : "green";
|
|
1253
|
+
this.consola.success(
|
|
1254
|
+
`${method} ${url} ${status} ${statusText} (${duration}ms)`
|
|
1255
|
+
);
|
|
1256
|
+
if (this.config.logBodies && data) {
|
|
1257
|
+
this.consola.debug("Response:", data);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Log error
|
|
1262
|
+
*/
|
|
1263
|
+
logError(request, error) {
|
|
1264
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
1265
|
+
const { method, url } = request;
|
|
1266
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
1267
|
+
this.consola.error(
|
|
1268
|
+
`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
|
|
1269
|
+
);
|
|
1270
|
+
this.consola.error("Message:", message);
|
|
1271
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
1272
|
+
this.consola.error("Field Errors:");
|
|
1273
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
1274
|
+
errors.forEach((err) => {
|
|
1275
|
+
this.consola.error(` \u2022 ${field}: ${err}`);
|
|
1276
|
+
});
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Log general info
|
|
1282
|
+
*/
|
|
1283
|
+
info(message, ...args) {
|
|
1284
|
+
if (!this.config.enabled) return;
|
|
1285
|
+
this.consola.info(message, ...args);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Log warning
|
|
1289
|
+
*/
|
|
1290
|
+
warn(message, ...args) {
|
|
1291
|
+
if (!this.config.enabled) return;
|
|
1292
|
+
this.consola.warn(message, ...args);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Log error
|
|
1296
|
+
*/
|
|
1297
|
+
error(message, ...args) {
|
|
1298
|
+
if (!this.config.enabled) return;
|
|
1299
|
+
this.consola.error(message, ...args);
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Log debug
|
|
1303
|
+
*/
|
|
1304
|
+
debug(message, ...args) {
|
|
1305
|
+
if (!this.config.enabled) return;
|
|
1306
|
+
this.consola.debug(message, ...args);
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Log success
|
|
1310
|
+
*/
|
|
1311
|
+
success(message, ...args) {
|
|
1312
|
+
if (!this.config.enabled) return;
|
|
1313
|
+
this.consola.success(message, ...args);
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Create a sub-logger with prefix
|
|
1317
|
+
*/
|
|
1318
|
+
withTag(tag) {
|
|
1319
|
+
return this.consola.withTag(tag);
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
var defaultLogger2 = new APILogger2();
|
|
1323
|
+
|
|
1324
|
+
// src/generated/cfg_centrifugo/retry.ts
|
|
1325
|
+
var import_p_retry2 = __toESM(require("p-retry"), 1);
|
|
1326
|
+
|
|
1327
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoChannelInfo.schema.ts
|
|
1328
|
+
var import_zod20 = require("zod");
|
|
1329
|
+
var CentrifugoChannelInfoSchema = import_zod20.z.object({
|
|
1330
|
+
num_clients: import_zod20.z.int()
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoChannelsRequestRequest.schema.ts
|
|
1334
|
+
var import_zod21 = require("zod");
|
|
1335
|
+
var CentrifugoChannelsRequestRequestSchema = import_zod21.z.object({
|
|
1336
|
+
pattern: import_zod21.z.string().nullable().optional()
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoChannelsResponse.schema.ts
|
|
1340
|
+
var import_zod24 = require("zod");
|
|
1341
|
+
|
|
1342
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoChannelsResult.schema.ts
|
|
1343
|
+
var import_zod22 = require("zod");
|
|
1344
|
+
var CentrifugoChannelsResultSchema = import_zod22.z.object({
|
|
1345
|
+
channels: import_zod22.z.record(import_zod22.z.string(), CentrifugoChannelInfoSchema)
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoError.schema.ts
|
|
1349
|
+
var import_zod23 = require("zod");
|
|
1350
|
+
var CentrifugoErrorSchema = import_zod23.z.object({
|
|
1351
|
+
code: import_zod23.z.int().optional(),
|
|
1352
|
+
message: import_zod23.z.string().optional()
|
|
1353
|
+
});
|
|
1354
|
+
|
|
1355
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoChannelsResponse.schema.ts
|
|
1356
|
+
var CentrifugoChannelsResponseSchema = import_zod24.z.object({
|
|
1357
|
+
error: CentrifugoErrorSchema.optional(),
|
|
1358
|
+
result: CentrifugoChannelsResultSchema.optional()
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoClientInfo.schema.ts
|
|
1362
|
+
var import_zod25 = require("zod");
|
|
1363
|
+
var CentrifugoClientInfoSchema = import_zod25.z.object({
|
|
1364
|
+
user: import_zod25.z.string(),
|
|
1365
|
+
client: import_zod25.z.string(),
|
|
1366
|
+
conn_info: import_zod25.z.record(import_zod25.z.string(), import_zod25.z.any()).nullable().optional(),
|
|
1367
|
+
chan_info: import_zod25.z.record(import_zod25.z.string(), import_zod25.z.any()).nullable().optional()
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHealthCheck.schema.ts
|
|
1371
|
+
var import_zod26 = require("zod");
|
|
1372
|
+
var CentrifugoHealthCheckSchema = import_zod26.z.object({
|
|
1373
|
+
status: import_zod26.z.string(),
|
|
1374
|
+
wrapper_url: import_zod26.z.string(),
|
|
1375
|
+
has_api_key: import_zod26.z.boolean(),
|
|
1376
|
+
timestamp: import_zod26.z.string()
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryRequestRequest.schema.ts
|
|
1380
|
+
var import_zod28 = require("zod");
|
|
1381
|
+
|
|
1382
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoStreamPosition.schema.ts
|
|
1383
|
+
var import_zod27 = require("zod");
|
|
1384
|
+
var CentrifugoStreamPositionSchema = import_zod27.z.object({
|
|
1385
|
+
offset: import_zod27.z.int(),
|
|
1386
|
+
epoch: import_zod27.z.string()
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryRequestRequest.schema.ts
|
|
1390
|
+
var CentrifugoHistoryRequestRequestSchema = import_zod28.z.object({
|
|
1391
|
+
channel: import_zod28.z.string(),
|
|
1392
|
+
limit: import_zod28.z.int().nullable().optional(),
|
|
1393
|
+
since: CentrifugoStreamPositionSchema.optional(),
|
|
1394
|
+
reverse: import_zod28.z.boolean().nullable().optional()
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryResponse.schema.ts
|
|
1398
|
+
var import_zod31 = require("zod");
|
|
1399
|
+
|
|
1400
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryResult.schema.ts
|
|
1401
|
+
var import_zod30 = require("zod");
|
|
1402
|
+
|
|
1403
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPublication.schema.ts
|
|
1404
|
+
var import_zod29 = require("zod");
|
|
1405
|
+
var CentrifugoPublicationSchema = import_zod29.z.object({
|
|
1406
|
+
data: import_zod29.z.record(import_zod29.z.string(), import_zod29.z.any()),
|
|
1407
|
+
info: CentrifugoClientInfoSchema.optional(),
|
|
1408
|
+
offset: import_zod29.z.int(),
|
|
1409
|
+
tags: import_zod29.z.record(import_zod29.z.string(), import_zod29.z.any()).nullable().optional()
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryResult.schema.ts
|
|
1413
|
+
var CentrifugoHistoryResultSchema = import_zod30.z.object({
|
|
1414
|
+
publications: import_zod30.z.array(CentrifugoPublicationSchema),
|
|
1415
|
+
epoch: import_zod30.z.string(),
|
|
1416
|
+
offset: import_zod30.z.int()
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoHistoryResponse.schema.ts
|
|
1420
|
+
var CentrifugoHistoryResponseSchema = import_zod31.z.object({
|
|
1421
|
+
error: CentrifugoErrorSchema.optional(),
|
|
1422
|
+
result: CentrifugoHistoryResultSchema.optional()
|
|
1423
|
+
});
|
|
1424
|
+
|
|
1425
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoInfoResponse.schema.ts
|
|
1426
|
+
var import_zod36 = require("zod");
|
|
1427
|
+
|
|
1428
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoInfoResult.schema.ts
|
|
1429
|
+
var import_zod35 = require("zod");
|
|
1430
|
+
|
|
1431
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoNodeInfo.schema.ts
|
|
1432
|
+
var import_zod34 = require("zod");
|
|
1433
|
+
|
|
1434
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoMetrics.schema.ts
|
|
1435
|
+
var import_zod32 = require("zod");
|
|
1436
|
+
var CentrifugoMetricsSchema = import_zod32.z.object({
|
|
1437
|
+
interval: import_zod32.z.number(),
|
|
1438
|
+
items: import_zod32.z.record(import_zod32.z.string(), import_zod32.z.number())
|
|
1439
|
+
});
|
|
1440
|
+
|
|
1441
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoProcess.schema.ts
|
|
1442
|
+
var import_zod33 = require("zod");
|
|
1443
|
+
var CentrifugoProcessSchema = import_zod33.z.object({
|
|
1444
|
+
cpu: import_zod33.z.number(),
|
|
1445
|
+
rss: import_zod33.z.int()
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoNodeInfo.schema.ts
|
|
1449
|
+
var CentrifugoNodeInfoSchema = import_zod34.z.object({
|
|
1450
|
+
uid: import_zod34.z.string(),
|
|
1451
|
+
name: import_zod34.z.string(),
|
|
1452
|
+
version: import_zod34.z.string(),
|
|
1453
|
+
num_clients: import_zod34.z.int(),
|
|
1454
|
+
num_users: import_zod34.z.int(),
|
|
1455
|
+
num_channels: import_zod34.z.int(),
|
|
1456
|
+
uptime: import_zod34.z.int(),
|
|
1457
|
+
num_subs: import_zod34.z.int(),
|
|
1458
|
+
metrics: CentrifugoMetricsSchema.optional(),
|
|
1459
|
+
process: CentrifugoProcessSchema.optional()
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoInfoResult.schema.ts
|
|
1463
|
+
var CentrifugoInfoResultSchema = import_zod35.z.object({
|
|
1464
|
+
nodes: import_zod35.z.array(CentrifugoNodeInfoSchema)
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoInfoResponse.schema.ts
|
|
1468
|
+
var CentrifugoInfoResponseSchema = import_zod36.z.object({
|
|
1469
|
+
error: CentrifugoErrorSchema.optional(),
|
|
1470
|
+
result: CentrifugoInfoResultSchema.optional()
|
|
1471
|
+
});
|
|
1472
|
+
|
|
1473
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoOverviewStats.schema.ts
|
|
1474
|
+
var import_zod37 = require("zod");
|
|
1475
|
+
var CentrifugoOverviewStatsSchema = import_zod37.z.object({
|
|
1476
|
+
total: import_zod37.z.int(),
|
|
1477
|
+
successful: import_zod37.z.int(),
|
|
1478
|
+
failed: import_zod37.z.int(),
|
|
1479
|
+
timeout: import_zod37.z.int(),
|
|
1480
|
+
success_rate: import_zod37.z.number(),
|
|
1481
|
+
avg_duration_ms: import_zod37.z.number(),
|
|
1482
|
+
avg_acks_received: import_zod37.z.number(),
|
|
1483
|
+
period_hours: import_zod37.z.int()
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceRequestRequest.schema.ts
|
|
1487
|
+
var import_zod38 = require("zod");
|
|
1488
|
+
var CentrifugoPresenceRequestRequestSchema = import_zod38.z.object({
|
|
1489
|
+
channel: import_zod38.z.string()
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceResponse.schema.ts
|
|
1493
|
+
var import_zod40 = require("zod");
|
|
1494
|
+
|
|
1495
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceResult.schema.ts
|
|
1496
|
+
var import_zod39 = require("zod");
|
|
1497
|
+
var CentrifugoPresenceResultSchema = import_zod39.z.object({
|
|
1498
|
+
presence: import_zod39.z.record(import_zod39.z.string(), CentrifugoClientInfoSchema)
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceResponse.schema.ts
|
|
1502
|
+
var CentrifugoPresenceResponseSchema = import_zod40.z.object({
|
|
1503
|
+
error: CentrifugoErrorSchema.optional(),
|
|
1504
|
+
result: CentrifugoPresenceResultSchema.optional()
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1507
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceStatsRequestRequest.schema.ts
|
|
1508
|
+
var import_zod41 = require("zod");
|
|
1509
|
+
var CentrifugoPresenceStatsRequestRequestSchema = import_zod41.z.object({
|
|
1510
|
+
channel: import_zod41.z.string()
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceStatsResponse.schema.ts
|
|
1514
|
+
var import_zod43 = require("zod");
|
|
1515
|
+
|
|
1516
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceStatsResult.schema.ts
|
|
1517
|
+
var import_zod42 = require("zod");
|
|
1518
|
+
var CentrifugoPresenceStatsResultSchema = import_zod42.z.object({
|
|
1519
|
+
num_clients: import_zod42.z.int(),
|
|
1520
|
+
num_users: import_zod42.z.int()
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
// src/generated/cfg_centrifugo/_utils/schemas/CentrifugoPresenceStatsResponse.schema.ts
|
|
1524
|
+
var CentrifugoPresenceStatsResponseSchema = import_zod43.z.object({
|
|
1525
|
+
error: CentrifugoErrorSchema.optional(),
|
|
1526
|
+
result: CentrifugoPresenceStatsResultSchema.optional()
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ChannelList.schema.ts
|
|
1530
|
+
var import_zod45 = require("zod");
|
|
1531
|
+
|
|
1532
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ChannelStats.schema.ts
|
|
1533
|
+
var import_zod44 = require("zod");
|
|
1534
|
+
var ChannelStatsSchema = import_zod44.z.object({
|
|
1535
|
+
channel: import_zod44.z.string(),
|
|
1536
|
+
total: import_zod44.z.int(),
|
|
1537
|
+
successful: import_zod44.z.int(),
|
|
1538
|
+
failed: import_zod44.z.int(),
|
|
1539
|
+
avg_duration_ms: import_zod44.z.number(),
|
|
1540
|
+
avg_acks: import_zod44.z.number(),
|
|
1541
|
+
last_activity_at: import_zod44.z.string().nullable()
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ChannelList.schema.ts
|
|
1545
|
+
var ChannelListSchema = import_zod45.z.object({
|
|
1546
|
+
channels: import_zod45.z.array(ChannelStatsSchema),
|
|
1547
|
+
total_channels: import_zod45.z.int()
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1550
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ConnectionTokenResponse.schema.ts
|
|
1551
|
+
var import_zod46 = require("zod");
|
|
1552
|
+
var ConnectionTokenResponseSchema = import_zod46.z.object({
|
|
1553
|
+
token: import_zod46.z.string(),
|
|
1554
|
+
centrifugo_url: import_zod46.z.string(),
|
|
1555
|
+
expires_at: import_zod46.z.string(),
|
|
1556
|
+
channels: import_zod46.z.array(import_zod46.z.string())
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1559
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ManualAckRequestRequest.schema.ts
|
|
1560
|
+
var import_zod47 = require("zod");
|
|
1561
|
+
var ManualAckRequestRequestSchema = import_zod47.z.object({
|
|
1562
|
+
message_id: import_zod47.z.string(),
|
|
1563
|
+
client_id: import_zod47.z.string()
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
// src/generated/cfg_centrifugo/_utils/schemas/ManualAckResponse.schema.ts
|
|
1567
|
+
var import_zod48 = require("zod");
|
|
1568
|
+
var ManualAckResponseSchema = import_zod48.z.object({
|
|
1569
|
+
success: import_zod48.z.boolean(),
|
|
1570
|
+
message_id: import_zod48.z.string(),
|
|
1571
|
+
error: import_zod48.z.string().nullable().optional()
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
// src/generated/cfg_centrifugo/_utils/schemas/PaginatedPublishList.schema.ts
|
|
1575
|
+
var import_zod50 = require("zod");
|
|
1576
|
+
|
|
1577
|
+
// src/generated/cfg_centrifugo/_utils/schemas/Publish.schema.ts
|
|
1578
|
+
var import_zod49 = require("zod");
|
|
1579
|
+
var PublishSchema = import_zod49.z.object({
|
|
1580
|
+
message_id: import_zod49.z.string(),
|
|
1581
|
+
channel: import_zod49.z.string(),
|
|
1582
|
+
status: import_zod49.z.string(),
|
|
1583
|
+
wait_for_ack: import_zod49.z.boolean(),
|
|
1584
|
+
acks_received: import_zod49.z.int(),
|
|
1585
|
+
acks_expected: import_zod49.z.int().nullable(),
|
|
1586
|
+
duration_ms: import_zod49.z.number().nullable(),
|
|
1587
|
+
created_at: import_zod49.z.iso.datetime(),
|
|
1588
|
+
completed_at: import_zod49.z.iso.datetime().nullable(),
|
|
1589
|
+
error_code: import_zod49.z.string().nullable(),
|
|
1590
|
+
error_message: import_zod49.z.string().nullable()
|
|
1591
|
+
});
|
|
1592
|
+
|
|
1593
|
+
// src/generated/cfg_centrifugo/_utils/schemas/PaginatedPublishList.schema.ts
|
|
1594
|
+
var PaginatedPublishListSchema = import_zod50.z.object({
|
|
1595
|
+
count: import_zod50.z.int(),
|
|
1596
|
+
page: import_zod50.z.int(),
|
|
1597
|
+
pages: import_zod50.z.int(),
|
|
1598
|
+
page_size: import_zod50.z.int(),
|
|
1599
|
+
has_next: import_zod50.z.boolean(),
|
|
1600
|
+
has_previous: import_zod50.z.boolean(),
|
|
1601
|
+
next_page: import_zod50.z.int().nullable().optional(),
|
|
1602
|
+
previous_page: import_zod50.z.int().nullable().optional(),
|
|
1603
|
+
results: import_zod50.z.array(PublishSchema)
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// src/generated/cfg_centrifugo/_utils/schemas/PublishTestRequestRequest.schema.ts
|
|
1607
|
+
var import_zod51 = require("zod");
|
|
1608
|
+
var PublishTestRequestRequestSchema = import_zod51.z.object({
|
|
1609
|
+
channel: import_zod51.z.string(),
|
|
1610
|
+
data: import_zod51.z.record(import_zod51.z.string(), import_zod51.z.any()),
|
|
1611
|
+
wait_for_ack: import_zod51.z.boolean().optional(),
|
|
1612
|
+
ack_timeout: import_zod51.z.int().min(1).max(60).optional()
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
// src/generated/cfg_centrifugo/_utils/schemas/PublishTestResponse.schema.ts
|
|
1616
|
+
var import_zod52 = require("zod");
|
|
1617
|
+
var PublishTestResponseSchema = import_zod52.z.object({
|
|
1618
|
+
success: import_zod52.z.boolean(),
|
|
1619
|
+
message_id: import_zod52.z.string(),
|
|
1620
|
+
channel: import_zod52.z.string(),
|
|
1621
|
+
acks_received: import_zod52.z.int().optional(),
|
|
1622
|
+
delivered: import_zod52.z.boolean().optional(),
|
|
1623
|
+
error: import_zod52.z.string().nullable().optional()
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
// src/generated/cfg_centrifugo/_utils/schemas/TimelineItem.schema.ts
|
|
1627
|
+
var import_zod53 = require("zod");
|
|
1628
|
+
var TimelineItemSchema = import_zod53.z.object({
|
|
1629
|
+
timestamp: import_zod53.z.string(),
|
|
1630
|
+
count: import_zod53.z.int(),
|
|
1631
|
+
successful: import_zod53.z.int(),
|
|
1632
|
+
failed: import_zod53.z.int(),
|
|
1633
|
+
timeout: import_zod53.z.int()
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
// src/generated/cfg_centrifugo/_utils/schemas/TimelineResponse.schema.ts
|
|
1637
|
+
var import_zod54 = require("zod");
|
|
1638
|
+
var TimelineResponseSchema = import_zod54.z.object({
|
|
1639
|
+
timeline: import_zod54.z.array(TimelineItemSchema),
|
|
1640
|
+
period_hours: import_zod54.z.int(),
|
|
1641
|
+
interval: import_zod54.z.string()
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// src/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_admin_api.ts
|
|
1645
|
+
var import_consola7 = require("consola");
|
|
1646
|
+
|
|
1647
|
+
// src/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_auth.ts
|
|
1648
|
+
var import_consola8 = require("consola");
|
|
1649
|
+
|
|
1650
|
+
// src/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_monitoring.ts
|
|
1651
|
+
var import_consola9 = require("consola");
|
|
1652
|
+
|
|
1653
|
+
// src/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_testing.ts
|
|
1654
|
+
var import_consola10 = require("consola");
|
|
1655
|
+
|
|
1656
|
+
// src/generated/cfg_webpush/logger.ts
|
|
1657
|
+
var import_consola11 = require("consola");
|
|
1658
|
+
var DEFAULT_CONFIG3 = {
|
|
1659
|
+
enabled: process.env.NODE_ENV !== "production",
|
|
1660
|
+
logRequests: true,
|
|
1661
|
+
logResponses: true,
|
|
1662
|
+
logErrors: true,
|
|
1663
|
+
logBodies: true,
|
|
1664
|
+
logHeaders: false
|
|
1665
|
+
};
|
|
1666
|
+
var SENSITIVE_HEADERS3 = [
|
|
1667
|
+
"authorization",
|
|
1668
|
+
"cookie",
|
|
1669
|
+
"set-cookie",
|
|
1670
|
+
"x-api-key",
|
|
1671
|
+
"x-csrf-token"
|
|
1672
|
+
];
|
|
1673
|
+
var APILogger3 = class {
|
|
1674
|
+
static {
|
|
1675
|
+
__name(this, "APILogger");
|
|
1676
|
+
}
|
|
1677
|
+
constructor(config = {}) {
|
|
1678
|
+
this.config = { ...DEFAULT_CONFIG3, ...config };
|
|
1679
|
+
this.consola = config.consola || (0, import_consola11.createConsola)({
|
|
1680
|
+
level: this.config.enabled ? 4 : 0
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Enable logging
|
|
1685
|
+
*/
|
|
1686
|
+
enable() {
|
|
1687
|
+
this.config.enabled = true;
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Disable logging
|
|
1691
|
+
*/
|
|
1692
|
+
disable() {
|
|
1693
|
+
this.config.enabled = false;
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Update configuration
|
|
1697
|
+
*/
|
|
1698
|
+
setConfig(config) {
|
|
1699
|
+
this.config = { ...this.config, ...config };
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Filter sensitive headers
|
|
1703
|
+
*/
|
|
1704
|
+
filterHeaders(headers) {
|
|
1705
|
+
if (!headers) return {};
|
|
1706
|
+
const filtered = {};
|
|
1707
|
+
Object.keys(headers).forEach((key) => {
|
|
1708
|
+
const lowerKey = key.toLowerCase();
|
|
1709
|
+
if (SENSITIVE_HEADERS3.includes(lowerKey)) {
|
|
1710
|
+
filtered[key] = "***";
|
|
1711
|
+
} else {
|
|
1712
|
+
filtered[key] = headers[key] || "";
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
return filtered;
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Log request
|
|
1719
|
+
*/
|
|
1720
|
+
logRequest(request) {
|
|
1721
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
1722
|
+
const { method, url, headers, body } = request;
|
|
1723
|
+
this.consola.start(`${method} ${url}`);
|
|
1724
|
+
if (this.config.logHeaders && headers) {
|
|
1725
|
+
this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
1726
|
+
}
|
|
1727
|
+
if (this.config.logBodies && body) {
|
|
1728
|
+
this.consola.debug("Body:", body);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Log response
|
|
1733
|
+
*/
|
|
1734
|
+
logResponse(request, response) {
|
|
1735
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
1736
|
+
const { method, url } = request;
|
|
1737
|
+
const { status, statusText, data, duration } = response;
|
|
1738
|
+
const statusColor = status >= 500 ? "red" : status >= 400 ? "yellow" : status >= 300 ? "cyan" : "green";
|
|
1739
|
+
this.consola.success(
|
|
1740
|
+
`${method} ${url} ${status} ${statusText} (${duration}ms)`
|
|
1741
|
+
);
|
|
1742
|
+
if (this.config.logBodies && data) {
|
|
1743
|
+
this.consola.debug("Response:", data);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Log error
|
|
1748
|
+
*/
|
|
1749
|
+
logError(request, error) {
|
|
1750
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
1751
|
+
const { method, url } = request;
|
|
1752
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
1753
|
+
this.consola.error(
|
|
1754
|
+
`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
|
|
1755
|
+
);
|
|
1756
|
+
this.consola.error("Message:", message);
|
|
1757
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
1758
|
+
this.consola.error("Field Errors:");
|
|
1759
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
1760
|
+
errors.forEach((err) => {
|
|
1761
|
+
this.consola.error(` \u2022 ${field}: ${err}`);
|
|
1762
|
+
});
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Log general info
|
|
1768
|
+
*/
|
|
1769
|
+
info(message, ...args) {
|
|
1770
|
+
if (!this.config.enabled) return;
|
|
1771
|
+
this.consola.info(message, ...args);
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Log warning
|
|
1775
|
+
*/
|
|
1776
|
+
warn(message, ...args) {
|
|
1777
|
+
if (!this.config.enabled) return;
|
|
1778
|
+
this.consola.warn(message, ...args);
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Log error
|
|
1782
|
+
*/
|
|
1783
|
+
error(message, ...args) {
|
|
1784
|
+
if (!this.config.enabled) return;
|
|
1785
|
+
this.consola.error(message, ...args);
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Log debug
|
|
1789
|
+
*/
|
|
1790
|
+
debug(message, ...args) {
|
|
1791
|
+
if (!this.config.enabled) return;
|
|
1792
|
+
this.consola.debug(message, ...args);
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Log success
|
|
1796
|
+
*/
|
|
1797
|
+
success(message, ...args) {
|
|
1798
|
+
if (!this.config.enabled) return;
|
|
1799
|
+
this.consola.success(message, ...args);
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Create a sub-logger with prefix
|
|
1803
|
+
*/
|
|
1804
|
+
withTag(tag) {
|
|
1805
|
+
return this.consola.withTag(tag);
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
var defaultLogger3 = new APILogger3();
|
|
1809
|
+
|
|
1810
|
+
// src/generated/cfg_webpush/retry.ts
|
|
1811
|
+
var import_p_retry3 = __toESM(require("p-retry"), 1);
|
|
1812
|
+
|
|
1813
|
+
// src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts
|
|
1814
|
+
var import_zod55 = require("zod");
|
|
1815
|
+
var SendPushRequestRequestSchema = import_zod55.z.object({
|
|
1816
|
+
title: import_zod55.z.string().min(1).max(255),
|
|
1817
|
+
body: import_zod55.z.string().min(1),
|
|
1818
|
+
icon: import_zod55.z.union([import_zod55.z.url(), import_zod55.z.literal("")]).nullable().optional(),
|
|
1819
|
+
url: import_zod55.z.union([import_zod55.z.url(), import_zod55.z.literal("")]).nullable().optional()
|
|
1820
|
+
});
|
|
1821
|
+
|
|
1822
|
+
// src/generated/cfg_webpush/_utils/schemas/SendPushResponse.schema.ts
|
|
1823
|
+
var import_zod56 = require("zod");
|
|
1824
|
+
var SendPushResponseSchema = import_zod56.z.object({
|
|
1825
|
+
success: import_zod56.z.boolean(),
|
|
1826
|
+
sent_to: import_zod56.z.int()
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
// src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts
|
|
1830
|
+
var import_zod57 = require("zod");
|
|
1831
|
+
var SubscribeRequestRequestSchema = import_zod57.z.object({
|
|
1832
|
+
endpoint: import_zod57.z.union([import_zod57.z.url(), import_zod57.z.literal("")]),
|
|
1833
|
+
keys: import_zod57.z.record(import_zod57.z.string(), import_zod57.z.string().min(1))
|
|
1834
|
+
});
|
|
1835
|
+
|
|
1836
|
+
// src/generated/cfg_webpush/_utils/schemas/SubscribeResponse.schema.ts
|
|
1837
|
+
var import_zod58 = require("zod");
|
|
1838
|
+
var SubscribeResponseSchema = import_zod58.z.object({
|
|
1839
|
+
success: import_zod58.z.boolean(),
|
|
1840
|
+
subscription_id: import_zod58.z.int(),
|
|
1841
|
+
created: import_zod58.z.boolean()
|
|
1842
|
+
});
|
|
1843
|
+
|
|
1844
|
+
// src/generated/cfg_webpush/_utils/schemas/VapidPublicKeyResponse.schema.ts
|
|
1845
|
+
var import_zod59 = require("zod");
|
|
1846
|
+
var VapidPublicKeyResponseSchema = import_zod59.z.object({
|
|
1847
|
+
publicKey: import_zod59.z.string()
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
// src/generated/cfg_webpush/_utils/fetchers/webpush__web_push.ts
|
|
1851
|
+
var import_consola12 = require("consola");
|
|
1852
|
+
|
|
1853
|
+
// src/index.ts
|
|
1854
|
+
var isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
|
|
1855
|
+
var apiUrl = isStaticBuild ? "" : process.env.NEXT_PUBLIC_API_URL || "";
|
|
1856
|
+
var api = new API(
|
|
1857
|
+
apiUrl,
|
|
1858
|
+
{
|
|
1859
|
+
storage: new LocalStorageAdapter()
|
|
1860
|
+
}
|
|
1861
|
+
);
|
|
1862
|
+
var BaseClient = class {
|
|
1863
|
+
static {
|
|
1864
|
+
__name(this, "BaseClient");
|
|
1865
|
+
}
|
|
1866
|
+
static {
|
|
1867
|
+
this.api = api;
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/auth/utils/logger.ts
|
|
1872
|
+
var import_consola13 = require("consola");
|
|
1873
|
+
var isDevelopment = process.env.NODE_ENV === "development";
|
|
1874
|
+
var isStaticBuild2 = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
|
|
1875
|
+
var showLogs = isDevelopment || isStaticBuild2;
|
|
1876
|
+
var logger = (0, import_consola13.createConsola)({
|
|
1877
|
+
level: showLogs ? 4 : 1
|
|
1878
|
+
// dev: debug, production: errors only
|
|
1879
|
+
}).withTag("api");
|
|
1880
|
+
var authLogger = logger.withTag("auth");
|
|
1881
|
+
|
|
1882
|
+
// src/auth/middlewares/tokenRefresh.ts
|
|
1883
|
+
var isRefreshing = false;
|
|
1884
|
+
var refreshSubscribers = [];
|
|
1885
|
+
function subscribeTokenRefresh(callback) {
|
|
1886
|
+
refreshSubscribers.push(callback);
|
|
1887
|
+
}
|
|
1888
|
+
__name(subscribeTokenRefresh, "subscribeTokenRefresh");
|
|
1889
|
+
function onTokenRefreshed(token) {
|
|
1890
|
+
refreshSubscribers.forEach((callback) => callback(token));
|
|
1891
|
+
refreshSubscribers = [];
|
|
1892
|
+
}
|
|
1893
|
+
__name(onTokenRefreshed, "onTokenRefreshed");
|
|
1894
|
+
async function refreshAccessToken() {
|
|
1895
|
+
if (isRefreshing) {
|
|
1896
|
+
return new Promise((resolve) => {
|
|
1897
|
+
subscribeTokenRefresh((token) => resolve(token));
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
isRefreshing = true;
|
|
1901
|
+
authLogger.info("Starting token refresh...");
|
|
1902
|
+
try {
|
|
1903
|
+
const refreshToken = api.getRefreshToken();
|
|
1904
|
+
if (!refreshToken) {
|
|
1905
|
+
authLogger.warn("No refresh token available for refresh");
|
|
1906
|
+
onTokenRefreshed(null);
|
|
1907
|
+
return null;
|
|
1908
|
+
}
|
|
1909
|
+
const response = await fetch("/api/accounts/token/refresh/", {
|
|
1910
|
+
method: "POST",
|
|
1911
|
+
headers: {
|
|
1912
|
+
"Content-Type": "application/json"
|
|
1913
|
+
},
|
|
1914
|
+
body: JSON.stringify({ refresh: refreshToken })
|
|
1915
|
+
});
|
|
1916
|
+
if (!response.ok) {
|
|
1917
|
+
authLogger.error("Token refresh failed with status:", response.status);
|
|
1918
|
+
onTokenRefreshed(null);
|
|
1919
|
+
return null;
|
|
1920
|
+
}
|
|
1921
|
+
const data = await response.json();
|
|
1922
|
+
const newAccessToken = data.access;
|
|
1923
|
+
if (!newAccessToken) {
|
|
1924
|
+
authLogger.error("Token refresh response missing access token");
|
|
1925
|
+
onTokenRefreshed(null);
|
|
1926
|
+
return null;
|
|
1927
|
+
}
|
|
1928
|
+
api.setToken(newAccessToken, refreshToken);
|
|
1929
|
+
authLogger.info("Token refreshed successfully");
|
|
1930
|
+
onTokenRefreshed(newAccessToken);
|
|
1931
|
+
return newAccessToken;
|
|
1932
|
+
} catch (error) {
|
|
1933
|
+
authLogger.error("Token refresh error:", error);
|
|
1934
|
+
onTokenRefreshed(null);
|
|
1935
|
+
return null;
|
|
1936
|
+
} finally {
|
|
1937
|
+
isRefreshing = false;
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
__name(refreshAccessToken, "refreshAccessToken");
|
|
1941
|
+
function isAuthenticationError(response) {
|
|
1942
|
+
return response.status === 401;
|
|
1943
|
+
}
|
|
1944
|
+
__name(isAuthenticationError, "isAuthenticationError");
|
|
1945
|
+
function createAutoRefreshFetch(originalFetch) {
|
|
1946
|
+
return async (input, init) => {
|
|
1947
|
+
let response = await originalFetch(input, init);
|
|
1948
|
+
if (isAuthenticationError(response) && api.getRefreshToken()) {
|
|
1949
|
+
authLogger.info("Received 401, attempting token refresh...");
|
|
1950
|
+
const newToken = await refreshAccessToken();
|
|
1951
|
+
if (newToken) {
|
|
1952
|
+
const newInit = {
|
|
1953
|
+
...init,
|
|
1954
|
+
headers: {
|
|
1955
|
+
...init?.headers,
|
|
1956
|
+
Authorization: `Bearer ${newToken}`
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
authLogger.info("Retrying request with new token...");
|
|
1960
|
+
response = await originalFetch(input, newInit);
|
|
1961
|
+
} else {
|
|
1962
|
+
authLogger.warn("Token refresh failed, returning original 401 response");
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
return response;
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
__name(createAutoRefreshFetch, "createAutoRefreshFetch");
|
|
1969
|
+
function isTokenExpiringSoon(thresholdMs = 5 * 60 * 1e3) {
|
|
1970
|
+
const token = api.getToken();
|
|
1971
|
+
if (!token) return false;
|
|
1972
|
+
try {
|
|
1973
|
+
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
1974
|
+
const expiresAt = payload.exp * 1e3;
|
|
1975
|
+
const now = Date.now();
|
|
1976
|
+
const timeUntilExpiry = expiresAt - now;
|
|
1977
|
+
return timeUntilExpiry < thresholdMs;
|
|
1978
|
+
} catch (error) {
|
|
1979
|
+
authLogger.error("Error checking token expiry:", error);
|
|
1980
|
+
return false;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
__name(isTokenExpiringSoon, "isTokenExpiringSoon");
|
|
1984
|
+
async function refreshIfExpiringSoon(thresholdMs = 5 * 60 * 1e3) {
|
|
1985
|
+
if (isTokenExpiringSoon(thresholdMs)) {
|
|
1986
|
+
authLogger.info("Token expiring soon, proactively refreshing...");
|
|
1987
|
+
await refreshAccessToken();
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
__name(refreshIfExpiringSoon, "refreshIfExpiringSoon");
|
|
47
1991
|
//# sourceMappingURL=auth-server.cjs.map
|