@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,122 +0,0 @@
1
- import { base64 } from "@gatwech/utils/base64";
2
- import { betterFetch } from "@better-fetch/fetch";
3
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
4
- import {
5
- createAuthorizationURL,
6
- getOAuth2Tokens,
7
- refreshAccessToken,
8
- } from "../oauth2";
9
-
10
- export interface RedditProfile {
11
- id: string;
12
- name: string;
13
- icon_img: string | null;
14
- has_verified_email: boolean;
15
- oauth_client_id: string;
16
- verified: boolean;
17
- }
18
-
19
- export interface RedditOptions extends ProviderOptions<RedditProfile> {
20
- clientId: string;
21
- duration?: string | undefined;
22
- }
23
-
24
- export const reddit = (options: RedditOptions) => {
25
- return {
26
- id: "reddit",
27
- name: "Reddit",
28
- createAuthorizationURL({ state, scopes, redirectURI }) {
29
- const _scopes = options.disableDefaultScope ? [] : ["identity"];
30
- if (options.scope) _scopes.push(...options.scope);
31
- if (scopes) _scopes.push(...scopes);
32
- return createAuthorizationURL({
33
- id: "reddit",
34
- options,
35
- authorizationEndpoint: "https://www.reddit.com/api/v1/authorize",
36
- scopes: _scopes,
37
- state,
38
- redirectURI,
39
- duration: options.duration,
40
- });
41
- },
42
- validateAuthorizationCode: async ({ code, redirectURI }) => {
43
- const body = new URLSearchParams({
44
- grant_type: "authorization_code",
45
- code,
46
- redirect_uri: options.redirectURI || redirectURI,
47
- });
48
- const headers = {
49
- "content-type": "application/x-www-form-urlencoded",
50
- accept: "text/plain",
51
- "user-agent": "gatwech",
52
- Authorization: `Basic ${base64.encode(
53
- `${options.clientId}:${options.clientSecret}`
54
- )}`,
55
- };
56
-
57
- const { data, error } = await betterFetch<object>(
58
- "https://www.reddit.com/api/v1/access_token",
59
- {
60
- method: "POST",
61
- headers,
62
- body: body.toString(),
63
- }
64
- );
65
-
66
- if (error) {
67
- throw error;
68
- }
69
-
70
- return getOAuth2Tokens(data);
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
- authentication: "basic",
84
- tokenEndpoint: "https://www.reddit.com/api/v1/access_token",
85
- });
86
- },
87
- async getUserInfo(token) {
88
- if (options.getUserInfo) {
89
- return options.getUserInfo(token);
90
- }
91
-
92
- const { data: profile, error } = await betterFetch<RedditProfile>(
93
- "https://oauth.reddit.com/api/v1/me",
94
- {
95
- headers: {
96
- Authorization: `Bearer ${token.accessToken}`,
97
- "User-Agent": "gatwech",
98
- },
99
- }
100
- );
101
-
102
- if (error) {
103
- return null;
104
- }
105
-
106
- const userMap = await options.mapProfileToUser?.(profile);
107
-
108
- return {
109
- user: {
110
- id: profile.id,
111
- name: profile.name,
112
- email: profile.oauth_client_id,
113
- emailVerified: profile.has_verified_email,
114
- image: profile.icon_img?.split("?")[0]!,
115
- ...userMap,
116
- },
117
- data: profile,
118
- };
119
- },
120
- options,
121
- } satisfies OAuthProvider<RedditProfile>;
122
- };
@@ -1,110 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
- import { refreshAccessToken, validateAuthorizationCode } from "../oauth2";
4
-
5
- export interface RobloxProfile extends Record<string, any> {
6
- /** the user's id */
7
- sub: string;
8
- /** the user's username */
9
- preferred_username: string;
10
- /** the user's display name, will return the same value as the preferred_username if not set */
11
- nickname: string;
12
- /** the user's display name, again, will return the same value as the preferred_username if not set */
13
- name: string;
14
- /** the account creation date as a unix timestamp in seconds */
15
- created_at: number;
16
- /** the user's profile URL */
17
- profile: string;
18
- /** the user's avatar URL */
19
- picture: string;
20
- }
21
-
22
- export interface RobloxOptions extends ProviderOptions<RobloxProfile> {
23
- clientId: string;
24
- prompt?:
25
- | (
26
- | "none"
27
- | "consent"
28
- | "login"
29
- | "select_account"
30
- | "select_account consent"
31
- )
32
- | undefined;
33
- }
34
-
35
- export const roblox = (options: RobloxOptions) => {
36
- return {
37
- id: "roblox",
38
- name: "Roblox",
39
- createAuthorizationURL({ state, scopes, redirectURI }) {
40
- const _scopes = options.disableDefaultScope ? [] : ["openid", "profile"];
41
- if (options.scope) _scopes.push(...options.scope);
42
- if (scopes) _scopes.push(...scopes);
43
- return new URL(
44
- `https://apis.roblox.com/oauth/v1/authorize?scope=${_scopes.join(
45
- "+",
46
- )}&response_type=code&client_id=${
47
- options.clientId
48
- }&redirect_uri=${encodeURIComponent(
49
- options.redirectURI || redirectURI,
50
- )}&state=${state}&prompt=${options.prompt || "select_account consent"}`,
51
- );
52
- },
53
- validateAuthorizationCode: async ({ code, redirectURI }) => {
54
- return validateAuthorizationCode({
55
- code,
56
- redirectURI: options.redirectURI || redirectURI,
57
- options,
58
- tokenEndpoint: "https://apis.roblox.com/oauth/v1/token",
59
- authentication: "post",
60
- });
61
- },
62
- refreshAccessToken: options.refreshAccessToken
63
- ? options.refreshAccessToken
64
- : async (refreshToken) => {
65
- return refreshAccessToken({
66
- refreshToken,
67
- options: {
68
- clientId: options.clientId,
69
- clientKey: options.clientKey,
70
- clientSecret: options.clientSecret,
71
- },
72
- tokenEndpoint: "https://apis.roblox.com/oauth/v1/token",
73
- });
74
- },
75
- async getUserInfo(token) {
76
- if (options.getUserInfo) {
77
- return options.getUserInfo(token);
78
- }
79
- const { data: profile, error } = await betterFetch<RobloxProfile>(
80
- "https://apis.roblox.com/oauth/v1/userinfo",
81
- {
82
- headers: {
83
- authorization: `Bearer ${token.accessToken}`,
84
- },
85
- },
86
- );
87
-
88
- if (error) {
89
- return null;
90
- }
91
-
92
- const userMap = await options.mapProfileToUser?.(profile);
93
-
94
- return {
95
- user: {
96
- id: profile.sub,
97
- name: profile.nickname || profile.preferred_username || "",
98
- image: profile.picture,
99
- email: profile.preferred_username || null, // Roblox does not provide email
100
- emailVerified: true,
101
- ...userMap,
102
- },
103
- data: {
104
- ...profile,
105
- },
106
- };
107
- },
108
- options,
109
- } satisfies OAuthProvider<RobloxProfile>;
110
- };
@@ -1,159 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import { logger } from "../env";
3
- import { PayvoAuthError } from "../error";
4
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
- import {
6
- createAuthorizationURL,
7
- refreshAccessToken,
8
- validateAuthorizationCode,
9
- } from "../oauth2";
10
-
11
- export interface SalesforceProfile {
12
- sub: string;
13
- user_id: string;
14
- organization_id: string;
15
- preferred_username?: string | undefined;
16
- email: string;
17
- email_verified?: boolean | undefined;
18
- name: string;
19
- given_name?: string | undefined;
20
- family_name?: string | undefined;
21
- zoneinfo?: string | undefined;
22
- photos?:
23
- | {
24
- picture?: string;
25
- thumbnail?: string;
26
- }
27
- | undefined;
28
- }
29
-
30
- export interface SalesforceOptions extends ProviderOptions<SalesforceProfile> {
31
- clientId: string;
32
- environment?: ("sandbox" | "production") | undefined;
33
- loginUrl?: string | undefined;
34
- /**
35
- * Override the redirect URI if auto-detection fails.
36
- * Should match the Callback URL configured in your Salesforce Connected App.
37
- * @example "http://localhost:3000/api/v1/auth/callback/salesforce"
38
- */
39
- redirectURI?: string | undefined;
40
- }
41
-
42
- export const salesforce = (options: SalesforceOptions) => {
43
- const environment = options.environment ?? "production";
44
- const isSandbox = environment === "sandbox";
45
- const authorizationEndpoint = options.loginUrl
46
- ? `https://${options.loginUrl}/services/oauth2/authorize`
47
- : isSandbox
48
- ? "https://test.salesforce.com/services/oauth2/authorize"
49
- : "https://login.salesforce.com/services/oauth2/authorize";
50
-
51
- const tokenEndpoint = options.loginUrl
52
- ? `https://${options.loginUrl}/services/oauth2/token`
53
- : isSandbox
54
- ? "https://test.salesforce.com/services/oauth2/token"
55
- : "https://login.salesforce.com/services/oauth2/token";
56
-
57
- const userInfoEndpoint = options.loginUrl
58
- ? `https://${options.loginUrl}/services/oauth2/userinfo`
59
- : isSandbox
60
- ? "https://test.salesforce.com/services/oauth2/userinfo"
61
- : "https://login.salesforce.com/services/oauth2/userinfo";
62
-
63
- return {
64
- id: "salesforce",
65
- name: "Salesforce",
66
-
67
- async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
68
- if (!options.clientId || !options.clientSecret) {
69
- logger.error(
70
- "Client Id and Client Secret are required for Salesforce. Make sure to provide them in the options."
71
- );
72
- throw new PayvoAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
73
- }
74
- if (!codeVerifier) {
75
- throw new PayvoAuthError("codeVerifier is required for Salesforce");
76
- }
77
-
78
- const _scopes = options.disableDefaultScope
79
- ? []
80
- : ["openid", "email", "profile"];
81
- if (options.scope) _scopes.push(...options.scope);
82
- if (scopes) _scopes.push(...scopes);
83
-
84
- return createAuthorizationURL({
85
- id: "salesforce",
86
- options,
87
- authorizationEndpoint,
88
- scopes: _scopes,
89
- state,
90
- codeVerifier,
91
- redirectURI: options.redirectURI || redirectURI,
92
- });
93
- },
94
-
95
- validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
96
- return validateAuthorizationCode({
97
- code,
98
- codeVerifier,
99
- redirectURI: options.redirectURI || redirectURI,
100
- options,
101
- tokenEndpoint,
102
- });
103
- },
104
-
105
- refreshAccessToken: options.refreshAccessToken
106
- ? options.refreshAccessToken
107
- : async (refreshToken) => {
108
- return refreshAccessToken({
109
- refreshToken,
110
- options: {
111
- clientId: options.clientId,
112
- clientSecret: options.clientSecret,
113
- },
114
- tokenEndpoint,
115
- });
116
- },
117
-
118
- async getUserInfo(token) {
119
- if (options.getUserInfo) {
120
- return options.getUserInfo(token);
121
- }
122
-
123
- try {
124
- const { data: user } = await betterFetch<SalesforceProfile>(
125
- userInfoEndpoint,
126
- {
127
- headers: {
128
- Authorization: `Bearer ${token.accessToken}`,
129
- },
130
- }
131
- );
132
-
133
- if (!user) {
134
- logger.error("Failed to fetch user info from Salesforce");
135
- return null;
136
- }
137
-
138
- const userMap = await options.mapProfileToUser?.(user);
139
-
140
- return {
141
- user: {
142
- id: user.user_id,
143
- name: user.name,
144
- email: user.email,
145
- image: user.photos?.picture || user.photos?.thumbnail,
146
- emailVerified: user.email_verified ?? false,
147
- ...userMap,
148
- },
149
- data: user,
150
- };
151
- } catch (error) {
152
- logger.error("Failed to fetch user info from Salesforce:", error);
153
- return null;
154
- }
155
- },
156
-
157
- options,
158
- } satisfies OAuthProvider<SalesforceProfile>;
159
- };
@@ -1,111 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
- import { refreshAccessToken, validateAuthorizationCode } from "../oauth2";
4
-
5
- export interface SlackProfile extends Record<string, any> {
6
- ok: boolean;
7
- sub: string;
8
- "https://slack.com/user_id": string;
9
- "https://slack.com/team_id": string;
10
- email: string;
11
- email_verified: boolean;
12
- date_email_verified: number;
13
- name: string;
14
- picture: string;
15
- given_name: string;
16
- family_name: string;
17
- locale: string;
18
- "https://slack.com/team_name": string;
19
- "https://slack.com/team_domain": string;
20
- "https://slack.com/user_image_24": string;
21
- "https://slack.com/user_image_32": string;
22
- "https://slack.com/user_image_48": string;
23
- "https://slack.com/user_image_72": string;
24
- "https://slack.com/user_image_192": string;
25
- "https://slack.com/user_image_512": string;
26
- "https://slack.com/team_image_34": string;
27
- "https://slack.com/team_image_44": string;
28
- "https://slack.com/team_image_68": string;
29
- "https://slack.com/team_image_88": string;
30
- "https://slack.com/team_image_102": string;
31
- "https://slack.com/team_image_132": string;
32
- "https://slack.com/team_image_230": string;
33
- "https://slack.com/team_image_default": boolean;
34
- }
35
-
36
- export interface SlackOptions extends ProviderOptions<SlackProfile> {
37
- clientId: string;
38
- }
39
-
40
- export const slack = (options: SlackOptions) => {
41
- return {
42
- id: "slack",
43
- name: "Slack",
44
- createAuthorizationURL({ state, scopes, redirectURI }) {
45
- const _scopes = options.disableDefaultScope
46
- ? []
47
- : ["openid", "profile", "email"];
48
- if (scopes) _scopes.push(...scopes);
49
- if (options.scope) _scopes.push(...options.scope);
50
- const url = new URL("https://slack.com/openid/connect/authorize");
51
- url.searchParams.set("scope", _scopes.join(" "));
52
- url.searchParams.set("response_type", "code");
53
- url.searchParams.set("client_id", options.clientId);
54
- url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
55
- url.searchParams.set("state", state);
56
- return url;
57
- },
58
- validateAuthorizationCode: async ({ code, redirectURI }) => {
59
- return validateAuthorizationCode({
60
- code,
61
- redirectURI,
62
- options,
63
- tokenEndpoint: "https://slack.com/api/openid.connect.token",
64
- });
65
- },
66
- refreshAccessToken: options.refreshAccessToken
67
- ? options.refreshAccessToken
68
- : async (refreshToken) => {
69
- return refreshAccessToken({
70
- refreshToken,
71
- options: {
72
- clientId: options.clientId,
73
- clientKey: options.clientKey,
74
- clientSecret: options.clientSecret,
75
- },
76
- tokenEndpoint: "https://slack.com/api/openid.connect.token",
77
- });
78
- },
79
- async getUserInfo(token) {
80
- if (options.getUserInfo) {
81
- return options.getUserInfo(token);
82
- }
83
- const { data: profile, error } = await betterFetch<SlackProfile>(
84
- "https://slack.com/api/openid.connect.userInfo",
85
- {
86
- headers: {
87
- authorization: `Bearer ${token.accessToken}`,
88
- },
89
- },
90
- );
91
-
92
- if (error) {
93
- return null;
94
- }
95
-
96
- const userMap = await options.mapProfileToUser?.(profile);
97
- return {
98
- user: {
99
- id: profile["https://slack.com/user_id"],
100
- name: profile.name || "",
101
- email: profile.email,
102
- emailVerified: profile.email_verified,
103
- image: profile.picture || profile["https://slack.com/user_image_512"],
104
- ...userMap,
105
- },
106
- data: profile,
107
- };
108
- },
109
- options,
110
- } satisfies OAuthProvider<SlackProfile>;
111
- };
@@ -1,93 +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 SpotifyProfile {
10
- id: string;
11
- display_name: string;
12
- email: string;
13
- images: {
14
- url: string;
15
- }[];
16
- }
17
-
18
- export interface SpotifyOptions extends ProviderOptions<SpotifyProfile> {
19
- clientId: string;
20
- }
21
-
22
- export const spotify = (options: SpotifyOptions) => {
23
- return {
24
- id: "spotify",
25
- name: "Spotify",
26
- createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
27
- const _scopes = options.disableDefaultScope ? [] : ["user-read-email"];
28
- if (options.scope) _scopes.push(...options.scope);
29
- if (scopes) _scopes.push(...scopes);
30
- return createAuthorizationURL({
31
- id: "spotify",
32
- options,
33
- authorizationEndpoint: "https://accounts.spotify.com/authorize",
34
- scopes: _scopes,
35
- state,
36
- codeVerifier,
37
- redirectURI,
38
- });
39
- },
40
- validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
41
- return validateAuthorizationCode({
42
- code,
43
- codeVerifier,
44
- redirectURI,
45
- options,
46
- tokenEndpoint: "https://accounts.spotify.com/api/token",
47
- });
48
- },
49
- refreshAccessToken: options.refreshAccessToken
50
- ? options.refreshAccessToken
51
- : async (refreshToken) => {
52
- return refreshAccessToken({
53
- refreshToken,
54
- options: {
55
- clientId: options.clientId,
56
- clientKey: options.clientKey,
57
- clientSecret: options.clientSecret,
58
- },
59
- tokenEndpoint: "https://accounts.spotify.com/api/token",
60
- });
61
- },
62
- async getUserInfo(token) {
63
- if (options.getUserInfo) {
64
- return options.getUserInfo(token);
65
- }
66
- const { data: profile, error } = await betterFetch<SpotifyProfile>(
67
- "https://api.spotify.com/v1/me",
68
- {
69
- method: "GET",
70
- headers: {
71
- Authorization: `Bearer ${token.accessToken}`,
72
- },
73
- },
74
- );
75
- if (error) {
76
- return null;
77
- }
78
- const userMap = await options.mapProfileToUser?.(profile);
79
- return {
80
- user: {
81
- id: profile.id,
82
- name: profile.display_name,
83
- email: profile.email,
84
- image: profile.images[0]?.url,
85
- emailVerified: false,
86
- ...userMap,
87
- },
88
- data: profile,
89
- };
90
- },
91
- options,
92
- } satisfies OAuthProvider<SpotifyProfile>;
93
- };