-
Notifications
You must be signed in to change notification settings - Fork 81
Feature/lit 3580 refactor js sdk change all enums to constants #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/lit 3580 refactor js sdk change all enums to constants #579
Conversation
…s-sdk-change-all-enums-to-constants-v7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! - Just one tiny suggested change on the comment.
EDITED:
- Awaiting migration guide for these changes, re-review required.
StytchWhatsAppFactorOtp: 12, | ||
StytchTotpFactorOtp: 13, | ||
} as const; | ||
export type AuthMethodType_TYPE = keyof typeof AuthMethodType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because we want to maintain the original name in camel case AuthMethodType
and adding our new naming convention _TYPE
and _VALUES
like LIT_NETWORK_TYPES
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use this chance to unify all constants naming conventions and expose the previous names as deprecated values so we end up with proper names but breaking as little as possible
…e-all-enums-to-constants-v7 # Conflicts: # packages/auth-helpers/src/lib/recap/utils.ts # packages/auth-helpers/src/lib/resources.ts # packages/constants/src/lib/errors.ts # packages/constants/src/lib/interfaces/i-errors.ts # packages/constants/src/lib/utils/utils.ts # packages/core/src/lib/lit-core.ts # packages/crypto/src/lib/crypto.ts # packages/lit-auth-client/src/lib/providers/AppleProvider.ts # packages/lit-auth-client/src/lib/providers/BaseProvider.ts # packages/lit-auth-client/src/lib/providers/DiscordProvider.ts # packages/lit-auth-client/src/lib/providers/EthWalletProvider.ts # packages/lit-auth-client/src/lib/providers/GoogleProvider.ts # packages/lit-auth-client/src/lib/providers/StytchAuthFactorOtp.ts # packages/lit-auth-client/src/lib/providers/StytchOtpProvider.ts # packages/lit-auth-client/src/lib/providers/WebAuthnProvider.ts # packages/lit-auth-client/src/lib/utils.ts # packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts # packages/misc/src/lib/misc.ts
Description
This PR changes all the enums used around the SDK to literal types and their derived types in order to improve type and values definitions and their imports on other packages
Migration guide
Several enums have been moved or replaced by others in
@lit-protocol/constants
as constant values that behave similarly to enums.They also export types representing their keys and values, with suffixes
_TYPE
and_VALUE
respectively in order to be able to use them in type-safe manner.For example, the
LitNetwork
enum has been replaced byLIT_NETWORK
constant, with the correspondingLIT_NETWORK_TYPES
andLIT_NETWORK_VALUES
types.The following table gives a detail of all the constants changed or removed.
@lit-protocol/auth-browser
WALLET_ERROR
@lit-protocol/auth-helpers
LitAbility
LIT_ABILITY
in constants package.@lit-protocol/auth-helpers
LitNamespace
LIT_NAMESPACE
in constants package.@lit-protocol/auth-helpers
LitRecapAbility
LIT_RECAP_ABILITY
in constants package.@lit-protocol/auth-helpers
LitResourcePrefix
LIT_RESOURCE_PREFIX
in constants package.@lit-protocol/constants
AuthMethodScope
AUTH_METHOD_SCOPE
in constants package.@lit-protocol/constants
AuthMethodType
AUTH_METHOD_TYPE
in constants package.@lit-protocol/constants
CENTRALISATION_BY_NETWORK
localhost
anymore. UseCENTRALISATION_BY_NETWORK.Custom
instead.@lit-protocol/constants
EITHER_TYPE
EITHER_TYPE
in constants package.@lit-protocol/constants
GENERAL_WORKER_URL_BY_NETWORK
localhost
anymore. UseLIT_NETWORKS.Custom
instead.@lit-protocol/constants
HTTP_BY_NETWORK
localhost
norinternalDev
anymore. UseHTTP_BY_NETWORK.Custom
instead.@lit-protocol/constants
LIT_CURVE
LIT_CURVE
in constants package.@lit-protocol/constants
LIT_ENDPOINT_VERSION
@lit-protocol/constants
LIT_NETWORKS
localhost
norinternalDev
anymore. UseLIT_NETWORKS.Custom
instead.@lit-protocol/constants
LitErrorKind
LIT_ERROR_KIND
in constants package.@lit-protocol/constants
LitNetwork
LIT_NETWORK
in constants package@lit-protocol/constants
METAMASK_CHAIN_INFO_BY_NETWORK
localhost
anymore. UseMETAMASK_CHAIN_INFO_BY_NETWORK.Custom
instead.@lit-protocol/constants
ProviderType
PROVIDER_TYPE
in constants package.@lit-protocol/constants
RELAYER_URL_BY_NETWORK
localhost
anymore. UseRELAYER_URL_BY_NETWORK.Custom
instead.@lit-protocol/constants
RPC_URL_BY_NETWORK
localhost
anymore. UseRPC_URL_BY_NETWORK.Custom
instead.@lit-protocol/constants
StakingStates
STAKING_STATES
in constants package.@lit-protocol/constants
VMTYPE
VMTYPE
in constants package.@lit-protocol/constants
metamaskChainInfo
METAMASK_CHAIN_INFO
in constants package.@lit-protocol/logger
LogLevel
LOG_LEVEL
in constants package.@lit-protocol/types
AuthMethodType
AUTH_METHOD_TYPE
in constants package.@lit-protocol/types
IRelayAuthStatus
RELAY_AUTH_STATUS
in constants package.@lit-protocol/types
LitAbility
LIT_ABILITY
in constants package.@lit-protocol/types
LitResourcePrefix
LIT_RESOURCE_PREFIX
in constants package.AuthMethodType
AUTH_METHOD_TYPE
in constants package.LIT_RPC
RPC_URL_BY_NETWORK
in constants package.LIT_TESTNET
LIT_NETWORK
in constants package.LIT_TESTNET.LOCALCHAIN
should be replaced withLIT_NETWORK.Custom
RPC_MAP
RPC_URL_BY_NETWORK
in constants package.Backwards compatibility
The
@lit-protocol/constants
package does however, also export the new constants under the old names for backwards compatibility and to ease migration.However, it is recommended to use the new constants instead as this will be removed in the future.
Following the example, you can also import the
LitNetwork
constant, which is an alias forLIT_NETWORK
.Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: