@djangocfg/api 2.1.355 → 2.1.357

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 (112) hide show
  1. package/README.md +53 -632
  2. package/dist/auth-server.cjs +717 -200
  3. package/dist/auth-server.cjs.map +1 -1
  4. package/dist/auth-server.mjs +717 -200
  5. package/dist/auth-server.mjs.map +1 -1
  6. package/dist/auth.cjs +843 -783
  7. package/dist/auth.cjs.map +1 -1
  8. package/dist/auth.d.cts +58 -37
  9. package/dist/auth.d.ts +58 -37
  10. package/dist/auth.mjs +846 -784
  11. package/dist/auth.mjs.map +1 -1
  12. package/dist/clients.cjs +1427 -0
  13. package/dist/clients.cjs.map +1 -1
  14. package/dist/clients.d.cts +1686 -0
  15. package/dist/clients.d.ts +1686 -0
  16. package/dist/clients.mjs +1427 -0
  17. package/dist/clients.mjs.map +1 -1
  18. package/dist/hooks.cjs +1277 -1924
  19. package/dist/hooks.cjs.map +1 -1
  20. package/dist/hooks.d.cts +18 -1206
  21. package/dist/hooks.d.ts +18 -1206
  22. package/dist/hooks.mjs +1253 -1900
  23. package/dist/hooks.mjs.map +1 -1
  24. package/dist/index.cjs +545 -1232
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +1389 -1455
  27. package/dist/index.d.ts +1389 -1455
  28. package/dist/index.mjs +545 -1232
  29. package/dist/index.mjs.map +1 -1
  30. package/package.json +7 -2
  31. package/src/_api/generated/_cfg_accounts/api.ts +11 -3
  32. package/src/_api/generated/_cfg_accounts/hooks/index.ts +3 -0
  33. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRegenerateCreate.ts +64 -0
  34. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +65 -0
  35. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyTestCreate.ts +64 -0
  36. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +43 -3
  37. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthDisconnectCreate.ts +43 -3
  38. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +43 -3
  39. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +43 -3
  40. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +43 -3
  41. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpRequestCreate.ts +43 -3
  42. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts +43 -3
  43. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileAvatarCreate.ts +43 -3
  44. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileDeleteCreate.ts +43 -3
  45. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +43 -3
  46. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfilePartialUpdate.ts +43 -3
  47. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +43 -3
  48. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +43 -3
  49. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileUpdateUpdate.ts +43 -3
  50. package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsTokenRefreshCreate.ts +43 -3
  51. package/src/_api/generated/_cfg_accounts/index.ts +1 -1
  52. package/src/_api/generated/_cfg_accounts/schemas/APIKey.ts +13 -0
  53. package/src/_api/generated/_cfg_accounts/schemas/APIKeyRegenerate.ts +12 -0
  54. package/src/_api/generated/_cfg_accounts/schemas/APIKeyRequest.ts +13 -0
  55. package/src/_api/generated/{_cfg_totp/schemas/DeviceListStatusEnum.ts → _cfg_accounts/schemas/APIKeyTestRequest.ts} +4 -2
  56. package/src/_api/generated/_cfg_accounts/schemas/APIKeyTestResult.ts +12 -0
  57. package/src/_api/generated/_cfg_accounts/schemas/AccountDeleteResponse.ts +1 -1
  58. package/src/_api/generated/_cfg_accounts/schemas/CentrifugoToken.ts +2 -2
  59. package/src/_api/generated/_cfg_accounts/schemas/CfgUserUpdateRequest.ts +3 -2
  60. package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +1 -1
  61. package/src/_api/generated/_cfg_accounts/schemas/OAuthConnection.ts +6 -6
  62. package/src/_api/generated/_cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts +2 -2
  63. package/src/_api/generated/_cfg_accounts/schemas/{ProviderEnum.ts → OAuthProviderEnum.ts} +2 -2
  64. package/src/_api/generated/_cfg_accounts/schemas/OAuthTokenResponse.ts +5 -5
  65. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts +1 -1
  66. package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts +3 -3
  67. package/src/_api/generated/_cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts +3 -2
  68. package/src/_api/generated/_cfg_accounts/schemas/User.ts +12 -10
  69. package/src/_api/generated/_cfg_accounts/schemas/cfg_accounts_oauth_connections_response_200_AutoRef.ts +10 -0
  70. package/src/_api/generated/_cfg_accounts/schemas/cfg_accounts_oauth_disconnect_response_200_AutoRef.ts +11 -0
  71. package/src/_api/generated/_cfg_accounts/schemas/index.ts +8 -1
  72. package/src/_api/generated/_cfg_centrifugo/api.ts +3 -3
  73. package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +43 -3
  74. package/src/_api/generated/_cfg_centrifugo/index.ts +1 -1
  75. package/src/_api/generated/_cfg_centrifugo/schemas/ConnectionTokenResponse.ts +2 -2
  76. package/src/_api/generated/_cfg_totp/api.ts +9 -3
  77. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +43 -3
  78. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +43 -3
  79. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesDestroy.ts +7 -3
  80. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +43 -3
  81. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDisableCreate.ts +43 -3
  82. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpSetupConfirmCreate.ts +43 -3
  83. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpSetupCreate.ts +43 -3
  84. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpVerifyBackupCreate.ts +43 -3
  85. package/src/_api/generated/_cfg_totp/hooks/useCfgTotpVerifyCreate.ts +43 -3
  86. package/src/_api/generated/_cfg_totp/index.ts +1 -1
  87. package/src/_api/generated/_cfg_totp/schemas/ConfirmSetupRequest.ts +1 -1
  88. package/src/_api/generated/_cfg_totp/schemas/ConfirmSetupResponse.ts +1 -1
  89. package/src/_api/generated/_cfg_totp/schemas/DeviceList.ts +5 -5
  90. package/src/_api/generated/_cfg_totp/schemas/DeviceStatusEnum.ts +9 -0
  91. package/src/_api/generated/_cfg_totp/schemas/SetupResponse.ts +2 -2
  92. package/src/_api/generated/_cfg_totp/schemas/TotpVerifyUser.ts +11 -9
  93. package/src/_api/generated/_cfg_totp/schemas/VerifyBackupRequest.ts +1 -1
  94. package/src/_api/generated/_cfg_totp/schemas/VerifyRequest.ts +1 -1
  95. package/src/_api/generated/_cfg_totp/schemas/VerifyResponse.ts +2 -2
  96. package/src/_api/generated/_cfg_totp/schemas/cfg_totp_disable_response_200_AutoRef.ts +9 -0
  97. package/src/_api/generated/_cfg_totp/schemas/index.ts +2 -1
  98. package/src/_api/generated/index.ts +3 -1
  99. package/src/_api/generated/sdk.gen.ts +80 -813
  100. package/src/_api/generated/types.gen.ts +320 -159
  101. package/src/auth/context/AccountsContext.tsx +18 -6
  102. package/src/auth/context/AuthContext.tsx +11 -3
  103. package/src/auth/hooks/useDeleteAccount.ts +2 -2
  104. package/src/auth/hooks/useGithubAuth.ts +3 -3
  105. package/src/auth/hooks/useTokenRefresh.ts +2 -2
  106. package/src/auth/hooks/useTwoFactor.ts +3 -3
  107. package/src/auth/hooks/useTwoFactorSetup.ts +3 -3
  108. package/src/auth/hooks/useTwoFactorStatus.ts +3 -3
  109. package/src/auth/middlewares/tokenRefresh.ts +2 -2
  110. package/src/hooks/index.ts +1 -0
  111. package/src/hooks/useApiKey.ts +73 -0
  112. package/src/index.ts +12 -16
package/dist/hooks.cjs CHANGED
@@ -1,5 +1,4 @@
1
1
  "use client";
2
- "use client";
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -32,2022 +31,1376 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
31
  // src/hooks/index.ts
33
32
  var hooks_exports = {};
34
33
  __export(hooks_exports, {
35
- useAccountsOauthConnectionsList: () => useAccountsOauthConnectionsList,
36
- useAccountsOauthProvidersRetrieve: () => useAccountsOauthProvidersRetrieve,
37
- useAccountsProfileRetrieve: () => useAccountsProfileRetrieve,
38
- useCreateAccountsOauthDisconnectCreate: () => useCreateAccountsOauthDisconnectCreate,
39
- useCreateAccountsOauthGithubAuthorizeCreate: () => useCreateAccountsOauthGithubAuthorizeCreate,
40
- useCreateAccountsOauthGithubCallbackCreate: () => useCreateAccountsOauthGithubCallbackCreate,
41
- useCreateAccountsOtpRequestCreate: () => useCreateAccountsOtpRequestCreate,
42
- useCreateAccountsOtpVerifyCreate: () => useCreateAccountsOtpVerifyCreate,
43
- useCreateAccountsProfileAvatarCreate: () => useCreateAccountsProfileAvatarCreate,
44
- useCreateAccountsProfileDeleteCreate: () => useCreateAccountsProfileDeleteCreate,
45
- useCreateAccountsTokenRefreshCreate: () => useCreateAccountsTokenRefreshCreate,
46
- usePartialUpdateAccountsProfilePartialPartialUpdate: () => usePartialUpdateAccountsProfilePartialPartialUpdate,
47
- usePartialUpdateAccountsProfilePartialUpdate: () => usePartialUpdateAccountsProfilePartialUpdate,
48
- usePartialUpdateAccountsProfileUpdatePartialUpdate: () => usePartialUpdateAccountsProfileUpdatePartialUpdate,
49
- useUpdateAccountsProfileUpdateUpdate: () => useUpdateAccountsProfileUpdateUpdate
34
+ useApiKey: () => useApiKey
50
35
  });
51
36
  module.exports = __toCommonJS(hooks_exports);
52
37
 
53
- // src/_api/generated/cfg_accounts/_utils/hooks/accounts__auth.ts
54
- var import_swr = require("swr");
38
+ // src/hooks/useApiKey.ts
39
+ var import_react = require("react");
55
40
 
56
- // src/_api/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts
57
- var import_consola5 = require("consola");
41
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRegenerateCreate.ts
42
+ var import_mutation = __toESM(require("swr/mutation"), 1);
58
43
 
59
- // src/_api/generated/cfg_accounts/_utils/schemas/TokenRefresh.schema.ts
60
- var import_zod = require("zod");
61
- var TokenRefreshSchema = import_zod.z.object({
62
- access: import_zod.z.string(),
63
- refresh: import_zod.z.string()
64
- });
44
+ // src/_api/generated/core/bodySerializer.gen.ts
45
+ var jsonBodySerializer = {
46
+ bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
47
+ };
65
48
 
66
- // src/_api/generated/cfg_accounts/accounts__auth/client.ts
67
- var Auth = class {
68
- static {
69
- __name(this, "Auth");
49
+ // src/_api/generated/core/params.gen.ts
50
+ var extraPrefixesMap = {
51
+ $body_: "body",
52
+ $headers_: "headers",
53
+ $path_: "path",
54
+ $query_: "query"
55
+ };
56
+ var extraPrefixes = Object.entries(extraPrefixesMap);
57
+
58
+ // src/_api/generated/core/serverSentEvents.gen.ts
59
+ function createSseClient({
60
+ onRequest,
61
+ onSseError,
62
+ onSseEvent,
63
+ responseTransformer,
64
+ responseValidator,
65
+ sseDefaultRetryDelay,
66
+ sseMaxRetryAttempts,
67
+ sseMaxRetryDelay,
68
+ sseSleepFn,
69
+ url,
70
+ ...options
71
+ }) {
72
+ let lastEventId;
73
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
74
+ const createStream = /* @__PURE__ */ __name(async function* () {
75
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
76
+ let attempt = 0;
77
+ const signal = options.signal ?? new AbortController().signal;
78
+ while (true) {
79
+ if (signal.aborted) break;
80
+ attempt++;
81
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
82
+ if (lastEventId !== void 0) {
83
+ headers.set("Last-Event-ID", lastEventId);
84
+ }
85
+ try {
86
+ const requestInit = {
87
+ redirect: "follow",
88
+ ...options,
89
+ body: options.serializedBody,
90
+ headers,
91
+ signal
92
+ };
93
+ let request = new Request(url, requestInit);
94
+ if (onRequest) {
95
+ request = await onRequest(url, requestInit);
96
+ }
97
+ const _fetch = options.fetch ?? globalThis.fetch;
98
+ const response = await _fetch(request);
99
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
100
+ if (!response.body) throw new Error("No body in SSE response");
101
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
102
+ let buffer = "";
103
+ const abortHandler = /* @__PURE__ */ __name(() => {
104
+ try {
105
+ reader.cancel();
106
+ } catch {
107
+ }
108
+ }, "abortHandler");
109
+ signal.addEventListener("abort", abortHandler);
110
+ try {
111
+ while (true) {
112
+ const { done, value } = await reader.read();
113
+ if (done) break;
114
+ buffer += value;
115
+ buffer = buffer.replace(/\r\n?/g, "\n");
116
+ const chunks = buffer.split("\n\n");
117
+ buffer = chunks.pop() ?? "";
118
+ for (const chunk of chunks) {
119
+ const lines = chunk.split("\n");
120
+ const dataLines = [];
121
+ let eventName;
122
+ for (const line of lines) {
123
+ if (line.startsWith("data:")) {
124
+ dataLines.push(line.replace(/^data:\s*/, ""));
125
+ } else if (line.startsWith("event:")) {
126
+ eventName = line.replace(/^event:\s*/, "");
127
+ } else if (line.startsWith("id:")) {
128
+ lastEventId = line.replace(/^id:\s*/, "");
129
+ } else if (line.startsWith("retry:")) {
130
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
131
+ if (!Number.isNaN(parsed)) {
132
+ retryDelay = parsed;
133
+ }
134
+ }
135
+ }
136
+ let data;
137
+ let parsedJson = false;
138
+ if (dataLines.length) {
139
+ const rawData = dataLines.join("\n");
140
+ try {
141
+ data = JSON.parse(rawData);
142
+ parsedJson = true;
143
+ } catch {
144
+ data = rawData;
145
+ }
146
+ }
147
+ if (parsedJson) {
148
+ if (responseValidator) {
149
+ await responseValidator(data);
150
+ }
151
+ if (responseTransformer) {
152
+ data = await responseTransformer(data);
153
+ }
154
+ }
155
+ onSseEvent?.({
156
+ data,
157
+ event: eventName,
158
+ id: lastEventId,
159
+ retry: retryDelay
160
+ });
161
+ if (dataLines.length) {
162
+ yield data;
163
+ }
164
+ }
165
+ }
166
+ } finally {
167
+ signal.removeEventListener("abort", abortHandler);
168
+ reader.releaseLock();
169
+ }
170
+ break;
171
+ } catch (error) {
172
+ onSseError?.(error);
173
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
174
+ break;
175
+ }
176
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
177
+ await sleep(backoff);
178
+ }
179
+ }
180
+ }, "createStream");
181
+ const stream = createStream();
182
+ return { stream };
183
+ }
184
+ __name(createSseClient, "createSseClient");
185
+
186
+ // src/_api/generated/core/pathSerializer.gen.ts
187
+ var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
188
+ switch (style) {
189
+ case "label":
190
+ return ".";
191
+ case "matrix":
192
+ return ";";
193
+ case "simple":
194
+ return ",";
195
+ default:
196
+ return "&";
197
+ }
198
+ }, "separatorArrayExplode");
199
+ var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
200
+ switch (style) {
201
+ case "form":
202
+ return ",";
203
+ case "pipeDelimited":
204
+ return "|";
205
+ case "spaceDelimited":
206
+ return "%20";
207
+ default:
208
+ return ",";
209
+ }
210
+ }, "separatorArrayNoExplode");
211
+ var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
212
+ switch (style) {
213
+ case "label":
214
+ return ".";
215
+ case "matrix":
216
+ return ";";
217
+ case "simple":
218
+ return ",";
219
+ default:
220
+ return "&";
221
+ }
222
+ }, "separatorObjectExplode");
223
+ var serializeArrayParam = /* @__PURE__ */ __name(({
224
+ allowReserved,
225
+ explode,
226
+ name,
227
+ style,
228
+ value
229
+ }) => {
230
+ if (!explode) {
231
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
232
+ switch (style) {
233
+ case "label":
234
+ return `.${joinedValues2}`;
235
+ case "matrix":
236
+ return `;${name}=${joinedValues2}`;
237
+ case "simple":
238
+ return joinedValues2;
239
+ default:
240
+ return `${name}=${joinedValues2}`;
241
+ }
70
242
  }
71
- client;
72
- constructor(client) {
73
- this.client = client;
243
+ const separator = separatorArrayExplode(style);
244
+ const joinedValues = value.map((v) => {
245
+ if (style === "label" || style === "simple") {
246
+ return allowReserved ? v : encodeURIComponent(v);
247
+ }
248
+ return serializePrimitiveParam({
249
+ allowReserved,
250
+ name,
251
+ value: v
252
+ });
253
+ }).join(separator);
254
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
255
+ }, "serializeArrayParam");
256
+ var serializePrimitiveParam = /* @__PURE__ */ __name(({
257
+ allowReserved,
258
+ name,
259
+ value
260
+ }) => {
261
+ if (value === void 0 || value === null) {
262
+ return "";
263
+ }
264
+ if (typeof value === "object") {
265
+ throw new Error(
266
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
267
+ );
74
268
  }
75
- /**
76
- * Refresh JWT token.
77
- */
78
- async accountsTokenRefreshCreate(data) {
79
- const response = await this.client.request("POST", "/cfg/accounts/token/refresh/", { body: data });
80
- return response;
269
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
270
+ }, "serializePrimitiveParam");
271
+ var serializeObjectParam = /* @__PURE__ */ __name(({
272
+ allowReserved,
273
+ explode,
274
+ name,
275
+ style,
276
+ value,
277
+ valueOnly
278
+ }) => {
279
+ if (value instanceof Date) {
280
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
281
+ }
282
+ if (style !== "deepObject" && !explode) {
283
+ let values = [];
284
+ Object.entries(value).forEach(([key, v]) => {
285
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
286
+ });
287
+ const joinedValues2 = values.join(",");
288
+ switch (style) {
289
+ case "form":
290
+ return `${name}=${joinedValues2}`;
291
+ case "label":
292
+ return `.${joinedValues2}`;
293
+ case "matrix":
294
+ return `;${name}=${joinedValues2}`;
295
+ default:
296
+ return joinedValues2;
297
+ }
81
298
  }
82
- };
299
+ const separator = separatorObjectExplode(style);
300
+ const joinedValues = Object.entries(value).map(
301
+ ([key, v]) => serializePrimitiveParam({
302
+ allowReserved,
303
+ name: style === "deepObject" ? `${name}[${key}]` : key,
304
+ value: v
305
+ })
306
+ ).join(separator);
307
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
308
+ }, "serializeObjectParam");
83
309
 
84
- // src/_api/generated/cfg_accounts/accounts__oauth/client.ts
85
- var Oauth = class {
86
- static {
87
- __name(this, "Oauth");
88
- }
89
- client;
90
- constructor(client) {
91
- this.client = client;
310
+ // src/_api/generated/core/utils.gen.ts
311
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
312
+ var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
313
+ let url = _url;
314
+ const matches = _url.match(PATH_PARAM_RE);
315
+ if (matches) {
316
+ for (const match of matches) {
317
+ let explode = false;
318
+ let name = match.substring(1, match.length - 1);
319
+ let style = "simple";
320
+ if (name.endsWith("*")) {
321
+ explode = true;
322
+ name = name.substring(0, name.length - 1);
323
+ }
324
+ if (name.startsWith(".")) {
325
+ name = name.substring(1);
326
+ style = "label";
327
+ } else if (name.startsWith(";")) {
328
+ name = name.substring(1);
329
+ style = "matrix";
330
+ }
331
+ const value = path[name];
332
+ if (value === void 0 || value === null) {
333
+ continue;
334
+ }
335
+ if (Array.isArray(value)) {
336
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
337
+ continue;
338
+ }
339
+ if (typeof value === "object") {
340
+ url = url.replace(
341
+ match,
342
+ serializeObjectParam({
343
+ explode,
344
+ name,
345
+ style,
346
+ value,
347
+ valueOnly: true
348
+ })
349
+ );
350
+ continue;
351
+ }
352
+ if (style === "matrix") {
353
+ url = url.replace(
354
+ match,
355
+ `;${serializePrimitiveParam({
356
+ name,
357
+ value
358
+ })}`
359
+ );
360
+ continue;
361
+ }
362
+ const replaceValue = encodeURIComponent(
363
+ style === "label" ? `.${value}` : value
364
+ );
365
+ url = url.replace(match, replaceValue);
366
+ }
92
367
  }
93
- /**
94
- * List OAuth connections
95
- *
96
- * Get all OAuth connections for the current user.
97
- */
98
- async accountsOauthConnectionsList() {
99
- const response = await this.client.request("GET", "/cfg/accounts/oauth/connections/");
100
- return response.results || response;
368
+ return url;
369
+ }, "defaultPathSerializer");
370
+ var getUrl = /* @__PURE__ */ __name(({
371
+ baseUrl,
372
+ path,
373
+ query,
374
+ querySerializer,
375
+ url: _url
376
+ }) => {
377
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
378
+ let url = (baseUrl ?? "") + pathUrl;
379
+ if (path) {
380
+ url = defaultPathSerializer({ path, url });
381
+ }
382
+ let search = query ? querySerializer(query) : "";
383
+ if (search.startsWith("?")) {
384
+ search = search.substring(1);
385
+ }
386
+ if (search) {
387
+ url += `?${search}`;
388
+ }
389
+ return url;
390
+ }, "getUrl");
391
+ function getValidRequestBody(options) {
392
+ const hasBody = options.body !== void 0;
393
+ const isSerializedBody = hasBody && options.bodySerializer;
394
+ if (isSerializedBody) {
395
+ if ("serializedBody" in options) {
396
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
397
+ return hasSerializedBody ? options.serializedBody : null;
398
+ }
399
+ return options.body !== "" ? options.body : null;
101
400
  }
102
- /**
103
- * Disconnect OAuth provider
104
- *
105
- * Remove OAuth connection for the specified provider.
106
- */
107
- async accountsOauthDisconnectCreate(data) {
108
- const response = await this.client.request("POST", "/cfg/accounts/oauth/disconnect/", { body: data });
109
- return response;
401
+ if (hasBody) {
402
+ return options.body;
110
403
  }
111
- /**
112
- * Start GitHub OAuth
113
- *
114
- * Generate GitHub OAuth authorization URL. Redirect user to this URL to
115
- * start authentication.
116
- */
117
- async accountsOauthGithubAuthorizeCreate(data) {
118
- const response = await this.client.request("POST", "/cfg/accounts/oauth/github/authorize/", { body: data });
119
- return response;
404
+ return void 0;
405
+ }
406
+ __name(getValidRequestBody, "getValidRequestBody");
407
+
408
+ // src/_api/generated/core/auth.gen.ts
409
+ var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
410
+ const token = typeof callback === "function" ? await callback(auth2) : callback;
411
+ if (!token) {
412
+ return;
120
413
  }
121
- /**
122
- * Complete GitHub OAuth
123
- *
124
- * Exchange authorization code for JWT tokens. Call this after GitHub
125
- * redirects back with code.
126
- */
127
- async accountsOauthGithubCallbackCreate(data) {
128
- const response = await this.client.request("POST", "/cfg/accounts/oauth/github/callback/", { body: data });
129
- return response;
414
+ if (auth2.scheme === "bearer") {
415
+ return `Bearer ${token}`;
130
416
  }
131
- /**
132
- * List OAuth providers
133
- *
134
- * Get list of available OAuth providers for authentication.
135
- */
136
- async accountsOauthProvidersRetrieve() {
137
- const response = await this.client.request("GET", "/cfg/accounts/oauth/providers/");
138
- return response;
417
+ if (auth2.scheme === "basic") {
418
+ return `Basic ${btoa(token)}`;
139
419
  }
140
- };
420
+ return token;
421
+ }, "getAuthToken");
141
422
 
142
- // src/_api/generated/cfg_accounts/accounts__user_profile/client.ts
143
- var UserProfile = class {
144
- static {
145
- __name(this, "UserProfile");
146
- }
147
- client;
148
- constructor(client) {
149
- this.client = client;
423
+ // src/_api/generated/client/utils.gen.ts
424
+ var createQuerySerializer = /* @__PURE__ */ __name(({
425
+ parameters = {},
426
+ ...args
427
+ } = {}) => {
428
+ const querySerializer = /* @__PURE__ */ __name((queryParams) => {
429
+ const search = [];
430
+ if (queryParams && typeof queryParams === "object") {
431
+ for (const name in queryParams) {
432
+ const value = queryParams[name];
433
+ if (value === void 0 || value === null) {
434
+ continue;
435
+ }
436
+ const options = parameters[name] || args;
437
+ if (Array.isArray(value)) {
438
+ const serializedArray = serializeArrayParam({
439
+ allowReserved: options.allowReserved,
440
+ explode: true,
441
+ name,
442
+ style: "form",
443
+ value,
444
+ ...options.array
445
+ });
446
+ if (serializedArray) search.push(serializedArray);
447
+ } else if (typeof value === "object") {
448
+ const serializedObject = serializeObjectParam({
449
+ allowReserved: options.allowReserved,
450
+ explode: true,
451
+ name,
452
+ style: "deepObject",
453
+ value,
454
+ ...options.object
455
+ });
456
+ if (serializedObject) search.push(serializedObject);
457
+ } else {
458
+ const serializedPrimitive = serializePrimitiveParam({
459
+ allowReserved: options.allowReserved,
460
+ name,
461
+ value
462
+ });
463
+ if (serializedPrimitive) search.push(serializedPrimitive);
464
+ }
465
+ }
466
+ }
467
+ return search.join("&");
468
+ }, "querySerializer");
469
+ return querySerializer;
470
+ }, "createQuerySerializer");
471
+ var getParseAs = /* @__PURE__ */ __name((contentType) => {
472
+ if (!contentType) {
473
+ return "stream";
474
+ }
475
+ const cleanContent = contentType.split(";")[0]?.trim();
476
+ if (!cleanContent) {
477
+ return;
478
+ }
479
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
480
+ return "json";
481
+ }
482
+ if (cleanContent === "multipart/form-data") {
483
+ return "formData";
484
+ }
485
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
486
+ return "blob";
487
+ }
488
+ if (cleanContent.startsWith("text/")) {
489
+ return "text";
490
+ }
491
+ return;
492
+ }, "getParseAs");
493
+ var checkForExistence = /* @__PURE__ */ __name((options, name) => {
494
+ if (!name) {
495
+ return false;
150
496
  }
151
- /**
152
- * Get current user profile
153
- *
154
- * Retrieve the current authenticated user's profile information.
155
- */
156
- async accountsProfileRetrieve() {
157
- const response = await this.client.request("GET", "/cfg/accounts/profile/");
158
- return response;
497
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
498
+ return true;
159
499
  }
160
- /**
161
- * Upload user avatar
162
- *
163
- * Upload avatar image for the current authenticated user. Accepts
164
- * multipart/form-data with 'avatar' field.
165
- */
166
- async accountsProfileAvatarCreate(data) {
167
- const formData = new FormData();
168
- formData.append("avatar", data.avatar);
169
- const response = await this.client.request("POST", "/cfg/accounts/profile/avatar/", { formData });
170
- return response;
500
+ return false;
501
+ }, "checkForExistence");
502
+ var setAuthParams = /* @__PURE__ */ __name(async ({
503
+ security,
504
+ ...options
505
+ }) => {
506
+ for (const auth2 of security) {
507
+ if (checkForExistence(options, auth2.name)) {
508
+ continue;
509
+ }
510
+ const token = await getAuthToken(auth2, options.auth);
511
+ if (!token) {
512
+ continue;
513
+ }
514
+ const name = auth2.name ?? "Authorization";
515
+ switch (auth2.in) {
516
+ case "query":
517
+ if (!options.query) {
518
+ options.query = {};
519
+ }
520
+ options.query[name] = token;
521
+ break;
522
+ case "cookie":
523
+ options.headers.append("Cookie", `${name}=${token}`);
524
+ break;
525
+ case "header":
526
+ default:
527
+ options.headers.set(name, token);
528
+ break;
529
+ }
171
530
  }
172
- /**
173
- * Delete user account
174
- *
175
- * Permanently delete the current user's account. This operation: -
176
- * Deactivates the account (user cannot log in) - Anonymizes personal data
177
- * (GDPR compliance) - Frees up the email address for re-registration -
178
- * Preserves audit trail The account can be restored by an administrator if
179
- * needed.
180
- */
181
- async accountsProfileDeleteCreate() {
182
- const response = await this.client.request("POST", "/cfg/accounts/profile/delete/");
183
- return response;
531
+ }, "setAuthParams");
532
+ var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
533
+ baseUrl: options.baseUrl,
534
+ path: options.path,
535
+ query: options.query,
536
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
537
+ url: options.url
538
+ }), "buildUrl");
539
+ var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
540
+ const config = { ...a, ...b };
541
+ if (config.baseUrl?.endsWith("/")) {
542
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
543
+ }
544
+ config.headers = mergeHeaders(a.headers, b.headers);
545
+ return config;
546
+ }, "mergeConfigs");
547
+ var headersEntries = /* @__PURE__ */ __name((headers) => {
548
+ const entries = [];
549
+ headers.forEach((value, key) => {
550
+ entries.push([key, value]);
551
+ });
552
+ return entries;
553
+ }, "headersEntries");
554
+ var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
555
+ const mergedHeaders = new Headers();
556
+ for (const header of headers) {
557
+ if (!header) {
558
+ continue;
559
+ }
560
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
561
+ for (const [key, value] of iterator) {
562
+ if (value === null) {
563
+ mergedHeaders.delete(key);
564
+ } else if (Array.isArray(value)) {
565
+ for (const v of value) {
566
+ mergedHeaders.append(key, v);
567
+ }
568
+ } else if (value !== void 0) {
569
+ mergedHeaders.set(
570
+ key,
571
+ typeof value === "object" ? JSON.stringify(value) : value
572
+ );
573
+ }
574
+ }
184
575
  }
185
- /**
186
- * Partial update user profile
187
- *
188
- * Partially update the current authenticated user's profile information.
189
- * Supports avatar upload.
190
- */
191
- async accountsProfilePartialUpdate(data) {
192
- const response = await this.client.request("PUT", "/cfg/accounts/profile/partial/", { body: data });
193
- return response;
576
+ return mergedHeaders;
577
+ }, "mergeHeaders");
578
+ var Interceptors = class {
579
+ static {
580
+ __name(this, "Interceptors");
194
581
  }
195
- /**
196
- * Partial update user profile
197
- *
198
- * Partially update the current authenticated user's profile information.
199
- * Supports avatar upload.
200
- */
201
- async accountsProfilePartialPartialUpdate(data) {
202
- const response = await this.client.request("PATCH", "/cfg/accounts/profile/partial/", { body: data });
203
- return response;
582
+ fns = [];
583
+ clear() {
584
+ this.fns = [];
204
585
  }
205
- /**
206
- * Update user profile
207
- *
208
- * Update the current authenticated user's profile information.
209
- */
210
- async accountsProfileUpdateUpdate(data) {
211
- const response = await this.client.request("PUT", "/cfg/accounts/profile/update/", { body: data });
212
- return response;
586
+ eject(id) {
587
+ const index = this.getInterceptorIndex(id);
588
+ if (this.fns[index]) {
589
+ this.fns[index] = null;
590
+ }
213
591
  }
214
- /**
215
- * Update user profile
216
- *
217
- * Update the current authenticated user's profile information.
218
- */
219
- async accountsProfileUpdatePartialUpdate(data) {
220
- const response = await this.client.request("PATCH", "/cfg/accounts/profile/update/", { body: data });
221
- return response;
592
+ exists(id) {
593
+ const index = this.getInterceptorIndex(id);
594
+ return Boolean(this.fns[index]);
222
595
  }
223
- };
224
-
225
- // src/_api/generated/cfg_accounts/accounts/client.ts
226
- var Accounts = class {
227
- static {
228
- __name(this, "Accounts");
596
+ getInterceptorIndex(id) {
597
+ if (typeof id === "number") {
598
+ return this.fns[id] ? id : -1;
599
+ }
600
+ return this.fns.indexOf(id);
229
601
  }
230
- client;
231
- constructor(client) {
232
- this.client = client;
602
+ update(id, fn) {
603
+ const index = this.getInterceptorIndex(id);
604
+ if (this.fns[index]) {
605
+ this.fns[index] = fn;
606
+ return id;
607
+ }
608
+ return false;
233
609
  }
234
- /**
235
- * Request OTP code to email.
236
- */
237
- async otpRequestCreate(data) {
238
- const response = await this.client.request("POST", "/cfg/accounts/otp/request/", { body: data });
239
- return response;
610
+ use(fn) {
611
+ this.fns.push(fn);
612
+ return this.fns.length - 1;
240
613
  }
241
- /**
242
- * Verify OTP code and return JWT tokens or 2FA session. If user has 2FA
243
- * enabled: - Returns requires_2fa=True with session_id - Client must
244
- * complete 2FA verification at /cfg/totp/verify/ If user has no 2FA: -
245
- * Returns JWT tokens and user data directly
246
- */
247
- async otpVerifyCreate(data) {
248
- const response = await this.client.request("POST", "/cfg/accounts/otp/verify/", { body: data });
249
- return response;
614
+ };
615
+ var createInterceptors = /* @__PURE__ */ __name(() => ({
616
+ error: new Interceptors(),
617
+ request: new Interceptors(),
618
+ response: new Interceptors()
619
+ }), "createInterceptors");
620
+ var defaultQuerySerializer = createQuerySerializer({
621
+ allowReserved: false,
622
+ array: {
623
+ explode: true,
624
+ style: "form"
625
+ },
626
+ object: {
627
+ explode: true,
628
+ style: "deepObject"
250
629
  }
630
+ });
631
+ var defaultHeaders = {
632
+ "Content-Type": "application/json"
251
633
  };
634
+ var createConfig = /* @__PURE__ */ __name((override = {}) => ({
635
+ ...jsonBodySerializer,
636
+ headers: defaultHeaders,
637
+ parseAs: "auto",
638
+ querySerializer: defaultQuerySerializer,
639
+ ...override
640
+ }), "createConfig");
252
641
 
253
- // src/_api/generated/cfg_accounts/http.ts
254
- var FetchAdapter = class {
255
- static {
256
- __name(this, "FetchAdapter");
257
- }
258
- async request(request) {
259
- const { method, url, headers, body, params, formData, binaryBody, responseType } = request;
260
- let finalUrl = url;
261
- if (params) {
262
- const searchParams = new URLSearchParams();
263
- Object.entries(params).forEach(([key, value]) => {
264
- if (value !== null && value !== void 0) {
265
- searchParams.append(key, String(value));
266
- }
642
+ // src/_api/generated/client/client.gen.ts
643
+ var createClient = /* @__PURE__ */ __name((config = {}) => {
644
+ let _config = mergeConfigs(createConfig(), config);
645
+ const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
646
+ const setConfig = /* @__PURE__ */ __name((config2) => {
647
+ _config = mergeConfigs(_config, config2);
648
+ return getConfig();
649
+ }, "setConfig");
650
+ const interceptors = createInterceptors();
651
+ const beforeRequest = /* @__PURE__ */ __name(async (options) => {
652
+ const opts = {
653
+ ..._config,
654
+ ...options,
655
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
656
+ headers: mergeHeaders(_config.headers, options.headers),
657
+ serializedBody: void 0
658
+ };
659
+ if (opts.security) {
660
+ await setAuthParams({
661
+ ...opts,
662
+ security: opts.security
267
663
  });
268
- const queryString = searchParams.toString();
269
- if (queryString) {
270
- finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
271
- }
272
664
  }
273
- const finalHeaders = { ...headers };
274
- let requestBody;
275
- if (formData) {
276
- requestBody = formData;
277
- } else if (binaryBody) {
278
- finalHeaders["Content-Type"] = "application/octet-stream";
279
- requestBody = binaryBody;
280
- } else if (body) {
281
- finalHeaders["Content-Type"] = "application/json";
282
- requestBody = JSON.stringify(body);
665
+ if (opts.requestValidator) {
666
+ await opts.requestValidator(opts);
667
+ }
668
+ if (opts.body !== void 0 && opts.bodySerializer) {
669
+ opts.serializedBody = opts.bodySerializer(opts.body);
670
+ }
671
+ if (opts.body === void 0 || opts.serializedBody === "") {
672
+ opts.headers.delete("Content-Type");
673
+ }
674
+ const resolvedOpts = opts;
675
+ const url = buildUrl(resolvedOpts);
676
+ return { opts: resolvedOpts, url };
677
+ }, "beforeRequest");
678
+ const request = /* @__PURE__ */ __name(async (options) => {
679
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
680
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
681
+ let request2;
682
+ let response;
683
+ try {
684
+ const { opts, url } = await beforeRequest(options);
685
+ const requestInit = {
686
+ redirect: "follow",
687
+ ...opts,
688
+ body: getValidRequestBody(opts)
689
+ };
690
+ request2 = new Request(url, requestInit);
691
+ for (const fn of interceptors.request.fns) {
692
+ if (fn) {
693
+ request2 = await fn(request2, opts);
694
+ }
695
+ }
696
+ const _fetch = opts.fetch;
697
+ response = await _fetch(request2);
698
+ for (const fn of interceptors.response.fns) {
699
+ if (fn) {
700
+ response = await fn(response, request2, opts);
701
+ }
702
+ }
703
+ const result = {
704
+ request: request2,
705
+ response
706
+ };
707
+ if (response.ok) {
708
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
709
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
710
+ let emptyData;
711
+ switch (parseAs) {
712
+ case "arrayBuffer":
713
+ case "blob":
714
+ case "text":
715
+ emptyData = await response[parseAs]();
716
+ break;
717
+ case "formData":
718
+ emptyData = new FormData();
719
+ break;
720
+ case "stream":
721
+ emptyData = response.body;
722
+ break;
723
+ case "json":
724
+ default:
725
+ emptyData = {};
726
+ break;
727
+ }
728
+ return opts.responseStyle === "data" ? emptyData : {
729
+ data: emptyData,
730
+ ...result
731
+ };
732
+ }
733
+ let data;
734
+ switch (parseAs) {
735
+ case "arrayBuffer":
736
+ case "blob":
737
+ case "formData":
738
+ case "text":
739
+ data = await response[parseAs]();
740
+ break;
741
+ case "json": {
742
+ const text = await response.text();
743
+ data = text ? JSON.parse(text) : {};
744
+ break;
745
+ }
746
+ case "stream":
747
+ return opts.responseStyle === "data" ? response.body : {
748
+ data: response.body,
749
+ ...result
750
+ };
751
+ }
752
+ if (parseAs === "json") {
753
+ if (opts.responseValidator) {
754
+ await opts.responseValidator(data);
755
+ }
756
+ if (opts.responseTransformer) {
757
+ data = await opts.responseTransformer(data);
758
+ }
759
+ }
760
+ return opts.responseStyle === "data" ? data : {
761
+ data,
762
+ ...result
763
+ };
764
+ }
765
+ const textError = await response.text();
766
+ let jsonError;
767
+ try {
768
+ jsonError = JSON.parse(textError);
769
+ } catch {
770
+ }
771
+ throw jsonError ?? textError;
772
+ } catch (error) {
773
+ let finalError = error;
774
+ for (const fn of interceptors.error.fns) {
775
+ if (fn) {
776
+ finalError = await fn(finalError, response, request2, options);
777
+ }
778
+ }
779
+ finalError = finalError || {};
780
+ if (throwOnError) {
781
+ throw finalError;
782
+ }
783
+ return responseStyle === "data" ? void 0 : {
784
+ error: finalError,
785
+ request: request2,
786
+ response
787
+ };
283
788
  }
284
- const response = await fetch(finalUrl, {
789
+ }, "request");
790
+ const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
791
+ const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
792
+ const { opts, url } = await beforeRequest(options);
793
+ return createSseClient({
794
+ ...opts,
795
+ body: opts.body,
285
796
  method,
286
- headers: finalHeaders,
287
- body: requestBody,
288
- credentials: "include"
289
- // Include Django session cookies
797
+ onRequest: /* @__PURE__ */ __name(async (url2, init) => {
798
+ let request2 = new Request(url2, init);
799
+ for (const fn of interceptors.request.fns) {
800
+ if (fn) {
801
+ request2 = await fn(request2, opts);
802
+ }
803
+ }
804
+ return request2;
805
+ }, "onRequest"),
806
+ serializedBody: getValidRequestBody(opts),
807
+ url
290
808
  });
291
- let data = null;
292
- const contentType = response.headers.get("content-type") ?? "";
293
- if (response.status !== 204) {
294
- if (responseType === "blob") {
295
- data = await response.blob();
296
- } else if (responseType === "text") {
297
- data = await response.text();
298
- } else if (responseType === "json") {
299
- data = await response.json();
300
- } else if (contentType.includes("application/json")) {
301
- data = await response.json();
302
- } else if (contentType.startsWith("text/")) {
303
- data = await response.text();
809
+ }, "makeSseFn");
810
+ const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl({ ..._config, ...options }), "_buildUrl");
811
+ return {
812
+ buildUrl: _buildUrl,
813
+ connect: makeMethodFn("CONNECT"),
814
+ delete: makeMethodFn("DELETE"),
815
+ get: makeMethodFn("GET"),
816
+ getConfig,
817
+ head: makeMethodFn("HEAD"),
818
+ interceptors,
819
+ options: makeMethodFn("OPTIONS"),
820
+ patch: makeMethodFn("PATCH"),
821
+ post: makeMethodFn("POST"),
822
+ put: makeMethodFn("PUT"),
823
+ request,
824
+ setConfig,
825
+ sse: {
826
+ connect: makeSseFn("CONNECT"),
827
+ delete: makeSseFn("DELETE"),
828
+ get: makeSseFn("GET"),
829
+ head: makeSseFn("HEAD"),
830
+ options: makeSseFn("OPTIONS"),
831
+ patch: makeSseFn("PATCH"),
832
+ post: makeSseFn("POST"),
833
+ put: makeSseFn("PUT"),
834
+ trace: makeSseFn("TRACE")
835
+ },
836
+ trace: makeMethodFn("TRACE")
837
+ };
838
+ }, "createClient");
839
+
840
+ // src/_api/generated/helpers/auth.ts
841
+ var ACCESS_KEY = "cfg.access_token";
842
+ var REFRESH_KEY = "cfg.refresh_token";
843
+ var API_KEY_KEY = "cfg.api_key";
844
+ var isBrowser = typeof window !== "undefined";
845
+ var localStorageBackend = {
846
+ get(key) {
847
+ if (!isBrowser) return null;
848
+ try {
849
+ return window.localStorage.getItem(key);
850
+ } catch {
851
+ return null;
852
+ }
853
+ },
854
+ set(key, value) {
855
+ if (!isBrowser) return;
856
+ try {
857
+ if (value === null) window.localStorage.removeItem(key);
858
+ else window.localStorage.setItem(key, value);
859
+ } catch {
860
+ }
861
+ }
862
+ };
863
+ var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
864
+ var cookieBackend = {
865
+ get(key) {
866
+ if (!isBrowser) return null;
867
+ try {
868
+ const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
869
+ const m = document.cookie.match(re);
870
+ return m ? decodeURIComponent(m[1]) : null;
871
+ } catch {
872
+ return null;
873
+ }
874
+ },
875
+ set(key, value) {
876
+ if (!isBrowser) return;
877
+ try {
878
+ const k = encodeURIComponent(key);
879
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
880
+ if (value === null) {
881
+ document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
304
882
  } else {
305
- data = await response.blob();
883
+ const v = encodeURIComponent(value);
884
+ document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax${secure}`;
306
885
  }
886
+ } catch {
307
887
  }
308
- const responseHeaders = {};
309
- response.headers.forEach((value, key) => {
310
- responseHeaders[key] = value;
311
- });
312
- return {
313
- data,
314
- status: response.status,
315
- statusText: response.statusText,
316
- headers: responseHeaders
317
- };
318
888
  }
319
889
  };
320
-
321
- // src/_api/generated/cfg_accounts/errors.ts
322
- var APIError = class extends Error {
323
- constructor(statusCode, statusText, response, url, message) {
324
- super(message || `HTTP ${statusCode}: ${statusText}`);
325
- this.statusCode = statusCode;
326
- this.statusText = statusText;
327
- this.response = response;
328
- this.url = url;
329
- this.name = "APIError";
890
+ var _storage = localStorageBackend;
891
+ var _storageMode = "localStorage";
892
+ function detectLocale() {
893
+ try {
894
+ if (typeof document !== "undefined") {
895
+ const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
896
+ if (m) return decodeURIComponent(m[1]);
897
+ }
898
+ if (typeof navigator !== "undefined" && navigator.language) {
899
+ return navigator.language;
900
+ }
901
+ } catch {
330
902
  }
331
- static {
332
- __name(this, "APIError");
903
+ return null;
904
+ }
905
+ __name(detectLocale, "detectLocale");
906
+ function defaultBaseUrl() {
907
+ try {
908
+ if (typeof process !== "undefined" && process.env) {
909
+ if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
910
+ return process.env.NEXT_PUBLIC_API_URL || "";
911
+ }
912
+ } catch {
333
913
  }
334
- /**
335
- * Get error details from response.
336
- * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
337
- */
338
- get details() {
339
- if (typeof this.response === "object" && this.response !== null) {
340
- return this.response;
914
+ return "";
915
+ }
916
+ __name(defaultBaseUrl, "defaultBaseUrl");
917
+ function defaultApiKey() {
918
+ try {
919
+ if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
920
+ return process.env.NEXT_PUBLIC_API_KEY;
341
921
  }
342
- return null;
922
+ } catch {
343
923
  }
924
+ return null;
925
+ }
926
+ __name(defaultApiKey, "defaultApiKey");
927
+ var _localeOverride = null;
928
+ var _apiKeyOverride = null;
929
+ var _baseUrlOverride = null;
930
+ var _withCredentials = true;
931
+ var _onUnauthorized = null;
932
+ var _refreshHandler = null;
933
+ var _refreshInflight = null;
934
+ var RETRY_MARKER = "X-Auth-Retry";
935
+ var _client = null;
936
+ function pushClientConfig() {
937
+ if (!_client) return;
938
+ _client.setConfig({
939
+ baseUrl: auth.getBaseUrl(),
940
+ credentials: _withCredentials ? "include" : "same-origin"
941
+ });
942
+ }
943
+ __name(pushClientConfig, "pushClientConfig");
944
+ var auth = {
945
+ // ── Storage mode ──────────────────────────────────────────────────
946
+ getStorageMode() {
947
+ return _storageMode;
948
+ },
949
+ setStorageMode(mode) {
950
+ _storageMode = mode;
951
+ _storage = mode === "cookie" ? cookieBackend : localStorageBackend;
952
+ },
953
+ // ── Bearer token ──────────────────────────────────────────────────
954
+ getToken() {
955
+ return _storage.get(ACCESS_KEY);
956
+ },
957
+ setToken(token) {
958
+ _storage.set(ACCESS_KEY, token);
959
+ },
960
+ getRefreshToken() {
961
+ return _storage.get(REFRESH_KEY);
962
+ },
963
+ setRefreshToken(token) {
964
+ _storage.set(REFRESH_KEY, token);
965
+ },
966
+ clearTokens() {
967
+ _storage.set(ACCESS_KEY, null);
968
+ _storage.set(REFRESH_KEY, null);
969
+ },
970
+ isAuthenticated() {
971
+ return _storage.get(ACCESS_KEY) !== null;
972
+ },
973
+ // ── API key ───────────────────────────────────────────────────────
974
+ getApiKey() {
975
+ return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
976
+ },
977
+ setApiKey(key) {
978
+ _apiKeyOverride = key;
979
+ },
980
+ setApiKeyPersist(key) {
981
+ _apiKeyOverride = key;
982
+ _storage.set(API_KEY_KEY, key);
983
+ },
984
+ clearApiKey() {
985
+ _apiKeyOverride = null;
986
+ _storage.set(API_KEY_KEY, null);
987
+ },
988
+ // ── Locale ────────────────────────────────────────────────────────
989
+ getLocale() {
990
+ return _localeOverride ?? detectLocale();
991
+ },
992
+ setLocale(locale) {
993
+ _localeOverride = locale;
994
+ },
995
+ // ── Base URL ──────────────────────────────────────────────────────
996
+ getBaseUrl() {
997
+ const url = _baseUrlOverride ?? defaultBaseUrl();
998
+ return url.replace(/\/$/, "");
999
+ },
1000
+ setBaseUrl(url) {
1001
+ _baseUrlOverride = url ? url.replace(/\/$/, "") : null;
1002
+ pushClientConfig();
1003
+ },
1004
+ // ── Credentials toggle ────────────────────────────────────────────
1005
+ getWithCredentials() {
1006
+ return _withCredentials;
1007
+ },
1008
+ setWithCredentials(value) {
1009
+ _withCredentials = value;
1010
+ pushClientConfig();
1011
+ },
1012
+ // ── 401 handler ───────────────────────────────────────────────────
344
1013
  /**
345
- * Get field-specific validation errors from DRF.
346
- * Returns: { "field_name": ["error1", "error2"], ... }
1014
+ * Fired when the server returns 401 AND no refresh path recovers it
1015
+ * (no refresh token, no refresh handler, refresh failed, or retry
1016
+ * still 401). The app should clear local state and redirect to login.
1017
+ *
1018
+ * NOT fired for 401 that gets transparently recovered by the refresh
1019
+ * handler — those are invisible to callers.
347
1020
  */
348
- get fieldErrors() {
349
- const details = this.details;
350
- if (!details) return null;
351
- const fieldErrors = {};
352
- for (const [key, value] of Object.entries(details)) {
353
- if (Array.isArray(value)) {
354
- fieldErrors[key] = value;
355
- }
356
- }
357
- return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
358
- }
1021
+ onUnauthorized(cb) {
1022
+ _onUnauthorized = cb;
1023
+ },
359
1024
  /**
360
- * Get single error message from DRF.
361
- * Checks for "detail", "message", or first field error.
1025
+ * Register the refresh strategy. The handler receives the current
1026
+ * refresh token and must call your refresh endpoint, returning
1027
+ * `{ access, refresh? }` on success or `null` on failure.
1028
+ *
1029
+ * @example
1030
+ * auth.setRefreshHandler(async (refresh) => {
1031
+ * const { data } = await Auth.tokenRefreshCreate({ body: { refresh } });
1032
+ * return data ? { access: data.access, refresh: data.refresh } : null;
1033
+ * });
362
1034
  */
363
- get errorMessage() {
364
- const details = this.details;
365
- if (!details) return this.message;
366
- if (details.detail) {
367
- return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
1035
+ setRefreshHandler(fn) {
1036
+ _refreshHandler = fn;
1037
+ }
1038
+ };
1039
+ async function tryRefresh() {
1040
+ if (_refreshInflight) return _refreshInflight;
1041
+ if (!_refreshHandler) return null;
1042
+ const refresh = auth.getRefreshToken();
1043
+ if (!refresh) return null;
1044
+ _refreshInflight = (async () => {
1045
+ try {
1046
+ const result = await _refreshHandler(refresh);
1047
+ if (!result?.access) return null;
1048
+ auth.setToken(result.access);
1049
+ if (result.refresh) auth.setRefreshToken(result.refresh);
1050
+ return result.access;
1051
+ } catch {
1052
+ return null;
1053
+ } finally {
1054
+ _refreshInflight = null;
1055
+ }
1056
+ })();
1057
+ return _refreshInflight;
1058
+ }
1059
+ __name(tryRefresh, "tryRefresh");
1060
+ function installAuthOnClient(client2) {
1061
+ if (_client) return;
1062
+ _client = client2;
1063
+ client2.setConfig({
1064
+ baseUrl: auth.getBaseUrl(),
1065
+ credentials: _withCredentials ? "include" : "same-origin"
1066
+ });
1067
+ client2.interceptors.request.use((request) => {
1068
+ const token = auth.getToken();
1069
+ if (token) request.headers.set("Authorization", `Bearer ${token}`);
1070
+ const locale = auth.getLocale();
1071
+ if (locale) request.headers.set("Accept-Language", locale);
1072
+ const apiKey = auth.getApiKey();
1073
+ if (apiKey) request.headers.set("X-API-Key", apiKey);
1074
+ try {
1075
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
1076
+ if (tz) request.headers.set("X-Timezone", tz);
1077
+ } catch {
368
1078
  }
369
- if (details.error) {
370
- return String(details.error);
1079
+ request.headers.set("X-Client-Time", (/* @__PURE__ */ new Date()).toISOString());
1080
+ return request;
1081
+ });
1082
+ client2.interceptors.response.use(async (response, request) => {
1083
+ if (response.status !== 401) return response;
1084
+ if (request.headers.get(RETRY_MARKER)) {
1085
+ if (_onUnauthorized) {
1086
+ try {
1087
+ _onUnauthorized(response);
1088
+ } catch {
1089
+ }
1090
+ }
1091
+ return response;
371
1092
  }
372
- if (details.message) {
373
- return String(details.message);
1093
+ const newToken = await tryRefresh();
1094
+ if (!newToken) {
1095
+ if (_onUnauthorized) {
1096
+ try {
1097
+ _onUnauthorized(response);
1098
+ } catch {
1099
+ }
1100
+ }
1101
+ return response;
374
1102
  }
375
- const fieldErrors = this.fieldErrors;
376
- if (fieldErrors) {
377
- const firstField = Object.keys(fieldErrors)[0];
378
- if (firstField) {
379
- return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
1103
+ const retry = request.clone();
1104
+ retry.headers.set("Authorization", `Bearer ${newToken}`);
1105
+ retry.headers.set(RETRY_MARKER, "1");
1106
+ try {
1107
+ const retried = await fetch(retry);
1108
+ if (retried.status === 401 && _onUnauthorized) {
1109
+ try {
1110
+ _onUnauthorized(retried);
1111
+ } catch {
1112
+ }
1113
+ }
1114
+ return retried;
1115
+ } catch {
1116
+ if (_onUnauthorized) {
1117
+ try {
1118
+ _onUnauthorized(response);
1119
+ } catch {
1120
+ }
380
1121
  }
1122
+ return response;
381
1123
  }
382
- return this.message;
383
- }
384
- // Helper methods for common HTTP status codes
385
- get isValidationError() {
386
- return this.statusCode === 400;
387
- }
388
- get isAuthError() {
389
- return this.statusCode === 401;
390
- }
391
- get isPermissionError() {
392
- return this.statusCode === 403;
393
- }
394
- get isNotFoundError() {
395
- return this.statusCode === 404;
396
- }
397
- get isServerError() {
398
- return this.statusCode >= 500 && this.statusCode < 600;
399
- }
400
- };
401
- var NetworkError = class extends Error {
402
- constructor(message, url, originalError) {
403
- super(message);
404
- this.url = url;
405
- this.originalError = originalError;
406
- this.name = "NetworkError";
407
- }
408
- static {
409
- __name(this, "NetworkError");
410
- }
411
- };
1124
+ });
1125
+ }
1126
+ __name(installAuthOnClient, "installAuthOnClient");
412
1127
 
413
- // src/_api/generated/cfg_accounts/logger.ts
414
- var import_consola = require("consola");
415
- var DEFAULT_CONFIG = {
416
- enabled: process.env.NODE_ENV !== "production",
417
- logRequests: true,
418
- logResponses: true,
419
- logErrors: true,
420
- logBodies: true,
421
- logHeaders: false
422
- };
423
- var SENSITIVE_HEADERS = [
424
- "authorization",
425
- "cookie",
426
- "set-cookie",
427
- "x-api-key",
428
- "x-csrf-token"
429
- ];
430
- var APILogger = class {
1128
+ // src/_api/generated/client.gen.ts
1129
+ var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
1130
+ installAuthOnClient(client);
1131
+
1132
+ // src/_api/generated/sdk.gen.ts
1133
+ var CfgAccountsApiKey = class {
431
1134
  static {
432
- __name(this, "APILogger");
433
- }
434
- config;
435
- consola;
436
- constructor(config = {}) {
437
- this.config = { ...DEFAULT_CONFIG, ...config };
438
- this.consola = config.consola || (0, import_consola.createConsola)({
439
- level: this.config.enabled ? 4 : 0
440
- });
441
- }
442
- /**
443
- * Enable logging
444
- */
445
- enable() {
446
- this.config.enabled = true;
1135
+ __name(this, "CfgAccountsApiKey");
447
1136
  }
448
1137
  /**
449
- * Disable logging
450
- */
451
- disable() {
452
- this.config.enabled = false;
453
- }
454
- /**
455
- * Update configuration
1138
+ * Get API key details
1139
+ *
1140
+ * Retrieve the current user's API key (masked) and metadata.
456
1141
  */
457
- setConfig(config) {
458
- this.config = { ...this.config, ...config };
1142
+ static cfgAccountsApiKeyRetrieve(options) {
1143
+ return (options?.client ?? client).get({
1144
+ security: [{ scheme: "bearer", type: "http" }, {
1145
+ in: "cookie",
1146
+ name: "sessionid",
1147
+ type: "apiKey"
1148
+ }],
1149
+ url: "/cfg/accounts/api-key/",
1150
+ ...options
1151
+ });
459
1152
  }
460
1153
  /**
461
- * Filter sensitive headers
1154
+ * Regenerate API key
1155
+ *
1156
+ * Generate a new API key. The full key is returned only once.
462
1157
  */
463
- filterHeaders(headers) {
464
- if (!headers) return {};
465
- const filtered = {};
466
- Object.keys(headers).forEach((key) => {
467
- const lowerKey = key.toLowerCase();
468
- if (SENSITIVE_HEADERS.includes(lowerKey)) {
469
- filtered[key] = "***";
470
- } else {
471
- filtered[key] = headers[key] || "";
1158
+ static cfgAccountsApiKeyRegenerateCreate(options) {
1159
+ return (options.client ?? client).post({
1160
+ security: [{ scheme: "bearer", type: "http" }, {
1161
+ in: "cookie",
1162
+ name: "sessionid",
1163
+ type: "apiKey"
1164
+ }],
1165
+ url: "/cfg/accounts/api-key/regenerate/",
1166
+ ...options,
1167
+ headers: {
1168
+ "Content-Type": "application/json",
1169
+ ...options.headers
472
1170
  }
473
1171
  });
474
- return filtered;
475
- }
476
- /**
477
- * Log request
478
- */
479
- logRequest(request) {
480
- if (!this.config.enabled || !this.config.logRequests) return;
481
- const { method, url, headers, body } = request;
482
- this.consola.start(`${method} ${url}`);
483
- if (this.config.logHeaders && headers) {
484
- this.consola.debug("Headers:", this.filterHeaders(headers));
485
- }
486
- if (this.config.logBodies && body) {
487
- this.consola.debug("Body:", body);
488
- }
489
1172
  }
490
1173
  /**
491
- * Log response
492
- */
493
- logResponse(request, response) {
494
- if (!this.config.enabled || !this.config.logResponses) return;
495
- const { method, url } = request;
496
- const { status, statusText, data, duration } = response;
497
- const statusColor = status >= 500 ? "red" : status >= 400 ? "yellow" : status >= 300 ? "cyan" : "green";
498
- this.consola.success(
499
- `${method} ${url} ${status} ${statusText} (${duration}ms)`
500
- );
501
- if (this.config.logBodies && data) {
502
- this.consola.debug("Response:", data);
503
- }
504
- }
505
- /**
506
- * Log error
507
- */
508
- logError(request, error) {
509
- if (!this.config.enabled || !this.config.logErrors) return;
510
- const { method, url } = request;
511
- const { message, statusCode, fieldErrors, duration } = error;
512
- this.consola.error(
513
- `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
514
- );
515
- this.consola.error("Message:", message);
516
- if (fieldErrors && Object.keys(fieldErrors).length > 0) {
517
- this.consola.error("Field Errors:");
518
- Object.entries(fieldErrors).forEach(([field, errors]) => {
519
- errors.forEach((err) => {
520
- this.consola.error(` \u2022 ${field}: ${err}`);
521
- });
522
- });
523
- }
524
- }
525
- /**
526
- * Log general info
1174
+ * Test API key
1175
+ *
1176
+ * Test whether an API key is valid without consuming it.
527
1177
  */
528
- info(message, ...args) {
529
- if (!this.config.enabled) return;
530
- this.consola.info(message, ...args);
531
- }
532
- /**
533
- * Log warning
534
- */
535
- warn(message, ...args) {
536
- if (!this.config.enabled) return;
537
- this.consola.warn(message, ...args);
538
- }
539
- /**
540
- * Log error
541
- */
542
- error(message, ...args) {
543
- if (!this.config.enabled) return;
544
- this.consola.error(message, ...args);
545
- }
546
- /**
547
- * Log debug
548
- */
549
- debug(message, ...args) {
550
- if (!this.config.enabled) return;
551
- this.consola.debug(message, ...args);
552
- }
553
- /**
554
- * Log success
555
- */
556
- success(message, ...args) {
557
- if (!this.config.enabled) return;
558
- this.consola.success(message, ...args);
559
- }
560
- /**
561
- * Create a sub-logger with prefix
562
- */
563
- withTag(tag) {
564
- return this.consola.withTag(tag);
1178
+ static cfgAccountsApiKeyTestCreate(options) {
1179
+ return (options.client ?? client).post({
1180
+ security: [{ scheme: "bearer", type: "http" }, {
1181
+ in: "cookie",
1182
+ name: "sessionid",
1183
+ type: "apiKey"
1184
+ }],
1185
+ url: "/cfg/accounts/api-key/test/",
1186
+ ...options,
1187
+ headers: {
1188
+ "Content-Type": "application/json",
1189
+ ...options.headers
1190
+ }
1191
+ });
565
1192
  }
566
1193
  };
567
- var defaultLogger = new APILogger();
568
1194
 
569
- // src/_api/generated/cfg_accounts/retry.ts
570
- var import_p_retry = __toESM(require("p-retry"), 1);
571
- var DEFAULT_RETRY_CONFIG = {
572
- retries: 3,
573
- factor: 2,
574
- minTimeout: 1e3,
575
- maxTimeout: 6e4,
576
- randomize: true,
577
- onFailedAttempt: /* @__PURE__ */ __name(() => {
578
- }, "onFailedAttempt")
579
- };
580
- function shouldRetry(error) {
581
- if (error instanceof NetworkError) {
582
- return true;
583
- }
584
- if (error instanceof APIError) {
585
- const status = error.statusCode;
586
- if (status >= 500 && status < 600) {
587
- return true;
588
- }
589
- if (status === 429) {
590
- return true;
591
- }
592
- return false;
593
- }
594
- return true;
595
- }
596
- __name(shouldRetry, "shouldRetry");
597
- async function withRetry(fn, config) {
598
- const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
599
- return (0, import_p_retry.default)(
600
- async () => {
601
- try {
602
- return await fn();
603
- } catch (error) {
604
- if (!shouldRetry(error)) {
605
- throw new import_p_retry.AbortError(error);
606
- }
607
- throw error;
608
- }
609
- },
610
- {
611
- retries: finalConfig.retries,
612
- factor: finalConfig.factor,
613
- minTimeout: finalConfig.minTimeout,
614
- maxTimeout: finalConfig.maxTimeout,
615
- randomize: finalConfig.randomize,
616
- onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
617
- const pRetryError = error;
618
- finalConfig.onFailedAttempt({
619
- error: pRetryError,
620
- attemptNumber: pRetryError.attemptNumber,
621
- retriesLeft: pRetryError.retriesLeft
622
- });
623
- } : void 0
624
- }
625
- );
626
- }
627
- __name(withRetry, "withRetry");
1195
+ // src/_api/generated/_cfg_accounts/schemas/APIKeyRegenerate.ts
1196
+ var import_zod = require("zod");
1197
+ var APIKeyRegenerateSchema = import_zod.z.object({
1198
+ key: import_zod.z.string(),
1199
+ reissued_at: import_zod.z.string().datetime({ offset: true })
1200
+ });
628
1201
 
629
- // src/_api/generated/cfg_accounts/client.ts
630
- var APIClient = class {
631
- static {
632
- __name(this, "APIClient");
633
- }
634
- baseUrl;
635
- httpClient;
636
- logger = null;
637
- retryConfig = null;
638
- tokenGetter = null;
639
- // Sub-clients
640
- auth;
641
- oauth;
642
- user_profile;
643
- accounts;
644
- constructor(baseUrl, options) {
645
- this.baseUrl = baseUrl.replace(/\/$/, "");
646
- this.httpClient = options?.httpClient || new FetchAdapter();
647
- this.tokenGetter = options?.tokenGetter || null;
648
- if (options?.loggerConfig !== void 0) {
649
- this.logger = new APILogger(options.loggerConfig);
650
- }
651
- if (options?.retryConfig !== void 0) {
652
- this.retryConfig = options.retryConfig;
653
- }
654
- this.auth = new Auth(this);
655
- this.oauth = new Oauth(this);
656
- this.user_profile = new UserProfile(this);
657
- this.accounts = new Accounts(this);
658
- }
659
- /**
660
- * Get CSRF token from cookies (for SessionAuthentication).
661
- *
662
- * Returns null if cookie doesn't exist (JWT-only auth).
663
- */
664
- getCsrfToken() {
665
- const name = "csrftoken";
666
- const value = `; ${document.cookie}`;
667
- const parts = value.split(`; ${name}=`);
668
- if (parts.length === 2) {
669
- return parts.pop()?.split(";").shift() || null;
670
- }
671
- return null;
672
- }
673
- /**
674
- * Get the base URL for building streaming/download URLs.
675
- */
676
- getBaseUrl() {
677
- return this.baseUrl;
678
- }
679
- /**
680
- * Get JWT token for URL authentication (used in streaming endpoints).
681
- * Returns null if no token getter is configured or no token is available.
682
- */
683
- getToken() {
684
- return this.tokenGetter ? this.tokenGetter() : null;
685
- }
686
- /**
687
- * Make HTTP request with Django CSRF and session handling.
688
- * Automatically retries on network errors and 5xx server errors.
689
- */
690
- async request(method, path, options) {
691
- if (this.retryConfig) {
692
- return withRetry(() => this._makeRequest(method, path, options), {
693
- ...this.retryConfig,
694
- onFailedAttempt: /* @__PURE__ */ __name((info) => {
695
- if (this.logger) {
696
- this.logger.warn(
697
- `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
698
- );
699
- }
700
- this.retryConfig?.onFailedAttempt?.(info);
701
- }, "onFailedAttempt")
702
- });
703
- }
704
- return this._makeRequest(method, path, options);
705
- }
706
- /**
707
- * Internal request method (without retry wrapper).
708
- * Used by request() method with optional retry logic.
709
- */
710
- async _makeRequest(method, path, options) {
711
- const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
712
- const startTime = Date.now();
713
- const headers = {
714
- ...options?.headers || {}
715
- };
716
- if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
717
- headers["Content-Type"] = "application/json";
718
- }
719
- if (!headers["Authorization"]) {
720
- const token = this.getToken();
721
- if (token) {
722
- headers["Authorization"] = `Bearer ${token}`;
723
- }
724
- }
725
- if (this.logger) {
726
- this.logger.logRequest({
727
- method,
728
- url,
729
- headers,
730
- body: options?.formData || options?.body,
731
- timestamp: startTime
732
- });
733
- }
734
- try {
735
- const response = await this.httpClient.request({
736
- method,
737
- url,
738
- headers,
739
- params: options?.params,
740
- body: options?.body,
741
- formData: options?.formData,
742
- binaryBody: options?.binaryBody,
743
- responseType: options?.responseType
744
- });
745
- const duration = Date.now() - startTime;
746
- if (response.status >= 400) {
747
- const error = new APIError(
748
- response.status,
749
- response.statusText,
750
- response.data,
751
- url
752
- );
753
- if (this.logger) {
754
- this.logger.logError(
755
- {
756
- method,
757
- url,
758
- headers,
759
- body: options?.formData || options?.body,
760
- timestamp: startTime
761
- },
762
- {
763
- message: error.message,
764
- statusCode: response.status,
765
- duration,
766
- timestamp: Date.now()
767
- }
768
- );
769
- }
770
- throw error;
771
- }
772
- if (this.logger) {
773
- this.logger.logResponse(
774
- {
775
- method,
776
- url,
777
- headers,
778
- body: options?.formData || options?.body,
779
- timestamp: startTime
780
- },
1202
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRegenerateCreate.ts
1203
+ function useCfgAccountsApiKeyRegenerateCreate(config) {
1204
+ return (0, import_mutation.default)(
1205
+ ["cfg_accounts_api_key_regenerate_create"],
1206
+ async (_key, { arg }) => {
1207
+ const res = await CfgAccountsApiKey.cfgAccountsApiKeyRegenerateCreate({ ...arg, throwOnError: true });
1208
+ const data = res.data;
1209
+ const parsed = APIKeyRegenerateSchema.safeParse(data);
1210
+ if (!parsed.success) {
1211
+ console.warn(
1212
+ "[zod] response did not match schema",
781
1213
  {
782
- status: response.status,
783
- statusText: response.statusText,
784
- data: response.data,
785
- duration,
786
- timestamp: Date.now()
1214
+ operation: "cfg_accounts_api_key_regenerate_create",
1215
+ method: "POST",
1216
+ path: "/cfg/accounts/api-key/regenerate/",
1217
+ issues: parsed.error.issues,
1218
+ data
787
1219
  }
788
1220
  );
789
- }
790
- return response.data;
791
- } catch (error) {
792
- const duration = Date.now() - startTime;
793
- if (error instanceof APIError) {
794
- throw error;
795
- }
796
- let possiblyCors = false;
797
- if (error instanceof TypeError && typeof window !== "undefined") {
798
- try {
799
- const isCrossOrigin = (() => {
800
- try {
801
- return new URL(url).origin !== window.location.origin;
802
- } catch {
803
- return false;
804
- }
805
- })();
806
- if (isCrossOrigin) {
807
- const entries = performance.getEntriesByName(url, "resource");
808
- if (entries.length > 0) {
809
- const last = entries[entries.length - 1];
810
- possiblyCors = "responseStatus" in last && last.responseStatus === 0;
811
- }
1221
+ if (typeof window !== "undefined") {
1222
+ try {
1223
+ window.dispatchEvent(
1224
+ new CustomEvent("zod-validation-error", {
1225
+ detail: {
1226
+ operation: "cfg_accounts_api_key_regenerate_create",
1227
+ method: "POST",
1228
+ path: "/cfg/accounts/api-key/regenerate/",
1229
+ issues: parsed.error.issues,
1230
+ data,
1231
+ timestamp: /* @__PURE__ */ new Date()
1232
+ },
1233
+ bubbles: true,
1234
+ cancelable: false
1235
+ })
1236
+ );
1237
+ } catch {
812
1238
  }
813
- } catch {
814
1239
  }
1240
+ return data;
815
1241
  }
816
- if (this.logger) {
817
- this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
818
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
819
- if (possiblyCors) {
820
- this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
821
- }
822
- }
823
- if (typeof window !== "undefined") {
824
- try {
825
- window.dispatchEvent(new CustomEvent("network-error", {
826
- detail: {
827
- url,
828
- method,
829
- error: error instanceof Error ? error.message : String(error),
830
- possibly_cors: possiblyCors,
831
- timestamp: /* @__PURE__ */ new Date()
832
- },
833
- bubbles: true,
834
- cancelable: false
835
- }));
836
- } catch {
837
- }
838
- }
839
- const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
840
- if (this.logger) {
841
- this.logger.logError(
842
- {
843
- method,
844
- url,
845
- headers,
846
- body: options?.formData || options?.body,
847
- timestamp: startTime
848
- },
849
- {
850
- message: networkError.message,
851
- duration,
852
- timestamp: Date.now()
853
- }
854
- );
855
- }
856
- throw networkError;
857
- }
858
- }
859
- };
860
-
861
- // src/_api/generated/cfg_accounts/storage.ts
862
- var LocalStorageAdapter = class {
863
- static {
864
- __name(this, "LocalStorageAdapter");
865
- }
866
- logger;
867
- constructor(logger) {
868
- this.logger = logger;
869
- }
870
- getItem(key) {
871
- try {
872
- if (typeof window !== "undefined" && window.localStorage) {
873
- const value = localStorage.getItem(key);
874
- this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
875
- return value;
876
- }
877
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
878
- } catch (error) {
879
- this.logger?.error("LocalStorage.getItem failed:", error);
880
- }
881
- return null;
882
- }
883
- setItem(key, value) {
884
- try {
885
- if (typeof window !== "undefined" && window.localStorage) {
886
- localStorage.setItem(key, value);
887
- this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
888
- } else {
889
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
890
- }
891
- } catch (error) {
892
- this.logger?.error("LocalStorage.setItem failed:", error);
893
- }
894
- }
895
- removeItem(key) {
896
- try {
897
- if (typeof window !== "undefined" && window.localStorage) {
898
- localStorage.removeItem(key);
899
- this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
900
- } else {
901
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
902
- }
903
- } catch (error) {
904
- this.logger?.error("LocalStorage.removeItem failed:", error);
905
- }
906
- }
907
- };
1242
+ return parsed.data;
1243
+ },
1244
+ config
1245
+ );
1246
+ }
1247
+ __name(useCfgAccountsApiKeyRegenerateCreate, "useCfgAccountsApiKeyRegenerateCreate");
908
1248
 
909
- // src/_api/generated/cfg_accounts/enums.ts
910
- var OAuthConnectionProvider = /* @__PURE__ */ ((OAuthConnectionProvider2) => {
911
- OAuthConnectionProvider2["GITHUB"] = "github";
912
- return OAuthConnectionProvider2;
913
- })(OAuthConnectionProvider || {});
1249
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts
1250
+ var import_swr = __toESM(require("swr"), 1);
914
1251
 
915
- // src/_api/generated/cfg_accounts/_utils/schemas/AccountDeleteResponse.schema.ts
1252
+ // src/_api/generated/_cfg_accounts/schemas/APIKey.ts
916
1253
  var import_zod2 = require("zod");
917
- var AccountDeleteResponseSchema = import_zod2.z.object({
918
- success: import_zod2.z.boolean(),
919
- message: import_zod2.z.string()
920
- });
921
-
922
- // src/_api/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts
923
- var import_zod3 = require("zod");
924
- var CentrifugoTokenSchema = import_zod3.z.object({
925
- token: import_zod3.z.string(),
926
- centrifugo_url: import_zod3.z.string(),
927
- expires_at: import_zod3.z.string().datetime({ offset: true }),
928
- channels: import_zod3.z.array(import_zod3.z.string())
929
- });
930
-
931
- // src/_api/generated/cfg_accounts/_utils/schemas/CfgAccountsProfileAvatarCreateRequest.schema.ts
932
- var import_zod4 = require("zod");
933
- var CfgAccountsProfileAvatarCreateRequestSchema = import_zod4.z.object({
934
- avatar: import_zod4.z.union([import_zod4.z.instanceof(File), import_zod4.z.instanceof(Blob)])
935
- });
936
-
937
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts
938
- var import_zod5 = require("zod");
939
- var OAuthAuthorizeRequestRequestSchema = import_zod5.z.object({
940
- redirect_uri: import_zod5.z.string().optional(),
941
- source_url: import_zod5.z.string().optional()
942
- });
943
-
944
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts
945
- var import_zod6 = require("zod");
946
- var OAuthAuthorizeResponseSchema = import_zod6.z.object({
947
- authorization_url: import_zod6.z.string(),
948
- state: import_zod6.z.string()
949
- });
950
-
951
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts
952
- var import_zod7 = require("zod");
953
- var OAuthCallbackRequestRequestSchema = import_zod7.z.object({
954
- code: import_zod7.z.string().min(10).max(500),
955
- state: import_zod7.z.string().min(20).max(100),
956
- redirect_uri: import_zod7.z.string().optional()
957
- });
958
-
959
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts
960
- var import_zod8 = require("zod");
961
- var OAuthConnectionSchema = import_zod8.z.object({
962
- id: import_zod8.z.number().int(),
963
- provider: import_zod8.z.nativeEnum(OAuthConnectionProvider),
964
- provider_display: import_zod8.z.string(),
965
- provider_username: import_zod8.z.string(),
966
- provider_email: import_zod8.z.email(),
967
- provider_avatar_url: import_zod8.z.string(),
968
- connected_at: import_zod8.z.string().datetime({ offset: true }),
969
- last_login_at: import_zod8.z.string().datetime({ offset: true })
970
- });
971
-
972
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthDisconnectRequestRequest.schema.ts
973
- var import_zod9 = require("zod");
974
- var OAuthDisconnectRequestRequestSchema = import_zod9.z.object({
975
- provider: import_zod9.z.nativeEnum(OAuthConnectionProvider)
976
- });
977
-
978
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthError.schema.ts
979
- var import_zod10 = require("zod");
980
- var OAuthErrorSchema = import_zod10.z.object({
981
- error: import_zod10.z.string(),
982
- error_description: import_zod10.z.string().optional()
983
- });
984
-
985
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts
986
- var import_zod11 = require("zod");
987
- var OAuthProvidersResponseSchema = import_zod11.z.object({
988
- providers: import_zod11.z.array(import_zod11.z.record(import_zod11.z.string(), import_zod11.z.any()))
989
- });
990
-
991
- // src/_api/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts
992
- var import_zod12 = require("zod");
993
- var OAuthTokenResponseSchema = import_zod12.z.object({
994
- requires_2fa: import_zod12.z.boolean().optional(),
995
- session_id: import_zod12.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(),
996
- access: import_zod12.z.string().nullable().optional(),
997
- refresh: import_zod12.z.string().nullable().optional(),
998
- user: import_zod12.z.record(import_zod12.z.string(), import_zod12.z.any()).nullable().optional(),
999
- is_new_user: import_zod12.z.boolean(),
1000
- is_new_connection: import_zod12.z.boolean(),
1001
- should_prompt_2fa: import_zod12.z.boolean().optional()
1002
- });
1003
-
1004
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts
1005
- var import_zod13 = require("zod");
1006
- var OTPErrorResponseSchema = import_zod13.z.object({
1007
- error: import_zod13.z.string(),
1008
- error_code: import_zod13.z.string().nullable().optional(),
1009
- retry_after: import_zod13.z.number().int().nullable().optional()
1010
- });
1011
-
1012
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts
1013
- var import_zod14 = require("zod");
1014
- var OTPRequestRequestSchema = import_zod14.z.object({
1015
- identifier: import_zod14.z.string().min(1),
1016
- source_url: import_zod14.z.string().optional()
1017
- });
1018
-
1019
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts
1020
- var import_zod15 = require("zod");
1021
- var OTPRequestResponseSchema = import_zod15.z.object({
1022
- message: import_zod15.z.string()
1023
- });
1024
-
1025
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts
1026
- var import_zod16 = require("zod");
1027
- var OTPVerifyRequestSchema = import_zod16.z.object({
1028
- identifier: import_zod16.z.string().min(1),
1029
- otp: import_zod16.z.string().min(6).max(6),
1030
- source_url: import_zod16.z.string().optional()
1031
- });
1032
-
1033
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
1034
- var import_zod18 = require("zod");
1035
-
1036
- // src/_api/generated/cfg_accounts/_utils/schemas/User.schema.ts
1037
- var import_zod17 = require("zod");
1038
- var UserSchema = import_zod17.z.object({
1039
- id: import_zod17.z.number().int(),
1040
- email: import_zod17.z.email(),
1041
- first_name: import_zod17.z.string().max(50).optional(),
1042
- last_name: import_zod17.z.string().max(50).optional(),
1043
- full_name: import_zod17.z.string(),
1044
- initials: import_zod17.z.string(),
1045
- display_username: import_zod17.z.string(),
1046
- company: import_zod17.z.string().max(100).optional(),
1047
- phone: import_zod17.z.string().max(20).optional(),
1048
- position: import_zod17.z.string().max(100).optional(),
1049
- language: import_zod17.z.string().max(10).optional(),
1050
- avatar: import_zod17.z.string().nullable(),
1051
- is_staff: import_zod17.z.boolean(),
1052
- is_superuser: import_zod17.z.boolean(),
1053
- date_joined: import_zod17.z.string().datetime({ offset: true }),
1054
- last_login: import_zod17.z.string().datetime({ offset: true }).nullable(),
1055
- unanswered_messages_count: import_zod17.z.number().int(),
1056
- centrifugo: CentrifugoTokenSchema.nullable()
1057
- });
1058
-
1059
- // src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts
1060
- var OTPVerifyResponseSchema = import_zod18.z.object({
1061
- requires_2fa: import_zod18.z.boolean().optional(),
1062
- session_id: import_zod18.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(),
1063
- refresh: import_zod18.z.string().nullable().optional(),
1064
- access: import_zod18.z.string().nullable().optional(),
1065
- user: UserSchema.nullable().optional(),
1066
- should_prompt_2fa: import_zod18.z.boolean().optional()
1254
+ var APIKeySchema = import_zod2.z.object({
1255
+ key: import_zod2.z.string(),
1256
+ reissued_at: import_zod2.z.string().datetime({ offset: true }).nullable(),
1257
+ created_at: import_zod2.z.string().datetime({ offset: true })
1067
1258
  });
1068
1259
 
1069
- // src/_api/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts
1070
- var import_zod19 = require("zod");
1071
- var PatchedUserProfileUpdateRequestSchema = import_zod19.z.object({
1072
- first_name: import_zod19.z.string().max(50).optional(),
1073
- last_name: import_zod19.z.string().max(50).optional(),
1074
- company: import_zod19.z.string().max(100).optional(),
1075
- phone: import_zod19.z.string().max(20).optional(),
1076
- position: import_zod19.z.string().max(100).optional(),
1077
- language: import_zod19.z.string().max(10).optional()
1078
- });
1079
-
1080
- // src/_api/generated/cfg_accounts/_utils/schemas/TokenRefreshRequest.schema.ts
1081
- var import_zod20 = require("zod");
1082
- var TokenRefreshRequestSchema = import_zod20.z.object({
1083
- refresh: import_zod20.z.string().min(1)
1084
- });
1085
-
1086
- // src/_api/generated/cfg_accounts/_utils/schemas/UserProfileUpdateRequest.schema.ts
1087
- var import_zod21 = require("zod");
1088
- var UserProfileUpdateRequestSchema = import_zod21.z.object({
1089
- first_name: import_zod21.z.string().max(50).optional(),
1090
- last_name: import_zod21.z.string().max(50).optional(),
1091
- company: import_zod21.z.string().max(100).optional(),
1092
- phone: import_zod21.z.string().max(20).optional(),
1093
- position: import_zod21.z.string().max(100).optional(),
1094
- language: import_zod21.z.string().max(10).optional()
1095
- });
1096
-
1097
- // src/_api/generated/cfg_accounts/_utils/fetchers/accounts.ts
1098
- var import_consola2 = require("consola");
1099
- async function createAccountsOtpRequestCreate(data, client) {
1100
- const api = client || getAPIInstance();
1101
- const response = await api.accounts.otpRequestCreate(data);
1102
- try {
1103
- return OTPRequestResponseSchema.parse(response);
1104
- } catch (error) {
1105
- import_consola2.consola.error("\u274C Zod Validation Failed");
1106
- import_consola2.consola.box(`createAccountsOtpRequestCreate
1107
- Path: /cfg/accounts/otp/request/
1108
- Method: POST`);
1109
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1110
- import_consola2.consola.error("Validation Issues:");
1111
- error.issues.forEach((issue, index) => {
1112
- import_consola2.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1113
- import_consola2.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1114
- if (issue.expected) import_consola2.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1115
- if (issue.received) import_consola2.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1116
- });
1117
- }
1118
- import_consola2.consola.error("Response data:", response);
1119
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1120
- try {
1121
- const event = new CustomEvent("zod-validation-error", {
1122
- detail: {
1123
- operation: "createAccountsOtpRequestCreate",
1124
- path: "/cfg/accounts/otp/request/",
1125
- method: "POST",
1126
- error,
1127
- response,
1128
- timestamp: /* @__PURE__ */ new Date()
1129
- },
1130
- bubbles: true,
1131
- cancelable: false
1132
- });
1133
- window.dispatchEvent(event);
1134
- } catch (eventError) {
1135
- import_consola2.consola.warn("Failed to dispatch validation error event:", eventError);
1136
- }
1137
- }
1138
- throw error;
1139
- }
1140
- }
1141
- __name(createAccountsOtpRequestCreate, "createAccountsOtpRequestCreate");
1142
- async function createAccountsOtpVerifyCreate(data, client) {
1143
- const api = client || getAPIInstance();
1144
- const response = await api.accounts.otpVerifyCreate(data);
1145
- try {
1146
- return OTPVerifyResponseSchema.parse(response);
1147
- } catch (error) {
1148
- import_consola2.consola.error("\u274C Zod Validation Failed");
1149
- import_consola2.consola.box(`createAccountsOtpVerifyCreate
1150
- Path: /cfg/accounts/otp/verify/
1151
- Method: POST`);
1152
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1153
- import_consola2.consola.error("Validation Issues:");
1154
- error.issues.forEach((issue, index) => {
1155
- import_consola2.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1156
- import_consola2.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1157
- if (issue.expected) import_consola2.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1158
- if (issue.received) import_consola2.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1159
- });
1160
- }
1161
- import_consola2.consola.error("Response data:", response);
1162
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1163
- try {
1164
- const event = new CustomEvent("zod-validation-error", {
1165
- detail: {
1166
- operation: "createAccountsOtpVerifyCreate",
1167
- path: "/cfg/accounts/otp/verify/",
1168
- method: "POST",
1169
- error,
1170
- response,
1171
- timestamp: /* @__PURE__ */ new Date()
1172
- },
1173
- bubbles: true,
1174
- cancelable: false
1175
- });
1176
- window.dispatchEvent(event);
1177
- } catch (eventError) {
1178
- import_consola2.consola.warn("Failed to dispatch validation error event:", eventError);
1179
- }
1180
- }
1181
- throw error;
1182
- }
1183
- }
1184
- __name(createAccountsOtpVerifyCreate, "createAccountsOtpVerifyCreate");
1185
-
1186
- // src/_api/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts
1187
- var import_consola3 = require("consola");
1188
- async function getAccountsOauthConnectionsList(client) {
1189
- const api = client || getAPIInstance();
1190
- const response = await api.oauth.accountsOauthConnectionsList();
1191
- try {
1192
- return OAuthConnectionSchema.array().parse(response);
1193
- } catch (error) {
1194
- import_consola3.consola.error("\u274C Zod Validation Failed");
1195
- import_consola3.consola.box(`getAccountsOauthConnectionsList
1196
- Path: /cfg/accounts/oauth/connections/
1197
- Method: GET`);
1198
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1199
- import_consola3.consola.error("Validation Issues:");
1200
- error.issues.forEach((issue, index) => {
1201
- import_consola3.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1202
- import_consola3.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1203
- if (issue.expected) import_consola3.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1204
- if (issue.received) import_consola3.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1205
- });
1206
- }
1207
- import_consola3.consola.error("Response data:", response);
1208
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1209
- try {
1210
- const event = new CustomEvent("zod-validation-error", {
1211
- detail: {
1212
- operation: "getAccountsOauthConnectionsList",
1213
- path: "/cfg/accounts/oauth/connections/",
1214
- method: "GET",
1215
- error,
1216
- response,
1217
- timestamp: /* @__PURE__ */ new Date()
1218
- },
1219
- bubbles: true,
1220
- cancelable: false
1221
- });
1222
- window.dispatchEvent(event);
1223
- } catch (eventError) {
1224
- import_consola3.consola.warn("Failed to dispatch validation error event:", eventError);
1225
- }
1226
- }
1227
- throw error;
1228
- }
1229
- }
1230
- __name(getAccountsOauthConnectionsList, "getAccountsOauthConnectionsList");
1231
- async function createAccountsOauthDisconnectCreate(data, client) {
1232
- const api = client || getAPIInstance();
1233
- const response = await api.oauth.accountsOauthDisconnectCreate(data);
1234
- return response;
1235
- }
1236
- __name(createAccountsOauthDisconnectCreate, "createAccountsOauthDisconnectCreate");
1237
- async function createAccountsOauthGithubAuthorizeCreate(data, client) {
1238
- const api = client || getAPIInstance();
1239
- const response = await api.oauth.accountsOauthGithubAuthorizeCreate(data);
1240
- try {
1241
- return OAuthAuthorizeResponseSchema.parse(response);
1242
- } catch (error) {
1243
- import_consola3.consola.error("\u274C Zod Validation Failed");
1244
- import_consola3.consola.box(`createAccountsOauthGithubAuthorizeCreate
1245
- Path: /cfg/accounts/oauth/github/authorize/
1246
- Method: POST`);
1247
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1248
- import_consola3.consola.error("Validation Issues:");
1249
- error.issues.forEach((issue, index) => {
1250
- import_consola3.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1251
- import_consola3.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1252
- if (issue.expected) import_consola3.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1253
- if (issue.received) import_consola3.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1254
- });
1255
- }
1256
- import_consola3.consola.error("Response data:", response);
1257
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1258
- try {
1259
- const event = new CustomEvent("zod-validation-error", {
1260
- detail: {
1261
- operation: "createAccountsOauthGithubAuthorizeCreate",
1262
- path: "/cfg/accounts/oauth/github/authorize/",
1263
- method: "POST",
1264
- error,
1265
- response,
1266
- timestamp: /* @__PURE__ */ new Date()
1267
- },
1268
- bubbles: true,
1269
- cancelable: false
1270
- });
1271
- window.dispatchEvent(event);
1272
- } catch (eventError) {
1273
- import_consola3.consola.warn("Failed to dispatch validation error event:", eventError);
1274
- }
1275
- }
1276
- throw error;
1277
- }
1278
- }
1279
- __name(createAccountsOauthGithubAuthorizeCreate, "createAccountsOauthGithubAuthorizeCreate");
1280
- async function createAccountsOauthGithubCallbackCreate(data, client) {
1281
- const api = client || getAPIInstance();
1282
- const response = await api.oauth.accountsOauthGithubCallbackCreate(data);
1283
- try {
1284
- return OAuthTokenResponseSchema.parse(response);
1285
- } catch (error) {
1286
- import_consola3.consola.error("\u274C Zod Validation Failed");
1287
- import_consola3.consola.box(`createAccountsOauthGithubCallbackCreate
1288
- Path: /cfg/accounts/oauth/github/callback/
1289
- Method: POST`);
1290
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1291
- import_consola3.consola.error("Validation Issues:");
1292
- error.issues.forEach((issue, index) => {
1293
- import_consola3.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1294
- import_consola3.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1295
- if (issue.expected) import_consola3.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1296
- if (issue.received) import_consola3.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1297
- });
1298
- }
1299
- import_consola3.consola.error("Response data:", response);
1300
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1301
- try {
1302
- const event = new CustomEvent("zod-validation-error", {
1303
- detail: {
1304
- operation: "createAccountsOauthGithubCallbackCreate",
1305
- path: "/cfg/accounts/oauth/github/callback/",
1306
- method: "POST",
1307
- error,
1308
- response,
1309
- timestamp: /* @__PURE__ */ new Date()
1310
- },
1311
- bubbles: true,
1312
- cancelable: false
1313
- });
1314
- window.dispatchEvent(event);
1315
- } catch (eventError) {
1316
- import_consola3.consola.warn("Failed to dispatch validation error event:", eventError);
1317
- }
1318
- }
1319
- throw error;
1320
- }
1321
- }
1322
- __name(createAccountsOauthGithubCallbackCreate, "createAccountsOauthGithubCallbackCreate");
1323
- async function getAccountsOauthProvidersRetrieve(client) {
1324
- const api = client || getAPIInstance();
1325
- const response = await api.oauth.accountsOauthProvidersRetrieve();
1326
- try {
1327
- return OAuthProvidersResponseSchema.parse(response);
1328
- } catch (error) {
1329
- import_consola3.consola.error("\u274C Zod Validation Failed");
1330
- import_consola3.consola.box(`getAccountsOauthProvidersRetrieve
1331
- Path: /cfg/accounts/oauth/providers/
1332
- Method: GET`);
1333
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1334
- import_consola3.consola.error("Validation Issues:");
1335
- error.issues.forEach((issue, index) => {
1336
- import_consola3.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1337
- import_consola3.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1338
- if (issue.expected) import_consola3.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1339
- if (issue.received) import_consola3.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1340
- });
1341
- }
1342
- import_consola3.consola.error("Response data:", response);
1343
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1344
- try {
1345
- const event = new CustomEvent("zod-validation-error", {
1346
- detail: {
1347
- operation: "getAccountsOauthProvidersRetrieve",
1348
- path: "/cfg/accounts/oauth/providers/",
1349
- method: "GET",
1350
- error,
1351
- response,
1352
- timestamp: /* @__PURE__ */ new Date()
1353
- },
1354
- bubbles: true,
1355
- cancelable: false
1356
- });
1357
- window.dispatchEvent(event);
1358
- } catch (eventError) {
1359
- import_consola3.consola.warn("Failed to dispatch validation error event:", eventError);
1360
- }
1361
- }
1362
- throw error;
1363
- }
1364
- }
1365
- __name(getAccountsOauthProvidersRetrieve, "getAccountsOauthProvidersRetrieve");
1366
-
1367
- // src/_api/generated/cfg_accounts/_utils/fetchers/accounts__user_profile.ts
1368
- var import_consola4 = require("consola");
1369
- async function getAccountsProfileRetrieve(client) {
1370
- const api = client || getAPIInstance();
1371
- const response = await api.user_profile.accountsProfileRetrieve();
1372
- try {
1373
- return UserSchema.parse(response);
1374
- } catch (error) {
1375
- import_consola4.consola.error("\u274C Zod Validation Failed");
1376
- import_consola4.consola.box(`getAccountsProfileRetrieve
1377
- Path: /cfg/accounts/profile/
1378
- Method: GET`);
1379
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1380
- import_consola4.consola.error("Validation Issues:");
1381
- error.issues.forEach((issue, index) => {
1382
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1383
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1384
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1385
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1386
- });
1387
- }
1388
- import_consola4.consola.error("Response data:", response);
1389
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1390
- try {
1391
- const event = new CustomEvent("zod-validation-error", {
1392
- detail: {
1393
- operation: "getAccountsProfileRetrieve",
1394
- path: "/cfg/accounts/profile/",
1260
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts
1261
+ function useCfgAccountsApiKeyRetrieve(args, config) {
1262
+ const key = ["cfg_accounts_api_key_retrieve", args ?? {}];
1263
+ return (0, import_swr.default)(
1264
+ key,
1265
+ async () => {
1266
+ const res = await CfgAccountsApiKey.cfgAccountsApiKeyRetrieve({ ...args ?? {}, throwOnError: true });
1267
+ const data = res.data;
1268
+ const parsed = APIKeySchema.safeParse(data);
1269
+ if (!parsed.success) {
1270
+ console.warn(
1271
+ "[zod] response did not match schema",
1272
+ {
1273
+ operation: "cfg_accounts_api_key_retrieve",
1395
1274
  method: "GET",
1396
- error,
1397
- response,
1398
- timestamp: /* @__PURE__ */ new Date()
1399
- },
1400
- bubbles: true,
1401
- cancelable: false
1402
- });
1403
- window.dispatchEvent(event);
1404
- } catch (eventError) {
1405
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1406
- }
1407
- }
1408
- throw error;
1409
- }
1410
- }
1411
- __name(getAccountsProfileRetrieve, "getAccountsProfileRetrieve");
1412
- async function createAccountsProfileAvatarCreate(data, client) {
1413
- const api = client || getAPIInstance();
1414
- const response = await api.user_profile.accountsProfileAvatarCreate(data);
1415
- try {
1416
- return UserSchema.parse(response);
1417
- } catch (error) {
1418
- import_consola4.consola.error("\u274C Zod Validation Failed");
1419
- import_consola4.consola.box(`createAccountsProfileAvatarCreate
1420
- Path: /cfg/accounts/profile/avatar/
1421
- Method: POST`);
1422
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1423
- import_consola4.consola.error("Validation Issues:");
1424
- error.issues.forEach((issue, index) => {
1425
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1426
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1427
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1428
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1429
- });
1430
- }
1431
- import_consola4.consola.error("Response data:", response);
1432
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1433
- try {
1434
- const event = new CustomEvent("zod-validation-error", {
1435
- detail: {
1436
- operation: "createAccountsProfileAvatarCreate",
1437
- path: "/cfg/accounts/profile/avatar/",
1438
- method: "POST",
1439
- error,
1440
- response,
1441
- timestamp: /* @__PURE__ */ new Date()
1442
- },
1443
- bubbles: true,
1444
- cancelable: false
1445
- });
1446
- window.dispatchEvent(event);
1447
- } catch (eventError) {
1448
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1449
- }
1450
- }
1451
- throw error;
1452
- }
1453
- }
1454
- __name(createAccountsProfileAvatarCreate, "createAccountsProfileAvatarCreate");
1455
- async function createAccountsProfileDeleteCreate(client) {
1456
- const api = client || getAPIInstance();
1457
- const response = await api.user_profile.accountsProfileDeleteCreate();
1458
- try {
1459
- return AccountDeleteResponseSchema.parse(response);
1460
- } catch (error) {
1461
- import_consola4.consola.error("\u274C Zod Validation Failed");
1462
- import_consola4.consola.box(`createAccountsProfileDeleteCreate
1463
- Path: /cfg/accounts/profile/delete/
1464
- Method: POST`);
1465
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1466
- import_consola4.consola.error("Validation Issues:");
1467
- error.issues.forEach((issue, index) => {
1468
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1469
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1470
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1471
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1472
- });
1473
- }
1474
- import_consola4.consola.error("Response data:", response);
1475
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1476
- try {
1477
- const event = new CustomEvent("zod-validation-error", {
1478
- detail: {
1479
- operation: "createAccountsProfileDeleteCreate",
1480
- path: "/cfg/accounts/profile/delete/",
1481
- method: "POST",
1482
- error,
1483
- response,
1484
- timestamp: /* @__PURE__ */ new Date()
1485
- },
1486
- bubbles: true,
1487
- cancelable: false
1488
- });
1489
- window.dispatchEvent(event);
1490
- } catch (eventError) {
1491
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1492
- }
1493
- }
1494
- throw error;
1495
- }
1496
- }
1497
- __name(createAccountsProfileDeleteCreate, "createAccountsProfileDeleteCreate");
1498
- async function partialUpdateAccountsProfilePartialUpdate(data, client) {
1499
- const api = client || getAPIInstance();
1500
- const response = await api.user_profile.accountsProfilePartialUpdate(data);
1501
- try {
1502
- return UserSchema.parse(response);
1503
- } catch (error) {
1504
- import_consola4.consola.error("\u274C Zod Validation Failed");
1505
- import_consola4.consola.box(`partialUpdateAccountsProfilePartialUpdate
1506
- Path: /cfg/accounts/profile/partial/
1507
- Method: PUT`);
1508
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1509
- import_consola4.consola.error("Validation Issues:");
1510
- error.issues.forEach((issue, index) => {
1511
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1512
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1513
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1514
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1515
- });
1516
- }
1517
- import_consola4.consola.error("Response data:", response);
1518
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1519
- try {
1520
- const event = new CustomEvent("zod-validation-error", {
1521
- detail: {
1522
- operation: "partialUpdateAccountsProfilePartialUpdate",
1523
- path: "/cfg/accounts/profile/partial/",
1524
- method: "PUT",
1525
- error,
1526
- response,
1527
- timestamp: /* @__PURE__ */ new Date()
1528
- },
1529
- bubbles: true,
1530
- cancelable: false
1531
- });
1532
- window.dispatchEvent(event);
1533
- } catch (eventError) {
1534
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1535
- }
1536
- }
1537
- throw error;
1538
- }
1539
- }
1540
- __name(partialUpdateAccountsProfilePartialUpdate, "partialUpdateAccountsProfilePartialUpdate");
1541
- async function partialUpdateAccountsProfilePartialPartialUpdate(data, client) {
1542
- const api = client || getAPIInstance();
1543
- const response = await api.user_profile.accountsProfilePartialPartialUpdate(data);
1544
- try {
1545
- return UserSchema.parse(response);
1546
- } catch (error) {
1547
- import_consola4.consola.error("\u274C Zod Validation Failed");
1548
- import_consola4.consola.box(`partialUpdateAccountsProfilePartialPartialUpdate
1549
- Path: /cfg/accounts/profile/partial/
1550
- Method: PATCH`);
1551
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1552
- import_consola4.consola.error("Validation Issues:");
1553
- error.issues.forEach((issue, index) => {
1554
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1555
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1556
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1557
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1558
- });
1559
- }
1560
- import_consola4.consola.error("Response data:", response);
1561
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1562
- try {
1563
- const event = new CustomEvent("zod-validation-error", {
1564
- detail: {
1565
- operation: "partialUpdateAccountsProfilePartialPartialUpdate",
1566
- path: "/cfg/accounts/profile/partial/",
1567
- method: "PATCH",
1568
- error,
1569
- response,
1570
- timestamp: /* @__PURE__ */ new Date()
1571
- },
1572
- bubbles: true,
1573
- cancelable: false
1574
- });
1575
- window.dispatchEvent(event);
1576
- } catch (eventError) {
1577
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1578
- }
1579
- }
1580
- throw error;
1581
- }
1582
- }
1583
- __name(partialUpdateAccountsProfilePartialPartialUpdate, "partialUpdateAccountsProfilePartialPartialUpdate");
1584
- async function updateAccountsProfileUpdateUpdate(data, client) {
1585
- const api = client || getAPIInstance();
1586
- const response = await api.user_profile.accountsProfileUpdateUpdate(data);
1587
- try {
1588
- return UserSchema.parse(response);
1589
- } catch (error) {
1590
- import_consola4.consola.error("\u274C Zod Validation Failed");
1591
- import_consola4.consola.box(`updateAccountsProfileUpdateUpdate
1592
- Path: /cfg/accounts/profile/update/
1593
- Method: PUT`);
1594
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1595
- import_consola4.consola.error("Validation Issues:");
1596
- error.issues.forEach((issue, index) => {
1597
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1598
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1599
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1600
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1601
- });
1602
- }
1603
- import_consola4.consola.error("Response data:", response);
1604
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1605
- try {
1606
- const event = new CustomEvent("zod-validation-error", {
1607
- detail: {
1608
- operation: "updateAccountsProfileUpdateUpdate",
1609
- path: "/cfg/accounts/profile/update/",
1610
- method: "PUT",
1611
- error,
1612
- response,
1613
- timestamp: /* @__PURE__ */ new Date()
1614
- },
1615
- bubbles: true,
1616
- cancelable: false
1617
- });
1618
- window.dispatchEvent(event);
1619
- } catch (eventError) {
1620
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1621
- }
1622
- }
1623
- throw error;
1624
- }
1625
- }
1626
- __name(updateAccountsProfileUpdateUpdate, "updateAccountsProfileUpdateUpdate");
1627
- async function partialUpdateAccountsProfileUpdatePartialUpdate(data, client) {
1628
- const api = client || getAPIInstance();
1629
- const response = await api.user_profile.accountsProfileUpdatePartialUpdate(data);
1630
- try {
1631
- return UserSchema.parse(response);
1632
- } catch (error) {
1633
- import_consola4.consola.error("\u274C Zod Validation Failed");
1634
- import_consola4.consola.box(`partialUpdateAccountsProfileUpdatePartialUpdate
1635
- Path: /cfg/accounts/profile/update/
1636
- Method: PATCH`);
1637
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1638
- import_consola4.consola.error("Validation Issues:");
1639
- error.issues.forEach((issue, index) => {
1640
- import_consola4.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1641
- import_consola4.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1642
- if (issue.expected) import_consola4.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1643
- if (issue.received) import_consola4.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1644
- });
1645
- }
1646
- import_consola4.consola.error("Response data:", response);
1647
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1648
- try {
1649
- const event = new CustomEvent("zod-validation-error", {
1650
- detail: {
1651
- operation: "partialUpdateAccountsProfileUpdatePartialUpdate",
1652
- path: "/cfg/accounts/profile/update/",
1653
- method: "PATCH",
1654
- error,
1655
- response,
1656
- timestamp: /* @__PURE__ */ new Date()
1657
- },
1658
- bubbles: true,
1659
- cancelable: false
1660
- });
1661
- window.dispatchEvent(event);
1662
- } catch (eventError) {
1663
- import_consola4.consola.warn("Failed to dispatch validation error event:", eventError);
1275
+ path: "/cfg/accounts/api-key/",
1276
+ issues: parsed.error.issues,
1277
+ data
1278
+ }
1279
+ );
1280
+ if (typeof window !== "undefined") {
1281
+ try {
1282
+ window.dispatchEvent(
1283
+ new CustomEvent("zod-validation-error", {
1284
+ detail: {
1285
+ operation: "cfg_accounts_api_key_retrieve",
1286
+ method: "GET",
1287
+ path: "/cfg/accounts/api-key/",
1288
+ issues: parsed.error.issues,
1289
+ data,
1290
+ timestamp: /* @__PURE__ */ new Date()
1291
+ },
1292
+ bubbles: true,
1293
+ cancelable: false
1294
+ })
1295
+ );
1296
+ } catch {
1297
+ }
1298
+ }
1299
+ return data;
1664
1300
  }
1665
- }
1666
- throw error;
1667
- }
1301
+ return parsed.data;
1302
+ },
1303
+ config
1304
+ );
1668
1305
  }
1669
- __name(partialUpdateAccountsProfileUpdatePartialUpdate, "partialUpdateAccountsProfileUpdatePartialUpdate");
1306
+ __name(useCfgAccountsApiKeyRetrieve, "useCfgAccountsApiKeyRetrieve");
1670
1307
 
1671
- // src/_api/generated/cfg_accounts/index.ts
1672
- var TOKEN_KEY = "auth_token";
1673
- var REFRESH_TOKEN_KEY = "refresh_token";
1674
- function detectLocale() {
1675
- try {
1676
- if (typeof document !== "undefined") {
1677
- const match = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1678
- if (match) return match[1];
1679
- }
1680
- if (typeof navigator !== "undefined" && navigator.language) {
1681
- return navigator.language;
1682
- }
1683
- } catch {
1684
- }
1685
- return null;
1686
- }
1687
- __name(detectLocale, "detectLocale");
1688
- var API = class {
1689
- static {
1690
- __name(this, "API");
1691
- }
1692
- baseUrl;
1693
- _client;
1694
- _token = null;
1695
- _refreshToken = null;
1696
- _locale = null;
1697
- storage;
1698
- options;
1699
- // Sub-clients
1700
- auth;
1701
- oauth;
1702
- user_profile;
1703
- accounts;
1704
- constructor(baseUrl, options) {
1705
- this.baseUrl = baseUrl;
1706
- this.options = options;
1707
- const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
1708
- this.storage = options?.storage || new LocalStorageAdapter(logger);
1709
- this._locale = options?.locale || null;
1710
- this._loadTokensFromStorage();
1711
- this._client = new APIClient(this.baseUrl, {
1712
- httpClient: this.options?.httpClient,
1713
- retryConfig: this.options?.retryConfig,
1714
- loggerConfig: this.options?.loggerConfig,
1715
- tokenGetter: /* @__PURE__ */ __name(() => this.getToken(), "tokenGetter")
1716
- });
1717
- this._injectAuthHeader();
1718
- this.auth = this._client.auth;
1719
- this.oauth = this._client.oauth;
1720
- this.user_profile = this._client.user_profile;
1721
- this.accounts = this._client.accounts;
1722
- }
1723
- _loadTokensFromStorage() {
1724
- this._token = this.storage.getItem(TOKEN_KEY);
1725
- this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
1726
- }
1727
- _reinitClients() {
1728
- this._client = new APIClient(this.baseUrl, {
1729
- httpClient: this.options?.httpClient,
1730
- retryConfig: this.options?.retryConfig,
1731
- loggerConfig: this.options?.loggerConfig,
1732
- tokenGetter: /* @__PURE__ */ __name(() => this.getToken(), "tokenGetter")
1733
- });
1734
- this._injectAuthHeader();
1735
- this.auth = this._client.auth;
1736
- this.oauth = this._client.oauth;
1737
- this.user_profile = this._client.user_profile;
1738
- this.accounts = this._client.accounts;
1739
- }
1740
- _injectAuthHeader() {
1741
- const originalRequest = this._client.request.bind(this._client);
1742
- this._client.request = async (method, path, options) => {
1743
- const token = this.getToken();
1744
- const locale = this._locale || detectLocale();
1745
- const mergedOptions = {
1746
- ...options,
1747
- headers: {
1748
- ...options?.headers || {},
1749
- ...token ? { "Authorization": `Bearer ${token}` } : {},
1750
- ...locale ? { "Accept-Language": locale } : {}
1751
- }
1752
- };
1753
- return originalRequest(method, path, mergedOptions);
1754
- };
1755
- }
1756
- /**
1757
- * Get current JWT token
1758
- */
1759
- getToken() {
1760
- return this.storage.getItem(TOKEN_KEY);
1761
- }
1762
- /**
1763
- * Get current refresh token
1764
- */
1765
- getRefreshToken() {
1766
- return this.storage.getItem(REFRESH_TOKEN_KEY);
1767
- }
1768
- /**
1769
- * Set JWT token and refresh token
1770
- * @param token - JWT access token
1771
- * @param refreshToken - JWT refresh token (optional)
1772
- */
1773
- setToken(token, refreshToken) {
1774
- this._token = token;
1775
- this.storage.setItem(TOKEN_KEY, token);
1776
- if (refreshToken) {
1777
- this._refreshToken = refreshToken;
1778
- this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
1779
- }
1780
- this._reinitClients();
1781
- }
1782
- /**
1783
- * Clear all tokens
1784
- */
1785
- clearTokens() {
1786
- this._token = null;
1787
- this._refreshToken = null;
1788
- this.storage.removeItem(TOKEN_KEY);
1789
- this.storage.removeItem(REFRESH_TOKEN_KEY);
1790
- this._reinitClients();
1791
- }
1792
- /**
1793
- * Check if user is authenticated
1794
- */
1795
- isAuthenticated() {
1796
- return !!this.getToken();
1797
- }
1798
- /**
1799
- * Update base URL and reinitialize clients
1800
- * @param url - New base URL
1801
- */
1802
- setBaseUrl(url) {
1803
- this.baseUrl = url;
1804
- this._reinitClients();
1805
- }
1806
- /**
1807
- * Get current base URL
1808
- */
1809
- getBaseUrl() {
1810
- return this.baseUrl;
1811
- }
1812
- /**
1813
- * Set locale for Accept-Language header
1814
- * @param locale - Locale string (e.g. 'en', 'ko', 'ru') or null to clear
1815
- */
1816
- setLocale(locale) {
1817
- this._locale = locale;
1818
- }
1819
- /**
1820
- * Get current locale
1821
- */
1822
- getLocale() {
1823
- return this._locale;
1824
- }
1825
- /**
1826
- * Get OpenAPI schema path
1827
- * @returns Path to the OpenAPI schema JSON file
1828
- *
1829
- * Note: The OpenAPI schema is available in the schema.json file.
1830
- * You can load it dynamically using:
1831
- * ```typescript
1832
- * const schema = await fetch('./schema.json').then(r => r.json());
1833
- * // or using fs in Node.js:
1834
- * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
1835
- * ```
1836
- */
1837
- getSchemaPath() {
1838
- return "./schema.json";
1839
- }
1840
- };
1308
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyTestCreate.ts
1309
+ var import_mutation2 = __toESM(require("swr/mutation"), 1);
1841
1310
 
1842
- // src/_api/generated/cfg_accounts/api-instance.ts
1843
- var globalAPI = null;
1844
- var autoConfigAttempted = false;
1845
- function tryAutoConfigureFromEnv() {
1846
- if (autoConfigAttempted) return;
1847
- autoConfigAttempted = true;
1848
- if (globalAPI) return;
1849
- if (typeof process === "undefined" || !process.env) return;
1850
- const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
1851
- if (baseUrl) {
1852
- globalAPI = new API(baseUrl);
1853
- }
1854
- }
1855
- __name(tryAutoConfigureFromEnv, "tryAutoConfigureFromEnv");
1856
- function getAPIInstance() {
1857
- tryAutoConfigureFromEnv();
1858
- if (!globalAPI) {
1859
- throw new Error(
1860
- 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })\n\nOr set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
1861
- );
1862
- }
1863
- return globalAPI;
1864
- }
1865
- __name(getAPIInstance, "getAPIInstance");
1311
+ // src/_api/generated/_cfg_accounts/schemas/APIKeyTestResult.ts
1312
+ var import_zod3 = require("zod");
1313
+ var APIKeyTestResultSchema = import_zod3.z.object({
1314
+ valid: import_zod3.z.boolean(),
1315
+ user_id: import_zod3.z.string().nullable()
1316
+ });
1866
1317
 
1867
- // src/_api/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts
1868
- async function createAccountsTokenRefreshCreate(data, client) {
1869
- const api = client || getAPIInstance();
1870
- const response = await api.auth.accountsTokenRefreshCreate(data);
1871
- try {
1872
- return TokenRefreshSchema.parse(response);
1873
- } catch (error) {
1874
- import_consola5.consola.error("\u274C Zod Validation Failed");
1875
- import_consola5.consola.box(`createAccountsTokenRefreshCreate
1876
- Path: /cfg/accounts/token/refresh/
1877
- Method: POST`);
1878
- if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1879
- import_consola5.consola.error("Validation Issues:");
1880
- error.issues.forEach((issue, index) => {
1881
- import_consola5.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1882
- import_consola5.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1883
- if (issue.expected) import_consola5.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1884
- if (issue.received) import_consola5.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1885
- });
1886
- }
1887
- import_consola5.consola.error("Response data:", response);
1888
- if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1889
- try {
1890
- const event = new CustomEvent("zod-validation-error", {
1891
- detail: {
1892
- operation: "createAccountsTokenRefreshCreate",
1893
- path: "/cfg/accounts/token/refresh/",
1318
+ // src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyTestCreate.ts
1319
+ function useCfgAccountsApiKeyTestCreate(config) {
1320
+ return (0, import_mutation2.default)(
1321
+ ["cfg_accounts_api_key_test_create"],
1322
+ async (_key, { arg }) => {
1323
+ const res = await CfgAccountsApiKey.cfgAccountsApiKeyTestCreate({ ...arg, throwOnError: true });
1324
+ const data = res.data;
1325
+ const parsed = APIKeyTestResultSchema.safeParse(data);
1326
+ if (!parsed.success) {
1327
+ console.warn(
1328
+ "[zod] response did not match schema",
1329
+ {
1330
+ operation: "cfg_accounts_api_key_test_create",
1894
1331
  method: "POST",
1895
- error,
1896
- response,
1897
- timestamp: /* @__PURE__ */ new Date()
1898
- },
1899
- bubbles: true,
1900
- cancelable: false
1901
- });
1902
- window.dispatchEvent(event);
1903
- } catch (eventError) {
1904
- import_consola5.consola.warn("Failed to dispatch validation error event:", eventError);
1332
+ path: "/cfg/accounts/api-key/test/",
1333
+ issues: parsed.error.issues,
1334
+ data
1335
+ }
1336
+ );
1337
+ if (typeof window !== "undefined") {
1338
+ try {
1339
+ window.dispatchEvent(
1340
+ new CustomEvent("zod-validation-error", {
1341
+ detail: {
1342
+ operation: "cfg_accounts_api_key_test_create",
1343
+ method: "POST",
1344
+ path: "/cfg/accounts/api-key/test/",
1345
+ issues: parsed.error.issues,
1346
+ data,
1347
+ timestamp: /* @__PURE__ */ new Date()
1348
+ },
1349
+ bubbles: true,
1350
+ cancelable: false
1351
+ })
1352
+ );
1353
+ } catch {
1354
+ }
1355
+ }
1356
+ return data;
1905
1357
  }
1906
- }
1907
- throw error;
1908
- }
1909
- }
1910
- __name(createAccountsTokenRefreshCreate, "createAccountsTokenRefreshCreate");
1911
-
1912
- // src/_api/generated/cfg_accounts/_utils/hooks/accounts__auth.ts
1913
- function useCreateAccountsTokenRefreshCreate() {
1914
- const { mutate } = (0, import_swr.useSWRConfig)();
1915
- return async (data, client) => {
1916
- const result = await createAccountsTokenRefreshCreate(data, client);
1917
- mutate("cfg-accounts-token-refresh");
1918
- return result;
1919
- };
1920
- }
1921
- __name(useCreateAccountsTokenRefreshCreate, "useCreateAccountsTokenRefreshCreate");
1922
-
1923
- // src/_api/generated/cfg_accounts/_utils/hooks/accounts__oauth.ts
1924
- var import_swr2 = __toESM(require("swr"), 1);
1925
- var import_swr3 = require("swr");
1926
- function useAccountsOauthConnectionsList(client) {
1927
- return (0, import_swr2.default)(
1928
- "cfg-accounts-oauth-connections",
1929
- () => getAccountsOauthConnectionsList(client)
1930
- );
1931
- }
1932
- __name(useAccountsOauthConnectionsList, "useAccountsOauthConnectionsList");
1933
- function useCreateAccountsOauthDisconnectCreate() {
1934
- const { mutate } = (0, import_swr3.useSWRConfig)();
1935
- return async (data, client) => {
1936
- const result = await createAccountsOauthDisconnectCreate(data, client);
1937
- mutate("cfg-accounts-oauth-disconnect");
1938
- return result;
1939
- };
1940
- }
1941
- __name(useCreateAccountsOauthDisconnectCreate, "useCreateAccountsOauthDisconnectCreate");
1942
- function useCreateAccountsOauthGithubAuthorizeCreate() {
1943
- const { mutate } = (0, import_swr3.useSWRConfig)();
1944
- return async (data, client) => {
1945
- const result = await createAccountsOauthGithubAuthorizeCreate(data, client);
1946
- mutate("cfg-accounts-oauth-github-authorize");
1947
- return result;
1948
- };
1949
- }
1950
- __name(useCreateAccountsOauthGithubAuthorizeCreate, "useCreateAccountsOauthGithubAuthorizeCreate");
1951
- function useCreateAccountsOauthGithubCallbackCreate() {
1952
- const { mutate } = (0, import_swr3.useSWRConfig)();
1953
- return async (data, client) => {
1954
- const result = await createAccountsOauthGithubCallbackCreate(data, client);
1955
- mutate("cfg-accounts-oauth-github-callback");
1956
- return result;
1957
- };
1958
- }
1959
- __name(useCreateAccountsOauthGithubCallbackCreate, "useCreateAccountsOauthGithubCallbackCreate");
1960
- function useAccountsOauthProvidersRetrieve(client) {
1961
- return (0, import_swr2.default)(
1962
- "cfg-accounts-oauth-provider",
1963
- () => getAccountsOauthProvidersRetrieve(client)
1358
+ return parsed.data;
1359
+ },
1360
+ config
1964
1361
  );
1965
1362
  }
1966
- __name(useAccountsOauthProvidersRetrieve, "useAccountsOauthProvidersRetrieve");
1363
+ __name(useCfgAccountsApiKeyTestCreate, "useCfgAccountsApiKeyTestCreate");
1967
1364
 
1968
- // src/_api/generated/cfg_accounts/_utils/hooks/accounts__user_profile.ts
1969
- var import_swr4 = __toESM(require("swr"), 1);
1970
- var import_swr5 = require("swr");
1971
- function useAccountsProfileRetrieve(client) {
1972
- return (0, import_swr4.default)(
1973
- "cfg-accounts-profile",
1974
- () => getAccountsProfileRetrieve(client)
1975
- );
1976
- }
1977
- __name(useAccountsProfileRetrieve, "useAccountsProfileRetrieve");
1978
- function useCreateAccountsProfileAvatarCreate() {
1979
- const { mutate } = (0, import_swr5.useSWRConfig)();
1980
- return async (data, client) => {
1981
- const result = await createAccountsProfileAvatarCreate(data, client);
1982
- mutate("cfg-accounts-profile-avatar");
1983
- return result;
1984
- };
1985
- }
1986
- __name(useCreateAccountsProfileAvatarCreate, "useCreateAccountsProfileAvatarCreate");
1987
- function useCreateAccountsProfileDeleteCreate() {
1988
- const { mutate } = (0, import_swr5.useSWRConfig)();
1989
- return async (client) => {
1990
- const result = await createAccountsProfileDeleteCreate(client);
1991
- mutate("cfg-accounts-profile-delete");
1992
- return result;
1993
- };
1994
- }
1995
- __name(useCreateAccountsProfileDeleteCreate, "useCreateAccountsProfileDeleteCreate");
1996
- function usePartialUpdateAccountsProfilePartialUpdate() {
1997
- const { mutate } = (0, import_swr5.useSWRConfig)();
1998
- return async (data, client) => {
1999
- const result = await partialUpdateAccountsProfilePartialUpdate(data, client);
2000
- mutate("cfg-accounts-profile");
2001
- return result;
2002
- };
2003
- }
2004
- __name(usePartialUpdateAccountsProfilePartialUpdate, "usePartialUpdateAccountsProfilePartialUpdate");
2005
- function usePartialUpdateAccountsProfilePartialPartialUpdate() {
2006
- const { mutate } = (0, import_swr5.useSWRConfig)();
2007
- return async (data, client) => {
2008
- const result = await partialUpdateAccountsProfilePartialPartialUpdate(data, client);
2009
- mutate("cfg-accounts-profile-partial");
2010
- return result;
2011
- };
2012
- }
2013
- __name(usePartialUpdateAccountsProfilePartialPartialUpdate, "usePartialUpdateAccountsProfilePartialPartialUpdate");
2014
- function useUpdateAccountsProfileUpdateUpdate() {
2015
- const { mutate } = (0, import_swr5.useSWRConfig)();
2016
- return async (data, client) => {
2017
- const result = await updateAccountsProfileUpdateUpdate(data, client);
2018
- mutate("cfg-accounts-profile");
2019
- return result;
2020
- };
2021
- }
2022
- __name(useUpdateAccountsProfileUpdateUpdate, "useUpdateAccountsProfileUpdateUpdate");
2023
- function usePartialUpdateAccountsProfileUpdatePartialUpdate() {
2024
- const { mutate } = (0, import_swr5.useSWRConfig)();
2025
- return async (data, client) => {
2026
- const result = await partialUpdateAccountsProfileUpdatePartialUpdate(data, client);
2027
- mutate("cfg-accounts-profile");
2028
- return result;
2029
- };
2030
- }
2031
- __name(usePartialUpdateAccountsProfileUpdatePartialUpdate, "usePartialUpdateAccountsProfileUpdatePartialUpdate");
2032
-
2033
- // src/_api/generated/cfg_accounts/_utils/hooks/accounts.ts
2034
- var import_swr6 = require("swr");
2035
- function useCreateAccountsOtpRequestCreate() {
2036
- const { mutate } = (0, import_swr6.useSWRConfig)();
2037
- return async (data, client) => {
2038
- const result = await createAccountsOtpRequestCreate(data, client);
2039
- mutate("cfg-accounts-otp-request");
2040
- return result;
2041
- };
2042
- }
2043
- __name(useCreateAccountsOtpRequestCreate, "useCreateAccountsOtpRequestCreate");
2044
- function useCreateAccountsOtpVerifyCreate() {
2045
- const { mutate } = (0, import_swr6.useSWRConfig)();
2046
- return async (data, client) => {
2047
- const result = await createAccountsOtpVerifyCreate(data, client);
2048
- mutate("cfg-accounts-otp-verify");
2049
- return result;
1365
+ // src/hooks/useApiKey.ts
1366
+ function useApiKey() {
1367
+ const { data, isLoading, mutate } = useCfgAccountsApiKeyRetrieve();
1368
+ const { trigger: regenerateTrigger, isMutating: isRegenerating } = useCfgAccountsApiKeyRegenerateCreate();
1369
+ const { trigger: testTrigger, isMutating: isTesting } = useCfgAccountsApiKeyTestCreate();
1370
+ const [freshKey, setFreshKey] = (0, import_react.useState)(null);
1371
+ const apiKey = freshKey ?? (data?.key ?? null);
1372
+ const reissuedAt = data?.reissued_at ?? null;
1373
+ const createdAt = data?.created_at ?? null;
1374
+ const regenerate = (0, import_react.useCallback)(async () => {
1375
+ const result = await regenerateTrigger({});
1376
+ const newKey = result?.key;
1377
+ if (newKey) {
1378
+ setFreshKey(newKey);
1379
+ }
1380
+ }, [regenerateTrigger]);
1381
+ const testKey = (0, import_react.useCallback)(async (key) => {
1382
+ const result = await testTrigger({ body: { key } });
1383
+ const record = result;
1384
+ return {
1385
+ valid: Boolean(record?.valid),
1386
+ userId: record?.user_id ?? null
1387
+ };
1388
+ }, [testTrigger]);
1389
+ const refresh = (0, import_react.useCallback)(() => {
1390
+ setFreshKey(null);
1391
+ mutate();
1392
+ }, [mutate]);
1393
+ return {
1394
+ apiKey,
1395
+ reissuedAt,
1396
+ createdAt,
1397
+ isLoading,
1398
+ isRegenerating,
1399
+ isTesting,
1400
+ regenerate,
1401
+ testKey,
1402
+ refresh
2050
1403
  };
2051
1404
  }
2052
- __name(useCreateAccountsOtpVerifyCreate, "useCreateAccountsOtpVerifyCreate");
1405
+ __name(useApiKey, "useApiKey");
2053
1406
  //# sourceMappingURL=hooks.cjs.map