@better-auth/i18n 1.5.7-beta.1 → 1.6.0-beta.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/client.d.mts +3 -3
- package/dist/client.mjs +2 -2
- package/dist/{index-CLgbyzkE.d.mts → index-CBC5D-Ic.d.mts} +6 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/version-BqMHXjG-.mjs +5 -0
- package/package.json +7 -6
- package/dist/client.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as i18n } from "./index-
|
|
1
|
+
import { t as i18n } from "./index-CBC5D-Ic.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/client.d.ts
|
|
4
4
|
/**
|
|
@@ -20,8 +20,8 @@ import { t as i18n } from "./index-CLgbyzkE.mjs";
|
|
|
20
20
|
*/
|
|
21
21
|
declare const i18nClient: () => {
|
|
22
22
|
id: "i18n";
|
|
23
|
+
version: string;
|
|
23
24
|
$InferServerPlugin: ReturnType<typeof i18n>;
|
|
24
25
|
};
|
|
25
26
|
//#endregion
|
|
26
|
-
export { i18nClient };
|
|
27
|
-
//# sourceMappingURL=client.d.mts.map
|
|
27
|
+
export { i18nClient };
|
package/dist/client.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-BqMHXjG-.mjs";
|
|
1
2
|
//#region src/client.ts
|
|
2
3
|
/**
|
|
3
4
|
* i18n client plugin for Better Auth
|
|
@@ -19,10 +20,9 @@
|
|
|
19
20
|
const i18nClient = () => {
|
|
20
21
|
return {
|
|
21
22
|
id: "i18n",
|
|
23
|
+
version: PACKAGE_VERSION,
|
|
22
24
|
$InferServerPlugin: {}
|
|
23
25
|
};
|
|
24
26
|
};
|
|
25
27
|
//#endregion
|
|
26
28
|
export { i18nClient };
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=client.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, GenericEndpointContext, UnionToIntersection } from "@better-auth/core";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/better-call@2.0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/cookies.d.mts
|
|
4
4
|
//#region src/cookies.d.ts
|
|
5
5
|
type CookiePrefixOptions = "host" | "secure";
|
|
6
6
|
type CookieOptions = {
|
|
@@ -90,7 +90,7 @@ type CookieOptions = {
|
|
|
90
90
|
prefix?: CookiePrefixOptions;
|
|
91
91
|
};
|
|
92
92
|
//#endregion
|
|
93
|
-
//#region ../../node_modules/.pnpm/better-call@2.0.
|
|
93
|
+
//#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/error.d.mts
|
|
94
94
|
declare const statusCodes: {
|
|
95
95
|
OK: number;
|
|
96
96
|
CREATED: number;
|
|
@@ -168,10 +168,10 @@ declare const APIError: new (status?: Status | "OK" | "CREATED" | "ACCEPTED" | "
|
|
|
168
168
|
errorStack: string | undefined;
|
|
169
169
|
}; //#endregion
|
|
170
170
|
//#endregion
|
|
171
|
-
//#region ../../node_modules/.pnpm/better-call@2.0.
|
|
171
|
+
//#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/helper.d.mts
|
|
172
172
|
type Prettify<T> = 0 extends 1 & T ? any : { [K in keyof T]: T[K] } & {};
|
|
173
173
|
//#endregion
|
|
174
|
-
//#region ../../node_modules/.pnpm/better-call@2.0.
|
|
174
|
+
//#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/middleware.d.mts
|
|
175
175
|
//#region src/middleware.d.ts
|
|
176
176
|
type MiddlewareContext<Context = {}> = {
|
|
177
177
|
/**
|
|
@@ -411,6 +411,7 @@ declare module "@better-auth/core" {
|
|
|
411
411
|
*/
|
|
412
412
|
declare const i18n: <Locales extends string[]>(options: I18nOptions<Locales>) => {
|
|
413
413
|
id: "i18n";
|
|
414
|
+
version: string;
|
|
414
415
|
hooks: {
|
|
415
416
|
after: {
|
|
416
417
|
matcher: () => true;
|
|
@@ -427,5 +428,4 @@ declare const i18n: <Locales extends string[]>(options: I18nOptions<Locales>) =>
|
|
|
427
428
|
};
|
|
428
429
|
};
|
|
429
430
|
//#endregion
|
|
430
|
-
export { TranslationDictionary as i, I18nOptions as n, LocaleDetectionStrategy as r, i18n as t };
|
|
431
|
-
//# sourceMappingURL=index-CLgbyzkE.d.mts.map
|
|
431
|
+
export { TranslationDictionary as i, I18nOptions as n, LocaleDetectionStrategy as r, i18n as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as TranslationDictionary, n as I18nOptions, r as LocaleDetectionStrategy, t as i18n } from "./index-
|
|
1
|
+
import { i as TranslationDictionary, n as I18nOptions, r as LocaleDetectionStrategy, t as i18n } from "./index-CBC5D-Ic.mjs";
|
|
2
2
|
export { I18nOptions, LocaleDetectionStrategy, TranslationDictionary, i18n };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-BqMHXjG-.mjs";
|
|
1
2
|
import { APIError, createAuthMiddleware, isAPIError } from "better-auth/api";
|
|
2
3
|
import { parseCookies } from "better-auth/cookies";
|
|
3
4
|
//#region src/index.ts
|
|
@@ -86,6 +87,7 @@ const i18n = (options) => {
|
|
|
86
87
|
}
|
|
87
88
|
return {
|
|
88
89
|
id: "i18n",
|
|
90
|
+
version: PACKAGE_VERSION,
|
|
89
91
|
hooks: { after: [{
|
|
90
92
|
matcher: () => true,
|
|
91
93
|
handler: createAuthMiddleware(async (ctx) => {
|
|
@@ -108,5 +110,3 @@ const i18n = (options) => {
|
|
|
108
110
|
};
|
|
109
111
|
//#endregion
|
|
110
112
|
export { i18n };
|
|
111
|
-
|
|
112
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/i18n",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-beta.0",
|
|
4
4
|
"description": "i18n plugin for Better Auth - translate error messages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
+
"sideEffects": false,
|
|
23
24
|
"files": [
|
|
24
25
|
"dist"
|
|
25
26
|
],
|
|
@@ -50,17 +51,17 @@
|
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"tsdown": "0.21.1",
|
|
53
|
-
"@better-auth/core": "1.
|
|
54
|
-
"better-auth": "1.
|
|
54
|
+
"@better-auth/core": "1.6.0-beta.0",
|
|
55
|
+
"better-auth": "1.6.0-beta.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
|
-
"@better-auth/core": "1.
|
|
58
|
-
"better-auth": "1.
|
|
58
|
+
"@better-auth/core": "^1.6.0-beta.0",
|
|
59
|
+
"better-auth": "^1.6.0-beta.0"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build": "tsdown",
|
|
62
63
|
"dev": "tsdown --watch",
|
|
63
|
-
"lint:package": "publint run --strict",
|
|
64
|
+
"lint:package": "publint run --strict --pack false",
|
|
64
65
|
"lint:types": "attw --profile esm-only --pack .",
|
|
65
66
|
"typecheck": "tsc --project tsconfig.json",
|
|
66
67
|
"test": "vitest",
|
package/dist/client.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { i18n } from \".\";\n\n/**\n * i18n client plugin for Better Auth\n *\n * This client plugin provides type inference for the i18n server plugin.\n * Error messages from the server will already be translated based on\n * the detected locale.\n *\n * @example\n * ```ts\n * import { createAuthClient } from \"better-auth/client\";\n * import { i18nClient } from \"@better-auth/i18n/client\";\n *\n * export const client = createAuthClient({\n * plugins: [i18nClient()],\n * });\n * ```\n */\nexport const i18nClient = () => {\n\treturn {\n\t\tid: \"i18n\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof i18n>,\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,mBAAmB;AAC/B,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n\tBetterAuthPlugin,\n\tGenericEndpointContext,\n} from \"@better-auth/core\";\nimport { APIError, createAuthMiddleware, isAPIError } from \"better-auth/api\";\nimport { parseCookies } from \"better-auth/cookies\";\nimport type { I18nOptions, LocaleDetectionStrategy } from \"./types\";\n\nexport type {\n\tI18nOptions,\n\tLocaleDetectionStrategy,\n\tTranslationDictionary,\n} from \"./types\";\n\ndeclare module \"@better-auth/core\" {\n\tinterface BetterAuthPluginRegistry<AuthOptions, Options> {\n\t\ti18n: {\n\t\t\tcreator: typeof i18n;\n\t\t};\n\t}\n}\n\n/**\n * Parse Accept-Language header and return locales sorted by quality\n */\nfunction parseAcceptLanguage(header: string | null): string[] {\n\tif (!header) return [];\n\treturn header\n\t\t.split(\",\")\n\t\t.map((part) => {\n\t\t\tconst [localeStr, quality = \"q=1\"] = part.trim().split(\";\");\n\t\t\tconst q = Number.parseFloat(quality.replace(\"q=\", \"\"));\n\t\t\t// Get base locale (e.g., \"en\" from \"en-US\")\n\t\t\tconst locale = localeStr?.trim().split(\"-\")[0] ?? \"\";\n\t\t\treturn { locale, q };\n\t\t})\n\t\t.filter((item) => item.locale.length > 0)\n\t\t.sort((a, b) => b.q - a.q)\n\t\t.map((item) => item.locale);\n}\n\n/**\n * i18n plugin for Better Auth\n *\n * Translates error messages based on detected locale.\n *\n * @example\n * ```ts\n * import { betterAuth } from \"better-auth\";\n * import { i18n } from \"@better-auth/i18n\";\n *\n * export const auth = betterAuth({\n * plugins: [\n * i18n({\n * translations: {\n * en: { USER_NOT_FOUND: \"User not found\" },\n * fr: { USER_NOT_FOUND: \"Utilisateur non trouvé\" },\n * },\n * detection: [\"header\", \"cookie\"],\n * }),\n * ],\n * });\n * ```\n */\nexport const i18n = <Locales extends string[]>(\n\toptions: I18nOptions<Locales>,\n) => {\n\tconst availableLocales = Object.keys(options.translations);\n\n\tlet defaultLocale: Locales[number];\n\tif (\n\t\toptions.defaultLocale &&\n\t\tavailableLocales.includes(options.defaultLocale)\n\t) {\n\t\tdefaultLocale = options.defaultLocale;\n\t} else if (availableLocales.includes(\"en\")) {\n\t\tdefaultLocale = \"en\" as Locales[number];\n\t} else if (availableLocales.length > 0) {\n\t\tdefaultLocale = availableLocales[0] as Locales[number];\n\t} else {\n\t\tthrow new Error(\n\t\t\t\"i18n plugin: translations object is empty. At least one locale must be provided.\",\n\t\t);\n\t}\n\n\tconst opts = {\n\t\tdefaultLocale,\n\t\tdetection: [\"header\"] as LocaleDetectionStrategy[],\n\t\tlocaleCookie: \"locale\",\n\t\tuserLocaleField: \"locale\",\n\t\t...options,\n\t};\n\n\tasync function detectLocale(\n\t\tctx: GenericEndpointContext,\n\t): Promise<Locales[number]> {\n\t\tfor (const strategy of opts.detection) {\n\t\t\tlet locale: Locales[number] | null = null;\n\n\t\t\tswitch (strategy) {\n\t\t\t\tcase \"header\": {\n\t\t\t\t\tconst acceptLang = ctx.headers?.get(\"Accept-Language\") ?? null;\n\t\t\t\t\tconst preferred = parseAcceptLanguage(acceptLang);\n\t\t\t\t\tlocale = preferred.find((l) => availableLocales.includes(l)) ?? null;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"cookie\": {\n\t\t\t\t\tconst cookieHeader = ctx.headers?.get(\"Cookie\");\n\t\t\t\t\tif (cookieHeader) {\n\t\t\t\t\t\tconst cookies = parseCookies(cookieHeader);\n\t\t\t\t\t\tconst cookieLocale = cookies.get(opts.localeCookie);\n\t\t\t\t\t\tif (cookieLocale && availableLocales.includes(cookieLocale)) {\n\t\t\t\t\t\t\tlocale = cookieLocale;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"session\": {\n\t\t\t\t\tif (ctx.context.session?.user) {\n\t\t\t\t\t\tconst userLocale = (\n\t\t\t\t\t\t\tctx.context.session.user as Record<string, unknown>\n\t\t\t\t\t\t)[opts.userLocaleField];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof userLocale === \"string\" &&\n\t\t\t\t\t\t\tavailableLocales.includes(userLocale)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlocale = userLocale;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"callback\": {\n\t\t\t\t\tif (opts.getLocale) {\n\t\t\t\t\t\tconst callbackLocale = await opts.getLocale(ctx);\n\t\t\t\t\t\tif (callbackLocale && availableLocales.includes(callbackLocale)) {\n\t\t\t\t\t\t\tlocale = callbackLocale;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (locale) return locale;\n\t\t}\n\n\t\treturn opts.defaultLocale;\n\t}\n\n\treturn {\n\t\tid: \"i18n\",\n\t\thooks: {\n\t\t\tafter: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: () => true,\n\t\t\t\t\thandler: createAuthMiddleware(async (ctx) => {\n\t\t\t\t\t\tconst returned = ctx.context.returned;\n\n\t\t\t\t\t\tif (!isAPIError(returned)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst errorCode = (returned.body as Record<string, unknown>)?.code;\n\t\t\t\t\t\tif (typeof errorCode !== \"string\") {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst locale = await detectLocale(ctx);\n\n\t\t\t\t\t\tconst translation = opts.translations[locale]?.[errorCode];\n\n\t\t\t\t\t\tif (!translation) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthrow new APIError(returned.status, {\n\t\t\t\t\t\t\tcode: errorCode,\n\t\t\t\t\t\t\tmessage: translation,\n\t\t\t\t\t\t\toriginalMessage: returned.message,\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\n\t\toptions: opts,\n\t} satisfies BetterAuthPlugin;\n};\n\nexport type * from \"./types\";\n"],"mappings":";;;;;;AAyBA,SAAS,oBAAoB,QAAiC;AAC7D,KAAI,CAAC,OAAQ,QAAO,EAAE;AACtB,QAAO,OACL,MAAM,IAAI,CACV,KAAK,SAAS;EACd,MAAM,CAAC,WAAW,UAAU,SAAS,KAAK,MAAM,CAAC,MAAM,IAAI;EAC3D,MAAM,IAAI,OAAO,WAAW,QAAQ,QAAQ,MAAM,GAAG,CAAC;AAGtD,SAAO;GAAE,QADM,WAAW,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM;GACjC;GAAG;GACnB,CACD,QAAQ,SAAS,KAAK,OAAO,SAAS,EAAE,CACxC,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,EAAE,CACzB,KAAK,SAAS,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0B7B,MAAa,QACZ,YACI;CACJ,MAAM,mBAAmB,OAAO,KAAK,QAAQ,aAAa;CAE1D,IAAI;AACJ,KACC,QAAQ,iBACR,iBAAiB,SAAS,QAAQ,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