@digitaldefiance/i18n-lib 1.3.12 → 1.3.13

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 (148) hide show
  1. package/README.md +4 -0
  2. package/package.json +12 -27
  3. package/src/active-context.ts +30 -0
  4. package/src/component-definition.ts +11 -0
  5. package/src/component-registration.ts +13 -0
  6. package/src/component-registry.ts +392 -0
  7. package/src/context-error-type.ts +3 -0
  8. package/src/context-error.ts +16 -0
  9. package/src/context-manager.ts +71 -0
  10. package/src/context.ts +90 -0
  11. package/src/core-i18n.ts +609 -0
  12. package/src/core-string-key.ts +49 -0
  13. package/src/create-translation-adapter.ts +47 -0
  14. package/src/currency-code.ts +35 -0
  15. package/{dist/currency-format.d.ts → src/currency-format.ts} +5 -4
  16. package/src/currency.ts +52 -0
  17. package/src/default-config.ts +199 -0
  18. package/src/enum-registry.ts +138 -0
  19. package/src/global-active-context.ts +255 -0
  20. package/src/handleable.ts +79 -0
  21. package/src/i-global-active-context.ts +59 -0
  22. package/src/i-handleable-error-options.ts +6 -0
  23. package/src/i-handleable.ts +5 -0
  24. package/src/i18n-config.ts +29 -0
  25. package/{dist/i18n-context.d.ts → src/i18n-context.ts} +7 -6
  26. package/src/i18n-engine.ts +491 -0
  27. package/{dist/index.d.ts → src/index.ts} +10 -1
  28. package/{dist/language-codes.d.ts → src/language-codes.ts} +23 -11
  29. package/src/language-definition.ts +13 -0
  30. package/src/language-registry.ts +292 -0
  31. package/src/plugin-i18n-engine.ts +520 -0
  32. package/src/plugin-translatable-generic-error.ts +106 -0
  33. package/src/plugin-translatable-handleable-generic.ts +60 -0
  34. package/src/plugin-typed-handleable.ts +77 -0
  35. package/src/registry-config.ts +15 -0
  36. package/src/registry-error-type.ts +12 -0
  37. package/src/registry-error.ts +74 -0
  38. package/src/strict-types.ts +35 -0
  39. package/src/template.ts +63 -0
  40. package/src/timezone.ts +20 -0
  41. package/src/translatable.ts +15 -0
  42. package/src/translation-engine.ts +8 -0
  43. package/src/translation-request.ts +12 -0
  44. package/src/translation-response.ts +8 -0
  45. package/src/typed-error.ts +384 -0
  46. package/src/typed-handleable.ts +70 -0
  47. package/{dist/types.d.ts → src/types.ts} +75 -20
  48. package/src/unified-translator.ts +96 -0
  49. package/src/utils.ts +213 -0
  50. package/src/validation-config.ts +11 -0
  51. package/src/validation-result.ts +12 -0
  52. package/dist/active-context.d.ts +0 -29
  53. package/dist/active-context.js +0 -2
  54. package/dist/component-definition.d.ts +0 -11
  55. package/dist/component-definition.js +0 -2
  56. package/dist/component-registration.d.ts +0 -9
  57. package/dist/component-registration.js +0 -2
  58. package/dist/component-registry.d.ts +0 -68
  59. package/dist/component-registry.js +0 -245
  60. package/dist/context-error-type.d.ts +0 -3
  61. package/dist/context-error-type.js +0 -7
  62. package/dist/context-error.d.ts +0 -6
  63. package/dist/context-error.js +0 -15
  64. package/dist/context-manager.d.ts +0 -33
  65. package/dist/context-manager.js +0 -61
  66. package/dist/context.d.ts +0 -44
  67. package/dist/context.js +0 -69
  68. package/dist/core-i18n.d.ts +0 -62
  69. package/dist/core-i18n.js +0 -477
  70. package/dist/core-string-key.d.ts +0 -42
  71. package/dist/core-string-key.js +0 -50
  72. package/dist/create-translation-adapter.d.ts +0 -20
  73. package/dist/create-translation-adapter.js +0 -36
  74. package/dist/currency-code.d.ts +0 -19
  75. package/dist/currency-code.js +0 -36
  76. package/dist/currency-format.js +0 -2
  77. package/dist/currency.d.ts +0 -11
  78. package/dist/currency.js +0 -48
  79. package/dist/default-config.d.ts +0 -32
  80. package/dist/default-config.js +0 -101
  81. package/dist/enum-registry.d.ts +0 -44
  82. package/dist/enum-registry.js +0 -100
  83. package/dist/global-active-context.d.ts +0 -50
  84. package/dist/global-active-context.js +0 -177
  85. package/dist/handleable.d.ts +0 -13
  86. package/dist/handleable.js +0 -56
  87. package/dist/i-global-active-context.d.ts +0 -22
  88. package/dist/i-global-active-context.js +0 -2
  89. package/dist/i-handleable-error-options.d.ts +0 -6
  90. package/dist/i-handleable-error-options.js +0 -2
  91. package/dist/i-handleable.d.ts +0 -5
  92. package/dist/i-handleable.js +0 -2
  93. package/dist/i18n-config.d.ts +0 -20
  94. package/dist/i18n-config.js +0 -2
  95. package/dist/i18n-context.js +0 -2
  96. package/dist/i18n-engine.d.ts +0 -178
  97. package/dist/i18n-engine.js +0 -338
  98. package/dist/index.js +0 -83
  99. package/dist/language-codes.js +0 -31
  100. package/dist/language-definition.d.ts +0 -13
  101. package/dist/language-definition.js +0 -2
  102. package/dist/language-registry.d.ts +0 -113
  103. package/dist/language-registry.js +0 -216
  104. package/dist/plugin-i18n-engine.d.ts +0 -146
  105. package/dist/plugin-i18n-engine.js +0 -360
  106. package/dist/plugin-translatable-generic-error.d.ts +0 -29
  107. package/dist/plugin-translatable-generic-error.js +0 -66
  108. package/dist/plugin-translatable-handleable-generic.d.ts +0 -28
  109. package/dist/plugin-translatable-handleable-generic.js +0 -40
  110. package/dist/plugin-typed-handleable.d.ts +0 -14
  111. package/dist/plugin-typed-handleable.js +0 -45
  112. package/dist/registry-config.d.ts +0 -14
  113. package/dist/registry-config.js +0 -2
  114. package/dist/registry-error-type.d.ts +0 -12
  115. package/dist/registry-error-type.js +0 -16
  116. package/dist/registry-error.d.ts +0 -18
  117. package/dist/registry-error.js +0 -45
  118. package/dist/strict-types.d.ts +0 -18
  119. package/dist/strict-types.js +0 -17
  120. package/dist/template.d.ts +0 -12
  121. package/dist/template.js +0 -30
  122. package/dist/timezone.d.ts +0 -11
  123. package/dist/timezone.js +0 -22
  124. package/dist/translatable-generic-error.d.ts +0 -29
  125. package/dist/translatable-generic-error.js +0 -66
  126. package/dist/translatable-handleable-generic.d.ts +0 -28
  127. package/dist/translatable-handleable-generic.js +0 -40
  128. package/dist/translatable.d.ts +0 -5
  129. package/dist/translatable.js +0 -11
  130. package/dist/translation-engine.d.ts +0 -8
  131. package/dist/translation-engine.js +0 -2
  132. package/dist/translation-request.d.ts +0 -9
  133. package/dist/translation-request.js +0 -2
  134. package/dist/translation-response.d.ts +0 -8
  135. package/dist/translation-response.js +0 -2
  136. package/dist/typed-error.d.ts +0 -72
  137. package/dist/typed-error.js +0 -251
  138. package/dist/typed-handleable.d.ts +0 -14
  139. package/dist/typed-handleable.js +0 -40
  140. package/dist/types.js +0 -18
  141. package/dist/unified-translator.d.ts +0 -30
  142. package/dist/unified-translator.js +0 -68
  143. package/dist/utils.d.ts +0 -64
  144. package/dist/utils.js +0 -130
  145. package/dist/validation-config.d.ts +0 -11
  146. package/dist/validation-config.js +0 -2
  147. package/dist/validation-result.d.ts +0 -12
  148. package/dist/validation-result.js +0 -2
@@ -1,360 +0,0 @@
1
- "use strict";
2
- /**
3
- * Plugin-based internationalization engine with component and language registration
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PluginI18nEngine = void 0;
7
- const component_registry_1 = require("./component-registry");
8
- const currency_code_1 = require("./currency-code");
9
- const enum_registry_1 = require("./enum-registry");
10
- const global_active_context_1 = require("./global-active-context");
11
- const language_registry_1 = require("./language-registry");
12
- const registry_error_1 = require("./registry-error");
13
- const registry_error_type_1 = require("./registry-error-type");
14
- const timezone_1 = require("./timezone");
15
- /**
16
- * Plugin-based I18n Engine with registration capabilities
17
- */
18
- class PluginI18nEngine {
19
- constructor(initialLanguages, config = {}) {
20
- // Find default language from initialLanguages or use the first one
21
- const defaultLang = initialLanguages.find((l) => l.isDefault) || initialLanguages[0];
22
- if (!defaultLang) {
23
- throw new Error('At least one language must be provided');
24
- }
25
- // Set up configuration with defaults
26
- this.config = {
27
- defaultLanguage: defaultLang.id,
28
- fallbackLanguage: defaultLang.id,
29
- defaultCurrencyCode: new currency_code_1.CurrencyCode('USD'),
30
- timezone: new timezone_1.Timezone('UTC'),
31
- adminTimezone: new timezone_1.Timezone('UTC'),
32
- validation: {
33
- requireCompleteStrings: false,
34
- allowPartialRegistration: true,
35
- fallbackLanguageId: defaultLang.id,
36
- },
37
- ...config,
38
- };
39
- // Register initial languages in static registry (skip if already registered)
40
- for (const lang of initialLanguages) {
41
- if (!language_registry_1.LanguageRegistry.hasLanguage(lang.id)) {
42
- language_registry_1.LanguageRegistry.registerLanguage(lang);
43
- }
44
- }
45
- // Initialize component registry (per-instance)
46
- this.componentRegistry = new component_registry_1.ComponentRegistry(initialLanguages.map((l) => l.id), this.config.validation);
47
- this.enumRegistry = new enum_registry_1.EnumTranslationRegistry(initialLanguages.map((l) => l.id), (key, vars) => this.safeTranslate('core', key, vars));
48
- // Initialize context key for this engine instance
49
- this.contextKey = PluginI18nEngine.DefaultInstanceKey;
50
- // Create or get the global context for this engine
51
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
52
- // Always create/update the context for this engine
53
- globalContext.createContext(this.config.defaultLanguage, this.config.defaultLanguage, this.contextKey);
54
- globalContext.setCurrencyCode(this.config.defaultCurrencyCode, this.contextKey);
55
- globalContext.setUserTimezone(this.config.timezone, this.contextKey);
56
- globalContext.setAdminTimezone(this.config.adminTimezone, this.contextKey);
57
- // Initialize the default template processor for component-based patterns
58
- this.t = (str, language, ...otherVars) => {
59
- // Step 1: Replace component-based patterns like {{componentId.stringKey}}
60
- let result = str.replace(/\{\{([^}]+)\}\}/g, (match, pattern) => {
61
- const parts = pattern.split('.');
62
- if (parts.length === 2) {
63
- const [componentId, stringKey] = parts;
64
- // For template strings, use the first variable object if available
65
- const isTemplate = stringKey.toLowerCase().endsWith('template');
66
- const vars = isTemplate && otherVars.length > 0 ? otherVars[0] : {};
67
- return this.safeTranslate(componentId.trim(), stringKey.trim(), vars, language);
68
- }
69
- return match; // Return original if pattern doesn't match expected format
70
- });
71
- // Step 2: Replace remaining variable patterns like {varName} with merged variables
72
- const allVars = otherVars.reduce((acc, vars) => ({ ...acc, ...vars }), {});
73
- result = result.replace(/\{(\w+)\}/g, (match, varName) => {
74
- return allVars[varName] !== undefined ? String(allVars[varName]) : match;
75
- });
76
- return result;
77
- };
78
- // Auto-register as default instance if none exists
79
- if (!PluginI18nEngine._defaultKey) {
80
- PluginI18nEngine._instances.set(PluginI18nEngine.DefaultInstanceKey, this);
81
- PluginI18nEngine._defaultKey = PluginI18nEngine.DefaultInstanceKey;
82
- }
83
- }
84
- /**
85
- * Create a new instance with a specific key
86
- */
87
- static createInstance(key, initialLanguages, config) {
88
- if (PluginI18nEngine._instances.has(key)) {
89
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.DuplicateComponent, `I18n instance with key '${key}' already exists`, { key });
90
- }
91
- const instance = new PluginI18nEngine(initialLanguages, config);
92
- instance.contextKey = key;
93
- // Create context for this specific instance
94
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
95
- globalContext.createContext(instance.config.defaultLanguage, instance.config.defaultLanguage, key);
96
- globalContext.setCurrencyCode(instance.config.defaultCurrencyCode, key);
97
- globalContext.setUserTimezone(instance.config.timezone, key);
98
- globalContext.setAdminTimezone(instance.config.adminTimezone, key);
99
- PluginI18nEngine._instances.set(key, instance);
100
- if (!PluginI18nEngine._defaultKey) {
101
- PluginI18nEngine._defaultKey = key;
102
- }
103
- return instance;
104
- }
105
- /**
106
- * Get an existing instance by key
107
- */
108
- static getInstance(key) {
109
- const instanceKey = key ||
110
- PluginI18nEngine._defaultKey ||
111
- PluginI18nEngine.DefaultInstanceKey;
112
- const instance = PluginI18nEngine._instances.get(instanceKey);
113
- if (!instance) {
114
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `I18n instance with key '${instanceKey}' not found`, { key: instanceKey });
115
- }
116
- return instance;
117
- }
118
- /**
119
- * Register a new language (updates static registry)
120
- */
121
- registerLanguage(language) {
122
- language_registry_1.LanguageRegistry.registerLanguage(language);
123
- // Update component registry with new language
124
- const newLanguages = language_registry_1.LanguageRegistry.getLanguageIds();
125
- this.componentRegistry.updateRegisteredLanguages(newLanguages);
126
- }
127
- /**
128
- * Register multiple languages (updates static registry)
129
- */
130
- registerLanguages(languages) {
131
- for (const language of languages) {
132
- this.registerLanguage(language);
133
- }
134
- }
135
- /**
136
- * Register a component with its translations
137
- */
138
- registerComponent(registration) {
139
- return this.componentRegistry.registerComponent(registration);
140
- }
141
- /**
142
- * Update strings for an existing component
143
- */
144
- updateComponentStrings(componentId, strings) {
145
- return this.componentRegistry.updateComponentStrings(componentId, strings);
146
- }
147
- /**
148
- * Register an enum with translations
149
- */
150
- registerEnum(enumObj, translations, enumName) {
151
- this.enumRegistry.register(enumObj, translations, enumName);
152
- }
153
- /**
154
- * Translate a string for a component
155
- */
156
- translate(componentId, stringKey, variables, language) {
157
- const request = {
158
- componentId,
159
- stringKey,
160
- language: language || this.getCurrentLanguage(),
161
- variables,
162
- };
163
- const response = this.componentRegistry.getTranslation(request);
164
- return response.translation;
165
- }
166
- /**
167
- * Safe translate that returns a placeholder if translation fails
168
- */
169
- safeTranslate(componentId, stringKey, variables, language) {
170
- try {
171
- return this.translate(componentId, stringKey, variables, language);
172
- }
173
- catch (error) {
174
- // Return a placeholder if translation fails
175
- return `[${componentId}.${stringKey}]`;
176
- }
177
- }
178
- /**
179
- * Translate an enum value
180
- */
181
- translateEnum(enumObj, value, language) {
182
- return this.enumRegistry.translate(enumObj, value, language || this.getCurrentLanguage());
183
- }
184
- /**
185
- * Get detailed translation response
186
- */
187
- getTranslationDetails(componentId, stringKey, variables, language) {
188
- const request = {
189
- componentId,
190
- stringKey,
191
- language: language || this.getCurrentLanguage(),
192
- variables,
193
- };
194
- return this.componentRegistry.getTranslation(request);
195
- }
196
- /**
197
- * Get current context
198
- */
199
- getContext() {
200
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
201
- return globalContext.getContext(this.contextKey);
202
- }
203
- /**
204
- * Update context
205
- */
206
- updateContext(updates) {
207
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
208
- if (updates.language)
209
- globalContext.setUserLanguage(updates.language, this.contextKey);
210
- if (updates.adminLanguage)
211
- globalContext.setAdminLanguage(updates.adminLanguage, this.contextKey);
212
- if (updates.currencyCode)
213
- globalContext.setCurrencyCode(updates.currencyCode, this.contextKey);
214
- if (updates.currentContext)
215
- globalContext.setLanguageContextSpace(updates.currentContext, this.contextKey);
216
- if (updates.timezone)
217
- globalContext.setUserTimezone(updates.timezone, this.contextKey);
218
- if (updates.adminTimezone)
219
- globalContext.setAdminTimezone(updates.adminTimezone, this.contextKey);
220
- }
221
- /**
222
- * Get current language from global context
223
- * Respects language context space (admin vs user)
224
- */
225
- getCurrentLanguage() {
226
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
227
- const context = globalContext.getContext(this.contextKey);
228
- return context.currentContext === 'admin' ? context.adminLanguage : context.language;
229
- }
230
- /**
231
- * Set current language
232
- */
233
- setLanguage(language) {
234
- if (!language_registry_1.LanguageRegistry.hasLanguage(language)) {
235
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.LanguageNotFound, `Language '${language}' is not registered`, { language });
236
- }
237
- const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
238
- globalContext.setUserLanguage(language, this.contextKey);
239
- }
240
- /**
241
- * Get available languages from static registry
242
- */
243
- getLanguages() {
244
- return language_registry_1.LanguageRegistry.getAllLanguages();
245
- }
246
- /**
247
- * Get registered components
248
- */
249
- getComponents() {
250
- return this.componentRegistry.getComponents();
251
- }
252
- /**
253
- * Check if a component is registered
254
- */
255
- hasComponent(componentId) {
256
- return this.componentRegistry.hasComponent(componentId);
257
- }
258
- /**
259
- * Check if a language is registered in static registry
260
- */
261
- hasLanguage(language) {
262
- return language_registry_1.LanguageRegistry.hasLanguage(language);
263
- }
264
- /**
265
- * Get language by code from static registry
266
- */
267
- getLanguageByCode(code) {
268
- return language_registry_1.LanguageRegistry.getLanguageByCode(code);
269
- }
270
- /**
271
- * Get component registry for direct access
272
- */
273
- getComponentRegistry() {
274
- return this.componentRegistry;
275
- }
276
- /**
277
- * Get enum registry for direct access
278
- */
279
- getEnumRegistry() {
280
- return this.enumRegistry;
281
- }
282
- /**
283
- * Validate that all components have complete translations
284
- */
285
- validateAllComponents() {
286
- const errors = [];
287
- const warnings = [];
288
- let isValid = true;
289
- const components = this.getComponents();
290
- const languages = language_registry_1.LanguageRegistry.getLanguageIds();
291
- for (const component of components) {
292
- const componentStrings = this.componentRegistry.getComponentStrings(component.id);
293
- if (!componentStrings) {
294
- errors.push(`Component '${component.id}' has no registered strings`);
295
- isValid = false;
296
- continue;
297
- }
298
- for (const language of languages) {
299
- const languageStrings = componentStrings[language];
300
- if (!languageStrings) {
301
- errors.push(`Component '${component.id}' missing strings for language '${language}'`);
302
- isValid = false;
303
- continue;
304
- }
305
- for (const stringKey of component.stringKeys) {
306
- if (!languageStrings[stringKey]) {
307
- warnings.push(`Component '${component.id}' missing key '${stringKey}' for language '${language}'`);
308
- }
309
- }
310
- }
311
- }
312
- return { isValid, errors, warnings };
313
- }
314
- /**
315
- * Clear all component registrations for this instance (useful for testing)
316
- */
317
- clearAllComponents() {
318
- this.componentRegistry.clearAllComponents();
319
- }
320
- /**
321
- * Remove a specific named instance
322
- */
323
- static removeInstance(key) {
324
- const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
325
- const removed = PluginI18nEngine._instances.delete(instanceKey);
326
- // If we removed the default instance, clear the default key
327
- if (removed && PluginI18nEngine._defaultKey === instanceKey) {
328
- PluginI18nEngine._defaultKey = null;
329
- }
330
- return removed;
331
- }
332
- /**
333
- * Check if an instance exists
334
- */
335
- static hasInstance(key) {
336
- const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
337
- return PluginI18nEngine._instances.has(instanceKey);
338
- }
339
- /**
340
- * Reset all plugin engines and clear component registrations
341
- * Useful for test cleanup
342
- */
343
- static resetAll() {
344
- // Clear component registrations for each engine BEFORE clearing instances
345
- for (const engine of PluginI18nEngine._instances.values()) {
346
- engine.clearAllComponents();
347
- }
348
- PluginI18nEngine._instances.clear();
349
- PluginI18nEngine._defaultKey = null;
350
- language_registry_1.LanguageRegistry.clear();
351
- global_active_context_1.GlobalActiveContext.clearAll();
352
- }
353
- }
354
- exports.PluginI18nEngine = PluginI18nEngine;
355
- /**
356
- * Static instances for semi-singleton pattern
357
- */
358
- PluginI18nEngine._instances = new Map();
359
- PluginI18nEngine._defaultKey = null;
360
- PluginI18nEngine.DefaultInstanceKey = 'default';
@@ -1,29 +0,0 @@
1
- import { PluginI18nEngine } from './plugin-i18n-engine';
2
- /**
3
- * Generic translatable error that works with any plugin engine and component
4
- */
5
- export declare class PluginTranslatableGenericError<TStringKey extends string = string, TLanguage extends string = string> extends Error {
6
- readonly stringKey: TStringKey;
7
- readonly componentId: string;
8
- readonly language?: TLanguage;
9
- readonly variables?: Record<string, string | number>;
10
- readonly metadata?: Record<string, any>;
11
- /**
12
- * Create a translatable error
13
- * @param componentId - The component ID to translate from
14
- * @param stringKey - The translation key
15
- * @param variables - Variables for interpolation
16
- * @param language - Optional language override
17
- * @param metadata - Additional error metadata
18
- * @param instanceKey - Optional engine instance key
19
- */
20
- constructor(componentId: string, stringKey: TStringKey, variables?: Record<string, string | number>, language?: TLanguage, metadata?: Record<string, any>, instanceKey?: string);
21
- /**
22
- * Create error with explicit engine instance
23
- */
24
- static withEngine<TStringKey extends string, TLanguage extends string>(engine: PluginI18nEngine<TLanguage>, componentId: string, stringKey: TStringKey, variables?: Record<string, string | number>, language?: TLanguage, metadata?: Record<string, any>): PluginTranslatableGenericError<TStringKey, TLanguage>;
25
- /**
26
- * Retranslate the error message in a different language
27
- */
28
- retranslate(language: TLanguage, instanceKey?: string): string;
29
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginTranslatableGenericError = void 0;
4
- const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
5
- /**
6
- * Generic translatable error that works with any plugin engine and component
7
- */
8
- class PluginTranslatableGenericError extends Error {
9
- /**
10
- * Create a translatable error
11
- * @param componentId - The component ID to translate from
12
- * @param stringKey - The translation key
13
- * @param variables - Variables for interpolation
14
- * @param language - Optional language override
15
- * @param metadata - Additional error metadata
16
- * @param instanceKey - Optional engine instance key
17
- */
18
- constructor(componentId, stringKey, variables, language, metadata, instanceKey) {
19
- let translatedMessage;
20
- try {
21
- const engine = plugin_i18n_engine_1.PluginI18nEngine.getInstance(instanceKey);
22
- translatedMessage = engine.safeTranslate(componentId, stringKey, variables, language);
23
- }
24
- catch (error) {
25
- // If engine not found or translation fails, use fallback format
26
- translatedMessage = `[${componentId}.${stringKey}]`;
27
- }
28
- super(translatedMessage);
29
- this.name = 'TranslatableGenericError';
30
- this.stringKey = stringKey;
31
- this.componentId = componentId;
32
- this.language = language;
33
- this.variables = variables;
34
- this.metadata = metadata;
35
- // Ensure proper prototype chain for instanceof checks across transpiled targets
36
- }
37
- /**
38
- * Create error with explicit engine instance
39
- */
40
- static withEngine(engine, componentId, stringKey, variables, language, metadata) {
41
- const translatedMessage = engine.safeTranslate(componentId, stringKey, variables, language);
42
- const error = Object.create(PluginTranslatableGenericError.prototype);
43
- Error.call(error, translatedMessage);
44
- error.name = 'TranslatableGenericError';
45
- error.stringKey = stringKey;
46
- error.componentId = componentId;
47
- error.language = language;
48
- error.variables = variables;
49
- error.metadata = metadata;
50
- error.message = translatedMessage;
51
- return error;
52
- }
53
- /**
54
- * Retranslate the error message in a different language
55
- */
56
- retranslate(language, instanceKey) {
57
- try {
58
- const engine = plugin_i18n_engine_1.PluginI18nEngine.getInstance(instanceKey);
59
- return engine.safeTranslate(this.componentId, this.stringKey, this.variables, language);
60
- }
61
- catch (error) {
62
- return `[${this.componentId}.${this.stringKey}]`;
63
- }
64
- }
65
- }
66
- exports.PluginTranslatableGenericError = PluginTranslatableGenericError;
@@ -1,28 +0,0 @@
1
- import { IHandleable } from './i-handleable';
2
- import { PluginTranslatableGenericError } from './plugin-translatable-generic-error';
3
- /**
4
- * Generic translatable error that works with any plugin engine and component
5
- */
6
- export declare class PluginTranslatableHandleableGenericError<TStringKey extends string = string, TLanguage extends string = string> extends PluginTranslatableGenericError<TStringKey, TLanguage> implements IHandleable {
7
- private _handled;
8
- readonly cause?: Error;
9
- readonly statusCode: number;
10
- readonly sourceData?: unknown;
11
- /**
12
- * Create a translatable error
13
- * @param componentId - The component ID to translate from
14
- * @param stringKey - The translation key
15
- * @param variables - Variables for interpolation
16
- * @param language - Optional language override
17
- * @param metadata - Additional error metadata
18
- * @param instanceKey - Optional engine instance key
19
- */
20
- constructor(componentId: string, stringKey: TStringKey, variables?: Record<string, string | number>, language?: TLanguage, metadata?: Record<string, any>, instanceKey?: string, handleableOptions?: {
21
- statusCode?: number;
22
- cause?: Error;
23
- sourceData?: unknown;
24
- });
25
- get handled(): boolean;
26
- set handled(value: boolean);
27
- toJSON(): Record<string, unknown>;
28
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginTranslatableHandleableGenericError = void 0;
4
- const plugin_translatable_generic_error_1 = require("./plugin-translatable-generic-error");
5
- /**
6
- * Generic translatable error that works with any plugin engine and component
7
- */
8
- class PluginTranslatableHandleableGenericError extends plugin_translatable_generic_error_1.PluginTranslatableGenericError {
9
- /**
10
- * Create a translatable error
11
- * @param componentId - The component ID to translate from
12
- * @param stringKey - The translation key
13
- * @param variables - Variables for interpolation
14
- * @param language - Optional language override
15
- * @param metadata - Additional error metadata
16
- * @param instanceKey - Optional engine instance key
17
- */
18
- constructor(componentId, stringKey, variables, language, metadata, instanceKey, handleableOptions) {
19
- super(componentId, stringKey, variables, language, metadata, instanceKey);
20
- this._handled = false;
21
- this.statusCode = handleableOptions?.statusCode ?? 500;
22
- this.cause = handleableOptions?.cause;
23
- this.sourceData = handleableOptions?.sourceData;
24
- }
25
- get handled() {
26
- return this._handled;
27
- }
28
- set handled(value) {
29
- this._handled = value;
30
- }
31
- toJSON() {
32
- return {
33
- statusCode: this.statusCode,
34
- message: this.message,
35
- cause: this.cause,
36
- sourceData: this.sourceData,
37
- };
38
- }
39
- }
40
- exports.PluginTranslatableHandleableGenericError = PluginTranslatableHandleableGenericError;
@@ -1,14 +0,0 @@
1
- import { HandleableErrorOptions } from './i-handleable-error-options';
2
- import { IHandleable } from './i-handleable';
3
- import { CompleteReasonMap, PluginTypedError } from './typed-error';
4
- import { PluginI18nEngine } from './plugin-i18n-engine';
5
- export declare class PluginTypedHandleableError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string = string> extends PluginTypedError<TEnum, TStringKey, TLanguages> implements IHandleable {
6
- readonly cause?: Error;
7
- readonly statusCode: number;
8
- readonly sourceData?: unknown;
9
- private _handled;
10
- constructor(engine: PluginI18nEngine<TLanguages>, componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, source: Error, options?: HandleableErrorOptions, language?: TLanguages, otherVars?: Record<string, string | number>);
11
- get handled(): boolean;
12
- set handled(value: boolean);
13
- toJSON(): Record<string, unknown>;
14
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginTypedHandleableError = void 0;
4
- const handleable_1 = require("./handleable");
5
- const typed_error_1 = require("./typed-error");
6
- class PluginTypedHandleableError extends typed_error_1.PluginTypedError {
7
- constructor(engine, componentId, type, reasonMap, source, options, language, otherVars) {
8
- super(engine, componentId, type, reasonMap, language, otherVars);
9
- this.cause = options?.cause ?? source;
10
- this.statusCode = options?.statusCode ?? 500;
11
- this._handled = options?.handled ?? false;
12
- this.sourceData = options?.sourceData;
13
- // Capture stack trace - prioritize source stack, then capture new one
14
- if (source.stack) {
15
- this.stack = source.stack;
16
- }
17
- else if (Error.captureStackTrace) {
18
- Error.captureStackTrace(this, this.constructor);
19
- }
20
- else {
21
- this.stack = new Error().stack;
22
- }
23
- this.name = this.constructor.name;
24
- }
25
- get handled() {
26
- return this._handled;
27
- }
28
- set handled(value) {
29
- this._handled = value;
30
- }
31
- toJSON() {
32
- return {
33
- name: this.name,
34
- message: this.message,
35
- statusCode: this.statusCode,
36
- handled: this.handled,
37
- stack: this.stack,
38
- cause: this.cause instanceof handleable_1.HandleableError || this.cause instanceof PluginTypedHandleableError
39
- ? this.cause.toJSON()
40
- : this.cause?.message,
41
- ...(this.sourceData ? { sourceData: this.sourceData } : {}),
42
- };
43
- }
44
- }
45
- exports.PluginTypedHandleableError = PluginTypedHandleableError;
@@ -1,14 +0,0 @@
1
- import { CurrencyCode } from './currency-code';
2
- import { Timezone } from './timezone';
3
- import { ValidationConfig } from './validation-config';
4
- /**
5
- * Registry configuration
6
- */
7
- export interface RegistryConfig<TLanguages extends string> {
8
- readonly defaultLanguage: TLanguages;
9
- readonly fallbackLanguage: TLanguages;
10
- readonly defaultCurrencyCode: CurrencyCode;
11
- readonly timezone: Timezone;
12
- readonly adminTimezone: Timezone;
13
- readonly validation: ValidationConfig;
14
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +0,0 @@
1
- /**
2
- * Error types for registry operations
3
- */
4
- export declare enum RegistryErrorType {
5
- ComponentNotFound = "COMPONENT_NOT_FOUND",
6
- LanguageNotFound = "LANGUAGE_NOT_FOUND",
7
- StringKeyNotFound = "STRING_KEY_NOT_FOUND",
8
- IncompleteRegistration = "INCOMPLETE_REGISTRATION",
9
- DuplicateComponent = "DUPLICATE_COMPONENT",
10
- DuplicateLanguage = "DUPLICATE_LANGUAGE",
11
- ValidationFailed = "VALIDATION_FAILED"
12
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RegistryErrorType = void 0;
4
- /**
5
- * Error types for registry operations
6
- */
7
- var RegistryErrorType;
8
- (function (RegistryErrorType) {
9
- RegistryErrorType["ComponentNotFound"] = "COMPONENT_NOT_FOUND";
10
- RegistryErrorType["LanguageNotFound"] = "LANGUAGE_NOT_FOUND";
11
- RegistryErrorType["StringKeyNotFound"] = "STRING_KEY_NOT_FOUND";
12
- RegistryErrorType["IncompleteRegistration"] = "INCOMPLETE_REGISTRATION";
13
- RegistryErrorType["DuplicateComponent"] = "DUPLICATE_COMPONENT";
14
- RegistryErrorType["DuplicateLanguage"] = "DUPLICATE_LANGUAGE";
15
- RegistryErrorType["ValidationFailed"] = "VALIDATION_FAILED";
16
- })(RegistryErrorType || (exports.RegistryErrorType = RegistryErrorType = {}));
@@ -1,18 +0,0 @@
1
- import { RegistryErrorType } from './registry-error-type';
2
- import { TranslationEngine } from './typed-error';
3
- /**
4
- * Registry error class that can work with plugin engines
5
- */
6
- export declare class RegistryError extends Error {
7
- readonly type: RegistryErrorType;
8
- readonly metadata?: Record<string, any> | undefined;
9
- constructor(type: RegistryErrorType, message: string, metadata?: Record<string, any> | undefined);
10
- /**
11
- * Create a registry error with translation support
12
- */
13
- static createWithEngine(engine: TranslationEngine, type: RegistryErrorType, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>): RegistryError;
14
- /**
15
- * Create a simple RegistryError without engine dependency
16
- */
17
- static createSimple(type: RegistryErrorType, message: string, metadata?: Record<string, any>): RegistryError;
18
- }