Skip to content

Commit 0bc3ccc

Browse files
authoredDec 5, 2024··
chore(shared,types): Move constants from types to shared (#4716)
1 parent 2a3462e commit 0bc3ccc

File tree

12 files changed

+259
-34
lines changed

12 files changed

+259
-34
lines changed
 

‎.changeset/curvy-sloths-dress.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/elements': minor
4+
'@clerk/ui': minor
5+
---
6+
7+
Replace usage of `OAUTH_PROVIDERS` and `WEB3_PROVIDERS` from `@clerk/types` to `@clerk/shared`.

‎.changeset/honest-news-peel.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/shared': minor
3+
---
4+
5+
Introduce new submodules:
6+
- Export `OAUTH_PROVIDERS` from `@clerk/shared/oauth`
7+
- Export `WEB3_PROVIDERS` from `@clerk/shared/web3`

‎.changeset/quiet-timers-mate.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/types': minor
3+
---
4+
5+
Deprecate the following constants and functions:
6+
- `OAUTH_PROVIDERS`
7+
- `getOAuthProviderData()`
8+
- `sortedOAuthProviders()`
9+
- `WEB3_PROVIDERS`
10+
- `getWeb3ProviderData()`

‎packages/clerk-js/src/ui/common/constants.ts

+1-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Attribute, Web3Provider } from '@clerk/types';
1+
import type { Attribute } from '@clerk/types';
22

33
import type { LocalizationKey } from '../localization/localizationKeys';
44
import { localizationKeys } from '../localization/localizationKeys';
@@ -77,31 +77,3 @@ export const PREFERRED_SIGN_IN_STRATEGIES = Object.freeze({
7777
Password: 'password',
7878
OTP: 'otp',
7979
});
80-
81-
interface Web3ProviderData {
82-
id: string;
83-
name: string;
84-
}
85-
86-
type Web3Providers = {
87-
[key in Web3Provider]: Web3ProviderData;
88-
};
89-
90-
export const WEB3_PROVIDERS: Web3Providers = Object.freeze({
91-
metamask: {
92-
id: 'metamask',
93-
name: 'MetaMask',
94-
},
95-
coinbase_wallet: {
96-
id: 'coinbase_wallet',
97-
name: 'Coinbase Wallet',
98-
},
99-
okx_wallet: {
100-
id: 'okx_wallet',
101-
name: 'OKX Wallet',
102-
},
103-
});
104-
105-
export function getWeb3ProviderData(name: Web3Provider): Web3ProviderData | undefined | null {
106-
return WEB3_PROVIDERS[name];
107-
}

‎packages/clerk-js/src/ui/hooks/useEnabledThirdPartyProviders.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { iconImageUrl } from '@clerk/shared/constants';
2+
import { OAUTH_PROVIDERS } from '@clerk/shared/oauth';
3+
import { WEB3_PROVIDERS } from '@clerk/shared/web3';
24
import type { OAuthProvider, OAuthStrategy, Web3Provider, Web3Strategy } from '@clerk/types';
3-
// TODO: This import shouldn't be part of @clerk/types
4-
import { OAUTH_PROVIDERS, WEB3_PROVIDERS } from '@clerk/types';
55

66
import { useEnvironment } from '../contexts/EnvironmentContext';
77
import { fromEntries } from '../utils';

‎packages/elements/src/utils/third-party-strategies.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// c.f. vendor/clerk-js/src/ui/hooks/useEnabledThirdPartyProviders.tsx [Modified]
22

33
import { iconImageUrl } from '@clerk/shared/constants';
4+
import { OAUTH_PROVIDERS } from '@clerk/shared/oauth';
5+
import { WEB3_PROVIDERS } from '@clerk/shared/web3';
46
import type {
57
EnvironmentResource,
68
OAuthProvider,
@@ -9,7 +11,6 @@ import type {
911
Web3Provider,
1012
Web3Strategy,
1113
} from '@clerk/types';
12-
import { OAUTH_PROVIDERS, WEB3_PROVIDERS } from '@clerk/types'; // TODO: This import shouldn't be part of @clerk/types
1314

1415
import { fromEntries } from './clerk-js';
1516

‎packages/shared/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@
112112
"utils",
113113
"workerTimers",
114114
"devBrowser",
115-
"object"
115+
"object",
116+
"oauth",
117+
"web3"
116118
],
117119
"scripts": {
118120
"build": "tsup",

‎packages/shared/src/oauth.ts

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import type { OAuthProvider, OAuthProviderData, OAuthStrategy } from '@clerk/types';
2+
3+
export const OAUTH_PROVIDERS: OAuthProviderData[] = [
4+
{
5+
provider: 'google',
6+
strategy: 'oauth_google',
7+
name: 'Google',
8+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/google',
9+
},
10+
{
11+
provider: 'discord',
12+
strategy: 'oauth_discord',
13+
name: 'Discord',
14+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/discord',
15+
},
16+
{
17+
provider: 'facebook',
18+
strategy: 'oauth_facebook',
19+
name: 'Facebook',
20+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/facebook',
21+
},
22+
{
23+
provider: 'twitch',
24+
strategy: 'oauth_twitch',
25+
name: 'Twitch',
26+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/twitch',
27+
},
28+
{
29+
provider: 'twitter',
30+
strategy: 'oauth_twitter',
31+
name: 'Twitter',
32+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/twitter',
33+
},
34+
{
35+
provider: 'microsoft',
36+
strategy: 'oauth_microsoft',
37+
name: 'Microsoft',
38+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/microsoft',
39+
},
40+
{
41+
provider: 'tiktok',
42+
strategy: 'oauth_tiktok',
43+
name: 'TikTok',
44+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/tiktok',
45+
},
46+
{
47+
provider: 'linkedin',
48+
strategy: 'oauth_linkedin',
49+
name: 'LinkedIn',
50+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/linkedin',
51+
},
52+
{
53+
provider: 'linkedin_oidc',
54+
strategy: 'oauth_linkedin_oidc',
55+
name: 'LinkedIn',
56+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/linkedin-oidc',
57+
},
58+
{
59+
provider: 'github',
60+
strategy: 'oauth_github',
61+
name: 'GitHub',
62+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/github',
63+
},
64+
{
65+
provider: 'gitlab',
66+
strategy: 'oauth_gitlab',
67+
name: 'GitLab',
68+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/gitlab',
69+
},
70+
{
71+
provider: 'dropbox',
72+
strategy: 'oauth_dropbox',
73+
name: 'Dropbox',
74+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/dropbox',
75+
},
76+
{
77+
provider: 'atlassian',
78+
strategy: 'oauth_atlassian',
79+
name: 'Atlassian',
80+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/atlassian',
81+
},
82+
{
83+
provider: 'bitbucket',
84+
strategy: 'oauth_bitbucket',
85+
name: 'Bitbucket',
86+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/bitbucket',
87+
},
88+
{
89+
provider: 'hubspot',
90+
strategy: 'oauth_hubspot',
91+
name: 'HubSpot',
92+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/hubspot',
93+
},
94+
{
95+
provider: 'notion',
96+
strategy: 'oauth_notion',
97+
name: 'Notion',
98+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/notion',
99+
},
100+
{
101+
provider: 'apple',
102+
strategy: 'oauth_apple',
103+
name: 'Apple',
104+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/apple',
105+
},
106+
{
107+
provider: 'line',
108+
strategy: 'oauth_line',
109+
name: 'LINE',
110+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/line',
111+
},
112+
{
113+
provider: 'instagram',
114+
strategy: 'oauth_instagram',
115+
name: 'Instagram',
116+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/instagram',
117+
},
118+
{
119+
provider: 'coinbase',
120+
strategy: 'oauth_coinbase',
121+
name: 'Coinbase',
122+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/coinbase',
123+
},
124+
{
125+
provider: 'spotify',
126+
strategy: 'oauth_spotify',
127+
name: 'Spotify',
128+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/spotify',
129+
},
130+
{
131+
provider: 'xero',
132+
strategy: 'oauth_xero',
133+
name: 'Xero',
134+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/xero',
135+
},
136+
{
137+
provider: 'box',
138+
strategy: 'oauth_box',
139+
name: 'Box',
140+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/box',
141+
},
142+
{
143+
provider: 'slack',
144+
strategy: 'oauth_slack',
145+
name: 'Slack',
146+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/slack',
147+
},
148+
{
149+
provider: 'linear',
150+
strategy: 'oauth_linear',
151+
name: 'Linear',
152+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/linear',
153+
},
154+
{
155+
provider: 'x',
156+
strategy: 'oauth_x',
157+
name: 'X / Twitter',
158+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/x-twitter-v2',
159+
},
160+
{
161+
provider: 'enstall',
162+
strategy: 'oauth_enstall',
163+
name: 'Enstall',
164+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/enstall',
165+
},
166+
{
167+
provider: 'huggingface',
168+
strategy: 'oauth_huggingface',
169+
name: 'Hugging Face',
170+
docsUrl: 'https://clerk.com/docs/authentication/social-connections/huggingface',
171+
},
172+
];
173+
174+
interface getOAuthProviderDataProps {
175+
provider?: OAuthProvider;
176+
strategy?: OAuthStrategy;
177+
}
178+
179+
export function getOAuthProviderData({
180+
provider,
181+
strategy,
182+
}: getOAuthProviderDataProps): OAuthProviderData | undefined | null {
183+
if (provider) {
184+
return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.provider == provider);
185+
}
186+
187+
return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy == strategy);
188+
}

‎packages/shared/src/web3.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Web3ProviderData } from '@clerk/types';
2+
3+
export const WEB3_PROVIDERS: Web3ProviderData[] = [
4+
{
5+
provider: 'metamask',
6+
strategy: 'web3_metamask_signature',
7+
name: 'MetaMask',
8+
},
9+
{
10+
provider: 'coinbase_wallet',
11+
strategy: 'web3_coinbase_wallet_signature',
12+
name: 'Coinbase Wallet',
13+
},
14+
{
15+
provider: 'okx_wallet',
16+
strategy: 'web3_okx_wallet_signature',
17+
name: 'OKX Wallet',
18+
},
19+
];

‎packages/types/src/oauth.ts

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export type OAuthProvider =
7070
| HuggingfaceOAuthProvider
7171
| CustomOauthProvider;
7272

73+
/**
74+
* @deprecated This utility will be dropped in the next major release.
75+
* You can import it from `@clerk/shared/oauth`.
76+
*/
7377
export const OAUTH_PROVIDERS: OAuthProviderData[] = [
7478
{
7579
provider: 'google',
@@ -246,6 +250,9 @@ interface getOAuthProviderDataProps {
246250
strategy?: OAuthStrategy;
247251
}
248252

253+
/**
254+
* @deprecated This utility will be dropped in the next major release.
255+
*/
249256
export function getOAuthProviderData({
250257
provider,
251258
strategy,
@@ -257,6 +264,9 @@ export function getOAuthProviderData({
257264
return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy == strategy);
258265
}
259266

267+
/**
268+
* @deprecated This utility will be dropped in the next major release.
269+
*/
260270
export function sortedOAuthProviders(sortingArray: OAuthStrategy[]) {
261271
return OAUTH_PROVIDERS.slice().sort((a, b) => {
262272
let aPos = sortingArray.indexOf(a.strategy);

‎packages/types/src/web3.ts

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type OKXWalletWeb3Provider = 'okx_wallet';
1212

1313
export type Web3Provider = MetamaskWeb3Provider | CoinbaseWalletWeb3Provider | OKXWalletWeb3Provider;
1414

15+
/**
16+
* @deprecated This constant will be dropped in the next major release.
17+
* You can import it from `@clerk/shared/web3`.
18+
*/
1519
export const WEB3_PROVIDERS: Web3ProviderData[] = [
1620
{
1721
provider: 'metamask',
@@ -35,6 +39,9 @@ interface getWeb3ProviderDataProps {
3539
strategy?: Web3Strategy;
3640
}
3741

42+
/**
43+
* @deprecated This utility will be dropped in the next major release.
44+
*/
3845
export function getWeb3ProviderData({
3946
provider,
4047
strategy,

‎packages/ui/src/descriptors.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { OAUTH_PROVIDERS, type OAuthProvider, WEB3_PROVIDERS, type Web3Provider } from '@clerk/types';
1+
import { OAUTH_PROVIDERS } from '@clerk/shared/oauth';
2+
import { WEB3_PROVIDERS } from '@clerk/shared/web3';
3+
import type { OAuthProvider, Web3Provider } from '@clerk/types';
24

35
export const DESCRIPTORS = [
46
// Alert

0 commit comments

Comments
 (0)
Please sign in to comment.