@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
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { getAuthToken } from '../core/auth.gen';
|
|
4
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
+
import { jsonBodySerializer } from '../core/bodySerializer.gen';
|
|
6
|
+
import {
|
|
7
|
+
serializeArrayParam,
|
|
8
|
+
serializeObjectParam,
|
|
9
|
+
serializePrimitiveParam,
|
|
10
|
+
} from '../core/pathSerializer.gen';
|
|
11
|
+
import { getUrl } from '../core/utils.gen';
|
|
12
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
13
|
+
|
|
14
|
+
export const createQuerySerializer = <T = unknown>({
|
|
15
|
+
parameters = {},
|
|
16
|
+
...args
|
|
17
|
+
}: QuerySerializerOptions = {}) => {
|
|
18
|
+
const querySerializer = (queryParams: T) => {
|
|
19
|
+
const search: string[] = [];
|
|
20
|
+
if (queryParams && typeof queryParams === 'object') {
|
|
21
|
+
for (const name in queryParams) {
|
|
22
|
+
const value = queryParams[name];
|
|
23
|
+
|
|
24
|
+
if (value === undefined || value === null) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const options = parameters[name] || args;
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
const serializedArray = serializeArrayParam({
|
|
32
|
+
allowReserved: options.allowReserved,
|
|
33
|
+
explode: true,
|
|
34
|
+
name,
|
|
35
|
+
style: 'form',
|
|
36
|
+
value,
|
|
37
|
+
...options.array,
|
|
38
|
+
});
|
|
39
|
+
if (serializedArray) search.push(serializedArray);
|
|
40
|
+
} else if (typeof value === 'object') {
|
|
41
|
+
const serializedObject = serializeObjectParam({
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
43
|
+
explode: true,
|
|
44
|
+
name,
|
|
45
|
+
style: 'deepObject',
|
|
46
|
+
value: value as Record<string, unknown>,
|
|
47
|
+
...options.object,
|
|
48
|
+
});
|
|
49
|
+
if (serializedObject) search.push(serializedObject);
|
|
50
|
+
} else {
|
|
51
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
52
|
+
allowReserved: options.allowReserved,
|
|
53
|
+
name,
|
|
54
|
+
value: value as string,
|
|
55
|
+
});
|
|
56
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return search.join('&');
|
|
61
|
+
};
|
|
62
|
+
return querySerializer;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Infers parseAs value from provided Content-Type header.
|
|
67
|
+
*/
|
|
68
|
+
export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
|
|
69
|
+
if (!contentType) {
|
|
70
|
+
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
71
|
+
// which is effectively the same as the 'stream' option.
|
|
72
|
+
return 'stream';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const cleanContent = contentType.split(';')[0]?.trim();
|
|
76
|
+
|
|
77
|
+
if (!cleanContent) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
82
|
+
return 'json';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (cleanContent === 'multipart/form-data') {
|
|
86
|
+
return 'formData';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
|
91
|
+
) {
|
|
92
|
+
return 'blob';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (cleanContent.startsWith('text/')) {
|
|
96
|
+
return 'text';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const checkForExistence = (
|
|
103
|
+
options: Pick<RequestOptions, 'auth' | 'query'> & {
|
|
104
|
+
headers: Headers;
|
|
105
|
+
},
|
|
106
|
+
name?: string,
|
|
107
|
+
): boolean => {
|
|
108
|
+
if (!name) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
options.headers.has(name) ||
|
|
113
|
+
options.query?.[name] ||
|
|
114
|
+
options.headers.get('Cookie')?.includes(`${name}=`)
|
|
115
|
+
) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const setAuthParams = async ({
|
|
122
|
+
security,
|
|
123
|
+
...options
|
|
124
|
+
}: Pick<Required<RequestOptions>, 'security'> &
|
|
125
|
+
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
126
|
+
headers: Headers;
|
|
127
|
+
}) => {
|
|
128
|
+
for (const auth of security) {
|
|
129
|
+
if (checkForExistence(options, auth.name)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const token = await getAuthToken(auth, options.auth);
|
|
134
|
+
|
|
135
|
+
if (!token) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const name = auth.name ?? 'Authorization';
|
|
140
|
+
|
|
141
|
+
switch (auth.in) {
|
|
142
|
+
case 'query':
|
|
143
|
+
if (!options.query) {
|
|
144
|
+
options.query = {};
|
|
145
|
+
}
|
|
146
|
+
options.query[name] = token;
|
|
147
|
+
break;
|
|
148
|
+
case 'cookie':
|
|
149
|
+
options.headers.append('Cookie', `${name}=${token}`);
|
|
150
|
+
break;
|
|
151
|
+
case 'header':
|
|
152
|
+
default:
|
|
153
|
+
options.headers.set(name, token);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
160
|
+
getUrl({
|
|
161
|
+
baseUrl: options.baseUrl as string,
|
|
162
|
+
path: options.path,
|
|
163
|
+
query: options.query,
|
|
164
|
+
querySerializer:
|
|
165
|
+
typeof options.querySerializer === 'function'
|
|
166
|
+
? options.querySerializer
|
|
167
|
+
: createQuerySerializer(options.querySerializer),
|
|
168
|
+
url: options.url,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
172
|
+
const config = { ...a, ...b };
|
|
173
|
+
if (config.baseUrl?.endsWith('/')) {
|
|
174
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
175
|
+
}
|
|
176
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
177
|
+
return config;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const headersEntries = (headers: Headers): Array<[string, string]> => {
|
|
181
|
+
const entries: Array<[string, string]> = [];
|
|
182
|
+
headers.forEach((value, key) => {
|
|
183
|
+
entries.push([key, value]);
|
|
184
|
+
});
|
|
185
|
+
return entries;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export const mergeHeaders = (
|
|
189
|
+
...headers: Array<Required<Config>['headers'] | undefined>
|
|
190
|
+
): Headers => {
|
|
191
|
+
const mergedHeaders = new Headers();
|
|
192
|
+
for (const header of headers) {
|
|
193
|
+
if (!header) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
198
|
+
|
|
199
|
+
for (const [key, value] of iterator) {
|
|
200
|
+
if (value === null) {
|
|
201
|
+
mergedHeaders.delete(key);
|
|
202
|
+
} else if (Array.isArray(value)) {
|
|
203
|
+
for (const v of value) {
|
|
204
|
+
mergedHeaders.append(key, v as string);
|
|
205
|
+
}
|
|
206
|
+
} else if (value !== undefined) {
|
|
207
|
+
// assume object headers are meant to be JSON stringified, i.e., their
|
|
208
|
+
// content value in OpenAPI specification is 'application/json'
|
|
209
|
+
mergedHeaders.set(
|
|
210
|
+
key,
|
|
211
|
+
typeof value === 'object' ? JSON.stringify(value) : (value as string),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return mergedHeaders;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
type ErrInterceptor<Err, Res, Req, Options> = (
|
|
220
|
+
error: Err,
|
|
221
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
222
|
+
response: Res | undefined,
|
|
223
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
224
|
+
request: Req | undefined,
|
|
225
|
+
options: Options,
|
|
226
|
+
) => Err | Promise<Err>;
|
|
227
|
+
|
|
228
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
229
|
+
|
|
230
|
+
type ResInterceptor<Res, Req, Options> = (
|
|
231
|
+
response: Res,
|
|
232
|
+
request: Req,
|
|
233
|
+
options: Options,
|
|
234
|
+
) => Res | Promise<Res>;
|
|
235
|
+
|
|
236
|
+
class Interceptors<Interceptor> {
|
|
237
|
+
fns: Array<Interceptor | null> = [];
|
|
238
|
+
|
|
239
|
+
clear(): void {
|
|
240
|
+
this.fns = [];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
eject(id: number | Interceptor): void {
|
|
244
|
+
const index = this.getInterceptorIndex(id);
|
|
245
|
+
if (this.fns[index]) {
|
|
246
|
+
this.fns[index] = null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
exists(id: number | Interceptor): boolean {
|
|
251
|
+
const index = this.getInterceptorIndex(id);
|
|
252
|
+
return Boolean(this.fns[index]);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
256
|
+
if (typeof id === 'number') {
|
|
257
|
+
return this.fns[id] ? id : -1;
|
|
258
|
+
}
|
|
259
|
+
return this.fns.indexOf(id);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
|
|
263
|
+
const index = this.getInterceptorIndex(id);
|
|
264
|
+
if (this.fns[index]) {
|
|
265
|
+
this.fns[index] = fn;
|
|
266
|
+
return id;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
use(fn: Interceptor): number {
|
|
272
|
+
this.fns.push(fn);
|
|
273
|
+
return this.fns.length - 1;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
278
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
279
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
280
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
284
|
+
Req,
|
|
285
|
+
Res,
|
|
286
|
+
Err,
|
|
287
|
+
Options
|
|
288
|
+
> => ({
|
|
289
|
+
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
290
|
+
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
291
|
+
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
295
|
+
allowReserved: false,
|
|
296
|
+
array: {
|
|
297
|
+
explode: true,
|
|
298
|
+
style: 'form',
|
|
299
|
+
},
|
|
300
|
+
object: {
|
|
301
|
+
explode: true,
|
|
302
|
+
style: 'deepObject',
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const defaultHeaders = {
|
|
307
|
+
'Content-Type': 'application/json',
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const createConfig = <T extends ClientOptions = ClientOptions>(
|
|
311
|
+
override: Config<Omit<ClientOptions, keyof T> & T> = {},
|
|
312
|
+
): Config<Omit<ClientOptions, keyof T> & T> => ({
|
|
313
|
+
...jsonBodySerializer,
|
|
314
|
+
headers: defaultHeaders,
|
|
315
|
+
parseAs: 'auto',
|
|
316
|
+
querySerializer: defaultQuerySerializer,
|
|
317
|
+
...override,
|
|
318
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { type ClientOptions, type Config, createClient, createConfig } from './client';
|
|
4
|
+
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
8
|
+
* and the returned object will become the client's initial configuration.
|
|
9
|
+
*
|
|
10
|
+
* You may want to initialize your client this way instead of calling
|
|
11
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
12
|
+
* to ensure your client always has the correct values.
|
|
13
|
+
*/
|
|
14
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
15
|
+
|
|
16
|
+
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://localhost:8000' }));
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type AuthToken = string | undefined;
|
|
4
|
+
|
|
5
|
+
export interface Auth {
|
|
6
|
+
/**
|
|
7
|
+
* Which part of the request do we use to send the auth?
|
|
8
|
+
*
|
|
9
|
+
* @default 'header'
|
|
10
|
+
*/
|
|
11
|
+
in?: 'header' | 'query' | 'cookie';
|
|
12
|
+
/**
|
|
13
|
+
* Header or query parameter name.
|
|
14
|
+
*
|
|
15
|
+
* @default 'Authorization'
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
scheme?: 'basic' | 'bearer';
|
|
19
|
+
type: 'apiKey' | 'http';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const getAuthToken = async (
|
|
23
|
+
auth: Auth,
|
|
24
|
+
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
|
25
|
+
): Promise<string | undefined> => {
|
|
26
|
+
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
27
|
+
|
|
28
|
+
if (!token) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (auth.scheme === 'bearer') {
|
|
33
|
+
return `Bearer ${token}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (auth.scheme === 'basic') {
|
|
37
|
+
return `Basic ${btoa(token)}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return token;
|
|
41
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
|
|
4
|
+
|
|
5
|
+
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
6
|
+
|
|
7
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
8
|
+
|
|
9
|
+
type QuerySerializerOptionsObject = {
|
|
10
|
+
allowReserved?: boolean;
|
|
11
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
12
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
16
|
+
/**
|
|
17
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
18
|
+
* override the global array/object settings for specific parameter names.
|
|
19
|
+
*/
|
|
20
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
|
|
24
|
+
if (typeof value === 'string' || value instanceof Blob) {
|
|
25
|
+
data.append(key, value);
|
|
26
|
+
} else if (value instanceof Date) {
|
|
27
|
+
data.append(key, value.toISOString());
|
|
28
|
+
} else {
|
|
29
|
+
data.append(key, JSON.stringify(value));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
data.append(key, value);
|
|
36
|
+
} else {
|
|
37
|
+
data.append(key, JSON.stringify(value));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const formDataBodySerializer = {
|
|
42
|
+
bodySerializer: (body: unknown): FormData => {
|
|
43
|
+
const data = new FormData();
|
|
44
|
+
|
|
45
|
+
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
|
46
|
+
if (value === undefined || value === null) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
value.forEach((v) => serializeFormDataPair(data, key, v));
|
|
51
|
+
} else {
|
|
52
|
+
serializeFormDataPair(data, key, value);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return data;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const jsonBodySerializer = {
|
|
61
|
+
bodySerializer: (body: unknown): string =>
|
|
62
|
+
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const urlSearchParamsBodySerializer = {
|
|
66
|
+
bodySerializer: (body: unknown): string => {
|
|
67
|
+
const data = new URLSearchParams();
|
|
68
|
+
|
|
69
|
+
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
|
|
75
|
+
} else {
|
|
76
|
+
serializeUrlSearchParamsPair(data, key, value);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return data.toString();
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
type Slot = 'body' | 'headers' | 'path' | 'query';
|
|
4
|
+
|
|
5
|
+
export type Field =
|
|
6
|
+
| {
|
|
7
|
+
in: Exclude<Slot, 'body'>;
|
|
8
|
+
/**
|
|
9
|
+
* Field name. This is the name we want the user to see and use.
|
|
10
|
+
*/
|
|
11
|
+
key: string;
|
|
12
|
+
/**
|
|
13
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
14
|
+
* If omitted, we use the same value as `key`.
|
|
15
|
+
*/
|
|
16
|
+
map?: string;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
in: Extract<Slot, 'body'>;
|
|
20
|
+
/**
|
|
21
|
+
* Key isn't required for bodies.
|
|
22
|
+
*/
|
|
23
|
+
key?: string;
|
|
24
|
+
map?: string;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
/**
|
|
28
|
+
* Field name. This is the name we want the user to see and use.
|
|
29
|
+
*/
|
|
30
|
+
key: string;
|
|
31
|
+
/**
|
|
32
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
33
|
+
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
34
|
+
*/
|
|
35
|
+
map: Slot;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface Fields {
|
|
39
|
+
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
40
|
+
args?: ReadonlyArray<Field>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
|
44
|
+
|
|
45
|
+
const extraPrefixesMap: Record<string, Slot> = {
|
|
46
|
+
$body_: 'body',
|
|
47
|
+
$headers_: 'headers',
|
|
48
|
+
$path_: 'path',
|
|
49
|
+
$query_: 'query',
|
|
50
|
+
};
|
|
51
|
+
const extraPrefixes = Object.entries(extraPrefixesMap);
|
|
52
|
+
|
|
53
|
+
type KeyMap = Map<
|
|
54
|
+
string,
|
|
55
|
+
| {
|
|
56
|
+
in: Slot;
|
|
57
|
+
map?: string;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
in?: never;
|
|
61
|
+
map: Slot;
|
|
62
|
+
}
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
|
|
66
|
+
if (!map) {
|
|
67
|
+
map = new Map();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const config of fields) {
|
|
71
|
+
if ('in' in config) {
|
|
72
|
+
if (config.key) {
|
|
73
|
+
map.set(config.key, {
|
|
74
|
+
in: config.in,
|
|
75
|
+
map: config.map,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} else if ('key' in config) {
|
|
79
|
+
map.set(config.key, {
|
|
80
|
+
map: config.map,
|
|
81
|
+
});
|
|
82
|
+
} else if (config.args) {
|
|
83
|
+
buildKeyMap(config.args, map);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return map;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
interface Params {
|
|
91
|
+
body: unknown;
|
|
92
|
+
headers: Record<string, unknown>;
|
|
93
|
+
path: Record<string, unknown>;
|
|
94
|
+
query: Record<string, unknown>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const stripEmptySlots = (params: Params) => {
|
|
98
|
+
for (const [slot, value] of Object.entries(params)) {
|
|
99
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
|
|
100
|
+
delete params[slot as Slot];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
|
|
106
|
+
const params: Params = {
|
|
107
|
+
body: {},
|
|
108
|
+
headers: {},
|
|
109
|
+
path: {},
|
|
110
|
+
query: {},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const map = buildKeyMap(fields);
|
|
114
|
+
|
|
115
|
+
let config: FieldsConfig[number] | undefined;
|
|
116
|
+
|
|
117
|
+
for (const [index, arg] of args.entries()) {
|
|
118
|
+
if (fields[index]) {
|
|
119
|
+
config = fields[index];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!config) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if ('in' in config) {
|
|
127
|
+
if (config.key) {
|
|
128
|
+
const field = map.get(config.key)!;
|
|
129
|
+
const name = field.map || config.key;
|
|
130
|
+
if (field.in) {
|
|
131
|
+
(params[field.in] as Record<string, unknown>)[name] = arg;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
params.body = arg;
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
138
|
+
const field = map.get(key);
|
|
139
|
+
|
|
140
|
+
if (field) {
|
|
141
|
+
if (field.in) {
|
|
142
|
+
const name = field.map || key;
|
|
143
|
+
(params[field.in] as Record<string, unknown>)[name] = value;
|
|
144
|
+
} else {
|
|
145
|
+
params[field.map] = value;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
149
|
+
|
|
150
|
+
if (extra) {
|
|
151
|
+
const [prefix, slot] = extra;
|
|
152
|
+
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
|
|
153
|
+
} else if ('allowExtra' in config && config.allowExtra) {
|
|
154
|
+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
155
|
+
if (allowed) {
|
|
156
|
+
(params[slot as Slot] as Record<string, unknown>)[key] = value;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
stripEmptySlots(params);
|
|
167
|
+
|
|
168
|
+
return params;
|
|
169
|
+
};
|