@better-auth/core 1.4.12-beta.2 → 1.4.13

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 (185) hide show
  1. package/.turbo/turbo-build.log +172 -35
  2. package/dist/api/index.d.mts +178 -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 +31 -0
  6. package/dist/context/global.d.mts +7 -0
  7. package/dist/context/global.mjs +37 -0
  8. package/dist/context/index.d.mts +5 -53
  9. package/dist/context/index.mjs +5 -2
  10. package/dist/context/request-state.d.mts +27 -0
  11. package/dist/context/request-state.mjs +49 -0
  12. package/dist/context/transaction.d.mts +16 -0
  13. package/dist/context/transaction.mjs +52 -0
  14. package/dist/db/adapter/factory.d.mts +27 -0
  15. package/dist/db/adapter/factory.mjs +738 -0
  16. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  17. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  18. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  19. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  20. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  21. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  22. package/dist/db/adapter/get-field-name.d.mts +18 -0
  23. package/dist/db/adapter/get-field-name.mjs +33 -0
  24. package/dist/db/adapter/get-id-field.d.mts +39 -0
  25. package/dist/db/adapter/get-id-field.mjs +68 -0
  26. package/dist/db/adapter/get-model-name.d.mts +12 -0
  27. package/dist/db/adapter/get-model-name.mjs +23 -0
  28. package/dist/db/adapter/index.d.mts +513 -1
  29. package/dist/db/adapter/index.mjs +8 -970
  30. package/dist/db/adapter/types.d.mts +139 -0
  31. package/dist/db/adapter/utils.d.mts +7 -0
  32. package/dist/db/adapter/utils.mjs +38 -0
  33. package/dist/db/get-tables.d.mts +8 -0
  34. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  35. package/dist/db/index.d.mts +10 -2
  36. package/dist/db/index.mjs +7 -60
  37. package/dist/db/plugin.d.mts +12 -0
  38. package/dist/db/schema/account.d.mts +26 -0
  39. package/dist/db/schema/account.mjs +19 -0
  40. package/dist/db/schema/rate-limit.d.mts +14 -0
  41. package/dist/db/schema/rate-limit.mjs +11 -0
  42. package/dist/db/schema/session.d.mts +21 -0
  43. package/dist/db/schema/session.mjs +14 -0
  44. package/dist/db/schema/shared.d.mts +10 -0
  45. package/dist/db/schema/shared.mjs +11 -0
  46. package/dist/db/schema/user.d.mts +20 -0
  47. package/dist/db/schema/user.mjs +13 -0
  48. package/dist/db/schema/verification.d.mts +19 -0
  49. package/dist/db/schema/verification.mjs +12 -0
  50. package/dist/db/type.d.mts +143 -0
  51. package/dist/env/color-depth.d.mts +4 -0
  52. package/dist/env/color-depth.mjs +88 -0
  53. package/dist/env/env-impl.d.mts +32 -0
  54. package/dist/env/env-impl.mjs +82 -0
  55. package/dist/env/index.d.mts +4 -2
  56. package/dist/env/index.mjs +3 -1
  57. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  58. package/dist/env/logger.mjs +81 -0
  59. package/dist/error/codes.d.mts +48 -0
  60. package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
  61. package/dist/error/index.d.mts +5 -48
  62. package/dist/error/index.mjs +12 -3
  63. package/dist/index.d.mts +8 -2
  64. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  65. package/dist/oauth2/client-credentials-token.mjs +54 -0
  66. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  67. package/dist/oauth2/create-authorization-url.mjs +42 -0
  68. package/dist/oauth2/index.d.mts +8 -2
  69. package/dist/oauth2/index.mjs +6 -2
  70. package/dist/oauth2/oauth-provider.d.mts +194 -0
  71. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  72. package/dist/oauth2/refresh-access-token.mjs +58 -0
  73. package/dist/oauth2/utils.d.mts +7 -0
  74. package/dist/oauth2/utils.mjs +27 -0
  75. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  76. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  77. package/dist/oauth2/verify.d.mts +49 -0
  78. package/dist/oauth2/verify.mjs +95 -0
  79. package/dist/social-providers/apple.d.mts +119 -0
  80. package/dist/social-providers/apple.mjs +102 -0
  81. package/dist/social-providers/atlassian.d.mts +72 -0
  82. package/dist/social-providers/atlassian.mjs +83 -0
  83. package/dist/social-providers/cognito.d.mts +87 -0
  84. package/dist/social-providers/cognito.mjs +166 -0
  85. package/dist/social-providers/discord.d.mts +126 -0
  86. package/dist/social-providers/discord.mjs +64 -0
  87. package/dist/social-providers/dropbox.d.mts +71 -0
  88. package/dist/social-providers/dropbox.mjs +75 -0
  89. package/dist/social-providers/facebook.d.mts +81 -0
  90. package/dist/social-providers/facebook.mjs +120 -0
  91. package/dist/social-providers/figma.d.mts +63 -0
  92. package/dist/social-providers/figma.mjs +84 -0
  93. package/dist/social-providers/github.d.mts +104 -0
  94. package/dist/social-providers/github.mjs +80 -0
  95. package/dist/social-providers/gitlab.d.mts +125 -0
  96. package/dist/social-providers/gitlab.mjs +82 -0
  97. package/dist/social-providers/google.d.mts +99 -0
  98. package/dist/social-providers/google.mjs +109 -0
  99. package/dist/social-providers/huggingface.d.mts +85 -0
  100. package/dist/social-providers/huggingface.mjs +75 -0
  101. package/dist/social-providers/index.d.mts +1723 -1
  102. package/dist/social-providers/index.mjs +33 -2570
  103. package/dist/social-providers/kakao.d.mts +163 -0
  104. package/dist/social-providers/kakao.mjs +72 -0
  105. package/dist/social-providers/kick.d.mts +75 -0
  106. package/dist/social-providers/kick.mjs +71 -0
  107. package/dist/social-providers/line.d.mts +107 -0
  108. package/dist/social-providers/line.mjs +113 -0
  109. package/dist/social-providers/linear.d.mts +70 -0
  110. package/dist/social-providers/linear.mjs +88 -0
  111. package/dist/social-providers/linkedin.d.mts +69 -0
  112. package/dist/social-providers/linkedin.mjs +76 -0
  113. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  114. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  115. package/dist/social-providers/naver.d.mts +104 -0
  116. package/dist/social-providers/naver.mjs +67 -0
  117. package/dist/social-providers/notion.d.mts +66 -0
  118. package/dist/social-providers/notion.mjs +75 -0
  119. package/dist/social-providers/paybin.d.mts +73 -0
  120. package/dist/social-providers/paybin.mjs +85 -0
  121. package/dist/social-providers/paypal.d.mts +131 -0
  122. package/dist/social-providers/paypal.mjs +144 -0
  123. package/dist/social-providers/polar.d.mts +76 -0
  124. package/dist/social-providers/polar.mjs +73 -0
  125. package/dist/social-providers/reddit.d.mts +64 -0
  126. package/dist/social-providers/reddit.mjs +83 -0
  127. package/dist/social-providers/roblox.d.mts +72 -0
  128. package/dist/social-providers/roblox.mjs +59 -0
  129. package/dist/social-providers/salesforce.d.mts +81 -0
  130. package/dist/social-providers/salesforce.mjs +91 -0
  131. package/dist/social-providers/slack.d.mts +85 -0
  132. package/dist/social-providers/slack.mjs +68 -0
  133. package/dist/social-providers/spotify.d.mts +65 -0
  134. package/dist/social-providers/spotify.mjs +71 -0
  135. package/dist/social-providers/tiktok.d.mts +171 -0
  136. package/dist/social-providers/tiktok.mjs +62 -0
  137. package/dist/social-providers/twitch.d.mts +81 -0
  138. package/dist/social-providers/twitch.mjs +78 -0
  139. package/dist/social-providers/twitter.d.mts +140 -0
  140. package/dist/social-providers/twitter.mjs +87 -0
  141. package/dist/social-providers/vercel.d.mts +64 -0
  142. package/dist/social-providers/vercel.mjs +61 -0
  143. package/dist/social-providers/vk.d.mts +72 -0
  144. package/dist/social-providers/vk.mjs +83 -0
  145. package/dist/social-providers/zoom.d.mts +173 -0
  146. package/dist/social-providers/zoom.mjs +72 -0
  147. package/dist/types/context.d.mts +215 -0
  148. package/dist/types/cookie.d.mts +15 -0
  149. package/dist/types/helper.d.mts +8 -0
  150. package/dist/types/index.d.mts +8 -0
  151. package/dist/types/init-options.d.mts +1266 -0
  152. package/dist/types/plugin-client.d.mts +103 -0
  153. package/dist/types/plugin.d.mts +121 -0
  154. package/dist/utils/deprecate.d.mts +10 -0
  155. package/dist/utils/deprecate.mjs +17 -0
  156. package/dist/utils/error-codes.d.mts +9 -0
  157. package/dist/utils/error-codes.mjs +7 -0
  158. package/dist/utils/id.d.mts +4 -0
  159. package/dist/utils/id.mjs +9 -0
  160. package/dist/utils/index.d.mts +5 -26
  161. package/dist/utils/index.mjs +5 -2
  162. package/dist/utils/json.d.mts +4 -0
  163. package/dist/utils/json.mjs +25 -0
  164. package/dist/utils/string.d.mts +4 -0
  165. package/dist/utils/string.mjs +7 -0
  166. package/package.json +1 -1
  167. package/src/context/endpoint-context.ts +7 -15
  168. package/src/context/global.ts +57 -0
  169. package/src/context/index.ts +1 -0
  170. package/src/context/request-state.ts +7 -12
  171. package/src/context/transaction.ts +7 -16
  172. package/src/db/adapter/factory.ts +13 -13
  173. package/src/db/adapter/get-default-model-name.ts +1 -1
  174. package/src/db/adapter/get-id-field.ts +2 -2
  175. package/src/error/index.ts +2 -3
  176. package/src/social-providers/gitlab.ts +1 -1
  177. package/src/types/context.ts +137 -131
  178. package/src/types/cookie.ts +6 -4
  179. package/src/types/index.ts +2 -1
  180. package/tsdown.config.ts +9 -0
  181. package/dist/context-BGZ8V6DD.mjs +0 -126
  182. package/dist/env-DbssmzoK.mjs +0 -245
  183. package/dist/index-zgYuzZ7O.d.mts +0 -8020
  184. package/dist/oauth2-COJkghlT.mjs +0 -326
  185. package/dist/utils-U2L7n92V.mjs +0 -59
@@ -1,245 +0,0 @@
1
- //#region src/env/env-impl.ts
2
- const _envShim = Object.create(null);
3
- const _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
4
- const env = new Proxy(_envShim, {
5
- get(_, prop) {
6
- return _getEnv()[prop] ?? _envShim[prop];
7
- },
8
- has(_, prop) {
9
- return prop in _getEnv() || prop in _envShim;
10
- },
11
- set(_, prop, value) {
12
- const env$1 = _getEnv(true);
13
- env$1[prop] = value;
14
- return true;
15
- },
16
- deleteProperty(_, prop) {
17
- if (!prop) return false;
18
- const env$1 = _getEnv(true);
19
- delete env$1[prop];
20
- return true;
21
- },
22
- ownKeys() {
23
- const env$1 = _getEnv(true);
24
- return Object.keys(env$1);
25
- }
26
- });
27
- function toBoolean(val) {
28
- return val ? val !== "false" : false;
29
- }
30
- const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
31
- /** Detect if `NODE_ENV` environment variable is `production` */
32
- const isProduction = nodeENV === "production";
33
- /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
34
- const isDevelopment = () => nodeENV === "dev" || nodeENV === "development";
35
- /** Detect if `NODE_ENV` environment variable is `test` */
36
- const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
37
- /**
38
- * Get environment variable with fallback
39
- */
40
- function getEnvVar(key, fallback) {
41
- if (typeof process !== "undefined" && process.env) return process.env[key] ?? fallback;
42
- if (typeof Deno !== "undefined") return Deno.env.get(key) ?? fallback;
43
- if (typeof Bun !== "undefined") return Bun.env[key] ?? fallback;
44
- return fallback;
45
- }
46
- /**
47
- * Get boolean environment variable
48
- */
49
- function getBooleanEnvVar(key, fallback = true) {
50
- const value = getEnvVar(key);
51
- if (!value) return fallback;
52
- return value !== "0" && value.toLowerCase() !== "false" && value !== "";
53
- }
54
- /**
55
- * Common environment variables used in Better Auth
56
- */
57
- const ENV = Object.freeze({
58
- get BETTER_AUTH_SECRET() {
59
- return getEnvVar("BETTER_AUTH_SECRET");
60
- },
61
- get AUTH_SECRET() {
62
- return getEnvVar("AUTH_SECRET");
63
- },
64
- get BETTER_AUTH_TELEMETRY() {
65
- return getEnvVar("BETTER_AUTH_TELEMETRY");
66
- },
67
- get BETTER_AUTH_TELEMETRY_ID() {
68
- return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
69
- },
70
- get NODE_ENV() {
71
- return getEnvVar("NODE_ENV", "development");
72
- },
73
- get PACKAGE_VERSION() {
74
- return getEnvVar("PACKAGE_VERSION", "0.0.0");
75
- },
76
- get BETTER_AUTH_TELEMETRY_ENDPOINT() {
77
- return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "https://telemetry.better-auth.com/v1/track");
78
- }
79
- });
80
-
81
- //#endregion
82
- //#region src/env/color-depth.ts
83
- const COLORS_2 = 1;
84
- const COLORS_16 = 4;
85
- const COLORS_256 = 8;
86
- const COLORS_16m = 24;
87
- const TERM_ENVS = {
88
- eterm: COLORS_16,
89
- cons25: COLORS_16,
90
- console: COLORS_16,
91
- cygwin: COLORS_16,
92
- dtterm: COLORS_16,
93
- gnome: COLORS_16,
94
- hurd: COLORS_16,
95
- jfbterm: COLORS_16,
96
- konsole: COLORS_16,
97
- kterm: COLORS_16,
98
- mlterm: COLORS_16,
99
- mosh: COLORS_16m,
100
- putty: COLORS_16,
101
- st: COLORS_16,
102
- "rxvt-unicode-24bit": COLORS_16m,
103
- terminator: COLORS_16m,
104
- "xterm-kitty": COLORS_16m
105
- };
106
- const CI_ENVS_MAP = new Map(Object.entries({
107
- APPVEYOR: COLORS_256,
108
- BUILDKITE: COLORS_256,
109
- CIRCLECI: COLORS_16m,
110
- DRONE: COLORS_256,
111
- GITEA_ACTIONS: COLORS_16m,
112
- GITHUB_ACTIONS: COLORS_16m,
113
- GITLAB_CI: COLORS_256,
114
- TRAVIS: COLORS_256
115
- }));
116
- const TERM_ENVS_REG_EXP = [
117
- /ansi/,
118
- /color/,
119
- /linux/,
120
- /direct/,
121
- /^con[0-9]*x[0-9]/,
122
- /^rxvt/,
123
- /^screen/,
124
- /^xterm/,
125
- /^vt100/,
126
- /^vt220/
127
- ];
128
- function getColorDepth() {
129
- if (getEnvVar("FORCE_COLOR") !== void 0) switch (getEnvVar("FORCE_COLOR")) {
130
- case "":
131
- case "1":
132
- case "true": return COLORS_16;
133
- case "2": return COLORS_256;
134
- case "3": return COLORS_16m;
135
- default: return COLORS_2;
136
- }
137
- if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || getEnvVar("TERM") === "dumb") return COLORS_2;
138
- if (getEnvVar("TMUX")) return COLORS_16m;
139
- if ("TF_BUILD" in env && "AGENT_NAME" in env) return COLORS_16;
140
- if ("CI" in env) {
141
- for (const { 0: envName, 1: colors } of CI_ENVS_MAP) if (envName in env) return colors;
142
- if (getEnvVar("CI_NAME") === "codeship") return COLORS_256;
143
- return COLORS_2;
144
- }
145
- if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
146
- switch (getEnvVar("TERM_PROGRAM")) {
147
- case "iTerm.app":
148
- if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) return COLORS_256;
149
- return COLORS_16m;
150
- case "HyperTerm":
151
- case "MacTerm": return COLORS_16m;
152
- case "Apple_Terminal": return COLORS_256;
153
- }
154
- if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") return COLORS_16m;
155
- if (getEnvVar("TERM")) {
156
- if (/truecolor/.exec(getEnvVar("TERM")) !== null) return COLORS_16m;
157
- if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) return COLORS_256;
158
- const termEnv = getEnvVar("TERM").toLowerCase();
159
- if (TERM_ENVS[termEnv]) return TERM_ENVS[termEnv];
160
- if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) return COLORS_16;
161
- }
162
- if (getEnvVar("COLORTERM")) return COLORS_16;
163
- return COLORS_2;
164
- }
165
-
166
- //#endregion
167
- //#region src/env/logger.ts
168
- const TTY_COLORS = {
169
- reset: "\x1B[0m",
170
- bright: "\x1B[1m",
171
- dim: "\x1B[2m",
172
- undim: "\x1B[22m",
173
- underscore: "\x1B[4m",
174
- blink: "\x1B[5m",
175
- reverse: "\x1B[7m",
176
- hidden: "\x1B[8m",
177
- fg: {
178
- black: "\x1B[30m",
179
- red: "\x1B[31m",
180
- green: "\x1B[32m",
181
- yellow: "\x1B[33m",
182
- blue: "\x1B[34m",
183
- magenta: "\x1B[35m",
184
- cyan: "\x1B[36m",
185
- white: "\x1B[37m"
186
- },
187
- bg: {
188
- black: "\x1B[40m",
189
- red: "\x1B[41m",
190
- green: "\x1B[42m",
191
- yellow: "\x1B[43m",
192
- blue: "\x1B[44m",
193
- magenta: "\x1B[45m",
194
- cyan: "\x1B[46m",
195
- white: "\x1B[47m"
196
- }
197
- };
198
- const levels = [
199
- "debug",
200
- "info",
201
- "success",
202
- "warn",
203
- "error"
204
- ];
205
- function shouldPublishLog(currentLogLevel, logLevel) {
206
- return levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);
207
- }
208
- const levelColors = {
209
- info: TTY_COLORS.fg.blue,
210
- success: TTY_COLORS.fg.green,
211
- warn: TTY_COLORS.fg.yellow,
212
- error: TTY_COLORS.fg.red,
213
- debug: TTY_COLORS.fg.magenta
214
- };
215
- const formatMessage = (level, message, colorsEnabled) => {
216
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
217
- if (colorsEnabled) return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
218
- return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
219
- };
220
- const createLogger = (options) => {
221
- const enabled = options?.disabled !== true;
222
- const logLevel = options?.level ?? "error";
223
- const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
224
- const LogFunc = (level, message, args = []) => {
225
- if (!enabled || !shouldPublishLog(logLevel, level)) return;
226
- const formattedMessage = formatMessage(level, message, colorsEnabled);
227
- if (!options || typeof options.log !== "function") {
228
- if (level === "error") console.error(formattedMessage, ...args);
229
- else if (level === "warn") console.warn(formattedMessage, ...args);
230
- else console.log(formattedMessage, ...args);
231
- return;
232
- }
233
- options.log(level === "success" ? "info" : level, message, ...args);
234
- };
235
- return {
236
- ...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
237
- get level() {
238
- return logLevel;
239
- }
240
- };
241
- };
242
- const logger = createLogger();
243
-
244
- //#endregion
245
- export { shouldPublishLog as a, env as c, isDevelopment as d, isProduction as f, logger as i, getBooleanEnvVar as l, nodeENV as m, createLogger as n, getColorDepth as o, isTest as p, levels as r, ENV as s, TTY_COLORS as t, getEnvVar as u };