@better-auth/core 1.4.17 → 1.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +253 -176
- package/dist/api/index.d.mts +11 -5
- package/dist/api/index.mjs +2 -1
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +2 -1
- package/dist/async_hooks/index.mjs +2 -1
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +2 -1
- package/dist/async_hooks/pure.index.mjs +2 -1
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +2 -1
- package/dist/context/endpoint-context.mjs +2 -1
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +2 -1
- package/dist/context/global.mjs +3 -2
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/request-state.d.mts +2 -1
- package/dist/context/request-state.mjs +2 -1
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +2 -1
- package/dist/context/transaction.mjs +2 -1
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +2 -1
- package/dist/db/adapter/factory.mjs +9 -27
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +2 -1
- package/dist/db/adapter/get-default-field-name.mjs +2 -1
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +2 -1
- package/dist/db/adapter/get-default-model-name.mjs +2 -1
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +2 -1
- package/dist/db/adapter/get-field-attributes.mjs +2 -1
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +2 -1
- package/dist/db/adapter/get-field-name.mjs +2 -1
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +2 -1
- package/dist/db/adapter/get-id-field.mjs +2 -1
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +2 -1
- package/dist/db/adapter/get-model-name.mjs +2 -1
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +5 -1
- package/dist/db/adapter/types.d.mts +2 -1
- package/dist/db/adapter/utils.d.mts +2 -1
- package/dist/db/adapter/utils.mjs +2 -1
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +2 -1
- package/dist/db/get-tables.mjs +8 -2
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/plugin.d.mts +2 -1
- package/dist/db/schema/account.d.mts +2 -1
- package/dist/db/schema/account.mjs +2 -1
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +2 -1
- package/dist/db/schema/rate-limit.mjs +2 -1
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +2 -1
- package/dist/db/schema/session.mjs +2 -1
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +2 -1
- package/dist/db/schema/shared.mjs +2 -1
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +2 -1
- package/dist/db/schema/user.mjs +2 -1
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +2 -1
- package/dist/db/schema/verification.mjs +2 -1
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +2 -1
- package/dist/env/color-depth.d.mts +2 -1
- package/dist/env/color-depth.mjs +2 -1
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +3 -2
- package/dist/env/env-impl.mjs +3 -2
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/logger.d.mts +2 -1
- package/dist/env/logger.mjs +3 -2
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +2 -1
- package/dist/error/codes.mjs +2 -1
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +2 -1
- package/dist/error/index.mjs +2 -1
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/oauth2/client-credentials-token.d.mts +2 -1
- package/dist/oauth2/client-credentials-token.mjs +2 -1
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +2 -1
- package/dist/oauth2/create-authorization-url.mjs +2 -1
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/oauth-provider.d.mts +3 -2
- package/dist/oauth2/refresh-access-token.d.mts +2 -1
- package/dist/oauth2/refresh-access-token.mjs +2 -1
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +2 -1
- package/dist/oauth2/utils.mjs +2 -1
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +6 -2
- package/dist/oauth2/validate-authorization-code.mjs +7 -12
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +2 -1
- package/dist/oauth2/verify.mjs +2 -1
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +2 -1
- package/dist/social-providers/apple.mjs +22 -15
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +2 -1
- package/dist/social-providers/atlassian.mjs +2 -1
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +2 -1
- package/dist/social-providers/cognito.mjs +2 -1
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +2 -1
- package/dist/social-providers/discord.mjs +2 -1
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +2 -1
- package/dist/social-providers/dropbox.mjs +2 -1
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +2 -1
- package/dist/social-providers/facebook.mjs +5 -4
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +2 -1
- package/dist/social-providers/figma.mjs +2 -1
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +3 -2
- package/dist/social-providers/github.mjs +22 -5
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +2 -1
- package/dist/social-providers/gitlab.mjs +2 -1
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +2 -1
- package/dist/social-providers/google.mjs +18 -13
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +2 -1
- package/dist/social-providers/huggingface.mjs +2 -1
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +5 -3
- package/dist/social-providers/index.mjs +3 -2
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +2 -1
- package/dist/social-providers/kakao.mjs +2 -1
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +2 -1
- package/dist/social-providers/kick.mjs +2 -1
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +2 -1
- package/dist/social-providers/line.mjs +2 -1
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +2 -1
- package/dist/social-providers/linear.mjs +2 -1
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +2 -1
- package/dist/social-providers/linkedin.mjs +2 -1
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +4 -1
- package/dist/social-providers/microsoft-entra-id.mjs +36 -2
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +2 -1
- package/dist/social-providers/naver.mjs +2 -1
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +2 -1
- package/dist/social-providers/notion.mjs +2 -1
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +2 -1
- package/dist/social-providers/paybin.mjs +2 -1
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +2 -1
- package/dist/social-providers/paypal.mjs +2 -1
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +2 -1
- package/dist/social-providers/polar.mjs +2 -1
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +2 -1
- package/dist/social-providers/reddit.mjs +2 -1
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +2 -1
- package/dist/social-providers/roblox.mjs +2 -1
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +2 -1
- package/dist/social-providers/salesforce.mjs +2 -1
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +2 -1
- package/dist/social-providers/slack.mjs +2 -1
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +2 -1
- package/dist/social-providers/spotify.mjs +2 -1
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +2 -1
- package/dist/social-providers/tiktok.mjs +2 -1
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +2 -1
- package/dist/social-providers/twitch.mjs +2 -1
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +3 -2
- package/dist/social-providers/twitter.mjs +2 -1
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +2 -1
- package/dist/social-providers/vercel.mjs +2 -1
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +2 -1
- package/dist/social-providers/vk.mjs +2 -1
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +3 -3
- package/dist/social-providers/zoom.mjs +2 -1
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +7 -3
- package/dist/types/cookie.d.mts +2 -1
- package/dist/types/helper.d.mts +2 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +36 -33
- package/dist/types/plugin-client.d.mts +2 -1
- package/dist/types/plugin.d.mts +2 -1
- package/dist/utils/db.d.mts +13 -0
- package/dist/utils/db.mjs +17 -0
- package/dist/utils/db.mjs.map +1 -0
- package/dist/utils/deprecate.d.mts +2 -1
- package/dist/utils/deprecate.mjs +2 -1
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +2 -1
- package/dist/utils/error-codes.mjs +2 -1
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +2 -1
- package/dist/utils/id.mjs +2 -1
- package/dist/utils/id.mjs.map +1 -0
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/index.mjs +2 -1
- package/dist/utils/ip.d.mts +2 -1
- package/dist/utils/ip.mjs +2 -1
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/json.d.mts +2 -1
- package/dist/utils/json.mjs +2 -1
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +2 -1
- package/dist/utils/string.mjs +2 -1
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +2 -1
- package/dist/utils/url.mjs +2 -1
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +1 -1
- package/src/db/adapter/factory.ts +5 -41
- package/src/db/adapter/index.ts +3 -0
- package/src/db/get-tables.ts +5 -0
- package/src/env/env-impl.ts +2 -2
- package/src/env/logger.ts +1 -1
- package/src/oauth2/oauth-provider.ts +1 -1
- package/src/oauth2/validate-authorization-code.ts +13 -26
- package/src/oauth2/validate-token.test.ts +241 -0
- package/src/social-providers/apple.ts +37 -24
- package/src/social-providers/facebook.ts +3 -3
- package/src/social-providers/github.ts +25 -3
- package/src/social-providers/google.ts +18 -14
- package/src/social-providers/microsoft-entra-id.ts +84 -1
- package/src/types/context.ts +6 -3
- package/src/types/index.ts +6 -1
- package/src/types/init-options.ts +44 -36
- package/src/utils/db.ts +20 -0
- package/src/utils/index.ts +1 -0
- package/tsdown.config.ts +3 -0
|
@@ -136,4 +136,5 @@ type AdapterConfig = AdapterFactoryConfig;
|
|
|
136
136
|
*/
|
|
137
137
|
type CreateCustomAdapter = AdapterFactoryCustomizeAdapterCreator;
|
|
138
138
|
//#endregion
|
|
139
|
-
export { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter$1 as CustomAdapter };
|
|
139
|
+
export { AdapterConfig, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter$1 as CustomAdapter };
|
|
140
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -4,4 +4,5 @@ import { DBFieldAttribute } from "../type.mjs";
|
|
|
4
4
|
declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
|
|
5
5
|
declare function deepmerge<T>(target: T, source: Partial<T>): T;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { deepmerge, withApplyDefault };
|
|
7
|
+
export { deepmerge, withApplyDefault };
|
|
8
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["result: Record<string, unknown>"],"sources":["../../../src/db/adapter/utils.ts"],"sourcesContent":["import type { DBFieldAttribute } from \"../type\";\n\nexport function withApplyDefault(\n\tvalue: any,\n\tfield: DBFieldAttribute,\n\taction: \"create\" | \"update\" | \"findOne\" | \"findMany\",\n) {\n\tif (action === \"update\") {\n\t\t// Apply onUpdate if value is undefined\n\t\tif (value === undefined && field.onUpdate !== undefined) {\n\t\t\tif (typeof field.onUpdate === \"function\") {\n\t\t\t\treturn field.onUpdate();\n\t\t\t}\n\t\t\treturn field.onUpdate;\n\t\t}\n\t\treturn value;\n\t}\n\tif (action === \"create\") {\n\t\t// we do not want to apply default values if the value is null & not required\n\t\tif (value === undefined || (field.required === true && value === null)) {\n\t\t\tif (field.defaultValue !== undefined) {\n\t\t\t\tif (typeof field.defaultValue === \"function\") {\n\t\t\t\t\treturn field.defaultValue();\n\t\t\t\t}\n\t\t\t\treturn field.defaultValue;\n\t\t\t}\n\t\t}\n\t}\n\treturn value;\n}\n\nfunction isObject(item: unknown): item is Record<string, unknown> {\n\treturn item !== null && typeof item === \"object\" && !Array.isArray(item);\n}\n\nexport function deepmerge<T>(target: T, source: Partial<T>): T {\n\tif (Array.isArray(target) && Array.isArray(source)) {\n\t\t// merge arrays by concatenation\n\t\treturn [...target, ...source] as T;\n\t} else if (isObject(target) && isObject(source)) {\n\t\tconst result: Record<string, unknown> = { ...target };\n\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tif (value === undefined) continue; // skip undefined\n\n\t\t\tif (key in target) {\n\t\t\t\tresult[key] = deepmerge(\n\t\t\t\t\t(target as Record<string, unknown>)[key],\n\t\t\t\t\tvalue as unknown as Partial<T>,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tresult[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn result as T;\n\t}\n\n\t// primitives and fallback: source overrides target\n\treturn source as T;\n}\n"],"mappings":";AAEA,SAAgB,iBACf,OACA,OACA,QACC;AACD,KAAI,WAAW,UAAU;AAExB,MAAI,UAAU,UAAa,MAAM,aAAa,QAAW;AACxD,OAAI,OAAO,MAAM,aAAa,WAC7B,QAAO,MAAM,UAAU;AAExB,UAAO,MAAM;;AAEd,SAAO;;AAER,KAAI,WAAW,UAEd;MAAI,UAAU,UAAc,MAAM,aAAa,QAAQ,UAAU,MAChE;OAAI,MAAM,iBAAiB,QAAW;AACrC,QAAI,OAAO,MAAM,iBAAiB,WACjC,QAAO,MAAM,cAAc;AAE5B,WAAO,MAAM;;;;AAIhB,QAAO;;AAGR,SAAS,SAAS,MAAgD;AACjE,QAAO,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,KAAK;;AAGzE,SAAgB,UAAa,QAAW,QAAuB;AAC9D,KAAI,MAAM,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,CAEjD,QAAO,CAAC,GAAG,QAAQ,GAAG,OAAO;UACnB,SAAS,OAAO,IAAI,SAAS,OAAO,EAAE;EAChD,MAAMA,SAAkC,EAAE,GAAG,QAAQ;AAErD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;AAClD,OAAI,UAAU,OAAW;AAEzB,OAAI,OAAO,OACV,QAAO,OAAO,UACZ,OAAmC,MACpC,MACA;OAED,QAAO,OAAO;;AAIhB,SAAO;;AAIR,QAAO"}
|
package/dist/db/get-tables.d.mts
CHANGED
package/dist/db/get-tables.mjs
CHANGED
|
@@ -18,16 +18,21 @@ const getAuthTables = (options) => {
|
|
|
18
18
|
fields: {
|
|
19
19
|
key: {
|
|
20
20
|
type: "string",
|
|
21
|
+
unique: true,
|
|
22
|
+
required: true,
|
|
21
23
|
fieldName: options.rateLimit?.fields?.key || "key"
|
|
22
24
|
},
|
|
23
25
|
count: {
|
|
24
26
|
type: "number",
|
|
27
|
+
required: true,
|
|
25
28
|
fieldName: options.rateLimit?.fields?.count || "count"
|
|
26
29
|
},
|
|
27
30
|
lastRequest: {
|
|
28
31
|
type: "number",
|
|
29
32
|
bigint: true,
|
|
30
|
-
|
|
33
|
+
required: true,
|
|
34
|
+
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
|
|
35
|
+
defaultValue: () => Date.now()
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
} };
|
|
@@ -257,4 +262,5 @@ const getAuthTables = (options) => {
|
|
|
257
262
|
};
|
|
258
263
|
|
|
259
264
|
//#endregion
|
|
260
|
-
export { getAuthTables };
|
|
265
|
+
export { getAuthTables };
|
|
266
|
+
//# sourceMappingURL=get-tables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-tables.mjs","names":[],"sources":["../../src/db/get-tables.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"../types\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"./type\";\n\nexport const getAuthTables = (\n\toptions: BetterAuthOptions,\n): BetterAuthDBSchema => {\n\tconst pluginSchema = (options.plugins ?? []).reduce(\n\t\t(acc, plugin) => {\n\t\t\tconst schema = plugin.schema;\n\t\t\tif (!schema) return acc;\n\t\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\t\tacc[key] = {\n\t\t\t\t\tfields: {\n\t\t\t\t\t\t...acc[key]?.fields,\n\t\t\t\t\t\t...value.fields,\n\t\t\t\t\t},\n\t\t\t\t\tmodelName: value.modelName || key,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<\n\t\t\tstring,\n\t\t\t{ fields: Record<string, DBFieldAttribute>; modelName: string }\n\t\t>,\n\t);\n\n\tconst shouldAddRateLimitTable = options.rateLimit?.storage === \"database\";\n\tconst rateLimitTable = {\n\t\trateLimit: {\n\t\t\tmodelName: options.rateLimit?.modelName || \"rateLimit\",\n\t\t\tfields: {\n\t\t\t\tkey: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.key || \"key\",\n\t\t\t\t},\n\t\t\t\tcount: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.count || \"count\",\n\t\t\t\t},\n\t\t\t\tlastRequest: {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tbigint: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.rateLimit?.fields?.lastRequest || \"lastRequest\",\n\t\t\t\t\tdefaultValue: () => Date.now(),\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\tconst { user, session, account, verification, ...pluginTables } =\n\t\tpluginSchema;\n\n\tconst sessionTable = {\n\t\tsession: {\n\t\t\tmodelName: options.session?.modelName || \"session\",\n\t\t\tfields: {\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\ttoken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.token || \"token\",\n\t\t\t\t\tunique: true,\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.session?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\tipAddress: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.ipAddress || \"ipAddress\",\n\t\t\t\t},\n\t\t\t\tuserAgent: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.session?.fields?.userAgent || \"userAgent\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tfieldName: options.session?.fields?.userId || \"userId\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\t...session?.fields,\n\t\t\t\t...options.session?.additionalFields,\n\t\t\t},\n\t\t\torder: 2,\n\t\t},\n\t} satisfies BetterAuthDBSchema;\n\n\treturn {\n\t\tuser: {\n\t\t\tmodelName: options.user?.modelName || \"user\",\n\t\t\tfields: {\n\t\t\t\tname: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.name || \"name\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temail: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tunique: true,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.email || \"email\",\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\temailVerified: {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdefaultValue: false,\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.emailVerified || \"emailVerified\",\n\t\t\t\t\tinput: false,\n\t\t\t\t},\n\t\t\t\timage: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.user?.fields?.image || \"image\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.user?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...user?.fields,\n\t\t\t\t...options.user?.additionalFields,\n\t\t\t},\n\t\t\torder: 1,\n\t\t},\n\t\t//only add session table if it's not stored in secondary storage\n\t\t...(!options.secondaryStorage || options.session?.storeSessionInDatabase\n\t\t\t? sessionTable\n\t\t\t: {}),\n\t\taccount: {\n\t\t\tmodelName: options.account?.modelName || \"account\",\n\t\t\tfields: {\n\t\t\t\taccountId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.accountId || \"accountId\",\n\t\t\t\t},\n\t\t\t\tproviderId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.providerId || \"providerId\",\n\t\t\t\t},\n\t\t\t\tuserId: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\treferences: {\n\t\t\t\t\t\tmodel: options.user?.modelName || \"user\",\n\t\t\t\t\t\tfield: \"id\",\n\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t},\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.userId || \"userId\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\taccessToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.accessToken || \"accessToken\",\n\t\t\t\t},\n\t\t\t\trefreshToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.refreshToken || \"refreshToken\",\n\t\t\t\t},\n\t\t\t\tidToken: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.idToken || \"idToken\",\n\t\t\t\t},\n\t\t\t\taccessTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.accessTokenExpiresAt ||\n\t\t\t\t\t\t\"accessTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\trefreshTokenExpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName:\n\t\t\t\t\t\toptions.account?.fields?.refreshTokenExpiresAt ||\n\t\t\t\t\t\t\"refreshTokenExpiresAt\",\n\t\t\t\t},\n\t\t\t\tscope: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tfieldName: options.account?.fields?.scope || \"scope\",\n\t\t\t\t},\n\t\t\t\tpassword: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\treturned: false,\n\t\t\t\t\tfieldName: options.account?.fields?.password || \"password\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.createdAt || \"createdAt\",\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.account?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t},\n\t\t\t\t...account?.fields,\n\t\t\t\t...options.account?.additionalFields,\n\t\t\t},\n\t\t\torder: 3,\n\t\t},\n\t\tverification: {\n\t\t\tmodelName: options.verification?.modelName || \"verification\",\n\t\t\tfields: {\n\t\t\t\tidentifier: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.identifier || \"identifier\",\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.value || \"value\",\n\t\t\t\t},\n\t\t\t\texpiresAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tfieldName: options.verification?.fields?.expiresAt || \"expiresAt\",\n\t\t\t\t},\n\t\t\t\tcreatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.createdAt || \"createdAt\",\n\t\t\t\t},\n\t\t\t\tupdatedAt: {\n\t\t\t\t\ttype: \"date\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdefaultValue: () => new Date(),\n\t\t\t\t\tonUpdate: () => new Date(),\n\t\t\t\t\tfieldName: options.verification?.fields?.updatedAt || \"updatedAt\",\n\t\t\t\t},\n\t\t\t\t...verification?.fields,\n\t\t\t\t...options.verification?.additionalFields,\n\t\t\t},\n\t\t\torder: 4,\n\t\t},\n\t\t...pluginTables,\n\t\t...(shouldAddRateLimitTable ? rateLimitTable : {}),\n\t} satisfies BetterAuthDBSchema;\n};\n"],"mappings":";AAGA,MAAa,iBACZ,YACwB;CACxB,MAAM,gBAAgB,QAAQ,WAAW,EAAE,EAAE,QAC3C,KAAK,WAAW;EAChB,MAAM,SAAS,OAAO;AACtB,MAAI,CAAC,OAAQ,QAAO;AACpB,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,CAChD,KAAI,OAAO;GACV,QAAQ;IACP,GAAG,IAAI,MAAM;IACb,GAAG,MAAM;IACT;GACD,WAAW,MAAM,aAAa;GAC9B;AAEF,SAAO;IAER,EAAE,CAIF;CAED,MAAM,0BA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aAAa;KACtD;IACD,WAAW;KACV,MAAM;KACN,UAAU;KACV,oCAAoB,IAAI,MAAM;KAC9B,gCAAgB,IAAI,MAAM;KAC1B,WAAW,QAAQ,cAAc,QAAQ,aAAa;KACtD;IACD,GAAG,cAAc;IACjB,GAAG,QAAQ,cAAc;IACzB;GACD,OAAO;GACP;EACD,GAAG;EACH,GAAI,0BAA0B,iBAAiB,EAAE;EACjD"}
|
package/dist/db/plugin.d.mts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.mjs","names":[],"sources":["../../../src/db/schema/account.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const accountSchema = coreSchema.extend({\n\tproviderId: z.string(),\n\taccountId: z.string(),\n\tuserId: z.coerce.string(),\n\taccessToken: z.string().nullish(),\n\trefreshToken: z.string().nullish(),\n\tidToken: z.string().nullish(),\n\t/**\n\t * Access token expires at\n\t */\n\taccessTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * Refresh token expires at\n\t */\n\trefreshTokenExpiresAt: z.date().nullish(),\n\t/**\n\t * The scopes that the user has authorized\n\t */\n\tscope: z.string().nullish(),\n\t/**\n\t * Password is only stored in the credential provider\n\t */\n\tpassword: z.string().nullish(),\n});\n\n/**\n * Account schema type used by better-auth, note that it's possible that account could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Account = z.infer<typeof accountSchema>;\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,YAAY,EAAE,QAAQ;CACtB,WAAW,EAAE,QAAQ;CACrB,QAAQ,EAAE,OAAO,QAAQ;CACzB,aAAa,EAAE,QAAQ,CAAC,SAAS;CACjC,cAAc,EAAE,QAAQ,CAAC,SAAS;CAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;CAI7B,sBAAsB,EAAE,MAAM,CAAC,SAAS;CAIxC,uBAAuB,EAAE,MAAM,CAAC,SAAS;CAIzC,OAAO,EAAE,QAAQ,CAAC,SAAS;CAI3B,UAAU,EAAE,QAAQ,CAAC,SAAS;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../../src/db/schema/rate-limit.ts"],"sourcesContent":["import * as z from \"zod\";\n\nexport const rateLimitSchema = z.object({\n\t/**\n\t * The key to use for rate limiting\n\t */\n\tkey: z.string(),\n\t/**\n\t * The number of requests made\n\t */\n\tcount: z.number(),\n\t/**\n\t * The last request time in milliseconds\n\t */\n\tlastRequest: z.number(),\n});\n\n/**\n * Rate limit schema type used by better-auth for rate limiting\n */\nexport type RateLimit = z.infer<typeof rateLimitSchema>;\n"],"mappings":";;;AAEA,MAAa,kBAAkB,EAAE,OAAO;CAIvC,KAAK,EAAE,QAAQ;CAIf,OAAO,EAAE,QAAQ;CAIjB,aAAa,EAAE,QAAQ;CACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.mjs","names":[],"sources":["../../../src/db/schema/session.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const sessionSchema = coreSchema.extend({\n\tuserId: z.coerce.string(),\n\texpiresAt: z.date(),\n\ttoken: z.string(),\n\tipAddress: z.string().nullish(),\n\tuserAgent: z.string().nullish(),\n});\n\n/**\n * Session schema type used by better-auth, note that it's possible that session could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Session = z.infer<typeof sessionSchema>;\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,WAAW,OAAO;CAC9C,QAAQ,EAAE,OAAO,QAAQ;CACzB,WAAW,EAAE,MAAM;CACnB,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,WAAW,EAAE,QAAQ,CAAC,SAAS;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.mjs","names":[],"sources":["../../../src/db/schema/shared.ts"],"sourcesContent":["import * as z from \"zod\";\n\nexport const coreSchema = z.object({\n\tid: z.string(),\n\tcreatedAt: z.date().default(() => new Date()),\n\tupdatedAt: z.date().default(() => new Date()),\n});\n"],"mappings":";;;AAEA,MAAa,aAAa,EAAE,OAAO;CAClC,IAAI,EAAE,QAAQ;CACd,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,WAAW,EAAE,MAAM,CAAC,8BAAc,IAAI,MAAM,CAAC;CAC7C,CAAC"}
|
package/dist/db/schema/user.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.mjs","names":[],"sources":["../../../src/db/schema/user.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const userSchema = coreSchema.extend({\n\temail: z.string().transform((val) => val.toLowerCase()),\n\temailVerified: z.boolean().default(false),\n\tname: z.string(),\n\timage: z.string().nullish(),\n});\n\n/**\n * User schema type used by better-auth, note that it's possible that user could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type User = z.infer<typeof userSchema>;\n"],"mappings":";;;;AAGA,MAAa,aAAa,WAAW,OAAO;CAC3C,OAAO,EAAE,QAAQ,CAAC,WAAW,QAAQ,IAAI,aAAa,CAAC;CACvD,eAAe,EAAE,SAAS,CAAC,QAAQ,MAAM;CACzC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,QAAQ,CAAC,SAAS;CAC3B,CAAC"}
|
|
@@ -16,4 +16,5 @@ declare const verificationSchema: z.ZodObject<{
|
|
|
16
16
|
*/
|
|
17
17
|
type Verification = z.infer<typeof verificationSchema>;
|
|
18
18
|
//#endregion
|
|
19
|
-
export { Verification, verificationSchema };
|
|
19
|
+
export { Verification, verificationSchema };
|
|
20
|
+
//# sourceMappingURL=verification.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.mjs","names":[],"sources":["../../../src/db/schema/verification.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { coreSchema } from \"./shared\";\n\nexport const verificationSchema = coreSchema.extend({\n\tvalue: z.string(),\n\texpiresAt: z.date(),\n\tidentifier: z.string(),\n});\n\n/**\n * Verification schema type used by better-auth, note that it's possible that verification could have additional fields\n *\n * todo: we should use generics to extend this type with additional fields from plugins and options in the future\n */\nexport type Verification = z.infer<typeof verificationSchema>;\n"],"mappings":";;;;AAGA,MAAa,qBAAqB,WAAW,OAAO;CACnD,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,MAAM;CACnB,YAAY,EAAE,QAAQ;CACtB,CAAC"}
|
package/dist/db/type.d.mts
CHANGED
|
@@ -140,4 +140,5 @@ interface SecondaryStorage {
|
|
|
140
140
|
delete: (key: string) => Awaitable<void | null | string>;
|
|
141
141
|
}
|
|
142
142
|
//#endregion
|
|
143
|
-
export { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage };
|
|
143
|
+
export { BaseModelNames, BetterAuthDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, SecondaryStorage };
|
|
144
|
+
//# sourceMappingURL=type.d.mts.map
|
package/dist/env/color-depth.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-depth.mjs","names":["TERM_ENVS: Record<string, number>"],"sources":["../../src/env/color-depth.ts"],"sourcesContent":["// Source code copied & modified from node internals: https://github.com/nodejs/node/blob/5b32bb1573dace2dd058c05ac4fab1e4e446c775/lib/internal/tty.js#L123\nimport { env, getEnvVar } from \"./env-impl\";\n\nconst COLORS_2 = 1;\nconst COLORS_16 = 4;\nconst COLORS_256 = 8;\nconst COLORS_16m = 24;\n\nconst TERM_ENVS: Record<string, number> = {\n\teterm: COLORS_16,\n\tcons25: COLORS_16,\n\tconsole: COLORS_16,\n\tcygwin: COLORS_16,\n\tdtterm: COLORS_16,\n\tgnome: COLORS_16,\n\thurd: COLORS_16,\n\tjfbterm: COLORS_16,\n\tkonsole: COLORS_16,\n\tkterm: COLORS_16,\n\tmlterm: COLORS_16,\n\tmosh: COLORS_16m,\n\tputty: COLORS_16,\n\tst: COLORS_16,\n\t// http://lists.schmorp.de/pipermail/rxvt-unicode/2016q2/002261.html\n\t\"rxvt-unicode-24bit\": COLORS_16m,\n\t// https://bugs.launchpad.net/terminator/+bug/1030562\n\tterminator: COLORS_16m,\n\t\"xterm-kitty\": COLORS_16m,\n};\n\nconst CI_ENVS_MAP = new Map(\n\tObject.entries({\n\t\tAPPVEYOR: COLORS_256,\n\t\tBUILDKITE: COLORS_256,\n\t\tCIRCLECI: COLORS_16m,\n\t\tDRONE: COLORS_256,\n\t\tGITEA_ACTIONS: COLORS_16m,\n\t\tGITHUB_ACTIONS: COLORS_16m,\n\t\tGITLAB_CI: COLORS_256,\n\t\tTRAVIS: COLORS_256,\n\t}),\n);\n\nconst TERM_ENVS_REG_EXP = [\n\t/ansi/,\n\t/color/,\n\t/linux/,\n\t/direct/,\n\t/^con[0-9]*x[0-9]/,\n\t/^rxvt/,\n\t/^screen/,\n\t/^xterm/,\n\t/^vt100/,\n\t/^vt220/,\n];\n\n// The `getColorDepth` API got inspired by multiple sources such as\n// https://github.com/chalk/supports-color,\n// https://github.com/isaacs/color-support.\nexport function getColorDepth(): number {\n\t// Use level 0-3 to support the same levels as `chalk` does. This is done for\n\t// consistency throughout the ecosystem.\n\tif (getEnvVar(\"FORCE_COLOR\") !== undefined) {\n\t\tswitch (getEnvVar(\"FORCE_COLOR\")) {\n\t\t\tcase \"\":\n\t\t\tcase \"1\":\n\t\t\tcase \"true\":\n\t\t\t\treturn COLORS_16;\n\t\t\tcase \"2\":\n\t\t\t\treturn COLORS_256;\n\t\t\tcase \"3\":\n\t\t\t\treturn COLORS_16m;\n\t\t\tdefault:\n\t\t\t\treturn COLORS_2;\n\t\t}\n\t}\n\n\tif (\n\t\t(getEnvVar(\"NODE_DISABLE_COLORS\") !== undefined &&\n\t\t\tgetEnvVar(\"NODE_DISABLE_COLORS\") !== \"\") ||\n\t\t// See https://no-color.org/\n\t\t(getEnvVar(\"NO_COLOR\") !== undefined && getEnvVar(\"NO_COLOR\") !== \"\") ||\n\t\t// The \"dumb\" special terminal, as defined by terminfo, doesn't support\n\t\t// ANSI color control codes.\n\t\t// See https://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials\n\t\tgetEnvVar(\"TERM\") === \"dumb\"\n\t) {\n\t\treturn COLORS_2;\n\t}\n\n\t// Edge runtime doesn't support `process?.platform` syntax\n\t// if (typeof process !== \"undefined\" && process?.platform === \"win32\") {\n\t// \t// Windows 10 build 14931 (from 2016) has true color support\n\t// \treturn COLORS_16m;\n\t// }\n\n\tif (getEnvVar(\"TMUX\")) {\n\t\treturn COLORS_16m;\n\t}\n\n\t// Azure DevOps\n\tif (\"TF_BUILD\" in env && \"AGENT_NAME\" in env) {\n\t\treturn COLORS_16;\n\t}\n\n\tif (\"CI\" in env) {\n\t\tfor (const { 0: envName, 1: colors } of CI_ENVS_MAP) {\n\t\t\tif (envName in env) {\n\t\t\t\treturn colors;\n\t\t\t}\n\t\t}\n\t\tif (getEnvVar(\"CI_NAME\") === \"codeship\") {\n\t\t\treturn COLORS_256;\n\t\t}\n\t\treturn COLORS_2;\n\t}\n\n\tif (\"TEAMCITY_VERSION\" in env) {\n\t\treturn /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.exec(\n\t\t\tgetEnvVar(\"TEAMCITY_VERSION\"),\n\t\t) !== null\n\t\t\t? COLORS_16\n\t\t\t: COLORS_2;\n\t}\n\n\tswitch (getEnvVar(\"TERM_PROGRAM\")) {\n\t\tcase \"iTerm.app\":\n\t\t\tif (\n\t\t\t\t!getEnvVar(\"TERM_PROGRAM_VERSION\") ||\n\t\t\t\t/^[0-2]\\./.exec(getEnvVar(\"TERM_PROGRAM_VERSION\")) !== null\n\t\t\t) {\n\t\t\t\treturn COLORS_256;\n\t\t\t}\n\t\t\treturn COLORS_16m;\n\t\tcase \"HyperTerm\":\n\t\tcase \"MacTerm\":\n\t\t\treturn COLORS_16m;\n\t\tcase \"Apple_Terminal\":\n\t\t\treturn COLORS_256;\n\t}\n\n\tif (\n\t\tgetEnvVar(\"COLORTERM\") === \"truecolor\" ||\n\t\tgetEnvVar(\"COLORTERM\") === \"24bit\"\n\t) {\n\t\treturn COLORS_16m;\n\t}\n\n\tif (getEnvVar(\"TERM\")) {\n\t\tif (/truecolor/.exec(getEnvVar(\"TERM\")) !== null) {\n\t\t\treturn COLORS_16m;\n\t\t}\n\n\t\tif (/^xterm-256/.exec(getEnvVar(\"TERM\")) !== null) {\n\t\t\treturn COLORS_256;\n\t\t}\n\n\t\tconst termEnv = getEnvVar(\"TERM\").toLowerCase();\n\n\t\tif (TERM_ENVS[termEnv]) {\n\t\t\treturn TERM_ENVS[termEnv];\n\t\t}\n\t\tif (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) {\n\t\t\treturn COLORS_16;\n\t\t}\n\t}\n\t// Move 16 color COLORTERM below 16m and 256\n\tif (getEnvVar(\"COLORTERM\")) {\n\t\treturn COLORS_16;\n\t}\n\treturn COLORS_2;\n}\n"],"mappings":";;;AAGA,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,aAAa;AAEnB,MAAMA,YAAoC;CACzC,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,MAAM;CACN,OAAO;CACP,IAAI;CAEJ,sBAAsB;CAEtB,YAAY;CACZ,eAAe;CACf;AAED,MAAM,cAAc,IAAI,IACvB,OAAO,QAAQ;CACd,UAAU;CACV,WAAW;CACX,UAAU;CACV,OAAO;CACP,eAAe;CACf,gBAAgB;CAChB,WAAW;CACX,Q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UAAU,SACb,QAAO,UAAU;AAElB,MAAI,kBAAkB,MAAM,SAAS,KAAK,KAAK,QAAQ,KAAK,KAAK,CAChE,QAAO;;AAIT,KAAI,UAAU,YAAY,CACzB,QAAO;AAER,QAAO"}
|
package/dist/env/env-impl.d.mts
CHANGED
|
@@ -26,7 +26,8 @@ declare const ENV: Readonly<{
|
|
|
26
26
|
readonly BETTER_AUTH_TELEMETRY_ID: string;
|
|
27
27
|
readonly NODE_ENV: string;
|
|
28
28
|
readonly PACKAGE_VERSION: string;
|
|
29
|
-
readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string;
|
|
29
|
+
readonly BETTER_AUTH_TELEMETRY_ENDPOINT: string | undefined;
|
|
30
30
|
}>;
|
|
31
31
|
//#endregion
|
|
32
|
-
export { ENV, EnvObject, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
|
|
32
|
+
export { ENV, EnvObject, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
|
|
33
|
+
//# sourceMappingURL=env-impl.d.mts.map
|
package/dist/env/env-impl.mjs
CHANGED
|
@@ -74,9 +74,10 @@ const ENV = Object.freeze({
|
|
|
74
74
|
return getEnvVar("PACKAGE_VERSION", "0.0.0");
|
|
75
75
|
},
|
|
76
76
|
get BETTER_AUTH_TELEMETRY_ENDPOINT() {
|
|
77
|
-
return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "
|
|
77
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "");
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
//#endregion
|
|
82
|
-
export { ENV, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
|
|
82
|
+
export { ENV, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV };
|
|
83
|
+
//# sourceMappingURL=env-impl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-impl.mjs","names":["env"],"sources":["../../src/env/env-impl.ts"],"sourcesContent":["/// <reference types=\"node\" />\n/// <reference types=\"bun\" />\n//https://github.com/unjs/std-env/blob/main/src/env.ts\n\nconst _envShim = Object.create(null);\n\nexport type EnvObject = Record<string, string | undefined>;\n\nconst _getEnv = (useShim?: boolean) =>\n\tglobalThis.process?.env ||\n\t//@ts-expect-error\n\tglobalThis.Deno?.env.toObject() ||\n\t//@ts-expect-error\n\tglobalThis.__env__ ||\n\t(useShim ? _envShim : globalThis);\n\nexport const env = new Proxy<EnvObject>(_envShim, {\n\tget(_, prop) {\n\t\tconst env = _getEnv();\n\t\treturn env[prop as any] ?? _envShim[prop];\n\t},\n\thas(_, prop) {\n\t\tconst env = _getEnv();\n\t\treturn prop in env || prop in _envShim;\n\t},\n\tset(_, prop, value) {\n\t\tconst env = _getEnv(true);\n\t\tenv[prop as any] = value;\n\t\treturn true;\n\t},\n\tdeleteProperty(_, prop) {\n\t\tif (!prop) {\n\t\t\treturn false;\n\t\t}\n\t\tconst env = _getEnv(true);\n\t\tdelete env[prop as any];\n\t\treturn true;\n\t},\n\townKeys() {\n\t\tconst env = _getEnv(true);\n\t\treturn Object.keys(env);\n\t},\n});\n\nfunction toBoolean(val: boolean | string | undefined) {\n\treturn val ? val !== \"false\" : false;\n}\n\nexport const nodeENV =\n\t(typeof process !== \"undefined\" && process.env && process.env.NODE_ENV) || \"\";\n\n/** Detect if `NODE_ENV` environment variable is `production` */\nexport const isProduction = nodeENV === \"production\";\n\n/** Detect if `NODE_ENV` environment variable is `dev` or `development` */\nexport const isDevelopment = () =>\n\tnodeENV === \"dev\" || nodeENV === \"development\";\n\n/** Detect if `NODE_ENV` environment variable is `test` */\nexport const isTest = () => nodeENV === \"test\" || toBoolean(env.TEST);\n\n/**\n * Get environment variable with fallback\n */\nexport function getEnvVar<Fallback extends string>(\n\tkey: string,\n\tfallback?: Fallback,\n): Fallback extends string ? string : string | undefined {\n\tif (typeof process !== \"undefined\" && process.env) {\n\t\treturn process.env[key] ?? (fallback as any);\n\t}\n\n\t// @ts-expect-error deno\n\tif (typeof Deno !== \"undefined\") {\n\t\t// @ts-expect-error deno\n\t\treturn Deno.env.get(key) ?? (fallback as string);\n\t}\n\n\t// Handle Bun\n\tif (typeof Bun !== \"undefined\") {\n\t\treturn Bun.env[key] ?? (fallback as string);\n\t}\n\n\treturn fallback as any;\n}\n\n/**\n * Get boolean environment variable\n */\nexport function getBooleanEnvVar(key: string, fallback = true): boolean {\n\tconst value = getEnvVar(key);\n\tif (!value) return fallback;\n\treturn value !== \"0\" && value.toLowerCase() !== \"false\" && value !== \"\";\n}\n\n/**\n * Common environment variables used in Better Auth\n */\nexport const ENV = Object.freeze({\n\tget BETTER_AUTH_SECRET() {\n\t\treturn getEnvVar(\"BETTER_AUTH_SECRET\");\n\t},\n\tget AUTH_SECRET() {\n\t\treturn getEnvVar(\"AUTH_SECRET\");\n\t},\n\tget BETTER_AUTH_TELEMETRY() {\n\t\treturn getEnvVar(\"BETTER_AUTH_TELEMETRY\");\n\t},\n\tget BETTER_AUTH_TELEMETRY_ID() {\n\t\treturn getEnvVar(\"BETTER_AUTH_TELEMETRY_ID\");\n\t},\n\tget NODE_ENV() {\n\t\treturn getEnvVar(\"NODE_ENV\", \"development\");\n\t},\n\tget PACKAGE_VERSION() {\n\t\treturn getEnvVar(\"PACKAGE_VERSION\", \"0.0.0\");\n\t},\n\tget BETTER_AUTH_TELEMETRY_ENDPOINT(): string | undefined {\n\t\treturn getEnvVar(\n\t\t\t\"BETTER_AUTH_TELEMETRY_ENDPOINT\",\n\t\t\timport.meta.env.BETTER_AUTH_TELEMETRY_ENDPOINT,\n\t\t);\n\t},\n});\n"],"mappings":";AAIA,MAAM,WAAW,OAAO,OAAO,KAAK;AAIpC,MAAM,WAAW,YAChB,WAAW,SAAS,OAEpB,WAAW,MAAM,IAAI,UAAU,IAE/B,WAAW,YACV,UAAU,WAAW;AAEvB,MAAa,MAAM,IAAI,MAAi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SAAO,UAAU,wBAAwB;;CAE1C,IAAI,2BAA2B;AAC9B,SAAO,UAAU,2BAA2B;;CAE7C,IAAI,WAAW;AACd,SAAO,UAAU,YAAY,cAAc;;CAE5C,IAAI,kBAAkB;AACrB,SAAO,UAAU,mBAAmB,QAAQ;;CAE7C,IAAI,iCAAqD;AACxD,SAAO,UACN,qCAEA;;CAEF,CAAC"}
|
package/dist/env/logger.d.mts
CHANGED
|
@@ -45,4 +45,5 @@ type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void }
|
|
|
45
45
|
declare const createLogger: (options?: Logger | undefined) => InternalLogger;
|
|
46
46
|
declare const logger: InternalLogger;
|
|
47
47
|
//#endregion
|
|
48
|
-
export { InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
|
|
48
|
+
export { InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
|
|
49
|
+
//# sourceMappingURL=logger.d.mts.map
|
package/dist/env/logger.mjs
CHANGED
|
@@ -55,7 +55,7 @@ const formatMessage = (level, message, colorsEnabled) => {
|
|
|
55
55
|
};
|
|
56
56
|
const createLogger = (options) => {
|
|
57
57
|
const enabled = options?.disabled !== true;
|
|
58
|
-
const logLevel = options?.level ?? "
|
|
58
|
+
const logLevel = options?.level ?? "warn";
|
|
59
59
|
const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
|
|
60
60
|
const LogFunc = (level, message, args = []) => {
|
|
61
61
|
if (!enabled || !shouldPublishLog(logLevel, level)) return;
|
|
@@ -78,4 +78,5 @@ const createLogger = (options) => {
|
|
|
78
78
|
const logger = createLogger();
|
|
79
79
|
|
|
80
80
|
//#endregion
|
|
81
|
-
export { TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
|
|
81
|
+
export { TTY_COLORS, createLogger, levels, logger, shouldPublishLog };
|
|
82
|
+
//# sourceMappingURL=logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":["levelColors: Record<LogLevel, string>"],"sources":["../../src/env/logger.ts"],"sourcesContent":["import { getColorDepth } from \"./color-depth\";\n\nexport const TTY_COLORS = {\n\treset: \"\\x1b[0m\",\n\tbright: \"\\x1b[1m\",\n\tdim: \"\\x1b[2m\",\n\tundim: \"\\x1b[22m\",\n\tunderscore: \"\\x1b[4m\",\n\tblink: \"\\x1b[5m\",\n\treverse: \"\\x1b[7m\",\n\thidden: \"\\x1b[8m\",\n\tfg: {\n\t\tblack: \"\\x1b[30m\",\n\t\tred: \"\\x1b[31m\",\n\t\tgreen: \"\\x1b[32m\",\n\t\tyellow: \"\\x1b[33m\",\n\t\tblue: \"\\x1b[34m\",\n\t\tmagenta: \"\\x1b[35m\",\n\t\tcyan: \"\\x1b[36m\",\n\t\twhite: \"\\x1b[37m\",\n\t},\n\tbg: {\n\t\tblack: \"\\x1b[40m\",\n\t\tred: \"\\x1b[41m\",\n\t\tgreen: \"\\x1b[42m\",\n\t\tyellow: \"\\x1b[43m\",\n\t\tblue: \"\\x1b[44m\",\n\t\tmagenta: \"\\x1b[45m\",\n\t\tcyan: \"\\x1b[46m\",\n\t\twhite: \"\\x1b[47m\",\n\t},\n} as const;\n\nexport type LogLevel = \"debug\" | \"info\" | \"success\" | \"warn\" | \"error\";\n\nexport const levels = [\"debug\", \"info\", \"success\", \"warn\", \"error\"] as const;\n\nexport function shouldPublishLog(\n\tcurrentLogLevel: LogLevel,\n\tlogLevel: LogLevel,\n): boolean {\n\treturn levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);\n}\n\nexport interface Logger {\n\tdisabled?: boolean | undefined;\n\tdisableColors?: boolean | undefined;\n\tlevel?: Exclude<LogLevel, \"success\"> | undefined;\n\tlog?:\n\t\t| ((\n\t\t\t\tlevel: Exclude<LogLevel, \"success\">,\n\t\t\t\tmessage: string,\n\t\t\t\t...args: any[]\n\t\t ) => void)\n\t\t| undefined;\n}\n\nexport type LogHandlerParams =\n\tParameters<NonNullable<Logger[\"log\"]>> extends [LogLevel, ...infer Rest]\n\t\t? Rest\n\t\t: never;\n\nconst levelColors: Record<LogLevel, string> = {\n\tinfo: TTY_COLORS.fg.blue,\n\tsuccess: TTY_COLORS.fg.green,\n\twarn: TTY_COLORS.fg.yellow,\n\terror: TTY_COLORS.fg.red,\n\tdebug: TTY_COLORS.fg.magenta,\n};\n\nconst formatMessage = (\n\tlevel: LogLevel,\n\tmessage: string,\n\tcolorsEnabled: boolean,\n): string => {\n\tconst timestamp = new Date().toISOString();\n\n\tif (colorsEnabled) {\n\t\treturn `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${\n\t\t\tlevelColors[level]\n\t\t}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${\n\t\t\tTTY_COLORS.reset\n\t\t} ${message}`;\n\t}\n\n\treturn `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;\n};\n\nexport type InternalLogger = {\n\t[K in LogLevel]: (...params: LogHandlerParams) => void;\n} & {\n\tget level(): LogLevel;\n};\n\nexport const createLogger = (options?: Logger | undefined): InternalLogger => {\n\tconst enabled = options?.disabled !== true;\n\tconst logLevel = options?.level ?? \"warn\";\n\n\tconst isDisableColorsSpecified = options?.disableColors !== undefined;\n\tconst colorsEnabled = isDisableColorsSpecified\n\t\t? !options.disableColors\n\t\t: getColorDepth() !== 1;\n\n\tconst LogFunc = (\n\t\tlevel: LogLevel,\n\t\tmessage: string,\n\t\targs: any[] = [],\n\t): void => {\n\t\tif (!enabled || !shouldPublishLog(logLevel, level)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst formattedMessage = formatMessage(level, message, colorsEnabled);\n\n\t\tif (!options || typeof options.log !== \"function\") {\n\t\t\tif (level === \"error\") {\n\t\t\t\tconsole.error(formattedMessage, ...args);\n\t\t\t} else if (level === \"warn\") {\n\t\t\t\tconsole.warn(formattedMessage, ...args);\n\t\t\t} else {\n\t\t\t\tconsole.log(formattedMessage, ...args);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\toptions.log(level === \"success\" ? \"info\" : level, message, ...args);\n\t};\n\n\tconst logger = Object.fromEntries(\n\t\tlevels.map((level) => [\n\t\t\tlevel,\n\t\t\t(...[message, ...args]: LogHandlerParams) =>\n\t\t\t\tLogFunc(level, message, args),\n\t\t]),\n\t) as Record<LogLevel, (...params: LogHandlerParams) => void>;\n\n\treturn {\n\t\t...logger,\n\t\tget level() {\n\t\t\treturn logLevel;\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n"],"mappings":";;;AAEA,MAAa,aAAa;CACzB,OAAO;CACP,QAAQ;CACR,KAAK;CACL,OAAO;CACP,YAAY;CACZ,OAAO;CACP,SAAS;CACT,QAAQ;CACR,IAAI;EACH,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACN,SAAS;EACT,MAAM;EACN,OAAO;EACP;CACD,IAAI;EACH,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACN,SAAS;EACT,MAAM;EACN,OAAO;EACP;CACD;AAID,MAAa,SAAS;CAAC;CAAS;CAAQ;CAAW;CAAQ;CAAQ;AAEnE,SAAgB,iBACf,iBACA,UACU;AACV,QAAO,OAAO,QAAQ,SAAS,IAAI,OAAO,QAAQ,gBAAgB;;AAqBnE,MAAMA,cAAwC;CAC7C,MAAM,WAAW,GAAG;CACpB,SAAS,WAAW,GAAG;CACvB,MAAM,WAAW,GAAG;CACpB,OAAO,WAAW,GAAG;CACrB,OAAO,WAAW,GAAG;CACrB;AAED,MAAM,iBACL,OACA,SACA,kBACY;CACZ,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;AAE1C,KAAI,cACH,QAAO,GAAG,WAAW,MAAM,YAAY,WAAW,MAAM,GACvD,YAAY,SACV,MAAM,aAAa,GAAG,WAAW,MAAM,GAAG,WAAW,OAAO,gBAC9D,WAAW,MACX,GAAG;AAGL,QAAO,GAAG,UAAU,GAAG,MAAM,aAAa,CAAC,kBAAkB;;AAS9D,MAAa,gBAAgB,YAAiD;CAC7E,MAAM,UAAU,SAAS,aAAa;CACtC,MAAM,WAAW,SAAS,SAAS;CAGnC,MAAM,gBAD2B,SAAS,kBAAkB,SAEzD,CAAC,QAAQ,gBACT,eAAe,KAAK;CAEvB,MAAM,WACL,OACA,SACA,OAAc,EAAE,KACN;AACV,MAAI,CAAC,WAAW,CAAC,iBAAiB,UAAU,MAAM,CACjD;EAGD,MAAM,mBAAmB,cAAc,OAAO,SAAS,cAAc;AAErE,MAAI,CAAC,WAAW,OAAO,QAAQ,QAAQ,YAAY;AAClD,OAAI,UAAU,QACb,SAAQ,MAAM,kBAAkB,GAAG,KAAK;YAC9B,UAAU,OACpB,SAAQ,KAAK,kBAAkB,GAAG,KAAK;OAEvC,SAAQ,IAAI,kBAAkB,GAAG,KAAK;AAEvC;;AAGD,UAAQ,IAAI,UAAU,YAAY,SAAS,OAAO,SAAS,GAAG,KAAK;;AAWpE,QAAO;EACN,GATc,OAAO,YACrB,OAAO,KAAK,UAAU,CACrB,QACC,GAAG,CAAC,SAAS,GAAG,UAChB,QAAQ,OAAO,SAAS,KAAK,CAC9B,CAAC,CACF;EAIA,IAAI,QAAQ;AACX,UAAO;;EAER;;AAGF,MAAa,SAAS,cAAc"}
|
package/dist/error/codes.d.mts
CHANGED
package/dist/error/codes.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.mjs","names":[],"sources":["../../src/error/codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"../utils\";\n\nexport const BASE_ERROR_CODES = defineErrorCodes({\n\tUSER_NOT_FOUND: \"User not found\",\n\tFAILED_TO_CREATE_USER: \"Failed to create user\",\n\tFAILED_TO_CREATE_SESSION: \"Failed to create session\",\n\tFAILED_TO_UPDATE_USER: \"Failed to update user\",\n\tFAILED_TO_GET_SESSION: \"Failed to get session\",\n\tINVALID_PASSWORD: \"Invalid password\",\n\tINVALID_EMAIL: \"Invalid email\",\n\tINVALID_EMAIL_OR_PASSWORD: \"Invalid email or password\",\n\tSOCIAL_ACCOUNT_ALREADY_LINKED: \"Social account already linked\",\n\tPROVIDER_NOT_FOUND: \"Provider not found\",\n\tINVALID_TOKEN: \"Invalid token\",\n\tID_TOKEN_NOT_SUPPORTED: \"id_token not supported\",\n\tFAILED_TO_GET_USER_INFO: \"Failed to get user info\",\n\tUSER_EMAIL_NOT_FOUND: \"User email not found\",\n\tEMAIL_NOT_VERIFIED: \"Email not verified\",\n\tPASSWORD_TOO_SHORT: \"Password too short\",\n\tPASSWORD_TOO_LONG: \"Password too long\",\n\tUSER_ALREADY_EXISTS: \"User already exists.\",\n\tUSER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:\n\t\t\"User already exists. Use another email.\",\n\tEMAIL_CAN_NOT_BE_UPDATED: \"Email can not be updated\",\n\tCREDENTIAL_ACCOUNT_NOT_FOUND: \"Credential account not found\",\n\tSESSION_EXPIRED: \"Session expired. Re-authenticate to perform this action.\",\n\tFAILED_TO_UNLINK_LAST_ACCOUNT: \"You can't unlink your last account\",\n\tACCOUNT_NOT_FOUND: \"Account not found\",\n\tUSER_ALREADY_HAS_PASSWORD:\n\t\t\"User already has a password. Provide that to delete the account.\",\n\tCROSS_SITE_NAVIGATION_LOGIN_BLOCKED:\n\t\t\"Cross-site navigation login blocked. This request appears to be a CSRF attack.\",\n\tVERIFICATION_EMAIL_NOT_ENABLED: \"Verification email isn't enabled\",\n\tEMAIL_ALREADY_VERIFIED: \"Email is already verified\",\n\tEMAIL_MISMATCH: \"Email mismatch\",\n\tSESSION_NOT_FRESH: \"Session is not fresh\",\n\tLINKED_ACCOUNT_ALREADY_EXISTS: \"Linked account already exists\",\n\tINVALID_ORIGIN: \"Invalid origin\",\n\tINVALID_CALLBACK_URL: \"Invalid callbackURL\",\n\tINVALID_REDIRECT_URL: \"Invalid redirectURL\",\n\tINVALID_ERROR_CALLBACK_URL: \"Invalid errorCallbackURL\",\n\tINVALID_NEW_USER_CALLBACK_URL: \"Invalid newUserCallbackURL\",\n\tMISSING_OR_NULL_ORIGIN: \"Missing or null Origin\",\n\tCALLBACK_URL_REQUIRED: \"callbackURL is required\",\n\tFAILED_TO_CREATE_VERIFICATION: \"Unable to create verification\",\n\tFIELD_NOT_ALLOWED: \"Field not allowed to be set\",\n\tASYNC_VALIDATION_NOT_SUPPORTED: \"Async validation is not supported\",\n\tVALIDATION_ERROR: \"Validation Error\",\n\tMISSING_FIELD: \"Field is required\",\n});\n"],"mappings":";;;;AAEA,MAAa,mBAAmB,iBAAiB;CAChD,gBAAgB;CAChB,uBAAuB;CACvB,0BAA0B;CAC1B,uBAAuB;CACvB,uBAAuB;CACvB,kBAAkB;CAClB,eAAe;CACf,2BAA2B;CAC3B,+BAA+B;CAC/B,oBAAoB;CACpB,eAAe;CACf,wBAAwB;CACxB,yBAAyB;CACzB,sBAAsB;CACtB,oBAAoB;CACpB,oBAAoB;CACpB,mBAAmB;CACnB,qBAAqB;CACrB,uCACC;CACD,0BAA0B;CAC1B,8BAA8B;CAC9B,iBAAiB;CACjB,+BAA+B;CAC/B,mBAAmB;CACnB,2BACC;CACD,qCACC;CACD,gCAAgC;CAChC,wBAAwB;CACxB,gBAAgB;CAChB,mBAAmB;CACnB,+BAA+B;CAC/B,gBAAgB;CAChB,sBAAsB;CACtB,sBAAsB;CACtB,4BAA4B;CAC5B,+BAA+B;CAC/B,wBAAwB;CACxB,uBAAuB;CACvB,+BAA+B;CAC/B,mBAAmB;CACnB,gCAAgC;CAChC,kBAAkB;CAClB,eAAe;CACf,CAAC"}
|
package/dist/error/index.d.mts
CHANGED
package/dist/error/index.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/error/index.ts"],"sourcesContent":["export class BetterAuthError extends Error {\n\tconstructor(message: string, options?: { cause?: unknown | undefined }) {\n\t\tsuper(message, options);\n\t\tthis.name = \"BetterAuthError\";\n\t\tthis.message = message;\n\t\tthis.stack = \"\";\n\t}\n}\n\nexport { BASE_ERROR_CODES } from \"./codes\";\n"],"mappings":";;;AAAA,IAAa,kBAAb,cAAqC,MAAM;CAC1C,YAAY,SAAiB,SAA2C;AACvE,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,UAAU;AACf,OAAK,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Awaitable, LiteralString, LiteralUnion, Prettify, Primitive } from "./types/helper.mjs";
|
|
2
2
|
import { BetterAuthCookie, BetterAuthCookies } from "./types/cookie.mjs";
|
|
3
3
|
import { BetterAuthPlugin, HookEndpointContext } from "./types/plugin.mjs";
|
|
4
|
-
import { BetterAuthAdvancedOptions, BetterAuthOptions, BetterAuthRateLimitOptions, GenerateIdFn } from "./types/init-options.mjs";
|
|
4
|
+
import { BetterAuthAdvancedOptions, BetterAuthOptions, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, GenerateIdFn } from "./types/init-options.mjs";
|
|
5
5
|
import { AuthContext, GenericEndpointContext, InfoContext, InternalAdapter, PluginContext } from "./types/context.mjs";
|
|
6
6
|
import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./types/plugin-client.mjs";
|
|
7
7
|
import { StandardSchemaV1 } from "./types/index.mjs";
|
|
8
|
-
export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, StandardSchemaV1 };
|
|
8
|
+
export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, StandardSchemaV1 };
|
|
@@ -33,4 +33,5 @@ declare function clientCredentialsToken({
|
|
|
33
33
|
resource?: (string | string[]) | undefined;
|
|
34
34
|
}): Promise<OAuth2Tokens>;
|
|
35
35
|
//#endregion
|
|
36
|
-
export { clientCredentialsToken, createClientCredentialsTokenRequest };
|
|
36
|
+
export { clientCredentialsToken, createClientCredentialsTokenRequest };
|
|
37
|
+
//# sourceMappingURL=client-credentials-token.d.mts.map
|
|
@@ -51,4 +51,5 @@ async function clientCredentialsToken({ options, tokenEndpoint, scope, authentic
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
//#endregion
|
|
54
|
-
export { clientCredentialsToken, createClientCredentialsTokenRequest };
|
|
54
|
+
export { clientCredentialsToken, createClientCredentialsTokenRequest };
|
|
55
|
+
//# sourceMappingURL=client-credentials-token.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-credentials-token.mjs","names":["headers: Record<string, any>","tokens: OAuth2Tokens"],"sources":["../../src/oauth2/client-credentials-token.ts"],"sourcesContent":["import { base64Url } from \"@better-auth/utils/base64\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport type { OAuth2Tokens, ProviderOptions } from \"./oauth-provider\";\n\nexport function createClientCredentialsTokenRequest({\n\toptions,\n\tscope,\n\tauthentication,\n\tresource,\n}: {\n\toptions: ProviderOptions & { clientSecret: string };\n\tscope?: string | undefined;\n\tauthentication?: (\"basic\" | \"post\") | undefined;\n\tresource?: (string | string[]) | undefined;\n}) {\n\tconst body = new URLSearchParams();\n\tconst headers: Record<string, any> = {\n\t\t\"content-type\": \"application/x-www-form-urlencoded\",\n\t\taccept: \"application/json\",\n\t};\n\n\tbody.set(\"grant_type\", \"client_credentials\");\n\tscope && body.set(\"scope\", scope);\n\tif (resource) {\n\t\tif (typeof resource === \"string\") {\n\t\t\tbody.append(\"resource\", resource);\n\t\t} else {\n\t\t\tfor (const _resource of resource) {\n\t\t\t\tbody.append(\"resource\", _resource);\n\t\t\t}\n\t\t}\n\t}\n\tif (authentication === \"basic\") {\n\t\tconst primaryClientId = Array.isArray(options.clientId)\n\t\t\t? options.clientId[0]\n\t\t\t: options.clientId;\n\t\tconst encodedCredentials = base64Url.encode(\n\t\t\t`${primaryClientId}:${options.clientSecret}`,\n\t\t);\n\t\theaders[\"authorization\"] = `Basic ${encodedCredentials}`;\n\t} else {\n\t\tconst primaryClientId = Array.isArray(options.clientId)\n\t\t\t? options.clientId[0]\n\t\t\t: options.clientId;\n\t\tbody.set(\"client_id\", primaryClientId);\n\t\tbody.set(\"client_secret\", options.clientSecret);\n\t}\n\n\treturn {\n\t\tbody,\n\t\theaders,\n\t};\n}\n\nexport async function clientCredentialsToken({\n\toptions,\n\ttokenEndpoint,\n\tscope,\n\tauthentication,\n\tresource,\n}: {\n\toptions: ProviderOptions & { clientSecret: string };\n\ttokenEndpoint: string;\n\tscope: string;\n\tauthentication?: (\"basic\" | \"post\") | undefined;\n\tresource?: (string | string[]) | undefined;\n}): Promise<OAuth2Tokens> {\n\tconst { body, headers } = createClientCredentialsTokenRequest({\n\t\toptions,\n\t\tscope,\n\t\tauthentication,\n\t\tresource,\n\t});\n\n\tconst { data, error } = await betterFetch<{\n\t\taccess_token: string;\n\t\texpires_in?: number | undefined;\n\t\ttoken_type?: string | undefined;\n\t\tscope?: string | undefined;\n\t}>(tokenEndpoint, {\n\t\tmethod: \"POST\",\n\t\tbody,\n\t\theaders,\n\t});\n\tif (error) {\n\t\tthrow error;\n\t}\n\tconst tokens: OAuth2Tokens = {\n\t\taccessToken: data.access_token,\n\t\ttokenType: data.token_type,\n\t\tscopes: data.scope?.split(\" \"),\n\t};\n\n\tif (data.expires_in) {\n\t\tconst now = new Date();\n\t\ttokens.accessTokenExpiresAt = new Date(\n\t\t\tnow.getTime() + data.expires_in * 1000,\n\t\t);\n\t}\n\n\treturn tokens;\n}\n"],"mappings":";;;;AAIA,SAAgB,oCAAoC,EACnD,SACA,OACA,gBACA,YAME;CACF,MAAM,OAAO,IAAI,iBAAiB;CAClC,MAAMA,UAA+B;EACpC,gBAAgB;EAChB,QAAQ;EACR;AAED,MAAK,IAAI,cAAc,qBAAqB;AAC5C,UAAS,KAAK,IAAI,SAAS,MAAM;AACjC,KAAI,SACH,KAAI,OAAO,aAAa,SACvB,MAAK,OAAO,YAAY,SAAS;KAEjC,MAAK,MAAM,aAAa,SACvB,MAAK,OAAO,YAAY,UAAU;AAIrC,KAAI,mBAAmB,SAAS;EAC/B,MAAM,kBAAkB,MAAM,QAAQ,QAAQ,SAAS,GACpD,QAAQ,SAAS,KACjB,QAAQ;AAIX,UAAQ,mBAAmB,SAHA,UAAU,OACpC,GAAG,gBAAgB,GAAG,QAAQ,eAC9B;QAEK;EACN,MAAM,kBAAkB,MAAM,QAAQ,QAAQ,SAAS,GACpD,QAAQ,SAAS,KACjB,QAAQ;AACX,OAAK,IAAI,aAAa,gBAAgB;AACtC,OAAK,IAAI,iBAAiB,QAAQ,aAAa;;AAGhD,QAAO;EACN;EACA;EACA;;AAGF,eAAsB,uBAAuB,EAC5C,SACA,eACA,OACA,gBACA,YAOyB;CACzB,MAAM,EAAE,MAAM,YAAY,oCAAoC;EAC7D;EACA;EACA;EACA;EACA,CAAC;CAEF,MAAM,EAAE,MAAM,UAAU,MAAM,YAK3B,eAAe;EACjB,QAAQ;EACR;EACA;EACA,CAAC;AACF,KAAI,MACH,OAAM;CAEP,MAAMC,SAAuB;EAC5B,aAAa,KAAK;EAClB,WAAW,KAAK;EAChB,QAAQ,KAAK,OAAO,MAAM,IAAI;EAC9B;AAED,KAAI,KAAK,YAAY;EACpB,MAAM,sBAAM,IAAI,MAAM;AACtB,SAAO,uBAAuB,IAAI,KACjC,IAAI,SAAS,GAAG,KAAK,aAAa,IAClC;;AAGF,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-authorization-url.mjs","names":[],"sources":["../../src/oauth2/create-authorization-url.ts"],"sourcesContent":["import type { ProviderOptions } from \"./index\";\nimport { generateCodeChallenge } from \"./utils\";\n\nexport async function createAuthorizationURL({\n\tid,\n\toptions,\n\tauthorizationEndpoint,\n\tstate,\n\tcodeVerifier,\n\tscopes,\n\tclaims,\n\tredirectURI,\n\tduration,\n\tprompt,\n\taccessType,\n\tresponseType,\n\tdisplay,\n\tloginHint,\n\thd,\n\tresponseMode,\n\tadditionalParams,\n\tscopeJoiner,\n}: {\n\tid: string;\n\toptions: ProviderOptions;\n\tredirectURI: string;\n\tauthorizationEndpoint: string;\n\tstate: string;\n\tcodeVerifier?: string | undefined;\n\tscopes?: string[] | undefined;\n\tclaims?: string[] | undefined;\n\tduration?: string | undefined;\n\tprompt?: string | undefined;\n\taccessType?: string | undefined;\n\tresponseType?: string | undefined;\n\tdisplay?: string | undefined;\n\tloginHint?: string | undefined;\n\thd?: string | undefined;\n\tresponseMode?: string | undefined;\n\tadditionalParams?: Record<string, string> | undefined;\n\tscopeJoiner?: string | undefined;\n}) {\n\tconst url = new URL(options.authorizationEndpoint || authorizationEndpoint);\n\turl.searchParams.set(\"response_type\", responseType || \"code\");\n\tconst primaryClientId = Array.isArray(options.clientId)\n\t\t? options.clientId[0]\n\t\t: options.clientId;\n\turl.searchParams.set(\"client_id\", primaryClientId);\n\turl.searchParams.set(\"state\", state);\n\tif (scopes) {\n\t\turl.searchParams.set(\"scope\", scopes.join(scopeJoiner || \" \"));\n\t}\n\turl.searchParams.set(\"redirect_uri\", options.redirectURI || redirectURI);\n\tduration && url.searchParams.set(\"duration\", duration);\n\tdisplay && url.searchParams.set(\"display\", display);\n\tloginHint && url.searchParams.set(\"login_hint\", loginHint);\n\tprompt && url.searchParams.set(\"prompt\", prompt);\n\thd && url.searchParams.set(\"hd\", hd);\n\taccessType && url.searchParams.set(\"access_type\", accessType);\n\tresponseMode && url.searchParams.set(\"response_mode\", responseMode);\n\tif (codeVerifier) {\n\t\tconst codeChallenge = await generateCodeChallenge(codeVerifier);\n\t\turl.searchParams.set(\"code_challenge_method\", \"S256\");\n\t\turl.searchParams.set(\"code_challenge\", codeChallenge);\n\t}\n\tif (claims) {\n\t\tconst claimsObj = claims.reduce(\n\t\t\t(acc, claim) => {\n\t\t\t\tacc[claim] = null;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record<string, null>,\n\t\t);\n\t\turl.searchParams.set(\n\t\t\t\"claims\",\n\t\t\tJSON.stringify({\n\t\t\t\tid_token: { email: null, email_verified: null, ...claimsObj },\n\t\t\t}),\n\t\t);\n\t}\n\tif (additionalParams) {\n\t\tObject.entries(additionalParams).forEach(([key, value]) => {\n\t\t\turl.searchParams.set(key, value);\n\t\t});\n\t}\n\treturn url;\n}\n"],"mappings":";;;AAGA,eAAsB,uBAAuB,EAC5C,IACA,SACA,uBACA,OACA,cACA,QACA,QACA,aACA,UACA,QACA,YACA,cACA,SACA,WACA,IACA,cACA,kBACA,eAoBE;CACF,MAAM,MAAM,IAAI,IAAI,QAAQ,yBAAyB,sBAAsB;AAC3E,KAAI,aAAa,IAAI,iBAAiB,gBAAgB,OAAO;CAC7D,MAAM,kBAAkB,MAAM,QAAQ,QAAQ,SAAS,GACpD,QAAQ,SAAS,KACjB,QAAQ;AACX,KAAI,aAAa,IAAI,aAAa,gBAAgB;AAClD,KAAI,aAAa,IAAI,SAAS,MAAM;AACpC,KAAI,OACH,KAAI,aAAa,IAAI,SAAS,OAAO,KAAK,eAAe,IAAI,CAAC;AAE/D,KAAI,aAAa,IAAI,gBAAgB,QAAQ,eAAe,YAAY;AACxE,aAAY,IAAI,aAAa,IAAI,YAAY,SAAS;AACtD,YAAW,IAAI,aAAa,IAAI,WAAW,QAAQ;AACnD,cAAa,IAAI,aAAa,IAAI,cAAc,UAAU;AAC1D,WAAU,IAAI,aAAa,IAAI,UAAU,OAAO;AAChD,OAAM,IAAI,aAAa,IAAI,MAAM,GAAG;AACpC,eAAc,IAAI,aAAa,IAAI,eAAe,WAAW;AAC7D,iBAAgB,IAAI,aAAa,IAAI,iBAAiB,aAAa;AACnE,KAAI,cAAc;EACjB,MAAM,gBAAgB,MAAM,sBAAsB,aAAa;AAC/D,MAAI,aAAa,IAAI,yBAAyB,OAAO;AACrD,MAAI,aAAa,IAAI,kBAAkB,cAAc;;AAEtD,KAAI,QAAQ;EACX,MAAM,YAAY,OAAO,QACvB,KAAK,UAAU;AACf,OAAI,SAAS;AACb,UAAO;KAER,EAAE,CACF;AACD,MAAI,aAAa,IAChB,UACA,KAAK,UAAU,EACd,UAAU;GAAE,OAAO;GAAM,gBAAgB;GAAM,GAAG;GAAW,EAC7D,CAAC,CACF;;AAEF,KAAI,iBACH,QAAO,QAAQ,iBAAiB,CAAC,SAAS,CAAC,KAAK,WAAW;AAC1D,MAAI,aAAa,IAAI,KAAK,MAAM;GAC/B;AAEH,QAAO"}
|
|
@@ -39,7 +39,7 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
|
|
|
39
39
|
redirectURI: string;
|
|
40
40
|
codeVerifier?: string | undefined;
|
|
41
41
|
deviceId?: string | undefined;
|
|
42
|
-
}) => Promise<OAuth2Tokens>;
|
|
42
|
+
}) => Promise<OAuth2Tokens | null>;
|
|
43
43
|
getUserInfo: (token: OAuth2Tokens & {
|
|
44
44
|
/**
|
|
45
45
|
* The user object from the provider
|
|
@@ -191,4 +191,5 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
|
191
191
|
overrideUserInfoOnSignIn?: boolean | undefined;
|
|
192
192
|
};
|
|
193
193
|
//#endregion
|
|
194
|
-
export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions };
|
|
194
|
+
export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions };
|
|
195
|
+
//# sourceMappingURL=oauth-provider.d.mts.map
|
|
@@ -33,4 +33,5 @@ declare function refreshAccessToken({
|
|
|
33
33
|
grantType?: string | undefined;
|
|
34
34
|
}): Promise<OAuth2Tokens>;
|
|
35
35
|
//#endregion
|
|
36
|
-
export { createRefreshAccessTokenRequest, refreshAccessToken };
|
|
36
|
+
export { createRefreshAccessTokenRequest, refreshAccessToken };
|
|
37
|
+
//# sourceMappingURL=refresh-access-token.d.mts.map
|
|
@@ -55,4 +55,5 @@ async function refreshAccessToken({ refreshToken, options, tokenEndpoint, authen
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
//#endregion
|
|
58
|
-
export { createRefreshAccessTokenRequest, refreshAccessToken };
|
|
58
|
+
export { createRefreshAccessTokenRequest, refreshAccessToken };
|
|
59
|
+
//# sourceMappingURL=refresh-access-token.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-access-token.mjs","names":["headers: Record<string, any>","tokens: OAuth2Tokens"],"sources":["../../src/oauth2/refresh-access-token.ts"],"sourcesContent":["import { base64 } from \"@better-auth/utils/base64\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport type { OAuth2Tokens, ProviderOptions } from \"./oauth-provider\";\n\nexport function createRefreshAccessTokenRequest({\n\trefreshToken,\n\toptions,\n\tauthentication,\n\textraParams,\n\tresource,\n}: {\n\trefreshToken: string;\n\toptions: Partial<ProviderOptions>;\n\tauthentication?: (\"basic\" | \"post\") | undefined;\n\textraParams?: Record<string, string> | undefined;\n\tresource?: (string | string[]) | undefined;\n}) {\n\tconst body = new URLSearchParams();\n\tconst headers: Record<string, any> = {\n\t\t\"content-type\": \"application/x-www-form-urlencoded\",\n\t\taccept: \"application/json\",\n\t};\n\n\tbody.set(\"grant_type\", \"refresh_token\");\n\tbody.set(\"refresh_token\", refreshToken);\n\t// Use standard Base64 encoding for HTTP Basic Auth (OAuth2 spec, RFC 7617)\n\t// Fixes compatibility with providers like Notion, Twitter, etc.\n\tif (authentication === \"basic\") {\n\t\tconst primaryClientId = Array.isArray(options.clientId)\n\t\t\t? options.clientId[0]\n\t\t\t: options.clientId;\n\t\tif (primaryClientId) {\n\t\t\theaders[\"authorization\"] =\n\t\t\t\t\"Basic \" +\n\t\t\t\tbase64.encode(`${primaryClientId}:${options.clientSecret ?? \"\"}`);\n\t\t} else {\n\t\t\theaders[\"authorization\"] =\n\t\t\t\t\"Basic \" + base64.encode(`:${options.clientSecret ?? \"\"}`);\n\t\t}\n\t} else {\n\t\tconst primaryClientId = Array.isArray(options.clientId)\n\t\t\t? options.clientId[0]\n\t\t\t: options.clientId;\n\t\tbody.set(\"client_id\", primaryClientId);\n\t\tif (options.clientSecret) {\n\t\t\tbody.set(\"client_secret\", options.clientSecret);\n\t\t}\n\t}\n\n\tif (resource) {\n\t\tif (typeof resource === \"string\") {\n\t\t\tbody.append(\"resource\", resource);\n\t\t} else {\n\t\t\tfor (const _resource of resource) {\n\t\t\t\tbody.append(\"resource\", _resource);\n\t\t\t}\n\t\t}\n\t}\n\tif (extraParams) {\n\t\tfor (const [key, value] of Object.entries(extraParams)) {\n\t\t\tbody.set(key, value);\n\t\t}\n\t}\n\n\treturn {\n\t\tbody,\n\t\theaders,\n\t};\n}\n\nexport async function refreshAccessToken({\n\trefreshToken,\n\toptions,\n\ttokenEndpoint,\n\tauthentication,\n\textraParams,\n}: {\n\trefreshToken: string;\n\toptions: Partial<ProviderOptions>;\n\ttokenEndpoint: string;\n\tauthentication?: (\"basic\" | \"post\") | undefined;\n\textraParams?: Record<string, string> | undefined;\n\t/** @deprecated always \"refresh_token\" */\n\tgrantType?: string | undefined;\n}): Promise<OAuth2Tokens> {\n\tconst { body, headers } = createRefreshAccessTokenRequest({\n\t\trefreshToken,\n\t\toptions,\n\t\tauthentication,\n\t\textraParams,\n\t});\n\n\tconst { data, error } = await betterFetch<{\n\t\taccess_token: string;\n\t\trefresh_token?: string | undefined;\n\t\texpires_in?: number | undefined;\n\t\ttoken_type?: string | undefined;\n\t\tscope?: string | undefined;\n\t\tid_token?: string | undefined;\n\t}>(tokenEndpoint, {\n\t\tmethod: \"POST\",\n\t\tbody,\n\t\theaders,\n\t});\n\tif (error) {\n\t\tthrow error;\n\t}\n\tconst tokens: OAuth2Tokens = {\n\t\taccessToken: data.access_token,\n\t\trefreshToken: data.refresh_token,\n\t\ttokenType: data.token_type,\n\t\tscopes: data.scope?.split(\" \"),\n\t\tidToken: data.id_token,\n\t};\n\n\tif (data.expires_in) {\n\t\tconst now = new Date();\n\t\ttokens.accessTokenExpiresAt = new Date(\n\t\t\tnow.getTime() + data.expires_in * 1000,\n\t\t);\n\t}\n\n\treturn tokens;\n}\n"],"mappings":";;;;AAIA,SAAgB,gCAAgC,EAC/C,cACA,SACA,gBACA,aACA,YAOE;CACF,MAAM,OAAO,IAAI,iBAAiB;CAClC,MAAMA,UAA+B;EACpC,gBAAgB;EAChB,QAAQ;EACR;AAED,MAAK,IAAI,cAAc,gBAAgB;AACvC,MAAK,IAAI,iBAAiB,aAAa;AAGvC,KAAI,mBAAmB,SAAS;EAC/B,MAAM,kBAAkB,MAAM,QAAQ,QAAQ,SAAS,GACpD,QAAQ,SAAS,KACjB,QAAQ;AACX,MAAI,gBACH,SAAQ,mBACP,WACA,OAAO,OAAO,GAAG,gBAAgB,GAAG,QAAQ,gBAAgB,KAAK;MAElE,SAAQ,mBACP,WAAW,OAAO,OAAO,IAAI,QAAQ,gBAAgB,KAAK;QAEtD;EACN,MAAM,kBAAkB,MAAM,QAAQ,QAAQ,SAAS,GACpD,QAAQ,SAAS,KACjB,QAAQ;AACX,OAAK,IAAI,aAAa,gBAAgB;AACtC,MAAI,QAAQ,aACX,MAAK,IAAI,iBAAiB,QAAQ,aAAa;;AAIjD,KAAI,SACH,KAAI,OAAO,aAAa,SACvB,MAAK,OAAO,YAAY,SAAS;KAEjC,MAAK,MAAM,aAAa,SACvB,MAAK,OAAO,YAAY,UAAU;AAIrC,KAAI,YACH,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,YAAY,CACrD,MAAK,IAAI,KAAK,MAAM;AAItB,QAAO;EACN;EACA;EACA;;AAGF,eAAsB,mBAAmB,EACxC,cACA,SACA,eACA,gBACA,eASyB;CACzB,MAAM,EAAE,MAAM,YAAY,gCAAgC;EACzD;EACA;EACA;EACA;EACA,CAAC;CAEF,MAAM,EAAE,MAAM,UAAU,MAAM,YAO3B,eAAe;EACjB,QAAQ;EACR;EACA;EACA,CAAC;AACF,KAAI,MACH,OAAM;CAEP,MAAMC,SAAuB;EAC5B,aAAa,KAAK;EAClB,cAAc,KAAK;EACnB,WAAW,KAAK;EAChB,QAAQ,KAAK,OAAO,MAAM,IAAI;EAC9B,SAAS,KAAK;EACd;AAED,KAAI,KAAK,YAAY;EACpB,MAAM,sBAAM,IAAI,MAAM;AACtB,SAAO,uBAAuB,IAAI,KACjC,IAAI,SAAS,GAAG,KAAK,aAAa,IAClC;;AAGF,QAAO"}
|
package/dist/oauth2/utils.d.mts
CHANGED
|
@@ -4,4 +4,5 @@ import { OAuth2Tokens } from "./oauth-provider.mjs";
|
|
|
4
4
|
declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
|
|
5
5
|
declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
|
|
6
6
|
//#endregion
|
|
7
|
-
export { generateCodeChallenge, getOAuth2Tokens };
|
|
7
|
+
export { generateCodeChallenge, getOAuth2Tokens };
|
|
8
|
+
//# sourceMappingURL=utils.d.mts.map
|
package/dist/oauth2/utils.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/oauth2/utils.ts"],"sourcesContent":["import { base64Url } from \"@better-auth/utils/base64\";\nimport type { OAuth2Tokens } from \"./oauth-provider\";\n\nexport function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens {\n\tconst getDate = (seconds: number) => {\n\t\tconst now = new Date();\n\t\treturn new Date(now.getTime() + seconds * 1000);\n\t};\n\n\treturn {\n\t\ttokenType: data.token_type,\n\t\taccessToken: data.access_token,\n\t\trefreshToken: data.refresh_token,\n\t\taccessTokenExpiresAt: data.expires_in\n\t\t\t? getDate(data.expires_in)\n\t\t\t: undefined,\n\t\trefreshTokenExpiresAt: data.refresh_token_expires_in\n\t\t\t? getDate(data.refresh_token_expires_in)\n\t\t\t: undefined,\n\t\tscopes: data?.scope\n\t\t\t? typeof data.scope === \"string\"\n\t\t\t\t? data.scope.split(\" \")\n\t\t\t\t: data.scope\n\t\t\t: [],\n\t\tidToken: data.id_token,\n\t\t// Preserve the raw token response for provider-specific fields\n\t\traw: data,\n\t};\n}\n\nexport async function generateCodeChallenge(codeVerifier: string) {\n\tconst encoder = new TextEncoder();\n\tconst data = encoder.encode(codeVerifier);\n\tconst hash = await crypto.subtle.digest(\"SHA-256\", data);\n\treturn base64Url.encode(new Uint8Array(hash), {\n\t\tpadding: false,\n\t});\n}\n"],"mappings":";;;AAGA,SAAgB,gBAAgB,MAAyC;CACxE,MAAM,WAAW,YAAoB;EACpC,MAAM,sBAAM,IAAI,MAAM;AACtB,SAAO,IAAI,KAAK,IAAI,SAAS,GAAG,UAAU,IAAK;;AAGhD,QAAO;EACN,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,cAAc,KAAK;EACnB,sBAAsB,KAAK,aACxB,QAAQ,KAAK,WAAW,GACxB;EACH,uBAAuB,KAAK,2BACzB,QAAQ,KAAK,yBAAyB,GACtC;EACH,QAAQ,MAAM,QACX,OAAO,KAAK,UAAU,WACrB,KAAK,MAAM,MAAM,IAAI,GACrB,KAAK,QACN,EAAE;EACL,SAAS,KAAK;EAEd,KAAK;EACL;;AAGF,eAAsB,sBAAsB,cAAsB;CAEjE,MAAM,OADU,IAAI,aAAa,CACZ,OAAO,aAAa;CACzC,MAAM,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AACxD,QAAO,UAAU,OAAO,IAAI,WAAW,KAAK,EAAE,EAC7C,SAAS,OACT,CAAC"}
|
|
@@ -50,6 +50,10 @@ declare function validateAuthorizationCode({
|
|
|
50
50
|
additionalParams?: Record<string, string> | undefined;
|
|
51
51
|
resource?: (string | string[]) | undefined;
|
|
52
52
|
}): Promise<OAuth2Tokens>;
|
|
53
|
-
declare function validateToken(token: string, jwksEndpoint: string
|
|
53
|
+
declare function validateToken(token: string, jwksEndpoint: string, options?: {
|
|
54
|
+
audience?: string | string[];
|
|
55
|
+
issuer?: string | string[];
|
|
56
|
+
}): Promise<jose0.JWTVerifyResult<jose0.JWTPayload> & jose0.ResolvedKey>;
|
|
54
57
|
//#endregion
|
|
55
|
-
export { createAuthorizationCodeRequest, validateAuthorizationCode, validateToken };
|
|
58
|
+
export { createAuthorizationCodeRequest, validateAuthorizationCode, validateToken };
|
|
59
|
+
//# sourceMappingURL=validate-authorization-code.d.mts.map
|