@better-auth/core 1.3.28 → 1.4.0-beta.11

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 (157) hide show
  1. package/.turbo/turbo-build.log +81 -76
  2. package/dist/api/index.cjs +30 -0
  3. package/dist/api/index.d.cts +7 -0
  4. package/dist/api/index.d.ts +7 -0
  5. package/dist/api/index.js +26 -0
  6. package/dist/async_hooks/index.cjs +2 -26
  7. package/dist/async_hooks/index.d.cts +4 -7
  8. package/dist/async_hooks/index.d.ts +4 -7
  9. package/dist/async_hooks/index.js +3 -0
  10. package/dist/async_hooks-CaXONcb9.cjs +24 -0
  11. package/dist/async_hooks-CkLtIFa6.js +18 -0
  12. package/dist/chunk-CUT6urMc.cjs +30 -0
  13. package/dist/context/index.cjs +8 -0
  14. package/dist/context/index.d.cts +17 -0
  15. package/dist/context/index.d.ts +17 -0
  16. package/dist/context/index.js +4 -0
  17. package/dist/context-DAu9ytQl.cjs +85 -0
  18. package/dist/context-rhoB1CVr.js +56 -0
  19. package/dist/db/adapter/index.cjs +0 -2
  20. package/dist/db/adapter/index.d.cts +7 -14
  21. package/dist/db/adapter/index.d.ts +7 -14
  22. package/dist/db/adapter/index.js +1 -0
  23. package/dist/db/index.cjs +46 -69
  24. package/dist/db/index.d.cts +3 -39
  25. package/dist/db/index.d.ts +3 -39
  26. package/dist/db/index.js +61 -0
  27. package/dist/env/index.cjs +15 -311
  28. package/dist/env/index.d.cts +2 -36
  29. package/dist/env/index.d.ts +2 -36
  30. package/dist/env/index.js +3 -0
  31. package/dist/env-D1OdwBk9.cjs +330 -0
  32. package/dist/env-DzHiLVFb.js +246 -0
  33. package/dist/error/index.cjs +4 -43
  34. package/dist/error/index.d.cts +31 -29
  35. package/dist/error/index.d.ts +31 -29
  36. package/dist/error/index.js +4 -0
  37. package/dist/error-H6U5qGNP.js +45 -0
  38. package/dist/error-k9KM7GAb.cjs +56 -0
  39. package/dist/helper-DVgWo5zB.d.cts +6 -0
  40. package/dist/helper-Dm5AtPVS.d.ts +6 -0
  41. package/dist/index-BPsqLi68.d.ts +4410 -0
  42. package/dist/index-CgIE2ECh.d.cts +262 -0
  43. package/dist/index-ChlC5Vy3.d.ts +344 -0
  44. package/dist/index-Cmh0x42V.d.ts +262 -0
  45. package/dist/index-CsHMVqbX.d.ts +82 -0
  46. package/dist/index-DFwrZMma.d.cts +82 -0
  47. package/dist/index-OrTFOyAG.d.ts +1871 -0
  48. package/dist/index-_Oiv-VVr.d.cts +344 -0
  49. package/dist/index-ehsSkBxt.d.cts +4410 -0
  50. package/dist/index-yBChAjSS.d.cts +1871 -0
  51. package/dist/index.cjs +0 -2
  52. package/dist/index.d.cts +7 -180
  53. package/dist/index.d.ts +7 -180
  54. package/dist/index.js +1 -0
  55. package/dist/oauth2/index.cjs +12 -368
  56. package/dist/oauth2/index.d.cts +3 -100
  57. package/dist/oauth2/index.d.ts +3 -100
  58. package/dist/oauth2/index.js +3 -0
  59. package/dist/oauth2-D_FUKfC8.js +239 -0
  60. package/dist/oauth2-DqX_pPhp.cjs +302 -0
  61. package/dist/social-providers/index.cjs +2262 -2645
  62. package/dist/social-providers/index.d.cts +4 -3903
  63. package/dist/social-providers/index.d.ts +4 -3903
  64. package/dist/social-providers/index.js +2370 -0
  65. package/dist/utils/index.cjs +2 -6
  66. package/dist/utils/index.d.cts +4 -5
  67. package/dist/utils/index.d.ts +4 -5
  68. package/dist/utils/index.js +3 -0
  69. package/dist/utils-Bs-jKit4.cjs +13 -0
  70. package/dist/utils-Sn10glI8.js +7 -0
  71. package/package.json +35 -25
  72. package/src/api/index.ts +57 -0
  73. package/src/async_hooks/index.ts +1 -9
  74. package/src/context/endpoint-context.ts +32 -0
  75. package/src/context/index.ts +6 -0
  76. package/src/context/transaction.ts +63 -0
  77. package/src/db/index.ts +2 -0
  78. package/src/db/type.ts +1 -10
  79. package/src/env/color-depth.ts +4 -5
  80. package/src/error/codes.ts +1 -1
  81. package/src/social-providers/apple.ts +2 -2
  82. package/src/social-providers/atlassian.ts +4 -7
  83. package/src/social-providers/cognito.ts +4 -7
  84. package/src/social-providers/discord.ts +2 -5
  85. package/src/social-providers/dropbox.ts +2 -2
  86. package/src/social-providers/facebook.ts +3 -6
  87. package/src/social-providers/figma.ts +4 -7
  88. package/src/social-providers/github.ts +2 -2
  89. package/src/social-providers/gitlab.ts +2 -2
  90. package/src/social-providers/google.ts +4 -7
  91. package/src/social-providers/huggingface.ts +2 -2
  92. package/src/social-providers/kakao.ts +2 -2
  93. package/src/social-providers/kick.ts +2 -5
  94. package/src/social-providers/line.ts +2 -2
  95. package/src/social-providers/linear.ts +2 -2
  96. package/src/social-providers/linkedin.ts +2 -2
  97. package/src/social-providers/microsoft-entra-id.ts +3 -3
  98. package/src/social-providers/naver.ts +2 -2
  99. package/src/social-providers/notion.ts +2 -2
  100. package/src/social-providers/paypal.ts +3 -3
  101. package/src/social-providers/reddit.ts +2 -2
  102. package/src/social-providers/roblox.ts +2 -5
  103. package/src/social-providers/salesforce.ts +4 -7
  104. package/src/social-providers/slack.ts +2 -5
  105. package/src/social-providers/spotify.ts +2 -2
  106. package/src/social-providers/tiktok.ts +2 -5
  107. package/src/social-providers/twitch.ts +3 -3
  108. package/src/social-providers/twitter.ts +2 -2
  109. package/src/social-providers/vk.ts +2 -5
  110. package/src/social-providers/zoom.ts +2 -5
  111. package/src/types/context.ts +20 -99
  112. package/src/types/index.ts +1 -1
  113. package/src/types/init-options.ts +20 -22
  114. package/src/types/plugin.ts +3 -3
  115. package/{build.config.ts → tsdown.config.ts} +8 -11
  116. package/dist/async_hooks/index.d.mts +0 -10
  117. package/dist/async_hooks/index.mjs +0 -25
  118. package/dist/db/adapter/index.d.mts +0 -14
  119. package/dist/db/adapter/index.mjs +0 -1
  120. package/dist/db/index.d.mts +0 -39
  121. package/dist/db/index.mjs +0 -70
  122. package/dist/env/index.d.mts +0 -36
  123. package/dist/env/index.mjs +0 -297
  124. package/dist/error/index.d.mts +0 -33
  125. package/dist/error/index.mjs +0 -41
  126. package/dist/index.d.mts +0 -180
  127. package/dist/index.mjs +0 -1
  128. package/dist/middleware/index.cjs +0 -25
  129. package/dist/middleware/index.d.cts +0 -14
  130. package/dist/middleware/index.d.mts +0 -14
  131. package/dist/middleware/index.d.ts +0 -14
  132. package/dist/middleware/index.mjs +0 -21
  133. package/dist/oauth2/index.d.mts +0 -100
  134. package/dist/oauth2/index.mjs +0 -357
  135. package/dist/shared/core.BJPBStdk.d.ts +0 -1693
  136. package/dist/shared/core.Bl6TpxyD.d.mts +0 -181
  137. package/dist/shared/core.Bqe5IGAi.d.ts +0 -13
  138. package/dist/shared/core.BwoNUcJQ.d.cts +0 -53
  139. package/dist/shared/core.BwoNUcJQ.d.mts +0 -53
  140. package/dist/shared/core.BwoNUcJQ.d.ts +0 -53
  141. package/dist/shared/core.CajxAutx.d.cts +0 -143
  142. package/dist/shared/core.CajxAutx.d.mts +0 -143
  143. package/dist/shared/core.CajxAutx.d.ts +0 -143
  144. package/dist/shared/core.CkkLHQWc.d.mts +0 -1693
  145. package/dist/shared/core.DkdZ1o38.d.ts +0 -181
  146. package/dist/shared/core.Dl-70uns.d.cts +0 -84
  147. package/dist/shared/core.Dl-70uns.d.mts +0 -84
  148. package/dist/shared/core.Dl-70uns.d.ts +0 -84
  149. package/dist/shared/core.DyEdx0m7.d.cts +0 -181
  150. package/dist/shared/core.E9DfzGLz.d.mts +0 -13
  151. package/dist/shared/core.HqYn20Fi.d.cts +0 -13
  152. package/dist/shared/core.gYIBmdi1.d.cts +0 -1693
  153. package/dist/social-providers/index.d.mts +0 -3903
  154. package/dist/social-providers/index.mjs +0 -2743
  155. package/dist/utils/index.d.mts +0 -10
  156. package/dist/utils/index.mjs +0 -5
  157. package/src/middleware/index.ts +0 -33
@@ -1,23 +1,20 @@
1
- import { defineBuildConfig } from "unbuild";
1
+ import { defineConfig } from "tsdown";
2
2
 
3
- export default defineBuildConfig({
4
- rollup: {
5
- emitCJS: true,
6
- },
7
- declaration: true,
8
- outDir: "dist",
9
- clean: true,
10
- failOnWarn: false,
11
- entries: [
3
+ export default defineConfig({
4
+ dts: true,
5
+ format: ["esm", "cjs"],
6
+ entry: [
12
7
  "./src/index.ts",
13
8
  "./src/db/index.ts",
14
9
  "./src/db/adapter/index.ts",
15
10
  "./src/async_hooks/index.ts",
11
+ "./src/context/index.ts",
16
12
  "./src/env/index.ts",
17
13
  "./src/oauth2/index.ts",
18
- "./src/middleware/index.ts",
14
+ "./src/api/index.ts",
19
15
  "./src/social-providers/index.ts",
20
16
  "./src/utils/index.ts",
21
17
  "./src/error/index.ts",
22
18
  ],
19
+ clean: true,
23
20
  });
@@ -1,10 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- export { AsyncLocalStorage } from 'node:async_hooks';
3
-
4
- /**
5
- * AsyncLocalStorage will be import directly in 1.5.x
6
- */
7
-
8
- declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
9
-
10
- export { getAsyncLocalStorage };
@@ -1,25 +0,0 @@
1
- let moduleName = "node:async_hooks";
2
- const AsyncLocalStoragePromise = import(
3
- /* @vite-ignore */
4
- /* webpackIgnore: true */
5
- moduleName
6
- ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
- if ("AsyncLocalStorage" in globalThis) {
8
- return globalThis.AsyncLocalStorage;
9
- }
10
- console.warn(
11
- "[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected."
12
- );
13
- console.warn(
14
- "[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler"
15
- );
16
- console.warn(
17
- "[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag"
18
- );
19
- throw err;
20
- });
21
- async function getAsyncLocalStorage() {
22
- return AsyncLocalStoragePromise;
23
- }
24
-
25
- export { getAsyncLocalStorage };
@@ -1,14 +0,0 @@
1
- import '../../shared/core.CajxAutx.mjs';
2
- export { C as CleanedWhere, j as CustomAdapter, i as DBAdapter, D as DBAdapterDebugLogOption, g as DBAdapterFactoryConfig, k as DBAdapterInstance, f as DBAdapterSchemaCreation, h as DBTransactionAdapter, W as Where } from '../../shared/core.CkkLHQWc.mjs';
3
- import 'zod';
4
- import 'kysely';
5
- import 'better-sqlite3';
6
- import 'better-call';
7
- import '../../shared/core.Dl-70uns.mjs';
8
- import 'bun:sqlite';
9
- import 'node:sqlite';
10
- import '../../social-providers/index.mjs';
11
- import '@better-auth/core/oauth2';
12
- import '../../shared/core.Bl6TpxyD.mjs';
13
- import '../../shared/core.BwoNUcJQ.mjs';
14
- import '@better-auth/core';
@@ -1 +0,0 @@
1
-
@@ -1,39 +0,0 @@
1
- import { D as DBFieldAttribute, b as DBFieldAttributeConfig, c as DBFieldType, d as DBPrimitive, B as BetterAuthDBSchema } from '../shared/core.CajxAutx.mjs';
2
- export { S as SecondaryStorage } from '../shared/core.CajxAutx.mjs';
3
- import { B as BetterAuthPluginDBSchema } from '../shared/core.E9DfzGLz.mjs';
4
- import * as z from 'zod';
5
- export { A as Account, R as RateLimit, S as Session, U as User, V as Verification, a as accountSchema, r as rateLimitSchema, s as sessionSchema, u as userSchema, v as verificationSchema } from '../shared/core.Dl-70uns.mjs';
6
-
7
- declare const coreSchema: z.ZodObject<{
8
- id: z.ZodString;
9
- createdAt: z.ZodDefault<z.ZodDate>;
10
- updatedAt: z.ZodDefault<z.ZodDate>;
11
- }, z.core.$strip>;
12
-
13
- /**
14
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
15
- */
16
- type AuthPluginSchema = BetterAuthPluginDBSchema;
17
- /**
18
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
19
- */
20
- type FieldAttribute = DBFieldAttribute;
21
- /**
22
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
23
- */
24
- type FieldAttributeConfig = DBFieldAttributeConfig;
25
- /**
26
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
27
- */
28
- type FieldType = DBFieldType;
29
- /**
30
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
31
- */
32
- type Primitive = DBPrimitive;
33
- /**
34
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
35
- */
36
- type BetterAuthDbSchema = BetterAuthDBSchema;
37
-
38
- export { BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, coreSchema };
39
- export type { AuthPluginSchema, BetterAuthDbSchema, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
package/dist/db/index.mjs DELETED
@@ -1,70 +0,0 @@
1
- import * as z from 'zod';
2
-
3
- const coreSchema = z.object({
4
- id: z.string(),
5
- createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
6
- updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
7
- });
8
-
9
- const userSchema = coreSchema.extend({
10
- email: z.string().transform((val) => val.toLowerCase()),
11
- emailVerified: z.boolean().default(false),
12
- name: z.string(),
13
- image: z.string().nullish()
14
- });
15
-
16
- const accountSchema = coreSchema.extend({
17
- providerId: z.string(),
18
- accountId: z.string(),
19
- userId: z.coerce.string(),
20
- accessToken: z.string().nullish(),
21
- refreshToken: z.string().nullish(),
22
- idToken: z.string().nullish(),
23
- /**
24
- * Access token expires at
25
- */
26
- accessTokenExpiresAt: z.date().nullish(),
27
- /**
28
- * Refresh token expires at
29
- */
30
- refreshTokenExpiresAt: z.date().nullish(),
31
- /**
32
- * The scopes that the user has authorized
33
- */
34
- scope: z.string().nullish(),
35
- /**
36
- * Password is only stored in the credential provider
37
- */
38
- password: z.string().nullish()
39
- });
40
-
41
- const sessionSchema = coreSchema.extend({
42
- userId: z.coerce.string(),
43
- expiresAt: z.date(),
44
- token: z.string(),
45
- ipAddress: z.string().nullish(),
46
- userAgent: z.string().nullish()
47
- });
48
-
49
- const verificationSchema = coreSchema.extend({
50
- value: z.string(),
51
- expiresAt: z.date(),
52
- identifier: z.string()
53
- });
54
-
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 };
@@ -1,36 +0,0 @@
1
- export { I as InternalLogger, d as LogHandlerParams, b as LogLevel, L as Logger, T as TTY_COLORS, c as createLogger, a as levels, l as logger, s as shouldPublishLog } from '../shared/core.BwoNUcJQ.mjs';
2
-
3
- type EnvObject = Record<string, string | undefined>;
4
- declare const env: EnvObject;
5
- declare const nodeENV: string;
6
- /** Detect if `NODE_ENV` environment variable is `production` */
7
- declare const isProduction: boolean;
8
- /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
9
- declare const isDevelopment: boolean;
10
- /** Detect if `NODE_ENV` environment variable is `test` */
11
- declare const isTest: () => boolean;
12
- /**
13
- * Get environment variable with fallback
14
- */
15
- declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
16
- /**
17
- * Get boolean environment variable
18
- */
19
- declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
20
- /**
21
- * Common environment variables used in Better Auth
22
- */
23
- declare const ENV: Readonly<{
24
- readonly BETTER_AUTH_SECRET: string;
25
- readonly AUTH_SECRET: string;
26
- readonly BETTER_AUTH_TELEMETRY: string;
27
- readonly BETTER_AUTH_TELEMETRY_ID: string;
28
- readonly NODE_ENV: string;
29
- readonly PACKAGE_VERSION: string;
30
- readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
31
- }>;
32
-
33
- declare function getColorDepth(): number;
34
-
35
- export { ENV, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
36
- export type { EnvObject };
@@ -1,297 +0,0 @@
1
- const _envShim = /* @__PURE__ */ Object.create(null);
2
- const _getEnv = (useShim) => globalThis.process?.env || //@ts-expect-error
3
- globalThis.Deno?.env.toObject() || //@ts-expect-error
4
- globalThis.__env__ || (useShim ? _envShim : globalThis);
5
- const env = new Proxy(_envShim, {
6
- get(_, prop) {
7
- const env2 = _getEnv();
8
- return env2[prop] ?? _envShim[prop];
9
- },
10
- has(_, prop) {
11
- const env2 = _getEnv();
12
- return prop in env2 || prop in _envShim;
13
- },
14
- set(_, prop, value) {
15
- const env2 = _getEnv(true);
16
- env2[prop] = value;
17
- return true;
18
- },
19
- deleteProperty(_, prop) {
20
- if (!prop) {
21
- return false;
22
- }
23
- const env2 = _getEnv(true);
24
- delete env2[prop];
25
- return true;
26
- },
27
- ownKeys() {
28
- const env2 = _getEnv(true);
29
- return Object.keys(env2);
30
- }
31
- });
32
- function toBoolean(val) {
33
- return val ? val !== "false" : false;
34
- }
35
- const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
36
- const isProduction = nodeENV === "production";
37
- const isDevelopment = nodeENV === "dev" || nodeENV === "development";
38
- const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
39
- function getEnvVar(key, fallback) {
40
- if (typeof process !== "undefined" && process.env) {
41
- return process.env[key] ?? fallback;
42
- }
43
- if (typeof Deno !== "undefined") {
44
- return Deno.env.get(key) ?? fallback;
45
- }
46
- if (typeof Bun !== "undefined") {
47
- return Bun.env[key] ?? fallback;
48
- }
49
- return fallback;
50
- }
51
- function getBooleanEnvVar(key, fallback = true) {
52
- const value = getEnvVar(key);
53
- if (!value) return fallback;
54
- return value !== "0" && value.toLowerCase() !== "false" && value !== "";
55
- }
56
- const ENV = Object.freeze({
57
- get BETTER_AUTH_SECRET() {
58
- return getEnvVar("BETTER_AUTH_SECRET");
59
- },
60
- get AUTH_SECRET() {
61
- return getEnvVar("AUTH_SECRET");
62
- },
63
- get BETTER_AUTH_TELEMETRY() {
64
- return getEnvVar("BETTER_AUTH_TELEMETRY");
65
- },
66
- get BETTER_AUTH_TELEMETRY_ID() {
67
- return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
68
- },
69
- get NODE_ENV() {
70
- return getEnvVar("NODE_ENV", "development");
71
- },
72
- get PACKAGE_VERSION() {
73
- return getEnvVar("PACKAGE_VERSION", "0.0.0");
74
- },
75
- get BETTER_AUTH_TELEMETRY_ENDPOINT() {
76
- return getEnvVar(
77
- "BETTER_AUTH_TELEMETRY_ENDPOINT",
78
- "https://telemetry.better-auth.com/v1/track"
79
- );
80
- }
81
- });
82
-
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
- // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
103
- "rxvt-unicode-24bit": COLORS_16m,
104
- // https://bugs.launchpad.net/terminator/+bug/1030562
105
- terminator: COLORS_16m,
106
- "xterm-kitty": COLORS_16m
107
- };
108
- const CI_ENVS_MAP = new Map(
109
- Object.entries({
110
- APPVEYOR: COLORS_256,
111
- BUILDKITE: COLORS_256,
112
- CIRCLECI: COLORS_16m,
113
- DRONE: COLORS_256,
114
- GITEA_ACTIONS: COLORS_16m,
115
- GITHUB_ACTIONS: COLORS_16m,
116
- GITLAB_CI: COLORS_256,
117
- TRAVIS: COLORS_256
118
- })
119
- );
120
- const TERM_ENVS_REG_EXP = [
121
- /ansi/,
122
- /color/,
123
- /linux/,
124
- /direct/,
125
- /^con[0-9]*x[0-9]/,
126
- /^rxvt/,
127
- /^screen/,
128
- /^xterm/,
129
- /^vt100/,
130
- /^vt220/
131
- ];
132
- function getColorDepth() {
133
- if (getEnvVar("FORCE_COLOR") !== void 0) {
134
- switch (getEnvVar("FORCE_COLOR")) {
135
- case "":
136
- case "1":
137
- case "true":
138
- return COLORS_16;
139
- case "2":
140
- return COLORS_256;
141
- case "3":
142
- return COLORS_16m;
143
- default:
144
- return COLORS_2;
145
- }
146
- }
147
- if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || // See https://no-color.org/
148
- getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || // The "dumb" special terminal, as defined by terminfo, doesn't support
149
- // ANSI color control codes.
150
- // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
151
- getEnvVar("TERM") === "dumb") {
152
- return COLORS_2;
153
- }
154
- if (getEnvVar("TMUX")) {
155
- return COLORS_16m;
156
- }
157
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
158
- return COLORS_16;
159
- }
160
- if ("CI" in env) {
161
- for (const { 0: envName, 1: colors } of CI_ENVS_MAP) {
162
- if (envName in env) {
163
- return colors;
164
- }
165
- }
166
- if (getEnvVar("CI_NAME") === "codeship") {
167
- return COLORS_256;
168
- }
169
- return COLORS_2;
170
- }
171
- if ("TEAMCITY_VERSION" in env) {
172
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
173
- getEnvVar("TEAMCITY_VERSION")
174
- ) !== null ? COLORS_16 : COLORS_2;
175
- }
176
- switch (getEnvVar("TERM_PROGRAM")) {
177
- case "iTerm.app":
178
- if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) {
179
- return COLORS_256;
180
- }
181
- return COLORS_16m;
182
- case "HyperTerm":
183
- case "MacTerm":
184
- return COLORS_16m;
185
- case "Apple_Terminal":
186
- return COLORS_256;
187
- }
188
- if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") {
189
- return COLORS_16m;
190
- }
191
- if (getEnvVar("TERM")) {
192
- if (/truecolor/.exec(getEnvVar("TERM")) !== null) {
193
- return COLORS_16m;
194
- }
195
- if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) {
196
- return COLORS_256;
197
- }
198
- const termEnv = getEnvVar("TERM").toLowerCase();
199
- if (TERM_ENVS[termEnv]) {
200
- return TERM_ENVS[termEnv];
201
- }
202
- if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {
203
- return COLORS_16;
204
- }
205
- }
206
- if (getEnvVar("COLORTERM")) {
207
- return COLORS_16;
208
- }
209
- return COLORS_2;
210
- }
211
-
212
- const TTY_COLORS = {
213
- reset: "\x1B[0m",
214
- bright: "\x1B[1m",
215
- dim: "\x1B[2m",
216
- undim: "\x1B[22m",
217
- underscore: "\x1B[4m",
218
- blink: "\x1B[5m",
219
- reverse: "\x1B[7m",
220
- hidden: "\x1B[8m",
221
- fg: {
222
- black: "\x1B[30m",
223
- red: "\x1B[31m",
224
- green: "\x1B[32m",
225
- yellow: "\x1B[33m",
226
- blue: "\x1B[34m",
227
- magenta: "\x1B[35m",
228
- cyan: "\x1B[36m",
229
- white: "\x1B[37m"
230
- },
231
- bg: {
232
- black: "\x1B[40m",
233
- red: "\x1B[41m",
234
- green: "\x1B[42m",
235
- yellow: "\x1B[43m",
236
- blue: "\x1B[44m",
237
- magenta: "\x1B[45m",
238
- cyan: "\x1B[46m",
239
- white: "\x1B[47m"
240
- }
241
- };
242
- const levels = ["info", "success", "warn", "error", "debug"];
243
- function shouldPublishLog(currentLogLevel, logLevel) {
244
- return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
245
- }
246
- const levelColors = {
247
- info: TTY_COLORS.fg.blue,
248
- success: TTY_COLORS.fg.green,
249
- warn: TTY_COLORS.fg.yellow,
250
- error: TTY_COLORS.fg.red,
251
- debug: TTY_COLORS.fg.magenta
252
- };
253
- const formatMessage = (level, message, colorsEnabled) => {
254
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
255
- if (colorsEnabled) {
256
- return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
257
- }
258
- return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
259
- };
260
- const createLogger = (options) => {
261
- const enabled = options?.disabled !== true;
262
- const logLevel = options?.level ?? "error";
263
- const isDisableColorsSpecified = options?.disableColors !== void 0;
264
- const colorsEnabled = isDisableColorsSpecified ? !options.disableColors : getColorDepth() !== 1;
265
- const LogFunc = (level, message, args = []) => {
266
- if (!enabled || !shouldPublishLog(logLevel, level)) {
267
- return;
268
- }
269
- const formattedMessage = formatMessage(level, message, colorsEnabled);
270
- if (!options || typeof options.log !== "function") {
271
- if (level === "error") {
272
- console.error(formattedMessage, ...args);
273
- } else if (level === "warn") {
274
- console.warn(formattedMessage, ...args);
275
- } else {
276
- console.log(formattedMessage, ...args);
277
- }
278
- return;
279
- }
280
- options.log(level === "success" ? "info" : level, message, ...args);
281
- };
282
- const logger2 = Object.fromEntries(
283
- levels.map((level) => [
284
- level,
285
- (...[message, ...args]) => LogFunc(level, message, args)
286
- ])
287
- );
288
- return {
289
- ...logger2,
290
- get level() {
291
- return logLevel;
292
- }
293
- };
294
- };
295
- const logger = createLogger();
296
-
297
- export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,33 +0,0 @@
1
- declare const BASE_ERROR_CODES: {
2
- readonly USER_NOT_FOUND: "User not found";
3
- readonly FAILED_TO_CREATE_USER: "Failed to create user";
4
- readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
5
- readonly FAILED_TO_UPDATE_USER: "Failed to update user";
6
- readonly FAILED_TO_GET_SESSION: "Failed to get session";
7
- readonly INVALID_PASSWORD: "Invalid password";
8
- readonly INVALID_EMAIL: "Invalid email";
9
- readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
10
- readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
11
- readonly PROVIDER_NOT_FOUND: "Provider not found";
12
- readonly INVALID_TOKEN: "Invalid token";
13
- readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
14
- readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
15
- readonly USER_EMAIL_NOT_FOUND: "User email not found";
16
- readonly EMAIL_NOT_VERIFIED: "Email not verified";
17
- readonly PASSWORD_TOO_SHORT: "Password too short";
18
- readonly PASSWORD_TOO_LONG: "Password too long";
19
- readonly USER_ALREADY_EXISTS: "User already exists.";
20
- readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
21
- readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
22
- readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
23
- readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
24
- readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
25
- readonly ACCOUNT_NOT_FOUND: "Account not found";
26
- readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
27
- };
28
-
29
- declare class BetterAuthError extends Error {
30
- constructor(message: string, cause?: string);
31
- }
32
-
33
- export { BASE_ERROR_CODES, BetterAuthError };
@@ -1,41 +0,0 @@
1
- import { defineErrorCodes } from '@better-auth/core/utils';
2
-
3
- const BASE_ERROR_CODES = defineErrorCodes({
4
- USER_NOT_FOUND: "User not found",
5
- FAILED_TO_CREATE_USER: "Failed to create user",
6
- FAILED_TO_CREATE_SESSION: "Failed to create session",
7
- FAILED_TO_UPDATE_USER: "Failed to update user",
8
- FAILED_TO_GET_SESSION: "Failed to get session",
9
- INVALID_PASSWORD: "Invalid password",
10
- INVALID_EMAIL: "Invalid email",
11
- INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
12
- SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
13
- PROVIDER_NOT_FOUND: "Provider not found",
14
- INVALID_TOKEN: "Invalid token",
15
- ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
16
- FAILED_TO_GET_USER_INFO: "Failed to get user info",
17
- USER_EMAIL_NOT_FOUND: "User email not found",
18
- EMAIL_NOT_VERIFIED: "Email not verified",
19
- PASSWORD_TOO_SHORT: "Password too short",
20
- PASSWORD_TOO_LONG: "Password too long",
21
- USER_ALREADY_EXISTS: "User already exists.",
22
- USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
23
- EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
24
- CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
25
- SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
26
- FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
27
- ACCOUNT_NOT_FOUND: "Account not found",
28
- USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account."
29
- });
30
-
31
- class BetterAuthError extends Error {
32
- constructor(message, cause) {
33
- super(message);
34
- this.name = "BetterAuthError";
35
- this.message = message;
36
- this.cause = cause;
37
- this.stack = "";
38
- }
39
- }
40
-
41
- export { BASE_ERROR_CODES, BetterAuthError };