Skip to content

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

Conversation

FedericoAmura
Copy link
Contributor

@FedericoAmura FedericoAmura commented Aug 6, 2024

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 by LIT_NETWORK constant, with the corresponding LIT_NETWORK_TYPES and LIT_NETWORK_VALUES types.

The following table gives a detail of all the constants changed or removed.

Old package Value Update
@lit-protocol/auth-browser WALLET_ERROR Replaced enum by a constant.
@lit-protocol/auth-helpers LitAbility Replaced by constant LIT_ABILITY in constants package.
@lit-protocol/auth-helpers LitNamespace Replaced by constant LIT_NAMESPACE in constants package.
@lit-protocol/auth-helpers LitRecapAbility Replaced by constant LIT_RECAP_ABILITY in constants package.
@lit-protocol/auth-helpers LitResourcePrefix Replaced by constant LIT_RESOURCE_PREFIX in constants package.
@lit-protocol/constants AuthMethodScope Replaced by constant AUTH_METHOD_SCOPE in constants package.
@lit-protocol/constants AuthMethodType Replaced by constant AUTH_METHOD_TYPE in constants package.
@lit-protocol/constants CENTRALISATION_BY_NETWORK Does not include localhost anymore. Use CENTRALISATION_BY_NETWORK.Custom instead.
@lit-protocol/constants EITHER_TYPE Replaced by constant EITHER_TYPE in constants package.
@lit-protocol/constants GENERAL_WORKER_URL_BY_NETWORK Does not include localhost anymore. Use LIT_NETWORKS.Custom instead.
@lit-protocol/constants HTTP_BY_NETWORK Does not include localhost nor internalDev anymore. Use HTTP_BY_NETWORK.Custom instead.
@lit-protocol/constants LIT_CURVE Replaced by constant LIT_CURVE in constants package.
@lit-protocol/constants LIT_ENDPOINT_VERSION Replaced enum by a constant.
@lit-protocol/constants LIT_NETWORKS Does not include localhost nor internalDev anymore. Use LIT_NETWORKS.Custom instead.
@lit-protocol/constants LitErrorKind Renamed to LIT_ERROR_KIND in constants package.
@lit-protocol/constants LitNetwork Replaced by constant LIT_NETWORK in constants package
@lit-protocol/constants METAMASK_CHAIN_INFO_BY_NETWORK Does not include localhost anymore. Use METAMASK_CHAIN_INFO_BY_NETWORK.Custom instead.
@lit-protocol/constants ProviderType Replaced by constant PROVIDER_TYPE in constants package.
@lit-protocol/constants RELAYER_URL_BY_NETWORK Does not include localhost anymore. Use RELAYER_URL_BY_NETWORK.Custom instead.
@lit-protocol/constants RPC_URL_BY_NETWORK Does not include localhost anymore. Use RPC_URL_BY_NETWORK.Custom instead.
@lit-protocol/constants StakingStates Replaced by constant STAKING_STATES in constants package.
@lit-protocol/constants VMTYPE Replaced by constant VMTYPE in constants package.
@lit-protocol/constants metamaskChainInfo Replaced by METAMASK_CHAIN_INFO in constants package.
@lit-protocol/logger LogLevel Replaced by constant LOG_LEVEL in constants package.
@lit-protocol/types AuthMethodType Replaced by constant AUTH_METHOD_TYPE in constants package.
@lit-protocol/types IRelayAuthStatus Replaced by constant RELAY_AUTH_STATUS in constants package.
@lit-protocol/types LitAbility Replaced by constant LIT_ABILITY in constants package.
@lit-protocol/types LitResourcePrefix Replaced by constant LIT_RESOURCE_PREFIX in constants package.
local-tests AuthMethodType Replaced by constant AUTH_METHOD_TYPE in constants package.
local-tests LIT_RPC Replaced by constant RPC_URL_BY_NETWORK in constants package.
local-tests LIT_TESTNET Replaced by constant LIT_NETWORK in constants package. LIT_TESTNET.LOCALCHAIN should be replaced with LIT_NETWORK.Custom
local-tests RPC_MAP Replaced by constant 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 for LIT_NETWORK.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • Test A
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@FedericoAmura FedericoAmura changed the base branch from master to staging/v7 August 7, 2024 13:36
@FedericoAmura FedericoAmura marked this pull request as ready for review August 13, 2024 16:52
Copy link
Collaborator

@Ansonhkg Ansonhkg left a 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;
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@Ansonhkg Ansonhkg self-requested a review August 16, 2024 15:51
@Ansonhkg Ansonhkg requested a review from DashKash54 August 19, 2024 21:11
@joshLong145 joshLong145 self-requested a review August 20, 2024 14:37
…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
@Ansonhkg Ansonhkg merged commit ee8c8c6 into staging/v7 Aug 20, 2024
4 checks passed
@Ansonhkg Ansonhkg deleted the feature/lit-3580-refactor-js-sdk-change-all-enums-to-constants-v7 branch August 20, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants