@gatwech/core 0.0.11 → 1.0.0-beta.19

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 (134) hide show
  1. package/dist/api/index.d.mts +2 -2
  2. package/dist/context/index.d.mts +2 -2
  3. package/dist/db/adapter/index.d.mts +2 -2
  4. package/dist/db/index.d.mts +2 -2
  5. package/dist/env/index.d.mts +1 -1
  6. package/dist/env/index.mjs +1 -1
  7. package/dist/{env-JMSMESs1.mjs → env-ubiqEEZm.mjs} +10 -9
  8. package/dist/error/index.mjs +2 -2
  9. package/dist/{error-41YsFQ8b.mjs → error-DKIIiFmH.mjs} +1 -1
  10. package/dist/{index-DLP-K0uY.d.mts → index-CNtOUpmF.d.mts} +4 -3
  11. package/dist/index-Df0KhQRf.d.mts +3002 -0
  12. package/dist/index.d.mts +3 -3
  13. package/dist/oauth2/index.d.mts +2 -2
  14. package/dist/social-providers/index.d.mts +3 -3
  15. package/dist/social-providers/index.mjs +73 -2414
  16. package/dist/src/api/index.d.ts +119 -0
  17. package/dist/src/async_hooks/index.d.ts +6 -0
  18. package/dist/src/context/endpoint-context.d.ts +14 -0
  19. package/dist/src/context/index.d.ts +3 -0
  20. package/dist/src/context/request-state.d.ts +13 -0
  21. package/dist/src/context/transaction.d.ts +11 -0
  22. package/dist/src/db/adapter/index.d.ts +401 -0
  23. package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
  24. package/dist/src/db/plugin.d.ts +10 -0
  25. package/dist/src/db/schema/account.d.ts +22 -0
  26. package/dist/src/db/schema/rate-limit.d.ts +10 -0
  27. package/dist/src/db/schema/session.d.ts +17 -0
  28. package/dist/src/db/schema/shared.d.ts +6 -0
  29. package/dist/src/db/schema/user.d.ts +16 -0
  30. package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
  31. package/dist/src/db/type.d.ts +159 -0
  32. package/dist/src/env/color-depth.d.ts +1 -0
  33. package/dist/src/env/env-impl.d.ts +29 -0
  34. package/dist/src/env/index.d.ts +3 -0
  35. package/dist/src/env/logger.d.ts +52 -0
  36. package/dist/src/error/codes.d.ts +27 -0
  37. package/dist/src/error/index.d.ts +4 -0
  38. package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
  39. package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
  40. package/dist/src/oauth2/index.d.ts +6 -0
  41. package/dist/src/oauth2/oauth-provider.d.ts +178 -0
  42. package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
  43. package/dist/src/oauth2/utils.d.ts +3 -0
  44. package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
  45. package/dist/src/social-providers/github.d.ts +89 -0
  46. package/dist/src/social-providers/google.d.ts +82 -0
  47. package/dist/src/social-providers/index.d.ts +93 -0
  48. package/dist/src/types/context.d.ts +177 -0
  49. package/dist/src/types/cookie.d.ts +15 -0
  50. package/dist/src/types/helper.d.ts +9 -0
  51. package/dist/src/types/index.d.ts +7 -0
  52. package/dist/src/types/init-options.d.ts +1140 -0
  53. package/dist/src/types/plugin-client.d.ts +88 -0
  54. package/dist/src/types/plugin.d.ts +120 -0
  55. package/dist/src/utils/error-codes.d.ts +9 -0
  56. package/dist/utils/index.mjs +1 -1
  57. package/package.json +11 -5
  58. package/.turbo/turbo-build.log +0 -42
  59. package/dist/index-DjrJweYn.d.mts +0 -7312
  60. package/src/api/index.ts +0 -57
  61. package/src/async_hooks/index.ts +0 -35
  62. package/src/context/endpoint-context.ts +0 -48
  63. package/src/context/index.ts +0 -21
  64. package/src/context/request-state.test.ts +0 -346
  65. package/src/context/request-state.ts +0 -75
  66. package/src/context/transaction.ts +0 -72
  67. package/src/db/adapter/index.ts +0 -466
  68. package/src/db/plugin.ts +0 -11
  69. package/src/db/schema/account.ts +0 -34
  70. package/src/db/schema/rate-limit.ts +0 -21
  71. package/src/db/schema/session.ts +0 -17
  72. package/src/db/schema/shared.ts +0 -7
  73. package/src/db/schema/user.ts +0 -16
  74. package/src/db/type.ts +0 -180
  75. package/src/env/color-depth.ts +0 -172
  76. package/src/env/env-impl.ts +0 -124
  77. package/src/env/index.ts +0 -23
  78. package/src/env/logger.test.ts +0 -33
  79. package/src/env/logger.ts +0 -145
  80. package/src/error/codes.ts +0 -31
  81. package/src/error/index.ts +0 -11
  82. package/src/oauth2/client-credentials-token.ts +0 -102
  83. package/src/oauth2/create-authorization-url.ts +0 -85
  84. package/src/oauth2/index.ts +0 -21
  85. package/src/oauth2/oauth-provider.ts +0 -211
  86. package/src/oauth2/refresh-access-token.ts +0 -124
  87. package/src/oauth2/utils.ts +0 -36
  88. package/src/oauth2/validate-authorization-code.ts +0 -154
  89. package/src/social-providers/apple.ts +0 -213
  90. package/src/social-providers/atlassian.ts +0 -132
  91. package/src/social-providers/cognito.ts +0 -269
  92. package/src/social-providers/discord.ts +0 -169
  93. package/src/social-providers/dropbox.ts +0 -112
  94. package/src/social-providers/facebook.ts +0 -204
  95. package/src/social-providers/figma.ts +0 -115
  96. package/src/social-providers/github.ts +0 -154
  97. package/src/social-providers/gitlab.ts +0 -152
  98. package/src/social-providers/google.ts +0 -171
  99. package/src/social-providers/huggingface.ts +0 -118
  100. package/src/social-providers/index.ts +0 -124
  101. package/src/social-providers/kakao.ts +0 -178
  102. package/src/social-providers/kick.ts +0 -92
  103. package/src/social-providers/line.ts +0 -169
  104. package/src/social-providers/linear.ts +0 -120
  105. package/src/social-providers/linkedin.ts +0 -110
  106. package/src/social-providers/microsoft-entra-id.ts +0 -245
  107. package/src/social-providers/naver.ts +0 -112
  108. package/src/social-providers/notion.ts +0 -108
  109. package/src/social-providers/paybin.ts +0 -122
  110. package/src/social-providers/paypal.ts +0 -263
  111. package/src/social-providers/polar.ts +0 -107
  112. package/src/social-providers/reddit.ts +0 -122
  113. package/src/social-providers/roblox.ts +0 -110
  114. package/src/social-providers/salesforce.ts +0 -159
  115. package/src/social-providers/slack.ts +0 -111
  116. package/src/social-providers/spotify.ts +0 -93
  117. package/src/social-providers/tiktok.ts +0 -210
  118. package/src/social-providers/twitch.ts +0 -111
  119. package/src/social-providers/twitter.ts +0 -198
  120. package/src/social-providers/vk.ts +0 -126
  121. package/src/social-providers/zoom.ts +0 -217
  122. package/src/types/context.ts +0 -269
  123. package/src/types/cookie.ts +0 -7
  124. package/src/types/helper.ts +0 -6
  125. package/src/types/index.ts +0 -21
  126. package/src/types/init-options.ts +0 -1346
  127. package/src/types/plugin-client.ts +0 -100
  128. package/src/types/plugin.ts +0 -158
  129. package/src/utils/error-codes.ts +0 -51
  130. package/tsconfig.json +0 -7
  131. package/tsdown.config.ts +0 -20
  132. /package/{src/index.ts → dist/src/index.d.ts} +0 -0
  133. /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
  134. /package/dist/{utils-BFQCAfNW.mjs → utils-CTOwq_Nj.mjs} +0 -0
package/src/db/type.ts DELETED
@@ -1,180 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- import type { LiteralString } from "../types";
3
-
4
- export type DBPreservedModels =
5
- | "user"
6
- | "account"
7
- | "session"
8
- | "verification"
9
- | "rate-limit"
10
- | "organization"
11
- | "member"
12
- | "invitation"
13
- | "jwks"
14
- | "passkey"
15
- | "two-factor";
16
-
17
- export type DBFieldType =
18
- | "string"
19
- | "number"
20
- | "boolean"
21
- | "date"
22
- | "json"
23
- | `${"string" | "number"}[]`
24
- | Array<LiteralString>;
25
-
26
- export type DBPrimitive =
27
- | string
28
- | number
29
- | boolean
30
- | Date
31
- | null
32
- | undefined
33
- | string[]
34
- | number[];
35
-
36
- export type DBFieldAttributeConfig = {
37
- /**
38
- * If the field should be required on a new record.
39
- * @default true
40
- */
41
- required?: boolean | undefined;
42
- /**
43
- * If the value should be returned on a response body.
44
- * @default true
45
- */
46
- returned?: boolean | undefined;
47
- /**
48
- * If a value should be provided when creating a new record.
49
- * @default true
50
- */
51
- input?: boolean | undefined;
52
- /**
53
- * Default value for the field
54
- *
55
- * Note: This will not create a default value on the database level. It will only
56
- * be used when creating a new record.
57
- */
58
- defaultValue?: (DBPrimitive | (() => DBPrimitive)) | undefined;
59
- /**
60
- * Update value for the field
61
- *
62
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
63
- * It will be called when updating a record.
64
- */
65
- onUpdate?: (() => DBPrimitive) | undefined;
66
- /**
67
- * transform the value before storing it.
68
- */
69
- transform?:
70
- | {
71
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
72
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
73
- }
74
- | undefined;
75
- /**
76
- * Reference to another model.
77
- */
78
- references?:
79
- | {
80
- /**
81
- * The model to reference.
82
- */
83
- model: string;
84
- /**
85
- * The field on the referenced model.
86
- */
87
- field: string;
88
- /**
89
- * The action to perform when the reference is deleted.
90
- * @default "cascade"
91
- */
92
- onDelete?:
93
- | "no action"
94
- | "restrict"
95
- | "cascade"
96
- | "set null"
97
- | "set default";
98
- }
99
- | undefined;
100
- unique?: boolean | undefined;
101
- /**
102
- * If the field should be a bigint on the database instead of integer.
103
- */
104
- bigint?: boolean | undefined;
105
- /**
106
- * A zod schema to validate the value.
107
- */
108
- validator?:
109
- | {
110
- input?: StandardSchemaV1;
111
- output?: StandardSchemaV1;
112
- }
113
- | undefined;
114
- /**
115
- * The name of the field on the database.
116
- */
117
- fieldName?: string | undefined;
118
- /**
119
- * If the field should be sortable.
120
- *
121
- * applicable only for `text` type.
122
- * It's useful to mark fields varchar instead of text.
123
- */
124
- sortable?: boolean | undefined;
125
- };
126
-
127
- export type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
128
- type: T;
129
- } & DBFieldAttributeConfig;
130
-
131
- export type PayvoAuthDBSchema = Record<
132
- string,
133
- {
134
- /**
135
- * The name of the table in the database
136
- */
137
- modelName: string;
138
- /**
139
- * The fields of the table
140
- */
141
- fields: Record<string, DBFieldAttribute>;
142
- /**
143
- * Whether to disable migrations for this table
144
- * @default false
145
- */
146
- disableMigrations?: boolean | undefined;
147
- /**
148
- * The order of the table
149
- */
150
- order?: number | undefined;
151
- }
152
- >;
153
-
154
- export interface SecondaryStorage {
155
- /**
156
- *
157
- * @param key - Key to get
158
- * @returns - Value of the key
159
- */
160
- get: (key: string) => Promise<unknown> | unknown;
161
- set: (
162
- /**
163
- * Key to store
164
- */
165
- key: string,
166
- /**
167
- * Value to store
168
- */
169
- value: string,
170
- /**
171
- * Time to live in seconds
172
- */
173
- ttl?: number | undefined
174
- ) => Promise<void | null | unknown> | void;
175
- /**
176
- *
177
- * @param key - Key to delete
178
- */
179
- delete: (key: string) => Promise<void | null | string> | void;
180
- }
@@ -1,172 +0,0 @@
1
- // Source code copied & modified from node internals: https://github.com/nodejs/node/blob/5b32bb1573dace2dd058c05ac4fab1e4e446c775/lib/internal/tty.js#L123
2
- import { env, getEnvVar } from "./env-impl";
3
-
4
- const COLORS_2 = 1;
5
- const COLORS_16 = 4;
6
- const COLORS_256 = 8;
7
- const COLORS_16m = 24;
8
-
9
- const TERM_ENVS: Record<string, number> = {
10
- eterm: COLORS_16,
11
- cons25: COLORS_16,
12
- console: COLORS_16,
13
- cygwin: COLORS_16,
14
- dtterm: COLORS_16,
15
- gnome: COLORS_16,
16
- hurd: COLORS_16,
17
- jfbterm: COLORS_16,
18
- konsole: COLORS_16,
19
- kterm: COLORS_16,
20
- mlterm: COLORS_16,
21
- mosh: COLORS_16m,
22
- putty: COLORS_16,
23
- st: COLORS_16,
24
- // http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html
25
- "rxvt-unicode-24bit": COLORS_16m,
26
- // https://bugs.launchpad.net/terminator/+bug/1030562
27
- terminator: COLORS_16m,
28
- "xterm-kitty": COLORS_16m,
29
- };
30
-
31
- const CI_ENVS_MAP = new Map(
32
- Object.entries({
33
- APPVEYOR: COLORS_256,
34
- BUILDKITE: COLORS_256,
35
- CIRCLECI: COLORS_16m,
36
- DRONE: COLORS_256,
37
- GITEA_ACTIONS: COLORS_16m,
38
- GITHUB_ACTIONS: COLORS_16m,
39
- GITLAB_CI: COLORS_256,
40
- TRAVIS: COLORS_256,
41
- }),
42
- );
43
-
44
- const TERM_ENVS_REG_EXP = [
45
- /ansi/,
46
- /color/,
47
- /linux/,
48
- /direct/,
49
- /^con[0-9]*x[0-9]/,
50
- /^rxvt/,
51
- /^screen/,
52
- /^xterm/,
53
- /^vt100/,
54
- /^vt220/,
55
- ];
56
-
57
- // The `getColorDepth` API got inspired by multiple sources such as
58
- // https://github.com/chalk/supports-color,
59
- // https://github.com/isaacs/color-support.
60
- export function getColorDepth(): number {
61
- // Use level 0-3 to support the same levels as `chalk` does. This is done for
62
- // consistency throughout the ecosystem.
63
- if (getEnvVar("FORCE_COLOR") !== undefined) {
64
- switch (getEnvVar("FORCE_COLOR")) {
65
- case "":
66
- case "1":
67
- case "true":
68
- return COLORS_16;
69
- case "2":
70
- return COLORS_256;
71
- case "3":
72
- return COLORS_16m;
73
- default:
74
- return COLORS_2;
75
- }
76
- }
77
-
78
- if (
79
- (getEnvVar("NODE_DISABLE_COLORS") !== undefined &&
80
- getEnvVar("NODE_DISABLE_COLORS") !== "") ||
81
- // See https://no-color.org/
82
- (getEnvVar("NO_COLOR") !== undefined && getEnvVar("NO_COLOR") !== "") ||
83
- // The "dumb" special terminal, as defined by terminfo, doesn't support
84
- // ANSI color control codes.
85
- // See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials
86
- getEnvVar("TERM") === "dumb"
87
- ) {
88
- return COLORS_2;
89
- }
90
-
91
- // Edge runtime doesn't support `process?.platform` syntax
92
- // if (typeof process !== "undefined" && process?.platform === "win32") {
93
- // // Windows 10 build 14931 (from 2016) has true color support
94
- // return COLORS_16m;
95
- // }
96
-
97
- if (getEnvVar("TMUX")) {
98
- return COLORS_16m;
99
- }
100
-
101
- // Azure DevOps
102
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
103
- return COLORS_16;
104
- }
105
-
106
- if ("CI" in env) {
107
- for (const { 0: envName, 1: colors } of CI_ENVS_MAP) {
108
- if (envName in env) {
109
- return colors;
110
- }
111
- }
112
- if (getEnvVar("CI_NAME") === "codeship") {
113
- return COLORS_256;
114
- }
115
- return COLORS_2;
116
- }
117
-
118
- if ("TEAMCITY_VERSION" in env) {
119
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(
120
- getEnvVar("TEAMCITY_VERSION"),
121
- ) !== null
122
- ? COLORS_16
123
- : COLORS_2;
124
- }
125
-
126
- switch (getEnvVar("TERM_PROGRAM")) {
127
- case "iTerm.app":
128
- if (
129
- !getEnvVar("TERM_PROGRAM_VERSION") ||
130
- /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null
131
- ) {
132
- return COLORS_256;
133
- }
134
- return COLORS_16m;
135
- case "HyperTerm":
136
- case "MacTerm":
137
- return COLORS_16m;
138
- case "Apple_Terminal":
139
- return COLORS_256;
140
- }
141
-
142
- if (
143
- getEnvVar("COLORTERM") === "truecolor" ||
144
- getEnvVar("COLORTERM") === "24bit"
145
- ) {
146
- return COLORS_16m;
147
- }
148
-
149
- if (getEnvVar("TERM")) {
150
- if (/truecolor/.exec(getEnvVar("TERM")) !== null) {
151
- return COLORS_16m;
152
- }
153
-
154
- if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) {
155
- return COLORS_256;
156
- }
157
-
158
- const termEnv = getEnvVar("TERM").toLowerCase();
159
-
160
- if (TERM_ENVS[termEnv]) {
161
- return TERM_ENVS[termEnv];
162
- }
163
- if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {
164
- return COLORS_16;
165
- }
166
- }
167
- // Move 16 color COLORTERM below 16m and 256
168
- if (getEnvVar("COLORTERM")) {
169
- return COLORS_16;
170
- }
171
- return COLORS_2;
172
- }
@@ -1,124 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="bun" />
3
- //https://github.com/unjs/std-env/blob/main/src/env.ts
4
-
5
- const _envShim = Object.create(null);
6
-
7
- export type EnvObject = Record<string, string | undefined>;
8
-
9
- const _getEnv = (useShim?: boolean) =>
10
- globalThis.process?.env ||
11
- //@ts-expect-error
12
- globalThis.Deno?.env.toObject() ||
13
- //@ts-expect-error
14
- globalThis.__env__ ||
15
- (useShim ? _envShim : globalThis);
16
-
17
- export const env = new Proxy<EnvObject>(_envShim, {
18
- get(_, prop) {
19
- const env = _getEnv();
20
- return env[prop as any] ?? _envShim[prop];
21
- },
22
- has(_, prop) {
23
- const env = _getEnv();
24
- return prop in env || prop in _envShim;
25
- },
26
- set(_, prop, value) {
27
- const env = _getEnv(true);
28
- env[prop as any] = value;
29
- return true;
30
- },
31
- deleteProperty(_, prop) {
32
- if (!prop) {
33
- return false;
34
- }
35
- const env = _getEnv(true);
36
- delete env[prop as any];
37
- return true;
38
- },
39
- ownKeys() {
40
- const env = _getEnv(true);
41
- return Object.keys(env);
42
- },
43
- });
44
-
45
- function toBoolean(val: boolean | string | undefined) {
46
- return val ? val !== "false" : false;
47
- }
48
-
49
- export const nodeENV =
50
- (typeof process !== "undefined" && process.env && process.env.NODE_ENV) || "";
51
-
52
- /** Detect if `NODE_ENV` environment variable is `production` */
53
- export const isProduction = nodeENV === "production";
54
-
55
- /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
56
- export const isDevelopment = () =>
57
- nodeENV === "dev" || nodeENV === "development";
58
-
59
- /** Detect if `NODE_ENV` environment variable is `test` */
60
- export const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
61
-
62
- /**
63
- * Get environment variable with fallback
64
- */
65
- export function getEnvVar<Fallback extends string>(
66
- key: string,
67
- fallback?: Fallback
68
- ): Fallback extends string ? string : string | undefined {
69
- if (typeof process !== "undefined" && process.env) {
70
- return process.env[key] ?? (fallback as any);
71
- }
72
-
73
- // @ts-expect-error deno
74
- if (typeof Deno !== "undefined") {
75
- // @ts-expect-error deno
76
- return Deno.env.get(key) ?? (fallback as string);
77
- }
78
-
79
- // Handle Bun
80
- if (typeof Bun !== "undefined") {
81
- return Bun.env[key] ?? (fallback as string);
82
- }
83
-
84
- return fallback as any;
85
- }
86
-
87
- /**
88
- * Get boolean environment variable
89
- */
90
- export function getBooleanEnvVar(key: string, fallback = true): boolean {
91
- const value = getEnvVar(key);
92
- if (!value) return fallback;
93
- return value !== "0" && value.toLowerCase() !== "false" && value !== "";
94
- }
95
-
96
- /**
97
- * Common environment variables used in Better Auth
98
- */
99
- export const ENV = Object.freeze({
100
- get PAYVO_AUTH_SECRET() {
101
- return getEnvVar("PAYVO_AUTH_SECRET");
102
- },
103
- get AUTH_SECRET() {
104
- return getEnvVar("AUTH_SECRET");
105
- },
106
- get BETTER_AUTH_TELEMETRY() {
107
- return getEnvVar("BETTER_AUTH_TELEMETRY");
108
- },
109
- get BETTER_AUTH_TELEMETRY_ID() {
110
- return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
111
- },
112
- get NODE_ENV() {
113
- return getEnvVar("NODE_ENV", "development");
114
- },
115
- get PACKAGE_VERSION() {
116
- return getEnvVar("PACKAGE_VERSION", "0.0.0");
117
- },
118
- get PAYVO_AUTH_TELEMETRY_ENDPOINT() {
119
- return getEnvVar(
120
- "PAYVO_AUTH_TELEMETRY_ENDPOINT",
121
- "https://telemetry.payvo-auth.com/v1/track"
122
- );
123
- },
124
- });
package/src/env/index.ts DELETED
@@ -1,23 +0,0 @@
1
- export { getColorDepth } from "./color-depth";
2
- export {
3
- ENV,
4
- type EnvObject,
5
- env,
6
- getBooleanEnvVar,
7
- getEnvVar,
8
- isDevelopment,
9
- isProduction,
10
- isTest,
11
- nodeENV,
12
- } from "./env-impl";
13
- export {
14
- createLogger,
15
- type InternalLogger,
16
- type Logger,
17
- type LogHandlerParams,
18
- type LogLevel,
19
- levels,
20
- logger,
21
- shouldPublishLog,
22
- TTY_COLORS,
23
- } from "./logger";
@@ -1,33 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { type LogLevel, shouldPublishLog } from "./logger";
3
-
4
- describe("shouldPublishLog", () => {
5
- const testCases: {
6
- currentLogLevel: LogLevel;
7
- logLevel: LogLevel;
8
- expected: boolean;
9
- }[] = [
10
- { currentLogLevel: "info", logLevel: "info", expected: true },
11
- { currentLogLevel: "info", logLevel: "warn", expected: false },
12
- { currentLogLevel: "info", logLevel: "error", expected: false },
13
- { currentLogLevel: "info", logLevel: "debug", expected: false },
14
- { currentLogLevel: "warn", logLevel: "info", expected: true },
15
- { currentLogLevel: "warn", logLevel: "warn", expected: true },
16
- { currentLogLevel: "warn", logLevel: "error", expected: false },
17
- { currentLogLevel: "warn", logLevel: "debug", expected: false },
18
- { currentLogLevel: "error", logLevel: "info", expected: true },
19
- { currentLogLevel: "error", logLevel: "warn", expected: true },
20
- { currentLogLevel: "error", logLevel: "error", expected: true },
21
- { currentLogLevel: "error", logLevel: "debug", expected: false },
22
- { currentLogLevel: "debug", logLevel: "info", expected: true },
23
- { currentLogLevel: "debug", logLevel: "warn", expected: true },
24
- { currentLogLevel: "debug", logLevel: "error", expected: true },
25
- { currentLogLevel: "debug", logLevel: "debug", expected: true },
26
- ];
27
-
28
- testCases.forEach(({ currentLogLevel, logLevel, expected }) => {
29
- it(`should return "${expected}" when currentLogLevel is "${currentLogLevel}" and logLevel is "${logLevel}"`, () => {
30
- expect(shouldPublishLog(currentLogLevel, logLevel)).toBe(expected);
31
- });
32
- });
33
- });
package/src/env/logger.ts DELETED
@@ -1,145 +0,0 @@
1
- import { getColorDepth } from "./color-depth";
2
-
3
- export const TTY_COLORS = {
4
- reset: "\x1b[0m",
5
- bright: "\x1b[1m",
6
- dim: "\x1b[2m",
7
- undim: "\x1b[22m",
8
- underscore: "\x1b[4m",
9
- blink: "\x1b[5m",
10
- reverse: "\x1b[7m",
11
- hidden: "\x1b[8m",
12
- fg: {
13
- black: "\x1b[30m",
14
- red: "\x1b[31m",
15
- green: "\x1b[32m",
16
- yellow: "\x1b[33m",
17
- blue: "\x1b[34m",
18
- magenta: "\x1b[35m",
19
- cyan: "\x1b[36m",
20
- white: "\x1b[37m",
21
- },
22
- bg: {
23
- black: "\x1b[40m",
24
- red: "\x1b[41m",
25
- green: "\x1b[42m",
26
- yellow: "\x1b[43m",
27
- blue: "\x1b[44m",
28
- magenta: "\x1b[45m",
29
- cyan: "\x1b[46m",
30
- white: "\x1b[47m",
31
- },
32
- } as const;
33
-
34
- export type LogLevel = "info" | "success" | "warn" | "error" | "debug";
35
-
36
- export const levels = ["info", "success", "warn", "error", "debug"] as const;
37
-
38
- export function shouldPublishLog(
39
- currentLogLevel: LogLevel,
40
- logLevel: LogLevel
41
- ): boolean {
42
- return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
43
- }
44
-
45
- export interface Logger {
46
- disabled?: boolean | undefined;
47
- disableColors?: boolean | undefined;
48
- level?: Exclude<LogLevel, "success"> | undefined;
49
- log?:
50
- | ((
51
- level: Exclude<LogLevel, "success">,
52
- message: string,
53
- ...args: any[]
54
- ) => void)
55
- | undefined;
56
- }
57
-
58
- export type LogHandlerParams =
59
- Parameters<NonNullable<Logger["log"]>> extends [LogLevel, ...infer Rest]
60
- ? Rest
61
- : never;
62
-
63
- const levelColors: Record<LogLevel, string> = {
64
- info: TTY_COLORS.fg.blue,
65
- success: TTY_COLORS.fg.green,
66
- warn: TTY_COLORS.fg.yellow,
67
- error: TTY_COLORS.fg.red,
68
- debug: TTY_COLORS.fg.magenta,
69
- };
70
-
71
- const formatMessage = (
72
- level: LogLevel,
73
- message: string,
74
- colorsEnabled: boolean
75
- ): string => {
76
- const timestamp = new Date().toISOString();
77
-
78
- if (colorsEnabled) {
79
- return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${
80
- levelColors[level]
81
- }${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${
82
- TTY_COLORS.reset
83
- } ${message}`;
84
- }
85
-
86
- return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
87
- };
88
-
89
- export type InternalLogger = {
90
- [K in LogLevel]: (...params: LogHandlerParams) => void;
91
- } & {
92
- get level(): LogLevel;
93
- };
94
-
95
- export const createLogger = (options?: Logger | undefined): InternalLogger => {
96
- const enabled = options?.disabled !== true;
97
- const logLevel = options?.level ?? "error";
98
-
99
- const isDisableColorsSpecified = options?.disableColors !== undefined;
100
- const colorsEnabled = isDisableColorsSpecified
101
- ? !options.disableColors
102
- : getColorDepth() !== 1;
103
-
104
- const LogFunc = (
105
- level: LogLevel,
106
- message: string,
107
- args: any[] = []
108
- ): void => {
109
- if (!enabled || !shouldPublishLog(logLevel, level)) {
110
- return;
111
- }
112
-
113
- const formattedMessage = formatMessage(level, message, colorsEnabled);
114
-
115
- if (!options || typeof options.log !== "function") {
116
- if (level === "error") {
117
- console.error(formattedMessage, ...args);
118
- } else if (level === "warn") {
119
- console.warn(formattedMessage, ...args);
120
- } else {
121
- console.log(formattedMessage, ...args);
122
- }
123
- return;
124
- }
125
-
126
- options.log(level === "success" ? "info" : level, message, ...args);
127
- };
128
-
129
- const logger = Object.fromEntries(
130
- levels.map((level) => [
131
- level,
132
- (...[message, ...args]: LogHandlerParams) =>
133
- LogFunc(level, message, args),
134
- ])
135
- ) as Record<LogLevel, (...params: LogHandlerParams) => void>;
136
-
137
- return {
138
- ...logger,
139
- get level() {
140
- return logLevel;
141
- },
142
- };
143
- };
144
-
145
- export const logger = createLogger();
@@ -1,31 +0,0 @@
1
- import { defineErrorCodes } from "../utils";
2
-
3
- export 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:
23
- "User already exists. Use another email.",
24
- EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
25
- CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
26
- SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
27
- FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
28
- ACCOUNT_NOT_FOUND: "Account not found",
29
- USER_ALREADY_HAS_PASSWORD:
30
- "User already has a password. Provide that to delete the account.",
31
- });