@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.
- package/dist/auth-server.cjs +4265 -1169
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +4265 -1159
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +4150 -3053
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +158 -209
- package/dist/auth.d.ts +158 -209
- package/dist/auth.mjs +4139 -3042
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +3932 -4031
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +2408 -2671
- package/dist/clients.d.ts +2408 -2671
- package/dist/clients.mjs +3945 -4038
- package/dist/clients.mjs.map +1 -1
- package/dist/index.cjs +4214 -2713
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2758 -1828
- package/dist/index.d.ts +2758 -1828
- package/dist/index.mjs +4183 -2676
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
- package/src/_api/generated/_shared/errors.ts +70 -0
- package/src/_api/generated/_shared/index.ts +25 -0
- package/src/_api/generated/_shared/logger.ts +123 -0
- package/src/_api/generated/_shared/storage.ts +83 -0
- package/src/_api/generated/_shared/validation-events.ts +52 -0
- package/src/_api/generated/cfg_accounts/api.ts +187 -0
- package/src/_api/generated/cfg_accounts/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_accounts/client/index.ts +25 -0
- package/src/_api/generated/cfg_accounts/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_accounts/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_accounts/client.gen.ts +16 -0
- package/src/_api/generated/cfg_accounts/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_accounts/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_accounts/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_accounts/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_accounts/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_accounts/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_accounts/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_accounts/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_accounts/events.ts +198 -0
- package/src/_api/generated/cfg_accounts/hooks/index.ts +18 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthDisconnectCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubAuthorizeCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthGithubCallbackCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpRequestCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsOtpVerifyCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileAvatarCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileDeleteCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialPartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfilePartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +26 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdatePartialUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsProfileUpdateUpdate.ts +24 -0
- package/src/_api/generated/cfg_accounts/hooks/useCfgAccountsTokenRefreshCreate.ts +24 -0
- package/src/_api/generated/cfg_accounts/index.ts +26 -335
- package/src/_api/generated/cfg_accounts/schemas/AccountDeleteResponse.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/CentrifugoToken.ts +14 -0
- package/src/_api/generated/cfg_accounts/schemas/CfgUserUpdateRequest.ts +16 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthAuthorizeResponse.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthConnection.ts +19 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthDisconnectRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthError.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthProvidersResponse.ts +11 -0
- package/src/_api/generated/cfg_accounts/schemas/OAuthTokenResponse.ts +18 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPErrorResponse.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPRequestRequest.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPRequestResponse.ts +11 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPVerifyRequest.ts +13 -0
- package/src/_api/generated/cfg_accounts/schemas/OTPVerifyResponse.ts +17 -0
- package/src/_api/generated/cfg_accounts/schemas/PatchedCfgUserUpdateRequest.ts +16 -0
- package/src/_api/generated/cfg_accounts/schemas/ProviderEnum.ts +9 -0
- package/src/_api/generated/cfg_accounts/schemas/TokenRefresh.ts +12 -0
- package/src/_api/generated/cfg_accounts/schemas/TokenRefreshRequest.ts +11 -0
- package/src/_api/generated/cfg_accounts/{_utils/schemas/User.schema.ts → schemas/User.ts} +8 -16
- package/src/_api/generated/cfg_accounts/schemas/index.ts +24 -0
- package/src/_api/generated/cfg_accounts/sdk.gen.ts +796 -0
- package/src/_api/generated/cfg_accounts/types.gen.ts +764 -0
- package/src/_api/generated/cfg_centrifugo/api.ts +164 -0
- package/src/_api/generated/cfg_centrifugo/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_centrifugo/client/index.ts +25 -0
- package/src/_api/generated/cfg_centrifugo/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_centrifugo/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_centrifugo/client.gen.ts +16 -0
- package/src/_api/generated/cfg_centrifugo/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_centrifugo/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_centrifugo/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_centrifugo/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_centrifugo/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_centrifugo/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_centrifugo/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_centrifugo/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_centrifugo/events.ts +198 -0
- package/src/_api/generated/cfg_centrifugo/hooks/index.ts +4 -0
- package/src/_api/generated/cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +26 -0
- package/src/_api/generated/cfg_centrifugo/index.ts +26 -313
- package/src/_api/generated/cfg_centrifugo/schemas/ConnectionTokenResponse.ts +14 -0
- package/src/_api/generated/cfg_centrifugo/schemas/index.ts +4 -0
- package/src/_api/generated/cfg_centrifugo/sdk.gen.ts +64 -0
- package/src/_api/generated/cfg_centrifugo/types.gen.ts +61 -0
- package/src/_api/generated/cfg_totp/api.ts +181 -0
- package/src/_api/generated/cfg_totp/client/client.gen.ts +280 -0
- package/src/_api/generated/cfg_totp/client/index.ts +25 -0
- package/src/_api/generated/cfg_totp/client/types.gen.ts +217 -0
- package/src/_api/generated/cfg_totp/client/utils.gen.ts +318 -0
- package/src/_api/generated/cfg_totp/client.gen.ts +16 -0
- package/src/_api/generated/cfg_totp/core/auth.gen.ts +41 -0
- package/src/_api/generated/cfg_totp/core/bodySerializer.gen.ts +82 -0
- package/src/_api/generated/cfg_totp/core/params.gen.ts +169 -0
- package/src/_api/generated/cfg_totp/core/pathSerializer.gen.ts +171 -0
- package/src/_api/generated/cfg_totp/core/queryKeySerializer.gen.ts +117 -0
- package/src/_api/generated/cfg_totp/core/serverSentEvents.gen.ts +242 -0
- package/src/_api/generated/cfg_totp/core/types.gen.ts +104 -0
- package/src/_api/generated/cfg_totp/core/utils.gen.ts +140 -0
- package/src/_api/generated/cfg_totp/events.ts +198 -0
- package/src/_api/generated/cfg_totp/hooks/index.ts +12 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRegenerateCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +26 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesDestroy.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +26 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpDisableCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupConfirmCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpSetupCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyBackupCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/hooks/useCfgTotpVerifyCreate.ts +24 -0
- package/src/_api/generated/cfg_totp/index.ts +26 -342
- package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/BackupCodesRegenerateResponse.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/BackupCodesStatus.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/ConfirmSetupRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/ConfirmSetupResponse.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceList.ts +18 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceListResponse.ts +13 -0
- package/src/_api/generated/cfg_totp/schemas/DeviceListStatusEnum.ts +9 -0
- package/src/_api/generated/cfg_totp/schemas/DisableRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/SetupRequest.ts +11 -0
- package/src/_api/generated/cfg_totp/schemas/SetupResponse.ts +15 -0
- package/src/_api/generated/cfg_totp/{_utils/schemas/TotpVerifyUser.schema.ts → schemas/TotpVerifyUser.ts} +7 -15
- package/src/_api/generated/cfg_totp/schemas/VerifyBackupRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/VerifyRequest.ts +12 -0
- package/src/_api/generated/cfg_totp/schemas/VerifyResponse.ts +17 -0
- package/src/_api/generated/cfg_totp/schemas/index.ts +18 -0
- package/src/_api/generated/cfg_totp/sdk.gen.ts +432 -0
- package/src/_api/generated/cfg_totp/types.gen.ts +479 -0
- package/src/_api/generated/index.ts +30 -0
- package/src/_api/index.ts +5 -23
- package/src/auth/context/AccountsContext.tsx +58 -89
- package/src/auth/context/AuthContext.tsx +3 -3
- package/src/auth/context/index.ts +2 -2
- package/src/auth/hooks/useDeleteAccount.ts +2 -1
- package/src/auth/hooks/useGithubAuth.ts +12 -11
- package/src/auth/hooks/useTokenRefresh.ts +6 -4
- package/src/auth/hooks/useTwoFactor.ts +14 -8
- package/src/auth/hooks/useTwoFactorSetup.ts +8 -5
- package/src/auth/hooks/useTwoFactorStatus.ts +3 -2
- package/src/auth/middlewares/tokenRefresh.ts +6 -4
- package/src/clients.ts +14 -51
- package/src/index.ts +15 -57
- package/src/server.ts +25 -23
- package/src/_api/BaseClient.ts +0 -22
- package/src/_api/generated/cfg_accounts/CLAUDE.md +0 -86
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts.ts +0 -154
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__auth.ts +0 -95
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__oauth.ts +0 -285
- package/src/_api/generated/cfg_accounts/_utils/fetchers/accounts__user_profile.ts +0 -440
- package/src/_api/generated/cfg_accounts/_utils/fetchers/index.ts +0 -33
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts.ts +0 -64
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__auth.ts +0 -44
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__oauth.ts +0 -114
- package/src/_api/generated/cfg_accounts/_utils/hooks/accounts__user_profile.ts +0 -152
- package/src/_api/generated/cfg_accounts/_utils/hooks/index.ts +0 -33
- package/src/_api/generated/cfg_accounts/_utils/schemas/AccountDeleteResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/CentrifugoToken.schema.ts +0 -22
- package/src/_api/generated/cfg_accounts/_utils/schemas/CfgAccountsProfileAvatarCreateRequest.schema.ts +0 -15
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthAuthorizeResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthCallbackRequestRequest.schema.ts +0 -21
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthConnection.schema.ts +0 -27
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthDisconnectRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthError.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthProvidersResponse.schema.ts +0 -19
- package/src/_api/generated/cfg_accounts/_utils/schemas/OAuthTokenResponse.schema.ts +0 -46
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPErrorResponse.schema.ts +0 -41
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPRequestResponse.schema.ts +0 -19
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyRequest.schema.ts +0 -21
- package/src/_api/generated/cfg_accounts/_utils/schemas/OTPVerifyResponse.schema.ts +0 -45
- package/src/_api/generated/cfg_accounts/_utils/schemas/PatchedUserProfileUpdateRequest.schema.ts +0 -24
- package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefresh.schema.ts +0 -16
- package/src/_api/generated/cfg_accounts/_utils/schemas/TokenRefreshRequest.schema.ts +0 -15
- package/src/_api/generated/cfg_accounts/_utils/schemas/UserProfileUpdateRequest.schema.ts +0 -24
- package/src/_api/generated/cfg_accounts/_utils/schemas/index.ts +0 -41
- package/src/_api/generated/cfg_accounts/accounts/client.ts +0 -34
- package/src/_api/generated/cfg_accounts/accounts/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts/models.ts +0 -127
- package/src/_api/generated/cfg_accounts/accounts__auth/client.ts +0 -23
- package/src/_api/generated/cfg_accounts/accounts__auth/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__auth/models.ts +0 -19
- package/src/_api/generated/cfg_accounts/accounts__oauth/client.ts +0 -67
- package/src/_api/generated/cfg_accounts/accounts__oauth/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__oauth/models.ts +0 -127
- package/src/_api/generated/cfg_accounts/accounts__user_profile/client.ts +0 -94
- package/src/_api/generated/cfg_accounts/accounts__user_profile/index.ts +0 -4
- package/src/_api/generated/cfg_accounts/accounts__user_profile/models.ts +0 -98
- package/src/_api/generated/cfg_accounts/api-instance.ts +0 -181
- package/src/_api/generated/cfg_accounts/client.ts +0 -339
- package/src/_api/generated/cfg_accounts/enums.ts +0 -10
- package/src/_api/generated/cfg_accounts/errors.ts +0 -123
- package/src/_api/generated/cfg_accounts/http.ts +0 -160
- package/src/_api/generated/cfg_accounts/logger.ts +0 -261
- package/src/_api/generated/cfg_accounts/retry.ts +0 -177
- package/src/_api/generated/cfg_accounts/schema.json +0 -1576
- package/src/_api/generated/cfg_accounts/storage.ts +0 -163
- package/src/_api/generated/cfg_accounts/validation-events.ts +0 -135
- package/src/_api/generated/cfg_centrifugo/CLAUDE.md +0 -60
- package/src/_api/generated/cfg_centrifugo/_utils/fetchers/centrifugo__centrifugo_auth.ts +0 -94
- package/src/_api/generated/cfg_centrifugo/_utils/fetchers/index.ts +0 -30
- package/src/_api/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_auth.ts +0 -39
- package/src/_api/generated/cfg_centrifugo/_utils/hooks/index.ts +0 -30
- package/src/_api/generated/cfg_centrifugo/_utils/schemas/ConnectionTokenResponse.schema.ts +0 -22
- package/src/_api/generated/cfg_centrifugo/_utils/schemas/index.ts +0 -21
- package/src/_api/generated/cfg_centrifugo/api-instance.ts +0 -181
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/client.ts +0 -27
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/index.ts +0 -4
- package/src/_api/generated/cfg_centrifugo/centrifugo__centrifugo_auth/models.ts +0 -18
- package/src/_api/generated/cfg_centrifugo/client.ts +0 -330
- package/src/_api/generated/cfg_centrifugo/errors.ts +0 -123
- package/src/_api/generated/cfg_centrifugo/http.ts +0 -160
- package/src/_api/generated/cfg_centrifugo/logger.ts +0 -261
- package/src/_api/generated/cfg_centrifugo/retry.ts +0 -177
- package/src/_api/generated/cfg_centrifugo/schema.json +0 -118
- package/src/_api/generated/cfg_centrifugo/storage.ts +0 -163
- package/src/_api/generated/cfg_centrifugo/validation-events.ts +0 -135
- package/src/_api/generated/cfg_totp/CLAUDE.md +0 -83
- package/src/_api/generated/cfg_totp/_utils/fetchers/index.ts +0 -34
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp.ts +0 -50
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__backup_codes.ts +0 -153
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_management.ts +0 -109
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_setup.ts +0 -154
- package/src/_api/generated/cfg_totp/_utils/fetchers/totp__totp_verification.ts +0 -153
- package/src/_api/generated/cfg_totp/_utils/hooks/index.ts +0 -34
- package/src/_api/generated/cfg_totp/_utils/hooks/totp.ts +0 -43
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts +0 -60
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_management.ts +0 -59
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_setup.ts +0 -64
- package/src/_api/generated/cfg_totp/_utils/hooks/totp__totp_verification.ts +0 -63
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesRegenerateResponse.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/BackupCodesStatus.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/ConfirmSetupResponse.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/DeviceList.schema.ts +0 -26
- package/src/_api/generated/cfg_totp/_utils/schemas/DeviceListResponse.schema.ts +0 -21
- package/src/_api/generated/cfg_totp/_utils/schemas/DisableRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/SetupRequest.schema.ts +0 -19
- package/src/_api/generated/cfg_totp/_utils/schemas/SetupResponse.schema.ts +0 -23
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyBackupRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyRequest.schema.ts +0 -20
- package/src/_api/generated/cfg_totp/_utils/schemas/VerifyResponse.schema.ts +0 -25
- package/src/_api/generated/cfg_totp/_utils/schemas/index.ts +0 -34
- package/src/_api/generated/cfg_totp/api-instance.ts +0 -181
- package/src/_api/generated/cfg_totp/client.ts +0 -342
- package/src/_api/generated/cfg_totp/enums.ts +0 -13
- package/src/_api/generated/cfg_totp/errors.ts +0 -123
- package/src/_api/generated/cfg_totp/http.ts +0 -160
- package/src/_api/generated/cfg_totp/logger.ts +0 -261
- package/src/_api/generated/cfg_totp/retry.ts +0 -177
- package/src/_api/generated/cfg_totp/schema.json +0 -910
- package/src/_api/generated/cfg_totp/storage.ts +0 -163
- package/src/_api/generated/cfg_totp/totp/client.ts +0 -24
- package/src/_api/generated/cfg_totp/totp/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp/models.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__backup_codes/client.ts +0 -32
- package/src/_api/generated/cfg_totp/totp__backup_codes/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__backup_codes/models.ts +0 -38
- package/src/_api/generated/cfg_totp/totp__totp_management/client.ts +0 -31
- package/src/_api/generated/cfg_totp/totp__totp_management/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_management/models.ts +0 -46
- package/src/_api/generated/cfg_totp/totp__totp_setup/client.ts +0 -33
- package/src/_api/generated/cfg_totp/totp__totp_setup/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_setup/models.ts +0 -55
- package/src/_api/generated/cfg_totp/totp__totp_verification/client.ts +0 -33
- package/src/_api/generated/cfg_totp/totp__totp_verification/index.ts +0 -4
- package/src/_api/generated/cfg_totp/totp__totp_verification/models.ts +0 -74
- package/src/_api/generated/cfg_totp/validation-events.ts +0 -135
- package/src/hooks/accounts.ts +0 -8
- package/src/hooks/index.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.327",
|
|
4
4
|
"description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"django",
|
|
@@ -40,11 +40,6 @@
|
|
|
40
40
|
"import": "./dist/index.mjs",
|
|
41
41
|
"require": "./dist/index.cjs"
|
|
42
42
|
},
|
|
43
|
-
"./hooks": {
|
|
44
|
-
"types": "./dist/hooks.d.ts",
|
|
45
|
-
"import": "./dist/hooks.mjs",
|
|
46
|
-
"require": "./dist/hooks.cjs"
|
|
47
|
-
},
|
|
48
43
|
"./auth": {
|
|
49
44
|
"types": "./dist/auth.d.ts",
|
|
50
45
|
"import": "./dist/auth.mjs",
|
|
@@ -84,7 +79,7 @@
|
|
|
84
79
|
"devDependencies": {
|
|
85
80
|
"@types/node": "^24.7.2",
|
|
86
81
|
"@types/react": "^19.1.0",
|
|
87
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
82
|
+
"@djangocfg/typescript-config": "^2.1.327",
|
|
88
83
|
"next": "^16.2.2",
|
|
89
84
|
"react": "^19.1.0",
|
|
90
85
|
"tsup": "^8.5.0",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Typed error classes with DRF field-error support.
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* HTTP API Error with DRF field-specific validation errors.
|
|
7
|
+
*/
|
|
8
|
+
export class APIError extends Error {
|
|
9
|
+
constructor(
|
|
10
|
+
public statusCode: number,
|
|
11
|
+
public statusText: string,
|
|
12
|
+
public response: any,
|
|
13
|
+
public url: string,
|
|
14
|
+
message?: string,
|
|
15
|
+
) {
|
|
16
|
+
super(message || `HTTP ${statusCode}: ${statusText}`);
|
|
17
|
+
this.name = "APIError";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get details(): Record<string, any> | null {
|
|
21
|
+
if (typeof this.response === "object" && this.response !== null) {
|
|
22
|
+
return this.response;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get fieldErrors(): Record<string, string[]> | null {
|
|
28
|
+
const details = this.details;
|
|
29
|
+
if (!details) return null;
|
|
30
|
+
const fieldErrors: Record<string, string[]> = {};
|
|
31
|
+
for (const [key, value] of Object.entries(details)) {
|
|
32
|
+
if (Array.isArray(value)) fieldErrors[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get errorMessage(): string {
|
|
38
|
+
const details = this.details;
|
|
39
|
+
if (!details) return this.message;
|
|
40
|
+
if (details.detail) {
|
|
41
|
+
return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
|
|
42
|
+
}
|
|
43
|
+
if (details.error) return String(details.error);
|
|
44
|
+
if (details.message) return String(details.message);
|
|
45
|
+
const fieldErrors = this.fieldErrors;
|
|
46
|
+
if (fieldErrors) {
|
|
47
|
+
const firstField = Object.keys(fieldErrors)[0];
|
|
48
|
+
if (firstField) return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
|
|
49
|
+
}
|
|
50
|
+
return this.message;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get isValidationError(): boolean { return this.statusCode === 400; }
|
|
54
|
+
get isAuthError(): boolean { return this.statusCode === 401; }
|
|
55
|
+
get isPermissionError(): boolean { return this.statusCode === 403; }
|
|
56
|
+
get isNotFoundError(): boolean { return this.statusCode === 404; }
|
|
57
|
+
get isServerError(): boolean { return this.statusCode >= 500 && this.statusCode < 600; }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Network Error (connection failed, timeout, etc.) */
|
|
61
|
+
export class NetworkError extends Error {
|
|
62
|
+
constructor(
|
|
63
|
+
message: string,
|
|
64
|
+
public url: string,
|
|
65
|
+
public originalError?: Error,
|
|
66
|
+
) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = "NetworkError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Shared utilities barrel. DO NOT EDIT — re-run `make gen`.
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
type StorageAdapter,
|
|
6
|
+
LocalStorageAdapter,
|
|
7
|
+
MemoryStorageAdapter,
|
|
8
|
+
CookieStorageAdapter,
|
|
9
|
+
} from './storage';
|
|
10
|
+
export { APIError, NetworkError } from './errors';
|
|
11
|
+
export {
|
|
12
|
+
APILogger,
|
|
13
|
+
defaultLogger,
|
|
14
|
+
type LoggerConfig,
|
|
15
|
+
type RequestLog,
|
|
16
|
+
type ResponseLog,
|
|
17
|
+
type ErrorLog,
|
|
18
|
+
} from './logger';
|
|
19
|
+
export {
|
|
20
|
+
dispatchValidationError,
|
|
21
|
+
onValidationError,
|
|
22
|
+
formatZodError,
|
|
23
|
+
type ValidationErrorDetail,
|
|
24
|
+
type ValidationErrorEvent,
|
|
25
|
+
} from './validation-events';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// API logger built on consola. Optional dependency — install if you enable logging:
|
|
3
|
+
// npm install consola
|
|
4
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
5
|
+
|
|
6
|
+
import { type ConsolaInstance, createConsola } from "consola";
|
|
7
|
+
|
|
8
|
+
export interface RequestLog {
|
|
9
|
+
method: string;
|
|
10
|
+
url: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
body?: any;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ResponseLog {
|
|
17
|
+
status: number;
|
|
18
|
+
statusText: string;
|
|
19
|
+
data?: any;
|
|
20
|
+
duration: number;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ErrorLog {
|
|
25
|
+
message: string;
|
|
26
|
+
statusCode?: number;
|
|
27
|
+
fieldErrors?: Record<string, string[]>;
|
|
28
|
+
duration: number;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LoggerConfig {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
logRequests: boolean;
|
|
35
|
+
logResponses: boolean;
|
|
36
|
+
logErrors: boolean;
|
|
37
|
+
logBodies: boolean;
|
|
38
|
+
logHeaders: boolean;
|
|
39
|
+
consola?: ConsolaInstance;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DEFAULT_CONFIG: LoggerConfig = {
|
|
43
|
+
enabled: typeof process !== "undefined" && process.env?.NODE_ENV !== "production",
|
|
44
|
+
logRequests: true,
|
|
45
|
+
logResponses: true,
|
|
46
|
+
logErrors: true,
|
|
47
|
+
logBodies: true,
|
|
48
|
+
logHeaders: false,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const SENSITIVE_HEADERS = [
|
|
52
|
+
"authorization",
|
|
53
|
+
"cookie",
|
|
54
|
+
"set-cookie",
|
|
55
|
+
"x-api-key",
|
|
56
|
+
"x-csrf-token",
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
export class APILogger {
|
|
60
|
+
private config: LoggerConfig;
|
|
61
|
+
private consola: ConsolaInstance;
|
|
62
|
+
|
|
63
|
+
constructor(config: Partial<LoggerConfig> = {}) {
|
|
64
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
65
|
+
this.consola = config.consola || createConsola({
|
|
66
|
+
level: this.config.enabled ? 4 : 0,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
enable(): void { this.config.enabled = true; }
|
|
71
|
+
disable(): void { this.config.enabled = false; }
|
|
72
|
+
setConfig(config: Partial<LoggerConfig>): void {
|
|
73
|
+
this.config = { ...this.config, ...config };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private filterHeaders(headers?: Record<string, string>): Record<string, string> {
|
|
77
|
+
if (!headers) return {};
|
|
78
|
+
const filtered: Record<string, string> = {};
|
|
79
|
+
Object.keys(headers).forEach((key) => {
|
|
80
|
+
filtered[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "***" : (headers[key] || "");
|
|
81
|
+
});
|
|
82
|
+
return filtered;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
logRequest(request: RequestLog): void {
|
|
86
|
+
if (!this.config.enabled || !this.config.logRequests) return;
|
|
87
|
+
const { method, url, headers, body } = request;
|
|
88
|
+
this.consola.start(`${method} ${url}`);
|
|
89
|
+
if (this.config.logHeaders && headers) this.consola.debug("Headers:", this.filterHeaders(headers));
|
|
90
|
+
if (this.config.logBodies && body) this.consola.debug("Body:", body);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
logResponse(request: RequestLog, response: ResponseLog): void {
|
|
94
|
+
if (!this.config.enabled || !this.config.logResponses) return;
|
|
95
|
+
const { method, url } = request;
|
|
96
|
+
const { status, statusText, data, duration } = response;
|
|
97
|
+
this.consola.success(`${method} ${url} ${status} ${statusText} (${duration}ms)`);
|
|
98
|
+
if (this.config.logBodies && data) this.consola.debug("Response:", data);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
logError(request: RequestLog, error: ErrorLog): void {
|
|
102
|
+
if (!this.config.enabled || !this.config.logErrors) return;
|
|
103
|
+
const { method, url } = request;
|
|
104
|
+
const { message, statusCode, fieldErrors, duration } = error;
|
|
105
|
+
this.consola.error(`${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`);
|
|
106
|
+
this.consola.error("Message:", message);
|
|
107
|
+
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
|
|
108
|
+
this.consola.error("Field Errors:");
|
|
109
|
+
Object.entries(fieldErrors).forEach(([field, errors]) => {
|
|
110
|
+
errors.forEach((err) => this.consola.error(` • ${field}: ${err}`));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
info(message: string, ...args: any[]): void { if (this.config.enabled) this.consola.info(message, ...args); }
|
|
116
|
+
warn(message: string, ...args: any[]): void { if (this.config.enabled) this.consola.warn(message, ...args); }
|
|
117
|
+
error(message: string, ...args: any[]): void { if (this.config.enabled) this.consola.error(message, ...args); }
|
|
118
|
+
debug(message: string, ...args: any[]): void { if (this.config.enabled) this.consola.debug(message, ...args); }
|
|
119
|
+
success(message: string, ...args: any[]): void { if (this.config.enabled) this.consola.success(message, ...args); }
|
|
120
|
+
withTag(tag: string): ConsolaInstance { return this.consola.withTag(tag); }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const defaultLogger = new APILogger();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Storage adapters for token persistence.
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
export interface StorageAdapter {
|
|
6
|
+
getItem(key: string): string | null;
|
|
7
|
+
setItem(key: string, value: string): void;
|
|
8
|
+
removeItem(key: string): void;
|
|
9
|
+
clear?(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Browser localStorage. Falls back to no-op on SSR / private mode. */
|
|
13
|
+
export class LocalStorageAdapter implements StorageAdapter {
|
|
14
|
+
getItem(key: string): string | null {
|
|
15
|
+
if (typeof window === "undefined") return null;
|
|
16
|
+
try { return window.localStorage.getItem(key); } catch { return null; }
|
|
17
|
+
}
|
|
18
|
+
setItem(key: string, value: string): void {
|
|
19
|
+
if (typeof window === "undefined") return;
|
|
20
|
+
try { window.localStorage.setItem(key, value); } catch { /* quota / private */ }
|
|
21
|
+
}
|
|
22
|
+
removeItem(key: string): void {
|
|
23
|
+
if (typeof window === "undefined") return;
|
|
24
|
+
try { window.localStorage.removeItem(key); } catch { /* ignore */ }
|
|
25
|
+
}
|
|
26
|
+
clear(): void {
|
|
27
|
+
if (typeof window === "undefined") return;
|
|
28
|
+
try { window.localStorage.clear(); } catch { /* ignore */ }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** In-memory store. Use for SSR, Electron main process, or tests. */
|
|
33
|
+
export class MemoryStorageAdapter implements StorageAdapter {
|
|
34
|
+
private store = new Map<string, string>();
|
|
35
|
+
getItem(key: string): string | null { return this.store.get(key) ?? null; }
|
|
36
|
+
setItem(key: string, value: string): void { this.store.set(key, value); }
|
|
37
|
+
removeItem(key: string): void { this.store.delete(key); }
|
|
38
|
+
clear(): void { this.store.clear(); }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Cookie-backed storage (browser only). */
|
|
42
|
+
export class CookieStorageAdapter implements StorageAdapter {
|
|
43
|
+
constructor(
|
|
44
|
+
private opts: {
|
|
45
|
+
domain?: string;
|
|
46
|
+
path?: string;
|
|
47
|
+
secure?: boolean;
|
|
48
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
49
|
+
maxAgeSeconds?: number;
|
|
50
|
+
} = {},
|
|
51
|
+
) {}
|
|
52
|
+
|
|
53
|
+
getItem(key: string): string | null {
|
|
54
|
+
if (typeof document === "undefined") return null;
|
|
55
|
+
const prefix = `${encodeURIComponent(key)}=`;
|
|
56
|
+
for (const part of document.cookie.split("; ")) {
|
|
57
|
+
if (part.startsWith(prefix)) {
|
|
58
|
+
return decodeURIComponent(part.slice(prefix.length));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setItem(key: string, value: string): void {
|
|
65
|
+
if (typeof document === "undefined") return;
|
|
66
|
+
const parts = [
|
|
67
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
|
|
68
|
+
`Path=${this.opts.path ?? "/"}`,
|
|
69
|
+
];
|
|
70
|
+
if (this.opts.domain) parts.push(`Domain=${this.opts.domain}`);
|
|
71
|
+
if (this.opts.secure) parts.push("Secure");
|
|
72
|
+
if (this.opts.sameSite) parts.push(`SameSite=${this.opts.sameSite}`);
|
|
73
|
+
if (this.opts.maxAgeSeconds != null) {
|
|
74
|
+
parts.push(`Max-Age=${this.opts.maxAgeSeconds}`);
|
|
75
|
+
}
|
|
76
|
+
document.cookie = parts.join("; ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
removeItem(key: string): void {
|
|
80
|
+
if (typeof document === "undefined") return;
|
|
81
|
+
document.cookie = `${encodeURIComponent(key)}=; Max-Age=0; Path=${this.opts.path ?? "/"}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// AUTO-GENERATED by django_generator / ts_extras.wrapper
|
|
2
|
+
// Browser CustomEvent integration for Zod validation errors.
|
|
3
|
+
// DO NOT EDIT — re-run `make gen`.
|
|
4
|
+
|
|
5
|
+
import type { ZodError } from "zod";
|
|
6
|
+
|
|
7
|
+
export interface ValidationErrorDetail {
|
|
8
|
+
operation: string;
|
|
9
|
+
path: string;
|
|
10
|
+
method: string;
|
|
11
|
+
error: ZodError;
|
|
12
|
+
response: any;
|
|
13
|
+
timestamp: Date;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ValidationErrorEvent = CustomEvent<ValidationErrorDetail>;
|
|
17
|
+
|
|
18
|
+
export function dispatchValidationError(detail: ValidationErrorDetail): void {
|
|
19
|
+
if (typeof window === "undefined") return;
|
|
20
|
+
try {
|
|
21
|
+
const event = new CustomEvent<ValidationErrorDetail>("zod-validation-error", {
|
|
22
|
+
detail,
|
|
23
|
+
bubbles: true,
|
|
24
|
+
cancelable: false,
|
|
25
|
+
});
|
|
26
|
+
window.dispatchEvent(event);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn("Failed to dispatch validation error event:", error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function onValidationError(
|
|
33
|
+
callback: (detail: ValidationErrorDetail) => void,
|
|
34
|
+
): () => void {
|
|
35
|
+
if (typeof window === "undefined") return () => {};
|
|
36
|
+
const handler = (event: Event) => {
|
|
37
|
+
if (event instanceof CustomEvent) callback(event.detail);
|
|
38
|
+
};
|
|
39
|
+
window.addEventListener("zod-validation-error", handler);
|
|
40
|
+
return () => window.removeEventListener("zod-validation-error", handler);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatZodError(error: ZodError): string {
|
|
44
|
+
const issues = error.issues.map((issue, index) => {
|
|
45
|
+
const path = issue.path.join(".") || "root";
|
|
46
|
+
const parts = [`${index + 1}. ${path}: ${issue.message}`];
|
|
47
|
+
if ("expected" in issue && issue.expected) parts.push(` Expected: ${issue.expected}`);
|
|
48
|
+
if ("received" in issue && issue.received) parts.push(` Received: ${issue.received}`);
|
|
49
|
+
return parts.join("\n");
|
|
50
|
+
});
|
|
51
|
+
return issues.join("\n");
|
|
52
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
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 { Accounts } from './sdk.gen';
|
|
11
|
+
import { OAuth } from './sdk.gen';
|
|
12
|
+
import { UserProfile } from './sdk.gen';
|
|
13
|
+
import { Auth } from './sdk.gen';
|
|
14
|
+
import type { ZodTypeAny } from 'zod';
|
|
15
|
+
import {
|
|
16
|
+
AccountDeleteResponseSchema,
|
|
17
|
+
OAuthAuthorizeResponseSchema,
|
|
18
|
+
OAuthProvidersResponseSchema,
|
|
19
|
+
OAuthTokenResponseSchema,
|
|
20
|
+
OTPRequestResponseSchema,
|
|
21
|
+
OTPVerifyResponseSchema,
|
|
22
|
+
TokenRefreshSchema,
|
|
23
|
+
UserSchema,
|
|
24
|
+
} from './schemas';
|
|
25
|
+
import { dispatchValidationError } from '../_shared/validation-events';
|
|
26
|
+
|
|
27
|
+
const ACCESS_KEY = 'cfg.access_token';
|
|
28
|
+
const REFRESH_KEY = 'cfg.refresh_token';
|
|
29
|
+
|
|
30
|
+
interface ValidationRoute {
|
|
31
|
+
method: string;
|
|
32
|
+
re: RegExp;
|
|
33
|
+
schema: ZodTypeAny;
|
|
34
|
+
path: string;
|
|
35
|
+
}
|
|
36
|
+
const VALIDATION_ROUTES: ReadonlyArray<ValidationRoute> = [
|
|
37
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/oauth/github/authorize/?$'), schema: OAuthAuthorizeResponseSchema, path: '/cfg/accounts/oauth/github/authorize/' },
|
|
38
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/oauth/github/callback/?$'), schema: OAuthTokenResponseSchema, path: '/cfg/accounts/oauth/github/callback/' },
|
|
39
|
+
{ method: 'GET', re: new RegExp('^/cfg/accounts/oauth/providers/?$'), schema: OAuthProvidersResponseSchema, path: '/cfg/accounts/oauth/providers/' },
|
|
40
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/otp/request/?$'), schema: OTPRequestResponseSchema, path: '/cfg/accounts/otp/request/' },
|
|
41
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/otp/verify/?$'), schema: OTPVerifyResponseSchema, path: '/cfg/accounts/otp/verify/' },
|
|
42
|
+
{ method: 'GET', re: new RegExp('^/cfg/accounts/profile/?$'), schema: UserSchema, path: '/cfg/accounts/profile/' },
|
|
43
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/profile/avatar/?$'), schema: UserSchema, path: '/cfg/accounts/profile/avatar/' },
|
|
44
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/profile/delete/?$'), schema: AccountDeleteResponseSchema, path: '/cfg/accounts/profile/delete/' },
|
|
45
|
+
{ method: 'PUT', re: new RegExp('^/cfg/accounts/profile/partial/?$'), schema: UserSchema, path: '/cfg/accounts/profile/partial/' },
|
|
46
|
+
{ method: 'PATCH', re: new RegExp('^/cfg/accounts/profile/partial/?$'), schema: UserSchema, path: '/cfg/accounts/profile/partial/' },
|
|
47
|
+
{ method: 'PUT', re: new RegExp('^/cfg/accounts/profile/update/?$'), schema: UserSchema, path: '/cfg/accounts/profile/update/' },
|
|
48
|
+
{ method: 'PATCH', re: new RegExp('^/cfg/accounts/profile/update/?$'), schema: UserSchema, path: '/cfg/accounts/profile/update/' },
|
|
49
|
+
{ method: 'POST', re: new RegExp('^/cfg/accounts/token/refresh/?$'), schema: TokenRefreshSchema, path: '/cfg/accounts/token/refresh/' }
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** Auto-detect locale from cookie NEXT_LOCALE or navigator.language. */
|
|
53
|
+
function detectLocale(): string | null {
|
|
54
|
+
try {
|
|
55
|
+
if (typeof document !== 'undefined') {
|
|
56
|
+
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
57
|
+
if (m) return decodeURIComponent(m[1]);
|
|
58
|
+
}
|
|
59
|
+
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
60
|
+
return navigator.language;
|
|
61
|
+
}
|
|
62
|
+
} catch {}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface APIOptions {
|
|
67
|
+
/** Override storage backend (LocalStorage by default; Memory for SSR/tests). */
|
|
68
|
+
storage?: StorageAdapter;
|
|
69
|
+
/** Logger config (defaults to dev-only). */
|
|
70
|
+
logger?: Partial<LoggerConfig>;
|
|
71
|
+
/** Locale for `Accept-Language`. If omitted, auto-detected from cookie/navigator. */
|
|
72
|
+
locale?: string;
|
|
73
|
+
/** API key sent as `X-API-Key`. Falls back to NEXT_PUBLIC_API_KEY. */
|
|
74
|
+
apiKey?: string;
|
|
75
|
+
/** Send Django session/CSRF cookies cross-origin. Defaults to true. */
|
|
76
|
+
withCredentials?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Self-contained API wrapper for this group.
|
|
81
|
+
*
|
|
82
|
+
* Each group has its own client + interceptor + token store. The interceptor
|
|
83
|
+
* automatically attaches:
|
|
84
|
+
* - `Authorization: Bearer <jwt>` from storage
|
|
85
|
+
* - `Accept-Language` from `opts.locale` or `NEXT_LOCALE` cookie
|
|
86
|
+
* - `X-API-Key` from `opts.apiKey` or `NEXT_PUBLIC_API_KEY`
|
|
87
|
+
* - `credentials: 'include'` for Django session/CSRF cookies (toggle via opts)
|
|
88
|
+
*/
|
|
89
|
+
export class API {
|
|
90
|
+
private baseUrl: string;
|
|
91
|
+
private storage: StorageAdapter;
|
|
92
|
+
private locale: string | null;
|
|
93
|
+
private apiKey: string | null;
|
|
94
|
+
readonly logger: APILogger;
|
|
95
|
+
|
|
96
|
+
readonly cfg = Cfg;
|
|
97
|
+
readonly accounts = Accounts;
|
|
98
|
+
readonly oAuth = OAuth;
|
|
99
|
+
readonly userProfile = UserProfile;
|
|
100
|
+
readonly auth = Auth;
|
|
101
|
+
|
|
102
|
+
constructor(baseUrl: string, opts: APIOptions = {}) {
|
|
103
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
104
|
+
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
105
|
+
this.logger = new APILogger(opts.logger);
|
|
106
|
+
this.locale = opts.locale ?? null;
|
|
107
|
+
this.apiKey = opts.apiKey ?? (typeof process !== 'undefined' ? (process.env?.NEXT_PUBLIC_API_KEY ?? null) : null);
|
|
108
|
+
|
|
109
|
+
const credentials: RequestCredentials = (opts.withCredentials ?? true) ? 'include' : 'same-origin';
|
|
110
|
+
client.setConfig({ baseUrl: this.baseUrl, credentials });
|
|
111
|
+
|
|
112
|
+
client.interceptors.request.use((request) => {
|
|
113
|
+
const access = this.getToken();
|
|
114
|
+
if (access) request.headers.set('Authorization', `Bearer ${access}`);
|
|
115
|
+
|
|
116
|
+
const locale = this.locale ?? detectLocale();
|
|
117
|
+
if (locale) request.headers.set('Accept-Language', locale);
|
|
118
|
+
|
|
119
|
+
if (this.apiKey) request.headers.set('X-API-Key', this.apiKey);
|
|
120
|
+
|
|
121
|
+
return request;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
client.interceptors.response.use(async (response, request) => {
|
|
125
|
+
if (!response.ok) return response;
|
|
126
|
+
const ct = response.headers.get('content-type') || '';
|
|
127
|
+
if (!ct.includes('application/json')) return response;
|
|
128
|
+
const url = new URL(request.url);
|
|
129
|
+
const method = request.method.toUpperCase();
|
|
130
|
+
const route = VALIDATION_ROUTES.find(
|
|
131
|
+
(r) => r.method === method && r.re.test(url.pathname),
|
|
132
|
+
);
|
|
133
|
+
if (!route) return response;
|
|
134
|
+
let payload: unknown;
|
|
135
|
+
try {
|
|
136
|
+
payload = await response.clone().json();
|
|
137
|
+
} catch {
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
const result = route.schema.safeParse(payload);
|
|
141
|
+
if (!result.success) {
|
|
142
|
+
dispatchValidationError({
|
|
143
|
+
operation: `${method} ${route.path}`,
|
|
144
|
+
path: route.path,
|
|
145
|
+
method,
|
|
146
|
+
error: result.error,
|
|
147
|
+
response: payload,
|
|
148
|
+
timestamp: new Date(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return response;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── Base URL ────────────────────────────────────────────────────────────
|
|
156
|
+
getBaseUrl(): string { return this.baseUrl; }
|
|
157
|
+
setBaseUrl(url: string): void {
|
|
158
|
+
this.baseUrl = url.replace(/\/$/, '');
|
|
159
|
+
client.setConfig({ baseUrl: this.baseUrl });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
163
|
+
getToken(): string | null { return this.storage.getItem(ACCESS_KEY); }
|
|
164
|
+
setToken(token: string | null): void {
|
|
165
|
+
if (token) this.storage.setItem(ACCESS_KEY, token);
|
|
166
|
+
else this.storage.removeItem(ACCESS_KEY);
|
|
167
|
+
}
|
|
168
|
+
getRefreshToken(): string | null { return this.storage.getItem(REFRESH_KEY); }
|
|
169
|
+
setRefreshToken(token: string | null): void {
|
|
170
|
+
if (token) this.storage.setItem(REFRESH_KEY, token);
|
|
171
|
+
else this.storage.removeItem(REFRESH_KEY);
|
|
172
|
+
}
|
|
173
|
+
clearToken(): void {
|
|
174
|
+
this.storage.removeItem(ACCESS_KEY);
|
|
175
|
+
this.storage.removeItem(REFRESH_KEY);
|
|
176
|
+
}
|
|
177
|
+
isAuthenticated(): boolean { return this.getToken() !== null; }
|
|
178
|
+
|
|
179
|
+
// ── Locale / API key ────────────────────────────────────────────────────
|
|
180
|
+
getLocale(): string | null { return this.locale ?? detectLocale(); }
|
|
181
|
+
setLocale(locale: string | null): void { this.locale = locale; }
|
|
182
|
+
getApiKey(): string | null { return this.apiKey; }
|
|
183
|
+
setApiKey(key: string | null): void { this.apiKey = key; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { Cfg, Accounts, OAuth, UserProfile, Auth };
|
|
187
|
+
export { client };
|