@djangocfg/api 2.1.454 → 2.1.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/auth.cjs +2654 -2920
  2. package/dist/auth.cjs.map +1 -1
  3. package/dist/auth.d.cts +18 -82
  4. package/dist/auth.d.ts +18 -82
  5. package/dist/auth.mjs +385 -2861
  6. package/dist/auth.mjs.map +1 -1
  7. package/dist/chunk-2G67QRNU.mjs +2096 -0
  8. package/dist/chunk-2G67QRNU.mjs.map +1 -0
  9. package/dist/chunk-32SRQGAC.mjs +2109 -0
  10. package/dist/chunk-32SRQGAC.mjs.map +1 -0
  11. package/dist/chunk-4BPRCONN.mjs +2098 -0
  12. package/dist/chunk-4BPRCONN.mjs.map +1 -0
  13. package/dist/chunk-5UZ2Z323.mjs +2021 -0
  14. package/dist/chunk-5UZ2Z323.mjs.map +1 -0
  15. package/dist/chunk-7KFTJXNM.mjs +2097 -0
  16. package/dist/chunk-7KFTJXNM.mjs.map +1 -0
  17. package/dist/chunk-BK4K5CVT.mjs +2019 -0
  18. package/dist/chunk-BK4K5CVT.mjs.map +1 -0
  19. package/dist/chunk-JLPJZ6WB.mjs +2020 -0
  20. package/dist/chunk-JLPJZ6WB.mjs.map +1 -0
  21. package/dist/chunk-TVU6PYJH.mjs +2032 -0
  22. package/dist/chunk-TVU6PYJH.mjs.map +1 -0
  23. package/dist/clients.cjs +2210 -1847
  24. package/dist/clients.cjs.map +1 -1
  25. package/dist/clients.d.cts +23 -0
  26. package/dist/clients.d.ts +23 -0
  27. package/dist/clients.mjs +14 -1845
  28. package/dist/clients.mjs.map +1 -1
  29. package/dist/hooks.cjs +1776 -962
  30. package/dist/hooks.cjs.map +1 -1
  31. package/dist/hooks.mjs +4 -1375
  32. package/dist/hooks.mjs.map +1 -1
  33. package/dist/index.cjs +2245 -1877
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +81 -4
  36. package/dist/index.d.ts +81 -4
  37. package/dist/index.mjs +20 -1860
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/sdk.gen-2SQOPTWJ.mjs +26 -0
  40. package/dist/sdk.gen-2SQOPTWJ.mjs.map +1 -0
  41. package/dist/sdk.gen-HSGK4C5S.mjs +26 -0
  42. package/dist/sdk.gen-HSGK4C5S.mjs.map +1 -0
  43. package/dist/sdk.gen-NUK2VGHO.mjs +25 -0
  44. package/dist/sdk.gen-NUK2VGHO.mjs.map +1 -0
  45. package/dist/sdk.gen-O4KAQUZB.mjs +26 -0
  46. package/dist/sdk.gen-O4KAQUZB.mjs.map +1 -0
  47. package/dist/sdk.gen-PPAVSBNT.mjs +26 -0
  48. package/dist/sdk.gen-PPAVSBNT.mjs.map +1 -0
  49. package/dist/sdk.gen-XLHLOCJ2.mjs +25 -0
  50. package/dist/sdk.gen-XLHLOCJ2.mjs.map +1 -0
  51. package/dist/sdk.gen-ZOE6NQAL.mjs +26 -0
  52. package/dist/sdk.gen-ZOE6NQAL.mjs.map +1 -0
  53. package/dist/sdk.gen-ZT7LGJVO.mjs +26 -0
  54. package/dist/sdk.gen-ZT7LGJVO.mjs.map +1 -0
  55. package/package.json +2 -2
  56. package/src/_api/generated/_cfg_accounts/hooks/index.ts +1 -0
  57. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenBlacklistCreate.ts +28 -0
  58. package/src/_api/generated/_cfg_accounts/openapi.json +99 -0
  59. package/src/_api/generated/_cfg_accounts/schemas/TokenBlacklistRequest.ts +11 -0
  60. package/src/_api/generated/_cfg_accounts/schemas/index.ts +1 -0
  61. package/src/_api/generated/_cfg_centrifugo/openapi.json +9 -0
  62. package/src/_api/generated/_cfg_totp/openapi.json +33 -0
  63. package/src/_api/generated/helpers/auth.ts +276 -31
  64. package/src/_api/generated/openapi.json +129 -0
  65. package/src/_api/generated/sdk.gen.ts +94 -16
  66. package/src/_api/generated/types.gen.ts +18 -0
  67. package/src/auth/__tests__/guard.test.ts +0 -31
  68. package/src/auth/constants.ts +6 -0
  69. package/src/auth/context/AccountsContext.tsx +14 -24
  70. package/src/auth/context/AuthContext.tsx +226 -609
  71. package/src/auth/hooks/index.ts +3 -4
  72. package/src/auth/hooks/useGithubAuth.ts +3 -3
  73. package/src/auth/hooks/useSession.ts +22 -0
  74. package/src/auth/hooks/useTwoFactor.ts +4 -4
  75. package/src/auth/middlewares/index.ts +5 -6
  76. package/src/auth/utils/guard.ts +0 -22
  77. package/src/auth/utils/index.ts +0 -2
  78. package/src/_api/generated/_cfg_accounts/events.ts +0 -198
  79. package/src/_api/generated/_cfg_centrifugo/events.ts +0 -198
  80. package/src/_api/generated/_cfg_totp/events.ts +0 -198
  81. package/src/auth/__tests__/jwt.test.ts +0 -119
  82. package/src/auth/__tests__/sessionBootstrap.test.ts +0 -111
  83. package/src/auth/__tests__/useTokenRefresh.dom.test.tsx +0 -167
  84. package/src/auth/hooks/useAuthGuard.ts +0 -35
  85. package/src/auth/hooks/useTokenRefresh.ts +0 -131
  86. package/src/auth/refreshHandler.ts +0 -79
  87. package/src/auth/utils/jwt.ts +0 -66
package/dist/clients.mjs CHANGED
@@ -1,485 +1,18 @@
1
1
  "use client";
2
- var __defProp = Object.defineProperty;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
-
5
- // src/_api/generated/helpers/errors.ts
6
- var APIError = class extends Error {
7
- constructor(statusCode, statusText, response, url, message) {
8
- super(message || `HTTP ${statusCode}: ${statusText}`);
9
- this.statusCode = statusCode;
10
- this.statusText = statusText;
11
- this.response = response;
12
- this.url = url;
13
- this.name = "APIError";
14
- }
15
- static {
16
- __name(this, "APIError");
17
- }
18
- get details() {
19
- if (typeof this.response === "object" && this.response !== null) {
20
- return this.response;
21
- }
22
- return null;
23
- }
24
- get fieldErrors() {
25
- const details = this.details;
26
- if (!details) return null;
27
- const fieldErrors = {};
28
- for (const [key, value] of Object.entries(details)) {
29
- if (Array.isArray(value)) fieldErrors[key] = value;
30
- }
31
- return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
32
- }
33
- get errorMessage() {
34
- const details = this.details;
35
- if (!details) return this.message;
36
- if (details.detail) {
37
- return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
38
- }
39
- if (details.error) return String(details.error);
40
- if (details.message) return String(details.message);
41
- const fieldErrors = this.fieldErrors;
42
- if (fieldErrors) {
43
- const firstField = Object.keys(fieldErrors)[0];
44
- if (firstField) return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
45
- }
46
- return this.message;
47
- }
48
- get isValidationError() {
49
- return this.statusCode === 400;
50
- }
51
- get isAuthError() {
52
- return this.statusCode === 401;
53
- }
54
- get isPermissionError() {
55
- return this.statusCode === 403;
56
- }
57
- get isNotFoundError() {
58
- return this.statusCode === 404;
59
- }
60
- get isServerError() {
61
- return this.statusCode >= 500 && this.statusCode < 600;
62
- }
63
- };
64
-
65
- // src/_api/generated/helpers/auth.ts
66
- var ACCESS_KEY = "cfg.access_token";
67
- var REFRESH_KEY = "cfg.refresh_token";
68
- var API_KEY_KEY = "cfg.api_key";
69
- var isBrowser = typeof window !== "undefined";
70
- var localStorageBackend = {
71
- get(key) {
72
- if (!isBrowser) return null;
73
- try {
74
- return window.localStorage.getItem(key);
75
- } catch {
76
- return null;
77
- }
78
- },
79
- set(key, value) {
80
- if (!isBrowser) return;
81
- try {
82
- if (value === null) window.localStorage.removeItem(key);
83
- else window.localStorage.setItem(key, value);
84
- } catch {
85
- }
86
- }
87
- };
88
- var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
89
- var cookieBackend = {
90
- get(key) {
91
- if (!isBrowser) return null;
92
- try {
93
- const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
94
- const m = document.cookie.match(re);
95
- return m ? decodeURIComponent(m[1]) : null;
96
- } catch {
97
- return null;
98
- }
99
- },
100
- set(key, value) {
101
- if (!isBrowser) return;
102
- try {
103
- const k = encodeURIComponent(key);
104
- const secure = window.location.protocol === "https:" ? "; Secure" : "";
105
- if (value === null) {
106
- document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
107
- } else {
108
- const v = encodeURIComponent(value);
109
- document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax${secure}`;
110
- }
111
- } catch {
112
- }
113
- }
114
- };
115
- var _storage = localStorageBackend;
116
- var _storageMode = "localStorage";
117
- function detectLocale() {
118
- try {
119
- if (typeof document !== "undefined") {
120
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
121
- if (m) return decodeURIComponent(m[1]);
122
- }
123
- if (typeof navigator !== "undefined" && navigator.language) {
124
- return navigator.language;
125
- }
126
- } catch {
127
- }
128
- return null;
129
- }
130
- __name(detectLocale, "detectLocale");
131
- function defaultBaseUrl() {
132
- if (typeof window !== "undefined") {
133
- try {
134
- if (typeof process !== "undefined" && process.env) {
135
- if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
136
- if (process.env.NEXT_PUBLIC_API_PROXY_URL !== void 0)
137
- return process.env.NEXT_PUBLIC_API_PROXY_URL;
138
- return process.env.NEXT_PUBLIC_API_URL || "";
139
- }
140
- } catch {
141
- }
142
- return "";
143
- }
144
- try {
145
- if (typeof process !== "undefined" && process.env) {
146
- if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
147
- return process.env.NEXT_PUBLIC_API_URL || "";
148
- }
149
- } catch {
150
- }
151
- return "";
152
- }
153
- __name(defaultBaseUrl, "defaultBaseUrl");
154
- function defaultApiKey() {
155
- try {
156
- if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
157
- return process.env.NEXT_PUBLIC_API_KEY;
158
- }
159
- } catch {
160
- }
161
- return null;
162
- }
163
- __name(defaultApiKey, "defaultApiKey");
164
- var _localeOverride = null;
165
- var _apiKeyOverride = null;
166
- var _baseUrlOverride = null;
167
- var _withCredentials = true;
168
- var _onUnauthorized = null;
169
- var _refreshHandler = null;
170
- var _refreshInflight = null;
171
- var RETRY_MARKER = "X-Auth-Retry";
172
- var _client = null;
173
- function pushClientConfig() {
174
- if (!_client) return;
175
- _client.setConfig({
176
- baseUrl: auth.getBaseUrl(),
177
- credentials: _withCredentials ? "include" : "same-origin"
178
- });
179
- }
180
- __name(pushClientConfig, "pushClientConfig");
181
- var auth = {
182
- // ── Storage mode ──────────────────────────────────────────────────
183
- getStorageMode() {
184
- return _storageMode;
185
- },
186
- setStorageMode(mode) {
187
- _storageMode = mode;
188
- _storage = mode === "cookie" ? cookieBackend : localStorageBackend;
189
- },
190
- // ── Bearer token ──────────────────────────────────────────────────
191
- getToken() {
192
- return _storage.get(ACCESS_KEY);
193
- },
194
- setToken(token) {
195
- _storage.set(ACCESS_KEY, token);
196
- },
197
- getRefreshToken() {
198
- return _storage.get(REFRESH_KEY);
199
- },
200
- setRefreshToken(token) {
201
- _storage.set(REFRESH_KEY, token);
202
- },
203
- clearTokens() {
204
- _storage.set(ACCESS_KEY, null);
205
- _storage.set(REFRESH_KEY, null);
206
- },
207
- isAuthenticated() {
208
- return _storage.get(ACCESS_KEY) !== null;
209
- },
210
- // ── API key ───────────────────────────────────────────────────────
211
- getApiKey() {
212
- return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
213
- },
214
- setApiKey(key) {
215
- _apiKeyOverride = key;
216
- },
217
- setApiKeyPersist(key) {
218
- _apiKeyOverride = key;
219
- _storage.set(API_KEY_KEY, key);
220
- },
221
- clearApiKey() {
222
- _apiKeyOverride = null;
223
- _storage.set(API_KEY_KEY, null);
224
- },
225
- // ── Locale ────────────────────────────────────────────────────────
226
- getLocale() {
227
- return _localeOverride ?? detectLocale();
228
- },
229
- setLocale(locale) {
230
- _localeOverride = locale;
231
- },
232
- // ── Base URL ──────────────────────────────────────────────────────
233
- getBaseUrl() {
234
- const url = _baseUrlOverride ?? defaultBaseUrl();
235
- return url.replace(/\/$/, "");
236
- },
237
- setBaseUrl(url) {
238
- _baseUrlOverride = url ? url.replace(/\/$/, "") : null;
239
- pushClientConfig();
240
- },
241
- // ── Credentials toggle ────────────────────────────────────────────
242
- getWithCredentials() {
243
- return _withCredentials;
244
- },
245
- setWithCredentials(value) {
246
- _withCredentials = value;
247
- pushClientConfig();
248
- },
249
- // ── 401 handler ───────────────────────────────────────────────────
250
- /**
251
- * Fired when the server returns 401 AND no refresh path recovers it
252
- * (no refresh token, no refresh handler, refresh failed, or retry
253
- * still 401). The app should clear local state and redirect to login.
254
- *
255
- * NOT fired for 401 that gets transparently recovered by the refresh
256
- * handler — those are invisible to callers.
257
- */
258
- onUnauthorized(cb) {
259
- _onUnauthorized = cb;
260
- },
261
- /**
262
- * Register the refresh strategy. The handler receives the current
263
- * refresh token and must call your refresh endpoint, returning
264
- * `{ access, refresh? }` on success or `null` on failure.
265
- *
266
- * @example
267
- * auth.setRefreshHandler(async (refresh) => {
268
- * const { data } = await Auth.tokenRefreshCreate({ body: { refresh } });
269
- * return data ? { access: data.access, refresh: data.refresh } : null;
270
- * });
271
- */
272
- setRefreshHandler(fn) {
273
- _refreshHandler = fn;
274
- },
275
- /**
276
- * Proactively run the registered refresh handler right now, reusing the
277
- * SAME single-flight promise as the 401-recovery interceptor. Callers
278
- * (e.g. an expiry timer / focus / reconnect) get token rotation,
279
- * de-duplication and rotated-token persistence for free — they must NOT
280
- * re-implement any of it. Returns the fresh access token, or null if
281
- * there is no handler / no refresh token / the refresh failed.
282
- */
283
- refreshNow() {
284
- return tryRefresh();
285
- }
286
- };
287
- async function tryRefresh() {
288
- if (_refreshInflight) return _refreshInflight;
289
- if (!_refreshHandler) return null;
290
- const refresh = auth.getRefreshToken();
291
- if (!refresh) return null;
292
- _refreshInflight = (async () => {
293
- try {
294
- const result = await _refreshHandler(refresh);
295
- if (!result?.access) return null;
296
- auth.setToken(result.access);
297
- if (result.refresh) auth.setRefreshToken(result.refresh);
298
- return result.access;
299
- } catch {
300
- return null;
301
- } finally {
302
- _refreshInflight = null;
303
- }
304
- })();
305
- return _refreshInflight;
306
- }
307
- __name(tryRefresh, "tryRefresh");
308
- function dpopEnabled() {
309
- try {
310
- return typeof process !== "undefined" && process.env?.NEXT_PUBLIC_DPOP_ENABLED === "true";
311
- } catch {
312
- return false;
313
- }
314
- }
315
- __name(dpopEnabled, "dpopEnabled");
316
- var _DPOP_DB = "cfg-auth";
317
- var _DPOP_STORE = "keys";
318
- var _DPOP_KEY_ID = "dpop-ec-p256";
319
- function _idbOpen() {
320
- return new Promise((resolve, reject) => {
321
- const req = indexedDB.open(_DPOP_DB, 1);
322
- req.onupgradeneeded = () => req.result.createObjectStore(_DPOP_STORE);
323
- req.onsuccess = () => resolve(req.result);
324
- req.onerror = () => reject(req.error);
325
- });
326
- }
327
- __name(_idbOpen, "_idbOpen");
328
- function _idbGet(key) {
329
- return _idbOpen().then((db) => new Promise((resolve, reject) => {
330
- const tx = db.transaction(_DPOP_STORE, "readonly");
331
- const req = tx.objectStore(_DPOP_STORE).get(key);
332
- req.onsuccess = () => resolve(req.result);
333
- req.onerror = () => reject(req.error);
334
- }));
335
- }
336
- __name(_idbGet, "_idbGet");
337
- function _idbPut(key, value) {
338
- return _idbOpen().then((db) => new Promise((resolve, reject) => {
339
- const tx = db.transaction(_DPOP_STORE, "readwrite");
340
- tx.objectStore(_DPOP_STORE).put(value, key);
341
- tx.oncomplete = () => resolve();
342
- tx.onerror = () => reject(tx.error);
343
- }));
344
- }
345
- __name(_idbPut, "_idbPut");
346
- var _dpopKeyPromise = null;
347
- function _getDpopKeyPair() {
348
- if (_dpopKeyPromise) return _dpopKeyPromise;
349
- _dpopKeyPromise = (async () => {
350
- const existing = await _idbGet(_DPOP_KEY_ID).catch(() => void 0);
351
- if (existing) return existing;
352
- const pair = await crypto.subtle.generateKey(
353
- { name: "ECDSA", namedCurve: "P-256" },
354
- false,
355
- // extractable:false — JS can sign but never export the private key
356
- ["sign"]
357
- );
358
- await _idbPut(_DPOP_KEY_ID, pair).catch(() => {
359
- });
360
- return pair;
361
- })();
362
- return _dpopKeyPromise;
363
- }
364
- __name(_getDpopKeyPair, "_getDpopKeyPair");
365
- function _b64urlFromBytes(bytes) {
366
- const arr = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
367
- let s = "";
368
- for (let i = 0; i < arr.length; i++) s += String.fromCharCode(arr[i]);
369
- return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
370
- }
371
- __name(_b64urlFromBytes, "_b64urlFromBytes");
372
- function _b64urlFromString(str) {
373
- return _b64urlFromBytes(new TextEncoder().encode(str));
374
- }
375
- __name(_b64urlFromString, "_b64urlFromString");
376
- async function _publicJwk(pub) {
377
- const jwk = await crypto.subtle.exportKey("jwk", pub);
378
- return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y };
379
- }
380
- __name(_publicJwk, "_publicJwk");
381
- async function _makeDpopProof(method, url) {
382
- try {
383
- const pair = await _getDpopKeyPair();
384
- const jwk = await _publicJwk(pair.publicKey);
385
- const header = { typ: "dpop+jwt", alg: "ES256", jwk };
386
- const htu = url.split("#")[0].split("?")[0];
387
- const jti = crypto.randomUUID && crypto.randomUUID() || _b64urlFromBytes(crypto.getRandomValues(new Uint8Array(16)));
388
- const payload = { htm: method.toUpperCase(), htu, iat: Math.floor(Date.now() / 1e3), jti };
389
- const signingInput = `${_b64urlFromString(JSON.stringify(header))}.${_b64urlFromString(JSON.stringify(payload))}`;
390
- const sig = await crypto.subtle.sign(
391
- { name: "ECDSA", hash: "SHA-256" },
392
- pair.privateKey,
393
- new TextEncoder().encode(signingInput)
394
- );
395
- return `${signingInput}.${_b64urlFromBytes(sig)}`;
396
- } catch {
397
- return null;
398
- }
399
- }
400
- __name(_makeDpopProof, "_makeDpopProof");
401
- function installAuthOnClient(client2) {
402
- if (_client) return;
403
- _client = client2;
404
- client2.setConfig({
405
- baseUrl: auth.getBaseUrl(),
406
- credentials: _withCredentials ? "include" : "same-origin"
407
- });
408
- client2.interceptors.request.use(async (request) => {
409
- const token = auth.getToken();
410
- if (token) request.headers.set("Authorization", `Bearer ${token}`);
411
- const locale = auth.getLocale();
412
- if (locale) request.headers.set("Accept-Language", locale);
413
- const apiKey = auth.getApiKey();
414
- if (apiKey && !request.headers.has("X-API-Key")) request.headers.set("X-API-Key", apiKey);
415
- try {
416
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
417
- if (tz) request.headers.set("X-Timezone", tz);
418
- } catch {
419
- }
420
- request.headers.set("X-Client-Time", (/* @__PURE__ */ new Date()).toISOString());
421
- if (dpopEnabled() && typeof window !== "undefined") {
422
- const proof = await _makeDpopProof(request.method, request.url);
423
- if (proof) request.headers.set("DPoP", proof);
424
- }
425
- return request;
426
- });
427
- client2.interceptors.error.use((err, res, req) => {
428
- if (err instanceof APIError) return err;
429
- const url = req?.url ?? "";
430
- const status = res?.status ?? 0;
431
- const statusText = res?.statusText ?? "";
432
- return new APIError(status, statusText, err, url);
433
- });
434
- client2.interceptors.response.use(async (response, request) => {
435
- if (response.status !== 401) return response;
436
- if (request.headers.get(RETRY_MARKER)) {
437
- if (_onUnauthorized) {
438
- try {
439
- _onUnauthorized(response);
440
- } catch {
441
- }
442
- }
443
- return response;
444
- }
445
- const newToken = await tryRefresh();
446
- if (!newToken) {
447
- if (_onUnauthorized) {
448
- try {
449
- _onUnauthorized(response);
450
- } catch {
451
- }
452
- }
453
- return response;
454
- }
455
- const retry = request.clone();
456
- retry.headers.set("Authorization", `Bearer ${newToken}`);
457
- retry.headers.set(RETRY_MARKER, "1");
458
- if (dpopEnabled() && typeof window !== "undefined") {
459
- const proof = await _makeDpopProof(retry.method, retry.url);
460
- if (proof) retry.headers.set("DPoP", proof);
461
- }
462
- try {
463
- const retried = await fetch(retry);
464
- if (retried.status === 401 && _onUnauthorized) {
465
- try {
466
- _onUnauthorized(retried);
467
- } catch {
468
- }
469
- }
470
- return retried;
471
- } catch {
472
- if (_onUnauthorized) {
473
- try {
474
- _onUnauthorized(response);
475
- } catch {
476
- }
477
- }
478
- return response;
479
- }
480
- });
481
- }
482
- __name(installAuthOnClient, "installAuthOnClient");
2
+ import {
3
+ CfgAccounts,
4
+ CfgAccountsApiKey,
5
+ CfgAccountsAuth,
6
+ CfgAccountsOauth,
7
+ CfgAccountsProfile,
8
+ CfgCentrifugo,
9
+ CfgTotp,
10
+ CfgTotpBackupCodes,
11
+ CfgTotpSetup,
12
+ CfgTotpVerify,
13
+ __name,
14
+ auth
15
+ } from "./chunk-7KFTJXNM.mjs";
483
16
 
484
17
  // src/_api/generated/helpers/logger.ts
485
18
  import { createConsola } from "consola";
@@ -575,1370 +108,6 @@ var APILogger = class {
575
108
  };
576
109
  var defaultLogger = new APILogger();
577
110
 
578
- // src/_api/generated/core/bodySerializer.gen.ts
579
- var serializeFormDataPair = /* @__PURE__ */ __name((data, key, value) => {
580
- if (typeof value === "string" || value instanceof Blob) {
581
- data.append(key, value);
582
- } else if (value instanceof Date) {
583
- data.append(key, value.toISOString());
584
- } else {
585
- data.append(key, JSON.stringify(value));
586
- }
587
- }, "serializeFormDataPair");
588
- var formDataBodySerializer = {
589
- bodySerializer: /* @__PURE__ */ __name((body) => {
590
- const data = new FormData();
591
- Object.entries(body).forEach(([key, value]) => {
592
- if (value === void 0 || value === null) {
593
- return;
594
- }
595
- if (Array.isArray(value)) {
596
- value.forEach((v) => serializeFormDataPair(data, key, v));
597
- } else {
598
- serializeFormDataPair(data, key, value);
599
- }
600
- });
601
- return data;
602
- }, "bodySerializer")
603
- };
604
- var jsonBodySerializer = {
605
- bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
606
- };
607
-
608
- // src/_api/generated/core/params.gen.ts
609
- var extraPrefixesMap = {
610
- $body_: "body",
611
- $headers_: "headers",
612
- $path_: "path",
613
- $query_: "query"
614
- };
615
- var extraPrefixes = Object.entries(extraPrefixesMap);
616
-
617
- // src/_api/generated/core/serverSentEvents.gen.ts
618
- function createSseClient({
619
- onRequest,
620
- onSseError,
621
- onSseEvent,
622
- responseTransformer,
623
- responseValidator,
624
- sseDefaultRetryDelay,
625
- sseMaxRetryAttempts,
626
- sseMaxRetryDelay,
627
- sseSleepFn,
628
- url,
629
- ...options
630
- }) {
631
- let lastEventId;
632
- const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
633
- const createStream = /* @__PURE__ */ __name(async function* () {
634
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
635
- let attempt = 0;
636
- const signal = options.signal ?? new AbortController().signal;
637
- while (true) {
638
- if (signal.aborted) break;
639
- attempt++;
640
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
641
- if (lastEventId !== void 0) {
642
- headers.set("Last-Event-ID", lastEventId);
643
- }
644
- try {
645
- const requestInit = {
646
- redirect: "follow",
647
- ...options,
648
- body: options.serializedBody,
649
- headers,
650
- signal
651
- };
652
- let request = new Request(url, requestInit);
653
- if (onRequest) {
654
- request = await onRequest(url, requestInit);
655
- }
656
- const _fetch = options.fetch ?? globalThis.fetch;
657
- const response = await _fetch(request);
658
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
659
- if (!response.body) throw new Error("No body in SSE response");
660
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
661
- let buffer = "";
662
- const abortHandler = /* @__PURE__ */ __name(() => {
663
- try {
664
- reader.cancel();
665
- } catch {
666
- }
667
- }, "abortHandler");
668
- signal.addEventListener("abort", abortHandler);
669
- try {
670
- while (true) {
671
- const { done, value } = await reader.read();
672
- if (done) break;
673
- buffer += value;
674
- buffer = buffer.replace(/\r\n?/g, "\n");
675
- const chunks = buffer.split("\n\n");
676
- buffer = chunks.pop() ?? "";
677
- for (const chunk of chunks) {
678
- const lines = chunk.split("\n");
679
- const dataLines = [];
680
- let eventName;
681
- for (const line of lines) {
682
- if (line.startsWith("data:")) {
683
- dataLines.push(line.replace(/^data:\s*/, ""));
684
- } else if (line.startsWith("event:")) {
685
- eventName = line.replace(/^event:\s*/, "");
686
- } else if (line.startsWith("id:")) {
687
- lastEventId = line.replace(/^id:\s*/, "");
688
- } else if (line.startsWith("retry:")) {
689
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
690
- if (!Number.isNaN(parsed)) {
691
- retryDelay = parsed;
692
- }
693
- }
694
- }
695
- let data;
696
- let parsedJson = false;
697
- if (dataLines.length) {
698
- const rawData = dataLines.join("\n");
699
- try {
700
- data = JSON.parse(rawData);
701
- parsedJson = true;
702
- } catch {
703
- data = rawData;
704
- }
705
- }
706
- if (parsedJson) {
707
- if (responseValidator) {
708
- await responseValidator(data);
709
- }
710
- if (responseTransformer) {
711
- data = await responseTransformer(data);
712
- }
713
- }
714
- onSseEvent?.({
715
- data,
716
- event: eventName,
717
- id: lastEventId,
718
- retry: retryDelay
719
- });
720
- if (dataLines.length) {
721
- yield data;
722
- }
723
- }
724
- }
725
- } finally {
726
- signal.removeEventListener("abort", abortHandler);
727
- reader.releaseLock();
728
- }
729
- break;
730
- } catch (error) {
731
- onSseError?.(error);
732
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
733
- break;
734
- }
735
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
736
- await sleep(backoff);
737
- }
738
- }
739
- }, "createStream");
740
- const stream = createStream();
741
- return { stream };
742
- }
743
- __name(createSseClient, "createSseClient");
744
-
745
- // src/_api/generated/core/pathSerializer.gen.ts
746
- var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
747
- switch (style) {
748
- case "label":
749
- return ".";
750
- case "matrix":
751
- return ";";
752
- case "simple":
753
- return ",";
754
- default:
755
- return "&";
756
- }
757
- }, "separatorArrayExplode");
758
- var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
759
- switch (style) {
760
- case "form":
761
- return ",";
762
- case "pipeDelimited":
763
- return "|";
764
- case "spaceDelimited":
765
- return "%20";
766
- default:
767
- return ",";
768
- }
769
- }, "separatorArrayNoExplode");
770
- var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
771
- switch (style) {
772
- case "label":
773
- return ".";
774
- case "matrix":
775
- return ";";
776
- case "simple":
777
- return ",";
778
- default:
779
- return "&";
780
- }
781
- }, "separatorObjectExplode");
782
- var serializeArrayParam = /* @__PURE__ */ __name(({
783
- allowReserved,
784
- explode,
785
- name,
786
- style,
787
- value
788
- }) => {
789
- if (!explode) {
790
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
791
- switch (style) {
792
- case "label":
793
- return `.${joinedValues2}`;
794
- case "matrix":
795
- return `;${name}=${joinedValues2}`;
796
- case "simple":
797
- return joinedValues2;
798
- default:
799
- return `${name}=${joinedValues2}`;
800
- }
801
- }
802
- const separator = separatorArrayExplode(style);
803
- const joinedValues = value.map((v) => {
804
- if (style === "label" || style === "simple") {
805
- return allowReserved ? v : encodeURIComponent(v);
806
- }
807
- return serializePrimitiveParam({
808
- allowReserved,
809
- name,
810
- value: v
811
- });
812
- }).join(separator);
813
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
814
- }, "serializeArrayParam");
815
- var serializePrimitiveParam = /* @__PURE__ */ __name(({
816
- allowReserved,
817
- name,
818
- value
819
- }) => {
820
- if (value === void 0 || value === null) {
821
- return "";
822
- }
823
- if (typeof value === "object") {
824
- throw new Error(
825
- "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
826
- );
827
- }
828
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
829
- }, "serializePrimitiveParam");
830
- var serializeObjectParam = /* @__PURE__ */ __name(({
831
- allowReserved,
832
- explode,
833
- name,
834
- style,
835
- value,
836
- valueOnly
837
- }) => {
838
- if (value instanceof Date) {
839
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
840
- }
841
- if (style !== "deepObject" && !explode) {
842
- let values = [];
843
- Object.entries(value).forEach(([key, v]) => {
844
- values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
845
- });
846
- const joinedValues2 = values.join(",");
847
- switch (style) {
848
- case "form":
849
- return `${name}=${joinedValues2}`;
850
- case "label":
851
- return `.${joinedValues2}`;
852
- case "matrix":
853
- return `;${name}=${joinedValues2}`;
854
- default:
855
- return joinedValues2;
856
- }
857
- }
858
- const separator = separatorObjectExplode(style);
859
- const joinedValues = Object.entries(value).map(
860
- ([key, v]) => serializePrimitiveParam({
861
- allowReserved,
862
- name: style === "deepObject" ? `${name}[${key}]` : key,
863
- value: v
864
- })
865
- ).join(separator);
866
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
867
- }, "serializeObjectParam");
868
-
869
- // src/_api/generated/core/utils.gen.ts
870
- var PATH_PARAM_RE = /\{[^{}]+\}/g;
871
- var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
872
- let url = _url;
873
- const matches = _url.match(PATH_PARAM_RE);
874
- if (matches) {
875
- for (const match of matches) {
876
- let explode = false;
877
- let name = match.substring(1, match.length - 1);
878
- let style = "simple";
879
- if (name.endsWith("*")) {
880
- explode = true;
881
- name = name.substring(0, name.length - 1);
882
- }
883
- if (name.startsWith(".")) {
884
- name = name.substring(1);
885
- style = "label";
886
- } else if (name.startsWith(";")) {
887
- name = name.substring(1);
888
- style = "matrix";
889
- }
890
- const value = path[name];
891
- if (value === void 0 || value === null) {
892
- continue;
893
- }
894
- if (Array.isArray(value)) {
895
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
896
- continue;
897
- }
898
- if (typeof value === "object") {
899
- url = url.replace(
900
- match,
901
- serializeObjectParam({
902
- explode,
903
- name,
904
- style,
905
- value,
906
- valueOnly: true
907
- })
908
- );
909
- continue;
910
- }
911
- if (style === "matrix") {
912
- url = url.replace(
913
- match,
914
- `;${serializePrimitiveParam({
915
- name,
916
- value
917
- })}`
918
- );
919
- continue;
920
- }
921
- const replaceValue = encodeURIComponent(
922
- style === "label" ? `.${value}` : value
923
- );
924
- url = url.replace(match, replaceValue);
925
- }
926
- }
927
- return url;
928
- }, "defaultPathSerializer");
929
- var getUrl = /* @__PURE__ */ __name(({
930
- baseUrl,
931
- path,
932
- query,
933
- querySerializer,
934
- url: _url
935
- }) => {
936
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
937
- let url = (baseUrl ?? "") + pathUrl;
938
- if (path) {
939
- url = defaultPathSerializer({ path, url });
940
- }
941
- let search = query ? querySerializer(query) : "";
942
- if (search.startsWith("?")) {
943
- search = search.substring(1);
944
- }
945
- if (search) {
946
- url += `?${search}`;
947
- }
948
- return url;
949
- }, "getUrl");
950
- function getValidRequestBody(options) {
951
- const hasBody = options.body !== void 0;
952
- const isSerializedBody = hasBody && options.bodySerializer;
953
- if (isSerializedBody) {
954
- if ("serializedBody" in options) {
955
- const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
956
- return hasSerializedBody ? options.serializedBody : null;
957
- }
958
- return options.body !== "" ? options.body : null;
959
- }
960
- if (hasBody) {
961
- return options.body;
962
- }
963
- return void 0;
964
- }
965
- __name(getValidRequestBody, "getValidRequestBody");
966
-
967
- // src/_api/generated/core/auth.gen.ts
968
- var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
969
- const token = typeof callback === "function" ? await callback(auth2) : callback;
970
- if (!token) {
971
- return;
972
- }
973
- if (auth2.scheme === "bearer") {
974
- return `Bearer ${token}`;
975
- }
976
- if (auth2.scheme === "basic") {
977
- return `Basic ${btoa(token)}`;
978
- }
979
- return token;
980
- }, "getAuthToken");
981
-
982
- // src/_api/generated/client/utils.gen.ts
983
- var createQuerySerializer = /* @__PURE__ */ __name(({
984
- parameters = {},
985
- ...args
986
- } = {}) => {
987
- const querySerializer = /* @__PURE__ */ __name((queryParams) => {
988
- const search = [];
989
- if (queryParams && typeof queryParams === "object") {
990
- for (const name in queryParams) {
991
- const value = queryParams[name];
992
- if (value === void 0 || value === null) {
993
- continue;
994
- }
995
- const options = parameters[name] || args;
996
- if (Array.isArray(value)) {
997
- const serializedArray = serializeArrayParam({
998
- allowReserved: options.allowReserved,
999
- explode: true,
1000
- name,
1001
- style: "form",
1002
- value,
1003
- ...options.array
1004
- });
1005
- if (serializedArray) search.push(serializedArray);
1006
- } else if (typeof value === "object") {
1007
- const serializedObject = serializeObjectParam({
1008
- allowReserved: options.allowReserved,
1009
- explode: true,
1010
- name,
1011
- style: "deepObject",
1012
- value,
1013
- ...options.object
1014
- });
1015
- if (serializedObject) search.push(serializedObject);
1016
- } else {
1017
- const serializedPrimitive = serializePrimitiveParam({
1018
- allowReserved: options.allowReserved,
1019
- name,
1020
- value
1021
- });
1022
- if (serializedPrimitive) search.push(serializedPrimitive);
1023
- }
1024
- }
1025
- }
1026
- return search.join("&");
1027
- }, "querySerializer");
1028
- return querySerializer;
1029
- }, "createQuerySerializer");
1030
- var getParseAs = /* @__PURE__ */ __name((contentType) => {
1031
- if (!contentType) {
1032
- return "stream";
1033
- }
1034
- const cleanContent = contentType.split(";")[0]?.trim();
1035
- if (!cleanContent) {
1036
- return;
1037
- }
1038
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
1039
- return "json";
1040
- }
1041
- if (cleanContent === "multipart/form-data") {
1042
- return "formData";
1043
- }
1044
- if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
1045
- return "blob";
1046
- }
1047
- if (cleanContent.startsWith("text/")) {
1048
- return "text";
1049
- }
1050
- return;
1051
- }, "getParseAs");
1052
- var checkForExistence = /* @__PURE__ */ __name((options, name) => {
1053
- if (!name) {
1054
- return false;
1055
- }
1056
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
1057
- return true;
1058
- }
1059
- return false;
1060
- }, "checkForExistence");
1061
- async function setAuthParams(options) {
1062
- for (const auth2 of options.security ?? []) {
1063
- if (checkForExistence(options, auth2.name)) {
1064
- continue;
1065
- }
1066
- const token = await getAuthToken(auth2, options.auth);
1067
- if (!token) {
1068
- continue;
1069
- }
1070
- const name = auth2.name ?? "Authorization";
1071
- switch (auth2.in) {
1072
- case "query":
1073
- if (!options.query) {
1074
- options.query = {};
1075
- }
1076
- options.query[name] = token;
1077
- break;
1078
- case "cookie":
1079
- options.headers.append("Cookie", `${name}=${token}`);
1080
- break;
1081
- case "header":
1082
- default:
1083
- options.headers.set(name, token);
1084
- break;
1085
- }
1086
- }
1087
- }
1088
- __name(setAuthParams, "setAuthParams");
1089
- var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
1090
- baseUrl: options.baseUrl,
1091
- path: options.path,
1092
- query: options.query,
1093
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
1094
- url: options.url
1095
- }), "buildUrl");
1096
- var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
1097
- const config = { ...a, ...b };
1098
- if (config.baseUrl?.endsWith("/")) {
1099
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
1100
- }
1101
- config.headers = mergeHeaders(a.headers, b.headers);
1102
- return config;
1103
- }, "mergeConfigs");
1104
- var headersEntries = /* @__PURE__ */ __name((headers) => {
1105
- const entries = [];
1106
- headers.forEach((value, key) => {
1107
- entries.push([key, value]);
1108
- });
1109
- return entries;
1110
- }, "headersEntries");
1111
- var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
1112
- const mergedHeaders = new Headers();
1113
- for (const header of headers) {
1114
- if (!header) {
1115
- continue;
1116
- }
1117
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
1118
- for (const [key, value] of iterator) {
1119
- if (value === null) {
1120
- mergedHeaders.delete(key);
1121
- } else if (Array.isArray(value)) {
1122
- for (const v of value) {
1123
- mergedHeaders.append(key, v);
1124
- }
1125
- } else if (value !== void 0) {
1126
- mergedHeaders.set(
1127
- key,
1128
- typeof value === "object" ? JSON.stringify(value) : value
1129
- );
1130
- }
1131
- }
1132
- }
1133
- return mergedHeaders;
1134
- }, "mergeHeaders");
1135
- var Interceptors = class {
1136
- static {
1137
- __name(this, "Interceptors");
1138
- }
1139
- fns = [];
1140
- clear() {
1141
- this.fns = [];
1142
- }
1143
- eject(id) {
1144
- const index = this.getInterceptorIndex(id);
1145
- if (this.fns[index]) {
1146
- this.fns[index] = null;
1147
- }
1148
- }
1149
- exists(id) {
1150
- const index = this.getInterceptorIndex(id);
1151
- return Boolean(this.fns[index]);
1152
- }
1153
- getInterceptorIndex(id) {
1154
- if (typeof id === "number") {
1155
- return this.fns[id] ? id : -1;
1156
- }
1157
- return this.fns.indexOf(id);
1158
- }
1159
- update(id, fn) {
1160
- const index = this.getInterceptorIndex(id);
1161
- if (this.fns[index]) {
1162
- this.fns[index] = fn;
1163
- return id;
1164
- }
1165
- return false;
1166
- }
1167
- use(fn) {
1168
- this.fns.push(fn);
1169
- return this.fns.length - 1;
1170
- }
1171
- };
1172
- var createInterceptors = /* @__PURE__ */ __name(() => ({
1173
- error: new Interceptors(),
1174
- request: new Interceptors(),
1175
- response: new Interceptors()
1176
- }), "createInterceptors");
1177
- var defaultQuerySerializer = createQuerySerializer({
1178
- allowReserved: false,
1179
- array: {
1180
- explode: true,
1181
- style: "form"
1182
- },
1183
- object: {
1184
- explode: true,
1185
- style: "deepObject"
1186
- }
1187
- });
1188
- var defaultHeaders = {
1189
- "Content-Type": "application/json"
1190
- };
1191
- var createConfig = /* @__PURE__ */ __name((override = {}) => ({
1192
- ...jsonBodySerializer,
1193
- headers: defaultHeaders,
1194
- parseAs: "auto",
1195
- querySerializer: defaultQuerySerializer,
1196
- ...override
1197
- }), "createConfig");
1198
-
1199
- // src/_api/generated/client/client.gen.ts
1200
- var createClient = /* @__PURE__ */ __name((config = {}) => {
1201
- let _config = mergeConfigs(createConfig(), config);
1202
- const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
1203
- const setConfig = /* @__PURE__ */ __name((config2) => {
1204
- _config = mergeConfigs(_config, config2);
1205
- return getConfig();
1206
- }, "setConfig");
1207
- const interceptors = createInterceptors();
1208
- const beforeRequest = /* @__PURE__ */ __name(async (options) => {
1209
- const opts = {
1210
- ..._config,
1211
- ...options,
1212
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
1213
- headers: mergeHeaders(_config.headers, options.headers),
1214
- serializedBody: void 0
1215
- };
1216
- if (opts.security) {
1217
- await setAuthParams(opts);
1218
- }
1219
- if (opts.requestValidator) {
1220
- await opts.requestValidator(opts);
1221
- }
1222
- if (opts.body !== void 0 && opts.bodySerializer) {
1223
- opts.serializedBody = opts.bodySerializer(opts.body);
1224
- }
1225
- if (opts.body === void 0 || opts.serializedBody === "") {
1226
- opts.headers.delete("Content-Type");
1227
- }
1228
- const resolvedOpts = opts;
1229
- const url = buildUrl(resolvedOpts);
1230
- return { opts: resolvedOpts, url };
1231
- }, "beforeRequest");
1232
- const request = /* @__PURE__ */ __name(async (options) => {
1233
- const throwOnError = options.throwOnError ?? _config.throwOnError;
1234
- const responseStyle = options.responseStyle ?? _config.responseStyle;
1235
- let request2;
1236
- let response;
1237
- try {
1238
- const { opts, url } = await beforeRequest(options);
1239
- const requestInit = {
1240
- redirect: "follow",
1241
- ...opts,
1242
- body: getValidRequestBody(opts)
1243
- };
1244
- request2 = new Request(url, requestInit);
1245
- for (const fn of interceptors.request.fns) {
1246
- if (fn) {
1247
- request2 = await fn(request2, opts);
1248
- }
1249
- }
1250
- const _fetch = opts.fetch;
1251
- response = await _fetch(request2);
1252
- for (const fn of interceptors.response.fns) {
1253
- if (fn) {
1254
- response = await fn(response, request2, opts);
1255
- }
1256
- }
1257
- const result = {
1258
- request: request2,
1259
- response
1260
- };
1261
- if (response.ok) {
1262
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
1263
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
1264
- let emptyData;
1265
- switch (parseAs) {
1266
- case "arrayBuffer":
1267
- case "blob":
1268
- case "text":
1269
- emptyData = await response[parseAs]();
1270
- break;
1271
- case "formData":
1272
- emptyData = new FormData();
1273
- break;
1274
- case "stream":
1275
- emptyData = response.body;
1276
- break;
1277
- case "json":
1278
- default:
1279
- emptyData = {};
1280
- break;
1281
- }
1282
- return opts.responseStyle === "data" ? emptyData : {
1283
- data: emptyData,
1284
- ...result
1285
- };
1286
- }
1287
- let data;
1288
- switch (parseAs) {
1289
- case "arrayBuffer":
1290
- case "blob":
1291
- case "formData":
1292
- case "text":
1293
- data = await response[parseAs]();
1294
- break;
1295
- case "json": {
1296
- const text = await response.text();
1297
- data = text ? JSON.parse(text) : {};
1298
- break;
1299
- }
1300
- case "stream":
1301
- return opts.responseStyle === "data" ? response.body : {
1302
- data: response.body,
1303
- ...result
1304
- };
1305
- }
1306
- if (parseAs === "json") {
1307
- if (opts.responseValidator) {
1308
- await opts.responseValidator(data);
1309
- }
1310
- if (opts.responseTransformer) {
1311
- data = await opts.responseTransformer(data);
1312
- }
1313
- }
1314
- return opts.responseStyle === "data" ? data : {
1315
- data,
1316
- ...result
1317
- };
1318
- }
1319
- const textError = await response.text();
1320
- let jsonError;
1321
- try {
1322
- jsonError = JSON.parse(textError);
1323
- } catch {
1324
- }
1325
- throw jsonError ?? textError;
1326
- } catch (error) {
1327
- let finalError = error;
1328
- for (const fn of interceptors.error.fns) {
1329
- if (fn) {
1330
- finalError = await fn(finalError, response, request2, options);
1331
- }
1332
- }
1333
- finalError = finalError || {};
1334
- if (throwOnError) {
1335
- throw finalError;
1336
- }
1337
- return responseStyle === "data" ? void 0 : {
1338
- error: finalError,
1339
- request: request2,
1340
- response
1341
- };
1342
- }
1343
- }, "request");
1344
- const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
1345
- const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
1346
- const { opts, url } = await beforeRequest(options);
1347
- return createSseClient({
1348
- ...opts,
1349
- body: opts.body,
1350
- method,
1351
- onRequest: /* @__PURE__ */ __name(async (url2, init) => {
1352
- let request2 = new Request(url2, init);
1353
- for (const fn of interceptors.request.fns) {
1354
- if (fn) {
1355
- request2 = await fn(request2, opts);
1356
- }
1357
- }
1358
- return request2;
1359
- }, "onRequest"),
1360
- serializedBody: getValidRequestBody(opts),
1361
- url
1362
- });
1363
- }, "makeSseFn");
1364
- const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl({ ..._config, ...options }), "_buildUrl");
1365
- return {
1366
- buildUrl: _buildUrl,
1367
- connect: makeMethodFn("CONNECT"),
1368
- delete: makeMethodFn("DELETE"),
1369
- get: makeMethodFn("GET"),
1370
- getConfig,
1371
- head: makeMethodFn("HEAD"),
1372
- interceptors,
1373
- options: makeMethodFn("OPTIONS"),
1374
- patch: makeMethodFn("PATCH"),
1375
- post: makeMethodFn("POST"),
1376
- put: makeMethodFn("PUT"),
1377
- request,
1378
- setConfig,
1379
- sse: {
1380
- connect: makeSseFn("CONNECT"),
1381
- delete: makeSseFn("DELETE"),
1382
- get: makeSseFn("GET"),
1383
- head: makeSseFn("HEAD"),
1384
- options: makeSseFn("OPTIONS"),
1385
- patch: makeSseFn("PATCH"),
1386
- post: makeSseFn("POST"),
1387
- put: makeSseFn("PUT"),
1388
- trace: makeSseFn("TRACE")
1389
- },
1390
- trace: makeMethodFn("TRACE")
1391
- };
1392
- }, "createClient");
1393
-
1394
- // src/_api/generated/client.gen.ts
1395
- var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
1396
- installAuthOnClient(client);
1397
-
1398
- // src/_api/generated/sdk.gen.ts
1399
- var CfgAccountsApiKey = class {
1400
- static {
1401
- __name(this, "CfgAccountsApiKey");
1402
- }
1403
- /**
1404
- * Get API key details
1405
- *
1406
- * Retrieve the current user's API key (masked) and metadata.
1407
- */
1408
- static cfgAccountsApiKeyRetrieve(options) {
1409
- return (options?.client ?? client).get({
1410
- security: [
1411
- { scheme: "bearer", type: "http" },
1412
- {
1413
- in: "cookie",
1414
- name: "sessionid",
1415
- type: "apiKey"
1416
- },
1417
- { name: "X-API-Key", type: "apiKey" }
1418
- ],
1419
- url: "/cfg/accounts/api-key/",
1420
- ...options
1421
- });
1422
- }
1423
- /**
1424
- * Regenerate API key
1425
- *
1426
- * Generate a new API key. The full key is returned only once.
1427
- */
1428
- static cfgAccountsApiKeyRegenerateCreate(options) {
1429
- return (options.client ?? client).post({
1430
- security: [
1431
- { scheme: "bearer", type: "http" },
1432
- {
1433
- in: "cookie",
1434
- name: "sessionid",
1435
- type: "apiKey"
1436
- },
1437
- { name: "X-API-Key", type: "apiKey" }
1438
- ],
1439
- url: "/cfg/accounts/api-key/regenerate/",
1440
- ...options,
1441
- headers: {
1442
- "Content-Type": "application/json",
1443
- ...options.headers
1444
- }
1445
- });
1446
- }
1447
- /**
1448
- * Reveal API key
1449
- *
1450
- * Return the current full API key WITHOUT rotating it. The same durable value every one of the user's agents uses — for the signed-in user to copy and paste into agent onboarding. Default GET stays masked; this is the explicit reveal action.
1451
- */
1452
- static cfgAccountsApiKeyRevealCreate(options) {
1453
- return (options.client ?? client).post({
1454
- security: [
1455
- { scheme: "bearer", type: "http" },
1456
- {
1457
- in: "cookie",
1458
- name: "sessionid",
1459
- type: "apiKey"
1460
- },
1461
- { name: "X-API-Key", type: "apiKey" }
1462
- ],
1463
- url: "/cfg/accounts/api-key/reveal/",
1464
- ...options,
1465
- headers: {
1466
- "Content-Type": "application/json",
1467
- ...options.headers
1468
- }
1469
- });
1470
- }
1471
- /**
1472
- * Test API key
1473
- *
1474
- * Test whether an API key is valid without consuming it.
1475
- */
1476
- static cfgAccountsApiKeyTestCreate(options) {
1477
- return (options.client ?? client).post({
1478
- security: [
1479
- { scheme: "bearer", type: "http" },
1480
- {
1481
- in: "cookie",
1482
- name: "sessionid",
1483
- type: "apiKey"
1484
- },
1485
- { name: "X-API-Key", type: "apiKey" }
1486
- ],
1487
- url: "/cfg/accounts/api-key/test/",
1488
- ...options,
1489
- headers: {
1490
- "Content-Type": "application/json",
1491
- ...options.headers
1492
- }
1493
- });
1494
- }
1495
- };
1496
- var CfgAccountsOauth = class {
1497
- static {
1498
- __name(this, "CfgAccountsOauth");
1499
- }
1500
- /**
1501
- * List OAuth connections
1502
- *
1503
- * Get all OAuth connections for the current user.
1504
- */
1505
- static cfgAccountsOauthConnectionsList(options) {
1506
- return (options?.client ?? client).get({
1507
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1508
- url: "/cfg/accounts/oauth/connections/",
1509
- ...options
1510
- });
1511
- }
1512
- /**
1513
- * Disconnect OAuth provider
1514
- *
1515
- * Remove OAuth connection for the specified provider.
1516
- */
1517
- static cfgAccountsOauthDisconnectCreate(options) {
1518
- return (options.client ?? client).post({
1519
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1520
- url: "/cfg/accounts/oauth/disconnect/",
1521
- ...options,
1522
- headers: {
1523
- "Content-Type": "application/json",
1524
- ...options.headers
1525
- }
1526
- });
1527
- }
1528
- /**
1529
- * Start GitHub OAuth
1530
- *
1531
- * Generate GitHub OAuth authorization URL. Redirect user to this URL to start authentication.
1532
- */
1533
- static cfgAccountsOauthGithubAuthorizeCreate(options) {
1534
- return (options?.client ?? client).post({
1535
- url: "/cfg/accounts/oauth/github/authorize/",
1536
- ...options,
1537
- headers: {
1538
- "Content-Type": "application/json",
1539
- ...options?.headers
1540
- }
1541
- });
1542
- }
1543
- /**
1544
- * Complete GitHub OAuth
1545
- *
1546
- * Exchange authorization code for JWT tokens. Call this after GitHub redirects back with code.
1547
- */
1548
- static cfgAccountsOauthGithubCallbackCreate(options) {
1549
- return (options.client ?? client).post({
1550
- url: "/cfg/accounts/oauth/github/callback/",
1551
- ...options,
1552
- headers: {
1553
- "Content-Type": "application/json",
1554
- ...options.headers
1555
- }
1556
- });
1557
- }
1558
- /**
1559
- * List OAuth providers
1560
- *
1561
- * Get list of available OAuth providers for authentication.
1562
- */
1563
- static cfgAccountsOauthProvidersRetrieve(options) {
1564
- return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1565
- }
1566
- };
1567
- var CfgAccounts = class {
1568
- static {
1569
- __name(this, "CfgAccounts");
1570
- }
1571
- /**
1572
- * Request OTP code to email.
1573
- */
1574
- static cfgAccountsOtpRequestCreate(options) {
1575
- return (options.client ?? client).post({
1576
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1577
- url: "/cfg/accounts/otp/request/",
1578
- ...options,
1579
- headers: {
1580
- "Content-Type": "application/json",
1581
- ...options.headers
1582
- }
1583
- });
1584
- }
1585
- /**
1586
- * Verify OTP code and return JWT tokens or 2FA session.
1587
- *
1588
- * If user has 2FA enabled:
1589
- * - Returns requires_2fa=True with session_id
1590
- * - Client must complete 2FA verification at /cfg/totp/verify/
1591
- *
1592
- * If user has no 2FA:
1593
- * - Returns JWT tokens and user data directly
1594
- */
1595
- static cfgAccountsOtpVerifyCreate(options) {
1596
- return (options.client ?? client).post({
1597
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1598
- url: "/cfg/accounts/otp/verify/",
1599
- ...options,
1600
- headers: {
1601
- "Content-Type": "application/json",
1602
- ...options.headers
1603
- }
1604
- });
1605
- }
1606
- };
1607
- var CfgAccountsProfile = class {
1608
- static {
1609
- __name(this, "CfgAccountsProfile");
1610
- }
1611
- /**
1612
- * Get current user profile
1613
- *
1614
- * Retrieve the current authenticated user's profile information.
1615
- */
1616
- static cfgAccountsProfileRetrieve(options) {
1617
- return (options?.client ?? client).get({
1618
- security: [{ scheme: "bearer", type: "http" }, {
1619
- in: "cookie",
1620
- name: "sessionid",
1621
- type: "apiKey"
1622
- }],
1623
- url: "/cfg/accounts/profile/",
1624
- ...options
1625
- });
1626
- }
1627
- /**
1628
- * Upload user avatar
1629
- *
1630
- * Upload avatar image for the current authenticated user. Accepts multipart/form-data with 'avatar' field.
1631
- */
1632
- static cfgAccountsProfileAvatarCreate(options) {
1633
- return (options?.client ?? client).post({
1634
- ...formDataBodySerializer,
1635
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1636
- url: "/cfg/accounts/profile/avatar/",
1637
- ...options,
1638
- headers: {
1639
- "Content-Type": null,
1640
- ...options?.headers
1641
- }
1642
- });
1643
- }
1644
- /**
1645
- * Delete user account
1646
- *
1647
- *
1648
- * Permanently delete the current user's account.
1649
- *
1650
- * This operation:
1651
- * - Deactivates the account (user cannot log in)
1652
- * - Anonymizes personal data (GDPR compliance)
1653
- * - Frees up the email address for re-registration
1654
- * - Preserves audit trail
1655
- *
1656
- * The account can be restored by an administrator if needed.
1657
- *
1658
- */
1659
- static cfgAccountsProfileDeleteCreate(options) {
1660
- return (options?.client ?? client).post({
1661
- security: [{ scheme: "bearer", type: "http" }, {
1662
- in: "cookie",
1663
- name: "sessionid",
1664
- type: "apiKey"
1665
- }],
1666
- url: "/cfg/accounts/profile/delete/",
1667
- ...options
1668
- });
1669
- }
1670
- /**
1671
- * Partial update user profile
1672
- *
1673
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1674
- */
1675
- static cfgAccountsProfilePartialPartialUpdate(options) {
1676
- return (options?.client ?? client).patch({
1677
- security: [{ scheme: "bearer", type: "http" }, {
1678
- in: "cookie",
1679
- name: "sessionid",
1680
- type: "apiKey"
1681
- }],
1682
- url: "/cfg/accounts/profile/partial/",
1683
- ...options,
1684
- headers: {
1685
- "Content-Type": "application/json",
1686
- ...options?.headers
1687
- }
1688
- });
1689
- }
1690
- /**
1691
- * Partial update user profile
1692
- *
1693
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1694
- */
1695
- static cfgAccountsProfilePartialUpdate(options) {
1696
- return (options?.client ?? client).put({
1697
- security: [{ scheme: "bearer", type: "http" }, {
1698
- in: "cookie",
1699
- name: "sessionid",
1700
- type: "apiKey"
1701
- }],
1702
- url: "/cfg/accounts/profile/partial/",
1703
- ...options,
1704
- headers: {
1705
- "Content-Type": "application/json",
1706
- ...options?.headers
1707
- }
1708
- });
1709
- }
1710
- /**
1711
- * Update user profile
1712
- *
1713
- * Update the current authenticated user's profile information.
1714
- */
1715
- static cfgAccountsProfileUpdatePartialUpdate(options) {
1716
- return (options?.client ?? client).patch({
1717
- security: [{ scheme: "bearer", type: "http" }, {
1718
- in: "cookie",
1719
- name: "sessionid",
1720
- type: "apiKey"
1721
- }],
1722
- url: "/cfg/accounts/profile/update/",
1723
- ...options,
1724
- headers: {
1725
- "Content-Type": "application/json",
1726
- ...options?.headers
1727
- }
1728
- });
1729
- }
1730
- /**
1731
- * Update user profile
1732
- *
1733
- * Update the current authenticated user's profile information.
1734
- */
1735
- static cfgAccountsProfileUpdateUpdate(options) {
1736
- return (options?.client ?? client).put({
1737
- security: [{ scheme: "bearer", type: "http" }, {
1738
- in: "cookie",
1739
- name: "sessionid",
1740
- type: "apiKey"
1741
- }],
1742
- url: "/cfg/accounts/profile/update/",
1743
- ...options,
1744
- headers: {
1745
- "Content-Type": "application/json",
1746
- ...options?.headers
1747
- }
1748
- });
1749
- }
1750
- };
1751
- var CfgAccountsAuth = class {
1752
- static {
1753
- __name(this, "CfgAccountsAuth");
1754
- }
1755
- /**
1756
- * Refresh JWT token.
1757
- *
1758
- * DPoP-aware: when the incoming refresh token is key-bound (`cnf.jkt`), the
1759
- * rotated access/refresh in the response are re-stamped with the same `cnf`
1760
- * (stock SimpleJWT drops it from the derived access), and a matching DPoP
1761
- * proof is required on the refresh request — so a stolen refresh token can't
1762
- * be used to mint fresh tokens.
1763
- */
1764
- static cfgAccountsTokenRefreshCreate(options) {
1765
- return (options.client ?? client).post({
1766
- url: "/cfg/accounts/token/refresh/",
1767
- ...options,
1768
- headers: {
1769
- "Content-Type": "application/json",
1770
- ...options.headers
1771
- }
1772
- });
1773
- }
1774
- };
1775
- var CfgCentrifugo = class {
1776
- static {
1777
- __name(this, "CfgCentrifugo");
1778
- }
1779
- /**
1780
- * Get Centrifugo connection token
1781
- *
1782
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
1783
- */
1784
- static cfgCentrifugoAuthTokenRetrieve(options) {
1785
- return (options?.client ?? client).get({
1786
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1787
- url: "/cfg/centrifugo/auth/token/",
1788
- ...options
1789
- });
1790
- }
1791
- };
1792
- var CfgTotpBackupCodes = class {
1793
- static {
1794
- __name(this, "CfgTotpBackupCodes");
1795
- }
1796
- /**
1797
- * Get backup codes status for user.
1798
- */
1799
- static cfgTotpBackupCodesRetrieve(options) {
1800
- return (options?.client ?? client).get({
1801
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1802
- url: "/cfg/totp/backup-codes/",
1803
- ...options
1804
- });
1805
- }
1806
- /**
1807
- * Regenerate backup codes.
1808
- *
1809
- * Requires TOTP code for verification.
1810
- * Invalidates all existing codes.
1811
- */
1812
- static cfgTotpBackupCodesRegenerateCreate(options) {
1813
- return (options.client ?? client).post({
1814
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1815
- url: "/cfg/totp/backup-codes/regenerate/",
1816
- ...options,
1817
- headers: {
1818
- "Content-Type": "application/json",
1819
- ...options.headers
1820
- }
1821
- });
1822
- }
1823
- };
1824
- var CfgTotp = class {
1825
- static {
1826
- __name(this, "CfgTotp");
1827
- }
1828
- /**
1829
- * List all TOTP devices for user.
1830
- */
1831
- static cfgTotpDevicesRetrieve(options) {
1832
- return (options?.client ?? client).get({
1833
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1834
- url: "/cfg/totp/devices/",
1835
- ...options
1836
- });
1837
- }
1838
- /**
1839
- * Delete a TOTP device.
1840
- *
1841
- * Requires verification code if removing the last/primary device.
1842
- */
1843
- static cfgTotpDevicesDestroy(options) {
1844
- return (options.client ?? client).delete({
1845
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1846
- url: "/cfg/totp/devices/{id}/",
1847
- ...options
1848
- });
1849
- }
1850
- /**
1851
- * Completely disable 2FA for account.
1852
- *
1853
- * Requires verification code.
1854
- */
1855
- static cfgTotpDisableCreate(options) {
1856
- return (options.client ?? client).post({
1857
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1858
- url: "/cfg/totp/disable/",
1859
- ...options,
1860
- headers: {
1861
- "Content-Type": "application/json",
1862
- ...options.headers
1863
- }
1864
- });
1865
- }
1866
- };
1867
- var CfgTotpSetup = class {
1868
- static {
1869
- __name(this, "CfgTotpSetup");
1870
- }
1871
- /**
1872
- * Start 2FA setup process.
1873
- *
1874
- * Creates a new TOTP device and returns QR code for scanning.
1875
- */
1876
- static cfgTotpSetupCreate(options) {
1877
- return (options?.client ?? client).post({
1878
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1879
- url: "/cfg/totp/setup/",
1880
- ...options,
1881
- headers: {
1882
- "Content-Type": "application/json",
1883
- ...options?.headers
1884
- }
1885
- });
1886
- }
1887
- /**
1888
- * Confirm 2FA setup with first valid code.
1889
- *
1890
- * Activates the device and generates backup codes.
1891
- */
1892
- static cfgTotpSetupConfirmCreate(options) {
1893
- return (options.client ?? client).post({
1894
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1895
- url: "/cfg/totp/setup/confirm/",
1896
- ...options,
1897
- headers: {
1898
- "Content-Type": "application/json",
1899
- ...options.headers
1900
- }
1901
- });
1902
- }
1903
- };
1904
- var CfgTotpVerify = class {
1905
- static {
1906
- __name(this, "CfgTotpVerify");
1907
- }
1908
- /**
1909
- * Verify TOTP code for 2FA session.
1910
- *
1911
- * Completes authentication and returns JWT tokens on success.
1912
- */
1913
- static cfgTotpVerifyCreate(options) {
1914
- return (options.client ?? client).post({
1915
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1916
- url: "/cfg/totp/verify/",
1917
- ...options,
1918
- headers: {
1919
- "Content-Type": "application/json",
1920
- ...options.headers
1921
- }
1922
- });
1923
- }
1924
- /**
1925
- * Verify backup recovery code for 2FA session.
1926
- *
1927
- * Alternative verification method when TOTP device unavailable.
1928
- */
1929
- static cfgTotpVerifyBackupCreate(options) {
1930
- return (options.client ?? client).post({
1931
- security: [{ name: "X-API-Key", type: "apiKey" }, { scheme: "bearer", type: "http" }],
1932
- url: "/cfg/totp/verify/backup/",
1933
- ...options,
1934
- headers: {
1935
- "Content-Type": "application/json",
1936
- ...options.headers
1937
- }
1938
- });
1939
- }
1940
- };
1941
-
1942
111
  // src/_api/generated/_cfg_accounts/api.ts
1943
112
  var API = class {
1944
113
  static {