@gatwech/core 0.0.11 → 1.0.0-beta.19

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.
Files changed (134) hide show
  1. package/dist/api/index.d.mts +2 -2
  2. package/dist/context/index.d.mts +2 -2
  3. package/dist/db/adapter/index.d.mts +2 -2
  4. package/dist/db/index.d.mts +2 -2
  5. package/dist/env/index.d.mts +1 -1
  6. package/dist/env/index.mjs +1 -1
  7. package/dist/{env-JMSMESs1.mjs → env-ubiqEEZm.mjs} +10 -9
  8. package/dist/error/index.mjs +2 -2
  9. package/dist/{error-41YsFQ8b.mjs → error-DKIIiFmH.mjs} +1 -1
  10. package/dist/{index-DLP-K0uY.d.mts → index-CNtOUpmF.d.mts} +4 -3
  11. package/dist/index-Df0KhQRf.d.mts +3002 -0
  12. package/dist/index.d.mts +3 -3
  13. package/dist/oauth2/index.d.mts +2 -2
  14. package/dist/social-providers/index.d.mts +3 -3
  15. package/dist/social-providers/index.mjs +73 -2414
  16. package/dist/src/api/index.d.ts +119 -0
  17. package/dist/src/async_hooks/index.d.ts +6 -0
  18. package/dist/src/context/endpoint-context.d.ts +14 -0
  19. package/dist/src/context/index.d.ts +3 -0
  20. package/dist/src/context/request-state.d.ts +13 -0
  21. package/dist/src/context/transaction.d.ts +11 -0
  22. package/dist/src/db/adapter/index.d.ts +401 -0
  23. package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
  24. package/dist/src/db/plugin.d.ts +10 -0
  25. package/dist/src/db/schema/account.d.ts +22 -0
  26. package/dist/src/db/schema/rate-limit.d.ts +10 -0
  27. package/dist/src/db/schema/session.d.ts +17 -0
  28. package/dist/src/db/schema/shared.d.ts +6 -0
  29. package/dist/src/db/schema/user.d.ts +16 -0
  30. package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
  31. package/dist/src/db/type.d.ts +159 -0
  32. package/dist/src/env/color-depth.d.ts +1 -0
  33. package/dist/src/env/env-impl.d.ts +29 -0
  34. package/dist/src/env/index.d.ts +3 -0
  35. package/dist/src/env/logger.d.ts +52 -0
  36. package/dist/src/error/codes.d.ts +27 -0
  37. package/dist/src/error/index.d.ts +4 -0
  38. package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
  39. package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
  40. package/dist/src/oauth2/index.d.ts +6 -0
  41. package/dist/src/oauth2/oauth-provider.d.ts +178 -0
  42. package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
  43. package/dist/src/oauth2/utils.d.ts +3 -0
  44. package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
  45. package/dist/src/social-providers/github.d.ts +89 -0
  46. package/dist/src/social-providers/google.d.ts +82 -0
  47. package/dist/src/social-providers/index.d.ts +93 -0
  48. package/dist/src/types/context.d.ts +177 -0
  49. package/dist/src/types/cookie.d.ts +15 -0
  50. package/dist/src/types/helper.d.ts +9 -0
  51. package/dist/src/types/index.d.ts +7 -0
  52. package/dist/src/types/init-options.d.ts +1140 -0
  53. package/dist/src/types/plugin-client.d.ts +88 -0
  54. package/dist/src/types/plugin.d.ts +120 -0
  55. package/dist/src/utils/error-codes.d.ts +9 -0
  56. package/dist/utils/index.mjs +1 -1
  57. package/package.json +11 -5
  58. package/.turbo/turbo-build.log +0 -42
  59. package/dist/index-DjrJweYn.d.mts +0 -7312
  60. package/src/api/index.ts +0 -57
  61. package/src/async_hooks/index.ts +0 -35
  62. package/src/context/endpoint-context.ts +0 -48
  63. package/src/context/index.ts +0 -21
  64. package/src/context/request-state.test.ts +0 -346
  65. package/src/context/request-state.ts +0 -75
  66. package/src/context/transaction.ts +0 -72
  67. package/src/db/adapter/index.ts +0 -466
  68. package/src/db/plugin.ts +0 -11
  69. package/src/db/schema/account.ts +0 -34
  70. package/src/db/schema/rate-limit.ts +0 -21
  71. package/src/db/schema/session.ts +0 -17
  72. package/src/db/schema/shared.ts +0 -7
  73. package/src/db/schema/user.ts +0 -16
  74. package/src/db/type.ts +0 -180
  75. package/src/env/color-depth.ts +0 -172
  76. package/src/env/env-impl.ts +0 -124
  77. package/src/env/index.ts +0 -23
  78. package/src/env/logger.test.ts +0 -33
  79. package/src/env/logger.ts +0 -145
  80. package/src/error/codes.ts +0 -31
  81. package/src/error/index.ts +0 -11
  82. package/src/oauth2/client-credentials-token.ts +0 -102
  83. package/src/oauth2/create-authorization-url.ts +0 -85
  84. package/src/oauth2/index.ts +0 -21
  85. package/src/oauth2/oauth-provider.ts +0 -211
  86. package/src/oauth2/refresh-access-token.ts +0 -124
  87. package/src/oauth2/utils.ts +0 -36
  88. package/src/oauth2/validate-authorization-code.ts +0 -154
  89. package/src/social-providers/apple.ts +0 -213
  90. package/src/social-providers/atlassian.ts +0 -132
  91. package/src/social-providers/cognito.ts +0 -269
  92. package/src/social-providers/discord.ts +0 -169
  93. package/src/social-providers/dropbox.ts +0 -112
  94. package/src/social-providers/facebook.ts +0 -204
  95. package/src/social-providers/figma.ts +0 -115
  96. package/src/social-providers/github.ts +0 -154
  97. package/src/social-providers/gitlab.ts +0 -152
  98. package/src/social-providers/google.ts +0 -171
  99. package/src/social-providers/huggingface.ts +0 -118
  100. package/src/social-providers/index.ts +0 -124
  101. package/src/social-providers/kakao.ts +0 -178
  102. package/src/social-providers/kick.ts +0 -92
  103. package/src/social-providers/line.ts +0 -169
  104. package/src/social-providers/linear.ts +0 -120
  105. package/src/social-providers/linkedin.ts +0 -110
  106. package/src/social-providers/microsoft-entra-id.ts +0 -245
  107. package/src/social-providers/naver.ts +0 -112
  108. package/src/social-providers/notion.ts +0 -108
  109. package/src/social-providers/paybin.ts +0 -122
  110. package/src/social-providers/paypal.ts +0 -263
  111. package/src/social-providers/polar.ts +0 -107
  112. package/src/social-providers/reddit.ts +0 -122
  113. package/src/social-providers/roblox.ts +0 -110
  114. package/src/social-providers/salesforce.ts +0 -159
  115. package/src/social-providers/slack.ts +0 -111
  116. package/src/social-providers/spotify.ts +0 -93
  117. package/src/social-providers/tiktok.ts +0 -210
  118. package/src/social-providers/twitch.ts +0 -111
  119. package/src/social-providers/twitter.ts +0 -198
  120. package/src/social-providers/vk.ts +0 -126
  121. package/src/social-providers/zoom.ts +0 -217
  122. package/src/types/context.ts +0 -269
  123. package/src/types/cookie.ts +0 -7
  124. package/src/types/helper.ts +0 -6
  125. package/src/types/index.ts +0 -21
  126. package/src/types/init-options.ts +0 -1346
  127. package/src/types/plugin-client.ts +0 -100
  128. package/src/types/plugin.ts +0 -158
  129. package/src/utils/error-codes.ts +0 -51
  130. package/tsconfig.json +0 -7
  131. package/tsdown.config.ts +0 -20
  132. /package/{src/index.ts → dist/src/index.d.ts} +0 -0
  133. /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
  134. /package/dist/{utils-BFQCAfNW.mjs → utils-CTOwq_Nj.mjs} +0 -0
@@ -1,210 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
- import { refreshAccessToken, validateAuthorizationCode } from "../oauth2";
4
-
5
- /**
6
- * [More info](https://developers.tiktok.com/doc/tiktok-api-v2-get-user-info/)
7
- */
8
- export interface TiktokProfile extends Record<string, any> {
9
- data: {
10
- user: {
11
- /**
12
- * The unique identification of the user in the current application.Open id
13
- * for the client.
14
- *
15
- * To return this field, add `fields=open_id` in the user profile request's query parameter.
16
- */
17
- open_id: string;
18
- /**
19
- * The unique identification of the user across different apps for the same developer.
20
- * For example, if a partner has X number of clients,
21
- * it will get X number of open_id for the same TikTok user,
22
- * but one persistent union_id for the particular user.
23
- *
24
- * To return this field, add `fields=union_id` in the user profile request's query parameter.
25
- */
26
- union_id?: string | undefined;
27
- /**
28
- * User's profile image.
29
- *
30
- * To return this field, add `fields=avatar_url` in the user profile request's query parameter.
31
- */
32
- avatar_url?: string | undefined;
33
- /**
34
- * User`s profile image in 100x100 size.
35
- *
36
- * To return this field, add `fields=avatar_url_100` in the user profile request's query parameter.
37
- */
38
- avatar_url_100?: string | undefined;
39
- /**
40
- * User's profile image with higher resolution
41
- *
42
- * To return this field, add `fields=avatar_url_100` in the user profile request's query parameter.
43
- */
44
- avatar_large_url: string;
45
- /**
46
- * User's profile name
47
- *
48
- * To return this field, add `fields=display_name` in the user profile request's query parameter.
49
- */
50
- display_name: string;
51
- /**
52
- * User's username.
53
- *
54
- * To return this field, add `fields=username` in the user profile request's query parameter.
55
- */
56
- username: string;
57
- /** @note Email is currently unsupported by TikTok */
58
- email?: string | undefined;
59
- /**
60
- * User's bio description if there is a valid one.
61
- *
62
- * To return this field, add `fields=bio_description` in the user profile request's query parameter.
63
- */
64
- bio_description?: string | undefined;
65
- /**
66
- * The link to user's TikTok profile page.
67
- *
68
- * To return this field, add `fields=profile_deep_link` in the user profile request's query parameter.
69
- */
70
- profile_deep_link?: string | undefined;
71
- /**
72
- * Whether TikTok has provided a verified badge to the account after confirming
73
- * that it belongs to the user it represents.
74
- *
75
- * To return this field, add `fields=is_verified` in the user profile request's query parameter.
76
- */
77
- is_verified?: boolean | undefined;
78
- /**
79
- * User's followers count.
80
- *
81
- * To return this field, add `fields=follower_count` in the user profile request's query parameter.
82
- */
83
- follower_count?: number | undefined;
84
- /**
85
- * The number of accounts that the user is following.
86
- *
87
- * To return this field, add `fields=following_count` in the user profile request's query parameter.
88
- */
89
- following_count?: number | undefined;
90
- /**
91
- * The total number of likes received by the user across all of their videos.
92
- *
93
- * To return this field, add `fields=likes_count` in the user profile request's query parameter.
94
- */
95
- likes_count?: number | undefined;
96
- /**
97
- * The total number of publicly posted videos by the user.
98
- *
99
- * To return this field, add `fields=video_count` in the user profile request's query parameter.
100
- */
101
- video_count?: number | undefined;
102
- };
103
- };
104
- error?:
105
- | {
106
- /**
107
- * The error category in string.
108
- */
109
- code?: string;
110
- /**
111
- * The error message in string.
112
- */
113
- message?: string;
114
- /**
115
- * The error message in string.
116
- */
117
- log_id?: string;
118
- }
119
- | undefined;
120
- }
121
-
122
- export interface TiktokOptions extends ProviderOptions {
123
- // Client ID is not used in TikTok, we delete it from the options
124
- clientId?: never | undefined;
125
- clientSecret: string;
126
- clientKey: string;
127
- }
128
-
129
- export const tiktok = (options: TiktokOptions) => {
130
- return {
131
- id: "tiktok",
132
- name: "TikTok",
133
- createAuthorizationURL({ state, scopes, redirectURI }) {
134
- const _scopes = options.disableDefaultScope ? [] : ["user.info.profile"];
135
- if (options.scope) _scopes.push(...options.scope);
136
- if (scopes) _scopes.push(...scopes);
137
- return new URL(
138
- `https://www.tiktok.com/v2/auth/authorize?scope=${_scopes.join(
139
- ",",
140
- )}&response_type=code&client_key=${options.clientKey}&redirect_uri=${encodeURIComponent(
141
- options.redirectURI || redirectURI,
142
- )}&state=${state}`,
143
- );
144
- },
145
-
146
- validateAuthorizationCode: async ({ code, redirectURI }) => {
147
- return validateAuthorizationCode({
148
- code,
149
- redirectURI: options.redirectURI || redirectURI,
150
- options: {
151
- clientKey: options.clientKey,
152
- clientSecret: options.clientSecret,
153
- },
154
- tokenEndpoint: "https://open.tiktokapis.com/v2/oauth/token/",
155
- });
156
- },
157
- refreshAccessToken: options.refreshAccessToken
158
- ? options.refreshAccessToken
159
- : async (refreshToken) => {
160
- return refreshAccessToken({
161
- refreshToken,
162
- options: {
163
- clientSecret: options.clientSecret,
164
- },
165
- tokenEndpoint: "https://open.tiktokapis.com/v2/oauth/token/",
166
- authentication: "post",
167
- extraParams: {
168
- client_key: options.clientKey,
169
- },
170
- });
171
- },
172
- async getUserInfo(token) {
173
- if (options.getUserInfo) {
174
- return options.getUserInfo(token);
175
- }
176
-
177
- const fields = [
178
- "open_id",
179
- "avatar_large_url",
180
- "display_name",
181
- "username",
182
- ];
183
- const { data: profile, error } = await betterFetch<TiktokProfile>(
184
- `https://open.tiktokapis.com/v2/user/info/?fields=${fields.join(",")}`,
185
- {
186
- headers: {
187
- authorization: `Bearer ${token.accessToken}`,
188
- },
189
- },
190
- );
191
-
192
- if (error) {
193
- return null;
194
- }
195
-
196
- return {
197
- user: {
198
- email: profile.data.user.email || profile.data.user.username,
199
- id: profile.data.user.open_id,
200
- name: profile.data.user.display_name || profile.data.user.username,
201
- image: profile.data.user.avatar_large_url,
202
- /** @note Tiktok does not provide emailVerified or even email*/
203
- emailVerified: profile.data.user.email ? true : false,
204
- },
205
- data: profile,
206
- };
207
- },
208
- options,
209
- } satisfies OAuthProvider<TiktokProfile, TiktokOptions>;
210
- };
@@ -1,111 +0,0 @@
1
- import { decodeJwt } from "jose";
2
- import { logger } from "../env";
3
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
4
- import {
5
- createAuthorizationURL,
6
- refreshAccessToken,
7
- validateAuthorizationCode,
8
- } from "../oauth2";
9
-
10
- /**
11
- * @see https://dev.twitch.tv/docs/authentication/getting-tokens-oidc/#requesting-claims
12
- */
13
- export interface TwitchProfile {
14
- /**
15
- * The sub of the user
16
- */
17
- sub: string;
18
- /**
19
- * The preferred username of the user
20
- */
21
- preferred_username: string;
22
- /**
23
- * The email of the user
24
- */
25
- email: string;
26
- /**
27
- * Indicate if this user has a verified email.
28
- */
29
- email_verified: boolean;
30
- /**
31
- * The picture of the user
32
- */
33
- picture: string;
34
- }
35
-
36
- export interface TwitchOptions extends ProviderOptions<TwitchProfile> {
37
- clientId: string;
38
- claims?: string[] | undefined;
39
- }
40
- export const twitch = (options: TwitchOptions) => {
41
- return {
42
- id: "twitch",
43
- name: "Twitch",
44
- createAuthorizationURL({ state, scopes, redirectURI }) {
45
- const _scopes = options.disableDefaultScope
46
- ? []
47
- : ["user:read:email", "openid"];
48
- if (options.scope) _scopes.push(...options.scope);
49
- if (scopes) _scopes.push(...scopes);
50
- return createAuthorizationURL({
51
- id: "twitch",
52
- redirectURI,
53
- options,
54
- authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
55
- scopes: _scopes,
56
- state,
57
- claims: options.claims || [
58
- "email",
59
- "email_verified",
60
- "preferred_username",
61
- "picture",
62
- ],
63
- });
64
- },
65
- validateAuthorizationCode: async ({ code, redirectURI }) => {
66
- return validateAuthorizationCode({
67
- code,
68
- redirectURI,
69
- options,
70
- tokenEndpoint: "https://id.twitch.tv/oauth2/token",
71
- });
72
- },
73
- refreshAccessToken: options.refreshAccessToken
74
- ? options.refreshAccessToken
75
- : async (refreshToken) => {
76
- return refreshAccessToken({
77
- refreshToken,
78
- options: {
79
- clientId: options.clientId,
80
- clientKey: options.clientKey,
81
- clientSecret: options.clientSecret,
82
- },
83
- tokenEndpoint: "https://id.twitch.tv/oauth2/token",
84
- });
85
- },
86
- async getUserInfo(token) {
87
- if (options.getUserInfo) {
88
- return options.getUserInfo(token);
89
- }
90
- const idToken = token.idToken;
91
- if (!idToken) {
92
- logger.error("No idToken found in token");
93
- return null;
94
- }
95
- const profile = decodeJwt(idToken) as TwitchProfile;
96
- const userMap = await options.mapProfileToUser?.(profile);
97
- return {
98
- user: {
99
- id: profile.sub,
100
- name: profile.preferred_username,
101
- email: profile.email,
102
- image: profile.picture,
103
- emailVerified: profile.email_verified,
104
- ...userMap,
105
- },
106
- data: profile,
107
- };
108
- },
109
- options,
110
- } satisfies OAuthProvider<TwitchProfile>;
111
- };
@@ -1,198 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
- import {
4
- createAuthorizationURL,
5
- refreshAccessToken,
6
- validateAuthorizationCode,
7
- } from "../oauth2";
8
-
9
- export interface TwitterProfile {
10
- data: {
11
- /**
12
- * Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools
13
- * that cannot handle large integers.
14
- */
15
- id: string;
16
- /** The friendly name of this user, as shown on their profile. */
17
- name: string;
18
- /** The email address of this user. */
19
- email?: string | undefined;
20
- /** The Twitter handle (screen name) of this user. */
21
- username: string;
22
- /**
23
- * The location specified in the user's profile, if the user provided one.
24
- * As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.
25
- *
26
- * To return this field, add `user.fields=location` in the authorization request's query parameter.
27
- */
28
- location?: string | undefined;
29
- /**
30
- * This object and its children fields contain details about text that has a special meaning in the user's description.
31
- *
32
- *To return this field, add `user.fields=entities` in the authorization request's query parameter.
33
- */
34
- entities?:
35
- | {
36
- /** Contains details about the user's profile website. */
37
- url: {
38
- /** Contains details about the user's profile website. */
39
- urls: Array<{
40
- /** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */
41
- start: number;
42
- /** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */
43
- end: number;
44
- /** The URL in the format entered by the user. */
45
- url: string;
46
- /** The fully resolved URL. */
47
- expanded_url: string;
48
- /** The URL as displayed in the user's profile. */
49
- display_url: string;
50
- }>;
51
- };
52
- /** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */
53
- description: {
54
- hashtags: Array<{
55
- start: number;
56
- end: number;
57
- tag: string;
58
- }>;
59
- };
60
- }
61
- | undefined;
62
- /**
63
- * Indicate if this user is a verified Twitter user.
64
- *
65
- * To return this field, add `user.fields=verified` in the authorization request's query parameter.
66
- */
67
- verified?: boolean | undefined;
68
- /**
69
- * The text of this user's profile description (also known as bio), if the user provided one.
70
- *
71
- * To return this field, add `user.fields=description` in the authorization request's query parameter.
72
- */
73
- description?: string | undefined;
74
- /**
75
- * The URL specified in the user's profile, if present.
76
- *
77
- * To return this field, add `user.fields=url` in the authorization request's query parameter.
78
- */
79
- url?: string | undefined;
80
- /** The URL to the profile image for this user, as shown on the user's profile. */
81
- profile_image_url?: string | undefined;
82
- protected?: boolean | undefined;
83
- /**
84
- * Unique identifier of this user's pinned Tweet.
85
- *
86
- * You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.
87
- */
88
- pinned_tweet_id?: string | undefined;
89
- created_at?: string | undefined;
90
- };
91
- includes?:
92
- | {
93
- tweets?: Array<{
94
- id: string;
95
- text: string;
96
- }>;
97
- }
98
- | undefined;
99
- [claims: string]: unknown;
100
- }
101
-
102
- export interface TwitterOption extends ProviderOptions<TwitterProfile> {
103
- clientId: string;
104
- }
105
-
106
- export const twitter = (options: TwitterOption) => {
107
- return {
108
- id: "twitter",
109
- name: "Twitter",
110
- createAuthorizationURL(data) {
111
- const _scopes = options.disableDefaultScope
112
- ? []
113
- : ["users.read", "tweet.read", "offline.access", "users.email"];
114
- if (options.scope) _scopes.push(...options.scope);
115
- if (data.scopes) _scopes.push(...data.scopes);
116
- return createAuthorizationURL({
117
- id: "twitter",
118
- options,
119
- authorizationEndpoint: "https://x.com/i/oauth2/authorize",
120
- scopes: _scopes,
121
- state: data.state,
122
- codeVerifier: data.codeVerifier,
123
- redirectURI: data.redirectURI,
124
- });
125
- },
126
- validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
127
- return validateAuthorizationCode({
128
- code,
129
- codeVerifier,
130
- authentication: "basic",
131
- redirectURI,
132
- options,
133
- tokenEndpoint: "https://api.x.com/2/oauth2/token",
134
- });
135
- },
136
-
137
- refreshAccessToken: options.refreshAccessToken
138
- ? options.refreshAccessToken
139
- : async (refreshToken) => {
140
- return refreshAccessToken({
141
- refreshToken,
142
- options: {
143
- clientId: options.clientId,
144
- clientKey: options.clientKey,
145
- clientSecret: options.clientSecret,
146
- },
147
- authentication: "basic",
148
- tokenEndpoint: "https://api.x.com/2/oauth2/token",
149
- });
150
- },
151
- async getUserInfo(token) {
152
- if (options.getUserInfo) {
153
- return options.getUserInfo(token);
154
- }
155
- const { data: profile, error: profileError } =
156
- await betterFetch<TwitterProfile>(
157
- "https://api.x.com/2/users/me?user.fields=profile_image_url",
158
- {
159
- method: "GET",
160
- headers: {
161
- Authorization: `Bearer ${token.accessToken}`,
162
- },
163
- },
164
- );
165
-
166
- if (profileError) {
167
- return null;
168
- }
169
-
170
- const { data: emailData, error: emailError } = await betterFetch<{
171
- data: { confirmed_email: string };
172
- }>("https://api.x.com/2/users/me?user.fields=confirmed_email", {
173
- method: "GET",
174
- headers: {
175
- Authorization: `Bearer ${token.accessToken}`,
176
- },
177
- });
178
- let emailVerified = false;
179
- if (!emailError && emailData?.data?.confirmed_email) {
180
- profile.data.email = emailData.data.confirmed_email;
181
- emailVerified = true;
182
- }
183
- const userMap = await options.mapProfileToUser?.(profile);
184
- return {
185
- user: {
186
- id: profile.data.id,
187
- name: profile.data.name,
188
- email: profile.data.email || profile.data.username || null,
189
- image: profile.data.profile_image_url,
190
- emailVerified: emailVerified,
191
- ...userMap,
192
- },
193
- data: profile,
194
- };
195
- },
196
- options,
197
- } satisfies OAuthProvider<TwitterProfile>;
198
- };
@@ -1,126 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import {
3
- createAuthorizationURL,
4
- type OAuthProvider,
5
- type ProviderOptions,
6
- refreshAccessToken,
7
- validateAuthorizationCode,
8
- } from "../oauth2";
9
-
10
- export interface VkProfile {
11
- user: {
12
- user_id: string;
13
- first_name: string;
14
- last_name: string;
15
- email?: string | undefined;
16
- phone?: number | undefined;
17
- avatar?: string | undefined;
18
- sex?: number | undefined;
19
- verified?: boolean | undefined;
20
- birthday: string;
21
- };
22
- }
23
-
24
- export interface VkOption extends ProviderOptions {
25
- clientId: string;
26
- scheme?: ("light" | "dark") | undefined;
27
- }
28
-
29
- export const vk = (options: VkOption) => {
30
- return {
31
- id: "vk",
32
- name: "VK",
33
- async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
34
- const _scopes = options.disableDefaultScope ? [] : ["email", "phone"];
35
- if (options.scope) _scopes.push(...options.scope);
36
- if (scopes) _scopes.push(...scopes);
37
- const authorizationEndpoint = "https://id.vk.com/authorize";
38
-
39
- return createAuthorizationURL({
40
- id: "vk",
41
- options,
42
- authorizationEndpoint,
43
- scopes: _scopes,
44
- state,
45
- redirectURI,
46
- codeVerifier,
47
- });
48
- },
49
- validateAuthorizationCode: async ({
50
- code,
51
- codeVerifier,
52
- redirectURI,
53
- deviceId,
54
- }) => {
55
- return validateAuthorizationCode({
56
- code,
57
- codeVerifier,
58
- redirectURI: options.redirectURI || redirectURI,
59
- options,
60
- deviceId,
61
- tokenEndpoint: "https://id.vk.com/oauth2/auth",
62
- });
63
- },
64
- refreshAccessToken: options.refreshAccessToken
65
- ? options.refreshAccessToken
66
- : async (refreshToken) => {
67
- return refreshAccessToken({
68
- refreshToken,
69
- options: {
70
- clientId: options.clientId,
71
- clientKey: options.clientKey,
72
- clientSecret: options.clientSecret,
73
- },
74
- tokenEndpoint: "https://id.vk.com/oauth2/auth",
75
- });
76
- },
77
- async getUserInfo(data) {
78
- if (options.getUserInfo) {
79
- return options.getUserInfo(data);
80
- }
81
- if (!data.accessToken) {
82
- return null;
83
- }
84
- const formBody = new URLSearchParams({
85
- access_token: data.accessToken,
86
- client_id: options.clientId,
87
- }).toString();
88
- const { data: profile, error } = await betterFetch<VkProfile>(
89
- "https://id.vk.com/oauth2/user_info",
90
- {
91
- method: "POST",
92
- headers: {
93
- "Content-Type": "application/x-www-form-urlencoded",
94
- },
95
- body: formBody,
96
- },
97
- );
98
- if (error) {
99
- return null;
100
- }
101
-
102
- const userMap = await options.mapProfileToUser?.(profile);
103
- if (!profile.user.email && !userMap?.email) {
104
- return null;
105
- }
106
-
107
- return {
108
- user: {
109
- id: profile.user.user_id,
110
- first_name: profile.user.first_name,
111
- last_name: profile.user.last_name,
112
- email: profile.user.email,
113
- image: profile.user.avatar,
114
- /** @note VK does not provide emailVerified*/
115
- emailVerified: !!profile.user.email,
116
- birthday: profile.user.birthday,
117
- sex: profile.user.sex,
118
- name: `${profile.user.first_name} ${profile.user.last_name}`,
119
- ...userMap,
120
- },
121
- data: profile,
122
- };
123
- },
124
- options,
125
- } satisfies OAuthProvider<VkProfile>;
126
- };