@burdenoff/be-sdk 2026.510.79

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.
Files changed (220) hide show
  1. package/README.md +173 -0
  2. package/configs/eslint/index.js +492 -0
  3. package/configs/tsconfig/tsconfig.json +53 -0
  4. package/dist/EventQueueFactory-6NMSGECR.js +8 -0
  5. package/dist/EventQueueFactory-6NMSGECR.js.map +1 -0
  6. package/dist/auth/index.d.ts +66 -0
  7. package/dist/auth/index.js +8 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/cache/index.d.ts +2 -0
  10. package/dist/cache/index.js +6 -0
  11. package/dist/cache/index.js.map +1 -0
  12. package/dist/captcha/index.d.ts +1 -0
  13. package/dist/captcha/index.js +4 -0
  14. package/dist/captcha/index.js.map +1 -0
  15. package/dist/chunk-2HANKZZM.js +245 -0
  16. package/dist/chunk-2HANKZZM.js.map +1 -0
  17. package/dist/chunk-2SD5L2F2.js +816 -0
  18. package/dist/chunk-2SD5L2F2.js.map +1 -0
  19. package/dist/chunk-3O2RQOPV.js +1068 -0
  20. package/dist/chunk-3O2RQOPV.js.map +1 -0
  21. package/dist/chunk-4B43DZIS.js +560 -0
  22. package/dist/chunk-4B43DZIS.js.map +1 -0
  23. package/dist/chunk-4XAEES25.js +2444 -0
  24. package/dist/chunk-4XAEES25.js.map +1 -0
  25. package/dist/chunk-4XGGWW36.js +1405 -0
  26. package/dist/chunk-4XGGWW36.js.map +1 -0
  27. package/dist/chunk-5LXDPGDH.js +245 -0
  28. package/dist/chunk-5LXDPGDH.js.map +1 -0
  29. package/dist/chunk-AI7L22ZJ.js +472 -0
  30. package/dist/chunk-AI7L22ZJ.js.map +1 -0
  31. package/dist/chunk-CBZNP6RF.js +286 -0
  32. package/dist/chunk-CBZNP6RF.js.map +1 -0
  33. package/dist/chunk-ELLX3K54.js +613 -0
  34. package/dist/chunk-ELLX3K54.js.map +1 -0
  35. package/dist/chunk-F5XEAGHQ.js +1875 -0
  36. package/dist/chunk-F5XEAGHQ.js.map +1 -0
  37. package/dist/chunk-FNZEQOJY.js +628 -0
  38. package/dist/chunk-FNZEQOJY.js.map +1 -0
  39. package/dist/chunk-GTEMQXCA.js +516 -0
  40. package/dist/chunk-GTEMQXCA.js.map +1 -0
  41. package/dist/chunk-HIWTWIGQ.js +226 -0
  42. package/dist/chunk-HIWTWIGQ.js.map +1 -0
  43. package/dist/chunk-IYE2NTRX.js +764 -0
  44. package/dist/chunk-IYE2NTRX.js.map +1 -0
  45. package/dist/chunk-J26YGR2U.js +1484 -0
  46. package/dist/chunk-J26YGR2U.js.map +1 -0
  47. package/dist/chunk-JG2FTZPI.js +509 -0
  48. package/dist/chunk-JG2FTZPI.js.map +1 -0
  49. package/dist/chunk-JVBTNSPG.js +1551 -0
  50. package/dist/chunk-JVBTNSPG.js.map +1 -0
  51. package/dist/chunk-L7ZMN2FJ.js +12 -0
  52. package/dist/chunk-L7ZMN2FJ.js.map +1 -0
  53. package/dist/chunk-M5IMU3US.js +473 -0
  54. package/dist/chunk-M5IMU3US.js.map +1 -0
  55. package/dist/chunk-MLW2HPS5.js +1267 -0
  56. package/dist/chunk-MLW2HPS5.js.map +1 -0
  57. package/dist/chunk-MNCGUYLJ.js +269 -0
  58. package/dist/chunk-MNCGUYLJ.js.map +1 -0
  59. package/dist/chunk-MOCUBSTW.js +373 -0
  60. package/dist/chunk-MOCUBSTW.js.map +1 -0
  61. package/dist/chunk-NGMEI42S.js +103 -0
  62. package/dist/chunk-NGMEI42S.js.map +1 -0
  63. package/dist/chunk-NUB5GQTU.js +270 -0
  64. package/dist/chunk-NUB5GQTU.js.map +1 -0
  65. package/dist/chunk-OVSYMNCI.js +145 -0
  66. package/dist/chunk-OVSYMNCI.js.map +1 -0
  67. package/dist/chunk-QLVKMWFA.js +94 -0
  68. package/dist/chunk-QLVKMWFA.js.map +1 -0
  69. package/dist/chunk-SAG6ZYWQ.js +89 -0
  70. package/dist/chunk-SAG6ZYWQ.js.map +1 -0
  71. package/dist/chunk-SAK2JCA7.js +198 -0
  72. package/dist/chunk-SAK2JCA7.js.map +1 -0
  73. package/dist/chunk-SBS4S2PJ.js +100 -0
  74. package/dist/chunk-SBS4S2PJ.js.map +1 -0
  75. package/dist/chunk-SNEOLWXT.js +148 -0
  76. package/dist/chunk-SNEOLWXT.js.map +1 -0
  77. package/dist/chunk-TKBD2ONF.js +564 -0
  78. package/dist/chunk-TKBD2ONF.js.map +1 -0
  79. package/dist/chunk-UBXFIIAW.js +127 -0
  80. package/dist/chunk-UBXFIIAW.js.map +1 -0
  81. package/dist/chunk-VI4VSNTI.js +57 -0
  82. package/dist/chunk-VI4VSNTI.js.map +1 -0
  83. package/dist/chunk-VWCN5PMD.js +268 -0
  84. package/dist/chunk-VWCN5PMD.js.map +1 -0
  85. package/dist/chunk-XC2YD6CF.js +913 -0
  86. package/dist/chunk-XC2YD6CF.js.map +1 -0
  87. package/dist/chunk-XE4OXN2W.js +10 -0
  88. package/dist/chunk-XE4OXN2W.js.map +1 -0
  89. package/dist/chunk-YMZEUTD2.js +110 -0
  90. package/dist/chunk-YMZEUTD2.js.map +1 -0
  91. package/dist/chunk-Z4IRLBWO.js +758 -0
  92. package/dist/chunk-Z4IRLBWO.js.map +1 -0
  93. package/dist/client/internal-client.d.ts +7 -0
  94. package/dist/client/internal-client.js +5 -0
  95. package/dist/client/internal-client.js.map +1 -0
  96. package/dist/client-CSjIrYKS.d.ts +77 -0
  97. package/dist/config-UKE2E3BW.js +4 -0
  98. package/dist/config-UKE2E3BW.js.map +1 -0
  99. package/dist/crypto/index.d.ts +1 -0
  100. package/dist/crypto/index.js +4 -0
  101. package/dist/crypto/index.js.map +1 -0
  102. package/dist/database/index.d.ts +117 -0
  103. package/dist/database/index.js +7 -0
  104. package/dist/database/index.js.map +1 -0
  105. package/dist/dataloader/index.d.ts +1 -0
  106. package/dist/dataloader/index.js +4 -0
  107. package/dist/dataloader/index.js.map +1 -0
  108. package/dist/esm-K6H7EIWK.js +1450 -0
  109. package/dist/esm-K6H7EIWK.js.map +1 -0
  110. package/dist/event-queue/index.d.ts +6 -0
  111. package/dist/event-queue/index.js +10 -0
  112. package/dist/event-queue/index.js.map +1 -0
  113. package/dist/export/index.d.ts +2 -0
  114. package/dist/export/index.js +9 -0
  115. package/dist/export/index.js.map +1 -0
  116. package/dist/feature-flags/index.d.ts +1 -0
  117. package/dist/feature-flags/index.js +4 -0
  118. package/dist/feature-flags/index.js.map +1 -0
  119. package/dist/gateway/index.d.ts +4 -0
  120. package/dist/gateway/index.js +8 -0
  121. package/dist/gateway/index.js.map +1 -0
  122. package/dist/gateway/security/index.d.ts +2 -0
  123. package/dist/gateway/security/index.js +5 -0
  124. package/dist/gateway/security/index.js.map +1 -0
  125. package/dist/graph/index.d.ts +9 -0
  126. package/dist/graph/index.js +13 -0
  127. package/dist/graph/index.js.map +1 -0
  128. package/dist/graph-emitter-Bk0FqD53.d.ts +47 -0
  129. package/dist/graphql/index.d.ts +2 -0
  130. package/dist/graphql/index.js +7 -0
  131. package/dist/graphql/index.js.map +1 -0
  132. package/dist/graphql/services/index.d.ts +24 -0
  133. package/dist/graphql/services/index.js +5 -0
  134. package/dist/graphql/services/index.js.map +1 -0
  135. package/dist/graphql-BAVrUgBF.d.ts +22 -0
  136. package/dist/i18n/index.d.ts +2 -0
  137. package/dist/i18n/index.js +5 -0
  138. package/dist/i18n/index.js.map +1 -0
  139. package/dist/i18n-DA6IPnYy.d.ts +101 -0
  140. package/dist/index-4gKQKZ2B.d.ts +71 -0
  141. package/dist/index-B18rrFru.d.ts +42 -0
  142. package/dist/index-B70b5mYS.d.ts +33 -0
  143. package/dist/index-BMq3lFjj.d.ts +247 -0
  144. package/dist/index-BODgvRtL.d.ts +316 -0
  145. package/dist/index-BS2idbnr.d.ts +874 -0
  146. package/dist/index-BV3G48cH.d.ts +124 -0
  147. package/dist/index-CHbVw5M7.d.ts +73 -0
  148. package/dist/index-Cq_xNjcv.d.ts +602 -0
  149. package/dist/index-CrQgidpx.d.ts +77 -0
  150. package/dist/index-CyVEg86m.d.ts +309 -0
  151. package/dist/index-DOcBnmMe.d.ts +166 -0
  152. package/dist/index-DSOpj8DI.d.ts +17 -0
  153. package/dist/index-DW9q22GH.d.ts +75 -0
  154. package/dist/index-DlFDFyWD.d.ts +55 -0
  155. package/dist/index-DoK0bjhH.d.ts +607 -0
  156. package/dist/index-Dtf6FBaD.d.ts +199 -0
  157. package/dist/index-KVWGHMbS.d.ts +415 -0
  158. package/dist/index-PaojfSdd.d.ts +71 -0
  159. package/dist/index-RU_M5c74.d.ts +163 -0
  160. package/dist/index-UhkH2eaB.d.ts +192 -0
  161. package/dist/index-e_18DzAg.d.ts +18 -0
  162. package/dist/index-jOuh_TKn.d.ts +59 -0
  163. package/dist/index.d.ts +584 -0
  164. package/dist/index.js +2626 -0
  165. package/dist/index.js.map +1 -0
  166. package/dist/init/index.d.ts +2 -0
  167. package/dist/init/index.js +12 -0
  168. package/dist/init/index.js.map +1 -0
  169. package/dist/instrumentation/index.d.ts +3 -0
  170. package/dist/instrumentation/index.js +5 -0
  171. package/dist/instrumentation/index.js.map +1 -0
  172. package/dist/layer/index.d.ts +2 -0
  173. package/dist/layer/index.js +6 -0
  174. package/dist/layer/index.js.map +1 -0
  175. package/dist/layer-DDip18KY.d.ts +67 -0
  176. package/dist/logger/index.d.ts +2 -0
  177. package/dist/logger/index.js +4 -0
  178. package/dist/logger/index.js.map +1 -0
  179. package/dist/middleware/index.d.ts +3 -0
  180. package/dist/middleware/index.js +5 -0
  181. package/dist/middleware/index.js.map +1 -0
  182. package/dist/notifications/index.d.ts +4 -0
  183. package/dist/notifications/index.js +7 -0
  184. package/dist/notifications/index.js.map +1 -0
  185. package/dist/observability/index.d.ts +3 -0
  186. package/dist/observability/index.js +5 -0
  187. package/dist/observability/index.js.map +1 -0
  188. package/dist/pino-logger-RYLGXPHZ.js +5 -0
  189. package/dist/pino-logger-RYLGXPHZ.js.map +1 -0
  190. package/dist/prisma/generator/index.d.ts +1 -0
  191. package/dist/prisma/generator/index.js +228 -0
  192. package/dist/prisma/generator/index.js.map +1 -0
  193. package/dist/prisma/index.d.ts +5 -0
  194. package/dist/prisma/index.js +12 -0
  195. package/dist/prisma/index.js.map +1 -0
  196. package/dist/prisma-extension-krXnYnrN.d.ts +30 -0
  197. package/dist/rbac/index.d.ts +116 -0
  198. package/dist/rbac/index.js +7 -0
  199. package/dist/rbac/index.js.map +1 -0
  200. package/dist/sdk-THO3IWEE.js +136 -0
  201. package/dist/sdk-THO3IWEE.js.map +1 -0
  202. package/dist/server/index.d.ts +359 -0
  203. package/dist/server/index.js +884 -0
  204. package/dist/server/index.js.map +1 -0
  205. package/dist/telemetry/index.d.ts +83 -0
  206. package/dist/telemetry/index.js +209 -0
  207. package/dist/telemetry/index.js.map +1 -0
  208. package/dist/temporal/index.d.ts +148 -0
  209. package/dist/temporal/index.js +6 -0
  210. package/dist/temporal/index.js.map +1 -0
  211. package/dist/tracker/index.d.ts +5 -0
  212. package/dist/tracker/index.js +9 -0
  213. package/dist/tracker/index.js.map +1 -0
  214. package/dist/types-Bo2wkjSP.d.ts +35 -0
  215. package/dist/utils/index.d.ts +1 -0
  216. package/dist/utils/index.js +4 -0
  217. package/dist/utils/index.js.map +1 -0
  218. package/dist/workspace-guard-LHBNK4TG.js +5 -0
  219. package/dist/workspace-guard-LHBNK4TG.js.map +1 -0
  220. package/package.json +241 -0
@@ -0,0 +1,764 @@
1
+ import { logger } from './chunk-CBZNP6RF.js';
2
+ import { __export, __name } from './chunk-XE4OXN2W.js';
3
+ import { readdir, readFile, stat } from 'fs/promises';
4
+ import { join, extname, basename, resolve, relative } from 'path';
5
+
6
+ // src/i18n/index.ts
7
+ var i18n_exports = {};
8
+ __export(i18n_exports, {
9
+ DEFAULT_I18N_CONFIG: () => DEFAULT_I18N_CONFIG,
10
+ I18n: () => I18n,
11
+ Locales: () => Locales,
12
+ RTL_LANGUAGES: () => RTL_LANGUAGES,
13
+ clearTranslationCache: () => clearTranslationCache,
14
+ createI18n: () => createI18n,
15
+ createTranslator: () => createTranslator,
16
+ discoverLocales: () => discoverLocales,
17
+ extractLocaleFromRequest: () => extractLocaleFromRequest,
18
+ findBestMatch: () => findBestMatch,
19
+ flattenDictionary: () => flattenDictionary,
20
+ getCachedTranslations: () => getCachedTranslations,
21
+ getI18n: () => getI18n,
22
+ getLanguage: () => getLanguage,
23
+ getLanguageFromLocale: () => getLanguageFromLocale,
24
+ getLocale: () => getLocale,
25
+ getRegionFromLocale: () => getRegionFromLocale,
26
+ getTextDirection: () => getTextDirection,
27
+ hasI18n: () => hasI18n,
28
+ initializeI18n: () => initializeI18n,
29
+ loadTranslationFile: () => loadTranslationFile,
30
+ loadTranslationsForLocale: () => loadTranslationsForLocale,
31
+ normalizeLocale: () => normalizeLocale,
32
+ parseAcceptLanguage: () => parseAcceptLanguage,
33
+ parseLocaleString: () => parseLocaleString,
34
+ preloadAllTranslations: () => preloadAllTranslations,
35
+ setCachedTranslations: () => setCachedTranslations,
36
+ t: () => t
37
+ });
38
+
39
+ // src/i18n/types.ts
40
+ var RTL_LANGUAGES = [
41
+ "ar",
42
+ "he"
43
+ ];
44
+ function getTextDirection(language) {
45
+ return RTL_LANGUAGES.includes(language) ? "rtl" : "ltr";
46
+ }
47
+ __name(getTextDirection, "getTextDirection");
48
+
49
+ // src/i18n/parser.ts
50
+ function parseLocaleString(localeStr) {
51
+ const trimmed = localeStr.trim();
52
+ if (!trimmed || trimmed === "*") {
53
+ return null;
54
+ }
55
+ const [localePart, ...params] = trimmed.split(";");
56
+ let quality = 1;
57
+ for (const param of params) {
58
+ const [key, value] = param.trim().split("=");
59
+ if (key?.toLowerCase() === "q" && value) {
60
+ const parsed = parseFloat(value);
61
+ if (!isNaN(parsed) && parsed >= 0 && parsed <= 1) {
62
+ quality = parsed;
63
+ }
64
+ }
65
+ }
66
+ const locale = localePart?.trim();
67
+ if (!locale) {
68
+ return null;
69
+ }
70
+ const parts = locale.split("-");
71
+ const language = parts[0]?.toLowerCase();
72
+ const region = parts[1]?.toUpperCase();
73
+ const normalizedLocale = region ? `${language}-${region}` : language;
74
+ return {
75
+ locale: normalizedLocale,
76
+ language,
77
+ region,
78
+ quality
79
+ };
80
+ }
81
+ __name(parseLocaleString, "parseLocaleString");
82
+ function parseAcceptLanguage(header) {
83
+ if (!header || header.trim() === "") {
84
+ return [];
85
+ }
86
+ const locales = [];
87
+ const parts = header.split(",");
88
+ for (const part of parts) {
89
+ const parsed = parseLocaleString(part);
90
+ if (parsed) {
91
+ locales.push(parsed);
92
+ }
93
+ }
94
+ locales.sort((a, b) => b.quality - a.quality);
95
+ return locales;
96
+ }
97
+ __name(parseAcceptLanguage, "parseAcceptLanguage");
98
+ function extractLocaleFromRequest(request, defaultLocale = "en-US") {
99
+ const explicitLocale = request.headers.get("x-locale") || request.headers.get("x-language");
100
+ if (explicitLocale) {
101
+ const parsed = parseLocaleString(explicitLocale);
102
+ if (parsed) {
103
+ return parsed;
104
+ }
105
+ }
106
+ const acceptLanguage = request.headers.get("accept-language");
107
+ const parsedLocales = parseAcceptLanguage(acceptLanguage);
108
+ if (parsedLocales.length > 0) {
109
+ return parsedLocales[0];
110
+ }
111
+ const [language, region] = defaultLocale.split("-");
112
+ return {
113
+ locale: defaultLocale,
114
+ language,
115
+ region,
116
+ quality: 1
117
+ };
118
+ }
119
+ __name(extractLocaleFromRequest, "extractLocaleFromRequest");
120
+ function normalizeLocale(locale) {
121
+ const parts = locale.trim().split(/[-_]/);
122
+ const language = parts[0]?.toLowerCase();
123
+ const region = parts[1]?.toUpperCase();
124
+ if (region) {
125
+ return `${language}-${region}`;
126
+ }
127
+ return language;
128
+ }
129
+ __name(normalizeLocale, "normalizeLocale");
130
+ function getLanguageFromLocale(locale) {
131
+ return locale.split("-")[0];
132
+ }
133
+ __name(getLanguageFromLocale, "getLanguageFromLocale");
134
+ function getRegionFromLocale(locale) {
135
+ const parts = locale.split("-");
136
+ return parts[1];
137
+ }
138
+ __name(getRegionFromLocale, "getRegionFromLocale");
139
+ function findBestMatch(requested, available, defaultLocale) {
140
+ const availableSet = new Set(available.map((l) => l.toLowerCase()));
141
+ for (const req of requested) {
142
+ if (availableSet.has(req.locale.toLowerCase())) {
143
+ return available.find((l) => l.toLowerCase() === req.locale.toLowerCase()) || req.locale;
144
+ }
145
+ if (availableSet.has(req.language.toLowerCase())) {
146
+ return available.find((l) => l.toLowerCase() === req.language.toLowerCase()) || req.language;
147
+ }
148
+ const langMatch = available.find((l) => getLanguageFromLocale(l).toLowerCase() === req.language.toLowerCase());
149
+ if (langMatch) {
150
+ return langMatch;
151
+ }
152
+ }
153
+ return defaultLocale;
154
+ }
155
+ __name(findBestMatch, "findBestMatch");
156
+
157
+ // src/i18n/loader.ts
158
+ var translationCache = /* @__PURE__ */ new Map();
159
+ function validateFilePath(filePath, baseDir) {
160
+ const resolvedBase = resolve(baseDir);
161
+ const resolvedPath = resolve(filePath);
162
+ const relativePath = relative(resolvedBase, resolvedPath);
163
+ if (relativePath.startsWith("..") || resolve(relativePath) === relativePath) {
164
+ throw new Error(`Invalid file path: ${filePath} is outside base directory ${baseDir}`);
165
+ }
166
+ return resolvedPath;
167
+ }
168
+ __name(validateFilePath, "validateFilePath");
169
+ async function safeReadFile(filePath, baseDir) {
170
+ const validatedPath = validateFilePath(filePath, baseDir);
171
+ return readFile(validatedPath, "utf-8");
172
+ }
173
+ __name(safeReadFile, "safeReadFile");
174
+ async function safeStat(filePath, baseDir) {
175
+ const validatedPath = validateFilePath(filePath, baseDir);
176
+ return stat(validatedPath).catch(() => null);
177
+ }
178
+ __name(safeStat, "safeStat");
179
+ async function safeReaddir(dirPath, baseDir) {
180
+ const validatedPath = validateFilePath(dirPath, baseDir);
181
+ return readdir(validatedPath);
182
+ }
183
+ __name(safeReaddir, "safeReaddir");
184
+ function flattenDictionary(obj, prefix = "") {
185
+ const result = {};
186
+ for (const [key, value] of Object.entries(obj)) {
187
+ const fullKey = prefix ? `${prefix}.${key}` : key;
188
+ if (typeof value === "string") {
189
+ result[fullKey] = value;
190
+ } else if (value !== null && typeof value === "object") {
191
+ Object.assign(result, flattenDictionary(value, fullKey));
192
+ }
193
+ }
194
+ return result;
195
+ }
196
+ __name(flattenDictionary, "flattenDictionary");
197
+ async function loadTranslationFile(filePath, baseDir) {
198
+ try {
199
+ const content = await safeReadFile(filePath, baseDir);
200
+ const data = JSON.parse(content);
201
+ return data;
202
+ } catch (error) {
203
+ logger.error(`[I18n] Failed to load translation file: ${filePath}`, error);
204
+ return {};
205
+ }
206
+ }
207
+ __name(loadTranslationFile, "loadTranslationFile");
208
+ function getCacheKey(namespace, locale) {
209
+ return namespace ? `${namespace}:${locale}` : locale;
210
+ }
211
+ __name(getCacheKey, "getCacheKey");
212
+ async function loadTranslationsForLocale(config, locale) {
213
+ const cacheKey = getCacheKey(config.namespace, locale);
214
+ if (config.enableCache !== false && translationCache.has(cacheKey)) {
215
+ return translationCache.get(cacheKey);
216
+ }
217
+ const normalizedLocale = normalizeLocale(locale);
218
+ const language = getLanguageFromLocale(normalizedLocale);
219
+ const result = {};
220
+ const pathsToTry = [
221
+ // Most specific: full locale
222
+ join(config.localesPath, `${normalizedLocale}.json`),
223
+ // Directory format
224
+ join(config.localesPath, normalizedLocale),
225
+ // Language only fallback
226
+ join(config.localesPath, `${language}.json`),
227
+ // Language directory
228
+ join(config.localesPath, language)
229
+ ];
230
+ for (const path of pathsToTry) {
231
+ try {
232
+ const stats = await safeStat(path, config.localesPath);
233
+ if (!stats) continue;
234
+ if (stats.isFile() && path.endsWith(".json")) {
235
+ const translations = await loadTranslationFile(path, config.localesPath);
236
+ const flattened = flattenDictionary(translations);
237
+ Object.assign(result, flattened);
238
+ logger.debug(`[I18n] Loaded translations from ${path}`);
239
+ break;
240
+ } else if (stats.isDirectory()) {
241
+ const files = await safeReaddir(path, config.localesPath);
242
+ for (const file of files) {
243
+ if (extname(file) === ".json") {
244
+ const namespace = basename(file, ".json");
245
+ const filePath = join(path, file);
246
+ const translations = await loadTranslationFile(filePath, config.localesPath);
247
+ const flattened = flattenDictionary(translations, namespace);
248
+ Object.assign(result, flattened);
249
+ logger.debug(`[I18n] Loaded namespace ${namespace} from ${filePath}`);
250
+ }
251
+ }
252
+ break;
253
+ }
254
+ } catch {
255
+ }
256
+ }
257
+ if (Object.keys(result).length === 0 && config.fallbackLocale && config.fallbackLocale !== locale) {
258
+ logger.warn(`[I18n] No translations found for ${locale}, trying fallback ${config.fallbackLocale}`);
259
+ const fallbackTranslations = await loadTranslationsForLocale({
260
+ ...config,
261
+ fallbackLocale: void 0
262
+ }, config.fallbackLocale);
263
+ Object.assign(result, fallbackTranslations);
264
+ }
265
+ if (config.enableCache !== false) {
266
+ translationCache.set(cacheKey, result);
267
+ }
268
+ return result;
269
+ }
270
+ __name(loadTranslationsForLocale, "loadTranslationsForLocale");
271
+ async function discoverLocales(localesPath) {
272
+ const locales = [];
273
+ try {
274
+ const validatedBasePath = resolve(localesPath);
275
+ const entries = await readdir(validatedBasePath);
276
+ for (const entry of entries) {
277
+ const entryPath = join(validatedBasePath, entry);
278
+ const stats = await safeStat(entryPath, validatedBasePath);
279
+ if (!stats) continue;
280
+ if (stats.isFile() && entry.endsWith(".json")) {
281
+ const locale = basename(entry, ".json");
282
+ locales.push(normalizeLocale(locale));
283
+ } else if (stats.isDirectory()) {
284
+ locales.push(normalizeLocale(entry));
285
+ }
286
+ }
287
+ } catch (error) {
288
+ logger.error(`[I18n] Failed to discover locales in ${localesPath}`, error);
289
+ }
290
+ return locales;
291
+ }
292
+ __name(discoverLocales, "discoverLocales");
293
+ async function preloadAllTranslations(config) {
294
+ const locales = config.supportedLocales || await discoverLocales(config.localesPath);
295
+ logger.info(`[I18n] Preloading translations for ${locales.length} locales...`);
296
+ await Promise.all(locales.map(async (locale) => {
297
+ try {
298
+ await loadTranslationsForLocale(config, locale);
299
+ } catch (error) {
300
+ logger.error(`[I18n] Failed to preload locale ${locale}`, error);
301
+ }
302
+ }));
303
+ logger.info(`[I18n] Preloaded translations for: ${locales.join(", ")}`);
304
+ }
305
+ __name(preloadAllTranslations, "preloadAllTranslations");
306
+ function clearTranslationCache(namespace) {
307
+ if (namespace) {
308
+ for (const key of translationCache.keys()) {
309
+ if (key.startsWith(`${namespace}:`)) {
310
+ translationCache.delete(key);
311
+ }
312
+ }
313
+ } else {
314
+ translationCache.clear();
315
+ }
316
+ }
317
+ __name(clearTranslationCache, "clearTranslationCache");
318
+ function getCachedTranslations(namespace, locale) {
319
+ return translationCache.get(getCacheKey(namespace, locale));
320
+ }
321
+ __name(getCachedTranslations, "getCachedTranslations");
322
+ function setCachedTranslations(namespace, locale, translations) {
323
+ translationCache.set(getCacheKey(namespace, locale), translations);
324
+ }
325
+ __name(setCachedTranslations, "setCachedTranslations");
326
+
327
+ // src/i18n/i18n.ts
328
+ function getEnglishPluralCategory(absCount) {
329
+ if (absCount === 1) return "one";
330
+ return "other";
331
+ }
332
+ __name(getEnglishPluralCategory, "getEnglishPluralCategory");
333
+ function getFrenchPluralCategory(absCount) {
334
+ if (absCount === 0 || absCount === 1) return "one";
335
+ return "other";
336
+ }
337
+ __name(getFrenchPluralCategory, "getFrenchPluralCategory");
338
+ function getSlavicPluralCategory(absCount) {
339
+ const mod10 = absCount % 10;
340
+ const mod100 = absCount % 100;
341
+ if (mod10 === 1 && mod100 !== 11) return "one";
342
+ if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
343
+ if (mod10 === 0 || mod10 >= 5 && mod10 <= 9 || mod100 >= 11 && mod100 <= 14) return "many";
344
+ return "other";
345
+ }
346
+ __name(getSlavicPluralCategory, "getSlavicPluralCategory");
347
+ function getArabicPluralCategory(absCount) {
348
+ if (absCount === 0) return "zero";
349
+ if (absCount === 1) return "one";
350
+ if (absCount === 2) return "two";
351
+ const mod100 = absCount % 100;
352
+ if (mod100 >= 3 && mod100 <= 10) return "few";
353
+ if (mod100 >= 11 && mod100 <= 99) return "many";
354
+ return "other";
355
+ }
356
+ __name(getArabicPluralCategory, "getArabicPluralCategory");
357
+ function getPolishCzechPluralCategory(absCount) {
358
+ const mod10 = absCount % 10;
359
+ const mod100 = absCount % 100;
360
+ if (absCount === 1) return "one";
361
+ if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return "few";
362
+ return "many";
363
+ }
364
+ __name(getPolishCzechPluralCategory, "getPolishCzechPluralCategory");
365
+ function getRomanianPluralCategory(absCount) {
366
+ if (absCount === 1) return "one";
367
+ const mod100 = absCount % 100;
368
+ if (absCount === 0 || mod100 >= 1 && mod100 <= 19) return "few";
369
+ return "other";
370
+ }
371
+ __name(getRomanianPluralCategory, "getRomanianPluralCategory");
372
+ function getHebrewPluralCategory(absCount) {
373
+ if (absCount === 1) return "one";
374
+ if (absCount === 2) return "two";
375
+ return "other";
376
+ }
377
+ __name(getHebrewPluralCategory, "getHebrewPluralCategory");
378
+ function getPluralCategory(language, count) {
379
+ const absCount = Math.abs(count);
380
+ const englishLanguages = [
381
+ "en",
382
+ "de",
383
+ "es",
384
+ "it",
385
+ "nl",
386
+ "sv",
387
+ "da",
388
+ "nb",
389
+ "fi",
390
+ "pt",
391
+ "el",
392
+ "hu",
393
+ "tr",
394
+ "id",
395
+ "ms",
396
+ "th",
397
+ "vi",
398
+ "ko",
399
+ "zh",
400
+ "ja"
401
+ ];
402
+ if (englishLanguages.includes(language)) {
403
+ return getEnglishPluralCategory(absCount);
404
+ }
405
+ if (language === "fr") {
406
+ return getFrenchPluralCategory(absCount);
407
+ }
408
+ if (language === "ru" || language === "uk") {
409
+ return getSlavicPluralCategory(absCount);
410
+ }
411
+ if (language === "ar") {
412
+ return getArabicPluralCategory(absCount);
413
+ }
414
+ if (language === "pl" || language === "cs") {
415
+ return getPolishCzechPluralCategory(absCount);
416
+ }
417
+ if (language === "ro") {
418
+ return getRomanianPluralCategory(absCount);
419
+ }
420
+ if (language === "he") {
421
+ return getHebrewPluralCategory(absCount);
422
+ }
423
+ return getEnglishPluralCategory(absCount);
424
+ }
425
+ __name(getPluralCategory, "getPluralCategory");
426
+ function interpolate(text, variables) {
427
+ if (!variables || !text) {
428
+ return text;
429
+ }
430
+ return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, key) => {
431
+ const value = variables[key.trim()];
432
+ if (value !== void 0) {
433
+ return String(value);
434
+ }
435
+ return match;
436
+ });
437
+ }
438
+ __name(interpolate, "interpolate");
439
+ var I18n = class {
440
+ static {
441
+ __name(this, "I18n");
442
+ }
443
+ config;
444
+ currentLocale;
445
+ supportedLocales = [];
446
+ initialized = false;
447
+ constructor(config) {
448
+ this.config = {
449
+ ...config,
450
+ fallbackLocale: config.fallbackLocale || "en-US",
451
+ enableCache: config.enableCache !== false,
452
+ returnKeyOnMissing: config.returnKeyOnMissing !== false,
453
+ logMissing: config.logMissing !== false
454
+ };
455
+ this.currentLocale = normalizeLocale(config.defaultLocale);
456
+ }
457
+ /**
458
+ * Initialize the i18n instance
459
+ * Discovers available locales and optionally preloads translations
460
+ */
461
+ async initialize() {
462
+ if (this.initialized) return;
463
+ if (this.config.supportedLocales && this.config.supportedLocales.length > 0) {
464
+ this.supportedLocales = this.config.supportedLocales;
465
+ } else {
466
+ this.supportedLocales = await discoverLocales(this.config.localesPath);
467
+ }
468
+ if (!this.config.lazyLoad) {
469
+ await preloadAllTranslations(this.config);
470
+ }
471
+ this.initialized = true;
472
+ logger.info(`[I18n] Initialized with ${this.supportedLocales.length} locales, default: ${this.currentLocale}`);
473
+ }
474
+ /**
475
+ * Get current locale
476
+ */
477
+ getLocale() {
478
+ return this.currentLocale;
479
+ }
480
+ /**
481
+ * Set current locale
482
+ */
483
+ setLocale(locale) {
484
+ this.currentLocale = normalizeLocale(locale);
485
+ }
486
+ /**
487
+ * Get supported locales
488
+ */
489
+ getSupportedLocales() {
490
+ return [
491
+ ...this.supportedLocales
492
+ ];
493
+ }
494
+ /**
495
+ * Check if a locale is supported
496
+ */
497
+ isSupported(locale) {
498
+ const normalized = normalizeLocale(locale);
499
+ const language = getLanguageFromLocale(normalized);
500
+ return this.supportedLocales.some((l) => {
501
+ const supportedNorm = normalizeLocale(l);
502
+ return supportedNorm === normalized || getLanguageFromLocale(supportedNorm) === language;
503
+ });
504
+ }
505
+ /**
506
+ * Load translations for a specific locale
507
+ */
508
+ async loadLocale(locale) {
509
+ await loadTranslationsForLocale(this.config, locale);
510
+ }
511
+ /**
512
+ * Get all translations for a locale
513
+ */
514
+ getTranslations(locale) {
515
+ return getCachedTranslations(this.config.namespace, locale);
516
+ }
517
+ /**
518
+ * Translate a key
519
+ */
520
+ t = /* @__PURE__ */ __name((key, variables, defaultValue) => {
521
+ return this.translate(this.currentLocale, key, variables, defaultValue);
522
+ }, "t");
523
+ /**
524
+ * Translate with pluralization
525
+ */
526
+ tp = /* @__PURE__ */ __name((key, count, variables) => {
527
+ return this.translatePlural(this.currentLocale, key, count, variables);
528
+ }, "tp");
529
+ /**
530
+ * Internal translate method
531
+ */
532
+ translate(locale, key, variables, defaultValue) {
533
+ const translations = getCachedTranslations(this.config.namespace, locale);
534
+ let text = translations?.[key];
535
+ if (!text && this.config.fallbackLocale && locale !== this.config.fallbackLocale) {
536
+ const fallbackTranslations = getCachedTranslations(this.config.namespace, this.config.fallbackLocale);
537
+ text = fallbackTranslations?.[key];
538
+ }
539
+ if (!text) {
540
+ const language = getLanguageFromLocale(locale);
541
+ if (language !== locale) {
542
+ const langTranslations = getCachedTranslations(this.config.namespace, language);
543
+ text = langTranslations?.[key];
544
+ }
545
+ }
546
+ if (!text) {
547
+ if (this.config.logMissing) {
548
+ logger.warn(`[I18n] Missing translation for key: ${key} in locale: ${locale}`);
549
+ }
550
+ return defaultValue ?? (this.config.returnKeyOnMissing ? key : "");
551
+ }
552
+ return interpolate(text, variables);
553
+ }
554
+ /**
555
+ * Internal translate with pluralization
556
+ */
557
+ translatePlural(locale, key, count, variables) {
558
+ const language = getLanguageFromLocale(locale);
559
+ const category = getPluralCategory(language, count);
560
+ const pluralKey = `${key}.${category}`;
561
+ let text = this.translate(locale, pluralKey, void 0, "");
562
+ if (!text && category !== "other") {
563
+ text = this.translate(locale, `${key}.other`, void 0, "");
564
+ }
565
+ if (!text) {
566
+ text = this.translate(locale, key, void 0, key);
567
+ }
568
+ return interpolate(text, {
569
+ ...variables,
570
+ count
571
+ });
572
+ }
573
+ /**
574
+ * Create an i18n context for a specific locale
575
+ */
576
+ createContext(locale) {
577
+ const normalizedLocale = normalizeLocale(locale);
578
+ const language = getLanguageFromLocale(normalizedLocale);
579
+ const region = getRegionFromLocale(normalizedLocale);
580
+ const t2 = /* @__PURE__ */ __name((key, variables, defaultValue) => {
581
+ return this.translate(normalizedLocale, key, variables, defaultValue);
582
+ }, "t");
583
+ const tp = /* @__PURE__ */ __name((key, count, variables) => {
584
+ return this.translatePlural(normalizedLocale, key, count, variables);
585
+ }, "tp");
586
+ const formatNumber = /* @__PURE__ */ __name((value, options) => {
587
+ return new Intl.NumberFormat(normalizedLocale, options).format(value);
588
+ }, "formatNumber");
589
+ const formatCurrency = /* @__PURE__ */ __name((value, currency) => {
590
+ return new Intl.NumberFormat(normalizedLocale, {
591
+ style: "currency",
592
+ currency
593
+ }).format(value);
594
+ }, "formatCurrency");
595
+ const formatDate = /* @__PURE__ */ __name((date, options) => {
596
+ const dateObj = typeof date === "string" ? new Date(date) : date;
597
+ return new Intl.DateTimeFormat(normalizedLocale, options).format(dateObj);
598
+ }, "formatDate");
599
+ const formatRelativeTime = /* @__PURE__ */ __name((value, unit) => {
600
+ return new Intl.RelativeTimeFormat(normalizedLocale, {
601
+ numeric: "auto"
602
+ }).format(value, unit);
603
+ }, "formatRelativeTime");
604
+ return {
605
+ locale: normalizedLocale,
606
+ language,
607
+ region,
608
+ t: t2,
609
+ tp,
610
+ formatNumber,
611
+ formatCurrency,
612
+ formatDate,
613
+ formatRelativeTime
614
+ };
615
+ }
616
+ /**
617
+ * Create context from a request
618
+ */
619
+ createContextFromRequest(request) {
620
+ const parsed = extractLocaleFromRequest(request, this.config.defaultLocale);
621
+ const bestMatch = findBestMatch([
622
+ parsed
623
+ ], this.supportedLocales, this.config.defaultLocale);
624
+ return this.createContext(bestMatch);
625
+ }
626
+ /**
627
+ * Get language metadata
628
+ */
629
+ getLanguageInfo(locale) {
630
+ const language = getLanguageFromLocale(locale);
631
+ const region = getRegionFromLocale(locale);
632
+ const direction = getTextDirection(language);
633
+ return {
634
+ code: language,
635
+ direction,
636
+ locale,
637
+ region
638
+ };
639
+ }
640
+ };
641
+ var globalI18n = null;
642
+ async function initializeI18n(config) {
643
+ globalI18n = new I18n(config);
644
+ await globalI18n.initialize();
645
+ return globalI18n;
646
+ }
647
+ __name(initializeI18n, "initializeI18n");
648
+ function getI18n() {
649
+ return globalI18n;
650
+ }
651
+ __name(getI18n, "getI18n");
652
+ function createI18n(config) {
653
+ return new I18n(config);
654
+ }
655
+ __name(createI18n, "createI18n");
656
+
657
+ // src/i18n/helpers.ts
658
+ function interpolateVariables(text, variables) {
659
+ if (!variables) return text;
660
+ return text.replace(/\{\{(\w+)\}\}/g, (match, key) => {
661
+ const value = variables[key];
662
+ return value !== void 0 ? String(value) : match;
663
+ });
664
+ }
665
+ __name(interpolateVariables, "interpolateVariables");
666
+ function t(ctx, key, defaultMessage, variables) {
667
+ if (!ctx.i18n?.t) {
668
+ return interpolateVariables(defaultMessage, variables);
669
+ }
670
+ const translated = ctx.i18n.t(key, variables, defaultMessage);
671
+ if (translated === key) {
672
+ return interpolateVariables(defaultMessage, variables);
673
+ }
674
+ return translated;
675
+ }
676
+ __name(t, "t");
677
+ function createTranslator(ctx) {
678
+ return (key, defaultMessage, variables) => {
679
+ return t(ctx, key, defaultMessage, variables);
680
+ };
681
+ }
682
+ __name(createTranslator, "createTranslator");
683
+ function hasI18n(ctx) {
684
+ return ctx.i18n?.t !== void 0;
685
+ }
686
+ __name(hasI18n, "hasI18n");
687
+ function getLocale(ctx, defaultLocale = "en-US") {
688
+ return ctx.i18n?.locale ?? defaultLocale;
689
+ }
690
+ __name(getLocale, "getLocale");
691
+ function getLanguage(ctx, defaultLanguage = "en") {
692
+ return ctx.i18n?.language ?? defaultLanguage;
693
+ }
694
+ __name(getLanguage, "getLanguage");
695
+
696
+ // src/i18n/index.ts
697
+ var Locales = {
698
+ // English
699
+ EN_US: "en-US",
700
+ EN_GB: "en-GB",
701
+ EN_AU: "en-AU",
702
+ EN_CA: "en-CA",
703
+ EN_IN: "en-IN",
704
+ // Spanish
705
+ ES_ES: "es-ES",
706
+ ES_MX: "es-MX",
707
+ // French
708
+ FR_FR: "fr-FR",
709
+ FR_CA: "fr-CA",
710
+ // German
711
+ DE_DE: "de-DE",
712
+ DE_AT: "de-AT",
713
+ DE_CH: "de-CH",
714
+ // Italian
715
+ IT_IT: "it-IT",
716
+ // Portuguese
717
+ PT_PT: "pt-PT",
718
+ PT_BR: "pt-BR",
719
+ // Russian
720
+ RU_RU: "ru-RU",
721
+ // Chinese
722
+ ZH_CN: "zh-CN",
723
+ ZH_TW: "zh-TW",
724
+ ZH_HK: "zh-HK",
725
+ // Japanese
726
+ JA_JP: "ja-JP",
727
+ // Korean
728
+ KO_KR: "ko-KR",
729
+ // Arabic
730
+ AR_SA: "ar-SA",
731
+ AR_AE: "ar-AE",
732
+ // Hindi
733
+ HI_IN: "hi-IN",
734
+ // Tamil
735
+ TA_IN: "ta-IN",
736
+ // Dutch
737
+ NL_NL: "nl-NL",
738
+ // Polish
739
+ PL_PL: "pl-PL",
740
+ // Turkish
741
+ TR_TR: "tr-TR",
742
+ // Vietnamese
743
+ VI_VN: "vi-VN",
744
+ // Thai
745
+ TH_TH: "th-TH",
746
+ // Indonesian
747
+ ID_ID: "id-ID",
748
+ // Hebrew
749
+ HE_IL: "he-IL",
750
+ // Ukrainian
751
+ UK_UA: "uk-UA"
752
+ };
753
+ var DEFAULT_I18N_CONFIG = {
754
+ defaultLocale: "en-US",
755
+ fallbackLocale: "en-US",
756
+ enableCache: true,
757
+ lazyLoad: false,
758
+ logMissing: true,
759
+ returnKeyOnMissing: true
760
+ };
761
+
762
+ export { DEFAULT_I18N_CONFIG, I18n, Locales, RTL_LANGUAGES, clearTranslationCache, createI18n, createTranslator, discoverLocales, extractLocaleFromRequest, findBestMatch, flattenDictionary, getCachedTranslations, getI18n, getLanguage, getLanguageFromLocale, getLocale, getRegionFromLocale, getTextDirection, hasI18n, i18n_exports, initializeI18n, loadTranslationFile, loadTranslationsForLocale, normalizeLocale, parseAcceptLanguage, parseLocaleString, preloadAllTranslations, setCachedTranslations, t };
763
+ //# sourceMappingURL=chunk-IYE2NTRX.js.map
764
+ //# sourceMappingURL=chunk-IYE2NTRX.js.map