@better-auth/core 1.5.0-beta.3 → 1.5.0-beta.5

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 (175) hide show
  1. package/.turbo/turbo-build.log +170 -37
  2. package/dist/api/index.d.mts +188 -1
  3. package/dist/api/index.mjs +2 -1
  4. package/dist/context/endpoint-context.d.mts +19 -0
  5. package/dist/context/endpoint-context.mjs +27 -0
  6. package/dist/context/index.d.mts +3 -52
  7. package/dist/context/index.mjs +22 -1
  8. package/dist/context/request-state.d.mts +27 -0
  9. package/dist/context/request-state.mjs +45 -0
  10. package/dist/context/transaction.d.mts +16 -0
  11. package/dist/context/transaction.mjs +48 -0
  12. package/dist/db/adapter/factory.d.mts +27 -0
  13. package/dist/db/adapter/factory.mjs +738 -0
  14. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  15. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  16. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  17. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  18. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  19. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  20. package/dist/db/adapter/get-field-name.d.mts +18 -0
  21. package/dist/db/adapter/get-field-name.mjs +33 -0
  22. package/dist/db/adapter/get-id-field.d.mts +39 -0
  23. package/dist/db/adapter/get-id-field.mjs +67 -0
  24. package/dist/db/adapter/get-model-name.d.mts +12 -0
  25. package/dist/db/adapter/get-model-name.mjs +23 -0
  26. package/dist/db/adapter/index.d.mts +513 -1
  27. package/dist/db/adapter/index.mjs +8 -970
  28. package/dist/db/adapter/types.d.mts +139 -0
  29. package/dist/db/adapter/utils.d.mts +7 -0
  30. package/dist/db/adapter/utils.mjs +38 -0
  31. package/dist/db/get-tables.d.mts +8 -0
  32. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  33. package/dist/db/index.d.mts +10 -2
  34. package/dist/db/index.mjs +7 -60
  35. package/dist/db/plugin.d.mts +12 -0
  36. package/dist/db/schema/account.d.mts +26 -0
  37. package/dist/db/schema/account.mjs +19 -0
  38. package/dist/db/schema/rate-limit.d.mts +14 -0
  39. package/dist/db/schema/rate-limit.mjs +11 -0
  40. package/dist/db/schema/session.d.mts +21 -0
  41. package/dist/db/schema/session.mjs +14 -0
  42. package/dist/db/schema/shared.d.mts +10 -0
  43. package/dist/db/schema/shared.mjs +11 -0
  44. package/dist/db/schema/user.d.mts +20 -0
  45. package/dist/db/schema/user.mjs +13 -0
  46. package/dist/db/schema/verification.d.mts +19 -0
  47. package/dist/db/schema/verification.mjs +12 -0
  48. package/dist/db/type.d.mts +143 -0
  49. package/dist/env/color-depth.d.mts +4 -0
  50. package/dist/env/color-depth.mjs +88 -0
  51. package/dist/env/env-impl.d.mts +32 -0
  52. package/dist/env/env-impl.mjs +82 -0
  53. package/dist/env/index.d.mts +4 -2
  54. package/dist/env/index.mjs +3 -1
  55. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  56. package/dist/env/logger.mjs +81 -0
  57. package/dist/error/codes.d.mts +186 -0
  58. package/dist/{error-GNtLPYaS.mjs → error/codes.mjs} +2 -29
  59. package/dist/error/index.d.mts +1 -185
  60. package/dist/error/index.mjs +28 -3
  61. package/dist/index.d.mts +7 -1
  62. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  63. package/dist/oauth2/client-credentials-token.mjs +54 -0
  64. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  65. package/dist/oauth2/create-authorization-url.mjs +42 -0
  66. package/dist/oauth2/index.d.mts +8 -2
  67. package/dist/oauth2/index.mjs +6 -2
  68. package/dist/oauth2/oauth-provider.d.mts +194 -0
  69. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  70. package/dist/oauth2/refresh-access-token.mjs +58 -0
  71. package/dist/oauth2/utils.d.mts +7 -0
  72. package/dist/oauth2/utils.mjs +27 -0
  73. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  74. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  75. package/dist/oauth2/verify.d.mts +49 -0
  76. package/dist/oauth2/verify.mjs +95 -0
  77. package/dist/social-providers/apple.d.mts +119 -0
  78. package/dist/social-providers/apple.mjs +102 -0
  79. package/dist/social-providers/atlassian.d.mts +72 -0
  80. package/dist/social-providers/atlassian.mjs +83 -0
  81. package/dist/social-providers/cognito.d.mts +87 -0
  82. package/dist/social-providers/cognito.mjs +165 -0
  83. package/dist/social-providers/discord.d.mts +126 -0
  84. package/dist/social-providers/discord.mjs +64 -0
  85. package/dist/social-providers/dropbox.d.mts +71 -0
  86. package/dist/social-providers/dropbox.mjs +75 -0
  87. package/dist/social-providers/facebook.d.mts +81 -0
  88. package/dist/social-providers/facebook.mjs +120 -0
  89. package/dist/social-providers/figma.d.mts +63 -0
  90. package/dist/social-providers/figma.mjs +84 -0
  91. package/dist/social-providers/github.d.mts +104 -0
  92. package/dist/social-providers/github.mjs +80 -0
  93. package/dist/social-providers/gitlab.d.mts +125 -0
  94. package/dist/social-providers/gitlab.mjs +82 -0
  95. package/dist/social-providers/google.d.mts +99 -0
  96. package/dist/social-providers/google.mjs +108 -0
  97. package/dist/social-providers/huggingface.d.mts +85 -0
  98. package/dist/social-providers/huggingface.mjs +75 -0
  99. package/dist/social-providers/index.d.mts +1723 -1
  100. package/dist/social-providers/index.mjs +33 -2569
  101. package/dist/social-providers/kakao.d.mts +163 -0
  102. package/dist/social-providers/kakao.mjs +72 -0
  103. package/dist/social-providers/kick.d.mts +75 -0
  104. package/dist/social-providers/kick.mjs +71 -0
  105. package/dist/social-providers/line.d.mts +107 -0
  106. package/dist/social-providers/line.mjs +113 -0
  107. package/dist/social-providers/linear.d.mts +70 -0
  108. package/dist/social-providers/linear.mjs +88 -0
  109. package/dist/social-providers/linkedin.d.mts +69 -0
  110. package/dist/social-providers/linkedin.mjs +76 -0
  111. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  112. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  113. package/dist/social-providers/naver.d.mts +104 -0
  114. package/dist/social-providers/naver.mjs +67 -0
  115. package/dist/social-providers/notion.d.mts +66 -0
  116. package/dist/social-providers/notion.mjs +75 -0
  117. package/dist/social-providers/paybin.d.mts +73 -0
  118. package/dist/social-providers/paybin.mjs +85 -0
  119. package/dist/social-providers/paypal.d.mts +131 -0
  120. package/dist/social-providers/paypal.mjs +144 -0
  121. package/dist/social-providers/polar.d.mts +76 -0
  122. package/dist/social-providers/polar.mjs +73 -0
  123. package/dist/social-providers/reddit.d.mts +64 -0
  124. package/dist/social-providers/reddit.mjs +83 -0
  125. package/dist/social-providers/roblox.d.mts +72 -0
  126. package/dist/social-providers/roblox.mjs +59 -0
  127. package/dist/social-providers/salesforce.d.mts +81 -0
  128. package/dist/social-providers/salesforce.mjs +91 -0
  129. package/dist/social-providers/slack.d.mts +85 -0
  130. package/dist/social-providers/slack.mjs +68 -0
  131. package/dist/social-providers/spotify.d.mts +65 -0
  132. package/dist/social-providers/spotify.mjs +71 -0
  133. package/dist/social-providers/tiktok.d.mts +171 -0
  134. package/dist/social-providers/tiktok.mjs +62 -0
  135. package/dist/social-providers/twitch.d.mts +81 -0
  136. package/dist/social-providers/twitch.mjs +78 -0
  137. package/dist/social-providers/twitter.d.mts +140 -0
  138. package/dist/social-providers/twitter.mjs +87 -0
  139. package/dist/social-providers/vercel.d.mts +64 -0
  140. package/dist/social-providers/vercel.mjs +61 -0
  141. package/dist/social-providers/vk.d.mts +72 -0
  142. package/dist/social-providers/vk.mjs +83 -0
  143. package/dist/social-providers/zoom.d.mts +173 -0
  144. package/dist/social-providers/zoom.mjs +72 -0
  145. package/dist/types/context.d.mts +246 -0
  146. package/dist/types/cookie.d.mts +23 -0
  147. package/dist/types/helper.d.mts +8 -0
  148. package/dist/types/index.d.mts +8 -0
  149. package/dist/types/init-options.d.mts +1266 -0
  150. package/dist/types/plugin-client.d.mts +110 -0
  151. package/dist/types/plugin.d.mts +124 -0
  152. package/dist/utils/deprecate.d.mts +10 -0
  153. package/dist/utils/deprecate.mjs +17 -0
  154. package/dist/utils/{index.d.mts → error-codes.d.mts} +1 -19
  155. package/dist/utils/error-codes.mjs +11 -0
  156. package/dist/utils/id.d.mts +4 -0
  157. package/dist/utils/id.mjs +9 -0
  158. package/dist/utils/json.d.mts +4 -0
  159. package/dist/utils/json.mjs +25 -0
  160. package/dist/utils/string.d.mts +4 -0
  161. package/dist/utils/string.mjs +7 -0
  162. package/package.json +10 -7
  163. package/src/db/adapter/get-id-field.ts +1 -1
  164. package/src/error/codes.ts +1 -1
  165. package/src/oauth2/create-authorization-url.ts +1 -1
  166. package/src/oauth2/oauth-provider.ts +6 -0
  167. package/src/types/init-options.ts +19 -4
  168. package/tsdown.config.ts +3 -1
  169. package/dist/context-BBNwughv.mjs +0 -133
  170. package/dist/env-DbssmzoK.mjs +0 -245
  171. package/dist/index-CGr4Qrv8.d.mts +0 -8039
  172. package/dist/oauth2-BjWM15hm.mjs +0 -326
  173. package/dist/utils/index.mjs +0 -4
  174. package/dist/utils-puAL36Bz.mjs +0 -63
  175. package/src/utils/index.ts +0 -5
@@ -1,190 +1,6 @@
1
+ import { APIErrorCode, BASE_ERROR_CODES } from "./codes.mjs";
1
2
  import { APIError as APIError$1 } from "better-call/error";
2
3
 
3
- //#region src/error/codes.d.ts
4
- declare const BASE_ERROR_CODES: {
5
- readonly USER_NOT_FOUND: {
6
- code: "USER_NOT_FOUND";
7
- message: "User not found";
8
- };
9
- readonly FAILED_TO_CREATE_USER: {
10
- code: "FAILED_TO_CREATE_USER";
11
- message: "Failed to create user";
12
- };
13
- readonly FAILED_TO_CREATE_SESSION: {
14
- code: "FAILED_TO_CREATE_SESSION";
15
- message: "Failed to create session";
16
- };
17
- readonly FAILED_TO_UPDATE_USER: {
18
- code: "FAILED_TO_UPDATE_USER";
19
- message: "Failed to update user";
20
- };
21
- readonly FAILED_TO_GET_SESSION: {
22
- code: "FAILED_TO_GET_SESSION";
23
- message: "Failed to get session";
24
- };
25
- readonly INVALID_PASSWORD: {
26
- code: "INVALID_PASSWORD";
27
- message: "Invalid password";
28
- };
29
- readonly INVALID_EMAIL: {
30
- code: "INVALID_EMAIL";
31
- message: "Invalid email";
32
- };
33
- readonly INVALID_EMAIL_OR_PASSWORD: {
34
- code: "INVALID_EMAIL_OR_PASSWORD";
35
- message: "Invalid email or password";
36
- };
37
- readonly INVALID_USER: {
38
- code: "INVALID_USER";
39
- message: "Invalid user";
40
- };
41
- readonly SOCIAL_ACCOUNT_ALREADY_LINKED: {
42
- code: "SOCIAL_ACCOUNT_ALREADY_LINKED";
43
- message: "Social account already linked";
44
- };
45
- readonly PROVIDER_NOT_FOUND: {
46
- code: "PROVIDER_NOT_FOUND";
47
- message: "Provider not found";
48
- };
49
- readonly INVALID_TOKEN: {
50
- code: "INVALID_TOKEN";
51
- message: "Invalid token";
52
- };
53
- readonly TOKEN_EXPIRED: {
54
- code: "TOKEN_EXPIRED";
55
- message: "Token expired";
56
- };
57
- readonly ID_TOKEN_NOT_SUPPORTED: {
58
- code: "ID_TOKEN_NOT_SUPPORTED";
59
- message: "id_token not supported";
60
- };
61
- readonly FAILED_TO_GET_USER_INFO: {
62
- code: "FAILED_TO_GET_USER_INFO";
63
- message: "Failed to get user info";
64
- };
65
- readonly USER_EMAIL_NOT_FOUND: {
66
- code: "USER_EMAIL_NOT_FOUND";
67
- message: "User email not found";
68
- };
69
- readonly EMAIL_NOT_VERIFIED: {
70
- code: "EMAIL_NOT_VERIFIED";
71
- message: "Email not verified";
72
- };
73
- readonly PASSWORD_TOO_SHORT: {
74
- code: "PASSWORD_TOO_SHORT";
75
- message: "Password too short";
76
- };
77
- readonly PASSWORD_TOO_LONG: {
78
- code: "PASSWORD_TOO_LONG";
79
- message: "Password too long";
80
- };
81
- readonly USER_ALREADY_EXISTS: {
82
- code: "USER_ALREADY_EXISTS";
83
- message: "User already exists.";
84
- };
85
- readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: {
86
- code: "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL";
87
- message: "User already exists. Use another email.";
88
- };
89
- readonly EMAIL_CAN_NOT_BE_UPDATED: {
90
- code: "EMAIL_CAN_NOT_BE_UPDATED";
91
- message: "Email can not be updated";
92
- };
93
- readonly CREDENTIAL_ACCOUNT_NOT_FOUND: {
94
- code: "CREDENTIAL_ACCOUNT_NOT_FOUND";
95
- message: "Credential account not found";
96
- };
97
- readonly SESSION_EXPIRED: {
98
- code: "SESSION_EXPIRED";
99
- message: "Session expired. Re-authenticate to perform this action.";
100
- };
101
- readonly FAILED_TO_UNLINK_LAST_ACCOUNT: {
102
- code: "FAILED_TO_UNLINK_LAST_ACCOUNT";
103
- message: "You can't unlink your last account";
104
- };
105
- readonly ACCOUNT_NOT_FOUND: {
106
- code: "ACCOUNT_NOT_FOUND";
107
- message: "Account not found";
108
- };
109
- readonly USER_ALREADY_HAS_PASSWORD: {
110
- code: "USER_ALREADY_HAS_PASSWORD";
111
- message: "User already has a password. Provide that to delete the account.";
112
- };
113
- readonly CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: {
114
- code: "CROSS_SITE_NAVIGATION_LOGIN_BLOCKED";
115
- message: "Cross-site navigation login blocked. This request appears to be a CSRF attack.";
116
- };
117
- readonly VERIFICATION_EMAIL_NOT_ENABLED: {
118
- code: "VERIFICATION_EMAIL_NOT_ENABLED";
119
- message: "Verification email isn't enabled";
120
- };
121
- readonly EMAIL_ALREADY_VERIFIED: {
122
- code: "EMAIL_ALREADY_VERIFIED";
123
- message: "Email is already verified";
124
- };
125
- readonly EMAIL_MISMATCH: {
126
- code: "EMAIL_MISMATCH";
127
- message: "Email mismatch";
128
- };
129
- readonly SESSION_NOT_FRESH: {
130
- code: "SESSION_NOT_FRESH";
131
- message: "Session is not fresh";
132
- };
133
- readonly LINKED_ACCOUNT_ALREADY_EXISTS: {
134
- code: "LINKED_ACCOUNT_ALREADY_EXISTS";
135
- message: "Linked account already exists";
136
- };
137
- readonly INVALID_ORIGIN: {
138
- code: "INVALID_ORIGIN";
139
- message: "Invalid origin";
140
- };
141
- readonly INVALID_CALLBACK_URL: {
142
- code: "INVALID_CALLBACK_URL";
143
- message: "Invalid callbackURL";
144
- };
145
- readonly INVALID_REDIRECT_URL: {
146
- code: "INVALID_REDIRECT_URL";
147
- message: "Invalid redirectURL";
148
- };
149
- readonly INVALID_ERROR_CALLBACK_URL: {
150
- code: "INVALID_ERROR_CALLBACK_URL";
151
- message: "Invalid errorCallbackURL";
152
- };
153
- readonly INVALID_NEW_USER_CALLBACK_URL: {
154
- code: "INVALID_NEW_USER_CALLBACK_URL";
155
- message: "Invalid newUserCallbackURL";
156
- };
157
- readonly MISSING_OR_NULL_ORIGIN: {
158
- code: "MISSING_OR_NULL_ORIGIN";
159
- message: "Missing or null Origin";
160
- };
161
- readonly CALLBACK_URL_REQUIRED: {
162
- code: "CALLBACK_URL_REQUIRED";
163
- message: "callbackURL is required";
164
- };
165
- readonly FAILED_TO_CREATE_VERIFICATION: {
166
- code: "FAILED_TO_CREATE_VERIFICATION";
167
- message: "Unable to create verification";
168
- };
169
- readonly FIELD_NOT_ALLOWED: {
170
- code: "FIELD_NOT_ALLOWED";
171
- message: "Field not allowed to be set";
172
- };
173
- readonly ASYNC_VALIDATION_NOT_SUPPORTED: {
174
- code: "ASYNC_VALIDATION_NOT_SUPPORTED";
175
- message: "Async validation is not supported";
176
- };
177
- readonly VALIDATION_ERROR: {
178
- code: "VALIDATION_ERROR";
179
- message: "Validation Error";
180
- };
181
- readonly MISSING_FIELD: {
182
- code: "MISSING_FIELD";
183
- message: "Field is required";
184
- };
185
- };
186
- type APIErrorCode = keyof typeof BASE_ERROR_CODES;
187
- //#endregion
188
4
  //#region src/error/index.d.ts
189
5
  declare class BetterAuthError extends Error {
190
6
  constructor(message: string, cause?: string | undefined);
@@ -1,5 +1,30 @@
1
- import "../env-DbssmzoK.mjs";
2
- import "../utils-puAL36Bz.mjs";
3
- import { n as BetterAuthError, r as BASE_ERROR_CODES, t as APIError } from "../error-GNtLPYaS.mjs";
1
+ import { BASE_ERROR_CODES } from "./codes.mjs";
2
+ import { APIError as APIError$1 } from "better-call/error";
4
3
 
4
+ //#region src/error/index.ts
5
+ var BetterAuthError = class extends Error {
6
+ constructor(message, cause) {
7
+ super(message);
8
+ this.name = "BetterAuthError";
9
+ this.message = message;
10
+ this.cause = cause;
11
+ this.stack = "";
12
+ }
13
+ };
14
+ var APIError = class APIError extends APIError$1 {
15
+ constructor(...args) {
16
+ super(...args);
17
+ }
18
+ static fromStatus(status, body) {
19
+ return new APIError(status, body);
20
+ }
21
+ static from(status, error) {
22
+ return new APIError(status, {
23
+ message: error.message,
24
+ code: error.code
25
+ });
26
+ }
27
+ };
28
+
29
+ //#endregion
5
30
  export { APIError, BASE_ERROR_CODES, BetterAuthError };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,8 @@
1
- import { C as HookEndpointContext, Cr as Primitive, Mn as BetterAuthCookies, S as BetterAuthPlugin, Sr as Prettify, _ as PluginContext, b as BetterAuthRateLimitOptions, br as LiteralString, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as InternalAdapter, h as GenericEndpointContext, l as ClientAtomListener, m as BetterAuthPluginRegistryIdentifier, o as StandardSchemaV1, p as BetterAuthPluginRegistry, s as BetterAuthClientOptions, u as ClientFetchOption, v as BetterAuthAdvancedOptions, x as GenerateIdFn, xr as LiteralUnion, y as BetterAuthOptions, yr as Awaitable } from "./index-CGr4Qrv8.mjs";
1
+ import { Awaitable, LiteralString, LiteralUnion, Prettify, Primitive } from "./types/helper.mjs";
2
+ import { BetterAuthCookies } from "./types/cookie.mjs";
3
+ import { BetterAuthPlugin, HookEndpointContext } from "./types/plugin.mjs";
4
+ import { BetterAuthAdvancedOptions, BetterAuthOptions, BetterAuthRateLimitOptions, GenerateIdFn } from "./types/init-options.mjs";
5
+ import { AuthContext, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, GenericEndpointContext, InternalAdapter, PluginContext } from "./types/context.mjs";
6
+ import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./types/plugin-client.mjs";
7
+ import { StandardSchemaV1 } from "./types/index.mjs";
2
8
  export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, StandardSchemaV1 };
@@ -0,0 +1,36 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
2
+
3
+ //#region src/oauth2/client-credentials-token.d.ts
4
+ declare function createClientCredentialsTokenRequest({
5
+ options,
6
+ scope,
7
+ authentication,
8
+ resource
9
+ }: {
10
+ options: ProviderOptions & {
11
+ clientSecret: string;
12
+ };
13
+ scope?: string | undefined;
14
+ authentication?: ("basic" | "post") | undefined;
15
+ resource?: (string | string[]) | undefined;
16
+ }): {
17
+ body: URLSearchParams;
18
+ headers: Record<string, any>;
19
+ };
20
+ declare function clientCredentialsToken({
21
+ options,
22
+ tokenEndpoint,
23
+ scope,
24
+ authentication,
25
+ resource
26
+ }: {
27
+ options: ProviderOptions & {
28
+ clientSecret: string;
29
+ };
30
+ tokenEndpoint: string;
31
+ scope: string;
32
+ authentication?: ("basic" | "post") | undefined;
33
+ resource?: (string | string[]) | undefined;
34
+ }): Promise<OAuth2Tokens>;
35
+ //#endregion
36
+ export { clientCredentialsToken, createClientCredentialsTokenRequest };
@@ -0,0 +1,54 @@
1
+ import { base64Url } from "@better-auth/utils/base64";
2
+ import { betterFetch } from "@better-fetch/fetch";
3
+
4
+ //#region src/oauth2/client-credentials-token.ts
5
+ function createClientCredentialsTokenRequest({ options, scope, authentication, resource }) {
6
+ const body = new URLSearchParams();
7
+ const headers = {
8
+ "content-type": "application/x-www-form-urlencoded",
9
+ accept: "application/json"
10
+ };
11
+ body.set("grant_type", "client_credentials");
12
+ scope && body.set("scope", scope);
13
+ if (resource) if (typeof resource === "string") body.append("resource", resource);
14
+ else for (const _resource of resource) body.append("resource", _resource);
15
+ if (authentication === "basic") {
16
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
17
+ headers["authorization"] = `Basic ${base64Url.encode(`${primaryClientId}:${options.clientSecret}`)}`;
18
+ } else {
19
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
20
+ body.set("client_id", primaryClientId);
21
+ body.set("client_secret", options.clientSecret);
22
+ }
23
+ return {
24
+ body,
25
+ headers
26
+ };
27
+ }
28
+ async function clientCredentialsToken({ options, tokenEndpoint, scope, authentication, resource }) {
29
+ const { body, headers } = createClientCredentialsTokenRequest({
30
+ options,
31
+ scope,
32
+ authentication,
33
+ resource
34
+ });
35
+ const { data, error } = await betterFetch(tokenEndpoint, {
36
+ method: "POST",
37
+ body,
38
+ headers
39
+ });
40
+ if (error) throw error;
41
+ const tokens = {
42
+ accessToken: data.access_token,
43
+ tokenType: data.token_type,
44
+ scopes: data.scope?.split(" ")
45
+ };
46
+ if (data.expires_in) {
47
+ const now = /* @__PURE__ */ new Date();
48
+ tokens.accessTokenExpiresAt = new Date(now.getTime() + data.expires_in * 1e3);
49
+ }
50
+ return tokens;
51
+ }
52
+
53
+ //#endregion
54
+ export { clientCredentialsToken, createClientCredentialsTokenRequest };
@@ -0,0 +1,45 @@
1
+ import { ProviderOptions } from "./oauth-provider.mjs";
2
+ import "./index.mjs";
3
+
4
+ //#region src/oauth2/create-authorization-url.d.ts
5
+ declare function createAuthorizationURL({
6
+ id,
7
+ options,
8
+ authorizationEndpoint,
9
+ state,
10
+ codeVerifier,
11
+ scopes,
12
+ claims,
13
+ redirectURI,
14
+ duration,
15
+ prompt,
16
+ accessType,
17
+ responseType,
18
+ display,
19
+ loginHint,
20
+ hd,
21
+ responseMode,
22
+ additionalParams,
23
+ scopeJoiner
24
+ }: {
25
+ id: string;
26
+ options: ProviderOptions;
27
+ redirectURI: string;
28
+ authorizationEndpoint: string;
29
+ state: string;
30
+ codeVerifier?: string | undefined;
31
+ scopes?: string[] | undefined;
32
+ claims?: string[] | undefined;
33
+ duration?: string | undefined;
34
+ prompt?: string | undefined;
35
+ accessType?: string | undefined;
36
+ responseType?: string | undefined;
37
+ display?: string | undefined;
38
+ loginHint?: string | undefined;
39
+ hd?: string | undefined;
40
+ responseMode?: string | undefined;
41
+ additionalParams?: Record<string, string> | undefined;
42
+ scopeJoiner?: string | undefined;
43
+ }): Promise<URL>;
44
+ //#endregion
45
+ export { createAuthorizationURL };
@@ -0,0 +1,42 @@
1
+ import { generateCodeChallenge } from "./utils.mjs";
2
+
3
+ //#region src/oauth2/create-authorization-url.ts
4
+ async function createAuthorizationURL({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, hd, responseMode, additionalParams, scopeJoiner }) {
5
+ const url = new URL(options.authorizationEndpoint || authorizationEndpoint);
6
+ url.searchParams.set("response_type", responseType || "code");
7
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
8
+ url.searchParams.set("client_id", primaryClientId);
9
+ url.searchParams.set("state", state);
10
+ if (scopes) url.searchParams.set("scope", scopes.join(scopeJoiner || " "));
11
+ url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
12
+ duration && url.searchParams.set("duration", duration);
13
+ display && url.searchParams.set("display", display);
14
+ loginHint && url.searchParams.set("login_hint", loginHint);
15
+ prompt && url.searchParams.set("prompt", prompt);
16
+ hd && url.searchParams.set("hd", hd);
17
+ accessType && url.searchParams.set("access_type", accessType);
18
+ responseMode && url.searchParams.set("response_mode", responseMode);
19
+ if (codeVerifier) {
20
+ const codeChallenge = await generateCodeChallenge(codeVerifier);
21
+ url.searchParams.set("code_challenge_method", "S256");
22
+ url.searchParams.set("code_challenge", codeChallenge);
23
+ }
24
+ if (claims) {
25
+ const claimsObj = claims.reduce((acc, claim) => {
26
+ acc[claim] = null;
27
+ return acc;
28
+ }, {});
29
+ url.searchParams.set("claims", JSON.stringify({ id_token: {
30
+ email: null,
31
+ email_verified: null,
32
+ ...claimsObj
33
+ } }));
34
+ }
35
+ if (additionalParams) Object.entries(additionalParams).forEach(([key, value]) => {
36
+ url.searchParams.set(key, value);
37
+ });
38
+ return url;
39
+ }
40
+
41
+ //#endregion
42
+ export { createAuthorizationURL };
@@ -1,2 +1,8 @@
1
- import { Bn as getOAuth2Tokens, Fn as verifyJwsAccessToken, Gn as createClientCredentialsTokenRequest, Hn as refreshAccessToken, In as createAuthorizationCodeRequest, Jn as OAuthProvider, Kn as OAuth2Tokens, Ln as validateAuthorizationCode, Nn as getJwks, Pn as verifyAccessToken, Rn as validateToken, Un as createAuthorizationURL, Vn as createRefreshAccessTokenRequest, Wn as clientCredentialsToken, Yn as ProviderOptions, qn as OAuth2UserInfo, zn as generateCodeChallenge } from "../index-CGr4Qrv8.mjs";
2
- export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
1
+ import { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions } from "./oauth-provider.mjs";
2
+ import { clientCredentialsToken, createClientCredentialsTokenRequest } from "./client-credentials-token.mjs";
3
+ import { createAuthorizationURL } from "./create-authorization-url.mjs";
4
+ import { createRefreshAccessTokenRequest, refreshAccessToken } from "./refresh-access-token.mjs";
5
+ import { generateCodeChallenge, getOAuth2Tokens } from "./utils.mjs";
6
+ import { createAuthorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
7
+ import { getJwks, verifyAccessToken, verifyJwsAccessToken } from "./verify.mjs";
8
+ export { type OAuth2Tokens, type OAuth2UserInfo, type OAuthProvider, type ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
@@ -1,4 +1,8 @@
1
- import "../env-DbssmzoK.mjs";
2
- import { a as validateAuthorizationCode, c as refreshAccessToken, d as getOAuth2Tokens, f as clientCredentialsToken, i as createAuthorizationCodeRequest, l as createAuthorizationURL, n as verifyAccessToken, o as validateToken, p as createClientCredentialsTokenRequest, r as verifyJwsAccessToken, s as createRefreshAccessTokenRequest, t as getJwks, u as generateCodeChallenge } from "../oauth2-BjWM15hm.mjs";
1
+ import { clientCredentialsToken, createClientCredentialsTokenRequest } from "./client-credentials-token.mjs";
2
+ import { generateCodeChallenge, getOAuth2Tokens } from "./utils.mjs";
3
+ import { createAuthorizationURL } from "./create-authorization-url.mjs";
4
+ import { createRefreshAccessTokenRequest, refreshAccessToken } from "./refresh-access-token.mjs";
5
+ import { createAuthorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
6
+ import { getJwks, verifyAccessToken, verifyJwsAccessToken } from "./verify.mjs";
3
7
 
4
8
  export { clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
@@ -0,0 +1,194 @@
1
+ import { Awaitable, LiteralString } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
3
+
4
+ //#region src/oauth2/oauth-provider.d.ts
5
+ interface OAuth2Tokens {
6
+ tokenType?: string | undefined;
7
+ accessToken?: string | undefined;
8
+ refreshToken?: string | undefined;
9
+ accessTokenExpiresAt?: Date | undefined;
10
+ refreshTokenExpiresAt?: Date | undefined;
11
+ scopes?: string[] | undefined;
12
+ idToken?: string | undefined;
13
+ /**
14
+ * Raw token response from the provider.
15
+ * Preserves provider-specific fields that are not part of the standard OAuth2 token response.
16
+ */
17
+ raw?: Record<string, unknown> | undefined;
18
+ }
19
+ type OAuth2UserInfo = {
20
+ id: string | number;
21
+ name?: string | undefined;
22
+ email?: (string | null) | undefined;
23
+ image?: string | undefined;
24
+ emailVerified: boolean;
25
+ };
26
+ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
27
+ id: LiteralString;
28
+ createAuthorizationURL: (data: {
29
+ state: string;
30
+ codeVerifier: string;
31
+ scopes?: string[] | undefined;
32
+ redirectURI: string;
33
+ display?: string | undefined;
34
+ loginHint?: string | undefined;
35
+ }) => Awaitable<URL>;
36
+ name: string;
37
+ validateAuthorizationCode: (data: {
38
+ code: string;
39
+ redirectURI: string;
40
+ codeVerifier?: string | undefined;
41
+ deviceId?: string | undefined;
42
+ }) => Promise<OAuth2Tokens>;
43
+ getUserInfo: (token: OAuth2Tokens & {
44
+ /**
45
+ * The user object from the provider
46
+ * This is only available for some providers like Apple
47
+ */
48
+ user?: {
49
+ name?: {
50
+ firstName?: string;
51
+ lastName?: string;
52
+ };
53
+ email?: string;
54
+ } | undefined;
55
+ }) => Promise<{
56
+ user: OAuth2UserInfo;
57
+ data: T;
58
+ } | null>;
59
+ /**
60
+ * Custom function to refresh a token
61
+ */
62
+ refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
63
+ revokeToken?: ((token: string) => Promise<void>) | undefined;
64
+ /**
65
+ * Verify the id token
66
+ * @param token - The id token
67
+ * @param nonce - The nonce
68
+ * @returns True if the id token is valid, false otherwise
69
+ */
70
+ verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
71
+ /**
72
+ * Disable implicit sign up for new users. When set to true for the provider,
73
+ * sign-in need to be called with with requestSignUp as true to create new users.
74
+ */
75
+ disableImplicitSignUp?: boolean | undefined;
76
+ /**
77
+ * Disable sign up for new users.
78
+ */
79
+ disableSignUp?: boolean | undefined;
80
+ /**
81
+ * Options for the provider
82
+ */
83
+ options?: O | undefined;
84
+ }
85
+ type ProviderOptions<Profile extends Record<string, any> = any> = {
86
+ /**
87
+ * The client ID of your application.
88
+ *
89
+ * This is usually a string but can be any type depending on the provider.
90
+ */
91
+ clientId?: unknown | undefined;
92
+ /**
93
+ * The client secret of your application
94
+ */
95
+ clientSecret?: string | undefined;
96
+ /**
97
+ * The scopes you want to request from the provider
98
+ */
99
+ scope?: string[] | undefined;
100
+ /**
101
+ * Remove default scopes of the provider
102
+ */
103
+ disableDefaultScope?: boolean | undefined;
104
+ /**
105
+ * The redirect URL for your application. This is where the provider will
106
+ * redirect the user after the sign in process. Make sure this URL is
107
+ * whitelisted in the provider's dashboard.
108
+ */
109
+ redirectURI?: string | undefined;
110
+ /**
111
+ * Custom authorization endpoint URL.
112
+ * Use this to override the default authorization endpoint of the provider.
113
+ * Useful for testing with local OAuth servers or using sandbox environments.
114
+ */
115
+ authorizationEndpoint?: string | undefined;
116
+ /**
117
+ * The client key of your application
118
+ * Tiktok Social Provider uses this field instead of clientId
119
+ */
120
+ clientKey?: string | undefined;
121
+ /**
122
+ * Disable provider from allowing users to sign in
123
+ * with this provider with an id token sent from the
124
+ * client.
125
+ */
126
+ disableIdTokenSignIn?: boolean | undefined;
127
+ /**
128
+ * verifyIdToken function to verify the id token
129
+ */
130
+ verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
131
+ /**
132
+ * Custom function to get user info from the provider
133
+ */
134
+ getUserInfo?: ((token: OAuth2Tokens) => Promise<{
135
+ user: {
136
+ id: string;
137
+ name?: string;
138
+ email?: string | null;
139
+ image?: string;
140
+ emailVerified: boolean;
141
+ [key: string]: any;
142
+ };
143
+ data: any;
144
+ } | null>) | undefined;
145
+ /**
146
+ * Custom function to refresh a token
147
+ */
148
+ refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
149
+ /**
150
+ * Custom function to map the provider profile to a
151
+ * user.
152
+ */
153
+ mapProfileToUser?: ((profile: Profile) => {
154
+ id?: string;
155
+ name?: string;
156
+ email?: string | null;
157
+ image?: string;
158
+ emailVerified?: boolean;
159
+ [key: string]: any;
160
+ } | Promise<{
161
+ id?: string;
162
+ name?: string;
163
+ email?: string | null;
164
+ image?: string;
165
+ emailVerified?: boolean;
166
+ [key: string]: any;
167
+ }>) | undefined;
168
+ /**
169
+ * Disable implicit sign up for new users. When set to true for the provider,
170
+ * sign-in need to be called with with requestSignUp as true to create new users.
171
+ */
172
+ disableImplicitSignUp?: boolean | undefined;
173
+ /**
174
+ * Disable sign up for new users.
175
+ */
176
+ disableSignUp?: boolean | undefined;
177
+ /**
178
+ * The prompt to use for the authorization code request
179
+ */
180
+ prompt?: ("select_account" | "consent" | "login" | "none" | "select_account consent") | undefined;
181
+ /**
182
+ * The response mode to use for the authorization code request
183
+ */
184
+ responseMode?: ("query" | "form_post") | undefined;
185
+ /**
186
+ * If enabled, the user info will be overridden with the provider user info
187
+ * This is useful if you want to use the provider user info to update the user info
188
+ *
189
+ * @default false
190
+ */
191
+ overrideUserInfoOnSignIn?: boolean | undefined;
192
+ };
193
+ //#endregion
194
+ export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions };
@@ -0,0 +1,36 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
2
+
3
+ //#region src/oauth2/refresh-access-token.d.ts
4
+ declare function createRefreshAccessTokenRequest({
5
+ refreshToken,
6
+ options,
7
+ authentication,
8
+ extraParams,
9
+ resource
10
+ }: {
11
+ refreshToken: string;
12
+ options: Partial<ProviderOptions>;
13
+ authentication?: ("basic" | "post") | undefined;
14
+ extraParams?: Record<string, string> | undefined;
15
+ resource?: (string | string[]) | undefined;
16
+ }): {
17
+ body: URLSearchParams;
18
+ headers: Record<string, any>;
19
+ };
20
+ declare function refreshAccessToken({
21
+ refreshToken,
22
+ options,
23
+ tokenEndpoint,
24
+ authentication,
25
+ extraParams
26
+ }: {
27
+ refreshToken: string;
28
+ options: Partial<ProviderOptions>;
29
+ tokenEndpoint: string;
30
+ authentication?: ("basic" | "post") | undefined;
31
+ extraParams?: Record<string, string> | undefined;
32
+ /** @deprecated always "refresh_token" */
33
+ grantType?: string | undefined;
34
+ }): Promise<OAuth2Tokens>;
35
+ //#endregion
36
+ export { createRefreshAccessTokenRequest, refreshAccessToken };