@better-auth/core 1.5.0-beta.4 → 1.5.0-beta.6

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 (178) 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 +31 -0
  6. package/dist/context/index.d.mts +3 -52
  7. package/dist/context/index.mjs +3 -1
  8. package/dist/context/request-state.d.mts +27 -0
  9. package/dist/context/request-state.mjs +49 -0
  10. package/dist/context/transaction.d.mts +16 -0
  11. package/dist/context/transaction.mjs +52 -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 +9 -6
  163. package/src/context/endpoint-context.ts +11 -2
  164. package/src/context/index.ts +0 -29
  165. package/src/context/request-state.ts +8 -2
  166. package/src/context/transaction.ts +11 -2
  167. package/src/db/adapter/get-id-field.ts +1 -1
  168. package/src/error/codes.ts +1 -1
  169. package/src/oauth2/create-authorization-url.ts +1 -1
  170. package/src/oauth2/oauth-provider.ts +6 -0
  171. package/tsdown.config.ts +3 -1
  172. package/dist/context-BBNwughv.mjs +0 -133
  173. package/dist/env-DbssmzoK.mjs +0 -245
  174. package/dist/index-B5x_W0dM.d.mts +0 -8054
  175. package/dist/oauth2-BjWM15hm.mjs +0 -326
  176. package/dist/utils/index.mjs +0 -4
  177. package/dist/utils-puAL36Bz.mjs +0 -63
  178. package/src/utils/index.ts +0 -5
@@ -1,133 +0,0 @@
1
- import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
2
-
3
- //#region src/context/endpoint-context.ts
4
- let currentContextAsyncStorage = null;
5
- const ensureAsyncStorage$2 = async () => {
6
- if (!currentContextAsyncStorage) currentContextAsyncStorage = new (await (getAsyncLocalStorage()))();
7
- return currentContextAsyncStorage;
8
- };
9
- /**
10
- * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
11
- *
12
- * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
13
- */
14
- async function getCurrentAuthContextAsyncLocalStorage() {
15
- return ensureAsyncStorage$2();
16
- }
17
- async function getCurrentAuthContext() {
18
- const context = (await ensureAsyncStorage$2()).getStore();
19
- if (!context) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
20
- return context;
21
- }
22
- async function runWithEndpointContext(context, fn) {
23
- return (await ensureAsyncStorage$2()).run(context, fn);
24
- }
25
-
26
- //#endregion
27
- //#region src/context/request-state.ts
28
- let requestStateAsyncStorage = null;
29
- const ensureAsyncStorage$1 = async () => {
30
- if (!requestStateAsyncStorage) requestStateAsyncStorage = new (await (getAsyncLocalStorage()))();
31
- return requestStateAsyncStorage;
32
- };
33
- async function getRequestStateAsyncLocalStorage() {
34
- return ensureAsyncStorage$1();
35
- }
36
- async function hasRequestState() {
37
- return (await ensureAsyncStorage$1()).getStore() !== void 0;
38
- }
39
- async function getCurrentRequestState() {
40
- const store = (await ensureAsyncStorage$1()).getStore();
41
- if (!store) throw new Error("No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.");
42
- return store;
43
- }
44
- async function runWithRequestState(store, fn) {
45
- return (await ensureAsyncStorage$1()).run(store, fn);
46
- }
47
- function defineRequestState(initFn) {
48
- const ref = Object.freeze({});
49
- return {
50
- get ref() {
51
- return ref;
52
- },
53
- async get() {
54
- const store = await getCurrentRequestState();
55
- if (!store.has(ref)) {
56
- const initialValue = await initFn();
57
- store.set(ref, initialValue);
58
- return initialValue;
59
- }
60
- return store.get(ref);
61
- },
62
- async set(value) {
63
- (await getCurrentRequestState()).set(ref, value);
64
- }
65
- };
66
- }
67
-
68
- //#endregion
69
- //#region src/context/transaction.ts
70
- let currentAdapterAsyncStorage = null;
71
- const ensureAsyncStorage = async () => {
72
- if (!currentAdapterAsyncStorage) currentAdapterAsyncStorage = new (await (getAsyncLocalStorage()))();
73
- return currentAdapterAsyncStorage;
74
- };
75
- /**
76
- * This is for internal use only. Most users should use `getCurrentAdapter` instead.
77
- *
78
- * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
79
- */
80
- const getCurrentDBAdapterAsyncLocalStorage = async () => {
81
- return ensureAsyncStorage();
82
- };
83
- const getCurrentAdapter = async (fallback) => {
84
- return ensureAsyncStorage().then((als) => {
85
- return als.getStore() || fallback;
86
- }).catch(() => {
87
- return fallback;
88
- });
89
- };
90
- const runWithAdapter = async (adapter, fn) => {
91
- let called = true;
92
- return ensureAsyncStorage().then((als) => {
93
- called = true;
94
- return als.run(adapter, fn);
95
- }).catch((err) => {
96
- if (!called) return fn();
97
- throw err;
98
- });
99
- };
100
- const runWithTransaction = async (adapter, fn) => {
101
- let called = true;
102
- return ensureAsyncStorage().then((als) => {
103
- called = true;
104
- return adapter.transaction(async (trx) => {
105
- return als.run(trx, fn);
106
- });
107
- }).catch((err) => {
108
- if (!called) return fn();
109
- throw err;
110
- });
111
- };
112
-
113
- //#endregion
114
- //#region src/context/index.ts
115
- const glo = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
116
- const importIdentifier = "__ $BETTER_AUTH$ __";
117
- if (glo[importIdentifier] === true)
118
- /**
119
- * Dear reader of this message. Please take this seriously.
120
- *
121
- * If you see this message, make sure that you only import one version of Better Auth. In many cases,
122
- * your package manager installs two versions of Better Auth that are used by different packages within your project.
123
- *
124
- * This often leads to issues that are hard to debug. We often need to ensure async local storage instance,
125
- * If you imported different versions of Better Auth, it is impossible for us to
126
- * do status synchronization per request anymore - which might break the states.
127
- *
128
- */
129
- console.error("Better Auth was already imported. This breaks async local storage instance and will lead to issues!");
130
- glo[importIdentifier] = true;
131
-
132
- //#endregion
133
- export { defineRequestState as a, hasRequestState as c, getCurrentAuthContextAsyncLocalStorage as d, runWithEndpointContext as f, runWithTransaction as i, runWithRequestState as l, getCurrentDBAdapterAsyncLocalStorage as n, getCurrentRequestState as o, runWithAdapter as r, getRequestStateAsyncLocalStorage as s, getCurrentAdapter as t, getCurrentAuthContext as u };
@@ -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 };