@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,171 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import { decodeJwt } from "jose";
3
- import { logger } from "../env";
4
- import { PayvoAuthError } from "../error";
5
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
6
- import {
7
- createAuthorizationURL,
8
- refreshAccessToken,
9
- validateAuthorizationCode,
10
- } from "../oauth2";
11
-
12
- export interface GoogleProfile {
13
- aud: string;
14
- azp: string;
15
- email: string;
16
- email_verified: boolean;
17
- exp: number;
18
- /**
19
- * The family name of the user, or last name in most
20
- * Western languages.
21
- */
22
- family_name: string;
23
- /**
24
- * The given name of the user, or first name in most
25
- * Western languages.
26
- */
27
- given_name: string;
28
- hd?: string | undefined;
29
- iat: number;
30
- iss: string;
31
- jti?: string | undefined;
32
- locale?: string | undefined;
33
- name: string;
34
- nbf?: number | undefined;
35
- picture: string;
36
- sub: string;
37
- }
38
-
39
- export interface GoogleOptions extends ProviderOptions<GoogleProfile> {
40
- clientId: string;
41
- /**
42
- * The access type to use for the authorization code request
43
- */
44
- accessType?: ("offline" | "online") | undefined;
45
- /**
46
- * The display mode to use for the authorization code request
47
- */
48
- display?: ("page" | "popup" | "touch" | "wap") | undefined;
49
- /**
50
- * The hosted domain of the user
51
- */
52
- hd?: string | undefined;
53
- }
54
-
55
- export const google = (options: GoogleOptions) => {
56
- return {
57
- id: "google",
58
- name: "Google",
59
- async createAuthorizationURL({
60
- state,
61
- scopes,
62
- codeVerifier,
63
- redirectURI,
64
- loginHint,
65
- display,
66
- }) {
67
- if (!options.clientId || !options.clientSecret) {
68
- logger.error(
69
- "Client Id and Client Secret is required for Google. Make sure to provide them in the options."
70
- );
71
- throw new PayvoAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
72
- }
73
- if (!codeVerifier) {
74
- throw new PayvoAuthError("codeVerifier is required for Google");
75
- }
76
- const _scopes = options.disableDefaultScope
77
- ? []
78
- : ["email", "profile", "openid"];
79
- if (options.scope) _scopes.push(...options.scope);
80
- if (scopes) _scopes.push(...scopes);
81
- const url = await createAuthorizationURL({
82
- id: "google",
83
- options,
84
- authorizationEndpoint: "https://accounts.google.com/o/oauth2/auth",
85
- scopes: _scopes,
86
- state,
87
- codeVerifier,
88
- redirectURI,
89
- prompt: options.prompt,
90
- accessType: options.accessType,
91
- display: display || options.display,
92
- loginHint,
93
- hd: options.hd,
94
- additionalParams: {
95
- include_granted_scopes: "true",
96
- },
97
- });
98
- return url;
99
- },
100
- validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
101
- return validateAuthorizationCode({
102
- code,
103
- codeVerifier,
104
- redirectURI,
105
- options,
106
- tokenEndpoint: "https://oauth2.googleapis.com/token",
107
- });
108
- },
109
- refreshAccessToken: options.refreshAccessToken
110
- ? options.refreshAccessToken
111
- : async (refreshToken) => {
112
- return refreshAccessToken({
113
- refreshToken,
114
- options: {
115
- clientId: options.clientId,
116
- clientKey: options.clientKey,
117
- clientSecret: options.clientSecret,
118
- },
119
- tokenEndpoint: "https://www.googleapis.com/oauth2/v4/token",
120
- });
121
- },
122
- async verifyIdToken(token, nonce) {
123
- if (options.disableIdTokenSignIn) {
124
- return false;
125
- }
126
- if (options.verifyIdToken) {
127
- return options.verifyIdToken(token, nonce);
128
- }
129
- const googlePublicKeyUrl = `https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=${token}`;
130
- const { data: tokenInfo } = await betterFetch<{
131
- aud: string;
132
- iss: string;
133
- email: string;
134
- email_verified: boolean;
135
- name: string;
136
- picture: string;
137
- sub: string;
138
- }>(googlePublicKeyUrl);
139
- if (!tokenInfo) {
140
- return false;
141
- }
142
- const isValid =
143
- tokenInfo.aud === options.clientId &&
144
- (tokenInfo.iss === "https://accounts.google.com" ||
145
- tokenInfo.iss === "accounts.google.com");
146
- return isValid;
147
- },
148
- async getUserInfo(token) {
149
- if (options.getUserInfo) {
150
- return options.getUserInfo(token);
151
- }
152
- if (!token.idToken) {
153
- return null;
154
- }
155
- const user = decodeJwt(token.idToken) as GoogleProfile;
156
- const userMap = await options.mapProfileToUser?.(user);
157
- return {
158
- user: {
159
- id: user.sub,
160
- name: user.name,
161
- email: user.email,
162
- image: user.picture,
163
- emailVerified: user.email_verified,
164
- ...userMap,
165
- },
166
- data: user,
167
- };
168
- },
169
- options,
170
- } satisfies OAuthProvider<GoogleProfile>;
171
- };
@@ -1,118 +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 HuggingFaceProfile {
10
- sub: string;
11
- name: string;
12
- preferred_username: string;
13
- profile: string;
14
- picture: string;
15
- website?: string | undefined;
16
- email?: string | undefined;
17
- email_verified?: boolean | undefined;
18
- isPro: boolean;
19
- canPay?: boolean | undefined;
20
- orgs?:
21
- | {
22
- sub: string;
23
- name: string;
24
- picture: string;
25
- preferred_username: string;
26
- isEnterprise: boolean | "plus";
27
- canPay?: boolean;
28
- roleInOrg?: "admin" | "write" | "contributor" | "read";
29
- pendingSSO?: boolean;
30
- missingMFA?: boolean;
31
- resourceGroups?: {
32
- sub: string;
33
- name: string;
34
- role: "admin" | "write" | "contributor" | "read";
35
- }[];
36
- }
37
- | undefined;
38
- }
39
-
40
- export interface HuggingFaceOptions
41
- extends ProviderOptions<HuggingFaceProfile> {
42
- clientId: string;
43
- }
44
-
45
- export const huggingface = (options: HuggingFaceOptions) => {
46
- return {
47
- id: "huggingface",
48
- name: "Hugging Face",
49
- createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
50
- const _scopes = options.disableDefaultScope
51
- ? []
52
- : ["openid", "profile", "email"];
53
- if (options.scope) _scopes.push(...options.scope);
54
- if (scopes) _scopes.push(...scopes);
55
- return createAuthorizationURL({
56
- id: "huggingface",
57
- options,
58
- authorizationEndpoint: "https://huggingface.co/oauth/authorize",
59
- scopes: _scopes,
60
- state,
61
- codeVerifier,
62
- redirectURI,
63
- });
64
- },
65
- validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
66
- return validateAuthorizationCode({
67
- code,
68
- codeVerifier,
69
- redirectURI,
70
- options,
71
- tokenEndpoint: "https://huggingface.co/oauth/token",
72
- });
73
- },
74
- refreshAccessToken: options.refreshAccessToken
75
- ? options.refreshAccessToken
76
- : async (refreshToken) => {
77
- return refreshAccessToken({
78
- refreshToken,
79
- options: {
80
- clientId: options.clientId,
81
- clientKey: options.clientKey,
82
- clientSecret: options.clientSecret,
83
- },
84
- tokenEndpoint: "https://huggingface.co/oauth/token",
85
- });
86
- },
87
- async getUserInfo(token) {
88
- if (options.getUserInfo) {
89
- return options.getUserInfo(token);
90
- }
91
- const { data: profile, error } = await betterFetch<HuggingFaceProfile>(
92
- "https://huggingface.co/oauth/userinfo",
93
- {
94
- method: "GET",
95
- headers: {
96
- Authorization: `Bearer ${token.accessToken}`,
97
- },
98
- },
99
- );
100
- if (error) {
101
- return null;
102
- }
103
- const userMap = await options.mapProfileToUser?.(profile);
104
- return {
105
- user: {
106
- id: profile.sub,
107
- name: profile.name || profile.preferred_username,
108
- email: profile.email,
109
- image: profile.picture,
110
- emailVerified: profile.email_verified ?? false,
111
- ...userMap,
112
- },
113
- data: profile,
114
- };
115
- },
116
- options,
117
- } satisfies OAuthProvider<HuggingFaceProfile>;
118
- };
@@ -1,124 +0,0 @@
1
- import * as z from "zod";
2
- import { apple } from "./apple";
3
- import { atlassian } from "./atlassian";
4
- import { cognito } from "./cognito";
5
- import { discord } from "./discord";
6
- import { dropbox } from "./dropbox";
7
- import { facebook } from "./facebook";
8
- import { figma } from "./figma";
9
- import { github } from "./github";
10
- import { gitlab } from "./gitlab";
11
- import { google } from "./google";
12
- import { huggingface } from "./huggingface";
13
- import { kakao } from "./kakao";
14
- import { kick } from "./kick";
15
- import { line } from "./line";
16
- import { linear } from "./linear";
17
- import { linkedin } from "./linkedin";
18
- import { microsoft } from "./microsoft-entra-id";
19
- import { naver } from "./naver";
20
- import { notion } from "./notion";
21
- import { paybin } from "./paybin";
22
- import { paypal } from "./paypal";
23
- import { polar } from "./polar";
24
- import { reddit } from "./reddit";
25
- import { roblox } from "./roblox";
26
- import { salesforce } from "./salesforce";
27
- import { slack } from "./slack";
28
- import { spotify } from "./spotify";
29
- import { tiktok } from "./tiktok";
30
- import { twitch } from "./twitch";
31
- import { twitter } from "./twitter";
32
- import { vk } from "./vk";
33
- import { zoom } from "./zoom";
34
-
35
- export const socialProviders = {
36
- apple,
37
- atlassian,
38
- cognito,
39
- discord,
40
- facebook,
41
- figma,
42
- github,
43
- microsoft,
44
- google,
45
- huggingface,
46
- slack,
47
- spotify,
48
- twitch,
49
- twitter,
50
- dropbox,
51
- kick,
52
- linear,
53
- linkedin,
54
- gitlab,
55
- tiktok,
56
- reddit,
57
- roblox,
58
- salesforce,
59
- vk,
60
- zoom,
61
- notion,
62
- kakao,
63
- naver,
64
- line,
65
- paybin,
66
- paypal,
67
- polar,
68
- };
69
-
70
- export const socialProviderList = Object.keys(socialProviders) as [
71
- "github",
72
- ...(keyof typeof socialProviders)[],
73
- ];
74
-
75
- export const SocialProviderListEnum = z
76
- .enum(socialProviderList)
77
- .or(z.string()) as z.ZodType<SocialProviderList[number] | (string & {})>;
78
-
79
- export type SocialProvider = z.infer<typeof SocialProviderListEnum>;
80
-
81
- export type SocialProviders = {
82
- [K in SocialProviderList[number]]?: Parameters<
83
- (typeof socialProviders)[K]
84
- >[0] & {
85
- enabled?: boolean | undefined;
86
- };
87
- };
88
-
89
- export * from "./apple";
90
- export * from "./atlassian";
91
- export * from "./cognito";
92
- export * from "./discord";
93
- export * from "./dropbox";
94
- export * from "./facebook";
95
- export * from "./figma";
96
- export * from "./github";
97
- export * from "./gitlab";
98
- export * from "./google";
99
- export * from "./huggingface";
100
- export * from "./kakao";
101
- export * from "./kick";
102
- export * from "./kick";
103
- export * from "./line";
104
- export * from "./linear";
105
- export * from "./linkedin";
106
- export * from "./linkedin";
107
- export * from "./microsoft-entra-id";
108
- export * from "./naver";
109
- export * from "./notion";
110
- export * from "./paybin";
111
- export * from "./paypal";
112
- export * from "./polar";
113
- export * from "./reddit";
114
- export * from "./roblox";
115
- export * from "./salesforce";
116
- export * from "./slack";
117
- export * from "./spotify";
118
- export * from "./tiktok";
119
- export * from "./twitch";
120
- export * from "./twitter";
121
- export * from "./vk";
122
- export * from "./zoom";
123
-
124
- export type SocialProviderList = typeof socialProviderList;
@@ -1,178 +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
- interface Partner {
10
- /** Partner-specific ID (consent required: kakaotalk_message) */
11
- uuid?: string | undefined;
12
- }
13
-
14
- interface Profile {
15
- /** Nickname (consent required: profile/nickname) */
16
- nickname?: string | undefined;
17
- /** Thumbnail image URL (consent required: profile/profile image) */
18
- thumbnail_image_url?: string | undefined;
19
- /** Profile image URL (consent required: profile/profile image) */
20
- profile_image_url?: string | undefined;
21
- /** Whether the profile image is the default */
22
- is_default_image?: boolean | undefined;
23
- /** Whether the nickname is the default */
24
- is_default_nickname?: boolean | undefined;
25
- }
26
-
27
- interface KakaoAccount {
28
- /** Consent required: profile info (nickname/profile image) */
29
- profile_needs_agreement?: boolean | undefined;
30
- /** Consent required: nickname */
31
- profile_nickname_needs_agreement?: boolean | undefined;
32
- /** Consent required: profile image */
33
- profile_image_needs_agreement?: boolean | undefined;
34
- /** Profile info */
35
- profile?: Profile | undefined;
36
- /** Consent required: name */
37
- name_needs_agreement?: boolean | undefined;
38
- /** Name */
39
- name?: string | undefined;
40
- /** Consent required: email */
41
- email_needs_agreement?: boolean | undefined;
42
- /** Email valid */
43
- is_email_valid?: boolean | undefined;
44
- /** Email verified */
45
- is_email_verified?: boolean | undefined;
46
- /** Email */
47
- email?: string | undefined;
48
- /** Consent required: age range */
49
- age_range_needs_agreement?: boolean | undefined;
50
- /** Age range */
51
- age_range?: string | undefined;
52
- /** Consent required: birth year */
53
- birthyear_needs_agreement?: boolean | undefined;
54
- /** Birth year (YYYY) */
55
- birthyear?: string | undefined;
56
- /** Consent required: birthday */
57
- birthday_needs_agreement?: boolean | undefined;
58
- /** Birthday (MMDD) */
59
- birthday?: string | undefined;
60
- /** Birthday type (SOLAR/LUNAR) */
61
- birthday_type?: string | undefined;
62
- /** Whether birthday is in a leap month */
63
- is_leap_month?: boolean | undefined;
64
- /** Consent required: gender */
65
- gender_needs_agreement?: boolean | undefined;
66
- /** Gender (male/female) */
67
- gender?: string | undefined;
68
- /** Consent required: phone number */
69
- phone_number_needs_agreement?: boolean | undefined;
70
- /** Phone number */
71
- phone_number?: string | undefined;
72
- /** Consent required: CI */
73
- ci_needs_agreement?: boolean | undefined;
74
- /** CI (unique identifier) */
75
- ci?: string | undefined;
76
- /** CI authentication time (UTC) */
77
- ci_authenticated_at?: string | undefined;
78
- }
79
-
80
- export interface KakaoProfile {
81
- /** Kakao user ID */
82
- id: number;
83
- /**
84
- * Whether the user has signed up (only present if auto-connection is disabled)
85
- * false: preregistered, true: registered
86
- */
87
- has_signed_up?: boolean | undefined;
88
- /** UTC datetime when the user connected the service */
89
- connected_at?: string | undefined;
90
- /** UTC datetime when the user signed up via Kakao Sync */
91
- synched_at?: string | undefined;
92
- /** Custom user properties */
93
- properties?: Record<string, any> | undefined;
94
- /** Kakao account info */
95
- kakao_account: KakaoAccount;
96
- /** Partner info */
97
- for_partner?: Partner | undefined;
98
- }
99
-
100
- export interface KakaoOptions extends ProviderOptions<KakaoProfile> {
101
- clientId: string;
102
- }
103
-
104
- export const kakao = (options: KakaoOptions) => {
105
- return {
106
- id: "kakao",
107
- name: "Kakao",
108
- createAuthorizationURL({ state, scopes, redirectURI }) {
109
- const _scopes = options.disableDefaultScope
110
- ? []
111
- : ["account_email", "profile_image", "profile_nickname"];
112
- if (options.scope) _scopes.push(...options.scope);
113
- if (scopes) _scopes.push(...scopes);
114
- return createAuthorizationURL({
115
- id: "kakao",
116
- options,
117
- authorizationEndpoint: "https://kauth.kakao.com/oauth/authorize",
118
- scopes: _scopes,
119
- state,
120
- redirectURI,
121
- });
122
- },
123
- validateAuthorizationCode: async ({ code, redirectURI }) => {
124
- return validateAuthorizationCode({
125
- code,
126
- redirectURI,
127
- options,
128
- tokenEndpoint: "https://kauth.kakao.com/oauth/token",
129
- });
130
- },
131
- refreshAccessToken: options.refreshAccessToken
132
- ? options.refreshAccessToken
133
- : async (refreshToken) => {
134
- return refreshAccessToken({
135
- refreshToken,
136
- options: {
137
- clientId: options.clientId,
138
- clientKey: options.clientKey,
139
- clientSecret: options.clientSecret,
140
- },
141
- tokenEndpoint: "https://kauth.kakao.com/oauth/token",
142
- });
143
- },
144
- async getUserInfo(token) {
145
- if (options.getUserInfo) {
146
- return options.getUserInfo(token);
147
- }
148
- const { data: profile, error } = await betterFetch<KakaoProfile>(
149
- "https://kapi.kakao.com/v2/user/me",
150
- {
151
- headers: {
152
- Authorization: `Bearer ${token.accessToken}`,
153
- },
154
- },
155
- );
156
- if (error || !profile) {
157
- return null;
158
- }
159
- const userMap = await options.mapProfileToUser?.(profile);
160
- const account = profile.kakao_account || {};
161
- const kakaoProfile = account.profile || {};
162
- const user = {
163
- id: String(profile.id),
164
- name: kakaoProfile.nickname || account.name || undefined,
165
- email: account.email,
166
- image:
167
- kakaoProfile.profile_image_url || kakaoProfile.thumbnail_image_url,
168
- emailVerified: !!account.is_email_valid && !!account.is_email_verified,
169
- ...userMap,
170
- };
171
- return {
172
- user,
173
- data: profile,
174
- };
175
- },
176
- options,
177
- } satisfies OAuthProvider<KakaoProfile>;
178
- };
@@ -1,92 +0,0 @@
1
- import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
- import { createAuthorizationURL, validateAuthorizationCode } from "../oauth2";
4
-
5
- export interface KickProfile {
6
- /**
7
- * The user id of the user
8
- */
9
- user_id: string;
10
- /**
11
- * The name of the user
12
- */
13
- name: string;
14
- /**
15
- * The email of the user
16
- */
17
- email: string;
18
- /**
19
- * The picture of the user
20
- */
21
- profile_picture: string;
22
- }
23
-
24
- export interface KickOptions extends ProviderOptions<KickProfile> {
25
- clientId: string;
26
- }
27
-
28
- export const kick = (options: KickOptions) => {
29
- return {
30
- id: "kick",
31
- name: "Kick",
32
- createAuthorizationURL({ state, scopes, redirectURI, codeVerifier }) {
33
- const _scopes = options.disableDefaultScope ? [] : ["user:read"];
34
- if (options.scope) _scopes.push(...options.scope);
35
- if (scopes) _scopes.push(...scopes);
36
-
37
- return createAuthorizationURL({
38
- id: "kick",
39
- redirectURI,
40
- options,
41
- authorizationEndpoint: "https://id.kick.com/oauth/authorize",
42
- scopes: _scopes,
43
- codeVerifier,
44
- state,
45
- });
46
- },
47
- async validateAuthorizationCode({ code, redirectURI, codeVerifier }) {
48
- return validateAuthorizationCode({
49
- code,
50
- redirectURI,
51
- options,
52
- tokenEndpoint: "https://id.kick.com/oauth/token",
53
- codeVerifier,
54
- });
55
- },
56
- async getUserInfo(token) {
57
- if (options.getUserInfo) {
58
- return options.getUserInfo(token);
59
- }
60
-
61
- const { data, error } = await betterFetch<{
62
- data: KickProfile[];
63
- }>("https://api.kick.com/public/v1/users", {
64
- method: "GET",
65
- headers: {
66
- Authorization: `Bearer ${token.accessToken}`,
67
- },
68
- });
69
-
70
- if (error) {
71
- return null;
72
- }
73
-
74
- const profile = data.data[0]!;
75
-
76
- const userMap = await options.mapProfileToUser?.(profile);
77
-
78
- return {
79
- user: {
80
- id: profile.user_id,
81
- name: profile.name,
82
- email: profile.email,
83
- image: profile.profile_picture,
84
- emailVerified: true,
85
- ...userMap,
86
- },
87
- data: profile,
88
- };
89
- },
90
- options,
91
- } satisfies OAuthProvider<KickProfile>;
92
- };