@better-auth/core 1.4.12-beta.2 → 1.4.13
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} +1 -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 +84 -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 +1266 -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 +1 -1
- 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/error/index.ts +2 -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/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,49 @@
|
|
|
1
|
+
import { __getBetterAuthGlobal } from "./global.mjs";
|
|
2
|
+
import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/context/request-state.ts
|
|
5
|
+
const ensureAsyncStorage = async () => {
|
|
6
|
+
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
7
|
+
if (!betterAuthGlobal.context.requestStateAsyncStorage) {
|
|
8
|
+
const AsyncLocalStorage$1 = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.requestStateAsyncStorage = new AsyncLocalStorage$1();
|
|
10
|
+
}
|
|
11
|
+
return betterAuthGlobal.context.requestStateAsyncStorage;
|
|
12
|
+
};
|
|
13
|
+
async function getRequestStateAsyncLocalStorage() {
|
|
14
|
+
return ensureAsyncStorage();
|
|
15
|
+
}
|
|
16
|
+
async function hasRequestState() {
|
|
17
|
+
return (await ensureAsyncStorage()).getStore() !== void 0;
|
|
18
|
+
}
|
|
19
|
+
async function getCurrentRequestState() {
|
|
20
|
+
const store = (await ensureAsyncStorage()).getStore();
|
|
21
|
+
if (!store) throw new Error("No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.");
|
|
22
|
+
return store;
|
|
23
|
+
}
|
|
24
|
+
async function runWithRequestState(store, fn) {
|
|
25
|
+
return (await ensureAsyncStorage()).run(store, fn);
|
|
26
|
+
}
|
|
27
|
+
function defineRequestState(initFn) {
|
|
28
|
+
const ref = Object.freeze({});
|
|
29
|
+
return {
|
|
30
|
+
get ref() {
|
|
31
|
+
return ref;
|
|
32
|
+
},
|
|
33
|
+
async get() {
|
|
34
|
+
const store = await getCurrentRequestState();
|
|
35
|
+
if (!store.has(ref)) {
|
|
36
|
+
const initialValue = await initFn();
|
|
37
|
+
store.set(ref, initialValue);
|
|
38
|
+
return initialValue;
|
|
39
|
+
}
|
|
40
|
+
return store.get(ref);
|
|
41
|
+
},
|
|
42
|
+
async set(value) {
|
|
43
|
+
(await getCurrentRequestState()).set(ref, value);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { defineRequestState, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithRequestState };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DBAdapter, DBTransactionAdapter } from "../db/adapter/index.mjs";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/context/transaction.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is for internal use only. Most users should use `getCurrentAdapter` instead.
|
|
8
|
+
*
|
|
9
|
+
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
10
|
+
*/
|
|
11
|
+
declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<DBTransactionAdapter>>;
|
|
12
|
+
declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBTransactionAdapter>;
|
|
13
|
+
declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
|
|
14
|
+
declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __getBetterAuthGlobal } from "./global.mjs";
|
|
2
|
+
import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/context/transaction.ts
|
|
5
|
+
const ensureAsyncStorage = async () => {
|
|
6
|
+
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
7
|
+
if (!betterAuthGlobal.context.adapterAsyncStorage) {
|
|
8
|
+
const AsyncLocalStorage$1 = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.adapterAsyncStorage = new AsyncLocalStorage$1();
|
|
10
|
+
}
|
|
11
|
+
return betterAuthGlobal.context.adapterAsyncStorage;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* This is for internal use only. Most users should use `getCurrentAdapter` instead.
|
|
15
|
+
*
|
|
16
|
+
* It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
|
|
17
|
+
*/
|
|
18
|
+
const getCurrentDBAdapterAsyncLocalStorage = async () => {
|
|
19
|
+
return ensureAsyncStorage();
|
|
20
|
+
};
|
|
21
|
+
const getCurrentAdapter = async (fallback) => {
|
|
22
|
+
return ensureAsyncStorage().then((als) => {
|
|
23
|
+
return als.getStore() || fallback;
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
return fallback;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const runWithAdapter = async (adapter, fn) => {
|
|
29
|
+
let called = true;
|
|
30
|
+
return ensureAsyncStorage().then((als) => {
|
|
31
|
+
called = true;
|
|
32
|
+
return als.run(adapter, fn);
|
|
33
|
+
}).catch((err) => {
|
|
34
|
+
if (!called) return fn();
|
|
35
|
+
throw err;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const runWithTransaction = async (adapter, fn) => {
|
|
39
|
+
let called = true;
|
|
40
|
+
return ensureAsyncStorage().then((als) => {
|
|
41
|
+
called = true;
|
|
42
|
+
return adapter.transaction(async (trx) => {
|
|
43
|
+
return als.run(trx, fn);
|
|
44
|
+
});
|
|
45
|
+
}).catch((err) => {
|
|
46
|
+
if (!called) return fn();
|
|
47
|
+
throw err;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, runWithAdapter, runWithTransaction };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
|
|
2
|
+
import { initGetDefaultModelName } from "./get-default-model-name.mjs";
|
|
3
|
+
import { initGetFieldAttributes } from "./get-field-attributes.mjs";
|
|
4
|
+
import { initGetFieldName } from "./get-field-name.mjs";
|
|
5
|
+
import { initGetIdField } from "./get-id-field.mjs";
|
|
6
|
+
import { initGetModelName } from "./get-model-name.mjs";
|
|
7
|
+
import { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter } from "./types.mjs";
|
|
8
|
+
import { DBAdapter } from "./index.mjs";
|
|
9
|
+
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
10
|
+
import "../../types/index.mjs";
|
|
11
|
+
|
|
12
|
+
//#region src/db/adapter/factory.d.ts
|
|
13
|
+
type AdapterFactory = (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
14
|
+
declare const createAdapterFactory: ({
|
|
15
|
+
adapter: customAdapter,
|
|
16
|
+
config: cfg
|
|
17
|
+
}: AdapterFactoryOptions) => AdapterFactory;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `createAdapterFactory` instead. This export will be removed in a future version.
|
|
20
|
+
* @alias
|
|
21
|
+
*/
|
|
22
|
+
declare const createAdapter: ({
|
|
23
|
+
adapter: customAdapter,
|
|
24
|
+
config: cfg
|
|
25
|
+
}: AdapterFactoryOptions) => AdapterFactory;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { AdapterFactory, createAdapter, createAdapterFactory };
|