@better-auth/core 1.4.0-beta.7 → 1.4.0-beta.8

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 (39) hide show
  1. package/.turbo/turbo-build.log +12 -4
  2. package/build.config.ts +2 -0
  3. package/dist/db/index.cjs +16 -0
  4. package/dist/db/index.d.cts +14 -3
  5. package/dist/db/index.d.mts +14 -3
  6. package/dist/db/index.d.ts +14 -3
  7. package/dist/db/index.mjs +16 -1
  8. package/dist/env/index.cjs +315 -0
  9. package/dist/env/index.d.cts +85 -0
  10. package/dist/env/index.d.mts +85 -0
  11. package/dist/env/index.d.ts +85 -0
  12. package/dist/env/index.mjs +300 -0
  13. package/dist/index.d.cts +2 -2
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/oauth2/index.cjs +368 -0
  17. package/dist/oauth2/index.d.cts +277 -0
  18. package/dist/oauth2/index.d.mts +277 -0
  19. package/dist/oauth2/index.d.ts +277 -0
  20. package/dist/oauth2/index.mjs +357 -0
  21. package/dist/shared/{core.CnvFgghY.d.cts → core.DeNN5HMO.d.cts} +27 -1
  22. package/dist/shared/{core.CnvFgghY.d.mts → core.DeNN5HMO.d.mts} +27 -1
  23. package/dist/shared/{core.CnvFgghY.d.ts → core.DeNN5HMO.d.ts} +27 -1
  24. package/package.json +29 -1
  25. package/src/db/index.ts +2 -0
  26. package/src/db/schema/rate-limit.ts +21 -0
  27. package/src/db/type.ts +28 -0
  28. package/src/env/color-depth.ts +171 -0
  29. package/src/env/env-impl.ts +123 -0
  30. package/src/env/index.ts +23 -0
  31. package/src/env/logger.test.ts +33 -0
  32. package/src/env/logger.ts +145 -0
  33. package/src/oauth2/client-credentials-token.ts +102 -0
  34. package/src/oauth2/create-authorization-url.ts +85 -0
  35. package/src/oauth2/index.ts +22 -0
  36. package/src/oauth2/oauth-provider.ts +194 -0
  37. package/src/oauth2/refresh-access-token.ts +124 -0
  38. package/src/oauth2/utils.ts +36 -0
  39. package/src/oauth2/validate-authorization-code.ts +156 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @better-auth/core@1.4.0-beta.7 build /home/runner/work/better-auth/better-auth/packages/core
2
+ > @better-auth/core@1.4.0-beta.8 build /home/runner/work/better-auth/better-auth/packages/core
3
3
  > unbuild --clean
4
4
 
5
5
  [info] Building core
@@ -13,15 +13,23 @@ Generated an empty chunk: "db/adapter/index".
13
13
 
14
14
  [log] dist/async_hooks/index.cjs (total size: 922 B, chunk size: 922 B, exports: getAsyncLocalStorage)
15
15
 
16
- [log] dist/db/index.cjs (total size: 2.09 kB, chunk size: 2.09 kB, exports: accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema)
16
+ [log] dist/env/index.cjs (total size: 8.71 kB, chunk size: 8.71 kB, exports: ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog)
17
+
18
+ [log] dist/oauth2/index.cjs (total size: 10.3 kB, chunk size: 10.3 kB, exports: clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken)
19
+
20
+ [log] dist/db/index.cjs (total size: 2.43 kB, chunk size: 2.43 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
17
21
 
18
22
  [log] dist/db/adapter/index.cjs (total size: 15 B, chunk size: 15 B)
19
23
  [log] dist/index.mjs (total size: 1 B, chunk size: 1 B)
20
24
 
21
25
  [log] dist/async_hooks/index.mjs (total size: 887 B, chunk size: 887 B, exports: getAsyncLocalStorage)
22
26
 
23
- [log] dist/db/index.mjs (total size: 1.4 kB, chunk size: 1.4 kB, exports: accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema)
27
+ [log] dist/env/index.mjs (total size: 8.42 kB, chunk size: 8.42 kB, exports: ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog)
28
+
29
+ [log] dist/oauth2/index.mjs (total size: 9.88 kB, chunk size: 9.88 kB, exports: clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken)
30
+
31
+ [log] dist/db/index.mjs (total size: 1.67 kB, chunk size: 1.67 kB, exports: accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema)
24
32
 
25
33
  [log] dist/db/adapter/index.mjs (total size: 1 B, chunk size: 1 B)
26
- Σ Total dist size (byte size): 41.9 kB
34
+ Σ Total dist size (byte size): 119 kB
27
35
  [log]
package/build.config.ts CHANGED
@@ -13,5 +13,7 @@ export default defineBuildConfig({
13
13
  "./src/db/index.ts",
14
14
  "./src/db/adapter/index.ts",
15
15
  "./src/async_hooks/index.ts",
16
+ "./src/env/index.ts",
17
+ "./src/oauth2/index.ts",
16
18
  ],
17
19
  });
package/dist/db/index.cjs CHANGED
@@ -68,8 +68,24 @@ const verificationSchema = coreSchema.extend({
68
68
  identifier: z__namespace.string()
69
69
  });
70
70
 
71
+ const rateLimitSchema = z__namespace.object({
72
+ /**
73
+ * The key to use for rate limiting
74
+ */
75
+ key: z__namespace.string(),
76
+ /**
77
+ * The number of requests made
78
+ */
79
+ count: z__namespace.number(),
80
+ /**
81
+ * The last request time in milliseconds
82
+ */
83
+ lastRequest: z__namespace.number()
84
+ });
85
+
71
86
  exports.accountSchema = accountSchema;
72
87
  exports.coreSchema = coreSchema;
88
+ exports.rateLimitSchema = rateLimitSchema;
73
89
  exports.sessionSchema = sessionSchema;
74
90
  exports.userSchema = userSchema;
75
91
  exports.verificationSchema = verificationSchema;
@@ -1,4 +1,5 @@
1
- import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.cjs';
1
+ import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.DeNN5HMO.cjs';
2
+ export { S as SecondaryStorage } from '../shared/core.DeNN5HMO.cjs';
2
3
  import * as z from 'zod';
3
4
 
4
5
  type BetterAuthPluginDBSchema = {
@@ -87,6 +88,16 @@ declare const verificationSchema: z.ZodObject<{
87
88
  */
88
89
  type Verification = z.infer<typeof verificationSchema>;
89
90
 
91
+ declare const rateLimitSchema: z.ZodObject<{
92
+ key: z.ZodString;
93
+ count: z.ZodNumber;
94
+ lastRequest: z.ZodNumber;
95
+ }, z.core.$strip>;
96
+ /**
97
+ * Rate limit schema type used by better-auth for rate limiting
98
+ */
99
+ type RateLimit = z.infer<typeof rateLimitSchema>;
100
+
90
101
  /**
91
102
  * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
92
103
  */
@@ -112,5 +123,5 @@ type Primitive = DBPrimitive;
112
123
  */
113
124
  type BetterAuthDbSchema = BetterAuthDBSchema;
114
125
 
115
- export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
116
- export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
126
+ export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
127
+ export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, RateLimit, Session, User, Verification };
@@ -1,4 +1,5 @@
1
- import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.mjs';
1
+ import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.DeNN5HMO.mjs';
2
+ export { S as SecondaryStorage } from '../shared/core.DeNN5HMO.mjs';
2
3
  import * as z from 'zod';
3
4
 
4
5
  type BetterAuthPluginDBSchema = {
@@ -87,6 +88,16 @@ declare const verificationSchema: z.ZodObject<{
87
88
  */
88
89
  type Verification = z.infer<typeof verificationSchema>;
89
90
 
91
+ declare const rateLimitSchema: z.ZodObject<{
92
+ key: z.ZodString;
93
+ count: z.ZodNumber;
94
+ lastRequest: z.ZodNumber;
95
+ }, z.core.$strip>;
96
+ /**
97
+ * Rate limit schema type used by better-auth for rate limiting
98
+ */
99
+ type RateLimit = z.infer<typeof rateLimitSchema>;
100
+
90
101
  /**
91
102
  * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
92
103
  */
@@ -112,5 +123,5 @@ type Primitive = DBPrimitive;
112
123
  */
113
124
  type BetterAuthDbSchema = BetterAuthDBSchema;
114
125
 
115
- export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
116
- export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
126
+ export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
127
+ export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, RateLimit, Session, User, Verification };
@@ -1,4 +1,5 @@
1
- import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CnvFgghY.js';
1
+ import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.DeNN5HMO.js';
2
+ export { S as SecondaryStorage } from '../shared/core.DeNN5HMO.js';
2
3
  import * as z from 'zod';
3
4
 
4
5
  type BetterAuthPluginDBSchema = {
@@ -87,6 +88,16 @@ declare const verificationSchema: z.ZodObject<{
87
88
  */
88
89
  type Verification = z.infer<typeof verificationSchema>;
89
90
 
91
+ declare const rateLimitSchema: z.ZodObject<{
92
+ key: z.ZodString;
93
+ count: z.ZodNumber;
94
+ lastRequest: z.ZodNumber;
95
+ }, z.core.$strip>;
96
+ /**
97
+ * Rate limit schema type used by better-auth for rate limiting
98
+ */
99
+ type RateLimit = z.infer<typeof rateLimitSchema>;
100
+
90
101
  /**
91
102
  * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
92
103
  */
@@ -112,5 +123,5 @@ type Primitive = DBPrimitive;
112
123
  */
113
124
  type BetterAuthDbSchema = BetterAuthDBSchema;
114
125
 
115
- export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
116
- export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, Session, User, Verification };
126
+ export { BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
127
+ export type { Account, AuthPluginSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive, RateLimit, Session, User, Verification };
package/dist/db/index.mjs CHANGED
@@ -52,4 +52,19 @@ const verificationSchema = coreSchema.extend({
52
52
  identifier: z.string()
53
53
  });
54
54
 
55
- export { accountSchema, coreSchema, sessionSchema, userSchema, verificationSchema };
55
+ const rateLimitSchema = z.object({
56
+ /**
57
+ * The key to use for rate limiting
58
+ */
59
+ key: z.string(),
60
+ /**
61
+ * The number of requests made
62
+ */
63
+ count: z.number(),
64
+ /**
65
+ * The last request time in milliseconds
66
+ */
67
+ lastRequest: z.number()
68
+ });
69
+
70
+ export { accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -0,0 +1,315 @@
1
+ 'use strict';
2
+
3
+ const _envShim = /* @__PURE__ */ Object.create(null);
4
+ const _getEnv = (useShim) => globalThis.process?.env || //@ts-expect-error
5
+ globalThis.Deno?.env.toObject() || //@ts-expect-error
6
+ globalThis.__env__ || (useShim ? _envShim : globalThis);
7
+ const env = new Proxy(_envShim, {
8
+ get(_, prop) {
9
+ const env2 = _getEnv();
10
+ return env2[prop] ?? _envShim[prop];
11
+ },
12
+ has(_, prop) {
13
+ const env2 = _getEnv();
14
+ return prop in env2 || prop in _envShim;
15
+ },
16
+ set(_, prop, value) {
17
+ const env2 = _getEnv(true);
18
+ env2[prop] = value;
19
+ return true;
20
+ },
21
+ deleteProperty(_, prop) {
22
+ if (!prop) {
23
+ return false;
24
+ }
25
+ const env2 = _getEnv(true);
26
+ delete env2[prop];
27
+ return true;
28
+ },
29
+ ownKeys() {
30
+ const env2 = _getEnv(true);
31
+ return Object.keys(env2);
32
+ }
33
+ });
34
+ function toBoolean(val) {
35
+ return val ? val !== "false" : false;
36
+ }
37
+ const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
38
+ const isProduction = nodeENV === "production";
39
+ const isDevelopment = nodeENV === "dev" || nodeENV === "development";
40
+ const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
41
+ function getEnvVar(key, fallback) {
42
+ if (typeof process !== "undefined" && process.env) {
43
+ return process.env[key] ?? fallback;
44
+ }
45
+ if (typeof Deno !== "undefined") {
46
+ return Deno.env.get(key) ?? fallback;
47
+ }
48
+ if (typeof Bun !== "undefined") {
49
+ return Bun.env[key] ?? fallback;
50
+ }
51
+ return fallback;
52
+ }
53
+ function getBooleanEnvVar(key, fallback = true) {
54
+ const value = getEnvVar(key);
55
+ if (!value) return fallback;
56
+ return value !== "0" && value.toLowerCase() !== "false" && value !== "";
57
+ }
58
+ const ENV = Object.freeze({
59
+ get BETTER_AUTH_SECRET() {
60
+ return getEnvVar("BETTER_AUTH_SECRET");
61
+ },
62
+ get AUTH_SECRET() {
63
+ return getEnvVar("AUTH_SECRET");
64
+ },
65
+ get BETTER_AUTH_TELEMETRY() {
66
+ return getEnvVar("BETTER_AUTH_TELEMETRY");
67
+ },
68
+ get BETTER_AUTH_TELEMETRY_ID() {
69
+ return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
70
+ },
71
+ get NODE_ENV() {
72
+ return getEnvVar("NODE_ENV", "development");
73
+ },
74
+ get PACKAGE_VERSION() {
75
+ return getEnvVar("PACKAGE_VERSION", "0.0.0");
76
+ },
77
+ get BETTER_AUTH_TELEMETRY_ENDPOINT() {
78
+ return getEnvVar(
79
+ "BETTER_AUTH_TELEMETRY_ENDPOINT",
80
+ "https://telemetry.better-auth.com/v1/track"
81
+ );
82
+ }
83
+ });
84
+
85
+ const COLORS_2 = 1;
86
+ const COLORS_16 = 4;
87
+ const COLORS_256 = 8;
88
+ const COLORS_16m = 24;
89
+ const TERM_ENVS = {
90
+ eterm: COLORS_16,
91
+ cons25: COLORS_16,
92
+ console: COLORS_16,
93
+ cygwin: COLORS_16,
94
+ dtterm: COLORS_16,
95
+ gnome: COLORS_16,
96
+ hurd: COLORS_16,
97
+ jfbterm: COLORS_16,
98
+ konsole: COLORS_16,
99
+ kterm: COLORS_16,
100
+ mlterm: COLORS_16,
101
+ mosh: COLORS_16m,
102
+ putty: COLORS_16,
103
+ st: COLORS_16,
104
+ // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
105
+ "rxvt-unicode-24bit": COLORS_16m,
106
+ // https://bugs.launchpad.net/terminator/+bug/1030562
107
+ terminator: COLORS_16m,
108
+ "xterm-kitty": COLORS_16m
109
+ };
110
+ const CI_ENVS_MAP = new Map(
111
+ Object.entries({
112
+ APPVEYOR: COLORS_256,
113
+ BUILDKITE: COLORS_256,
114
+ CIRCLECI: COLORS_16m,
115
+ DRONE: COLORS_256,
116
+ GITEA_ACTIONS: COLORS_16m,
117
+ GITHUB_ACTIONS: COLORS_16m,
118
+ GITLAB_CI: COLORS_256,
119
+ TRAVIS: COLORS_256
120
+ })
121
+ );
122
+ const TERM_ENVS_REG_EXP = [
123
+ /ansi/,
124
+ /color/,
125
+ /linux/,
126
+ /direct/,
127
+ /^con[0-9]*x[0-9]/,
128
+ /^rxvt/,
129
+ /^screen/,
130
+ /^xterm/,
131
+ /^vt100/,
132
+ /^vt220/
133
+ ];
134
+ function getColorDepth() {
135
+ if (getEnvVar("FORCE_COLOR") !== void 0) {
136
+ switch (getEnvVar("FORCE_COLOR")) {
137
+ case "":
138
+ case "1":
139
+ case "true":
140
+ return COLORS_16;
141
+ case "2":
142
+ return COLORS_256;
143
+ case "3":
144
+ return COLORS_16m;
145
+ default:
146
+ return COLORS_2;
147
+ }
148
+ }
149
+ if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || // See https://no-color.org/
150
+ getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || // The "dumb" special terminal, as defined by terminfo, doesn't support
151
+ // ANSI color control codes.
152
+ // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
153
+ getEnvVar("TERM") === "dumb") {
154
+ return COLORS_2;
155
+ }
156
+ if (typeof process !== "undefined" && process.platform === "win32") {
157
+ return COLORS_16m;
158
+ }
159
+ if (getEnvVar("TMUX")) {
160
+ return COLORS_16m;
161
+ }
162
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
163
+ return COLORS_16;
164
+ }
165
+ if ("CI" in env) {
166
+ for (const { 0: envName, 1: colors } of CI_ENVS_MAP) {
167
+ if (envName in env) {
168
+ return colors;
169
+ }
170
+ }
171
+ if (getEnvVar("CI_NAME") === "codeship") {
172
+ return COLORS_256;
173
+ }
174
+ return COLORS_2;
175
+ }
176
+ if ("TEAMCITY_VERSION" in env) {
177
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
178
+ getEnvVar("TEAMCITY_VERSION")
179
+ ) !== null ? COLORS_16 : COLORS_2;
180
+ }
181
+ switch (getEnvVar("TERM_PROGRAM")) {
182
+ case "iTerm.app":
183
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) {
184
+ return COLORS_256;
185
+ }
186
+ return COLORS_16m;
187
+ case "HyperTerm":
188
+ case "MacTerm":
189
+ return COLORS_16m;
190
+ case "Apple_Terminal":
191
+ return COLORS_256;
192
+ }
193
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") {
194
+ return COLORS_16m;
195
+ }
196
+ if (getEnvVar("TERM")) {
197
+ if (/truecolor/.exec(getEnvVar("TERM")) !== null) {
198
+ return COLORS_16m;
199
+ }
200
+ if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) {
201
+ return COLORS_256;
202
+ }
203
+ const termEnv = getEnvVar("TERM").toLowerCase();
204
+ if (TERM_ENVS[termEnv]) {
205
+ return TERM_ENVS[termEnv];
206
+ }
207
+ if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {
208
+ return COLORS_16;
209
+ }
210
+ }
211
+ if (getEnvVar("COLORTERM")) {
212
+ return COLORS_16;
213
+ }
214
+ return COLORS_2;
215
+ }
216
+
217
+ const TTY_COLORS = {
218
+ reset: "\x1B[0m",
219
+ bright: "\x1B[1m",
220
+ dim: "\x1B[2m",
221
+ undim: "\x1B[22m",
222
+ underscore: "\x1B[4m",
223
+ blink: "\x1B[5m",
224
+ reverse: "\x1B[7m",
225
+ hidden: "\x1B[8m",
226
+ fg: {
227
+ black: "\x1B[30m",
228
+ red: "\x1B[31m",
229
+ green: "\x1B[32m",
230
+ yellow: "\x1B[33m",
231
+ blue: "\x1B[34m",
232
+ magenta: "\x1B[35m",
233
+ cyan: "\x1B[36m",
234
+ white: "\x1B[37m"
235
+ },
236
+ bg: {
237
+ black: "\x1B[40m",
238
+ red: "\x1B[41m",
239
+ green: "\x1B[42m",
240
+ yellow: "\x1B[43m",
241
+ blue: "\x1B[44m",
242
+ magenta: "\x1B[45m",
243
+ cyan: "\x1B[46m",
244
+ white: "\x1B[47m"
245
+ }
246
+ };
247
+ const levels = ["info", "success", "warn", "error", "debug"];
248
+ function shouldPublishLog(currentLogLevel, logLevel) {
249
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
250
+ }
251
+ const levelColors = {
252
+ info: TTY_COLORS.fg.blue,
253
+ success: TTY_COLORS.fg.green,
254
+ warn: TTY_COLORS.fg.yellow,
255
+ error: TTY_COLORS.fg.red,
256
+ debug: TTY_COLORS.fg.magenta
257
+ };
258
+ const formatMessage = (level, message, colorsEnabled) => {
259
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
260
+ if (colorsEnabled) {
261
+ return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
262
+ }
263
+ return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
264
+ };
265
+ const createLogger = (options) => {
266
+ const enabled = options?.disabled !== true;
267
+ const logLevel = options?.level ?? "error";
268
+ const isDisableColorsSpecified = options?.disableColors !== void 0;
269
+ const colorsEnabled = isDisableColorsSpecified ? !options.disableColors : getColorDepth() !== 1;
270
+ const LogFunc = (level, message, args = []) => {
271
+ if (!enabled || !shouldPublishLog(logLevel, level)) {
272
+ return;
273
+ }
274
+ const formattedMessage = formatMessage(level, message, colorsEnabled);
275
+ if (!options || typeof options.log !== "function") {
276
+ if (level === "error") {
277
+ console.error(formattedMessage, ...args);
278
+ } else if (level === "warn") {
279
+ console.warn(formattedMessage, ...args);
280
+ } else {
281
+ console.log(formattedMessage, ...args);
282
+ }
283
+ return;
284
+ }
285
+ options.log(level === "success" ? "info" : level, message, ...args);
286
+ };
287
+ const logger2 = Object.fromEntries(
288
+ levels.map((level) => [
289
+ level,
290
+ (...[message, ...args]) => LogFunc(level, message, args)
291
+ ])
292
+ );
293
+ return {
294
+ ...logger2,
295
+ get level() {
296
+ return logLevel;
297
+ }
298
+ };
299
+ };
300
+ const logger = createLogger();
301
+
302
+ exports.ENV = ENV;
303
+ exports.TTY_COLORS = TTY_COLORS;
304
+ exports.createLogger = createLogger;
305
+ exports.env = env;
306
+ exports.getBooleanEnvVar = getBooleanEnvVar;
307
+ exports.getColorDepth = getColorDepth;
308
+ exports.getEnvVar = getEnvVar;
309
+ exports.isDevelopment = isDevelopment;
310
+ exports.isProduction = isProduction;
311
+ exports.isTest = isTest;
312
+ exports.levels = levels;
313
+ exports.logger = logger;
314
+ exports.nodeENV = nodeENV;
315
+ exports.shouldPublishLog = shouldPublishLog;
@@ -0,0 +1,85 @@
1
+ type EnvObject = Record<string, string | undefined>;
2
+ declare const env: EnvObject;
3
+ declare const nodeENV: string;
4
+ /** Detect if `NODE_ENV` environment variable is `production` */
5
+ declare const isProduction: boolean;
6
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
7
+ declare const isDevelopment: boolean;
8
+ /** Detect if `NODE_ENV` environment variable is `test` */
9
+ declare const isTest: () => boolean;
10
+ /**
11
+ * Get environment variable with fallback
12
+ */
13
+ declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
14
+ /**
15
+ * Get boolean environment variable
16
+ */
17
+ declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
18
+ /**
19
+ * Common environment variables used in Better Auth
20
+ */
21
+ declare const ENV: Readonly<{
22
+ readonly BETTER_AUTH_SECRET: string;
23
+ readonly AUTH_SECRET: string;
24
+ readonly BETTER_AUTH_TELEMETRY: string;
25
+ readonly BETTER_AUTH_TELEMETRY_ID: string;
26
+ readonly NODE_ENV: string;
27
+ readonly PACKAGE_VERSION: string;
28
+ readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
29
+ }>;
30
+
31
+ declare function getColorDepth(): number;
32
+
33
+ declare const TTY_COLORS: {
34
+ readonly reset: "\u001B[0m";
35
+ readonly bright: "\u001B[1m";
36
+ readonly dim: "\u001B[2m";
37
+ readonly undim: "\u001B[22m";
38
+ readonly underscore: "\u001B[4m";
39
+ readonly blink: "\u001B[5m";
40
+ readonly reverse: "\u001B[7m";
41
+ readonly hidden: "\u001B[8m";
42
+ readonly fg: {
43
+ readonly black: "\u001B[30m";
44
+ readonly red: "\u001B[31m";
45
+ readonly green: "\u001B[32m";
46
+ readonly yellow: "\u001B[33m";
47
+ readonly blue: "\u001B[34m";
48
+ readonly magenta: "\u001B[35m";
49
+ readonly cyan: "\u001B[36m";
50
+ readonly white: "\u001B[37m";
51
+ };
52
+ readonly bg: {
53
+ readonly black: "\u001B[40m";
54
+ readonly red: "\u001B[41m";
55
+ readonly green: "\u001B[42m";
56
+ readonly yellow: "\u001B[43m";
57
+ readonly blue: "\u001B[44m";
58
+ readonly magenta: "\u001B[45m";
59
+ readonly cyan: "\u001B[46m";
60
+ readonly white: "\u001B[47m";
61
+ };
62
+ };
63
+ type LogLevel = "info" | "success" | "warn" | "error" | "debug";
64
+ declare const levels: readonly ["info", "success", "warn", "error", "debug"];
65
+ declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
66
+ interface Logger {
67
+ disabled?: boolean;
68
+ disableColors?: boolean;
69
+ level?: Exclude<LogLevel, "success">;
70
+ log?: (level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void;
71
+ }
72
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
73
+ LogLevel,
74
+ ...infer Rest
75
+ ] ? Rest : never;
76
+ type InternalLogger = {
77
+ [K in LogLevel]: (...params: LogHandlerParams) => void;
78
+ } & {
79
+ get level(): LogLevel;
80
+ };
81
+ declare const createLogger: (options?: Logger) => InternalLogger;
82
+ declare const logger: InternalLogger;
83
+
84
+ export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
85
+ export type { EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger };
@@ -0,0 +1,85 @@
1
+ type EnvObject = Record<string, string | undefined>;
2
+ declare const env: EnvObject;
3
+ declare const nodeENV: string;
4
+ /** Detect if `NODE_ENV` environment variable is `production` */
5
+ declare const isProduction: boolean;
6
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
7
+ declare const isDevelopment: boolean;
8
+ /** Detect if `NODE_ENV` environment variable is `test` */
9
+ declare const isTest: () => boolean;
10
+ /**
11
+ * Get environment variable with fallback
12
+ */
13
+ declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
14
+ /**
15
+ * Get boolean environment variable
16
+ */
17
+ declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
18
+ /**
19
+ * Common environment variables used in Better Auth
20
+ */
21
+ declare const ENV: Readonly<{
22
+ readonly BETTER_AUTH_SECRET: string;
23
+ readonly AUTH_SECRET: string;
24
+ readonly BETTER_AUTH_TELEMETRY: string;
25
+ readonly BETTER_AUTH_TELEMETRY_ID: string;
26
+ readonly NODE_ENV: string;
27
+ readonly PACKAGE_VERSION: string;
28
+ readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
29
+ }>;
30
+
31
+ declare function getColorDepth(): number;
32
+
33
+ declare const TTY_COLORS: {
34
+ readonly reset: "\u001B[0m";
35
+ readonly bright: "\u001B[1m";
36
+ readonly dim: "\u001B[2m";
37
+ readonly undim: "\u001B[22m";
38
+ readonly underscore: "\u001B[4m";
39
+ readonly blink: "\u001B[5m";
40
+ readonly reverse: "\u001B[7m";
41
+ readonly hidden: "\u001B[8m";
42
+ readonly fg: {
43
+ readonly black: "\u001B[30m";
44
+ readonly red: "\u001B[31m";
45
+ readonly green: "\u001B[32m";
46
+ readonly yellow: "\u001B[33m";
47
+ readonly blue: "\u001B[34m";
48
+ readonly magenta: "\u001B[35m";
49
+ readonly cyan: "\u001B[36m";
50
+ readonly white: "\u001B[37m";
51
+ };
52
+ readonly bg: {
53
+ readonly black: "\u001B[40m";
54
+ readonly red: "\u001B[41m";
55
+ readonly green: "\u001B[42m";
56
+ readonly yellow: "\u001B[43m";
57
+ readonly blue: "\u001B[44m";
58
+ readonly magenta: "\u001B[45m";
59
+ readonly cyan: "\u001B[46m";
60
+ readonly white: "\u001B[47m";
61
+ };
62
+ };
63
+ type LogLevel = "info" | "success" | "warn" | "error" | "debug";
64
+ declare const levels: readonly ["info", "success", "warn", "error", "debug"];
65
+ declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
66
+ interface Logger {
67
+ disabled?: boolean;
68
+ disableColors?: boolean;
69
+ level?: Exclude<LogLevel, "success">;
70
+ log?: (level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void;
71
+ }
72
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
73
+ LogLevel,
74
+ ...infer Rest
75
+ ] ? Rest : never;
76
+ type InternalLogger = {
77
+ [K in LogLevel]: (...params: LogHandlerParams) => void;
78
+ } & {
79
+ get level(): LogLevel;
80
+ };
81
+ declare const createLogger: (options?: Logger) => InternalLogger;
82
+ declare const logger: InternalLogger;
83
+
84
+ export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
85
+ export type { EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger };