@djangocfg/api 2.1.322 → 2.1.327

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 (293) hide show
  1. package/dist/auth-server.cjs +4265 -1169
  2. package/dist/auth-server.cjs.map +1 -1
  3. package/dist/auth-server.mjs +4265 -1159
  4. package/dist/auth-server.mjs.map +1 -1
  5. package/dist/auth.cjs +4150 -3053
  6. package/dist/auth.cjs.map +1 -1
  7. package/dist/auth.d.cts +158 -209
  8. package/dist/auth.d.ts +158 -209
  9. package/dist/auth.mjs +4139 -3042
  10. package/dist/auth.mjs.map +1 -1
  11. package/dist/clients.cjs +3932 -4031
  12. package/dist/clients.cjs.map +1 -1
  13. package/dist/clients.d.cts +2408 -2671
  14. package/dist/clients.d.ts +2408 -2671
  15. package/dist/clients.mjs +3945 -4038
  16. package/dist/clients.mjs.map +1 -1
  17. package/dist/index.cjs +4214 -2713
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +2758 -1828
  20. package/dist/index.d.ts +2758 -1828
  21. package/dist/index.mjs +4183 -2676
  22. package/dist/index.mjs.map +1 -1
  23. package/package.json +2 -7
  24. package/src/_api/generated/_shared/errors.ts +70 -0
  25. package/src/_api/generated/_shared/index.ts +25 -0
  26. package/src/_api/generated/_shared/logger.ts +123 -0
  27. package/src/_api/generated/_shared/storage.ts +83 -0
  28. package/src/_api/generated/_shared/validation-events.ts +52 -0
  29. package/src/_api/generated/cfg_accounts/api.ts +187 -0
  30. package/src/_api/generated/cfg_accounts/client/client.gen.ts +280 -0
  31. package/src/_api/generated/cfg_accounts/client/index.ts +25 -0
  32. package/src/_api/generated/cfg_accounts/client/types.gen.ts +217 -0
  33. package/src/_api/generated/cfg_accounts/client/utils.gen.ts +318 -0
  34. package/src/_api/generated/cfg_accounts/client.gen.ts +16 -0
  35. package/src/_api/generated/cfg_accounts/core/auth.gen.ts +41 -0
  36. package/src/_api/generated/cfg_accounts/core/bodySerializer.gen.ts +82 -0
  37. package/src/_api/generated/cfg_accounts/core/params.gen.ts +169 -0
  38. package/src/_api/generated/cfg_accounts/core/pathSerializer.gen.ts +171 -0
  39. package/src/_api/generated/cfg_accounts/core/queryKeySerializer.gen.ts +117 -0
  40. package/src/_api/generated/cfg_accounts/core/serverSentEvents.gen.ts +242 -0
  41. package/src/_api/generated/cfg_accounts/core/types.gen.ts +104 -0
  42. package/src/_api/generated/cfg_accounts/core/utils.gen.ts +140 -0
  43. package/src/_api/generated/cfg_accounts/events.ts +198 -0
  44. package/src/_api/generated/cfg_accounts/hooks/index.ts +18 -0
  45. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +26 -0
  46. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthDisconnectCreate.ts +24 -0
  47. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +24 -0
  48. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +24 -0
  49. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +26 -0
  50. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpRequestCreate.ts +24 -0
  51. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts +24 -0
  52. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileAvatarCreate.ts +24 -0
  53. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileDeleteCreate.ts +24 -0
  54. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +24 -0
  55. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialUpdate.ts +24 -0
  56. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +26 -0
  57. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +24 -0
  58. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdateUpdate.ts +24 -0
  59. package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsTokenRefreshCreate.ts +24 -0
  60. package/src/_api/generated/cfg_accounts/index.ts +26 -335
  61. package/src/_api/generated/cfg_accounts/schemas/AccountDeleteResponse.ts +12 -0
  62. package/src/_api/generated/cfg_accounts/schemas/CentrifugoToken.ts +14 -0
  63. package/src/_api/generated/cfg_accounts/schemas/CfgUserUpdateRequest.ts +16 -0
  64. package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts +12 -0
  65. package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeResponse.ts +12 -0
  66. package/src/_api/generated/cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +13 -0
  67. package/src/_api/generated/cfg_accounts/schemas/OAuthConnection.ts +19 -0
  68. package/src/_api/generated/cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts +12 -0
  69. package/src/_api/generated/cfg_accounts/schemas/OAuthError.ts +12 -0
  70. package/src/_api/generated/cfg_accounts/schemas/OAuthProvidersResponse.ts +11 -0
  71. package/src/_api/generated/cfg_accounts/schemas/OAuthTokenResponse.ts +18 -0
  72. package/src/_api/generated/cfg_accounts/schemas/OTPErrorResponse.ts +13 -0
  73. package/src/_api/generated/cfg_accounts/schemas/OTPRequestRequest.ts +12 -0
  74. package/src/_api/generated/cfg_accounts/schemas/OTPRequestResponse.ts +11 -0
  75. package/src/_api/generated/cfg_accounts/schemas/OTPVerifyRequest.ts +13 -0
  76. package/src/_api/generated/cfg_accounts/schemas/OTPVerifyResponse.ts +17 -0
  77. package/src/_api/generated/cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts +16 -0
  78. package/src/_api/generated/cfg_accounts/schemas/ProviderEnum.ts +9 -0
  79. package/src/_api/generated/cfg_accounts/schemas/TokenRefresh.ts +12 -0
  80. package/src/_api/generated/cfg_accounts/schemas/TokenRefreshRequest.ts +11 -0
  81. package/src/_api/generated/cfg_accounts/{_utils/schemas/User.schema.ts → schemas/User.ts} +8 -16
  82. package/src/_api/generated/cfg_accounts/schemas/index.ts +24 -0
  83. package/src/_api/generated/cfg_accounts/sdk.gen.ts +796 -0
  84. package/src/_api/generated/cfg_accounts/types.gen.ts +764 -0
  85. package/src/_api/generated/cfg_centrifugo/api.ts +164 -0
  86. package/src/_api/generated/cfg_centrifugo/client/client.gen.ts +280 -0
  87. package/src/_api/generated/cfg_centrifugo/client/index.ts +25 -0
  88. package/src/_api/generated/cfg_centrifugo/client/types.gen.ts +217 -0
  89. package/src/_api/generated/cfg_centrifugo/client/utils.gen.ts +318 -0
  90. package/src/_api/generated/cfg_centrifugo/client.gen.ts +16 -0
  91. package/src/_api/generated/cfg_centrifugo/core/auth.gen.ts +41 -0
  92. package/src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts +82 -0
  93. package/src/_api/generated/cfg_centrifugo/core/params.gen.ts +169 -0
  94. package/src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts +171 -0
  95. package/src/_api/generated/cfg_centrifugo/core/queryKeySerializer.gen.ts +117 -0
  96. package/src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts +242 -0
  97. package/src/_api/generated/cfg_centrifugo/core/types.gen.ts +104 -0
  98. package/src/_api/generated/cfg_centrifugo/core/utils.gen.ts +140 -0
  99. package/src/_api/generated/cfg_centrifugo/events.ts +198 -0
  100. package/src/_api/generated/cfg_centrifugo/hooks/index.ts +4 -0
  101. package/src/_api/generated/cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +26 -0
  102. package/src/_api/generated/cfg_centrifugo/index.ts +26 -313
  103. package/src/_api/generated/cfg_centrifugo/schemas/ConnectionTokenResponse.ts +14 -0
  104. package/src/_api/generated/cfg_centrifugo/schemas/index.ts +4 -0
  105. package/src/_api/generated/cfg_centrifugo/sdk.gen.ts +64 -0
  106. package/src/_api/generated/cfg_centrifugo/types.gen.ts +61 -0
  107. package/src/_api/generated/cfg_totp/api.ts +181 -0
  108. package/src/_api/generated/cfg_totp/client/client.gen.ts +280 -0
  109. package/src/_api/generated/cfg_totp/client/index.ts +25 -0
  110. package/src/_api/generated/cfg_totp/client/types.gen.ts +217 -0
  111. package/src/_api/generated/cfg_totp/client/utils.gen.ts +318 -0
  112. package/src/_api/generated/cfg_totp/client.gen.ts +16 -0
  113. package/src/_api/generated/cfg_totp/core/auth.gen.ts +41 -0
  114. package/src/_api/generated/cfg_totp/core/bodySerializer.gen.ts +82 -0
  115. package/src/_api/generated/cfg_totp/core/params.gen.ts +169 -0
  116. package/src/_api/generated/cfg_totp/core/pathSerializer.gen.ts +171 -0
  117. package/src/_api/generated/cfg_totp/core/queryKeySerializer.gen.ts +117 -0
  118. package/src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts +242 -0
  119. package/src/_api/generated/cfg_totp/core/types.gen.ts +104 -0
  120. package/src/_api/generated/cfg_totp/core/utils.gen.ts +140 -0
  121. package/src/_api/generated/cfg_totp/events.ts +198 -0
  122. package/src/_api/generated/cfg_totp/hooks/index.ts +12 -0
  123. package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +24 -0
  124. package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +26 -0
  125. package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesDestroy.ts +24 -0
  126. package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +26 -0
  127. package/src/_api/generated/cfg_totp/hooks/useCfgTotpDisableCreate.ts +24 -0
  128. package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupConfirmCreate.ts +24 -0
  129. package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupCreate.ts +24 -0
  130. package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyBackupCreate.ts +24 -0
  131. package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyCreate.ts +24 -0
  132. package/src/_api/generated/cfg_totp/index.ts +26 -342
  133. package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateRequest.ts +11 -0
  134. package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateResponse.ts +12 -0
  135. package/src/_api/generated/cfg_totp/schemas/BackupCodesStatus.ts +13 -0
  136. package/src/_api/generated/cfg_totp/schemas/ConfirmSetupRequest.ts +12 -0
  137. package/src/_api/generated/cfg_totp/schemas/ConfirmSetupResponse.ts +13 -0
  138. package/src/_api/generated/cfg_totp/schemas/DeviceList.ts +18 -0
  139. package/src/_api/generated/cfg_totp/schemas/DeviceListResponse.ts +13 -0
  140. package/src/_api/generated/cfg_totp/schemas/DeviceListStatusEnum.ts +9 -0
  141. package/src/_api/generated/cfg_totp/schemas/DisableRequest.ts +11 -0
  142. package/src/_api/generated/cfg_totp/schemas/SetupRequest.ts +11 -0
  143. package/src/_api/generated/cfg_totp/schemas/SetupResponse.ts +15 -0
  144. package/src/_api/generated/cfg_totp/{_utils/schemas/TotpVerifyUser.schema.ts → schemas/TotpVerifyUser.ts} +7 -15
  145. package/src/_api/generated/cfg_totp/schemas/VerifyBackupRequest.ts +12 -0
  146. package/src/_api/generated/cfg_totp/schemas/VerifyRequest.ts +12 -0
  147. package/src/_api/generated/cfg_totp/schemas/VerifyResponse.ts +17 -0
  148. package/src/_api/generated/cfg_totp/schemas/index.ts +18 -0
  149. package/src/_api/generated/cfg_totp/sdk.gen.ts +432 -0
  150. package/src/_api/generated/cfg_totp/types.gen.ts +479 -0
  151. package/src/_api/generated/index.ts +30 -0
  152. package/src/_api/index.ts +5 -23
  153. package/src/auth/context/AccountsContext.tsx +58 -89
  154. package/src/auth/context/AuthContext.tsx +3 -3
  155. package/src/auth/context/index.ts +2 -2
  156. package/src/auth/hooks/useDeleteAccount.ts +2 -1
  157. package/src/auth/hooks/useGithubAuth.ts +12 -11
  158. package/src/auth/hooks/useTokenRefresh.ts +6 -4
  159. package/src/auth/hooks/useTwoFactor.ts +14 -8
  160. package/src/auth/hooks/useTwoFactorSetup.ts +8 -5
  161. package/src/auth/hooks/useTwoFactorStatus.ts +3 -2
  162. package/src/auth/middlewares/tokenRefresh.ts +6 -4
  163. package/src/clients.ts +14 -51
  164. package/src/index.ts +15 -57
  165. package/src/server.ts +25 -23
  166. package/src/_api/BaseClient.ts +0 -22
  167. package/src/_api/generated/cfg_accounts/CLAUDE.md +0 -86
  168. package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts.ts +0 -154
  169. package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts +0 -95
  170. package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts +0 -285
  171. package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__user_profile.ts +0 -440
  172. package/src/_api/generated/cfg_accounts/_utils/fetchers/index.ts +0 -33
  173. package/src/_api/generated/cfg_accounts/_utils/hooks/accounts.ts +0 -64
  174. package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__auth.ts +0 -44
  175. package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__oauth.ts +0 -114
  176. package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__user_profile.ts +0 -152
  177. package/src/_api/generated/cfg_accounts/_utils/hooks/index.ts +0 -33
  178. package/src/_api/generated/cfg_accounts/_utils/schemas/AccountDeleteResponse.schema.ts +0 -20
  179. package/src/_api/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +0 -22
  180. package/src/_api/generated/cfg_accounts/_utils/schemas/CfgAccountsProfileAvatarCreateRequest.schema.ts +0 -15
  181. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +0 -20
  182. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +0 -20
  183. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +0 -21
  184. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +0 -27
  185. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthDisconnectRequestRequest.schema.ts +0 -20
  186. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthError.schema.ts +0 -20
  187. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +0 -19
  188. package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +0 -46
  189. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts +0 -41
  190. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +0 -20
  191. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts +0 -19
  192. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +0 -21
  193. package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts +0 -45
  194. package/src/_api/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts +0 -24
  195. package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefresh.schema.ts +0 -16
  196. package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefreshRequest.schema.ts +0 -15
  197. package/src/_api/generated/cfg_accounts/_utils/schemas/UserProfileUpdateRequest.schema.ts +0 -24
  198. package/src/_api/generated/cfg_accounts/_utils/schemas/index.ts +0 -41
  199. package/src/_api/generated/cfg_accounts/accounts/client.ts +0 -34
  200. package/src/_api/generated/cfg_accounts/accounts/index.ts +0 -4
  201. package/src/_api/generated/cfg_accounts/accounts/models.ts +0 -127
  202. package/src/_api/generated/cfg_accounts/accounts__auth/client.ts +0 -23
  203. package/src/_api/generated/cfg_accounts/accounts__auth/index.ts +0 -4
  204. package/src/_api/generated/cfg_accounts/accounts__auth/models.ts +0 -19
  205. package/src/_api/generated/cfg_accounts/accounts__oauth/client.ts +0 -67
  206. package/src/_api/generated/cfg_accounts/accounts__oauth/index.ts +0 -4
  207. package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +0 -127
  208. package/src/_api/generated/cfg_accounts/accounts__user_profile/client.ts +0 -94
  209. package/src/_api/generated/cfg_accounts/accounts__user_profile/index.ts +0 -4
  210. package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +0 -98
  211. package/src/_api/generated/cfg_accounts/api-instance.ts +0 -181
  212. package/src/_api/generated/cfg_accounts/client.ts +0 -339
  213. package/src/_api/generated/cfg_accounts/enums.ts +0 -10
  214. package/src/_api/generated/cfg_accounts/errors.ts +0 -123
  215. package/src/_api/generated/cfg_accounts/http.ts +0 -160
  216. package/src/_api/generated/cfg_accounts/logger.ts +0 -261
  217. package/src/_api/generated/cfg_accounts/retry.ts +0 -177
  218. package/src/_api/generated/cfg_accounts/schema.json +0 -1576
  219. package/src/_api/generated/cfg_accounts/storage.ts +0 -163
  220. package/src/_api/generated/cfg_accounts/validation-events.ts +0 -135
  221. package/src/_api/generated/cfg_centrifugo/CLAUDE.md +0 -60
  222. package/src/_api/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_auth.ts +0 -94
  223. package/src/_api/generated/cfg_centrifugo/_utils/fetchers/index.ts +0 -30
  224. package/src/_api/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_auth.ts +0 -39
  225. package/src/_api/generated/cfg_centrifugo/_utils/hooks/index.ts +0 -30
  226. package/src/_api/generated/cfg_centrifugo/_utils/schemas/ConnectionTokenResponse.schema.ts +0 -22
  227. package/src/_api/generated/cfg_centrifugo/_utils/schemas/index.ts +0 -21
  228. package/src/_api/generated/cfg_centrifugo/api-instance.ts +0 -181
  229. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/client.ts +0 -27
  230. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/index.ts +0 -4
  231. package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/models.ts +0 -18
  232. package/src/_api/generated/cfg_centrifugo/client.ts +0 -330
  233. package/src/_api/generated/cfg_centrifugo/errors.ts +0 -123
  234. package/src/_api/generated/cfg_centrifugo/http.ts +0 -160
  235. package/src/_api/generated/cfg_centrifugo/logger.ts +0 -261
  236. package/src/_api/generated/cfg_centrifugo/retry.ts +0 -177
  237. package/src/_api/generated/cfg_centrifugo/schema.json +0 -118
  238. package/src/_api/generated/cfg_centrifugo/storage.ts +0 -163
  239. package/src/_api/generated/cfg_centrifugo/validation-events.ts +0 -135
  240. package/src/_api/generated/cfg_totp/CLAUDE.md +0 -83
  241. package/src/_api/generated/cfg_totp/_utils/fetchers/index.ts +0 -34
  242. package/src/_api/generated/cfg_totp/_utils/fetchers/totp.ts +0 -50
  243. package/src/_api/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +0 -153
  244. package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_management.ts +0 -109
  245. package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_setup.ts +0 -154
  246. package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_verification.ts +0 -153
  247. package/src/_api/generated/cfg_totp/_utils/hooks/index.ts +0 -34
  248. package/src/_api/generated/cfg_totp/_utils/hooks/totp.ts +0 -43
  249. package/src/_api/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +0 -60
  250. package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_management.ts +0 -59
  251. package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_setup.ts +0 -64
  252. package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_verification.ts +0 -63
  253. package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +0 -19
  254. package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +0 -20
  255. package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +0 -21
  256. package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +0 -20
  257. package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +0 -21
  258. package/src/_api/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +0 -26
  259. package/src/_api/generated/cfg_totp/_utils/schemas/DeviceListResponse.schema.ts +0 -21
  260. package/src/_api/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +0 -19
  261. package/src/_api/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +0 -19
  262. package/src/_api/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +0 -23
  263. package/src/_api/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +0 -20
  264. package/src/_api/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +0 -20
  265. package/src/_api/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +0 -25
  266. package/src/_api/generated/cfg_totp/_utils/schemas/index.ts +0 -34
  267. package/src/_api/generated/cfg_totp/api-instance.ts +0 -181
  268. package/src/_api/generated/cfg_totp/client.ts +0 -342
  269. package/src/_api/generated/cfg_totp/enums.ts +0 -13
  270. package/src/_api/generated/cfg_totp/errors.ts +0 -123
  271. package/src/_api/generated/cfg_totp/http.ts +0 -160
  272. package/src/_api/generated/cfg_totp/logger.ts +0 -261
  273. package/src/_api/generated/cfg_totp/retry.ts +0 -177
  274. package/src/_api/generated/cfg_totp/schema.json +0 -910
  275. package/src/_api/generated/cfg_totp/storage.ts +0 -163
  276. package/src/_api/generated/cfg_totp/totp/client.ts +0 -24
  277. package/src/_api/generated/cfg_totp/totp/index.ts +0 -4
  278. package/src/_api/generated/cfg_totp/totp/models.ts +0 -4
  279. package/src/_api/generated/cfg_totp/totp__backup_codes/client.ts +0 -32
  280. package/src/_api/generated/cfg_totp/totp__backup_codes/index.ts +0 -4
  281. package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +0 -38
  282. package/src/_api/generated/cfg_totp/totp__totp_management/client.ts +0 -31
  283. package/src/_api/generated/cfg_totp/totp__totp_management/index.ts +0 -4
  284. package/src/_api/generated/cfg_totp/totp__totp_management/models.ts +0 -46
  285. package/src/_api/generated/cfg_totp/totp__totp_setup/client.ts +0 -33
  286. package/src/_api/generated/cfg_totp/totp__totp_setup/index.ts +0 -4
  287. package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +0 -55
  288. package/src/_api/generated/cfg_totp/totp__totp_verification/client.ts +0 -33
  289. package/src/_api/generated/cfg_totp/totp__totp_verification/index.ts +0 -4
  290. package/src/_api/generated/cfg_totp/totp__totp_verification/models.ts +0 -74
  291. package/src/_api/generated/cfg_totp/validation-events.ts +0 -135
  292. package/src/hooks/accounts.ts +0 -8
  293. package/src/hooks/index.ts +0 -10
@@ -1,316 +1,29 @@
1
- // @ts-nocheck
2
- // Auto-generated by DjangoCFG - see CLAUDE.md
3
- /**
4
- * Django CFG API - API Client with JWT Management
5
- *
6
- * Usage:
7
- * ```typescript
8
- * import { API } from './api';
9
- *
10
- * const api = new API('https://api.example.com');
11
- *
12
- * // Set JWT token
13
- * api.setToken('your-jwt-token', 'refresh-token');
14
- *
15
- * // Use API
16
- * const posts = await api.posts.list();
17
- * const user = await api.users.retrieve(1);
18
- *
19
- * // Check authentication
20
- * if (api.isAuthenticated()) {
21
- * // ...
22
- * }
23
- *
24
- * // Custom storage with logging (for Electron/Node.js)
25
- * import { MemoryStorageAdapter, APILogger } from './storage';
26
- * const logger = new APILogger({ enabled: true, logLevel: 'debug' });
27
- * const api = new API('https://api.example.com', {
28
- * storage: new MemoryStorageAdapter(logger),
29
- * loggerConfig: { enabled: true, logLevel: 'debug' }
30
- * });
31
- *
32
- * // Get OpenAPI schema
33
- * const schema = api.getSchema();
34
- * ```
35
- */
1
+ // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
+ // Group barrel. DO NOT EDIT — re-run `make gen`.
36
3
 
37
- import { APIClient } from "./client";
38
- import {
39
- StorageAdapter,
40
- LocalStorageAdapter,
41
- CookieStorageAdapter,
42
- MemoryStorageAdapter
43
- } from "./storage";
44
- import type { RetryConfig } from "./retry";
45
- import type { LoggerConfig } from "./logger";
46
- import { APILogger } from "./logger";
47
- import { CentrifugoAuth } from "./centrifugo__centrifugo_auth/client";
48
- export * as CentrifugoAuthTypes from "./centrifugo__centrifugo_auth/models";
49
- // Note: Direct exports (export * from) are removed to avoid duplicate type conflicts
50
- // Use namespace exports like CfgAccountsTypes.User or import from specific modules
51
-
52
- // Re-export Zod schemas for runtime validation
53
- export * as Schemas from "./_utils/schemas";
54
- // Also export all schemas directly for convenience
55
- export * from "./_utils/schemas";
4
+ // Wrapper class + per-group SDK re-exports
5
+ export { API, type APIOptions, Cfg, Centrifugo, CentrifugoAuth } from './api';
56
6
 
57
- // Re-export Zod validation events for browser integration
58
- export type { ValidationErrorDetail, ValidationErrorEvent } from "./validation-events";
59
- export { dispatchValidationError, onValidationError, formatZodError } from "./validation-events";
60
-
61
- // Re-export typed fetchers for universal usage
62
- export * as Fetchers from "./_utils/fetchers";
63
- export * from "./_utils/fetchers";
64
-
65
- // Re-export API instance configuration functions
7
+ // Shared utilities (storage / errors / logger / validation events)
66
8
  export {
67
- configureAPI,
68
- getAPIInstance,
69
- reconfigureAPI,
70
- clearAPITokens,
71
- resetAPI,
72
- isAPIConfigured
73
- } from "./api-instance";
74
- // NOTE: SWR hooks are generated in ./_utils/hooks/ but NOT exported here to keep
75
- // the main bundle server-safe. Import hooks directly from the hooks directory:
76
- // import { useUsers } from './_utils/hooks';
77
- // Or use a separate entry point like '@djangocfg/api/hooks' for client components.
78
-
79
- // Re-export core client
80
- export { APIClient };
81
-
82
- // Re-export storage adapters for convenience
83
- export type { StorageAdapter };
84
- export { LocalStorageAdapter, CookieStorageAdapter, MemoryStorageAdapter };
85
-
86
- // Re-export error classes for convenience
87
- export { APIError, NetworkError } from "./errors";
88
-
89
- // Re-export HTTP adapters for custom implementations
90
- export type { HttpClientAdapter, HttpRequest, HttpResponse } from "./http";
91
- export { FetchAdapter, KeepAliveFetchAdapter } from "./http";
92
-
93
- // Re-export logger types and classes
94
- export type { LoggerConfig, RequestLog, ResponseLog, ErrorLog } from "./logger";
95
- export { APILogger } from "./logger";
96
-
97
- // Re-export retry configuration and utilities
98
- export type { RetryConfig, FailedAttemptInfo } from "./retry";
99
- export { withRetry, shouldRetry, DEFAULT_RETRY_CONFIG } from "./retry";
100
-
101
- export const TOKEN_KEY = "auth_token";
102
- export const REFRESH_TOKEN_KEY = "refresh_token";
103
-
104
- /** Auto-detect locale from cookie NEXT_LOCALE or navigator.language */
105
- function detectLocale(): string | null {
106
- try {
107
- if (typeof document !== 'undefined') {
108
- const match = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
109
- if (match) return match[1];
110
- }
111
- if (typeof navigator !== 'undefined' && navigator.language) {
112
- return navigator.language;
113
- }
114
- } catch {}
115
- return null;
116
- }
117
-
118
- export interface APIOptions {
119
- /** Custom storage adapter (defaults to LocalStorageAdapter) */
120
- storage?: StorageAdapter;
121
- /** Custom HTTP client adapter (defaults to FetchAdapter) */
122
- httpClient?: HttpClientAdapter;
123
- /** Retry configuration for failed requests */
124
- retryConfig?: RetryConfig;
125
- /** Logger configuration */
126
- loggerConfig?: Partial<LoggerConfig>;
127
- /** Locale for Accept-Language header (e.g. 'en', 'ko', 'ru') */
128
- locale?: string;
129
- }
130
-
131
- export class API {
132
- private baseUrl: string;
133
- private _client: APIClient;
134
- private _token: string | null = null;
135
- private _refreshToken: string | null = null;
136
- private _locale: string | null = null;
137
- private storage: StorageAdapter;
138
- private options?: APIOptions;
139
-
140
- // Sub-clients
141
- public centrifugo_auth!: CentrifugoAuth;
142
-
143
- constructor(baseUrl: string, options?: APIOptions) {
144
- this.baseUrl = baseUrl;
145
- this.options = options;
146
-
147
- // Create logger if config provided
148
- const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : undefined;
149
-
150
- // Initialize storage with logger
151
- this.storage = options?.storage || new LocalStorageAdapter(logger);
152
-
153
- this._locale = options?.locale || null;
154
-
155
- this._loadTokensFromStorage();
156
-
157
- // Initialize APIClient with token getter for URL authentication
158
- this._client = new APIClient(this.baseUrl, {
159
- httpClient: this.options?.httpClient,
160
- retryConfig: this.options?.retryConfig,
161
- loggerConfig: this.options?.loggerConfig,
162
- tokenGetter: () => this.getToken(),
163
- });
164
-
165
- // Always inject auth header wrapper (reads token dynamically from storage)
166
- this._injectAuthHeader();
167
-
168
- // Initialize sub-clients from APIClient
169
- this.centrifugo_auth = this._client.centrifugo_auth;
170
- }
171
-
172
- private _loadTokensFromStorage(): void {
173
- this._token = this.storage.getItem(TOKEN_KEY);
174
- this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
175
- }
176
-
177
- private _reinitClients(): void {
178
- this._client = new APIClient(this.baseUrl, {
179
- httpClient: this.options?.httpClient,
180
- retryConfig: this.options?.retryConfig,
181
- loggerConfig: this.options?.loggerConfig,
182
- tokenGetter: () => this.getToken(),
183
- });
184
-
185
- // Always inject auth header wrapper (reads token dynamically from storage)
186
- this._injectAuthHeader();
187
-
188
- // Reinitialize sub-clients
189
- this.centrifugo_auth = this._client.centrifugo_auth;
190
- }
191
-
192
- private _injectAuthHeader(): void {
193
- // Override request method to inject auth header
194
- const originalRequest = this._client.request.bind(this._client);
195
- this._client.request = async <T>(
196
- method: string,
197
- path: string,
198
- options?: { params?: Record<string, any>; body?: any; formData?: FormData; headers?: Record<string, string> }
199
- ): Promise<T> => {
200
- // Read token from storage dynamically (supports JWT injection after instantiation)
201
- const token = this.getToken();
202
- const locale = this._locale || detectLocale();
203
- const mergedOptions = {
204
- ...options,
205
- headers: {
206
- ...(options?.headers || {}),
207
- ...(token ? { 'Authorization': `Bearer ${token}` } : {}),
208
- ...(locale ? { 'Accept-Language': locale } : {}),
209
- },
210
- };
211
-
212
- return originalRequest(method, path, mergedOptions);
213
- };
214
- }
215
-
216
- /**
217
- * Get current JWT token
218
- */
219
- getToken(): string | null {
220
- return this.storage.getItem(TOKEN_KEY);
221
- }
222
-
223
- /**
224
- * Get current refresh token
225
- */
226
- getRefreshToken(): string | null {
227
- return this.storage.getItem(REFRESH_TOKEN_KEY);
228
- }
229
-
230
- /**
231
- * Set JWT token and refresh token
232
- * @param token - JWT access token
233
- * @param refreshToken - JWT refresh token (optional)
234
- */
235
- setToken(token: string, refreshToken?: string): void {
236
- this._token = token;
237
- this.storage.setItem(TOKEN_KEY, token);
238
-
239
- if (refreshToken) {
240
- this._refreshToken = refreshToken;
241
- this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
242
- }
243
-
244
- // Reinitialize clients with new token
245
- this._reinitClients();
246
- }
247
-
248
- /**
249
- * Clear all tokens
250
- */
251
- clearTokens(): void {
252
- this._token = null;
253
- this._refreshToken = null;
254
- this.storage.removeItem(TOKEN_KEY);
255
- this.storage.removeItem(REFRESH_TOKEN_KEY);
256
-
257
- // Reinitialize clients without token
258
- this._reinitClients();
259
- }
260
-
261
- /**
262
- * Check if user is authenticated
263
- */
264
- isAuthenticated(): boolean {
265
- return !!this.getToken();
266
- }
267
-
268
- /**
269
- * Update base URL and reinitialize clients
270
- * @param url - New base URL
271
- */
272
- setBaseUrl(url: string): void {
273
- this.baseUrl = url;
274
- this._reinitClients();
275
- }
276
-
277
- /**
278
- * Get current base URL
279
- */
280
- getBaseUrl(): string {
281
- return this.baseUrl;
282
- }
283
-
284
- /**
285
- * Set locale for Accept-Language header
286
- * @param locale - Locale string (e.g. 'en', 'ko', 'ru') or null to clear
287
- */
288
- setLocale(locale: string | null): void {
289
- this._locale = locale;
290
- }
291
-
292
- /**
293
- * Get current locale
294
- */
295
- getLocale(): string | null {
296
- return this._locale;
297
- }
298
-
299
- /**
300
- * Get OpenAPI schema path
301
- * @returns Path to the OpenAPI schema JSON file
302
- *
303
- * Note: The OpenAPI schema is available in the schema.json file.
304
- * You can load it dynamically using:
305
- * ```typescript
306
- * const schema = await fetch('./schema.json').then(r => r.json());
307
- * // or using fs in Node.js:
308
- * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
309
- * ```
310
- */
311
- getSchemaPath(): string {
312
- return './schema.json';
313
- }
314
- }
315
-
316
- export default API;
9
+ type StorageAdapter,
10
+ LocalStorageAdapter,
11
+ MemoryStorageAdapter,
12
+ CookieStorageAdapter,
13
+ APIError,
14
+ NetworkError,
15
+ APILogger,
16
+ defaultLogger,
17
+ type LoggerConfig,
18
+ type RequestLog,
19
+ type ResponseLog,
20
+ type ErrorLog,
21
+ dispatchValidationError,
22
+ onValidationError,
23
+ formatZodError,
24
+ type ValidationErrorDetail,
25
+ type ValidationErrorEvent,
26
+ } from '../_shared';
27
+
28
+ // Generated artifacts (Hey API)
29
+ export type * from './types.gen';
@@ -0,0 +1,14 @@
1
+ // AUTO-GENERATED by django-cfg / django_generator.ts_extras
2
+ // Source: OpenAPI 3.1 components.schemas
3
+ // DO NOT EDIT — re-run `make gen`.
4
+
5
+ import { z } from "zod";
6
+
7
+ export const ConnectionTokenResponseSchema = z.object({
8
+ token: z.string(),
9
+ centrifugo_url: z.string(),
10
+ expires_at: z.string(),
11
+ channels: z.array(z.string()),
12
+ });
13
+
14
+ export type ConnectionTokenResponse = z.infer<typeof ConnectionTokenResponseSchema>;
@@ -0,0 +1,4 @@
1
+ // AUTO-GENERATED — barrel for zod schemas.
2
+ // DO NOT EDIT.
3
+
4
+ export * from "./ConnectionTokenResponse";
@@ -0,0 +1,64 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { Client, Options as Options2, TDataShape } from './client';
4
+ import { client } from './client.gen';
5
+ import type { CfgCentrifugoAuthTokenRetrieveData, CfgCentrifugoAuthTokenRetrieveErrors, CfgCentrifugoAuthTokenRetrieveResponses } from './types.gen';
6
+
7
+ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options2<TData, ThrowOnError, TResponse> & {
8
+ /**
9
+ * You can provide a client instance returned by `createClient()` instead of
10
+ * individual options. This might be also useful if you want to implement a
11
+ * custom client.
12
+ */
13
+ client?: Client;
14
+ /**
15
+ * You can pass arbitrary values through the `meta` object. This can be
16
+ * used to access values that aren't defined as part of the SDK function.
17
+ */
18
+ meta?: Record<string, unknown>;
19
+ };
20
+
21
+ export class Cfg {
22
+ /**
23
+ * Get Centrifugo connection token
24
+ *
25
+ * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
26
+ */
27
+ public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
28
+ return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
29
+ security: [{ scheme: 'bearer', type: 'http' }],
30
+ url: '/cfg/centrifugo/auth/token/',
31
+ ...options
32
+ });
33
+ }
34
+ }
35
+
36
+ export class Centrifugo {
37
+ /**
38
+ * Get Centrifugo connection token
39
+ *
40
+ * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
41
+ */
42
+ public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
43
+ return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
44
+ security: [{ scheme: 'bearer', type: 'http' }],
45
+ url: '/cfg/centrifugo/auth/token/',
46
+ ...options
47
+ });
48
+ }
49
+ }
50
+
51
+ export class CentrifugoAuth {
52
+ /**
53
+ * Get Centrifugo connection token
54
+ *
55
+ * Generate JWT token for WebSocket connection to Centrifugo. Token includes user's allowed channels based on their permissions. Requires authentication.
56
+ */
57
+ public static cfgCentrifugoAuthTokenRetrieve<ThrowOnError extends boolean = false>(options?: Options<CfgCentrifugoAuthTokenRetrieveData, ThrowOnError>) {
58
+ return (options?.client ?? client).get<CfgCentrifugoAuthTokenRetrieveResponses, CfgCentrifugoAuthTokenRetrieveErrors, ThrowOnError>({
59
+ security: [{ scheme: 'bearer', type: 'http' }],
60
+ url: '/cfg/centrifugo/auth/token/',
61
+ ...options
62
+ });
63
+ }
64
+ }
@@ -0,0 +1,61 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type ClientOptions = {
4
+ baseUrl: 'http://localhost:8000' | (string & {});
5
+ };
6
+
7
+ /**
8
+ * ConnectionTokenResponse
9
+ *
10
+ * Response model for Centrifugo connection token.
11
+ */
12
+ export type ConnectionTokenResponse = {
13
+ /**
14
+ * Token
15
+ *
16
+ * JWT token for Centrifugo connection
17
+ */
18
+ token: string;
19
+ /**
20
+ * Centrifugo Url
21
+ *
22
+ * Centrifugo WebSocket URL
23
+ */
24
+ centrifugo_url: string;
25
+ /**
26
+ * Expires At
27
+ *
28
+ * Token expiration time (ISO 8601)
29
+ */
30
+ expires_at: string;
31
+ /**
32
+ * Channels
33
+ *
34
+ * List of allowed channels
35
+ */
36
+ channels: Array<string>;
37
+ };
38
+
39
+ export type CfgCentrifugoAuthTokenRetrieveData = {
40
+ body?: never;
41
+ path?: never;
42
+ query?: never;
43
+ url: '/cfg/centrifugo/auth/token/';
44
+ };
45
+
46
+ export type CfgCentrifugoAuthTokenRetrieveErrors = {
47
+ /**
48
+ * Unauthorized - authentication required
49
+ */
50
+ 401: unknown;
51
+ /**
52
+ * Server error
53
+ */
54
+ 500: unknown;
55
+ };
56
+
57
+ export type CfgCentrifugoAuthTokenRetrieveResponses = {
58
+ 200: ConnectionTokenResponse;
59
+ };
60
+
61
+ export type CfgCentrifugoAuthTokenRetrieveResponse = CfgCentrifugoAuthTokenRetrieveResponses[keyof CfgCentrifugoAuthTokenRetrieveResponses];
@@ -0,0 +1,181 @@
1
+ // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
+ // Self-contained API wrapper for this group. DO NOT EDIT — re-run `make gen`.
3
+
4
+ import { client } from './client.gen';
5
+ import type { StorageAdapter } from '../_shared/storage';
6
+ import { LocalStorageAdapter } from '../_shared/storage';
7
+ import { APILogger, type LoggerConfig } from '../_shared/logger';
8
+
9
+ import { Cfg } from './sdk.gen';
10
+ import { Totp } from './sdk.gen';
11
+ import { BackupCodes } from './sdk.gen';
12
+ import { TotpManagement } from './sdk.gen';
13
+ import { TotpSetup } from './sdk.gen';
14
+ import { TotpVerification } from './sdk.gen';
15
+ import type { ZodTypeAny } from 'zod';
16
+ import {
17
+ BackupCodesRegenerateResponseSchema,
18
+ BackupCodesStatusSchema,
19
+ ConfirmSetupResponseSchema,
20
+ DeviceListResponseSchema,
21
+ SetupResponseSchema,
22
+ VerifyResponseSchema,
23
+ } from './schemas';
24
+ import { dispatchValidationError } from '../_shared/validation-events';
25
+
26
+ const ACCESS_KEY = 'cfg.access_token';
27
+ const REFRESH_KEY = 'cfg.refresh_token';
28
+
29
+ interface ValidationRoute {
30
+ method: string;
31
+ re: RegExp;
32
+ schema: ZodTypeAny;
33
+ path: string;
34
+ }
35
+ const VALIDATION_ROUTES: ReadonlyArray<ValidationRoute> = [
36
+ { method: 'GET', re: new RegExp('^/cfg/totp/backup\\-codes/?$'), schema: BackupCodesStatusSchema, path: '/cfg/totp/backup-codes/' },
37
+ { method: 'POST', re: new RegExp('^/cfg/totp/backup\\-codes/regenerate/?$'), schema: BackupCodesRegenerateResponseSchema, path: '/cfg/totp/backup-codes/regenerate/' },
38
+ { method: 'GET', re: new RegExp('^/cfg/totp/devices/?$'), schema: DeviceListResponseSchema, path: '/cfg/totp/devices/' },
39
+ { method: 'POST', re: new RegExp('^/cfg/totp/setup/?$'), schema: SetupResponseSchema, path: '/cfg/totp/setup/' },
40
+ { method: 'POST', re: new RegExp('^/cfg/totp/setup/confirm/?$'), schema: ConfirmSetupResponseSchema, path: '/cfg/totp/setup/confirm/' },
41
+ { method: 'POST', re: new RegExp('^/cfg/totp/verify/?$'), schema: VerifyResponseSchema, path: '/cfg/totp/verify/' },
42
+ { method: 'POST', re: new RegExp('^/cfg/totp/verify/backup/?$'), schema: VerifyResponseSchema, path: '/cfg/totp/verify/backup/' }
43
+ ];
44
+
45
+ /** Auto-detect locale from cookie NEXT_LOCALE or navigator.language. */
46
+ function detectLocale(): string | null {
47
+ try {
48
+ if (typeof document !== 'undefined') {
49
+ const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
50
+ if (m) return decodeURIComponent(m[1]);
51
+ }
52
+ if (typeof navigator !== 'undefined' && navigator.language) {
53
+ return navigator.language;
54
+ }
55
+ } catch {}
56
+ return null;
57
+ }
58
+
59
+ export interface APIOptions {
60
+ /** Override storage backend (LocalStorage by default; Memory for SSR/tests). */
61
+ storage?: StorageAdapter;
62
+ /** Logger config (defaults to dev-only). */
63
+ logger?: Partial<LoggerConfig>;
64
+ /** Locale for `Accept-Language`. If omitted, auto-detected from cookie/navigator. */
65
+ locale?: string;
66
+ /** API key sent as `X-API-Key`. Falls back to NEXT_PUBLIC_API_KEY. */
67
+ apiKey?: string;
68
+ /** Send Django session/CSRF cookies cross-origin. Defaults to true. */
69
+ withCredentials?: boolean;
70
+ }
71
+
72
+ /**
73
+ * Self-contained API wrapper for this group.
74
+ *
75
+ * Each group has its own client + interceptor + token store. The interceptor
76
+ * automatically attaches:
77
+ * - `Authorization: Bearer <jwt>` from storage
78
+ * - `Accept-Language` from `opts.locale` or `NEXT_LOCALE` cookie
79
+ * - `X-API-Key` from `opts.apiKey` or `NEXT_PUBLIC_API_KEY`
80
+ * - `credentials: 'include'` for Django session/CSRF cookies (toggle via opts)
81
+ */
82
+ export class API {
83
+ private baseUrl: string;
84
+ private storage: StorageAdapter;
85
+ private locale: string | null;
86
+ private apiKey: string | null;
87
+ readonly logger: APILogger;
88
+
89
+ readonly cfg = Cfg;
90
+ readonly totp = Totp;
91
+ readonly backupCodes = BackupCodes;
92
+ readonly totpManagement = TotpManagement;
93
+ readonly totpSetup = TotpSetup;
94
+ readonly totpVerification = TotpVerification;
95
+
96
+ constructor(baseUrl: string, opts: APIOptions = {}) {
97
+ this.baseUrl = baseUrl.replace(/\/$/, '');
98
+ this.storage = opts.storage ?? new LocalStorageAdapter();
99
+ this.logger = new APILogger(opts.logger);
100
+ this.locale = opts.locale ?? null;
101
+ this.apiKey = opts.apiKey ?? (typeof process !== 'undefined' ? (process.env?.NEXT_PUBLIC_API_KEY ?? null) : null);
102
+
103
+ const credentials: RequestCredentials = (opts.withCredentials ?? true) ? 'include' : 'same-origin';
104
+ client.setConfig({ baseUrl: this.baseUrl, credentials });
105
+
106
+ client.interceptors.request.use((request) => {
107
+ const access = this.getToken();
108
+ if (access) request.headers.set('Authorization', `Bearer ${access}`);
109
+
110
+ const locale = this.locale ?? detectLocale();
111
+ if (locale) request.headers.set('Accept-Language', locale);
112
+
113
+ if (this.apiKey) request.headers.set('X-API-Key', this.apiKey);
114
+
115
+ return request;
116
+ });
117
+
118
+ client.interceptors.response.use(async (response, request) => {
119
+ if (!response.ok) return response;
120
+ const ct = response.headers.get('content-type') || '';
121
+ if (!ct.includes('application/json')) return response;
122
+ const url = new URL(request.url);
123
+ const method = request.method.toUpperCase();
124
+ const route = VALIDATION_ROUTES.find(
125
+ (r) => r.method === method && r.re.test(url.pathname),
126
+ );
127
+ if (!route) return response;
128
+ let payload: unknown;
129
+ try {
130
+ payload = await response.clone().json();
131
+ } catch {
132
+ return response;
133
+ }
134
+ const result = route.schema.safeParse(payload);
135
+ if (!result.success) {
136
+ dispatchValidationError({
137
+ operation: `${method} ${route.path}`,
138
+ path: route.path,
139
+ method,
140
+ error: result.error,
141
+ response: payload,
142
+ timestamp: new Date(),
143
+ });
144
+ }
145
+ return response;
146
+ });
147
+ }
148
+
149
+ // ── Base URL ────────────────────────────────────────────────────────────
150
+ getBaseUrl(): string { return this.baseUrl; }
151
+ setBaseUrl(url: string): void {
152
+ this.baseUrl = url.replace(/\/$/, '');
153
+ client.setConfig({ baseUrl: this.baseUrl });
154
+ }
155
+
156
+ // ── Tokens ──────────────────────────────────────────────────────────────
157
+ getToken(): string | null { return this.storage.getItem(ACCESS_KEY); }
158
+ setToken(token: string | null): void {
159
+ if (token) this.storage.setItem(ACCESS_KEY, token);
160
+ else this.storage.removeItem(ACCESS_KEY);
161
+ }
162
+ getRefreshToken(): string | null { return this.storage.getItem(REFRESH_KEY); }
163
+ setRefreshToken(token: string | null): void {
164
+ if (token) this.storage.setItem(REFRESH_KEY, token);
165
+ else this.storage.removeItem(REFRESH_KEY);
166
+ }
167
+ clearToken(): void {
168
+ this.storage.removeItem(ACCESS_KEY);
169
+ this.storage.removeItem(REFRESH_KEY);
170
+ }
171
+ isAuthenticated(): boolean { return this.getToken() !== null; }
172
+
173
+ // ── Locale / API key ────────────────────────────────────────────────────
174
+ getLocale(): string | null { return this.locale ?? detectLocale(); }
175
+ setLocale(locale: string | null): void { this.locale = locale; }
176
+ getApiKey(): string | null { return this.apiKey; }
177
+ setApiKey(key: string | null): void { this.apiKey = key; }
178
+ }
179
+
180
+ export { Cfg, Totp, BackupCodes, TotpManagement, TotpSetup, TotpVerification };
181
+ export { client };