fastify-intlayer 8.1.2 → 8.1.3

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.
@@ -1,29 +1 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
-
29
- exports.__toESM = __toESM;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
@@ -1,148 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_chokidar = require("@intlayer/chokidar");
4
- let _intlayer_config = require("@intlayer/config");
5
- let _intlayer_core = require("@intlayer/core");
6
- let cls_hooked = require("cls-hooked");
7
- let fastify_plugin = require("fastify-plugin");
8
- fastify_plugin = require_runtime.__toESM(fastify_plugin);
9
-
10
- //#region src/index.ts
11
- const configuration = (0, _intlayer_config.getConfiguration)();
12
- const { internationalization } = configuration;
13
- /**
14
- * Retrieves the locale from storage (cookies, headers).
15
- * Note: req.cookies requires @fastify/cookie to be registered.
16
- * We cast req to any to avoid hard dependency on @fastify/cookie types.
17
- */
18
- const getStorageLocale = (req) => (0, _intlayer_core.getLocaleFromStorage)({
19
- getCookie: (name) => req.cookies?.[name],
20
- getHeader: (name) => req.headers?.[name]
21
- });
22
- const appNamespace = (0, cls_hooked.createNamespace)("app");
23
- (0, _intlayer_chokidar.prepareIntlayer)(configuration);
24
- const translateFunction = (req) => (content, locale) => {
25
- const { locale: currentLocale, defaultLocale } = req.intlayer;
26
- const targetLocale = locale ?? currentLocale;
27
- if (typeof content === "undefined") return "";
28
- if (typeof content === "string") return content;
29
- if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
30
- else return (0, _intlayer_core.getTranslation)(content, defaultLocale);
31
- return (0, _intlayer_core.getTranslation)(content, targetLocale);
32
- };
33
- /**
34
- * Fastify Plugin that integrates Intlayer into your Fastify application.
35
- *
36
- * It handles:
37
- * 1. Locale detection from storage (cookies, headers).
38
- * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.
39
- * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.
40
- *
41
- * @example
42
- * ```ts
43
- * import Fastify from 'fastify';
44
- * import { intlayer } from 'fastify-intlayer';
45
- *
46
- * const fastify = Fastify();
47
- * fastify.register(intlayer);
48
- * ```
49
- */
50
- const fastifyIntlayer = async (fastify, _opts) => {
51
- if (!fastify.hasRequestDecorator("intlayer")) fastify.decorateRequest("intlayer", null);
52
- fastify.addHook("preHandler", (req, _reply, done) => {
53
- const localeFromStorage = getStorageLocale(req);
54
- const negotiatorHeaders = {};
55
- if (req && typeof req.headers === "object") for (const key in req.headers) {
56
- const val = req.headers[key];
57
- if (typeof val === "string") negotiatorHeaders[key] = val;
58
- else if (Array.isArray(val)) negotiatorHeaders[key] = val.join(",");
59
- }
60
- const localeDetected = (0, _intlayer_core.localeDetector)(negotiatorHeaders, internationalization.locales, internationalization.defaultLocale);
61
- const locale = localeFromStorage ?? localeDetected;
62
- const defaultLocale = internationalization.defaultLocale;
63
- const getIntlayerWrapped = (key, localeArg = localeDetected, ...props) => (0, _intlayer_core.getIntlayer)(key, localeArg, ...props);
64
- const getDictionaryWrapped = (key, localeArg = localeDetected, ...props) => (0, _intlayer_core.getDictionary)(key, localeArg, ...props);
65
- req.intlayer = {
66
- locale_storage: localeFromStorage,
67
- locale_detected: localeDetected,
68
- locale,
69
- defaultLocale,
70
- getIntlayer: getIntlayerWrapped,
71
- getDictionary: getDictionaryWrapped,
72
- t: void 0
73
- };
74
- const t = translateFunction(req);
75
- req.intlayer.t = t;
76
- appNamespace.run(() => {
77
- appNamespace.set("t", t);
78
- appNamespace.set("getIntlayer", getIntlayerWrapped);
79
- appNamespace.set("getDictionary", getDictionaryWrapped);
80
- done();
81
- });
82
- });
83
- };
84
- const intlayer = (0, fastify_plugin.default)(fastifyIntlayer, {
85
- name: "fastify-intlayer",
86
- fastify: "5.x"
87
- });
88
- /**
89
- * Global translation function that retrieves content for the current locale in Fastify.
90
- *
91
- * This function utilizes CLS (Async Local Storage) and must be used within a request context
92
- * managed by the `intlayer` plugin.
93
- *
94
- * @param content - A map of locales to content.
95
- * @param locale - Optional locale override.
96
- * @returns The translated content.
97
- *
98
- * @example
99
- * ```ts
100
- * import { t } from 'fastify-intlayer';
101
- *
102
- * fastify.get('/', async (req, reply) => {
103
- * const greeting = t({
104
- * en: 'Hello',
105
- * fr: 'Bonjour',
106
- * });
107
- * return greeting;
108
- * });
109
- * ```
110
- */
111
- const t = (content, locale) => {
112
- try {
113
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
114
- if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.");
115
- return appNamespace.get("t")(content, locale);
116
- } catch (error) {
117
- if (process.env.NODE_ENV === "development") console.error(error.message);
118
- return (0, _intlayer_core.getTranslation)(content, locale ?? internationalization.defaultLocale);
119
- }
120
- };
121
- const getIntlayer = (...args) => {
122
- try {
123
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
124
- if (typeof appNamespace.get("getIntlayer") !== "function") throw new Error("Context not found. Ensure you are inside a request handling flow.");
125
- return appNamespace.get("getIntlayer")(...args);
126
- } catch (error) {
127
- if (process.env.NODE_ENV === "development") console.error(error.message);
128
- return (0, _intlayer_core.getIntlayer)(...args);
129
- }
130
- };
131
- const getDictionary = (...args) => {
132
- try {
133
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
134
- if (typeof appNamespace.get("getDictionary") !== "function") throw new Error("Context not found. Ensure you are inside a request handling flow.");
135
- return appNamespace.get("getDictionary")(...args);
136
- } catch (error) {
137
- if (process.env.NODE_ENV === "development") console.error(error.message);
138
- return (0, _intlayer_core.getDictionary)(...args);
139
- }
140
- };
141
-
142
- //#endregion
143
- exports.getDictionary = getDictionary;
144
- exports.getIntlayer = getIntlayer;
145
- exports.intlayer = intlayer;
146
- exports.t = t;
147
- exports.translateFunction = translateFunction;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/chokidar/build`),n=require(`@intlayer/config/node`),r=require(`@intlayer/core/interpreter`),i=require(`@intlayer/core/localization`),a=require(`@intlayer/core/utils`),o=require(`cls-hooked`),s=require(`fastify-plugin`);s=e.__toESM(s);const c=(0,n.getConfiguration)(),{internationalization:l}=c,u=e=>(0,a.getLocaleFromStorage)({getCookie:t=>e.cookies?.[t],getHeader:t=>e.headers?.[t]}),d=(0,o.createNamespace)(`app`);(0,t.prepareIntlayer)(c);const f=e=>(t,n)=>{let{locale:i,defaultLocale:a}=e.intlayer,o=n??i;return t===void 0?``:typeof t==`string`?t:t?.[o]===void 0?t?.[a]===void 0?t:(0,r.getTranslation)(t,a):(0,r.getTranslation)(t,o)},p=(0,s.default)(async(e,t)=>{e.hasRequestDecorator(`intlayer`)||e.decorateRequest(`intlayer`,null),e.addHook(`preHandler`,(e,t,n)=>{let a=u(e),o={};if(e&&typeof e.headers==`object`)for(let t in e.headers){let n=e.headers[t];typeof n==`string`?o[t]=n:Array.isArray(n)&&(o[t]=n.join(`,`))}let s=(0,i.localeDetector)(o,l.locales,l.defaultLocale),c=a??s,p=l.defaultLocale,m=(e,t=s,...n)=>(0,r.getIntlayer)(e,t,...n),h=(e,t=s,...n)=>(0,r.getDictionary)(e,t,...n);e.intlayer={locale_storage:a,locale_detected:s,locale:c,defaultLocale:p,getIntlayer:m,getDictionary:h,t:void 0};let g=f(e);e.intlayer.t=g,d.run(()=>{d.set(`t`,g),d.set(`getIntlayer`,m),d.set(`getDictionary`,h),n()})})},{name:`fastify-intlayer`,fastify:`5.x`}),m=(e,t)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof d.get(`t`)!=`function`)throw Error(`Using the import { t } from "fastify-intlayer" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.`);return d.get(`t`)(e,t)}catch(n){return process.env.NODE_ENV===`development`&&console.error(n.message),(0,r.getTranslation)(e,t??l.defaultLocale)}},h=(...e)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof d.get(`getIntlayer`)!=`function`)throw Error(`Context not found. Ensure you are inside a request handling flow.`);return d.get(`getIntlayer`)(...e)}catch(t){return process.env.NODE_ENV===`development`&&console.error(t.message),(0,r.getIntlayer)(...e)}},g=(...e)=>{try{if(d===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof d.get(`getDictionary`)!=`function`)throw Error(`Context not found. Ensure you are inside a request handling flow.`);return d.get(`getDictionary`)(...e)}catch(t){return process.env.NODE_ENV===`development`&&console.error(t.message),(0,r.getDictionary)(...e)}};exports.getDictionary=g,exports.getIntlayer=h,exports.intlayer=p,exports.t=m,exports.translateFunction=f;
148
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getLocaleFromStorage,\n getTranslation,\n localeDetector,\n} from '@intlayer/core';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { FastifyPluginAsync, FastifyRequest } from 'fastify';\nimport fp from 'fastify-plugin';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n * Note: req.cookies requires @fastify/cookie to be registered.\n * We cast req to any to avoid hard dependency on @fastify/cookie types.\n */\nconst getStorageLocale = (req: FastifyRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => (req as any).cookies?.[name],\n getHeader: (name: string) => req.headers?.[name] as string | undefined,\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n// Module augmentation to type the request decoration\ndeclare module 'fastify' {\n interface FastifyRequest {\n intlayer: {\n locale: Locale;\n defaultLocale: Locale;\n locale_storage?: Locale;\n locale_detected?: Locale;\n t: <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ) => T;\n getIntlayer: typeof getIntlayerFunction;\n getDictionary: typeof getDictionaryFunction;\n };\n }\n}\n\nexport const translateFunction =\n (req: FastifyRequest) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n // Access the decorated state from the request\n const { locale: currentLocale, defaultLocale } = req.intlayer;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Fastify Plugin that integrates Intlayer into your Fastify application.\n *\n * It handles:\n * 1. Locale detection from storage (cookies, headers).\n * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.\n * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.\n *\n * @example\n * ```ts\n * import Fastify from 'fastify';\n * import { intlayer } from 'fastify-intlayer';\n *\n * const fastify = Fastify();\n * fastify.register(intlayer);\n * ```\n */\nconst fastifyIntlayer: FastifyPluginAsync = async (fastify, _opts) => {\n // Decorate the request object to ensure types are stable.\n // We use 'null as any' to bypass the initial type check, knowing\n // the preHandler will populate it before any route handler runs.\n if (!fastify.hasRequestDecorator('intlayer')) {\n fastify.decorateRequest('intlayer', null as any);\n }\n\n fastify.addHook('preHandler', (req, _reply, done) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(req);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n if (req && typeof req.headers === 'object') {\n for (const key in req.headers) {\n const val = req.headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n // Handle array headers (unlikely for accept-language but possible in Fastify)\n negotiatorHeaders[key] = val.join(',');\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n const defaultLocale = internationalization.defaultLocale;\n\n // Helper functions bound to the current request context\n const getIntlayerWrapped: typeof getIntlayerFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionaryWrapped: typeof getDictionaryFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Assign data to request decoration\n req.intlayer = {\n locale_storage: localeFromStorage,\n locale_detected: localeDetected,\n locale,\n defaultLocale,\n getIntlayer: getIntlayerWrapped,\n getDictionary: getDictionaryWrapped,\n t: undefined as unknown as any, // Placeholder\n };\n\n // Now bind t using the updated req\n const t = translateFunction(req);\n req.intlayer.t = t;\n\n // Run CLS context\n appNamespace.run(() => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayerWrapped);\n appNamespace.set('getDictionary', getDictionaryWrapped);\n\n done();\n });\n });\n};\n\n// Export as a Fastify Plugin (wrapped in fp to skip encapsulation)\nexport const intlayer = fp(fastifyIntlayer as any, {\n name: 'fastify-intlayer',\n fastify: '5.x',\n}) as unknown as FastifyPluginAsync;\n\n/**\n * Global translation function that retrieves content for the current locale in Fastify.\n *\n * This function utilizes CLS (Async Local Storage) and must be used within a request context\n * managed by the `intlayer` plugin.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'fastify-intlayer';\n *\n * fastify.get('/', async (req, reply) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,wDAAkC;AACxC,MAAM,EAAE,yBAAyB;;;;;;AAOjC,MAAM,oBAAoB,iDACH;CACnB,YAAY,SAAkB,IAAY,UAAU;CACpD,YAAY,SAAiB,IAAI,UAAU;CA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 {"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { localeDetector } from '@intlayer/core/localization';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { FastifyPluginAsync, FastifyRequest } from 'fastify';\nimport fp from 'fastify-plugin';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n * Note: req.cookies requires @fastify/cookie to be registered.\n * We cast req to any to avoid hard dependency on @fastify/cookie types.\n */\nconst getStorageLocale = (req: FastifyRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => (req as any).cookies?.[name],\n getHeader: (name: string) => req.headers?.[name] as string | undefined,\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n// Module augmentation to type the request decoration\ndeclare module 'fastify' {\n interface FastifyRequest {\n intlayer: {\n locale: Locale;\n defaultLocale: Locale;\n locale_storage?: Locale;\n locale_detected?: Locale;\n t: <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ) => T;\n getIntlayer: typeof getIntlayerFunction;\n getDictionary: typeof getDictionaryFunction;\n };\n }\n}\n\nexport const translateFunction =\n (req: FastifyRequest) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n // Access the decorated state from the request\n const { locale: currentLocale, defaultLocale } = req.intlayer;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Fastify Plugin that integrates Intlayer into your Fastify application.\n *\n * It handles:\n * 1. Locale detection from storage (cookies, headers).\n * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.\n * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.\n *\n * @example\n * ```ts\n * import Fastify from 'fastify';\n * import { intlayer } from 'fastify-intlayer';\n *\n * const fastify = Fastify();\n * fastify.register(intlayer);\n * ```\n */\nconst fastifyIntlayer: FastifyPluginAsync = async (fastify, _opts) => {\n // Decorate the request object to ensure types are stable.\n // We use 'null as any' to bypass the initial type check, knowing\n // the preHandler will populate it before any route handler runs.\n if (!fastify.hasRequestDecorator('intlayer')) {\n fastify.decorateRequest('intlayer', null as any);\n }\n\n fastify.addHook('preHandler', (req, _reply, done) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(req);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n if (req && typeof req.headers === 'object') {\n for (const key in req.headers) {\n const val = req.headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n // Handle array headers (unlikely for accept-language but possible in Fastify)\n negotiatorHeaders[key] = val.join(',');\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n const defaultLocale = internationalization.defaultLocale;\n\n // Helper functions bound to the current request context\n const getIntlayerWrapped: typeof getIntlayerFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionaryWrapped: typeof getDictionaryFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Assign data to request decoration\n req.intlayer = {\n locale_storage: localeFromStorage,\n locale_detected: localeDetected,\n locale,\n defaultLocale,\n getIntlayer: getIntlayerWrapped,\n getDictionary: getDictionaryWrapped,\n t: undefined as unknown as any, // Placeholder\n };\n\n // Now bind t using the updated req\n const t = translateFunction(req);\n req.intlayer.t = t;\n\n // Run CLS context\n appNamespace.run(() => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayerWrapped);\n appNamespace.set('getDictionary', getDictionaryWrapped);\n\n done();\n });\n });\n};\n\n// Export as a Fastify Plugin (wrapped in fp to skip encapsulation)\nexport const intlayer = fp(fastifyIntlayer as any, {\n name: 'fastify-intlayer',\n fastify: '5.x',\n}) as unknown as FastifyPluginAsync;\n\n/**\n * Global translation function that retrieves content for the current locale in Fastify.\n *\n * This function utilizes CLS (Async Local Storage) and must be used within a request context\n * managed by the `intlayer` plugin.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'fastify-intlayer';\n *\n * fastify.get('/', async (req, reply) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":"0XAcA,MAAM,GAAA,EAAA,EAAA,mBAAkC,CAClC,CAAE,wBAAyB,EAO3B,EAAoB,IAAA,EAAA,EAAA,sBACH,CACnB,UAAY,GAAkB,EAAY,UAAU,GACpD,UAAY,GAAiB,EAAI,UAAU,GAC5C,CAAC,CAEE,GAAA,EAAA,EAAA,iBAA+B,MAAM,uBAE3B,EAAc,CAoB9B,MAAa,EACV,IAEC,EACA,IACM,CAEN,GAAM,CAAE,OAAQ,EAAe,iBAAkB,EAAI,SAE/C,EAAe,GAAU,EA0B/B,OAxBW,IAAY,OACd,GAGL,OAAO,GAAY,SACd,EAIA,IACL,KACI,OAGG,IACL,KACI,OAEC,GAEP,EAAA,EAAA,gBAAsB,EAAS,EAAc,EAIjD,EAAA,EAAA,gBAAsB,EAAS,EAAa,EAgGnC,GAAA,EAAA,EAAA,SA5E+B,MAAO,EAAS,IAAU,CAI/D,EAA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AAgB,QAAQ,EAGzC,EAAA,EAAA,gBACE,EACA,GAAU,EAAqB,cAChC,GAIQ,GAA2C,GAAG,IAAS,CAClE,GAAI,CACF,GAAW,IAAiB,OAC1B,MAAU,MACR,iFACD,CAGH,GAAI,OAAO,EAAa,IAAI,cAAc,EAAK,WAC7C,MAAU,MACR,oEACD,CAGH,OAAO,EAAa,IAAI,cAAc,CAAC,GAAG,EAAK,OACxC,EAAO,CAId,OAHI,QAAQ,IAAI,WAAa,eAC3B,QAAQ,MAAO,EAAgB,QAAQ,EAEzC,EAAA,EAAA,aAA2B,GAAG,EAAK,GAI1B,GAA+C,GAAG,IAAS,CACtE,GAAI,CACF,GAAW,IAAiB,OAC1B,MAAU,MACR,iFACD,CAGH,GAAI,OAAO,EAAa,IAAI,gBAAgB,EAAK,WAC/C,MAAU,MACR,oEACD,CAGH,OAAO,EAAa,IAAI,gBAAgB,CAAC,GAAG,EAAK,OAC1C,EAAO,CAId,OAHI,QAAQ,IAAI,WAAa,eAC3B,QAAQ,MAAO,EAAgB,QAAQ,EAEzC,EAAA,EAAA,eAA6B,GAAG,EAAK"}
@@ -1,141 +1,2 @@
1
- import { prepareIntlayer } from "@intlayer/chokidar";
2
- import { getConfiguration } from "@intlayer/config";
3
- import { getDictionary as getDictionary$1, getIntlayer as getIntlayer$1, getLocaleFromStorage, getTranslation, localeDetector } from "@intlayer/core";
4
- import { createNamespace } from "cls-hooked";
5
- import fp from "fastify-plugin";
6
-
7
- //#region src/index.ts
8
- const configuration = getConfiguration();
9
- const { internationalization } = configuration;
10
- /**
11
- * Retrieves the locale from storage (cookies, headers).
12
- * Note: req.cookies requires @fastify/cookie to be registered.
13
- * We cast req to any to avoid hard dependency on @fastify/cookie types.
14
- */
15
- const getStorageLocale = (req) => getLocaleFromStorage({
16
- getCookie: (name) => req.cookies?.[name],
17
- getHeader: (name) => req.headers?.[name]
18
- });
19
- const appNamespace = createNamespace("app");
20
- prepareIntlayer(configuration);
21
- const translateFunction = (req) => (content, locale) => {
22
- const { locale: currentLocale, defaultLocale } = req.intlayer;
23
- const targetLocale = locale ?? currentLocale;
24
- if (typeof content === "undefined") return "";
25
- if (typeof content === "string") return content;
26
- if (typeof content?.[targetLocale] === "undefined") if (typeof content?.[defaultLocale] === "undefined") return content;
27
- else return getTranslation(content, defaultLocale);
28
- return getTranslation(content, targetLocale);
29
- };
30
- /**
31
- * Fastify Plugin that integrates Intlayer into your Fastify application.
32
- *
33
- * It handles:
34
- * 1. Locale detection from storage (cookies, headers).
35
- * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.
36
- * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.
37
- *
38
- * @example
39
- * ```ts
40
- * import Fastify from 'fastify';
41
- * import { intlayer } from 'fastify-intlayer';
42
- *
43
- * const fastify = Fastify();
44
- * fastify.register(intlayer);
45
- * ```
46
- */
47
- const fastifyIntlayer = async (fastify, _opts) => {
48
- if (!fastify.hasRequestDecorator("intlayer")) fastify.decorateRequest("intlayer", null);
49
- fastify.addHook("preHandler", (req, _reply, done) => {
50
- const localeFromStorage = getStorageLocale(req);
51
- const negotiatorHeaders = {};
52
- if (req && typeof req.headers === "object") for (const key in req.headers) {
53
- const val = req.headers[key];
54
- if (typeof val === "string") negotiatorHeaders[key] = val;
55
- else if (Array.isArray(val)) negotiatorHeaders[key] = val.join(",");
56
- }
57
- const localeDetected = localeDetector(negotiatorHeaders, internationalization.locales, internationalization.defaultLocale);
58
- const locale = localeFromStorage ?? localeDetected;
59
- const defaultLocale = internationalization.defaultLocale;
60
- const getIntlayerWrapped = (key, localeArg = localeDetected, ...props) => getIntlayer$1(key, localeArg, ...props);
61
- const getDictionaryWrapped = (key, localeArg = localeDetected, ...props) => getDictionary$1(key, localeArg, ...props);
62
- req.intlayer = {
63
- locale_storage: localeFromStorage,
64
- locale_detected: localeDetected,
65
- locale,
66
- defaultLocale,
67
- getIntlayer: getIntlayerWrapped,
68
- getDictionary: getDictionaryWrapped,
69
- t: void 0
70
- };
71
- const t = translateFunction(req);
72
- req.intlayer.t = t;
73
- appNamespace.run(() => {
74
- appNamespace.set("t", t);
75
- appNamespace.set("getIntlayer", getIntlayerWrapped);
76
- appNamespace.set("getDictionary", getDictionaryWrapped);
77
- done();
78
- });
79
- });
80
- };
81
- const intlayer = fp(fastifyIntlayer, {
82
- name: "fastify-intlayer",
83
- fastify: "5.x"
84
- });
85
- /**
86
- * Global translation function that retrieves content for the current locale in Fastify.
87
- *
88
- * This function utilizes CLS (Async Local Storage) and must be used within a request context
89
- * managed by the `intlayer` plugin.
90
- *
91
- * @param content - A map of locales to content.
92
- * @param locale - Optional locale override.
93
- * @returns The translated content.
94
- *
95
- * @example
96
- * ```ts
97
- * import { t } from 'fastify-intlayer';
98
- *
99
- * fastify.get('/', async (req, reply) => {
100
- * const greeting = t({
101
- * en: 'Hello',
102
- * fr: 'Bonjour',
103
- * });
104
- * return greeting;
105
- * });
106
- * ```
107
- */
108
- const t = (content, locale) => {
109
- try {
110
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
111
- if (typeof appNamespace.get("t") !== "function") throw new Error("Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.");
112
- return appNamespace.get("t")(content, locale);
113
- } catch (error) {
114
- console.error(error.message);
115
- return getTranslation(content, locale ?? internationalization.defaultLocale);
116
- }
117
- };
118
- const getIntlayer = (...args) => {
119
- try {
120
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
121
- if (typeof appNamespace.get("getIntlayer") !== "function") throw new Error("Context not found. Ensure you are inside a request handling flow.");
122
- return appNamespace.get("getIntlayer")(...args);
123
- } catch (error) {
124
- console.error(error.message);
125
- return getIntlayer$1(...args);
126
- }
127
- };
128
- const getDictionary = (...args) => {
129
- try {
130
- if (typeof appNamespace === "undefined") throw new Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");
131
- if (typeof appNamespace.get("getDictionary") !== "function") throw new Error("Context not found. Ensure you are inside a request handling flow.");
132
- return appNamespace.get("getDictionary")(...args);
133
- } catch (error) {
134
- console.error(error.message);
135
- return getDictionary$1(...args);
136
- }
137
- };
138
-
139
- //#endregion
140
- export { getDictionary, getIntlayer, intlayer, t, translateFunction };
1
+ import{prepareIntlayer as e}from"@intlayer/chokidar/build";import{getConfiguration as t}from"@intlayer/config/node";import{getDictionary as n,getIntlayer as r,getTranslation as i}from"@intlayer/core/interpreter";import{localeDetector as a}from"@intlayer/core/localization";import{getLocaleFromStorage as o}from"@intlayer/core/utils";import{createNamespace as s}from"cls-hooked";import c from"fastify-plugin";const l=t(),{internationalization:u}=l,d=e=>o({getCookie:t=>e.cookies?.[t],getHeader:t=>e.headers?.[t]}),f=s(`app`);e(l);const p=e=>(t,n)=>{let{locale:r,defaultLocale:a}=e.intlayer,o=n??r;return t===void 0?``:typeof t==`string`?t:t?.[o]===void 0?t?.[a]===void 0?t:i(t,a):i(t,o)},m=c(async(e,t)=>{e.hasRequestDecorator(`intlayer`)||e.decorateRequest(`intlayer`,null),e.addHook(`preHandler`,(e,t,i)=>{let o=d(e),s={};if(e&&typeof e.headers==`object`)for(let t in e.headers){let n=e.headers[t];typeof n==`string`?s[t]=n:Array.isArray(n)&&(s[t]=n.join(`,`))}let c=a(s,u.locales,u.defaultLocale),l=o??c,m=u.defaultLocale,h=(e,t=c,...n)=>r(e,t,...n),g=(e,t=c,...r)=>n(e,t,...r);e.intlayer={locale_storage:o,locale_detected:c,locale:l,defaultLocale:m,getIntlayer:h,getDictionary:g,t:void 0};let _=p(e);e.intlayer.t=_,f.run(()=>{f.set(`t`,_),f.set(`getIntlayer`,h),f.set(`getDictionary`,g),i()})})},{name:`fastify-intlayer`,fastify:`5.x`}),h=(e,t)=>{try{if(f===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof f.get(`t`)!=`function`)throw Error(`Using the import { t } from "fastify-intlayer" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.`);return f.get(`t`)(e,t)}catch{return i(e,t??u.defaultLocale)}},g=(...e)=>{try{if(f===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof f.get(`getIntlayer`)!=`function`)throw Error(`Context not found. Ensure you are inside a request handling flow.`);return f.get(`getIntlayer`)(...e)}catch{return r(...e)}},_=(...e)=>{try{if(f===void 0)throw Error("Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.");if(typeof f.get(`getDictionary`)!=`function`)throw Error(`Context not found. Ensure you are inside a request handling flow.`);return f.get(`getDictionary`)(...e)}catch{return n(...e)}};export{_ as getDictionary,g as getIntlayer,m as intlayer,h as t,p as translateFunction};
141
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["getIntlayerFunction","getDictionaryFunction"],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getLocaleFromStorage,\n getTranslation,\n localeDetector,\n} from '@intlayer/core';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { FastifyPluginAsync, FastifyRequest } from 'fastify';\nimport fp from 'fastify-plugin';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n * Note: req.cookies requires @fastify/cookie to be registered.\n * We cast req to any to avoid hard dependency on @fastify/cookie types.\n */\nconst getStorageLocale = (req: FastifyRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => (req as any).cookies?.[name],\n getHeader: (name: string) => req.headers?.[name] as string | undefined,\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n// Module augmentation to type the request decoration\ndeclare module 'fastify' {\n interface FastifyRequest {\n intlayer: {\n locale: Locale;\n defaultLocale: Locale;\n locale_storage?: Locale;\n locale_detected?: Locale;\n t: <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ) => T;\n getIntlayer: typeof getIntlayerFunction;\n getDictionary: typeof getDictionaryFunction;\n };\n }\n}\n\nexport const translateFunction =\n (req: FastifyRequest) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n // Access the decorated state from the request\n const { locale: currentLocale, defaultLocale } = req.intlayer;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Fastify Plugin that integrates Intlayer into your Fastify application.\n *\n * It handles:\n * 1. Locale detection from storage (cookies, headers).\n * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.\n * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.\n *\n * @example\n * ```ts\n * import Fastify from 'fastify';\n * import { intlayer } from 'fastify-intlayer';\n *\n * const fastify = Fastify();\n * fastify.register(intlayer);\n * ```\n */\nconst fastifyIntlayer: FastifyPluginAsync = async (fastify, _opts) => {\n // Decorate the request object to ensure types are stable.\n // We use 'null as any' to bypass the initial type check, knowing\n // the preHandler will populate it before any route handler runs.\n if (!fastify.hasRequestDecorator('intlayer')) {\n fastify.decorateRequest('intlayer', null as any);\n }\n\n fastify.addHook('preHandler', (req, _reply, done) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(req);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n if (req && typeof req.headers === 'object') {\n for (const key in req.headers) {\n const val = req.headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n // Handle array headers (unlikely for accept-language but possible in Fastify)\n negotiatorHeaders[key] = val.join(',');\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n const defaultLocale = internationalization.defaultLocale;\n\n // Helper functions bound to the current request context\n const getIntlayerWrapped: typeof getIntlayerFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionaryWrapped: typeof getDictionaryFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Assign data to request decoration\n req.intlayer = {\n locale_storage: localeFromStorage,\n locale_detected: localeDetected,\n locale,\n defaultLocale,\n getIntlayer: getIntlayerWrapped,\n getDictionary: getDictionaryWrapped,\n t: undefined as unknown as any, // Placeholder\n };\n\n // Now bind t using the updated req\n const t = translateFunction(req);\n req.intlayer.t = t;\n\n // Run CLS context\n appNamespace.run(() => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayerWrapped);\n appNamespace.set('getDictionary', getDictionaryWrapped);\n\n done();\n });\n });\n};\n\n// Export as a Fastify Plugin (wrapped in fp to skip encapsulation)\nexport const intlayer = fp(fastifyIntlayer as any, {\n name: 'fastify-intlayer',\n fastify: '5.x',\n}) as unknown as FastifyPluginAsync;\n\n/**\n * Global translation function that retrieves content for the current locale in Fastify.\n *\n * This function utilizes CLS (Async Local Storage) and must be used within a request context\n * managed by the `intlayer` plugin.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'fastify-intlayer';\n *\n * fastify.get('/', async (req, reply) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB,kBAAkB;AACxC,MAAM,EAAE,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UAC1C,OAAO;AAEZ,UAAQ,MAAO,MAAgB,QAAQ;AAEzC,SAAOC,gBAAsB,GAAG,KAAK"}
1
+ {"version":3,"file":"index.mjs","names":["getIntlayerFunction","getDictionaryFunction"],"sources":["../../src/index.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getDictionary as getDictionaryFunction,\n getIntlayer as getIntlayerFunction,\n getTranslation,\n} from '@intlayer/core/interpreter';\nimport { localeDetector } from '@intlayer/core/localization';\nimport { getLocaleFromStorage } from '@intlayer/core/utils';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { createNamespace } from 'cls-hooked';\nimport type { FastifyPluginAsync, FastifyRequest } from 'fastify';\nimport fp from 'fastify-plugin';\n\nconst configuration = getConfiguration();\nconst { internationalization } = configuration;\n\n/**\n * Retrieves the locale from storage (cookies, headers).\n * Note: req.cookies requires @fastify/cookie to be registered.\n * We cast req to any to avoid hard dependency on @fastify/cookie types.\n */\nconst getStorageLocale = (req: FastifyRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => (req as any).cookies?.[name],\n getHeader: (name: string) => req.headers?.[name] as string | undefined,\n });\n\nconst appNamespace = createNamespace('app');\n\nprepareIntlayer(configuration);\n\n// Module augmentation to type the request decoration\ndeclare module 'fastify' {\n interface FastifyRequest {\n intlayer: {\n locale: Locale;\n defaultLocale: Locale;\n locale_storage?: Locale;\n locale_detected?: Locale;\n t: <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ) => T;\n getIntlayer: typeof getIntlayerFunction;\n getDictionary: typeof getDictionaryFunction;\n };\n }\n}\n\nexport const translateFunction =\n (req: FastifyRequest) =>\n <T extends string>(\n content: StrictModeLocaleMap<T> | string,\n locale?: Locale\n ): T => {\n // Access the decorated state from the request\n const { locale: currentLocale, defaultLocale } = req.intlayer;\n\n const targetLocale = locale ?? currentLocale;\n\n if (typeof content === 'undefined') {\n return '' as unknown as T;\n }\n\n if (typeof content === 'string') {\n return content as unknown as T;\n }\n\n if (\n typeof content?.[\n targetLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n if (\n typeof content?.[\n defaultLocale as unknown as keyof StrictModeLocaleMap<T>\n ] === 'undefined'\n ) {\n return content as unknown as T;\n } else {\n return getTranslation(content, defaultLocale);\n }\n }\n\n return getTranslation(content, targetLocale);\n };\n\n/**\n * Fastify Plugin that integrates Intlayer into your Fastify application.\n *\n * It handles:\n * 1. Locale detection from storage (cookies, headers).\n * 2. Decorating the request object with `intlayer` data containing `t`, `getIntlayer`, and `getDictionary`.\n * 3. Setting up a `cls-hooked` namespace for programmatic access during the request lifecycle.\n *\n * @example\n * ```ts\n * import Fastify from 'fastify';\n * import { intlayer } from 'fastify-intlayer';\n *\n * const fastify = Fastify();\n * fastify.register(intlayer);\n * ```\n */\nconst fastifyIntlayer: FastifyPluginAsync = async (fastify, _opts) => {\n // Decorate the request object to ensure types are stable.\n // We use 'null as any' to bypass the initial type check, knowing\n // the preHandler will populate it before any route handler runs.\n if (!fastify.hasRequestDecorator('intlayer')) {\n fastify.decorateRequest('intlayer', null as any);\n }\n\n fastify.addHook('preHandler', (req, _reply, done) => {\n // Detect if locale is set by intlayer frontend lib in the headers\n const localeFromStorage = getStorageLocale(req);\n\n const negotiatorHeaders: Record<string, string> = {};\n\n // Copy all headers from the request to negotiatorHeaders\n if (req && typeof req.headers === 'object') {\n for (const key in req.headers) {\n const val = req.headers[key];\n if (typeof val === 'string') {\n negotiatorHeaders[key] = val;\n } else if (Array.isArray(val)) {\n // Handle array headers (unlikely for accept-language but possible in Fastify)\n negotiatorHeaders[key] = val.join(',');\n }\n }\n }\n\n const localeDetected = localeDetector(\n negotiatorHeaders,\n internationalization.locales,\n internationalization.defaultLocale\n );\n\n const locale = localeFromStorage ?? localeDetected;\n const defaultLocale = internationalization.defaultLocale;\n\n // Helper functions bound to the current request context\n const getIntlayerWrapped: typeof getIntlayerFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getIntlayerFunction>[1],\n ...props\n ) => getIntlayerFunction(key, localeArg, ...props);\n\n const getDictionaryWrapped: typeof getDictionaryFunction = (\n key,\n localeArg = localeDetected as Parameters<typeof getDictionaryFunction>[1],\n ...props\n ) => getDictionaryFunction(key, localeArg, ...props);\n\n // Assign data to request decoration\n req.intlayer = {\n locale_storage: localeFromStorage,\n locale_detected: localeDetected,\n locale,\n defaultLocale,\n getIntlayer: getIntlayerWrapped,\n getDictionary: getDictionaryWrapped,\n t: undefined as unknown as any, // Placeholder\n };\n\n // Now bind t using the updated req\n const t = translateFunction(req);\n req.intlayer.t = t;\n\n // Run CLS context\n appNamespace.run(() => {\n appNamespace.set('t', t);\n appNamespace.set('getIntlayer', getIntlayerWrapped);\n appNamespace.set('getDictionary', getDictionaryWrapped);\n\n done();\n });\n });\n};\n\n// Export as a Fastify Plugin (wrapped in fp to skip encapsulation)\nexport const intlayer = fp(fastifyIntlayer as any, {\n name: 'fastify-intlayer',\n fastify: '5.x',\n}) as unknown as FastifyPluginAsync;\n\n/**\n * Global translation function that retrieves content for the current locale in Fastify.\n *\n * This function utilizes CLS (Async Local Storage) and must be used within a request context\n * managed by the `intlayer` plugin.\n *\n * @param content - A map of locales to content.\n * @param locale - Optional locale override.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * import { t } from 'fastify-intlayer';\n *\n * fastify.get('/', async (req, reply) => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * });\n * return greeting;\n * });\n * ```\n */\nexport const t = <Content = string>(\n content: StrictModeLocaleMap<Content>,\n locale?: Locale\n): Content => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('t') !== 'function') {\n throw new Error(\n 'Using the import { t } from \"fastify-intlayer\" is not supported in your environment outside of a request context or proper setup. Use req.intlayer.t instead.'\n );\n }\n\n return appNamespace.get('t')(content, locale);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n\n return getTranslation(\n content,\n locale ?? internationalization.defaultLocale\n );\n }\n};\n\nexport const getIntlayer: typeof getIntlayerFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getIntlayer') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getIntlayer')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getIntlayerFunction(...args);\n }\n};\n\nexport const getDictionary: typeof getDictionaryFunction = (...args) => {\n try {\n if (typeof appNamespace === 'undefined') {\n throw new Error(\n 'Intlayer is not initialized. Register the plugin `fastify.register(intlayer)`.'\n );\n }\n\n if (typeof appNamespace.get('getDictionary') !== 'function') {\n throw new Error(\n 'Context not found. Ensure you are inside a request handling flow.'\n );\n }\n\n return appNamespace.get('getDictionary')(...args);\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.error((error as Error).message);\n }\n return getDictionaryFunction(...args);\n }\n};\n"],"mappings":"wZAcA,MAAM,EAAgB,GAAkB,CAClC,CAAE,wBAAyB,EAO3B,EAAoB,GACxB,EAAqB,CACnB,UAAY,GAAkB,EAAY,UAAU,GACpD,UAAY,GAAiB,EAAI,UAAU,GAC5C,CAAC,CAEE,EAAe,EAAgB,MAAM,CAE3C,EAAgB,EAAc,CAoB9B,MAAa,EACV,IAEC,EACA,IACM,CAEN,GAAM,CAAE,OAAQ,EAAe,iBAAkB,EAAI,SAE/C,EAAe,GAAU,EA0B/B,OAxBW,IAAY,OACd,GAGL,OAAO,GAAY,SACd,EAIA,IACL,KACI,OAGG,IACL,KACI,OAEC,EAEA,EAAe,EAAS,EAAc,CAI1C,EAAe,EAAS,EAAa,EAgGnC,E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AA2C,GAAG,IAAS,CAClE,GAAI,CACF,GAAW,IAAiB,OAC1B,MAAU,MACR,iFACD,CAGH,GAAI,OAAO,EAAa,IAAI,cAAc,EAAK,WAC7C,MAAU,MACR,oEACD,CAGH,OAAO,EAAa,IAAI,cAAc,CAAC,GAAG,EAAK,MACjC,CAId,OAAOD,EAAoB,GAAG,EAAK,GAI1B,GAA+C,GAAG,IAAS,CACtE,GAAI,CACF,GAAW,IAAiB,OAC1B,MAAU,MACR,iFACD,CAGH,GAAI,OAAO,EAAa,IAAI,gBAAgB,EAAK,WAC/C,MAAU,MACR,oEACD,CAGH,OAAO,EAAa,IAAI,gBAAgB,CAAC,GAAG,EAAK,MACnC,CAId,OAAOC,EAAsB,GAAG,EAAK"}
@@ -1,4 +1,4 @@
1
- import { getDictionary as getDictionary$1, getIntlayer as getIntlayer$1 } from "@intlayer/core";
1
+ import { getDictionary as getDictionary$1, getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
2
2
  import { Locale, StrictModeLocaleMap } from "@intlayer/types";
3
3
  import { FastifyPluginAsync, FastifyRequest } from "fastify";
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-intlayer",
3
- "version": "8.1.2",
3
+ "version": "8.1.3",
4
4
  "private": false,
5
5
  "description": "Manage internationalization i18n in a simple way for Fastify applications.",
6
6
  "keywords": [
@@ -76,13 +76,13 @@
76
76
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
77
77
  },
78
78
  "dependencies": {
79
- "@intlayer/chokidar": "8.1.2",
80
- "@intlayer/config": "8.1.2",
81
- "@intlayer/core": "8.1.2",
82
- "@intlayer/types": "8.1.2",
79
+ "@intlayer/chokidar": "8.1.3",
80
+ "@intlayer/config": "8.1.3",
81
+ "@intlayer/core": "8.1.3",
82
+ "@intlayer/types": "8.1.3",
83
83
  "cls-hooked": "4.2.2",
84
84
  "fastify-plugin": "5.1.0",
85
- "intlayer": "8.1.2"
85
+ "intlayer": "8.1.3"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/cls-hooked": "4.3.9",