@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
@@ -0,0 +1,88 @@
1
+ import { env, getEnvVar } from "./env-impl.mjs";
2
+
3
+ //#region src/env/color-depth.ts
4
+ const COLORS_2 = 1;
5
+ const COLORS_16 = 4;
6
+ const COLORS_256 = 8;
7
+ const COLORS_16m = 24;
8
+ const TERM_ENVS = {
9
+ eterm: COLORS_16,
10
+ cons25: COLORS_16,
11
+ console: COLORS_16,
12
+ cygwin: COLORS_16,
13
+ dtterm: COLORS_16,
14
+ gnome: COLORS_16,
15
+ hurd: COLORS_16,
16
+ jfbterm: COLORS_16,
17
+ konsole: COLORS_16,
18
+ kterm: COLORS_16,
19
+ mlterm: COLORS_16,
20
+ mosh: COLORS_16m,
21
+ putty: COLORS_16,
22
+ st: COLORS_16,
23
+ "rxvt-unicode-24bit": COLORS_16m,
24
+ terminator: COLORS_16m,
25
+ "xterm-kitty": COLORS_16m
26
+ };
27
+ const CI_ENVS_MAP = new Map(Object.entries({
28
+ APPVEYOR: COLORS_256,
29
+ BUILDKITE: COLORS_256,
30
+ CIRCLECI: COLORS_16m,
31
+ DRONE: COLORS_256,
32
+ GITEA_ACTIONS: COLORS_16m,
33
+ GITHUB_ACTIONS: COLORS_16m,
34
+ GITLAB_CI: COLORS_256,
35
+ TRAVIS: COLORS_256
36
+ }));
37
+ const TERM_ENVS_REG_EXP = [
38
+ /ansi/,
39
+ /color/,
40
+ /linux/,
41
+ /direct/,
42
+ /^con[0-9]*x[0-9]/,
43
+ /^rxvt/,
44
+ /^screen/,
45
+ /^xterm/,
46
+ /^vt100/,
47
+ /^vt220/
48
+ ];
49
+ function getColorDepth() {
50
+ if (getEnvVar("FORCE_COLOR") !== void 0) switch (getEnvVar("FORCE_COLOR")) {
51
+ case "":
52
+ case "1":
53
+ case "true": return COLORS_16;
54
+ case "2": return COLORS_256;
55
+ case "3": return COLORS_16m;
56
+ default: return COLORS_2;
57
+ }
58
+ 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;
59
+ if (getEnvVar("TMUX")) return COLORS_16m;
60
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return COLORS_16;
61
+ if ("CI" in env) {
62
+ for (const { 0: envName, 1: colors } of CI_ENVS_MAP) if (envName in env) return colors;
63
+ if (getEnvVar("CI_NAME") === "codeship") return COLORS_256;
64
+ return COLORS_2;
65
+ }
66
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
67
+ switch (getEnvVar("TERM_PROGRAM")) {
68
+ case "iTerm.app":
69
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) return COLORS_256;
70
+ return COLORS_16m;
71
+ case "HyperTerm":
72
+ case "MacTerm": return COLORS_16m;
73
+ case "Apple_Terminal": return COLORS_256;
74
+ }
75
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") return COLORS_16m;
76
+ if (getEnvVar("TERM")) {
77
+ if (/truecolor/.exec(getEnvVar("TERM")) !== null) return COLORS_16m;
78
+ if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) return COLORS_256;
79
+ const termEnv = getEnvVar("TERM").toLowerCase();
80
+ if (TERM_ENVS[termEnv]) return TERM_ENVS[termEnv];
81
+ if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) return COLORS_16;
82
+ }
83
+ if (getEnvVar("COLORTERM")) return COLORS_16;
84
+ return COLORS_2;
85
+ }
86
+
87
+ //#endregion
88
+ export { getColorDepth };
@@ -0,0 +1,32 @@
1
+ //#region src/env/env-impl.d.ts
2
+ type EnvObject = Record<string, string | undefined>;
3
+ declare const env: EnvObject;
4
+ declare const nodeENV: string;
5
+ /** Detect if `NODE_ENV` environment variable is `production` */
6
+ declare const isProduction: boolean;
7
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
8
+ declare const isDevelopment: () => boolean;
9
+ /** Detect if `NODE_ENV` environment variable is `test` */
10
+ declare const isTest: () => boolean;
11
+ /**
12
+ * Get environment variable with fallback
13
+ */
14
+ declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
15
+ /**
16
+ * Get boolean environment variable
17
+ */
18
+ declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
19
+ /**
20
+ * Common environment variables used in Better Auth
21
+ */
22
+ declare const ENV: Readonly<{
23
+ readonly BETTER_AUTH_SECRET: string;
24
+ readonly AUTH_SECRET: string;
25
+ readonly BETTER_AUTH_TELEMETRY: string;
26
+ readonly BETTER_AUTH_TELEMETRY_ID: string;
27
+ readonly NODE_ENV: string;
28
+ readonly PACKAGE_VERSION: string;
29
+ readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
30
+ }>;
31
+ //#endregion
32
+ export { ENV, EnvObject, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
@@ -0,0 +1,82 @@
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
+ export { ENV, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
@@ -1,2 +1,4 @@
1
- import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-BRBu0-5h.mjs";
2
- export { ENV, EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
1
+ import { getColorDepth } from "./color-depth.mjs";
2
+ import { ENV, EnvObject, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV } from "./env-impl.mjs";
3
+ import { InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, levels, logger, shouldPublishLog } from "./logger.mjs";
4
+ export { ENV, type EnvObject, type InternalLogger, type LogHandlerParams, type LogLevel, type Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,3 +1,5 @@
1
- import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-DbssmzoK.mjs";
1
+ import { ENV, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV } from "./env-impl.mjs";
2
+ import { getColorDepth } from "./color-depth.mjs";
3
+ import { TTY_COLORS, createLogger, levels, logger, shouldPublishLog } from "./logger.mjs";
2
4
 
3
5
  export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,37 +1,3 @@
1
- //#region src/env/color-depth.d.ts
2
- declare function getColorDepth(): number;
3
- //#endregion
4
- //#region src/env/env-impl.d.ts
5
- type EnvObject = Record<string, string | undefined>;
6
- declare const env: EnvObject;
7
- declare const nodeENV: string;
8
- /** Detect if `NODE_ENV` environment variable is `production` */
9
- declare const isProduction: boolean;
10
- /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
11
- declare const isDevelopment: () => boolean;
12
- /** Detect if `NODE_ENV` environment variable is `test` */
13
- declare const isTest: () => boolean;
14
- /**
15
- * Get environment variable with fallback
16
- */
17
- declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
18
- /**
19
- * Get boolean environment variable
20
- */
21
- declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
22
- /**
23
- * Common environment variables used in Better Auth
24
- */
25
- declare const ENV: Readonly<{
26
- readonly BETTER_AUTH_SECRET: string;
27
- readonly AUTH_SECRET: string;
28
- readonly BETTER_AUTH_TELEMETRY: string;
29
- readonly BETTER_AUTH_TELEMETRY_ID: string;
30
- readonly NODE_ENV: string;
31
- readonly PACKAGE_VERSION: string;
32
- readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
33
- }>;
34
- //#endregion
35
1
  //#region src/env/logger.d.ts
36
2
  declare const TTY_COLORS: {
37
3
  readonly reset: "\u001B[0m";
@@ -79,4 +45,4 @@ type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void }
79
45
  declare const createLogger: (options?: Logger | undefined) => InternalLogger;
80
46
  declare const logger: InternalLogger;
81
47
  //#endregion
82
- export { isTest as _, TTY_COLORS as a, logger as c, EnvObject as d, env as f, isProduction as g, isDevelopment as h, Logger as i, shouldPublishLog as l, getEnvVar as m, LogHandlerParams as n, createLogger as o, getBooleanEnvVar as p, LogLevel as r, levels as s, InternalLogger as t, ENV as u, nodeENV as v, getColorDepth as y };
48
+ export { InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
@@ -0,0 +1,81 @@
1
+ import { getColorDepth } from "./color-depth.mjs";
2
+
3
+ //#region src/env/logger.ts
4
+ const TTY_COLORS = {
5
+ reset: "\x1B[0m",
6
+ bright: "\x1B[1m",
7
+ dim: "\x1B[2m",
8
+ undim: "\x1B[22m",
9
+ underscore: "\x1B[4m",
10
+ blink: "\x1B[5m",
11
+ reverse: "\x1B[7m",
12
+ hidden: "\x1B[8m",
13
+ fg: {
14
+ black: "\x1B[30m",
15
+ red: "\x1B[31m",
16
+ green: "\x1B[32m",
17
+ yellow: "\x1B[33m",
18
+ blue: "\x1B[34m",
19
+ magenta: "\x1B[35m",
20
+ cyan: "\x1B[36m",
21
+ white: "\x1B[37m"
22
+ },
23
+ bg: {
24
+ black: "\x1B[40m",
25
+ red: "\x1B[41m",
26
+ green: "\x1B[42m",
27
+ yellow: "\x1B[43m",
28
+ blue: "\x1B[44m",
29
+ magenta: "\x1B[45m",
30
+ cyan: "\x1B[46m",
31
+ white: "\x1B[47m"
32
+ }
33
+ };
34
+ const levels = [
35
+ "debug",
36
+ "info",
37
+ "success",
38
+ "warn",
39
+ "error"
40
+ ];
41
+ function shouldPublishLog(currentLogLevel, logLevel) {
42
+ return levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);
43
+ }
44
+ const levelColors = {
45
+ info: TTY_COLORS.fg.blue,
46
+ success: TTY_COLORS.fg.green,
47
+ warn: TTY_COLORS.fg.yellow,
48
+ error: TTY_COLORS.fg.red,
49
+ debug: TTY_COLORS.fg.magenta
50
+ };
51
+ const formatMessage = (level, message, colorsEnabled) => {
52
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
53
+ 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}`;
54
+ return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
55
+ };
56
+ const createLogger = (options) => {
57
+ const enabled = options?.disabled !== true;
58
+ const logLevel = options?.level ?? "error";
59
+ const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
60
+ const LogFunc = (level, message, args = []) => {
61
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
62
+ const formattedMessage = formatMessage(level, message, colorsEnabled);
63
+ if (!options || typeof options.log !== "function") {
64
+ if (level === "error") console.error(formattedMessage, ...args);
65
+ else if (level === "warn") console.warn(formattedMessage, ...args);
66
+ else console.log(formattedMessage, ...args);
67
+ return;
68
+ }
69
+ options.log(level === "success" ? "info" : level, message, ...args);
70
+ };
71
+ return {
72
+ ...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
73
+ get level() {
74
+ return logLevel;
75
+ }
76
+ };
77
+ };
78
+ const logger = createLogger();
79
+
80
+ //#endregion
81
+ export { TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
@@ -0,0 +1,48 @@
1
+ //#region src/error/codes.d.ts
2
+ declare const BASE_ERROR_CODES: {
3
+ readonly USER_NOT_FOUND: "User not found";
4
+ readonly FAILED_TO_CREATE_USER: "Failed to create user";
5
+ readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
6
+ readonly FAILED_TO_UPDATE_USER: "Failed to update user";
7
+ readonly FAILED_TO_GET_SESSION: "Failed to get session";
8
+ readonly INVALID_PASSWORD: "Invalid password";
9
+ readonly INVALID_EMAIL: "Invalid email";
10
+ readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
11
+ readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
12
+ readonly PROVIDER_NOT_FOUND: "Provider not found";
13
+ readonly INVALID_TOKEN: "Invalid token";
14
+ readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
15
+ readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
16
+ readonly USER_EMAIL_NOT_FOUND: "User email not found";
17
+ readonly EMAIL_NOT_VERIFIED: "Email not verified";
18
+ readonly PASSWORD_TOO_SHORT: "Password too short";
19
+ readonly PASSWORD_TOO_LONG: "Password too long";
20
+ readonly USER_ALREADY_EXISTS: "User already exists.";
21
+ readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
22
+ readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
23
+ readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
24
+ readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
25
+ readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
26
+ readonly ACCOUNT_NOT_FOUND: "Account not found";
27
+ readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
28
+ readonly CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Cross-site navigation login blocked. This request appears to be a CSRF attack.";
29
+ readonly VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled";
30
+ readonly EMAIL_ALREADY_VERIFIED: "Email is already verified";
31
+ readonly EMAIL_MISMATCH: "Email mismatch";
32
+ readonly SESSION_NOT_FRESH: "Session is not fresh";
33
+ readonly LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists";
34
+ readonly INVALID_ORIGIN: "Invalid origin";
35
+ readonly INVALID_CALLBACK_URL: "Invalid callbackURL";
36
+ readonly INVALID_REDIRECT_URL: "Invalid redirectURL";
37
+ readonly INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL";
38
+ readonly INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL";
39
+ readonly MISSING_OR_NULL_ORIGIN: "Missing or null Origin";
40
+ readonly CALLBACK_URL_REQUIRED: "callbackURL is required";
41
+ readonly FAILED_TO_CREATE_VERIFICATION: "Unable to create verification";
42
+ readonly FIELD_NOT_ALLOWED: "Field not allowed to be set";
43
+ readonly ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported";
44
+ readonly VALIDATION_ERROR: "Validation Error";
45
+ readonly MISSING_FIELD: "Field is required";
46
+ };
47
+ //#endregion
48
+ export { BASE_ERROR_CODES };
@@ -1,4 +1,5 @@
1
- import { i as defineErrorCodes } from "./utils-U2L7n92V.mjs";
1
+ import { defineErrorCodes } from "../utils/error-codes.mjs";
2
+ import "../utils/index.mjs";
2
3
 
3
4
  //#region src/error/codes.ts
4
5
  const BASE_ERROR_CODES = defineErrorCodes({
@@ -48,16 +49,4 @@ const BASE_ERROR_CODES = defineErrorCodes({
48
49
  });
49
50
 
50
51
  //#endregion
51
- //#region src/error/index.ts
52
- var BetterAuthError = class extends Error {
53
- constructor(message, cause) {
54
- super(message);
55
- this.name = "BetterAuthError";
56
- this.message = message;
57
- this.cause = cause;
58
- this.stack = "";
59
- }
60
- };
61
-
62
- //#endregion
63
- export { BASE_ERROR_CODES as n, BetterAuthError as t };
52
+ export { BASE_ERROR_CODES };
@@ -1,53 +1,10 @@
1
- //#region src/error/codes.d.ts
2
- declare const BASE_ERROR_CODES: {
3
- readonly USER_NOT_FOUND: "User not found";
4
- readonly FAILED_TO_CREATE_USER: "Failed to create user";
5
- readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
6
- readonly FAILED_TO_UPDATE_USER: "Failed to update user";
7
- readonly FAILED_TO_GET_SESSION: "Failed to get session";
8
- readonly INVALID_PASSWORD: "Invalid password";
9
- readonly INVALID_EMAIL: "Invalid email";
10
- readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
11
- readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
12
- readonly PROVIDER_NOT_FOUND: "Provider not found";
13
- readonly INVALID_TOKEN: "Invalid token";
14
- readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
15
- readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
16
- readonly USER_EMAIL_NOT_FOUND: "User email not found";
17
- readonly EMAIL_NOT_VERIFIED: "Email not verified";
18
- readonly PASSWORD_TOO_SHORT: "Password too short";
19
- readonly PASSWORD_TOO_LONG: "Password too long";
20
- readonly USER_ALREADY_EXISTS: "User already exists.";
21
- readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
22
- readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
23
- readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
24
- readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
25
- readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
26
- readonly ACCOUNT_NOT_FOUND: "Account not found";
27
- readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
28
- readonly CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Cross-site navigation login blocked. This request appears to be a CSRF attack.";
29
- readonly VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled";
30
- readonly EMAIL_ALREADY_VERIFIED: "Email is already verified";
31
- readonly EMAIL_MISMATCH: "Email mismatch";
32
- readonly SESSION_NOT_FRESH: "Session is not fresh";
33
- readonly LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists";
34
- readonly INVALID_ORIGIN: "Invalid origin";
35
- readonly INVALID_CALLBACK_URL: "Invalid callbackURL";
36
- readonly INVALID_REDIRECT_URL: "Invalid redirectURL";
37
- readonly INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL";
38
- readonly INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL";
39
- readonly MISSING_OR_NULL_ORIGIN: "Missing or null Origin";
40
- readonly CALLBACK_URL_REQUIRED: "callbackURL is required";
41
- readonly FAILED_TO_CREATE_VERIFICATION: "Unable to create verification";
42
- readonly FIELD_NOT_ALLOWED: "Field not allowed to be set";
43
- readonly ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported";
44
- readonly VALIDATION_ERROR: "Validation Error";
45
- readonly MISSING_FIELD: "Field is required";
46
- };
47
- //#endregion
1
+ import { BASE_ERROR_CODES } from "./codes.mjs";
2
+
48
3
  //#region src/error/index.d.ts
49
4
  declare class BetterAuthError extends Error {
50
- constructor(message: string, cause?: string | undefined);
5
+ constructor(message: string, options?: {
6
+ cause?: unknown | undefined;
7
+ });
51
8
  }
52
9
  //#endregion
53
10
  export { BASE_ERROR_CODES, BetterAuthError };
@@ -1,5 +1,14 @@
1
- import "../env-DbssmzoK.mjs";
2
- import "../utils-U2L7n92V.mjs";
3
- import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-DP1xOn7P.mjs";
1
+ import { BASE_ERROR_CODES } from "./codes.mjs";
4
2
 
3
+ //#region src/error/index.ts
4
+ var BetterAuthError = class extends Error {
5
+ constructor(message, options) {
6
+ super(message, options);
7
+ this.name = "BetterAuthError";
8
+ this.message = message;
9
+ this.stack = "";
10
+ }
11
+ };
12
+
13
+ //#endregion
5
14
  export { BASE_ERROR_CODES, BetterAuthError };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,8 @@
1
- import { An as BetterAuthCookies, _ as BetterAuthOptions, _r as Awaitable, b as BetterAuthPlugin, br as Prettify, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthAdvancedOptions, h as PluginContext, l as ClientAtomListener, m as InternalAdapter, o as StandardSchemaV1, p as GenericEndpointContext, s as BetterAuthClientOptions, u as ClientFetchOption, v as BetterAuthRateLimitOptions, vr as LiteralString, x as HookEndpointContext, xr as Primitive, y as GenerateIdFn, yr as LiteralUnion } from "./index-zgYuzZ7O.mjs";
2
- export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, StandardSchemaV1 };
1
+ import { Awaitable, LiteralString, LiteralUnion, Prettify, Primitive } from "./types/helper.mjs";
2
+ import { BetterAuthCookie, 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, GenericEndpointContext, InfoContext, 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";
8
+ export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, 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 };