@djangocfg/api 2.1.327 → 2.1.331

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 (170) hide show
  1. package/dist/auth-server.cjs +185 -3471
  2. package/dist/auth-server.cjs.map +1 -1
  3. package/dist/auth-server.mjs +185 -3471
  4. package/dist/auth-server.mjs.map +1 -1
  5. package/dist/auth.cjs +952 -3305
  6. package/dist/auth.cjs.map +1 -1
  7. package/dist/auth.d.cts +35 -35
  8. package/dist/auth.d.ts +35 -35
  9. package/dist/auth.mjs +952 -3305
  10. package/dist/auth.mjs.map +1 -1
  11. package/dist/clients.cjs +90 -3396
  12. package/dist/clients.cjs.map +1 -1
  13. package/dist/clients.d.cts +4 -2508
  14. package/dist/clients.d.ts +4 -2508
  15. package/dist/clients.mjs +90 -3396
  16. package/dist/clients.mjs.map +1 -1
  17. package/dist/index.cjs +985 -3052
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1544 -1938
  20. package/dist/index.d.ts +1544 -1938
  21. package/dist/index.mjs +985 -3052
  22. package/dist/index.mjs.map +1 -1
  23. package/package.json +2 -2
  24. package/src/_api/generated/{cfg_centrifugo → _cfg_accounts}/api.ts +11 -55
  25. package/src/_api/generated/{cfg_totp → _cfg_accounts}/events.ts +3 -3
  26. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/index.ts +1 -1
  27. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthConnectionsList.ts +5 -6
  28. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthDisconnectCreate.ts +3 -3
  29. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +3 -3
  30. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +3 -3
  31. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOauthProvidersRetrieve.ts +5 -6
  32. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOtpRequestCreate.ts +3 -3
  33. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsOtpVerifyCreate.ts +3 -3
  34. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileAvatarCreate.ts +3 -3
  35. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileDeleteCreate.ts +3 -3
  36. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +3 -3
  37. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfilePartialUpdate.ts +3 -3
  38. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileRetrieve.ts +5 -6
  39. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +3 -3
  40. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsProfileUpdateUpdate.ts +3 -3
  41. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/hooks/useCfgAccountsTokenRefreshCreate.ts +3 -3
  42. package/src/_api/generated/{cfg_centrifugo → _cfg_accounts}/index.ts +3 -3
  43. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/AccountDeleteResponse.ts +3 -3
  44. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/CentrifugoToken.ts +4 -4
  45. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/CfgUserUpdateRequest.ts +4 -4
  46. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthAuthorizeRequestRequest.ts +2 -2
  47. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthAuthorizeResponse.ts +2 -2
  48. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthCallbackRequestRequest.ts +3 -3
  49. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthConnection.ts +6 -6
  50. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthDisconnectRequestRequest.ts +2 -2
  51. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthError.ts +2 -2
  52. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthProvidersResponse.ts +3 -3
  53. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OAuthTokenResponse.ts +7 -7
  54. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPErrorResponse.ts +2 -2
  55. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPRequestRequest.ts +2 -2
  56. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPRequestResponse.ts +2 -2
  57. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPVerifyRequest.ts +2 -2
  58. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/OTPVerifyResponse.ts +6 -6
  59. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/PatchedCfgUserUpdateRequest.ts +4 -4
  60. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/ProviderEnum.ts +2 -2
  61. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/TokenRefresh.ts +2 -2
  62. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/TokenRefreshRequest.ts +2 -2
  63. package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/User.ts +13 -13
  64. package/src/_api/generated/_cfg_accounts/sdk.gen.ts +5 -0
  65. package/src/_api/generated/_cfg_accounts/types.gen.ts +5 -0
  66. package/src/_api/generated/{cfg_totp → _cfg_centrifugo}/api.ts +11 -72
  67. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/events.ts +3 -3
  68. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/hooks/index.ts +1 -1
  69. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +5 -6
  70. package/src/_api/generated/{cfg_accounts → _cfg_centrifugo}/index.ts +3 -3
  71. package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/schemas/ConnectionTokenResponse.ts +4 -4
  72. package/src/_api/generated/_cfg_centrifugo/sdk.gen.ts +5 -0
  73. package/src/_api/generated/_cfg_centrifugo/types.gen.ts +5 -0
  74. package/src/_api/generated/{cfg_accounts → _cfg_totp}/api.ts +11 -78
  75. package/src/_api/generated/{cfg_accounts → _cfg_totp}/events.ts +3 -3
  76. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/index.ts +1 -1
  77. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +3 -3
  78. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpBackupCodesRetrieve.ts +5 -6
  79. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDevicesDestroy.ts +3 -3
  80. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDevicesRetrieve.ts +5 -6
  81. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpDisableCreate.ts +3 -3
  82. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpSetupConfirmCreate.ts +3 -3
  83. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpSetupCreate.ts +3 -3
  84. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpVerifyBackupCreate.ts +3 -3
  85. package/src/_api/generated/{cfg_totp → _cfg_totp}/hooks/useCfgTotpVerifyCreate.ts +3 -3
  86. package/src/_api/generated/{cfg_totp → _cfg_totp}/index.ts +3 -3
  87. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesRegenerateRequest.ts +2 -2
  88. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesRegenerateResponse.ts +2 -2
  89. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/BackupCodesStatus.ts +2 -2
  90. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/ConfirmSetupRequest.ts +3 -3
  91. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/ConfirmSetupResponse.ts +3 -3
  92. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceList.ts +6 -6
  93. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceListResponse.ts +2 -2
  94. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DeviceListStatusEnum.ts +2 -2
  95. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/DisableRequest.ts +2 -2
  96. package/src/_api/generated/_cfg_totp/schemas/SetupRequest.ts +11 -0
  97. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/SetupResponse.ts +4 -4
  98. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/TotpVerifyUser.ts +12 -12
  99. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyBackupRequest.ts +3 -3
  100. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyRequest.ts +3 -3
  101. package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/VerifyResponse.ts +4 -4
  102. package/src/_api/generated/_cfg_totp/sdk.gen.ts +5 -0
  103. package/src/_api/generated/_cfg_totp/types.gen.ts +5 -0
  104. package/src/_api/generated/index.ts +11 -13
  105. package/src/_api/generated/{cfg_accounts/sdk.gen.ts → sdk.gen.ts} +455 -1
  106. package/src/_api/generated/{cfg_accounts/types.gen.ts → types.gen.ts} +607 -77
  107. package/src/auth/context/AccountsContext.tsx +10 -10
  108. package/src/auth/context/AuthContext.tsx +1 -1
  109. package/src/auth/hooks/useDeleteAccount.ts +2 -1
  110. package/src/auth/hooks/useGithubAuth.ts +3 -2
  111. package/src/auth/hooks/useTokenRefresh.ts +2 -1
  112. package/src/auth/hooks/useTwoFactor.ts +4 -3
  113. package/src/auth/hooks/useTwoFactorSetup.ts +3 -2
  114. package/src/auth/hooks/useTwoFactorStatus.ts +4 -3
  115. package/src/auth/middlewares/tokenRefresh.ts +2 -1
  116. package/src/clients.ts +3 -3
  117. package/src/index.ts +22 -5
  118. package/src/server.ts +9 -9
  119. package/src/_api/generated/cfg_centrifugo/client/client.gen.ts +0 -280
  120. package/src/_api/generated/cfg_centrifugo/client/index.ts +0 -25
  121. package/src/_api/generated/cfg_centrifugo/client/types.gen.ts +0 -217
  122. package/src/_api/generated/cfg_centrifugo/client/utils.gen.ts +0 -318
  123. package/src/_api/generated/cfg_centrifugo/client.gen.ts +0 -16
  124. package/src/_api/generated/cfg_centrifugo/core/auth.gen.ts +0 -41
  125. package/src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts +0 -82
  126. package/src/_api/generated/cfg_centrifugo/core/params.gen.ts +0 -169
  127. package/src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts +0 -171
  128. package/src/_api/generated/cfg_centrifugo/core/queryKeySerializer.gen.ts +0 -117
  129. package/src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts +0 -242
  130. package/src/_api/generated/cfg_centrifugo/core/types.gen.ts +0 -104
  131. package/src/_api/generated/cfg_centrifugo/core/utils.gen.ts +0 -140
  132. package/src/_api/generated/cfg_centrifugo/sdk.gen.ts +0 -64
  133. package/src/_api/generated/cfg_centrifugo/types.gen.ts +0 -61
  134. package/src/_api/generated/cfg_totp/client/client.gen.ts +0 -280
  135. package/src/_api/generated/cfg_totp/client/index.ts +0 -25
  136. package/src/_api/generated/cfg_totp/client/types.gen.ts +0 -217
  137. package/src/_api/generated/cfg_totp/client/utils.gen.ts +0 -318
  138. package/src/_api/generated/cfg_totp/client.gen.ts +0 -16
  139. package/src/_api/generated/cfg_totp/core/auth.gen.ts +0 -41
  140. package/src/_api/generated/cfg_totp/core/bodySerializer.gen.ts +0 -82
  141. package/src/_api/generated/cfg_totp/core/params.gen.ts +0 -169
  142. package/src/_api/generated/cfg_totp/core/pathSerializer.gen.ts +0 -171
  143. package/src/_api/generated/cfg_totp/core/queryKeySerializer.gen.ts +0 -117
  144. package/src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts +0 -242
  145. package/src/_api/generated/cfg_totp/core/types.gen.ts +0 -104
  146. package/src/_api/generated/cfg_totp/core/utils.gen.ts +0 -140
  147. package/src/_api/generated/cfg_totp/schemas/SetupRequest.ts +0 -11
  148. package/src/_api/generated/cfg_totp/sdk.gen.ts +0 -432
  149. package/src/_api/generated/cfg_totp/types.gen.ts +0 -479
  150. /package/src/_api/generated/{cfg_accounts → _cfg_accounts}/schemas/index.ts +0 -0
  151. /package/src/_api/generated/{cfg_centrifugo → _cfg_centrifugo}/schemas/index.ts +0 -0
  152. /package/src/_api/generated/{cfg_totp → _cfg_totp}/schemas/index.ts +0 -0
  153. /package/src/_api/generated/{cfg_accounts/client → client}/client.gen.ts +0 -0
  154. /package/src/_api/generated/{cfg_accounts/client → client}/index.ts +0 -0
  155. /package/src/_api/generated/{cfg_accounts/client → client}/types.gen.ts +0 -0
  156. /package/src/_api/generated/{cfg_accounts/client → client}/utils.gen.ts +0 -0
  157. /package/src/_api/generated/{cfg_accounts/client.gen.ts → client.gen.ts} +0 -0
  158. /package/src/_api/generated/{cfg_accounts/core → core}/auth.gen.ts +0 -0
  159. /package/src/_api/generated/{cfg_accounts/core → core}/bodySerializer.gen.ts +0 -0
  160. /package/src/_api/generated/{cfg_accounts/core → core}/params.gen.ts +0 -0
  161. /package/src/_api/generated/{cfg_accounts/core → core}/pathSerializer.gen.ts +0 -0
  162. /package/src/_api/generated/{cfg_accounts/core → core}/queryKeySerializer.gen.ts +0 -0
  163. /package/src/_api/generated/{cfg_accounts/core → core}/serverSentEvents.gen.ts +0 -0
  164. /package/src/_api/generated/{cfg_accounts/core → core}/types.gen.ts +0 -0
  165. /package/src/_api/generated/{cfg_accounts/core → core}/utils.gen.ts +0 -0
  166. /package/src/_api/generated/{_shared → helpers}/errors.ts +0 -0
  167. /package/src/_api/generated/{_shared → helpers}/index.ts +0 -0
  168. /package/src/_api/generated/{_shared → helpers}/logger.ts +0 -0
  169. /package/src/_api/generated/{_shared → helpers}/storage.ts +0 -0
  170. /package/src/_api/generated/{_shared → helpers}/validation-events.ts +0 -0
@@ -50,37 +50,12 @@ var proxyMiddlewareConfig = {
50
50
  matcher: ["/media/:path*", "/api/:path*"]
51
51
  };
52
52
 
53
- // src/_api/generated/cfg_accounts/core/bodySerializer.gen.ts
54
- var serializeFormDataPair = /* @__PURE__ */ __name((data, key, value) => {
55
- if (typeof value === "string" || value instanceof Blob) {
56
- data.append(key, value);
57
- } else if (value instanceof Date) {
58
- data.append(key, value.toISOString());
59
- } else {
60
- data.append(key, JSON.stringify(value));
61
- }
62
- }, "serializeFormDataPair");
63
- var formDataBodySerializer = {
64
- bodySerializer: /* @__PURE__ */ __name((body) => {
65
- const data = new FormData();
66
- Object.entries(body).forEach(([key, value]) => {
67
- if (value === void 0 || value === null) {
68
- return;
69
- }
70
- if (Array.isArray(value)) {
71
- value.forEach((v) => serializeFormDataPair(data, key, v));
72
- } else {
73
- serializeFormDataPair(data, key, value);
74
- }
75
- });
76
- return data;
77
- }, "bodySerializer")
78
- };
53
+ // src/_api/generated/core/bodySerializer.gen.ts
79
54
  var jsonBodySerializer = {
80
55
  bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
81
56
  };
82
57
 
83
- // src/_api/generated/cfg_accounts/core/params.gen.ts
58
+ // src/_api/generated/core/params.gen.ts
84
59
  var extraPrefixesMap = {
85
60
  $body_: "body",
86
61
  $headers_: "headers",
@@ -89,7 +64,7 @@ var extraPrefixesMap = {
89
64
  };
90
65
  var extraPrefixes = Object.entries(extraPrefixesMap);
91
66
 
92
- // src/_api/generated/cfg_accounts/core/serverSentEvents.gen.ts
67
+ // src/_api/generated/core/serverSentEvents.gen.ts
93
68
  function createSseClient({
94
69
  onRequest,
95
70
  onSseError,
@@ -217,7 +192,7 @@ function createSseClient({
217
192
  }
218
193
  __name(createSseClient, "createSseClient");
219
194
 
220
- // src/_api/generated/cfg_accounts/core/pathSerializer.gen.ts
195
+ // src/_api/generated/core/pathSerializer.gen.ts
221
196
  var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
222
197
  switch (style) {
223
198
  case "label":
@@ -341,7 +316,7 @@ var serializeObjectParam = /* @__PURE__ */ __name(({
341
316
  return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
342
317
  }, "serializeObjectParam");
343
318
 
344
- // src/_api/generated/cfg_accounts/core/utils.gen.ts
319
+ // src/_api/generated/core/utils.gen.ts
345
320
  var PATH_PARAM_RE = /\{[^{}]+\}/g;
346
321
  var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
347
322
  let url = _url;
@@ -439,7 +414,7 @@ function getValidRequestBody(options) {
439
414
  }
440
415
  __name(getValidRequestBody, "getValidRequestBody");
441
416
 
442
- // src/_api/generated/cfg_accounts/core/auth.gen.ts
417
+ // src/_api/generated/core/auth.gen.ts
443
418
  var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
444
419
  const token = typeof callback === "function" ? await callback(auth) : callback;
445
420
  if (!token) {
@@ -454,7 +429,7 @@ var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
454
429
  return token;
455
430
  }, "getAuthToken");
456
431
 
457
- // src/_api/generated/cfg_accounts/client/utils.gen.ts
432
+ // src/_api/generated/client/utils.gen.ts
458
433
  var createQuerySerializer = /* @__PURE__ */ __name(({
459
434
  parameters = {},
460
435
  ...args
@@ -673,7 +648,7 @@ var createConfig = /* @__PURE__ */ __name((override = {}) => ({
673
648
  ...override
674
649
  }), "createConfig");
675
650
 
676
- // src/_api/generated/cfg_accounts/client/client.gen.ts
651
+ // src/_api/generated/client/client.gen.ts
677
652
  var createClient = /* @__PURE__ */ __name((config = {}) => {
678
653
  let _config = mergeConfigs(createConfig(), config);
679
654
  const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
@@ -871,10 +846,10 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
871
846
  };
872
847
  }, "createClient");
873
848
 
874
- // src/_api/generated/cfg_accounts/client.gen.ts
849
+ // src/_api/generated/client.gen.ts
875
850
  var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
876
851
 
877
- // src/_api/generated/_shared/storage.ts
852
+ // src/_api/generated/helpers/storage.ts
878
853
  var LocalStorageAdapter = class {
879
854
  static {
880
855
  __name(this, "LocalStorageAdapter");
@@ -910,7 +885,7 @@ var LocalStorageAdapter = class {
910
885
  }
911
886
  };
912
887
 
913
- // src/_api/generated/_shared/logger.ts
888
+ // src/_api/generated/helpers/logger.ts
914
889
  var import_consola = require("consola");
915
890
  var DEFAULT_CONFIG = {
916
891
  enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
@@ -1004,3431 +979,185 @@ var APILogger = class {
1004
979
  };
1005
980
  var defaultLogger = new APILogger();
1006
981
 
1007
- // src/_api/generated/cfg_accounts/sdk.gen.ts
1008
- var Cfg = class {
1009
- static {
1010
- __name(this, "Cfg");
1011
- }
1012
- /**
1013
- * List OAuth connections
1014
- *
1015
- * Get all OAuth connections for the current user.
1016
- */
1017
- static cfgAccountsOauthConnectionsList(options) {
1018
- return (options?.client ?? client).get({
1019
- security: [{ scheme: "bearer", type: "http" }],
1020
- url: "/cfg/accounts/oauth/connections/",
1021
- ...options
1022
- });
982
+ // src/_api/generated/_cfg_accounts/api.ts
983
+ var ACCESS_KEY = "cfg.access_token";
984
+ var REFRESH_KEY = "cfg.refresh_token";
985
+ function detectLocale() {
986
+ try {
987
+ if (typeof document !== "undefined") {
988
+ const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
989
+ if (m) return decodeURIComponent(m[1]);
990
+ }
991
+ if (typeof navigator !== "undefined" && navigator.language) {
992
+ return navigator.language;
993
+ }
994
+ } catch {
1023
995
  }
1024
- /**
1025
- * Disconnect OAuth provider
1026
- *
1027
- * Remove OAuth connection for the specified provider.
1028
- */
1029
- static cfgAccountsOauthDisconnectCreate(options) {
1030
- return (options.client ?? client).post({
1031
- security: [{ scheme: "bearer", type: "http" }],
1032
- url: "/cfg/accounts/oauth/disconnect/",
1033
- ...options,
1034
- headers: {
1035
- "Content-Type": "application/json",
1036
- ...options.headers
1037
- }
1038
- });
996
+ return null;
997
+ }
998
+ __name(detectLocale, "detectLocale");
999
+ var API = class {
1000
+ static {
1001
+ __name(this, "API");
1039
1002
  }
1040
- /**
1041
- * Start GitHub OAuth
1042
- *
1043
- * Generate GitHub OAuth authorization URL. Redirect user to this URL to start authentication.
1044
- */
1045
- static cfgAccountsOauthGithubAuthorizeCreate(options) {
1046
- return (options?.client ?? client).post({
1047
- url: "/cfg/accounts/oauth/github/authorize/",
1048
- ...options,
1049
- headers: {
1050
- "Content-Type": "application/json",
1051
- ...options?.headers
1052
- }
1003
+ baseUrl;
1004
+ storage;
1005
+ locale;
1006
+ apiKey;
1007
+ logger;
1008
+ constructor(baseUrl2, opts = {}) {
1009
+ this.baseUrl = baseUrl2.replace(/\/$/, "");
1010
+ this.storage = opts.storage ?? new LocalStorageAdapter();
1011
+ this.logger = new APILogger(opts.logger);
1012
+ this.locale = opts.locale ?? null;
1013
+ this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
1014
+ const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
1015
+ client.setConfig({ baseUrl: this.baseUrl, credentials });
1016
+ client.interceptors.request.use((request) => {
1017
+ const access = this.getToken();
1018
+ if (access) request.headers.set("Authorization", `Bearer ${access}`);
1019
+ const locale = this.locale ?? detectLocale();
1020
+ if (locale) request.headers.set("Accept-Language", locale);
1021
+ if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
1022
+ return request;
1053
1023
  });
1054
1024
  }
1055
- /**
1056
- * Complete GitHub OAuth
1057
- *
1058
- * Exchange authorization code for JWT tokens. Call this after GitHub redirects back with code.
1059
- */
1060
- static cfgAccountsOauthGithubCallbackCreate(options) {
1061
- return (options.client ?? client).post({
1062
- url: "/cfg/accounts/oauth/github/callback/",
1063
- ...options,
1064
- headers: {
1065
- "Content-Type": "application/json",
1066
- ...options.headers
1067
- }
1068
- });
1025
+ // ── Base URL ────────────────────────────────────────────────────────────
1026
+ getBaseUrl() {
1027
+ return this.baseUrl;
1069
1028
  }
1070
- /**
1071
- * List OAuth providers
1072
- *
1073
- * Get list of available OAuth providers for authentication.
1074
- */
1075
- static cfgAccountsOauthProvidersRetrieve(options) {
1076
- return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1029
+ setBaseUrl(url) {
1030
+ this.baseUrl = url.replace(/\/$/, "");
1031
+ client.setConfig({ baseUrl: this.baseUrl });
1077
1032
  }
1078
- /**
1079
- * Request OTP code to email.
1080
- */
1081
- static cfgAccountsOtpRequestCreate(options) {
1082
- return (options.client ?? client).post({
1083
- security: [{ scheme: "bearer", type: "http" }],
1084
- url: "/cfg/accounts/otp/request/",
1085
- ...options,
1086
- headers: {
1087
- "Content-Type": "application/json",
1088
- ...options.headers
1089
- }
1090
- });
1033
+ // ── Tokens ──────────────────────────────────────────────────────────────
1034
+ getToken() {
1035
+ return this.storage.getItem(ACCESS_KEY);
1091
1036
  }
1092
- /**
1093
- * Verify OTP code and return JWT tokens or 2FA session.
1094
- *
1095
- * If user has 2FA enabled:
1096
- * - Returns requires_2fa=True with session_id
1097
- * - Client must complete 2FA verification at /cfg/totp/verify/
1098
- *
1099
- * If user has no 2FA:
1100
- * - Returns JWT tokens and user data directly
1101
- */
1102
- static cfgAccountsOtpVerifyCreate(options) {
1103
- return (options.client ?? client).post({
1104
- security: [{ scheme: "bearer", type: "http" }],
1105
- url: "/cfg/accounts/otp/verify/",
1106
- ...options,
1107
- headers: {
1108
- "Content-Type": "application/json",
1109
- ...options.headers
1110
- }
1111
- });
1037
+ setToken(token) {
1038
+ if (token) this.storage.setItem(ACCESS_KEY, token);
1039
+ else this.storage.removeItem(ACCESS_KEY);
1112
1040
  }
1113
- /**
1114
- * Get current user profile
1115
- *
1116
- * Retrieve the current authenticated user's profile information.
1117
- */
1118
- static cfgAccountsProfileRetrieve(options) {
1119
- return (options?.client ?? client).get({
1120
- security: [{ scheme: "bearer", type: "http" }, {
1121
- in: "cookie",
1122
- name: "sessionid",
1123
- type: "apiKey"
1124
- }],
1125
- url: "/cfg/accounts/profile/",
1126
- ...options
1127
- });
1041
+ getRefreshToken() {
1042
+ return this.storage.getItem(REFRESH_KEY);
1128
1043
  }
1129
- /**
1130
- * Upload user avatar
1131
- *
1132
- * Upload avatar image for the current authenticated user. Accepts multipart/form-data with 'avatar' field.
1133
- */
1134
- static cfgAccountsProfileAvatarCreate(options) {
1135
- return (options?.client ?? client).post({
1136
- ...formDataBodySerializer,
1137
- security: [{ scheme: "bearer", type: "http" }],
1138
- url: "/cfg/accounts/profile/avatar/",
1139
- ...options,
1140
- headers: {
1141
- "Content-Type": null,
1142
- ...options?.headers
1143
- }
1144
- });
1044
+ setRefreshToken(token) {
1045
+ if (token) this.storage.setItem(REFRESH_KEY, token);
1046
+ else this.storage.removeItem(REFRESH_KEY);
1145
1047
  }
1146
- /**
1147
- * Delete user account
1148
- *
1149
- *
1150
- * Permanently delete the current user's account.
1151
- *
1152
- * This operation:
1153
- * - Deactivates the account (user cannot log in)
1154
- * - Anonymizes personal data (GDPR compliance)
1155
- * - Frees up the email address for re-registration
1156
- * - Preserves audit trail
1157
- *
1158
- * The account can be restored by an administrator if needed.
1159
- *
1160
- */
1161
- static cfgAccountsProfileDeleteCreate(options) {
1162
- return (options?.client ?? client).post({
1163
- security: [{ scheme: "bearer", type: "http" }, {
1164
- in: "cookie",
1165
- name: "sessionid",
1166
- type: "apiKey"
1167
- }],
1168
- url: "/cfg/accounts/profile/delete/",
1169
- ...options
1170
- });
1048
+ clearToken() {
1049
+ this.storage.removeItem(ACCESS_KEY);
1050
+ this.storage.removeItem(REFRESH_KEY);
1171
1051
  }
1172
- /**
1173
- * Partial update user profile
1174
- *
1175
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1176
- */
1177
- static cfgAccountsProfilePartialPartialUpdate(options) {
1178
- return (options?.client ?? client).patch({
1179
- security: [{ scheme: "bearer", type: "http" }, {
1180
- in: "cookie",
1181
- name: "sessionid",
1182
- type: "apiKey"
1183
- }],
1184
- url: "/cfg/accounts/profile/partial/",
1185
- ...options,
1186
- headers: {
1187
- "Content-Type": "application/json",
1188
- ...options?.headers
1189
- }
1190
- });
1052
+ isAuthenticated() {
1053
+ return this.getToken() !== null;
1191
1054
  }
1192
- /**
1193
- * Partial update user profile
1194
- *
1195
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1196
- */
1197
- static cfgAccountsProfilePartialUpdate(options) {
1198
- return (options?.client ?? client).put({
1199
- security: [{ scheme: "bearer", type: "http" }, {
1200
- in: "cookie",
1201
- name: "sessionid",
1202
- type: "apiKey"
1203
- }],
1204
- url: "/cfg/accounts/profile/partial/",
1205
- ...options,
1206
- headers: {
1207
- "Content-Type": "application/json",
1208
- ...options?.headers
1209
- }
1210
- });
1055
+ // ── Locale / API key ────────────────────────────────────────────────────
1056
+ getLocale() {
1057
+ return this.locale ?? detectLocale();
1211
1058
  }
1212
- /**
1213
- * Update user profile
1214
- *
1215
- * Update the current authenticated user's profile information.
1216
- */
1217
- static cfgAccountsProfileUpdatePartialUpdate(options) {
1218
- return (options?.client ?? client).patch({
1219
- security: [{ scheme: "bearer", type: "http" }, {
1220
- in: "cookie",
1221
- name: "sessionid",
1222
- type: "apiKey"
1223
- }],
1224
- url: "/cfg/accounts/profile/update/",
1225
- ...options,
1226
- headers: {
1227
- "Content-Type": "application/json",
1228
- ...options?.headers
1229
- }
1230
- });
1059
+ setLocale(locale) {
1060
+ this.locale = locale;
1231
1061
  }
1232
- /**
1233
- * Update user profile
1234
- *
1235
- * Update the current authenticated user's profile information.
1236
- */
1237
- static cfgAccountsProfileUpdateUpdate(options) {
1238
- return (options?.client ?? client).put({
1239
- security: [{ scheme: "bearer", type: "http" }, {
1240
- in: "cookie",
1241
- name: "sessionid",
1242
- type: "apiKey"
1243
- }],
1244
- url: "/cfg/accounts/profile/update/",
1245
- ...options,
1246
- headers: {
1247
- "Content-Type": "application/json",
1248
- ...options?.headers
1249
- }
1250
- });
1062
+ getApiKey() {
1063
+ return this.apiKey;
1251
1064
  }
1252
- /**
1253
- * Refresh JWT token.
1254
- */
1255
- static cfgAccountsTokenRefreshCreate(options) {
1256
- return (options.client ?? client).post({
1257
- url: "/cfg/accounts/token/refresh/",
1258
- ...options,
1259
- headers: {
1260
- "Content-Type": "application/json",
1261
- ...options.headers
1262
- }
1263
- });
1065
+ setApiKey(key) {
1066
+ this.apiKey = key;
1264
1067
  }
1265
1068
  };
1266
- var Accounts = class {
1267
- static {
1268
- __name(this, "Accounts");
1069
+
1070
+ // src/_api/generated/_cfg_centrifugo/api.ts
1071
+ var ACCESS_KEY2 = "cfg.access_token";
1072
+ var REFRESH_KEY2 = "cfg.refresh_token";
1073
+ function detectLocale2() {
1074
+ try {
1075
+ if (typeof document !== "undefined") {
1076
+ const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1077
+ if (m) return decodeURIComponent(m[1]);
1078
+ }
1079
+ if (typeof navigator !== "undefined" && navigator.language) {
1080
+ return navigator.language;
1081
+ }
1082
+ } catch {
1269
1083
  }
1270
- /**
1271
- * List OAuth connections
1272
- *
1273
- * Get all OAuth connections for the current user.
1274
- */
1275
- static cfgAccountsOauthConnectionsList(options) {
1276
- return (options?.client ?? client).get({
1277
- security: [{ scheme: "bearer", type: "http" }],
1278
- url: "/cfg/accounts/oauth/connections/",
1279
- ...options
1280
- });
1084
+ return null;
1085
+ }
1086
+ __name(detectLocale2, "detectLocale");
1087
+ var API2 = class {
1088
+ static {
1089
+ __name(this, "API");
1281
1090
  }
1282
- /**
1283
- * Disconnect OAuth provider
1284
- *
1285
- * Remove OAuth connection for the specified provider.
1286
- */
1287
- static cfgAccountsOauthDisconnectCreate(options) {
1288
- return (options.client ?? client).post({
1289
- security: [{ scheme: "bearer", type: "http" }],
1290
- url: "/cfg/accounts/oauth/disconnect/",
1291
- ...options,
1292
- headers: {
1293
- "Content-Type": "application/json",
1294
- ...options.headers
1295
- }
1091
+ baseUrl;
1092
+ storage;
1093
+ locale;
1094
+ apiKey;
1095
+ logger;
1096
+ constructor(baseUrl2, opts = {}) {
1097
+ this.baseUrl = baseUrl2.replace(/\/$/, "");
1098
+ this.storage = opts.storage ?? new LocalStorageAdapter();
1099
+ this.logger = new APILogger(opts.logger);
1100
+ this.locale = opts.locale ?? null;
1101
+ this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
1102
+ const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
1103
+ client.setConfig({ baseUrl: this.baseUrl, credentials });
1104
+ client.interceptors.request.use((request) => {
1105
+ const access = this.getToken();
1106
+ if (access) request.headers.set("Authorization", `Bearer ${access}`);
1107
+ const locale = this.locale ?? detectLocale2();
1108
+ if (locale) request.headers.set("Accept-Language", locale);
1109
+ if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
1110
+ return request;
1296
1111
  });
1297
1112
  }
1298
- /**
1299
- * Start GitHub OAuth
1300
- *
1301
- * Generate GitHub OAuth authorization URL. Redirect user to this URL to start authentication.
1302
- */
1303
- static cfgAccountsOauthGithubAuthorizeCreate(options) {
1304
- return (options?.client ?? client).post({
1305
- url: "/cfg/accounts/oauth/github/authorize/",
1306
- ...options,
1307
- headers: {
1308
- "Content-Type": "application/json",
1309
- ...options?.headers
1310
- }
1311
- });
1113
+ // ── Base URL ────────────────────────────────────────────────────────────
1114
+ getBaseUrl() {
1115
+ return this.baseUrl;
1312
1116
  }
1313
- /**
1314
- * Complete GitHub OAuth
1315
- *
1316
- * Exchange authorization code for JWT tokens. Call this after GitHub redirects back with code.
1317
- */
1318
- static cfgAccountsOauthGithubCallbackCreate(options) {
1319
- return (options.client ?? client).post({
1320
- url: "/cfg/accounts/oauth/github/callback/",
1321
- ...options,
1322
- headers: {
1323
- "Content-Type": "application/json",
1324
- ...options.headers
1325
- }
1326
- });
1117
+ setBaseUrl(url) {
1118
+ this.baseUrl = url.replace(/\/$/, "");
1119
+ client.setConfig({ baseUrl: this.baseUrl });
1327
1120
  }
1328
- /**
1329
- * List OAuth providers
1330
- *
1331
- * Get list of available OAuth providers for authentication.
1332
- */
1333
- static cfgAccountsOauthProvidersRetrieve(options) {
1334
- return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1121
+ // ── Tokens ──────────────────────────────────────────────────────────────
1122
+ getToken() {
1123
+ return this.storage.getItem(ACCESS_KEY2);
1335
1124
  }
1336
- /**
1337
- * Request OTP code to email.
1338
- */
1339
- static cfgAccountsOtpRequestCreate(options) {
1340
- return (options.client ?? client).post({
1341
- security: [{ scheme: "bearer", type: "http" }],
1342
- url: "/cfg/accounts/otp/request/",
1343
- ...options,
1344
- headers: {
1345
- "Content-Type": "application/json",
1346
- ...options.headers
1347
- }
1348
- });
1349
- }
1350
- /**
1351
- * Verify OTP code and return JWT tokens or 2FA session.
1352
- *
1353
- * If user has 2FA enabled:
1354
- * - Returns requires_2fa=True with session_id
1355
- * - Client must complete 2FA verification at /cfg/totp/verify/
1356
- *
1357
- * If user has no 2FA:
1358
- * - Returns JWT tokens and user data directly
1359
- */
1360
- static cfgAccountsOtpVerifyCreate(options) {
1361
- return (options.client ?? client).post({
1362
- security: [{ scheme: "bearer", type: "http" }],
1363
- url: "/cfg/accounts/otp/verify/",
1364
- ...options,
1365
- headers: {
1366
- "Content-Type": "application/json",
1367
- ...options.headers
1368
- }
1369
- });
1370
- }
1371
- /**
1372
- * Get current user profile
1373
- *
1374
- * Retrieve the current authenticated user's profile information.
1375
- */
1376
- static cfgAccountsProfileRetrieve(options) {
1377
- return (options?.client ?? client).get({
1378
- security: [{ scheme: "bearer", type: "http" }, {
1379
- in: "cookie",
1380
- name: "sessionid",
1381
- type: "apiKey"
1382
- }],
1383
- url: "/cfg/accounts/profile/",
1384
- ...options
1385
- });
1386
- }
1387
- /**
1388
- * Upload user avatar
1389
- *
1390
- * Upload avatar image for the current authenticated user. Accepts multipart/form-data with 'avatar' field.
1391
- */
1392
- static cfgAccountsProfileAvatarCreate(options) {
1393
- return (options?.client ?? client).post({
1394
- ...formDataBodySerializer,
1395
- security: [{ scheme: "bearer", type: "http" }],
1396
- url: "/cfg/accounts/profile/avatar/",
1397
- ...options,
1398
- headers: {
1399
- "Content-Type": null,
1400
- ...options?.headers
1401
- }
1402
- });
1403
- }
1404
- /**
1405
- * Delete user account
1406
- *
1407
- *
1408
- * Permanently delete the current user's account.
1409
- *
1410
- * This operation:
1411
- * - Deactivates the account (user cannot log in)
1412
- * - Anonymizes personal data (GDPR compliance)
1413
- * - Frees up the email address for re-registration
1414
- * - Preserves audit trail
1415
- *
1416
- * The account can be restored by an administrator if needed.
1417
- *
1418
- */
1419
- static cfgAccountsProfileDeleteCreate(options) {
1420
- return (options?.client ?? client).post({
1421
- security: [{ scheme: "bearer", type: "http" }, {
1422
- in: "cookie",
1423
- name: "sessionid",
1424
- type: "apiKey"
1425
- }],
1426
- url: "/cfg/accounts/profile/delete/",
1427
- ...options
1428
- });
1429
- }
1430
- /**
1431
- * Partial update user profile
1432
- *
1433
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1434
- */
1435
- static cfgAccountsProfilePartialPartialUpdate(options) {
1436
- return (options?.client ?? client).patch({
1437
- security: [{ scheme: "bearer", type: "http" }, {
1438
- in: "cookie",
1439
- name: "sessionid",
1440
- type: "apiKey"
1441
- }],
1442
- url: "/cfg/accounts/profile/partial/",
1443
- ...options,
1444
- headers: {
1445
- "Content-Type": "application/json",
1446
- ...options?.headers
1447
- }
1448
- });
1449
- }
1450
- /**
1451
- * Partial update user profile
1452
- *
1453
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1454
- */
1455
- static cfgAccountsProfilePartialUpdate(options) {
1456
- return (options?.client ?? client).put({
1457
- security: [{ scheme: "bearer", type: "http" }, {
1458
- in: "cookie",
1459
- name: "sessionid",
1460
- type: "apiKey"
1461
- }],
1462
- url: "/cfg/accounts/profile/partial/",
1463
- ...options,
1464
- headers: {
1465
- "Content-Type": "application/json",
1466
- ...options?.headers
1467
- }
1468
- });
1469
- }
1470
- /**
1471
- * Update user profile
1472
- *
1473
- * Update the current authenticated user's profile information.
1474
- */
1475
- static cfgAccountsProfileUpdatePartialUpdate(options) {
1476
- return (options?.client ?? client).patch({
1477
- security: [{ scheme: "bearer", type: "http" }, {
1478
- in: "cookie",
1479
- name: "sessionid",
1480
- type: "apiKey"
1481
- }],
1482
- url: "/cfg/accounts/profile/update/",
1483
- ...options,
1484
- headers: {
1485
- "Content-Type": "application/json",
1486
- ...options?.headers
1487
- }
1488
- });
1489
- }
1490
- /**
1491
- * Update user profile
1492
- *
1493
- * Update the current authenticated user's profile information.
1494
- */
1495
- static cfgAccountsProfileUpdateUpdate(options) {
1496
- return (options?.client ?? client).put({
1497
- security: [{ scheme: "bearer", type: "http" }, {
1498
- in: "cookie",
1499
- name: "sessionid",
1500
- type: "apiKey"
1501
- }],
1502
- url: "/cfg/accounts/profile/update/",
1503
- ...options,
1504
- headers: {
1505
- "Content-Type": "application/json",
1506
- ...options?.headers
1507
- }
1508
- });
1509
- }
1510
- /**
1511
- * Refresh JWT token.
1512
- */
1513
- static cfgAccountsTokenRefreshCreate(options) {
1514
- return (options.client ?? client).post({
1515
- url: "/cfg/accounts/token/refresh/",
1516
- ...options,
1517
- headers: {
1518
- "Content-Type": "application/json",
1519
- ...options.headers
1520
- }
1521
- });
1522
- }
1523
- };
1524
- var OAuth = class {
1525
- static {
1526
- __name(this, "OAuth");
1527
- }
1528
- /**
1529
- * List OAuth connections
1530
- *
1531
- * Get all OAuth connections for the current user.
1532
- */
1533
- static cfgAccountsOauthConnectionsList(options) {
1534
- return (options?.client ?? client).get({
1535
- security: [{ scheme: "bearer", type: "http" }],
1536
- url: "/cfg/accounts/oauth/connections/",
1537
- ...options
1538
- });
1539
- }
1540
- /**
1541
- * Disconnect OAuth provider
1542
- *
1543
- * Remove OAuth connection for the specified provider.
1544
- */
1545
- static cfgAccountsOauthDisconnectCreate(options) {
1546
- return (options.client ?? client).post({
1547
- security: [{ scheme: "bearer", type: "http" }],
1548
- url: "/cfg/accounts/oauth/disconnect/",
1549
- ...options,
1550
- headers: {
1551
- "Content-Type": "application/json",
1552
- ...options.headers
1553
- }
1554
- });
1555
- }
1556
- /**
1557
- * Start GitHub OAuth
1558
- *
1559
- * Generate GitHub OAuth authorization URL. Redirect user to this URL to start authentication.
1560
- */
1561
- static cfgAccountsOauthGithubAuthorizeCreate(options) {
1562
- return (options?.client ?? client).post({
1563
- url: "/cfg/accounts/oauth/github/authorize/",
1564
- ...options,
1565
- headers: {
1566
- "Content-Type": "application/json",
1567
- ...options?.headers
1568
- }
1569
- });
1570
- }
1571
- /**
1572
- * Complete GitHub OAuth
1573
- *
1574
- * Exchange authorization code for JWT tokens. Call this after GitHub redirects back with code.
1575
- */
1576
- static cfgAccountsOauthGithubCallbackCreate(options) {
1577
- return (options.client ?? client).post({
1578
- url: "/cfg/accounts/oauth/github/callback/",
1579
- ...options,
1580
- headers: {
1581
- "Content-Type": "application/json",
1582
- ...options.headers
1583
- }
1584
- });
1585
- }
1586
- /**
1587
- * List OAuth providers
1588
- *
1589
- * Get list of available OAuth providers for authentication.
1590
- */
1591
- static cfgAccountsOauthProvidersRetrieve(options) {
1592
- return (options?.client ?? client).get({ url: "/cfg/accounts/oauth/providers/", ...options });
1593
- }
1594
- };
1595
- var UserProfile = class {
1596
- static {
1597
- __name(this, "UserProfile");
1598
- }
1599
- /**
1600
- * Get current user profile
1601
- *
1602
- * Retrieve the current authenticated user's profile information.
1603
- */
1604
- static cfgAccountsProfileRetrieve(options) {
1605
- return (options?.client ?? client).get({
1606
- security: [{ scheme: "bearer", type: "http" }, {
1607
- in: "cookie",
1608
- name: "sessionid",
1609
- type: "apiKey"
1610
- }],
1611
- url: "/cfg/accounts/profile/",
1612
- ...options
1613
- });
1614
- }
1615
- /**
1616
- * Upload user avatar
1617
- *
1618
- * Upload avatar image for the current authenticated user. Accepts multipart/form-data with 'avatar' field.
1619
- */
1620
- static cfgAccountsProfileAvatarCreate(options) {
1621
- return (options?.client ?? client).post({
1622
- ...formDataBodySerializer,
1623
- security: [{ scheme: "bearer", type: "http" }],
1624
- url: "/cfg/accounts/profile/avatar/",
1625
- ...options,
1626
- headers: {
1627
- "Content-Type": null,
1628
- ...options?.headers
1629
- }
1630
- });
1631
- }
1632
- /**
1633
- * Delete user account
1634
- *
1635
- *
1636
- * Permanently delete the current user's account.
1637
- *
1638
- * This operation:
1639
- * - Deactivates the account (user cannot log in)
1640
- * - Anonymizes personal data (GDPR compliance)
1641
- * - Frees up the email address for re-registration
1642
- * - Preserves audit trail
1643
- *
1644
- * The account can be restored by an administrator if needed.
1645
- *
1646
- */
1647
- static cfgAccountsProfileDeleteCreate(options) {
1648
- return (options?.client ?? client).post({
1649
- security: [{ scheme: "bearer", type: "http" }, {
1650
- in: "cookie",
1651
- name: "sessionid",
1652
- type: "apiKey"
1653
- }],
1654
- url: "/cfg/accounts/profile/delete/",
1655
- ...options
1656
- });
1657
- }
1658
- /**
1659
- * Partial update user profile
1660
- *
1661
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1662
- */
1663
- static cfgAccountsProfilePartialPartialUpdate(options) {
1664
- return (options?.client ?? client).patch({
1665
- security: [{ scheme: "bearer", type: "http" }, {
1666
- in: "cookie",
1667
- name: "sessionid",
1668
- type: "apiKey"
1669
- }],
1670
- url: "/cfg/accounts/profile/partial/",
1671
- ...options,
1672
- headers: {
1673
- "Content-Type": "application/json",
1674
- ...options?.headers
1675
- }
1676
- });
1677
- }
1678
- /**
1679
- * Partial update user profile
1680
- *
1681
- * Partially update the current authenticated user's profile information. Supports avatar upload.
1682
- */
1683
- static cfgAccountsProfilePartialUpdate(options) {
1684
- return (options?.client ?? client).put({
1685
- security: [{ scheme: "bearer", type: "http" }, {
1686
- in: "cookie",
1687
- name: "sessionid",
1688
- type: "apiKey"
1689
- }],
1690
- url: "/cfg/accounts/profile/partial/",
1691
- ...options,
1692
- headers: {
1693
- "Content-Type": "application/json",
1694
- ...options?.headers
1695
- }
1696
- });
1697
- }
1698
- /**
1699
- * Update user profile
1700
- *
1701
- * Update the current authenticated user's profile information.
1702
- */
1703
- static cfgAccountsProfileUpdatePartialUpdate(options) {
1704
- return (options?.client ?? client).patch({
1705
- security: [{ scheme: "bearer", type: "http" }, {
1706
- in: "cookie",
1707
- name: "sessionid",
1708
- type: "apiKey"
1709
- }],
1710
- url: "/cfg/accounts/profile/update/",
1711
- ...options,
1712
- headers: {
1713
- "Content-Type": "application/json",
1714
- ...options?.headers
1715
- }
1716
- });
1717
- }
1718
- /**
1719
- * Update user profile
1720
- *
1721
- * Update the current authenticated user's profile information.
1722
- */
1723
- static cfgAccountsProfileUpdateUpdate(options) {
1724
- return (options?.client ?? client).put({
1725
- security: [{ scheme: "bearer", type: "http" }, {
1726
- in: "cookie",
1727
- name: "sessionid",
1728
- type: "apiKey"
1729
- }],
1730
- url: "/cfg/accounts/profile/update/",
1731
- ...options,
1732
- headers: {
1733
- "Content-Type": "application/json",
1734
- ...options?.headers
1735
- }
1736
- });
1737
- }
1738
- };
1739
- var Auth = class {
1740
- static {
1741
- __name(this, "Auth");
1742
- }
1743
- /**
1744
- * Refresh JWT token.
1745
- */
1746
- static cfgAccountsTokenRefreshCreate(options) {
1747
- return (options.client ?? client).post({
1748
- url: "/cfg/accounts/token/refresh/",
1749
- ...options,
1750
- headers: {
1751
- "Content-Type": "application/json",
1752
- ...options.headers
1753
- }
1754
- });
1755
- }
1756
- };
1757
-
1758
- // src/_api/generated/cfg_accounts/schemas/AccountDeleteResponse.ts
1759
- var import_zod = require("zod");
1760
- var AccountDeleteResponseSchema = import_zod.z.object({
1761
- success: import_zod.z.boolean(),
1762
- message: import_zod.z.string()
1763
- });
1764
-
1765
- // src/_api/generated/cfg_accounts/schemas/CentrifugoToken.ts
1766
- var import_zod2 = require("zod");
1767
- var CentrifugoTokenSchema = import_zod2.z.object({
1768
- token: import_zod2.z.string(),
1769
- centrifugo_url: import_zod2.z.string(),
1770
- expires_at: import_zod2.z.string().datetime({ offset: true }),
1771
- channels: import_zod2.z.array(import_zod2.z.string())
1772
- });
1773
-
1774
- // src/_api/generated/cfg_accounts/schemas/CfgUserUpdateRequest.ts
1775
- var import_zod3 = require("zod");
1776
- var CfgUserUpdateRequestSchema = import_zod3.z.object({
1777
- first_name: import_zod3.z.string().max(50).optional(),
1778
- last_name: import_zod3.z.string().max(50).optional(),
1779
- company: import_zod3.z.string().max(100).optional(),
1780
- phone: import_zod3.z.string().max(20).optional(),
1781
- position: import_zod3.z.string().max(100).optional(),
1782
- language: import_zod3.z.string().max(10).optional()
1783
- });
1784
-
1785
- // src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts
1786
- var import_zod4 = require("zod");
1787
- var OAuthAuthorizeRequestRequestSchema = import_zod4.z.object({
1788
- redirect_uri: import_zod4.z.string().optional(),
1789
- source_url: import_zod4.z.string().optional()
1790
- });
1791
-
1792
- // src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeResponse.ts
1793
- var import_zod5 = require("zod");
1794
- var OAuthAuthorizeResponseSchema = import_zod5.z.object({
1795
- authorization_url: import_zod5.z.string(),
1796
- state: import_zod5.z.string()
1797
- });
1798
-
1799
- // src/_api/generated/cfg_accounts/schemas/OAuthCallbackRequestRequest.ts
1800
- var import_zod6 = require("zod");
1801
- var OAuthCallbackRequestRequestSchema = import_zod6.z.object({
1802
- code: import_zod6.z.string().min(10).max(500),
1803
- state: import_zod6.z.string().min(20).max(100),
1804
- redirect_uri: import_zod6.z.string().optional()
1805
- });
1806
-
1807
- // src/_api/generated/cfg_accounts/schemas/OAuthConnection.ts
1808
- var import_zod8 = require("zod");
1809
-
1810
- // src/_api/generated/cfg_accounts/schemas/ProviderEnum.ts
1811
- var import_zod7 = require("zod");
1812
- var ProviderEnumSchema = import_zod7.z.enum(["github"]);
1813
-
1814
- // src/_api/generated/cfg_accounts/schemas/OAuthConnection.ts
1815
- var OAuthConnectionSchema = import_zod8.z.object({
1816
- id: import_zod8.z.number().int(),
1817
- provider: ProviderEnumSchema,
1818
- provider_display: import_zod8.z.string(),
1819
- provider_username: import_zod8.z.string(),
1820
- provider_email: import_zod8.z.email(),
1821
- provider_avatar_url: import_zod8.z.string(),
1822
- connected_at: import_zod8.z.string().datetime({ offset: true }),
1823
- last_login_at: import_zod8.z.string().datetime({ offset: true })
1824
- });
1825
-
1826
- // src/_api/generated/cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts
1827
- var import_zod9 = require("zod");
1828
- var OAuthDisconnectRequestRequestSchema = import_zod9.z.object({
1829
- provider: ProviderEnumSchema
1830
- });
1831
-
1832
- // src/_api/generated/cfg_accounts/schemas/OAuthError.ts
1833
- var import_zod10 = require("zod");
1834
- var OAuthErrorSchema = import_zod10.z.object({
1835
- error: import_zod10.z.string(),
1836
- error_description: import_zod10.z.string().optional()
1837
- });
1838
-
1839
- // src/_api/generated/cfg_accounts/schemas/OAuthProvidersResponse.ts
1840
- var import_zod11 = require("zod");
1841
- var OAuthProvidersResponseSchema = import_zod11.z.object({
1842
- providers: import_zod11.z.array(import_zod11.z.object({}))
1843
- });
1844
-
1845
- // src/_api/generated/cfg_accounts/schemas/OAuthTokenResponse.ts
1846
- var import_zod12 = require("zod");
1847
- var OAuthTokenResponseSchema = import_zod12.z.object({
1848
- requires_2fa: import_zod12.z.boolean().optional(),
1849
- 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(),
1850
- access: import_zod12.z.string().nullable().optional(),
1851
- refresh: import_zod12.z.string().nullable().optional(),
1852
- user: import_zod12.z.object({}).nullable().optional(),
1853
- is_new_user: import_zod12.z.boolean(),
1854
- is_new_connection: import_zod12.z.boolean(),
1855
- should_prompt_2fa: import_zod12.z.boolean().optional()
1856
- });
1857
-
1858
- // src/_api/generated/cfg_accounts/schemas/OTPErrorResponse.ts
1859
- var import_zod13 = require("zod");
1860
- var OTPErrorResponseSchema = import_zod13.z.object({
1861
- error: import_zod13.z.string(),
1862
- error_code: import_zod13.z.string().nullable().optional(),
1863
- retry_after: import_zod13.z.number().int().nullable().optional()
1864
- });
1865
-
1866
- // src/_api/generated/cfg_accounts/schemas/OTPRequestRequest.ts
1867
- var import_zod14 = require("zod");
1868
- var OTPRequestRequestSchema = import_zod14.z.object({
1869
- identifier: import_zod14.z.string().min(1),
1870
- source_url: import_zod14.z.string().optional()
1871
- });
1872
-
1873
- // src/_api/generated/cfg_accounts/schemas/OTPRequestResponse.ts
1874
- var import_zod15 = require("zod");
1875
- var OTPRequestResponseSchema = import_zod15.z.object({
1876
- message: import_zod15.z.string()
1877
- });
1878
-
1879
- // src/_api/generated/cfg_accounts/schemas/OTPVerifyRequest.ts
1880
- var import_zod16 = require("zod");
1881
- var OTPVerifyRequestSchema = import_zod16.z.object({
1882
- identifier: import_zod16.z.string().min(1),
1883
- otp: import_zod16.z.string().min(6).max(6),
1884
- source_url: import_zod16.z.string().optional()
1885
- });
1886
-
1887
- // src/_api/generated/cfg_accounts/schemas/OTPVerifyResponse.ts
1888
- var import_zod18 = require("zod");
1889
-
1890
- // src/_api/generated/cfg_accounts/schemas/User.ts
1891
- var import_zod17 = require("zod");
1892
- var UserSchema = import_zod17.z.object({
1893
- id: import_zod17.z.number().int(),
1894
- email: import_zod17.z.email(),
1895
- first_name: import_zod17.z.string().max(50).optional(),
1896
- last_name: import_zod17.z.string().max(50).optional(),
1897
- full_name: import_zod17.z.string(),
1898
- initials: import_zod17.z.string(),
1899
- display_username: import_zod17.z.string(),
1900
- company: import_zod17.z.string().max(100).optional(),
1901
- phone: import_zod17.z.string().max(20).optional(),
1902
- position: import_zod17.z.string().max(100).optional(),
1903
- language: import_zod17.z.string().max(10).optional(),
1904
- avatar: import_zod17.z.string().nullable(),
1905
- is_staff: import_zod17.z.boolean(),
1906
- is_superuser: import_zod17.z.boolean(),
1907
- date_joined: import_zod17.z.string().datetime({ offset: true }),
1908
- last_login: import_zod17.z.string().datetime({ offset: true }).nullable(),
1909
- unanswered_messages_count: import_zod17.z.number().int(),
1910
- centrifugo: CentrifugoTokenSchema.nullable()
1911
- });
1912
-
1913
- // src/_api/generated/cfg_accounts/schemas/OTPVerifyResponse.ts
1914
- var OTPVerifyResponseSchema = import_zod18.z.object({
1915
- requires_2fa: import_zod18.z.boolean().optional(),
1916
- 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(),
1917
- refresh: import_zod18.z.string().nullable().optional(),
1918
- access: import_zod18.z.string().nullable().optional(),
1919
- user: UserSchema.nullable().optional(),
1920
- should_prompt_2fa: import_zod18.z.boolean().optional()
1921
- });
1922
-
1923
- // src/_api/generated/cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts
1924
- var import_zod19 = require("zod");
1925
- var PatchedCfgUserUpdateRequestSchema = import_zod19.z.object({
1926
- first_name: import_zod19.z.string().max(50).optional(),
1927
- last_name: import_zod19.z.string().max(50).optional(),
1928
- company: import_zod19.z.string().max(100).optional(),
1929
- phone: import_zod19.z.string().max(20).optional(),
1930
- position: import_zod19.z.string().max(100).optional(),
1931
- language: import_zod19.z.string().max(10).optional()
1932
- });
1933
-
1934
- // src/_api/generated/cfg_accounts/schemas/TokenRefresh.ts
1935
- var import_zod20 = require("zod");
1936
- var TokenRefreshSchema = import_zod20.z.object({
1937
- access: import_zod20.z.string(),
1938
- refresh: import_zod20.z.string()
1939
- });
1940
-
1941
- // src/_api/generated/cfg_accounts/schemas/TokenRefreshRequest.ts
1942
- var import_zod21 = require("zod");
1943
- var TokenRefreshRequestSchema = import_zod21.z.object({
1944
- refresh: import_zod21.z.string().min(1)
1945
- });
1946
-
1947
- // src/_api/generated/_shared/validation-events.ts
1948
- function dispatchValidationError(detail) {
1949
- if (typeof window === "undefined") return;
1950
- try {
1951
- const event = new CustomEvent("zod-validation-error", {
1952
- detail,
1953
- bubbles: true,
1954
- cancelable: false
1955
- });
1956
- window.dispatchEvent(event);
1957
- } catch (error) {
1958
- console.warn("Failed to dispatch validation error event:", error);
1959
- }
1960
- }
1961
- __name(dispatchValidationError, "dispatchValidationError");
1962
-
1963
- // src/_api/generated/cfg_accounts/api.ts
1964
- var ACCESS_KEY = "cfg.access_token";
1965
- var REFRESH_KEY = "cfg.refresh_token";
1966
- var VALIDATION_ROUTES = [
1967
- { method: "POST", re: new RegExp("^/cfg/accounts/oauth/github/authorize/?$"), schema: OAuthAuthorizeResponseSchema, path: "/cfg/accounts/oauth/github/authorize/" },
1968
- { method: "POST", re: new RegExp("^/cfg/accounts/oauth/github/callback/?$"), schema: OAuthTokenResponseSchema, path: "/cfg/accounts/oauth/github/callback/" },
1969
- { method: "GET", re: new RegExp("^/cfg/accounts/oauth/providers/?$"), schema: OAuthProvidersResponseSchema, path: "/cfg/accounts/oauth/providers/" },
1970
- { method: "POST", re: new RegExp("^/cfg/accounts/otp/request/?$"), schema: OTPRequestResponseSchema, path: "/cfg/accounts/otp/request/" },
1971
- { method: "POST", re: new RegExp("^/cfg/accounts/otp/verify/?$"), schema: OTPVerifyResponseSchema, path: "/cfg/accounts/otp/verify/" },
1972
- { method: "GET", re: new RegExp("^/cfg/accounts/profile/?$"), schema: UserSchema, path: "/cfg/accounts/profile/" },
1973
- { method: "POST", re: new RegExp("^/cfg/accounts/profile/avatar/?$"), schema: UserSchema, path: "/cfg/accounts/profile/avatar/" },
1974
- { method: "POST", re: new RegExp("^/cfg/accounts/profile/delete/?$"), schema: AccountDeleteResponseSchema, path: "/cfg/accounts/profile/delete/" },
1975
- { method: "PUT", re: new RegExp("^/cfg/accounts/profile/partial/?$"), schema: UserSchema, path: "/cfg/accounts/profile/partial/" },
1976
- { method: "PATCH", re: new RegExp("^/cfg/accounts/profile/partial/?$"), schema: UserSchema, path: "/cfg/accounts/profile/partial/" },
1977
- { method: "PUT", re: new RegExp("^/cfg/accounts/profile/update/?$"), schema: UserSchema, path: "/cfg/accounts/profile/update/" },
1978
- { method: "PATCH", re: new RegExp("^/cfg/accounts/profile/update/?$"), schema: UserSchema, path: "/cfg/accounts/profile/update/" },
1979
- { method: "POST", re: new RegExp("^/cfg/accounts/token/refresh/?$"), schema: TokenRefreshSchema, path: "/cfg/accounts/token/refresh/" }
1980
- ];
1981
- function detectLocale() {
1982
- try {
1983
- if (typeof document !== "undefined") {
1984
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1985
- if (m) return decodeURIComponent(m[1]);
1986
- }
1987
- if (typeof navigator !== "undefined" && navigator.language) {
1988
- return navigator.language;
1989
- }
1990
- } catch {
1991
- }
1992
- return null;
1993
- }
1994
- __name(detectLocale, "detectLocale");
1995
- var API = class {
1996
- static {
1997
- __name(this, "API");
1998
- }
1999
- baseUrl;
2000
- storage;
2001
- locale;
2002
- apiKey;
2003
- logger;
2004
- cfg = Cfg;
2005
- accounts = Accounts;
2006
- oAuth = OAuth;
2007
- userProfile = UserProfile;
2008
- auth = Auth;
2009
- constructor(baseUrl2, opts = {}) {
2010
- this.baseUrl = baseUrl2.replace(/\/$/, "");
2011
- this.storage = opts.storage ?? new LocalStorageAdapter();
2012
- this.logger = new APILogger(opts.logger);
2013
- this.locale = opts.locale ?? null;
2014
- this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
2015
- const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
2016
- client.setConfig({ baseUrl: this.baseUrl, credentials });
2017
- client.interceptors.request.use((request) => {
2018
- const access = this.getToken();
2019
- if (access) request.headers.set("Authorization", `Bearer ${access}`);
2020
- const locale = this.locale ?? detectLocale();
2021
- if (locale) request.headers.set("Accept-Language", locale);
2022
- if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
2023
- return request;
2024
- });
2025
- client.interceptors.response.use(async (response, request) => {
2026
- if (!response.ok) return response;
2027
- const ct = response.headers.get("content-type") || "";
2028
- if (!ct.includes("application/json")) return response;
2029
- const url = new URL(request.url);
2030
- const method = request.method.toUpperCase();
2031
- const route = VALIDATION_ROUTES.find(
2032
- (r) => r.method === method && r.re.test(url.pathname)
2033
- );
2034
- if (!route) return response;
2035
- let payload;
2036
- try {
2037
- payload = await response.clone().json();
2038
- } catch {
2039
- return response;
2040
- }
2041
- const result = route.schema.safeParse(payload);
2042
- if (!result.success) {
2043
- dispatchValidationError({
2044
- operation: `${method} ${route.path}`,
2045
- path: route.path,
2046
- method,
2047
- error: result.error,
2048
- response: payload,
2049
- timestamp: /* @__PURE__ */ new Date()
2050
- });
2051
- }
2052
- return response;
2053
- });
2054
- }
2055
- // ── Base URL ────────────────────────────────────────────────────────────
2056
- getBaseUrl() {
2057
- return this.baseUrl;
2058
- }
2059
- setBaseUrl(url) {
2060
- this.baseUrl = url.replace(/\/$/, "");
2061
- client.setConfig({ baseUrl: this.baseUrl });
2062
- }
2063
- // ── Tokens ──────────────────────────────────────────────────────────────
2064
- getToken() {
2065
- return this.storage.getItem(ACCESS_KEY);
2066
- }
2067
- setToken(token) {
2068
- if (token) this.storage.setItem(ACCESS_KEY, token);
2069
- else this.storage.removeItem(ACCESS_KEY);
2070
- }
2071
- getRefreshToken() {
2072
- return this.storage.getItem(REFRESH_KEY);
2073
- }
2074
- setRefreshToken(token) {
2075
- if (token) this.storage.setItem(REFRESH_KEY, token);
2076
- else this.storage.removeItem(REFRESH_KEY);
2077
- }
2078
- clearToken() {
2079
- this.storage.removeItem(ACCESS_KEY);
2080
- this.storage.removeItem(REFRESH_KEY);
2081
- }
2082
- isAuthenticated() {
2083
- return this.getToken() !== null;
2084
- }
2085
- // ── Locale / API key ────────────────────────────────────────────────────
2086
- getLocale() {
2087
- return this.locale ?? detectLocale();
2088
- }
2089
- setLocale(locale) {
2090
- this.locale = locale;
2091
- }
2092
- getApiKey() {
2093
- return this.apiKey;
2094
- }
2095
- setApiKey(key) {
2096
- this.apiKey = key;
2097
- }
2098
- };
2099
-
2100
- // src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts
2101
- var jsonBodySerializer2 = {
2102
- bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
2103
- };
2104
-
2105
- // src/_api/generated/cfg_centrifugo/core/params.gen.ts
2106
- var extraPrefixesMap2 = {
2107
- $body_: "body",
2108
- $headers_: "headers",
2109
- $path_: "path",
2110
- $query_: "query"
2111
- };
2112
- var extraPrefixes2 = Object.entries(extraPrefixesMap2);
2113
-
2114
- // src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts
2115
- function createSseClient2({
2116
- onRequest,
2117
- onSseError,
2118
- onSseEvent,
2119
- responseTransformer,
2120
- responseValidator,
2121
- sseDefaultRetryDelay,
2122
- sseMaxRetryAttempts,
2123
- sseMaxRetryDelay,
2124
- sseSleepFn,
2125
- url,
2126
- ...options
2127
- }) {
2128
- let lastEventId;
2129
- const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
2130
- const createStream = /* @__PURE__ */ __name(async function* () {
2131
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
2132
- let attempt = 0;
2133
- const signal = options.signal ?? new AbortController().signal;
2134
- while (true) {
2135
- if (signal.aborted) break;
2136
- attempt++;
2137
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
2138
- if (lastEventId !== void 0) {
2139
- headers.set("Last-Event-ID", lastEventId);
2140
- }
2141
- try {
2142
- const requestInit = {
2143
- redirect: "follow",
2144
- ...options,
2145
- body: options.serializedBody,
2146
- headers,
2147
- signal
2148
- };
2149
- let request = new Request(url, requestInit);
2150
- if (onRequest) {
2151
- request = await onRequest(url, requestInit);
2152
- }
2153
- const _fetch = options.fetch ?? globalThis.fetch;
2154
- const response = await _fetch(request);
2155
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
2156
- if (!response.body) throw new Error("No body in SSE response");
2157
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
2158
- let buffer = "";
2159
- const abortHandler = /* @__PURE__ */ __name(() => {
2160
- try {
2161
- reader.cancel();
2162
- } catch {
2163
- }
2164
- }, "abortHandler");
2165
- signal.addEventListener("abort", abortHandler);
2166
- try {
2167
- while (true) {
2168
- const { done, value } = await reader.read();
2169
- if (done) break;
2170
- buffer += value;
2171
- buffer = buffer.replace(/\r\n?/g, "\n");
2172
- const chunks = buffer.split("\n\n");
2173
- buffer = chunks.pop() ?? "";
2174
- for (const chunk of chunks) {
2175
- const lines = chunk.split("\n");
2176
- const dataLines = [];
2177
- let eventName;
2178
- for (const line of lines) {
2179
- if (line.startsWith("data:")) {
2180
- dataLines.push(line.replace(/^data:\s*/, ""));
2181
- } else if (line.startsWith("event:")) {
2182
- eventName = line.replace(/^event:\s*/, "");
2183
- } else if (line.startsWith("id:")) {
2184
- lastEventId = line.replace(/^id:\s*/, "");
2185
- } else if (line.startsWith("retry:")) {
2186
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
2187
- if (!Number.isNaN(parsed)) {
2188
- retryDelay = parsed;
2189
- }
2190
- }
2191
- }
2192
- let data;
2193
- let parsedJson = false;
2194
- if (dataLines.length) {
2195
- const rawData = dataLines.join("\n");
2196
- try {
2197
- data = JSON.parse(rawData);
2198
- parsedJson = true;
2199
- } catch {
2200
- data = rawData;
2201
- }
2202
- }
2203
- if (parsedJson) {
2204
- if (responseValidator) {
2205
- await responseValidator(data);
2206
- }
2207
- if (responseTransformer) {
2208
- data = await responseTransformer(data);
2209
- }
2210
- }
2211
- onSseEvent?.({
2212
- data,
2213
- event: eventName,
2214
- id: lastEventId,
2215
- retry: retryDelay
2216
- });
2217
- if (dataLines.length) {
2218
- yield data;
2219
- }
2220
- }
2221
- }
2222
- } finally {
2223
- signal.removeEventListener("abort", abortHandler);
2224
- reader.releaseLock();
2225
- }
2226
- break;
2227
- } catch (error) {
2228
- onSseError?.(error);
2229
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
2230
- break;
2231
- }
2232
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
2233
- await sleep(backoff);
2234
- }
2235
- }
2236
- }, "createStream");
2237
- const stream = createStream();
2238
- return { stream };
2239
- }
2240
- __name(createSseClient2, "createSseClient");
2241
-
2242
- // src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts
2243
- var separatorArrayExplode2 = /* @__PURE__ */ __name((style) => {
2244
- switch (style) {
2245
- case "label":
2246
- return ".";
2247
- case "matrix":
2248
- return ";";
2249
- case "simple":
2250
- return ",";
2251
- default:
2252
- return "&";
2253
- }
2254
- }, "separatorArrayExplode");
2255
- var separatorArrayNoExplode2 = /* @__PURE__ */ __name((style) => {
2256
- switch (style) {
2257
- case "form":
2258
- return ",";
2259
- case "pipeDelimited":
2260
- return "|";
2261
- case "spaceDelimited":
2262
- return "%20";
2263
- default:
2264
- return ",";
2265
- }
2266
- }, "separatorArrayNoExplode");
2267
- var separatorObjectExplode2 = /* @__PURE__ */ __name((style) => {
2268
- switch (style) {
2269
- case "label":
2270
- return ".";
2271
- case "matrix":
2272
- return ";";
2273
- case "simple":
2274
- return ",";
2275
- default:
2276
- return "&";
2277
- }
2278
- }, "separatorObjectExplode");
2279
- var serializeArrayParam2 = /* @__PURE__ */ __name(({
2280
- allowReserved,
2281
- explode,
2282
- name,
2283
- style,
2284
- value
2285
- }) => {
2286
- if (!explode) {
2287
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode2(style));
2288
- switch (style) {
2289
- case "label":
2290
- return `.${joinedValues2}`;
2291
- case "matrix":
2292
- return `;${name}=${joinedValues2}`;
2293
- case "simple":
2294
- return joinedValues2;
2295
- default:
2296
- return `${name}=${joinedValues2}`;
2297
- }
2298
- }
2299
- const separator = separatorArrayExplode2(style);
2300
- const joinedValues = value.map((v) => {
2301
- if (style === "label" || style === "simple") {
2302
- return allowReserved ? v : encodeURIComponent(v);
2303
- }
2304
- return serializePrimitiveParam2({
2305
- allowReserved,
2306
- name,
2307
- value: v
2308
- });
2309
- }).join(separator);
2310
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
2311
- }, "serializeArrayParam");
2312
- var serializePrimitiveParam2 = /* @__PURE__ */ __name(({
2313
- allowReserved,
2314
- name,
2315
- value
2316
- }) => {
2317
- if (value === void 0 || value === null) {
2318
- return "";
2319
- }
2320
- if (typeof value === "object") {
2321
- throw new Error(
2322
- "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
2323
- );
2324
- }
2325
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
2326
- }, "serializePrimitiveParam");
2327
- var serializeObjectParam2 = /* @__PURE__ */ __name(({
2328
- allowReserved,
2329
- explode,
2330
- name,
2331
- style,
2332
- value,
2333
- valueOnly
2334
- }) => {
2335
- if (value instanceof Date) {
2336
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
2337
- }
2338
- if (style !== "deepObject" && !explode) {
2339
- let values = [];
2340
- Object.entries(value).forEach(([key, v]) => {
2341
- values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
2342
- });
2343
- const joinedValues2 = values.join(",");
2344
- switch (style) {
2345
- case "form":
2346
- return `${name}=${joinedValues2}`;
2347
- case "label":
2348
- return `.${joinedValues2}`;
2349
- case "matrix":
2350
- return `;${name}=${joinedValues2}`;
2351
- default:
2352
- return joinedValues2;
2353
- }
2354
- }
2355
- const separator = separatorObjectExplode2(style);
2356
- const joinedValues = Object.entries(value).map(
2357
- ([key, v]) => serializePrimitiveParam2({
2358
- allowReserved,
2359
- name: style === "deepObject" ? `${name}[${key}]` : key,
2360
- value: v
2361
- })
2362
- ).join(separator);
2363
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
2364
- }, "serializeObjectParam");
2365
-
2366
- // src/_api/generated/cfg_centrifugo/core/utils.gen.ts
2367
- var PATH_PARAM_RE2 = /\{[^{}]+\}/g;
2368
- var defaultPathSerializer2 = /* @__PURE__ */ __name(({ path, url: _url }) => {
2369
- let url = _url;
2370
- const matches = _url.match(PATH_PARAM_RE2);
2371
- if (matches) {
2372
- for (const match of matches) {
2373
- let explode = false;
2374
- let name = match.substring(1, match.length - 1);
2375
- let style = "simple";
2376
- if (name.endsWith("*")) {
2377
- explode = true;
2378
- name = name.substring(0, name.length - 1);
2379
- }
2380
- if (name.startsWith(".")) {
2381
- name = name.substring(1);
2382
- style = "label";
2383
- } else if (name.startsWith(";")) {
2384
- name = name.substring(1);
2385
- style = "matrix";
2386
- }
2387
- const value = path[name];
2388
- if (value === void 0 || value === null) {
2389
- continue;
2390
- }
2391
- if (Array.isArray(value)) {
2392
- url = url.replace(match, serializeArrayParam2({ explode, name, style, value }));
2393
- continue;
2394
- }
2395
- if (typeof value === "object") {
2396
- url = url.replace(
2397
- match,
2398
- serializeObjectParam2({
2399
- explode,
2400
- name,
2401
- style,
2402
- value,
2403
- valueOnly: true
2404
- })
2405
- );
2406
- continue;
2407
- }
2408
- if (style === "matrix") {
2409
- url = url.replace(
2410
- match,
2411
- `;${serializePrimitiveParam2({
2412
- name,
2413
- value
2414
- })}`
2415
- );
2416
- continue;
2417
- }
2418
- const replaceValue = encodeURIComponent(
2419
- style === "label" ? `.${value}` : value
2420
- );
2421
- url = url.replace(match, replaceValue);
2422
- }
2423
- }
2424
- return url;
2425
- }, "defaultPathSerializer");
2426
- var getUrl2 = /* @__PURE__ */ __name(({
2427
- baseUrl: baseUrl2,
2428
- path,
2429
- query,
2430
- querySerializer,
2431
- url: _url
2432
- }) => {
2433
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
2434
- let url = (baseUrl2 ?? "") + pathUrl;
2435
- if (path) {
2436
- url = defaultPathSerializer2({ path, url });
2437
- }
2438
- let search = query ? querySerializer(query) : "";
2439
- if (search.startsWith("?")) {
2440
- search = search.substring(1);
2441
- }
2442
- if (search) {
2443
- url += `?${search}`;
2444
- }
2445
- return url;
2446
- }, "getUrl");
2447
- function getValidRequestBody2(options) {
2448
- const hasBody = options.body !== void 0;
2449
- const isSerializedBody = hasBody && options.bodySerializer;
2450
- if (isSerializedBody) {
2451
- if ("serializedBody" in options) {
2452
- const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
2453
- return hasSerializedBody ? options.serializedBody : null;
2454
- }
2455
- return options.body !== "" ? options.body : null;
2456
- }
2457
- if (hasBody) {
2458
- return options.body;
2459
- }
2460
- return void 0;
2461
- }
2462
- __name(getValidRequestBody2, "getValidRequestBody");
2463
-
2464
- // src/_api/generated/cfg_centrifugo/core/auth.gen.ts
2465
- var getAuthToken2 = /* @__PURE__ */ __name(async (auth, callback) => {
2466
- const token = typeof callback === "function" ? await callback(auth) : callback;
2467
- if (!token) {
2468
- return;
2469
- }
2470
- if (auth.scheme === "bearer") {
2471
- return `Bearer ${token}`;
2472
- }
2473
- if (auth.scheme === "basic") {
2474
- return `Basic ${btoa(token)}`;
2475
- }
2476
- return token;
2477
- }, "getAuthToken");
2478
-
2479
- // src/_api/generated/cfg_centrifugo/client/utils.gen.ts
2480
- var createQuerySerializer2 = /* @__PURE__ */ __name(({
2481
- parameters = {},
2482
- ...args
2483
- } = {}) => {
2484
- const querySerializer = /* @__PURE__ */ __name((queryParams) => {
2485
- const search = [];
2486
- if (queryParams && typeof queryParams === "object") {
2487
- for (const name in queryParams) {
2488
- const value = queryParams[name];
2489
- if (value === void 0 || value === null) {
2490
- continue;
2491
- }
2492
- const options = parameters[name] || args;
2493
- if (Array.isArray(value)) {
2494
- const serializedArray = serializeArrayParam2({
2495
- allowReserved: options.allowReserved,
2496
- explode: true,
2497
- name,
2498
- style: "form",
2499
- value,
2500
- ...options.array
2501
- });
2502
- if (serializedArray) search.push(serializedArray);
2503
- } else if (typeof value === "object") {
2504
- const serializedObject = serializeObjectParam2({
2505
- allowReserved: options.allowReserved,
2506
- explode: true,
2507
- name,
2508
- style: "deepObject",
2509
- value,
2510
- ...options.object
2511
- });
2512
- if (serializedObject) search.push(serializedObject);
2513
- } else {
2514
- const serializedPrimitive = serializePrimitiveParam2({
2515
- allowReserved: options.allowReserved,
2516
- name,
2517
- value
2518
- });
2519
- if (serializedPrimitive) search.push(serializedPrimitive);
2520
- }
2521
- }
2522
- }
2523
- return search.join("&");
2524
- }, "querySerializer");
2525
- return querySerializer;
2526
- }, "createQuerySerializer");
2527
- var getParseAs2 = /* @__PURE__ */ __name((contentType) => {
2528
- if (!contentType) {
2529
- return "stream";
2530
- }
2531
- const cleanContent = contentType.split(";")[0]?.trim();
2532
- if (!cleanContent) {
2533
- return;
2534
- }
2535
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
2536
- return "json";
2537
- }
2538
- if (cleanContent === "multipart/form-data") {
2539
- return "formData";
2540
- }
2541
- if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
2542
- return "blob";
2543
- }
2544
- if (cleanContent.startsWith("text/")) {
2545
- return "text";
2546
- }
2547
- return;
2548
- }, "getParseAs");
2549
- var checkForExistence2 = /* @__PURE__ */ __name((options, name) => {
2550
- if (!name) {
2551
- return false;
2552
- }
2553
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
2554
- return true;
2555
- }
2556
- return false;
2557
- }, "checkForExistence");
2558
- var setAuthParams2 = /* @__PURE__ */ __name(async ({
2559
- security,
2560
- ...options
2561
- }) => {
2562
- for (const auth of security) {
2563
- if (checkForExistence2(options, auth.name)) {
2564
- continue;
2565
- }
2566
- const token = await getAuthToken2(auth, options.auth);
2567
- if (!token) {
2568
- continue;
2569
- }
2570
- const name = auth.name ?? "Authorization";
2571
- switch (auth.in) {
2572
- case "query":
2573
- if (!options.query) {
2574
- options.query = {};
2575
- }
2576
- options.query[name] = token;
2577
- break;
2578
- case "cookie":
2579
- options.headers.append("Cookie", `${name}=${token}`);
2580
- break;
2581
- case "header":
2582
- default:
2583
- options.headers.set(name, token);
2584
- break;
2585
- }
2586
- }
2587
- }, "setAuthParams");
2588
- var buildUrl2 = /* @__PURE__ */ __name((options) => getUrl2({
2589
- baseUrl: options.baseUrl,
2590
- path: options.path,
2591
- query: options.query,
2592
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer2(options.querySerializer),
2593
- url: options.url
2594
- }), "buildUrl");
2595
- var mergeConfigs2 = /* @__PURE__ */ __name((a, b) => {
2596
- const config = { ...a, ...b };
2597
- if (config.baseUrl?.endsWith("/")) {
2598
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
2599
- }
2600
- config.headers = mergeHeaders2(a.headers, b.headers);
2601
- return config;
2602
- }, "mergeConfigs");
2603
- var headersEntries2 = /* @__PURE__ */ __name((headers) => {
2604
- const entries = [];
2605
- headers.forEach((value, key) => {
2606
- entries.push([key, value]);
2607
- });
2608
- return entries;
2609
- }, "headersEntries");
2610
- var mergeHeaders2 = /* @__PURE__ */ __name((...headers) => {
2611
- const mergedHeaders = new Headers();
2612
- for (const header of headers) {
2613
- if (!header) {
2614
- continue;
2615
- }
2616
- const iterator = header instanceof Headers ? headersEntries2(header) : Object.entries(header);
2617
- for (const [key, value] of iterator) {
2618
- if (value === null) {
2619
- mergedHeaders.delete(key);
2620
- } else if (Array.isArray(value)) {
2621
- for (const v of value) {
2622
- mergedHeaders.append(key, v);
2623
- }
2624
- } else if (value !== void 0) {
2625
- mergedHeaders.set(
2626
- key,
2627
- typeof value === "object" ? JSON.stringify(value) : value
2628
- );
2629
- }
2630
- }
2631
- }
2632
- return mergedHeaders;
2633
- }, "mergeHeaders");
2634
- var Interceptors2 = class {
2635
- static {
2636
- __name(this, "Interceptors");
2637
- }
2638
- fns = [];
2639
- clear() {
2640
- this.fns = [];
2641
- }
2642
- eject(id) {
2643
- const index = this.getInterceptorIndex(id);
2644
- if (this.fns[index]) {
2645
- this.fns[index] = null;
2646
- }
2647
- }
2648
- exists(id) {
2649
- const index = this.getInterceptorIndex(id);
2650
- return Boolean(this.fns[index]);
2651
- }
2652
- getInterceptorIndex(id) {
2653
- if (typeof id === "number") {
2654
- return this.fns[id] ? id : -1;
2655
- }
2656
- return this.fns.indexOf(id);
2657
- }
2658
- update(id, fn) {
2659
- const index = this.getInterceptorIndex(id);
2660
- if (this.fns[index]) {
2661
- this.fns[index] = fn;
2662
- return id;
2663
- }
2664
- return false;
2665
- }
2666
- use(fn) {
2667
- this.fns.push(fn);
2668
- return this.fns.length - 1;
2669
- }
2670
- };
2671
- var createInterceptors2 = /* @__PURE__ */ __name(() => ({
2672
- error: new Interceptors2(),
2673
- request: new Interceptors2(),
2674
- response: new Interceptors2()
2675
- }), "createInterceptors");
2676
- var defaultQuerySerializer2 = createQuerySerializer2({
2677
- allowReserved: false,
2678
- array: {
2679
- explode: true,
2680
- style: "form"
2681
- },
2682
- object: {
2683
- explode: true,
2684
- style: "deepObject"
2685
- }
2686
- });
2687
- var defaultHeaders2 = {
2688
- "Content-Type": "application/json"
2689
- };
2690
- var createConfig2 = /* @__PURE__ */ __name((override = {}) => ({
2691
- ...jsonBodySerializer2,
2692
- headers: defaultHeaders2,
2693
- parseAs: "auto",
2694
- querySerializer: defaultQuerySerializer2,
2695
- ...override
2696
- }), "createConfig");
2697
-
2698
- // src/_api/generated/cfg_centrifugo/client/client.gen.ts
2699
- var createClient2 = /* @__PURE__ */ __name((config = {}) => {
2700
- let _config = mergeConfigs2(createConfig2(), config);
2701
- const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
2702
- const setConfig = /* @__PURE__ */ __name((config2) => {
2703
- _config = mergeConfigs2(_config, config2);
2704
- return getConfig();
2705
- }, "setConfig");
2706
- const interceptors = createInterceptors2();
2707
- const beforeRequest = /* @__PURE__ */ __name(async (options) => {
2708
- const opts = {
2709
- ..._config,
2710
- ...options,
2711
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
2712
- headers: mergeHeaders2(_config.headers, options.headers),
2713
- serializedBody: void 0
2714
- };
2715
- if (opts.security) {
2716
- await setAuthParams2({
2717
- ...opts,
2718
- security: opts.security
2719
- });
2720
- }
2721
- if (opts.requestValidator) {
2722
- await opts.requestValidator(opts);
2723
- }
2724
- if (opts.body !== void 0 && opts.bodySerializer) {
2725
- opts.serializedBody = opts.bodySerializer(opts.body);
2726
- }
2727
- if (opts.body === void 0 || opts.serializedBody === "") {
2728
- opts.headers.delete("Content-Type");
2729
- }
2730
- const resolvedOpts = opts;
2731
- const url = buildUrl2(resolvedOpts);
2732
- return { opts: resolvedOpts, url };
2733
- }, "beforeRequest");
2734
- const request = /* @__PURE__ */ __name(async (options) => {
2735
- const throwOnError = options.throwOnError ?? _config.throwOnError;
2736
- const responseStyle = options.responseStyle ?? _config.responseStyle;
2737
- let request2;
2738
- let response;
2739
- try {
2740
- const { opts, url } = await beforeRequest(options);
2741
- const requestInit = {
2742
- redirect: "follow",
2743
- ...opts,
2744
- body: getValidRequestBody2(opts)
2745
- };
2746
- request2 = new Request(url, requestInit);
2747
- for (const fn of interceptors.request.fns) {
2748
- if (fn) {
2749
- request2 = await fn(request2, opts);
2750
- }
2751
- }
2752
- const _fetch = opts.fetch;
2753
- response = await _fetch(request2);
2754
- for (const fn of interceptors.response.fns) {
2755
- if (fn) {
2756
- response = await fn(response, request2, opts);
2757
- }
2758
- }
2759
- const result = {
2760
- request: request2,
2761
- response
2762
- };
2763
- if (response.ok) {
2764
- const parseAs = (opts.parseAs === "auto" ? getParseAs2(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
2765
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
2766
- let emptyData;
2767
- switch (parseAs) {
2768
- case "arrayBuffer":
2769
- case "blob":
2770
- case "text":
2771
- emptyData = await response[parseAs]();
2772
- break;
2773
- case "formData":
2774
- emptyData = new FormData();
2775
- break;
2776
- case "stream":
2777
- emptyData = response.body;
2778
- break;
2779
- case "json":
2780
- default:
2781
- emptyData = {};
2782
- break;
2783
- }
2784
- return opts.responseStyle === "data" ? emptyData : {
2785
- data: emptyData,
2786
- ...result
2787
- };
2788
- }
2789
- let data;
2790
- switch (parseAs) {
2791
- case "arrayBuffer":
2792
- case "blob":
2793
- case "formData":
2794
- case "text":
2795
- data = await response[parseAs]();
2796
- break;
2797
- case "json": {
2798
- const text = await response.text();
2799
- data = text ? JSON.parse(text) : {};
2800
- break;
2801
- }
2802
- case "stream":
2803
- return opts.responseStyle === "data" ? response.body : {
2804
- data: response.body,
2805
- ...result
2806
- };
2807
- }
2808
- if (parseAs === "json") {
2809
- if (opts.responseValidator) {
2810
- await opts.responseValidator(data);
2811
- }
2812
- if (opts.responseTransformer) {
2813
- data = await opts.responseTransformer(data);
2814
- }
2815
- }
2816
- return opts.responseStyle === "data" ? data : {
2817
- data,
2818
- ...result
2819
- };
2820
- }
2821
- const textError = await response.text();
2822
- let jsonError;
2823
- try {
2824
- jsonError = JSON.parse(textError);
2825
- } catch {
2826
- }
2827
- throw jsonError ?? textError;
2828
- } catch (error) {
2829
- let finalError = error;
2830
- for (const fn of interceptors.error.fns) {
2831
- if (fn) {
2832
- finalError = await fn(finalError, response, request2, options);
2833
- }
2834
- }
2835
- finalError = finalError || {};
2836
- if (throwOnError) {
2837
- throw finalError;
2838
- }
2839
- return responseStyle === "data" ? void 0 : {
2840
- error: finalError,
2841
- request: request2,
2842
- response
2843
- };
2844
- }
2845
- }, "request");
2846
- const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
2847
- const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
2848
- const { opts, url } = await beforeRequest(options);
2849
- return createSseClient2({
2850
- ...opts,
2851
- body: opts.body,
2852
- method,
2853
- onRequest: /* @__PURE__ */ __name(async (url2, init) => {
2854
- let request2 = new Request(url2, init);
2855
- for (const fn of interceptors.request.fns) {
2856
- if (fn) {
2857
- request2 = await fn(request2, opts);
2858
- }
2859
- }
2860
- return request2;
2861
- }, "onRequest"),
2862
- serializedBody: getValidRequestBody2(opts),
2863
- url
2864
- });
2865
- }, "makeSseFn");
2866
- const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl2({ ..._config, ...options }), "_buildUrl");
2867
- return {
2868
- buildUrl: _buildUrl,
2869
- connect: makeMethodFn("CONNECT"),
2870
- delete: makeMethodFn("DELETE"),
2871
- get: makeMethodFn("GET"),
2872
- getConfig,
2873
- head: makeMethodFn("HEAD"),
2874
- interceptors,
2875
- options: makeMethodFn("OPTIONS"),
2876
- patch: makeMethodFn("PATCH"),
2877
- post: makeMethodFn("POST"),
2878
- put: makeMethodFn("PUT"),
2879
- request,
2880
- setConfig,
2881
- sse: {
2882
- connect: makeSseFn("CONNECT"),
2883
- delete: makeSseFn("DELETE"),
2884
- get: makeSseFn("GET"),
2885
- head: makeSseFn("HEAD"),
2886
- options: makeSseFn("OPTIONS"),
2887
- patch: makeSseFn("PATCH"),
2888
- post: makeSseFn("POST"),
2889
- put: makeSseFn("PUT"),
2890
- trace: makeSseFn("TRACE")
2891
- },
2892
- trace: makeMethodFn("TRACE")
2893
- };
2894
- }, "createClient");
2895
-
2896
- // src/_api/generated/cfg_centrifugo/client.gen.ts
2897
- var client2 = createClient2(createConfig2({ baseUrl: "http://localhost:8000" }));
2898
-
2899
- // src/_api/generated/cfg_centrifugo/sdk.gen.ts
2900
- var Cfg2 = class {
2901
- static {
2902
- __name(this, "Cfg");
2903
- }
2904
- /**
2905
- * Get Centrifugo connection token
2906
- *
2907
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
2908
- */
2909
- static cfgCentrifugoAuthTokenRetrieve(options) {
2910
- return (options?.client ?? client2).get({
2911
- security: [{ scheme: "bearer", type: "http" }],
2912
- url: "/cfg/centrifugo/auth/token/",
2913
- ...options
2914
- });
2915
- }
2916
- };
2917
- var Centrifugo = class {
2918
- static {
2919
- __name(this, "Centrifugo");
2920
- }
2921
- /**
2922
- * Get Centrifugo connection token
2923
- *
2924
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
2925
- */
2926
- static cfgCentrifugoAuthTokenRetrieve(options) {
2927
- return (options?.client ?? client2).get({
2928
- security: [{ scheme: "bearer", type: "http" }],
2929
- url: "/cfg/centrifugo/auth/token/",
2930
- ...options
2931
- });
2932
- }
2933
- };
2934
- var CentrifugoAuth = class {
2935
- static {
2936
- __name(this, "CentrifugoAuth");
2937
- }
2938
- /**
2939
- * Get Centrifugo connection token
2940
- *
2941
- * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
2942
- */
2943
- static cfgCentrifugoAuthTokenRetrieve(options) {
2944
- return (options?.client ?? client2).get({
2945
- security: [{ scheme: "bearer", type: "http" }],
2946
- url: "/cfg/centrifugo/auth/token/",
2947
- ...options
2948
- });
2949
- }
2950
- };
2951
-
2952
- // src/_api/generated/cfg_centrifugo/schemas/ConnectionTokenResponse.ts
2953
- var import_zod22 = require("zod");
2954
- var ConnectionTokenResponseSchema = import_zod22.z.object({
2955
- token: import_zod22.z.string(),
2956
- centrifugo_url: import_zod22.z.string(),
2957
- expires_at: import_zod22.z.string(),
2958
- channels: import_zod22.z.array(import_zod22.z.string())
2959
- });
2960
-
2961
- // src/_api/generated/cfg_centrifugo/api.ts
2962
- var ACCESS_KEY2 = "cfg.access_token";
2963
- var REFRESH_KEY2 = "cfg.refresh_token";
2964
- var VALIDATION_ROUTES2 = [
2965
- { method: "GET", re: new RegExp("^/cfg/centrifugo/auth/token/?$"), schema: ConnectionTokenResponseSchema, path: "/cfg/centrifugo/auth/token/" }
2966
- ];
2967
- function detectLocale2() {
2968
- try {
2969
- if (typeof document !== "undefined") {
2970
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
2971
- if (m) return decodeURIComponent(m[1]);
2972
- }
2973
- if (typeof navigator !== "undefined" && navigator.language) {
2974
- return navigator.language;
2975
- }
2976
- } catch {
2977
- }
2978
- return null;
2979
- }
2980
- __name(detectLocale2, "detectLocale");
2981
- var API2 = class {
2982
- static {
2983
- __name(this, "API");
2984
- }
2985
- baseUrl;
2986
- storage;
2987
- locale;
2988
- apiKey;
2989
- logger;
2990
- cfg = Cfg2;
2991
- centrifugo = Centrifugo;
2992
- centrifugoAuth = CentrifugoAuth;
2993
- constructor(baseUrl2, opts = {}) {
2994
- this.baseUrl = baseUrl2.replace(/\/$/, "");
2995
- this.storage = opts.storage ?? new LocalStorageAdapter();
2996
- this.logger = new APILogger(opts.logger);
2997
- this.locale = opts.locale ?? null;
2998
- this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
2999
- const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
3000
- client2.setConfig({ baseUrl: this.baseUrl, credentials });
3001
- client2.interceptors.request.use((request) => {
3002
- const access = this.getToken();
3003
- if (access) request.headers.set("Authorization", `Bearer ${access}`);
3004
- const locale = this.locale ?? detectLocale2();
3005
- if (locale) request.headers.set("Accept-Language", locale);
3006
- if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
3007
- return request;
3008
- });
3009
- client2.interceptors.response.use(async (response, request) => {
3010
- if (!response.ok) return response;
3011
- const ct = response.headers.get("content-type") || "";
3012
- if (!ct.includes("application/json")) return response;
3013
- const url = new URL(request.url);
3014
- const method = request.method.toUpperCase();
3015
- const route = VALIDATION_ROUTES2.find(
3016
- (r) => r.method === method && r.re.test(url.pathname)
3017
- );
3018
- if (!route) return response;
3019
- let payload;
3020
- try {
3021
- payload = await response.clone().json();
3022
- } catch {
3023
- return response;
3024
- }
3025
- const result = route.schema.safeParse(payload);
3026
- if (!result.success) {
3027
- dispatchValidationError({
3028
- operation: `${method} ${route.path}`,
3029
- path: route.path,
3030
- method,
3031
- error: result.error,
3032
- response: payload,
3033
- timestamp: /* @__PURE__ */ new Date()
3034
- });
3035
- }
3036
- return response;
3037
- });
3038
- }
3039
- // ── Base URL ────────────────────────────────────────────────────────────
3040
- getBaseUrl() {
3041
- return this.baseUrl;
3042
- }
3043
- setBaseUrl(url) {
3044
- this.baseUrl = url.replace(/\/$/, "");
3045
- client2.setConfig({ baseUrl: this.baseUrl });
3046
- }
3047
- // ── Tokens ──────────────────────────────────────────────────────────────
3048
- getToken() {
3049
- return this.storage.getItem(ACCESS_KEY2);
3050
- }
3051
- setToken(token) {
3052
- if (token) this.storage.setItem(ACCESS_KEY2, token);
3053
- else this.storage.removeItem(ACCESS_KEY2);
3054
- }
3055
- getRefreshToken() {
3056
- return this.storage.getItem(REFRESH_KEY2);
3057
- }
3058
- setRefreshToken(token) {
3059
- if (token) this.storage.setItem(REFRESH_KEY2, token);
3060
- else this.storage.removeItem(REFRESH_KEY2);
3061
- }
3062
- clearToken() {
3063
- this.storage.removeItem(ACCESS_KEY2);
3064
- this.storage.removeItem(REFRESH_KEY2);
3065
- }
3066
- isAuthenticated() {
3067
- return this.getToken() !== null;
3068
- }
3069
- // ── Locale / API key ────────────────────────────────────────────────────
3070
- getLocale() {
3071
- return this.locale ?? detectLocale2();
3072
- }
3073
- setLocale(locale) {
3074
- this.locale = locale;
3075
- }
3076
- getApiKey() {
3077
- return this.apiKey;
3078
- }
3079
- setApiKey(key) {
3080
- this.apiKey = key;
3081
- }
3082
- };
3083
-
3084
- // src/_api/generated/cfg_totp/core/bodySerializer.gen.ts
3085
- var jsonBodySerializer3 = {
3086
- bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
3087
- };
3088
-
3089
- // src/_api/generated/cfg_totp/core/params.gen.ts
3090
- var extraPrefixesMap3 = {
3091
- $body_: "body",
3092
- $headers_: "headers",
3093
- $path_: "path",
3094
- $query_: "query"
3095
- };
3096
- var extraPrefixes3 = Object.entries(extraPrefixesMap3);
3097
-
3098
- // src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts
3099
- function createSseClient3({
3100
- onRequest,
3101
- onSseError,
3102
- onSseEvent,
3103
- responseTransformer,
3104
- responseValidator,
3105
- sseDefaultRetryDelay,
3106
- sseMaxRetryAttempts,
3107
- sseMaxRetryDelay,
3108
- sseSleepFn,
3109
- url,
3110
- ...options
3111
- }) {
3112
- let lastEventId;
3113
- const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
3114
- const createStream = /* @__PURE__ */ __name(async function* () {
3115
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
3116
- let attempt = 0;
3117
- const signal = options.signal ?? new AbortController().signal;
3118
- while (true) {
3119
- if (signal.aborted) break;
3120
- attempt++;
3121
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
3122
- if (lastEventId !== void 0) {
3123
- headers.set("Last-Event-ID", lastEventId);
3124
- }
3125
- try {
3126
- const requestInit = {
3127
- redirect: "follow",
3128
- ...options,
3129
- body: options.serializedBody,
3130
- headers,
3131
- signal
3132
- };
3133
- let request = new Request(url, requestInit);
3134
- if (onRequest) {
3135
- request = await onRequest(url, requestInit);
3136
- }
3137
- const _fetch = options.fetch ?? globalThis.fetch;
3138
- const response = await _fetch(request);
3139
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
3140
- if (!response.body) throw new Error("No body in SSE response");
3141
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
3142
- let buffer = "";
3143
- const abortHandler = /* @__PURE__ */ __name(() => {
3144
- try {
3145
- reader.cancel();
3146
- } catch {
3147
- }
3148
- }, "abortHandler");
3149
- signal.addEventListener("abort", abortHandler);
3150
- try {
3151
- while (true) {
3152
- const { done, value } = await reader.read();
3153
- if (done) break;
3154
- buffer += value;
3155
- buffer = buffer.replace(/\r\n?/g, "\n");
3156
- const chunks = buffer.split("\n\n");
3157
- buffer = chunks.pop() ?? "";
3158
- for (const chunk of chunks) {
3159
- const lines = chunk.split("\n");
3160
- const dataLines = [];
3161
- let eventName;
3162
- for (const line of lines) {
3163
- if (line.startsWith("data:")) {
3164
- dataLines.push(line.replace(/^data:\s*/, ""));
3165
- } else if (line.startsWith("event:")) {
3166
- eventName = line.replace(/^event:\s*/, "");
3167
- } else if (line.startsWith("id:")) {
3168
- lastEventId = line.replace(/^id:\s*/, "");
3169
- } else if (line.startsWith("retry:")) {
3170
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
3171
- if (!Number.isNaN(parsed)) {
3172
- retryDelay = parsed;
3173
- }
3174
- }
3175
- }
3176
- let data;
3177
- let parsedJson = false;
3178
- if (dataLines.length) {
3179
- const rawData = dataLines.join("\n");
3180
- try {
3181
- data = JSON.parse(rawData);
3182
- parsedJson = true;
3183
- } catch {
3184
- data = rawData;
3185
- }
3186
- }
3187
- if (parsedJson) {
3188
- if (responseValidator) {
3189
- await responseValidator(data);
3190
- }
3191
- if (responseTransformer) {
3192
- data = await responseTransformer(data);
3193
- }
3194
- }
3195
- onSseEvent?.({
3196
- data,
3197
- event: eventName,
3198
- id: lastEventId,
3199
- retry: retryDelay
3200
- });
3201
- if (dataLines.length) {
3202
- yield data;
3203
- }
3204
- }
3205
- }
3206
- } finally {
3207
- signal.removeEventListener("abort", abortHandler);
3208
- reader.releaseLock();
3209
- }
3210
- break;
3211
- } catch (error) {
3212
- onSseError?.(error);
3213
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
3214
- break;
3215
- }
3216
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
3217
- await sleep(backoff);
3218
- }
3219
- }
3220
- }, "createStream");
3221
- const stream = createStream();
3222
- return { stream };
3223
- }
3224
- __name(createSseClient3, "createSseClient");
3225
-
3226
- // src/_api/generated/cfg_totp/core/pathSerializer.gen.ts
3227
- var separatorArrayExplode3 = /* @__PURE__ */ __name((style) => {
3228
- switch (style) {
3229
- case "label":
3230
- return ".";
3231
- case "matrix":
3232
- return ";";
3233
- case "simple":
3234
- return ",";
3235
- default:
3236
- return "&";
3237
- }
3238
- }, "separatorArrayExplode");
3239
- var separatorArrayNoExplode3 = /* @__PURE__ */ __name((style) => {
3240
- switch (style) {
3241
- case "form":
3242
- return ",";
3243
- case "pipeDelimited":
3244
- return "|";
3245
- case "spaceDelimited":
3246
- return "%20";
3247
- default:
3248
- return ",";
3249
- }
3250
- }, "separatorArrayNoExplode");
3251
- var separatorObjectExplode3 = /* @__PURE__ */ __name((style) => {
3252
- switch (style) {
3253
- case "label":
3254
- return ".";
3255
- case "matrix":
3256
- return ";";
3257
- case "simple":
3258
- return ",";
3259
- default:
3260
- return "&";
3261
- }
3262
- }, "separatorObjectExplode");
3263
- var serializeArrayParam3 = /* @__PURE__ */ __name(({
3264
- allowReserved,
3265
- explode,
3266
- name,
3267
- style,
3268
- value
3269
- }) => {
3270
- if (!explode) {
3271
- const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode3(style));
3272
- switch (style) {
3273
- case "label":
3274
- return `.${joinedValues2}`;
3275
- case "matrix":
3276
- return `;${name}=${joinedValues2}`;
3277
- case "simple":
3278
- return joinedValues2;
3279
- default:
3280
- return `${name}=${joinedValues2}`;
3281
- }
3282
- }
3283
- const separator = separatorArrayExplode3(style);
3284
- const joinedValues = value.map((v) => {
3285
- if (style === "label" || style === "simple") {
3286
- return allowReserved ? v : encodeURIComponent(v);
3287
- }
3288
- return serializePrimitiveParam3({
3289
- allowReserved,
3290
- name,
3291
- value: v
3292
- });
3293
- }).join(separator);
3294
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
3295
- }, "serializeArrayParam");
3296
- var serializePrimitiveParam3 = /* @__PURE__ */ __name(({
3297
- allowReserved,
3298
- name,
3299
- value
3300
- }) => {
3301
- if (value === void 0 || value === null) {
3302
- return "";
3303
- }
3304
- if (typeof value === "object") {
3305
- throw new Error(
3306
- "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
3307
- );
3308
- }
3309
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
3310
- }, "serializePrimitiveParam");
3311
- var serializeObjectParam3 = /* @__PURE__ */ __name(({
3312
- allowReserved,
3313
- explode,
3314
- name,
3315
- style,
3316
- value,
3317
- valueOnly
3318
- }) => {
3319
- if (value instanceof Date) {
3320
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
3321
- }
3322
- if (style !== "deepObject" && !explode) {
3323
- let values = [];
3324
- Object.entries(value).forEach(([key, v]) => {
3325
- values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
3326
- });
3327
- const joinedValues2 = values.join(",");
3328
- switch (style) {
3329
- case "form":
3330
- return `${name}=${joinedValues2}`;
3331
- case "label":
3332
- return `.${joinedValues2}`;
3333
- case "matrix":
3334
- return `;${name}=${joinedValues2}`;
3335
- default:
3336
- return joinedValues2;
3337
- }
3338
- }
3339
- const separator = separatorObjectExplode3(style);
3340
- const joinedValues = Object.entries(value).map(
3341
- ([key, v]) => serializePrimitiveParam3({
3342
- allowReserved,
3343
- name: style === "deepObject" ? `${name}[${key}]` : key,
3344
- value: v
3345
- })
3346
- ).join(separator);
3347
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
3348
- }, "serializeObjectParam");
3349
-
3350
- // src/_api/generated/cfg_totp/core/utils.gen.ts
3351
- var PATH_PARAM_RE3 = /\{[^{}]+\}/g;
3352
- var defaultPathSerializer3 = /* @__PURE__ */ __name(({ path, url: _url }) => {
3353
- let url = _url;
3354
- const matches = _url.match(PATH_PARAM_RE3);
3355
- if (matches) {
3356
- for (const match of matches) {
3357
- let explode = false;
3358
- let name = match.substring(1, match.length - 1);
3359
- let style = "simple";
3360
- if (name.endsWith("*")) {
3361
- explode = true;
3362
- name = name.substring(0, name.length - 1);
3363
- }
3364
- if (name.startsWith(".")) {
3365
- name = name.substring(1);
3366
- style = "label";
3367
- } else if (name.startsWith(";")) {
3368
- name = name.substring(1);
3369
- style = "matrix";
3370
- }
3371
- const value = path[name];
3372
- if (value === void 0 || value === null) {
3373
- continue;
3374
- }
3375
- if (Array.isArray(value)) {
3376
- url = url.replace(match, serializeArrayParam3({ explode, name, style, value }));
3377
- continue;
3378
- }
3379
- if (typeof value === "object") {
3380
- url = url.replace(
3381
- match,
3382
- serializeObjectParam3({
3383
- explode,
3384
- name,
3385
- style,
3386
- value,
3387
- valueOnly: true
3388
- })
3389
- );
3390
- continue;
3391
- }
3392
- if (style === "matrix") {
3393
- url = url.replace(
3394
- match,
3395
- `;${serializePrimitiveParam3({
3396
- name,
3397
- value
3398
- })}`
3399
- );
3400
- continue;
3401
- }
3402
- const replaceValue = encodeURIComponent(
3403
- style === "label" ? `.${value}` : value
3404
- );
3405
- url = url.replace(match, replaceValue);
3406
- }
3407
- }
3408
- return url;
3409
- }, "defaultPathSerializer");
3410
- var getUrl3 = /* @__PURE__ */ __name(({
3411
- baseUrl: baseUrl2,
3412
- path,
3413
- query,
3414
- querySerializer,
3415
- url: _url
3416
- }) => {
3417
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
3418
- let url = (baseUrl2 ?? "") + pathUrl;
3419
- if (path) {
3420
- url = defaultPathSerializer3({ path, url });
3421
- }
3422
- let search = query ? querySerializer(query) : "";
3423
- if (search.startsWith("?")) {
3424
- search = search.substring(1);
3425
- }
3426
- if (search) {
3427
- url += `?${search}`;
3428
- }
3429
- return url;
3430
- }, "getUrl");
3431
- function getValidRequestBody3(options) {
3432
- const hasBody = options.body !== void 0;
3433
- const isSerializedBody = hasBody && options.bodySerializer;
3434
- if (isSerializedBody) {
3435
- if ("serializedBody" in options) {
3436
- const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
3437
- return hasSerializedBody ? options.serializedBody : null;
3438
- }
3439
- return options.body !== "" ? options.body : null;
3440
- }
3441
- if (hasBody) {
3442
- return options.body;
3443
- }
3444
- return void 0;
3445
- }
3446
- __name(getValidRequestBody3, "getValidRequestBody");
3447
-
3448
- // src/_api/generated/cfg_totp/core/auth.gen.ts
3449
- var getAuthToken3 = /* @__PURE__ */ __name(async (auth, callback) => {
3450
- const token = typeof callback === "function" ? await callback(auth) : callback;
3451
- if (!token) {
3452
- return;
3453
- }
3454
- if (auth.scheme === "bearer") {
3455
- return `Bearer ${token}`;
3456
- }
3457
- if (auth.scheme === "basic") {
3458
- return `Basic ${btoa(token)}`;
3459
- }
3460
- return token;
3461
- }, "getAuthToken");
3462
-
3463
- // src/_api/generated/cfg_totp/client/utils.gen.ts
3464
- var createQuerySerializer3 = /* @__PURE__ */ __name(({
3465
- parameters = {},
3466
- ...args
3467
- } = {}) => {
3468
- const querySerializer = /* @__PURE__ */ __name((queryParams) => {
3469
- const search = [];
3470
- if (queryParams && typeof queryParams === "object") {
3471
- for (const name in queryParams) {
3472
- const value = queryParams[name];
3473
- if (value === void 0 || value === null) {
3474
- continue;
3475
- }
3476
- const options = parameters[name] || args;
3477
- if (Array.isArray(value)) {
3478
- const serializedArray = serializeArrayParam3({
3479
- allowReserved: options.allowReserved,
3480
- explode: true,
3481
- name,
3482
- style: "form",
3483
- value,
3484
- ...options.array
3485
- });
3486
- if (serializedArray) search.push(serializedArray);
3487
- } else if (typeof value === "object") {
3488
- const serializedObject = serializeObjectParam3({
3489
- allowReserved: options.allowReserved,
3490
- explode: true,
3491
- name,
3492
- style: "deepObject",
3493
- value,
3494
- ...options.object
3495
- });
3496
- if (serializedObject) search.push(serializedObject);
3497
- } else {
3498
- const serializedPrimitive = serializePrimitiveParam3({
3499
- allowReserved: options.allowReserved,
3500
- name,
3501
- value
3502
- });
3503
- if (serializedPrimitive) search.push(serializedPrimitive);
3504
- }
3505
- }
3506
- }
3507
- return search.join("&");
3508
- }, "querySerializer");
3509
- return querySerializer;
3510
- }, "createQuerySerializer");
3511
- var getParseAs3 = /* @__PURE__ */ __name((contentType) => {
3512
- if (!contentType) {
3513
- return "stream";
3514
- }
3515
- const cleanContent = contentType.split(";")[0]?.trim();
3516
- if (!cleanContent) {
3517
- return;
3518
- }
3519
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
3520
- return "json";
3521
- }
3522
- if (cleanContent === "multipart/form-data") {
3523
- return "formData";
3524
- }
3525
- if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
3526
- return "blob";
3527
- }
3528
- if (cleanContent.startsWith("text/")) {
3529
- return "text";
3530
- }
3531
- return;
3532
- }, "getParseAs");
3533
- var checkForExistence3 = /* @__PURE__ */ __name((options, name) => {
3534
- if (!name) {
3535
- return false;
3536
- }
3537
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
3538
- return true;
3539
- }
3540
- return false;
3541
- }, "checkForExistence");
3542
- var setAuthParams3 = /* @__PURE__ */ __name(async ({
3543
- security,
3544
- ...options
3545
- }) => {
3546
- for (const auth of security) {
3547
- if (checkForExistence3(options, auth.name)) {
3548
- continue;
3549
- }
3550
- const token = await getAuthToken3(auth, options.auth);
3551
- if (!token) {
3552
- continue;
3553
- }
3554
- const name = auth.name ?? "Authorization";
3555
- switch (auth.in) {
3556
- case "query":
3557
- if (!options.query) {
3558
- options.query = {};
3559
- }
3560
- options.query[name] = token;
3561
- break;
3562
- case "cookie":
3563
- options.headers.append("Cookie", `${name}=${token}`);
3564
- break;
3565
- case "header":
3566
- default:
3567
- options.headers.set(name, token);
3568
- break;
3569
- }
3570
- }
3571
- }, "setAuthParams");
3572
- var buildUrl3 = /* @__PURE__ */ __name((options) => getUrl3({
3573
- baseUrl: options.baseUrl,
3574
- path: options.path,
3575
- query: options.query,
3576
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer3(options.querySerializer),
3577
- url: options.url
3578
- }), "buildUrl");
3579
- var mergeConfigs3 = /* @__PURE__ */ __name((a, b) => {
3580
- const config = { ...a, ...b };
3581
- if (config.baseUrl?.endsWith("/")) {
3582
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
3583
- }
3584
- config.headers = mergeHeaders3(a.headers, b.headers);
3585
- return config;
3586
- }, "mergeConfigs");
3587
- var headersEntries3 = /* @__PURE__ */ __name((headers) => {
3588
- const entries = [];
3589
- headers.forEach((value, key) => {
3590
- entries.push([key, value]);
3591
- });
3592
- return entries;
3593
- }, "headersEntries");
3594
- var mergeHeaders3 = /* @__PURE__ */ __name((...headers) => {
3595
- const mergedHeaders = new Headers();
3596
- for (const header of headers) {
3597
- if (!header) {
3598
- continue;
3599
- }
3600
- const iterator = header instanceof Headers ? headersEntries3(header) : Object.entries(header);
3601
- for (const [key, value] of iterator) {
3602
- if (value === null) {
3603
- mergedHeaders.delete(key);
3604
- } else if (Array.isArray(value)) {
3605
- for (const v of value) {
3606
- mergedHeaders.append(key, v);
3607
- }
3608
- } else if (value !== void 0) {
3609
- mergedHeaders.set(
3610
- key,
3611
- typeof value === "object" ? JSON.stringify(value) : value
3612
- );
3613
- }
3614
- }
3615
- }
3616
- return mergedHeaders;
3617
- }, "mergeHeaders");
3618
- var Interceptors3 = class {
3619
- static {
3620
- __name(this, "Interceptors");
3621
- }
3622
- fns = [];
3623
- clear() {
3624
- this.fns = [];
3625
- }
3626
- eject(id) {
3627
- const index = this.getInterceptorIndex(id);
3628
- if (this.fns[index]) {
3629
- this.fns[index] = null;
3630
- }
3631
- }
3632
- exists(id) {
3633
- const index = this.getInterceptorIndex(id);
3634
- return Boolean(this.fns[index]);
3635
- }
3636
- getInterceptorIndex(id) {
3637
- if (typeof id === "number") {
3638
- return this.fns[id] ? id : -1;
3639
- }
3640
- return this.fns.indexOf(id);
3641
- }
3642
- update(id, fn) {
3643
- const index = this.getInterceptorIndex(id);
3644
- if (this.fns[index]) {
3645
- this.fns[index] = fn;
3646
- return id;
3647
- }
3648
- return false;
3649
- }
3650
- use(fn) {
3651
- this.fns.push(fn);
3652
- return this.fns.length - 1;
3653
- }
3654
- };
3655
- var createInterceptors3 = /* @__PURE__ */ __name(() => ({
3656
- error: new Interceptors3(),
3657
- request: new Interceptors3(),
3658
- response: new Interceptors3()
3659
- }), "createInterceptors");
3660
- var defaultQuerySerializer3 = createQuerySerializer3({
3661
- allowReserved: false,
3662
- array: {
3663
- explode: true,
3664
- style: "form"
3665
- },
3666
- object: {
3667
- explode: true,
3668
- style: "deepObject"
3669
- }
3670
- });
3671
- var defaultHeaders3 = {
3672
- "Content-Type": "application/json"
3673
- };
3674
- var createConfig3 = /* @__PURE__ */ __name((override = {}) => ({
3675
- ...jsonBodySerializer3,
3676
- headers: defaultHeaders3,
3677
- parseAs: "auto",
3678
- querySerializer: defaultQuerySerializer3,
3679
- ...override
3680
- }), "createConfig");
3681
-
3682
- // src/_api/generated/cfg_totp/client/client.gen.ts
3683
- var createClient3 = /* @__PURE__ */ __name((config = {}) => {
3684
- let _config = mergeConfigs3(createConfig3(), config);
3685
- const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
3686
- const setConfig = /* @__PURE__ */ __name((config2) => {
3687
- _config = mergeConfigs3(_config, config2);
3688
- return getConfig();
3689
- }, "setConfig");
3690
- const interceptors = createInterceptors3();
3691
- const beforeRequest = /* @__PURE__ */ __name(async (options) => {
3692
- const opts = {
3693
- ..._config,
3694
- ...options,
3695
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
3696
- headers: mergeHeaders3(_config.headers, options.headers),
3697
- serializedBody: void 0
3698
- };
3699
- if (opts.security) {
3700
- await setAuthParams3({
3701
- ...opts,
3702
- security: opts.security
3703
- });
3704
- }
3705
- if (opts.requestValidator) {
3706
- await opts.requestValidator(opts);
3707
- }
3708
- if (opts.body !== void 0 && opts.bodySerializer) {
3709
- opts.serializedBody = opts.bodySerializer(opts.body);
3710
- }
3711
- if (opts.body === void 0 || opts.serializedBody === "") {
3712
- opts.headers.delete("Content-Type");
3713
- }
3714
- const resolvedOpts = opts;
3715
- const url = buildUrl3(resolvedOpts);
3716
- return { opts: resolvedOpts, url };
3717
- }, "beforeRequest");
3718
- const request = /* @__PURE__ */ __name(async (options) => {
3719
- const throwOnError = options.throwOnError ?? _config.throwOnError;
3720
- const responseStyle = options.responseStyle ?? _config.responseStyle;
3721
- let request2;
3722
- let response;
3723
- try {
3724
- const { opts, url } = await beforeRequest(options);
3725
- const requestInit = {
3726
- redirect: "follow",
3727
- ...opts,
3728
- body: getValidRequestBody3(opts)
3729
- };
3730
- request2 = new Request(url, requestInit);
3731
- for (const fn of interceptors.request.fns) {
3732
- if (fn) {
3733
- request2 = await fn(request2, opts);
3734
- }
3735
- }
3736
- const _fetch = opts.fetch;
3737
- response = await _fetch(request2);
3738
- for (const fn of interceptors.response.fns) {
3739
- if (fn) {
3740
- response = await fn(response, request2, opts);
3741
- }
3742
- }
3743
- const result = {
3744
- request: request2,
3745
- response
3746
- };
3747
- if (response.ok) {
3748
- const parseAs = (opts.parseAs === "auto" ? getParseAs3(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
3749
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
3750
- let emptyData;
3751
- switch (parseAs) {
3752
- case "arrayBuffer":
3753
- case "blob":
3754
- case "text":
3755
- emptyData = await response[parseAs]();
3756
- break;
3757
- case "formData":
3758
- emptyData = new FormData();
3759
- break;
3760
- case "stream":
3761
- emptyData = response.body;
3762
- break;
3763
- case "json":
3764
- default:
3765
- emptyData = {};
3766
- break;
3767
- }
3768
- return opts.responseStyle === "data" ? emptyData : {
3769
- data: emptyData,
3770
- ...result
3771
- };
3772
- }
3773
- let data;
3774
- switch (parseAs) {
3775
- case "arrayBuffer":
3776
- case "blob":
3777
- case "formData":
3778
- case "text":
3779
- data = await response[parseAs]();
3780
- break;
3781
- case "json": {
3782
- const text = await response.text();
3783
- data = text ? JSON.parse(text) : {};
3784
- break;
3785
- }
3786
- case "stream":
3787
- return opts.responseStyle === "data" ? response.body : {
3788
- data: response.body,
3789
- ...result
3790
- };
3791
- }
3792
- if (parseAs === "json") {
3793
- if (opts.responseValidator) {
3794
- await opts.responseValidator(data);
3795
- }
3796
- if (opts.responseTransformer) {
3797
- data = await opts.responseTransformer(data);
3798
- }
3799
- }
3800
- return opts.responseStyle === "data" ? data : {
3801
- data,
3802
- ...result
3803
- };
3804
- }
3805
- const textError = await response.text();
3806
- let jsonError;
3807
- try {
3808
- jsonError = JSON.parse(textError);
3809
- } catch {
3810
- }
3811
- throw jsonError ?? textError;
3812
- } catch (error) {
3813
- let finalError = error;
3814
- for (const fn of interceptors.error.fns) {
3815
- if (fn) {
3816
- finalError = await fn(finalError, response, request2, options);
3817
- }
3818
- }
3819
- finalError = finalError || {};
3820
- if (throwOnError) {
3821
- throw finalError;
3822
- }
3823
- return responseStyle === "data" ? void 0 : {
3824
- error: finalError,
3825
- request: request2,
3826
- response
3827
- };
3828
- }
3829
- }, "request");
3830
- const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
3831
- const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
3832
- const { opts, url } = await beforeRequest(options);
3833
- return createSseClient3({
3834
- ...opts,
3835
- body: opts.body,
3836
- method,
3837
- onRequest: /* @__PURE__ */ __name(async (url2, init) => {
3838
- let request2 = new Request(url2, init);
3839
- for (const fn of interceptors.request.fns) {
3840
- if (fn) {
3841
- request2 = await fn(request2, opts);
3842
- }
3843
- }
3844
- return request2;
3845
- }, "onRequest"),
3846
- serializedBody: getValidRequestBody3(opts),
3847
- url
3848
- });
3849
- }, "makeSseFn");
3850
- const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl3({ ..._config, ...options }), "_buildUrl");
3851
- return {
3852
- buildUrl: _buildUrl,
3853
- connect: makeMethodFn("CONNECT"),
3854
- delete: makeMethodFn("DELETE"),
3855
- get: makeMethodFn("GET"),
3856
- getConfig,
3857
- head: makeMethodFn("HEAD"),
3858
- interceptors,
3859
- options: makeMethodFn("OPTIONS"),
3860
- patch: makeMethodFn("PATCH"),
3861
- post: makeMethodFn("POST"),
3862
- put: makeMethodFn("PUT"),
3863
- request,
3864
- setConfig,
3865
- sse: {
3866
- connect: makeSseFn("CONNECT"),
3867
- delete: makeSseFn("DELETE"),
3868
- get: makeSseFn("GET"),
3869
- head: makeSseFn("HEAD"),
3870
- options: makeSseFn("OPTIONS"),
3871
- patch: makeSseFn("PATCH"),
3872
- post: makeSseFn("POST"),
3873
- put: makeSseFn("PUT"),
3874
- trace: makeSseFn("TRACE")
3875
- },
3876
- trace: makeMethodFn("TRACE")
3877
- };
3878
- }, "createClient");
3879
-
3880
- // src/_api/generated/cfg_totp/client.gen.ts
3881
- var client3 = createClient3(createConfig3({ baseUrl: "http://localhost:8000" }));
3882
-
3883
- // src/_api/generated/cfg_totp/sdk.gen.ts
3884
- var Cfg3 = class {
3885
- static {
3886
- __name(this, "Cfg");
3887
- }
3888
- /**
3889
- * Get backup codes status for user.
3890
- */
3891
- static cfgTotpBackupCodesRetrieve(options) {
3892
- return (options?.client ?? client3).get({
3893
- security: [{ scheme: "bearer", type: "http" }],
3894
- url: "/cfg/totp/backup-codes/",
3895
- ...options
3896
- });
3897
- }
3898
- /**
3899
- * Regenerate backup codes.
3900
- *
3901
- * Requires TOTP code for verification.
3902
- * Invalidates all existing codes.
3903
- */
3904
- static cfgTotpBackupCodesRegenerateCreate(options) {
3905
- return (options.client ?? client3).post({
3906
- security: [{ scheme: "bearer", type: "http" }],
3907
- url: "/cfg/totp/backup-codes/regenerate/",
3908
- ...options,
3909
- headers: {
3910
- "Content-Type": "application/json",
3911
- ...options.headers
3912
- }
3913
- });
3914
- }
3915
- /**
3916
- * List all TOTP devices for user.
3917
- */
3918
- static cfgTotpDevicesRetrieve(options) {
3919
- return (options?.client ?? client3).get({
3920
- security: [{ scheme: "bearer", type: "http" }],
3921
- url: "/cfg/totp/devices/",
3922
- ...options
3923
- });
3924
- }
3925
- /**
3926
- * Delete a TOTP device.
3927
- *
3928
- * Requires verification code if removing the last/primary device.
3929
- */
3930
- static cfgTotpDevicesDestroy(options) {
3931
- return (options.client ?? client3).delete({
3932
- security: [{ scheme: "bearer", type: "http" }],
3933
- url: "/cfg/totp/devices/{id}/",
3934
- ...options
3935
- });
3936
- }
3937
- /**
3938
- * Completely disable 2FA for account.
3939
- *
3940
- * Requires verification code.
3941
- */
3942
- static cfgTotpDisableCreate(options) {
3943
- return (options.client ?? client3).post({
3944
- security: [{ scheme: "bearer", type: "http" }],
3945
- url: "/cfg/totp/disable/",
3946
- ...options,
3947
- headers: {
3948
- "Content-Type": "application/json",
3949
- ...options.headers
3950
- }
3951
- });
3952
- }
3953
- /**
3954
- * Start 2FA setup process.
3955
- *
3956
- * Creates a new TOTP device and returns QR code for scanning.
3957
- */
3958
- static cfgTotpSetupCreate(options) {
3959
- return (options?.client ?? client3).post({
3960
- security: [{ scheme: "bearer", type: "http" }],
3961
- url: "/cfg/totp/setup/",
3962
- ...options,
3963
- headers: {
3964
- "Content-Type": "application/json",
3965
- ...options?.headers
3966
- }
3967
- });
3968
- }
3969
- /**
3970
- * Confirm 2FA setup with first valid code.
3971
- *
3972
- * Activates the device and generates backup codes.
3973
- */
3974
- static cfgTotpSetupConfirmCreate(options) {
3975
- return (options.client ?? client3).post({
3976
- security: [{ scheme: "bearer", type: "http" }],
3977
- url: "/cfg/totp/setup/confirm/",
3978
- ...options,
3979
- headers: {
3980
- "Content-Type": "application/json",
3981
- ...options.headers
3982
- }
3983
- });
3984
- }
3985
- /**
3986
- * Verify TOTP code for 2FA session.
3987
- *
3988
- * Completes authentication and returns JWT tokens on success.
3989
- */
3990
- static cfgTotpVerifyCreate(options) {
3991
- return (options.client ?? client3).post({
3992
- security: [{ scheme: "bearer", type: "http" }],
3993
- url: "/cfg/totp/verify/",
3994
- ...options,
3995
- headers: {
3996
- "Content-Type": "application/json",
3997
- ...options.headers
3998
- }
3999
- });
4000
- }
4001
- /**
4002
- * Verify backup recovery code for 2FA session.
4003
- *
4004
- * Alternative verification method when TOTP device unavailable.
4005
- */
4006
- static cfgTotpVerifyBackupCreate(options) {
4007
- return (options.client ?? client3).post({
4008
- security: [{ scheme: "bearer", type: "http" }],
4009
- url: "/cfg/totp/verify/backup/",
4010
- ...options,
4011
- headers: {
4012
- "Content-Type": "application/json",
4013
- ...options.headers
4014
- }
4015
- });
4016
- }
4017
- };
4018
- var Totp = class {
4019
- static {
4020
- __name(this, "Totp");
4021
- }
4022
- /**
4023
- * Get backup codes status for user.
4024
- */
4025
- static cfgTotpBackupCodesRetrieve(options) {
4026
- return (options?.client ?? client3).get({
4027
- security: [{ scheme: "bearer", type: "http" }],
4028
- url: "/cfg/totp/backup-codes/",
4029
- ...options
4030
- });
4031
- }
4032
- /**
4033
- * Regenerate backup codes.
4034
- *
4035
- * Requires TOTP code for verification.
4036
- * Invalidates all existing codes.
4037
- */
4038
- static cfgTotpBackupCodesRegenerateCreate(options) {
4039
- return (options.client ?? client3).post({
4040
- security: [{ scheme: "bearer", type: "http" }],
4041
- url: "/cfg/totp/backup-codes/regenerate/",
4042
- ...options,
4043
- headers: {
4044
- "Content-Type": "application/json",
4045
- ...options.headers
4046
- }
4047
- });
4048
- }
4049
- /**
4050
- * List all TOTP devices for user.
4051
- */
4052
- static cfgTotpDevicesRetrieve(options) {
4053
- return (options?.client ?? client3).get({
4054
- security: [{ scheme: "bearer", type: "http" }],
4055
- url: "/cfg/totp/devices/",
4056
- ...options
4057
- });
4058
- }
4059
- /**
4060
- * Delete a TOTP device.
4061
- *
4062
- * Requires verification code if removing the last/primary device.
4063
- */
4064
- static cfgTotpDevicesDestroy(options) {
4065
- return (options.client ?? client3).delete({
4066
- security: [{ scheme: "bearer", type: "http" }],
4067
- url: "/cfg/totp/devices/{id}/",
4068
- ...options
4069
- });
4070
- }
4071
- /**
4072
- * Completely disable 2FA for account.
4073
- *
4074
- * Requires verification code.
4075
- */
4076
- static cfgTotpDisableCreate(options) {
4077
- return (options.client ?? client3).post({
4078
- security: [{ scheme: "bearer", type: "http" }],
4079
- url: "/cfg/totp/disable/",
4080
- ...options,
4081
- headers: {
4082
- "Content-Type": "application/json",
4083
- ...options.headers
4084
- }
4085
- });
4086
- }
4087
- /**
4088
- * Start 2FA setup process.
4089
- *
4090
- * Creates a new TOTP device and returns QR code for scanning.
4091
- */
4092
- static cfgTotpSetupCreate(options) {
4093
- return (options?.client ?? client3).post({
4094
- security: [{ scheme: "bearer", type: "http" }],
4095
- url: "/cfg/totp/setup/",
4096
- ...options,
4097
- headers: {
4098
- "Content-Type": "application/json",
4099
- ...options?.headers
4100
- }
4101
- });
4102
- }
4103
- /**
4104
- * Confirm 2FA setup with first valid code.
4105
- *
4106
- * Activates the device and generates backup codes.
4107
- */
4108
- static cfgTotpSetupConfirmCreate(options) {
4109
- return (options.client ?? client3).post({
4110
- security: [{ scheme: "bearer", type: "http" }],
4111
- url: "/cfg/totp/setup/confirm/",
4112
- ...options,
4113
- headers: {
4114
- "Content-Type": "application/json",
4115
- ...options.headers
4116
- }
4117
- });
4118
- }
4119
- /**
4120
- * Verify TOTP code for 2FA session.
4121
- *
4122
- * Completes authentication and returns JWT tokens on success.
4123
- */
4124
- static cfgTotpVerifyCreate(options) {
4125
- return (options.client ?? client3).post({
4126
- security: [{ scheme: "bearer", type: "http" }],
4127
- url: "/cfg/totp/verify/",
4128
- ...options,
4129
- headers: {
4130
- "Content-Type": "application/json",
4131
- ...options.headers
4132
- }
4133
- });
4134
- }
4135
- /**
4136
- * Verify backup recovery code for 2FA session.
4137
- *
4138
- * Alternative verification method when TOTP device unavailable.
4139
- */
4140
- static cfgTotpVerifyBackupCreate(options) {
4141
- return (options.client ?? client3).post({
4142
- security: [{ scheme: "bearer", type: "http" }],
4143
- url: "/cfg/totp/verify/backup/",
4144
- ...options,
4145
- headers: {
4146
- "Content-Type": "application/json",
4147
- ...options.headers
4148
- }
4149
- });
4150
- }
4151
- };
4152
- var BackupCodes = class {
4153
- static {
4154
- __name(this, "BackupCodes");
4155
- }
4156
- /**
4157
- * Get backup codes status for user.
4158
- */
4159
- static cfgTotpBackupCodesRetrieve(options) {
4160
- return (options?.client ?? client3).get({
4161
- security: [{ scheme: "bearer", type: "http" }],
4162
- url: "/cfg/totp/backup-codes/",
4163
- ...options
4164
- });
4165
- }
4166
- /**
4167
- * Regenerate backup codes.
4168
- *
4169
- * Requires TOTP code for verification.
4170
- * Invalidates all existing codes.
4171
- */
4172
- static cfgTotpBackupCodesRegenerateCreate(options) {
4173
- return (options.client ?? client3).post({
4174
- security: [{ scheme: "bearer", type: "http" }],
4175
- url: "/cfg/totp/backup-codes/regenerate/",
4176
- ...options,
4177
- headers: {
4178
- "Content-Type": "application/json",
4179
- ...options.headers
4180
- }
4181
- });
4182
- }
4183
- };
4184
- var TotpManagement = class {
4185
- static {
4186
- __name(this, "TotpManagement");
1125
+ setToken(token) {
1126
+ if (token) this.storage.setItem(ACCESS_KEY2, token);
1127
+ else this.storage.removeItem(ACCESS_KEY2);
4187
1128
  }
4188
- /**
4189
- * List all TOTP devices for user.
4190
- */
4191
- static cfgTotpDevicesRetrieve(options) {
4192
- return (options?.client ?? client3).get({
4193
- security: [{ scheme: "bearer", type: "http" }],
4194
- url: "/cfg/totp/devices/",
4195
- ...options
4196
- });
1129
+ getRefreshToken() {
1130
+ return this.storage.getItem(REFRESH_KEY2);
4197
1131
  }
4198
- /**
4199
- * Completely disable 2FA for account.
4200
- *
4201
- * Requires verification code.
4202
- */
4203
- static cfgTotpDisableCreate(options) {
4204
- return (options.client ?? client3).post({
4205
- security: [{ scheme: "bearer", type: "http" }],
4206
- url: "/cfg/totp/disable/",
4207
- ...options,
4208
- headers: {
4209
- "Content-Type": "application/json",
4210
- ...options.headers
4211
- }
4212
- });
1132
+ setRefreshToken(token) {
1133
+ if (token) this.storage.setItem(REFRESH_KEY2, token);
1134
+ else this.storage.removeItem(REFRESH_KEY2);
4213
1135
  }
4214
- };
4215
- var TotpSetup = class {
4216
- static {
4217
- __name(this, "TotpSetup");
1136
+ clearToken() {
1137
+ this.storage.removeItem(ACCESS_KEY2);
1138
+ this.storage.removeItem(REFRESH_KEY2);
4218
1139
  }
4219
- /**
4220
- * Start 2FA setup process.
4221
- *
4222
- * Creates a new TOTP device and returns QR code for scanning.
4223
- */
4224
- static cfgTotpSetupCreate(options) {
4225
- return (options?.client ?? client3).post({
4226
- security: [{ scheme: "bearer", type: "http" }],
4227
- url: "/cfg/totp/setup/",
4228
- ...options,
4229
- headers: {
4230
- "Content-Type": "application/json",
4231
- ...options?.headers
4232
- }
4233
- });
1140
+ isAuthenticated() {
1141
+ return this.getToken() !== null;
4234
1142
  }
4235
- /**
4236
- * Confirm 2FA setup with first valid code.
4237
- *
4238
- * Activates the device and generates backup codes.
4239
- */
4240
- static cfgTotpSetupConfirmCreate(options) {
4241
- return (options.client ?? client3).post({
4242
- security: [{ scheme: "bearer", type: "http" }],
4243
- url: "/cfg/totp/setup/confirm/",
4244
- ...options,
4245
- headers: {
4246
- "Content-Type": "application/json",
4247
- ...options.headers
4248
- }
4249
- });
1143
+ // ── Locale / API key ────────────────────────────────────────────────────
1144
+ getLocale() {
1145
+ return this.locale ?? detectLocale2();
4250
1146
  }
4251
- };
4252
- var TotpVerification = class {
4253
- static {
4254
- __name(this, "TotpVerification");
1147
+ setLocale(locale) {
1148
+ this.locale = locale;
4255
1149
  }
4256
- /**
4257
- * Verify TOTP code for 2FA session.
4258
- *
4259
- * Completes authentication and returns JWT tokens on success.
4260
- */
4261
- static cfgTotpVerifyCreate(options) {
4262
- return (options.client ?? client3).post({
4263
- security: [{ scheme: "bearer", type: "http" }],
4264
- url: "/cfg/totp/verify/",
4265
- ...options,
4266
- headers: {
4267
- "Content-Type": "application/json",
4268
- ...options.headers
4269
- }
4270
- });
1150
+ getApiKey() {
1151
+ return this.apiKey;
4271
1152
  }
4272
- /**
4273
- * Verify backup recovery code for 2FA session.
4274
- *
4275
- * Alternative verification method when TOTP device unavailable.
4276
- */
4277
- static cfgTotpVerifyBackupCreate(options) {
4278
- return (options.client ?? client3).post({
4279
- security: [{ scheme: "bearer", type: "http" }],
4280
- url: "/cfg/totp/verify/backup/",
4281
- ...options,
4282
- headers: {
4283
- "Content-Type": "application/json",
4284
- ...options.headers
4285
- }
4286
- });
1153
+ setApiKey(key) {
1154
+ this.apiKey = key;
4287
1155
  }
4288
1156
  };
4289
1157
 
4290
- // src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateRequest.ts
4291
- var import_zod23 = require("zod");
4292
- var BackupCodesRegenerateRequestSchema = import_zod23.z.object({
4293
- code: import_zod23.z.string().min(6).max(6)
4294
- });
4295
-
4296
- // src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateResponse.ts
4297
- var import_zod24 = require("zod");
4298
- var BackupCodesRegenerateResponseSchema = import_zod24.z.object({
4299
- backup_codes: import_zod24.z.array(import_zod24.z.string()),
4300
- warning: import_zod24.z.string()
4301
- });
4302
-
4303
- // src/_api/generated/cfg_totp/schemas/BackupCodesStatus.ts
4304
- var import_zod25 = require("zod");
4305
- var BackupCodesStatusSchema = import_zod25.z.object({
4306
- remaining_count: import_zod25.z.number().int(),
4307
- total_generated: import_zod25.z.number().int(),
4308
- warning: import_zod25.z.string().nullable().optional()
4309
- });
4310
-
4311
- // src/_api/generated/cfg_totp/schemas/ConfirmSetupRequest.ts
4312
- var import_zod26 = require("zod");
4313
- var ConfirmSetupRequestSchema = import_zod26.z.object({
4314
- device_id: import_zod26.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
4315
- code: import_zod26.z.string().min(6).max(6)
4316
- });
4317
-
4318
- // src/_api/generated/cfg_totp/schemas/ConfirmSetupResponse.ts
4319
- var import_zod27 = require("zod");
4320
- var ConfirmSetupResponseSchema = import_zod27.z.object({
4321
- message: import_zod27.z.string(),
4322
- backup_codes: import_zod27.z.array(import_zod27.z.string()),
4323
- backup_codes_warning: import_zod27.z.string()
4324
- });
4325
-
4326
- // src/_api/generated/cfg_totp/schemas/DeviceList.ts
4327
- var import_zod29 = require("zod");
4328
-
4329
- // src/_api/generated/cfg_totp/schemas/DeviceListStatusEnum.ts
4330
- var import_zod28 = require("zod");
4331
- var DeviceListStatusEnumSchema = import_zod28.z.enum(["pending", "active", "disabled"]);
4332
-
4333
- // src/_api/generated/cfg_totp/schemas/DeviceList.ts
4334
- var DeviceListSchema = import_zod29.z.object({
4335
- id: import_zod29.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
4336
- name: import_zod29.z.string(),
4337
- is_primary: import_zod29.z.boolean(),
4338
- status: DeviceListStatusEnumSchema,
4339
- created_at: import_zod29.z.string().datetime({ offset: true }),
4340
- confirmed_at: import_zod29.z.string().datetime({ offset: true }).nullable(),
4341
- last_used_at: import_zod29.z.string().datetime({ offset: true }).nullable()
4342
- });
4343
-
4344
- // src/_api/generated/cfg_totp/schemas/DeviceListResponse.ts
4345
- var import_zod30 = require("zod");
4346
- var DeviceListResponseSchema = import_zod30.z.object({
4347
- devices: import_zod30.z.array(DeviceListSchema),
4348
- has_2fa_enabled: import_zod30.z.boolean()
4349
- });
4350
-
4351
- // src/_api/generated/cfg_totp/schemas/DisableRequest.ts
4352
- var import_zod31 = require("zod");
4353
- var DisableRequestSchema = import_zod31.z.object({
4354
- code: import_zod31.z.string().min(6).max(6)
4355
- });
4356
-
4357
- // src/_api/generated/cfg_totp/schemas/SetupRequest.ts
4358
- var import_zod32 = require("zod");
4359
- var SetupRequestSchema = import_zod32.z.object({
4360
- device_name: import_zod32.z.string().min(1).max(100).optional()
4361
- });
4362
-
4363
- // src/_api/generated/cfg_totp/schemas/SetupResponse.ts
4364
- var import_zod33 = require("zod");
4365
- var SetupResponseSchema = import_zod33.z.object({
4366
- device_id: import_zod33.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
4367
- secret: import_zod33.z.string(),
4368
- provisioning_uri: import_zod33.z.string(),
4369
- qr_code_base64: import_zod33.z.string(),
4370
- expires_in: import_zod33.z.number().int()
4371
- });
4372
-
4373
- // src/_api/generated/cfg_totp/schemas/TotpVerifyUser.ts
4374
- var import_zod34 = require("zod");
4375
- var TotpVerifyUserSchema = import_zod34.z.object({
4376
- id: import_zod34.z.number().int(),
4377
- email: import_zod34.z.email(),
4378
- first_name: import_zod34.z.string().max(50).optional(),
4379
- last_name: import_zod34.z.string().max(50).optional(),
4380
- full_name: import_zod34.z.string(),
4381
- initials: import_zod34.z.string(),
4382
- display_username: import_zod34.z.string(),
4383
- company: import_zod34.z.string().max(100).optional(),
4384
- phone: import_zod34.z.string().max(20).optional(),
4385
- position: import_zod34.z.string().max(100).optional(),
4386
- language: import_zod34.z.string().max(10).optional(),
4387
- avatar: import_zod34.z.string().nullable(),
4388
- is_staff: import_zod34.z.boolean(),
4389
- is_superuser: import_zod34.z.boolean(),
4390
- date_joined: import_zod34.z.string().datetime({ offset: true }),
4391
- last_login: import_zod34.z.string().datetime({ offset: true }).nullable(),
4392
- unanswered_messages_count: import_zod34.z.number().int()
4393
- });
4394
-
4395
- // src/_api/generated/cfg_totp/schemas/VerifyBackupRequest.ts
4396
- var import_zod35 = require("zod");
4397
- var VerifyBackupRequestSchema = import_zod35.z.object({
4398
- session_id: import_zod35.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
4399
- backup_code: import_zod35.z.string().min(8).max(8)
4400
- });
4401
-
4402
- // src/_api/generated/cfg_totp/schemas/VerifyRequest.ts
4403
- var import_zod36 = require("zod");
4404
- var VerifyRequestSchema = import_zod36.z.object({
4405
- session_id: import_zod36.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
4406
- code: import_zod36.z.string().min(6).max(6)
4407
- });
4408
-
4409
- // src/_api/generated/cfg_totp/schemas/VerifyResponse.ts
4410
- var import_zod37 = require("zod");
4411
- var VerifyResponseSchema = import_zod37.z.object({
4412
- message: import_zod37.z.string(),
4413
- access_token: import_zod37.z.string(),
4414
- refresh_token: import_zod37.z.string(),
4415
- user: TotpVerifyUserSchema,
4416
- remaining_backup_codes: import_zod37.z.number().int().optional(),
4417
- warning: import_zod37.z.string().optional()
4418
- });
4419
-
4420
- // src/_api/generated/cfg_totp/api.ts
1158
+ // src/_api/generated/_cfg_totp/api.ts
4421
1159
  var ACCESS_KEY3 = "cfg.access_token";
4422
1160
  var REFRESH_KEY3 = "cfg.refresh_token";
4423
- var VALIDATION_ROUTES3 = [
4424
- { method: "GET", re: new RegExp("^/cfg/totp/backup\\-codes/?$"), schema: BackupCodesStatusSchema, path: "/cfg/totp/backup-codes/" },
4425
- { method: "POST", re: new RegExp("^/cfg/totp/backup\\-codes/regenerate/?$"), schema: BackupCodesRegenerateResponseSchema, path: "/cfg/totp/backup-codes/regenerate/" },
4426
- { method: "GET", re: new RegExp("^/cfg/totp/devices/?$"), schema: DeviceListResponseSchema, path: "/cfg/totp/devices/" },
4427
- { method: "POST", re: new RegExp("^/cfg/totp/setup/?$"), schema: SetupResponseSchema, path: "/cfg/totp/setup/" },
4428
- { method: "POST", re: new RegExp("^/cfg/totp/setup/confirm/?$"), schema: ConfirmSetupResponseSchema, path: "/cfg/totp/setup/confirm/" },
4429
- { method: "POST", re: new RegExp("^/cfg/totp/verify/?$"), schema: VerifyResponseSchema, path: "/cfg/totp/verify/" },
4430
- { method: "POST", re: new RegExp("^/cfg/totp/verify/backup/?$"), schema: VerifyResponseSchema, path: "/cfg/totp/verify/backup/" }
4431
- ];
4432
1161
  function detectLocale3() {
4433
1162
  try {
4434
1163
  if (typeof document !== "undefined") {
@@ -4452,12 +1181,6 @@ var API3 = class {
4452
1181
  locale;
4453
1182
  apiKey;
4454
1183
  logger;
4455
- cfg = Cfg3;
4456
- totp = Totp;
4457
- backupCodes = BackupCodes;
4458
- totpManagement = TotpManagement;
4459
- totpSetup = TotpSetup;
4460
- totpVerification = TotpVerification;
4461
1184
  constructor(baseUrl2, opts = {}) {
4462
1185
  this.baseUrl = baseUrl2.replace(/\/$/, "");
4463
1186
  this.storage = opts.storage ?? new LocalStorageAdapter();
@@ -4465,8 +1188,8 @@ var API3 = class {
4465
1188
  this.locale = opts.locale ?? null;
4466
1189
  this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
4467
1190
  const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
4468
- client3.setConfig({ baseUrl: this.baseUrl, credentials });
4469
- client3.interceptors.request.use((request) => {
1191
+ client.setConfig({ baseUrl: this.baseUrl, credentials });
1192
+ client.interceptors.request.use((request) => {
4470
1193
  const access = this.getToken();
4471
1194
  if (access) request.headers.set("Authorization", `Bearer ${access}`);
4472
1195
  const locale = this.locale ?? detectLocale3();
@@ -4474,35 +1197,6 @@ var API3 = class {
4474
1197
  if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
4475
1198
  return request;
4476
1199
  });
4477
- client3.interceptors.response.use(async (response, request) => {
4478
- if (!response.ok) return response;
4479
- const ct = response.headers.get("content-type") || "";
4480
- if (!ct.includes("application/json")) return response;
4481
- const url = new URL(request.url);
4482
- const method = request.method.toUpperCase();
4483
- const route = VALIDATION_ROUTES3.find(
4484
- (r) => r.method === method && r.re.test(url.pathname)
4485
- );
4486
- if (!route) return response;
4487
- let payload;
4488
- try {
4489
- payload = await response.clone().json();
4490
- } catch {
4491
- return response;
4492
- }
4493
- const result = route.schema.safeParse(payload);
4494
- if (!result.success) {
4495
- dispatchValidationError({
4496
- operation: `${method} ${route.path}`,
4497
- path: route.path,
4498
- method,
4499
- error: result.error,
4500
- response: payload,
4501
- timestamp: /* @__PURE__ */ new Date()
4502
- });
4503
- }
4504
- return response;
4505
- });
4506
1200
  }
4507
1201
  // ── Base URL ────────────────────────────────────────────────────────────
4508
1202
  getBaseUrl() {
@@ -4510,7 +1204,7 @@ var API3 = class {
4510
1204
  }
4511
1205
  setBaseUrl(url) {
4512
1206
  this.baseUrl = url.replace(/\/$/, "");
4513
- client3.setConfig({ baseUrl: this.baseUrl });
1207
+ client.setConfig({ baseUrl: this.baseUrl });
4514
1208
  }
4515
1209
  // ── Tokens ──────────────────────────────────────────────────────────────
4516
1210
  getToken() {
@@ -4552,9 +1246,29 @@ var API3 = class {
4552
1246
  // src/_api/generated/index.ts
4553
1247
  var isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
4554
1248
  var baseUrl = isStaticBuild ? "" : process.env.NEXT_PUBLIC_API_URL || "";
4555
- var cfgAccountsApi = new API(baseUrl, { storage: new LocalStorageAdapter() });
4556
- var cfgCentrifugoApi = new API2(baseUrl, { storage: new LocalStorageAdapter() });
4557
- var cfgTotpApi = new API3(baseUrl, { storage: new LocalStorageAdapter() });
1249
+ var CfgAccountsApi = new API(baseUrl, { storage: new LocalStorageAdapter() });
1250
+ var CfgCentrifugoApi = new API2(baseUrl, { storage: new LocalStorageAdapter() });
1251
+ var CfgTotpApi = new API3(baseUrl, { storage: new LocalStorageAdapter() });
1252
+
1253
+ // src/_api/generated/sdk.gen.ts
1254
+ var Auth = class {
1255
+ static {
1256
+ __name(this, "Auth");
1257
+ }
1258
+ /**
1259
+ * Refresh JWT token.
1260
+ */
1261
+ static cfgAccountsTokenRefreshCreate(options) {
1262
+ return (options.client ?? client).post({
1263
+ url: "/cfg/accounts/token/refresh/",
1264
+ ...options,
1265
+ headers: {
1266
+ "Content-Type": "application/json",
1267
+ ...options.headers
1268
+ }
1269
+ });
1270
+ }
1271
+ };
4558
1272
 
4559
1273
  // src/auth/utils/logger.ts
4560
1274
  var import_consola2 = require("consola");
@@ -4592,13 +1306,13 @@ async function refreshAccessToken() {
4592
1306
  isRefreshing = true;
4593
1307
  authLogger.info("Starting token refresh...");
4594
1308
  try {
4595
- const refreshToken = cfgAccountsApi.getRefreshToken();
1309
+ const refreshToken = CfgAccountsApi.getRefreshToken();
4596
1310
  if (!refreshToken) {
4597
1311
  authLogger.warn("No refresh token available for refresh");
4598
1312
  onTokenRefreshed(null);
4599
1313
  return null;
4600
1314
  }
4601
- const result = await cfgAccountsApi.auth.cfgAccountsTokenRefreshCreate({
1315
+ const result = await Auth.cfgAccountsTokenRefreshCreate({
4602
1316
  body: { refresh: refreshToken },
4603
1317
  throwOnError: true
4604
1318
  });
@@ -4608,8 +1322,8 @@ async function refreshAccessToken() {
4608
1322
  onTokenRefreshed(null);
4609
1323
  return null;
4610
1324
  }
4611
- cfgAccountsApi.setToken(newAccessToken);
4612
- cfgAccountsApi.setRefreshToken(refreshToken);
1325
+ CfgAccountsApi.setToken(newAccessToken);
1326
+ CfgAccountsApi.setRefreshToken(refreshToken);
4613
1327
  authLogger.info("Token refreshed successfully");
4614
1328
  onTokenRefreshed(newAccessToken);
4615
1329
  return newAccessToken;
@@ -4629,7 +1343,7 @@ __name(isAuthenticationError, "isAuthenticationError");
4629
1343
  function createAutoRefreshFetch(originalFetch) {
4630
1344
  return async (input, init) => {
4631
1345
  let response = await originalFetch(input, init);
4632
- if (isAuthenticationError(response) && cfgAccountsApi.getRefreshToken()) {
1346
+ if (isAuthenticationError(response) && CfgAccountsApi.getRefreshToken()) {
4633
1347
  authLogger.info("Received 401, attempting token refresh...");
4634
1348
  const newToken = await refreshAccessToken();
4635
1349
  if (newToken) {
@@ -4651,7 +1365,7 @@ function createAutoRefreshFetch(originalFetch) {
4651
1365
  }
4652
1366
  __name(createAutoRefreshFetch, "createAutoRefreshFetch");
4653
1367
  function isTokenExpiringSoon(thresholdMs = 5 * 60 * 1e3) {
4654
- const token = cfgAccountsApi.getToken();
1368
+ const token = CfgAccountsApi.getToken();
4655
1369
  if (!token) return false;
4656
1370
  try {
4657
1371
  const payload = JSON.parse(atob(token.split(".")[1]));