@better-auth/core 1.5.7-beta.1 → 1.6.0
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/dist/api/index.d.mts +12 -43
- package/dist/api/index.mjs +0 -3
- package/dist/async_hooks/index.d.mts +1 -2
- package/dist/async_hooks/index.mjs +0 -2
- package/dist/async_hooks/pure.index.d.mts +1 -2
- package/dist/async_hooks/pure.index.mjs +0 -2
- package/dist/context/endpoint-context.d.mts +2 -3
- package/dist/context/endpoint-context.mjs +0 -2
- package/dist/context/global.d.mts +1 -2
- package/dist/context/global.mjs +1 -3
- package/dist/context/request-state.d.mts +1 -2
- package/dist/context/request-state.mjs +0 -2
- package/dist/context/transaction.d.mts +1 -2
- package/dist/context/transaction.mjs +0 -2
- package/dist/db/adapter/factory.d.mts +1 -2
- package/dist/db/adapter/factory.mjs +3 -6
- package/dist/db/adapter/get-default-field-name.d.mts +1 -2
- package/dist/db/adapter/get-default-field-name.mjs +0 -2
- package/dist/db/adapter/get-default-model-name.d.mts +1 -2
- package/dist/db/adapter/get-default-model-name.mjs +0 -2
- package/dist/db/adapter/get-field-attributes.d.mts +1 -2
- package/dist/db/adapter/get-field-attributes.mjs +0 -2
- package/dist/db/adapter/get-field-name.d.mts +1 -2
- package/dist/db/adapter/get-field-name.mjs +0 -2
- package/dist/db/adapter/get-id-field.d.mts +1 -2
- package/dist/db/adapter/get-id-field.mjs +0 -3
- package/dist/db/adapter/get-model-name.d.mts +1 -2
- package/dist/db/adapter/get-model-name.mjs +0 -2
- package/dist/db/adapter/index.d.mts +9 -2
- package/dist/db/adapter/index.mjs +0 -2
- package/dist/db/adapter/types.d.mts +1 -2
- package/dist/db/adapter/utils.d.mts +1 -2
- package/dist/db/adapter/utils.mjs +0 -2
- package/dist/db/get-tables.d.mts +1 -2
- package/dist/db/get-tables.mjs +0 -2
- package/dist/db/plugin.d.mts +1 -2
- package/dist/db/schema/account.d.mts +1 -2
- package/dist/db/schema/account.mjs +0 -2
- package/dist/db/schema/rate-limit.d.mts +1 -2
- package/dist/db/schema/rate-limit.mjs +0 -2
- package/dist/db/schema/session.d.mts +1 -2
- package/dist/db/schema/session.mjs +0 -2
- package/dist/db/schema/shared.d.mts +1 -2
- package/dist/db/schema/shared.mjs +0 -2
- package/dist/db/schema/user.d.mts +1 -2
- package/dist/db/schema/user.mjs +0 -2
- package/dist/db/schema/verification.d.mts +1 -2
- package/dist/db/schema/verification.mjs +0 -2
- package/dist/db/type.d.mts +1 -2
- package/dist/env/color-depth.d.mts +1 -2
- package/dist/env/color-depth.mjs +0 -2
- package/dist/env/env-impl.d.mts +1 -2
- package/dist/env/env-impl.mjs +0 -2
- package/dist/env/logger.d.mts +1 -2
- package/dist/env/logger.mjs +0 -2
- package/dist/error/codes.d.mts +1 -2
- package/dist/error/codes.mjs +0 -2
- package/dist/error/index.d.mts +1 -2
- package/dist/error/index.mjs +0 -2
- package/dist/instrumentation/attributes.d.mts +1 -2
- package/dist/instrumentation/attributes.mjs +0 -2
- package/dist/instrumentation/tracer.d.mts +1 -2
- package/dist/instrumentation/tracer.mjs +29 -15
- package/dist/oauth2/client-credentials-token.d.mts +1 -2
- package/dist/oauth2/client-credentials-token.mjs +0 -2
- package/dist/oauth2/create-authorization-url.d.mts +1 -2
- package/dist/oauth2/create-authorization-url.mjs +0 -2
- package/dist/oauth2/oauth-provider.d.mts +1 -2
- package/dist/oauth2/refresh-access-token.d.mts +1 -2
- package/dist/oauth2/refresh-access-token.mjs +0 -2
- package/dist/oauth2/utils.d.mts +1 -2
- package/dist/oauth2/utils.mjs +0 -2
- package/dist/oauth2/validate-authorization-code.d.mts +1 -2
- package/dist/oauth2/validate-authorization-code.mjs +0 -3
- package/dist/oauth2/verify.d.mts +1 -2
- package/dist/oauth2/verify.mjs +0 -3
- package/dist/social-providers/apple.d.mts +1 -2
- package/dist/social-providers/apple.mjs +0 -3
- package/dist/social-providers/atlassian.d.mts +1 -2
- package/dist/social-providers/atlassian.mjs +0 -4
- package/dist/social-providers/cognito.d.mts +1 -2
- package/dist/social-providers/cognito.mjs +0 -4
- package/dist/social-providers/discord.d.mts +1 -2
- package/dist/social-providers/discord.mjs +0 -3
- package/dist/social-providers/dropbox.d.mts +1 -2
- package/dist/social-providers/dropbox.mjs +0 -3
- package/dist/social-providers/facebook.d.mts +1 -2
- package/dist/social-providers/facebook.mjs +0 -3
- package/dist/social-providers/figma.d.mts +1 -2
- package/dist/social-providers/figma.mjs +0 -4
- package/dist/social-providers/github.d.mts +1 -2
- package/dist/social-providers/github.mjs +0 -4
- package/dist/social-providers/gitlab.d.mts +1 -2
- package/dist/social-providers/gitlab.mjs +0 -3
- package/dist/social-providers/google.d.mts +1 -2
- package/dist/social-providers/google.mjs +0 -4
- package/dist/social-providers/huggingface.d.mts +1 -2
- package/dist/social-providers/huggingface.mjs +0 -3
- package/dist/social-providers/index.d.mts +1 -2
- package/dist/social-providers/index.mjs +0 -2
- package/dist/social-providers/kakao.d.mts +1 -2
- package/dist/social-providers/kakao.mjs +0 -3
- package/dist/social-providers/kick.d.mts +1 -2
- package/dist/social-providers/kick.mjs +0 -3
- package/dist/social-providers/line.d.mts +1 -2
- package/dist/social-providers/line.mjs +0 -3
- package/dist/social-providers/linear.d.mts +1 -2
- package/dist/social-providers/linear.mjs +0 -3
- package/dist/social-providers/linkedin.d.mts +1 -2
- package/dist/social-providers/linkedin.mjs +0 -3
- package/dist/social-providers/microsoft-entra-id.d.mts +1 -2
- package/dist/social-providers/microsoft-entra-id.mjs +0 -4
- package/dist/social-providers/naver.d.mts +1 -2
- package/dist/social-providers/naver.mjs +0 -3
- package/dist/social-providers/notion.d.mts +1 -2
- package/dist/social-providers/notion.mjs +0 -3
- package/dist/social-providers/paybin.d.mts +1 -2
- package/dist/social-providers/paybin.mjs +0 -4
- package/dist/social-providers/paypal.d.mts +1 -2
- package/dist/social-providers/paypal.mjs +0 -4
- package/dist/social-providers/polar.d.mts +1 -2
- package/dist/social-providers/polar.mjs +0 -3
- package/dist/social-providers/railway.d.mts +1 -2
- package/dist/social-providers/railway.mjs +0 -3
- package/dist/social-providers/reddit.d.mts +1 -2
- package/dist/social-providers/reddit.mjs +0 -3
- package/dist/social-providers/roblox.d.mts +1 -2
- package/dist/social-providers/roblox.mjs +0 -3
- package/dist/social-providers/salesforce.d.mts +1 -2
- package/dist/social-providers/salesforce.mjs +0 -4
- package/dist/social-providers/slack.d.mts +1 -2
- package/dist/social-providers/slack.mjs +0 -3
- package/dist/social-providers/spotify.d.mts +1 -2
- package/dist/social-providers/spotify.mjs +0 -3
- package/dist/social-providers/tiktok.d.mts +1 -2
- package/dist/social-providers/tiktok.mjs +0 -3
- package/dist/social-providers/twitch.d.mts +1 -2
- package/dist/social-providers/twitch.mjs +0 -4
- package/dist/social-providers/twitter.d.mts +1 -2
- package/dist/social-providers/twitter.mjs +0 -3
- package/dist/social-providers/vercel.d.mts +1 -2
- package/dist/social-providers/vercel.mjs +0 -3
- package/dist/social-providers/vk.d.mts +1 -2
- package/dist/social-providers/vk.mjs +0 -3
- package/dist/social-providers/wechat.d.mts +1 -2
- package/dist/social-providers/wechat.mjs +0 -2
- package/dist/social-providers/zoom.d.mts +1 -2
- package/dist/social-providers/zoom.mjs +0 -3
- package/dist/types/context.d.mts +5 -3
- package/dist/types/cookie.d.mts +1 -2
- package/dist/types/helper.d.mts +1 -2
- package/dist/types/init-options.d.mts +14 -6
- package/dist/types/plugin-client.d.mts +2 -2
- package/dist/types/plugin.d.mts +3 -6
- package/dist/types/secret.d.mts +1 -2
- package/dist/utils/db.d.mts +1 -2
- package/dist/utils/db.mjs +0 -2
- package/dist/utils/deprecate.d.mts +1 -2
- package/dist/utils/deprecate.mjs +0 -2
- package/dist/utils/error-codes.d.mts +1 -2
- package/dist/utils/error-codes.mjs +0 -2
- package/dist/utils/fetch-metadata.d.mts +1 -2
- package/dist/utils/fetch-metadata.mjs +0 -2
- package/dist/utils/id.d.mts +1 -2
- package/dist/utils/id.mjs +0 -2
- package/dist/utils/ip.d.mts +1 -2
- package/dist/utils/ip.mjs +0 -2
- package/dist/utils/json.d.mts +1 -2
- package/dist/utils/json.mjs +0 -3
- package/dist/utils/string.d.mts +1 -2
- package/dist/utils/string.mjs +0 -2
- package/dist/utils/url.d.mts +1 -2
- package/dist/utils/url.mjs +0 -2
- package/package.json +9 -7
- package/src/api/index.ts +41 -151
- package/src/context/endpoint-context.ts +1 -2
- package/src/db/adapter/factory.ts +2 -0
- package/src/db/adapter/index.ts +8 -0
- package/src/instrumentation/tracer.ts +40 -12
- package/src/social-providers/index.ts +0 -2
- package/src/types/context.ts +4 -1
- package/src/types/init-options.ts +13 -4
- package/src/types/plugin-client.ts +1 -0
- package/src/types/plugin.ts +2 -14
- package/dist/api/index.mjs.map +0 -1
- package/dist/async_hooks/index.mjs.map +0 -1
- package/dist/async_hooks/pure.index.mjs.map +0 -1
- package/dist/context/endpoint-context.mjs.map +0 -1
- package/dist/context/global.mjs.map +0 -1
- package/dist/context/request-state.mjs.map +0 -1
- package/dist/context/transaction.mjs.map +0 -1
- package/dist/db/adapter/factory.mjs.map +0 -1
- package/dist/db/adapter/get-default-field-name.mjs.map +0 -1
- package/dist/db/adapter/get-default-model-name.mjs.map +0 -1
- package/dist/db/adapter/get-field-attributes.mjs.map +0 -1
- package/dist/db/adapter/get-field-name.mjs.map +0 -1
- package/dist/db/adapter/get-id-field.mjs.map +0 -1
- package/dist/db/adapter/get-model-name.mjs.map +0 -1
- package/dist/db/adapter/index.mjs.map +0 -1
- package/dist/db/adapter/utils.mjs.map +0 -1
- package/dist/db/get-tables.mjs.map +0 -1
- package/dist/db/schema/account.mjs.map +0 -1
- package/dist/db/schema/rate-limit.mjs.map +0 -1
- package/dist/db/schema/session.mjs.map +0 -1
- package/dist/db/schema/shared.mjs.map +0 -1
- package/dist/db/schema/user.mjs.map +0 -1
- package/dist/db/schema/verification.mjs.map +0 -1
- package/dist/env/color-depth.mjs.map +0 -1
- package/dist/env/env-impl.mjs.map +0 -1
- package/dist/env/logger.mjs.map +0 -1
- package/dist/error/codes.mjs.map +0 -1
- package/dist/error/index.mjs.map +0 -1
- package/dist/instrumentation/attributes.mjs.map +0 -1
- package/dist/instrumentation/tracer.mjs.map +0 -1
- package/dist/oauth2/client-credentials-token.mjs.map +0 -1
- package/dist/oauth2/create-authorization-url.mjs.map +0 -1
- package/dist/oauth2/refresh-access-token.mjs.map +0 -1
- package/dist/oauth2/utils.mjs.map +0 -1
- package/dist/oauth2/validate-authorization-code.mjs.map +0 -1
- package/dist/oauth2/verify.mjs.map +0 -1
- package/dist/social-providers/apple.mjs.map +0 -1
- package/dist/social-providers/atlassian.mjs.map +0 -1
- package/dist/social-providers/cognito.mjs.map +0 -1
- package/dist/social-providers/discord.mjs.map +0 -1
- package/dist/social-providers/dropbox.mjs.map +0 -1
- package/dist/social-providers/facebook.mjs.map +0 -1
- package/dist/social-providers/figma.mjs.map +0 -1
- package/dist/social-providers/github.mjs.map +0 -1
- package/dist/social-providers/gitlab.mjs.map +0 -1
- package/dist/social-providers/google.mjs.map +0 -1
- package/dist/social-providers/huggingface.mjs.map +0 -1
- package/dist/social-providers/index.mjs.map +0 -1
- package/dist/social-providers/kakao.mjs.map +0 -1
- package/dist/social-providers/kick.mjs.map +0 -1
- package/dist/social-providers/line.mjs.map +0 -1
- package/dist/social-providers/linear.mjs.map +0 -1
- package/dist/social-providers/linkedin.mjs.map +0 -1
- package/dist/social-providers/microsoft-entra-id.mjs.map +0 -1
- package/dist/social-providers/naver.mjs.map +0 -1
- package/dist/social-providers/notion.mjs.map +0 -1
- package/dist/social-providers/paybin.mjs.map +0 -1
- package/dist/social-providers/paypal.mjs.map +0 -1
- package/dist/social-providers/polar.mjs.map +0 -1
- package/dist/social-providers/railway.mjs.map +0 -1
- package/dist/social-providers/reddit.mjs.map +0 -1
- package/dist/social-providers/roblox.mjs.map +0 -1
- package/dist/social-providers/salesforce.mjs.map +0 -1
- package/dist/social-providers/slack.mjs.map +0 -1
- package/dist/social-providers/spotify.mjs.map +0 -1
- package/dist/social-providers/tiktok.mjs.map +0 -1
- package/dist/social-providers/twitch.mjs.map +0 -1
- package/dist/social-providers/twitter.mjs.map +0 -1
- package/dist/social-providers/vercel.mjs.map +0 -1
- package/dist/social-providers/vk.mjs.map +0 -1
- package/dist/social-providers/wechat.mjs.map +0 -1
- package/dist/social-providers/zoom.mjs.map +0 -1
- package/dist/utils/db.mjs.map +0 -1
- package/dist/utils/deprecate.mjs.map +0 -1
- package/dist/utils/error-codes.mjs.map +0 -1
- package/dist/utils/fetch-metadata.mjs.map +0 -1
- package/dist/utils/id.mjs.map +0 -1
- package/dist/utils/ip.mjs.map +0 -1
- package/dist/utils/json.mjs.map +0 -1
- package/dist/utils/string.mjs.map +0 -1
- package/dist/utils/url.mjs.map +0 -1
- package/src/context/request-state.test.ts +0 -94
- package/src/db/adapter/get-id-field.test.ts +0 -222
- package/src/db/test/get-tables.test.ts +0 -116
- package/src/env/logger.test.ts +0 -34
- package/src/instrumentation/instrumentation.test.ts +0 -139
- package/src/oauth2/refresh-access-token.test.ts +0 -90
- package/src/oauth2/validate-token.test.ts +0 -229
- package/src/utils/deprecate.test.ts +0 -71
- package/src/utils/fetch-metadata.test.ts +0 -28
- package/src/utils/ip.test.ts +0 -255
package/dist/utils/json.d.mts
CHANGED
package/dist/utils/json.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { logger } from "../env/logger.mjs";
|
|
2
|
-
import "../env/index.mjs";
|
|
3
2
|
//#region src/utils/json.ts
|
|
4
3
|
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
5
4
|
function reviveDate(value) {
|
|
@@ -40,5 +39,3 @@ function safeJSONParse(data) {
|
|
|
40
39
|
}
|
|
41
40
|
//#endregion
|
|
42
41
|
export { safeJSONParse };
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=json.mjs.map
|
package/dist/utils/string.d.mts
CHANGED
package/dist/utils/string.mjs
CHANGED
package/dist/utils/url.d.mts
CHANGED
package/dist/utils/url.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
+
"sideEffects": false,
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
24
|
-
"src"
|
|
25
|
+
"src",
|
|
26
|
+
"!src/**/*.test.ts"
|
|
25
27
|
],
|
|
26
28
|
"main": "./dist/index.mjs",
|
|
27
29
|
"module": "./dist/index.mjs",
|
|
@@ -143,12 +145,12 @@
|
|
|
143
145
|
"zod": "^4.3.6"
|
|
144
146
|
},
|
|
145
147
|
"devDependencies": {
|
|
146
|
-
"@better-auth/utils": "0.
|
|
148
|
+
"@better-auth/utils": "0.4.0",
|
|
147
149
|
"@better-fetch/fetch": "1.1.21",
|
|
148
150
|
"@opentelemetry/api": "^1.9.0",
|
|
149
151
|
"@opentelemetry/sdk-trace-base": "^1.30.0",
|
|
150
152
|
"@opentelemetry/sdk-trace-node": "^1.30.0",
|
|
151
|
-
"better-call": "
|
|
153
|
+
"better-call": "1.3.5",
|
|
152
154
|
"@cloudflare/workers-types": "^4.20250121.0",
|
|
153
155
|
"jose": "^6.1.3",
|
|
154
156
|
"kysely": "^0.28.14",
|
|
@@ -156,10 +158,10 @@
|
|
|
156
158
|
"tsdown": "0.21.1"
|
|
157
159
|
},
|
|
158
160
|
"peerDependencies": {
|
|
159
|
-
"@better-auth/utils": "0.
|
|
161
|
+
"@better-auth/utils": "0.4.0",
|
|
160
162
|
"@better-fetch/fetch": "1.1.21",
|
|
161
163
|
"@opentelemetry/api": "^1.9.0",
|
|
162
|
-
"better-call": "
|
|
164
|
+
"better-call": "1.3.5",
|
|
163
165
|
"@cloudflare/workers-types": ">=4",
|
|
164
166
|
"jose": "^6.1.0",
|
|
165
167
|
"kysely": "^0.28.5",
|
|
@@ -173,7 +175,7 @@
|
|
|
173
175
|
"scripts": {
|
|
174
176
|
"build": "tsdown",
|
|
175
177
|
"dev": "tsdown --watch",
|
|
176
|
-
"lint:package": "publint run --strict",
|
|
178
|
+
"lint:package": "publint run --strict --pack false",
|
|
177
179
|
"lint:types": "attw --profile esm-only --pack .",
|
|
178
180
|
"typecheck": "tsc --project tsconfig.json",
|
|
179
181
|
"test": "vitest",
|
package/src/api/index.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
Endpoint,
|
|
3
2
|
EndpointContext,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
HTTPMethod,
|
|
7
|
-
Middleware,
|
|
8
|
-
ResolveBodyInput,
|
|
9
|
-
ResolveErrorInput,
|
|
10
|
-
ResolveMetaInput,
|
|
11
|
-
ResolveQueryInput,
|
|
12
|
-
StandardSchemaV1,
|
|
3
|
+
EndpointOptions,
|
|
4
|
+
StrictEndpoint,
|
|
13
5
|
} from "better-call";
|
|
14
6
|
import { createEndpoint, createMiddleware } from "better-call";
|
|
15
7
|
import { runWithEndpointContext } from "../context";
|
|
@@ -41,145 +33,47 @@ export const createAuthMiddleware = createMiddleware.create({
|
|
|
41
33
|
|
|
42
34
|
const use = [optionsMiddleware];
|
|
43
35
|
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
: { body?: B };
|
|
50
|
-
|
|
51
|
-
type AuthEndpointOptions<
|
|
52
|
-
Method extends HTTPMethod | HTTPMethod[] | "*",
|
|
53
|
-
BodySchema extends object | undefined,
|
|
54
|
-
QuerySchema extends object | undefined,
|
|
55
|
-
Use extends Middleware[],
|
|
56
|
-
ReqHeaders extends boolean,
|
|
57
|
-
ReqRequest extends boolean,
|
|
58
|
-
Meta extends EndpointMetadata | undefined,
|
|
59
|
-
ErrorSchema extends StandardSchemaV1 | undefined = undefined,
|
|
60
|
-
> = { method: Method } & BodyOption<Method, BodySchema> & {
|
|
61
|
-
query?: QuerySchema;
|
|
62
|
-
use?: [...Use];
|
|
63
|
-
requireHeaders?: ReqHeaders;
|
|
64
|
-
requireRequest?: ReqRequest;
|
|
65
|
-
error?: ErrorSchema;
|
|
66
|
-
cloneRequest?: boolean;
|
|
67
|
-
disableBody?: boolean;
|
|
68
|
-
metadata?: Meta;
|
|
69
|
-
[key: string]: any;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Normalize readonly tuples produced by `const` type parameters
|
|
74
|
-
* into mutable arrays so downstream `M extends Array<any>` checks work.
|
|
75
|
-
*/
|
|
76
|
-
type NormalizeMethod<M> = M extends readonly (infer E)[] ? E[] : M;
|
|
36
|
+
type EndpointHandler<
|
|
37
|
+
Path extends string,
|
|
38
|
+
Options extends EndpointOptions,
|
|
39
|
+
R,
|
|
40
|
+
> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
|
|
77
41
|
|
|
78
|
-
// Path + options + handler overload
|
|
79
42
|
export function createAuthEndpoint<
|
|
80
43
|
Path extends string,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
QuerySchema extends object | undefined = undefined,
|
|
84
|
-
Use extends Middleware[] = [],
|
|
85
|
-
ReqHeaders extends boolean = false,
|
|
86
|
-
ReqRequest extends boolean = false,
|
|
87
|
-
R = unknown,
|
|
88
|
-
Meta extends EndpointMetadata | undefined = undefined,
|
|
89
|
-
ErrorSchema extends StandardSchemaV1 | undefined = undefined,
|
|
44
|
+
Options extends EndpointOptions,
|
|
45
|
+
R,
|
|
90
46
|
>(
|
|
91
47
|
path: Path,
|
|
92
|
-
options:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
QuerySchema,
|
|
96
|
-
Use,
|
|
97
|
-
ReqHeaders,
|
|
98
|
-
ReqRequest,
|
|
99
|
-
Meta,
|
|
100
|
-
ErrorSchema
|
|
101
|
-
>,
|
|
102
|
-
handler: (
|
|
103
|
-
ctx: EndpointContext<
|
|
104
|
-
Path,
|
|
105
|
-
Method,
|
|
106
|
-
BodySchema,
|
|
107
|
-
QuerySchema,
|
|
108
|
-
Use,
|
|
109
|
-
ReqHeaders,
|
|
110
|
-
ReqRequest,
|
|
111
|
-
AuthContext,
|
|
112
|
-
Meta
|
|
113
|
-
>,
|
|
114
|
-
) => Promise<R>,
|
|
115
|
-
): Endpoint<
|
|
116
|
-
Path,
|
|
117
|
-
NormalizeMethod<Method>,
|
|
118
|
-
ResolveBodyInput<BodySchema, Meta>,
|
|
119
|
-
ResolveQueryInput<QuerySchema, Meta>,
|
|
120
|
-
Use,
|
|
121
|
-
R,
|
|
122
|
-
ResolveMetaInput<Meta>,
|
|
123
|
-
ResolveErrorInput<ErrorSchema, Meta>
|
|
124
|
-
>;
|
|
48
|
+
options: Options,
|
|
49
|
+
handler: EndpointHandler<Path, Options, R>,
|
|
50
|
+
): StrictEndpoint<Path, Options, R>;
|
|
125
51
|
|
|
126
|
-
// Options-only (virtual/path-less) overload
|
|
127
52
|
export function createAuthEndpoint<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
QuerySchema extends object | undefined = undefined,
|
|
131
|
-
Use extends Middleware[] = [],
|
|
132
|
-
ReqHeaders extends boolean = false,
|
|
133
|
-
ReqRequest extends boolean = false,
|
|
134
|
-
R = unknown,
|
|
135
|
-
Meta extends EndpointMetadata | undefined = undefined,
|
|
136
|
-
ErrorSchema extends StandardSchemaV1 | undefined = undefined,
|
|
137
|
-
>(
|
|
138
|
-
options: AuthEndpointOptions<
|
|
139
|
-
Method,
|
|
140
|
-
BodySchema,
|
|
141
|
-
QuerySchema,
|
|
142
|
-
Use,
|
|
143
|
-
ReqHeaders,
|
|
144
|
-
ReqRequest,
|
|
145
|
-
Meta,
|
|
146
|
-
ErrorSchema
|
|
147
|
-
>,
|
|
148
|
-
handler: (
|
|
149
|
-
ctx: EndpointContext<
|
|
150
|
-
string,
|
|
151
|
-
Method,
|
|
152
|
-
BodySchema,
|
|
153
|
-
QuerySchema,
|
|
154
|
-
Use,
|
|
155
|
-
ReqHeaders,
|
|
156
|
-
ReqRequest,
|
|
157
|
-
AuthContext,
|
|
158
|
-
Meta
|
|
159
|
-
>,
|
|
160
|
-
) => Promise<R>,
|
|
161
|
-
): Endpoint<
|
|
162
|
-
string,
|
|
163
|
-
NormalizeMethod<Method>,
|
|
164
|
-
ResolveBodyInput<BodySchema, Meta>,
|
|
165
|
-
ResolveQueryInput<QuerySchema, Meta>,
|
|
166
|
-
Use,
|
|
53
|
+
Path extends string,
|
|
54
|
+
Options extends EndpointOptions,
|
|
167
55
|
R,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
56
|
+
>(
|
|
57
|
+
options: Options,
|
|
58
|
+
handler: EndpointHandler<Path, Options, R>,
|
|
59
|
+
): StrictEndpoint<Path, Options, R>;
|
|
171
60
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
61
|
+
export function createAuthEndpoint<
|
|
62
|
+
Path extends string,
|
|
63
|
+
Opts extends EndpointOptions,
|
|
64
|
+
R,
|
|
65
|
+
>(
|
|
66
|
+
pathOrOptions: Path | Opts,
|
|
67
|
+
handlerOrOptions: EndpointHandler<Path, Opts, R> | Opts,
|
|
176
68
|
handlerOrNever?: any,
|
|
177
69
|
) {
|
|
178
|
-
const path:
|
|
70
|
+
const path: Path | undefined =
|
|
179
71
|
typeof pathOrOptions === "string" ? pathOrOptions : undefined;
|
|
180
|
-
const options:
|
|
181
|
-
typeof handlerOrOptions === "object"
|
|
182
|
-
|
|
72
|
+
const options: Opts =
|
|
73
|
+
typeof handlerOrOptions === "object"
|
|
74
|
+
? handlerOrOptions
|
|
75
|
+
: (pathOrOptions as Opts);
|
|
76
|
+
const handler: EndpointHandler<Path, Opts, R> =
|
|
183
77
|
typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
184
78
|
|
|
185
79
|
if (path) {
|
|
@@ -188,9 +82,9 @@ export function createAuthEndpoint(
|
|
|
188
82
|
{
|
|
189
83
|
...options,
|
|
190
84
|
use: [...(options?.use || []), ...use],
|
|
191
|
-
}
|
|
85
|
+
},
|
|
192
86
|
// todo: prettify the code, we want to call `runWithEndpointContext` to top level
|
|
193
|
-
async (ctx
|
|
87
|
+
async (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),
|
|
194
88
|
);
|
|
195
89
|
}
|
|
196
90
|
|
|
@@ -198,19 +92,15 @@ export function createAuthEndpoint(
|
|
|
198
92
|
{
|
|
199
93
|
...options,
|
|
200
94
|
use: [...(options?.use || []), ...use],
|
|
201
|
-
}
|
|
95
|
+
},
|
|
202
96
|
// todo: prettify the code, we want to call `runWithEndpointContext` to top level
|
|
203
|
-
async (ctx
|
|
97
|
+
async (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),
|
|
204
98
|
);
|
|
205
99
|
}
|
|
206
100
|
|
|
207
|
-
export type AuthEndpoint
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
*/
|
|
214
|
-
export type AuthMiddleware = (
|
|
215
|
-
inputContext: Record<string, any>,
|
|
216
|
-
) => Promise<unknown>;
|
|
101
|
+
export type AuthEndpoint<
|
|
102
|
+
Path extends string,
|
|
103
|
+
Opts extends EndpointOptions,
|
|
104
|
+
R,
|
|
105
|
+
> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
|
|
106
|
+
export type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
|
|
@@ -5,8 +5,7 @@ import type { AuthContext } from "../types";
|
|
|
5
5
|
import { __getBetterAuthGlobal } from "./global";
|
|
6
6
|
|
|
7
7
|
export type AuthEndpointContext = Partial<
|
|
8
|
-
InputContext<string, any
|
|
9
|
-
EndpointContext<string, any, any, any, any, any, any, AuthContext>
|
|
8
|
+
InputContext<string, any> & EndpointContext<string, any>
|
|
10
9
|
> & {
|
|
11
10
|
context: AuthContext;
|
|
12
11
|
};
|
|
@@ -496,6 +496,7 @@ export const createAdapterFactory =
|
|
|
496
496
|
value,
|
|
497
497
|
operator = "eq",
|
|
498
498
|
connector = "AND",
|
|
499
|
+
mode = "sensitive",
|
|
499
500
|
} = w;
|
|
500
501
|
if (operator === "in") {
|
|
501
502
|
if (!Array.isArray(value)) {
|
|
@@ -606,6 +607,7 @@ export const createAdapterFactory =
|
|
|
606
607
|
connector,
|
|
607
608
|
field: fieldName,
|
|
608
609
|
value: newValue,
|
|
610
|
+
mode,
|
|
609
611
|
} satisfies CleanedWhere;
|
|
610
612
|
}) as any;
|
|
611
613
|
};
|
package/src/db/adapter/index.ts
CHANGED
|
@@ -328,6 +328,14 @@ export type Where = {
|
|
|
328
328
|
* @default AND
|
|
329
329
|
*/
|
|
330
330
|
connector?: ("AND" | "OR") | undefined;
|
|
331
|
+
/**
|
|
332
|
+
* Case sensitivity for string comparisons.
|
|
333
|
+
* When "insensitive", string equality and pattern matching (contains, starts_with, ends_with)
|
|
334
|
+
* will be case-insensitive. Only applies to string values.
|
|
335
|
+
*
|
|
336
|
+
* @default "sensitive"
|
|
337
|
+
*/
|
|
338
|
+
mode?: "sensitive" | "insensitive" | undefined;
|
|
331
339
|
};
|
|
332
340
|
|
|
333
341
|
/**
|
|
@@ -1,10 +1,48 @@
|
|
|
1
|
+
import type { Span } from "@opentelemetry/api";
|
|
1
2
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
3
|
+
import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes";
|
|
2
4
|
|
|
3
5
|
const INSTRUMENTATION_SCOPE = "better-auth";
|
|
4
6
|
const INSTRUMENTATION_VERSION = import.meta.env?.BETTER_AUTH_VERSION ?? "1.0.0";
|
|
5
7
|
|
|
6
8
|
const tracer = trace.getTracer(INSTRUMENTATION_SCOPE, INSTRUMENTATION_VERSION);
|
|
7
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
|
|
12
|
+
* callbacks). These are APIErrors with 3xx status codes and should not be
|
|
13
|
+
* recorded as span errors.
|
|
14
|
+
*/
|
|
15
|
+
function isRedirectError(err: unknown): boolean {
|
|
16
|
+
if (
|
|
17
|
+
err != null &&
|
|
18
|
+
typeof err === "object" &&
|
|
19
|
+
"name" in err &&
|
|
20
|
+
(err as { name: string }).name === "APIError" &&
|
|
21
|
+
"statusCode" in err
|
|
22
|
+
) {
|
|
23
|
+
const status = (err as { statusCode: number }).statusCode;
|
|
24
|
+
return status >= 300 && status < 400;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function endSpanWithError(span: Span, err: unknown) {
|
|
30
|
+
if (isRedirectError(err)) {
|
|
31
|
+
span.setAttribute(
|
|
32
|
+
ATTR_HTTP_RESPONSE_STATUS_CODE,
|
|
33
|
+
(err as { statusCode: number }).statusCode,
|
|
34
|
+
);
|
|
35
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
36
|
+
} else {
|
|
37
|
+
span.recordException(err as Error);
|
|
38
|
+
span.setStatus({
|
|
39
|
+
code: SpanStatusCode.ERROR,
|
|
40
|
+
message: String((err as Error)?.message ?? err),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
span.end();
|
|
44
|
+
}
|
|
45
|
+
|
|
8
46
|
/**
|
|
9
47
|
* Creates a child span whose lifetime is bound to the execution of the given function
|
|
10
48
|
*
|
|
@@ -38,24 +76,14 @@ export function withSpan<T>(
|
|
|
38
76
|
return value;
|
|
39
77
|
})
|
|
40
78
|
.catch((err) => {
|
|
41
|
-
span
|
|
42
|
-
span.setStatus({
|
|
43
|
-
code: SpanStatusCode.ERROR,
|
|
44
|
-
message: String(err.message ?? err),
|
|
45
|
-
});
|
|
46
|
-
span.end();
|
|
79
|
+
endSpanWithError(span, err);
|
|
47
80
|
throw err;
|
|
48
81
|
}) as Promise<T>;
|
|
49
82
|
}
|
|
50
83
|
span.end();
|
|
51
84
|
return result;
|
|
52
85
|
} catch (err) {
|
|
53
|
-
span
|
|
54
|
-
span.setStatus({
|
|
55
|
-
code: SpanStatusCode.ERROR,
|
|
56
|
-
message: String((err as Error)?.message ?? err),
|
|
57
|
-
});
|
|
58
|
-
span.end();
|
|
86
|
+
endSpanWithError(span, err);
|
|
59
87
|
throw err;
|
|
60
88
|
}
|
|
61
89
|
});
|
|
@@ -106,11 +106,9 @@ export * from "./google";
|
|
|
106
106
|
export * from "./huggingface";
|
|
107
107
|
export * from "./kakao";
|
|
108
108
|
export * from "./kick";
|
|
109
|
-
export * from "./kick";
|
|
110
109
|
export * from "./line";
|
|
111
110
|
export * from "./linear";
|
|
112
111
|
export * from "./linkedin";
|
|
113
|
-
export * from "./linkedin";
|
|
114
112
|
export * from "./microsoft-entra-id";
|
|
115
113
|
export * from "./naver";
|
|
116
114
|
export * from "./notion";
|
package/src/types/context.ts
CHANGED
|
@@ -58,6 +58,7 @@ type InferPluginOptions<
|
|
|
58
58
|
*
|
|
59
59
|
* const createMyPlugin = <Options extends MyPluginOptions>(options?: Options) => ({
|
|
60
60
|
* id: 'my-plugin',
|
|
61
|
+
* version: '1.0.0',
|
|
61
62
|
* options,
|
|
62
63
|
* } satisfies BetterAuthPlugin);
|
|
63
64
|
*
|
|
@@ -79,7 +80,9 @@ export type BetterAuthPluginRegistryIdentifier = keyof BetterAuthPluginRegistry<
|
|
|
79
80
|
|
|
80
81
|
export type GenericEndpointContext<
|
|
81
82
|
Options extends BetterAuthOptions = BetterAuthOptions,
|
|
82
|
-
> = EndpointContext<string, any
|
|
83
|
+
> = EndpointContext<string, any> & {
|
|
84
|
+
context: AuthContext<Options>;
|
|
85
|
+
};
|
|
83
86
|
|
|
84
87
|
export interface InternalAdapter<
|
|
85
88
|
_Options extends BetterAuthOptions = BetterAuthOptions,
|
|
@@ -216,7 +216,9 @@ export type BetterAuthAdvancedOptions = {
|
|
|
216
216
|
}
|
|
217
217
|
| undefined;
|
|
218
218
|
/**
|
|
219
|
-
*
|
|
219
|
+
* Force cookies to always use the `Secure` attribute. By default,
|
|
220
|
+
* cookies are secure in production environments. Set this to `true`
|
|
221
|
+
* to enforce secure cookies in all environments.
|
|
220
222
|
*
|
|
221
223
|
* @default false
|
|
222
224
|
*/
|
|
@@ -384,9 +386,11 @@ export type BetterAuthAdvancedOptions = {
|
|
|
384
386
|
|
|
385
387
|
export type BetterAuthOptions = {
|
|
386
388
|
/**
|
|
387
|
-
* The name of
|
|
389
|
+
* The name of your application. Used as a display name in contexts
|
|
390
|
+
* where your app needs to be identified — for example, as the default
|
|
391
|
+
* issuer name in authenticator apps when users set up 2FA/TOTP.
|
|
388
392
|
*
|
|
389
|
-
*
|
|
393
|
+
* Can also be set via the `APP_NAME` environment variable.
|
|
390
394
|
*
|
|
391
395
|
* @default "Better Auth"
|
|
392
396
|
*/
|
|
@@ -1145,7 +1149,12 @@ export type BetterAuthOptions = {
|
|
|
1145
1149
|
})
|
|
1146
1150
|
| undefined;
|
|
1147
1151
|
/**
|
|
1148
|
-
*
|
|
1152
|
+
* Additional trusted origins. By default, Better Auth trusts your
|
|
1153
|
+
* app's {@link baseURL}. Use this option to allow additional origins
|
|
1154
|
+
* (e.g. a separate frontend domain).
|
|
1155
|
+
*
|
|
1156
|
+
* Can be a static array, a function that returns origins dynamically,
|
|
1157
|
+
* or use wildcard patterns (e.g. `"https://*.example.com"`).
|
|
1149
1158
|
*
|
|
1150
1159
|
* @param request - The request object.
|
|
1151
1160
|
* It'll be undefined if no request was
|
package/src/types/plugin.ts
CHANGED
|
@@ -19,20 +19,7 @@ type DeepPartial<T> = T extends Function
|
|
|
19
19
|
: T;
|
|
20
20
|
|
|
21
21
|
export type HookEndpointContext = Partial<
|
|
22
|
-
EndpointContext<
|
|
23
|
-
string,
|
|
24
|
-
any,
|
|
25
|
-
any,
|
|
26
|
-
any,
|
|
27
|
-
any,
|
|
28
|
-
any,
|
|
29
|
-
any,
|
|
30
|
-
AuthContext & {
|
|
31
|
-
returned?: unknown | undefined;
|
|
32
|
-
responseHeaders?: Headers | undefined;
|
|
33
|
-
}
|
|
34
|
-
> &
|
|
35
|
-
Omit<InputContext<string, any, any, any, any, any>, "method">
|
|
22
|
+
EndpointContext<string, any> & Omit<InputContext<string, any>, "method">
|
|
36
23
|
> & {
|
|
37
24
|
path?: string;
|
|
38
25
|
context: AuthContext & {
|
|
@@ -51,6 +38,7 @@ export type BetterAuthPluginErrorCodePart = {
|
|
|
51
38
|
|
|
52
39
|
export type BetterAuthPlugin = BetterAuthPluginErrorCodePart & {
|
|
53
40
|
id: LiteralString;
|
|
41
|
+
version?: string | undefined;
|
|
54
42
|
/**
|
|
55
43
|
* The init function is called when the plugin is initialized.
|
|
56
44
|
* You can return a new context or modify the existing context.
|
package/dist/api/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import type {\n\tEndpoint,\n\tEndpointContext,\n\tEndpointMetadata,\n\tEndpointRuntimeOptions,\n\tHTTPMethod,\n\tMiddleware,\n\tResolveBodyInput,\n\tResolveErrorInput,\n\tResolveMetaInput,\n\tResolveQueryInput,\n\tStandardSchemaV1,\n} from \"better-call\";\nimport { createEndpoint, createMiddleware } from \"better-call\";\nimport { runWithEndpointContext } from \"../context\";\nimport type { AuthContext } from \"../types\";\n\nexport const optionsMiddleware = createMiddleware(async () => {\n\t/**\n\t * This will be passed on the instance of\n\t * the context. Used to infer the type\n\t * here.\n\t */\n\treturn {} as AuthContext;\n});\n\nexport const createAuthMiddleware = createMiddleware.create({\n\tuse: [\n\t\toptionsMiddleware,\n\t\t/**\n\t\t * Only use for post hooks\n\t\t */\n\t\tcreateMiddleware(async () => {\n\t\t\treturn {} as {\n\t\t\t\treturned?: unknown | undefined;\n\t\t\t\tresponseHeaders?: Headers | undefined;\n\t\t\t};\n\t\t}),\n\t],\n});\n\nconst use = [optionsMiddleware];\n\ntype BodyOption<M, B extends object | undefined = undefined> = M extends\n\t| \"GET\"\n\t| \"HEAD\"\n\t| (\"GET\" | \"HEAD\")[]\n\t? { body?: never }\n\t: { body?: B };\n\ntype AuthEndpointOptions<\n\tMethod extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined,\n\tQuerySchema extends object | undefined,\n\tUse extends Middleware[],\n\tReqHeaders extends boolean,\n\tReqRequest extends boolean,\n\tMeta extends EndpointMetadata | undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n> = { method: Method } & BodyOption<Method, BodySchema> & {\n\t\tquery?: QuerySchema;\n\t\tuse?: [...Use];\n\t\trequireHeaders?: ReqHeaders;\n\t\trequireRequest?: ReqRequest;\n\t\terror?: ErrorSchema;\n\t\tcloneRequest?: boolean;\n\t\tdisableBody?: boolean;\n\t\tmetadata?: Meta;\n\t\t[key: string]: any;\n\t};\n\n/**\n * Normalize readonly tuples produced by `const` type parameters\n * into mutable arrays so downstream `M extends Array<any>` checks work.\n */\ntype NormalizeMethod<M> = M extends readonly (infer E)[] ? E[] : M;\n\n// Path + options + handler overload\nexport function createAuthEndpoint<\n\tPath extends string,\n\tconst Method extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined = undefined,\n\tQuerySchema extends object | undefined = undefined,\n\tUse extends Middleware[] = [],\n\tReqHeaders extends boolean = false,\n\tReqRequest extends boolean = false,\n\tR = unknown,\n\tMeta extends EndpointMetadata | undefined = undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n>(\n\tpath: Path,\n\toptions: AuthEndpointOptions<\n\t\tMethod,\n\t\tBodySchema,\n\t\tQuerySchema,\n\t\tUse,\n\t\tReqHeaders,\n\t\tReqRequest,\n\t\tMeta,\n\t\tErrorSchema\n\t>,\n\thandler: (\n\t\tctx: EndpointContext<\n\t\t\tPath,\n\t\t\tMethod,\n\t\t\tBodySchema,\n\t\t\tQuerySchema,\n\t\t\tUse,\n\t\t\tReqHeaders,\n\t\t\tReqRequest,\n\t\t\tAuthContext,\n\t\t\tMeta\n\t\t>,\n\t) => Promise<R>,\n): Endpoint<\n\tPath,\n\tNormalizeMethod<Method>,\n\tResolveBodyInput<BodySchema, Meta>,\n\tResolveQueryInput<QuerySchema, Meta>,\n\tUse,\n\tR,\n\tResolveMetaInput<Meta>,\n\tResolveErrorInput<ErrorSchema, Meta>\n>;\n\n// Options-only (virtual/path-less) overload\nexport function createAuthEndpoint<\n\tconst Method extends HTTPMethod | HTTPMethod[] | \"*\",\n\tBodySchema extends object | undefined = undefined,\n\tQuerySchema extends object | undefined = undefined,\n\tUse extends Middleware[] = [],\n\tReqHeaders extends boolean = false,\n\tReqRequest extends boolean = false,\n\tR = unknown,\n\tMeta extends EndpointMetadata | undefined = undefined,\n\tErrorSchema extends StandardSchemaV1 | undefined = undefined,\n>(\n\toptions: AuthEndpointOptions<\n\t\tMethod,\n\t\tBodySchema,\n\t\tQuerySchema,\n\t\tUse,\n\t\tReqHeaders,\n\t\tReqRequest,\n\t\tMeta,\n\t\tErrorSchema\n\t>,\n\thandler: (\n\t\tctx: EndpointContext<\n\t\t\tstring,\n\t\t\tMethod,\n\t\t\tBodySchema,\n\t\t\tQuerySchema,\n\t\t\tUse,\n\t\t\tReqHeaders,\n\t\t\tReqRequest,\n\t\t\tAuthContext,\n\t\t\tMeta\n\t\t>,\n\t) => Promise<R>,\n): Endpoint<\n\tstring,\n\tNormalizeMethod<Method>,\n\tResolveBodyInput<BodySchema, Meta>,\n\tResolveQueryInput<QuerySchema, Meta>,\n\tUse,\n\tR,\n\tResolveMetaInput<Meta>,\n\tResolveErrorInput<ErrorSchema, Meta>\n>;\n\n// Implementation\nexport function createAuthEndpoint(\n\tpathOrOptions: any,\n\thandlerOrOptions: any,\n\thandlerOrNever?: any,\n) {\n\tconst path: string | undefined =\n\t\ttypeof pathOrOptions === \"string\" ? pathOrOptions : undefined;\n\tconst options: EndpointRuntimeOptions =\n\t\ttypeof handlerOrOptions === \"object\" ? handlerOrOptions : pathOrOptions;\n\tconst handler =\n\t\ttypeof handlerOrOptions === \"function\" ? handlerOrOptions : handlerOrNever;\n\n\tif (path) {\n\t\treturn createEndpoint(\n\t\t\tpath,\n\t\t\t{\n\t\t\t\t...options,\n\t\t\t\tuse: [...(options?.use || []), ...use],\n\t\t\t} as any,\n\t\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\t\tasync (ctx: any) => runWithEndpointContext(ctx, () => handler(ctx)),\n\t\t);\n\t}\n\n\treturn createEndpoint(\n\t\t{\n\t\t\t...options,\n\t\t\tuse: [...(options?.use || []), ...use],\n\t\t} as any,\n\t\t// todo: prettify the code, we want to call `runWithEndpointContext` to top level\n\t\tasync (ctx: any) => runWithEndpointContext(ctx, () => handler(ctx)),\n\t);\n}\n\nexport type AuthEndpoint = ReturnType<typeof createAuthEndpoint>;\n/**\n * The handler type for plugin hooks.\n *\n * Accepts both `Middleware` instances (from `createAuthMiddleware`)\n * and plain async functions for better-call v1/v2 compatibility.\n */\nexport type AuthMiddleware = (\n\tinputContext: Record<string, any>,\n) => Promise<unknown>;\n"],"mappings":";;;;AAiBA,MAAa,oBAAoB,iBAAiB,YAAY;;;;;;AAM7D,QAAO,EAAE;EACR;AAEF,MAAa,uBAAuB,iBAAiB,OAAO,EAC3D,KAAK,CACJ,mBAIA,iBAAiB,YAAY;AAC5B,QAAO,EAAE;EAIR,CACF,EACD,CAAC;AAEF,MAAM,MAAM,CAAC,kBAAkB;AAmI/B,SAAgB,mBACf,eACA,kBACA,gBACC;CACD,MAAM,OACL,OAAO,kBAAkB,WAAW,gBAAgB,KAAA;CACrD,MAAM,UACL,OAAO,qBAAqB,WAAW,mBAAmB;CAC3D,MAAM,UACL,OAAO,qBAAqB,aAAa,mBAAmB;AAE7D,KAAI,KACH,QAAO,eACN,MACA;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAa,uBAAuB,WAAW,QAAQ,IAAI,CAAC,CACnE;AAGF,QAAO,eACN;EACC,GAAG;EACH,KAAK,CAAC,GAAI,SAAS,OAAO,EAAE,EAAG,GAAG,IAAI;EACtC,EAED,OAAO,QAAa,uBAAuB,WAAW,QAAQ,IAAI,CAAC,CACnE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/async_hooks/index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type { AsyncLocalStorage };\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\timport(\n\t\t/* @vite-ignore */\n\t\t/* webpackIgnore: true */\n\t\t\"node:async_hooks\"\n\t)\n\t\t.then((mod) => mod.AsyncLocalStorage)\n\t\t.catch((err) => {\n\t\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t\t}\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler\",\n\t\t\t);\n\t\t\tconsole.warn(\n\t\t\t\t\"[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag\",\n\t\t\t);\n\t\t\tthrow err;\n\t\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";AAIA,MAAM,2BACL;;;CAGC;EAEC,MAAM,QAAQ,IAAI,kBAAkB,CACpC,OAAO,QAAQ;AACf,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,KAAI,OAAO,WAAW,YACrB,QAAO;AAER,SAAQ,KACP,yHACA;AACD,SAAQ,KACP,+GACA;AACD,SAAQ,KACP,wKACA;AACD,OAAM;EACL;AAEJ,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pure.index.mjs","names":["#current"],"sources":["../../src/async_hooks/pure.index.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Due to the lack of AsyncLocalStorage in some environments (like Convex),\n *\n * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.\n */\nclass AsyncLocalStoragePolyfill<T> {\n\t#current: T | undefined = undefined;\n\n\trun(store: T, fn: () => unknown): unknown {\n\t\tconst prev = this.#current;\n\t\tthis.#current = store;\n\t\tconst result = fn();\n\t\tif (result instanceof Promise) {\n\t\t\treturn result.finally(() => {\n\t\t\t\tthis.#current = prev;\n\t\t\t});\n\t\t}\n\t\tthis.#current = prev;\n\t\treturn result;\n\t}\n\n\tgetStore(): T | undefined {\n\t\treturn this.#current;\n\t}\n}\n\nconst AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =\n\tPromise.resolve().then(() => {\n\t\tif (\"AsyncLocalStorage\" in globalThis) {\n\t\t\treturn (globalThis as any).AsyncLocalStorage;\n\t\t}\n\t\treturn AsyncLocalStoragePolyfill;\n\t});\n\nexport async function getAsyncLocalStorage(): Promise<\n\ttypeof AsyncLocalStorage\n> {\n\tconst mod = await AsyncLocalStoragePromise;\n\tif (mod === null) {\n\t\tthrow new Error(\"getAsyncLocalStorage is only available in server code\");\n\t} else {\n\t\treturn mod;\n\t}\n}\n"],"mappings":";;;;;;AAOA,IAAM,4BAAN,MAAmC;CAClC,WAA0B,KAAA;CAE1B,IAAI,OAAU,IAA4B;EACzC,MAAM,OAAO,MAAA;AACb,QAAA,UAAgB;EAChB,MAAM,SAAS,IAAI;AACnB,MAAI,kBAAkB,QACrB,QAAO,OAAO,cAAc;AAC3B,SAAA,UAAgB;IACf;AAEH,QAAA,UAAgB;AAChB,SAAO;;CAGR,WAA0B;AACzB,SAAO,MAAA;;;AAIT,MAAM,2BACL,QAAQ,SAAS,CAAC,WAAW;AAC5B,KAAI,uBAAuB,WAC1B,QAAQ,WAAmB;AAE5B,QAAO;EACN;AAEH,eAAsB,uBAEpB;CACD,MAAM,MAAM,MAAM;AAClB,KAAI,QAAQ,KACX,OAAM,IAAI,MAAM,wDAAwD;KAExE,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-context.mjs","names":[],"sources":["../../src/context/endpoint-context.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { EndpointContext, InputContext } from \"better-call\";\nimport type { AuthContext } from \"../types\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type AuthEndpointContext = Partial<\n\tInputContext<string, any, any, any, any, any> &\n\t\tEndpointContext<string, any, any, any, any, any, any, AuthContext>\n> & {\n\tcontext: AuthContext;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.endpointContextAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.endpointContextAsyncStorage =\n\t\t\tnew AsyncLocalStorage<AuthEndpointContext>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.endpointContextAsyncStorage as AsyncLocalStorage<AuthEndpointContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAuthContext` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport async function getCurrentAuthContextAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function getCurrentAuthContext(): Promise<AuthEndpointContext> {\n\tconst als = await ensureAsyncStorage();\n\tconst context = als.getStore();\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.\",\n\t\t);\n\t}\n\treturn context;\n}\n\nexport async function runWithEndpointContext<T>(\n\tcontext: AuthEndpointContext,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(context, fn);\n}\n"],"mappings":";;;AAaA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,6BAA6B;EAC1D,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,8BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;;;;;;AAQH,eAAsB,yCAAyC;AAC9D,QAAO,oBAAoB;;AAG5B,eAAsB,wBAAsD;CAE3E,MAAM,WADM,MAAM,oBAAoB,EAClB,UAAU;AAC9B,KAAI,CAAC,QACJ,OAAM,IAAI,MACT,oHACA;AAEF,QAAO;;AAGR,eAAsB,uBACrB,SACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,SAAS,GAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global.mjs","names":[],"sources":["../../src/context/global.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\n\ninterface BetterAuthGlobal {\n\t/**\n\t * The version of BetterAuth.\n\t */\n\tversion: string;\n\t/**\n\t * Used to track the number of BetterAuth instances in the same process.\n\t *\n\t * Debugging purposes only.\n\t */\n\tepoch: number;\n\t/**\n\t * Stores the AsyncLocalStorage instances for each context.\n\t */\n\tcontext: Record<string, AsyncLocalStorage<unknown>>;\n}\n\nconst symbol = Symbol.for(\"better-auth:global\");\nlet bind: BetterAuthGlobal | null = null;\n\nconst __context: Record<string, AsyncLocalStorage<unknown>> = {};\nconst __betterAuthVersion: string = import.meta.env\n\t.BETTER_AUTH_VERSION as string;\n\n/**\n * We store context instance in the globalThis.\n *\n * The reason we do this is that some bundlers, web framework, or package managers might\n * create multiple copies of BetterAuth in the same process intentionally or unintentionally.\n *\n * For example, yarn v1, Next.js, SSR, Vite...\n *\n * @internal\n */\nexport function __getBetterAuthGlobal(): BetterAuthGlobal {\n\tif (!(globalThis as any)[symbol]) {\n\t\t(globalThis as any)[symbol] = {\n\t\t\tversion: __betterAuthVersion,\n\t\t\tepoch: 1,\n\t\t\tcontext: __context,\n\t\t};\n\t\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\t}\n\tbind = (globalThis as any)[symbol] as BetterAuthGlobal;\n\tif (bind.version !== __betterAuthVersion) {\n\t\tbind.version = __betterAuthVersion;\n\t\t// Different versions of BetterAuth are loaded in the same process.\n\t\tbind.epoch++;\n\t}\n\treturn (globalThis as any)[symbol] as BetterAuthGlobal;\n}\n\nexport function getBetterAuthVersion(): string {\n\treturn __getBetterAuthGlobal().version;\n}\n"],"mappings":";AAmBA,MAAM,SAAS,OAAO,IAAI,qBAAqB;AAC/C,IAAI,OAAgC;AAEpC,MAAM,YAAwD,EAAE;AAChE,MAAM,sBAAA;;;;;;;;;;;AAaN,SAAgB,wBAA0C;AACzD,KAAI,CAAE,WAAmB,SAAS;AAChC,aAAmB,UAAU;GAC7B,SAAS;GACT,OAAO;GACP,SAAS;GACT;AACD,SAAQ,WAAmB;;AAE5B,QAAQ,WAAmB;AAC3B,KAAI,KAAK,YAAY,qBAAqB;AACzC,OAAK,UAAU;AAEf,OAAK;;AAEN,QAAQ,WAAmB;;AAG5B,SAAgB,uBAA+B;AAC9C,QAAO,uBAAuB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-state.mjs","names":[],"sources":["../../src/context/request-state.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\nexport type RequestStateWeakMap = WeakMap<object, any>;\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.requestStateAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.requestStateAsyncStorage =\n\t\t\tnew AsyncLocalStorage<RequestStateWeakMap>();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;\n};\n\nexport async function getRequestStateAsyncLocalStorage() {\n\treturn ensureAsyncStorage();\n}\n\nexport async function hasRequestState() {\n\tconst als = await ensureAsyncStorage();\n\treturn als.getStore() !== undefined;\n}\n\nexport async function getCurrentRequestState(): Promise<RequestStateWeakMap> {\n\tconst als = await ensureAsyncStorage();\n\tconst store = als.getStore();\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t\"No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.\",\n\t\t);\n\t}\n\treturn store;\n}\n\nexport async function runWithRequestState<T>(\n\tstore: RequestStateWeakMap,\n\tfn: () => T,\n): Promise<T> {\n\tconst als = await ensureAsyncStorage();\n\treturn als.run(store, fn);\n}\n\nexport interface RequestState<T> {\n\tget(): Promise<T>;\n\tset(value: T): Promise<void>;\n\n\t// A unique reference used as a key to identify this state within the request's WeakMap. Useful for debugging purposes.\n\treadonly ref: Readonly<object>;\n}\n\n/**\n * Defines a request-scoped state with lazy initialization.\n *\n * @param initFn - A function that initializes the state. It is called the first time `get()` is invoked within each request context, and only once per context.\n * @returns A RequestState object with `get` and `set` methods, and a unique `ref` for debugging.\n *\n * @example\n * const userState = defineRequestState(() => ({ id: '', name: '' }));\n * // Later, within a request context:\n * const user = await userState.get();\n */\nexport function defineRequestState<T>(\n\tinitFn: () => T | Promise<T>,\n): RequestState<T>;\nexport function defineRequestState(\n\tinitFn: () => any | Promise<any>,\n): RequestState<any> {\n\tconst ref = Object.freeze({});\n\treturn {\n\t\tget ref(): Readonly<object> {\n\t\t\treturn ref;\n\t\t},\n\t\tasync get() {\n\t\t\tconst store = await getCurrentRequestState();\n\t\t\tif (!store.has(ref)) {\n\t\t\t\tconst initialValue = await initFn();\n\t\t\t\tstore.set(ref, initialValue);\n\t\t\t\treturn initialValue;\n\t\t\t}\n\t\t\treturn store.get(ref);\n\t\t},\n\n\t\tasync set(value) {\n\t\t\tconst store = await getCurrentRequestState();\n\t\t\tstore.set(ref, value);\n\t\t},\n\t};\n}\n"],"mappings":";;;AAMA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,0BAA0B;EACvD,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,2BACxB,IAAI,mBAAwC;;AAE9C,QAAO,iBAAiB,QACtB;;AAGH,eAAsB,mCAAmC;AACxD,QAAO,oBAAoB;;AAG5B,eAAsB,kBAAkB;AAEvC,SADY,MAAM,oBAAoB,EAC3B,UAAU,KAAK,KAAA;;AAG3B,eAAsB,yBAAuD;CAE5E,MAAM,SADM,MAAM,oBAAoB,EACpB,UAAU;AAC5B,KAAI,CAAC,MACJ,OAAM,IAAI,MACT,kHACA;AAEF,QAAO;;AAGR,eAAsB,oBACrB,OACA,IACa;AAEb,SADY,MAAM,oBAAoB,EAC3B,IAAI,OAAO,GAAG;;AAyB1B,SAAgB,mBACf,QACoB;CACpB,MAAM,MAAM,OAAO,OAAO,EAAE,CAAC;AAC7B,QAAO;EACN,IAAI,MAAwB;AAC3B,UAAO;;EAER,MAAM,MAAM;GACX,MAAM,QAAQ,MAAM,wBAAwB;AAC5C,OAAI,CAAC,MAAM,IAAI,IAAI,EAAE;IACpB,MAAM,eAAe,MAAM,QAAQ;AACnC,UAAM,IAAI,KAAK,aAAa;AAC5B,WAAO;;AAER,UAAO,MAAM,IAAI,IAAI;;EAGtB,MAAM,IAAI,OAAO;AAEhB,IADc,MAAM,wBAAwB,EACtC,IAAI,KAAK,MAAM;;EAEtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","names":[],"sources":["../../src/context/transaction.ts"],"sourcesContent":["import type { AsyncLocalStorage } from \"node:async_hooks\";\nimport { getAsyncLocalStorage } from \"@better-auth/core/async_hooks\";\nimport type { DBAdapter, DBTransactionAdapter } from \"../db/adapter\";\nimport { __getBetterAuthGlobal } from \"./global\";\n\ntype HookContext = {\n\tadapter: DBTransactionAdapter;\n\tpendingHooks: Array<() => Promise<void>>;\n};\n\nconst ensureAsyncStorage = async () => {\n\tconst betterAuthGlobal = __getBetterAuthGlobal();\n\tif (!betterAuthGlobal.context.adapterAsyncStorage) {\n\t\tconst AsyncLocalStorage = await getAsyncLocalStorage();\n\t\tbetterAuthGlobal.context.adapterAsyncStorage = new AsyncLocalStorage();\n\t}\n\treturn betterAuthGlobal.context\n\t\t.adapterAsyncStorage as AsyncLocalStorage<HookContext>;\n};\n\n/**\n * This is for internal use only. Most users should use `getCurrentAdapter` instead.\n *\n * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.\n */\nexport const getCurrentDBAdapterAsyncLocalStorage = async () => {\n\treturn ensureAsyncStorage();\n};\n\nexport const getCurrentAdapter = async (\n\tfallback: DBTransactionAdapter,\n): Promise<DBTransactionAdapter> => {\n\treturn ensureAsyncStorage()\n\t\t.then((als) => {\n\t\t\tconst store = als.getStore();\n\t\t\treturn store?.adapter || fallback;\n\t\t})\n\t\t.catch(() => {\n\t\t\treturn fallback;\n\t\t});\n};\n\nexport const runWithAdapter = async <R>(\n\tadapter: DBAdapter,\n\tfn: () => R,\n): Promise<R> => {\n\tlet called = false;\n\treturn ensureAsyncStorage()\n\t\t.then(async (als) => {\n\t\t\tcalled = true;\n\t\t\tconst pendingHooks: Array<() => Promise<void>> = [];\n\t\t\tlet result: Awaited<R>;\n\t\t\tlet error: unknown;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tresult = await als.run({ adapter, pendingHooks }, fn);\n\t\t\t} catch (err) {\n\t\t\t\terror = err;\n\t\t\t\thasError = true;\n\t\t\t}\n\t\t\t// Execute pending hooks after the function completes (even if it threw)\n\t\t\tfor (const hook of pendingHooks) {\n\t\t\t\tawait hook();\n\t\t\t}\n\t\t\tif (hasError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn result!;\n\t\t})\n\t\t.catch((err) => {\n\t\t\tif (!called) {\n\t\t\t\treturn fn();\n\t\t\t}\n\t\t\tthrow err;\n\t\t});\n};\n\nexport const runWithTransaction = async <R>(\n\tadapter: DBAdapter,\n\tfn: () => R,\n): Promise<R> => {\n\tlet called = true;\n\treturn ensureAsyncStorage()\n\t\t.then(async (als) => {\n\t\t\tcalled = true;\n\t\t\tconst pendingHooks: Array<() => Promise<void>> = [];\n\t\t\tlet result: Awaited<R>;\n\t\t\tlet error: unknown;\n\t\t\tlet hasError = false;\n\t\t\ttry {\n\t\t\t\tresult = await adapter.transaction(async (trx) => {\n\t\t\t\t\treturn als.run({ adapter: trx, pendingHooks }, fn);\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\thasError = true;\n\t\t\t\terror = e;\n\t\t\t}\n\t\t\tfor (const hook of pendingHooks) {\n\t\t\t\tawait hook();\n\t\t\t}\n\t\t\tif (hasError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn result!;\n\t\t})\n\t\t.catch((err) => {\n\t\t\tif (!called) {\n\t\t\t\treturn fn();\n\t\t\t}\n\t\t\tthrow err;\n\t\t});\n};\n\n/**\n * Queue a hook to be executed after the current transaction commits.\n * If not in a transaction, the hook will execute immediately.\n */\nexport const queueAfterTransactionHook = async (\n\thook: () => Promise<void>,\n): Promise<void> => {\n\treturn ensureAsyncStorage()\n\t\t.then((als) => {\n\t\t\tconst store = als.getStore();\n\t\t\tif (store) {\n\t\t\t\t// We're in a transaction context, queue the hook\n\t\t\t\tstore.pendingHooks.push(hook);\n\t\t\t} else {\n\t\t\t\t// Not in a transaction, execute immediately\n\t\t\t\treturn hook();\n\t\t\t}\n\t\t})\n\t\t.catch(() => {\n\t\t\t// No async storage available, execute immediately\n\t\t\treturn hook();\n\t\t});\n};\n"],"mappings":";;;AAUA,MAAM,qBAAqB,YAAY;CACtC,MAAM,mBAAmB,uBAAuB;AAChD,KAAI,CAAC,iBAAiB,QAAQ,qBAAqB;EAClD,MAAM,oBAAoB,MAAM,sBAAsB;AACtD,mBAAiB,QAAQ,sBAAsB,IAAI,mBAAmB;;AAEvE,QAAO,iBAAiB,QACtB;;;;;;;AAQH,MAAa,uCAAuC,YAAY;AAC/D,QAAO,oBAAoB;;AAG5B,MAAa,oBAAoB,OAChC,aACmC;AACnC,QAAO,oBAAoB,CACzB,MAAM,QAAQ;AAEd,SADc,IAAI,UAAU,EACd,WAAW;GACxB,CACD,YAAY;AACZ,SAAO;GACN;;AAGJ,MAAa,iBAAiB,OAC7B,SACA,OACgB;CAChB,IAAI,SAAS;AACb,QAAO,oBAAoB,CACzB,KAAK,OAAO,QAAQ;AACpB,WAAS;EACT,MAAM,eAA2C,EAAE;EACnD,IAAI;EACJ,IAAI;EACJ,IAAI,WAAW;AACf,MAAI;AACH,YAAS,MAAM,IAAI,IAAI;IAAE;IAAS;IAAc,EAAE,GAAG;WAC7C,KAAK;AACb,WAAQ;AACR,cAAW;;AAGZ,OAAK,MAAM,QAAQ,aAClB,OAAM,MAAM;AAEb,MAAI,SACH,OAAM;AAEP,SAAO;GACN,CACD,OAAO,QAAQ;AACf,MAAI,CAAC,OACJ,QAAO,IAAI;AAEZ,QAAM;GACL;;AAGJ,MAAa,qBAAqB,OACjC,SACA,OACgB;CAChB,IAAI,SAAS;AACb,QAAO,oBAAoB,CACzB,KAAK,OAAO,QAAQ;AACpB,WAAS;EACT,MAAM,eAA2C,EAAE;EACnD,IAAI;EACJ,IAAI;EACJ,IAAI,WAAW;AACf,MAAI;AACH,YAAS,MAAM,QAAQ,YAAY,OAAO,QAAQ;AACjD,WAAO,IAAI,IAAI;KAAE,SAAS;KAAK;KAAc,EAAE,GAAG;KACjD;WACM,GAAG;AACX,cAAW;AACX,WAAQ;;AAET,OAAK,MAAM,QAAQ,aAClB,OAAM,MAAM;AAEb,MAAI,SACH,OAAM;AAEP,SAAO;GACN,CACD,OAAO,QAAQ;AACf,MAAI,CAAC,OACJ,QAAO,IAAI;AAEZ,QAAM;GACL;;;;;;AAOJ,MAAa,4BAA4B,OACxC,SACmB;AACnB,QAAO,oBAAoB,CACzB,MAAM,QAAQ;EACd,MAAM,QAAQ,IAAI,UAAU;AAC5B,MAAI,MAEH,OAAM,aAAa,KAAK,KAAK;MAG7B,QAAO,MAAM;GAEb,CACD,YAAY;AAEZ,SAAO,MAAM;GACZ"}
|