@better-auth/core 1.4.12 → 1.4.14
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.
- package/.turbo/turbo-build.log +172 -35
- package/dist/api/index.d.mts +178 -1
- package/dist/api/index.mjs +2 -1
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +31 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +37 -0
- package/dist/context/index.d.mts +5 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +49 -0
- package/dist/context/transaction.d.mts +16 -0
- package/dist/context/transaction.mjs +52 -0
- package/dist/db/adapter/factory.d.mts +27 -0
- package/dist/db/adapter/factory.mjs +738 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +38 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +32 -0
- package/dist/db/adapter/get-field-attributes.d.mts +29 -0
- package/dist/db/adapter/get-field-attributes.mjs +39 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +33 -0
- package/dist/db/adapter/get-id-field.d.mts +39 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +23 -0
- package/dist/db/adapter/index.d.mts +513 -1
- package/dist/db/adapter/index.mjs +8 -970
- package/dist/db/adapter/types.d.mts +139 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +38 -0
- package/dist/db/get-tables.d.mts +8 -0
- package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +7 -1
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +26 -0
- package/dist/db/schema/account.mjs +19 -0
- package/dist/db/schema/rate-limit.d.mts +14 -0
- package/dist/db/schema/rate-limit.mjs +11 -0
- package/dist/db/schema/session.d.mts +21 -0
- package/dist/db/schema/session.mjs +14 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +11 -0
- package/dist/db/schema/user.d.mts +20 -0
- package/dist/db/schema/user.mjs +13 -0
- package/dist/db/schema/verification.d.mts +19 -0
- package/dist/db/schema/verification.mjs +12 -0
- package/dist/db/type.d.mts +143 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +88 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +82 -0
- package/dist/env/index.d.mts +4 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
- package/dist/env/logger.mjs +81 -0
- package/dist/error/codes.d.mts +48 -0
- package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
- package/dist/error/index.d.mts +5 -48
- package/dist/error/index.mjs +12 -3
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +36 -0
- package/dist/oauth2/client-credentials-token.mjs +54 -0
- package/dist/oauth2/create-authorization-url.d.mts +45 -0
- package/dist/oauth2/create-authorization-url.mjs +42 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +6 -2
- package/dist/oauth2/oauth-provider.d.mts +194 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +58 -0
- package/dist/oauth2/utils.d.mts +7 -0
- package/dist/oauth2/utils.mjs +27 -0
- package/dist/oauth2/validate-authorization-code.d.mts +55 -0
- package/dist/oauth2/validate-authorization-code.mjs +71 -0
- package/dist/oauth2/verify.d.mts +49 -0
- package/dist/oauth2/verify.mjs +95 -0
- package/dist/social-providers/apple.d.mts +119 -0
- package/dist/social-providers/apple.mjs +102 -0
- package/dist/social-providers/atlassian.d.mts +72 -0
- package/dist/social-providers/atlassian.mjs +83 -0
- package/dist/social-providers/cognito.d.mts +87 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/discord.d.mts +126 -0
- package/dist/social-providers/discord.mjs +64 -0
- package/dist/social-providers/dropbox.d.mts +71 -0
- package/dist/social-providers/dropbox.mjs +75 -0
- package/dist/social-providers/facebook.d.mts +81 -0
- package/dist/social-providers/facebook.mjs +120 -0
- package/dist/social-providers/figma.d.mts +63 -0
- package/dist/social-providers/figma.mjs +86 -0
- package/dist/social-providers/github.d.mts +104 -0
- package/dist/social-providers/github.mjs +80 -0
- package/dist/social-providers/gitlab.d.mts +125 -0
- package/dist/social-providers/gitlab.mjs +82 -0
- package/dist/social-providers/google.d.mts +99 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/huggingface.d.mts +85 -0
- package/dist/social-providers/huggingface.mjs +75 -0
- package/dist/social-providers/index.d.mts +1723 -1
- package/dist/social-providers/index.mjs +33 -2570
- package/dist/social-providers/kakao.d.mts +163 -0
- package/dist/social-providers/kakao.mjs +72 -0
- package/dist/social-providers/kick.d.mts +75 -0
- package/dist/social-providers/kick.mjs +71 -0
- package/dist/social-providers/line.d.mts +107 -0
- package/dist/social-providers/line.mjs +113 -0
- package/dist/social-providers/linear.d.mts +70 -0
- package/dist/social-providers/linear.mjs +88 -0
- package/dist/social-providers/linkedin.d.mts +69 -0
- package/dist/social-providers/linkedin.mjs +76 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +106 -0
- package/dist/social-providers/naver.d.mts +104 -0
- package/dist/social-providers/naver.mjs +67 -0
- package/dist/social-providers/notion.d.mts +66 -0
- package/dist/social-providers/notion.mjs +75 -0
- package/dist/social-providers/paybin.d.mts +73 -0
- package/dist/social-providers/paybin.mjs +85 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +144 -0
- package/dist/social-providers/polar.d.mts +76 -0
- package/dist/social-providers/polar.mjs +73 -0
- package/dist/social-providers/reddit.d.mts +64 -0
- package/dist/social-providers/reddit.mjs +83 -0
- package/dist/social-providers/roblox.d.mts +72 -0
- package/dist/social-providers/roblox.mjs +59 -0
- package/dist/social-providers/salesforce.d.mts +81 -0
- package/dist/social-providers/salesforce.mjs +91 -0
- package/dist/social-providers/slack.d.mts +85 -0
- package/dist/social-providers/slack.mjs +68 -0
- package/dist/social-providers/spotify.d.mts +65 -0
- package/dist/social-providers/spotify.mjs +71 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +62 -0
- package/dist/social-providers/twitch.d.mts +81 -0
- package/dist/social-providers/twitch.mjs +78 -0
- package/dist/social-providers/twitter.d.mts +140 -0
- package/dist/social-providers/twitter.mjs +87 -0
- package/dist/social-providers/vercel.d.mts +64 -0
- package/dist/social-providers/vercel.mjs +61 -0
- package/dist/social-providers/vk.d.mts +72 -0
- package/dist/social-providers/vk.mjs +83 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +72 -0
- package/dist/types/context.d.mts +215 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +8 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1272 -0
- package/dist/types/plugin-client.d.mts +103 -0
- package/dist/types/plugin.d.mts +121 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +17 -0
- package/dist/utils/error-codes.d.mts +9 -0
- package/dist/utils/error-codes.mjs +7 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +9 -0
- package/dist/utils/index.d.mts +5 -26
- package/dist/utils/index.mjs +5 -2
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +25 -0
- package/dist/utils/string.d.mts +4 -0
- package/dist/utils/string.mjs +7 -0
- package/package.json +3 -3
- package/src/context/endpoint-context.ts +7 -15
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +1 -0
- package/src/context/request-state.ts +7 -12
- package/src/context/transaction.ts +7 -16
- package/src/db/adapter/factory.ts +13 -13
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +2 -2
- package/src/db/get-tables.ts +6 -0
- package/src/error/index.ts +2 -3
- package/src/social-providers/figma.ts +5 -3
- package/src/social-providers/gitlab.ts +1 -1
- package/src/types/context.ts +137 -131
- package/src/types/cookie.ts +6 -4
- package/src/types/index.ts +2 -1
- package/src/types/init-options.ts +6 -0
- package/tsdown.config.ts +9 -0
- package/dist/context-BGZ8V6DD.mjs +0 -126
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-zgYuzZ7O.d.mts +0 -8020
- package/dist/oauth2-COJkghlT.mjs +0 -326
- package/dist/utils-U2L7n92V.mjs +0 -59
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
import { Prettify } from "../../types/helper.mjs";
|
|
3
|
+
import { CustomAdapter, DBAdapterFactoryConfig, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
|
|
4
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
5
|
+
import "../../types/index.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/db/adapter/types.d.ts
|
|
8
|
+
type AdapterFactoryOptions = {
|
|
9
|
+
config: AdapterFactoryConfig;
|
|
10
|
+
adapter: AdapterFactoryCustomizeAdapterCreator;
|
|
11
|
+
};
|
|
12
|
+
interface AdapterFactoryConfig extends Omit<DBAdapterFactoryConfig<BetterAuthOptions>, "transaction"> {
|
|
13
|
+
/**
|
|
14
|
+
* Execute multiple operations in a transaction.
|
|
15
|
+
*
|
|
16
|
+
* If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
|
|
17
|
+
*
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter) => Promise<R>) => Promise<R>)) | undefined;
|
|
21
|
+
}
|
|
22
|
+
type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
23
|
+
options: BetterAuthOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The schema of the user's Better-Auth instance.
|
|
26
|
+
*/
|
|
27
|
+
schema: BetterAuthDBSchema;
|
|
28
|
+
/**
|
|
29
|
+
* The debug log function.
|
|
30
|
+
*
|
|
31
|
+
* If the config has defined `debugLogs` as `false`, no logs will be shown.
|
|
32
|
+
*/
|
|
33
|
+
debugLog: (...args: unknown[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the model name which is expected to be saved in the database based on the user's schema.
|
|
36
|
+
*/
|
|
37
|
+
getModelName: (model: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
40
|
+
*/
|
|
41
|
+
getFieldName: ({
|
|
42
|
+
model,
|
|
43
|
+
field
|
|
44
|
+
}: {
|
|
45
|
+
model: string;
|
|
46
|
+
field: string;
|
|
47
|
+
}) => string;
|
|
48
|
+
/**
|
|
49
|
+
* This function helps us get the default model name from the schema defined by devs.
|
|
50
|
+
* Often times, the user will be using the `modelName` which could had been customized by the users.
|
|
51
|
+
* This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
|
|
52
|
+
*
|
|
53
|
+
* If it's still unclear what this does:
|
|
54
|
+
*
|
|
55
|
+
* 1. User can define a custom modelName.
|
|
56
|
+
* 2. When using a custom modelName, doing something like `schema[model]` will not work.
|
|
57
|
+
* 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
|
|
58
|
+
* 4. Thus allowing us to use `schema[model]`.
|
|
59
|
+
*/
|
|
60
|
+
getDefaultModelName: (model: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* This function helps us get the default field name from the schema defined by devs.
|
|
63
|
+
* Often times, the user will be using the `fieldName` which could had been customized by the users.
|
|
64
|
+
* This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
|
|
65
|
+
*
|
|
66
|
+
* If it's still unclear what this does:
|
|
67
|
+
*
|
|
68
|
+
* 1. User can define a custom fieldName.
|
|
69
|
+
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
getDefaultFieldName: ({
|
|
73
|
+
model,
|
|
74
|
+
field
|
|
75
|
+
}: {
|
|
76
|
+
model: string;
|
|
77
|
+
field: string;
|
|
78
|
+
}) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the field attributes for a given model and field.
|
|
81
|
+
*
|
|
82
|
+
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
83
|
+
*/
|
|
84
|
+
getFieldAttributes: ({
|
|
85
|
+
model,
|
|
86
|
+
field
|
|
87
|
+
}: {
|
|
88
|
+
model: string;
|
|
89
|
+
field: string;
|
|
90
|
+
}) => DBFieldAttribute;
|
|
91
|
+
transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
|
|
92
|
+
transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
|
|
93
|
+
transformWhereClause: <W extends Where[] | undefined>({
|
|
94
|
+
model,
|
|
95
|
+
where,
|
|
96
|
+
action
|
|
97
|
+
}: {
|
|
98
|
+
where: W;
|
|
99
|
+
model: string;
|
|
100
|
+
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "count";
|
|
101
|
+
}) => W extends undefined ? undefined : CleanedWhere[];
|
|
102
|
+
}) => CustomAdapter$1;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use `CustomAdapter` from `@better-auth/core/db/adapter` instead.
|
|
105
|
+
*/
|
|
106
|
+
interface CustomAdapter$1 extends Omit<CustomAdapter, "createSchema"> {
|
|
107
|
+
createSchema?: ((props: {
|
|
108
|
+
/**
|
|
109
|
+
* The file the user may have passed in to the `generate` command as the expected schema file output path.
|
|
110
|
+
*/
|
|
111
|
+
file?: string;
|
|
112
|
+
/**
|
|
113
|
+
* The tables from the user's Better-Auth instance schema.
|
|
114
|
+
*/
|
|
115
|
+
tables: BetterAuthDBSchema;
|
|
116
|
+
}) => Promise<DBAdapterSchemaCreation>) | undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use `CleanedWhere` from `@better-auth/core/db/adapter` instead.
|
|
120
|
+
*/
|
|
121
|
+
type CleanedWhere = Prettify<Required<Where>>;
|
|
122
|
+
type AdapterTestDebugLogs = {
|
|
123
|
+
resetDebugLogs: () => void;
|
|
124
|
+
printDebugLogs: () => void;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `AdapterFactoryOptions` instead. This export will be removed in a future version.
|
|
128
|
+
*/
|
|
129
|
+
type CreateAdapterOptions = AdapterFactoryOptions;
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated Use `AdapterFactoryConfig` instead. This export will be removed in a future version.
|
|
132
|
+
*/
|
|
133
|
+
type AdapterConfig = AdapterFactoryConfig;
|
|
134
|
+
/**
|
|
135
|
+
* @deprecated Use `AdapterFactoryCustomizeAdapterCreator` instead. This export will be removed in a future version.
|
|
136
|
+
*/
|
|
137
|
+
type CreateCustomAdapter = AdapterFactoryCustomizeAdapterCreator;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter$1 as CustomAdapter };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/adapter/utils.d.ts
|
|
4
|
+
declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
|
|
5
|
+
declare function deepmerge<T>(target: T, source: Partial<T>): T;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { deepmerge, withApplyDefault };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/db/adapter/utils.ts
|
|
2
|
+
function withApplyDefault(value, field, action) {
|
|
3
|
+
if (action === "update") {
|
|
4
|
+
if (value === void 0 && field.onUpdate !== void 0) {
|
|
5
|
+
if (typeof field.onUpdate === "function") return field.onUpdate();
|
|
6
|
+
return field.onUpdate;
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (action === "create") {
|
|
11
|
+
if (value === void 0 || field.required === true && value === null) {
|
|
12
|
+
if (field.defaultValue !== void 0) {
|
|
13
|
+
if (typeof field.defaultValue === "function") return field.defaultValue();
|
|
14
|
+
return field.defaultValue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function isObject(item) {
|
|
21
|
+
return item !== null && typeof item === "object" && !Array.isArray(item);
|
|
22
|
+
}
|
|
23
|
+
function deepmerge(target, source) {
|
|
24
|
+
if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
|
|
25
|
+
else if (isObject(target) && isObject(source)) {
|
|
26
|
+
const result = { ...target };
|
|
27
|
+
for (const [key, value] of Object.entries(source)) {
|
|
28
|
+
if (value === void 0) continue;
|
|
29
|
+
if (key in target) result[key] = deepmerge(target[key], value);
|
|
30
|
+
else result[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return source;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { deepmerge, withApplyDefault };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BetterAuthDBSchema } from "./type.mjs";
|
|
2
|
+
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
+
import "../types/index.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/db/get-tables.d.ts
|
|
6
|
+
declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getAuthTables };
|
|
@@ -159,26 +159,31 @@ const getAuthTables = (options) => {
|
|
|
159
159
|
accessToken: {
|
|
160
160
|
type: "string",
|
|
161
161
|
required: false,
|
|
162
|
+
returned: false,
|
|
162
163
|
fieldName: options.account?.fields?.accessToken || "accessToken"
|
|
163
164
|
},
|
|
164
165
|
refreshToken: {
|
|
165
166
|
type: "string",
|
|
166
167
|
required: false,
|
|
168
|
+
returned: false,
|
|
167
169
|
fieldName: options.account?.fields?.refreshToken || "refreshToken"
|
|
168
170
|
},
|
|
169
171
|
idToken: {
|
|
170
172
|
type: "string",
|
|
171
173
|
required: false,
|
|
174
|
+
returned: false,
|
|
172
175
|
fieldName: options.account?.fields?.idToken || "idToken"
|
|
173
176
|
},
|
|
174
177
|
accessTokenExpiresAt: {
|
|
175
178
|
type: "date",
|
|
176
179
|
required: false,
|
|
180
|
+
returned: false,
|
|
177
181
|
fieldName: options.account?.fields?.accessTokenExpiresAt || "accessTokenExpiresAt"
|
|
178
182
|
},
|
|
179
183
|
refreshTokenExpiresAt: {
|
|
180
184
|
type: "date",
|
|
181
185
|
required: false,
|
|
186
|
+
returned: false,
|
|
182
187
|
fieldName: options.account?.fields?.refreshTokenExpiresAt || "refreshTokenExpiresAt"
|
|
183
188
|
},
|
|
184
189
|
scope: {
|
|
@@ -189,6 +194,7 @@ const getAuthTables = (options) => {
|
|
|
189
194
|
password: {
|
|
190
195
|
type: "string",
|
|
191
196
|
required: false,
|
|
197
|
+
returned: false,
|
|
192
198
|
fieldName: options.account?.fields?.password || "password"
|
|
193
199
|
},
|
|
194
200
|
createdAt: {
|
|
@@ -251,4 +257,4 @@ const getAuthTables = (options) => {
|
|
|
251
257
|
};
|
|
252
258
|
|
|
253
259
|
//#endregion
|
|
254
|
-
export { getAuthTables
|
|
260
|
+
export { getAuthTables };
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage } from "./type.mjs";
|
|
2
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
3
|
+
import { BetterAuthPluginDBSchema } from "./plugin.mjs";
|
|
4
|
+
import { Account, accountSchema } from "./schema/account.mjs";
|
|
5
|
+
import { RateLimit, rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
6
|
+
import { Session, sessionSchema } from "./schema/session.mjs";
|
|
7
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
8
|
+
import { User, userSchema } from "./schema/user.mjs";
|
|
9
|
+
import { Verification, verificationSchema } from "./schema/verification.mjs";
|
|
10
|
+
export { type Account, type BaseModelNames, type BetterAuthDBSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute, type DBFieldAttributeConfig, type DBFieldType, type DBPrimitive, type ModelNames, type RateLimit, type SecondaryStorage, type Session, type User, type Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
package/dist/db/index.mjs
CHANGED
|
@@ -1,62 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { getAuthTables } from "./get-tables.mjs";
|
|
2
|
+
import { coreSchema } from "./schema/shared.mjs";
|
|
3
|
+
import { accountSchema } from "./schema/account.mjs";
|
|
4
|
+
import { rateLimitSchema } from "./schema/rate-limit.mjs";
|
|
5
|
+
import { sessionSchema } from "./schema/session.mjs";
|
|
6
|
+
import { userSchema } from "./schema/user.mjs";
|
|
7
|
+
import { verificationSchema } from "./schema/verification.mjs";
|
|
3
8
|
|
|
4
|
-
//#region src/db/schema/shared.ts
|
|
5
|
-
const coreSchema = z.object({
|
|
6
|
-
id: z.string(),
|
|
7
|
-
createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
|
|
8
|
-
updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/db/schema/account.ts
|
|
13
|
-
const accountSchema = coreSchema.extend({
|
|
14
|
-
providerId: z.string(),
|
|
15
|
-
accountId: z.string(),
|
|
16
|
-
userId: z.coerce.string(),
|
|
17
|
-
accessToken: z.string().nullish(),
|
|
18
|
-
refreshToken: z.string().nullish(),
|
|
19
|
-
idToken: z.string().nullish(),
|
|
20
|
-
accessTokenExpiresAt: z.date().nullish(),
|
|
21
|
-
refreshTokenExpiresAt: z.date().nullish(),
|
|
22
|
-
scope: z.string().nullish(),
|
|
23
|
-
password: z.string().nullish()
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/db/schema/rate-limit.ts
|
|
28
|
-
const rateLimitSchema = z.object({
|
|
29
|
-
key: z.string(),
|
|
30
|
-
count: z.number(),
|
|
31
|
-
lastRequest: z.number()
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/db/schema/session.ts
|
|
36
|
-
const sessionSchema = coreSchema.extend({
|
|
37
|
-
userId: z.coerce.string(),
|
|
38
|
-
expiresAt: z.date(),
|
|
39
|
-
token: z.string(),
|
|
40
|
-
ipAddress: z.string().nullish(),
|
|
41
|
-
userAgent: z.string().nullish()
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/db/schema/user.ts
|
|
46
|
-
const userSchema = coreSchema.extend({
|
|
47
|
-
email: z.string().transform((val) => val.toLowerCase()),
|
|
48
|
-
emailVerified: z.boolean().default(false),
|
|
49
|
-
name: z.string(),
|
|
50
|
-
image: z.string().nullish()
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/db/schema/verification.ts
|
|
55
|
-
const verificationSchema = coreSchema.extend({
|
|
56
|
-
value: z.string(),
|
|
57
|
-
expiresAt: z.date(),
|
|
58
|
-
identifier: z.string()
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
9
|
export { accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DBFieldAttribute } from "./type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/db/plugin.d.ts
|
|
4
|
+
type BetterAuthPluginDBSchema = { [table in string]: {
|
|
5
|
+
fields: {
|
|
6
|
+
[field: string]: DBFieldAttribute;
|
|
7
|
+
};
|
|
8
|
+
disableMigration?: boolean | undefined;
|
|
9
|
+
modelName?: string | undefined;
|
|
10
|
+
} };
|
|
11
|
+
//#endregion
|
|
12
|
+
export { BetterAuthPluginDBSchema };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/account.d.ts
|
|
4
|
+
declare const accountSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
providerId: z.ZodString;
|
|
9
|
+
accountId: z.ZodString;
|
|
10
|
+
userId: z.ZodCoercedString<unknown>;
|
|
11
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
15
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
16
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* Account schema type used by better-auth, note that it's possible that account could have additional fields
|
|
21
|
+
*
|
|
22
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
23
|
+
*/
|
|
24
|
+
type Account = z.infer<typeof accountSchema>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Account, accountSchema };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/account.ts
|
|
5
|
+
const accountSchema = coreSchema.extend({
|
|
6
|
+
providerId: z.string(),
|
|
7
|
+
accountId: z.string(),
|
|
8
|
+
userId: z.coerce.string(),
|
|
9
|
+
accessToken: z.string().nullish(),
|
|
10
|
+
refreshToken: z.string().nullish(),
|
|
11
|
+
idToken: z.string().nullish(),
|
|
12
|
+
accessTokenExpiresAt: z.date().nullish(),
|
|
13
|
+
refreshTokenExpiresAt: z.date().nullish(),
|
|
14
|
+
scope: z.string().nullish(),
|
|
15
|
+
password: z.string().nullish()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { accountSchema };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/rate-limit.d.ts
|
|
4
|
+
declare const rateLimitSchema: z.ZodObject<{
|
|
5
|
+
key: z.ZodString;
|
|
6
|
+
count: z.ZodNumber;
|
|
7
|
+
lastRequest: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
/**
|
|
10
|
+
* Rate limit schema type used by better-auth for rate limiting
|
|
11
|
+
*/
|
|
12
|
+
type RateLimit = z.infer<typeof rateLimitSchema>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { RateLimit, rateLimitSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/session.d.ts
|
|
4
|
+
declare const sessionSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
userId: z.ZodCoercedString<unknown>;
|
|
9
|
+
expiresAt: z.ZodDate;
|
|
10
|
+
token: z.ZodString;
|
|
11
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/**
|
|
15
|
+
* Session schema type used by better-auth, note that it's possible that session could have additional fields
|
|
16
|
+
*
|
|
17
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
18
|
+
*/
|
|
19
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Session, sessionSchema };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/session.ts
|
|
5
|
+
const sessionSchema = coreSchema.extend({
|
|
6
|
+
userId: z.coerce.string(),
|
|
7
|
+
expiresAt: z.date(),
|
|
8
|
+
token: z.string(),
|
|
9
|
+
ipAddress: z.string().nullish(),
|
|
10
|
+
userAgent: z.string().nullish()
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { sessionSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/shared.d.ts
|
|
4
|
+
declare const coreSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { coreSchema };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/shared.ts
|
|
4
|
+
const coreSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
createdAt: z.date().default(() => /* @__PURE__ */ new Date()),
|
|
7
|
+
updatedAt: z.date().default(() => /* @__PURE__ */ new Date())
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { coreSchema };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/user.d.ts
|
|
4
|
+
declare const userSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
9
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
/**
|
|
14
|
+
* User schema type used by better-auth, note that it's possible that user could have additional fields
|
|
15
|
+
*
|
|
16
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
17
|
+
*/
|
|
18
|
+
type User = z.infer<typeof userSchema>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { User, userSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/user.ts
|
|
5
|
+
const userSchema = coreSchema.extend({
|
|
6
|
+
email: z.string().transform((val) => val.toLowerCase()),
|
|
7
|
+
emailVerified: z.boolean().default(false),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
image: z.string().nullish()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { userSchema };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/db/schema/verification.d.ts
|
|
4
|
+
declare const verificationSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
7
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
8
|
+
value: z.ZodString;
|
|
9
|
+
expiresAt: z.ZodDate;
|
|
10
|
+
identifier: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
/**
|
|
13
|
+
* Verification schema type used by better-auth, note that it's possible that verification could have additional fields
|
|
14
|
+
*
|
|
15
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
16
|
+
*/
|
|
17
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Verification, verificationSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { coreSchema } from "./shared.mjs";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/db/schema/verification.ts
|
|
5
|
+
const verificationSchema = coreSchema.extend({
|
|
6
|
+
value: z.string(),
|
|
7
|
+
expiresAt: z.date(),
|
|
8
|
+
identifier: z.string()
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { verificationSchema };
|